@vectojs/core 0.1.0 → 0.2.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.
Files changed (46) hide show
  1. package/dist/animation/drivers.d.ts +48 -0
  2. package/dist/animation/easing.d.ts +16 -0
  3. package/dist/{chunk-M2IZPGOL.mjs → chunk-H3QIE77O.mjs} +316 -12
  4. package/dist/{chunk-53DAQC3U.js → chunk-LA3FJLP2.js} +369 -65
  5. package/dist/components/GridTextEntity.d.ts +15 -0
  6. package/dist/components/SplineEntity.d.ts +144 -0
  7. package/dist/components/TextEntity.d.ts +35 -0
  8. package/dist/index.d.ts +26 -577
  9. package/dist/index.js +121 -136
  10. package/dist/index.mjs +19 -34
  11. package/dist/{layout.d.mts → layout/LayoutEngine.d.ts} +15 -70
  12. package/dist/layout/LayoutWorker.d.ts +23 -0
  13. package/dist/layout/LayoutWorkerManager.d.ts +22 -0
  14. package/dist/layout/LayoutWorkerSource.d.ts +1 -0
  15. package/dist/layout/index.d.ts +3 -0
  16. package/dist/layout/measure.d.ts +20 -0
  17. package/dist/math/SpatialHashGrid.d.ts +53 -0
  18. package/dist/math/SpringPhysics.d.ts +13 -0
  19. package/dist/renderer/CanvasRenderer.d.ts +81 -0
  20. package/dist/renderer/IRenderer.d.ts +178 -0
  21. package/dist/renderer/SVGRenderer.d.ts +69 -0
  22. package/dist/renderer/WebGLPointRenderer.d.ts +62 -0
  23. package/dist/renderer/WebGPUParticleSystemManager.d.ts +14 -0
  24. package/dist/renderer/colorParse.d.ts +17 -0
  25. package/dist/renderer/index.d.ts +6 -0
  26. package/dist/text/ArabicShaper.d.ts +10 -0
  27. package/dist/text/BidiResolver.d.ts +6 -0
  28. package/dist/{text.d.ts → text/MSDFFont.d.ts} +10 -82
  29. package/dist/text/MSDFTextEntity.d.ts +30 -0
  30. package/dist/text/SVGEntity.d.ts +22 -0
  31. package/dist/text/index.d.ts +5 -0
  32. package/dist/text.js +2 -2
  33. package/dist/text.mjs +1 -1
  34. package/dist/tree/ComputeParticleEntity.d.ts +118 -0
  35. package/dist/tree/DOMPortalEntity.d.ts +18 -0
  36. package/dist/{Entity-D-rfAFCf.d.mts → tree/Entity.d.ts} +71 -201
  37. package/dist/tree/Scene.d.ts +302 -0
  38. package/package.json +5 -5
  39. package/dist/Entity-D-rfAFCf.d.ts +0 -572
  40. package/dist/index-ByBDSmMK.d.mts +0 -365
  41. package/dist/index-C3Fd_XmG.d.ts +0 -365
  42. package/dist/index.d.mts +0 -577
  43. package/dist/layout.d.ts +0 -319
  44. package/dist/renderer.d.mts +0 -2
  45. package/dist/renderer.d.ts +0 -2
  46. package/dist/text.d.mts +0 -201
