From 20eabd8c4c62ee4334401dd732a99ea3ee07db29 Mon Sep 17 00:00:00 2001 From: David Montero Crespo Date: Sat, 9 May 2026 00:05:28 -0300 Subject: [PATCH] fix(scripts): generate-component-svgs no longer skips bmp280 / fails on ssd1306 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two distinct issues hit the component SVG generation step: 1. `velxio-bmp280` was in ELEMENTS but tries to require bmp280-element.js from the wokwi-elements CJS dist — that file doesn't exist because BMP280 is a velxio-native component, not a wokwi one. Its SVG already ships hand-authored at frontend/public/component-svgs/bmp280.svg, so the script should never have tried to extract it. Drop the row and leave a comment explaining why. 2. `wokwi-ssd1306` failed with "ImageData is not defined" because the element constructor seeds an off-screen canvas with `new ImageData(width, height)` — a browser API absent in Node. We never invoke putImageData (renderSVG() draws the static frame from scratch), so a minimal global stub that doesn't throw is all that's needed. Polyfill it on globalThis next to the existing customElements stub. After this: - 38 generated, 0 skipped, 0 failed (was: 1 skip, 1 fail). - ssd1306.svg now ships in frontend/public/component-svgs/. --- frontend/public/component-svgs/ssd1306.svg | 52 ++++++++++++++++++++++ scripts/generate-component-svgs.cjs | 23 +++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 frontend/public/component-svgs/ssd1306.svg diff --git a/frontend/public/component-svgs/ssd1306.svg b/frontend/public/component-svgs/ssd1306.svg new file mode 100644 index 00000000..1ced6b70 --- /dev/null +++ b/frontend/public/component-svgs/ssd1306.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + Data + SA0 + CS + Vin + C1k + DC + Rst + 3v3 + Gnd + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scripts/generate-component-svgs.cjs b/scripts/generate-component-svgs.cjs index b84c886c..15ae56ff 100644 --- a/scripts/generate-component-svgs.cjs +++ b/scripts/generate-component-svgs.cjs @@ -118,6 +118,26 @@ if (typeof globalThis.customElements === 'undefined') { globalThis.customElements = { define: () => {} }; } +// Stub `ImageData` — used by ssd1306-element's constructor to seed the +// off-screen canvas. We never invoke `putImageData` (the script only calls +// renderSVG()), so a minimal shape that doesn't throw is enough. +if (typeof globalThis.ImageData === 'undefined') { + globalThis.ImageData = class ImageData { + constructor(widthOrData, height, settings) { + if (typeof widthOrData === 'number') { + this.width = widthOrData; + this.height = height; + this.data = new Uint8ClampedArray(widthOrData * height * 4); + } else { + this.data = widthOrData; + this.width = height; + this.height = settings; + } + this.colorSpace = 'srgb'; + } + }; +} + // ── Elements to extract ─────────────────────────────────────────────────────── // [ tagName, elementFile, defaultProps, useRenderSVG ] const ELEMENTS = [ @@ -133,7 +153,8 @@ const ELEMENTS = [ ['wokwi-dht22', 'dht22-element', {}, false ], ['wokwi-hc-sr04', 'hc-sr04-element', {}, false ], ['wokwi-mpu6050', 'mpu6050-element', {}, false ], - ['velxio-bmp280', 'bmp280-element', {}, false ], + // velxio-bmp280 is a velxio-native component — its SVG ships hand-authored + // at frontend/public/component-svgs/bmp280.svg, so no extraction is needed. ['wokwi-lcd2004', 'lcd2004-element', {}, false ], ['wokwi-ssd1306', 'ssd1306-element', { width: 128, height: 64 }, false ], ['wokwi-ili9341', 'ili9341-element', {}, false ],