@vectojs/core 1.14.0 → 1.16.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.
Files changed (52) hide show
  1. package/dist/{chunk-XIEQHSBB.mjs → chunk-AQTO7OSU.mjs} +253 -496
  2. package/dist/{chunk-2Z23LTH3.js → chunk-DUYB4GX4.js} +310 -551
  3. package/dist/{chunk-BEUIB3U7.js → chunk-IYPLG4Z4.js} +93 -43
  4. package/dist/{chunk-L5BCKFQE.mjs → chunk-JFU56BX4.mjs} +48 -0
  5. package/dist/index.d.ts +4 -12
  6. package/dist/index.js +2155 -456
  7. package/dist/index.mjs +1977 -279
  8. package/dist/layout/index.d.ts +1 -3
  9. package/dist/layout.js +3 -15
  10. package/dist/layout.mjs +2 -16
  11. package/dist/renderer/CanvasRenderer.d.ts +22 -0
  12. package/dist/renderer/IRenderer.d.ts +13 -0
  13. package/dist/renderer.js +4 -3
  14. package/dist/renderer.mjs +1 -1
  15. package/dist/text/MSDFTextEntity.d.ts +30 -1
  16. package/dist/text/index.d.ts +1 -5
  17. package/dist/text.js +5 -15
  18. package/dist/text.mjs +6 -17
  19. package/dist/tree/ComputeParticleEntity.d.ts +18 -0
  20. package/dist/tree/DOMPortalEntity.d.ts +18 -0
  21. package/dist/tree/Entity.d.ts +122 -6
  22. package/dist/tree/Scene.d.ts +380 -0
  23. package/dist/wasm/anim-backend.d.ts +86 -0
  24. package/dist/wasm/asset.d.ts +25 -0
  25. package/dist/wasm/asset.js +7 -0
  26. package/dist/wasm/asset.mjs +5 -0
  27. package/dist/wasm/backend.d.ts +154 -0
  28. package/dist/wasm/hit-backend.d.ts +92 -0
  29. package/dist/wasm/hit-store.d.ts +48 -0
  30. package/dist/wasm/particle-backend.d.ts +104 -0
  31. package/dist/wasm/scene-store.d.ts +28 -0
  32. package/dist/wasm/soa.d.ts +146 -0
  33. package/dist/wasm/vectojs_core.wasm +0 -0
  34. package/package.json +17 -8
  35. package/dist/animation/drivers.d.ts +0 -48
  36. package/dist/animation/easing.d.ts +0 -16
  37. package/dist/chunk-4AR425AR.js +0 -1121
  38. package/dist/chunk-BA5HUUDF.js +0 -760
  39. package/dist/chunk-IESDTEJ4.mjs +0 -1121
  40. package/dist/chunk-X7I465AQ.mjs +0 -760
  41. package/dist/layout/LayoutEngine.d.ts +0 -289
  42. package/dist/layout/LayoutWorker.d.ts +0 -23
  43. package/dist/layout/LayoutWorkerManager.d.ts +0 -26
  44. package/dist/layout/LayoutWorkerSource.d.ts +0 -1
  45. package/dist/layout/measure.d.ts +0 -20
  46. package/dist/math/SpatialHashGrid.d.ts +0 -53
  47. package/dist/math/SpringPhysics.d.ts +0 -13
  48. package/dist/text/ArabicShaper.d.ts +0 -10
  49. package/dist/text/BidiResolver.d.ts +0 -5
  50. package/dist/text/MSDFFont.d.ts +0 -129
  51. package/dist/text/PreparedContentGrid.d.ts +0 -60
  52. package/dist/text/Typography.d.ts +0 -11
@@ -1,4 +1,6 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4;// src/renderer/CanvasRenderer.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4;const __vecto_cjs_url=require("url").pathToFileURL(__filename).href;
2
+
3
+ // src/renderer/CanvasRenderer.ts
2
4
  var TWO_PI = Math.PI * 2;
