@popcraft/kit 0.1.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 (171) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +74 -0
  4. package/dist/index.js +160558 -0
  5. package/package.json +40 -0
  6. package/types/design-script.d.ts +39 -0
  7. package/types/lib/agent/design-script/build.d.ts +35 -0
  8. package/types/lib/agent/design-script/check.d.ts +11 -0
  9. package/types/lib/agent/design-script/helper-names.d.ts +1 -0
  10. package/types/lib/agent/design-script/kit-modules.d.ts +43 -0
  11. package/types/lib/agent/design-script/recorder.d.ts +52 -0
  12. package/types/lib/agent/design-script/replay.d.ts +13 -0
  13. package/types/lib/agent/design-script/run-node.d.ts +2 -0
  14. package/types/lib/ai/audio-models.d.ts +66 -0
  15. package/types/lib/ai/content.d.ts +27 -0
  16. package/types/lib/ai/limits.d.ts +42 -0
  17. package/types/lib/audio/presentation/loudness.d.ts +80 -0
  18. package/types/lib/audio/presentation/types.d.ts +112 -0
  19. package/types/lib/brand/apply.d.ts +25 -0
  20. package/types/lib/brand/review-kits.d.ts +10 -0
  21. package/types/lib/brand/types.d.ts +20 -0
  22. package/types/lib/code/hash.d.ts +2 -0
  23. package/types/lib/document/auto-layout.d.ts +10 -0
  24. package/types/lib/document/breakpoints.d.ts +45 -0
  25. package/types/lib/document/clone.d.ts +6 -0
  26. package/types/lib/document/color.d.ts +52 -0
  27. package/types/lib/document/detach.d.ts +12 -0
  28. package/types/lib/document/effects.d.ts +60 -0
  29. package/types/lib/document/expressions.d.ts +78 -0
  30. package/types/lib/document/instance-layout.d.ts +94 -0
  31. package/types/lib/document/instances.d.ts +63 -0
  32. package/types/lib/document/libraries.d.ts +97 -0
  33. package/types/lib/document/node-delta.d.ts +21 -0
  34. package/types/lib/document/page-tokens.d.ts +16 -0
  35. package/types/lib/document/photo-frames.d.ts +14 -0
  36. package/types/lib/document/print-pages.d.ts +85 -0
  37. package/types/lib/document/scene-graph.d.ts +194 -0
  38. package/types/lib/document/scene3d.d.ts +76 -0
  39. package/types/lib/document/shader-graph-effects.d.ts +8 -0
  40. package/types/lib/document/shader-graph.d.ts +134 -0
  41. package/types/lib/document/shader-params.d.ts +65 -0
  42. package/types/lib/document/shape-to-path.d.ts +20 -0
  43. package/types/lib/document/text-styles.d.ts +28 -0
  44. package/types/lib/document/text-tokens.d.ts +6 -0
  45. package/types/lib/document/transform.d.ts +79 -0
  46. package/types/lib/document/transform3d.d.ts +99 -0
  47. package/types/lib/document/trim.d.ts +35 -0
  48. package/types/lib/document/types.d.ts +2560 -0
  49. package/types/lib/document/variables.d.ts +14 -0
  50. package/types/lib/editor/easing.d.ts +46 -0
  51. package/types/lib/editor/modes/types.d.ts +131 -0
  52. package/types/lib/editor/prototype-connect.d.ts +49 -0
  53. package/types/lib/editor/smart-animate.d.ts +37 -0
  54. package/types/lib/engine/geometry/flatten.d.ts +2 -0
  55. package/types/lib/engine/geometry/shape-outline.d.ts +24 -0
  56. package/types/lib/engine/pixel/cells.d.ts +12 -0
  57. package/types/lib/engine/pixel/palettes.d.ts +25 -0
  58. package/types/lib/engine/readiness.d.ts +20 -0
  59. package/types/lib/engine/routing.d.ts +41 -0
  60. package/types/lib/engine/shader-graph-presets.d.ts +22 -0
  61. package/types/lib/engine/shader-presets-legacy.d.ts +7 -0
  62. package/types/lib/engine/shader-presets.d.ts +43 -0
  63. package/types/lib/engine/text/atlas.d.ts +120 -0
  64. package/types/lib/engine/text/emoji/segment.d.ts +15 -0
  65. package/types/lib/engine/text/fallback-fonts.d.ts +47 -0
  66. package/types/lib/engine/text/fontkit-lazy.d.ts +8 -0
  67. package/types/lib/engine/text/fonts.d.ts +33 -0
  68. package/types/lib/engine/text/glyph-linear.d.ts +22 -0
  69. package/types/lib/engine/text/google-fonts.d.ts +17 -0
  70. package/types/lib/engine/text/hyphenate/en-us.d.ts +6 -0
  71. package/types/lib/engine/text/hyphenate/liang.d.ts +21 -0
  72. package/types/lib/engine/text/layout-access.d.ts +16 -0
  73. package/types/lib/engine/text/layout.d.ts +168 -0
  74. package/types/lib/engine/text/lists.d.ts +16 -0
  75. package/types/lib/engine/text/measure.d.ts +58 -0
  76. package/types/lib/engine/text/outline-sdf.d.ts +34 -0
  77. package/types/lib/engine/text/shaper.d.ts +88 -0
  78. package/types/lib/engine/text/text-area.d.ts +16 -0
  79. package/types/lib/engine/text/text-fit.d.ts +51 -0
  80. package/types/lib/engine/text/text-path.d.ts +134 -0
  81. package/types/lib/engine/text/text-rings.d.ts +17 -0
  82. package/types/lib/engine/text/wrap-obstacles.d.ts +20 -0
  83. package/types/lib/i18n/catalogs.d.ts +10 -0
  84. package/types/lib/i18n/format.d.ts +27 -0
  85. package/types/lib/i18n/locales.d.ts +25 -0
  86. package/types/lib/i18n/pseudo.d.ts +10 -0
  87. package/types/lib/i18n/runtime.d.ts +27 -0
  88. package/types/lib/io/codecs/wav.d.ts +7 -0
  89. package/types/lib/io/codecs/webp.d.ts +7 -0
  90. package/types/lib/io/export-ir/children.d.ts +2 -0
  91. package/types/lib/io/json-export.d.ts +11 -0
  92. package/types/lib/media-library/types.d.ts +39 -0
  93. package/types/lib/motion/audio-analysis.d.ts +44 -0
  94. package/types/lib/motion/audio-clips.d.ts +92 -0
  95. package/types/lib/motion/audio-onsets.d.ts +13 -0
  96. package/types/lib/motion/audio-signals.d.ts +59 -0
  97. package/types/lib/motion/author.d.ts +80 -0
  98. package/types/lib/motion/composition.d.ts +99 -0
  99. package/types/lib/motion/instances.d.ts +95 -0
  100. package/types/lib/motion/key-selection.d.ts +100 -0
  101. package/types/lib/motion/keys.d.ts +41 -0
  102. package/types/lib/motion/layer-time-edit.d.ts +40 -0
  103. package/types/lib/motion/markers.d.ts +31 -0
  104. package/types/lib/motion/modifier-edit.d.ts +84 -0
  105. package/types/lib/motion/modifiers.d.ts +44 -0
  106. package/types/lib/motion/morph.d.ts +14 -0
  107. package/types/lib/motion/pose-layout.d.ts +6 -0
  108. package/types/lib/motion/pose.d.ts +115 -0
  109. package/types/lib/motion/presets.d.ts +148 -0
  110. package/types/lib/motion/properties.d.ts +74 -0
  111. package/types/lib/motion/sample-keys.d.ts +8 -0
  112. package/types/lib/motion/sample.d.ts +51 -0
  113. package/types/lib/motion/sound.d.ts +25 -0
  114. package/types/lib/motion/spatial-curve.d.ts +15 -0
  115. package/types/lib/motion/spatial.d.ts +38 -0
  116. package/types/lib/motion/text-animators.d.ts +79 -0
  117. package/types/lib/motion/text-units.d.ts +47 -0
  118. package/types/lib/motion/time.d.ts +58 -0
  119. package/types/lib/motion/transitions.d.ts +99 -0
  120. package/types/lib/motion/values.d.ts +12 -0
  121. package/types/lib/motion/video-clip.d.ts +63 -0
  122. package/types/lib/presets/page-presets.d.ts +50 -0
  123. package/types/lib/storage/media-hash.d.ts +4 -0
  124. package/types/lib/storage/media-refs.d.ts +2 -0
  125. package/types/lib/storage/media-store.d.ts +70 -0
  126. package/types/lib/templates/apply.d.ts +38 -0
  127. package/types/lib/templates/capture.d.ts +25 -0
  128. package/types/lib/templates/groups.d.ts +82 -0
  129. package/types/lib/templates/layout.d.ts +20 -0
  130. package/types/lib/templates/quality.d.ts +59 -0
  131. package/types/lib/templates/resize.d.ts +34 -0
  132. package/types/lib/templates/safe-areas.d.ts +42 -0
  133. package/types/lib/templates/text-measurer.d.ts +10 -0
  134. package/types/lib/templates/thumbnail.d.ts +134 -0
  135. package/types/lib/templates/types.d.ts +95 -0
  136. package/types/lib/templates/vocabulary.d.ts +50 -0
  137. package/types/lib/units/units.d.ts +23 -0
  138. package/types/packages/kit/src/index.d.ts +59 -0
  139. package/types/packages/runtime/src/expressions.d.ts +41 -0
  140. package/types/templates/src/app/shared.d.ts +29 -0
  141. package/types/templates/src/audio/beat-loop.d.ts +9 -0
  142. package/types/templates/src/audio/media.d.ts +42 -0
  143. package/types/templates/src/audio/music-synth.d.ts +57 -0
  144. package/types/templates/src/audio/music-worlds.d.ts +8 -0
  145. package/types/templates/src/audio/music.d.ts +19 -0
  146. package/types/templates/src/audio/studio/deck.d.ts +340 -0
  147. package/types/templates/src/audio/studio/dsp.d.ts +151 -0
  148. package/types/templates/src/audio/studio/fx.d.ts +96 -0
  149. package/types/templates/src/audio/studio/mix.d.ts +84 -0
  150. package/types/templates/src/audio/studio/voices.d.ts +120 -0
  151. package/types/templates/src/data/geometry.d.ts +16 -0
  152. package/types/templates/src/effects/shared.d.ts +17 -0
  153. package/types/templates/src/kit.d.ts +582 -0
  154. package/types/templates/src/motion3d/devices.d.ts +42 -0
  155. package/types/templates/src/motion3d/ui.d.ts +48 -0
  156. package/types/templates/src/saas/video-shared.d.ts +114 -0
  157. package/types/templates/src/saas/web-shared.d.ts +74 -0
  158. package/types/templates/src/shared/beat.d.ts +24 -0
  159. package/types/templates/src/shared/captions.d.ts +24 -0
  160. package/types/templates/src/shared/devices.d.ts +188 -0
  161. package/types/templates/src/shared/draw.d.ts +43 -0
  162. package/types/templates/src/shared/fit.d.ts +73 -0
  163. package/types/templates/src/shared/marks.d.ts +51 -0
  164. package/types/templates/src/shared/motion.d.ts +15 -0
  165. package/types/templates/src/shared/overlays.d.ts +80 -0
  166. package/types/templates/src/shared/pointer.d.ts +46 -0
  167. package/types/templates/src/shared/texture.d.ts +41 -0
  168. package/types/templates/src/shared/type.d.ts +6 -0
  169. package/types/templates/src/shared/window.d.ts +50 -0
  170. package/types/templates/src/social/shared.d.ts +66 -0
  171. package/types/templates/src/web/shared.d.ts +64 -0
