@flatkit/types 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zwyk Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,501 @@
1
+ type Point = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ /** A closed ring (the closing point is not duplicated). */
6
+ type Polygon = Point[];
7
+ /** Axis-aligned bounding box (alignment, snapping, marquee hit-test). */
8
+ type BBox = {
9
+ minX: number;
10
+ minY: number;
11
+ maxX: number;
12
+ maxY: number;
13
+ };
14
+
15
+ type ExprContext = Record<string, number | number[] | ((...a: number[]) => number) | Record<string, number>>;
16
+ type Transform = {
17
+ a: number;
18
+ b: number;
19
+ c: number;
20
+ d: number;
21
+ e: number;
22
+ f: number;
23
+ };
24
+ /** A segment: an anchor point plus optional tangent handles (absolute coordinates). */
25
+ type Seg = {
26
+ anchor: Point;
27
+ inHandle?: Point;
28
+ outHandle?: Point;
29
+ };
30
+ /** A subpath: a sequence of segments, open or closed. */
31
+ type Subpath = {
32
+ closed: boolean;
33
+ segments: Seg[];
34
+ };
35
+ /** A path: a set of subpaths (contour + holes, multi-piece). */
36
+ type Path = {
37
+ subpaths: Subpath[];
38
+ };
39
+ /** A closed ring, closing point not duplicated. */
40
+ type Ring = Point[];
41
+ /** A connected polygon: [contour, ...holes]. */
42
+ type PolyGroup = Ring[];
43
+ /** A "material": a set of disjoint polygons (multipolygon). */
44
+ type Shape = PolyGroup[];
45
+ type Stop = {
46
+ offset: number;
47
+ color: string;
48
+ };
49
+ /** A Flash-style "tint" color effect: recolors a container toward `color` by `amount` (0..1). */
50
+ type Tint = {
51
+ color: string;
52
+ amount: number;
53
+ };
54
+ /** Blend mode (Flash / After Effects style). `add`/`screen` = additive light (glow, mixing); `multiply` = shadow. */
55
+ type BlendMode = 'add' | 'screen' | 'multiply';
56
+ type Paint = {
57
+ type: 'solid';
58
+ color: string;
59
+ } | {
60
+ type: 'linear';
61
+ angle: number;
62
+ stops: Stop[];
63
+ box?: BBox;
64
+ } | {
65
+ type: 'radial';
66
+ cx: number;
67
+ cy: number;
68
+ r: number;
69
+ stops: Stop[];
70
+ box?: BBox;
71
+ };
72
+ /** A region stroke: width + paint (solid OR gradient), cap/join style, dashes. */
73
+ type Stroke = {
74
+ width: number;
75
+ paint: Paint;
76
+ cap?: 'butt' | 'round' | 'square';
77
+ join?: 'miter' | 'round' | 'bevel';
78
+ miterLimit?: number;
79
+ dash?: number[];
80
+ };
81
+ type Filter = {
82
+ type: 'blur';
83
+ radius: number;
84
+ } | {
85
+ type: 'shadow';
86
+ dx: number;
87
+ dy: number;
88
+ blur: number;
89
+ color: string;
90
+ } | {
91
+ type: 'glow';
92
+ blur: number;
93
+ color: string;
94
+ } | {
95
+ type: 'adjust';
96
+ brightness?: number;
97
+ contrast?: number;
98
+ saturate?: number;
99
+ hue?: number;
100
+ };
101
+ /** Easing curve. `cubic` = control points, CSS cubic-bezier style. */
102
+ type Easing = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | {
103
+ cubic: [number, number, number, number];
104
+ };
105
+ /** Spin direction of a tween (absent = shortest arc). */
106
+ type SpinDir = 'cw' | 'ccw';
107
+ type Keyframe = {
108
+ frame: number;
109
+ transform?: Transform;
110
+ opacity?: number;
111
+ color?: string;
112
+ paint?: Paint;
113
+ tint?: Tint;
114
+ visible?: boolean;
115
+ easing?: Easing;
116
+ rotate?: SpinDir;
117
+ turns?: number;
118
+ };
119
+ /** Channels animatable by expression (= the decomposed components + opacity). */
120
+ type ExprChannel = 'x' | 'y' | 'scaleX' | 'scaleY' | 'rotation' | 'opacity';
121
+ type TimelineTrack = {
122
+ id: string;
123
+ targetId: string;
124
+ keyframes: Keyframe[];
125
+ /** Per-channel expressions (`rotation = sin(time)*20`); take priority over interpolation. */
126
+ expressions?: Partial<Record<ExprChannel, string>>;
127
+ };
128
+ /** Audio clip placed on the timeline: references an asset, starts at `startFrame`. */
129
+ type SoundClip = {
130
+ id: string;
131
+ assetId: string;
132
+ startFrame: number;
133
+ gain?: number;
134
+ loop?: boolean;
135
+ name?: string;
136
+ };
137
+ /** A CONTENT (material) keyframe — frame-by-frame / stop-motion: a snapshot of the drawing. */
138
+ type ContentKey = {
139
+ frame: number;
140
+ items: Region[];
141
+ };
142
+ /** Content track of a material layer (frame-by-frame animation, no interpolation). */
143
+ type ContentTrack = {
144
+ layerId: string;
145
+ keyframes: ContentKey[];
146
+ };
147
+ type Timeline = {
148
+ fps: number;
149
+ durationFrames: number;
150
+ tracks: TimelineTrack[];
151
+ /** Frame-by-frame material animation (per layer); HOLD, never tweened. */
152
+ contentTracks?: ContentTrack[];
153
+ sounds?: SoundClip[];
154
+ labels?: FrameLabel[];
155
+ frameActions?: FrameAction[];
156
+ onLoad?: Action[];
157
+ onEnterFrame?: Action[];
158
+ binds?: InstanceBind[];
159
+ };
160
+ /** Collective binding rule: binds ALL instances of a symbol, with a per-instance index.
161
+ * `each "<symbol>" as <as> { opacity = data[i] … }` — the player expands it on load. */
162
+ type InstanceBind = {
163
+ symbol: string;
164
+ as: string;
165
+ expr: Partial<Record<ExprChannel, string>>;
166
+ };
167
+ type PlaybackMode = 'synced' | 'singleFrame' | 'independent';
168
+ type InstancePlayback = {
169
+ mode: PlaybackMode;
170
+ frame?: number;
171
+ speed?: number;
172
+ loop?: boolean;
173
+ };
174
+ /**
175
+ * Payload of a `send`: numeric (DSL expression) or textual (`text("itemId")`, the live content of a
176
+ * Text item). Discriminated for an exact parse/print round-trip.
177
+ */
178
+ type SendPayload = {
179
+ kind: 'expr';
180
+ expr: string;
181
+ } | {
182
+ kind: 'text';
183
+ itemId: string;
184
+ };
185
+ type Action = {
186
+ do: 'play';
187
+ } | {
188
+ do: 'pause';
189
+ } | {
190
+ do: 'gotoFrame';
191
+ frame: number;
192
+ play?: boolean;
193
+ } | {
194
+ do: 'gotoLabel';
195
+ label: string;
196
+ play?: boolean;
197
+ } | {
198
+ do: 'setVar';
199
+ name: string;
200
+ value: string;
201
+ } | {
202
+ do: 'setIndex';
203
+ name: string;
204
+ index: string;
205
+ value: string;
206
+ } | {
207
+ do: 'if';
208
+ cond: string;
209
+ then: Action[];
210
+ else?: Action[];
211
+ } | {
212
+ do: 'repeat';
213
+ count: string;
214
+ body: Action[];
215
+ } | {
216
+ do: 'repeatRange';
217
+ var: string;
218
+ from: string;
219
+ to: string;
220
+ body: Action[];
221
+ } | {
222
+ do: 'call';
223
+ name: string;
224
+ args: string[];
225
+ } | {
226
+ do: 'send';
227
+ event: string;
228
+ payload?: SendPayload;
229
+ } | {
230
+ do: 'sound';
231
+ assetId: string;
232
+ };
233
+ /** Reusable function: pure value (usable in an expression) or procedure (action block). */
234
+ type FuncDef = {
235
+ name: string;
236
+ params: string[];
237
+ } & ({
238
+ kind: 'value';
239
+ expr: string;
240
+ } | {
241
+ kind: 'proc';
242
+ body: Action[];
243
+ });
244
+ /** Actions triggered when the playhead reaches `frame`. */
245
+ type FrameAction = {
246
+ frame: number;
247
+ actions: Action[];
248
+ };
249
+ /** Named marker on the timeline (target of gotoLabel). */
250
+ type FrameLabel = {
251
+ frame: number;
252
+ name: string;
253
+ };
254
+ /** Item event: click, hover enter/leave, pointer (press/release/drag/longpress), and `drop`
255
+ * (released over a named zone; requires `over`). */
256
+ type ItemEvent = 'click' | 'enter' | 'leave' | 'press' | 'release' | 'drag' | 'longpress' | 'drop';
257
+ /** Interaction: an event on an item triggers actions (Layer B). `over` = named zone (event `drop`). */
258
+ type Interaction = {
259
+ id: string;
260
+ targetId: string;
261
+ event: ItemEvent;
262
+ over?: string;
263
+ atPointer?: boolean;
264
+ actions: Action[];
265
+ };
266
+ /**
267
+ * "drag" interactor: moves an item with the mouse and writes its position into EXPLICIT variables. A
268
+ * declarative front-end → produces the same mutations as a hand-written handler. `axis`: 'xy' (both),
269
+ * 'x' (dragX), 'y' (dragY). `confine` = name of a zone (clamp to its bbox). `grid` = snap.
270
+ */
271
+ type Interactor = {
272
+ targetId: string;
273
+ axis: 'xy' | 'x' | 'y' | 'turn' | 'trace' | 'reveal' | 'link';
274
+ varX?: string;
275
+ varY?: string;
276
+ varT?: string;
277
+ confine?: string;
278
+ grid?: number;
279
+ enabled?: string;
280
+ pivot?: Point;
281
+ };
282
+ /** Presence + pose of a container at a keyframe (matched by `id` across cels). */
283
+ type Pose = {
284
+ id: string;
285
+ transform?: Transform;
286
+ opacity?: number;
287
+ tint?: Tint;
288
+ spin?: SpinDir;
289
+ turns?: number;
290
+ filters?: Filter[];
291
+ };
292
+ /** Layer-wide keyframe: the full content of the layer at `frame`. */
293
+ type Cel = {
294
+ frame: number;
295
+ poses: Pose[];
296
+ matter?: Region[];
297
+ tween?: boolean;
298
+ shapeTween?: boolean;
299
+ ease?: Easing;
300
+ };
301
+ /** Per-object interaction state exposed to channel expressions as `self.hovered`/`self.grabbed`/`self.pressed` (0/1). */
302
+ type ItemInteractionState = {
303
+ hovered: number;
304
+ grabbed: number;
305
+ pressed: number;
306
+ };
307
+ /** Resolution context (container expressions + guide layer). `itemState` lets channel expressions read the
308
+ * object's own interaction state (`self.hovered`…); the PLAYER provides it, absent elsewhere (flags → 0). */
309
+ type ResolveOpts = {
310
+ fps?: number;
311
+ ctx?: ExprContext;
312
+ guide?: Path;
313
+ orient?: boolean;
314
+ parent?: Transform;
315
+ itemState?: (id: string) => ItemInteractionState | undefined;
316
+ };
317
+ type Region = {
318
+ id: string;
319
+ color: string;
320
+ path: Path;
321
+ paint?: Paint;
322
+ stroke?: Stroke;
323
+ noFill?: boolean;
324
+ xform?: Transform;
325
+ opacity?: number;
326
+ filters?: Filter[];
327
+ hidden?: boolean;
328
+ noHit?: boolean;
329
+ };
330
+ /**
331
+ * GROUP (Ctrl+G, Flash style): a TRANSIENT container — a transform plus its own layers, edited in place
332
+ * (double-click), movable/tweenable as an object on its parent's track. NOT in the library, not reusable,
333
+ * and WITHOUT its own internal timeline: to animate the content, turn it into a SYMBOL (F8 → SymbolDef +
334
+ * Instance). `timeline?` is LEGACY (no longer produced by the editor): kept for reading/rendering old
335
+ * docs, MIGRATED to a symbol on open (cf. liftAnimatedGroups).
336
+ */
337
+ type Group = {
338
+ id: string;
339
+ kind: 'group';
340
+ name: string;
341
+ transform: Transform;
342
+ layers: Layer[];
343
+ timeline?: Timeline;
344
+ opacity?: number;
345
+ tint?: Tint;
346
+ hidden?: boolean;
347
+ noHit?: boolean;
348
+ pivot?: Point;
349
+ filters?: Filter[];
350
+ blend?: BlendMode;
351
+ hitbox?: {
352
+ w: number;
353
+ h: number;
354
+ };
355
+ expressions?: Partial<Record<ExprChannel, string>>;
356
+ };
357
+ /** Instance of a reusable symbol: a transform + a reference to the symbol. */
358
+ type Instance = {
359
+ id: string;
360
+ kind: 'instance';
361
+ name: string;
362
+ transform: Transform;
363
+ symbolId: string;
364
+ opacity?: number;
365
+ tint?: Tint;
366
+ hidden?: boolean;
367
+ noHit?: boolean;
368
+ pivot?: Point;
369
+ playback?: InstancePlayback;
370
+ filters?: Filter[];
371
+ blend?: BlendMode;
372
+ expressions?: Partial<Record<ExprChannel, string>>;
373
+ };
374
+ /**
375
+ * Library folder (pure organization, Flash style): a tree by `parent`. SYMBOLS stay FLAT (referenced by
376
+ * name/id) — a folder does not nest them, it just files them away.
377
+ */
378
+ type Folder = {
379
+ id: string;
380
+ name: string;
381
+ parent?: string;
382
+ collapsed?: boolean;
383
+ };
384
+ /** Reusable definition (Flash MovieClip-style symbol) stored in the library. */
385
+ type SymbolDef = {
386
+ id: string;
387
+ name: string;
388
+ layers: Layer[];
389
+ timeline?: Timeline;
390
+ folderId?: string;
391
+ };
392
+ /**
393
+ * "live" (editable) text: a leaf item animatable like a container (transform/opacity/tint, pivot). LOCAL
394
+ * origin = top-left corner; text flows toward (box.w, box.h). `box` = measured extent (updated by the
395
+ * editor via measureText) → pure bbox/hit without a canvas.
396
+ */
397
+ type Text = {
398
+ id: string;
399
+ kind: 'text';
400
+ name: string;
401
+ transform: Transform;
402
+ content: string;
403
+ font: string;
404
+ size: number;
405
+ align: 'left' | 'center' | 'right';
406
+ lineHeight: number;
407
+ color: string;
408
+ weight?: number;
409
+ italic?: boolean;
410
+ box: {
411
+ w: number;
412
+ h: number;
413
+ };
414
+ wrap?: boolean;
415
+ bind?: string;
416
+ decimals?: number;
417
+ /** `id` explicitly set by the author via `text "…" as "<id>"` (≠ auto-generated id). Drives the
418
+ * printing of `as` in the flatFormat DSL. */
419
+ idExplicit?: boolean;
420
+ opacity?: number;
421
+ tint?: Tint;
422
+ hidden?: boolean;
423
+ noHit?: boolean;
424
+ pivot?: Point;
425
+ filters?: Filter[];
426
+ blend?: BlendMode;
427
+ expressions?: Partial<Record<ExprChannel, string>>;
428
+ };
429
+ /** Bitmap image: a leaf item animatable like text. References an asset; `w`/`h` = intrinsic size in px
430
+ * (local coords, origin = top-left corner). */
431
+ type Image = {
432
+ id: string;
433
+ kind: 'image';
434
+ name: string;
435
+ transform: Transform;
436
+ assetId: string;
437
+ w: number;
438
+ h: number;
439
+ opacity?: number;
440
+ tint?: Tint;
441
+ hidden?: boolean;
442
+ noHit?: boolean;
443
+ pivot?: Point;
444
+ filters?: Filter[];
445
+ blend?: BlendMode;
446
+ expressions?: Partial<Record<ExprChannel, string>>;
447
+ };
448
+ /** Layer content: material, one-off group, symbol instance, text, or image. */
449
+ type Item = Region | Group | Instance | Text | Image;
450
+ /** Embedded asset (media) — the `Doc.assets` registry. `data` = base64 data-URI (media) or raw SVG text ('svg'). */
451
+ type Asset = {
452
+ id: string;
453
+ kind: 'image' | 'audio' | 'video' | 'font' | 'svg';
454
+ name: string;
455
+ mime: string;
456
+ data: string;
457
+ };
458
+ type Layer = {
459
+ id: string;
460
+ name: string;
461
+ visible: boolean;
462
+ locked: boolean;
463
+ opacity: number;
464
+ items: Item[];
465
+ cels?: Cel[];
466
+ isFolder?: boolean;
467
+ parent?: string;
468
+ collapsed?: boolean;
469
+ isMask?: boolean;
470
+ maskOff?: boolean;
471
+ isGuide?: boolean;
472
+ orientToGuide?: boolean;
473
+ };
474
+ type Doc = {
475
+ width: number;
476
+ height: number;
477
+ background?: string;
478
+ layers: Layer[];
479
+ symbols: SymbolDef[];
480
+ folders?: Folder[];
481
+ assets?: Asset[];
482
+ timeline?: Timeline;
483
+ variables?: Record<string, number | number[]>;
484
+ imports?: string[];
485
+ functions?: FuncDef[];
486
+ interactions?: Interaction[];
487
+ interactors?: Interactor[];
488
+ };
489
+ /** Edit-navigation step (breadcrumb): a one-off group or an entry into a symbol. */
490
+ type EditFrame = {
491
+ kind: 'group';
492
+ id: string;
493
+ name: string;
494
+ } | {
495
+ kind: 'symbol';
496
+ symbolId: string;
497
+ name: string;
498
+ };
499
+ type Tool = 'brush' | 'rect' | 'ellipse' | 'eraser' | 'fill' | 'select' | 'transform' | 'text' | 'pan' | 'pen' | 'pathselect' | 'ink';
500
+
501
+ export type { Action, Asset, BBox, BlendMode, Cel, ContentKey, ContentTrack, Doc, Easing, EditFrame, ExprChannel, ExprContext, Filter, Folder, FrameAction, FrameLabel, FuncDef, Group, Image, Instance, InstanceBind, InstancePlayback, Interaction, Interactor, Item, ItemEvent, ItemInteractionState, Keyframe, Layer, Paint, Path, PlaybackMode, Point, PolyGroup, Polygon, Pose, Region, ResolveOpts, Ring, Seg, SendPayload, Shape, SoundClip, SpinDir, Stop, Stroke, Subpath, SymbolDef, Text, Timeline, TimelineTrack, Tint, Tool, Transform };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@flatkit/types",
3
+ "version": "0.1.0",
4
+ "description": "Shared types for the FlatInk format (Doc, Layer, Item, …). The leaf of the dependency graph.",
5
+ "license": "MIT",
6
+ "author": "Zwyk Studio",
7
+ "homepage": "http://flatink.zwyk-studio.com/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/zwykstudio/flatkit.git",
11
+ "directory": "packages/types"
12
+ },
13
+ "bugs": "https://github.com/zwykstudio/flatkit/issues",
14
+ "keywords": [
15
+ "flatink",
16
+ "flatpack",
17
+ "animation",
18
+ "types"
19
+ ],
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "typecheck": "tsc -p tsconfig.json"
39
+ },
40
+ "module": "./dist/index.js"
41
+ }