@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,58 @@
1
+ import type { AnyNode, FrameTimeline, InstancePlayback, PlaybackField, PlaybackLoop, PlaybackTrigger, StaggerOrder } from '../document/types.js';
2
+ /**
3
+ * Each id's place in the stagger (0 goes first; `center` gives equal places to equidistant children). `random` is
4
+ * seeded and depends only on the ids, so adding a layer never reshuffles the others. A custom list plays its ids
5
+ * in list order, then any children it does not name in their tree order.
6
+ */
7
+ export declare function staggerRanks(ids: readonly string[], order: StaggerOrder, seed?: number): Map<string, number>;
8
+ /** How much later (ms) the parent's live stagger starts `childId` (0 without one). Memoised on the parent's identity. */
9
+ export declare function staggerOffset(parent: AnyNode | undefined, childId: string): number;
10
+ /**
11
+ * `id`'s local time given its parent's local time (ms): parent time − timeOffset − the parent's stagger for it.
12
+ * Null when the layer's `span` (in parent time) does not include that moment.
13
+ */
14
+ export declare function layerTime(nodes: Record<string, AnyNode>, id: string, parentLocalMs: number): number | null;
15
+ /**
16
+ * `id`'s local time when `rootId` (an ancestor, or `id` itself) is at `rootMs`: layer time applied down the chain.
17
+ * The root's own offset is not applied — `rootMs` is already its local time. Null when a layer on the way is
18
+ * outside its span; undefined when `id` is not inside `rootId`.
19
+ */
20
+ export declare function localTime(nodes: Record<string, AnyNode>, id: string, rootId: string, rootMs: number): number | null | undefined;
21
+ /** How much later (ms) than `rootId`'s time `id`'s local time runs: the offsets and staggers on the way, spans ignored. */
22
+ export declare function timeShift(nodes: Record<string, AnyNode>, id: string, rootId: string): number;
23
+ /** An instance's playback with every field decided (lib/motion/instances.ts `playbackOf`). */
24
+ export interface PlaybackMapping {
25
+ start: number;
26
+ speed: number;
27
+ loop: PlaybackLoop;
28
+ hold: 'first' | 'last';
29
+ trigger: PlaybackTrigger;
30
+ /** Component ms [from, to): the marker range, or the whole timeline. */
31
+ range: [number, number];
32
+ }
33
+ export declare const DEFAULT_PLAYBACK: Required<Omit<InstancePlayback, 'range'>>;
34
+ /** The playback fields a MOTION property can show, in panel order. */
35
+ export declare const PLAYBACK_FIELDS: PlaybackField[];
36
+ /** Whether `v` is a value playback `field` can hold. */
37
+ export declare const isPlaybackValue: (field: PlaybackField, v: unknown) => boolean;
38
+ /** The component ms `[from, to)` a playback covers: between its range's markers when both exist in order, else the whole timeline. */
39
+ export declare function playbackRange(timeline: FrameTimeline, range: InstancePlayback['range']): [number, number];
40
+ /**
41
+ * The component time (ms) an instance shows, `elapsed` ms after its own zero — its layer time for `load` and
42
+ * `inView`, the time since its trigger otherwise; null: not started (a trigger that has not fired), so it waits on
43
+ * its first frame. Before `start` it shows the range's first frame; after it, `speed` component ms pass per ms;
44
+ * past the range it loops, ping-pongs, or holds its last (or first) frame.
45
+ *
46
+ * This is the one mapping: nested instances apply it to their host's mapped time, and precomps reuse it.
47
+ */
48
+ export declare function instanceTime(elapsed: number | null, m: PlaybackMapping): number;
49
+ /** Whether a later `elapsed` would show a different component time: still to start, playing, or looping. */
50
+ export declare function playbackLive(elapsed: number | null, m: PlaybackMapping): boolean;
51
+ /** How long after its zero (ms) a playback stops changing: Infinity while it loops, 0 when it never moves. */
52
+ export declare function playbackEnd(m: PlaybackMapping): number;
53
+ /**
54
+ * `localTime` for many layers of one root at one moment, each ancestor timed once (a pose asks it of every animated
55
+ * layer of a subtree, and walked each one's chain). `false` for a layer inside one that is out of its span: hidden
56
+ * with that layer, it needs no pose of its own.
57
+ */
58
+ export declare function layerTimer(nodes: Record<string, AnyNode>, rootId: string, rootMs: number): (id: string) => number | null | false | undefined;
@@ -0,0 +1,99 @@
1
+ import type { EasingType, TransitionParams, TransitionType } from '../document/types.js';
2
+ import { type Affine } from '../document/transform.js';
3
+ /** A circle a root is drawn inside, in world coordinates. */
4
+ export interface RootClip {
5
+ kind: 'circle';
6
+ cx: number;
7
+ cy: number;
8
+ r: number;
9
+ }
10
+ /** A streak over a whole root: a motion blur of `radius` px along `angle`° (page axes), on everything it draws. */
11
+ export interface RootSmear {
12
+ radius: number;
13
+ angle: number;
14
+ }
15
+ /**
16
+ * A frame to draw, placed by `matrix` (applied on top of its own world placement), faded by `opacity`, clipped by `clip`,
17
+ * smeared by `smear` (a whip pan's motion blur: lib/engine/buffers.ts hands it to every layer under the root).
18
+ */
19
+ export interface RenderRoot {
20
+ rootId: string;
21
+ matrix: Affine;
22
+ opacity: number;
23
+ clip?: RootClip;
24
+ smear?: RootSmear;
25
+ }
26
+ /** One side of a transition: its frame, its size, and where it sits on the stage before the transition moves it. */
27
+ export interface TransitionSide {
28
+ id: string;
29
+ width: number;
30
+ height: number;
31
+ base: Affine;
32
+ }
33
+ /** The world rectangle a transition plays on: the source frame for prototypes, the composition's stage for scenes. */
34
+ export interface Stage {
35
+ x: number;
36
+ y: number;
37
+ width: number;
38
+ height: number;
39
+ }
40
+ /** Every type, in the order pickers list them. */
41
+ export declare const TRANSITION_TYPES: readonly TransitionType[];
42
+ /** A prototype or slide transition's easing, as its pickers name it. */
43
+ export declare const EASING_LABELS: Readonly<Record<EasingType, string>>;
44
+ export declare const TRANSITION_LABELS: Readonly<Record<TransitionType, string>>;
45
+ /** Prototype transitions: `CUT` is the scene name for what prototypes call `INSTANT`. */
46
+ export declare const PROTOTYPE_TRANSITION_TYPES: readonly TransitionType[];
47
+ /** Scene transitions: smart animate matches layers between two frames of one prototype, which scenes are not. */
48
+ export declare const SCENE_TRANSITION_TYPES: readonly TransitionType[];
49
+ /** Whether `type` swaps at once, with nothing in between. */
50
+ export declare const isCut: (type: TransitionType) => boolean;
51
+ /** Whether the transition centres on a point (`params.center`). */
52
+ export declare const usesCenter: (type: TransitionType) => boolean;
53
+ /** The transition that undoes `type` on the way back (present mode's Back). */
54
+ export declare const reverseTransitionType: (type: TransitionType) => TransitionType;
55
+ /** How far the outgoing root has grown when a zoom-through ends, and the incoming root's start scale. */
56
+ export declare const ZOOM_OUT_SCALE = 2.5;
57
+ export declare const ZOOM_IN_SCALE = 0.85;
58
+ /** How long a whip's streak is at its fastest, as a share of the stage's width. */
59
+ export declare const WHIP_SMEAR = 0.22;
60
+ /**
61
+ * A whip pan's streak at `p`: none at either end, longest half-way, where the pan is fastest (its travel follows the
62
+ * transition's curve, and a curve that eases in and out is quickest in the middle).
63
+ */
64
+ export declare const whipSmear: (p: number, width: number) => number;
65
+ /** The transition's centre in world coordinates. */
66
+ export declare function transitionCenter(stage: Stage, params?: TransitionParams): {
67
+ x: number;
68
+ y: number;
69
+ };
70
+ /** The radius that covers the whole stage from `c`: its farthest corner. */
71
+ export declare function coverRadius(stage: Stage, c: {
72
+ x: number;
73
+ y: number;
74
+ }): number;
75
+ /**
76
+ * The roots for `a` giving way to `b` at `progress` (0: all `a`, 1: all `b`), bottom to top. Old prototype types keep
77
+ * exactly the placements they always had (a destination slides by its own width, a push moves both, a move-out
78
+ * slides the source off a destination that stays put); the new ones:
79
+ * - CIRCLE_WIPE: `b` over `a`, inside a circle about the centre growing to cover the stage;
80
+ * - IRIS: `a` over `b`, inside a circle shrinking onto the centre;
81
+ * - ZOOM_THROUGH: `a` scales up about the centre and fades, over `b` settling from slightly small.
82
+ * A cut shows `b`. Smart animate places `b` where `a` is: its layers are matched by the caller.
83
+ */
84
+ export declare function transitionRoots(type: TransitionType, progress: number, a: TransitionSide, b: TransitionSide, stage: Stage, params?: TransitionParams): RenderRoot[];
85
+ /** Whether a root draws anything: faded out entirely, or clipped to nothing, it does not. */
86
+ export declare const rootShows: (r: RenderRoot) => boolean;
87
+ /** A frame's world box by its centre (a top-level frame's placement), for prototype transitions. */
88
+ export interface PlacedFrame {
89
+ id: string;
90
+ width: number;
91
+ height: number;
92
+ cx: number;
93
+ cy: number;
94
+ }
95
+ /**
96
+ * A prototype navigation's roots: the destination is drawn where the source is (its centre on the source's), and
97
+ * the transition plays over the source's box.
98
+ */
99
+ export declare function prototypeTransitionRoots(type: TransitionType, progress: number, source: PlacedFrame, dest: PlacedFrame, params?: TransitionParams): RenderRoot[];
@@ -0,0 +1,12 @@
1
+ import type { Color, MotionValue } from '../document/types.js';
2
+ import type { ValueType } from './properties.js';
3
+ export declare const lerpNumber: (a: number, b: number, e: number) => number;
4
+ export declare const lerpColor: (a: Color, b: Color, e: number) => Color;
5
+ /** Discrete values change when the segment ends. */
6
+ export declare const holdValue: <T>(a: T, b: T, e: number) => T;
7
+ export declare const isColor: (v: unknown) => v is Color;
8
+ /** Whether `v` is a value of `type` (finite numbers and color channels only). */
9
+ export declare function isValueOf(type: ValueType, v: unknown): v is MotionValue;
10
+ /** `a` → `b` at eased progress `e`, by value type. Mismatched values hold. */
11
+ export declare function lerpValue(type: ValueType, a: MotionValue, b: MotionValue, e: number): MotionValue;
12
+ export declare function sameValue(a: MotionValue | undefined, b: MotionValue | undefined): boolean;
@@ -0,0 +1,63 @@
1
+ import type { AnyNode, Paint, VideoTransition } from '../document/types.js';
2
+ export declare const MIN_VIDEO_SPEED = 0.25;
3
+ export declare const MAX_VIDEO_SPEED = 4;
4
+ /** `speed` as a clip can hold it: finite, within MIN…MAX, 1 when it is not a number. */
5
+ export declare const clampSpeed: (speed: number | undefined) => number;
6
+ /** A node's paints, whatever its type (every layer that can hold a video fill has `fills`). */
7
+ export declare const fillsOf: (node: AnyNode | undefined) => readonly Paint[];
8
+ /** Whether `p` is a video fill with a file. */
9
+ export declare const isVideoPaint: (p: Paint | undefined) => p is Paint & {
10
+ videoHash: string;
11
+ };
12
+ /** The index of the layer's first video fill with a file (the one its clip is), or −1. */
13
+ export declare const videoFillIndex: (node: AnyNode | undefined) => number;
14
+ /** Ids of the layers with a video fill (memoised along edits: lib/document/node-delta.ts). */
15
+ export declare const videoNodeIds: (nodes: Record<string, AnyNode>) => readonly string[];
16
+ /** Source ms a video fill shows at layer time `t` ms (before looping). */
17
+ export declare const sourceMsAt: (p: Pick<Paint, "videoIn" | "videoSpeed">, t: number) => number;
18
+ /**
19
+ * The source second shown at layer time `t` ms: wrapped by the file's length when it loops, else held on its last
20
+ * frame (and never before 0). `durationS` unknown (not loaded yet): unwrapped.
21
+ */
22
+ export declare function sourceSecondAt(p: Pick<Paint, 'videoIn' | 'videoSpeed' | 'videoLoop'>, t: number, durationS?: number): number;
23
+ /** A video layer as a clip on `frameId`'s timeline (`duration` ms long). */
24
+ export interface VideoClip {
25
+ nodeId: string;
26
+ /** Which of its fills is the video. */
27
+ fill: number;
28
+ paint: Paint & {
29
+ videoHash: string;
30
+ };
31
+ /** The bar, frame ms. */
32
+ start: number;
33
+ end: number;
34
+ /** Frame ms where the layer's own time is 0 (its offsets and staggers). */
35
+ zero: number;
36
+ speed: number;
37
+ /** Source ms at the bar's start and end (unwrapped). */
38
+ in: number;
39
+ out: number;
40
+ }
41
+ /** `id` as a clip on `frameId`'s timeline, or null when it has no video fill. */
42
+ export declare function videoClipOf(nodes: Record<string, AnyNode>, id: string, frameId: string, duration: number): VideoClip | null;
43
+ /** `node` with its fill `index` patched (the same node when nothing changes). */
44
+ export declare function withVideoPaint(node: AnyNode, index: number, patch: Partial<Paint>): AnyNode;
45
+ /** The video transitions, in menu order. */
46
+ export declare const VIDEO_TRANSITIONS: readonly ["DISSOLVE", "DIP_BLACK", "DIP_WHITE"];
47
+ /**
48
+ * `node` (its fills `fills`) `into` ms into its transition in: a cross-dissolve fades it in over what is under it
49
+ * (its opacity p — over an opaque clip below that is exactly A·(1−p) + B·p); a dip covers what is under it with the
50
+ * colour over the first half and uncovers itself from the colour over the second.
51
+ */
52
+ export declare function transitionPose(node: AnyNode, fills: Paint[], tr: VideoTransition, into: number): {
53
+ node: AnyNode;
54
+ fills: Paint[];
55
+ };
56
+ /**
57
+ * Tell every video layer under `frameId` which source second it shows at frame time `time`: each posed copy (in
58
+ * `patches`, or a new one there) has `videoTime` on its video fills, which the renderer seeks or steers its decoder
59
+ * to (lib/engine/video-texture.ts), and a clip inside its transition in is drawn part way through it. A layer outside
60
+ * its span is left hidden, and so is one before its own start (a clip is on screen over its bar only); a PAUSED video
61
+ * keeps its poster.
62
+ */
63
+ export declare function poseVideoTimes(nodes: Record<string, AnyNode>, frameId: string, time: number, patches: Record<string, AnyNode>): void;
@@ -0,0 +1,50 @@
1
+ import type { DocumentKind, Unit } from '../document/types.js';
2
+ export type PresetCategory = 'PRINT' | 'SOCIAL' | 'PRESENTATION' | 'WEB' | 'APP' | 'EMAIL';
3
+ export interface PagePreset {
4
+ id: string;
5
+ name: string;
6
+ category: PresetCategory;
7
+ width: number;
8
+ height: number;
9
+ unit: Unit;
10
+ /** Bleed on every side, in `unit` (print only). */
11
+ bleed?: number;
12
+ /** Safe margin on every side, in `unit`. */
13
+ margin?: number;
14
+ dpi?: number;
15
+ /** Fold positions as fractions of the width (X) or height (Y): a tri-fold is `{ axis: 'X', at: [1/3, 2/3] }`. */
16
+ folds?: {
17
+ axis: 'X' | 'Y';
18
+ at: number[];
19
+ };
20
+ /**
21
+ * This size is N pages of another preset printed side by side on one sheet — a comic spread is two
22
+ * comic pages, a cover wrap is the back and front cover. It is what lets an export cut the sheet back
23
+ * into single pages, which is how almost every printer wants the file.
24
+ *
25
+ * A folding sheet is NOT this: a tri-fold brochure has fold lines but it is one sheet, one page, and
26
+ * splitting it would be wrong. Only say `sheetOf` when the sheet really carries separate pages.
27
+ */
28
+ sheetOf?: {
29
+ presetId: string;
30
+ across: number;
31
+ };
32
+ /** The `PageNode.prototypeDevice` id this screen size corresponds to. */
33
+ prototypeDevice?: string;
34
+ }
35
+ export declare const PAGE_PRESETS: readonly PagePreset[];
36
+ export declare const PRESET_CATEGORIES: {
37
+ id: PresetCategory;
38
+ label: string;
39
+ }[];
40
+ export declare const presetById: (id: string | undefined) => PagePreset | undefined;
41
+ export declare const presetsFor: (category: PresetCategory) => PagePreset[];
42
+ /** The preset's page size and bleed/margin in px. */
43
+ export declare function presetPx(preset: PagePreset): {
44
+ width: number;
45
+ height: number;
46
+ bleed: number;
47
+ margin: number;
48
+ };
49
+ /** Which document kind a preset category starts. */
50
+ export declare const kindForCategory: (category: PresetCategory) => DocumentKind;
@@ -0,0 +1,4 @@
1
+ /** cyrb53-style 64-bit hash over bytes, run twice with different seeds → 32 hex chars. */
2
+ export declare function hashBytesSync(bytes: Uint8Array): string;
3
+ /** SHA-256 prefix (32 hex) — the hash used for stored video files. */
4
+ export declare function sha256Prefix(bytes: Uint8Array): Promise<string>;
@@ -0,0 +1,2 @@
1
+ /** Every media hash `value` references (image fills, raster tiles, video fills, a composition's audio clips). */
2
+ export declare function mediaHashes(value: unknown): string[];
@@ -0,0 +1,70 @@
1
+ import { type MediaSource } from '../media-library/types.js';
2
+ /** Where an audio file's waveform peaks are cached beside it (lib/motion/audio-peaks-store.ts). */
3
+ export declare const peaksKey: (hash: string) => string;
4
+ export declare function hashBytes(buf: ArrayBuffer): Promise<string>;
5
+ /** Record where `hash` came from — once: a known origin is never replaced (the first maker of the bytes wins). */
6
+ export declare function setMediaSource(hash: string, source: MediaSource | null | undefined): Promise<void>;
7
+ /** Where `hash` came from, when this device recorded it. */
8
+ export declare function getMediaSource(hash: string): Promise<MediaSource | null>;
9
+ /** Store a media file; returns its content hash. `source` records where it came from (made by AI, uploaded, stock). */
10
+ export declare function putMedia(file: Blob, opts?: {
11
+ source?: MediaSource | null;
12
+ }): Promise<string>;
13
+ export declare function setRemoteMediaResolver(fn: ((hash: string) => Promise<Blob | null>) | null): void;
14
+ /** Whether this device holds the bytes for `hash` (never asks the server). */
15
+ export declare function hasLocalMedia(hash: string): Promise<boolean>;
16
+ /** How long the cloud and the shipped media are each waited for before the next source is tried (ms). */
17
+ export declare const MEDIA_FETCH_TIMEOUT_MS = 8000;
18
+ /** Where PopCraft's own template media are published: public, content-addressed files (lib/templates/use.ts). */
19
+ export declare const SHIPPED_MEDIA_PATH = "/templates/media/";
20
+ /**
21
+ * Drop this device's copy of `hash` when it is not the file the hash names (empty, cut short, other bytes), so the
22
+ * next read fetches it again. True when a copy was dropped. A copy that is the right file is kept, however it fails
23
+ * to decode: that is the file's own problem, and fetching it again would not change it.
24
+ */
25
+ export declare function dropCorruptMedia(hash: string): Promise<boolean>;
26
+ /**
27
+ * The bytes of media `hash`: this device's copy, else the app's shipped template media (public, hash-checked and
28
+ * needing no sign-in, so it goes first), else the cloud's copy for the open file. Each source is waited for at most
29
+ * `MEDIA_FETCH_TIMEOUT_MS`. A cloud request that stalls (a token refresh that never returns, a hung request) used to
30
+ * hold up the file for ever, and every audio-reactive layer read 0 with no error. Null when no source has it.
31
+ */
32
+ export declare function getMediaBlob(hash: string): Promise<Blob | null>;
33
+ /** A (cached) object URL for a stored media blob, or null if the hash is unknown. */
34
+ export declare function getMediaUrl(hash: string): Promise<string | null>;
35
+ export declare function deleteMedia(hash: string): Promise<void>;
36
+ export declare const MEDIA_SCHEME = "media://";
37
+ export declare function isMediaUrl(u: string): boolean;
38
+ export declare function isMediaUrl(u: unknown): u is string;
39
+ /** Intern an image data URL; returns its `media://` reference (the input unchanged if undecodable). `source` as `putMedia`. */
40
+ export declare function internDataUrl(dataUrl: string, source?: MediaSource | null): string;
41
+ /** Intern raw bytes (e.g. an encoded PNG tile); returns its `media://` reference. */
42
+ export declare function internBytes(bytes: Uint8Array, type: string): string;
43
+ /**
44
+ * Take media a collaborator sent over the live session (lib/collab/protocol.ts MSG_MEDIA): kept in memory and
45
+ * IndexedDB like any local media, so the node that references it — arriving right after — draws at once. Only bytes
46
+ * that are that hash are kept.
47
+ */
48
+ export declare function putReceivedMedia(hash: string, type: string, bytes: Uint8Array): boolean;
49
+ /** The blob behind a media ref (memory first, then IndexedDB). */
50
+ export declare function loadMediaBlob(ref: string): Promise<Blob | null>;
51
+ /** The data URL a media ref was interned from this session, if any (cache-key aliasing). */
52
+ export declare function mediaSourceAlias(ref: string): string | undefined;
53
+ /** Object URL for a media ref if its bytes are already in memory; null otherwise. */
54
+ export declare function resolveMediaUrlSync(ref: string): string | null;
55
+ /** Object URL for a media ref, loading it from IndexedDB if needed (null if unknown). */
56
+ export declare function loadMediaUrl(ref: string): Promise<string | null>;
57
+ /** Any image reference → something `<img src>` / fetch can use (media refs resolve to object URLs). */
58
+ export declare function resolveImageSrc(url: string | null | undefined): Promise<string | null>;
59
+ /** Media ref → self-contained data URL (for exports that leave this browser). */
60
+ export declare function mediaToDataUrl(ref: string): Promise<string | null>;
61
+ /** Media hashes one node references (image refs, raster tiles, video fills) — a field walk, no serialization. */
62
+ export declare function nodeMediaHashes(node: object): string[];
63
+ /**
64
+ * Replace image data URLs in `nodes` with media refs. Only nodes whose object identity differs from
65
+ * `prevNodes` are inspected (the store is immutable), so this is cheap to run on every change.
66
+ * Returns the same object when nothing changed.
67
+ */
68
+ export declare function internNodeMedia<T extends Record<string, unknown>>(nodes: T, prevNodes?: T | null, changed?: readonly string[] | null): T;
69
+ /** Replace media refs with data URLs throughout a node map (async; for portable exports). */
70
+ export declare function embedNodeMedia<T extends Record<string, unknown>>(nodes: T): Promise<T>;
@@ -0,0 +1,38 @@
1
+ import type { Document } from '../document/types.js';
2
+ import type { Template, TemplateVariant } from './types.js';
3
+ export declare const variantOf: (t: Template, sizeId?: string) => TemplateVariant;
4
+ /**
5
+ * Insert a fragment (or one variant of any template) centred at (cx, cy) on `parentId`.
6
+ * Returns the new document and the inserted roots' ids.
7
+ */
8
+ export declare function insertFragment(doc: Document, t: Template, parentId: string, cx: number, cy: number, sizeId?: string): {
9
+ document: Document;
10
+ rootIds: string[];
11
+ };
12
+ /**
13
+ * Insert the subtrees at `rootIds` of a payload (a template's, or any document's nodes and records) under `parentId`,
14
+ * every root offset by (ox, oy), with fresh ids throughout and the payload's styles, variables and libraries merged
15
+ * in. The roots keep their places relative to each other. Returns the new document and the inserted roots' ids.
16
+ */
17
+ export declare function insertRoots(doc: Document, t: Pick<Template, 'payload'>, rootIds: readonly string[], parentId: string, ox: number, oy: number): {
18
+ document: Document;
19
+ rootIds: string[];
20
+ };
21
+ /**
22
+ * Several groups of roots from one payload, each at its own offset, inserted with ONE id map: an instance in one group
23
+ * keeps pointing at its component in another (two separate inserts would give the component two different new ids).
24
+ */
25
+ export declare function insertRootGroups(doc: Document, t: Pick<Template, 'payload'>, groups: readonly {
26
+ rootIds: readonly string[];
27
+ ox: number;
28
+ oy: number;
29
+ }[], parentId: string): {
30
+ document: Document;
31
+ rootIds: string[];
32
+ };
33
+ /**
34
+ * A new document from a template: one canvas page per template page (one page for a fragment), settings
35
+ * from the chosen size's page preset, styles and variables carried over. When the template offers several
36
+ * sizes, only the chosen (default: first) size's roots are placed.
37
+ */
38
+ export declare function documentFromTemplate(t: Template, name?: string, sizeId?: string): Document;
@@ -0,0 +1,25 @@
1
+ import type { AnyNode, Document, DocumentKind } from '../document/types.js';
2
+ import type { Template, TemplateMeta } from './types.js';
3
+ type MetaInput = Pick<TemplateMeta, 'name'> & Partial<Omit<TemplateMeta, 'name' | 'schema' | 'createdAt' | 'updatedAt'>>;
4
+ /** Family names every TEXT node in `nodes` uses, so a use can load them first. */
5
+ export declare function fontsIn(nodes: Record<string, AnyNode>): string[];
6
+ export declare function makeMeta(input: MetaInput, kind: DocumentKind, nodes: Record<string, AnyNode>, variables?: Document['variables'], styles?: Document['styles']): TemplateMeta;
7
+ /**
8
+ * Capture the selected top-level nodes (and everything under them) as a fragment template. Roots are
9
+ * re-based so the fragment's top-left is the origin; connectors and nested instances keep their links
10
+ * because ids are copied as-is (they are remapped on insert).
11
+ */
12
+ export declare function templateFromSelection(doc: Document, ids: string[], meta: MetaInput): Template | null;
13
+ /**
14
+ * The whole document as a template: pages keep their roots, and roots are grouped into size variants by the
15
+ * page preset they are sized as (a deck is one variant with N slides; a post + story set is two variants).
16
+ *
17
+ * `sequence` says the sheets are ONE ordered document rather than alternative sizes — a comic issue whose
18
+ * centrefold is a double-width sheet, an email with a phone version. Without it those odd sheets are read
19
+ * as another size to choose between, and applying the template silently drops them.
20
+ */
21
+ export declare function templateFromDocument(doc: Document, meta: MetaInput, o?: {
22
+ sequence?: boolean;
23
+ breakpoints?: boolean;
24
+ }): Template;
25
+ export {};
@@ -0,0 +1,82 @@
1
+ import type { DocumentKind } from '../document/types.js';
2
+ import { type PagePreset } from '../presets/page-presets.js';
3
+ export declare const TEMPLATE_GROUP_IDS: readonly ["print", "comic", "social", "slides", "web", "app", "game", "email", "motion", "board"];
4
+ export type TemplateGroupId = typeof TEMPLATE_GROUP_IDS[number];
5
+ export interface TemplateType {
6
+ /** What `meta.category` stores. */
7
+ id: string;
8
+ label: string;
9
+ /** The kinds a template of this type may be. */
10
+ kinds: readonly DocumentKind[];
11
+ }
12
+ export interface TemplateGroup {
13
+ id: TemplateGroupId;
14
+ label: string;
15
+ /** One line under the group's heading. */
16
+ hint: string;
17
+ /** Kinds whose templates sit here unless their type claims them for another group. */
18
+ home: readonly DocumentKind[];
19
+ /** The types a template in this group may be (at least one). */
20
+ types: readonly TemplateType[];
21
+ /** The page sizes New file offers in this group, in order (ids from lib/presets/page-presets.ts). */
22
+ presets: readonly string[];
23
+ /** Other words that find this group in search, and old names a link or a query may still use. */
24
+ keywords: readonly string[];
25
+ }
26
+ export declare const TEMPLATE_GROUPS: readonly TemplateGroup[];
27
+ /** New file under All: one row of the sizes most files start at, not every size there is (search still finds them). */
28
+ export declare const COMMON_PRESETS: string[];
29
+ /** Old names for a group — the rail's former sections, and what a bookmarked link or a query may say. */
30
+ export declare const GROUP_ALIASES: Readonly<Record<string, TemplateGroupId>>;
31
+ /** `id` (or an alias of one) as a group, or undefined. */
32
+ export declare function templateGroup(id: string | null | undefined): TemplateGroup | undefined;
33
+ /** Every type in the model. */
34
+ export declare const TEMPLATE_TYPES: readonly (TemplateType & {
35
+ group: TemplateGroupId;
36
+ })[];
37
+ /** The group a template of `kind` and type `category` sits in. Every kind has a home, so this always answers. */
38
+ export declare function groupOf(kind: DocumentKind | string, category: string | null | undefined): TemplateGroupId;
39
+ /** Types a template of `kind` may be (what the build and the save dialog accept). */
40
+ export declare const typesForKind: (kind: DocumentKind | string) => TemplateType[];
41
+ /** A type's label; a category from before the model reads as itself, sentence-cased. */
42
+ export declare function typeLabel(category: string | null | undefined): string;
43
+ /**
44
+ * The type a template of `kind` is filed as: `category` when the model allows it for that kind, else the first type
45
+ * of the kind's home group. What a saved template is normalised to, so nothing new lands outside the model.
46
+ */
47
+ export declare function normalizeType(kind: DocumentKind | string, category: string | null | undefined): string;
48
+ /**
49
+ * What "in group g" means as data, for a query: a template is in g when ANY clause matches, and a clause matches
50
+ * when the kind is one of `kinds`, and the category is one of `categories` (when given) and none of `exclude`.
51
+ *
52
+ * - one clause per type of g: its kinds, that category;
53
+ * - one per home kind: that kind, minus every type another group claims for it.
54
+ *
55
+ * `matchesClauses` is the same test in memory; the tests hold it equal to `groupOf`.
56
+ */
57
+ export interface GroupClause {
58
+ kinds: DocumentKind[];
59
+ categories?: string[];
60
+ exclude?: string[];
61
+ }
62
+ export declare function groupClauses(id: TemplateGroupId): GroupClause[];
63
+ export declare const matchesClauses: (clauses: GroupClause[], kind: string, category: string) => boolean;
64
+ /** The page sizes a group offers, as presets. */
65
+ export declare const groupPresets: (id: TemplateGroupId) => PagePreset[];
66
+ /** Per-group and per-type counts from `(kind, category, count)` rows, as the rail and the type filter show them. */
67
+ export declare function groupCounts(rows: readonly {
68
+ kind: string;
69
+ category: string;
70
+ count: number;
71
+ }[]): {
72
+ group: TemplateGroupId;
73
+ count: number;
74
+ types: {
75
+ category: string;
76
+ count: number;
77
+ }[];
78
+ }[];
79
+ /** Where a template sits, as a badge says it: "Print · Poster", "Motion", "Web · Components". */
80
+ export declare function placeLabel(kind: DocumentKind | string, category: string | null | undefined): string;
81
+ /** Does `q` name a group (its label, a keyword, or an alias)? Search uses it to widen a query to the whole group. */
82
+ export declare function groupForQuery(q: string): TemplateGroupId | undefined;
@@ -0,0 +1,20 @@
1
+ import type { Document } from '../document/types.js';
2
+ import type { TemplatePayload } from './types.js';
3
+ export declare function settleLayout(doc: Document): Document;
4
+ /**
5
+ * `settleLayout` over the words as the canvas shows them: tokens swapped for their fields while it measures, then
6
+ * put back — in texts, and in the text properties an instance fills its component with (a name tag reading
7
+ * `{{brand.name}}`). Measuring the token itself sized a hugging pill to the fourteen characters of `{{brand.title}}`.
8
+ */
9
+ export declare function settleShownLayout(doc: Document): Document;
10
+ /**
11
+ * Every text re-measured at its shown words, and the layout settled around them, until no text changes size: a
12
+ * taller text moves everything after it, and a text whose box width the layout changed wraps again at that width.
13
+ * What the template kit bakes a design with, and what a fixture migration bakes an edited one with.
14
+ */
15
+ export declare function settleMeasuredLayout(doc: Document): Document;
16
+ /**
17
+ * A template payload's layout baked again, after an edit to its frozen nodes (a fixture migration): texts are
18
+ * re-measured at their own sizes and shown words, since auto layout sizes a hugging text from the box it already has.
19
+ */
20
+ export declare function settlePayload(payload: TemplatePayload): TemplatePayload;
@@ -0,0 +1,59 @@
1
+ import '../document/auto-layout.js';
2
+ import '../document/scene-graph.js';
3
+ import type { AnyNode, DocumentKind } from '../document/types.js';
4
+ export { contrastRatio, luminance, over } from '../document/color.js';
5
+ /** WCAG "large text": 18 pt, or 14 pt bold — 24 px, or 18.67 px at weight 700 and up. */
6
+ export declare const isLargeText: (fontSize: number, fontWeight: number) => boolean;
7
+ /** AA: 4.5 for body text, 3 for large text. */
8
+ export declare const requiredContrast: (fontSize: number, fontWeight: number) => number;
9
+ /**
10
+ * The smallest type a kind may set, in document px (1/96 in). Print's floor is 8 px, which is 6 pt: below that
11
+ * a press fills the counters in. Screens get 12 px. Social posts are read on a phone after the network has
12
+ * scaled a 1080 px sheet to about a third, so 16 px is where a caption stops being a smear.
13
+ */
14
+ export declare const MIN_TEXT_PX: Record<DocumentKind, number>;
15
+ /**
16
+ * How far inside the trim printed text has to stay: 1/8 in (12 px), the tolerance a guillotine cuts to — the
17
+ * same distance the bleed runs outside it.
18
+ */
19
+ export declare const PRINT_SAFE_INSET_PX = 12;
20
+ export interface PaintedText {
21
+ /** The text's id (a virtual `instance::child` id inside an instance or a master). */
22
+ id: string;
23
+ name: string;
24
+ characters: string;
25
+ fontSize: number;
26
+ fontWeight: number;
27
+ /** Box in root space. */
28
+ x: number;
29
+ y: number;
30
+ width: number;
31
+ height: number;
32
+ /** The worst contrast over every colour the text and its backdrop can take. */
33
+ contrast: number;
34
+ /** What AA asks of text this size. */
35
+ required: number;
36
+ /** The node whose paint is directly under the text's centre (the ground it is read against), if any. */
37
+ groundId?: string;
38
+ }
39
+ /** The scope a template (or a document) is read in: its nodes plus what resolves brand tokens and styles. */
40
+ export interface PaintScope {
41
+ nodes: Record<string, AnyNode>;
42
+ variables?: Record<string, unknown>;
43
+ variableCollections?: Record<string, unknown>;
44
+ styles?: Record<string, unknown>;
45
+ }
46
+ /**
47
+ * Every text a variant's roots draw, with the worst contrast it can have against its real backdrop. Hidden layers and
48
+ * empty text are skipped; so is text on a picture (an IMAGE layer or an image fill under it), which only the
49
+ * person placing the picture can judge. Layers are placed as they are drawn: scaled by their own scale (about its
50
+ * anchor) and their ancestors'.
51
+ */
52
+ export declare function paintedTexts(scope: PaintScope, rootIds: readonly string[]): PaintedText[];
53
+ /** The texts that fail AA, as a readable summary — what a practices test prints when it fails. */
54
+ export declare const contrastFailures: (texts: readonly PaintedText[]) => {
55
+ text: string;
56
+ size: number;
57
+ contrast: number;
58
+ required: number;
59
+ }[];
@@ -0,0 +1,34 @@
1
+ import type { Document } from '../document/types.js';
2
+ export interface ResizeTarget {
3
+ width: number;
4
+ height: number;
5
+ presetId?: string;
6
+ }
7
+ export declare const resizeTargetFromPreset: (presetId: string) => ResizeTarget | null;
8
+ /**
9
+ * The copy's motion, re-measured against the source's. `content` is how much the content itself was scaled
10
+ * (the uniform factor, or 1 when it reflowed); `dx`/`dy` are the offsets the uniform branch centred the
11
+ * root's children by, which absolute x/y keys on those children need too.
12
+ */
13
+ export declare function resizeMotion(before: Document, srcRootId: string, after: Document, copyRootId: string, content: number, offset?: {
14
+ dx: number;
15
+ dy: number;
16
+ }): Document;
17
+ export interface ResizeResult {
18
+ document: Document;
19
+ id: string | null;
20
+ /** How much the content itself was scaled (1 when it reflowed at its own size), and where it was centred. */
21
+ content: number;
22
+ offset: {
23
+ dx: number;
24
+ dy: number;
25
+ };
26
+ }
27
+ /**
28
+ * Add a resized copy of `rootId` beside it (returns the copy's id). `name` defaults to the preset's name.
29
+ * `motion: false` leaves the copy's keys as the source's, for a caller that changes the copy's layout further
30
+ * and re-measures the motion against the final result itself (`resizeMotion`, with `content` and `offset`).
31
+ */
32
+ export declare function magicResize(doc: Document, rootId: string, target: ResizeTarget, name?: string, o?: {
33
+ motion?: boolean;
34
+ }): ResizeResult;