@@ -0,0 +1,144 @@
1
+ import { Bounds, Entity } from '../tree/Entity';
2
+ import { IRenderer } from '../renderer/IRenderer';
3
+ /** One piecewise-cubic segment: x(t) and y(t) as `[a,b,c,d]` polynomial coefficients. */
4
+ export interface SplineSegment {
5
+ start_t: number;
6
+ end_t: number;
7
+ x_poly: number[];
8
+ y_poly: number[];
9
+ }
10
+ /**
11
+ * Color of a spline equation: an `[r,g,b]` triple in `0..1`, a linear-gradient
12
+ * descriptor, or `null` (use the entity's default color).
13
+ */
14
+ export type SplineColor = [number, number, number] | {
15
+ stops: [number, [number, number, number]][];
16
+ start_pos: [number, number];
17
+ end_pos: [number, number];
18
+ } | null;
19
+ /** A single curve (one stroke color) made of consecutive {@link SplineSegment}s. */
20
+ export interface SplineEquation {
21
+ color_rgb: SplineColor;
22
+ data: SplineSegment[];
23
+ }
24
+ /** The native vectomancy `Spline` document. */
25
+ export interface SplineDocument {
26
+ type: 'Spline' | 'Polyline';
27
+ equations?: SplineEquation[];
28
+ paths?: {
29
+ color_rgb: SplineColor;
30
+ data: {
31
+ x: number;
32
+ y: number;
33
+ }[];
34
+ }[];
35
+ bounding_box?: [number, number, number, number];
36
+ }
37
+ /** Construction options for {@link SplineEntity}. */
38
+ export interface SplineOptions {
39
+ /** Stroke width in local units. Default `2`. */
40
+ lineWidth?: number;
41
+ /** Bake to an OffscreenCanvas once and `drawImage` each frame. Default `true`. */
42
+ cache?: boolean;
43
+ /** Color used when an equation's `color_rgb` is `null`. Default `#e2e8f0`. */
44
+ defaultColor?: string;
45
+ /**
46
+ * Hit-test strategy:
47
+ * - `'curve'` (default): precise — a point hits only within `lineWidth/2 +
48
+ * hitTolerance` of an actual curve.
49
+ * - `'aabb'`: coarse — anywhere in the bounding box hits.
50
+ */
51
+ hitTest?: 'curve' | 'aabb';
52
+ /** Extra pick padding (local units) added to `lineWidth/2` in `'curve'` mode. Default `0`. */
53
+ hitTolerance?: number;
54
+ }
55
+ /** Cubic Bézier control points produced from a {@link SplineSegment}. */
56
+ export interface BezierControlPoints {
57
+ x0: number;
58
+ y0: number;
59
+ cp1x: number;
60
+ cp1y: number;
61
+ cp2x: number;
62
+ cp2y: number;
63
+ x3: number;
64
+ y3: number;
65
+ }
66
+ /**
67
+ * Convert one cubic-polynomial segment to Bézier control points.
68
+ *
69
+ * For a coefficient vector `[a,b,c,d]` describing `f(t)=a+bt+ct²+dt³` on `t∈[0,1]`,
70
+ * the equivalent Bézier control values are `a`, `a+b/3`, `a+2b/3+c/3`, `a+b+c+d`.
71
+ * Applied independently to the x and y polynomials.
72
+ *
73
+ * @param seg - The polynomial segment.
74
+ * @returns The cubic Bézier control points.
75
+ */
76
+ export declare function polySegmentToBezier(seg: SplineSegment): BezierControlPoints;
77
+ /**
78
+ * Renders a native vectomancy `Spline` document (piecewise-cubic curves) to canvas.
79
+ *
80
+ * Bounds come from the document's `bounding_box` (or are computed from segment
81
+ * endpoints), so the entity participates in {@link Scene} viewport culling. By
82
+ * default the curves are baked once into an `OffscreenCanvas` and blitted each
83
+ * frame; without `OffscreenCanvas` it strokes the Bézier paths per frame.
84
+ *
85
+ * @example
86
+ * const doc = await loadSpline('/ast/logo.json');
87
+ * scene.add(new SplineEntity(doc).setPosition(100, 100));
88
+ */
89
+ export declare class SplineEntity extends Entity {
90
+ doc: SplineDocument;
91
+ lineWidth: number;
92
+ defaultColor: string;
93
+ hitTolerance: number;
94
+ private cache;
95
+ private hitMode;
96
+ private bounds;
97
+ private offscreen;
98
+ private baked;
99
+ /** Lazily-flattened polylines (one Float32Array of [x,y,...] per segment) for hit-testing. */
100
+ private polylines;
101
+ /**
102
+ * When `true`, the renderer draws a rounded-rect outline of the entity's
103
+ * local bounds after painting the curves. Useful for drag feedback and
104
+ * debugging hit areas. Defaults to `false`.
105
+ */
106
+ showBounds: boolean;
107
+ constructor(doc: SplineDocument, opts?: SplineOptions);
108
+ private computeBounds;
109
+ /** @inheritdoc */
110
+ getBounds(): Bounds;
111
+ /**
112
+ * AABB hit-test against the document bounds in world space.
113
+ *
114
+ * Curve-accurate hit-testing can be layered on later via {@link hitTestCurve};
115
+ * this method already calls it as a refinement when it is overridden.
116
+ */
117
+ isPointInside(globalX: number, globalY: number): boolean;
118
+ /**
119
+ * Curve-accurate refinement of {@link isPointInside}: hit only when the local
120
+ * point lies within `lineWidth/2 + hitTolerance` of an actual curve.
121
+ *
122
+ * Returns `null` in `hitTest: 'aabb'` mode (keep the bounding-box result).
123
+ * Curves are flattened to polylines once and cached. Override for custom logic.
124
+ *
125
+ * @param localX - X in the entity's local space.
126
+ * @param localY - Y in the entity's local space.
127
+ * @returns `true`/`false`, or `null` to keep the AABB result.
128
+ */
129
+ protected hitTestCurve(localX: number, localY: number): boolean | null;
130
+ /** Flatten every Bézier segment into a sampled polyline once, then cache. */
131
+ private getPolylines;
132
+ private resolveColor;
133
+ private strokeEquations;
134
+ /** Bake all equations into an OffscreenCanvas once (when available). */
135
+ private bake;
136
+ render(r: IRenderer): void;
137
+ }
138
+ /**
139
+ * Fetch and parse a vectomancy `Spline` JSON document (browser only).
140
+ *
141
+ * @param url - URL of the `.json` spline document.
142
+ * @returns The parsed {@link SplineDocument}.
143
+ */
144
+ export declare function loadSpline(url: string): Promise<SplineDocument>;
@@ -0,0 +1,35 @@
1
+ import { Entity } from '../tree/Entity';
2
+ import { IRenderer } from '../renderer/IRenderer';
3
+ export declare class TextEntity extends Entity {
4
+ text: string;
5
+ private atlas;
6
+ private layout;
7
+ private prepared;
8
+ private nodes;
9
+ fontSize: number;
10
+ fillStyle: string | any;
11
+ strokeStyle: string | any;
12
+ hoveredFillStyle: string | any;
13
+ lineWidth: number;
14
+ private isHovered;
15
+ constructor(text: string, atlas: any, maxWidth: number, fontSize?: number);
16
+ /**
17
+ * Replace the text content. Runs the **cold** measurement pass (re-segment +
18
+ * re-measure) since the glyphs changed, then re-lays out.
19
+ *
20
+ * @returns `this` for chaining.
21
+ */
22
+ setText(text: string): this;
23
+ /**
24
+ * Change the wrap width and reflow. Cheap **hot** path only — reuses the
25
+ * cached {@link PreparedText}, doing no re-segmentation or re-measurement.
26
+ * Ideal for responsive resize.
27
+ *
28
+ * @returns `this` for chaining.
29
+ */
30
+ setMaxWidth(maxWidth: number): this;
31
+ /** Hot pass: place the cached {@link PreparedText} and refresh the a11y box. */
32
+ private applyLayout;
33
+ isPointInside(globalX: number, globalY: number): boolean;
34
+ render(renderer: IRenderer): void;
35
+ }