@pairdraw/core 0.19.2 → 0.20.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/dist/ai/providers.d.ts +6 -0
- package/dist/ai/providers.d.ts.map +1 -1
- package/dist/ai/providers.js.map +1 -1
- package/dist/cache/resource.d.ts +8 -1
- package/dist/cache/resource.d.ts.map +1 -1
- package/dist/cache/resource.js +18 -0
- package/dist/cache/resource.js.map +1 -1
- package/dist/canvas/effects.d.ts +6 -4
- package/dist/canvas/effects.d.ts.map +1 -1
- package/dist/canvas/effects.js +37 -34
- package/dist/canvas/effects.js.map +1 -1
- package/dist/canvas/fills.d.ts.map +1 -1
- package/dist/canvas/fills.js +12 -8
- package/dist/canvas/fills.js.map +1 -1
- package/dist/canvas/images/adjustments.d.ts +18 -0
- package/dist/canvas/images/adjustments.d.ts.map +1 -0
- package/dist/canvas/images/adjustments.js +184 -0
- package/dist/canvas/images/adjustments.js.map +1 -0
- package/dist/canvas/images/sampling.d.ts +13 -0
- package/dist/canvas/images/sampling.d.ts.map +1 -0
- package/dist/canvas/images/sampling.js +49 -0
- package/dist/canvas/images/sampling.js.map +1 -0
- package/dist/canvas/index.d.ts +2 -2
- package/dist/canvas/masks.d.ts +1 -1
- package/dist/canvas/masks.d.ts.map +1 -1
- package/dist/canvas/masks.js.map +1 -1
- package/dist/canvas/noise/render.d.ts +15 -0
- package/dist/canvas/noise/render.d.ts.map +1 -0
- package/dist/canvas/noise/render.js +56 -0
- package/dist/canvas/noise/render.js.map +1 -0
- package/dist/canvas/noise/shader.d.ts +43 -0
- package/dist/canvas/noise/shader.d.ts.map +1 -0
- package/dist/canvas/noise/shader.js +161 -0
- package/dist/canvas/noise/shader.js.map +1 -0
- package/dist/canvas/noise/table.d.ts +13 -0
- package/dist/canvas/noise/table.d.ts.map +1 -0
- package/dist/canvas/noise/table.js +408 -0
- package/dist/canvas/noise/table.js.map +1 -0
- package/dist/canvas/noise/tile.d.ts +22 -0
- package/dist/canvas/noise/tile.d.ts.map +1 -0
- package/dist/canvas/noise/tile.js +73 -0
- package/dist/canvas/noise/tile.js.map +1 -0
- package/dist/canvas/outline-stroke.js +1 -1
- package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
- package/dist/canvas/overlays/auto-layout-hover.js +31 -71
- package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
- package/dist/canvas/renderer/chunks/index.d.ts +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +6 -0
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +13 -1
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/play-scenes.d.ts +13 -0
- package/dist/canvas/renderer/play-scenes.d.ts.map +1 -0
- package/dist/canvas/renderer/play-scenes.js +40 -0
- package/dist/canvas/renderer/play-scenes.js.map +1 -0
- package/dist/canvas/renderer/tiles/cache.d.ts +19 -1
- package/dist/canvas/renderer/tiles/cache.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/cache.js +32 -1
- package/dist/canvas/renderer/tiles/cache.js.map +1 -1
- package/dist/canvas/renderer/tiles/controller.d.ts +11 -0
- package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/controller.js +18 -1
- package/dist/canvas/renderer/tiles/controller.js.map +1 -1
- package/dist/canvas/renderer/tiles/index.d.ts +2 -2
- package/dist/canvas/renderer/tiles/planner.d.ts +1 -1
- package/dist/canvas/renderer/types.d.ts +18 -3
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer/visual-bounds.d.ts +1 -1
- package/dist/canvas/renderer/visual-bounds.js +1 -1
- package/dist/canvas/renderer.d.ts +22 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +29 -1
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts +2 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +41 -9
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shadows/silhouette.js +1 -1
- package/dist/canvas/texture.d.ts +20 -0
- package/dist/canvas/texture.d.ts.map +1 -0
- package/dist/canvas/texture.js +100 -0
- package/dist/canvas/texture.js.map +1 -0
- package/dist/clipboard.js +16 -5
- package/dist/clipboard.js.map +1 -1
- package/dist/constants.d.ts +5 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -1
- package/dist/constants.js.map +1 -1
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/design-memory/check.d.ts +90 -0
- package/dist/design-memory/check.d.ts.map +1 -0
- package/dist/design-memory/check.js +281 -0
- package/dist/design-memory/check.js.map +1 -0
- package/dist/design-memory/describe.d.ts +37 -0
- package/dist/design-memory/describe.d.ts.map +1 -0
- package/dist/design-memory/describe.js +52 -0
- package/dist/design-memory/describe.js.map +1 -0
- package/dist/design-memory/distil.d.ts +22 -0
- package/dist/design-memory/distil.d.ts.map +1 -0
- package/dist/design-memory/distil.js +54 -0
- package/dist/design-memory/distil.js.map +1 -0
- package/dist/design-memory/document.d.ts +12 -0
- package/dist/design-memory/document.d.ts.map +1 -0
- package/dist/design-memory/document.js +64 -0
- package/dist/design-memory/document.js.map +1 -0
- package/dist/design-memory/guard.d.ts +48 -0
- package/dist/design-memory/guard.d.ts.map +1 -0
- package/dist/design-memory/guard.js +105 -0
- package/dist/design-memory/guard.js.map +1 -0
- package/dist/design-memory/index.d.ts +9 -0
- package/dist/design-memory/index.js +9 -0
- package/dist/design-memory/refusal.d.ts +32 -0
- package/dist/design-memory/refusal.d.ts.map +1 -0
- package/dist/design-memory/refusal.js +68 -0
- package/dist/design-memory/refusal.js.map +1 -0
- package/dist/design-memory/rules.d.ts +63 -0
- package/dist/design-memory/rules.d.ts.map +1 -0
- package/dist/design-memory/rules.js +224 -0
- package/dist/design-memory/rules.js.map +1 -0
- package/dist/design-memory/values.d.ts +28 -0
- package/dist/design-memory/values.d.ts.map +1 -0
- package/dist/design-memory/values.js +160 -0
- package/dist/design-memory/values.js.map +1 -0
- package/dist/editor/alignment.js +1 -1
- package/dist/editor/bridges/components.d.ts +2 -0
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +2 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/assets.js +1 -1
- package/dist/editor/clipboard/export.d.ts.map +1 -1
- package/dist/editor/clipboard/export.js +16 -2
- package/dist/editor/clipboard/export.js.map +1 -1
- package/dist/editor/clipboard/placement.d.ts +1 -1
- package/dist/editor/clipboard/placement.js +1 -1
- package/dist/editor/components/instances.d.ts +2 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +22 -1
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components.d.ts +2 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/connectors/attach.js +1 -1
- package/dist/editor/create.d.ts +27 -3
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +16 -60
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/design-memory.d.ts +11 -0
- package/dist/editor/design-memory.d.ts.map +1 -0
- package/dist/editor/design-memory.js +40 -0
- package/dist/editor/design-memory.js.map +1 -0
- package/dist/editor/design-tokens.d.ts +4 -0
- package/dist/editor/design-tokens.d.ts.map +1 -1
- package/dist/editor/design-tokens.js +30 -1
- package/dist/editor/design-tokens.js.map +1 -1
- package/dist/editor/document-colors.d.ts +23 -0
- package/dist/editor/document-colors.d.ts.map +1 -0
- package/dist/editor/document-colors.js +53 -0
- package/dist/editor/document-colors.js.map +1 -0
- package/dist/editor/eyedropper.d.ts +47 -0
- package/dist/editor/eyedropper.d.ts.map +1 -0
- package/dist/editor/eyedropper.js +168 -0
- package/dist/editor/eyedropper.js.map +1 -0
- package/dist/editor/fonts.d.ts +9 -0
- package/dist/editor/fonts.d.ts.map +1 -0
- package/dist/editor/fonts.js +14 -0
- package/dist/editor/fonts.js.map +1 -0
- package/dist/editor/history/atomic-tool.d.ts +9 -2
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +6 -0
- package/dist/editor/history/atomic-tool.js.map +1 -1
- package/dist/editor/history/capture.d.ts +13 -0
- package/dist/editor/history/capture.d.ts.map +1 -0
- package/dist/editor/history/capture.js +28 -0
- package/dist/editor/history/capture.js.map +1 -0
- package/dist/editor/history/document-change.d.ts.map +1 -1
- package/dist/editor/history/document-change.js +2 -22
- package/dist/editor/history/document-change.js.map +1 -1
- package/dist/editor/history/edit.d.ts +7 -0
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +4 -2
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/history/subtree.d.ts +9 -0
- package/dist/editor/history/subtree.d.ts.map +1 -1
- package/dist/editor/history/subtree.js +12 -2
- package/dist/editor/history/subtree.js.map +1 -1
- package/dist/editor/index.d.ts +4 -2
- package/dist/editor/index.js +4 -2
- package/dist/editor/pages.d.ts +7 -5
- package/dist/editor/pages.d.ts.map +1 -1
- package/dist/editor/pages.js +35 -25
- package/dist/editor/pages.js.map +1 -1
- package/dist/editor/play/states.d.ts +3 -1
- package/dist/editor/play/states.d.ts.map +1 -1
- package/dist/editor/play/states.js +1 -1
- package/dist/editor/play/states.js.map +1 -1
- package/dist/editor/read-only/actions.js +4 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/render-requests.d.ts +18 -0
- package/dist/editor/render-requests.d.ts.map +1 -0
- package/dist/editor/render-requests.js +76 -0
- package/dist/editor/render-requests.js.map +1 -0
- package/dist/editor/scale/rescale.d.ts +1 -1
- package/dist/editor/selection/overlays.d.ts.map +1 -1
- package/dist/editor/selection/overlays.js +1 -1
- package/dist/editor/selection/overlays.js.map +1 -1
- package/dist/editor/selection/read.d.ts +4 -0
- package/dist/editor/selection.d.ts +5 -0
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/tool-registry.d.ts.map +1 -1
- package/dist/editor/tool-registry.js +2 -1
- package/dist/editor/tool-registry.js.map +1 -1
- package/dist/editor/types.d.ts +5 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variations/create.d.ts +28 -0
- package/dist/editor/variations/create.d.ts.map +1 -0
- package/dist/editor/variations/create.js +176 -0
- package/dist/editor/variations/create.js.map +1 -0
- package/dist/editor/variations/pick.d.ts +16 -0
- package/dist/editor/variations/pick.d.ts.map +1 -0
- package/dist/editor/variations/pick.js +23 -0
- package/dist/editor/variations/pick.js.map +1 -0
- package/dist/editor/variations.d.ts +28 -0
- package/dist/editor/variations.d.ts.map +1 -0
- package/dist/editor/variations.js +88 -0
- package/dist/editor/variations.js.map +1 -0
- package/dist/figma-api/accessors/reactions.d.ts.map +1 -1
- package/dist/figma-api/accessors/reactions.js +4 -1
- package/dist/figma-api/accessors/reactions.js.map +1 -1
- package/dist/figma-api/accessors/text/index.js +3 -0
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/accessors/text/opentype.d.ts +17 -0
- package/dist/figma-api/accessors/text/opentype.d.ts.map +1 -0
- package/dist/figma-api/accessors/text/opentype.js +28 -0
- package/dist/figma-api/accessors/text/opentype.js.map +1 -0
- package/dist/figma-api/accessors/visual.d.ts.map +1 -1
- package/dist/figma-api/accessors/visual.js +33 -0
- package/dist/figma-api/accessors/visual.js.map +1 -1
- package/dist/figma-api/effects.d.ts +79 -3
- package/dist/figma-api/effects.d.ts.map +1 -1
- package/dist/figma-api/effects.js +150 -9
- package/dist/figma-api/effects.js.map +1 -1
- package/dist/figma-api/index.d.ts +5 -0
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +6 -1
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/overrides.d.ts +13 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +196 -4
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/paints.d.ts +3 -3
- package/dist/figma-api/paints.d.ts.map +1 -1
- package/dist/figma-api/paints.js +14 -4
- package/dist/figma-api/paints.js.map +1 -1
- package/dist/figma-api/proxy.d.ts +4 -1
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +1 -1
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +41 -13
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +113 -31
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/render-bounds.js +1 -1
- package/dist/figma-api/surface.d.ts +6 -3
- package/dist/figma-api/surface.d.ts.map +1 -1
- package/dist/figma-api/surface.js +6 -2
- package/dist/figma-api/surface.js.map +1 -1
- package/dist/figma-api/transform.d.ts +1 -1
- package/dist/geometry/figma.d.ts +1 -1
- package/dist/geometry/image-crop.d.ts +1 -1
- package/dist/geometry/image-crop.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/io/formats/boolean-path.d.ts +19 -0
- package/dist/io/formats/boolean-path.d.ts.map +1 -0
- package/dist/io/formats/boolean-path.js +47 -0
- package/dist/io/formats/boolean-path.js.map +1 -0
- package/dist/io/formats/design-tokens/decode.js +1 -1
- package/dist/io/formats/design-tokens/index.d.ts +4 -1
- package/dist/io/formats/design-tokens/index.js +4 -1
- package/dist/io/formats/design-tokens/plan/changes.d.ts +5 -3
- package/dist/io/formats/design-tokens/plan/changes.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/changes.js +1 -1
- package/dist/io/formats/design-tokens/plan/changes.js.map +1 -1
- package/dist/io/formats/design-tokens/project.d.ts +17 -2
- package/dist/io/formats/design-tokens/project.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/project.js +29 -8
- package/dist/io/formats/design-tokens/project.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/sync/apply.d.ts +42 -0
- package/dist/io/formats/design-tokens/sync/apply.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/apply.js +73 -0
- package/dist/io/formats/design-tokens/sync/apply.js.map +1 -0
- package/dist/io/formats/design-tokens/sync/drift.d.ts +77 -0
- package/dist/io/formats/design-tokens/sync/drift.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/drift.js +391 -0
- package/dist/io/formats/design-tokens/sync/drift.js.map +1 -0
- package/dist/io/formats/design-tokens/sync/files.d.ts +15 -0
- package/dist/io/formats/design-tokens/sync/files.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/files.js +35 -0
- package/dist/io/formats/design-tokens/sync/files.js.map +1 -0
- package/dist/io/formats/drawio/edges.d.ts +7 -1
- package/dist/io/formats/drawio/edges.d.ts.map +1 -1
- package/dist/io/formats/drawio/edges.js +54 -1
- package/dist/io/formats/drawio/edges.js.map +1 -1
- package/dist/io/formats/drawio/export.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.js +19 -2
- package/dist/io/formats/drawio/export.js.map +1 -1
- package/dist/io/formats/drawio/index.js +1 -0
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/drawio/label.js +1 -1
- package/dist/io/formats/drawio/paint.js +1 -1
- package/dist/io/formats/drawio/placement.d.ts +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +5 -0
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/thumbnail-page.d.ts +3 -4
- package/dist/io/formats/fig/thumbnail-page.d.ts.map +1 -1
- package/dist/io/formats/fig/thumbnail-page.js.map +1 -1
- package/dist/io/formats/html/import.d.ts.map +1 -1
- package/dist/io/formats/html/import.js +3 -1
- package/dist/io/formats/html/import.js.map +1 -1
- package/dist/io/formats/html/index.d.ts +2 -2
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +6 -4
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/html/vectors.d.ts +2 -1
- package/dist/io/formats/html/vectors.d.ts.map +1 -1
- package/dist/io/formats/html/vectors.js +3 -2
- package/dist/io/formats/html/vectors.js.map +1 -1
- package/dist/io/formats/mermaid/styles.js +1 -1
- package/dist/io/formats/pdf/document.d.ts +3 -1
- package/dist/io/formats/pdf/document.d.ts.map +1 -1
- package/dist/io/formats/pdf/document.js +6 -3
- package/dist/io/formats/pdf/document.js.map +1 -1
- package/dist/io/formats/pdf/prepare.d.ts +1 -1
- package/dist/io/formats/pen/imports.d.ts +4 -1
- package/dist/io/formats/pen/imports.d.ts.map +1 -1
- package/dist/io/formats/pen/imports.js.map +1 -1
- package/dist/io/formats/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +31 -3
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/pptx/export.js +1 -1
- package/dist/io/formats/pptx/geometry.d.ts +1 -1
- package/dist/io/formats/raster/adjusted-images.d.ts +15 -0
- package/dist/io/formats/raster/adjusted-images.d.ts.map +1 -0
- package/dist/io/formats/raster/adjusted-images.js +118 -0
- package/dist/io/formats/raster/adjusted-images.js.map +1 -0
- package/dist/io/formats/raster/headless.d.ts +11 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +4 -4
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/pixels.d.ts +7 -1
- package/dist/io/formats/raster/pixels.d.ts.map +1 -1
- package/dist/io/formats/raster/pixels.js.map +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +4 -0
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +5 -6
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +1 -53
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/effects.d.ts +16 -0
- package/dist/io/formats/svg/effects.d.ts.map +1 -0
- package/dist/io/formats/svg/effects.js +126 -0
- package/dist/io/formats/svg/effects.js.map +1 -0
- package/dist/io/formats/svg/export.d.ts +7 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +174 -36
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +27 -0
- package/dist/io/formats/svg/filter.d.ts.map +1 -0
- package/dist/io/formats/svg/filter.js +44 -0
- package/dist/io/formats/svg/filter.js.map +1 -0
- package/dist/io/formats/svg/grain.d.ts +26 -0
- package/dist/io/formats/svg/grain.d.ts.map +1 -0
- package/dist/io/formats/svg/grain.js +298 -0
- package/dist/io/formats/svg/grain.js.map +1 -0
- package/dist/io/formats/svg/strokes.d.ts +1 -1
- package/dist/io/formats/svg/strokes.d.ts.map +1 -1
- package/dist/io/formats/svg/strokes.js +1 -2
- package/dist/io/formats/svg/strokes.js.map +1 -1
- package/dist/io/formats/svg/text/import.js +1 -1
- package/dist/io/formats/svg/text/layout.d.ts +5 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +6 -3
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/composite.d.ts +18 -0
- package/dist/io/formats/video/composite.d.ts.map +1 -0
- package/dist/io/formats/video/composite.js +79 -0
- package/dist/io/formats/video/composite.js.map +1 -0
- package/dist/io/formats/video/formats.d.ts +29 -0
- package/dist/io/formats/video/formats.d.ts.map +1 -0
- package/dist/io/formats/video/formats.js +43 -0
- package/dist/io/formats/video/formats.js.map +1 -0
- package/dist/io/formats/video/gif.d.ts +13 -0
- package/dist/io/formats/video/gif.d.ts.map +1 -0
- package/dist/io/formats/video/gif.js +56 -0
- package/dist/io/formats/video/gif.js.map +1 -0
- package/dist/io/formats/video/index.d.ts +9 -0
- package/dist/io/formats/video/index.js +9 -0
- package/dist/io/formats/video/plan.d.ts +64 -0
- package/dist/io/formats/video/plan.d.ts.map +1 -0
- package/dist/io/formats/video/plan.js +90 -0
- package/dist/io/formats/video/plan.js.map +1 -0
- package/dist/io/formats/video/record.d.ts +36 -0
- package/dist/io/formats/video/record.d.ts.map +1 -0
- package/dist/io/formats/video/record.js +154 -0
- package/dist/io/formats/video/record.js.map +1 -0
- package/dist/io/formats/video/sink.d.ts +29 -0
- package/dist/io/formats/video/sink.d.ts.map +1 -0
- package/dist/io/formats/video/sink.js +16 -0
- package/dist/io/formats/video/sink.js.map +1 -0
- package/dist/io/formats/video/size.d.ts +19 -0
- package/dist/io/formats/video/size.d.ts.map +1 -0
- package/dist/io/formats/video/size.js +26 -0
- package/dist/io/formats/video/size.js.map +1 -0
- package/dist/io/formats/video/webcodecs.d.ts +18 -0
- package/dist/io/formats/video/webcodecs.d.ts.map +1 -0
- package/dist/io/formats/video/webcodecs.js +74 -0
- package/dist/io/formats/video/webcodecs.js.map +1 -0
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +40 -11
- package/dist/io/formats.js.map +1 -1
- package/dist/io/types.d.ts +19 -4
- package/dist/io/types.d.ts.map +1 -1
- package/dist/kiwi/fig/parse/transfer.d.ts +1 -1
- package/dist/layout/auto-layout-handles.d.ts +66 -0
- package/dist/layout/auto-layout-handles.d.ts.map +1 -0
- package/dist/layout/auto-layout-handles.js +291 -0
- package/dist/layout/auto-layout-handles.js.map +1 -0
- package/dist/layout.d.ts +3 -2
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +2 -1
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.d.ts.map +1 -1
- package/dist/lint/fixes.js +9 -3
- package/dist/lint/fixes.js.map +1 -1
- package/dist/lint/index.d.ts +3 -2
- package/dist/lint/index.js +2 -1
- package/dist/lint/linter.d.ts +12 -0
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +110 -8
- package/dist/lint/linter.js.map +1 -1
- package/dist/lint/presets.d.ts.map +1 -1
- package/dist/lint/presets.js +2 -0
- package/dist/lint/presets.js.map +1 -1
- package/dist/lint/rules/design-memory.d.ts +15 -0
- package/dist/lint/rules/design-memory.d.ts.map +1 -0
- package/dist/lint/rules/design-memory.js +90 -0
- package/dist/lint/rules/design-memory.js.map +1 -0
- package/dist/lint/rules/index.d.ts +6 -5
- package/dist/lint/rules/index.d.ts.map +1 -1
- package/dist/lint/rules/index.js +6 -2
- package/dist/lint/rules/index.js.map +1 -1
- package/dist/lint/rules/no-unbound-token-values.d.ts +6 -0
- package/dist/lint/rules/no-unbound-token-values.d.ts.map +1 -0
- package/dist/lint/rules/no-unbound-token-values.js +79 -0
- package/dist/lint/rules/no-unbound-token-values.js.map +1 -0
- package/dist/lint/types.d.ts +25 -2
- package/dist/lint/types.d.ts.map +1 -1
- package/dist/node/video.d.ts +12 -0
- package/dist/node/video.d.ts.map +1 -0
- package/dist/node/video.js +206 -0
- package/dist/node/video.js.map +1 -0
- package/dist/pairdraw-api/design-memory.d.ts +19 -0
- package/dist/pairdraw-api/design-memory.d.ts.map +1 -0
- package/dist/pairdraw-api/design-memory.js +39 -0
- package/dist/pairdraw-api/design-memory.js.map +1 -0
- package/dist/pairdraw-api/index.d.ts +45 -1
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +55 -2
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +12 -1
- package/dist/pairdraw-api/nodes.d.ts.map +1 -1
- package/dist/pairdraw-api/nodes.js +28 -1
- package/dist/pairdraw-api/nodes.js.map +1 -1
- package/dist/pairdraw-api/variations.d.ts +48 -0
- package/dist/pairdraw-api/variations.d.ts.map +1 -0
- package/dist/pairdraw-api/variations.js +76 -0
- package/dist/pairdraw-api/variations.js.map +1 -0
- package/dist/prototype/easing.d.ts +13 -0
- package/dist/prototype/easing.d.ts.map +1 -0
- package/dist/prototype/easing.js +36 -0
- package/dist/prototype/easing.js.map +1 -0
- package/dist/prototype/frames.d.ts +10 -0
- package/dist/prototype/frames.d.ts.map +1 -0
- package/dist/prototype/frames.js +12 -0
- package/dist/prototype/frames.js.map +1 -0
- package/dist/prototype/hit.d.ts +17 -0
- package/dist/prototype/hit.d.ts.map +1 -0
- package/dist/prototype/hit.js +45 -0
- package/dist/prototype/hit.js.map +1 -0
- package/dist/prototype/index.d.ts +14 -0
- package/dist/prototype/index.js +14 -0
- package/dist/prototype/pointer.d.ts +63 -0
- package/dist/prototype/pointer.d.ts.map +1 -0
- package/dist/prototype/pointer.js +104 -0
- package/dist/prototype/pointer.js.map +1 -0
- package/dist/prototype/reactions.d.ts +45 -0
- package/dist/prototype/reactions.d.ts.map +1 -0
- package/dist/prototype/reactions.js +122 -0
- package/dist/prototype/reactions.js.map +1 -0
- package/dist/prototype/scene.d.ts +35 -0
- package/dist/prototype/scene.d.ts.map +1 -0
- package/dist/prototype/scene.js +86 -0
- package/dist/prototype/scene.js.map +1 -0
- package/dist/prototype/scenes.d.ts +81 -0
- package/dist/prototype/scenes.d.ts.map +1 -0
- package/dist/prototype/scenes.js +175 -0
- package/dist/prototype/scenes.js.map +1 -0
- package/dist/prototype/scroll.d.ts +48 -0
- package/dist/prototype/scroll.d.ts.map +1 -0
- package/dist/prototype/scroll.js +159 -0
- package/dist/prototype/scroll.js.map +1 -0
- package/dist/prototype/session.d.ts +71 -0
- package/dist/prototype/session.d.ts.map +1 -0
- package/dist/prototype/session.js +135 -0
- package/dist/prototype/session.js.map +1 -0
- package/dist/prototype/smart-animate/animation.d.ts +34 -0
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -0
- package/dist/prototype/smart-animate/animation.js +212 -0
- package/dist/prototype/smart-animate/animation.js.map +1 -0
- package/dist/prototype/smart-animate/match.d.ts +24 -0
- package/dist/prototype/smart-animate/match.d.ts.map +1 -0
- package/dist/prototype/smart-animate/match.js +72 -0
- package/dist/prototype/smart-animate/match.js.map +1 -0
- package/dist/prototype/snapshot.d.ts +19 -0
- package/dist/prototype/snapshot.d.ts.map +1 -0
- package/dist/prototype/snapshot.js +56 -0
- package/dist/prototype/snapshot.js.map +1 -0
- package/dist/prototype/timeline.d.ts +132 -0
- package/dist/prototype/timeline.d.ts.map +1 -0
- package/dist/prototype/timeline.js +260 -0
- package/dist/prototype/timeline.js.map +1 -0
- package/dist/rpc/read-commands.js +1 -1
- package/dist/text/font/features.d.ts +9 -0
- package/dist/text/font/features.d.ts.map +1 -0
- package/dist/text/font/features.js +27 -0
- package/dist/text/font/features.js.map +1 -0
- package/dist/text/font/manager.d.ts +12 -0
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +60 -1
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +10 -8
- package/dist/text/index.js +3 -1
- package/dist/text/replace-fonts.d.ts +41 -0
- package/dist/text/replace-fonts.d.ts.map +1 -0
- package/dist/text/replace-fonts.js +121 -0
- package/dist/text/replace-fonts.js.map +1 -0
- package/dist/tools/analyze/responsive/index.d.ts +15 -0
- package/dist/tools/analyze/responsive/index.d.ts.map +1 -0
- package/dist/tools/analyze/responsive/index.js +203 -0
- package/dist/tools/analyze/responsive/index.js.map +1 -0
- package/dist/tools/analyze.d.ts +2 -1
- package/dist/tools/analyze.js +2 -1
- package/dist/tools/codegen/token-sync.d.ts +7 -0
- package/dist/tools/codegen/token-sync.d.ts.map +1 -0
- package/dist/tools/codegen/token-sync.js +85 -0
- package/dist/tools/codegen/token-sync.js.map +1 -0
- package/dist/tools/codegen/tokens.d.ts +1 -1
- package/dist/tools/codegen.d.ts +2 -1
- package/dist/tools/codegen.js +2 -1
- package/dist/tools/create/basic.js +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/components.d.ts.map +1 -1
- package/dist/tools/create/components.js +4 -0
- package/dist/tools/create/components.js.map +1 -1
- package/dist/tools/create/html.js +3 -2
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.d.ts.map +1 -1
- package/dist/tools/create/icons.js +2 -1
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.js +2 -1
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +2 -1
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +1 -1
- package/dist/tools/design-memory.d.ts +8 -0
- package/dist/tools/design-memory.d.ts.map +1 -0
- package/dist/tools/design-memory.js +68 -0
- package/dist/tools/design-memory.js.map +1 -0
- package/dist/tools/image-ai/generate.d.ts.map +1 -1
- package/dist/tools/image-ai/generate.js +3 -1
- package/dist/tools/image-ai/generate.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/modify/fonts.d.ts +6 -0
- package/dist/tools/modify/fonts.d.ts.map +1 -0
- package/dist/tools/modify/fonts.js +27 -0
- package/dist/tools/modify/fonts.js.map +1 -0
- package/dist/tools/modify/paint.js +1 -1
- package/dist/tools/modify/reactions.d.ts.map +1 -1
- package/dist/tools/modify/reactions.js +3 -3
- package/dist/tools/modify/reactions.js.map +1 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +26 -5
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify/update.d.ts +10 -1
- package/dist/tools/modify/update.d.ts.map +1 -1
- package/dist/tools/modify/update.js +34 -3
- package/dist/tools/modify/update.js.map +1 -1
- package/dist/tools/modify.d.ts +2 -1
- package/dist/tools/modify.js +2 -1
- package/dist/tools/read/fonts.d.ts.map +1 -1
- package/dist/tools/read/fonts.js +17 -2
- package/dist/tools/read/fonts.js.map +1 -1
- package/dist/tools/read/libraries.js +2 -1
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/space.d.ts +3 -1
- package/dist/tools/read/space.d.ts.map +1 -1
- package/dist/tools/read/space.js +4 -3
- package/dist/tools/read/space.js.map +1 -1
- package/dist/tools/registry/core.d.ts +1 -1
- package/dist/tools/registry/core.d.ts.map +1 -1
- package/dist/tools/registry/core.js +3 -1
- package/dist/tools/registry/core.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +16 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +18 -2
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +1 -1
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/stock-photo.js +1 -0
- package/dist/tools/stock-photo.js.map +1 -1
- package/dist/tools/structure/basic.d.ts.map +1 -1
- package/dist/tools/structure/basic.js +1 -0
- package/dist/tools/structure/basic.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +8 -1
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/structure/hierarchy.d.ts.map +1 -1
- package/dist/tools/structure/hierarchy.js +4 -0
- package/dist/tools/structure/hierarchy.js.map +1 -1
- package/dist/tools/structure/variations.d.ts +8 -0
- package/dist/tools/structure/variations.d.ts.map +1 -0
- package/dist/tools/structure/variations.js +106 -0
- package/dist/tools/structure/variations.js.map +1 -0
- package/dist/tools/structure.d.ts +2 -1
- package/dist/tools/structure.js +2 -1
- package/dist/tools/styles/types.d.ts +2 -4
- package/dist/tools/styles/types.d.ts.map +1 -1
- package/dist/tools/styles/types.js.map +1 -1
- package/dist/tools/vector/boolean.d.ts.map +1 -1
- package/dist/tools/vector/boolean.js +4 -0
- package/dist/tools/vector/boolean.js.map +1 -1
- package/dist/tools/vector/vectorize.js +1 -0
- package/dist/tools/vector/vectorize.js.map +1 -1
- package/dist/tools/vector/video.d.ts +6 -0
- package/dist/tools/vector/video.d.ts.map +1 -0
- package/dist/tools/vector/video.js +133 -0
- package/dist/tools/vector/video.js.map +1 -0
- package/dist/tools/vector.d.ts +2 -1
- package/dist/tools/vector.js +2 -1
- package/dist/tools/video-host.d.ts +12 -0
- package/dist/tools/video-host.d.ts.map +1 -0
- package/dist/tools/video-host.js +19 -0
- package/dist/tools/video-host.js.map +1 -0
- package/dist/vector/point-transform.d.ts +1 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts +1 -1
- package/package.json +31 -9
- package/src/ai/providers.ts +2 -0
- package/src/cache/resource.ts +24 -1
- package/src/canvas/effects.ts +47 -50
- package/src/canvas/fills.ts +19 -15
- package/src/canvas/images/adjustments.ts +203 -0
- package/src/canvas/images/sampling.ts +88 -0
- package/src/canvas/index.ts +1 -0
- package/src/canvas/masks.ts +1 -1
- package/src/canvas/noise/render.ts +75 -0
- package/src/canvas/noise/shader.ts +161 -0
- package/src/canvas/noise/table.ts +91 -0
- package/src/canvas/noise/tile.ts +94 -0
- package/src/canvas/overlays/auto-layout-hover.ts +47 -65
- package/src/canvas/renderer/lifecycle.ts +6 -0
- package/src/canvas/renderer/pipeline.ts +19 -1
- package/src/canvas/renderer/play-scenes.ts +51 -0
- package/src/canvas/renderer/tiles/cache.ts +54 -1
- package/src/canvas/renderer/tiles/controller.ts +30 -1
- package/src/canvas/renderer/types.ts +18 -2
- package/src/canvas/renderer.ts +40 -3
- package/src/canvas/scene.ts +65 -9
- package/src/canvas/texture.ts +136 -0
- package/src/clipboard.ts +23 -10
- package/src/constants.ts +6 -0
- package/src/design-memory/check.ts +376 -0
- package/src/design-memory/describe.ts +77 -0
- package/src/design-memory/distil.ts +69 -0
- package/src/design-memory/document.ts +80 -0
- package/src/design-memory/guard.ts +157 -0
- package/src/design-memory/index.ts +8 -0
- package/src/design-memory/refusal.ts +90 -0
- package/src/design-memory/rules.ts +274 -0
- package/src/design-memory/values.ts +179 -0
- package/src/editor/bridges/components.ts +2 -0
- package/src/editor/clipboard/export.ts +24 -7
- package/src/editor/components/instances.ts +31 -0
- package/src/editor/create.ts +25 -69
- package/src/editor/design-memory.ts +39 -0
- package/src/editor/design-tokens.ts +41 -2
- package/src/editor/document-colors.ts +65 -0
- package/src/editor/eyedropper.ts +198 -0
- package/src/editor/fonts.ts +19 -0
- package/src/editor/history/atomic-tool.ts +29 -1
- package/src/editor/history/capture.ts +19 -0
- package/src/editor/history/document-change.ts +5 -17
- package/src/editor/history/edit.ts +11 -1
- package/src/editor/history/subtree.ts +13 -2
- package/src/editor/index.ts +11 -0
- package/src/editor/pages.ts +40 -29
- package/src/editor/play/states.ts +1 -1
- package/src/editor/read-only/actions.ts +4 -0
- package/src/editor/render-requests.ts +83 -0
- package/src/editor/selection/overlays.ts +1 -0
- package/src/editor/tool-registry.ts +2 -1
- package/src/editor/types.ts +4 -0
- package/src/editor/variations/create.ts +235 -0
- package/src/editor/variations/pick.ts +35 -0
- package/src/editor/variations.ts +110 -0
- package/src/figma-api/accessors/reactions.ts +11 -1
- package/src/figma-api/accessors/text/index.ts +7 -0
- package/src/figma-api/accessors/text/opentype.ts +33 -0
- package/src/figma-api/accessors/visual.ts +55 -2
- package/src/figma-api/compatibility.ts +5 -2
- package/src/figma-api/effects.ts +143 -5
- package/src/figma-api/index.ts +10 -0
- package/src/figma-api/overrides.ts +295 -3
- package/src/figma-api/paints.ts +24 -9
- package/src/figma-api/proxy.ts +6 -1
- package/src/figma-api/reactions.ts +130 -32
- package/src/figma-api/surface.ts +6 -2
- package/src/global.d.ts +26 -0
- package/src/io/formats/boolean-path.ts +60 -0
- package/src/io/formats/design-tokens/index.ts +21 -0
- package/src/io/formats/design-tokens/plan/changes.ts +4 -1
- package/src/io/formats/design-tokens/project.ts +40 -9
- package/src/io/formats/design-tokens/styles.ts +10 -2
- package/src/io/formats/design-tokens/sync/apply.ts +130 -0
- package/src/io/formats/design-tokens/sync/drift.ts +587 -0
- package/src/io/formats/design-tokens/sync/files.ts +40 -0
- package/src/io/formats/drawio/edges.ts +65 -0
- package/src/io/formats/drawio/export.ts +37 -14
- package/src/io/formats/drawio/index.ts +2 -0
- package/src/io/formats/fig/export/patch/index.ts +8 -0
- package/src/io/formats/fig/thumbnail-page.ts +4 -4
- package/src/io/formats/html/import.ts +9 -1
- package/src/io/formats/html/index.ts +14 -7
- package/src/io/formats/html/vectors.ts +8 -2
- package/src/io/formats/pdf/document.ts +14 -4
- package/src/io/formats/pen/imports.ts +5 -6
- package/src/io/formats/pen/index.ts +36 -5
- package/src/io/formats/raster/adjusted-images.ts +125 -0
- package/src/io/formats/raster/headless.ts +3 -3
- package/src/io/formats/raster/index.ts +6 -1
- package/src/io/formats/raster/pixels.ts +7 -0
- package/src/io/formats/raster/render.ts +12 -1
- package/src/io/formats/svg/defs.ts +4 -72
- package/src/io/formats/svg/effects.ts +131 -0
- package/src/io/formats/svg/export.ts +278 -46
- package/src/io/formats/svg/filter.ts +47 -0
- package/src/io/formats/svg/grain.ts +249 -0
- package/src/io/formats/svg/strokes.ts +2 -2
- package/src/io/formats/svg/text/layout.ts +13 -3
- package/src/io/formats/video/composite.ts +79 -0
- package/src/io/formats/video/formats.ts +77 -0
- package/src/io/formats/video/gif.ts +65 -0
- package/src/io/formats/video/index.ts +30 -0
- package/src/io/formats/video/plan.ts +116 -0
- package/src/io/formats/video/record.ts +227 -0
- package/src/io/formats/video/sink.ts +32 -0
- package/src/io/formats/video/size.ts +25 -0
- package/src/io/formats/video/webcodecs.ts +89 -0
- package/src/io/formats.ts +59 -11
- package/src/io/types.ts +29 -10
- package/src/layout/auto-layout-handles.ts +396 -0
- package/src/layout.ts +2 -0
- package/src/lint/fixes.ts +12 -3
- package/src/lint/index.ts +3 -1
- package/src/lint/linter.ts +107 -10
- package/src/lint/presets.ts +2 -0
- package/src/lint/rules/design-memory.ts +97 -0
- package/src/lint/rules/index.ts +6 -1
- package/src/lint/rules/no-unbound-token-values.ts +73 -0
- package/src/lint/types.ts +32 -0
- package/src/node/video.ts +196 -0
- package/src/pairdraw-api/design-memory.ts +61 -0
- package/src/pairdraw-api/index.ts +81 -0
- package/src/pairdraw-api/nodes.ts +38 -0
- package/src/pairdraw-api/variations.ts +109 -0
- package/src/prototype/easing.ts +37 -0
- package/src/prototype/frames.ts +9 -0
- package/src/prototype/hit.ts +70 -0
- package/src/prototype/index.ts +69 -0
- package/src/prototype/pointer.ts +146 -0
- package/src/prototype/reactions.ts +178 -0
- package/src/prototype/scene.ts +116 -0
- package/src/prototype/scenes.ts +256 -0
- package/src/prototype/scroll.ts +190 -0
- package/src/prototype/session.ts +188 -0
- package/src/prototype/smart-animate/animation.ts +267 -0
- package/src/prototype/smart-animate/match.ts +85 -0
- package/src/prototype/snapshot.ts +60 -0
- package/src/prototype/timeline.ts +400 -0
- package/src/text/font/features.ts +27 -0
- package/src/text/font/manager.ts +79 -1
- package/src/text/index.ts +2 -0
- package/src/text/replace-fonts.ts +171 -0
- package/src/tools/analyze/responsive/index.ts +264 -0
- package/src/tools/analyze.ts +2 -0
- package/src/tools/codegen/token-sync.ts +98 -0
- package/src/tools/codegen.ts +1 -0
- package/src/tools/create/components.ts +4 -0
- package/src/tools/create/html.ts +1 -0
- package/src/tools/create/icons.ts +1 -0
- package/src/tools/create/mermaid.ts +1 -0
- package/src/tools/create/svg.ts +1 -0
- package/src/tools/design-memory.ts +72 -0
- package/src/tools/image-ai/generate.ts +2 -0
- package/src/tools/index.ts +1 -0
- package/src/tools/modify/fonts.ts +34 -0
- package/src/tools/modify/reactions.ts +15 -8
- package/src/tools/modify/text.ts +42 -5
- package/src/tools/modify/update.ts +46 -2
- package/src/tools/modify.ts +1 -0
- package/src/tools/read/fonts.ts +24 -2
- package/src/tools/read/libraries.ts +1 -0
- package/src/tools/read/space.ts +3 -2
- package/src/tools/registry/core.ts +3 -1
- package/src/tools/registry/extended.ts +28 -1
- package/src/tools/schema.ts +28 -4
- package/src/tools/stock-photo.ts +1 -0
- package/src/tools/structure/basic.ts +1 -0
- package/src/tools/structure/batch.ts +12 -1
- package/src/tools/structure/hierarchy.ts +4 -0
- package/src/tools/structure/variations.ts +118 -0
- package/src/tools/structure.ts +2 -0
- package/src/tools/styles/types.ts +3 -4
- package/src/tools/vector/boolean.ts +4 -0
- package/src/tools/vector/vectorize.ts +1 -0
- package/src/tools/vector/video.ts +228 -0
- package/src/tools/vector.ts +1 -0
- package/src/tools/video-host.ts +18 -0
|
@@ -39,6 +39,6 @@ function countTokenImportChanges(graph, plan) {
|
|
|
39
39
|
return plan.collections.reduce((count, collection) => count + collectionChanges(graph, plan, collection), plan.styles.length);
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
|
-
export { countTokenImportChanges };
|
|
42
|
+
export { countTokenImportChanges, plannedValue };
|
|
43
43
|
|
|
44
44
|
//# sourceMappingURL=changes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changes.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/plan/changes.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph, VariableValue } from '@pairdraw/scene-graph'\n\nimport type { PlannedCollection, PlannedValue, TokenImportPlan } from './index'\n\n/** The value a planned one sets, or undefined where it points at a variable the import adds. */\
|
|
1
|
+
{"version":3,"file":"changes.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/plan/changes.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph, VariableValue } from '@pairdraw/scene-graph'\n\nimport type { PlannedCollection, PlannedValue, TokenImportPlan } from './index'\n\n/** The value a planned one sets, or undefined where it points at a variable the import adds. */\nexport function plannedValue(\n plan: TokenImportPlan,\n value: PlannedValue\n): VariableValue | undefined {\n if (value.kind === 'literal') return value.value\n const { target } = value\n if (target.kind === 'variable') return { aliasId: target.variableId }\n const existingId = plan.collections[target.collection]?.variables[target.variable]?.existingId\n return existingId ? { aliasId: existingId } : undefined\n}\n\nfunction collectionChanges(\n graph: SceneGraph,\n plan: TokenImportPlan,\n collection: PlannedCollection\n): number {\n if (collection.target.kind === 'new') return collection.variables.length + 1\n const newModes = collection.modes.filter((mode) => mode.target.kind === 'new').length\n let changed = newModes\n for (const variable of collection.variables) {\n const current = variable.existingId ? graph.variables.get(variable.existingId) : undefined\n if (!current) {\n changed++\n continue\n }\n // A changed unit or CSS expression counts even where the number it comes to is the same.\n const unitChanged = variable.unit !== undefined && variable.unit !== current.unit\n const differs = variable.values.some((value, index) => {\n const target = collection.modes.at(index)?.target\n if (!value || !target) return false\n if (target.kind !== 'existing') return true\n const next = plannedValue(plan, value)\n if (next === undefined || !isEqual(current.valuesByMode[target.modeId], next)) return true\n return variable.expressions[index] !== current.expressions?.[target.modeId]?.css\n })\n if (unitChanged || differs) changed++\n }\n return changed\n}\n\n/**\n * How many things an import would change: collections and modes it adds, variables it adds, and\n * variables whose values it changes, so an import that would only write what the document already\n * has can be left out. Styles count whenever they are planned.\n */\nexport function countTokenImportChanges(graph: SceneGraph, plan: TokenImportPlan): number {\n return plan.collections.reduce(\n (count, collection) => count + collectionChanges(graph, plan, collection),\n plan.styles.length\n )\n}\n"],"mappings":";;;AAOA,SAAgB,aACd,MACA,OAC2B;CAC3B,IAAI,MAAM,SAAS,WAAW,OAAO,MAAM;CAC3C,MAAM,EAAE,WAAW;CACnB,IAAI,OAAO,SAAS,YAAY,OAAO,EAAE,SAAS,OAAO,WAAW;CACpE,MAAM,aAAa,KAAK,YAAY,OAAO,WAAW,EAAE,UAAU,OAAO,SAAS,EAAE;CACpF,OAAO,aAAa,EAAE,SAAS,WAAW,IAAI,KAAA;AAChD;AAEA,SAAS,kBACP,OACA,MACA,YACQ;CACR,IAAI,WAAW,OAAO,SAAS,OAAO,OAAO,WAAW,UAAU,SAAS;CAE3E,IAAI,UADa,WAAW,MAAM,QAAQ,SAAS,KAAK,OAAO,SAAS,KAAK,CAAC,CAAC;CAE/E,KAAK,MAAM,YAAY,WAAW,WAAW;EAC3C,MAAM,UAAU,SAAS,aAAa,MAAM,UAAU,IAAI,SAAS,UAAU,IAAI,KAAA;EACjF,IAAI,CAAC,SAAS;GACZ;GACA;EACF;EAEA,MAAM,cAAc,SAAS,SAAS,KAAA,KAAa,SAAS,SAAS,QAAQ;EAC7E,MAAM,UAAU,SAAS,OAAO,MAAM,OAAO,UAAU;GACrD,MAAM,SAAS,WAAW,MAAM,GAAG,KAAK,CAAC,EAAE;GAC3C,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;GAC9B,IAAI,OAAO,SAAS,YAAY,OAAO;GACvC,MAAM,OAAO,aAAa,MAAM,KAAK;GACrC,IAAI,SAAS,KAAA,KAAa,CAAC,QAAQ,QAAQ,aAAa,OAAO,SAAS,IAAI,GAAG,OAAO;GACtF,OAAO,SAAS,YAAY,WAAW,QAAQ,cAAc,OAAO,OAAO,EAAE;EAC/E,CAAC;EACD,IAAI,eAAe,SAAS;CAC9B;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,wBAAwB,OAAmB,MAA+B;CACxF,OAAO,KAAK,YAAY,QACrB,OAAO,eAAe,QAAQ,kBAAkB,OAAO,MAAM,UAAU,GACxE,KAAK,OAAO,MACd;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DesignTokenReadIssue, DesignTokenSourceFile } from "./read.js";
|
|
1
|
+
import { DesignTokenBundle, DesignTokenReadIssue, DesignTokenSourceFile } from "./read.js";
|
|
2
2
|
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
3
3
|
//#region src/io/formats/design-tokens/project.d.ts
|
|
4
4
|
/** A stylesheet or manifest the folder reader already loaded. Paths stay inside the folder. */
|
|
@@ -53,6 +53,21 @@ declare const DESIGN_SYSTEM_MAX_FILES = 200;
|
|
|
53
53
|
declare const DESIGN_SYSTEM_MAX_TOTAL_BYTES: number;
|
|
54
54
|
/** A relative path that cannot climb out of the folder it was given against. */
|
|
55
55
|
declare function confinedDesignSystemPath(path: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The stylesheets a project folder's tokens come from: the one `components.json` names, or every
|
|
58
|
+
* stylesheet that declares custom properties. Paths that leave the folder and JavaScript config
|
|
59
|
+
* are reported, not read.
|
|
60
|
+
*/
|
|
61
|
+
declare function designSystemStylesheets(folder: DesignSystemFolder): {
|
|
62
|
+
stylesheets: DesignSystemSourceFile[];
|
|
63
|
+
issues: DesignSystemIssue[];
|
|
64
|
+
manifestPath?: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* One stylesheet of a project as a token bundle, read against the document as it is now. A
|
|
68
|
+
* shadcn/ui `:root` and `.dark` pair becomes Light and Dark modes; the bundle's issues are noted.
|
|
69
|
+
*/
|
|
70
|
+
declare function readDesignSystemStylesheet(graph: SceneGraph, file: DesignSystemSourceFile, issues: DesignSystemIssue[]): DesignTokenBundle;
|
|
56
71
|
/**
|
|
57
72
|
* Imports CSS variables from files already read inside one project folder.
|
|
58
73
|
* A shadcn/ui `:root` and `.dark` pair becomes one collection with Light and Dark modes.
|
|
@@ -60,5 +75,5 @@ declare function confinedDesignSystemPath(path: string): boolean;
|
|
|
60
75
|
*/
|
|
61
76
|
declare function importDesignSystemFiles(graph: SceneGraph, folder: DesignSystemFolder): DesignSystemImportResult;
|
|
62
77
|
//#endregion
|
|
63
|
-
export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, DesignSystemFolder, DesignSystemImportResult, DesignSystemIssue, DesignSystemSourceFile, confinedDesignSystemPath, importDesignSystemFiles };
|
|
78
|
+
export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, DesignSystemFolder, DesignSystemImportResult, DesignSystemIssue, DesignSystemSourceFile, confinedDesignSystemPath, designSystemStylesheets, importDesignSystemFiles, readDesignSystemStylesheet };
|
|
64
79
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"mappings":";;;;KAeY,yBAAyB;KAEzB,oBACR;EACE;EAA0B;;EAC1B;EAA4B;;EAC5B;EAAsB;;EACtB;EAAwB;;EACxB;EAAwB;;EACxB;EAAyB;;EACzB;EAAoB;;EACpB;EAAiC;;EACjC;EAA2B;EAAc;EAAc;;;UAG5C;EACf,OAAO;EACP,QAAQ;;EAER;;UAGe;EACf;EACA;EACA,QAAQ;;;cAIG;;cAGA;;cAGA;;iBAsBG,yBAAyB;;;;;;iBA+
|
|
1
|
+
{"version":3,"file":"project.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"mappings":";;;;KAeY,yBAAyB;KAEzB,oBACR;EACE;EAA0B;;EAC1B;EAA4B;;EAC5B;EAAsB;;EACtB;EAAwB;;EACxB;EAAwB;;EACxB;EAAyB;;EACzB;EAAoB;;EACpB;EAAiC;;EACjC;EAA2B;EAAc;EAAc;;;UAG5C;EACf,OAAO;EACP,QAAQ;;EAER;;UAGe;EACf;EACA;EACA,QAAQ;;;cAIG;;cAGA;;cAGA;;iBAsBG,yBAAyB;;;;;;iBA0GzB,wBAAwB,QAAQ;EAC9C,aAAa;EACb,QAAQ;EACR;;;;;;iBAgBc,2BACd,OAAO,YACP,MAAM,wBACN,QAAQ,sBACP;;;;;;iBA+Ba,wBACd,OAAO,YACP,QAAQ,qBACP"}
|
|
@@ -124,10 +124,33 @@ function manifestChoice(files, issues) {
|
|
|
124
124
|
path: manifest.path
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The stylesheets a project folder's tokens come from: the one `components.json` names, or every
|
|
129
|
+
* stylesheet that declares custom properties. Paths that leave the folder and JavaScript config
|
|
130
|
+
* are reported, not read.
|
|
131
|
+
*/
|
|
132
|
+
function designSystemStylesheets(folder) {
|
|
133
|
+
const issues = [...folder.issues];
|
|
134
|
+
const files = confineFiles(folder, issues);
|
|
135
|
+
const manifest = manifestChoice(files, issues);
|
|
136
|
+
return {
|
|
137
|
+
stylesheets: stylesheets(files, manifest.stylesheet, issues),
|
|
138
|
+
issues,
|
|
139
|
+
manifestPath: manifest.path
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* One stylesheet of a project as a token bundle, read against the document as it is now. A
|
|
144
|
+
* shadcn/ui `:root` and `.dark` pair becomes Light and Dark modes; the bundle's issues are noted.
|
|
145
|
+
*/
|
|
146
|
+
function readDesignSystemStylesheet(graph, file, issues) {
|
|
128
147
|
const bundle = readCSSDesignTokens(graph, file.text, { file: file.path });
|
|
129
148
|
renameShadcnModes(bundle);
|
|
130
149
|
for (const issue of bundle.issues) addIssue(issues, issue);
|
|
150
|
+
return bundle;
|
|
151
|
+
}
|
|
152
|
+
function importStylesheetFile(graph, pageId, file, issues) {
|
|
153
|
+
const bundle = readDesignSystemStylesheet(graph, file, issues);
|
|
131
154
|
const plan = planTokenImport(graph, bundle, defaultTokenImportOptions(graph, bundle));
|
|
132
155
|
for (const skip of plan.skipped) addIssue(issues, {
|
|
133
156
|
kind: "unsupported-value",
|
|
@@ -143,17 +166,15 @@ function importStylesheetFile(graph, pageId, file, issues) {
|
|
|
143
166
|
* JavaScript config is reported and ignored. Component source is recorded and not imported.
|
|
144
167
|
*/
|
|
145
168
|
function importDesignSystemFiles(graph, folder) {
|
|
146
|
-
const issues =
|
|
147
|
-
|
|
148
|
-
const manifest = manifestChoice(files, issues);
|
|
149
|
-
if (manifest.path || folder.componentsPath) addIssue(issues, {
|
|
169
|
+
const { stylesheets: files, issues, manifestPath } = designSystemStylesheets(folder);
|
|
170
|
+
if (manifestPath || folder.componentsPath) addIssue(issues, {
|
|
150
171
|
kind: "components-not-imported",
|
|
151
|
-
path:
|
|
172
|
+
path: manifestPath ?? folder.componentsPath ?? "components.json"
|
|
152
173
|
});
|
|
153
174
|
const pageId = graph.getPages()[0]?.id ?? graph.rootId;
|
|
154
175
|
const collectionIds = [];
|
|
155
176
|
const variableIds = [];
|
|
156
|
-
for (const file of
|
|
177
|
+
for (const file of files) {
|
|
157
178
|
const imported = importStylesheetFile(graph, pageId, file, issues);
|
|
158
179
|
collectionIds.push(...imported.collectionIds);
|
|
159
180
|
variableIds.push(...imported.variableIds);
|
|
@@ -165,6 +186,6 @@ function importDesignSystemFiles(graph, folder) {
|
|
|
165
186
|
};
|
|
166
187
|
}
|
|
167
188
|
//#endregion
|
|
168
|
-
export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, confinedDesignSystemPath, importDesignSystemFiles };
|
|
189
|
+
export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, confinedDesignSystemPath, designSystemStylesheets, importDesignSystemFiles, readDesignSystemStylesheet };
|
|
169
190
|
|
|
170
191
|
//# sourceMappingURL=project.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"sourcesContent":["import { isAbsolute, normalize, posix } from 'pathe'\nimport * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { importTokensIntoGraph } from '#core/io/formats/design-tokens/apply'\nimport { readCSSDesignTokens } from '#core/io/formats/design-tokens/css/read'\nimport { defaultTokenImportOptions, planTokenImport } from '#core/io/formats/design-tokens/plan'\nimport type {\n DesignTokenBundle,\n DesignTokenReadIssue,\n DesignTokenSourceFile\n} from '#core/io/formats/design-tokens/read'\n\n/** A stylesheet or manifest the folder reader already loaded. Paths stay inside the folder. */\nexport type DesignSystemSourceFile = DesignTokenSourceFile\n\nexport type DesignSystemIssue =\n | DesignTokenReadIssue\n | { kind: 'invalid-manifest'; path: string }\n | { kind: 'unsupported-config'; path: string }\n | { kind: 'escaped-path'; path: string }\n | { kind: 'file-too-large'; path: string }\n | { kind: 'too-many-files'; path: string }\n | { kind: 'total-too-large'; path: string }\n | { kind: 'unreadable'; path: string }\n | { kind: 'components-not-imported'; path: string }\n | { kind: 'unsupported-value'; path: string; name: string; reason: string }\n\n/** Files and notes a folder walk hands to the importer. The walk itself stays in Node. */\nexport interface DesignSystemFolder {\n files: DesignSystemSourceFile[]\n issues: DesignSystemIssue[]\n /** Set when the folder has component source, which this import does not read. */\n componentsPath?: string\n}\n\nexport interface DesignSystemImportResult {\n collectionIds: string[]\n variableIds: string[]\n issues: DesignSystemIssue[]\n}\n\n/** Files larger than this are reported and not read. */\nexport const DESIGN_SYSTEM_MAX_FILE_BYTES = 1_048_576\n\n/** How many stylesheets and manifests a folder read keeps. The next one is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_FILES = 200\n\n/** Total bytes of files a folder read keeps. The file that would pass this is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_TOTAL_BYTES = 8 * DESIGN_SYSTEM_MAX_FILE_BYTES\n\nconst CONFIG_FILE = /^tailwind\\.config\\.(?:js|ts|mjs|cjs|cts|mts)$/\n\nconst manifestSchema = v.looseObject({\n tailwind: v.optional(\n v.looseObject({\n css: v.optional(v.string()),\n config: v.optional(v.string())\n })\n )\n})\n\nfunction sameIssue(left: DesignSystemIssue, right: DesignSystemIssue): boolean {\n return JSON.stringify(left) === JSON.stringify(right)\n}\n\nfunction addIssue(issues: DesignSystemIssue[], issue: DesignSystemIssue): void {\n if (!issues.some((existing) => sameIssue(existing, issue))) issues.push(issue)\n}\n\n/** A relative path that cannot climb out of the folder it was given against. */\nexport function confinedDesignSystemPath(path: string): boolean {\n if (path.trim() === '') return false\n const normalized = normalize(path)\n if (normalized === '.' || isAbsolute(normalized)) return false\n return !normalized.split('/').includes('..')\n}\n\nfunction isConfigFile(path: string): boolean {\n return CONFIG_FILE.test(posix.basename(normalize(path)))\n}\n\nfunction declaresCustomProperties(text: string): boolean {\n return /@theme\\b/.test(text) || /(?:^|[^\\w-])--[\\w-]+\\s*:/.test(text)\n}\n\n/** shadcn/ui writes the light values on `:root` and the dark values on `.dark`. */\nfunction renameShadcnModes(bundle: DesignTokenBundle): void {\n for (const collection of bundle.collections) {\n const base = collection.modes.find(\n (mode) => mode.isDefault && mode.name === 'Default' && mode.condition === undefined\n )\n const dark = collection.modes.find((mode) => mode.name === 'dark' && mode.condition === '.dark')\n if (!base || !dark) continue\n const taken = new Set(collection.modes.map((mode) => mode.name))\n if (taken.has('Light') || taken.has('Dark')) continue\n base.name = 'Light'\n dark.name = 'Dark'\n }\n}\n\nfunction stylesheets(\n files: readonly DesignSystemSourceFile[],\n named: string | null | undefined,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n if (named === null) return []\n const css = files.filter((file) => posix.basename(file.path).endsWith('.css'))\n if (named === undefined) return css.filter((file) => declaresCustomProperties(file.text))\n const match = css.find((file) => posix.normalize(file.path) === named)\n if (!match) addIssue(issues, { kind: 'missing-file', file: named, from: 'components.json' })\n return match ? [match] : []\n}\n\nfunction confineFiles(\n folder: DesignSystemFolder,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n const files: DesignSystemSourceFile[] = []\n for (const file of folder.files) {\n if (!confinedDesignSystemPath(file.path)) {\n addIssue(issues, { kind: 'escaped-path', path: file.path })\n continue\n }\n files.push(file)\n if (isConfigFile(file.path)) addIssue(issues, { kind: 'unsupported-config', path: file.path })\n }\n return files\n}\n\nfunction noteTailwindConfig(config: string | undefined, issues: DesignSystemIssue[]): void {\n const path = config?.trim()\n if (!path) return\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return\n }\n if (isConfigFile(path)) addIssue(issues, { kind: 'unsupported-config', path })\n}\n\n/** `undefined` scans stylesheets that declare variables. `null` imports none. */\nfunction stylesheetNamedByManifest(\n css: string | undefined,\n issues: DesignSystemIssue[]\n): string | null | undefined {\n const path = css?.trim()\n if (!path) return undefined\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return null\n }\n return posix.normalize(path)\n}\n\nfunction manifestChoice(\n files: readonly DesignSystemSourceFile[],\n issues: DesignSystemIssue[]\n): { stylesheet: string | null | undefined; path?: string } {\n const manifest = files.find((file) => posix.normalize(file.path) === 'components.json')\n if (!manifest) return { stylesheet: undefined }\n const parsed = v.safeParse(v.pipe(v.string(), v.parseJson(), manifestSchema), manifest.text)\n if (!parsed.success) {\n addIssue(issues, { kind: 'invalid-manifest', path: manifest.path })\n return { stylesheet: undefined, path: manifest.path }\n }\n noteTailwindConfig(parsed.output.tailwind?.config, issues)\n return {\n stylesheet: stylesheetNamedByManifest(parsed.output.tailwind?.css, issues),\n path: manifest.path\n }\n}\n\nfunction importStylesheetFile(\n graph: SceneGraph,\n pageId: string,\n file: DesignSystemSourceFile,\n issues: DesignSystemIssue[]\n): { collectionIds: string[]; variableIds: string[] } {\n const bundle = readCSSDesignTokens(graph, file.text, { file: file.path })\n renameShadcnModes(bundle)\n for (const issue of bundle.issues) addIssue(issues, issue)\n const plan = planTokenImport(graph, bundle, defaultTokenImportOptions(graph, bundle))\n for (const skip of plan.skipped) {\n addIssue(issues, {\n kind: 'unsupported-value',\n path: file.path,\n name: skip.name,\n reason: skip.reason\n })\n }\n return importTokensIntoGraph(graph, pageId, plan)\n}\n\n/**\n * Imports CSS variables from files already read inside one project folder.\n * A shadcn/ui `:root` and `.dark` pair becomes one collection with Light and Dark modes.\n * JavaScript config is reported and ignored. Component source is recorded and not imported.\n */\nexport function importDesignSystemFiles(\n graph: SceneGraph,\n folder: DesignSystemFolder\n): DesignSystemImportResult {\n const issues = [...folder.issues]\n const files = confineFiles(folder, issues)\n const manifest = manifestChoice(files, issues)\n if (manifest.path || folder.componentsPath) {\n addIssue(issues, {\n kind: 'components-not-imported',\n path: manifest.path ?? folder.componentsPath ?? 'components.json'\n })\n }\n\n const pageId = graph.getPages()[0]?.id ?? graph.rootId\n const collectionIds: string[] = []\n const variableIds: string[] = []\n for (const file of stylesheets(files, manifest.stylesheet, issues)) {\n const imported = importStylesheetFile(graph, pageId, file, issues)\n collectionIds.push(...imported.collectionIds)\n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BAAsB,OAAO,QAAQ,IAAI;AAClD;;;;;;AAOA,SAAgB,wBACd,OACA,QAC0B;CAC1B,MAAM,SAAS,CAAC,GAAG,OAAO,MAAM;CAChC,MAAM,QAAQ,aAAa,QAAQ,MAAM;CACzC,MAAM,WAAW,eAAe,OAAO,MAAM;CAC7C,IAAI,SAAS,QAAQ,OAAO,gBAC1B,SAAS,QAAQ;EACf,MAAM;EACN,MAAM,SAAS,QAAQ,OAAO,kBAAkB;CAClD,CAAC;CAGH,MAAM,SAAS,MAAM,SAAS,CAAC,CAAC,EAAE,EAAE,MAAM,MAAM;CAChD,MAAM,gBAA0B,CAAC;CACjC,MAAM,cAAwB,CAAC;CAC/B,KAAK,MAAM,QAAQ,YAAY,OAAO,SAAS,YAAY,MAAM,GAAG;EAClE,MAAM,WAAW,qBAAqB,OAAO,QAAQ,MAAM,MAAM;EACjE,cAAc,KAAK,GAAG,SAAS,aAAa;EAC5C,YAAY,KAAK,GAAG,SAAS,WAAW;CAC1C;CACA,OAAO;EAAE;EAAe;EAAa;CAAO;AAC9C"}
|
|
1
|
+
{"version":3,"file":"project.js","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"sourcesContent":["import { isAbsolute, normalize, posix } from 'pathe'\nimport * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { importTokensIntoGraph } from '#core/io/formats/design-tokens/apply'\nimport { readCSSDesignTokens } from '#core/io/formats/design-tokens/css/read'\nimport { defaultTokenImportOptions, planTokenImport } from '#core/io/formats/design-tokens/plan'\nimport type {\n DesignTokenBundle,\n DesignTokenReadIssue,\n DesignTokenSourceFile\n} from '#core/io/formats/design-tokens/read'\n\n/** A stylesheet or manifest the folder reader already loaded. Paths stay inside the folder. */\nexport type DesignSystemSourceFile = DesignTokenSourceFile\n\nexport type DesignSystemIssue =\n | DesignTokenReadIssue\n | { kind: 'invalid-manifest'; path: string }\n | { kind: 'unsupported-config'; path: string }\n | { kind: 'escaped-path'; path: string }\n | { kind: 'file-too-large'; path: string }\n | { kind: 'too-many-files'; path: string }\n | { kind: 'total-too-large'; path: string }\n | { kind: 'unreadable'; path: string }\n | { kind: 'components-not-imported'; path: string }\n | { kind: 'unsupported-value'; path: string; name: string; reason: string }\n\n/** Files and notes a folder walk hands to the importer. The walk itself stays in Node. */\nexport interface DesignSystemFolder {\n files: DesignSystemSourceFile[]\n issues: DesignSystemIssue[]\n /** Set when the folder has component source, which this import does not read. */\n componentsPath?: string\n}\n\nexport interface DesignSystemImportResult {\n collectionIds: string[]\n variableIds: string[]\n issues: DesignSystemIssue[]\n}\n\n/** Files larger than this are reported and not read. */\nexport const DESIGN_SYSTEM_MAX_FILE_BYTES = 1_048_576\n\n/** How many stylesheets and manifests a folder read keeps. The next one is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_FILES = 200\n\n/** Total bytes of files a folder read keeps. The file that would pass this is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_TOTAL_BYTES = 8 * DESIGN_SYSTEM_MAX_FILE_BYTES\n\nconst CONFIG_FILE = /^tailwind\\.config\\.(?:js|ts|mjs|cjs|cts|mts)$/\n\nconst manifestSchema = v.looseObject({\n tailwind: v.optional(\n v.looseObject({\n css: v.optional(v.string()),\n config: v.optional(v.string())\n })\n )\n})\n\nfunction sameIssue(left: DesignSystemIssue, right: DesignSystemIssue): boolean {\n return JSON.stringify(left) === JSON.stringify(right)\n}\n\nfunction addIssue(issues: DesignSystemIssue[], issue: DesignSystemIssue): void {\n if (!issues.some((existing) => sameIssue(existing, issue))) issues.push(issue)\n}\n\n/** A relative path that cannot climb out of the folder it was given against. */\nexport function confinedDesignSystemPath(path: string): boolean {\n if (path.trim() === '') return false\n const normalized = normalize(path)\n if (normalized === '.' || isAbsolute(normalized)) return false\n return !normalized.split('/').includes('..')\n}\n\nfunction isConfigFile(path: string): boolean {\n return CONFIG_FILE.test(posix.basename(normalize(path)))\n}\n\nfunction declaresCustomProperties(text: string): boolean {\n return /@theme\\b/.test(text) || /(?:^|[^\\w-])--[\\w-]+\\s*:/.test(text)\n}\n\n/** shadcn/ui writes the light values on `:root` and the dark values on `.dark`. */\nfunction renameShadcnModes(bundle: DesignTokenBundle): void {\n for (const collection of bundle.collections) {\n const base = collection.modes.find(\n (mode) => mode.isDefault && mode.name === 'Default' && mode.condition === undefined\n )\n const dark = collection.modes.find((mode) => mode.name === 'dark' && mode.condition === '.dark')\n if (!base || !dark) continue\n const taken = new Set(collection.modes.map((mode) => mode.name))\n if (taken.has('Light') || taken.has('Dark')) continue\n base.name = 'Light'\n dark.name = 'Dark'\n }\n}\n\nfunction stylesheets(\n files: readonly DesignSystemSourceFile[],\n named: string | null | undefined,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n if (named === null) return []\n const css = files.filter((file) => posix.basename(file.path).endsWith('.css'))\n if (named === undefined) return css.filter((file) => declaresCustomProperties(file.text))\n const match = css.find((file) => posix.normalize(file.path) === named)\n if (!match) addIssue(issues, { kind: 'missing-file', file: named, from: 'components.json' })\n return match ? [match] : []\n}\n\nfunction confineFiles(\n folder: DesignSystemFolder,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n const files: DesignSystemSourceFile[] = []\n for (const file of folder.files) {\n if (!confinedDesignSystemPath(file.path)) {\n addIssue(issues, { kind: 'escaped-path', path: file.path })\n continue\n }\n files.push(file)\n if (isConfigFile(file.path)) addIssue(issues, { kind: 'unsupported-config', path: file.path })\n }\n return files\n}\n\nfunction noteTailwindConfig(config: string | undefined, issues: DesignSystemIssue[]): void {\n const path = config?.trim()\n if (!path) return\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return\n }\n if (isConfigFile(path)) addIssue(issues, { kind: 'unsupported-config', path })\n}\n\n/** `undefined` scans stylesheets that declare variables. `null` imports none. */\nfunction stylesheetNamedByManifest(\n css: string | undefined,\n issues: DesignSystemIssue[]\n): string | null | undefined {\n const path = css?.trim()\n if (!path) return undefined\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return null\n }\n return posix.normalize(path)\n}\n\nfunction manifestChoice(\n files: readonly DesignSystemSourceFile[],\n issues: DesignSystemIssue[]\n): { stylesheet: string | null | undefined; path?: string } {\n const manifest = files.find((file) => posix.normalize(file.path) === 'components.json')\n if (!manifest) return { stylesheet: undefined }\n const parsed = v.safeParse(v.pipe(v.string(), v.parseJson(), manifestSchema), manifest.text)\n if (!parsed.success) {\n addIssue(issues, { kind: 'invalid-manifest', path: manifest.path })\n return { stylesheet: undefined, path: manifest.path }\n }\n noteTailwindConfig(parsed.output.tailwind?.config, issues)\n return {\n stylesheet: stylesheetNamedByManifest(parsed.output.tailwind?.css, issues),\n path: manifest.path\n }\n}\n\n/**\n * The stylesheets a project folder's tokens come from: the one `components.json` names, or every\n * stylesheet that declares custom properties. Paths that leave the folder and JavaScript config\n * are reported, not read.\n */\nexport function designSystemStylesheets(folder: DesignSystemFolder): {\n stylesheets: DesignSystemSourceFile[]\n issues: DesignSystemIssue[]\n manifestPath?: string\n} {\n const issues = [...folder.issues]\n const files = confineFiles(folder, issues)\n const manifest = manifestChoice(files, issues)\n return {\n stylesheets: stylesheets(files, manifest.stylesheet, issues),\n issues,\n manifestPath: manifest.path\n }\n}\n\n/**\n * One stylesheet of a project as a token bundle, read against the document as it is now. A\n * shadcn/ui `:root` and `.dark` pair becomes Light and Dark modes; the bundle's issues are noted.\n */\nexport function readDesignSystemStylesheet(\n graph: SceneGraph,\n file: DesignSystemSourceFile,\n issues: DesignSystemIssue[]\n): DesignTokenBundle {\n const bundle = readCSSDesignTokens(graph, file.text, { file: file.path })\n renameShadcnModes(bundle)\n for (const issue of bundle.issues) addIssue(issues, issue)\n return bundle\n}\n\nfunction importStylesheetFile(\n graph: SceneGraph,\n pageId: string,\n file: DesignSystemSourceFile,\n issues: DesignSystemIssue[]\n): { collectionIds: string[]; variableIds: string[] } {\n const bundle = readDesignSystemStylesheet(graph, file, issues)\n const plan = planTokenImport(graph, bundle, defaultTokenImportOptions(graph, bundle))\n for (const skip of plan.skipped) {\n addIssue(issues, {\n kind: 'unsupported-value',\n path: file.path,\n name: skip.name,\n reason: skip.reason\n })\n }\n return importTokensIntoGraph(graph, pageId, plan)\n}\n\n/**\n * Imports CSS variables from files already read inside one project folder.\n * A shadcn/ui `:root` and `.dark` pair becomes one collection with Light and Dark modes.\n * JavaScript config is reported and ignored. Component source is recorded and not imported.\n */\nexport function importDesignSystemFiles(\n graph: SceneGraph,\n folder: DesignSystemFolder\n): DesignSystemImportResult {\n const { stylesheets: files, issues, manifestPath } = designSystemStylesheets(folder)\n if (manifestPath || folder.componentsPath) {\n addIssue(issues, {\n kind: 'components-not-imported',\n path: manifestPath ?? folder.componentsPath ?? 'components.json'\n })\n }\n\n const pageId = graph.getPages()[0]?.id ?? graph.rootId\n const collectionIds: string[] = []\n const variableIds: string[] = []\n for (const file of files) {\n const imported = importStylesheetFile(graph, pageId, file, issues)\n collectionIds.push(...imported.collectionIds)\n variableIds.push(...imported.variableIds)\n }\n return { collectionIds, variableIds, issues }\n}\n"],"mappings":";;;;;;;AA4CA,MAAa,+BAA+B;;AAG5C,MAAa,0BAA0B;;AAGvC,MAAa,gCAAgC,IAAI;AAEjD,MAAM,cAAc;AAEpB,MAAM,iBAAiB,EAAE,YAAY,EACnC,UAAU,EAAE,SACV,EAAE,YAAY;CACZ,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;CAC1B,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;AAC/B,CAAC,CACH,EACF,CAAC;AAED,SAAS,UAAU,MAAyB,OAAmC;CAC7E,OAAO,KAAK,UAAU,IAAI,MAAM,KAAK,UAAU,KAAK;AACtD;AAEA,SAAS,SAAS,QAA6B,OAAgC;CAC7E,IAAI,CAAC,OAAO,MAAM,aAAa,UAAU,UAAU,KAAK,CAAC,GAAG,OAAO,KAAK,KAAK;AAC/E;;AAGA,SAAgB,yBAAyB,MAAuB;CAC9D,IAAI,KAAK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,CAAC,EAAE,EAAE,MAAM,MAAM;CAChD,MAAM,gBAA0B,CAAC;CACjC,MAAM,cAAwB,CAAC;CAC/B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,qBAAqB,OAAO,QAAQ,MAAM,MAAM;EACjE,cAAc,KAAK,GAAG,SAAS,aAAa;EAC5C,YAAY,KAAK,GAAG,SAAS,WAAW;CAC1C;CACA,OAAO;EAAE;EAAe;EAAa;CAAO;AAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"styles.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"mappings":";;;;KAmBY,kBAAkB;;;;;UAMb;EACf;EACA;;cA+BI;KAcM,mBAAmB,KAC7B;;iBAKc,gBACd,MAAM,kBACN,OAAO,QAAQ,eAAe;;;;;;;;;;;;;iBA+ChB,SAAS,QAAQ,SAAS,UAAU;;iBAgBpC,iBAAiB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgDnC,YACd,OAAO,YACP,YAAY;EACT,QAAQ;IAAQ;IAAgB,OAAO;;EAAgB,QAAQ;;;iBAwCpD,iBACd,OAAO,aACP,cACA,0BACC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"sourcesContent":["import { countBy } from 'es-toolkit/array'\nimport { isEmptyObject, isPlainObject } from 'es-toolkit/predicate'\n\nimport type { Effect, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\n\nimport { toFigmaEffect } from '#core/figma-api/effects'\n\nimport { pathName, placeTokens, tokenPath, tokenReference } from './paths'\nimport { PAIRDRAW_EXTENSION, type DesignToken, type DesignTokenIssue } from './types'\nimport { colorTokenValue, dimensionTokenValue, trimNumber } from './values'\n\n/** Where a variable's token sits, for references to it. */\nexport type TokenReferences = ReadonlyMap<string, readonly string[]>\n\n/**\n * The variable a bound style field points at, by collection and name, as Figma's\n * `com.figma.aliasData` names an alias target, since a path alone can be in several collections.\n */\nexport interface BindingTarget {\n targetVariableSetName: string\n targetVariableName: string\n}\n\n/** The variables a style's bound fields point at, by field, for those a reference was written for. */\nfunction bindingTargets(\n graph: SceneGraph,\n node: SceneNode,\n fields: Iterable<string>\n): Record<string, BindingTarget> {\n const targets: Record<string, BindingTarget> = {}\n for (const field of fields) {\n const variable = graph.variables.get(node.boundVariables[field] ?? '')\n const collection = variable && graph.variableCollections.get(variable.collectionId)\n if (variable && collection)\n targets[field] = { targetVariableSetName: collection.name, targetVariableName: variable.name }\n }\n return targets\n}\n\n/** The fields a style binds and how a file read back finds each: its reference and its target. */\nfunction ownBindings(graph: SceneGraph, node: SceneNode, bindings: Record<string, string>) {\n const own: Record<string, unknown> = {}\n if (isEmptyObject(bindings)) return own\n own.bindings = bindings\n own.aliasData = bindingTargets(graph, node, Object.keys(bindings))\n return own\n}\n\n/** Figma's auto line height, written as the multiplier browsers use for `normal`. */\nconst AUTO_LINE_HEIGHT = 1.2\n\nconst TEXT_BINDING_FIELDS = ['fontFamily', 'fontSize', 'letterSpacing', 'lineHeight'] as const\n\nfunction bindingReferences(\n node: SceneNode,\n references: TokenReferences\n): Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>> {\n const bound = TEXT_BINDING_FIELDS.flatMap((field) => {\n const variableId = node.boundVariables[field]\n const path = variableId ? references.get(variableId) : undefined\n return path ? [[field, tokenReference(path)] as const] : []\n })\n return Object.fromEntries(bound)\n}\n\nexport type TypographyFields = Pick<\n SceneNode,\n 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing'\n>\n\n/** A typography token's `$value`: bound fields as references to their variables' tokens. */\nexport function typographyValue(\n text: TypographyFields,\n bound: Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>>\n) {\n // A typography token writes a line height as a multiple of the font size.\n const lineHeightPx = lineHeightPixels(text.lineHeight, text.fontSize)\n const lineHeight =\n lineHeightPx === null || text.fontSize <= 0\n ? AUTO_LINE_HEIGHT\n : trimNumber(lineHeightPx / text.fontSize)\n return {\n fontFamily: bound.fontFamily ?? text.fontFamily,\n fontSize: bound.fontSize ?? dimensionTokenValue(text.fontSize),\n fontWeight: text.fontWeight,\n lineHeight,\n letterSpacing:\n bound.letterSpacing ??\n dimensionTokenValue(textLengthPixels(text.letterSpacing, text.fontSize))\n }\n}\n\n/** A text style as a typography token; its own fields ride along so Pairdraw reads it back exactly. */\nfunction typographyToken(\n graph: SceneGraph,\n node: SceneNode,\n references: TokenReferences\n): DesignToken {\n const bound = bindingReferences(node, references)\n return {\n $type: 'typography',\n $value: typographyValue(node, bound),\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n text: {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n lineHeight: node.lineHeight,\n letterSpacing: node.letterSpacing,\n textDecoration: node.textDecoration,\n textCase: node.textCase\n },\n ...ownBindings(graph, node, bound)\n }\n }\n }\n}\n\nexport function isShadow(effect: Effect): effect is ShadowEffect {\n return effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW'\n}\n\nfunction shadowValue(effect: ShadowEffect) {\n return {\n color: colorTokenValue(effect.color),\n offsetX: dimensionTokenValue(effect.offset.x),\n offsetY: dimensionTokenValue(effect.offset.y),\n blur: dimensionTokenValue(effect.radius),\n spread: dimensionTokenValue(effect.spread),\n ...(effect.type === 'INNER_SHADOW' ? { inset: true } : {})\n }\n}\n\n/** A shadow token's `$value`: the visible shadows of `effects`, or undefined when there are none. */\nexport function shadowTokenValue(effects: readonly Effect[]) {\n const values = effects\n .filter((effect): effect is ShadowEffect => isShadow(effect) && effect.visible)\n .map(shadowValue)\n if (values.length === 0) return undefined\n return values.length === 1 ? values[0] : values\n}\n\n/**\n * An effect style's shadows as a shadow token. Effects a shadow token cannot express, such as\n * blurs or hidden shadows, ride along whole in Pairdraw's extension, in the plugin API's shape;\n * a style with no visible shadow has no token.\n */\nfunction shadowToken(node: SceneNode): DesignToken | undefined {\n const $value = shadowTokenValue(node.effects)\n if ($value === undefined) return undefined\n const exact = node.effects.every(\n (effect) =>\n isShadow(effect) &&\n effect.visible &&\n (effect.blendMode ?? 'NORMAL') === 'NORMAL' &&\n effect.showShadowBehindNode !== true\n )\n return {\n $type: 'shadow',\n $value,\n ...(exact\n ? {}\n : {\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n effects: node.effects\n .filter((effect): effect is ShadowEffect => effect.type !== 'SHADER')\n .map(toFigmaEffect)\n }\n }\n })\n }\n}\n\n/** Whether a style's token writes a reference for this bound field. */\nfunction writesBinding(node: SceneNode, field: string): boolean {\n return node.sharedStyleType === 'TEXT' && TEXT_BINDING_FIELDS.some((bound) => bound === field)\n}\n\n/** Text and effect styles as typography and shadow tokens, nested by their names. */\nexport function styleTokens(\n graph: SceneGraph,\n references: TokenReferences\n): { tokens: Array<{ path: string[]; token: DesignToken }>; issues: DesignTokenIssue[] } {\n const issues: DesignTokenIssue[] = []\n const styles = [...graph.getAllNodes()].filter(\n (node) =>\n (node.sharedStyleType === 'TEXT' || node.sharedStyleType === 'EFFECT') &&\n node.source.id !== null\n )\n // Another tool reads a reference to a path several collections hold as whichever comes last.\n const shared = new Set(\n Object.entries(countBy([...references.values()], (path) => tokenReference(path)))\n .filter(([, count]) => count > 1)\n .map(([reference]) => reference)\n )\n const candidates = styles.flatMap((node) => {\n const token =\n node.sharedStyleType === 'TEXT' ? typographyToken(graph, node, references) : shadowToken(node)\n if (!token) {\n issues.push({ kind: 'unsupported-effect', style: node.name })\n return []\n }\n return [{ key: { node, token }, path: tokenPath(node.name) }]\n })\n const { placed, duplicates } = placeTokens(candidates)\n for (const { node } of duplicates)\n issues.push({ kind: 'duplicate-path', collection: 'Styles', token: node.name })\n for (const [{ node }] of placed) {\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const path = writesBinding(node, field) ? references.get(variableId) : undefined\n if (path && shared.has(tokenReference(path)))\n issues.push({ kind: 'ambiguous-reference', style: node.name, field, token: pathName(path) })\n }\n }\n const tokens = [...placed].map(([{ node, token }, path]) => ({\n path,\n token: withOriginalName(token, node.name, path)\n }))\n return { tokens, issues }\n}\n\n/** Keeps a name the token path could not hold, such as one with a `.`, in Pairdraw's extension. */\nexport function withOriginalName(\n token: DesignToken,\n name: string,\n path: readonly string[]\n): DesignToken {\n if (pathName(path) === name) return token\n const own = token.$extensions?.[PAIRDRAW_EXTENSION]\n return {\n ...token,\n $extensions: {\n ...token.$extensions,\n [PAIRDRAW_EXTENSION]: { ...(isPlainObject(own) ? own : {}), name }\n }\n }\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAS,eACP,OACA,MACA,QAC+B;CAC/B,MAAM,UAAyC,CAAC;CAChD,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM,UAAU,IAAI,KAAK,eAAe,UAAU,EAAE;EACrE,MAAM,aAAa,YAAY,MAAM,oBAAoB,IAAI,SAAS,YAAY;EAClF,IAAI,YAAY,YACd,QAAQ,SAAS;GAAE,uBAAuB,WAAW;GAAM,oBAAoB,SAAS;EAAK;CACjG;CACA,OAAO;AACT;;AAGA,SAAS,YAAY,OAAmB,MAAiB,UAAkC;CACzF,MAAM,MAA+B,CAAC;CACtC,IAAI,cAAc,QAAQ,GAAG,OAAO;CACpC,IAAI,WAAW;CACf,IAAI,YAAY,eAAe,OAAO,MAAM,OAAO,KAAK,QAAQ,CAAC;CACjE,OAAO;AACT;;AAGA,MAAM,mBAAmB;AAEzB,MAAM,sBAAsB;CAAC;CAAc;CAAY;CAAiB;AAAY;AAEpF,SAAS,kBACP,MACA,YAC+D;CAC/D,MAAM,QAAQ,oBAAoB,SAAS,UAAU;EACnD,M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"],"sourcesContent":["import { countBy } from 'es-toolkit/array'\nimport { isEmptyObject, isPlainObject } from 'es-toolkit/predicate'\n\nimport type {\n Effect,\n SceneGraph,\n SceneNode,\n ShaderEffect,\n ShadowEffect\n} from '@pairdraw/scene-graph'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\n\nimport { toFigmaEffect } from '#core/figma-api/effects'\n\nimport { pathName, placeTokens, tokenPath, tokenReference } from './paths'\nimport { PAIRDRAW_EXTENSION, type DesignToken, type DesignTokenIssue } from './types'\nimport { colorTokenValue, dimensionTokenValue, trimNumber } from './values'\n\n/** Where a variable's token sits, for references to it. */\nexport type TokenReferences = ReadonlyMap<string, readonly string[]>\n\n/**\n * The variable a bound style field points at, by collection and name, as Figma's\n * `com.figma.aliasData` names an alias target, since a path alone can be in several collections.\n */\nexport interface BindingTarget {\n targetVariableSetName: string\n targetVariableName: string\n}\n\n/** The variables a style's bound fields point at, by field, for those a reference was written for. */\nfunction bindingTargets(\n graph: SceneGraph,\n node: SceneNode,\n fields: Iterable<string>\n): Record<string, BindingTarget> {\n const targets: Record<string, BindingTarget> = {}\n for (const field of fields) {\n const variable = graph.variables.get(node.boundVariables[field] ?? '')\n const collection = variable && graph.variableCollections.get(variable.collectionId)\n if (variable && collection)\n targets[field] = { targetVariableSetName: collection.name, targetVariableName: variable.name }\n }\n return targets\n}\n\n/** The fields a style binds and how a file read back finds each: its reference and its target. */\nfunction ownBindings(graph: SceneGraph, node: SceneNode, bindings: Record<string, string>) {\n const own: Record<string, unknown> = {}\n if (isEmptyObject(bindings)) return own\n own.bindings = bindings\n own.aliasData = bindingTargets(graph, node, Object.keys(bindings))\n return own\n}\n\n/** Figma's auto line height, written as the multiplier browsers use for `normal`. */\nconst AUTO_LINE_HEIGHT = 1.2\n\nconst TEXT_BINDING_FIELDS = ['fontFamily', 'fontSize', 'letterSpacing', 'lineHeight'] as const\n\nfunction bindingReferences(\n node: SceneNode,\n references: TokenReferences\n): Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>> {\n const bound = TEXT_BINDING_FIELDS.flatMap((field) => {\n const variableId = node.boundVariables[field]\n const path = variableId ? references.get(variableId) : undefined\n return path ? [[field, tokenReference(path)] as const] : []\n })\n return Object.fromEntries(bound)\n}\n\nexport type TypographyFields = Pick<\n SceneNode,\n 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing'\n>\n\n/** A typography token's `$value`: bound fields as references to their variables' tokens. */\nexport function typographyValue(\n text: TypographyFields,\n bound: Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>>\n) {\n // A typography token writes a line height as a multiple of the font size.\n const lineHeightPx = lineHeightPixels(text.lineHeight, text.fontSize)\n const lineHeight =\n lineHeightPx === null || text.fontSize <= 0\n ? AUTO_LINE_HEIGHT\n : trimNumber(lineHeightPx / text.fontSize)\n return {\n fontFamily: bound.fontFamily ?? text.fontFamily,\n fontSize: bound.fontSize ?? dimensionTokenValue(text.fontSize),\n fontWeight: text.fontWeight,\n lineHeight,\n letterSpacing:\n bound.letterSpacing ??\n dimensionTokenValue(textLengthPixels(text.letterSpacing, text.fontSize))\n }\n}\n\n/** A text style as a typography token; its own fields ride along so Pairdraw reads it back exactly. */\nfunction typographyToken(\n graph: SceneGraph,\n node: SceneNode,\n references: TokenReferences\n): DesignToken {\n const bound = bindingReferences(node, references)\n return {\n $type: 'typography',\n $value: typographyValue(node, bound),\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n text: {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n lineHeight: node.lineHeight,\n letterSpacing: node.letterSpacing,\n textDecoration: node.textDecoration,\n textCase: node.textCase\n },\n ...ownBindings(graph, node, bound)\n }\n }\n }\n}\n\nexport function isShadow(effect: Effect): effect is ShadowEffect {\n return effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW'\n}\n\nfunction shadowValue(effect: ShadowEffect) {\n return {\n color: colorTokenValue(effect.color),\n offsetX: dimensionTokenValue(effect.offset.x),\n offsetY: dimensionTokenValue(effect.offset.y),\n blur: dimensionTokenValue(effect.radius),\n spread: dimensionTokenValue(effect.spread),\n ...(effect.type === 'INNER_SHADOW' ? { inset: true } : {})\n }\n}\n\n/** A shadow token's `$value`: the visible shadows of `effects`, or undefined when there are none. */\nexport function shadowTokenValue(effects: readonly Effect[]) {\n const values = effects\n .filter((effect): effect is ShadowEffect => isShadow(effect) && effect.visible)\n .map(shadowValue)\n if (values.length === 0) return undefined\n return values.length === 1 ? values[0] : values\n}\n\n/**\n * An effect style's shadows as a shadow token. Effects a shadow token cannot express, such as\n * blurs or hidden shadows, ride along whole in Pairdraw's extension, in the plugin API's shape;\n * a style with no visible shadow has no token.\n */\nfunction shadowToken(node: SceneNode): DesignToken | undefined {\n const $value = shadowTokenValue(node.effects)\n if ($value === undefined) return undefined\n const exact = node.effects.every(\n (effect) =>\n isShadow(effect) &&\n effect.visible &&\n (effect.blendMode ?? 'NORMAL') === 'NORMAL' &&\n effect.showShadowBehindNode !== true\n )\n return {\n $type: 'shadow',\n $value,\n ...(exact\n ? {}\n : {\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n effects: node.effects\n .filter(\n (effect): effect is Exclude<Effect, ShaderEffect> => effect.type !== 'SHADER'\n )\n .map(toFigmaEffect)\n }\n }\n })\n }\n}\n\n/** Whether a style's token writes a reference for this bound field. */\nfunction writesBinding(node: SceneNode, field: string): boolean {\n return node.sharedStyleType === 'TEXT' && TEXT_BINDING_FIELDS.some((bound) => bound === field)\n}\n\n/** Text and effect styles as typography and shadow tokens, nested by their names. */\nexport function styleTokens(\n graph: SceneGraph,\n references: TokenReferences\n): { tokens: Array<{ path: string[]; token: DesignToken }>; issues: DesignTokenIssue[] } {\n const issues: DesignTokenIssue[] = []\n const styles = [...graph.getAllNodes()].filter(\n (node) =>\n (node.sharedStyleType === 'TEXT' || node.sharedStyleType === 'EFFECT') &&\n node.source.id !== null\n )\n // Another tool reads a reference to a path several collections hold as whichever comes last.\n const shared = new Set(\n Object.entries(countBy([...references.values()], (path) => tokenReference(path)))\n .filter(([, count]) => count > 1)\n .map(([reference]) => reference)\n )\n const candidates = styles.flatMap((node) => {\n const token =\n node.sharedStyleType === 'TEXT' ? typographyToken(graph, node, references) : shadowToken(node)\n if (!token) {\n issues.push({ kind: 'unsupported-effect', style: node.name })\n return []\n }\n return [{ key: { node, token }, path: tokenPath(node.name) }]\n })\n const { placed, duplicates } = placeTokens(candidates)\n for (const { node } of duplicates)\n issues.push({ kind: 'duplicate-path', collection: 'Styles', token: node.name })\n for (const [{ node }] of placed) {\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const path = writesBinding(node, field) ? references.get(variableId) : undefined\n if (path && shared.has(tokenReference(path)))\n issues.push({ kind: 'ambiguous-reference', style: node.name, field, token: pathName(path) })\n }\n }\n const tokens = [...placed].map(([{ node, token }, path]) => ({\n path,\n token: withOriginalName(token, node.name, path)\n }))\n return { tokens, issues }\n}\n\n/** Keeps a name the token path could not hold, such as one with a `.`, in Pairdraw's extension. */\nexport function withOriginalName(\n token: DesignToken,\n name: string,\n path: readonly string[]\n): DesignToken {\n if (pathName(path) === name) return token\n const own = token.$extensions?.[PAIRDRAW_EXTENSION]\n return {\n ...token,\n $extensions: {\n ...token.$extensions,\n [PAIRDRAW_EXTENSION]: { ...(isPlainObject(own) ? own : {}), name }\n }\n }\n}\n"],"mappings":";;;;;;;;;AA+BA,SAAS,eACP,OACA,MACA,QAC+B;CAC/B,MAAM,UAAyC,CAAC;CAChD,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM,UAAU,IAAI,KAAK,eAAe,UAAU,EAAE;EACrE,MAAM,aAAa,YAAY,MAAM,oBAAoB,IAAI,SAAS,YAAY;EAClF,IAAI,YAAY,YACd,QAAQ,SAAS;GAAE,uBAAuB,WAAW;GAAM,oBAAoB,SAAS;EAAK;CACjG;CACA,OAAO;AACT;;AAGA,SAAS,YAAY,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EAAG;CAAO;AAC1B;;AAGA,SAAgB,iBACd,OACA,MACA,MACa;CACb,IAAI,SAAS,IAAI,MAAM,MAAM,OAAO;CACpC,MAAM,MAAM,MAAM,cAAc;CAChC,OAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,MAAM;IACR,qBAAqB;IAAE,GAAI,cAAc,GAAG,IAAI,MAAM,CAAC;IAAI;GAAK;EACnE;CACF;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DesignTokenBundle, DesignTokenSourceFile } from "../read.js";
|
|
2
|
+
import { DesignSystemIssue } from "../project.js";
|
|
3
|
+
import { TokenDrift, TokenSyncChoice, TokenSyncResolution } from "./drift.js";
|
|
4
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
5
|
+
import { TokenSource } from "@pairdraw/scene-graph/token-sources";
|
|
6
|
+
//#region src/io/formats/design-tokens/sync/apply.d.ts
|
|
7
|
+
/** A link as a sync records it, before it learns what the code holds. */
|
|
8
|
+
type TokenSourceLink = Omit<TokenSource, 'snapshot' | 'syncedAt'>;
|
|
9
|
+
/**
|
|
10
|
+
* The document's links with `link` recorded as synced now, its snapshot taken from the code once
|
|
11
|
+
* the resolution's imports are applied. A link already there keeps its place.
|
|
12
|
+
*/
|
|
13
|
+
declare function syncedTokenSources(graph: SceneGraph, link: TokenSourceLink, bundles: readonly DesignTokenBundle[], resolution: TokenSyncResolution): TokenSource[];
|
|
14
|
+
/** Applies a resolved sync straight to a graph and records the link, for tools and the CLI. */
|
|
15
|
+
declare function syncTokensIntoGraph(graph: SceneGraph, link: TokenSourceLink, bundles: readonly DesignTokenBundle[], resolution: TokenSyncResolution): void;
|
|
16
|
+
/**
|
|
17
|
+
* The link some files of linked code belong to. Given `path`, their place from the document's
|
|
18
|
+
* folder, it is the link recorded there, or one recorded by name only; two files of one name in
|
|
19
|
+
* different folders are two links. Without it, a link whose path or file name is one of theirs.
|
|
20
|
+
* Files no link names are compared without a snapshot.
|
|
21
|
+
*/
|
|
22
|
+
declare function tokenSourceForFiles(graph: SceneGraph, files: readonly DesignTokenSourceFile[], path?: string): TokenSource | undefined;
|
|
23
|
+
interface TokenFilesSync {
|
|
24
|
+
/** Tokens that came in or had a side picked. */
|
|
25
|
+
applied: number;
|
|
26
|
+
/** Drift left for a person to review. */
|
|
27
|
+
left: TokenDrift[];
|
|
28
|
+
issues: DesignSystemIssue[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Syncs a headless document with linked code read from files, for tools and the CLI: what changed
|
|
32
|
+
* only in code and what is new there comes in, a token changed on the canvas or on both sides
|
|
33
|
+
* takes `conflicts` (left as it is by default), and the link is recorded under `path`, a path
|
|
34
|
+
* from the document's folder, when one is known.
|
|
35
|
+
*/
|
|
36
|
+
declare function syncTokenFiles(graph: SceneGraph, files: readonly DesignTokenSourceFile[], options?: {
|
|
37
|
+
conflicts?: TokenSyncChoice;
|
|
38
|
+
path?: string;
|
|
39
|
+
}): TokenFilesSync;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { TokenFilesSync, TokenSourceLink, syncTokenFiles, syncTokensIntoGraph, syncedTokenSources, tokenSourceForFiles };
|
|
42
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/sync/apply.ts"],"mappings":";;;;;;;KAwBY,kBAAkB,KAAK;;;;;iBAMnB,mBACd,OAAO,YACP,MAAM,iBACN,kBAAkB,qBAClB,YAAY,sBACX;;iBAca,oBACd,OAAO,YACP,MAAM,iBACN,kBAAkB,qBAClB,YAAY;;;;;;;iBAeE,oBACd,OAAO,YACP,gBAAgB,yBAChB,gBACC;UA8Bc;;EAEf;;EAEA,MAAM;EACN,QAAQ;;;;;;;;iBASM,eACd,OAAO,YACP,gBAAgB,yBAChB;EAAW,YAAY;EAAiB;IACvC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { importTokensIntoGraph } from "../apply.js";
|
|
2
|
+
import { planTokenSync, tokenSnapshot } from "./drift.js";
|
|
3
|
+
import { readTokenSourceFiles } from "./files.js";
|
|
4
|
+
import { randomHex } from "@pairdraw/scene-graph/random";
|
|
5
|
+
import { readTokenSources, tokenSourcesPluginData } from "@pairdraw/scene-graph/token-sources";
|
|
6
|
+
import { posix } from "pathe";
|
|
7
|
+
//#region src/io/formats/design-tokens/sync/apply.ts
|
|
8
|
+
/**
|
|
9
|
+
* The document's links with `link` recorded as synced now, its snapshot taken from the code once
|
|
10
|
+
* the resolution's imports are applied. A link already there keeps its place.
|
|
11
|
+
*/
|
|
12
|
+
function syncedTokenSources(graph, link, bundles, resolution) {
|
|
13
|
+
const sources = readTokenSources(graph);
|
|
14
|
+
const previous = sources.find((source) => source.id === link.id);
|
|
15
|
+
const synced = {
|
|
16
|
+
...link,
|
|
17
|
+
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
18
|
+
...tokenSnapshot(graph, bundles, previous, resolution.undecided)
|
|
19
|
+
};
|
|
20
|
+
return previous ? sources.map((source) => source === previous ? synced : source) : [...sources, synced];
|
|
21
|
+
}
|
|
22
|
+
/** Applies a resolved sync straight to a graph and records the link, for tools and the CLI. */
|
|
23
|
+
function syncTokensIntoGraph(graph, link, bundles, resolution) {
|
|
24
|
+
const pageId = graph.getPages()[0]?.id ?? graph.rootId;
|
|
25
|
+
for (const plan of resolution.plans) importTokensIntoGraph(graph, pageId, plan);
|
|
26
|
+
graph.updateNode(graph.rootId, { pluginData: tokenSourcesPluginData(graph, syncedTokenSources(graph, link, bundles, resolution)) });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The link some files of linked code belong to. Given `path`, their place from the document's
|
|
30
|
+
* folder, it is the link recorded there, or one recorded by name only; two files of one name in
|
|
31
|
+
* different folders are two links. Without it, a link whose path or file name is one of theirs.
|
|
32
|
+
* Files no link names are compared without a snapshot.
|
|
33
|
+
*/
|
|
34
|
+
function tokenSourceForFiles(graph, files, path) {
|
|
35
|
+
const sources = readTokenSources(graph);
|
|
36
|
+
if (path !== void 0) {
|
|
37
|
+
const place = posix.normalize(path);
|
|
38
|
+
return sources.find((source) => source.path && posix.normalize(source.path) === place) ?? sources.find((source) => !source.path && source.name === posix.basename(place));
|
|
39
|
+
}
|
|
40
|
+
const paths = files.map((file) => posix.normalize(file.path));
|
|
41
|
+
return sources.find((source) => source.path && paths.includes(posix.normalize(source.path))) ?? sources.find((source) => paths.some((entry) => posix.basename(entry) === source.name));
|
|
42
|
+
}
|
|
43
|
+
/** A link for files no link names yet, named after where they are. */
|
|
44
|
+
function newLink(files, path) {
|
|
45
|
+
const stylesheets = files.every((file) => posix.basename(file.path).endsWith(".css"));
|
|
46
|
+
return {
|
|
47
|
+
id: randomHex(12),
|
|
48
|
+
kind: stylesheets ? files.length > 1 ? "folder" : "css" : "dtcg",
|
|
49
|
+
name: posix.basename(path ?? files.at(0)?.path ?? "tokens"),
|
|
50
|
+
...path ? { path } : {}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Syncs a headless document with linked code read from files, for tools and the CLI: what changed
|
|
55
|
+
* only in code and what is new there comes in, a token changed on the canvas or on both sides
|
|
56
|
+
* takes `conflicts` (left as it is by default), and the link is recorded under `path`, a path
|
|
57
|
+
* from the document's folder, when one is known.
|
|
58
|
+
*/
|
|
59
|
+
function syncTokenFiles(graph, files, options = {}) {
|
|
60
|
+
const { bundles, issues } = readTokenSourceFiles(graph, files);
|
|
61
|
+
const linked = tokenSourceForFiles(graph, files, options.path);
|
|
62
|
+
const resolution = planTokenSync(graph, bundles, linked).resolve((drift) => drift.kind === "missing" ? void 0 : options.conflicts);
|
|
63
|
+
syncTokensIntoGraph(graph, linked ?? newLink(files, options.path), bundles, resolution);
|
|
64
|
+
return {
|
|
65
|
+
applied: resolution.applied,
|
|
66
|
+
left: resolution.undecided,
|
|
67
|
+
issues
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { syncTokenFiles, syncTokensIntoGraph, syncedTokenSources, tokenSourceForFiles };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/sync/apply.ts"],"sourcesContent":["import { posix } from 'pathe'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { randomHex } from '@pairdraw/scene-graph/random'\nimport {\n readTokenSources,\n tokenSourcesPluginData,\n type TokenSource\n} from '@pairdraw/scene-graph/token-sources'\n\nimport { importTokensIntoGraph } from '#core/io/formats/design-tokens/apply'\nimport type { DesignSystemIssue } from '#core/io/formats/design-tokens/project'\nimport type { DesignTokenBundle, DesignTokenSourceFile } from '#core/io/formats/design-tokens/read'\n\nimport {\n planTokenSync,\n tokenSnapshot,\n type TokenDrift,\n type TokenSyncChoice,\n type TokenSyncResolution\n} from './drift'\nimport { readTokenSourceFiles } from './files'\n\n/** A link as a sync records it, before it learns what the code holds. */\nexport type TokenSourceLink = Omit<TokenSource, 'snapshot' | 'syncedAt'>\n\n/**\n * The document's links with `link` recorded as synced now, its snapshot taken from the code once\n * the resolution's imports are applied. A link already there keeps its place.\n */\nexport function syncedTokenSources(\n graph: SceneGraph,\n link: TokenSourceLink,\n bundles: readonly DesignTokenBundle[],\n resolution: TokenSyncResolution\n): TokenSource[] {\n const sources = readTokenSources(graph)\n const previous = sources.find((source) => source.id === link.id)\n const synced: TokenSource = {\n ...link,\n syncedAt: new Date().toISOString(),\n ...tokenSnapshot(graph, bundles, previous, resolution.undecided)\n }\n return previous\n ? sources.map((source) => (source === previous ? synced : source))\n : [...sources, synced]\n}\n\n/** Applies a resolved sync straight to a graph and records the link, for tools and the CLI. */\nexport function syncTokensIntoGraph(\n graph: SceneGraph,\n link: TokenSourceLink,\n bundles: readonly DesignTokenBundle[],\n resolution: TokenSyncResolution\n): void {\n const pageId = graph.getPages()[0]?.id ?? graph.rootId\n for (const plan of resolution.plans) importTokensIntoGraph(graph, pageId, plan)\n graph.updateNode(graph.rootId, {\n pluginData: tokenSourcesPluginData(graph, syncedTokenSources(graph, link, bundles, resolution))\n })\n}\n\n/**\n * The link some files of linked code belong to. Given `path`, their place from the document's\n * folder, it is the link recorded there, or one recorded by name only; two files of one name in\n * different folders are two links. Without it, a link whose path or file name is one of theirs.\n * Files no link names are compared without a snapshot.\n */\nexport function tokenSourceForFiles(\n graph: SceneGraph,\n files: readonly DesignTokenSourceFile[],\n path?: string\n): TokenSource | undefined {\n const sources = readTokenSources(graph)\n if (path !== undefined) {\n const place = posix.normalize(path)\n return (\n sources.find((source) => source.path && posix.normalize(source.path) === place) ??\n sources.find((source) => !source.path && source.name === posix.basename(place))\n )\n }\n const paths = files.map((file) => posix.normalize(file.path))\n return (\n sources.find((source) => source.path && paths.includes(posix.normalize(source.path))) ??\n sources.find((source) => paths.some((entry) => posix.basename(entry) === source.name))\n )\n}\n\n/** A link for files no link names yet, named after where they are. */\nfunction newLink(\n files: readonly DesignTokenSourceFile[],\n path: string | undefined\n): TokenSourceLink {\n const stylesheets = files.every((file) => posix.basename(file.path).endsWith('.css'))\n return {\n id: randomHex(12),\n kind: stylesheets ? (files.length > 1 ? 'folder' : 'css') : 'dtcg',\n name: posix.basename(path ?? files.at(0)?.path ?? 'tokens'),\n ...(path ? { path } : {})\n }\n}\n\nexport interface TokenFilesSync {\n /** Tokens that came in or had a side picked. */\n applied: number\n /** Drift left for a person to review. */\n left: TokenDrift[]\n issues: DesignSystemIssue[]\n}\n\n/**\n * Syncs a headless document with linked code read from files, for tools and the CLI: what changed\n * only in code and what is new there comes in, a token changed on the canvas or on both sides\n * takes `conflicts` (left as it is by default), and the link is recorded under `path`, a path\n * from the document's folder, when one is known.\n */\nexport function syncTokenFiles(\n graph: SceneGraph,\n files: readonly DesignTokenSourceFile[],\n options: { conflicts?: TokenSyncChoice; path?: string } = {}\n): TokenFilesSync {\n const { bundles, issues } = readTokenSourceFiles(graph, files)\n const linked = tokenSourceForFiles(graph, files, options.path)\n const sync = planTokenSync(graph, bundles, linked)\n const resolution = sync.resolve((drift) =>\n drift.kind === 'missing' ? undefined : options.conflicts\n )\n syncTokensIntoGraph(graph, linked ?? newLink(files, options.path), bundles, resolution)\n return { applied: resolution.applied, left: resolution.undecided, issues }\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd,OACA,MACA,SACA,YACe;CACf,MAAM,UAAU,iBAAiB,KAAK;CACtC,MAAM,WAAW,QAAQ,MAAM,WAAW,OAAO,OAAO,KAAK,EAAE;CAC/D,MAAM,SAAsB;EAC1B,GAAG;EACH,2BAAU,IAAI,KAAK,EAAA,CAAE,YAAY;EACjC,GAAG,cAAc,OAAO,SAAS,UAAU,WAAW,SAAS;CACjE;CACA,OAAO,WACH,QAAQ,KAAK,WAAY,WAAW,WAAW,SAAS,MAAO,IAC/D,CAAC,GAAG,SAAS,MAAM;AACzB;;AAGA,SAAgB,oBACd,OACA,MACA,SACA,YACM;CACN,MAAM,SAAS,MAAM,SAAS,CAAC,CAAC,EAAE,EAAE,MAAM,MAAM;CAChD,KAAK,MAAM,QAAQ,WAAW,OAAO,sBAAsB,OAAO,QAAQ,IAAI;CAC9E,MAAM,WAAW,MAAM,QAAQ,EAC7B,YAAY,uBAAuB,OAAO,mBAAmB,OAAO,MAAM,SAAS,UAAU,CAAC,EAChG,CAAC;AACH;;;;;;;AAQA,SAAgB,oBACd,OACA,OACA,MACyB;CACzB,MAAM,UAAU,iBAAiB,KAAK;CACtC,IAAI,SAAS,KAAA,GAAW;EACtB,MAAM,QAAQ,MAAM,UAAU,IAAI;EAClC,OACE,QAAQ,MAAM,WAAW,OAAO,QAAQ,MAAM,UAAU,OAAO,IAAI,MAAM,KAAK,KAC9E,QAAQ,MAAM,WAAW,CAAC,OAAO,QAAQ,OAAO,SAAS,MAAM,SAAS,KAAK,CAAC;CAElF;CACA,MAAM,QAAQ,MAAM,KAAK,SAAS,MAAM,UAAU,KAAK,IAAI,CAAC;CAC5D,OACE,QAAQ,MAAM,WAAW,OAAO,QAAQ,MAAM,SAAS,MAAM,UAAU,OAAO,IAAI,CAAC,CAAC,KACpF,QAAQ,MAAM,WAAW,MAAM,MAAM,UAAU,MAAM,SAAS,KAAK,MAAM,OAAO,IAAI,CAAC;AAEzF;;AAGA,SAAS,QACP,OACA,MACiB;CACjB,MAAM,cAAc,MAAM,OAAO,SAAS,MAAM,SAAS,KAAK,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC;CACpF,OAAO;EACL,IAAI,UAAU,EAAE;EAChB,MAAM,cAAe,MAAM,SAAS,IAAI,WAAW,QAAS;EAC5D,MAAM,MAAM,SAAS,QAAQ,MAAM,GAAG,CAAC,CAAC,EAAE,QAAQ,QAAQ;EAC1D,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;CACzB;AACF;;;;;;;AAgBA,SAAgB,eACd,OACA,OACA,UAA0D,CAAC,GAC3C;CAChB,MAAM,EAAE,SAAS,WAAW,qBAAqB,OAAO,KAAK;CAC7D,MAAM,SAAS,oBAAoB,OAAO,OAAO,QAAQ,IAAI;CAE7D,MAAM,aADO,cAAc,OAAO,SAAS,MACrB,CAAC,CAAC,SAAS,UAC/B,MAAM,SAAS,YAAY,KAAA,IAAY,QAAQ,SACjD;CACA,oBAAoB,OAAO,UAAU,QAAQ,OAAO,QAAQ,IAAI,GAAG,SAAS,UAAU;CACtF,OAAO;EAAE,SAAS,WAAW;EAAS,MAAM,WAAW;EAAW;CAAO;AAC3E"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DesignTokenBundle } from "../read.js";
|
|
2
|
+
import { TokenImportPlan } from "../plan/index.js";
|
|
3
|
+
import { SceneGraph, VariableValue } from "@pairdraw/scene-graph";
|
|
4
|
+
import { TokenSource } from "@pairdraw/scene-graph/token-sources";
|
|
5
|
+
//#region src/io/formats/design-tokens/sync/drift.d.ts
|
|
6
|
+
/** What linked code held at the last sync, and the token each variable then was. */
|
|
7
|
+
type TokenSyncBase = Pick<TokenSource, 'snapshot' | 'names' | 'modes'>;
|
|
8
|
+
/**
|
|
9
|
+
* How a token differs between linked code and the canvas, against what the code held at the last
|
|
10
|
+
* sync: changed in code only, on the canvas only, on both, new in code, no longer in code, or
|
|
11
|
+
* deleted on the canvas while the code still has it.
|
|
12
|
+
*/
|
|
13
|
+
type TokenDriftKind = 'code' | 'canvas' | 'conflict' | 'added' | 'missing' | 'deleted';
|
|
14
|
+
interface TokenDrift {
|
|
15
|
+
kind: TokenDriftKind;
|
|
16
|
+
collection: string;
|
|
17
|
+
variable: string;
|
|
18
|
+
/** Null for a variable the code adds; a deleted variable keeps the id it had. */
|
|
19
|
+
variableId: string | null;
|
|
20
|
+
/** Null where the whole variable is added, gone, or deleted. */
|
|
21
|
+
mode: string | null;
|
|
22
|
+
modeId: string | null;
|
|
23
|
+
/** The value as the code writes it, for people to read. */
|
|
24
|
+
code?: string;
|
|
25
|
+
/** The value the canvas holds, for people to read. */
|
|
26
|
+
canvas?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Which side a person keeps for a token that changed on the canvas, on both, or left the code. */
|
|
29
|
+
type TokenSyncChoice = 'code' | 'canvas';
|
|
30
|
+
interface TokenSyncResolution {
|
|
31
|
+
/**
|
|
32
|
+
* The imports that bring the code in, one per file, to apply in order. Values that already
|
|
33
|
+
* match are left alone, and nothing is deleted: a token gone from code keeps its variable.
|
|
34
|
+
*/
|
|
35
|
+
plans: TokenImportPlan[];
|
|
36
|
+
/** How many tokens the imports write: those changed or added only in code, and those chosen. */
|
|
37
|
+
applied: number;
|
|
38
|
+
/** Drift nobody chose a side for, which the next sync reports again. */
|
|
39
|
+
undecided: TokenDrift[];
|
|
40
|
+
}
|
|
41
|
+
interface TokenSync {
|
|
42
|
+
/** In the order of the code's files, collections, and tokens; tokens gone from code last. */
|
|
43
|
+
drift: TokenDrift[];
|
|
44
|
+
/**
|
|
45
|
+
* Changes made only in code and tokens new in code always come in. A token changed or deleted
|
|
46
|
+
* on the canvas, or changed on both sides, takes the code only where `choose` picks the code;
|
|
47
|
+
* one gone from code stops being reported once a side is picked for it.
|
|
48
|
+
*/
|
|
49
|
+
resolve(choose?: (drift: TokenDrift) => TokenSyncChoice | undefined): TokenSyncResolution;
|
|
50
|
+
}
|
|
51
|
+
/** Drift a person decides: the canvas changed or deleted the token, or both sides changed it. */
|
|
52
|
+
declare function driftNeedsChoice(drift: TokenDrift): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* A value as sync compares it: colors to 8-bit channels, numbers to four decimals, aliases by
|
|
55
|
+
* target, and a CSS expression by its text, whatever number an engine computed for it.
|
|
56
|
+
*/
|
|
57
|
+
declare function tokenValueSignature(value: VariableValue | undefined, expression?: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Compares linked code, read into one token bundle per file, with the canvas, and plans bringing
|
|
60
|
+
* it in. Collections and modes match by name and variables by name within them, as an import
|
|
61
|
+
* does. Without a snapshot nobody knows which side changed, so every difference is a conflict.
|
|
62
|
+
*/
|
|
63
|
+
declare function planTokenSync(graph: SceneGraph, bundles: readonly DesignTokenBundle[], base?: TokenSyncBase): TokenSync;
|
|
64
|
+
/**
|
|
65
|
+
* Drift against the canvas as it is whenever asked, for a view that follows edits: the code is
|
|
66
|
+
* read and planned once, and a value unchanged since the last call is not compared again.
|
|
67
|
+
*/
|
|
68
|
+
declare function trackTokenDrift(graph: SceneGraph, bundles: readonly DesignTokenBundle[], base?: TokenSyncBase): () => TokenDrift[];
|
|
69
|
+
/**
|
|
70
|
+
* What the code holds now for the variables it matches, and the token each one is, to compare
|
|
71
|
+
* later syncs against. Files that set different modes of one variable add up. Drift left
|
|
72
|
+
* undecided keeps what `previous` had, so the next sync still sees both changes.
|
|
73
|
+
*/
|
|
74
|
+
declare function tokenSnapshot(graph: SceneGraph, bundles: readonly DesignTokenBundle[], previous?: TokenSyncBase, undecided?: readonly TokenDrift[]): Required<TokenSyncBase>;
|
|
75
|
+
//#endregion
|
|
76
|
+
export { TokenDrift, TokenDriftKind, TokenSync, TokenSyncBase, TokenSyncChoice, TokenSyncResolution, driftNeedsChoice, planTokenSync, tokenSnapshot, tokenValueSignature, trackTokenDrift };
|
|
77
|
+
//# sourceMappingURL=drift.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/sync/drift.ts"],"mappings":";;;;;;KAoBY,gBAAgB,KAAK;;;;;;KAOrB;UAEK;EACf,MAAM;EACN;EACA;;EAEA;;EAEA;EACA;;EAEA;;EAEA;;;KAIU;UAEK;;;;;EAKf,OAAO;;EAEP;;EAEA,WAAW;;UAGI;;EAEf,OAAO;;;;;;EAMP,QAAQ,UAAU,OAAO,eAAe,8BAA8B;;;iBAIxD,iBAAiB,OAAO;;;;;iBAkBxB,oBAAoB,OAAO,2BAA2B;;;;;;iBA4TtD,cACd,OAAO,YACP,kBAAkB,qBAClB,OAAO,gBACN;;;;;iBAkDa,gBACd,OAAO,YACP,kBAAkB,qBAClB,OAAO,sBACA;;;;;;iBAoGO,cACd,OAAO,YACP,kBAAkB,qBAClB,WAAU,eACV,qBAAoB,eACnB,SAAS"}
|