@pairdraw/core 0.19.2 → 0.21.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 +46 -0
- package/dist/canvas/noise/shader.d.ts.map +1 -0
- package/dist/canvas/noise/shader.js +166 -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 +74 -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/colors.d.ts +20 -5
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +48 -42
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +25 -0
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -0
- package/dist/canvas/renderer/document-surface.js +46 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -0
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +6 -4
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +10 -3
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -0
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +36 -3
- 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/retained-backing.d.ts.map +1 -1
- package/dist/canvas/renderer/retained-backing.js +2 -1
- package/dist/canvas/renderer/retained-backing.js.map +1 -1
- 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/tiles/surface-pool.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js +2 -7
- package/dist/canvas/renderer/tiles/surface-pool.js.map +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 +42 -4
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +57 -5
- 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 +45 -12
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +2 -1
- package/dist/canvas/shaders/effect.js.map +1 -1
- package/dist/canvas/shadows/shape.d.ts.map +1 -1
- package/dist/canvas/shadows/shape.js +4 -2
- package/dist/canvas/shadows/shape.js.map +1 -1
- package/dist/canvas/shadows/silhouette.js +1 -1
- package/dist/canvas/shadows.d.ts.map +1 -1
- package/dist/canvas/shadows.js +4 -2
- package/dist/canvas/shadows.js.map +1 -1
- package/dist/canvas/text/decorations.d.ts +2 -2
- package/dist/canvas/text/decorations.d.ts.map +1 -1
- package/dist/canvas/text/decorations.js +5 -5
- package/dist/canvas/text/decorations.js.map +1 -1
- package/dist/canvas/text/index.js +1 -1
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/paragraph/index.d.ts +2 -2
- package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/index.js +16 -5
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -1
- package/dist/canvas/text/renderer.d.ts.map +1 -1
- package/dist/canvas/text/shape.js +4 -4
- package/dist/canvas/text/shape.js.map +1 -1
- package/dist/canvas/texture.d.ts +20 -0
- package/dist/canvas/texture.d.ts.map +1 -0
- package/dist/canvas/texture.js +101 -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/clipboard/assets.d.ts.map +1 -1
- package/dist/editor/clipboard/assets.js +3 -3
- package/dist/editor/clipboard/assets.js.map +1 -1
- package/dist/editor/clipboard/component-matches.d.ts +13 -0
- package/dist/editor/clipboard/component-matches.d.ts.map +1 -0
- package/dist/editor/clipboard/component-matches.js +50 -0
- package/dist/editor/clipboard/component-matches.js.map +1 -0
- package/dist/editor/clipboard/dependencies.d.ts +7 -0
- package/dist/editor/clipboard/dependencies.d.ts.map +1 -1
- package/dist/editor/clipboard/dependencies.js +5 -0
- package/dist/editor/clipboard/dependencies.js.map +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/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +48 -19
- package/dist/editor/clipboard.js.map +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/properties.d.ts.map +1 -1
- package/dist/editor/components/properties.js +3 -3
- package/dist/editor/components/properties.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 +26 -2
- 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 +171 -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 +9 -2
- 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/shapes/pencil.js +1 -1
- package/dist/editor/structure/state.d.ts.map +1 -1
- package/dist/editor/structure/state.js +2 -2
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/text.d.ts.map +1 -1
- package/dist/editor/text.js +2 -2
- package/dist/editor/text.js.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/variables.js +3 -3
- package/dist/editor/variables.js.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/fresh-read.d.ts +15 -0
- package/dist/figma-api/fresh-read.d.ts.map +1 -0
- package/dist/figma-api/fresh-read.js +54 -0
- package/dist/figma-api/fresh-read.js.map +1 -0
- package/dist/figma-api/graph-ref.d.ts +9 -0
- package/dist/figma-api/graph-ref.d.ts.map +1 -0
- package/dist/figma-api/graph-ref.js +14 -0
- package/dist/figma-api/graph-ref.js.map +1 -0
- package/dist/figma-api/index.d.ts +11 -1
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +16 -4
- 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/pending-layout.d.ts +3 -3
- package/dist/figma-api/pending-layout.d.ts.map +1 -1
- package/dist/figma-api/pending-layout.js +7 -3
- package/dist/figma-api/pending-layout.js.map +1 -1
- package/dist/figma-api/pending-sync.d.ts +1 -1
- package/dist/figma-api/pending-sync.d.ts.map +1 -1
- package/dist/figma-api/pending-sync.js +3 -1
- package/dist/figma-api/pending-sync.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 +2 -1
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +59 -15
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +160 -32
- 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/figma-api/variables/index.d.ts.map +1 -1
- package/dist/figma-api/variables/index.js +2 -2
- package/dist/figma-api/variables/index.js.map +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/css/known.js +1 -1
- package/dist/io/formats/design-tokens/css/known.js.map +1 -1
- package/dist/io/formats/design-tokens/css/read.d.ts +3 -1
- package/dist/io/formats/design-tokens/css/read.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/read.js +11 -5
- package/dist/io/formats/design-tokens/css/read.js.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.js +17 -4
- package/dist/io/formats/design-tokens/css/sync.js.map +1 -1
- package/dist/io/formats/design-tokens/css/values.d.ts +6 -5
- package/dist/io/formats/design-tokens/css/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/values.js +24 -8
- package/dist/io/formats/design-tokens/css/values.js.map +1 -1
- package/dist/io/formats/design-tokens/decode.d.ts +7 -6
- package/dist/io/formats/design-tokens/decode.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/decode.js +14 -13
- package/dist/io/formats/design-tokens/decode.js.map +1 -1
- package/dist/io/formats/design-tokens/export.js +3 -3
- package/dist/io/formats/design-tokens/export.js.map +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/plan/index.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/index.js +4 -3
- package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.js +9 -9
- package/dist/io/formats/design-tokens/plan/styles.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 +4 -4
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js +7 -7
- 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/design-tokens/values.d.ts +10 -5
- package/dist/io/formats/design-tokens/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/values.js +13 -7
- package/dist/io/formats/design-tokens/values.js.map +1 -1
- 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/placement.d.ts +1 -1
- package/dist/io/formats/drawio/warnings.js +2 -2
- package/dist/io/formats/drawio/warnings.js.map +1 -1
- package/dist/io/formats/fig/export/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/index.js +15 -3
- package/dist/io/formats/fig/export/index.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +7 -1
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts +7 -2
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +12 -13
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
- package/dist/io/formats/fig/export/variables.js +9 -7
- package/dist/io/formats/fig/export/variables.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 +4 -2
- package/dist/io/formats/html/vectors.js.map +1 -1
- package/dist/io/formats/mermaid/layers.js +2 -2
- package/dist/io/formats/mermaid/layers.js.map +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/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -0
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/prepare.d.ts +4 -4
- package/dist/io/formats/pdf/prepare.d.ts.map +1 -1
- package/dist/io/formats/pdf/prepare.js +2 -2
- package/dist/io/formats/pdf/prepare.js.map +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 +35 -5
- 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/pptx/style.js +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 +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +13 -4
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +10 -8
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +13 -64
- 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 +11 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +177 -37
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +30 -0
- package/dist/io/formats/svg/filter.d.ts.map +1 -0
- package/dist/io/formats/svg/filter.js +48 -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/import.d.ts +4 -2
- package/dist/io/formats/svg/import.d.ts.map +1 -1
- package/dist/io/formats/svg/import.js +2 -1
- package/dist/io/formats/svg/import.js.map +1 -1
- 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/export.d.ts.map +1 -1
- package/dist/io/formats/svg/text/export.js +8 -8
- package/dist/io/formats/svg/text/export.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 +8 -5
- 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 +41 -11
- package/dist/io/formats.js.map +1 -1
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +1 -1
- package/dist/io/subgraph.js.map +1 -1
- package/dist/io/types.d.ts +20 -5
- package/dist/io/types.d.ts.map +1 -1
- package/dist/kiwi/fig/parse/transfer.d.ts +1 -1
- package/dist/kiwi/fig/session/options.d.ts +3 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js +4 -0
- package/dist/kiwi/fig/session/options.js.map +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/yoga-helpers.d.ts +2 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +7 -1
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.d.ts +3 -2
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +26 -2
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.d.ts.map +1 -1
- package/dist/lint/fixes.js +10 -4
- 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 +112 -10
- 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/comments.d.ts +4 -1
- package/dist/pairdraw-api/comments.d.ts.map +1 -1
- package/dist/pairdraw-api/comments.js +5 -0
- package/dist/pairdraw-api/comments.js.map +1 -1
- 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 +48 -4
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +59 -6
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +13 -2
- 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/analyze-commands.js +1 -1
- package/dist/rpc/read-commands.d.ts +2 -2
- package/dist/rpc/read-commands.js +2 -2
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/rpc/variables-command.js +2 -2
- package/dist/rpc/variables-command.js.map +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/font/provider.d.ts +15 -0
- package/dist/text/font/provider.d.ts.map +1 -0
- package/dist/text/font/provider.js +18 -0
- package/dist/text/font/provider.js.map +1 -0
- package/dist/text/font/readiness.d.ts +32 -0
- package/dist/text/font/readiness.d.ts.map +1 -0
- package/dist/text/font/{status.js → readiness.js} +8 -4
- package/dist/text/font/readiness.js.map +1 -0
- package/dist/text/index.d.ts +12 -9
- package/dist/text/index.js +6 -3
- package/dist/text/prepare.d.ts +9 -4
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +9 -4
- package/dist/text/prepare.js.map +1 -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/colors.js +1 -1
- 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 +192 -0
- package/dist/tools/analyze/responsive/index.js.map +1 -0
- package/dist/tools/analyze/responsive/widths.d.ts +27 -0
- package/dist/tools/analyze/responsive/widths.d.ts.map +1 -0
- package/dist/tools/analyze/responsive/widths.js +49 -0
- package/dist/tools/analyze/responsive/widths.js.map +1 -0
- package/dist/tools/analyze.d.ts +3 -1
- package/dist/tools/analyze.js +3 -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/tokens.d.ts.map +1 -1
- package/dist/tools/codegen/tokens.js +2 -2
- package/dist/tools/codegen/tokens.js.map +1 -1
- package/dist/tools/codegen.d.ts +2 -1
- package/dist/tools/codegen.js +2 -1
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +2 -2
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/component-catalog.d.ts.map +1 -1
- package/dist/tools/component-catalog.js +5 -3
- package/dist/tools/component-catalog.js.map +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.d.ts.map +1 -1
- package/dist/tools/create/html.js +2 -3
- 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 +1 -0
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/svg.js +5 -1
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +2 -2
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/css/shorthand.d.ts +20 -0
- package/dist/tools/css/shorthand.d.ts.map +1 -0
- package/dist/tools/css/shorthand.js +54 -0
- package/dist/tools/css/shorthand.js.map +1 -0
- package/dist/tools/describe/index.js +2 -2
- package/dist/tools/describe/index.js.map +1 -1
- package/dist/tools/describe/issues.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/html-host.d.ts.map +1 -1
- package/dist/tools/html-host.js +5 -3
- package/dist/tools/html-host.js.map +1 -1
- package/dist/tools/image-ai/apply.d.ts.map +1 -1
- package/dist/tools/image-ai/apply.js +1 -3
- package/dist/tools/image-ai/apply.js.map +1 -1
- package/dist/tools/image-ai/generate.d.ts.map +1 -1
- package/dist/tools/image-ai/generate.js +2 -0
- package/dist/tools/image-ai/generate.js.map +1 -1
- package/dist/tools/image-ai/service.d.ts.map +1 -1
- package/dist/tools/image-ai/service.js +5 -3
- package/dist/tools/image-ai/service.js.map +1 -1
- package/dist/tools/index.d.ts +3 -1
- package/dist/tools/index.js +3 -1
- package/dist/tools/modify/effects.js +1 -1
- package/dist/tools/modify/effects.js.map +1 -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/geometry.d.ts.map +1 -1
- package/dist/tools/modify/geometry.js +14 -3
- package/dist/tools/modify/geometry.js.map +1 -1
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +35 -8
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +10 -10
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +56 -4
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/reactions.d.ts.map +1 -1
- package/dist/tools/modify/reactions.js +2 -2
- 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 +29 -8
- 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/prompts/codegen.js +1 -1
- package/dist/tools/prompts/codegen.js.map +1 -1
- package/dist/tools/read/css.d.ts +14 -0
- package/dist/tools/read/css.d.ts.map +1 -0
- package/dist/tools/read/css.js +306 -0
- package/dist/tools/read/css.js.map +1 -0
- 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 +1 -0
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/reactions.js +1 -1
- package/dist/tools/read/reactions.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 -5
- package/dist/tools/read/space.js.map +1 -1
- package/dist/tools/read.d.ts +2 -1
- package/dist/tools/read.js +2 -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 +5 -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 +24 -6
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +10 -6
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/script/host.d.ts.map +1 -1
- package/dist/tools/script/host.js +5 -3
- package/dist/tools/script/host.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/variables/collections.js +1 -1
- package/dist/tools/variables/collections.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -4
- package/dist/tools/variables/values.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.d.ts.map +1 -1
- package/dist/tools/vector/vectorize.js +7 -4
- 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 +21 -0
- package/dist/tools/video-host.js.map +1 -0
- package/dist/vector/point-transform.d.ts +1 -1
- package/dist/vector/vectorize/svg/gradients.d.ts +2 -2
- package/dist/vector/vectorize/svg/gradients.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/gradients.js +5 -5
- package/dist/vector/vectorize/svg/gradients.js.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts +3 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.js +13 -12
- package/dist/vector/vectorize/svg/to-vectors.js.map +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 +169 -0
- package/src/canvas/noise/table.ts +91 -0
- package/src/canvas/noise/tile.ts +95 -0
- package/src/canvas/overlays/auto-layout-hover.ts +47 -65
- package/src/canvas/renderer/colors.ts +76 -50
- package/src/canvas/renderer/document-surface.ts +53 -0
- package/src/canvas/renderer/fonts.ts +6 -4
- package/src/canvas/renderer/lifecycle.ts +10 -4
- package/src/canvas/renderer/methods.ts +1 -0
- package/src/canvas/renderer/pipeline.ts +40 -4
- package/src/canvas/renderer/play-scenes.ts +51 -0
- package/src/canvas/renderer/retained-backing.ts +2 -1
- package/src/canvas/renderer/tiles/cache.ts +54 -1
- package/src/canvas/renderer/tiles/controller.ts +30 -1
- package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
- package/src/canvas/renderer/types.ts +18 -2
- package/src/canvas/renderer.ts +76 -14
- package/src/canvas/scene.ts +69 -12
- package/src/canvas/shaders/effect.ts +2 -1
- package/src/canvas/shadows/shape.ts +4 -2
- package/src/canvas/shadows.ts +5 -2
- package/src/canvas/text/decorations.ts +15 -5
- package/src/canvas/text/index.ts +9 -1
- package/src/canvas/text/paragraph/index.ts +16 -6
- package/src/canvas/text/renderer.ts +2 -1
- package/src/canvas/text/shape.ts +4 -4
- package/src/canvas/texture.ts +137 -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/assets.ts +6 -2
- package/src/editor/clipboard/component-matches.ts +65 -0
- package/src/editor/clipboard/dependencies.ts +22 -1
- package/src/editor/clipboard/export.ts +24 -7
- package/src/editor/clipboard.ts +74 -20
- package/src/editor/components/instances.ts +31 -0
- package/src/editor/components/properties.ts +3 -2
- 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 +208 -0
- package/src/editor/fonts.ts +19 -0
- package/src/editor/history/atomic-tool.ts +32 -3
- 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/structure/state.ts +2 -1
- package/src/editor/text.ts +2 -1
- package/src/editor/tool-registry.ts +2 -1
- package/src/editor/types.ts +4 -0
- package/src/editor/variables.ts +3 -3
- 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/fresh-read.ts +57 -0
- package/src/figma-api/graph-ref.ts +13 -0
- package/src/figma-api/index.ts +22 -4
- package/src/figma-api/overrides.ts +295 -3
- package/src/figma-api/paints.ts +24 -9
- package/src/figma-api/pending-layout.ts +7 -3
- package/src/figma-api/pending-sync.ts +4 -1
- package/src/figma-api/proxy.ts +8 -2
- package/src/figma-api/reactions.ts +212 -33
- package/src/figma-api/surface.ts +6 -2
- package/src/figma-api/variables/index.ts +5 -4
- package/src/global.d.ts +26 -0
- package/src/io/formats/boolean-path.ts +60 -0
- package/src/io/formats/design-tokens/css/known.ts +1 -1
- package/src/io/formats/design-tokens/css/read.ts +20 -7
- package/src/io/formats/design-tokens/css/sync.ts +9 -4
- package/src/io/formats/design-tokens/css/values.ts +37 -9
- package/src/io/formats/design-tokens/decode.ts +17 -12
- package/src/io/formats/design-tokens/export.ts +3 -3
- 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/plan/index.ts +6 -5
- package/src/io/formats/design-tokens/plan/styles.ts +37 -10
- package/src/io/formats/design-tokens/project.ts +40 -9
- package/src/io/formats/design-tokens/styles.ts +20 -9
- package/src/io/formats/design-tokens/sync/apply.ts +130 -0
- package/src/io/formats/design-tokens/sync/drift.ts +589 -0
- package/src/io/formats/design-tokens/sync/files.ts +40 -0
- package/src/io/formats/design-tokens/values.ts +15 -8
- 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/drawio/warnings.ts +2 -2
- package/src/io/formats/fig/export/index.ts +36 -3
- package/src/io/formats/fig/export/patch/index.ts +12 -1
- package/src/io/formats/fig/export/setup.ts +25 -15
- package/src/io/formats/fig/export/variables.ts +17 -6
- 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 +9 -2
- package/src/io/formats/mermaid/layers.ts +2 -2
- package/src/io/formats/pdf/document.ts +14 -4
- package/src/io/formats/pdf/export.ts +1 -0
- package/src/io/formats/pdf/prepare.ts +6 -6
- package/src/io/formats/pen/imports.ts +5 -6
- package/src/io/formats/pen/index.ts +41 -7
- 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 +24 -5
- package/src/io/formats/svg/defs.ts +24 -80
- package/src/io/formats/svg/effects.ts +131 -0
- package/src/io/formats/svg/export.ts +295 -49
- package/src/io/formats/svg/filter.ts +57 -0
- package/src/io/formats/svg/grain.ts +249 -0
- package/src/io/formats/svg/import.ts +6 -3
- package/src/io/formats/svg/strokes.ts +2 -2
- package/src/io/formats/svg/text/export.ts +10 -8
- package/src/io/formats/svg/text/layout.ts +15 -5
- 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 +66 -11
- package/src/io/subgraph.ts +4 -1
- package/src/io/types.ts +29 -10
- package/src/kiwi/fig/session/options.ts +4 -1
- package/src/layout/auto-layout-handles.ts +396 -0
- package/src/layout/yoga-helpers.ts +8 -0
- package/src/layout.ts +49 -1
- package/src/lint/fixes.ts +12 -3
- package/src/lint/index.ts +3 -1
- package/src/lint/linter.ts +108 -11
- 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/comments.ts +6 -0
- package/src/pairdraw-api/design-memory.ts +61 -0
- package/src/pairdraw-api/index.ts +88 -9
- 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/rpc/read-commands.ts +4 -4
- package/src/rpc/variables-command.ts +2 -2
- package/src/text/font/features.ts +27 -0
- package/src/text/font/manager.ts +79 -1
- package/src/text/font/provider.ts +26 -0
- package/src/text/font/{status.ts → readiness.ts} +13 -9
- package/src/text/index.ts +4 -1
- package/src/text/prepare.ts +9 -4
- package/src/text/replace-fonts.ts +171 -0
- package/src/tools/analyze/responsive/index.ts +257 -0
- package/src/tools/analyze/responsive/widths.ts +63 -0
- package/src/tools/analyze.ts +4 -0
- package/src/tools/codegen/token-sync.ts +98 -0
- package/src/tools/codegen/tokens.ts +4 -2
- package/src/tools/codegen.ts +1 -0
- package/src/tools/comments.ts +6 -4
- package/src/tools/component-catalog.ts +5 -3
- package/src/tools/create/components.ts +4 -0
- package/src/tools/create/html.ts +1 -3
- package/src/tools/create/icons.ts +2 -1
- package/src/tools/create/mermaid.ts +1 -0
- package/src/tools/create/svg.ts +5 -1
- package/src/tools/create/vector.ts +2 -2
- package/src/tools/css/shorthand.ts +64 -0
- package/src/tools/describe/index.ts +2 -8
- package/src/tools/design-memory.ts +72 -0
- package/src/tools/html-host.ts +5 -3
- package/src/tools/image-ai/apply.ts +0 -2
- package/src/tools/image-ai/generate.ts +2 -0
- package/src/tools/image-ai/service.ts +5 -3
- package/src/tools/index.ts +3 -0
- package/src/tools/modify/effects.ts +1 -1
- package/src/tools/modify/fonts.ts +34 -0
- package/src/tools/modify/geometry.ts +16 -3
- package/src/tools/modify/layout.ts +47 -13
- package/src/tools/modify/matching.ts +14 -11
- package/src/tools/modify/paint.ts +85 -5
- package/src/tools/modify/reactions.ts +16 -8
- package/src/tools/modify/text.ts +56 -15
- package/src/tools/modify/update.ts +46 -2
- package/src/tools/modify.ts +1 -0
- package/src/tools/prompts/codegen.md +2 -1
- package/src/tools/read/css.ts +365 -0
- package/src/tools/read/fonts.ts +24 -2
- package/src/tools/read/libraries.ts +1 -0
- package/src/tools/read/reactions.ts +3 -2
- package/src/tools/read/space.ts +3 -4
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/core.ts +5 -2
- package/src/tools/registry/extended.ts +28 -1
- package/src/tools/schema.ts +42 -9
- package/src/tools/script/host.ts +6 -3
- 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/variables/collections.ts +1 -1
- package/src/tools/variables/values.ts +16 -5
- package/src/tools/vector/boolean.ts +4 -0
- package/src/tools/vector/vectorize.ts +11 -4
- package/src/tools/vector/video.ts +228 -0
- package/src/tools/vector.ts +1 -0
- package/src/tools/video-host.ts +20 -0
- package/src/vector/vectorize/svg/gradients.ts +8 -5
- package/src/vector/vectorize/svg/to-vectors.ts +48 -14
- package/dist/text/font/status.d.ts +0 -28
- package/dist/text/font/status.d.ts.map +0 -1
- package/dist/text/font/status.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/canvas/shadows.ts"],"sourcesContent":["import type { Canvas, ImageFilter } from 'canvaskit-wasm'\n\nimport type { BlendMode, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { blurSigma } from '@pairdraw/scene-graph/geometry'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport { nodeOrientationMatrix } from '#core/geometry'\n\nimport { needsIsolatedBlendLayer, setPaintBlendMode } from './blend'\nimport { makeBooleanOperationPath } from './boolean'\nimport { renderNoiseEffects } from './effects'\nimport type { SkiaRenderer } from './renderer'\nimport {\n castsFromOwnShape,\n castsOwnShapeDropShadow,\n clipOutShapeKnockout,\n drawOutlineDropShadow,\n drawRingDropShadow,\n drawShapeDropShadow,\n drawShapeInnerShadow,\n regularStrokeOutline,\n strokeGrowsOutline\n} from './shadows/shape'\nimport {\n drawSilhouette,\n fillsCastShadow,\n isLayerContainer,\n paintsCastShadow,\n paintsOverKnockout,\n shadowIncludesChildren,\n silhouetteBounds,\n separateShadowChildren\n} from './shadows/silhouette'\nfunction resetEffectLayerPaint(r: SkiaRenderer): void {\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)\n}\n\n/** `behind` draws drop shadows and background blur, `inner` inner shadows over fills, `front` noise. */\nexport type EffectPass = 'behind' | 'inner' | 'front'\n\n/**\n * Layers whose shadows Figma 126 never spreads: only boxes and ellipses, arcs among them, take a\n * spread, for drop and inner shadows alike.\n */\nconst UNSPREAD_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'TEXT',\n 'BOOLEAN_OPERATION',\n 'STAR',\n 'POLYGON',\n 'VECTOR'\n])\n\n/** Figma spreads a shadow only where it follows the layer's own outline: shapes and filled frames that clip. */\nfunction shadowSpread(node: SceneNode, effect: ShadowEffect): number {\n if (UNSPREAD_TYPES.has(node.type)) return 0\n if (!isLayerContainer(node)) return effect.spread\n return node.clipsContent && fillsCastShadow(node) ? effect.spread : 0\n}\n\n/** The spread an inner shadow takes, inside any layer whose type Figma spreads. */\nfunction innerShadowSpread(node: SceneNode, effect: ShadowEffect): number {\n return UNSPREAD_TYPES.has(node.type) ? 0 : effect.spread\n}\n\nfunction shadowLayerBounds(\n r: SkiaRenderer,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n includeChildren: boolean\n): Float32Array {\n const box = silhouetteBounds(graph, node, includeChildren) ?? {\n x: 0,\n y: 0,\n width: node.width,\n height: node.height\n }\n const offset = effect.offset\n const padding = effect.radius * 2 + Math.abs(spread)\n return r.ck.LTRBRect(\n box.x + Math.min(0, offset.x) - padding,\n box.y + Math.min(0, offset.y) - padding,\n box.x + box.width + Math.max(0, offset.x) + padding,\n box.y + box.height + Math.max(0, offset.y) + padding\n )\n}\n\n/** Grows or shrinks a silhouette by the spread, square as Figma spreads a rectangle. */\nfunction spreadFilter(r: SkiaRenderer, spread: number): ImageFilter | null {\n if (spread > 0) return r.ck.ImageFilter.MakeDilate(spread, spread, null)\n if (spread < 0) return r.ck.ImageFilter.MakeErode(-spread, -spread, null)\n return null\n}\n\n/** Draws a shadow cast by whatever `draw` paints: its alpha is the outline, offset and blurred. */\nfunction drawSilhouetteDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n spread: number,\n bounds: Float32Array,\n blendMode: BlendMode | undefined,\n draw: () => void\n): void {\n const ck = r.ck\n const color = ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a)\n const sigma = blurSigma(effect.radius)\n const morphology = spreadFilter(r, spread)\n const filter = morphology\n ? ck.ImageFilter.MakeDropShadowOnly(\n effect.offset.x,\n effect.offset.y,\n sigma,\n sigma,\n color,\n morphology\n )\n : r.getCachedDropShadow(effect.offset.x, effect.offset.y, sigma, color)\n const paint = new ck.Paint()\n paint.setImageFilter(filter)\n setPaintBlendMode(r, paint, blendMode)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n if (morphology) {\n // The filter built with the morphology is ours; a zero sigma hands back none.\n filter?.delete()\n morphology.delete()\n }\n }\n}\n\nfunction drawKnockout(r: SkiaRenderer, canvas: Canvas, bounds: Float32Array, draw: () => void) {\n const paint = new r.ck.Paint()\n paint.setBlendMode(r.ck.BlendMode.DstOut)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n }\n}\n\n/**\n * Draws a shadow cast by the node's own outline without a layer, when that outline is a shape\n * grown by its stroke; false when the node needs its silhouette drawn instead.\n */\nfunction drawOwnShapeDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n blendMode: BlendMode | undefined,\n knockout: boolean\n): boolean {\n const outline = regularStrokeOutline(node, spread)\n if (!outline && !castsFromOwnShape(node)) return false\n const castsFill = fillsCastShadow(node)\n canvas.save()\n try {\n if (knockout) clipOutShapeKnockout(r, canvas, node, outline)\n if (castsFill && outline && strokeGrowsOutline(outline)) {\n drawOutlineDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n } else if (castsFill) {\n drawShapeDropShadow(r, canvas, node, effect, spread, blendMode)\n } else if (outline) {\n drawRingDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n }\n } finally {\n canvas.restore()\n }\n return true\n}\n\n/**\n * How far apart a container's children must be for their shadows to reach neither each other nor\n * another child: the blur's reach from both, any spread, and the offset.\n */\nfunction shadowGap(effect: ShadowEffect, spread: number): number {\n const reach = 3 * blurSigma(effect.radius) + Math.abs(spread) + 1\n return 2 * reach + Math.hypot(effect.offset.x, effect.offset.y)\n}\n\n/**\n * Draws a shadow cast by `child`, in its parent's coordinates. The parent's effect is drawn in the\n * child's own space, so its offset is turned back by the child's rotation and flips; blur and\n * spread are the same in every direction.\n */\nfunction withChildCoordinates<T>(\n canvas: Canvas,\n child: SceneNode,\n effect: ShadowEffect,\n draw: (local: ShadowEffect) => T\n): T {\n const orientation = nodeOrientationMatrix(child)\n const inverse = Matrix.invert(orientation) ?? Matrix.identity()\n const origin = Matrix.mapPoint(inverse, { x: 0, y: 0 })\n const offset = Matrix.mapPoint(inverse, effect.offset)\n canvas.save()\n try {\n canvas.translate(child.x, child.y)\n canvas.concat(orientation)\n return draw({ ...effect, offset: { x: offset.x - origin.x, y: offset.y - origin.y } })\n } finally {\n canvas.restore()\n }\n}\n\nfunction renderDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const spread = shadowSpread(node, effect)\n const blendMode = effect.blendMode\n const knockout =\n effect.showShadowBehindNode === false && !paintsOverKnockout(graph, node, includeChildren)\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, spread))\n : null\n if (children?.every((child) => castsOwnShapeDropShadow(child, spread))) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawOwnShapeDropShadow(r, canvas, child, local, spread, blendMode, knockout)\n )\n }\n return\n }\n if (\n !includeChildren &&\n drawOwnShapeDropShadow(r, canvas, node, effect, spread, blendMode, knockout)\n ) {\n return\n }\n\n const bounds = shadowLayerBounds(r, graph, node, effect, spread, includeChildren)\n const isolation = knockout ? new r.ck.Paint() : null\n if (isolation) {\n setPaintBlendMode(r, isolation, blendMode)\n canvas.saveLayer(isolation, bounds)\n }\n try {\n drawSilhouetteDropShadow(\n r,\n canvas,\n effect,\n spread,\n bounds,\n isolation ? 'NORMAL' : blendMode,\n () => drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n if (knockout) {\n drawKnockout(r, canvas, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'knockout', includeChildren)\n )\n }\n } finally {\n if (isolation) {\n canvas.restore()\n isolation.delete()\n }\n resetEffectLayerPaint(r)\n }\n}\n\n/** Draws an inner shadow inside whatever `draw` paints, cut from an offset, blurred inverse of it. */\nfunction drawSilhouetteInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n bounds: Float32Array,\n draw: () => void\n): void {\n const ck = r.ck\n\n resetEffectLayerPaint(r)\n let restoreCount = 0\n let tintFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n let solidBlackFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n\n try {\n setPaintBlendMode(r, r.effectLayerPaint, effect.blendMode)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n draw()\n\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcIn)\n tintFilter = ck.ColorFilter.MakeBlend(\n ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a),\n ck.BlendMode.SrcIn\n )\n r.effectLayerPaint.setColorFilter(tintFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n\n canvas.save()\n restoreCount++\n canvas.translate(effect.offset.x, effect.offset.y)\n\n // The inverse is drawn in offset coordinates, so it covers `bounds` once shifted back.\n const { x: dx, y: dy } = effect.offset\n const inverse = ck.LTRBRect(bounds[0] - dx, bounds[1] - dy, bounds[2] - dx, bounds[3] - dy)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setImageFilter(r.getCachedDecalBlur(blurSigma(effect.radius)))\n canvas.saveLayer(r.effectLayerPaint, inverse)\n restoreCount++\n\n r.auxFill.setColor(ck.Color4f(0, 0, 0, 1))\n canvas.drawRect(inverse, r.auxFill)\n\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.DstOut)\n solidBlackFilter = ck.ColorFilter.MakeBlend(ck.Color4f(0, 0, 0, 1), ck.BlendMode.SrcIn)\n r.effectLayerPaint.setColorFilter(solidBlackFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n draw()\n } finally {\n while (restoreCount > 0) {\n canvas.restore()\n restoreCount--\n }\n r.effectLayerPaint.setColorFilter(null)\n if (solidBlackFilter) solidBlackFilter.delete()\n if (tintFilter) tintFilter.delete()\n resetEffectLayerPaint(r)\n }\n}\n\nfunction renderInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, 0))\n : null\n if (children?.every(castsFromOwnShape)) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawShapeInnerShadow(r, canvas, child, local, innerShadowSpread(child, local))\n )\n }\n return\n }\n if (!includeChildren && castsFromOwnShape(node)) {\n const spread = innerShadowSpread(node, effect)\n drawShapeInnerShadow(r, canvas, node, effect, spread, isolatesInnerShadows(node))\n return\n }\n const bounds = shadowLayerBounds(r, graph, node, effect, 0, includeChildren)\n drawSilhouetteInnerShadow(r, canvas, effect, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n}\n\n/**\n * Whether a shape draws its fills and inner shadows in a layer of their own. There each shadow\n * replaces the fill under it before taking the shape's outline, so the antialiased edge applies\n * once, as in Figma, rather than letting the fill show through. Blended fills and shadows mix with\n * what lies under the shape, so they keep drawing in place.\n */\nexport function isolatesInnerShadows(node: SceneNode): boolean {\n if (isLayerContainer(node) || !castsFromOwnShape(node)) return false\n const shadows = node.effects.filter((effect) => effect.visible && effect.type === 'INNER_SHADOW')\n return (\n shadows.length > 0 &&\n shadows.every((effect) => !needsIsolatedBlendLayer(effect.blendMode)) &&\n [...node.fills, ...node.fillGeometry.flatMap((geometry) => geometry.fills ?? [])].every(\n (fill) => !fill.visible || !needsIsolatedBlendLayer(fill.blendMode)\n )\n )\n}\n\n/**\n * Draws a shape's own effects. Frames, groups, and other containers take their shadows from\n * `renderLayerShadows` instead, because Figma casts them from the children as well.\n */\nexport function renderEffects(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n graph: SceneGraph,\n pass: EffectPass\n): void {\n // Noise draws per pixel and a background blur reads back what is behind; both are left out\n // while the renderer keeps effects cheap.\n if (pass === 'front' && !r.effectsReduced) renderNoiseEffects(r, canvas, node)\n\n const ownShadows = !isLayerContainer(node)\n for (const effect of node.effects) {\n if (!effect.visible) continue\n\n if (pass === 'behind' && effect.type === 'DROP_SHADOW' && ownShadows) {\n renderDropShadow(r, canvas, graph, node, effect, false)\n }\n\n if (pass === 'behind' && effect.type === 'BACKGROUND_BLUR' && !r.effectsReduced) {\n const shape =\n node.type === 'BOOLEAN_OPERATION' ? makeBooleanOperationPath(r, node, graph) : null\n r.applyClippedBlur(canvas, node, blurSigma(effect.radius), shape)\n shape?.delete()\n }\n\n if (pass === 'inner' && effect.type === 'INNER_SHADOW' && ownShadows) {\n renderInnerShadow(r, canvas, graph, node, effect, false)\n }\n }\n}\n\n/**\n * Draws a container's drop shadows before it (`behind`) and its inner shadows over its fills,\n * strokes, and children (`front`), cast from the children too unless its own fill covers them.\n */\nexport function renderLayerShadows(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n pass: 'behind' | 'front'\n): void {\n if (!isLayerContainer(node)) return\n const effects = node.effects.filter(\n (effect): effect is ShadowEffect =>\n effect.visible && effect.type === (pass === 'behind' ? 'DROP_SHADOW' : 'INNER_SHADOW')\n )\n if (effects.length === 0) return\n const includeChildren = shadowIncludesChildren(graph, node)\n for (const effect of effects) {\n if (pass === 'behind') renderDropShadow(r, canvas, graph, node, effect, includeChildren)\n else renderInnerShadow(r, canvas, graph, node, effect, includeChildren)\n }\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAS,sBAAsB,GAAuB;CACpD,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,aAAa,EAAE,GAAG,UAAU,OAAO;AACxD;;;;;AASA,MAAM,iCAAiD,IAAI,IAAuB;CAChF;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAS,aAAa,MAAiB,QAA8B;CACnE,IAAI,eAAe,IAAI,KAAK,IAAI,GAAG,OAAO;CAC1C,IAAI,CAAC,iBAAiB,IAAI,GAAG,OAAO,OAAO;CAC3C,OAAO,KAAK,gBAAgB,gBAAgB,IAAI,IAAI,OAAO,SAAS;AACtE;;AAGA,SAAS,kBAAkB,MAAiB,QAA8B;CACxE,OAAO,eAAe,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO;AACpD;AAEA,SAAS,kBACP,GACA,OACA,MACA,QACA,QACA,iBACc;CACd,MAAM,MAAM,iBAAiB,OAAO,MAAM,eAAe,KAAK;EAC5D,GAAG;EACH,GAAG;EACH,OAAO,KAAK;EACZ,QAAQ,KAAK;CACf;CACA,MAAM,SAAS,OAAO;CACtB,MAAM,UAAU,OAAO,SAAS,IAAI,KAAK,IAAI,MAAM;CACnD,OAAO,EAAE,GAAG,SACV,IAAI,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,SAChC,IAAI,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,SAChC,IAAI,IAAI,IAAI,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,SAC5C,IAAI,IAAI,IAAI,SAAS,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,OAC/C;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ACA,MACM;CAGN,IAAI,SAAS,WAAW,CAAC,EAAE,gBAAgB,mBAAmB,GAAG,QAAQ,IAAI;CAE7E,MAAM,aAAa,CAAC,iBAAiB,IAAI;CACzC,KAAK,MAAM,UAAU,KAAK,SAAS;EACjC,IAAI,CAAC,OAAO,SAAS;EAErB,IAAI,SAAS,YAAY,OAAO,SAAS,iBAAiB,YACxD,iBAAiB,GAAG,QAAQ,OAAO,MAAM,QAAQ,KAAK;EAGxD,IAAI,SAAS,YAAY,OAAO,SAAS,qBAAqB,CAAC,EAAE,gBAAgB;GAC/E,MAAM,QACJ,KAAK,SAAS,sBAAsB,yBAAyB,GAAG,MAAM,KAAK,IAAI;GACjF,EAAE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAAG,KAAK;GAChE,OAAO,OAAO;EAChB;EAEA,IAAI,SAAS,WAAW,OAAO,SAAS,kBAAkB,YACxD,kBAAkB,GAAG,QAAQ,OAAO,MAAM,QAAQ,KAAK;CAE3D;AACF;;;;;AAMA,SAAgB,mBACd,GACA,QACA,OACA,MACA,MACM;CACN,IAAI,CAAC,iBAAiB,IAAI,GAAG;CAC7B,MAAM,UAAU,KAAK,QAAQ,QAC1B,WACC,OAAO,WAAW,OAAO,UAAU,SAAS,WAAW,gBAAgB,eAC3E;CACA,IAAI,QAAQ,WAAW,GAAG;CAC1B,MAAM,kBAAkB,uBAAuB,OAAO,IAAI;CAC1D,KAAK,MAAM,UAAU,SACnB,IAAI,SAAS,UAAU,iBAAiB,GAAG,QAAQ,OAAO,MAAM,QAAQ,eAAe;MAClF,kBAAkB,GAAG,QAAQ,OAAO,MAAM,QAAQ,eAAe;AAE1E"}
|
|
1
|
+
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/canvas/shadows.ts"],"sourcesContent":["import type { Canvas, ImageFilter } from 'canvaskit-wasm'\n\nimport type { BlendMode, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { blurSigma } from '@pairdraw/scene-graph/geometry'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport { nodeOrientationMatrix } from '#core/geometry'\n\nimport { needsIsolatedBlendLayer, setPaintBlendMode } from './blend'\nimport { makeBooleanOperationPath } from './boolean'\nimport { renderNoiseEffects } from './effects'\nimport type { SkiaRenderer } from './renderer'\nimport {\n castsFromOwnShape,\n castsOwnShapeDropShadow,\n clipOutShapeKnockout,\n drawOutlineDropShadow,\n drawRingDropShadow,\n drawShapeDropShadow,\n drawShapeInnerShadow,\n regularStrokeOutline,\n strokeGrowsOutline\n} from './shadows/shape'\nimport {\n drawSilhouette,\n fillsCastShadow,\n isLayerContainer,\n paintsCastShadow,\n paintsOverKnockout,\n shadowIncludesChildren,\n silhouetteBounds,\n separateShadowChildren\n} from './shadows/silhouette'\nfunction resetEffectLayerPaint(r: SkiaRenderer): void {\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)\n}\n\n/** `behind` draws drop shadows and background blur, `inner` inner shadows over fills, `front` noise. */\nexport type EffectPass = 'behind' | 'inner' | 'front'\n\n/**\n * Layers whose shadows Figma 126 never spreads: only boxes and ellipses, arcs among them, take a\n * spread, for drop and inner shadows alike.\n */\nconst UNSPREAD_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'TEXT',\n 'BOOLEAN_OPERATION',\n 'STAR',\n 'POLYGON',\n 'VECTOR'\n])\n\n/** Figma spreads a shadow only where it follows the layer's own outline: shapes and filled frames that clip. */\nfunction shadowSpread(node: SceneNode, effect: ShadowEffect): number {\n if (UNSPREAD_TYPES.has(node.type)) return 0\n if (!isLayerContainer(node)) return effect.spread\n return node.clipsContent && fillsCastShadow(node) ? effect.spread : 0\n}\n\n/** The spread an inner shadow takes, inside any layer whose type Figma spreads. */\nfunction innerShadowSpread(node: SceneNode, effect: ShadowEffect): number {\n return UNSPREAD_TYPES.has(node.type) ? 0 : effect.spread\n}\n\nfunction shadowLayerBounds(\n r: SkiaRenderer,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n includeChildren: boolean\n): Float32Array {\n const box = silhouetteBounds(graph, node, includeChildren) ?? {\n x: 0,\n y: 0,\n width: node.width,\n height: node.height\n }\n const offset = effect.offset\n const padding = effect.radius * 2 + Math.abs(spread)\n return r.ck.LTRBRect(\n box.x + Math.min(0, offset.x) - padding,\n box.y + Math.min(0, offset.y) - padding,\n box.x + box.width + Math.max(0, offset.x) + padding,\n box.y + box.height + Math.max(0, offset.y) + padding\n )\n}\n\n/** Grows or shrinks a silhouette by the spread, square as Figma spreads a rectangle. */\nfunction spreadFilter(r: SkiaRenderer, spread: number): ImageFilter | null {\n if (spread > 0) return r.ck.ImageFilter.MakeDilate(spread, spread, null)\n if (spread < 0) return r.ck.ImageFilter.MakeErode(-spread, -spread, null)\n return null\n}\n\n/** Draws a shadow cast by whatever `draw` paints: its alpha is the outline, offset and blurred. */\nfunction drawSilhouetteDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n spread: number,\n bounds: Float32Array,\n blendMode: BlendMode | undefined,\n draw: () => void\n): void {\n const ck = r.ck\n // Stored in the document's profile, as every paint is; Skia converts it to its surface.\n const drawn = r.renderColor(effect.color)\n const color = ck.Color4f(drawn.r, drawn.g, drawn.b, drawn.a)\n const sigma = blurSigma(effect.radius)\n const morphology = spreadFilter(r, spread)\n const filter = morphology\n ? ck.ImageFilter.MakeDropShadowOnly(\n effect.offset.x,\n effect.offset.y,\n sigma,\n sigma,\n color,\n morphology\n )\n : r.getCachedDropShadow(effect.offset.x, effect.offset.y, sigma, color)\n const paint = new ck.Paint()\n paint.setImageFilter(filter)\n setPaintBlendMode(r, paint, blendMode)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n if (morphology) {\n // The filter built with the morphology is ours; a zero sigma hands back none.\n filter?.delete()\n morphology.delete()\n }\n }\n}\n\nfunction drawKnockout(r: SkiaRenderer, canvas: Canvas, bounds: Float32Array, draw: () => void) {\n const paint = new r.ck.Paint()\n paint.setBlendMode(r.ck.BlendMode.DstOut)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n }\n}\n\n/**\n * Draws a shadow cast by the node's own outline without a layer, when that outline is a shape\n * grown by its stroke; false when the node needs its silhouette drawn instead.\n */\nfunction drawOwnShapeDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n blendMode: BlendMode | undefined,\n knockout: boolean\n): boolean {\n const outline = regularStrokeOutline(node, spread)\n if (!outline && !castsFromOwnShape(node)) return false\n const castsFill = fillsCastShadow(node)\n canvas.save()\n try {\n if (knockout) clipOutShapeKnockout(r, canvas, node, outline)\n if (castsFill && outline && strokeGrowsOutline(outline)) {\n drawOutlineDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n } else if (castsFill) {\n drawShapeDropShadow(r, canvas, node, effect, spread, blendMode)\n } else if (outline) {\n drawRingDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n }\n } finally {\n canvas.restore()\n }\n return true\n}\n\n/**\n * How far apart a container's children must be for their shadows to reach neither each other nor\n * another child: the blur's reach from both, any spread, and the offset.\n */\nfunction shadowGap(effect: ShadowEffect, spread: number): number {\n const reach = 3 * blurSigma(effect.radius) + Math.abs(spread) + 1\n return 2 * reach + Math.hypot(effect.offset.x, effect.offset.y)\n}\n\n/**\n * Draws a shadow cast by `child`, in its parent's coordinates. The parent's effect is drawn in the\n * child's own space, so its offset is turned back by the child's rotation and flips; blur and\n * spread are the same in every direction.\n */\nfunction withChildCoordinates<T>(\n canvas: Canvas,\n child: SceneNode,\n effect: ShadowEffect,\n draw: (local: ShadowEffect) => T\n): T {\n const orientation = nodeOrientationMatrix(child)\n const inverse = Matrix.invert(orientation) ?? Matrix.identity()\n const origin = Matrix.mapPoint(inverse, { x: 0, y: 0 })\n const offset = Matrix.mapPoint(inverse, effect.offset)\n canvas.save()\n try {\n canvas.translate(child.x, child.y)\n canvas.concat(orientation)\n return draw({ ...effect, offset: { x: offset.x - origin.x, y: offset.y - origin.y } })\n } finally {\n canvas.restore()\n }\n}\n\nfunction renderDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const spread = shadowSpread(node, effect)\n const blendMode = effect.blendMode\n const knockout =\n effect.showShadowBehindNode === false && !paintsOverKnockout(graph, node, includeChildren)\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, spread))\n : null\n if (children?.every((child) => castsOwnShapeDropShadow(child, spread))) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawOwnShapeDropShadow(r, canvas, child, local, spread, blendMode, knockout)\n )\n }\n return\n }\n if (\n !includeChildren &&\n drawOwnShapeDropShadow(r, canvas, node, effect, spread, blendMode, knockout)\n ) {\n return\n }\n\n const bounds = shadowLayerBounds(r, graph, node, effect, spread, includeChildren)\n const isolation = knockout ? new r.ck.Paint() : null\n if (isolation) {\n setPaintBlendMode(r, isolation, blendMode)\n canvas.saveLayer(isolation, bounds)\n }\n try {\n drawSilhouetteDropShadow(\n r,\n canvas,\n effect,\n spread,\n bounds,\n isolation ? 'NORMAL' : blendMode,\n () => drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n if (knockout) {\n drawKnockout(r, canvas, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'knockout', includeChildren)\n )\n }\n } finally {\n if (isolation) {\n canvas.restore()\n isolation.delete()\n }\n resetEffectLayerPaint(r)\n }\n}\n\n/** Draws an inner shadow inside whatever `draw` paints, cut from an offset, blurred inverse of it. */\nfunction drawSilhouetteInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n bounds: Float32Array,\n draw: () => void\n): void {\n const ck = r.ck\n\n resetEffectLayerPaint(r)\n let restoreCount = 0\n let tintFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n let solidBlackFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n\n try {\n setPaintBlendMode(r, r.effectLayerPaint, effect.blendMode)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n draw()\n\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcIn)\n const drawn = r.renderColor(effect.color)\n tintFilter = ck.ColorFilter.MakeBlend(\n ck.Color4f(drawn.r, drawn.g, drawn.b, drawn.a),\n ck.BlendMode.SrcIn\n )\n r.effectLayerPaint.setColorFilter(tintFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n\n canvas.save()\n restoreCount++\n canvas.translate(effect.offset.x, effect.offset.y)\n\n // The inverse is drawn in offset coordinates, so it covers `bounds` once shifted back.\n const { x: dx, y: dy } = effect.offset\n const inverse = ck.LTRBRect(bounds[0] - dx, bounds[1] - dy, bounds[2] - dx, bounds[3] - dy)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setImageFilter(r.getCachedDecalBlur(blurSigma(effect.radius)))\n canvas.saveLayer(r.effectLayerPaint, inverse)\n restoreCount++\n\n r.auxFill.setColor(ck.Color4f(0, 0, 0, 1))\n canvas.drawRect(inverse, r.auxFill)\n\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.DstOut)\n solidBlackFilter = ck.ColorFilter.MakeBlend(ck.Color4f(0, 0, 0, 1), ck.BlendMode.SrcIn)\n r.effectLayerPaint.setColorFilter(solidBlackFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n draw()\n } finally {\n while (restoreCount > 0) {\n canvas.restore()\n restoreCount--\n }\n r.effectLayerPaint.setColorFilter(null)\n if (solidBlackFilter) solidBlackFilter.delete()\n if (tintFilter) tintFilter.delete()\n resetEffectLayerPaint(r)\n }\n}\n\nfunction renderInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, 0))\n : null\n if (children?.every(castsFromOwnShape)) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawShapeInnerShadow(r, canvas, child, local, innerShadowSpread(child, local))\n )\n }\n return\n }\n if (!includeChildren && castsFromOwnShape(node)) {\n const spread = innerShadowSpread(node, effect)\n drawShapeInnerShadow(r, canvas, node, effect, spread, isolatesInnerShadows(node))\n return\n }\n const bounds = shadowLayerBounds(r, graph, node, effect, 0, includeChildren)\n drawSilhouetteInnerShadow(r, canvas, effect, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n}\n\n/**\n * Whether a shape draws its fills and inner shadows in a layer of their own. There each shadow\n * replaces the fill under it before taking the shape's outline, so the antialiased edge applies\n * once, as in Figma, rather than letting the fill show through. Blended fills and shadows mix with\n * what lies under the shape, so they keep drawing in place.\n */\nexport function isolatesInnerShadows(node: SceneNode): boolean {\n if (isLayerContainer(node) || !castsFromOwnShape(node)) return false\n const shadows = node.effects.filter((effect) => effect.visible && effect.type === 'INNER_SHADOW')\n return (\n shadows.length > 0 &&\n shadows.every((effect) => !needsIsolatedBlendLayer(effect.blendMode)) &&\n [...node.fills, ...node.fillGeometry.flatMap((geometry) => geometry.fills ?? [])].every(\n (fill) => !fill.visible || !needsIsolatedBlendLayer(fill.blendMode)\n )\n )\n}\n\n/**\n * Draws a shape's own effects. Frames, groups, and other containers take their shadows from\n * `renderLayerShadows` instead, because Figma casts them from the children as well.\n */\nexport function renderEffects(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n graph: SceneGraph,\n pass: EffectPass\n): void {\n // Noise draws per pixel and a background blur reads back what is behind; both are left out\n // while the renderer keeps effects cheap.\n if (pass === 'front' && !r.effectsReduced) renderNoiseEffects(r, canvas, node)\n\n const ownShadows = !isLayerContainer(node)\n for (const effect of node.effects) {\n if (!effect.visible) continue\n\n if (pass === 'behind' && effect.type === 'DROP_SHADOW' && ownShadows) {\n renderDropShadow(r, canvas, graph, node, effect, false)\n }\n\n if (pass === 'behind' && effect.type === 'BACKGROUND_BLUR' && !r.effectsReduced) {\n const shape =\n node.type === 'BOOLEAN_OPERATION' ? makeBooleanOperationPath(r, node, graph) : null\n r.applyClippedBlur(canvas, node, blurSigma(effect.radius), shape)\n shape?.delete()\n }\n\n if (pass === 'inner' && effect.type === 'INNER_SHADOW' && ownShadows) {\n renderInnerShadow(r, canvas, graph, node, effect, false)\n }\n }\n}\n\n/**\n * Draws a container's drop shadows before it (`behind`) and its inner shadows over its fills,\n * strokes, and children (`front`), cast from the children too unless its own fill covers them.\n */\nexport function renderLayerShadows(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n pass: 'behind' | 'front'\n): void {\n if (!isLayerContainer(node)) return\n const effects = node.effects.filter(\n (effect): effect is ShadowEffect =>\n effect.visible && effect.type === (pass === 'behind' ? 'DROP_SHADOW' : 'INNER_SHADOW')\n )\n if (effects.length === 0) return\n const includeChildren = shadowIncludesChildren(graph, node)\n for (const effect of effects) {\n if (pass === 'behind') renderDropShadow(r, canvas, graph, node, effect, includeChildren)\n else renderInnerShadow(r, canvas, graph, node, effect, includeChildren)\n }\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAS,sBAAsB,GAAuB;CACpD,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,aAAa,EAAE,GAAG,UAAU,OAAO;AACxD;;;;;AASA,MAAM,iCAAiD,IAAI,IAAuB;CAChF;CACA;CACA;C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,QACJ,KAAK,SAAS,sBAAsB,yBAAyB,GAAG,MAAM,KAAK,IAAI;GACjF,EAAE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAAG,KAAK;GAChE,OAAO,OAAO;EAChB;EAEA,IAAI,SAAS,WAAW,OAAO,SAAS,kBAAkB,YACxD,kBAAkB,GAAG,QAAQ,OAAO,MAAM,QAAQ,KAAK;CAE3D;AACF;;;;;AAMA,SAAgB,mBACd,GACA,QACA,OACA,MACA,MACM;CACN,IAAI,CAAC,iBAAiB,IAAI,GAAG;CAC7B,MAAM,UAAU,KAAK,QAAQ,QAC1B,WACC,OAAO,WAAW,OAAO,UAAU,SAAS,WAAW,gBAAgB,eAC3E;CACA,IAAI,QAAQ,WAAW,GAAG;CAC1B,MAAM,kBAAkB,uBAAuB,OAAO,IAAI;CAC1D,KAAK,MAAM,UAAU,SACnB,IAAI,SAAS,UAAU,iBAAiB,GAAG,QAAQ,OAAO,MAAM,QAAQ,eAAe;MAClF,kBAAkB,GAAG,QAAQ,OAAO,MAAM,QAAQ,eAAe;AAE1E"}
|
|
@@ -2,7 +2,7 @@ import { InkSpan } from "./ink.js";
|
|
|
2
2
|
import { LaidOutGlyph } from "./placed.js";
|
|
3
3
|
import { PreparedText } from "./preparation/cache.js";
|
|
4
4
|
import { Canvas, CanvasKit, Paint } from "canvaskit-wasm";
|
|
5
|
-
import { DerivedTextGlyph, Fill, SceneNode, TextDecorationStyle } from "@pairdraw/scene-graph";
|
|
5
|
+
import { ColorProfile, DerivedTextGlyph, Fill, SceneNode, TextDecorationStyle } from "@pairdraw/scene-graph";
|
|
6
6
|
//#region src/canvas/text/decorations.d.ts
|
|
7
7
|
/** A glyph where it stands, as saved and freshly laid-out glyphs both give it. */
|
|
8
8
|
type PlacedGlyph = Pick<DerivedTextGlyph, 'x' | 'y' | 'firstCharacter' | 'advance' | 'scaleX'>;
|
|
@@ -47,7 +47,7 @@ type SavedDecorationCache = WeakMap<readonly DerivedTextGlyph[], {
|
|
|
47
47
|
* change the decorations of the same glyphs.
|
|
48
48
|
*/
|
|
49
49
|
declare function savedTextDecorationRects(cache: SavedDecorationCache, node: SceneNode, glyphs: readonly DerivedTextGlyph[], fontGeneration: number): TextDecorationRect[];
|
|
50
|
-
declare function drawTextLayout(ck: CanvasKit, canvas: Canvas, node: SceneNode, prepared: PreparedText, y: number, textPaint: Paint): void;
|
|
50
|
+
declare function drawTextLayout(ck: CanvasKit, canvas: Canvas, node: SceneNode, prepared: PreparedText, y: number, textPaint: Paint, space?: ColorProfile): void;
|
|
51
51
|
//#endregion
|
|
52
52
|
export { DecoratedGlyph, PlacedGlyph, SavedDecorationCache, TextDecorationRect, drawTextDecorations, drawTextLayout, hasDecoration, laidOutDecoratedGlyphs, savedDecoratedGlyphs, savedTextDecorationRects, textDecorationRects };
|
|
53
53
|
//# sourceMappingURL=decorations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorations.d.ts","names":[],"sources":["../../../src/canvas/text/decorations.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"decorations.d.ts","names":[],"sources":["../../../src/canvas/text/decorations.ts"],"mappings":";;;;;;;KAmCY,cAAc,KACxB;;UAKe,uBAAuB;EACtC,OAAO,aAAa,mBAAmB;;;UAYxB;;EAEf;EACA;EACA;EACA;EACA;EACA,OAAO;;EAEP,OAAO;;;iBAIO,cAAc,MAAM;;;;;;iBA4IpB,oBACd,MAAM,WACN,iBAAiB,mBAChB;;iBA4Ba,qBAAqB,iBAAiB,qBAAqB;;iBAQ3D,uBAAuB,iBAAiB,iBAAiB;;iBA8CzD,oBACd,IAAI,WACJ,QAAQ,QACR,gBAAgB,sBAChB,WAAW;;KAuBD,uBAAuB,iBACxB;EACP;EAAmB,OAAO;;;;;;;iBAQd,yBACd,OAAO,sBACP,MAAM,WACN,iBAAiB,oBACjB,yBACC;iBAyDa,eACd,IAAI,WACJ,QAAQ,QACR,MAAM,WACN,UAAU,cACV,WACA,WAAW,OACX,QAAO"}
|
|
@@ -5,8 +5,8 @@ import { drawKeycapFrame } from "./keycap.js";
|
|
|
5
5
|
import { styleRunColor } from "./paragraph/index.js";
|
|
6
6
|
import { laidOutGlyphs } from "./placed.js";
|
|
7
7
|
import { TEXT_STYLE_KEYS, characterStyles } from "../../text/character-style.js";
|
|
8
|
-
import { faceStyleKey } from "@pairdraw/scene-graph/font-style";
|
|
9
8
|
import { resolveRGBAForPreview } from "@pairdraw/scene-graph/color";
|
|
9
|
+
import { faceStyleKey } from "@pairdraw/scene-graph/font-style";
|
|
10
10
|
import { isEqual } from "es-toolkit/predicate";
|
|
11
11
|
//#region src/canvas/text/decorations.ts
|
|
12
12
|
/**
|
|
@@ -234,7 +234,7 @@ function savedTextDecorationRects(cache, node, glyphs, fontGeneration) {
|
|
|
234
234
|
* with the prepared text, which its cache replaces when an input of the text changes.
|
|
235
235
|
*/
|
|
236
236
|
/** The frames of the text's keycaps, which its layout leaves to be drawn, in their text's colour. */
|
|
237
|
-
function drawKeycapFrames(ck, canvas, node, layout, y, paint) {
|
|
237
|
+
function drawKeycapFrames(ck, canvas, node, layout, y, paint, space) {
|
|
238
238
|
const text = shownText(node);
|
|
239
239
|
if (!text.includes("⃣")) return;
|
|
240
240
|
const sourceIndexAt = /* @__PURE__ */ new Map();
|
|
@@ -250,17 +250,17 @@ function drawKeycapFrames(ck, canvas, node, layout, y, paint) {
|
|
|
250
250
|
if (character === void 0 || text[character] !== "⃣") continue;
|
|
251
251
|
const source = sourceIndexAt.get(character) ?? character;
|
|
252
252
|
const run = node.styleRuns.find((item) => source >= item.start && source < item.start + item.length);
|
|
253
|
-
runPaint.setColor(run ? styleRunColor(ck, run.style, paint.getColor()) : paint.getColor());
|
|
253
|
+
runPaint.setColor(run ? styleRunColor(ck, run.style, paint.getColor(), space) : paint.getColor());
|
|
254
254
|
drawKeycapFrame(ck, canvas, glyph.x, glyph.y, glyph.fontSize, runPaint);
|
|
255
255
|
}
|
|
256
256
|
} finally {
|
|
257
257
|
runPaint.delete();
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
function drawTextLayout(ck, canvas, node, prepared, y, textPaint) {
|
|
260
|
+
function drawTextLayout(ck, canvas, node, prepared, y, textPaint, space = "srgb") {
|
|
261
261
|
const layout = prepared.paragraph;
|
|
262
262
|
layout.draw(canvas, 0, y);
|
|
263
|
-
drawKeycapFrames(ck, canvas, node, layout, y, textPaint);
|
|
263
|
+
drawKeycapFrames(ck, canvas, node, layout, y, textPaint, space);
|
|
264
264
|
if (!hasDecoration(node)) return;
|
|
265
265
|
if (prepared.decorations?.y !== y) {
|
|
266
266
|
const glyphs = laidOutGlyphs(node, layout, shownText(node), y);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorations.js","names":[],"sources":["../../../src/canvas/text/decorations.ts"],"sourcesContent":["import type { Canvas, CanvasKit, Paint } from 'canvaskit-wasm'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type { DerivedTextGlyph, Fill, SceneNode, TextDecorationStyle } from '@pairdraw/scene-graph'\nimport { resolveRGBAForPreview } from '@pairdraw/scene-graph/color'\nimport { faceStyleKey } from '@pairdraw/scene-graph/font-style'\n\nimport { outlineInk, savedGlyphInk, type InkSpan } from '#core/canvas/text/ink'\nimport { COMBINING_KEYCAP, drawKeycapFrame } from '#core/canvas/text/keycap'\nimport type { TextLayout } from '#core/canvas/text/layout'\nimport { styleRunColor } from '#core/canvas/text/paragraph'\nimport { laidOutGlyphs, type LaidOutGlyph } from '#core/canvas/text/placed'\nimport type { PreparedText } from '#core/canvas/text/preparation/cache'\nimport { shownCharacters, shownText } from '#core/text/case'\nimport { characterStyles, TEXT_STYLE_KEYS, type CharacterStyle } from '#core/text/character-style'\nimport { fontDecorationMetricsSync, type FontDecorationMetrics } from '#core/text/font/glyphs'\n\n/**\n * Figma's Inter, measured from the decorations it saves, for text drawn without its font: its\n * glyphs come from the file, but the font's own metrics are not at hand.\n */\nconst UNLOADED_FONT_METRICS: FontDecorationMetrics = {\n underlineTop: 0.19887,\n underlineThickness: 0.06818,\n strikethroughTop: -0.32742,\n strikethroughThickness: 0.06818\n}\n\n/** A glyph where it stands, as saved and freshly laid-out glyphs both give it. */\nexport type PlacedGlyph = Pick<\n DerivedTextGlyph,\n 'x' | 'y' | 'firstCharacter' | 'advance' | 'scaleX'\n>\n\n/** A placed glyph that can tell where its ink crosses a band, when its outline is known. */\nexport interface DecoratedGlyph extends PlacedGlyph {\n ink?: (top: number, bottom: number) => InkSpan | null\n}\n\n/** Decorated characters on one line: its baseline, their extent, and the glyphs drawing them. */\ninterface LineSpan {\n baseline: number\n x1: number\n x2: number\n glyphs: { glyph: DecoratedGlyph; advance: number }[]\n}\n\n/** One underline or strikethrough on one line, as Figma saves it. */\nexport interface TextDecorationRect {\n /** The first character it decorates, by whose style Figma saves it. */\n firstCharacter: number\n x: number\n y: number\n width: number\n height: number\n style: TextDecorationStyle\n /** The decoration's own paints, or the text's when it has none. */\n fills: Fill[]\n}\n\n/** Whether any character of the text is underlined or struck through. */\nexport function hasDecoration(node: SceneNode): boolean {\n return (\n node.textDecoration !== 'NONE' ||\n node.styleRuns.some((run) => run.style.textDecoration && run.style.textDecoration !== 'NONE')\n )\n}\n\n/** Whether two characters' decorations are one line: Figma joins characters of one style. */\nfunction sameDecoration(a: CharacterStyle, b: CharacterStyle): boolean {\n return (\n a.textDecoration === b.textDecoration &&\n a.textDecorationStyle === b.textDecorationStyle &&\n a.textDecorationThickness === b.textDecorationThickness &&\n a.textUnderlineOffset === b.textUnderlineOffset &&\n a.fontFamily === b.fontFamily &&\n a.fontWeight === b.fontWeight &&\n a.italic === b.italic &&\n a.fontSize === b.fontSize &&\n isEqual(a.textDecorationFills, b.textDecorationFills) &&\n isEqual(a.fills, b.fills)\n )\n}\n\n/** A glyph's advance; one saved without it reaches the next glyph on its line. */\nfunction glyphAdvance(glyph: PlacedGlyph, next: PlacedGlyph | undefined): number {\n if (glyph.advance !== undefined) return glyph.advance * (glyph.scaleX ?? 1)\n return next?.y === glyph.y ? next.x - glyph.x : 0\n}\n\n/** Where the glyphs drawing `text[start, end)` sit, one span per line. */\nfunction lineSpans(\n glyphs: readonly DecoratedGlyph[],\n byCharacter: ReadonlyMap<number, number[]>,\n start: number,\n end: number\n): LineSpan[] {\n const lines = new Map<number, LineSpan>()\n for (let character = start; character < end; character++) {\n for (const index of byCharacter.get(character) ?? []) {\n const glyph = glyphs[index]\n const advance = glyphAdvance(glyph, glyphs.at(index + 1))\n const line = lines.get(glyph.y)\n if (line) {\n line.x1 = Math.min(line.x1, glyph.x)\n line.x2 = Math.max(line.x2, glyph.x + advance)\n line.glyphs.push({ glyph, advance })\n } else {\n lines.set(glyph.y, {\n baseline: glyph.y,\n x1: glyph.x,\n x2: glyph.x + advance,\n glyphs: [{ glyph, advance }]\n })\n }\n }\n }\n return [...lines.values()]\n}\n\n/**\n * Where an underline breaks for descenders, as Figma skips ink: around each glyph's ink in the\n * band the underline covers before its baseline is rounded, kept within the glyph's own box and\n * widened by `pad` on each side.\n */\nfunction inkGaps(line: LineSpan, top: number, height: number, pad: number): InkSpan[] {\n const bandTop = line.baseline + top\n const gaps: InkSpan[] = []\n for (const { glyph, advance } of line.glyphs) {\n const ink = glyph.ink?.(bandTop, bandTop + height)\n if (!ink) continue\n const left = Math.max(ink[0], glyph.x)\n const right = Math.min(ink[1], glyph.x + advance)\n if (right >= left) gaps.push([left - pad, right + pad])\n }\n return gaps.toSorted((a, b) => a[0] - b[0])\n}\n\n/** The parts of `[x1, x2]` outside every gap, but for pieces narrower than `minWidth`. */\nfunction withoutGaps(\n x1: number,\n x2: number,\n gaps: readonly InkSpan[],\n minWidth: number\n): InkSpan[] {\n const parts: InkSpan[] = []\n let from = x1\n for (const [left, right] of gaps) {\n if (left > from) parts.push([from, Math.min(left, x2)])\n from = Math.max(from, right)\n if (from >= x2) break\n }\n if (from < x2) parts.push([from, x2])\n if (gaps.length === 0) return parts\n return parts.filter(([left, right]) => right - left >= minWidth)\n}\n\nfunction decorationRects(\n style: CharacterStyle,\n firstCharacter: number,\n lines: LineSpan[]\n): TextDecorationRect[] {\n const metrics =\n fontDecorationMetricsSync(style.fontFamily, faceStyleKey(style)) ?? UNLOADED_FONT_METRICS\n const size = style.fontSize\n const underline = style.textDecoration === 'UNDERLINE'\n // Figma measures from the baseline rounded to a whole pixel. An underline's offset and\n // thickness replace the font's; a strikethrough always takes the font's, and is solid.\n const top = underline\n ? (style.textUnderlineOffset ?? metrics.underlineTop * size)\n : metrics.strikethroughTop * size\n const height = underline\n ? (style.textDecorationThickness ?? metrics.underlineThickness * size)\n : metrics.strikethroughThickness * size\n const fills = style.textDecorationFills.length > 0 ? style.textDecorationFills : style.fills\n const skipInk = underline && style.textDecorationSkipInk\n // Figma widens a solid underline's gaps by its thickness and drops the slivers they leave; a\n // dotted or wavy one's by 0.6 of it, keeping every piece (measured from 12px to 88px).\n const solid = !underline || style.textDecorationStyle === 'SOLID'\n const pad = solid ? height : height * 0.6\n const minWidth = solid ? height : 0\n return lines.flatMap((line) => {\n const gaps = skipInk ? inkGaps(line, top, height, pad) : []\n const parts = withoutGaps(line.x1, line.x2, gaps, minWidth)\n return parts.map(([x1, x2]) => ({\n firstCharacter,\n x: x1,\n y: Math.round(line.baseline) + top,\n width: x2 - x1,\n height,\n style: underline ? style.textDecorationStyle : 'SOLID',\n fills\n }))\n })\n}\n\n/**\n * The underlines and strikethroughs of a text over its glyphs, placed as Figma places them:\n * one per line for each run of characters decorated alike, from the font's metrics, with\n * underlines broken where descenders cross them.\n */\nexport function textDecorationRects(\n node: SceneNode,\n glyphs: readonly DecoratedGlyph[]\n): TextDecorationRect[] {\n if (!hasDecoration(node)) return []\n const text = node.text\n const styles = characterStyles(node, 0, text.length)\n const byCharacter = new Map<number, number[]>()\n for (const [index, glyph] of glyphs.entries()) {\n if (glyph.firstCharacter === undefined) continue\n const indices = byCharacter.get(glyph.firstCharacter)\n if (indices) indices.push(index)\n else byCharacter.set(glyph.firstCharacter, [index])\n }\n const rects: TextDecorationRect[] = []\n let start = 0\n while (start < text.length) {\n const style = styles[start]\n if (style.textDecoration === 'NONE' || text[start] === '\\n') {\n start++\n continue\n }\n let end = start + 1\n while (end < text.length && text[end] !== '\\n' && sameDecoration(styles[end], style)) end++\n rects.push(...decorationRects(style, start, lineSpans(glyphs, byCharacter, start, end)))\n start = end\n }\n return rects\n}\n\n/** Saved glyphs, whose ink comes from their saved outlines. */\nexport function savedDecoratedGlyphs(glyphs: readonly DerivedTextGlyph[]): DecoratedGlyph[] {\n return glyphs.map((glyph) => ({\n ...glyph,\n ink: (top, bottom) => savedGlyphInk(glyph.commandsBlob, glyph, top, bottom)\n }))\n}\n\n/** Laid-out glyphs, whose ink comes from their font when it drew them. */\nexport function laidOutDecoratedGlyphs(glyphs: readonly LaidOutGlyph[]): DecoratedGlyph[] {\n return glyphs.map((glyph) => ({\n x: glyph.x,\n y: glyph.y,\n firstCharacter: glyph.firstCharacter,\n advance: glyph.advance,\n ink: (top, bottom) => {\n const commands = glyph.source?.outline(glyph.id, glyph.fontSize)\n return commands ? outlineInk(commands, glyph.x, glyph.y, top, bottom) : null\n }\n }))\n}\n\nfunction solidColor(fills: Fill[]): Fill | undefined {\n return fills.find((fill) => fill.visible && fill.type === 'SOLID')\n}\n\nfunction drawDots(canvas: Canvas, rect: TextDecorationRect, paint: Paint) {\n const radius = rect.height / 2\n const y = rect.y + radius\n for (let x = rect.x + radius; x <= rect.x + rect.width - radius; x += rect.height * 2) {\n canvas.drawCircle(x, y, radius, paint)\n }\n}\n\nfunction drawWave(ck: CanvasKit, canvas: Canvas, rect: TextDecorationRect, paint: Paint) {\n // A cosine through the rect's middle that starts in a trough, as Figma draws it.\n const amplitude = rect.height / 2\n const period = rect.height * 3.5\n const y = rect.y + rect.height / 2\n const step = Math.max(0.25, period / 32)\n const path = new ck.PathBuilder()\n path.moveTo(rect.x, y + amplitude)\n for (let x = rect.x + step; x < rect.x + rect.width; x += step) {\n path.lineTo(x, y + amplitude * Math.cos(((x - rect.x) / period) * Math.PI * 2))\n }\n const end = rect.x + rect.width\n path.lineTo(end, y + amplitude * Math.cos(((end - rect.x) / period) * Math.PI * 2))\n const wave = path.detachAndDelete()\n paint.setStyle(ck.PaintStyle.Stroke)\n paint.setStrokeWidth((rect.height * 2) / 3)\n canvas.drawPath(wave, paint)\n wave.delete()\n}\n\n/** Draws decorations in their own paints, or in `textPaint` where the text's has no colour. */\nexport function drawTextDecorations(\n ck: CanvasKit,\n canvas: Canvas,\n rects: readonly TextDecorationRect[],\n textPaint: Paint\n): void {\n for (const rect of rects) {\n const fill = solidColor(rect.fills)\n const paint = textPaint.copy()\n try {\n paint.setAntiAlias(true)\n paint.setStyle(ck.PaintStyle.Fill)\n if (fill?.type === 'SOLID') {\n const { r: red, g, b, a } = resolveRGBAForPreview(fill.color).color\n paint.setShader(null)\n paint.setColor(ck.Color4f(red, g, b, a * fill.opacity))\n }\n if (rect.style === 'DOTTED') drawDots(canvas, rect, paint)\n else if (rect.style === 'WAVY') drawWave(ck, canvas, rect, paint)\n else canvas.drawRect(ck.XYWHRect(rect.x, rect.y, rect.width, rect.height), paint)\n } finally {\n paint.delete()\n }\n }\n}\n\n/** Decorations of saved glyphs, by the glyphs, with what they were found from. */\nexport type SavedDecorationCache = WeakMap<\n readonly DerivedTextGlyph[],\n { inputs: unknown[]; rects: TextDecorationRect[] }\n>\n\n/**\n * The decorations of text drawn from its saved glyphs. A change that moves or reshapes glyphs\n * replaces them, so only the character styles, and the fonts whose metrics place lines, can\n * change the decorations of the same glyphs.\n */\nexport function savedTextDecorationRects(\n cache: SavedDecorationCache,\n node: SceneNode,\n glyphs: readonly DerivedTextGlyph[],\n fontGeneration: number\n): TextDecorationRect[] {\n const inputs = [\n node.text,\n node.styleRuns,\n fontGeneration,\n ...TEXT_STYLE_KEYS.map((key) => node[key])\n ]\n const cached = cache.get(glyphs)\n if (cached?.inputs.every((value, index) => value === inputs[index])) return cached.rects\n const rects = textDecorationRects(node, savedDecoratedGlyphs(glyphs))\n cache.set(glyphs, { inputs, rects })\n return rects\n}\n\n/**\n * Draws laid-out text and its decorations, `y` below the node's top. The decorations are kept\n * with the prepared text, which its cache replaces when an input of the text changes.\n */\n/** The frames of the text's keycaps, which its layout leaves to be drawn, in their text's colour. */\nfunction drawKeycapFrames(\n ck: CanvasKit,\n canvas: Canvas,\n node: SceneNode,\n layout: TextLayout,\n y: number,\n paint: Paint\n): void {\n const text = shownText(node)\n if (!text.includes(COMBINING_KEYCAP)) return\n // Style runs index the source text, which a case such as `ß` to `SS` makes shorter.\n const sourceIndexAt = new Map<number, number>()\n let shownIndex = 0\n for (const { character, sourceIndex } of shownCharacters(node)) {\n sourceIndexAt.set(shownIndex, sourceIndex)\n shownIndex += character.length\n }\n const runPaint = paint.copy()\n try {\n for (const glyph of laidOutGlyphs(node, layout, text, y) ?? []) {\n const character = glyph.firstCharacter\n if (character === undefined || text[character] !== COMBINING_KEYCAP) continue\n // The frame takes the colour the paragraph gives its mark: its style run's, if it has one.\n const source = sourceIndexAt.get(character) ?? character\n const run = node.styleRuns.find(\n (item) => source >= item.start && source < item.start + item.length\n )\n runPaint.setColor(run ? styleRunColor(ck, run.style, paint.getColor()) : paint.getColor())\n drawKeycapFrame(ck, canvas, glyph.x, glyph.y, glyph.fontSize, runPaint)\n }\n } finally {\n runPaint.delete()\n }\n}\n\nexport function drawTextLayout(\n ck: CanvasKit,\n canvas: Canvas,\n node: SceneNode,\n prepared: PreparedText,\n y: number,\n textPaint: Paint\n): void {\n const layout = prepared.paragraph\n layout.draw(canvas, 0, y)\n drawKeycapFrames(ck, canvas, node, layout, y, textPaint)\n if (!hasDecoration(node)) return\n if (prepared.decorations?.y !== y) {\n const glyphs = laidOutGlyphs(node, layout, shownText(node), y)\n const rects = glyphs ? textDecorationRects(node, laidOutDecoratedGlyphs(glyphs)) : []\n prepared.decorations = { y, rects }\n }\n drawTextDecorations(ck, canvas, prepared.decorations.rects, textPaint)\n}\n"],"mappings":";;;;;;;;;;;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AM,GAAG,MAAM,GAAG,MAAM,UAAU,QAAQ;EACxE;CACF,UAAU;EACR,SAAS,OAAO;CAClB;AACF;AAEA,SAAgB,eACd,IACA,QACA,MACA,UACA,GACA,WACM;CACN,MAAM,SAAS,SAAS;CACxB,OAAO,KAAK,QAAQ,GAAG,CAAC;CACxB,iBAAiB,IAAI,QAAQ,MAAM,QAAQ,GAAG,SAAS;CACvD,IAAI,CAAC,cAAc,IAAI,GAAG;CAC1B,IAAI,SAAS,aAAa,MAAM,GAAG;EACjC,MAAM,SAAS,cAAc,MAAM,QAAQ,UAAU,IAAI,GAAG,CAAC;EAE7D,SAAS,cAAc;GAAE;GAAG,OADd,SAAS,oBAAoB,MAAM,uBAAuB,MAAM,CAAC,IAAI,CAAC;EAClD;CACpC;CACA,oBAAoB,IAAI,QAAQ,SAAS,YAAY,OAAO,SAAS;AACvE"}
|
|
1
|
+
{"version":3,"file":"decorations.js","names":[],"sources":["../../../src/canvas/text/decorations.ts"],"sourcesContent":["import type { Canvas, CanvasKit, Paint } from 'canvaskit-wasm'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type {\n ColorProfile,\n DerivedTextGlyph,\n Fill,\n SceneNode,\n TextDecorationStyle\n} from '@pairdraw/scene-graph'\nimport { resolveRGBAForPreview } from '@pairdraw/scene-graph/color'\nimport { faceStyleKey } from '@pairdraw/scene-graph/font-style'\n\nimport { outlineInk, savedGlyphInk, type InkSpan } from '#core/canvas/text/ink'\nimport { COMBINING_KEYCAP, drawKeycapFrame } from '#core/canvas/text/keycap'\nimport type { TextLayout } from '#core/canvas/text/layout'\nimport { styleRunColor } from '#core/canvas/text/paragraph'\nimport { laidOutGlyphs, type LaidOutGlyph } from '#core/canvas/text/placed'\nimport type { PreparedText } from '#core/canvas/text/preparation/cache'\nimport { shownCharacters, shownText } from '#core/text/case'\nimport { characterStyles, TEXT_STYLE_KEYS, type CharacterStyle } from '#core/text/character-style'\nimport { fontDecorationMetricsSync, type FontDecorationMetrics } from '#core/text/font/glyphs'\n\n/**\n * Figma's Inter, measured from the decorations it saves, for text drawn without its font: its\n * glyphs come from the file, but the font's own metrics are not at hand.\n */\nconst UNLOADED_FONT_METRICS: FontDecorationMetrics = {\n underlineTop: 0.19887,\n underlineThickness: 0.06818,\n strikethroughTop: -0.32742,\n strikethroughThickness: 0.06818\n}\n\n/** A glyph where it stands, as saved and freshly laid-out glyphs both give it. */\nexport type PlacedGlyph = Pick<\n DerivedTextGlyph,\n 'x' | 'y' | 'firstCharacter' | 'advance' | 'scaleX'\n>\n\n/** A placed glyph that can tell where its ink crosses a band, when its outline is known. */\nexport interface DecoratedGlyph extends PlacedGlyph {\n ink?: (top: number, bottom: number) => InkSpan | null\n}\n\n/** Decorated characters on one line: its baseline, their extent, and the glyphs drawing them. */\ninterface LineSpan {\n baseline: number\n x1: number\n x2: number\n glyphs: { glyph: DecoratedGlyph; advance: number }[]\n}\n\n/** One underline or strikethrough on one line, as Figma saves it. */\nexport interface TextDecorationRect {\n /** The first character it decorates, by whose style Figma saves it. */\n firstCharacter: number\n x: number\n y: number\n width: number\n height: number\n style: TextDecorationStyle\n /** The decoration's own paints, or the text's when it has none. */\n fills: Fill[]\n}\n\n/** Whether any character of the text is underlined or struck through. */\nexport function hasDecoration(node: SceneNode): boolean {\n return (\n node.textDecoration !== 'NONE' ||\n node.styleRuns.some((run) => run.style.textDecoration && run.style.textDecoration !== 'NONE')\n )\n}\n\n/** Whether two characters' decorations are one line: Figma joins characters of one style. */\nfunction sameDecoration(a: CharacterStyle, b: CharacterStyle): boolean {\n return (\n a.textDecoration === b.textDecoration &&\n a.textDecorationStyle === b.textDecorationStyle &&\n a.textDecorationThickness === b.textDecorationThickness &&\n a.textUnderlineOffset === b.textUnderlineOffset &&\n a.fontFamily === b.fontFamily &&\n a.fontWeight === b.fontWeight &&\n a.italic === b.italic &&\n a.fontSize === b.fontSize &&\n isEqual(a.textDecorationFills, b.textDecorationFills) &&\n isEqual(a.fills, b.fills)\n )\n}\n\n/** A glyph's advance; one saved without it reaches the next glyph on its line. */\nfunction glyphAdvance(glyph: PlacedGlyph, next: PlacedGlyph | undefined): number {\n if (glyph.advance !== undefined) return glyph.advance * (glyph.scaleX ?? 1)\n return next?.y === glyph.y ? next.x - glyph.x : 0\n}\n\n/** Where the glyphs drawing `text[start, end)` sit, one span per line. */\nfunction lineSpans(\n glyphs: readonly DecoratedGlyph[],\n byCharacter: ReadonlyMap<number, number[]>,\n start: number,\n end: number\n): LineSpan[] {\n const lines = new Map<number, LineSpan>()\n for (let character = start; character < end; character++) {\n for (const index of byCharacter.get(character) ?? []) {\n const glyph = glyphs[index]\n const advance = glyphAdvance(glyph, glyphs.at(index + 1))\n const line = lines.get(glyph.y)\n if (line) {\n line.x1 = Math.min(line.x1, glyph.x)\n line.x2 = Math.max(line.x2, glyph.x + advance)\n line.glyphs.push({ glyph, advance })\n } else {\n lines.set(glyph.y, {\n baseline: glyph.y,\n x1: glyph.x,\n x2: glyph.x + advance,\n glyphs: [{ glyph, advance }]\n })\n }\n }\n }\n return [...lines.values()]\n}\n\n/**\n * Where an underline breaks for descenders, as Figma skips ink: around each glyph's ink in the\n * band the underline covers before its baseline is rounded, kept within the glyph's own box and\n * widened by `pad` on each side.\n */\nfunction inkGaps(line: LineSpan, top: number, height: number, pad: number): InkSpan[] {\n const bandTop = line.baseline + top\n const gaps: InkSpan[] = []\n for (const { glyph, advance } of line.glyphs) {\n const ink = glyph.ink?.(bandTop, bandTop + height)\n if (!ink) continue\n const left = Math.max(ink[0], glyph.x)\n const right = Math.min(ink[1], glyph.x + advance)\n if (right >= left) gaps.push([left - pad, right + pad])\n }\n return gaps.toSorted((a, b) => a[0] - b[0])\n}\n\n/** The parts of `[x1, x2]` outside every gap, but for pieces narrower than `minWidth`. */\nfunction withoutGaps(\n x1: number,\n x2: number,\n gaps: readonly InkSpan[],\n minWidth: number\n): InkSpan[] {\n const parts: InkSpan[] = []\n let from = x1\n for (const [left, right] of gaps) {\n if (left > from) parts.push([from, Math.min(left, x2)])\n from = Math.max(from, right)\n if (from >= x2) break\n }\n if (from < x2) parts.push([from, x2])\n if (gaps.length === 0) return parts\n return parts.filter(([left, right]) => right - left >= minWidth)\n}\n\nfunction decorationRects(\n style: CharacterStyle,\n firstCharacter: number,\n lines: LineSpan[]\n): TextDecorationRect[] {\n const metrics =\n fontDecorationMetricsSync(style.fontFamily, faceStyleKey(style)) ?? UNLOADED_FONT_METRICS\n const size = style.fontSize\n const underline = style.textDecoration === 'UNDERLINE'\n // Figma measures from the baseline rounded to a whole pixel. An underline's offset and\n // thickness replace the font's; a strikethrough always takes the font's, and is solid.\n const top = underline\n ? (style.textUnderlineOffset ?? metrics.underlineTop * size)\n : metrics.strikethroughTop * size\n const height = underline\n ? (style.textDecorationThickness ?? metrics.underlineThickness * size)\n : metrics.strikethroughThickness * size\n const fills = style.textDecorationFills.length > 0 ? style.textDecorationFills : style.fills\n const skipInk = underline && style.textDecorationSkipInk\n // Figma widens a solid underline's gaps by its thickness and drops the slivers they leave; a\n // dotted or wavy one's by 0.6 of it, keeping every piece (measured from 12px to 88px).\n const solid = !underline || style.textDecorationStyle === 'SOLID'\n const pad = solid ? height : height * 0.6\n const minWidth = solid ? height : 0\n return lines.flatMap((line) => {\n const gaps = skipInk ? inkGaps(line, top, height, pad) : []\n const parts = withoutGaps(line.x1, line.x2, gaps, minWidth)\n return parts.map(([x1, x2]) => ({\n firstCharacter,\n x: x1,\n y: Math.round(line.baseline) + top,\n width: x2 - x1,\n height,\n style: underline ? style.textDecorationStyle : 'SOLID',\n fills\n }))\n })\n}\n\n/**\n * The underlines and strikethroughs of a text over its glyphs, placed as Figma places them:\n * one per line for each run of characters decorated alike, from the font's metrics, with\n * underlines broken where descenders cross them.\n */\nexport function textDecorationRects(\n node: SceneNode,\n glyphs: readonly DecoratedGlyph[]\n): TextDecorationRect[] {\n if (!hasDecoration(node)) return []\n const text = node.text\n const styles = characterStyles(node, 0, text.length)\n const byCharacter = new Map<number, number[]>()\n for (const [index, glyph] of glyphs.entries()) {\n if (glyph.firstCharacter === undefined) continue\n const indices = byCharacter.get(glyph.firstCharacter)\n if (indices) indices.push(index)\n else byCharacter.set(glyph.firstCharacter, [index])\n }\n const rects: TextDecorationRect[] = []\n let start = 0\n while (start < text.length) {\n const style = styles[start]\n if (style.textDecoration === 'NONE' || text[start] === '\\n') {\n start++\n continue\n }\n let end = start + 1\n while (end < text.length && text[end] !== '\\n' && sameDecoration(styles[end], style)) end++\n rects.push(...decorationRects(style, start, lineSpans(glyphs, byCharacter, start, end)))\n start = end\n }\n return rects\n}\n\n/** Saved glyphs, whose ink comes from their saved outlines. */\nexport function savedDecoratedGlyphs(glyphs: readonly DerivedTextGlyph[]): DecoratedGlyph[] {\n return glyphs.map((glyph) => ({\n ...glyph,\n ink: (top, bottom) => savedGlyphInk(glyph.commandsBlob, glyph, top, bottom)\n }))\n}\n\n/** Laid-out glyphs, whose ink comes from their font when it drew them. */\nexport function laidOutDecoratedGlyphs(glyphs: readonly LaidOutGlyph[]): DecoratedGlyph[] {\n return glyphs.map((glyph) => ({\n x: glyph.x,\n y: glyph.y,\n firstCharacter: glyph.firstCharacter,\n advance: glyph.advance,\n ink: (top, bottom) => {\n const commands = glyph.source?.outline(glyph.id, glyph.fontSize)\n return commands ? outlineInk(commands, glyph.x, glyph.y, top, bottom) : null\n }\n }))\n}\n\nfunction solidColor(fills: Fill[]): Fill | undefined {\n return fills.find((fill) => fill.visible && fill.type === 'SOLID')\n}\n\nfunction drawDots(canvas: Canvas, rect: TextDecorationRect, paint: Paint) {\n const radius = rect.height / 2\n const y = rect.y + radius\n for (let x = rect.x + radius; x <= rect.x + rect.width - radius; x += rect.height * 2) {\n canvas.drawCircle(x, y, radius, paint)\n }\n}\n\nfunction drawWave(ck: CanvasKit, canvas: Canvas, rect: TextDecorationRect, paint: Paint) {\n // A cosine through the rect's middle that starts in a trough, as Figma draws it.\n const amplitude = rect.height / 2\n const period = rect.height * 3.5\n const y = rect.y + rect.height / 2\n const step = Math.max(0.25, period / 32)\n const path = new ck.PathBuilder()\n path.moveTo(rect.x, y + amplitude)\n for (let x = rect.x + step; x < rect.x + rect.width; x += step) {\n path.lineTo(x, y + amplitude * Math.cos(((x - rect.x) / period) * Math.PI * 2))\n }\n const end = rect.x + rect.width\n path.lineTo(end, y + amplitude * Math.cos(((end - rect.x) / period) * Math.PI * 2))\n const wave = path.detachAndDelete()\n paint.setStyle(ck.PaintStyle.Stroke)\n paint.setStrokeWidth((rect.height * 2) / 3)\n canvas.drawPath(wave, paint)\n wave.delete()\n}\n\n/** Draws decorations in their own paints, or in `textPaint` where the text's has no colour. */\nexport function drawTextDecorations(\n ck: CanvasKit,\n canvas: Canvas,\n rects: readonly TextDecorationRect[],\n textPaint: Paint\n): void {\n for (const rect of rects) {\n const fill = solidColor(rect.fills)\n const paint = textPaint.copy()\n try {\n paint.setAntiAlias(true)\n paint.setStyle(ck.PaintStyle.Fill)\n if (fill?.type === 'SOLID') {\n const { r: red, g, b, a } = resolveRGBAForPreview(fill.color).color\n paint.setShader(null)\n paint.setColor(ck.Color4f(red, g, b, a * fill.opacity))\n }\n if (rect.style === 'DOTTED') drawDots(canvas, rect, paint)\n else if (rect.style === 'WAVY') drawWave(ck, canvas, rect, paint)\n else canvas.drawRect(ck.XYWHRect(rect.x, rect.y, rect.width, rect.height), paint)\n } finally {\n paint.delete()\n }\n }\n}\n\n/** Decorations of saved glyphs, by the glyphs, with what they were found from. */\nexport type SavedDecorationCache = WeakMap<\n readonly DerivedTextGlyph[],\n { inputs: unknown[]; rects: TextDecorationRect[] }\n>\n\n/**\n * The decorations of text drawn from its saved glyphs. A change that moves or reshapes glyphs\n * replaces them, so only the character styles, and the fonts whose metrics place lines, can\n * change the decorations of the same glyphs.\n */\nexport function savedTextDecorationRects(\n cache: SavedDecorationCache,\n node: SceneNode,\n glyphs: readonly DerivedTextGlyph[],\n fontGeneration: number\n): TextDecorationRect[] {\n const inputs = [\n node.text,\n node.styleRuns,\n fontGeneration,\n ...TEXT_STYLE_KEYS.map((key) => node[key])\n ]\n const cached = cache.get(glyphs)\n if (cached?.inputs.every((value, index) => value === inputs[index])) return cached.rects\n const rects = textDecorationRects(node, savedDecoratedGlyphs(glyphs))\n cache.set(glyphs, { inputs, rects })\n return rects\n}\n\n/**\n * Draws laid-out text and its decorations, `y` below the node's top. The decorations are kept\n * with the prepared text, which its cache replaces when an input of the text changes.\n */\n/** The frames of the text's keycaps, which its layout leaves to be drawn, in their text's colour. */\nfunction drawKeycapFrames(\n ck: CanvasKit,\n canvas: Canvas,\n node: SceneNode,\n layout: TextLayout,\n y: number,\n paint: Paint,\n space: ColorProfile\n): void {\n const text = shownText(node)\n if (!text.includes(COMBINING_KEYCAP)) return\n // Style runs index the source text, which a case such as `ß` to `SS` makes shorter.\n const sourceIndexAt = new Map<number, number>()\n let shownIndex = 0\n for (const { character, sourceIndex } of shownCharacters(node)) {\n sourceIndexAt.set(shownIndex, sourceIndex)\n shownIndex += character.length\n }\n const runPaint = paint.copy()\n try {\n for (const glyph of laidOutGlyphs(node, layout, text, y) ?? []) {\n const character = glyph.firstCharacter\n if (character === undefined || text[character] !== COMBINING_KEYCAP) continue\n // The frame takes the colour the paragraph gives its mark: its style run's, if it has one.\n const source = sourceIndexAt.get(character) ?? character\n const run = node.styleRuns.find(\n (item) => source >= item.start && source < item.start + item.length\n )\n runPaint.setColor(\n run ? styleRunColor(ck, run.style, paint.getColor(), space) : paint.getColor()\n )\n drawKeycapFrame(ck, canvas, glyph.x, glyph.y, glyph.fontSize, runPaint)\n }\n } finally {\n runPaint.delete()\n }\n}\n\nexport function drawTextLayout(\n ck: CanvasKit,\n canvas: Canvas,\n node: SceneNode,\n prepared: PreparedText,\n y: number,\n textPaint: Paint,\n space: ColorProfile = 'srgb'\n): void {\n const layout = prepared.paragraph\n layout.draw(canvas, 0, y)\n drawKeycapFrames(ck, canvas, node, layout, y, textPaint, space)\n if (!hasDecoration(node)) return\n if (prepared.decorations?.y !== y) {\n const glyphs = laidOutGlyphs(node, layout, shownText(node), y)\n const rects = glyphs ? textDecorationRects(node, laidOutDecoratedGlyphs(glyphs)) : []\n prepared.decorations = { y, rects }\n }\n drawTextDecorations(ck, canvas, prepared.decorations.rects, textPaint)\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAM,wBAA+C;CACnD,cAAc;CACd,oBAAoB;CACpB,kBAAkB;CAClB,wBAAwB;AAC1B;;AAmCA,SAAgB,cAAc,MAA0B;CACtD,OACE,KAAK,mBAAmB,UACxB,KAAK,UAAU,MAAM,QAAQ,IAAI,MAAM,kBAAkB,IAAI,MAAM,mBAAmB,MAAM;AAEhG;;AAGA,SAAS,eAAe,GAAmB,GAA4B;CACrE,OACE,EAAE,mBAAmB,EAAE,kBACvB,EAAE,wBAAwB,EAAE,uBAC5B,EAAE,4BAA4B,EAAE,2BAChC,EAAE,wBAAwB,EAAE,uBAC5B,EAAE,eAAe,EAAE,cACnB,EAAE,eAAe,EAAE,cACnB,EAAE,WAAW,EAAE,UACf,EAAE,aAAa,EAAE,YACjB,QAAQ,EAAE,qBAAqB,EAAE,mBAAmB,KACpD,QAAQ,EAAE,OAAO,EAAE,KAAK;AAE5B;;AAGA,SAAS,aAAa,OAAoB,MAAuC;CAC/E,IAAI,MAAM,YAAY,KAAA,GAAW,OAAO,MAAM,WAAW,MAAM,UAAU;CACzE,OAAO,MAAM,MAAM,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI;AAClD;;AAGA,SAAS,UACP,QACA,aACA,OACA,KACY;CACZ,MAAM,wBAAQ,IAAI,IAAsB;CACxC,KAAK,IAAI,YAAY,OAAO,YAAY,KAAK,aAC3C,KAAK,MAAM,SAAS,YAAY,IAAI,SAAS,KAAK,CAAC,GAAG;EACpD,MAAM,QAAQ,OAAO;EACrB,MAAM,UAAU,aAAa,OAAO,OAAO,GAAG,QAAQ,CAAC,CAAC;EACxD,MAAM,OAAO,MAAM,IAAI,MAAM,CAAC;EAC9B,IAAI,MAAM;GACR,KAAK,KAAK,KAAK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,KAAK,SAAS,SAAS,KAAK,QAAQ,KAAK,MAC/D;GACA,SAAS,SACP,MAAM,cAAc,IAAI,IAAI,OAAO,MAAM,SAAS,GAAG,KAAK,IAAI,MAAM,SAAS,CAC/E;GACA,gBAAgB,IAAI,QAAQ,MAAM,GAAG,MAAM,GAAG,MAAM,UAAU,QAAQ;EACxE;CACF,UAAU;EACR,SAAS,OAAO;CAClB;AACF;AAEA,SAAgB,eACd,IACA,QACA,MACA,UACA,GACA,WACA,QAAsB,QAChB;CACN,MAAM,SAAS,SAAS;CACxB,OAAO,KAAK,QAAQ,GAAG,CAAC;CACxB,iBAAiB,IAAI,QAAQ,MAAM,QAAQ,GAAG,WAAW,KAAK;CAC9D,IAAI,CAAC,cAAc,IAAI,GAAG;CAC1B,IAAI,SAAS,aAAa,MAAM,GAAG;EACjC,MAAM,SAAS,cAAc,MAAM,QAAQ,UAAU,IAAI,GAAG,CAAC;EAE7D,SAAS,cAAc;GAAE;GAAG,OADd,SAAS,oBAAoB,MAAM,uBAAuB,MAAM,CAAC,IAAI,CAAC;EAClD;CACpC;CACA,oBAAoB,IAAI,QAAQ,SAAS,YAAY,OAAO,SAAS;AACvE"}
|
|
@@ -150,7 +150,7 @@ function buildTextPicture(r, node) {
|
|
|
150
150
|
const layout = buildParagraph(r, node);
|
|
151
151
|
const paint = new ck.Paint();
|
|
152
152
|
try {
|
|
153
|
-
drawTextLayout(ck, recCanvas, node, { paragraph: layout }, 0, paint);
|
|
153
|
+
drawTextLayout(ck, recCanvas, node, { paragraph: layout }, 0, paint, r.documentColorSpace ?? "srgb");
|
|
154
154
|
} finally {
|
|
155
155
|
paint.delete();
|
|
156
156
|
layout.delete();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/canvas/text/index.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport { DEFAULT_FONT_FAMILY } from '#core/constants'\nimport { shownCharacters, shownText } from '#core/text/case'\nimport { fontManager } from '#core/text/font/manager'\nimport { textFontFace } from '#core/text/requirements/collect'\nimport {\n fontCoverageDemand,\n fontFaceDemand,\n fontRemoteCoverageDemand,\n fontResolver,\n missingGlyphOccurrences,\n missingGlyphsByScript\n} from '#core/text/resolver'\n\nimport { drawTextLayout } from './decorations'\nimport { buildParagraph } from './layout/build'\nimport { resolveParagraphLayoutWidth } from './paragraph'\nimport { withPreparedText } from './preparation'\nimport type { FontReadinessRenderer, TextRenderer } from './renderer'\n\nexport { buildParagraph } from './layout/build'\nexport type { TextLayout } from './layout'\nexport type { ParagraphBuildOptions } from './paint'\nexport { textFontFeatures, textFontVariations, textHeightBehaviorValue } from './paragraph'\nexport { withTextParagraph } from './preparation'\n\nfunction demandFace(\n r: FontReadinessRenderer,\n node: SceneNode,\n family: string,\n style: string\n): boolean {\n if (fontManager.isStyleLoaded(family, style)) return true\n const demand = fontFaceDemand(family, style, node.text)\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return false\n}\n\nfunction requiredNodeFaces(node: SceneNode): Array<{ family: string; style: string }> {\n const baseFamily = node.fontFamily || DEFAULT_FONT_FAMILY\n const faces = new Map<string, { family: string; style: string }>()\n const add = (family: string, style: string) => faces.set(`${family}\\0${style}`, { family, style })\n add(baseFamily, textFontFace(node).style)\n for (const run of node.styleRuns) {\n add(run.style.fontFamily ?? baseFamily, textFontFace(node, run.style).style)\n }\n return Array.from(faces.values())\n}\n\nfunction languageForCharacter(node: SceneNode, sourceIndex: number): string | null {\n const run = node.styleRuns.find(\n (item) => sourceIndex >= item.start && sourceIndex < item.start + item.length\n )\n return run?.style.textLanguage !== undefined ? run.style.textLanguage : node.textLanguage\n}\n\nfunction transformedSourceOffsets(node: SceneNode): number[] {\n return shownCharacters(node).map((shown) => shown.sourceIndex)\n}\n\nexport type NodeFontReadiness = 'ready' | 'substituted' | 'pending' | 'exhausted'\n\nfunction requiredFacesReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n let pending = false\n let exhausted = false\n for (const { family, style } of requiredNodeFaces(node)) {\n if (fontManager.isStyleLoaded(family, style)) continue\n const demand = fontFaceDemand(family, style, node.text)\n const state = fontResolver.state(demand).state\n demandFace(r, node, family, style)\n if (state === 'failed' || state === 'exhausted') {\n // A missing face is drawn in another loaded face of the family, as Figma draws it, and\n // reported missing; the text stays visible when an exact face (Italic) is unavailable.\n if (fontManager.isLoaded(family)) continue\n exhausted = true\n } else {\n pending = true\n }\n }\n if (pending) return 'pending'\n if (exhausted && fontManager.isStyleLoaded(DEFAULT_FONT_FAMILY, 'Regular')) return 'substituted'\n return exhausted ? 'exhausted' : 'ready'\n}\n\nfunction demandRemoteCoverage(r: TextRenderer, node: SceneNode, characters: string[]): boolean {\n for (const { family, style } of requiredNodeFaces(node)) {\n if (!fontManager.remoteStyleNeedsCoverage(family, style, characters)) continue\n const demand = fontRemoteCoverageDemand(family, style, characters)\n const state = fontResolver.state(demand).state\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return true\n }\n if (state === 'loading') return true\n if (state === 'loaded') fontResolver.exhaust(demand)\n }\n return false\n}\n\nfunction observedGlyphReadiness(r: TextRenderer, node: SceneNode): NodeFontReadiness {\n if (\n r.fontProvider &&\n r.textPreparationCache?.hasGlyphCoverage(node, fontManager.generation(), r.fontProvider)\n )\n return 'ready'\n\n const missingOccurrences = withPreparedText(\n r,\n node,\n 'coverage',\n () => buildParagraph(r, node),\n (prepared) => {\n if (!prepared.missingGlyphs) {\n prepared.paragraph.layout(resolveParagraphLayoutWidth(node))\n prepared.missingGlyphs = missingGlyphOccurrences(\n shownText(node),\n prepared.paragraph.getShapedLines(),\n transformedSourceOffsets(node)\n )\n }\n return prepared.missingGlyphs\n }\n )\n if (missingOccurrences.length === 0) {\n r.textPreparationCache?.recordGlyphCoverage(node)\n return 'ready'\n }\n\n const charactersByScript = missingGlyphsByScript(missingOccurrences, (offset) =>\n languageForCharacter(node, offset)\n )\n\n let pending = false\n let exhausted = charactersByScript.size === 0\n for (const [script, characters] of charactersByScript) {\n if (demandRemoteCoverage(r, node, characters)) {\n pending = true\n continue\n }\n\n const demand = fontCoverageDemand(script, characters)\n const state = fontResolver.state(demand).state\n if (state === 'loaded') {\n fontResolver.exhaust(demand)\n exhausted = true\n continue\n }\n if (state === 'exhausted' || state === 'failed') {\n exhausted = true\n continue\n }\n pending = true\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n }\n }\n // An export draws once: a face that has not arrived by then is not coming, and the characters\n // it would have covered keep the text's own fonts rather than leaving the layer blank.\n if (pending) return r.exportFontsSettled ? 'substituted' : 'pending'\n // Once no fallback is left for a character, the text draws with the fonts it has, the font's\n // missing-glyph box standing in for that character, rather than not at all.\n return exhausted ? 'substituted' : 'ready'\n}\n\nfunction canObserveGlyphCoverage(r: FontReadinessRenderer): r is TextRenderer {\n return r.ck !== undefined && r.fontProvider != null && r.fontsLoaded !== undefined\n}\n\nexport function nodeFontReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n if (node.type !== 'TEXT') return 'ready'\n const faces = requiredFacesReadiness(r, node)\n if (faces === 'pending' || faces === 'exhausted') return faces\n if (!node.text || !canObserveGlyphCoverage(r)) return faces\n const glyphs = observedGlyphReadiness(r, node)\n // Substituted text still needs script fallbacks (for example CJK) for glyphs the substitute\n // lacks, but stays visible when none can be found.\n if (faces === 'substituted') return glyphs === 'pending' ? 'pending' : 'substituted'\n return glyphs\n}\n\nexport function isNodeFontLoaded(r: FontReadinessRenderer, node: SceneNode): boolean {\n const readiness = nodeFontReadiness(r, node)\n return readiness === 'ready' || readiness === 'substituted'\n}\n\nexport function measureTextNode(\n r: TextRenderer,\n node: SceneNode,\n maxWidth?: number\n): { width: number; height: number } | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const layoutWidth = resolveParagraphLayoutWidth(node, maxWidth)\n const measure = () => {\n const paragraph = buildParagraph(r, node)\n paragraph.layout(layoutWidth)\n const width = paragraph.getLongestLine()\n const height = paragraph.getHeight()\n paragraph.delete()\n return { width: Math.ceil(width), height: Math.ceil(height) }\n }\n // Layout asks for the same text at the same width many times per pass.\n return r.textPreparationCache\n ? r.textPreparationCache.measure(\n node,\n layoutWidth,\n fontManager.generation(),\n r.fontProvider,\n measure\n )\n : measure()\n}\n\nexport function buildTextPicture(r: TextRenderer, node: SceneNode): Uint8Array | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const ck = r.ck\n const recorder = new ck.PictureRecorder()\n const bounds = ck.LTRBRect(0, 0, node.width || 1e6, node.height || 1e6)\n const recCanvas = recorder.beginRecording(bounds)\n\n const layout = buildParagraph(r, node)\n const paint = new ck.Paint()\n try {\n drawTextLayout(ck, recCanvas, node, { paragraph: layout }, 0, paint)\n } finally {\n paint.delete()\n layout.delete()\n }\n\n const picture = recorder.finishRecordingAsPicture()\n recorder.delete()\n\n const bytes = picture.serialize()\n picture.delete()\n return bytes ?? null\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAS,WACP,GACA,MACA,QACA,OACS;CACT,IAAI,YAAY,cAAc,QAAQ,KAAK,GAAG,OAAO;CACrD,MAAM,SAAS,eAAe,QAAQ,OAAO,KAAK,IAAI;CACtD,EAAE,kBAAkB,MAAM,OAAO,GAAG;CACpC,aAAkB,cAAc,QAAQ,KAAK,IAAI,EAAE,uBAAuB;CAC1E,OAAO;AACT;AAEA,SAAS,kBAAkB,MAA2D;CACpF,MAAM,aAAa,KAAK,cAAA;CACxB,MAAM,wBAAQ,IAAI,IAA+C;CACjE,MAAM,OAAO,QAAgB,UAAkB,MAAM,IAAI,GAAG,OAAO,IAAI,SAAS;EAAE;EAAQ;CAAM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CAC9D;CAEA,OAAO,EAAE,uBACL,EAAE,qBAAqB,QACrB,MACA,aACA,YAAY,WAAW,GACvB,EAAE,cACF,OACF,IACA,QAAQ;AACd;AAEA,SAAgB,iBAAiB,GAAiB,MAAoC;CACpF,IAAI,CAAC,EAAE,eAAe,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,IAAI,GAAG,OAAO;CAC5E,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,MAAM,OAAO;CAE/C,MAAM,KAAK,EAAE;CACb,MAAM,WAAW,IAAI,GAAG,gBAAgB;CACxC,MAAM,SAAS,GAAG,SAAS,GAAG,GAAG,KAAK,SAAS,KAAK,KAAK,UAAU,GAAG;CACtE,MAAM,YAAY,SAAS,eAAe,MAAM;CAEhD,MAAM,SAAS,eAAe,GAAG,IAAI;CACrC,MAAM,QAAQ,IAAI,GAAG,MAAM;CAC3B,IAAI;EACF,eAAe,IAAI,WAAW,MAAM,EAAE,WAAW,OAAO,GAAG,GAAG,KAAK;CACrE,UAAU;EACR,MAAM,OAAO;EACb,OAAO,OAAO;CAChB;CAEA,MAAM,UAAU,SAAS,yBAAyB;CAClD,SAAS,OAAO;CAEhB,MAAM,QAAQ,QAAQ,UAAU;CAChC,QAAQ,OAAO;CACf,OAAO,SAAS;AAClB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/canvas/text/index.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport { DEFAULT_FONT_FAMILY } from '#core/constants'\nimport { shownCharacters, shownText } from '#core/text/case'\nimport { fontManager } from '#core/text/font/manager'\nimport { textFontFace } from '#core/text/requirements/collect'\nimport {\n fontCoverageDemand,\n fontFaceDemand,\n fontRemoteCoverageDemand,\n fontResolver,\n missingGlyphOccurrences,\n missingGlyphsByScript\n} from '#core/text/resolver'\n\nimport { drawTextLayout } from './decorations'\nimport { buildParagraph } from './layout/build'\nimport { resolveParagraphLayoutWidth } from './paragraph'\nimport { withPreparedText } from './preparation'\nimport type { FontReadinessRenderer, TextRenderer } from './renderer'\n\nexport { buildParagraph } from './layout/build'\nexport type { TextLayout } from './layout'\nexport type { ParagraphBuildOptions } from './paint'\nexport { textFontFeatures, textFontVariations, textHeightBehaviorValue } from './paragraph'\nexport { withTextParagraph } from './preparation'\n\nfunction demandFace(\n r: FontReadinessRenderer,\n node: SceneNode,\n family: string,\n style: string\n): boolean {\n if (fontManager.isStyleLoaded(family, style)) return true\n const demand = fontFaceDemand(family, style, node.text)\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return false\n}\n\nfunction requiredNodeFaces(node: SceneNode): Array<{ family: string; style: string }> {\n const baseFamily = node.fontFamily || DEFAULT_FONT_FAMILY\n const faces = new Map<string, { family: string; style: string }>()\n const add = (family: string, style: string) => faces.set(`${family}\\0${style}`, { family, style })\n add(baseFamily, textFontFace(node).style)\n for (const run of node.styleRuns) {\n add(run.style.fontFamily ?? baseFamily, textFontFace(node, run.style).style)\n }\n return Array.from(faces.values())\n}\n\nfunction languageForCharacter(node: SceneNode, sourceIndex: number): string | null {\n const run = node.styleRuns.find(\n (item) => sourceIndex >= item.start && sourceIndex < item.start + item.length\n )\n return run?.style.textLanguage !== undefined ? run.style.textLanguage : node.textLanguage\n}\n\nfunction transformedSourceOffsets(node: SceneNode): number[] {\n return shownCharacters(node).map((shown) => shown.sourceIndex)\n}\n\nexport type NodeFontReadiness = 'ready' | 'substituted' | 'pending' | 'exhausted'\n\nfunction requiredFacesReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n let pending = false\n let exhausted = false\n for (const { family, style } of requiredNodeFaces(node)) {\n if (fontManager.isStyleLoaded(family, style)) continue\n const demand = fontFaceDemand(family, style, node.text)\n const state = fontResolver.state(demand).state\n demandFace(r, node, family, style)\n if (state === 'failed' || state === 'exhausted') {\n // A missing face is drawn in another loaded face of the family, as Figma draws it, and\n // reported missing; the text stays visible when an exact face (Italic) is unavailable.\n if (fontManager.isLoaded(family)) continue\n exhausted = true\n } else {\n pending = true\n }\n }\n if (pending) return 'pending'\n if (exhausted && fontManager.isStyleLoaded(DEFAULT_FONT_FAMILY, 'Regular')) return 'substituted'\n return exhausted ? 'exhausted' : 'ready'\n}\n\nfunction demandRemoteCoverage(r: TextRenderer, node: SceneNode, characters: string[]): boolean {\n for (const { family, style } of requiredNodeFaces(node)) {\n if (!fontManager.remoteStyleNeedsCoverage(family, style, characters)) continue\n const demand = fontRemoteCoverageDemand(family, style, characters)\n const state = fontResolver.state(demand).state\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return true\n }\n if (state === 'loading') return true\n if (state === 'loaded') fontResolver.exhaust(demand)\n }\n return false\n}\n\nfunction observedGlyphReadiness(r: TextRenderer, node: SceneNode): NodeFontReadiness {\n if (\n r.fontProvider &&\n r.textPreparationCache?.hasGlyphCoverage(node, fontManager.generation(), r.fontProvider)\n )\n return 'ready'\n\n const missingOccurrences = withPreparedText(\n r,\n node,\n 'coverage',\n () => buildParagraph(r, node),\n (prepared) => {\n if (!prepared.missingGlyphs) {\n prepared.paragraph.layout(resolveParagraphLayoutWidth(node))\n prepared.missingGlyphs = missingGlyphOccurrences(\n shownText(node),\n prepared.paragraph.getShapedLines(),\n transformedSourceOffsets(node)\n )\n }\n return prepared.missingGlyphs\n }\n )\n if (missingOccurrences.length === 0) {\n r.textPreparationCache?.recordGlyphCoverage(node)\n return 'ready'\n }\n\n const charactersByScript = missingGlyphsByScript(missingOccurrences, (offset) =>\n languageForCharacter(node, offset)\n )\n\n let pending = false\n let exhausted = charactersByScript.size === 0\n for (const [script, characters] of charactersByScript) {\n if (demandRemoteCoverage(r, node, characters)) {\n pending = true\n continue\n }\n\n const demand = fontCoverageDemand(script, characters)\n const state = fontResolver.state(demand).state\n if (state === 'loaded') {\n fontResolver.exhaust(demand)\n exhausted = true\n continue\n }\n if (state === 'exhausted' || state === 'failed') {\n exhausted = true\n continue\n }\n pending = true\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n }\n }\n // An export draws once: a face that has not arrived by then is not coming, and the characters\n // it would have covered keep the text's own fonts rather than leaving the layer blank.\n if (pending) return r.exportFontsSettled ? 'substituted' : 'pending'\n // Once no fallback is left for a character, the text draws with the fonts it has, the font's\n // missing-glyph box standing in for that character, rather than not at all.\n return exhausted ? 'substituted' : 'ready'\n}\n\nfunction canObserveGlyphCoverage(r: FontReadinessRenderer): r is TextRenderer {\n return r.ck !== undefined && r.fontProvider != null && r.fontsLoaded !== undefined\n}\n\nexport function nodeFontReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n if (node.type !== 'TEXT') return 'ready'\n const faces = requiredFacesReadiness(r, node)\n if (faces === 'pending' || faces === 'exhausted') return faces\n if (!node.text || !canObserveGlyphCoverage(r)) return faces\n const glyphs = observedGlyphReadiness(r, node)\n // Substituted text still needs script fallbacks (for example CJK) for glyphs the substitute\n // lacks, but stays visible when none can be found.\n if (faces === 'substituted') return glyphs === 'pending' ? 'pending' : 'substituted'\n return glyphs\n}\n\nexport function isNodeFontLoaded(r: FontReadinessRenderer, node: SceneNode): boolean {\n const readiness = nodeFontReadiness(r, node)\n return readiness === 'ready' || readiness === 'substituted'\n}\n\nexport function measureTextNode(\n r: TextRenderer,\n node: SceneNode,\n maxWidth?: number\n): { width: number; height: number } | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const layoutWidth = resolveParagraphLayoutWidth(node, maxWidth)\n const measure = () => {\n const paragraph = buildParagraph(r, node)\n paragraph.layout(layoutWidth)\n const width = paragraph.getLongestLine()\n const height = paragraph.getHeight()\n paragraph.delete()\n return { width: Math.ceil(width), height: Math.ceil(height) }\n }\n // Layout asks for the same text at the same width many times per pass.\n return r.textPreparationCache\n ? r.textPreparationCache.measure(\n node,\n layoutWidth,\n fontManager.generation(),\n r.fontProvider,\n measure\n )\n : measure()\n}\n\nexport function buildTextPicture(r: TextRenderer, node: SceneNode): Uint8Array | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const ck = r.ck\n const recorder = new ck.PictureRecorder()\n const bounds = ck.LTRBRect(0, 0, node.width || 1e6, node.height || 1e6)\n const recCanvas = recorder.beginRecording(bounds)\n\n const layout = buildParagraph(r, node)\n const paint = new ck.Paint()\n try {\n drawTextLayout(\n ck,\n recCanvas,\n node,\n { paragraph: layout },\n 0,\n paint,\n r.documentColorSpace ?? 'srgb'\n )\n } finally {\n paint.delete()\n layout.delete()\n }\n\n const picture = recorder.finishRecordingAsPicture()\n recorder.delete()\n\n const bytes = picture.serialize()\n picture.delete()\n return bytes ?? null\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAS,WACP,GACA,MACA,QACA,OACS;CACT,IAAI,YAAY,cAAc,QAAQ,KAAK,GAAG,OAAO;CACrD,MAAM,SAAS,eAAe,QAAQ,OAAO,KAAK,IAAI;CACtD,EAAE,kBAAkB,MAAM,OAAO,GAAG;CACpC,aAAkB,cAAc,QAAQ,KAAK,IAAI,EAAE,uBAAuB;CAC1E,OAAO;AACT;AAEA,SAAS,kBAAkB,MAA2D;CACpF,MAAM,aAAa,KAAK,cAAA;CACxB,MAAM,wBAAQ,IAAI,IAA+C;CACjE,MAAM,OAAO,QAAgB,UAAkB,MAAM,IAAI,GAAG,OAAO,IAAI,SAAS;EAAE;EAAQ;CAAM,CAAC;CACjG,IAAI,YAAY,aAAa,IAAI,CAAC,CAAC,KAAK;CACxC,KAAK,MAAM,OAAO,KAAK,WACrB,IAAI,IAAI,MAAM,cAAc,YAAY,aAAa,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK;CAE7E,OAAO,MAAM,KAAK,MAAM,OAAO,CAAC;AAClC;AAEA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,IAAI,GAAG,OAAO;CAC5E,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,MAAM,OAAO;CAE/C,MAAM,KAAK,EAAE;CACb,MAAM,WAAW,IAAI,GAAG,gBAAgB;CACxC,MAAM,SAAS,GAAG,SAAS,GAAG,GAAG,KAAK,SAAS,KAAK,KAAK,UAAU,GAAG;CACtE,MAAM,YAAY,SAAS,eAAe,MAAM;CAEhD,MAAM,SAAS,eAAe,GAAG,IAAI;CACrC,MAAM,QAAQ,IAAI,GAAG,MAAM;CAC3B,IAAI;EACF,eACE,IACA,WACA,MACA,EAAE,WAAW,OAAO,GACpB,GACA,OACA,EAAE,sBAAsB,MAC1B;CACF,UAAU;EACR,MAAM,OAAO;EACb,OAAO,OAAO;CAChB;CAEA,MAAM,UAAU,SAAS,yBAAyB;CAClD,SAAS,OAAO;CAEhB,MAAM,QAAQ,QAAQ,UAAU;CAChC,QAAQ,OAAO;CACf,OAAO,SAAS;AAClB"}
|
|
@@ -2,7 +2,7 @@ import { TextRenderer } from "../renderer.js";
|
|
|
2
2
|
import { ParagraphBuildOptions } from "../paint.js";
|
|
3
3
|
import { ParagraphNode } from "./inputs.js";
|
|
4
4
|
import { CanvasKit, Paragraph, TextFontFeatures, TextFontVariations } from "canvaskit-wasm";
|
|
5
|
-
import { SceneNode } from "@pairdraw/scene-graph";
|
|
5
|
+
import { ColorProfile, SceneNode } from "@pairdraw/scene-graph";
|
|
6
6
|
//#region src/canvas/text/paragraph/index.d.ts
|
|
7
7
|
declare function resolveParagraphLayoutWidth(node: ParagraphNode, maxWidth?: number): number;
|
|
8
8
|
/**
|
|
@@ -28,7 +28,7 @@ interface ParagraphEdges {
|
|
|
28
28
|
last: boolean;
|
|
29
29
|
}
|
|
30
30
|
/** The colour a style run's text is drawn in: its first visible solid fill, or `baseColor`. */
|
|
31
|
-
declare function styleRunColor(ck: CanvasKit, style: SceneNode['styleRuns'][number]['style'], baseColor: Float32Array): Float32Array;
|
|
31
|
+
declare function styleRunColor(ck: CanvasKit, style: SceneNode['styleRuns'][number]['style'], baseColor: Float32Array, space: ColorProfile): Float32Array;
|
|
32
32
|
/** What a paragraph that is one block of a longer text needs beyond its node's own style. */
|
|
33
33
|
interface ParagraphBlockOptions {
|
|
34
34
|
/** Room before the first line, as a plain paragraph's first-line indent. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"mappings":";;;;;;iBAuCgB,4BAA4B,MAAM,eAAe;;;;;;iBAajD,kBAAkB,MAAM;EAAkB;EAAmB;;;iBA4B7D,mBACd,YAAY,yCACZ,WAAU,qCACT;iBAUa,iBACd,UAAU,wCACT;iBAQa,wBAAwB,GACtC;EAAM;IAAsB,YAAY;;GACxC,aAAa,2BACZ;;UAKc;EACf;EACA;;;iBAsCc,cACd,IAAI,WACJ,OAAO,yCACP,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"mappings":";;;;;;iBAuCgB,4BAA4B,MAAM,eAAe;;;;;;iBAajD,kBAAkB,MAAM;EAAkB;EAAmB;;;iBA4B7D,mBACd,YAAY,yCACZ,WAAU,qCACT;iBAUa,iBACd,UAAU,wCACT;iBAQa,wBAAwB,GACtC;EAAM;IAAsB,YAAY;;GACxC,aAAa,2BACZ;;UAKc;EACf;EACA;;;iBAsCc,cACd,IAAI,WACJ,OAAO,yCACP,WAAW,cACX,OAAO,eACN;;UA0Hc;;EAEf;;EAEA;IAAe;IAAmB;;EAClC,QAAQ;;;;;;iBAYM,iBACd,GAAG,cACH,MAAM,eACN,QAAQ,gBACN,aAAqB,oBAAmB,uBAC1C,QAAO,wBACN"}
|
|
@@ -7,10 +7,10 @@ import { laidOutText } from "../keycap.js";
|
|
|
7
7
|
import { pushParagraphStyle } from "../paint.js";
|
|
8
8
|
import { autoWidthWrapWidth } from "../../../layout/text-measurement.js";
|
|
9
9
|
import "../../../text/ellipsis.js";
|
|
10
|
+
import { normalizeColor, toExtendedSRGB } from "@pairdraw/scene-graph/color";
|
|
10
11
|
import { lineHeightPixels, textLengthPixels } from "@pairdraw/scene-graph/text";
|
|
11
12
|
import { faceStyleKey } from "@pairdraw/scene-graph/font-style";
|
|
12
13
|
import { rangeFontStyle } from "@pairdraw/scene-graph/shared-styles";
|
|
13
|
-
import { resolveRGBAForPreview } from "@pairdraw/scene-graph/color";
|
|
14
14
|
import { resolveNodeTextDirection } from "@pairdraw/scene-graph/text/direction";
|
|
15
15
|
//#region src/canvas/text/paragraph/index.ts
|
|
16
16
|
function resolveParagraphLayoutWidth(node, maxWidth) {
|
|
@@ -86,12 +86,23 @@ function drawnFontStyle(ck, family, weight, italic, style) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
/** The colour a style run's text is drawn in: its first visible solid fill, or `baseColor`. */
|
|
89
|
-
function styleRunColor(ck, style, baseColor) {
|
|
89
|
+
function styleRunColor(ck, style, baseColor, space) {
|
|
90
90
|
const visibleFill = style.fills?.find((fill) => fill.visible && fill.type === "SOLID");
|
|
91
91
|
if (!visibleFill) return baseColor;
|
|
92
|
-
const color =
|
|
92
|
+
const color = toExtendedSRGB(normalizeColor(visibleFill.color), space);
|
|
93
93
|
return ck.Color4f(color.r, color.g, color.b, color.a * visibleFill.opacity);
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* A text style's color. CanvasKit keeps `color` in 8-bit sRGB, which clips a wide-gamut color, and
|
|
97
|
+
* draws `foregroundColor` with float components, so both carry it; a pushed foreground paint, as a
|
|
98
|
+
* gradient fill draws with, still takes their place.
|
|
99
|
+
*/
|
|
100
|
+
function textColor(color) {
|
|
101
|
+
return {
|
|
102
|
+
color,
|
|
103
|
+
foregroundColor: color
|
|
104
|
+
};
|
|
105
|
+
}
|
|
95
106
|
function styleRunLanguage(style, node) {
|
|
96
107
|
return (style.textLanguage !== void 0 ? style.textLanguage : node.textLanguage) ?? void 0;
|
|
97
108
|
}
|
|
@@ -110,7 +121,7 @@ function pushStyleRun(r, builder, node, run, baseColor, baseFontSize, fontFamili
|
|
|
110
121
|
};
|
|
111
122
|
const runKey = faceStyleKey(runFace);
|
|
112
123
|
const textStyle = new ck.TextStyle({
|
|
113
|
-
|
|
124
|
+
...textColor(styleRunColor(ck, style, baseColor, r.documentColorSpace ?? "srgb")),
|
|
114
125
|
fontFamilies: fontFamilies(runFamily, runFace),
|
|
115
126
|
fontSize: runFontSize,
|
|
116
127
|
locale: styleRunLanguage(style, node),
|
|
@@ -171,7 +182,7 @@ function buildSkParagraph(r, node, color, { halfLeading = false, foregroundPaint
|
|
|
171
182
|
}, letterFallbacks, cjkFallbacks);
|
|
172
183
|
const nodeKey = faceStyleKey(node);
|
|
173
184
|
const baseTextStyle = {
|
|
174
|
-
|
|
185
|
+
...textColor(baseColor),
|
|
175
186
|
fontFamilies: fontFamilies(node.fontFamily || "Inter", node),
|
|
176
187
|
fontSize: baseFontSize,
|
|
177
188
|
locale: node.textLanguage ?? void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"sourcesContent":["import type {\n CanvasKit,\n FontStyle,\n Paint,\n Paragraph,\n ParagraphBuilder,\n TextFontFeatures,\n TextFontVariations,\n TextHeightBehavior\n} from 'canvaskit-wasm'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { resolveRGBAForPreview } from '@pairdraw/scene-graph/color'\nimport { faceStyleKey, type NamedFace } from '@pairdraw/scene-graph/font-style'\nimport { rangeFontStyle } from '@pairdraw/scene-graph/shared-styles'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport {\n drawnFontVariations,\n loadedFace,\n resolveParagraphFontFamilies\n} from '#core/canvas/text/font-families'\nimport { laidOutText } from '#core/canvas/text/keycap'\nimport {\n pushParagraphStyle,\n type ParagraphPaintStyle,\n type ParagraphBuildOptions\n} from '#core/canvas/text/paint'\nimport type { TextRenderer } from '#core/canvas/text/renderer'\nimport { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from '#core/constants'\nimport { autoWidthWrapWidth } from '#core/layout/text-measurement'\nimport { shownTextSlice } from '#core/text/case'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport { makeParagraphBuilder } from '#core/text/font/collection'\nimport { fontManager } from '#core/text/font/manager'\n\nimport type { ParagraphNode } from './inputs'\n\nexport function resolveParagraphLayoutWidth(node: ParagraphNode, maxWidth?: number): number {\n if (maxWidth !== undefined) return maxWidth\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') {\n return autoWidthWrapWidth(node) ?? 1e6\n }\n return node.width || 1e6\n}\n\n/**\n * The lines a truncating box shows: what `maxLines` allows, else as many as its height holds, as\n * Figma keeps the last and ends it with an ellipsis. A text box set to truncate truncates even\n * where nothing turned on `textTruncation`, which is how the auto-resize mode is chosen.\n */\nexport function buildTruncateOpts(node: ParagraphNode): { maxLines?: number; ellipsis?: string } {\n if (node.textTruncation !== 'ENDING' && node.textAutoResize !== 'TRUNCATE') return {}\n // A box that truncates only by its height is measured as it is, then capped by the lines that\n // fit and built again with that count.\n if (node.maxLines == null || node.maxLines <= 0) {\n return node.textAutoResize === 'TRUNCATE' ? {} : { ellipsis: ELLIPSIS }\n }\n return { maxLines: node.maxLines, ellipsis: ELLIPSIS }\n}\n\nfunction getParagraphTextAlign(\n ck: CanvasKit,\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n) {\n const direction = resolveNodeTextDirection(node)\n switch (node.textAlignHorizontal) {\n case 'CENTER':\n return ck.TextAlign.Center\n case 'RIGHT':\n return direction === 'RTL' ? ck.TextAlign.Left : ck.TextAlign.Right\n case 'JUSTIFIED':\n return ck.TextAlign.Justify\n default:\n return direction === 'RTL' ? ck.TextAlign.Right : ck.TextAlign.Left\n }\n}\n\n/** Explicit axes win over the named-instance axes of a variable face (`implicit`). */\nexport function textFontVariations(\n variations: SceneNode['fontVariations'] | undefined,\n implicit: SceneNode['fontVariations'] | null = null\n): TextFontVariations[] | undefined {\n const explicitAxes = new Set(variations?.map((variation) => variation.axis))\n const merged = [\n ...(implicit ?? []).filter((variation) => !explicitAxes.has(variation.axis)),\n ...(variations ?? [])\n ]\n if (merged.length === 0) return undefined\n return merged.map((variation) => ({ axis: variation.axis, value: variation.value }))\n}\n\nexport function textFontFeatures(\n features: SceneNode['fontFeatures'] | undefined\n): TextFontFeatures[] | undefined {\n if (!features || features.length === 0) return undefined\n return features.map((feature) => ({\n name: feature.tag.toLowerCase(),\n value: feature.enabled ? 1 : 0\n }))\n}\n\nexport function textHeightBehaviorValue<T>(\n ck: { TextHeightBehavior: { DisableAll: T } },\n leadingTrim: SceneNode['leadingTrim']\n): T | undefined {\n return leadingTrim === 'CAP_HEIGHT' ? ck.TextHeightBehavior.DisableAll : undefined\n}\n\n/** Which edges of the text a paragraph is: leading trim only trims the text's own edges. */\nexport interface ParagraphEdges {\n first: boolean\n last: boolean\n}\n\nfunction blockHeightBehavior(\n ck: CanvasKit,\n leadingTrim: SceneNode['leadingTrim'],\n edges: ParagraphEdges | undefined\n): TextHeightBehavior | undefined {\n if (!edges) return textHeightBehaviorValue(ck, leadingTrim)\n const { first, last } = edges\n if (leadingTrim !== 'CAP_HEIGHT') return undefined\n if (first && last) return ck.TextHeightBehavior.DisableAll\n if (first) return ck.TextHeightBehavior.DisableFirstAscent\n if (last) return ck.TextHeightBehavior.DisableLastDescent\n return ck.TextHeightBehavior.All\n}\n\n/**\n * The style a paragraph asks CanvasKit for: the face of the family that is loaded. Asked for a\n * face it lacks, CanvasKit slants and emboldens another, which neither Figma, a browser, nor a\n * native text stack draws the same, so a missing face is drawn as the face that exists and\n * reported missing, as Figma does. A family with no face loaded asks for the style as given.\n */\nfunction drawnFontStyle(\n ck: CanvasKit,\n family: string,\n weight: number,\n italic: boolean,\n style: string\n): FontStyle {\n const face = loadedFace(family, weight, italic, style) ?? { weight, italic }\n return {\n weight: { value: face.weight },\n slant: face.italic ? ck.FontSlant.Italic : ck.FontSlant.Upright\n }\n}\n\n/** The colour a style run's text is drawn in: its first visible solid fill, or `baseColor`. */\nexport function styleRunColor(\n ck: CanvasKit,\n style: SceneNode['styleRuns'][number]['style'],\n baseColor: Float32Array\n): Float32Array {\n const visibleFill = style.fills?.find((fill) => fill.visible && fill.type === 'SOLID')\n if (!visibleFill) return baseColor\n const color = resolveRGBAForPreview(visibleFill.color).color\n return ck.Color4f(color.r, color.g, color.b, color.a * visibleFill.opacity)\n}\n\nfunction styleRunLanguage(\n style: SceneNode['styleRuns'][number]['style'],\n node: Pick<ParagraphNode, 'textLanguage'>\n): string | undefined {\n return (style.textLanguage !== undefined ? style.textLanguage : node.textLanguage) ?? undefined\n}\n\nfunction pushStyleRun(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n run: SceneNode['styleRuns'][number],\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const ck = r.ck\n const style = run.style\n const runFontSize = style.fontSize ?? baseFontSize\n // A percent follows the run's own font size, as in Figma.\n const runLineHeight = lineHeightPixels(\n style.lineHeight !== undefined ? style.lineHeight : node.lineHeight,\n runFontSize\n )\n const runFamily = style.fontFamily ?? (node.fontFamily || DEFAULT_FONT_FAMILY)\n const runWeight = style.fontWeight ?? node.fontWeight\n const runItalic = style.italic ?? node.italic\n const runFace = {\n fontWeight: runWeight,\n italic: runItalic,\n fontStyle: rangeFontStyle(node, style)\n }\n const runKey = faceStyleKey(runFace)\n\n const textStyle = new ck.TextStyle({\n color: styleRunColor(ck, style, baseColor),\n fontFamilies: fontFamilies(runFamily, runFace),\n fontSize: runFontSize,\n locale: styleRunLanguage(style, node),\n fontStyle: drawnFontStyle(ck, runFamily, runWeight, runItalic, runKey),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: runFamily,\n weight: runWeight,\n italic: runItalic,\n style: runKey,\n fontSize: runFontSize,\n variations: style.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: style.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(style.fontFeatures ?? node.fontFeatures),\n letterSpacing: textLengthPixels(style.letterSpacing ?? node.letterSpacing, runFontSize),\n heightMultiplier: runLineHeight ? runLineHeight / runFontSize : undefined,\n halfLeading\n })\n pushParagraphStyle(builder, textStyle, paintStyle)\n}\n\n/** `text[start, end)` in the case each of its characters has. */\nfunction addParagraphText(\n builder: ParagraphBuilder,\n node: ParagraphNode,\n start: number,\n end: number\n): void {\n builder.addText(laidOutText(shownTextSlice(node, start, end)))\n}\n\nfunction addStyledRuns(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const text = node.text\n let pos = 0\n\n for (const run of node.styleRuns) {\n if (pos < run.start) addParagraphText(builder, node, pos, run.start)\n pushStyleRun(\n r,\n builder,\n node,\n run,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n addParagraphText(builder, node, run.start, run.start + run.length)\n builder.pop()\n pos = run.start + run.length\n }\n\n if (pos < text.length) addParagraphText(builder, node, pos, text.length)\n}\n\n/** What a paragraph that is one block of a longer text needs beyond its node's own style. */\nexport interface ParagraphBlockOptions {\n /** Room before the first line, as a plain paragraph's first-line indent. */\n firstLineIndent?: number\n /** Truncation for this block in place of the node's. */\n truncation?: { maxLines?: number; ellipsis?: string }\n edges?: ParagraphEdges\n}\n\n/** Room before a paragraph's first line, as an empty placeholder on its baseline. */\nfunction addFirstLineIndent(ck: CanvasKit, builder: ParagraphBuilder, width: number): void {\n builder.addPlaceholder(width, 0, ck.PlaceholderAlignment.Baseline, ck.TextBaseline.Alphabetic, 0)\n}\n\n/**\n * A native paragraph for `node`'s text in its style runs, not yet laid out. A first-line\n * indent is a placeholder before the text, which takes the first character index.\n */\nexport function buildSkParagraph(\n r: TextRenderer,\n node: ParagraphNode,\n color?: Float32Array,\n { halfLeading = false, foregroundPaint }: ParagraphBuildOptions = {},\n block: ParagraphBlockOptions = {}\n): Paragraph {\n const ck = r.ck\n const baseColor = color ?? ck.BLACK\n const baseFontSize = node.fontSize || DEFAULT_FONT_SIZE\n const baseLineHeight = lineHeightPixels(node.lineHeight, baseFontSize)\n const cjkFallbacks = fontManager.getCJKFallbackFamilies()\n const letterFallbacks = fontManager.getLetterFallbackFamilies()\n const textDirection = resolveNodeTextDirection(node)\n\n const truncateOpts = block.truncation ?? buildTruncateOpts(node)\n\n const fontFamilies = (primary: string, face: NamedFace) =>\n resolveParagraphFontFamilies(\n primary,\n { weight: face.fontWeight, italic: face.italic, style: faceStyleKey(face) },\n letterFallbacks,\n cjkFallbacks\n )\n const nodeKey = faceStyleKey(node)\n\n const baseTextStyle = {\n color: baseColor,\n fontFamilies: fontFamilies(node.fontFamily || DEFAULT_FONT_FAMILY, node),\n fontSize: baseFontSize,\n locale: node.textLanguage ?? undefined,\n fontStyle: drawnFontStyle(\n ck,\n node.fontFamily || DEFAULT_FONT_FAMILY,\n node.fontWeight,\n node.italic,\n nodeKey\n ),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: node.fontFamily || DEFAULT_FONT_FAMILY,\n weight: node.fontWeight,\n italic: node.italic,\n style: nodeKey,\n fontSize: baseFontSize,\n variations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(node.fontFeatures),\n letterSpacing: textLengthPixels(node.letterSpacing, baseFontSize),\n heightMultiplier: baseLineHeight ? baseLineHeight / baseFontSize : undefined,\n halfLeading\n }\n const paraStyle = new ck.ParagraphStyle({\n textAlign: getParagraphTextAlign(ck, node),\n textDirection: textDirection === 'RTL' ? ck.TextDirection.RTL : ck.TextDirection.LTR,\n textHeightBehavior: blockHeightBehavior(ck, node.leadingTrim, block.edges),\n ...truncateOpts,\n textStyle: baseTextStyle\n })\n\n if (!r.fontProvider) throw new Error('Font provider not initialized')\n const builder = makeParagraphBuilder(ck, paraStyle, r.fontProvider)\n\n let background: Paint | undefined\n try {\n let paintStyle: ParagraphPaintStyle | undefined\n if (foregroundPaint) {\n background = new ck.Paint()\n background.setColor(ck.TRANSPARENT)\n paintStyle = { foreground: foregroundPaint, background }\n builder.pushPaintStyle(new ck.TextStyle(baseTextStyle), foregroundPaint, background)\n }\n if (block.firstLineIndent) addFirstLineIndent(ck, builder, block.firstLineIndent)\n if (node.styleRuns.length === 0) {\n addParagraphText(builder, node, 0, node.text.length)\n } else {\n addStyledRuns(\n r,\n builder,\n node,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n }\n\n return builder.build()\n } finally {\n builder.delete()\n background?.delete()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAgB,4BAA4B,MAAqB,UAA2B;CAC1F,IAAI,aAAa,KAAA,GAAW,OAAO;CACnC,IAAI,KAAK,mBAAmB,oBAC1B,OAAO,mBAAmB,IAAI,KAAK;CAErC,OAAO,KAAK,SAAS;AACvB;;;;;;AAOA,SAAgB,kBAAkB,MAA+D;CAC/F,IAAI,KAAK,mBAAmB,YAAY,KAAK,mBAAmB,YAAY,OAAO,CAAC;CAGpF,IAAI,KAAK,YAAY,QAAQ,KAAK,YAAY,GAC5C,OAAO,KAAK,mBAAmB,aAAa,CAAC,IAAI,EAAE,UAAA,IAAmB;CAExE,OAAO;EAAE,UAAU,KAAK;EAAU,UAAA;CAAmB;AACvD;AAEA,SAAS,sBACP,IACA,MACA;CACA,MAAM,YAAY,yBAAyB,IAAI;CAC/C,QAAQ,KAAK,qBAAb;EACE,KAAK,UACH,OAAO,GAAG,UAAU;EACtB,KAAK,SACH,OAAO,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GAAG,UAAU,aAAa,GAAG,iBAAiB,UAAU;EACrF;EACA,IAAI,MAAM,iBAAiB,mBAAmB,IAAI,SAAS,MAAM,eAAe;EAChF,IAAI,KAAK,UAAU,WAAW,GAC5B,iBAAiB,SAAS,MAAM,GAAG,KAAK,KAAK,MAAM;OAEnD,cACE,GACA,SACA,MACA,WACA,cACA,cACA,aACA,UACF;EAGF,OAAO,QAAQ,MAAM;CACvB,UAAU;EACR,QAAQ,OAAO;EACf,YAAY,OAAO;CACrB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"sourcesContent":["import type {\n CanvasKit,\n FontStyle,\n Paint,\n Paragraph,\n ParagraphBuilder,\n TextFontFeatures,\n TextFontVariations,\n TextHeightBehavior\n} from 'canvaskit-wasm'\n\nimport type { ColorProfile, SceneNode } from '@pairdraw/scene-graph'\nimport { normalizeColor, toExtendedSRGB } from '@pairdraw/scene-graph/color'\nimport { faceStyleKey, type NamedFace } from '@pairdraw/scene-graph/font-style'\nimport { rangeFontStyle } from '@pairdraw/scene-graph/shared-styles'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport {\n drawnFontVariations,\n loadedFace,\n resolveParagraphFontFamilies\n} from '#core/canvas/text/font-families'\nimport { laidOutText } from '#core/canvas/text/keycap'\nimport {\n pushParagraphStyle,\n type ParagraphPaintStyle,\n type ParagraphBuildOptions\n} from '#core/canvas/text/paint'\nimport type { TextRenderer } from '#core/canvas/text/renderer'\nimport { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from '#core/constants'\nimport { autoWidthWrapWidth } from '#core/layout/text-measurement'\nimport { shownTextSlice } from '#core/text/case'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport { makeParagraphBuilder } from '#core/text/font/collection'\nimport { fontManager } from '#core/text/font/manager'\n\nimport type { ParagraphNode } from './inputs'\n\nexport function resolveParagraphLayoutWidth(node: ParagraphNode, maxWidth?: number): number {\n if (maxWidth !== undefined) return maxWidth\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') {\n return autoWidthWrapWidth(node) ?? 1e6\n }\n return node.width || 1e6\n}\n\n/**\n * The lines a truncating box shows: what `maxLines` allows, else as many as its height holds, as\n * Figma keeps the last and ends it with an ellipsis. A text box set to truncate truncates even\n * where nothing turned on `textTruncation`, which is how the auto-resize mode is chosen.\n */\nexport function buildTruncateOpts(node: ParagraphNode): { maxLines?: number; ellipsis?: string } {\n if (node.textTruncation !== 'ENDING' && node.textAutoResize !== 'TRUNCATE') return {}\n // A box that truncates only by its height is measured as it is, then capped by the lines that\n // fit and built again with that count.\n if (node.maxLines == null || node.maxLines <= 0) {\n return node.textAutoResize === 'TRUNCATE' ? {} : { ellipsis: ELLIPSIS }\n }\n return { maxLines: node.maxLines, ellipsis: ELLIPSIS }\n}\n\nfunction getParagraphTextAlign(\n ck: CanvasKit,\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n) {\n const direction = resolveNodeTextDirection(node)\n switch (node.textAlignHorizontal) {\n case 'CENTER':\n return ck.TextAlign.Center\n case 'RIGHT':\n return direction === 'RTL' ? ck.TextAlign.Left : ck.TextAlign.Right\n case 'JUSTIFIED':\n return ck.TextAlign.Justify\n default:\n return direction === 'RTL' ? ck.TextAlign.Right : ck.TextAlign.Left\n }\n}\n\n/** Explicit axes win over the named-instance axes of a variable face (`implicit`). */\nexport function textFontVariations(\n variations: SceneNode['fontVariations'] | undefined,\n implicit: SceneNode['fontVariations'] | null = null\n): TextFontVariations[] | undefined {\n const explicitAxes = new Set(variations?.map((variation) => variation.axis))\n const merged = [\n ...(implicit ?? []).filter((variation) => !explicitAxes.has(variation.axis)),\n ...(variations ?? [])\n ]\n if (merged.length === 0) return undefined\n return merged.map((variation) => ({ axis: variation.axis, value: variation.value }))\n}\n\nexport function textFontFeatures(\n features: SceneNode['fontFeatures'] | undefined\n): TextFontFeatures[] | undefined {\n if (!features || features.length === 0) return undefined\n return features.map((feature) => ({\n name: feature.tag.toLowerCase(),\n value: feature.enabled ? 1 : 0\n }))\n}\n\nexport function textHeightBehaviorValue<T>(\n ck: { TextHeightBehavior: { DisableAll: T } },\n leadingTrim: SceneNode['leadingTrim']\n): T | undefined {\n return leadingTrim === 'CAP_HEIGHT' ? ck.TextHeightBehavior.DisableAll : undefined\n}\n\n/** Which edges of the text a paragraph is: leading trim only trims the text's own edges. */\nexport interface ParagraphEdges {\n first: boolean\n last: boolean\n}\n\nfunction blockHeightBehavior(\n ck: CanvasKit,\n leadingTrim: SceneNode['leadingTrim'],\n edges: ParagraphEdges | undefined\n): TextHeightBehavior | undefined {\n if (!edges) return textHeightBehaviorValue(ck, leadingTrim)\n const { first, last } = edges\n if (leadingTrim !== 'CAP_HEIGHT') return undefined\n if (first && last) return ck.TextHeightBehavior.DisableAll\n if (first) return ck.TextHeightBehavior.DisableFirstAscent\n if (last) return ck.TextHeightBehavior.DisableLastDescent\n return ck.TextHeightBehavior.All\n}\n\n/**\n * The style a paragraph asks CanvasKit for: the face of the family that is loaded. Asked for a\n * face it lacks, CanvasKit slants and emboldens another, which neither Figma, a browser, nor a\n * native text stack draws the same, so a missing face is drawn as the face that exists and\n * reported missing, as Figma does. A family with no face loaded asks for the style as given.\n */\nfunction drawnFontStyle(\n ck: CanvasKit,\n family: string,\n weight: number,\n italic: boolean,\n style: string\n): FontStyle {\n const face = loadedFace(family, weight, italic, style) ?? { weight, italic }\n return {\n weight: { value: face.weight },\n slant: face.italic ? ck.FontSlant.Italic : ck.FontSlant.Upright\n }\n}\n\n/** The colour a style run's text is drawn in: its first visible solid fill, or `baseColor`. */\nexport function styleRunColor(\n ck: CanvasKit,\n style: SceneNode['styleRuns'][number]['style'],\n baseColor: Float32Array,\n space: ColorProfile\n): Float32Array {\n const visibleFill = style.fills?.find((fill) => fill.visible && fill.type === 'SOLID')\n if (!visibleFill) return baseColor\n const color = toExtendedSRGB(normalizeColor(visibleFill.color), space)\n return ck.Color4f(color.r, color.g, color.b, color.a * visibleFill.opacity)\n}\n\n/**\n * A text style's color. CanvasKit keeps `color` in 8-bit sRGB, which clips a wide-gamut color, and\n * draws `foregroundColor` with float components, so both carry it; a pushed foreground paint, as a\n * gradient fill draws with, still takes their place.\n */\nfunction textColor(color: Float32Array) {\n return { color, foregroundColor: color }\n}\n\nfunction styleRunLanguage(\n style: SceneNode['styleRuns'][number]['style'],\n node: Pick<ParagraphNode, 'textLanguage'>\n): string | undefined {\n return (style.textLanguage !== undefined ? style.textLanguage : node.textLanguage) ?? undefined\n}\n\nfunction pushStyleRun(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n run: SceneNode['styleRuns'][number],\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const ck = r.ck\n const style = run.style\n const runFontSize = style.fontSize ?? baseFontSize\n // A percent follows the run's own font size, as in Figma.\n const runLineHeight = lineHeightPixels(\n style.lineHeight !== undefined ? style.lineHeight : node.lineHeight,\n runFontSize\n )\n const runFamily = style.fontFamily ?? (node.fontFamily || DEFAULT_FONT_FAMILY)\n const runWeight = style.fontWeight ?? node.fontWeight\n const runItalic = style.italic ?? node.italic\n const runFace = {\n fontWeight: runWeight,\n italic: runItalic,\n fontStyle: rangeFontStyle(node, style)\n }\n const runKey = faceStyleKey(runFace)\n\n const textStyle = new ck.TextStyle({\n ...textColor(styleRunColor(ck, style, baseColor, r.documentColorSpace ?? 'srgb')),\n fontFamilies: fontFamilies(runFamily, runFace),\n fontSize: runFontSize,\n locale: styleRunLanguage(style, node),\n fontStyle: drawnFontStyle(ck, runFamily, runWeight, runItalic, runKey),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: runFamily,\n weight: runWeight,\n italic: runItalic,\n style: runKey,\n fontSize: runFontSize,\n variations: style.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: style.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(style.fontFeatures ?? node.fontFeatures),\n letterSpacing: textLengthPixels(style.letterSpacing ?? node.letterSpacing, runFontSize),\n heightMultiplier: runLineHeight ? runLineHeight / runFontSize : undefined,\n halfLeading\n })\n pushParagraphStyle(builder, textStyle, paintStyle)\n}\n\n/** `text[start, end)` in the case each of its characters has. */\nfunction addParagraphText(\n builder: ParagraphBuilder,\n node: ParagraphNode,\n start: number,\n end: number\n): void {\n builder.addText(laidOutText(shownTextSlice(node, start, end)))\n}\n\nfunction addStyledRuns(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const text = node.text\n let pos = 0\n\n for (const run of node.styleRuns) {\n if (pos < run.start) addParagraphText(builder, node, pos, run.start)\n pushStyleRun(\n r,\n builder,\n node,\n run,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n addParagraphText(builder, node, run.start, run.start + run.length)\n builder.pop()\n pos = run.start + run.length\n }\n\n if (pos < text.length) addParagraphText(builder, node, pos, text.length)\n}\n\n/** What a paragraph that is one block of a longer text needs beyond its node's own style. */\nexport interface ParagraphBlockOptions {\n /** Room before the first line, as a plain paragraph's first-line indent. */\n firstLineIndent?: number\n /** Truncation for this block in place of the node's. */\n truncation?: { maxLines?: number; ellipsis?: string }\n edges?: ParagraphEdges\n}\n\n/** Room before a paragraph's first line, as an empty placeholder on its baseline. */\nfunction addFirstLineIndent(ck: CanvasKit, builder: ParagraphBuilder, width: number): void {\n builder.addPlaceholder(width, 0, ck.PlaceholderAlignment.Baseline, ck.TextBaseline.Alphabetic, 0)\n}\n\n/**\n * A native paragraph for `node`'s text in its style runs, not yet laid out. A first-line\n * indent is a placeholder before the text, which takes the first character index.\n */\nexport function buildSkParagraph(\n r: TextRenderer,\n node: ParagraphNode,\n color?: Float32Array,\n { halfLeading = false, foregroundPaint }: ParagraphBuildOptions = {},\n block: ParagraphBlockOptions = {}\n): Paragraph {\n const ck = r.ck\n const baseColor = color ?? ck.BLACK\n const baseFontSize = node.fontSize || DEFAULT_FONT_SIZE\n const baseLineHeight = lineHeightPixels(node.lineHeight, baseFontSize)\n const cjkFallbacks = fontManager.getCJKFallbackFamilies()\n const letterFallbacks = fontManager.getLetterFallbackFamilies()\n const textDirection = resolveNodeTextDirection(node)\n\n const truncateOpts = block.truncation ?? buildTruncateOpts(node)\n\n const fontFamilies = (primary: string, face: NamedFace) =>\n resolveParagraphFontFamilies(\n primary,\n { weight: face.fontWeight, italic: face.italic, style: faceStyleKey(face) },\n letterFallbacks,\n cjkFallbacks\n )\n const nodeKey = faceStyleKey(node)\n\n const baseTextStyle = {\n ...textColor(baseColor),\n fontFamilies: fontFamilies(node.fontFamily || DEFAULT_FONT_FAMILY, node),\n fontSize: baseFontSize,\n locale: node.textLanguage ?? undefined,\n fontStyle: drawnFontStyle(\n ck,\n node.fontFamily || DEFAULT_FONT_FAMILY,\n node.fontWeight,\n node.italic,\n nodeKey\n ),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: node.fontFamily || DEFAULT_FONT_FAMILY,\n weight: node.fontWeight,\n italic: node.italic,\n style: nodeKey,\n fontSize: baseFontSize,\n variations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(node.fontFeatures),\n letterSpacing: textLengthPixels(node.letterSpacing, baseFontSize),\n heightMultiplier: baseLineHeight ? baseLineHeight / baseFontSize : undefined,\n halfLeading\n }\n const paraStyle = new ck.ParagraphStyle({\n textAlign: getParagraphTextAlign(ck, node),\n textDirection: textDirection === 'RTL' ? ck.TextDirection.RTL : ck.TextDirection.LTR,\n textHeightBehavior: blockHeightBehavior(ck, node.leadingTrim, block.edges),\n ...truncateOpts,\n textStyle: baseTextStyle\n })\n\n if (!r.fontProvider) throw new Error('Font provider not initialized')\n const builder = makeParagraphBuilder(ck, paraStyle, r.fontProvider)\n\n let background: Paint | undefined\n try {\n let paintStyle: ParagraphPaintStyle | undefined\n if (foregroundPaint) {\n background = new ck.Paint()\n background.setColor(ck.TRANSPARENT)\n paintStyle = { foreground: foregroundPaint, background }\n builder.pushPaintStyle(new ck.TextStyle(baseTextStyle), foregroundPaint, background)\n }\n if (block.firstLineIndent) addFirstLineIndent(ck, builder, block.firstLineIndent)\n if (node.styleRuns.length === 0) {\n addParagraphText(builder, node, 0, node.text.length)\n } else {\n addStyledRuns(\n r,\n builder,\n node,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n }\n\n return builder.build()\n } finally {\n builder.delete()\n background?.delete()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAgB,4BAA4B,MAAqB,UAA2B;CAC1F,IAAI,aAAa,KAAA,GAAW,OAAO;CACnC,IAAI,KAAK,mBAAmB,oBAC1B,OAAO,mBAAmB,IAAI,KAAK;CAErC,OAAO,KAAK,SAAS;AACvB;;;;;;AAOA,SAAgB,kBAAkB,MAA+D;CAC/F,IAAI,KAAK,mBAAmB,YAAY,KAAK,mBAAmB,YAAY,OAAO,CAAC;CAGpF,IAAI,KAAK,YAAY,QAAQ,KAAK,YAAY,GAC5C,OAAO,KAAK,mBAAmB,aAAa,CAAC,IAAI,EAAE,UAAA,IAAmB;CAExE,OAAO;EAAE,UAAU,KAAK;EAAU,UAAA;CAAmB;AACvD;AAEA,SAAS,sBACP,IACA,MACA;CACA,MAAM,YAAY,yBAAyB,IAAI;CAC/C,QAAQ,KAAK,qBAAb;EACE,KAAK,UACH,OAAO,GAAG,UAAU;EACtB,KAAK,SACH,OAAO,cAAc,QAAQ,GAAG,UAAU,OAAO,GAAG,UAAU;EAChE,KAAK,aACH,OAAO,GAAG,UAAU;EACtB,SACE,OAAO,cAA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GAAW;GACvD,QAAQ,eAAe,IAAI,GAAG,UAAU,aAAa,GAAG,iBAAiB,UAAU;EACrF;EACA,IAAI,MAAM,iBAAiB,mBAAmB,IAAI,SAAS,MAAM,eAAe;EAChF,IAAI,KAAK,UAAU,WAAW,GAC5B,iBAAiB,SAAS,MAAM,GAAG,KAAK,KAAK,MAAM;OAEnD,cACE,GACA,SACA,MACA,WACA,cACA,cACA,aACA,UACF;EAGF,OAAO,QAAQ,MAAM;CACvB,UAAU;EACR,QAAQ,OAAO;EACf,YAAY,OAAO;CACrB;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FontResolutionSettled } from "../../text/resolver/types.js";
|
|
2
2
|
import { TextPreparationCache } from "./preparation/cache.js";
|
|
3
3
|
import { CanvasKit, TypefaceFontProvider } from "canvaskit-wasm";
|
|
4
|
-
import { SceneNode } from "@pairdraw/scene-graph";
|
|
4
|
+
import { ColorProfile, SceneNode } from "@pairdraw/scene-graph";
|
|
5
5
|
//#region src/canvas/text/renderer.d.ts
|
|
6
6
|
interface FontReadinessRenderer {
|
|
7
7
|
textPreparationCache?: TextPreparationCache;
|
|
@@ -15,6 +15,7 @@ interface FontReadinessRenderer {
|
|
|
15
15
|
}
|
|
16
16
|
interface TextRenderer extends FontReadinessRenderer {
|
|
17
17
|
ck: CanvasKit;
|
|
18
|
+
documentColorSpace?: ColorProfile;
|
|
18
19
|
fontProvider: TypefaceFontProvider | null;
|
|
19
20
|
fontsLoaded: boolean;
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","names":[],"sources":["../../../src/canvas/text/renderer.ts"],"mappings":";;;;;UAQiB;EACf,uBAAuB;EACvB,KAAK;EACL,eAAe;EACf;;EAEA;EACA,0BAA0B;EAC1B,mBAAmB,MAAM,WAAW;;UAGrB,qBAAqB;EACpC,IAAI;EACJ,cAAc;EACd"}
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","names":[],"sources":["../../../src/canvas/text/renderer.ts"],"mappings":";;;;;UAQiB;EACf,uBAAuB;EACvB,KAAK;EACL,eAAe;EACf;;EAEA;EACA,0BAA0B;EAC1B,mBAAmB,MAAM,WAAW;;UAGrB,qBAAqB;EACpC,IAAI;EACJ,qBAAqB;EACrB,cAAc;EACd"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getCanvasKit } from "../../canvaskit.js";
|
|
2
2
|
import "../../text/emoji.js";
|
|
3
3
|
import { shownText } from "../../text/case.js";
|
|
4
|
-
import { fontManager } from "../../text/font/manager.js";
|
|
5
4
|
import { outlineInk, savedGlyphInk } from "./ink.js";
|
|
6
5
|
import { keycapFrame } from "./keycap.js";
|
|
7
6
|
import { characterFamily, laidOutGlyphs } from "./placed.js";
|
|
8
7
|
import { textDecorationRects } from "./decorations.js";
|
|
9
8
|
import { buildParagraph } from "./layout/build.js";
|
|
10
9
|
import { faceStyleName } from "../../text/font/names.js";
|
|
10
|
+
import { leaseFontProvider } from "../../text/font/provider.js";
|
|
11
11
|
import { nextGraphemeBoundary } from "../../text/graphemes.js";
|
|
12
12
|
import { EMPTY_EXPORT_RUNTIME } from "@pairdraw/fig/node-change";
|
|
13
13
|
import { textVerticalOffset } from "@pairdraw/scene-graph/text";
|
|
@@ -191,11 +191,11 @@ function needsShaping(graph) {
|
|
|
191
191
|
* last to finish releases it; a provider with no share left is deleted.
|
|
192
192
|
*/
|
|
193
193
|
async function withTextShaper(canvasKit, use) {
|
|
194
|
-
const
|
|
194
|
+
const lease = leaseFontProvider(canvasKit);
|
|
195
195
|
try {
|
|
196
|
-
return await use((node) => shapeText(canvasKit, provider, node));
|
|
196
|
+
return await use((node) => shapeText(canvasKit, lease.provider, node));
|
|
197
197
|
} finally {
|
|
198
|
-
|
|
198
|
+
lease.release();
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
/** Run a `.fig` or Figma clipboard write with text shaping. */
|