takumi-paint 0.1.0 → 0.1.1

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/dist/export.cjs CHANGED
@@ -60,7 +60,7 @@ var Painter$1 = class {
60
60
  };
61
61
  if (Symbol.dispose) Painter$1.prototype[Symbol.dispose] = Painter$1.prototype.free;
62
62
  /**
63
- * A painted tree and the font files its runs use.
63
+ * A serialized tree, and the font files and run outlines it keeps in wasm memory.
64
64
  */
65
65
  var RenderedPaint = class RenderedPaint {
66
66
  static __wrap(ptr) {
@@ -94,13 +94,26 @@ var RenderedPaint = class RenderedPaint {
94
94
  return v1;
95
95
  }
96
96
  /**
97
+ * The SVG path data of run `run` of text node `node`.
98
+ * @param {number} node
99
+ * @param {number} run
100
+ * @returns {string | undefined}
101
+ */
102
+ runOutline(node, run) {
103
+ const ret = wasm.renderedpaint_runOutline(this.__wbg_ptr, node, run);
104
+ let v1;
105
+ if (ret[0] !== 0) {
106
+ v1 = getStringFromWasm0(ret[0], ret[1]);
107
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
108
+ }
109
+ return v1;
110
+ }
111
+ /**
97
112
  * The serialized tree.
98
113
  * @returns {RawPaintTree}
99
114
  */
100
115
  tree() {
101
- const ret = wasm.renderedpaint_tree(this.__wbg_ptr);
102
- if (ret[2]) throw takeFromExternrefTable0(ret[1]);
103
- return takeFromExternrefTable0(ret[0]);
116
+ return wasm.renderedpaint_tree(this.__wbg_ptr);
104
117
  }
105
118
  };
106
119
  if (Symbol.dispose) RenderedPaint.prototype[Symbol.dispose] = RenderedPaint.prototype.free;
@@ -514,16 +527,16 @@ var PaintTreeView = class {
514
527
  #raw;
515
528
  #listing;
516
529
  #steps;
517
- /** Wraps the serialized tree `raw`, reading font files through `fontData`. */
518
- constructor(raw, fontData) {
530
+ /** Wraps the serialized tree `raw`, reading font files and run outlines from `files`. */
531
+ constructor(raw, files) {
519
532
  this.#raw = raw;
520
533
  this.width = raw.width;
521
534
  this.height = raw.height;
522
535
  this.fonts = raw.fonts.map((font, index) => ({
523
536
  ...font,
524
- data: () => fontData(index) ?? /* @__PURE__ */ new Uint8Array()
537
+ data: () => files.fontData(index) ?? /* @__PURE__ */ new Uint8Array()
525
538
  }));
526
- this.#listing = new Listing(raw.nodes, this.fonts);
539
+ this.#listing = new Listing(raw.nodes, this.fonts, files);
527
540
  const root = this.#listing.at(0);
528
541
  if (root.type !== "box") throw new Error("The tree's root is not a box");
529
542
  this.root = root;
@@ -574,9 +587,11 @@ function inDocumentOrder(root) {
574
587
  /** The nodes as the serialized tree lists them, which is how nodes and steps name each other. */
575
588
  var Listing = class {
576
589
  fonts;
590
+ files;
577
591
  #nodes;
578
- constructor(raw, fonts) {
592
+ constructor(raw, fonts, files) {
579
593
  this.fonts = fonts;
594
+ this.files = files;
580
595
  this.#nodes = raw.map((node) => {
581
596
  switch (node.type) {
582
597
  case "box": return new BoxView(node, this);
@@ -681,7 +696,7 @@ var TextView = class extends NodeView {
681
696
  return this.raw.textAlign;
682
697
  }
683
698
  get runs() {
684
- this.#runs ??= this.raw.runs.map((run) => this.wrap(run));
699
+ this.#runs ??= this.raw.runs.map((run, index) => this.wrap(run, index));
685
700
  return this.#runs;
686
701
  }
687
702
  resolveRun(drawable) {
@@ -692,14 +707,14 @@ var TextView = class extends NodeView {
692
707
  run
693
708
  };
694
709
  }
695
- wrap(raw) {
696
- const { outline, font, ...fields } = raw;
710
+ wrap(raw, index) {
711
+ const { font, ...fields } = raw;
697
712
  const resolved = this.listing.fonts[font];
698
713
  if (!resolved) throw new Error(`The tree lists no font ${font}`);
699
714
  return {
700
715
  ...fields,
701
716
  font: resolved,
702
- outline: () => outline
717
+ outline: () => this.listing.files.runOutline(this.raw.id, index) ?? ""
703
718
  };
704
719
  }
705
720
  };
@@ -751,7 +766,7 @@ var Painter = class {
751
766
  images: resources.images,
752
767
  fontFamilies: resources.fontFamilies
753
768
  });
754
- return new PaintTreeView(painted.tree(), (index) => painted.fontData(index));
769
+ return new PaintTreeView(painted.tree(), painted);
755
770
  }
756
771
  /** Registers a font ahead of time, deduped against earlier registrations. */
757
772
  registerFont(font) {
package/dist/export.mjs CHANGED
@@ -56,7 +56,7 @@ var Painter$1 = class {
56
56
  };
57
57
  if (Symbol.dispose) Painter$1.prototype[Symbol.dispose] = Painter$1.prototype.free;
58
58
  /**
59
- * A painted tree and the font files its runs use.
59
+ * A serialized tree, and the font files and run outlines it keeps in wasm memory.
60
60
  */
61
61
  var RenderedPaint = class RenderedPaint {
62
62
  static __wrap(ptr) {
@@ -90,13 +90,26 @@ var RenderedPaint = class RenderedPaint {
90
90
  return v1;
91
91
  }
92
92
  /**
93
+ * The SVG path data of run `run` of text node `node`.
94
+ * @param {number} node
95
+ * @param {number} run
96
+ * @returns {string | undefined}
97
+ */
98
+ runOutline(node, run) {
99
+ const ret = wasm.renderedpaint_runOutline(this.__wbg_ptr, node, run);
100
+ let v1;
101
+ if (ret[0] !== 0) {
102
+ v1 = getStringFromWasm0(ret[0], ret[1]);
103
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
104
+ }
105
+ return v1;
106
+ }
107
+ /**
93
108
  * The serialized tree.
94
109
  * @returns {RawPaintTree}
95
110
  */
96
111
  tree() {
97
- const ret = wasm.renderedpaint_tree(this.__wbg_ptr);
98
- if (ret[2]) throw takeFromExternrefTable0(ret[1]);
99
- return takeFromExternrefTable0(ret[0]);
112
+ return wasm.renderedpaint_tree(this.__wbg_ptr);
100
113
  }
101
114
  };
102
115
  if (Symbol.dispose) RenderedPaint.prototype[Symbol.dispose] = RenderedPaint.prototype.free;
@@ -510,16 +523,16 @@ var PaintTreeView = class {
510
523
  #raw;
511
524
  #listing;
512
525
  #steps;
513
- /** Wraps the serialized tree `raw`, reading font files through `fontData`. */
514
- constructor(raw, fontData) {
526
+ /** Wraps the serialized tree `raw`, reading font files and run outlines from `files`. */
527
+ constructor(raw, files) {
515
528
  this.#raw = raw;
516
529
  this.width = raw.width;
517
530
  this.height = raw.height;
518
531
  this.fonts = raw.fonts.map((font, index) => ({
519
532
  ...font,
520
- data: () => fontData(index) ?? /* @__PURE__ */ new Uint8Array()
533
+ data: () => files.fontData(index) ?? /* @__PURE__ */ new Uint8Array()
521
534
  }));
522
- this.#listing = new Listing(raw.nodes, this.fonts);
535
+ this.#listing = new Listing(raw.nodes, this.fonts, files);
523
536
  const root = this.#listing.at(0);
524
537
  if (root.type !== "box") throw new Error("The tree's root is not a box");
525
538
  this.root = root;
@@ -570,9 +583,11 @@ function inDocumentOrder(root) {
570
583
  /** The nodes as the serialized tree lists them, which is how nodes and steps name each other. */
571
584
  var Listing = class {
572
585
  fonts;
586
+ files;
573
587
  #nodes;
574
- constructor(raw, fonts) {
588
+ constructor(raw, fonts, files) {
575
589
  this.fonts = fonts;
590
+ this.files = files;
576
591
  this.#nodes = raw.map((node) => {
577
592
  switch (node.type) {
578
593
  case "box": return new BoxView(node, this);
@@ -677,7 +692,7 @@ var TextView = class extends NodeView {
677
692
  return this.raw.textAlign;
678
693
  }
679
694
  get runs() {
680
- this.#runs ??= this.raw.runs.map((run) => this.wrap(run));
695
+ this.#runs ??= this.raw.runs.map((run, index) => this.wrap(run, index));
681
696
  return this.#runs;
682
697
  }
683
698
  resolveRun(drawable) {
@@ -688,14 +703,14 @@ var TextView = class extends NodeView {
688
703
  run
689
704
  };
690
705
  }
691
- wrap(raw) {
692
- const { outline, font, ...fields } = raw;
706
+ wrap(raw, index) {
707
+ const { font, ...fields } = raw;
693
708
  const resolved = this.listing.fonts[font];
694
709
  if (!resolved) throw new Error(`The tree lists no font ${font}`);
695
710
  return {
696
711
  ...fields,
697
712
  font: resolved,
698
- outline: () => outline
713
+ outline: () => this.listing.files.runOutline(this.raw.id, index) ?? ""
699
714
  };
700
715
  }
701
716
  };
@@ -747,7 +762,7 @@ var Painter = class {
747
762
  images: resources.images,
748
763
  fontFamilies: resources.fontFamilies
749
764
  });
750
- return new PaintTreeView(painted.tree(), (index) => painted.fontData(index));
765
+ return new PaintTreeView(painted.tree(), painted);
751
766
  }
752
767
  /** Registers a font ahead of time, deduped against earlier registrations. */
753
768
  registerFont(font) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "takumi-paint",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Turn JSX, HTML, and CSS into a paint tree: shapes, paints, text runs, and images with every CSS value resolved.",
5
5
  "keywords": [
6
6
  "css",
@@ -131,7 +131,7 @@
131
131
  "publish-lint": "attw --pack . && publint --strict ."
132
132
  },
133
133
  "dependencies": {
134
- "@takumi-rs/helpers": "2.15.0"
134
+ "@takumi-rs/helpers": "2.15.1"
135
135
  },
136
136
  "devDependencies": {
137
137
  "@types/bun": "^1.4.1",
Binary file
@@ -7,7 +7,8 @@ export const painter_new: () => [number, number, number];
7
7
  export const painter_paint: (a: number, b: any, c: number) => [number, number, number];
8
8
  export const painter_registerFont: (a: number, b: any) => [number, number, number];
9
9
  export const renderedpaint_fontData: (a: number, b: number) => [number, number];
10
- export const renderedpaint_tree: (a: number) => [number, number, number];
10
+ export const renderedpaint_runOutline: (a: number, b: number, c: number) => [number, number];
11
+ export const renderedpaint_tree: (a: number) => any;
11
12
  export const __wbindgen_malloc: (a: number, b: number) => number;
12
13
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
13
14
  export const __wbindgen_exn_store: (a: number) => void;