@@ -0,0 +1,10 @@
1
+ import { Document } from './types.js';
2
+ export declare function applyAutoLayout(doc: Document): Document;
3
+ /** Children grouped into lines that fit the primary axis (a child wider than the line gets its own). */
4
+ export declare function wrapLines(frame: any, childIds: string[], size: (id: string) => {
5
+ intrinsicWidth: number;
6
+ intrinsicHeight: number;
7
+ }): {
8
+ ids: string[];
9
+ counter: number;
10
+ }[];
@@ -0,0 +1,45 @@
1
+ import type { AnyNode, Breakpoint, Document, ResponsiveProps } from './types.js';
2
+ /** The breakpoints a file has until it sets its own: the design, a tablet's width and a phone's. */
3
+ export declare const DEFAULT_BREAKPOINTS: Breakpoint[];
4
+ /** Every property a layer may override at a breakpoint: the keys of `ResponsiveProps`. */
5
+ export declare const RESPONSIVE_PROPS: readonly ["visible", "x", "y", "width", "height", "minWidth", "maxWidth", "minHeight", "maxHeight", "layoutMode", "layoutWrap", "itemSpacing", "counterAxisSpacing", "padding", "primaryAxisAlignItems", "counterAxisAlignItems", "layoutGridColumns", "layoutSizingHorizontal", "layoutSizingVertical", "layoutPositioning", "fontSize", "lineHeight", "textAlign", "textStyleId"];
6
+ /** The file's breakpoints, widest first: the base (no `maxWidth`), then each narrower one. */
7
+ export declare function breakpointsOf(doc: Pick<Document, 'site'>): Breakpoint[];
8
+ /** Whether `id` names the base (or nothing): the design itself, with no overrides. */
9
+ export declare const isBaseBreakpoint: (doc: Pick<Document, "site">, id: string | null | undefined) => boolean;
10
+ /** What a layer sets at breakpoint `id`, the wider breakpoints' overrides under its own. Null when nothing. */
11
+ export declare function overridesAt(node: AnyNode, doc: Pick<Document, 'site'>, id: string): ResponsiveProps | null;
12
+ /** The properties `node` overrides at exactly breakpoint `id` (not what it inherits). */
13
+ export declare const ownOverrides: (node: AnyNode | undefined, id: string) => (keyof ResponsiveProps)[];
14
+ /**
15
+ * The document as it is at breakpoint `id`: every layer with its overrides applied, each screen as wide as the
16
+ * breakpoint is previewed at (unless it sets a width there itself), and auto layout run again. The document itself
17
+ * for the base. Memoised on the document, so the canvas and its handlers can ask on every frame.
18
+ */
19
+ export declare function breakpointDocument(doc: Document, id: string | null | undefined): Document;
20
+ /**
21
+ * An edit made at breakpoint `id`, as what the document stores: the properties a breakpoint may override go into
22
+ * that breakpoint's overrides (dropped again where they equal what the layer has without them), and the rest —
23
+ * paint, words — are the layer's own, at every width.
24
+ */
25
+ export declare function breakpointPatch(node: AnyNode, doc: Pick<Document, 'site'>, id: string, props: Partial<AnyNode>): Partial<AnyNode>;
26
+ /** `props` with the breakpoint's overrides for `keys` removed: the layer takes what it inherits there again. */
27
+ export declare function resetOverrides(node: AnyNode, id: string, keys?: readonly string[]): Partial<AnyNode>;
28
+ /**
29
+ * What a gesture made at breakpoint `id` leaves in the document. `rest` is the document before it; `baked` is the
30
+ * breakpoint's view of it, which the gesture started from; `edited` is that view after the gesture. Each layer
31
+ * goes back to its base values with the gesture's changes to overridable properties kept as overrides at `id`;
32
+ * what it changed otherwise (a colour, the words, a layer added or removed) is the document's, as edited.
33
+ */
34
+ export declare function breakpointResult(rest: Document, baked: Document, edited: Document, id: string): Document;
35
+ /**
36
+ * A separately laid-out copy of a screen (the same layers, arranged for a narrower window) folded into the screen
37
+ * itself: each layer of `masterId` gets, at breakpoint `id`, what its twin under `variantId` sets differently. The
38
+ * two trees are walked side by side, so they must hold the same layers in the same order (a copy that only moved,
39
+ * resized, restyled or hid things); where they stop matching, that subtree is left as it is. What auto layout
40
+ * decides in the copy (a place in a stack, a size that hugs or fills) is not an override: the layout decides it
41
+ * again at the breakpoint. Fold the wider breakpoints first: a narrower one keeps only what it changes again.
42
+ */
43
+ export declare function foldVariant(doc: Document, masterId: string, variantId: string, id: string): Document;
44
+ /** A document's breakpoints set to `list` (the base kept first), with overrides of removed breakpoints dropped. */
45
+ export declare function setBreakpoints(doc: Document, list: Breakpoint[]): Document;
@@ -0,0 +1,6 @@
1
+ import type { AnyNode, Document } from './types.js';
2
+ /** The copied nodes in pre-order (root first); `parentId`s point into the copy except the root's. */
3
+ export declare function cloneSubtree(doc: Document, rootId: string): {
4
+ root: AnyNode;
5
+ nodes: AnyNode[];
6
+ };
@@ -0,0 +1,52 @@
1
+ import type { Color } from './types.js';
2
+ /**
3
+ * Parse hex to a `Color`, or null when it is not (yet) a color.
4
+ *
5
+ * Accepts `#RGB`, `#RGBA`, `#RRGGBB` and `#RRGGBBAA`, with or without the `#`, in either case. The short
6
+ * forms expand by repeating each digit, as CSS does — `#f0c` is `#ff00cc`, not `#f0c000`.
7
+ *
8
+ * `fallbackAlpha` is used by the 3- and 6-digit forms, which carry no alpha: a field showing an opaque
9
+ * color should not silently reset the layer's opacity when someone retypes the same six digits.
10
+ */
11
+ export declare function hexToColor(input: string, fallbackAlpha?: number): Color | null;
12
+ /**
13
+ * `hexToColor` for a value still being typed: null for the 4-digit `#RGBA` shorthand.
14
+ *
15
+ * Every 6- and 8-digit value passes through 4 digits on the way, so applying `#RGBA` per keystroke turned
16
+ * "#1234…" into an alpha change halfway through a color. The shorthand still applies when the person commits
17
+ * it (Enter or blur), which goes through `hexToColor`.
18
+ */
19
+ export declare function hexToColorWhileTyping(input: string, fallbackAlpha?: number): Color | null;
20
+ /** `#RRGGBB`, upper-case. Alpha is not included — ask for `colorToHex8` when it matters. */
21
+ export declare const colorToHex: (c: Color) => string;
22
+ /** `#RRGGBBAA`, upper-case. */
23
+ export declare const colorToHex8: (c: Color) => string;
24
+ /** The 0..255 form the color pickers and canvas APIs use. Alpha stays 0..1, as those libraries expect. */
25
+ export declare const colorToRgba255: (c: Color) => {
26
+ r: number;
27
+ g: number;
28
+ b: number;
29
+ a: number;
30
+ };
31
+ export declare const rgba255ToColor: (v: {
32
+ r: number;
33
+ g: number;
34
+ b: number;
35
+ a: number;
36
+ }) => Color;
37
+ /** `rgba(r, g, b, a)` for CSS. */
38
+ export declare const colorToCss: (c: Color) => string;
39
+ /**
40
+ * Repair a color that may have been stored 0..255 by an old bug.
41
+ *
42
+ * Any channel above 1 means the whole triple is byte-scaled — a legitimate 0..1 color cannot exceed 1.
43
+ * Alpha is left alone: it was always 0..1, and 1 is both a valid alpha and the byte value for "almost
44
+ * nothing", so scaling it would turn opaque into invisible.
45
+ */
46
+ export declare function normalizeColor(c: Color): Color;
47
+ /** Relative luminance (WCAG 2.x) of an opaque colour. */
48
+ export declare const luminance: (c: Color) => number;
49
+ /** The WCAG contrast ratio of two opaque colours, 1–21. */
50
+ export declare function contrastRatio(a: Color, b: Color): number;
51
+ /** `top` (with its alpha) composited over the opaque `bottom`. */
52
+ export declare function over(top: Color, bottom: Color): Color;
@@ -0,0 +1,12 @@
1
+ import type { AnyNode } from './types.js';
2
+ /**
3
+ * `nodes` with each of `ids` that is an instance (of a component in the map) turned into a frame with copies of its
4
+ * children, as drawn. Other ids are ignored. Returns the same map when nothing was detached.
5
+ */
6
+ export declare function detachInstances(nodes: Record<string, AnyNode>, ids: Iterable<string>): Record<string, AnyNode>;
7
+ /**
8
+ * `nodes` with every instance of the given components detached (the components are leaving the file). A detached
9
+ * instance's nested instances stay instances, so the ones of a leaving component are detached in turn, until none is
10
+ * left: removing a library drew a button's icon as nothing, its component gone from under it.
11
+ */
12
+ export declare function detachInstancesOf(nodes: Record<string, AnyNode>, componentIds: ReadonlySet<string>): Record<string, AnyNode>;
@@ -0,0 +1,60 @@
1
+ import type { AnyNode, Blur, BlurEffect, Color, Document, Effect, GlassEffect, HalftoneEffect, NoiseEffect, ProgressiveBlurEffect, Shadow, TextureEffect } from './types.js';
2
+ export type StylesMap = Record<string, {
3
+ type?: string;
4
+ effects?: Effect[];
5
+ } & Record<string, unknown>> | undefined;
6
+ /** Every effect on a node: the effect style's list when one is applied, else the node's (plus legacy fields). */
7
+ export declare function effectsOf(node: AnyNode, styles?: StylesMap): Effect[];
8
+ export declare const isShadowEffect: (e: Effect) => e is Shadow;
9
+ export declare const isBlurEffect: (e: Effect) => e is BlurEffect;
10
+ /** Glass beyond its own refraction pass: a light rim and a soft shadow, in passes the renderer already has. */
11
+ export declare function expandGlass(g: GlassEffect): Effect[];
12
+ /** Visible shadows to draw (glass contributes its rim and drop). */
13
+ export declare function shadowsOf(node: AnyNode, styles?: StylesMap): Shadow[];
14
+ /**
15
+ * Blurs in the shape the GPU passes consume: LAYER / BACKGROUND with a radius. Progressive blur and noise
16
+ * ride the layer-blur pass (they need the node rendered to scratch), tagged with their parameters.
17
+ */
18
+ export interface RenderBlur extends Blur {
19
+ progressive?: Omit<ProgressiveBlurEffect, 'type' | 'visible'>;
20
+ noise?: Omit<NoiseEffect, 'type' | 'visible'>;
21
+ texture?: Omit<TextureEffect, 'type' | 'visible'>;
22
+ /** A motion blur: both blur passes run along this angle (degrees, page axes) instead of across and down. */
23
+ motion?: {
24
+ angle: number;
25
+ };
26
+ }
27
+ export declare function blursOf(node: AnyNode, styles?: StylesMap): RenderBlur[];
28
+ /**
29
+ * Motion blurs add as streaks do: the smear a layer gets from its own motion blur and the ones of every group it is in
30
+ * is the vector sum of them (radius along angle), so a character smearing inside a camera group that whips smears by
31
+ * both. Undefined when they cancel out or there are none.
32
+ */
33
+ export declare function addMotionBlurs(a: RenderBlur | undefined, b: RenderBlur | undefined): RenderBlur | undefined;
34
+ /**
35
+ * The smear a container (group, frame, instance, component) hands to every layer inside it: its visible motion blurs,
36
+ * added up. What the render walk carries down the tree (lib/engine/buffers.ts), so a layer drawn inside it smears as
37
+ * if the group were one picture streaked along the angle.
38
+ */
39
+ export declare function containerMotionBlur(node: AnyNode, styles?: StylesMap): RenderBlur | undefined;
40
+ /**
41
+ * A layer's blurs with the smear it inherits (`inherited`: its groups' `containerMotionBlur`s, added up) folded into its
42
+ * own motion blur, first in the list — the one layer-blur pass the GPU runs for a shape takes the first.
43
+ */
44
+ export declare function withInheritedMotionBlur(own: RenderBlur[], inherited: RenderBlur | undefined): RenderBlur[];
45
+ /**
46
+ * The directions (unit vectors, y down) the two passes of a layer blur run along: across then down for a gaussian, and
47
+ * twice along the streak for a motion blur (two gaussians along one line make a smoother streak than one).
48
+ */
49
+ export declare function blurPassDirections(b: Pick<RenderBlur, 'motion'>): [[number, number], [number, number]];
50
+ /** The glass effect to refract through, if any (the renderer draws it in its own pass before the fill). */
51
+ export declare const glassOf: (node: AnyNode, styles?: StylesMap) => GlassEffect | undefined;
52
+ export declare const halftoneOf: (node: AnyNode, styles?: StylesMap) => HalftoneEffect | undefined;
53
+ /** Does the node draw anything beyond its fills and strokes? */
54
+ export declare const hasEffects: (node: AnyNode, styles?: StylesMap) => boolean;
55
+ /** Legacy fields folded into `effects`; the same object back when there is nothing to migrate. */
56
+ export declare function normalizeNodeEffects<T extends AnyNode>(node: T): T;
57
+ export declare function migrateDocumentEffects(doc: Document): Document;
58
+ /** Default parameters for a newly added effect. */
59
+ export declare function defaultEffect(type: Effect['type'], accent?: Color): Effect;
60
+ export declare const EFFECT_LABELS: Record<Effect['type'], string>;
@@ -0,0 +1,78 @@
1
+ import type { Variable, VariableCollection } from './types.js';
2
+ import { dayOf, exprText, type ExprData, type ExprRow, type ExprValue } from '../../packages/runtime/src/expressions.js';
3
+ export { dayOf, exprText, type ExprData, type ExprRow, type ExprValue };
4
+ /**
5
+ * Layer properties a live value can bind to an expression (`boundExpressions`), besides a text's `characters`: what the
6
+ * Prototype panel's Live values section offers and what `edit_prototype` accepts.
7
+ */
8
+ export declare const LIVE_VALUE_PROPS: readonly ["width", "height", "x", "y", "opacity", "visible", "rotation", "scaleX", "scaleY", "translateX", "translateY", "cornerRadius"];
9
+ export declare class ExpressionError extends Error {
10
+ readonly at: number;
11
+ constructor(message: string, at: number);
12
+ }
13
+ /** What an expression reads: a variable's value by name, and the key that fired a key trigger. */
14
+ export interface ExprScope {
15
+ /** A variable's current value by the name the expression uses; undefined when there is none of that name. */
16
+ get(name: string): ExprValue | undefined;
17
+ /** Whether `name` names a variable (a slash in a name is part of it only when the whole name is one). */
18
+ has(name: string): boolean;
19
+ /** `$key`: the KeyboardEvent.key a KEY_DOWN trigger fired with. */
20
+ key?: string;
21
+ /** The file's collections, for the functions that add records up (`count`, `sum`, `streak`). */
22
+ data?: ExprData;
23
+ }
24
+ /** A parsed expression, as `parseExpression` gives it (an exported project compiles it to TypeScript). */
25
+ export type ExprNode = Node;
26
+ type Node = {
27
+ k: 'lit';
28
+ v: ExprValue;
29
+ } | {
30
+ k: 'var';
31
+ name: string;
32
+ at: number;
33
+ } | {
34
+ k: 'key';
35
+ } | {
36
+ k: 'un';
37
+ op: string;
38
+ a: Node;
39
+ } | {
40
+ k: 'bin';
41
+ op: string;
42
+ a: Node;
43
+ b: Node;
44
+ } | {
45
+ k: 'if';
46
+ c: Node;
47
+ a: Node;
48
+ b: Node;
49
+ } | {
50
+ k: 'call';
51
+ fn: string;
52
+ args: Node[];
53
+ at: number;
54
+ };
55
+ /** `src` as a tree; `has` says which slashed names are whole variable names. Throws an ExpressionError. */
56
+ export declare const parseExpression: (src: string, has: (name: string) => boolean) => ExprNode;
57
+ /** The functions an expression may call, for the panel's help line. */
58
+ export declare const EXPRESSION_FUNCTIONS: string[];
59
+ /** Evaluate `src` against `scope`; throws an ExpressionError (with the offending position) when it cannot. */
60
+ export declare function evaluateExpression(src: string, scope: ExprScope): ExprValue;
61
+ /** `src`'s value, or undefined when it does not parse or reads a variable that is not there. */
62
+ export declare function tryEvaluate(src: string, scope: ExprScope): ExprValue | undefined;
63
+ /** Whether `src` holds true (a Conditional's branch): false when it cannot be worked out. */
64
+ export declare const holds: (src: string, scope: ExprScope) => boolean;
65
+ /** The problem with `src`, for the panel to show under the field, or null when it parses and every name exists. */
66
+ export declare function expressionProblem(src: string, scope: ExprScope): string | null;
67
+ /** A variable's value in the collection's active mode, else its default mode, else any mode (as bindings read it). */
68
+ export declare function variableValue(v: Variable, collections?: Record<string, VariableCollection>, activeModes?: Record<string, string>): unknown;
69
+ export declare function variablesScope(variables: Record<string, Variable> | undefined, collections?: Record<string, VariableCollection>, activeModes?: Record<string, string>): ExprScope;
70
+ /** `scope` with `$key` set (a key trigger's actions). */
71
+ export declare const withKey: (scope: ExprScope, key: string | undefined) => ExprScope;
72
+ /**
73
+ * `value` as a variable of `type` holds it: a FLOAT a number, a STRING text, a BOOLEAN true / false; a COLOR keeps
74
+ * a colour object (anything else leaves it as it was, returned as undefined).
75
+ */
76
+ export declare function coerceToVariable(type: Variable['type'], value: ExprValue): unknown;
77
+ export declare const markWholeGlide: (v: Variable) => void;
78
+ export declare const isWholeGlide: (v: Variable) => boolean;
@@ -0,0 +1,94 @@
1
+ import type { AnyNode, Document, TextNode } from './types.js';
2
+ export interface Box {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ /**
9
+ * The layout engine, handed over by `auto-layout` when it loads. It is injected rather than imported so
10
+ * the two modules do not import each other: auto-layout asks this module for an instance's height while
11
+ * this module asks it to lay the instance's own copy out, and a real cycle left one of the two bindings
12
+ * undefined in the bundler's output (the render loop crashed on it).
13
+ */
14
+ type LayoutEngine = (doc: Document) => Document;
15
+ export declare function setLayoutEngine(fn: LayoutEngine): void;
16
+ /**
17
+ * The scene-graph helpers, handed over by `scene-graph` when it loads — same reason as the engine above:
18
+ * the resolver asks this module where a child sits while this module asks the resolver what that child
19
+ * is, and importing each other left a binding undefined in the bundler's output.
20
+ */
21
+ export interface SceneApi {
22
+ resolve: (nodes: Record<string, AnyNode>, id: string, opts?: {
23
+ layout?: boolean;
24
+ }) => AnyNode | null;
25
+ childId: (parent: AnyNode, childId: string) => string;
26
+ rootOf: (host: AnyNode | undefined) => string | undefined;
27
+ }
28
+ export declare function setSceneApi(api: SceneApi): void;
29
+ /** How tall a text is once it has wrapped. The editor installs the real GPU layout through
30
+ * `setTextMeasurer` and the template kit the font-metric estimate; this module keeps only a rough
31
+ * fallback, so the scene graph stays free of the text engine (and of the store behind it). */
32
+ export type TextMeasurer = (node: TextNode) => {
33
+ width: number;
34
+ height: number;
35
+ } | null;
36
+ /**
37
+ * Install (or remove) the measurer. Removing is by identity: an editor that mounts twice installs twice
38
+ * and tears down once, and a teardown that cleared whatever was current left the reflow measuring with
39
+ * the fallback — which reports every text at the width it already had, and instances collapsed onto
40
+ * their component's default words.
41
+ */
42
+ export declare function setTextMeasurer(fn: TextMeasurer | null, previous?: TextMeasurer): void;
43
+ /**
44
+ * The installed text engine's measurement of `node`: the real GPU layout while the editor's canvas is up,
45
+ * the font-metric estimate while templates are laid out. Null when only this module's rough fallback is
46
+ * installed, or when the engine cannot measure right now (atlas warming up, face on its way) — callers
47
+ * then keep their own estimate.
48
+ */
49
+ export declare function measureTextLayout(node: TextNode): {
50
+ width: number;
51
+ height: number;
52
+ } | null;
53
+ /**
54
+ * Throw away cached layouts: what the text measures has changed under them.
55
+ *
56
+ * A layout is memoised on the host node and the node table, neither of which moves when a font finishes
57
+ * loading or the canvas takes over measuring from the estimate — so a toggle laid out before its font
58
+ * arrived kept the width it had then, and its label ran into the next one.
59
+ */
60
+ export declare function invalidateInstanceLayouts(): void;
61
+ /**
62
+ * A component child as an instance draws it at `virtualId`: the pose's node when the pose resolved and posed one
63
+ * there (lib/motion/instances.ts), else the child under that id in the box the instance's reflow gives it. The
64
+ * render walks expand instances through this, so a playing motion component draws where the pose put it.
65
+ */
66
+ /**
67
+ * `${prefix}::${child}`, the same string object every time: the pose and the render walks make one per instance layer
68
+ * per frame, and every node-map lookup of a new string hashes it again (tens of thousands a frame, for a file with
69
+ * dozens of animated instances). The table only grows with the instances and layers a document has.
70
+ */
71
+ export declare function joinVirtual(prefix: string, child: string): string;
72
+ export declare function instanceChild(child: AnyNode, virtualId: string, nodes: Record<string, AnyNode>): AnyNode;
73
+ /** Whether a render walk met an instance child the pose already resolved: overrides and property values are in it. */
74
+ export declare const isPosedChild: (node: AnyNode, nodes: Record<string, AnyNode>) => boolean;
75
+ /** A synthesised virtual child moved into the box its instance's own reflow puts it in. Every pass that
76
+ * expands an instance by hand (the two render walks) goes through this, so they agree with the resolver. */
77
+ export declare function withInstanceBox<T extends AnyNode>(node: T, nodes: Record<string, AnyNode>): T;
78
+ /** The box an instance's child is drawn at, once the instance has reflowed around its own content. */
79
+ export declare function instanceChildBox(nodes: Record<string, AnyNode>, virtualId: string): Box | null;
80
+ /** The height an instance needs for its own content (its component hugs), or null when it is fixed. */
81
+ export declare function instanceContentHeight(nodes: Record<string, AnyNode>, hostId: string): number | null;
82
+ /**
83
+ * The width an instance needs for its own content, when both it and its component hug.
84
+ *
85
+ * A component sized to its default words is not the size of an instance's words: a button laid out for
86
+ * "Get started" kept that width with "Start free" in it, and the shorter label sat off to one side.
87
+ */
88
+ export declare function instanceContentWidth(nodes: Record<string, AnyNode>, hostId: string): number | null;
89
+ /**
90
+ * Virtual ids of the text an instance fills itself: the children whose words come from a property or an
91
+ * override. Only these can measure differently from the component, so only these need re-measuring.
92
+ */
93
+ export declare function instanceTextIds(nodes: Record<string, AnyNode>): string[];
94
+ export {};
@@ -0,0 +1,63 @@
1
+ import type { AnyNode, ComponentNode, ComponentPropertyDefinition, ComponentPropertyValue, InstanceNode, Key, MotionValue, PropPath } from './types.js';
2
+ import { isValueOf } from '../motion/values.js';
3
+ export type PropertyValues = Record<string, ComponentPropertyValue>;
4
+ export interface VirtualId {
5
+ /** The top-level instance (or master host) that draws the child. */
6
+ hostId: string;
7
+ /** The child's own id inside the component. */
8
+ childId: string;
9
+ /** The instance whose component holds the child: the host, or a nested instance further down. */
10
+ ownerId: string;
11
+ parts: string[];
12
+ }
13
+ export declare function splitVirtualId(id: string): VirtualId | null;
14
+ /**
15
+ * Property values in force for the child at the end of `parts`: the host's values, then each nested
16
+ * instance's own values (with the host's overrides on it) down the chain. Mirrors the renderer.
17
+ */
18
+ export declare function effectiveComponentProperties(nodes: Record<string, AnyNode>, parts: string[]): PropertyValues;
19
+ /** A nested instance's property values as one host instance shows them (its own, under the host's overrides). */
20
+ export declare function nestedInstanceProperties(nodes: Record<string, AnyNode>, host: InstanceNode, nestedId: string): PropertyValues;
21
+ export interface ExposedNested {
22
+ instance: InstanceNode;
23
+ component: ComponentNode;
24
+ definitions: Record<string, ComponentPropertyDefinition>;
25
+ }
26
+ /** Nested instances under `componentId` marked `isExposedInstance`, in layer order (depth-first). */
27
+ export declare function exposedNestedInstances(nodes: Record<string, AnyNode>, componentId: string): ExposedNested[];
28
+ /** The host patch that sets one property of a nested instance (an override on that instance). */
29
+ export declare function nestedInstancePropertyPatch(host: InstanceNode, nestedId: string, name: string, value: ComponentPropertyValue): Partial<InstanceNode>;
30
+ /** The property definitions an instance of `componentId` edits: its set's for a variant, else the component's own. */
31
+ export declare function componentDefinitions(nodes: Record<string, AnyNode>, componentId: string): Record<string, ComponentPropertyDefinition>;
32
+ /** The component `id` belongs to (itself when it is one): what owns its property definitions and its timeline. */
33
+ export declare function owningComponent(nodes: Record<string, AnyNode>, id: string): ComponentNode | undefined;
34
+ /** Each property's default value: what a layer shows where no instance sets it (and on the component itself). */
35
+ export declare function propertyDefaults(defs: Record<string, ComponentPropertyDefinition>): PropertyValues;
36
+ /** A value `path` can take: the registry's type for it. */
37
+ export declare function fitsPath(path: string, v: ComponentPropertyValue | undefined): boolean;
38
+ /** A bound key's value under `values`: the property's (`· mul + add` for numbers), or the key's own when it has none that fits. */
39
+ export declare function boundValue(key: Key, prop: {
40
+ valueType: Parameters<typeof isValueOf>[0];
41
+ }, values: PropertyValues | undefined): MotionValue;
42
+ /**
43
+ * `node` showing the values its NUMBER / COLOR properties give its bound paths (`componentPropertyPaths`), for
44
+ * the properties `values` sets — and, at rest, the value its bound keys give (see `withRestBindings`). The same node
45
+ * when none applies. Every pass that resolves an instance's child goes through this (the resolver and the render
46
+ * walks), so they agree.
47
+ */
48
+ export declare function withPropertyPaths<T extends AnyNode>(node: T, values: PropertyValues | undefined): T;
49
+ /**
50
+ * Whether the instance's `values` take over `path` on `node`: text bound to a TEXT property, or a path bound to a
51
+ * NUMBER / COLOR property, that the instance sets. The component's keys on such a path give way (an input); an
52
+ * unmarked keyed path stays the component's even where an instance overrides it — the override is its rest value.
53
+ */
54
+ export declare function isInputPath(node: AnyNode, path: PropPath, values: PropertyValues | undefined): boolean;
55
+ /**
56
+ * Fold an edit of an instance child into a patch on its host. Text or visibility the component bound to a
57
+ * property edits the property (on the host, or as an override of the nested instance that owns the child);
58
+ * everything else is an override keyed by the child's id.
59
+ */
60
+ export declare function instanceChildPatch(nodes: Record<string, AnyNode>, virtualId: string, props: Partial<AnyNode>): {
61
+ hostId: string;
62
+ patch: Partial<InstanceNode>;
63
+ } | null;
@@ -0,0 +1,97 @@
1
+ import type { AnyNode, Document, Style, Variable, VariableCollection } from './types.js';
2
+ export interface LibraryPayload {
3
+ styles: Record<string, Style>;
4
+ variables: Record<string, Variable>;
5
+ variableCollections: Record<string, VariableCollection>;
6
+ /** Published component roots (COMPONENT or COMPONENT_SET) and every node in their subtrees. */
7
+ components: {
8
+ rootIds: string[];
9
+ nodes: Record<string, AnyNode>;
10
+ };
11
+ }
12
+ export interface LibraryUse {
13
+ name: string;
14
+ version: number;
15
+ fileKey?: string;
16
+ importedAt: number;
17
+ }
18
+ export type LibraryItemKind = 'component' | 'style' | 'variable';
19
+ export interface LibraryItemChange {
20
+ kind: LibraryItemKind;
21
+ id: string;
22
+ name: string;
23
+ change: 'added' | 'changed' | 'removed';
24
+ }
25
+ export declare const libraryPrefix: (libId: string) => string;
26
+ export declare const libraryPageId: (libId: string) => string;
27
+ export declare const isLibraryId: (id: string) => boolean;
28
+ /** The library an imported id belongs to (null for local ids). */
29
+ export declare function libraryOf(id: string): string | null;
30
+ export declare function subtree(nodes: Record<string, AnyNode>, rootId: string, out: Record<string, AnyNode>): void;
31
+ /**
32
+ * Payload for publishing the chosen items from a document, with what they depend on pulled in: styles and
33
+ * variables referenced by published components, collections of published variables, variables aliased by
34
+ * other variables, and components nested (as instances) inside published components. Imported library items
35
+ * are never republished.
36
+ */
37
+ export interface StyleDependencies {
38
+ styles: Record<string, Style>;
39
+ variables: Record<string, Variable>;
40
+ variableCollections: Record<string, VariableCollection>;
41
+ }
42
+ /**
43
+ * The local styles, variables (with their collections and the variables they alias) that `nodes` reference,
44
+ * added into `into`. Imported library items are never collected. Shared by publishing and templates.
45
+ */
46
+ export declare function collectStyleDependencies(doc: Document, nodes: Record<string, AnyNode>, into?: StyleDependencies): StyleDependencies;
47
+ export declare function buildLibraryPayload(doc: Document, pick: {
48
+ componentIds: string[];
49
+ styleIds: string[];
50
+ variableIds: string[];
51
+ }): LibraryPayload;
52
+ /** A copy of `value` with every string (and object key) found in `map` replaced by its mapping (ids anywhere: children, connectors, instances, style and variable refs). */
53
+ export declare function rewriteIds<T>(value: T, map: Map<string, string>): T;
54
+ /** The payload with all its ids namespaced for `libId`, ready to place in a document. */
55
+ export declare function namespacePayload(libId: string, payload: LibraryPayload): LibraryPayload;
56
+ /** Items that differ between what the document has from `libId` and a (namespaced) new version. */
57
+ export declare function diffLibrary(doc: Document, libId: string, next: LibraryPayload): LibraryItemChange[];
58
+ /**
59
+ * Bring `libId` into the document at `next` (a namespaced payload). With `accept`, only those item ids are
60
+ * applied (the rest stay at their current version); otherwise everything is. Instances of removed components
61
+ * are detached first.
62
+ */
63
+ export declare function applyLibrary(doc: Document, libId: string, use: LibraryUse, next: LibraryPayload, accept?: Set<string>): Document;
64
+ /** Stop using a library: its styles/variables go away, instances of its components are detached. */
65
+ export declare function removeLibrary(doc: Document, libId: string): Document;
66
+ /**
67
+ * Stop linking `libId`: every one of its components, styles, variables and collections becomes the file's own
68
+ * (fresh ids), its components move onto a "<library> components" page, every instance of them is an instance of the
69
+ * local copy, and `document.libraries` no longer names it — so nothing updates from the library again. One document
70
+ * in, one out: the caller commits it as one undo step.
71
+ */
72
+ export declare function unlinkLibrary(doc: Document, libId: string, newId?: () => string): Document;
73
+ /**
74
+ * The file's own copy of the library component `componentId` — what inserting it unlinked makes: the component (its
75
+ * whole set, for a variant), the library components nested in it, and the library styles and variables they use,
76
+ * under fresh ids on the "<library> components" page, with their inputs and timelines. A component copied before
77
+ * (its `libraryOrigin`) is reused, so a second unlinked insert adds no second copy. The library itself stays linked.
78
+ */
79
+ export declare function localCopyOfLibraryComponent(doc: Document, componentId: string, newId?: () => string): {
80
+ document: Document;
81
+ id: string;
82
+ };
83
+ /** The instances in the file (library pages aside) whose component comes from `libId`. */
84
+ export declare function libraryInstances(nodes: Record<string, AnyNode>, libId: string): string[];
85
+ /**
86
+ * The library components the nodes under `rootIds` are instances of (and what those nest), as a map of their
87
+ * subtrees under their `lib:` ids: what a copy carries along, so a paste into a file that does not use the library
88
+ * still has them to copy from.
89
+ */
90
+ export declare function libraryComponentsUsedBy(nodes: Record<string, AnyNode>, rootIds: readonly string[]): Record<string, AnyNode>;
91
+ /**
92
+ * After a paste: the pasted instances (`pastedIds` and their subtrees) of library components, linked or made local.
93
+ * Linked keeps them the library's — when the file uses that library. Unlinked, or when the file does not use the
94
+ * library (the copy came from another file), they become instances of the file's own copies, made from `carried`
95
+ * (the components the clipboard brought, `libraryComponentsUsedBy`).
96
+ */
97
+ export declare function adoptPastedLibraryInstances(doc: Document, pastedIds: readonly string[], carried: Record<string, AnyNode>, link: 'linked' | 'unlinked', newId?: () => string): Document;
@@ -0,0 +1,21 @@
1
+ import type { AnyNode } from './types.js';
2
+ export type NodeMap = Record<string, AnyNode>;
3
+ /** `to` is `from` with exactly `ids` replaced, added or removed. */
4
+ export declare function noteChanged(from: NodeMap, to: NodeMap, ids: readonly string[]): void;
5
+ /**
6
+ * The ids that differ between `from` and `to` (a superset: an id changed and changed back is listed), or null when
7
+ * the notes do not connect them. They connect when both lead back to one map within a few edits: `to` made from
8
+ * `from`, or the two made from a common map — a posed copy of one document state and the next state's.
9
+ */
10
+ export declare function changedSince(from: NodeMap, to: NodeMap): readonly string[] | null;
11
+ /**
12
+ * An index over node maps: memoised per map; for a map it has not seen, carried from the last one it worked out
13
+ * when the notes connect the two (`update(prev, from, to, changed)`, which may return undefined to ask for a
14
+ * rebuild), else built.
15
+ */
16
+ export declare function nodeIndex<T>(build: (nodes: NodeMap) => T, update: (prev: T, from: NodeMap, to: NodeMap, changed: readonly string[]) => T | undefined): (nodes: NodeMap) => T;
17
+ /**
18
+ * An index of the ids whose node passes `test` (a test of the node alone), in map order when built and with
19
+ * additions appended when carried. Memoised per map and carried along the notes in O(matches + changed).
20
+ */
21
+ export declare function idIndex(test: (n: AnyNode) => boolean): (nodes: NodeMap) => readonly string[];
@@ -0,0 +1,16 @@
1
+ import type { AnyNode, DocumentSettings } from './types.js';
2
+ export { substituteTokens } from './text-tokens.js';
3
+ export declare const hasPageTokens: (text: string | undefined) => boolean;
4
+ export interface PageTokenContext {
5
+ page: number;
6
+ pageCount: number;
7
+ }
8
+ /** A page number in the document's numbering style (1-based ordinal in; "iv", "D", "A-3" out). */
9
+ export declare function formatPageNumber(ordinal: number, numbering: DocumentSettings['pageNumbering'] | undefined): string;
10
+ /**
11
+ * The numbering context for text at `nodeId`: null when it is on the free canvas or on a master viewed
12
+ * directly (the master keeps its literal tokens). Virtual ids (`page::child`) resolve to their host page.
13
+ */
14
+ export declare function pageTokenContext(nodes: Record<string, AnyNode>, nodeId: string): PageTokenContext | null;
15
+ /** `node` with its page tokens replaced for `ctx`; the same object back when there is nothing to substitute. */
16
+ export declare function substitutePageTokens<T extends AnyNode>(node: T, ctx: PageTokenContext | null, numbering?: DocumentSettings['pageNumbering']): T;
@@ -0,0 +1,14 @@
1
+ import type { AnyNode, Document, GroupNode, MediaCredit } from './types.js';
2
+ export declare const isPhotoFrame: (n: AnyNode | undefined) => n is GroupNode;
3
+ /** The photo-frame group containing `nodeId` (or the node itself), walking up. */
4
+ export declare function photoFrameOf(nodes: Record<string, AnyNode>, nodeId: string | null): GroupNode | null;
5
+ /** Turn a shape into a photo frame: a mask group of [shape as mask, placeholder]. Returns the group id. */
6
+ export declare function makePhotoFrame(doc: Document, shapeId: string): {
7
+ document: Document;
8
+ id: string | null;
9
+ };
10
+ /** Replace the frame's content with `imageUrl`, cover-fitted to the mask's box (a stock photo keeps its `credit`). */
11
+ export declare function fillPhotoFrame(doc: Document, groupId: string, imageUrl: string, size: {
12
+ width: number;
13
+ height: number;
14
+ }, name?: string, credit?: MediaCredit): Document;