@pygmalionjs/pygmalion 0.8.1 → 0.10.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 (150) hide show
  1. package/README.md +34 -0
  2. package/binding-source.d.ts +25 -0
  3. package/dist-lib/{CameraLayer-B2D29VXQ.js → CameraLayer-BUOlJcUa.js} +17 -17
  4. package/dist-lib/pygmalion.js +24524 -12555
  5. package/dist-lib/{runtime-BAy8W1mJ.js → runtime-BOfDlGPR.js} +12438 -11118
  6. package/dist-lib/style.css +1 -1
  7. package/dist-lib/testing.js +19 -19
  8. package/dist-lib/types/binding/catalog.d.ts +10 -0
  9. package/dist-lib/types/binding/contracts.d.ts +202 -0
  10. package/dist-lib/types/binding/documentCommands.d.ts +38 -0
  11. package/dist-lib/types/binding/duplicateMetadata.d.ts +8 -0
  12. package/dist-lib/types/binding/index.d.ts +7 -0
  13. package/dist-lib/types/binding/preview.d.ts +37 -0
  14. package/dist-lib/types/binding/source.d.ts +109 -0
  15. package/dist-lib/types/binding/useDataProjection.d.ts +9 -0
  16. package/dist-lib/types/binding/validate.d.ts +8 -0
  17. package/dist-lib/types/core/runtime.d.ts +6 -0
  18. package/dist-lib/types/document/appearance.d.ts +112 -0
  19. package/dist-lib/types/document/assets.d.ts +204 -0
  20. package/dist-lib/types/document/components.d.ts +169 -0
  21. package/dist-lib/types/document/contracts.d.ts +171 -0
  22. package/dist-lib/types/document/engine.d.ts +20 -0
  23. package/dist-lib/types/document/exportSettings.d.ts +45 -0
  24. package/dist-lib/types/document/geometry.d.ts +11 -0
  25. package/dist-lib/types/document/layout.d.ts +53 -0
  26. package/dist-lib/types/document/prototype.d.ts +424 -0
  27. package/dist-lib/types/document/prototypeReferences.d.ts +3 -0
  28. package/dist-lib/types/document/richText.d.ts +185 -0
  29. package/dist-lib/types/document/styles.d.ts +216 -0
  30. package/dist-lib/types/document/svgImport.d.ts +17 -0
  31. package/dist-lib/types/document/vector.d.ts +222 -0
  32. package/dist-lib/types/editor/designCompiler.d.ts +7 -0
  33. package/dist-lib/types/editor/designImport.d.ts +7 -0
  34. package/dist-lib/types/editor/inspect.d.ts +8 -0
  35. package/dist-lib/types/editor/revisionCatalogInstall.d.ts +1 -1
  36. package/dist-lib/types/editor/screenInteractions.d.ts +3 -3
  37. package/dist-lib/types/editor/store.d.ts +1 -1
  38. package/dist-lib/types/host/project.d.ts +44 -0
  39. package/dist-lib/types/host/registryConnections.d.ts +11 -0
  40. package/dist-lib/types/host/sourceFilePlan.d.ts +15 -0
  41. package/dist-lib/types/host/sourceWriteback.d.ts +50 -0
  42. package/dist-lib/types/lib.d.ts +103 -3
  43. package/dist-lib/types/token-library/bindings.d.ts +62 -0
  44. package/dist-lib/types/token-library/contracts.d.ts +117 -0
  45. package/dist-lib/types/token-library/engine.d.ts +13 -0
  46. package/dist-lib/types/token-library/valueResolver.d.ts +19 -0
  47. package/dist-lib/types/workspace/WorkspaceShell.d.ts +9 -0
  48. package/dist-lib/types/workspace/application/ApplicationWorkspace.d.ts +3 -0
  49. package/dist-lib/types/workspace/configuration.d.ts +47 -0
  50. package/dist-lib/types/workspace/contracts.d.ts +64 -0
  51. package/dist-lib/types/workspace/controller.d.ts +35 -0
  52. package/dist-lib/types/workspace/documentSessions.d.ts +42 -0
  53. package/dist-lib/types/workspace/edit/AppearancePanel.d.ts +23 -0
  54. package/dist-lib/types/workspace/edit/ArrangeLayers.d.ts +10 -0
  55. package/dist-lib/types/workspace/edit/AssetsPanel.d.ts +16 -0
  56. package/dist-lib/types/workspace/edit/CanvasGuides.d.ts +19 -0
  57. package/dist-lib/types/workspace/edit/ComponentPanel.d.ts +11 -0
  58. package/dist-lib/types/workspace/edit/DataPanel.d.ts +16 -0
  59. package/dist-lib/types/workspace/edit/DesignWorkspace.d.ts +10 -0
  60. package/dist-lib/types/workspace/edit/LayerTree.d.ts +14 -0
  61. package/dist-lib/types/workspace/edit/LayoutPanel.d.ts +13 -0
  62. package/dist-lib/types/workspace/edit/PrototypePanel.d.ts +12 -0
  63. package/dist-lib/types/workspace/edit/ScopeTransferDialog.d.ts +40 -0
  64. package/dist-lib/types/workspace/edit/SelectionHandles.d.ts +52 -0
  65. package/dist-lib/types/workspace/edit/StylesPanel.d.ts +8 -0
  66. package/dist-lib/types/workspace/edit/TextEditor.d.ts +50 -0
  67. package/dist-lib/types/workspace/edit/VectorEditor.d.ts +89 -0
  68. package/dist-lib/types/workspace/edit/VectorToolbar.d.ts +5 -0
  69. package/dist-lib/types/workspace/edit/canvasGuideModel.d.ts +102 -0
  70. package/dist-lib/types/workspace/edit/clipboard.d.ts +35 -0
  71. package/dist-lib/types/workspace/edit/duplicateMetadata.d.ts +2 -0
  72. package/dist-lib/types/workspace/edit/geometryHandles.d.ts +224 -0
  73. package/dist-lib/types/workspace/edit/layerArrangement.d.ts +39 -0
  74. package/dist-lib/types/workspace/edit/layerMoves.d.ts +44 -0
  75. package/dist-lib/types/workspace/edit/projection.d.ts +12 -0
  76. package/dist-lib/types/workspace/edit/scopeTransfer.d.ts +96 -0
  77. package/dist-lib/types/workspace/edit/textStyles.d.ts +75 -0
  78. package/dist-lib/types/workspace/edit/vectorTools.d.ts +136 -0
  79. package/dist-lib/types/workspace/legacyModeAdapter.d.ts +13 -0
  80. package/dist-lib/types/workspace/source/ResponsiveLayoutPanel.d.ts +20 -0
  81. package/dist-lib/types/workspace/source/SourceReview.d.ts +11 -0
  82. package/dist-lib/types/workspace/source/appearanceSource.d.ts +19 -0
  83. package/dist-lib/types/workspace/source/compiler.d.ts +5 -0
  84. package/dist-lib/types/workspace/source/contracts.d.ts +156 -0
  85. package/dist-lib/types/workspace/source/controller.d.ts +50 -0
  86. package/dist-lib/types/workspace/source/documentRevision.d.ts +2 -0
  87. package/dist-lib/types/workspace/source/draftPreviewClient.d.ts +13 -0
  88. package/dist-lib/types/workspace/source/draftRecipe.d.ts +30 -0
  89. package/dist-lib/types/workspace/source/flowContracts.d.ts +72 -0
  90. package/dist-lib/types/workspace/source/prototypeSource.d.ts +4 -0
  91. package/dist-lib/types/workspace/source/responsive.d.ts +13 -0
  92. package/dist-lib/types/workspace/source/responsiveContracts.d.ts +78 -0
  93. package/dist-lib/types/workspace/source/structure.d.ts +21 -0
  94. package/dist-lib/types/workspace/source/textSource.d.ts +28 -0
  95. package/dist-lib/types/workspace/tokens/TokenLibraryContext.d.ts +11 -0
  96. package/dist-lib/types/workspace/tokens/TokenLibraryWorkspace.d.ts +14 -0
  97. package/dist-lib/types/workspace/tokens/contracts.d.ts +74 -0
  98. package/dist-lib/types/workspace/tokens/controller.d.ts +44 -0
  99. package/dist-lib/types/workspace/view/PrototypePlayer.d.ts +17 -0
  100. package/dist-lib/types/workspace/view/StoryboardWorkspace.d.ts +3 -0
  101. package/dist-lib/types/workspace/view/prototypePlayback.d.ts +46 -0
  102. package/draft-preview.d.ts +54 -0
  103. package/host-runtime.d.ts +73 -0
  104. package/inspect.d.ts +2 -0
  105. package/jsx-source-reconciler.d.ts +35 -0
  106. package/node/design-session.mjs +3 -0
  107. package/node/host-runtime.mjs +4 -0
  108. package/node/inspect-plugin.mjs +3 -1
  109. package/node/inspect-writeback.mjs +18 -2
  110. package/node/jsx-source-reconciler.mjs +155 -0
  111. package/node/preview-artifact-store.mjs +10 -7
  112. package/node/revision-catalog-resolver.mjs +159 -0
  113. package/node/source-archive-runtime.mjs +63 -0
  114. package/node/source-archive.mjs +88 -0
  115. package/node/source-bindings.mjs +65 -0
  116. package/node/source-file-lock.mjs +15 -0
  117. package/node/source-file-plan.mjs +162 -0
  118. package/node/source-file-proofs.mjs +44 -0
  119. package/node/source-module.mjs +17 -0
  120. package/node/source-responsive-codec.d.mts +17 -0
  121. package/node/source-responsive-codec.mjs +133 -0
  122. package/node/source-responsive.mjs +189 -0
  123. package/node/source-service-inputs.mjs +81 -0
  124. package/node/source-service-plugin.mjs +57 -0
  125. package/node/source-service.mjs +4 -0
  126. package/node/source-structure-reconcile.mjs +186 -0
  127. package/node/source-structure-wrapper-codec.d.mts +20 -0
  128. package/node/source-structure-wrapper-codec.mjs +205 -0
  129. package/node/source-structure.mjs +404 -0
  130. package/node/token-source-references.mjs +136 -0
  131. package/node/token-source-service.mjs +151 -0
  132. package/node/workspace-draft-entry.mjs +52 -0
  133. package/node/workspace-draft-preview-plugin.mjs +70 -0
  134. package/node/workspace-draft-preview.mjs +232 -0
  135. package/node/workspace-draft-process.mjs +129 -0
  136. package/node/workspace-draft-runtime.mjs +67 -0
  137. package/node/workspace-source-identity.d.mts +1 -0
  138. package/node/workspace-source-identity.mjs +21 -0
  139. package/node/workspace-source-plan.mjs +195 -0
  140. package/node/workspace-source-session.mjs +187 -0
  141. package/package.json +90 -6
  142. package/source-files.d.ts +35 -0
  143. package/source-module.d.ts +16 -0
  144. package/source-responsive.d.ts +10 -0
  145. package/source-service.d.ts +92 -0
  146. package/source-structure.d.ts +155 -0
  147. package/workspace-draft-entry.d.ts +15 -0
  148. package/workspace-source-plan.d.ts +44 -0
  149. package/docs/coverage-contracts.md +0 -444
  150. package/docs/screen-state-contract.md +0 -252
