@moondraft/import 0.0.0-stage → 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 (323) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +169 -0
  5. package/dist/adapter/convert.d.ts +122 -0
  6. package/dist/adapter/convert.js +2302 -0
  7. package/dist/adapter/figma.d.ts +9 -0
  8. package/dist/adapter/figma.js +30 -0
  9. package/dist/adapter/file-components.d.ts +14 -0
  10. package/dist/adapter/file-components.js +262 -0
  11. package/dist/adapter/file-resources.d.ts +29 -0
  12. package/dist/adapter/file-resources.js +562 -0
  13. package/dist/adapter/index.d.ts +6 -0
  14. package/dist/adapter/index.js +9 -0
  15. package/dist/adapter/link.d.ts +45 -0
  16. package/dist/adapter/link.js +688 -0
  17. package/dist/adapter/payload.d.ts +31 -0
  18. package/dist/adapter/payload.js +78 -0
  19. package/dist/adapter/shapes.d.ts +31 -0
  20. package/dist/adapter/shapes.js +75 -0
  21. package/dist/adapter/variables.d.ts +44 -0
  22. package/dist/adapter/variables.js +103 -0
  23. package/dist/figma-file.d.ts +38 -0
  24. package/dist/figma-file.js +97 -0
  25. package/dist/figma-worker.d.ts +11 -0
  26. package/dist/figma-worker.js +12 -0
  27. package/dist/figma.d.ts +26 -0
  28. package/dist/figma.js +96 -0
  29. package/dist/index.d.ts +28 -0
  30. package/dist/index.js +49 -0
  31. package/dist/report.d.ts +15 -0
  32. package/dist/report.js +69 -0
  33. package/dist/svg.d.ts +33 -0
  34. package/dist/svg.js +44 -0
  35. package/dist/syntax.d.ts +8 -0
  36. package/dist/syntax.js +19 -0
  37. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  38. package/dist/taco/figma-import/clipboard.js +87 -0
  39. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  40. package/dist/taco/figma-import/clipboardSize.js +107 -0
  41. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  42. package/dist/taco/figma-import/container/compression.js +174 -0
  43. package/dist/taco/figma-import/container/error.d.ts +15 -0
  44. package/dist/taco/figma-import/container/error.js +19 -0
  45. package/dist/taco/figma-import/container/kiwiContainer.d.ts +38 -0
  46. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  47. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  48. package/dist/taco/figma-import/container/limits.js +22 -0
  49. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  50. package/dist/taco/figma-import/container/zip.js +154 -0
  51. package/dist/taco/figma-import/figFile.d.ts +34 -0
  52. package/dist/taco/figma-import/figFile.js +91 -0
  53. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  54. package/dist/taco/figma-import/figFileDocument.js +100 -0
  55. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  56. package/dist/taco/figma-import/import/blobs.js +23 -0
  57. package/dist/taco/figma-import/import/carry.d.ts +11 -0
  58. package/dist/taco/figma-import/import/carry.js +33 -0
  59. package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
  60. package/dist/taco/figma-import/import/componentProps.js +313 -0
  61. package/dist/taco/figma-import/import/componentSets.d.ts +83 -0
  62. package/dist/taco/figma-import/import/componentSets.js +647 -0
  63. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  64. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  65. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  66. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  67. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  68. package/dist/taco/figma-import/import/converters/frame.js +55 -0
  69. package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
  70. package/dist/taco/figma-import/import/converters/gradient.js +106 -0
  71. package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
  72. package/dist/taco/figma-import/import/converters/group.js +39 -0
  73. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  74. package/dist/taco/figma-import/import/converters/image.js +83 -0
  75. package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
  76. package/dist/taco/figma-import/import/converters/layout.js +168 -0
  77. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  78. package/dist/taco/figma-import/import/converters/line.js +40 -0
  79. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  80. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  81. package/dist/taco/figma-import/import/converters/section.d.ts +9 -0
  82. package/dist/taco/figma-import/import/converters/section.js +35 -0
  83. package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
  84. package/dist/taco/figma-import/import/converters/shared.js +362 -0
  85. package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
  86. package/dist/taco/figma-import/import/converters/text.js +576 -0
  87. package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
  88. package/dist/taco/figma-import/import/converters/vector.js +468 -0
  89. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
  90. package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -0
  91. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  92. package/dist/taco/figma-import/import/fields.js +29 -0
  93. package/dist/taco/figma-import/import/instances.d.ts +163 -0
  94. package/dist/taco/figma-import/import/instances.js +1323 -0
  95. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  96. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  97. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  98. package/dist/taco/figma-import/import/slots.js +96 -0
  99. package/dist/taco/figma-import/import/styles.d.ts +46 -0
  100. package/dist/taco/figma-import/import/styles.js +42 -0
  101. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  102. package/dist/taco/figma-import/import/tree.js +194 -0
  103. package/dist/taco/figma-import/import/types.d.ts +232 -0
  104. package/dist/taco/figma-import/import/types.js +33 -0
  105. package/dist/taco/figma-import/import/variables.d.ts +136 -0
  106. package/dist/taco/figma-import/import/variables.js +762 -0
  107. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  108. package/dist/taco/figma-import/import/variantTrees.js +480 -0
  109. package/dist/taco/figma-import/import/walk.d.ts +159 -0
  110. package/dist/taco/figma-import/import/walk.js +1297 -0
  111. package/dist/taco/figma-import/index.d.ts +22 -0
  112. package/dist/taco/figma-import/index.js +13 -0
  113. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  114. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  115. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  116. package/dist/taco/figma-import/kiwi/error.js +29 -0
  117. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  118. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  119. package/dist/taco/figma-import/kiwi/message.d.ts +10 -0
  120. package/dist/taco/figma-import/kiwi/message.js +145 -0
  121. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  122. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  123. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  124. package/dist/taco/figma-import/kiwi/types.js +18 -0
  125. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  126. package/dist/taco/model/agent-hidden-fields.js +29 -0
  127. package/dist/taco/model/asset-users.d.ts +23 -0
  128. package/dist/taco/model/asset-users.js +128 -0
  129. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  130. package/dist/taco/model/auto-layout-lines.js +70 -0
  131. package/dist/taco/model/codec.d.ts +444 -0
  132. package/dist/taco/model/codec.js +5635 -0
  133. package/dist/taco/model/color.d.ts +11 -0
  134. package/dist/taco/model/color.js +61 -0
  135. package/dist/taco/model/comment-operations.d.ts +102 -0
  136. package/dist/taco/model/comment-operations.js +227 -0
  137. package/dist/taco/model/component-evaluation.d.ts +94 -0
  138. package/dist/taco/model/component-evaluation.js +548 -0
  139. package/dist/taco/model/component-expressions.d.ts +242 -0
  140. package/dist/taco/model/component-expressions.js +1082 -0
  141. package/dist/taco/model/component-properties.d.ts +111 -0
  142. package/dist/taco/model/component-properties.js +339 -0
  143. package/dist/taco/model/component-samples.d.ts +83 -0
  144. package/dist/taco/model/component-samples.js +290 -0
  145. package/dist/taco/model/component-validity.d.ts +85 -0
  146. package/dist/taco/model/component-validity.js +397 -0
  147. package/dist/taco/model/components.d.ts +155 -0
  148. package/dist/taco/model/components.js +505 -0
  149. package/dist/taco/model/connector-ends.d.ts +20 -0
  150. package/dist/taco/model/connector-ends.js +188 -0
  151. package/dist/taco/model/connector-geometry.d.ts +74 -0
  152. package/dist/taco/model/connector-geometry.js +293 -0
  153. package/dist/taco/model/corner-radii.d.ts +26 -0
  154. package/dist/taco/model/corner-radii.js +47 -0
  155. package/dist/taco/model/derivations.d.ts +81 -0
  156. package/dist/taco/model/derivations.js +151 -0
  157. package/dist/taco/model/export-settings.d.ts +53 -0
  158. package/dist/taco/model/export-settings.js +156 -0
  159. package/dist/taco/model/expressions/ast.d.ts +153 -0
  160. package/dist/taco/model/expressions/ast.js +6 -0
  161. package/dist/taco/model/expressions/cache.d.ts +23 -0
  162. package/dist/taco/model/expressions/cache.js +43 -0
  163. package/dist/taco/model/expressions/check.d.ts +72 -0
  164. package/dist/taco/model/expressions/check.js +517 -0
  165. package/dist/taco/model/expressions/completion.d.ts +61 -0
  166. package/dist/taco/model/expressions/completion.js +421 -0
  167. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  168. package/dist/taco/model/expressions/evaluate.js +519 -0
  169. package/dist/taco/model/expressions/forms.d.ts +84 -0
  170. package/dist/taco/model/expressions/forms.js +200 -0
  171. package/dist/taco/model/expressions/index.d.ts +14 -0
  172. package/dist/taco/model/expressions/index.js +17 -0
  173. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  174. package/dist/taco/model/expressions/lexer.js +213 -0
  175. package/dist/taco/model/expressions/library.d.ts +33 -0
  176. package/dist/taco/model/expressions/library.js +117 -0
  177. package/dist/taco/model/expressions/names.d.ts +43 -0
  178. package/dist/taco/model/expressions/names.js +99 -0
  179. package/dist/taco/model/expressions/parser.d.ts +15 -0
  180. package/dist/taco/model/expressions/parser.js +438 -0
  181. package/dist/taco/model/expressions/rename.d.ts +34 -0
  182. package/dist/taco/model/expressions/rename.js +46 -0
  183. package/dist/taco/model/expressions/source.d.ts +15 -0
  184. package/dist/taco/model/expressions/source.js +161 -0
  185. package/dist/taco/model/expressions/types.d.ts +119 -0
  186. package/dist/taco/model/expressions/types.js +102 -0
  187. package/dist/taco/model/expressions/values.d.ts +97 -0
  188. package/dist/taco/model/expressions/values.js +160 -0
  189. package/dist/taco/model/geometry-limits.d.ts +16 -0
  190. package/dist/taco/model/geometry-limits.js +67 -0
  191. package/dist/taco/model/geometry.d.ts +47 -0
  192. package/dist/taco/model/geometry.js +193 -0
  193. package/dist/taco/model/group-bounds.d.ts +38 -0
  194. package/dist/taco/model/group-bounds.js +144 -0
  195. package/dist/taco/model/id-table.d.ts +37 -0
  196. package/dist/taco/model/id-table.js +80 -0
  197. package/dist/taco/model/index.d.ts +25 -0
  198. package/dist/taco/model/index.js +27 -0
  199. package/dist/taco/model/instance-resolver.d.ts +372 -0
  200. package/dist/taco/model/instance-resolver.js +1748 -0
  201. package/dist/taco/model/layer-syntax.d.ts +340 -0
  202. package/dist/taco/model/layer-syntax.js +3506 -0
  203. package/dist/taco/model/layout/constraints.d.ts +84 -0
  204. package/dist/taco/model/layout/constraints.js +445 -0
  205. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  206. package/dist/taco/model/layout/frame-layout.js +618 -0
  207. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  208. package/dist/taco/model/layout/node-sizing.js +486 -0
  209. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  210. package/dist/taco/model/legacy-connector-caps.js +70 -0
  211. package/dist/taco/model/linear-call.d.ts +48 -0
  212. package/dist/taco/model/linear-call.js +58 -0
  213. package/dist/taco/model/new-nodes.d.ts +145 -0
  214. package/dist/taco/model/new-nodes.js +277 -0
  215. package/dist/taco/model/node-builder.d.ts +449 -0
  216. package/dist/taco/model/node-builder.js +2294 -0
  217. package/dist/taco/model/node-table-watch.d.ts +36 -0
  218. package/dist/taco/model/node-table-watch.js +63 -0
  219. package/dist/taco/model/node-transform.d.ts +39 -0
  220. package/dist/taco/model/node-transform.js +79 -0
  221. package/dist/taco/model/node-users-index.d.ts +10 -0
  222. package/dist/taco/model/node-users-index.js +82 -0
  223. package/dist/taco/model/operation-references.d.ts +80 -0
  224. package/dist/taco/model/operation-references.js +399 -0
  225. package/dist/taco/model/operations.d.ts +610 -0
  226. package/dist/taco/model/operations.js +2882 -0
  227. package/dist/taco/model/overlay-table.d.ts +71 -0
  228. package/dist/taco/model/overlay-table.js +171 -0
  229. package/dist/taco/model/override-remap.d.ts +69 -0
  230. package/dist/taco/model/override-remap.js +230 -0
  231. package/dist/taco/model/parent-table.d.ts +53 -0
  232. package/dist/taco/model/parent-table.js +193 -0
  233. package/dist/taco/model/problem-collector.d.ts +27 -0
  234. package/dist/taco/model/problem-collector.js +101 -0
  235. package/dist/taco/model/sha256.d.ts +10 -0
  236. package/dist/taco/model/sha256.js +74 -0
  237. package/dist/taco/model/shape-geometry.d.ts +96 -0
  238. package/dist/taco/model/shape-geometry.js +368 -0
  239. package/dist/taco/model/shared-node-table.d.ts +97 -0
  240. package/dist/taco/model/shared-node-table.js +546 -0
  241. package/dist/taco/model/slots.d.ts +113 -0
  242. package/dist/taco/model/slots.js +281 -0
  243. package/dist/taco/model/stroke-settings.d.ts +37 -0
  244. package/dist/taco/model/stroke-settings.js +90 -0
  245. package/dist/taco/model/svg-path-import.d.ts +89 -0
  246. package/dist/taco/model/svg-path-import.js +219 -0
  247. package/dist/taco/model/text-measurement.d.ts +142 -0
  248. package/dist/taco/model/text-measurement.js +846 -0
  249. package/dist/taco/model/text-reads.d.ts +66 -0
  250. package/dist/taco/model/text-reads.js +128 -0
  251. package/dist/taco/model/text-sizer.d.ts +358 -0
  252. package/dist/taco/model/text-sizer.js +996 -0
  253. package/dist/taco/model/theme-users.d.ts +59 -0
  254. package/dist/taco/model/theme-users.js +312 -0
  255. package/dist/taco/model/thumbnail.d.ts +15 -0
  256. package/dist/taco/model/thumbnail.js +34 -0
  257. package/dist/taco/model/types.d.ts +2347 -0
  258. package/dist/taco/model/types.js +366 -0
  259. package/dist/taco/model/unknown-property.d.ts +5 -0
  260. package/dist/taco/model/unknown-property.js +7 -0
  261. package/dist/taco/model/validated-documents.d.ts +22 -0
  262. package/dist/taco/model/validated-documents.js +22 -0
  263. package/dist/taco/model/variable-modes.d.ts +61 -0
  264. package/dist/taco/model/variable-modes.js +438 -0
  265. package/dist/taco/model/variable-references.d.ts +54 -0
  266. package/dist/taco/model/variable-references.js +183 -0
  267. package/dist/taco/model/variables.d.ts +24 -0
  268. package/dist/taco/model/variables.js +151 -0
  269. package/dist/taco/model/vector-network.d.ts +34 -0
  270. package/dist/taco/model/vector-network.js +411 -0
  271. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  272. package/dist/taco/svg-import/import-svg.js +729 -0
  273. package/dist/taco/svg-import/index.d.ts +3 -0
  274. package/dist/taco/svg-import/index.js +3 -0
  275. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  276. package/dist/taco/svg-import/limits/limits.js +160 -0
  277. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  278. package/dist/taco/svg-import/paint/gradients.js +429 -0
  279. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  280. package/dist/taco/svg-import/paint/paint.js +162 -0
  281. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  282. package/dist/taco/svg-import/paths/paths.js +205 -0
  283. package/dist/taco/svg-import/public-types.d.ts +279 -0
  284. package/dist/taco/svg-import/public-types.js +56 -0
  285. package/dist/taco/svg-import/report/report.d.ts +44 -0
  286. package/dist/taco/svg-import/report/report.js +79 -0
  287. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  288. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  289. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  290. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  291. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  292. package/dist/taco/svg-import/structure/effects.js +618 -0
  293. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  294. package/dist/taco/svg-import/structure/image.js +495 -0
  295. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  296. package/dist/taco/svg-import/structure/walk.js +544 -0
  297. package/dist/taco/svg-import/style/color.d.ts +40 -0
  298. package/dist/taco/svg-import/style/color.js +275 -0
  299. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  300. package/dist/taco/svg-import/style/computed.js +1534 -0
  301. package/dist/taco/svg-import/style/css.d.ts +127 -0
  302. package/dist/taco/svg-import/style/css.js +541 -0
  303. package/dist/taco/svg-import/style/media.d.ts +25 -0
  304. package/dist/taco/svg-import/style/media.js +307 -0
  305. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  306. package/dist/taco/svg-import/style/properties.js +135 -0
  307. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  308. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  309. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  310. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  311. package/dist/taco/svg-import/text/text.d.ts +29 -0
  312. package/dist/taco/svg-import/text/text.js +545 -0
  313. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  314. package/dist/taco/svg-import/transform/matrix.js +229 -0
  315. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  316. package/dist/taco/svg-import/tree/element-data.js +155 -0
  317. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  318. package/dist/taco/svg-import/tree/elements.js +121 -0
  319. package/dist/taco/svg-import/units/length.d.ts +43 -0
  320. package/dist/taco/svg-import/units/length.js +125 -0
  321. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  322. package/dist/taco/svg-import/units/viewbox.js +77 -0
  323. package/package.json +54 -4
