@strategicprojects/rpic 0.6.2 → 0.7.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/README.md CHANGED
@@ -9,7 +9,7 @@ import * as rpic from '@strategicprojects/rpic';
9
9
 
10
10
  await rpic.ready(); // browser: wasm fetched automatically
11
11
 
12
- const { svg, animations, diagnostics, warnings } = rpic.compile('box "A"; arrow; box "B"');
12
+ const { svg, animations, diagnostics, warnings, objects } = rpic.compile('box "A"; arrow; box "B"');
13
13
  document.querySelector('#stage').innerHTML = svg;
14
14
 
15
15
  // animate with GSAP:
@@ -52,7 +52,7 @@ first build. In Node, pass the math artifact's bytes:
52
52
  | Function | Description |
53
53
  |----------|-------------|
54
54
  | `ready(wasmInput?, {math?})` | Initialize WASM. Browser: no arg. Node: pass `.wasm` bytes/URL. `math: true` loads the math-enabled build; conflicting later calls reject. |
55
- | `compile(src, {circuits?, texlabels?})` | → `{ svg, animations, diagnostics, warnings }` (throws on a pic error with `errorInfo`). |
55
+ | `compile(src, {circuits?, texlabels?})` | → `{ svg, animations, diagnostics, warnings, objects }` (throws on a pic error with `errorInfo`). |
56
56
  | `renderSvg(src, {circuits?, texlabels?})` | → SVG string. |
57
57
  | `animate(root, animations, gsap)` | Build/play a GSAP timeline (`draw`/`fade`/`pop`). Browser only. |
58
58
 
package/index.d.ts CHANGED
@@ -26,6 +26,22 @@ export interface Diagnostic {
26
26
  hint: string | null;
27
27
  }
28
28
 
29
+ export interface ObjectGeometry {
30
+ /** matches the shape's `<g id="sN">` group in the SVG */
31
+ id: string;
32
+ /** "box" | "circle" | "ellipse" | "path" | "spline" | "arc" | "brace" | "text" */
33
+ kind: string;
34
+ /** bounds in SVG user units (the viewBox space); `null` for invisible shapes */
35
+ bbox: { x: number; y: number; w: number; h: number } | null;
36
+ /** 1-based source position of the statement that drew it, when known */
37
+ line?: number;
38
+ col?: number;
39
+ /** exclusive end column of the statement's leading token */
40
+ end_col?: number;
41
+ /** absent = your own input; a `copy` include name or `"circuits"` otherwise */
42
+ file?: string;
43
+ }
44
+
29
45
  export interface Bundle {
30
46
  svg: string;
31
47
  animations: Anim[];
@@ -33,6 +49,8 @@ export interface Bundle {
33
49
  diagnostics: string[];
34
50
  /** non-fatal compiler warnings for accepted but suspicious input */
35
51
  warnings: Diagnostic[];
52
+ /** per-object geometry, index-aligned with the `<g id="sN">` groups */
53
+ objects: ObjectGeometry[];
36
54
  }
37
55
 
38
56
  export interface CompileError extends Error {
@@ -75,7 +93,7 @@ export function ready(
75
93
  opts?: ReadyOptions
76
94
  ): Promise<void>;
77
95
 
78
- /** Compile pic source into `{ svg, animations, diagnostics, warnings }`. Throws on a pic error. */
96
+ /** Compile pic source into `{ svg, animations, diagnostics, warnings, objects }`. Throws on a pic error. */
79
97
  export function compile(src: string, opts?: CompileOptions): Bundle;
80
98
 
81
99
  /** Compile and return only the SVG string. */
package/index.js CHANGED
@@ -63,7 +63,7 @@ function ensure() {
63
63
  }
64
64
 
65
65
  /**
66
- * Compile pic source into `{ svg, animations, diagnostics, warnings }` (throws on a pic error).
66
+ * Compile pic source into `{ svg, animations, diagnostics, warnings, objects }` (throws on a pic error).
67
67
  * @param {string} src
68
68
  * @param {{circuits?: boolean, texlabels?: boolean}} [opts]
69
69
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strategicprojects/rpic",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "The pic graphics language compiled to SVG with animation manifests, via WebAssembly. Browser + Node.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
Binary file
Binary file