@pairdraw/kiwi 0.0.0-stage → 0.16.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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +28 -0
  3. package/README.md +112 -2
  4. package/dist/chunks/fig/codec.js +1371 -0
  5. package/dist/chunks/fig/codec.js.map +1 -0
  6. package/dist/fig/codec.d.ts +477 -0
  7. package/dist/fig/codec.js +2 -0
  8. package/dist/fig/container.d.ts +48 -0
  9. package/dist/fig/container.js +2 -0
  10. package/dist/fig/guid.d.ts +13 -0
  11. package/dist/fig/guid.js +31 -0
  12. package/dist/fig/guid.js.map +1 -0
  13. package/dist/fig/parse.d.ts +33 -0
  14. package/dist/fig/parse.js +83 -0
  15. package/dist/fig/parse.js.map +1 -0
  16. package/dist/fig.d.ts +185 -0
  17. package/dist/fig.js +117 -0
  18. package/dist/fig.js.map +1 -0
  19. package/dist/index.d.ts +182 -0
  20. package/dist/page-manifest.d.ts +16 -0
  21. package/dist/schema-runtime.d.ts +2 -0
  22. package/dist/schema-runtime.js +2 -0
  23. package/dist/types.d.ts +26 -0
  24. package/package.json +52 -4
  25. package/src/fig/codec.ts +536 -0
  26. package/src/fig/container.ts +180 -0
  27. package/src/fig/guid.ts +24 -0
  28. package/src/fig/index.ts +5 -0
  29. package/src/fig/page-manifest.ts +149 -0
  30. package/src/fig/parse.ts +136 -0
  31. package/src/fig/protocol.ts +237 -0
  32. package/src/fig/schema/fig.kiwi +5628 -0
  33. package/src/fig/schema.ts +7 -0
  34. package/src/fig/types.ts +25 -0
  35. package/src/fig/variable-bindings.ts +11 -0
  36. package/src/global.d.ts +4 -0
  37. package/src/schema-runtime/bb.ts +284 -0
  38. package/src/schema-runtime/binary.ts +102 -0
  39. package/src/schema-runtime/index.ts +25 -0
  40. package/src/schema-runtime/interpreter.ts +465 -0
  41. package/src/schema-runtime/parser.ts +287 -0
  42. package/src/schema-runtime/schema.ts +24 -0
  43. package/src/schema-runtime/util.ts +10 -0
  44. package/src/schema-runtime/validate.ts +88 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Danila Poyarkov and OpenPencil contributors
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.
package/NOTICE ADDED
@@ -0,0 +1,28 @@
1
+ Kiwi schema runtime
2
+
3
+ Copyright (c) 2016-2023 Evan Wallace
4
+
5
+ This package includes an adapted implementation of the JavaScript Kiwi schema
6
+ runtime from:
7
+
8
+ https://github.com/evanw/kiwi
9
+
10
+ The original implementation is licensed under the MIT License:
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is furnished
17
+ to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,113 @@
1
- # Temporary Holding Version
1
+ # @pairdraw/kiwi
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Scene-graph-agnostic Kiwi runtime utilities for Pairdraw.
4
+
5
+ This package owns pure Kiwi schema parsing, Figma Kiwi schema data, low-level Figma message encode/decode, raw `fig-kiwi` container helpers, and GUID formatting. Complete `.fig` archive parsing lives in `@pairdraw/fig`; SceneGraph integration remains outside this package.
6
+
7
+ ## Credits and licensing
8
+
9
+ The schema runtime is based on [Kiwi](https://github.com/evanw/kiwi), a
10
+ schema-based binary format and JavaScript implementation by Evan Wallace.
11
+ The original Kiwi implementation is copyright (c) 2016–2023 Evan Wallace and
12
+ is licensed under the MIT License. Pairdraw's adapted runtime is distributed
13
+ under the terms of that license; see [`NOTICE`](./NOTICE).
14
+
15
+ ```sh
16
+ bun add @pairdraw/kiwi
17
+ ```
18
+
19
+ ## Package-local checks
20
+
21
+ ```sh
22
+ cd packages/kiwi
23
+ bun run check
24
+ ```
25
+
26
+ Package scripts:
27
+
28
+ - `bun run test` — package-local Bun tests for schema runtime, Figma schema guards, codec, container, parse, GUID, and variable bindings
29
+ - `bun run typecheck` — type-checks `src` and tests
30
+ - `bun run build` — builds the distributable `dist` entrypoints
31
+ - `bun run check` — runs typecheck, tests, and build in sequence
32
+
33
+ ## Schema runtime
34
+
35
+ ```ts
36
+ import { compileSchema, parseSchema, validateSchema } from '@pairdraw/kiwi/schema-runtime'
37
+
38
+ const schema = parseSchema(`
39
+ message Point {
40
+ float x = 1;
41
+ float y = 2;
42
+ }
43
+ `)
44
+
45
+ validateSchema(schema)
46
+ const codec = compileSchema(schema)
47
+ const bytes = codec.encodeMessage({ x: 12, y: 24 })
48
+ const point = codec.decodeMessage(bytes)
49
+ ```
50
+
51
+ ## Figma Kiwi codec
52
+
53
+ ```ts
54
+ import { createNodeChangesMessage, encodeMessage, initCodec } from '@pairdraw/kiwi/fig/codec'
55
+
56
+ await initCodec()
57
+
58
+ const message = createNodeChangesMessage(1, 1, [
59
+ {
60
+ guid: { sessionID: 1, localID: 1 },
61
+ phase: 'CREATED',
62
+ type: 'RECTANGLE',
63
+ name: 'Card',
64
+ size: { x: 320, y: 180 }
65
+ }
66
+ ])
67
+
68
+ const bytes = encodeMessage(message)
69
+ ```
70
+
71
+ Boolean operation payloads use Figma's Kiwi enum names. SceneGraph `EXCLUDE` is a core-level concept and should be serialized as Kiwi `XOR` before calling the low-level codec.
72
+
73
+ ## FIG Kiwi containers
74
+
75
+ ```ts
76
+ import { buildFigKiwi, parseFigKiwiChunks } from '@pairdraw/kiwi/fig/container'
77
+
78
+ const container = buildFigKiwi(new Uint8Array([1, 2, 3]))
79
+ const chunks = parseFigKiwiChunks(container)
80
+ ```
81
+
82
+ ## Raw `fig-kiwi` payload decoding
83
+
84
+ ```ts
85
+ import { decodeFigKiwiCanvas } from '@pairdraw/kiwi/fig/parse'
86
+
87
+ const decoded = decodeFigKiwiCanvas(canvasBytes)
88
+ console.log(decoded.nodeChanges.length, decoded.blobs.length)
89
+ ```
90
+
91
+ Use `parseFigBuffer()` from `@pairdraw/fig` for complete zipped `.fig` files, including image resources. Use `@pairdraw/core/io` for conversion into an editable `SceneGraph`.
92
+
93
+ ## GUID helpers
94
+
95
+ ```ts
96
+ import { guidToString, stringToGuid } from '@pairdraw/kiwi/fig/guid'
97
+
98
+ const id = guidToString({ sessionID: 1, localID: 42 })
99
+ const guid = stringToGuid('1:42')
100
+ ```
101
+
102
+ ## Public subpaths
103
+
104
+ The package has no root entry; import each name from its subpath.
105
+
106
+ - `@pairdraw/kiwi/schema-runtime`
107
+ - `@pairdraw/kiwi/fig`
108
+ - `@pairdraw/kiwi/fig/codec`
109
+ - `@pairdraw/kiwi/fig/container`
110
+ - `@pairdraw/kiwi/fig/guid`
111
+ - `@pairdraw/kiwi/fig/parse`
112
+
113
+ `@pairdraw/kiwi` must not import `@pairdraw/core`, `#core/*`, app code, Vue code, CLI code, or MCP code.