embedded-react 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +5 -0
- package/README.md +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +246 -111
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +320 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- package/assets/bake-font.mjs +123 -77
- package/assets/bake-image.mjs +39 -22
- package/assets/bake-svg.mjs +361 -262
- package/assets/build-builtin-font.mjs +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +23 -13
- package/cli.mjs +402 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +62 -64
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +37 -21
- package/package.json +7 -8
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- package/src/embedded-react/layout-anim-config.js +10 -4
- package/src/embedded-react/list-child.js +5 -5
- package/src/embedded-react/named-colors.js +1 -1
- package/src/embedded-react/nativeModule.js +462 -0
- package/src/embedded-react/split-style.js +11 -11
- package/src/embedded-react/svg-ops.js +760 -593
- package/src/embedded-react/useHostValue.js +3 -3
- package/src/embedded-react/usePersistentState.js +6 -6
- package/src/embedded-react/warn-props.js +1 -1
- package/src/host-config.js +60 -53
- package/src/props.js +49 -41
- package/src/renderer.js +7 -4
- package/aot/compiler/assemble.mjs +0 -944
- package/aot/compiler/c/animations.mjs +0 -436
- package/aot/compiler/c/boot.mjs +0 -127
- package/aot/compiler/c/expressions.mjs +0 -270
- package/aot/compiler/c/functions.mjs +0 -268
- package/aot/compiler/c/keyboard.mjs +0 -96
- package/aot/compiler/c/nodes.mjs +0 -303
- package/aot/compiler/c/pan-responder.mjs +0 -136
- package/aot/compiler/c/statements.mjs +0 -319
- package/aot/compiler/c/text.mjs +0 -83
- package/aot/compiler/c/vectors.mjs +0 -381
- package/aot/compiler/c-syntax.mjs +0 -127
package/sim/index.html
CHANGED
|
@@ -150,17 +150,17 @@
|
|
|
150
150
|
(async () => {
|
|
151
151
|
const stage = document.getElementById('stage');
|
|
152
152
|
const canvas = document.getElementById('screen');
|
|
153
|
-
const
|
|
153
|
+
const canvasContext = canvas.getContext('2d');
|
|
154
154
|
const panel = document.getElementById('panel');
|
|
155
155
|
const toggle = document.getElementById('toggle');
|
|
156
156
|
const sizeLabel = document.getElementById('sizeLabel');
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
157
|
+
const presetSelect = document.getElementById('preset');
|
|
158
|
+
const widthInput = document.getElementById('w');
|
|
159
|
+
const heightInput = document.getElementById('h');
|
|
160
160
|
const device = document.getElementById('device');
|
|
161
|
-
const
|
|
161
|
+
const frameCheckbox = document.getElementById('frame');
|
|
162
162
|
let framed = false;
|
|
163
|
-
const fail = (
|
|
163
|
+
const fail = (message) => { sizeLabel.textContent = message; panel.classList.remove('collapsed'); };
|
|
164
164
|
|
|
165
165
|
// "Fit to window" (the full viewport) is the default — the browser's responsive/device toolbar drives
|
|
166
166
|
// the board directly. Presets lock to a real panel size.
|
|
@@ -171,15 +171,15 @@
|
|
|
171
171
|
[320, 240],
|
|
172
172
|
[240, 320],
|
|
173
173
|
];
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
for (const [
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
174
|
+
const fitOption = document.createElement('option');
|
|
175
|
+
fitOption.value = 'fit';
|
|
176
|
+
fitOption.textContent = 'Fit to window';
|
|
177
|
+
presetSelect.appendChild(fitOption);
|
|
178
|
+
for (const [presetWidth, presetHeight] of PRESETS) {
|
|
179
|
+
const option = document.createElement('option');
|
|
180
|
+
option.value = `${presetWidth}x${presetHeight}`;
|
|
181
|
+
option.textContent = `${presetWidth} × ${presetHeight}`;
|
|
182
|
+
presetSelect.appendChild(option);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
toggle.addEventListener('click', () => panel.classList.toggle('collapsed'));
|
|
@@ -187,9 +187,9 @@
|
|
|
187
187
|
let Module;
|
|
188
188
|
try {
|
|
189
189
|
Module = await createEmbeddedReact();
|
|
190
|
-
} catch (
|
|
190
|
+
} catch (error) {
|
|
191
191
|
fail('load failed — run build.mjs');
|
|
192
|
-
throw
|
|
192
|
+
throw error;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
const init = Module.cwrap('er_web_init', 'number', ['number', 'number']);
|
|
@@ -200,43 +200,52 @@
|
|
|
200
200
|
const pump = Module.cwrap('er_web_pump', null, ['number']);
|
|
201
201
|
const touch = Module.cwrap('er_web_touch', null, ['number', 'number', 'number']);
|
|
202
202
|
const framebuffer = Module.cwrap('er_web_framebuffer', 'number', []);
|
|
203
|
-
const
|
|
204
|
-
const
|
|
203
|
+
const framebufferWidth = Module.cwrap('er_web_framebuffer_width', 'number', []);
|
|
204
|
+
const framebufferHeight = Module.cwrap('er_web_framebuffer_height', 'number', []);
|
|
205
205
|
|
|
206
|
-
const
|
|
206
|
+
const MIN_SCREEN_SIZE = 64;
|
|
207
|
+
const MAX_SCREEN_SIZE = 4096;
|
|
208
|
+
const RGBA_BYTES = 4;
|
|
209
|
+
const REFIT_DEBOUNCE_MS = 60;
|
|
210
|
+
// The touch phases er_web_touch() takes.
|
|
211
|
+
const TOUCH_DOWN = 0;
|
|
212
|
+
const TOUCH_MOVE = 1;
|
|
213
|
+
const TOUCH_UP = 2;
|
|
214
|
+
|
|
215
|
+
const clamp = (size) => Math.max(MIN_SCREEN_SIZE, Math.min(MAX_SCREEN_SIZE, size | 0));
|
|
207
216
|
// The stage is inset:0, so its client size is the full viewport (the floating panel never shrinks it).
|
|
208
217
|
const stageSize = () => [clamp(stage.clientWidth), clamp(stage.clientHeight)];
|
|
209
218
|
|
|
210
219
|
// Initial size: ?screen=WxH locks to that size; otherwise fit the viewport.
|
|
211
220
|
const params = new URLSearchParams(location.search);
|
|
212
221
|
let mode = 'fit';
|
|
213
|
-
let [
|
|
222
|
+
let [screenWidth, screenHeight] = stageSize();
|
|
214
223
|
const initial = params.get('screen');
|
|
215
224
|
if (initial) {
|
|
216
|
-
const [
|
|
217
|
-
if (
|
|
225
|
+
const [queryWidth, queryHeight] = initial.split('x').map((part) => parseInt(part, 10) || 0);
|
|
226
|
+
if (queryWidth && queryHeight) {
|
|
218
227
|
mode = 'fixed';
|
|
219
|
-
|
|
220
|
-
|
|
228
|
+
screenWidth = clamp(queryWidth);
|
|
229
|
+
screenHeight = clamp(queryHeight);
|
|
221
230
|
}
|
|
222
231
|
}
|
|
223
|
-
|
|
232
|
+
presetSelect.value = mode === 'fit' ? 'fit' : PRESETS.some(([presetWidth, presetHeight]) => presetWidth === screenWidth && presetHeight === screenHeight) ? `${screenWidth}x${screenHeight}` : 'fit';
|
|
224
233
|
|
|
225
|
-
if (!init(
|
|
234
|
+
if (!init(screenWidth, screenHeight)) {
|
|
226
235
|
fail('init failed');
|
|
227
236
|
return;
|
|
228
237
|
}
|
|
229
238
|
|
|
230
239
|
// Copy bytes into wasm memory, hand the pointer to a C function, then free.
|
|
231
|
-
const withWasmBytes = (bytes,
|
|
232
|
-
const
|
|
233
|
-
Module.HEAPU8.set(bytes,
|
|
234
|
-
|
|
235
|
-
Module._free(
|
|
240
|
+
const withWasmBytes = (bytes, call) => {
|
|
241
|
+
const pointer = Module._malloc(bytes.length);
|
|
242
|
+
Module.HEAPU8.set(bytes, pointer);
|
|
243
|
+
call(pointer, bytes.length);
|
|
244
|
+
Module._free(pointer);
|
|
236
245
|
};
|
|
237
246
|
const fetchBytes = async (url) => {
|
|
238
|
-
const
|
|
239
|
-
return
|
|
247
|
+
const response = await fetch(url, { cache: 'no-store' });
|
|
248
|
+
return response.ok ? new Uint8Array(await response.arrayBuffer()) : null;
|
|
240
249
|
};
|
|
241
250
|
|
|
242
251
|
// Load the asset pack (if any) BEFORE the bundle so <Image>/custom-font nodes resolve, then run the
|
|
@@ -261,46 +270,46 @@
|
|
|
261
270
|
// server) doesn't poll a nonexistent /reload endpoint.
|
|
262
271
|
if (window.__erHot) {
|
|
263
272
|
try {
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
273
|
+
const events = new EventSource('/reload');
|
|
274
|
+
events.onmessage = () => loadApp();
|
|
275
|
+
events.onerror = () => {};
|
|
267
276
|
} catch {
|
|
268
277
|
/* EventSource unavailable */
|
|
269
278
|
}
|
|
270
279
|
}
|
|
271
280
|
|
|
272
|
-
let
|
|
273
|
-
let
|
|
274
|
-
let
|
|
281
|
+
let width = 0;
|
|
282
|
+
let height = 0;
|
|
283
|
+
let byteLength = 0;
|
|
275
284
|
let image = null;
|
|
276
285
|
|
|
277
286
|
const syncCanvas = () => {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
canvas.width =
|
|
282
|
-
canvas.height =
|
|
287
|
+
width = framebufferWidth();
|
|
288
|
+
height = framebufferHeight();
|
|
289
|
+
byteLength = width * height * RGBA_BYTES;
|
|
290
|
+
canvas.width = width;
|
|
291
|
+
canvas.height = height;
|
|
283
292
|
// Fit: fill the viewport (backing already equals it, so still 1:1). Locked: native size, centered,
|
|
284
293
|
// scroll if larger than the window. The #device wrapper fills the stage in Fit mode or shrinks to
|
|
285
294
|
// the canvas (+ bezel when framed) when locked.
|
|
286
|
-
canvas.style.width = mode === 'fit' ? '100%' :
|
|
287
|
-
canvas.style.height = mode === 'fit' ? '100%' :
|
|
295
|
+
canvas.style.width = mode === 'fit' ? '100%' : width + 'px';
|
|
296
|
+
canvas.style.height = mode === 'fit' ? '100%' : height + 'px';
|
|
288
297
|
device.style.display = mode === 'fit' ? 'block' : 'inline-block';
|
|
289
298
|
device.style.width = mode === 'fit' ? '100%' : 'auto';
|
|
290
299
|
device.style.height = mode === 'fit' ? '100%' : 'auto';
|
|
291
300
|
device.classList.toggle('framed', framed && mode === 'fixed');
|
|
292
|
-
image =
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
sizeLabel.textContent = `${
|
|
301
|
+
image = canvasContext.createImageData(width, height);
|
|
302
|
+
widthInput.value = width;
|
|
303
|
+
heightInput.value = height;
|
|
304
|
+
sizeLabel.textContent = `${width}×${height}${mode === 'fit' ? ' · fit' : ''}`;
|
|
296
305
|
};
|
|
297
306
|
syncCanvas();
|
|
298
307
|
|
|
299
|
-
const applySize = (
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
if (resize(
|
|
308
|
+
const applySize = (newWidth, newHeight) => {
|
|
309
|
+
newWidth = clamp(newWidth);
|
|
310
|
+
newHeight = clamp(newHeight);
|
|
311
|
+
if (newWidth === width && newHeight === height) return;
|
|
312
|
+
if (resize(newWidth, newHeight)) syncCanvas();
|
|
304
313
|
};
|
|
305
314
|
|
|
306
315
|
// Debounced refit while the viewport changes (window drag, device toolbar, rotate). Driven by the
|
|
@@ -310,62 +319,62 @@
|
|
|
310
319
|
const refit = () => {
|
|
311
320
|
if (mode !== 'fit') return;
|
|
312
321
|
clearTimeout(resizeTimer);
|
|
313
|
-
resizeTimer = setTimeout(() => applySize(...stageSize()),
|
|
322
|
+
resizeTimer = setTimeout(() => applySize(...stageSize()), REFIT_DEBOUNCE_MS);
|
|
314
323
|
};
|
|
315
324
|
window.addEventListener('resize', refit);
|
|
316
325
|
new ResizeObserver(refit).observe(stage);
|
|
317
326
|
// Initial fit once layout has settled (the first synchronous measure can predate viewport layout).
|
|
318
327
|
setTimeout(() => mode === 'fit' && applySize(...stageSize()), 0);
|
|
319
328
|
|
|
320
|
-
|
|
321
|
-
if (
|
|
329
|
+
presetSelect.addEventListener('change', () => {
|
|
330
|
+
if (presetSelect.value === 'fit') {
|
|
322
331
|
mode = 'fit';
|
|
323
332
|
applySize(...stageSize());
|
|
324
333
|
} else {
|
|
325
334
|
mode = 'fixed';
|
|
326
|
-
applySize(...
|
|
335
|
+
applySize(...presetSelect.value.split('x').map((part) => parseInt(part, 10)));
|
|
327
336
|
}
|
|
328
337
|
syncCanvas();
|
|
329
338
|
});
|
|
330
339
|
document.getElementById('apply').addEventListener('click', () => {
|
|
331
340
|
mode = 'fixed';
|
|
332
|
-
|
|
333
|
-
? `${+
|
|
341
|
+
presetSelect.value = PRESETS.some(([presetWidth, presetHeight]) => presetWidth === +widthInput.value && presetHeight === +heightInput.value)
|
|
342
|
+
? `${+widthInput.value}x${+heightInput.value}`
|
|
334
343
|
: 'fit';
|
|
335
|
-
applySize(+
|
|
344
|
+
applySize(+widthInput.value, +heightInput.value);
|
|
336
345
|
syncCanvas();
|
|
337
346
|
});
|
|
338
347
|
// Device-frame chrome only makes sense at a locked size, so enabling it locks the current size.
|
|
339
|
-
|
|
340
|
-
framed =
|
|
348
|
+
frameCheckbox.addEventListener('change', () => {
|
|
349
|
+
framed = frameCheckbox.checked;
|
|
341
350
|
if (framed && mode === 'fit') {
|
|
342
351
|
mode = 'fixed';
|
|
343
|
-
|
|
352
|
+
presetSelect.value = PRESETS.some(([presetWidth, presetHeight]) => presetWidth === width && presetHeight === height) ? `${width}x${height}` : 'fit';
|
|
344
353
|
}
|
|
345
354
|
syncCanvas();
|
|
346
355
|
});
|
|
347
356
|
|
|
348
357
|
// Pointer -> touch. Map CSS pixels to framebuffer pixels (the canvas may be stretched in Fit mode).
|
|
349
358
|
let down = false;
|
|
350
|
-
const toFb = (
|
|
351
|
-
const
|
|
352
|
-
const x = Math.round(((
|
|
353
|
-
const y = Math.round(((
|
|
359
|
+
const toFb = (event) => {
|
|
360
|
+
const bounds = canvas.getBoundingClientRect();
|
|
361
|
+
const x = Math.round(((event.clientX - bounds.left) / bounds.width) * width);
|
|
362
|
+
const y = Math.round(((event.clientY - bounds.top) / bounds.height) * height);
|
|
354
363
|
return [x, y];
|
|
355
364
|
};
|
|
356
|
-
canvas.addEventListener('pointerdown', (
|
|
357
|
-
|
|
365
|
+
canvas.addEventListener('pointerdown', (event) => {
|
|
366
|
+
event.preventDefault();
|
|
358
367
|
down = true;
|
|
359
|
-
canvas.setPointerCapture(
|
|
360
|
-
touch(
|
|
368
|
+
canvas.setPointerCapture(event.pointerId);
|
|
369
|
+
touch(TOUCH_DOWN, ...toFb(event));
|
|
361
370
|
});
|
|
362
|
-
canvas.addEventListener('pointermove', (
|
|
363
|
-
if (down) touch(
|
|
371
|
+
canvas.addEventListener('pointermove', (event) => {
|
|
372
|
+
if (down) touch(TOUCH_MOVE, ...toFb(event));
|
|
364
373
|
});
|
|
365
|
-
const release = (
|
|
374
|
+
const release = (event) => {
|
|
366
375
|
if (!down) return;
|
|
367
376
|
down = false;
|
|
368
|
-
touch(
|
|
377
|
+
touch(TOUCH_UP, ...toFb(event));
|
|
369
378
|
};
|
|
370
379
|
canvas.addEventListener('pointerup', release);
|
|
371
380
|
canvas.addEventListener('pointercancel', release);
|
|
@@ -378,23 +387,23 @@
|
|
|
378
387
|
// minutes of throttling is immediately at the right time. Catching up is cheap however long it was:
|
|
379
388
|
// the physics integrators cap their step count, timing animations clamp to their duration, and each
|
|
380
389
|
// timer fires once per pass rather than once per period it missed.
|
|
381
|
-
const
|
|
390
|
+
const MAX_ELAPSED_MS = 2147483647; // INT32_MAX: er_web_pump takes an int, and that is the only bound needed
|
|
382
391
|
// No frame for this long means rAF is stalled and the interval below takes over the pump.
|
|
383
392
|
const RAF_IDLE_MS = 250;
|
|
384
393
|
|
|
385
|
-
let
|
|
394
|
+
let previousTime = performance.now();
|
|
386
395
|
let lastFrame = performance.now();
|
|
387
396
|
|
|
388
397
|
const step = (paint) => {
|
|
389
398
|
const now = performance.now();
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
pump(Math.round(
|
|
399
|
+
const elapsedMs = Math.min(MAX_ELAPSED_MS, now - previousTime);
|
|
400
|
+
previousTime = now;
|
|
401
|
+
pump(Math.round(elapsedMs));
|
|
393
402
|
if (!paint) return;
|
|
394
403
|
// HEAPU8 may detach when WASM memory grows, so wrap a fresh view each frame, then copy into the
|
|
395
404
|
// persistent ImageData (robust against detach during the copy).
|
|
396
|
-
image.data.set(new Uint8ClampedArray(Module.HEAPU8.buffer, framebuffer(),
|
|
397
|
-
|
|
405
|
+
image.data.set(new Uint8ClampedArray(Module.HEAPU8.buffer, framebuffer(), byteLength));
|
|
406
|
+
canvasContext.putImageData(image, 0, 0);
|
|
398
407
|
};
|
|
399
408
|
|
|
400
409
|
const frame = () => {
|