@@ -0,0 +1,169 @@
1
+ import type { DesignDocument, DocumentDiagnostic, DocumentDuplicateMetadataRemapper, DocumentNode, DocumentNodeKind, DocumentNodePatch, DocumentTransaction, DocumentValue } from './contracts.js';
2
+ /**
3
+ * Component model on top of the document engine's component commands.
4
+ *
5
+ * Everything here is stored in `node.properties` so that the document contract is unchanged:
6
+ * - a component set is a container with `properties.componentSet === true` whose children are the
7
+ * variant components; each variant carries `properties.variant`, a map of axis name to value, and its
8
+ * layer name is the Figma-style `Axis=Value, Axis=Value` string;
9
+ * - a main component may declare `properties.componentProperties` (text, boolean and instance-swap
10
+ * properties), each bound to layer addresses inside the definition; an instance's property value is
11
+ * the override on those layers, so the document never stores a second copy of the value;
12
+ * - a nested instance inside a definition may set `properties.exposeInstanceProperties === true` so
13
+ * that its definition's properties appear on every outer instance;
14
+ * - `properties.hidden === true` hides a layer; boolean properties toggle it.
15
+ *
16
+ * Override addresses are the definition node id (`layer`) or a slash-joined path through nested
17
+ * instances (`nestedInstance/layer`). Exact canonical IDs take precedence over nested paths.
18
+ * An address shadowed by an exact canonical ID is not exposed as an editable nested target.
19
+ */
20
+ export declare const COMPONENT_SET_KEY = "componentSet";
21
+ export declare const VARIANT_KEY = "variant";
22
+ export declare const COMPONENT_PROPERTIES_KEY = "componentProperties";
23
+ export declare const EXPOSE_PROPERTIES_KEY = "exposeInstanceProperties";
24
+ export declare const HIDDEN_KEY = "hidden";
25
+ export declare const COMPONENT_DESCRIPTION_KEY = "componentDescription";
26
+ export declare const COMPONENT_DOCUMENTATION_KEY = "componentDocumentationLink";
27
+ export declare const OVERRIDE_ADDRESS_SEPARATOR = "/";
28
+ export declare const VARIANT_NAME_LIMIT = 64;
29
+ export type ComponentVariantValues = Record<string, string>;
30
+ export interface ComponentVariantAxis {
31
+ name: string;
32
+ values: string[];
33
+ }
34
+ export interface ComponentVariantSet {
35
+ setId: string;
36
+ name: string;
37
+ variantIds: string[];
38
+ axes: ComponentVariantAxis[];
39
+ diagnostics: DocumentDiagnostic[];
40
+ }
41
+ export type ComponentPropertyType = 'text' | 'boolean' | 'instanceSwap';
42
+ export interface ComponentPropertyDefinition {
43
+ id: string;
44
+ name: string;
45
+ type: ComponentPropertyType;
46
+ /** Override addresses inside the definition that the property writes. */
47
+ targets: string[];
48
+ /** Instance-swap properties may list component ids to offer first. */
49
+ preferredValues?: string[];
50
+ }
51
+ export type InstanceOverrideField = 'name' | 'width' | 'height' | 'transform' | 'layout' | 'constraints' | 'definitionId' | `properties.${string}`;
52
+ export interface InstanceOverride {
53
+ /** Override address, or the instance's own definition id for size and direct properties. */
54
+ address: string;
55
+ layerName: string;
56
+ field: InstanceOverrideField;
57
+ value: DocumentValue | undefined;
58
+ /** A property written on the instance node itself rather than through `overrides`. */
59
+ direct: boolean;
60
+ }
61
+ export interface InstanceLayer {
62
+ address: string;
63
+ nodeId: string;
64
+ name: string;
65
+ kind: DocumentNodeKind;
66
+ depth: number;
67
+ /** Nested instance addresses crossed to reach the layer; empty for the definition's own layers. */
68
+ through: string[];
69
+ resolved: DocumentNode;
70
+ definition: DocumentNode;
71
+ overridden: boolean;
72
+ }
73
+ export interface InstanceProperty {
74
+ id: string;
75
+ definition: ComponentPropertyDefinition;
76
+ /** Address prefix of the nested instance that exposes the property; empty for the definition's own. */
77
+ prefix: string;
78
+ targets: string[];
79
+ value: DocumentValue;
80
+ overridden: boolean;
81
+ mixed: boolean;
82
+ }
83
+ export interface OverrideAddressEntry {
84
+ address: string;
85
+ nodeId: string;
86
+ name: string;
87
+ kind: DocumentNodeKind;
88
+ parentAddress: string | null;
89
+ }
90
+ export interface ComponentSwapPlan {
91
+ status: 'ready' | 'unchanged' | 'blocked';
92
+ instanceId: string;
93
+ definitionId: string;
94
+ /** Explicit definition-relative mapping handed to `swapInstance`; names are matched here, never in the engine. */
95
+ overrideTargets: Record<string, string>;
96
+ /** Override addresses with no compatible target in the new definition; dropped only on explicit request. */
97
+ unmatched: string[];
98
+ diagnostics: DocumentDiagnostic[];
99
+ }
100
+ export declare const componentPropertyField: Readonly<Record<ComponentPropertyType, InstanceOverrideField>>;
101
+ export declare function overrideAddressSegments(address: string): string[];
102
+ export declare function joinOverrideAddress(...segments: readonly string[]): string;
103
+ /**
104
+ * Every address an instance of `definitionId` can override: the definition's descendants and, through
105
+ * each nested instance, its definition's descendants prefixed with the nested instance's address.
106
+ */
107
+ export declare function definitionOverrideAddresses(document: DesignDocument, definitionId: string, options?: {
108
+ nested?: boolean;
109
+ }): OverrideAddressEntry[];
110
+ export declare function isComponentSet(node: DocumentNode | undefined | null): boolean;
111
+ export declare function isVariantValues(value: unknown): value is ComponentVariantValues;
112
+ export declare function variantValuesOf(node: DocumentNode | undefined | null): ComponentVariantValues | null;
113
+ /** `Size=Large, State=Hover` becomes `{ Size: 'Large', State: 'Hover' }`; any other name is not a variant name. */
114
+ export declare function parseVariantName(name: string): ComponentVariantValues | null;
115
+ export declare function formatVariantName(values: ComponentVariantValues): string;
116
+ export declare function componentSetOf(document: DesignDocument, componentId: string): DocumentNode | null;
117
+ export declare function describeComponentVariantSet(document: DesignDocument, setId: string): ComponentVariantSet;
118
+ export declare function validateComponentSet(document: DesignDocument, setId: string): DocumentDiagnostic[];
119
+ export declare function findVariant(document: DesignDocument, set: ComponentVariantSet, values: ComponentVariantValues): string | null;
120
+ /** The variant reached by changing one axis of an instance's current variant; other axes keep their values. */
121
+ export declare function variantSwitchTarget(document: DesignDocument, instanceId: string, axis: string, value: string): string | null;
122
+ /** One container becomes the main component in place; any other selection is wrapped first, as in Figma. */
123
+ export declare function createComponentFromLayers(tx: DocumentTransaction, document: DesignDocument, nodeIds: readonly string[], allocateId: (sourceNodeId: string) => string, name?: string): string;
124
+ /** Wraps sibling components in a component set; names in `Axis=Value` form keep their axes, others become `Property 1`. */
125
+ export declare function combineAsVariants(tx: DocumentTransaction, document: DesignDocument, componentIds: readonly string[], setId: string, name?: string): void;
126
+ /** Duplicates a variant into its set below the existing variants and names it by its values. */
127
+ export declare function addVariant(tx: DocumentTransaction, document: DesignDocument, setId: string, sourceVariantId: string, allocateId: (sourceNodeId: string) => string, values: ComponentVariantValues, options?: {
128
+ remapMetadata?: DocumentDuplicateMetadataRemapper;
129
+ }): string;
130
+ export declare function setVariantValues(tx: DocumentTransaction, document: DesignDocument, variantId: string, values: ComponentVariantValues): void;
131
+ export declare function addVariantAxis(tx: DocumentTransaction, document: DesignDocument, setId: string, axis: string, defaultValue: string): void;
132
+ export declare function renameVariantAxis(tx: DocumentTransaction, document: DesignDocument, setId: string, from: string, to: string): void;
133
+ export declare function removeVariantAxis(tx: DocumentTransaction, document: DesignDocument, setId: string, axis: string): void;
134
+ export declare function renameVariantValue(tx: DocumentTransaction, document: DesignDocument, setId: string, axis: string, from: string, to: string): void;
135
+ /** Matches overrides to the new definition by address, then by unique layer name and kind; the engine receives the explicit result. */
136
+ export declare function planInstanceSwap(document: DesignDocument, instanceId: string, definitionId: string): ComponentSwapPlan;
137
+ export declare function applyInstanceSwap(tx: DocumentTransaction, plan: ComponentSwapPlan, options?: {
138
+ discardUnmatched?: boolean;
139
+ }): void;
140
+ export declare function planVariantSwitch(document: DesignDocument, instanceId: string, axis: string, value: string): ComponentSwapPlan;
141
+ export declare function instanceLayers(document: DesignDocument, instanceId: string, options?: {
142
+ nested?: boolean;
143
+ }): InstanceLayer[];
144
+ export declare function listInstanceOverrides(document: DesignDocument, instanceId: string): InstanceOverride[];
145
+ export declare function setInstanceOverride(tx: DocumentTransaction, instanceId: string, address: string, patch: DocumentNodePatch): void;
146
+ /** Resets one layer, or one field of one layer; a direct instance property is removed from the instance node. */
147
+ export declare function resetInstanceOverride(tx: DocumentTransaction, document: DesignDocument, instanceId: string, address: string, field?: InstanceOverrideField, direct?: boolean): void;
148
+ export declare function resetInstanceSize(tx: DocumentTransaction, document: DesignDocument, instanceId: string): void;
149
+ export declare function resetAllInstanceOverrides(tx: DocumentTransaction, instanceId: string, preserveProperties?: readonly string[]): void;
150
+ /** Writes an instance's overrides into the shared definition and clears them; nested addresses become the nested instance's own overrides. */
151
+ export declare function pushOverridesToMainComponent(tx: DocumentTransaction, document: DesignDocument, instanceId: string): void;
152
+ export declare function isComponentPropertyDefinition(value: unknown): value is ComponentPropertyDefinition;
153
+ export declare function componentPropertyDefinitions(node: DocumentNode | undefined | null): ComponentPropertyDefinition[];
154
+ export declare function validateComponentProperties(document: DesignDocument, componentId: string): DocumentDiagnostic[];
155
+ /** Adds a property, or replaces the one with the same id. */
156
+ export declare function defineComponentProperty(tx: DocumentTransaction, document: DesignDocument, componentId: string, definition: ComponentPropertyDefinition): void;
157
+ export declare function removeComponentProperty(tx: DocumentTransaction, document: DesignDocument, componentId: string, propertyId: string): void;
158
+ /** The definition's own properties, then those exposed by nested instances, each read from the current overrides. */
159
+ export declare function instanceProperties(document: DesignDocument, instanceId: string): InstanceProperty[];
160
+ /** Writes the value as overrides on every target; a value equal to the definition's own removes the override instead. */
161
+ export declare function setInstanceProperty(tx: DocumentTransaction, document: DesignDocument, instanceId: string, property: InstanceProperty, value: DocumentValue): void;
162
+ export declare function resetInstanceProperty(tx: DocumentTransaction, document: DesignDocument, instanceId: string, property: InstanceProperty): void;
163
+ /** Instances whose definition is `componentId`, in document order; nested instances inside other definitions included. */
164
+ export declare function componentInstances(document: DesignDocument, componentId: string): string[];
165
+ /** The main component a canonical layer belongs to (itself for a component), or null outside any definition. */
166
+ export declare function mainComponentOf(document: DesignDocument, nodeId: string): string | null;
167
+ export declare function validateDocumentComponents(document: DesignDocument): DocumentDiagnostic[];
168
+ /** Component authoring metadata is draft-only until a source component codec is declared. */
169
+ export declare function componentsSourceDiagnostics(after: DesignDocument, before: DesignDocument): DocumentDiagnostic[];
@@ -0,0 +1,171 @@
1
+ /** Serializable authoring state. Rendered trees are projections of this document. */
2
+ export type DocumentValue = null | boolean | number | string | DocumentValue[] | {
3
+ [key: string]: DocumentValue;
4
+ };
5
+ export type DocumentMatrix = [number, number, number, number, number, number];
6
+ export type DocumentNodeKind = 'root' | 'frame' | 'group' | 'component' | 'instance' | 'slot' | 'text' | 'vector';
7
+ export interface DocumentLayout {
8
+ direction: 'horizontal' | 'vertical' | 'grid';
9
+ gap: number;
10
+ padding: number;
11
+ align?: 'start' | 'center' | 'end' | 'stretch';
12
+ sizing?: 'fixed' | 'hug';
13
+ crossSizing?: 'fixed' | 'hug';
14
+ wrap?: boolean;
15
+ crossGap?: number;
16
+ distribute?: 'start' | 'center' | 'end' | 'space-between';
17
+ paddingTop?: number;
18
+ paddingRight?: number;
19
+ paddingBottom?: number;
20
+ paddingLeft?: number;
21
+ columns?: number;
22
+ minWidth?: number;
23
+ maxWidth?: number;
24
+ minHeight?: number;
25
+ maxHeight?: number;
26
+ }
27
+ export type DocumentConstraint = 'start' | 'end' | 'center' | 'stretch' | 'scale';
28
+ /** How a child follows its parent's resize; an omitted axis behaves as `start`. */
29
+ export interface DocumentNodeConstraints {
30
+ horizontal?: DocumentConstraint;
31
+ vertical?: DocumentConstraint;
32
+ }
33
+ export interface DocumentNodePatch {
34
+ /** Nested instance target only; ordinary patch commands use swapInstance instead. */
35
+ definitionId?: string;
36
+ name?: string;
37
+ transform?: DocumentMatrix;
38
+ width?: number;
39
+ height?: number;
40
+ layout?: DocumentLayout | null;
41
+ constraints?: DocumentNodeConstraints;
42
+ properties?: Record<string, DocumentValue>;
43
+ }
44
+ export interface DocumentNode {
45
+ id: string;
46
+ kind: DocumentNodeKind;
47
+ name: string;
48
+ parentId: string | null;
49
+ children: string[];
50
+ /** Local affine transform, including translation relative to the parent. */
51
+ transform: DocumentMatrix;
52
+ width: number;
53
+ height: number;
54
+ layout?: DocumentLayout | null;
55
+ constraints?: DocumentNodeConstraints;
56
+ properties: Record<string, DocumentValue>;
57
+ /** Slots are explicit containers with optional child-kind restrictions. */
58
+ accepts?: DocumentNodeKind[];
59
+ /** An instance has no owned children; its render tree comes from its definition. */
60
+ definitionId?: string;
61
+ /** Definition-relative overrides. Instance sizes inherit unless overridden here. */
62
+ overrides?: Record<string, DocumentNodePatch>;
63
+ }
64
+ export interface DesignDocument {
65
+ schemaVersion: 1;
66
+ id: string;
67
+ sourceRevision: string;
68
+ rootId: string;
69
+ nodes: Record<string, DocumentNode>;
70
+ /** Domain adapters may store serializable sidecars, including bindings, here. */
71
+ metadata: Record<string, DocumentValue>;
72
+ }
73
+ export interface DocumentDiagnostic {
74
+ code: string;
75
+ message: string;
76
+ nodeId?: string;
77
+ }
78
+ export interface DocumentPreflightInput {
79
+ before: DesignDocument;
80
+ after: DesignDocument;
81
+ operations: readonly string[];
82
+ }
83
+ export interface DocumentEngineOptions {
84
+ preflight?: (input: DocumentPreflightInput) => readonly DocumentDiagnostic[];
85
+ historyLimit?: number;
86
+ }
87
+ export interface DocumentInstanceSwapOptions {
88
+ /** Explicit definition-relative addresses; names and child positions are never matched. */
89
+ overrideTargets?: Readonly<Record<string, string>>;
90
+ /** Unmapped or incompatible overrides reject the swap unless discarding is explicit. */
91
+ incompatibleOverrides?: 'reject' | 'discard';
92
+ }
93
+ export interface DocumentInstanceResetOptions {
94
+ /** Adapter-owned identity/source properties that are not presentation overrides. */
95
+ preserveProperties?: readonly string[];
96
+ }
97
+ export interface DocumentDuplicateMetadataInput {
98
+ /** State at the start of the duplicate command, including earlier transaction commands. */
99
+ before: DesignDocument;
100
+ /** Copied structure before sidecar remapping and final layout/preflight. */
101
+ after: DesignDocument;
102
+ nodeIds: Readonly<Record<string, string>>;
103
+ }
104
+ export type DocumentDuplicateMetadataRemapper = (input: DocumentDuplicateMetadataInput) => Record<string, DocumentValue>;
105
+ export interface DocumentDuplicateOptions {
106
+ /** Defaults to the original parent, immediately after the selected subtree. */
107
+ parentId?: string;
108
+ index?: number;
109
+ preserveWorld?: boolean;
110
+ /** Pure callback, required for nonempty metadata. The adapter owns sidecar IDs and scope references. */
111
+ remapMetadata?: DocumentDuplicateMetadataRemapper;
112
+ }
113
+ export interface DocumentTransaction {
114
+ /** Restores a same-identity snapshot as one undoable transaction. */
115
+ replaceDocument(document: DesignDocument): void;
116
+ add(node: DocumentNode, parentId: string, index?: number): void;
117
+ patch(nodeId: string, patch: DocumentNodePatch): void;
118
+ move(nodeId: string, x: number, y: number): void;
119
+ resize(nodeId: string, width: number, height: number): void;
120
+ reparent(nodeId: string, parentId: string, index?: number, options?: {
121
+ preserveWorld?: boolean;
122
+ }): void;
123
+ moveOut(nodeId: string): void;
124
+ group(nodeIds: readonly string[], groupId: string, name?: string): void;
125
+ ungroup(groupId: string): void;
126
+ remove(nodeId: string): void;
127
+ defineComponent(nodeId: string): void;
128
+ createInstance(definitionId: string, instanceId: string, parentId: string, index?: number): void;
129
+ setOverride(instanceId: string, definitionNodeId: string, patch: DocumentNodePatch | null): void;
130
+ /** Keeps placement and explicit compatible overrides; host semantics use preflight. */
131
+ swapInstance(instanceId: string, definitionId: string, options?: DocumentInstanceSwapOptions): void;
132
+ /** Clears definition overrides and direct instance properties, retaining placement and name. */
133
+ resetInstanceOverrides(instanceId: string, options?: DocumentInstanceResetOptions): void;
134
+ detachInstance(instanceId: string, allocateId: (definitionNodeId: string) => string): void;
135
+ /** Copies owned children only; the ID allocator is pure and external definitions remain shared. */
136
+ duplicateSubtree(nodeId: string, allocateId: (sourceNodeId: string) => string, options?: DocumentDuplicateOptions): Readonly<Record<string, string>>;
137
+ setMetadata(key: string, value: DocumentValue | undefined): void;
138
+ }
139
+ export interface DocumentEngine {
140
+ readonly snapshot: DesignDocument;
141
+ readonly revision: number;
142
+ readonly canUndo: boolean;
143
+ readonly canRedo: boolean;
144
+ transact(label: string, apply: (transaction: DocumentTransaction) => void): boolean;
145
+ undo(): boolean;
146
+ redo(): boolean;
147
+ serialize(): string;
148
+ subscribe(listener: () => void): () => void;
149
+ }
150
+ export interface ResolvedDocumentNode {
151
+ /** Definition identity is retained so the UI can address explicit overrides. */
152
+ sourceNodeId: string;
153
+ /** Authored instance properties, excluding values inherited from its main component. */
154
+ instanceProperties?: Record<string, DocumentValue>;
155
+ instanceId?: string;
156
+ node: DocumentNode;
157
+ children: ResolvedDocumentNode[];
158
+ }
159
+ /** Optional presentation-time instance resolution; normal editing uses canonical definitions. */
160
+ export interface DocumentResolveOptions {
161
+ resolveInstance?: (input: {
162
+ node: DocumentNode;
163
+ /** Outer-to-inner instance IDs. IDs remain opaque, including slashes. */
164
+ instancePath: readonly string[];
165
+ /** Effective overrides after outer and nested instance overrides have been merged. */
166
+ overrides: Readonly<Record<string, DocumentNodePatch>>;
167
+ }) => {
168
+ definitionId: string;
169
+ overrides: Record<string, DocumentNodePatch>;
170
+ } | undefined;
171
+ }
@@ -0,0 +1,20 @@
1
+ import type { DesignDocument, DocumentDiagnostic, DocumentEngine, DocumentEngineOptions, DocumentNode, DocumentNodePatch, ResolvedDocumentNode, DocumentResolveOptions } from './contracts.js';
2
+ export declare class DocumentValidationError extends Error {
3
+ readonly diagnostics: readonly DocumentDiagnostic[];
4
+ constructor(diagnostics: readonly DocumentDiagnostic[]);
5
+ }
6
+ export declare function createDocumentNode(input: Pick<DocumentNode, 'id' | 'kind'> & Partial<DocumentNode>): DocumentNode;
7
+ export declare function createDesignDocument(id: string, sourceRevision: string, rootId?: string): DesignDocument;
8
+ /** Exact node IDs keep their meaning; slash paths cross only declared nested instances. */
9
+ export declare function componentOverrideTarget(document: DesignDocument, definitionId: string, address: string, overrides?: Record<string, DocumentNodePatch>, definitions?: Set<string>): DocumentNode | undefined;
10
+ /** Remap only canonical IDs reached by the address, never coincidental slash-separated text. */
11
+ export declare function remapComponentOverrideAddress(document: DesignDocument, definitionId: string, address: string, nodeIds: Readonly<Record<string, string>>, overrides?: Record<string, DocumentNodePatch>): string;
12
+ /** Resolves components without materializing a second mutable tree in the document. */
13
+ export declare function resolveDocumentNode(document: DesignDocument, nodeId: string, options?: DocumentResolveOptions): ResolvedDocumentNode;
14
+ /** Checks persisted trees before they become authoring state. */
15
+ export declare function validateDesignDocument(document: DesignDocument): DocumentDiagnostic[];
16
+ export declare function createDocumentEngine(input: DesignDocument, options?: DocumentEngineOptions): DocumentEngine;
17
+ export declare function reopenDesignDocument(serialized: string, options?: DocumentEngineOptions): DocumentEngine;
18
+ /** A detached serialized projection; consumers cannot mutate canonical state through it. */
19
+ export declare function projectDesignDocument(document: DesignDocument): DesignDocument;
20
+ export type { DesignDocument, DocumentEngine, DocumentNode, DocumentValue } from './contracts.js';
@@ -0,0 +1,45 @@
1
+ import type { DesignDocument, DocumentDiagnostic, DocumentNode, DocumentValue } from './contracts.js';
2
+ export type ExportFormat = 'svg' | 'png' | 'jpg' | 'webp';
3
+ export interface ExportSetting {
4
+ format: ExportFormat;
5
+ constraint: {
6
+ type: 'scale' | 'width' | 'height';
7
+ value: number;
8
+ };
9
+ suffix: string;
10
+ contentsOnly?: boolean;
11
+ }
12
+ export declare const DEFAULT_EXPORT_SETTING: ExportSetting;
13
+ export declare function isExportSetting(value: unknown): value is ExportSetting;
14
+ export declare function nodeExportSettings(node: Pick<DocumentNode, 'properties'>): ExportSetting[];
15
+ export declare function exportSettingsProperties(properties: Record<string, DocumentValue>, settings: readonly ExportSetting[]): Record<string, DocumentValue>;
16
+ export declare function exportDimensions(node: Pick<DocumentNode, 'width' | 'height'>, setting: ExportSetting): {
17
+ width: number;
18
+ height: number;
19
+ scale: number;
20
+ };
21
+ export interface SvgExportResult {
22
+ markup: string;
23
+ width: number;
24
+ height: number;
25
+ diagnostics: DocumentDiagnostic[];
26
+ }
27
+ /** Safe SVG export of document geometry. Any unsupported visual is reported and prevents export. */
28
+ export declare function exportNodeSvg(document: DesignDocument, nodeId: string, setting?: ExportSetting): SvgExportResult;
29
+ export interface RasterExportRequest {
30
+ document: DesignDocument;
31
+ nodeId: string;
32
+ format: 'png' | 'jpg' | 'webp';
33
+ width: number;
34
+ height: number;
35
+ scale: number;
36
+ contentsOnly: boolean;
37
+ }
38
+ export type RasterExportRenderer = (request: RasterExportRequest) => Promise<Uint8Array>;
39
+ export interface DesignExportArtifact {
40
+ fileName: string;
41
+ mediaType: string;
42
+ bytes: Uint8Array;
43
+ }
44
+ /** Raster bytes come only from an explicit host renderer; no hidden capture or network access. */
45
+ export declare function exportDesignNode(document: DesignDocument, nodeId: string, setting: ExportSetting, renderer?: RasterExportRenderer): Promise<DesignExportArtifact>;
@@ -0,0 +1,11 @@
1
+ import type { DesignDocument, DocumentMatrix } from './contracts.js';
2
+ export declare function identityDocumentMatrix(): DocumentMatrix;
3
+ export declare function multiplyDocumentMatrices(a: DocumentMatrix, b: DocumentMatrix): DocumentMatrix;
4
+ export declare function invertDocumentMatrix(m: DocumentMatrix): DocumentMatrix;
5
+ export declare function documentWorldTransform(document: DesignDocument, nodeId: string): DocumentMatrix;
6
+ export declare function documentTransformedBounds(matrix: DocumentMatrix, width: number, height: number): {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ };
@@ -0,0 +1,53 @@
1
+ import type { DocumentNode } from './contracts.js';
2
+ /** Pure layout projection. Input nodes and intrinsic source leaves are never mutated. */
3
+ export interface LayoutSpec {
4
+ direction: 'horizontal' | 'vertical' | 'grid';
5
+ gap: number;
6
+ padding: number;
7
+ align?: 'start' | 'center' | 'end' | 'stretch';
8
+ sizing?: 'fixed' | 'hug';
9
+ crossSizing?: 'fixed' | 'hug';
10
+ wrap?: boolean;
11
+ crossGap?: number;
12
+ distribute?: 'start' | 'center' | 'end' | 'space-between';
13
+ paddingTop?: number;
14
+ paddingRight?: number;
15
+ paddingBottom?: number;
16
+ paddingLeft?: number;
17
+ columns?: number;
18
+ minWidth?: number;
19
+ maxWidth?: number;
20
+ minHeight?: number;
21
+ maxHeight?: number;
22
+ }
23
+ export declare function layoutHugAxes(layout?: LayoutSpec | null): {
24
+ width: boolean;
25
+ height: boolean;
26
+ };
27
+ export interface LayoutChild {
28
+ position?: 'auto' | 'absolute';
29
+ horizontal?: 'fixed' | 'fill';
30
+ vertical?: 'fixed' | 'fill';
31
+ columnSpan?: number;
32
+ }
33
+ export interface LayoutPlacement {
34
+ nodeId: string;
35
+ x: number;
36
+ y: number;
37
+ width: number;
38
+ height: number;
39
+ }
40
+ export interface LayoutResult {
41
+ width: number;
42
+ height: number;
43
+ children: LayoutPlacement[];
44
+ }
45
+ export declare function layoutProblem(value: unknown): string | null;
46
+ export declare function layoutChildProblem(properties: DocumentNode['properties']): string | null;
47
+ export declare function layoutChild(node: Pick<DocumentNode, 'properties'>): LayoutChild;
48
+ export declare const isAbsoluteLayoutChild: (node: Pick<DocumentNode, "properties">) => boolean;
49
+ export declare const participatesInLayout: (node: Pick<DocumentNode, "properties">) => boolean;
50
+ export declare function applyLayout(node: Pick<DocumentNode, 'width' | 'height'> & {
51
+ layout?: LayoutSpec | null;
52
+ properties?: DocumentNode['properties'];
53
+ }, children: readonly DocumentNode[]): LayoutResult;