@@ -0,0 +1,22 @@
1
+ export { decodeKiwiSchema } from "./kiwi/schema.ts";
2
+ export { decodeKiwiMessage } from "./kiwi/message.ts";
3
+ export { KiwiDecodeError } from "./kiwi/error.ts";
4
+ export { KIWI_LIMITS } from "./kiwi/limits.ts";
5
+ export type { KiwiDefinition, KiwiDefinitionKind, KiwiField, KiwiNativeType, KiwiObject, KiwiSchema, KiwiValue, } from "./kiwi/types.ts";
6
+ export { importFigmaMessage, converterFor } from "./import/walk.ts";
7
+ export type { FigmaNodeConverter, NodeWalk } from "./import/walk.ts";
8
+ export type { FigmaTreeNode } from "./import/tree.ts";
9
+ export * from "./import/types.ts";
10
+ export { readFigmaClipboardHtml } from "./clipboard.ts";
11
+ export type { FigmaClipboard, FigmaClipboardMeta } from "./clipboard.ts";
12
+ export { peekFigmaClipboardSize } from "./clipboardSize.ts";
13
+ export type { FigmaClipboardSize } from "./clipboardSize.ts";
14
+ export { FIGMA_MESSAGE_ROOT_TYPE, KIWI_CONTAINER_MAGICS, readKiwiContainer, } from "./container/kiwiContainer.ts";
15
+ export type { KiwiContainer, KiwiContainerHeader, KiwiContainerMagic, KiwiContainerOptions, } from "./container/kiwiContainer.ts";
16
+ export { FigmaReadError } from "./container/error.ts";
17
+ export type { FigmaReadProblem } from "./container/error.ts";
18
+ export { FIGMA_READ_LIMITS } from "./container/limits.ts";
19
+ export { readFigFile } from "./figFile.ts";
20
+ export type { FigFile, FigFileOptions } from "./figFile.ts";
21
+ export { figmaFileDocument } from "./figFileDocument.ts";
22
+ export type { FigmaFileDocumentOptions } from "./figFileDocument.ts";
@@ -0,0 +1,13 @@
1
+ export { decodeKiwiSchema } from "./kiwi/schema.js";
2
+ export { decodeKiwiMessage } from "./kiwi/message.js";
3
+ export { KiwiDecodeError } from "./kiwi/error.js";
4
+ export { KIWI_LIMITS } from "./kiwi/limits.js";
5
+ export { importFigmaMessage, converterFor } from "./import/walk.js";
6
+ export * from "./import/types.js";
7
+ export { readFigmaClipboardHtml } from "./clipboard.js";
8
+ export { peekFigmaClipboardSize } from "./clipboardSize.js";
9
+ export { FIGMA_MESSAGE_ROOT_TYPE, KIWI_CONTAINER_MAGICS, readKiwiContainer, } from "./container/kiwiContainer.js";
10
+ export { FigmaReadError } from "./container/error.js";
11
+ export { FIGMA_READ_LIMITS } from "./container/limits.js";
12
+ export { readFigFile } from "./figFile.js";
13
+ export { figmaFileDocument } from "./figFileDocument.js";
@@ -0,0 +1,37 @@
1
+ import { KiwiDecodeError } from "./error.ts";
2
+ /**
3
+ * Reads Kiwi's wire encodings from a byte array, mirroring the reference
4
+ * ByteBuffer in https://github.com/evanw/kiwi/blob/master/js/bb.ts but
5
+ * refusing input the reference reader would silently misread: varints longer
6
+ * than their type allows and malformed UTF-8.
7
+ */
8
+ export declare class ByteReader {
9
+ offset: number;
10
+ private readonly bytes;
11
+ constructor(bytes: Uint8Array);
12
+ get remaining(): number;
13
+ fail(problem: string, offset?: number): KiwiDecodeError;
14
+ readByte(): number;
15
+ readBool(): boolean;
16
+ /** Unsigned 32-bit varint: 7 bits per byte, low bits first, at most 5 bytes. */
17
+ readVarUint(): number;
18
+ /** Signed 32-bit integer, zigzag encoded as a uint varint. */
19
+ readVarInt(): number;
20
+ /** Unsigned 64-bit varint: eight 7-bit groups, then a ninth byte used whole. */
21
+ readVarUint64(): bigint;
22
+ /** Signed 64-bit integer, zigzag encoded as a uint64 varint. */
23
+ readVarInt64(): bigint;
24
+ /**
25
+ * Kiwi's float: one 0 byte for zero, otherwise the 32-bit float's bits with
26
+ * the exponent rotated into the first byte, stored low byte first.
27
+ */
28
+ readVarFloat(): number;
29
+ /**
30
+ * Null-terminated UTF-8. Like the reference reader, a code point in the
31
+ * surrogate range is kept as one UTF-16 unit, because the reference writer
32
+ * stores an unpaired surrogate that way.
33
+ */
34
+ readString(): string;
35
+ /** Copies the next `length` bytes. The caller has already bounded `length`. */
36
+ readBytes(length: number): Uint8Array;
37
+ }
@@ -0,0 +1,151 @@
1
+ import { KiwiDecodeError } from "./error.js";
2
+ const floatBits = new Int32Array(1);
3
+ const floatValue = new Float32Array(floatBits.buffer);
4
+ const STRING_CHUNK = 4096;
5
+ /**
6
+ * Reads Kiwi's wire encodings from a byte array, mirroring the reference
7
+ * ByteBuffer in https://github.com/evanw/kiwi/blob/master/js/bb.ts but
8
+ * refusing input the reference reader would silently misread: varints longer
9
+ * than their type allows and malformed UTF-8.
10
+ */
11
+ export class ByteReader {
12
+ offset = 0;
13
+ bytes;
14
+ constructor(bytes) {
15
+ this.bytes = bytes;
16
+ }
17
+ get remaining() {
18
+ return this.bytes.length - this.offset;
19
+ }
20
+ fail(problem, offset = this.offset) {
21
+ return new KiwiDecodeError(problem, offset);
22
+ }
23
+ readByte() {
24
+ const byte = this.bytes[this.offset];
25
+ if (byte === undefined)
26
+ throw this.fail("the bytes end too early");
27
+ this.offset += 1;
28
+ return byte;
29
+ }
30
+ readBool() {
31
+ const start = this.offset;
32
+ const byte = this.readByte();
33
+ if (byte > 1)
34
+ throw this.fail(`bool must be 0 or 1, found ${byte}`, start);
35
+ return byte === 1;
36
+ }
37
+ /** Unsigned 32-bit varint: 7 bits per byte, low bits first, at most 5 bytes. */
38
+ readVarUint() {
39
+ const start = this.offset;
40
+ let value = 0;
41
+ for (let shift = 0; shift < 35; shift += 7) {
42
+ const byte = this.readByte();
43
+ if (shift === 28 && byte > 0x0f) {
44
+ throw this.fail("uint varint does not fit in 32 bits", start);
45
+ }
46
+ value += (byte & 0x7f) * 2 ** shift;
47
+ if ((byte & 0x80) === 0)
48
+ return value;
49
+ }
50
+ throw this.fail("uint varint does not fit in 32 bits", start);
51
+ }
52
+ /** Signed 32-bit integer, zigzag encoded as a uint varint. */
53
+ readVarInt() {
54
+ const value = this.readVarUint();
55
+ return value % 2 === 1 ? -(value + 1) / 2 : value / 2;
56
+ }
57
+ /** Unsigned 64-bit varint: eight 7-bit groups, then a ninth byte used whole. */
58
+ readVarUint64() {
59
+ let value = 0n;
60
+ let shift = 0n;
61
+ for (let index = 0; index < 8; index += 1) {
62
+ const byte = this.readByte();
63
+ value |= BigInt(byte & 0x7f) << shift;
64
+ if ((byte & 0x80) === 0)
65
+ return value;
66
+ shift += 7n;
67
+ }
68
+ return value | (BigInt(this.readByte()) << shift);
69
+ }
70
+ /** Signed 64-bit integer, zigzag encoded as a uint64 varint. */
71
+ readVarInt64() {
72
+ const value = this.readVarUint64();
73
+ return (value & 1n) === 1n ? ~(value >> 1n) : value >> 1n;
74
+ }
75
+ /**
76
+ * Kiwi's float: one 0 byte for zero, otherwise the 32-bit float's bits with
77
+ * the exponent rotated into the first byte, stored low byte first.
78
+ */
79
+ readVarFloat() {
80
+ const first = this.readByte();
81
+ if (first === 0)
82
+ return 0;
83
+ if (this.remaining < 3)
84
+ throw this.fail("the bytes end too early", this.offset - 1);
85
+ const bits = first |
86
+ (this.readByte() << 8) |
87
+ (this.readByte() << 16) |
88
+ (this.readByte() << 24);
89
+ floatBits[0] = (bits << 23) | (bits >>> 9);
90
+ return floatValue[0] ?? Number.NaN;
91
+ }
92
+ /**
93
+ * Null-terminated UTF-8. Like the reference reader, a code point in the
94
+ * surrogate range is kept as one UTF-16 unit, because the reference writer
95
+ * stores an unpaired surrogate that way.
96
+ */
97
+ readString() {
98
+ const parts = [];
99
+ const units = [];
100
+ for (;;) {
101
+ const start = this.offset;
102
+ const lead = this.readByte();
103
+ let codePoint;
104
+ if (lead < 0x80) {
105
+ codePoint = lead;
106
+ }
107
+ else if (lead < 0xc0 || lead >= 0xf8) {
108
+ throw this.fail(`invalid UTF-8 lead byte 0x${lead.toString(16)}`, start);
109
+ }
110
+ else {
111
+ const extra = lead < 0xe0 ? 1 : lead < 0xf0 ? 2 : 3;
112
+ codePoint = lead & (0x3f >> extra);
113
+ for (let index = 0; index < extra; index += 1) {
114
+ const at = this.offset;
115
+ const next = this.readByte();
116
+ if ((next & 0xc0) !== 0x80) {
117
+ throw this.fail(`invalid UTF-8 continuation byte 0x${next.toString(16)}`, at);
118
+ }
119
+ codePoint = (codePoint << 6) | (next & 0x3f);
120
+ }
121
+ if (codePoint < (extra === 1 ? 0x80 : extra === 2 ? 0x800 : 0x10000)) {
122
+ throw this.fail(`UTF-8 code point 0x${codePoint.toString(16)} is encoded in more bytes than it needs`, start);
123
+ }
124
+ if (codePoint > 0x10ffff) {
125
+ throw this.fail(`UTF-8 code point 0x${codePoint.toString(16)} is past U+10FFFF`, start);
126
+ }
127
+ }
128
+ if (codePoint === 0)
129
+ break;
130
+ if (codePoint < 0x10000) {
131
+ units.push(codePoint);
132
+ }
133
+ else {
134
+ codePoint -= 0x10000;
135
+ units.push(0xd800 + (codePoint >> 10), 0xdc00 + (codePoint & 0x3ff));
136
+ }
137
+ if (units.length >= STRING_CHUNK) {
138
+ parts.push(String.fromCharCode(...units));
139
+ units.length = 0;
140
+ }
141
+ }
142
+ parts.push(String.fromCharCode(...units));
143
+ return parts.join("");
144
+ }
145
+ /** Copies the next `length` bytes. The caller has already bounded `length`. */
146
+ readBytes(length) {
147
+ const start = this.offset;
148
+ this.offset += length;
149
+ return this.bytes.slice(start, this.offset);
150
+ }
151
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Thrown when Kiwi bytes or a Kiwi schema are refused. `offset` is the byte
3
+ * where the problem was found, or `null` when the problem is in a schema
4
+ * object that did not come from bytes. `path` names the fields being read,
5
+ * from the root down, for example `["children", "[2]", "name"]`.
6
+ */
7
+ export declare class KiwiDecodeError extends Error {
8
+ readonly problem: string;
9
+ readonly offset: number | null;
10
+ readonly path: string[];
11
+ constructor(problem: string, offset: number | null, path?: string[]);
12
+ /** Records that the error happened inside `segment`, then updates the message. */
13
+ within(segment: string): this;
14
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Thrown when Kiwi bytes or a Kiwi schema are refused. `offset` is the byte
3
+ * where the problem was found, or `null` when the problem is in a schema
4
+ * object that did not come from bytes. `path` names the fields being read,
5
+ * from the root down, for example `["children", "[2]", "name"]`.
6
+ */
7
+ export class KiwiDecodeError extends Error {
8
+ problem;
9
+ offset;
10
+ path;
11
+ constructor(problem, offset, path = []) {
12
+ super(describe(problem, offset, path));
13
+ this.name = "KiwiDecodeError";
14
+ this.problem = problem;
15
+ this.offset = offset;
16
+ this.path = path;
17
+ }
18
+ /** Records that the error happened inside `segment`, then updates the message. */
19
+ within(segment) {
20
+ this.path.unshift(segment);
21
+ this.message = describe(this.problem, this.offset, this.path);
22
+ return this;
23
+ }
24
+ }
25
+ function describe(problem, offset, path) {
26
+ const where = offset === null ? "" : ` at byte ${offset}`;
27
+ const inside = path.length === 0 ? "" : ` (in ${path.join(".").replace(/\.\[/g, "[")})`;
28
+ return `Kiwi: ${problem}${where}${inside}`;
29
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Bounds the decoder applies to untrusted bytes. Every length read from the
3
+ * bytes is also checked against the bytes that remain, so these only cover
4
+ * what that check cannot.
5
+ */
6
+ export declare const KIWI_LIMITS: {
7
+ /**
8
+ * How many structs and messages may sit inside one another, counting the
9
+ * root as 1. Messages may contain themselves, so without a limit a crafted
10
+ * input could exhaust the call stack.
11
+ */
12
+ readonly maxNestingDepth: 100;
13
+ /**
14
+ * The longest array whose element type takes zero bytes (a struct with no
15
+ * fields). Such an array cannot be bounded by the remaining bytes.
16
+ */
17
+ readonly maxZeroSizeArrayLength: 65536;
18
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Bounds the decoder applies to untrusted bytes. Every length read from the
3
+ * bytes is also checked against the bytes that remain, so these only cover
4
+ * what that check cannot.
5
+ */
6
+ export const KIWI_LIMITS = {
7
+ /**
8
+ * How many structs and messages may sit inside one another, counting the
9
+ * root as 1. Messages may contain themselves, so without a limit a crafted
10
+ * input could exhaust the call stack.
11
+ */
12
+ maxNestingDepth: 100,
13
+ /**
14
+ * The longest array whose element type takes zero bytes (a struct with no
15
+ * fields). Such an array cannot be bounded by the remaining bytes.
16
+ */
17
+ maxZeroSizeArrayLength: 65536,
18
+ };
@@ -0,0 +1,10 @@
1
+ import type { KiwiObject, KiwiSchema } from "./types.ts";
2
+ /**
3
+ * Decodes `bytes` as one value of the struct or message `rootTypeName` in
4
+ * `schema`. A struct reads every field in order; a message reads
5
+ * (field id, value) pairs until field id 0. Refuses unknown field ids, a
6
+ * field that appears twice, unknown enum numbers, bools other than 0 or 1,
7
+ * arrays longer than the remaining bytes allow, nesting deeper than
8
+ * `KIWI_LIMITS.maxNestingDepth`, and bytes left over after the root.
9
+ */
10
+ export declare function decodeKiwiMessage(schema: KiwiSchema, rootTypeName: string, bytes: Uint8Array): KiwiObject;
@@ -0,0 +1,145 @@
1
+ import { ByteReader } from "./byteReader.js";
2
+ import { KiwiDecodeError } from "./error.js";
3
+ import { KIWI_LIMITS } from "./limits.js";
4
+ import { indexKiwiSchema } from "./schema.js";
5
+ /**
6
+ * Decodes `bytes` as one value of the struct or message `rootTypeName` in
7
+ * `schema`. A struct reads every field in order; a message reads
8
+ * (field id, value) pairs until field id 0. Refuses unknown field ids, a
9
+ * field that appears twice, unknown enum numbers, bools other than 0 or 1,
10
+ * arrays longer than the remaining bytes allow, nesting deeper than
11
+ * `KIWI_LIMITS.maxNestingDepth`, and bytes left over after the root.
12
+ */
13
+ export function decodeKiwiMessage(schema, rootTypeName, bytes) {
14
+ if (!(bytes instanceof Uint8Array)) {
15
+ throw new TypeError("decodeKiwiMessage expects a Uint8Array");
16
+ }
17
+ const definitions = indexKiwiSchema(schema);
18
+ const root = definitions.get(rootTypeName);
19
+ if (root === undefined) {
20
+ throw new KiwiDecodeError(`the schema has no type named ${rootTypeName}`, null);
21
+ }
22
+ if (root.kind === "ENUM") {
23
+ throw new KiwiDecodeError(`the root type ${rootTypeName} is an enum, not a struct or message`, null);
24
+ }
25
+ const reader = new ByteReader(bytes);
26
+ try {
27
+ const value = readObject(reader, root, 1);
28
+ if (reader.remaining > 0) {
29
+ throw reader.fail(`${reader.remaining} unread bytes after the ${rootTypeName}`);
30
+ }
31
+ return value;
32
+ }
33
+ catch (error) {
34
+ if (error instanceof KiwiDecodeError)
35
+ error.within(rootTypeName);
36
+ throw error;
37
+ }
38
+ }
39
+ function readObject(reader, definition, depth) {
40
+ if (depth > KIWI_LIMITS.maxNestingDepth) {
41
+ throw reader.fail(`nesting is deeper than KIWI_LIMITS.maxNestingDepth (${KIWI_LIMITS.maxNestingDepth})`);
42
+ }
43
+ const result = {};
44
+ if (definition.kind === "STRUCT") {
45
+ for (const field of definition.fields) {
46
+ setField(result, field.name, readFieldValue(reader, field, depth));
47
+ }
48
+ return result;
49
+ }
50
+ const seen = new Set();
51
+ for (;;) {
52
+ const idOffset = reader.offset;
53
+ const id = reader.readVarUint();
54
+ if (id === 0)
55
+ return result;
56
+ const field = definition.fieldsById.get(id);
57
+ if (field === undefined) {
58
+ throw reader.fail(`field id ${id} is not in message ${definition.name}`, idOffset);
59
+ }
60
+ if (seen.has(id))
61
+ throw reader.fail(`field ${field.name} (id ${id}) appears twice`, idOffset);
62
+ seen.add(id);
63
+ setField(result, field.name, readFieldValue(reader, field, depth));
64
+ }
65
+ }
66
+ function readFieldValue(reader, field, depth) {
67
+ try {
68
+ if (!field.isArray)
69
+ return readSingle(reader, field, depth);
70
+ const lengthOffset = reader.offset;
71
+ const length = reader.readVarUint();
72
+ if (field.native === "byte") {
73
+ if (length > reader.remaining) {
74
+ throw reader.fail(`byte array length ${length} is longer than the ${reader.remaining} bytes that remain`, lengthOffset);
75
+ }
76
+ return reader.readBytes(length);
77
+ }
78
+ const elementBytes = field.definition?.minBytes ?? 1;
79
+ if (elementBytes === 0 && length > KIWI_LIMITS.maxZeroSizeArrayLength) {
80
+ throw reader.fail(`array length ${length} is above KIWI_LIMITS.maxZeroSizeArrayLength (${KIWI_LIMITS.maxZeroSizeArrayLength})`, lengthOffset);
81
+ }
82
+ if (length * elementBytes > reader.remaining) {
83
+ throw reader.fail(`array length ${length} needs at least ${length * elementBytes} bytes but ${reader.remaining} remain`, lengthOffset);
84
+ }
85
+ const values = [];
86
+ for (let index = 0; index < length; index += 1) {
87
+ try {
88
+ values.push(readSingle(reader, field, depth));
89
+ }
90
+ catch (error) {
91
+ if (error instanceof KiwiDecodeError)
92
+ error.within(`[${index}]`);
93
+ throw error;
94
+ }
95
+ }
96
+ return values;
97
+ }
98
+ catch (error) {
99
+ if (error instanceof KiwiDecodeError)
100
+ error.within(field.name);
101
+ throw error;
102
+ }
103
+ }
104
+ function readSingle(reader, field, depth) {
105
+ if (field.native !== null)
106
+ return readNative(reader, field.native);
107
+ const definition = field.definition;
108
+ if (definition.kind !== "ENUM")
109
+ return readObject(reader, definition, depth + 1);
110
+ const offset = reader.offset;
111
+ const number = reader.readVarUint();
112
+ const name = definition.enumNames.get(number);
113
+ if (name === undefined)
114
+ throw reader.fail(`enum ${definition.name} has no value ${number}`, offset);
115
+ return name;
116
+ }
117
+ function readNative(reader, type) {
118
+ switch (type) {
119
+ case "bool":
120
+ return reader.readBool();
121
+ case "byte":
122
+ return reader.readByte();
123
+ case "int":
124
+ return reader.readVarInt();
125
+ case "uint":
126
+ return reader.readVarUint();
127
+ case "float":
128
+ return reader.readVarFloat();
129
+ case "string":
130
+ return reader.readString();
131
+ case "int64":
132
+ return reader.readVarInt64();
133
+ case "uint64":
134
+ return reader.readVarUint64();
135
+ }
136
+ }
137
+ /** Defines the field as an own property, so a field named `__proto__` cannot change the prototype. */
138
+ function setField(target, name, value) {
139
+ if (name === "__proto__") {
140
+ Object.defineProperty(target, name, { value, enumerable: true, writable: true, configurable: true });
141
+ }
142
+ else {
143
+ target[name] = value;
144
+ }
145
+ }
@@ -0,0 +1,42 @@
1
+ import { type KiwiDefinitionKind, type KiwiNativeType, type KiwiSchema } from "./types.ts";
2
+ /** Where each definition and field started, so checks after reading can name a byte. */
3
+ interface SchemaOffsets {
4
+ readonly definitions: readonly number[];
5
+ readonly fields: readonly (readonly number[])[];
6
+ }
7
+ /**
8
+ * Decodes a binary Kiwi schema, the format written by `encodeBinarySchema` in
9
+ * the reference implementation: a definition count, then for each definition
10
+ * its name, kind and fields, and for each field its name, type, flags and
11
+ * value. The schema is checked before it is returned; see `indexKiwiSchema`.
12
+ */
13
+ export declare function decodeKiwiSchema(bytes: Uint8Array): KiwiSchema;
14
+ export interface IndexedField {
15
+ readonly name: string;
16
+ readonly isArray: boolean;
17
+ /** Set when the field's type is built in. */
18
+ readonly native: KiwiNativeType | null;
19
+ /** Set when the field's type is another definition. */
20
+ readonly definition: IndexedDefinition | null;
21
+ }
22
+ export interface IndexedDefinition {
23
+ readonly name: string;
24
+ readonly kind: KiwiDefinitionKind;
25
+ /** Struct fields in reading order. */
26
+ readonly fields: IndexedField[];
27
+ /** Message fields by id. */
28
+ readonly fieldsById: Map<number, IndexedField>;
29
+ /** Enum value names by number. */
30
+ readonly enumNames: Map<number, string>;
31
+ /** The fewest bytes one value of this type can take, used to bound arrays. */
32
+ minBytes: number;
33
+ }
34
+ /**
35
+ * Checks a schema and builds the lookups the message decoder uses. Refuses
36
+ * empty or repeated definition names, repeated field names, repeated enum
37
+ * numbers, message field ids that are 0 or repeated, unknown field types,
38
+ * array enum values, and structs that contain themselves (they would have no
39
+ * finite encoding).
40
+ */
41
+ export declare function indexKiwiSchema(schema: KiwiSchema, offsets?: SchemaOffsets): Map<string, IndexedDefinition>;
42
+ export {};