3
5
  function getDevicePixelRatio() {
4
6
  return typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
@@ -7,6 +9,14 @@ var CanvasRenderer = (_class = class _CanvasRenderer {
7
9
 
8
10
 
9
11
 
12
+
13
+ /** True between a `contextlost` and its `contextrestored` — the 2D context is
14
+ * unusable, so draw calls are skipped until it comes back. Canvas2D context
15
+ * loss is rare (GPU reset / memory pressure) but a real browser event. */
16
+ __init() {this.contextLost = false}
17
+ /** Invoked after the context is restored + re-initialized, so the owner
18
+ * (`Scene`) can repaint the now-blank canvas. Set via {@link onContextRestored}. */
19
+ __init2() {this.contextRestoredCb = null}
10
20
  /**
11
21
  * Cap on the effective device pixel ratio applied by the constructor and
12
22
  * {@link resize}. `undefined` (default) uses the real, uncapped
@@ -25,12 +35,12 @@ var CanvasRenderer = (_class = class _CanvasRenderer {
25
35
  static __initStatic() {this.MAX_BATCH = 64}
26
36
  // Order-preserving batch state for fillCircle(): a run of same-style circles
27
37
  // accumulates into one path and is committed by a single fill() on flush().
28
- __init() {this.batchActive = false}
29
- __init2() {this.batchColor = ""}
30
- __init3() {this.batchAlpha = 1}
31
- __init4() {this.batchCount = 0}
32
- __init5() {this._cachedFont = ""}
33
- __init6() {this._cachedFill = ""}
38
+ __init3() {this.batchActive = false}
39
+ __init4() {this.batchColor = ""}
40
+ __init5() {this.batchAlpha = 1}
41
+ __init6() {this.batchCount = 0}
42
+ __init7() {this._cachedFont = ""}
43
+ __init8() {this._cachedFill = ""}
34
44
  /**
35
45
  * @param canvas - The target canvas. Its backing store is resized to the
36
46
  * logical size × devicePixelRatio.
@@ -40,7 +50,7 @@ var CanvasRenderer = (_class = class _CanvasRenderer {
40
50
  * set) so the canvas's own dimensions aren't clobbered by the window's.
41
51
  * @param maxDPR - See {@link maxDPR}.
42
52
  */
43
- constructor(canvas, size, maxDPR) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);
53
+ constructor(canvas, size, maxDPR) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);
44
54
  this.maxDPR = maxDPR;
45
55
  const dpr = this.effectiveDPR();
46
56
  this.width = _nullishCoalesce(_optionalChain([size, 'optionalAccess', _ => _.width]), () => ( (typeof window !== "undefined" ? window.innerWidth : canvas.width || 0)));
@@ -54,6 +64,40 @@ var CanvasRenderer = (_class = class _CanvasRenderer {
54
64
  const ctx = canvas.getContext("2d");
55
65
  this.ctx = ctx;
56
66
  if (ctx) ctx.scale(dpr, dpr);
67
+ this.canvas = canvas;
68
+ this.setupContextLossRecovery();
69
+ }
70
+ /** Register a callback fired after a lost 2D context is restored + re-scaled,
71
+ * so the owner can repaint (the restored canvas comes back cleared). */
72
+ onContextRestored(cb) {
73
+ this.contextRestoredCb = cb;
74
+ }
75
+ /**
76
+ * Handle Canvas2D context loss/restore (GPU reset, memory pressure). The
77
+ * `contextlost` handler MUST call `preventDefault()` or the browser never
78
+ * fires `contextrestored`; while lost, draw calls are skipped. On restore we
79
+ * re-acquire the 2D context, re-apply the DPR scale, drop cached style, and
80
+ * notify the owner to repaint.
81
+ */
82
+ setupContextLossRecovery() {
83
+ if (typeof this.canvas.addEventListener !== "function") return;
84
+ this.canvas.addEventListener("contextlost", (e) => {
85
+ e.preventDefault();
86
+ this.contextLost = true;
87
+ });
88
+ this.canvas.addEventListener("contextrestored", () => {
89
+ const ctx = this.canvas.getContext("2d");
90
+ if (!ctx) return;
91
+ this.ctx = ctx;
92
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
93
+ ctx.scale(this.effectiveDPR(), this.effectiveDPR());
94
+ this._cachedFont = "";
95
+ this._cachedFill = "";
96
+ this.batchActive = false;
97
+ this.batchCount = 0;
98
+ this.contextLost = false;
99
+ _optionalChain([this, 'access', _3 => _3.contextRestoredCb, 'optionalCall', _4 => _4()]);
100
+ });
57
101
  }
58
102
  /**
59
103
  * Expose the underlying `CanvasRenderingContext2D` for operations not
@@ -87,8 +131,14 @@ var CanvasRenderer = (_class = class _CanvasRenderer {
87
131
  this.ctx.canvas.style.height = `${height}px`;
88
132
  this.ctx.scale(dpr, dpr);
89
133
  }
134
+ /** Whether the 2D context is currently lost (drawing is a no-op until it is
135
+ * restored). The owner skips its render pass while this is true. */
136
+ isContextLost() {
137
+ return this.contextLost;
138
+ }
90
139
  /** @inheritdoc */
91
140
  clear() {
141
+ if (this.contextLost) return;
92
142
  this.flush();
93
143
  this.ctx.clearRect(0, 0, this.width, this.height);
94
144
  }
@@ -325,39 +375,39 @@ function fontFamilyFromShorthand(font, sizeToken) {
325
375
  var SVGRenderer = (_class2 = class {
326
376
 
327
377
 
328
- __init7() {this.buffer = []}
329
- __init8() {this.defsBuffer = []}
330
- __init9() {this.currentPath = []}
378
+ __init9() {this.buffer = []}
379
+ __init10() {this.defsBuffer = []}
380
+ __init11() {this.currentPath = []}
331
381
  // Inline matrix states (3x3 representation)
332
382
  // [a, b, c, d, e, f] corresponding to:
333
383
  // | a c e |
334
384
  // | b d f |
335
385
  // | 0 0 1 |
336
- __init10() {this.mStack = []}
337
- __init11() {this.ma = 1}
338
- __init12() {this.mb = 0}
339
- __init13() {this.mc = 0}
340
- __init14() {this.md = 1}
341
- __init15() {this.me = 0}
342
- __init16() {this.mf = 0}
386
+ __init12() {this.mStack = []}
387
+ __init13() {this.ma = 1}
388
+ __init14() {this.mb = 0}
389
+ __init15() {this.mc = 0}
390
+ __init16() {this.md = 1}
391
+ __init17() {this.me = 0}
392
+ __init18() {this.mf = 0}
343
393
  // Alpha stack
344
- __init17() {this.alphaStack = []}
345
- __init18() {this.globalAlpha = 1}
394
+ __init19() {this.alphaStack = []}
395
+ __init20() {this.globalAlpha = 1}
346
396
  // Clipping stack
347
- __init19() {this.clipDepthStack = []}
348
- __init20() {this.clipDepth = 0}
349
- __init21() {this.clipCounter = 0}
397
+ __init21() {this.clipDepthStack = []}
398
+ __init22() {this.clipDepth = 0}
399
+ __init23() {this.clipCounter = 0}
350
400
  // uniquely identifies clipPaths
351
401
  // Batch circles states (local coordinates)
352
- __init22() {this.batchCircles = []}
353
- __init23() {this.batchMatrix = [1, 0, 0, 1, 0, 0]}
354
- __init24() {this.batchColor = ""}
355
- __init25() {this.batchAlpha = 1}
356
- __init26() {this.batchActive = false}
402
+ __init24() {this.batchCircles = []}
403
+ __init25() {this.batchMatrix = [1, 0, 0, 1, 0, 0]}
404
+ __init26() {this.batchColor = ""}
405
+ __init27() {this.batchAlpha = 1}
406
+ __init28() {this.batchActive = false}
357
407
  // Cache for generated gradient defs
358
- __init27() {this.gradientCounter = 0}
359
- __init28() {this.gradientCache = /* @__PURE__ */ new Map()}
360
- constructor(width, height) {;_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);_class2.prototype.__init14.call(this);_class2.prototype.__init15.call(this);_class2.prototype.__init16.call(this);_class2.prototype.__init17.call(this);_class2.prototype.__init18.call(this);_class2.prototype.__init19.call(this);_class2.prototype.__init20.call(this);_class2.prototype.__init21.call(this);_class2.prototype.__init22.call(this);_class2.prototype.__init23.call(this);_class2.prototype.__init24.call(this);_class2.prototype.__init25.call(this);_class2.prototype.__init26.call(this);_class2.prototype.__init27.call(this);_class2.prototype.__init28.call(this);
408
+ __init29() {this.gradientCounter = 0}
409
+ __init30() {this.gradientCache = /* @__PURE__ */ new Map()}
410
+ constructor(width, height) {;_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);_class2.prototype.__init14.call(this);_class2.prototype.__init15.call(this);_class2.prototype.__init16.call(this);_class2.prototype.__init17.call(this);_class2.prototype.__init18.call(this);_class2.prototype.__init19.call(this);_class2.prototype.__init20.call(this);_class2.prototype.__init21.call(this);_class2.prototype.__init22.call(this);_class2.prototype.__init23.call(this);_class2.prototype.__init24.call(this);_class2.prototype.__init25.call(this);_class2.prototype.__init26.call(this);_class2.prototype.__init27.call(this);_class2.prototype.__init28.call(this);_class2.prototype.__init29.call(this);_class2.prototype.__init30.call(this);
361
411
  this.width = width;
362
412
  this.height = height;
363
413
  }
@@ -581,8 +631,8 @@ var SVGRenderer = (_class2 = class {
581
631
  }
582
632
  drawImage(source, dx, dy, dw, dh) {
583
633
  this.flush();
584
- const fromCanvas2 = typeof _optionalChain([source, 'optionalAccess', _3 => _3.toDataURL]) === "function";
585
- const rawHref = fromCanvas2 ? source.toDataURL() : _optionalChain([source, 'optionalAccess', _4 => _4.src]) || "";
634
+ const fromCanvas2 = typeof _optionalChain([source, 'optionalAccess', _5 => _5.toDataURL]) === "function";
635
+ const rawHref = fromCanvas2 ? source.toDataURL() : _optionalChain([source, 'optionalAccess', _6 => _6.src]) || "";
586
636
  const href = fromCanvas2 && this.isSafeRasterDataUrl(rawHref) ? rawHref : sanitizeUrl(String(rawHref));
587
637
  const transformStr = `matrix(${this.ma},${this.mb},${this.mc},${this.md},${this.me},${this.mf})`;
588
638
  if (href) {
@@ -1501,11 +1551,11 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
1501
1551
  `;
1502
1552
  var WebGPUParticleSystemManager = (_class3 = class {
1503
1553
 
1504
- __init29() {this.computePipeline = null}
1505
- __init30() {this.renderPipeline = null}
1506
- __init31() {this.computeBindGroupLayout = null}
1507
- __init32() {this.renderBindGroupLayout = null}
1508
- constructor(device) {;_class3.prototype.__init29.call(this);_class3.prototype.__init30.call(this);_class3.prototype.__init31.call(this);_class3.prototype.__init32.call(this);
1554
+ __init31() {this.computePipeline = null}
1555
+ __init32() {this.renderPipeline = null}
1556
+ __init33() {this.computeBindGroupLayout = null}
1557
+ __init34() {this.renderBindGroupLayout = null}
1558
+ constructor(device) {;_class3.prototype.__init31.call(this);_class3.prototype.__init32.call(this);_class3.prototype.__init33.call(this);_class3.prototype.__init34.call(this);
1509
1559
  this.device = device;
1510
1560
  }
1511
1561
  initPipelines(format) {
@@ -1648,13 +1698,13 @@ var WebGPUParticleSystemManager = (_class3 = class {
1648
1698
 
1649
1699
  // src/renderer/TextRasterCache.ts
1650
1700
  var TextRasterCache = (_class4 = class {
1651
- __init33() {this.cache = /* @__PURE__ */ new Map()}
1701
+ __init35() {this.cache = /* @__PURE__ */ new Map()}
1652
1702
 
1653
1703
 
1654
- __init34() {this.scratchCtx = null}
1655
- __init35() {this._hits = 0}
1656
- __init36() {this._misses = 0}
1657
- constructor(options = {}) {;_class4.prototype.__init33.call(this);_class4.prototype.__init34.call(this);_class4.prototype.__init35.call(this);_class4.prototype.__init36.call(this);
1704
+ __init36() {this.scratchCtx = null}
1705
+ __init37() {this._hits = 0}
1706
+ __init38() {this._misses = 0}
1707
+ constructor(options = {}) {;_class4.prototype.__init35.call(this);_class4.prototype.__init36.call(this);_class4.prototype.__init37.call(this);_class4.prototype.__init38.call(this);
1658
1708
  this.maxEntries = Math.max(1, _nullishCoalesce(options.maxEntries, () => ( 4096)));
1659
1709
  this.dpr = Math.max(1, _nullishCoalesce(options.dpr, () => ( 1)));
1660
1710
  }
@@ -7,6 +7,14 @@ var CanvasRenderer = class _CanvasRenderer {
7
7
  ctx;
8
8
  width;
9
9
  height;
10
+ canvas;
11
+ /** True between a `contextlost` and its `contextrestored` — the 2D context is
12
+ * unusable, so draw calls are skipped until it comes back. Canvas2D context
13
+ * loss is rare (GPU reset / memory pressure) but a real browser event. */
14
+ contextLost = false;
15
+ /** Invoked after the context is restored + re-initialized, so the owner
16
+ * (`Scene`) can repaint the now-blank canvas. Set via {@link onContextRestored}. */
17
+ contextRestoredCb = null;
10
18
  /**
11
19
  * Cap on the effective device pixel ratio applied by the constructor and
12
20
  * {@link resize}. `undefined` (default) uses the real, uncapped
@@ -54,6 +62,40 @@ var CanvasRenderer = class _CanvasRenderer {
54
62
  const ctx = canvas.getContext("2d");
55
63
  this.ctx = ctx;
56
64
  if (ctx) ctx.scale(dpr, dpr);
65
+ this.canvas = canvas;
66
+ this.setupContextLossRecovery();
67
+ }
68
+ /** Register a callback fired after a lost 2D context is restored + re-scaled,
69
+ * so the owner can repaint (the restored canvas comes back cleared). */
70
+ onContextRestored(cb) {
71
+ this.contextRestoredCb = cb;
72
+ }
73
+ /**
74
+ * Handle Canvas2D context loss/restore (GPU reset, memory pressure). The
75
+ * `contextlost` handler MUST call `preventDefault()` or the browser never
76
+ * fires `contextrestored`; while lost, draw calls are skipped. On restore we
77
+ * re-acquire the 2D context, re-apply the DPR scale, drop cached style, and
78
+ * notify the owner to repaint.
79
+ */
80
+ setupContextLossRecovery() {
81
+ if (typeof this.canvas.addEventListener !== "function") return;
82
+ this.canvas.addEventListener("contextlost", (e) => {
83
+ e.preventDefault();
84
+ this.contextLost = true;
85
+ });
86
+ this.canvas.addEventListener("contextrestored", () => {
87
+ const ctx = this.canvas.getContext("2d");
88
+ if (!ctx) return;
89
+ this.ctx = ctx;
90
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
91
+ ctx.scale(this.effectiveDPR(), this.effectiveDPR());
92
+ this._cachedFont = "";
93
+ this._cachedFill = "";
94
+ this.batchActive = false;
95
+ this.batchCount = 0;
96
+ this.contextLost = false;
97
+ this.contextRestoredCb?.();
98
+ });
57
99
  }
58
100
  /**
59
101
  * Expose the underlying `CanvasRenderingContext2D` for operations not
@@ -87,8 +129,14 @@ var CanvasRenderer = class _CanvasRenderer {
87
129
  this.ctx.canvas.style.height = `${height}px`;
88
130
  this.ctx.scale(dpr, dpr);
89
131
  }
132
+ /** Whether the 2D context is currently lost (drawing is a no-op until it is
133
+ * restored). The owner skips its render pass while this is true. */
134
+ isContextLost() {
135
+ return this.contextLost;
136
+ }
90
137
  /** @inheritdoc */
91
138
  clear() {
139
+ if (this.contextLost) return;
92
140
  this.flush();
93
141
  this.ctx.clearRect(0, 0, this.width, this.height);
94
142
  }
package/dist/index.d.ts CHANGED
@@ -14,20 +14,12 @@ export * from './components/SplineEntity';
14
14
  export * from './components/Rect';
15
15
  export * from './components/Circle';
16
16
  export * from './components/Group';
17
- export * from './layout/LayoutEngine';
18
- export * from './layout/measure';
19
- export * from './text/MSDFFont';
20
- export * from './math/SpatialHashGrid';
21
- export * from './math/SpringPhysics';
22
- export * from './animation/easing';
23
- export * from './animation/drivers';
17
+ export * from '@vectojs/layout';
18
+ export * from '@vectojs/text';
19
+ export * from '@vectojs/math';
20
+ export * from '@vectojs/animation';
24
21
  export { MSDFTextEntity } from './text/MSDFTextEntity';
25
22
  export type { MSDFTextEntityOptions } from './text/MSDFTextEntity';
26
- export { LayoutWorkerManager } from './layout/LayoutWorkerManager';
27
23
  export { DOMPortalEntity } from './tree/DOMPortalEntity';
28
24
  export { SVGEntity } from './text/SVGEntity';
29
25
  export * from './tree/ComputeParticleEntity';
30
- export * from './text/ArabicShaper';
31
- export * from './text/BidiResolver';
32
- export * from './text/PreparedContentGrid';
33
- export * from './text/Typography';