@fulate/core 2.0.11 → 3.0.2

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/index.d.ts CHANGED
@@ -40,3 +40,5 @@ export { VectorPath, VectorPathProperties, VectorPathTransform } from "./node/ve
40
40
  export type { VectorPathOption } from "./node/vector-path";
41
41
  export { createVectorPathGeometry, appendAuthoredLineAnchor, insertAuthoredPathAnchor, removeAuthoredAnchor, replaceAuthoredAnchorPoint, replaceAuthoredCubicHandle, transformAuthoredSubpath, getAuthoredAnchorBounds } from "./geometry/path";
42
42
  export type { VectorPathCommand, VectorPathGeometry } from "./geometry/path";
43
+ export { coreElementV2Codecs, encodeElement, decodeElement, decodeCopiedElements } from "./serialization";
44
+ export type { ElementV2, EncodeContext, ElementV2Codec, ElementV2Codecs } from "./serialization";
package/dist/index.js CHANGED
@@ -7588,4 +7588,50 @@ var VectorPath = class extends Shape {
7588
7588
  }
7589
7589
  };
7590
7590
  //#endregion
7591
- export { ChangeImpact, CustomEvent, EVENT_NAMES, Element, ElementProperties, ElementTransform, EventEmitter, EventPhase, FrameStabilizationError, Layer, LayerProperties, Node, NodeLifecycleEvent, NodeProperties, PaintContext, Root, RootFrameRuntime, RootInputController, SKIN_DEFAULTS, SceneRegistry, Shape, ShapeProperties, ShapeTransform, Skin, TransformProperties, VectorPath, VectorPathProperties, VectorPathTransform, Viewport, appendAuthoredLineAnchor, captureElementTransformReference, createAuthoredLineSubpath, createGeometryQuery, createGeometrySnapshot, createLineSubpath, createPathLocalId, createVectorPathGeometry, diffChildren, evaluatePathSegmentPoint, generateNodeKey, getAuthoredAnchorBounds, getAuthoredPathLayoutBounds, getElementConnectionPort, getElementConnectionPortPoint, getElementConnectionPortPoints, insertAuthoredPathAnchor, isFormControlTarget, isReparentTransformIntent, mergeOwnerPropertyChanges, parseEventOptionKey, projectConnectionPortPoint, removeAuthoredAnchor, replaceAuthoredAnchorPoint, replaceAuthoredCubicHandle, resolveAuthoredGeometryFramePatch, resolveAuthoredSubpath, resolveOrigin, resolveReferenceBoundsTranslation, resolveReferenceTransform, resolveReferenceTransformTarget, splitPathSegment, transformAuthoredSubpath };
7591
+ //#region packages/core/src/serialization.ts
7592
+ function codec(Constructor) {
7593
+ return {
7594
+ encode: (element) => element.toJSON(),
7595
+ decode: ({ type, ...properties }) => new Constructor(properties)
7596
+ };
7597
+ }
7598
+ function createCodecs() {
7599
+ return new Map([
7600
+ ["element", codec(Element)],
7601
+ ["shape", codec(Shape)],
7602
+ ["layer", codec(Layer)],
7603
+ ["vectorPath", codec(VectorPath)]
7604
+ ]);
7605
+ }
7606
+ /** Core-owned payload codecs; compose UI and application types at the caller. */
7607
+ var coreElementV2Codecs = /* @__PURE__ */ createCodecs();
7608
+ /** The sole owner of persistent child recursion. */
7609
+ function encodeElement(element, codecs, context) {
7610
+ const data = codecs.get(element.type).encode(element, context);
7611
+ const children = element.getPersistentChildren();
7612
+ if (children.length) data.children = children.map((child) => encodeElement(child, codecs, context));
7613
+ return data;
7614
+ }
7615
+ /** Restore a persistent tree with the supplied codecs, retaining keys unless a copy map is supplied. */
7616
+ function decodeElement(data, codecs, keyMap) {
7617
+ const { children, ...payload } = data;
7618
+ if (keyMap) payload.key = keyMap.get(data.key);
7619
+ const element = codecs.get(payload.type).decode(payload, keyMap);
7620
+ if (children) element.replaceChildren(...children.map((child) => decodeElement(child, codecs, keyMap)));
7621
+ return element;
7622
+ }
7623
+ /** Adopt a copied DTO graph, generate new element keys, and preserve owner-local IDs. */
7624
+ function decodeCopiedElements(data, codecs) {
7625
+ const keyMap = /* @__PURE__ */ new Map();
7626
+ const allocate = (entry) => {
7627
+ keyMap.set(entry.key, generateNodeKey());
7628
+ entry.children?.forEach(allocate);
7629
+ };
7630
+ data.forEach(allocate);
7631
+ return {
7632
+ elements: data.map((entry) => decodeElement(entry, codecs, keyMap)),
7633
+ keyMap
7634
+ };
7635
+ }
7636
+ //#endregion
7637
+ export { ChangeImpact, CustomEvent, EVENT_NAMES, Element, ElementProperties, ElementTransform, EventEmitter, EventPhase, FrameStabilizationError, Layer, LayerProperties, Node, NodeLifecycleEvent, NodeProperties, PaintContext, Root, RootFrameRuntime, RootInputController, SKIN_DEFAULTS, SceneRegistry, Shape, ShapeProperties, ShapeTransform, Skin, TransformProperties, VectorPath, VectorPathProperties, VectorPathTransform, Viewport, appendAuthoredLineAnchor, captureElementTransformReference, coreElementV2Codecs, createAuthoredLineSubpath, createGeometryQuery, createGeometrySnapshot, createLineSubpath, createPathLocalId, createVectorPathGeometry, decodeCopiedElements, decodeElement, diffChildren, encodeElement, evaluatePathSegmentPoint, generateNodeKey, getAuthoredAnchorBounds, getAuthoredPathLayoutBounds, getElementConnectionPort, getElementConnectionPortPoint, getElementConnectionPortPoints, insertAuthoredPathAnchor, isFormControlTarget, isReparentTransformIntent, mergeOwnerPropertyChanges, parseEventOptionKey, projectConnectionPortPoint, removeAuthoredAnchor, replaceAuthoredAnchorPoint, replaceAuthoredCubicHandle, resolveAuthoredGeometryFramePatch, resolveAuthoredSubpath, resolveOrigin, resolveReferenceBoundsTranslation, resolveReferenceTransform, resolveReferenceTransformTarget, splitPathSegment, transformAuthoredSubpath };
@@ -0,0 +1,30 @@
1
+ import { Element, type ElementPayload } from "./node/element";
2
+ /** Persisted data contains canonical authored values, never creation intents. */
3
+ export interface ElementV2 extends ElementPayload {
4
+ children?: ElementV2[];
5
+ }
6
+ /** Copy boundary metadata shared with each payload encoder. */
7
+ export interface EncodeContext {
8
+ /** Present for copying a subgraph: external relations become free endpoints. */
9
+ readonly sourceKeys: ReadonlySet<string>;
10
+ }
11
+ /** Encodes and constructs one element payload; Core owns child recursion. */
12
+ export interface ElementV2Codec {
13
+ /** Return independent authored payload data, excluding children and runtime state. */
14
+ encode(element: Element, context?: EncodeContext): ElementPayload;
15
+ /** Adopt canonical payload values, remapping cross-element references when copying. */
16
+ decode(data: ElementPayload, keyMap?: ReadonlyMap<string, string>): Element;
17
+ }
18
+ /** Exact element type to codec mapping shared by file and Clipboard callers. */
19
+ export type ElementV2Codecs = ReadonlyMap<string, ElementV2Codec>;
20
+ /** Core-owned payload codecs; compose UI and application types at the caller. */
21
+ export declare const coreElementV2Codecs: ElementV2Codecs;
22
+ /** The sole owner of persistent child recursion. */
23
+ export declare function encodeElement(element: Element, codecs: ElementV2Codecs, context?: EncodeContext): ElementV2;
24
+ /** Restore a persistent tree with the supplied codecs, retaining keys unless a copy map is supplied. */
25
+ export declare function decodeElement(data: ElementV2, codecs: ElementV2Codecs, keyMap?: ReadonlyMap<string, string>): Element;
26
+ /** Adopt a copied DTO graph, generate new element keys, and preserve owner-local IDs. */
27
+ export declare function decodeCopiedElements(data: readonly ElementV2[], codecs: ElementV2Codecs): {
28
+ elements: Element<import(".").ElementProperties, import(".").BaseElementOption<any>, Partial<Omit<import(".").BaseElementOption<any>, "key" | "children">>, Partial<Omit<import(".").BaseElementOption<any>, "key" | "children">>>[];
29
+ keyMap: Map<string, string>;
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fulate/core",
3
- "version": "2.0.11",
3
+ "version": "3.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "test:watch": "vitest --config vitest.config.ts"
20
20
  },
21
21
  "dependencies": {
22
- "@fulate/share": "2.0.11",
22
+ "@fulate/share": "3.0.2",
23
23
  "@tweenjs/tween.js": "^25.0.0",
24
24
  "lodash-es": "^4.17.22",
25
25
  "rbush": "^4.0.1"