@pairdraw/core 0.20.0 → 0.21.1
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/canvas/noise/render.js +1 -1
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +6 -3
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +12 -7
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/noise/tile.d.ts.map +1 -1
- package/dist/canvas/noise/tile.js +2 -1
- package/dist/canvas/noise/tile.js.map +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.js +4 -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 +23 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- 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/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.d.ts +20 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +28 -4
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +4 -3
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shaders/compile.d.ts +3 -1
- package/dist/canvas/shaders/compile.d.ts.map +1 -1
- package/dist/canvas/shaders/compile.js +12 -3
- package/dist/canvas/shaders/compile.js.map +1 -1
- package/dist/canvas/shaders/draw.d.ts.map +1 -1
- package/dist/canvas/shaders/draw.js +10 -3
- package/dist/canvas/shaders/draw.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +8 -17
- 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.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.map +1 -1
- package/dist/canvas/texture.js +2 -1
- package/dist/canvas/texture.js.map +1 -1
- package/dist/design-memory/rules.js +1 -1
- package/dist/editor/clipboard/assets.d.ts.map +1 -1
- package/dist/editor/clipboard/assets.js +2 -2
- 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.js +2 -2
- package/dist/editor/clipboard/export.js.map +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/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/eyedropper.d.ts +1 -1
- package/dist/editor/eyedropper.d.ts.map +1 -1
- package/dist/editor/eyedropper.js +6 -3
- package/dist/editor/eyedropper.js.map +1 -1
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +3 -2
- package/dist/editor/history/atomic-tool.js.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/variables.js +3 -3
- package/dist/editor/variables.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 +6 -1
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +12 -5
- package/dist/figma-api/index.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.map +1 -1
- package/dist/figma-api/proxy.js +3 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +20 -4
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +49 -3
- package/dist/figma-api/reactions.js.map +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/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 +13 -12
- 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/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/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/drift.js +2 -2
- package/dist/io/formats/design-tokens/sync/drift.js.map +1 -1
- 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/label.js +1 -1
- package/dist/io/formats/drawio/paint.js +1 -1
- package/dist/io/formats/drawio/warnings.d.ts +17 -2
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
- package/dist/io/formats/drawio/warnings.js +15 -8
- 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 +2 -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/html/index.d.ts +1 -0
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +5 -3
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/html/vectors.js +1 -0
- 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/mermaid/styles.js +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/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +13 -2
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/pptx/style.js +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 +9 -4
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +6 -3
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +12 -11
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/effects.js +2 -2
- package/dist/io/formats/svg/effects.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +4 -2
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +4 -1
- package/dist/io/formats/svg/filter.d.ts.map +1 -1
- package/dist/io/formats/svg/filter.js +6 -2
- package/dist/io/formats/svg/filter.js.map +1 -1
- package/dist/io/formats/svg/grain.js +1 -1
- package/dist/io/formats/svg/grain.js.map +1 -1
- 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/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/layout.js +2 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +11 -4
- package/dist/io/formats.js.map +1 -1
- package/dist/io/index.d.ts +2 -2
- 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 +12 -3
- package/dist/io/types.d.ts.map +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/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.js +24 -1
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.js +1 -1
- package/dist/lint/linter.js +2 -2
- package/dist/lint/linter.js.map +1 -1
- 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/index.d.ts +3 -3
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +5 -5
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +1 -1
- package/dist/prototype/scene.js +1 -1
- package/dist/rpc/analyze-commands.js +1 -1
- package/dist/rpc/read-commands.d.ts +2 -2
- package/dist/rpc/read-commands.js +3 -3
- 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/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 +4 -3
- package/dist/text/index.js +4 -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/tools/analyze/colors.js +1 -1
- package/dist/tools/analyze/responsive/index.js +7 -18
- package/dist/tools/analyze/responsive/index.js.map +1 -1
- 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 +2 -1
- package/dist/tools/analyze.js +2 -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/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/basic.js +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +1 -3
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +2 -2
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.js +1 -1
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +5 -2
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +3 -3
- 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/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.js +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 +2 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/modify/effects.js +1 -1
- package/dist/tools/modify/effects.js.map +1 -1
- 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 +57 -5
- 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 +3 -3
- package/dist/tools/modify/text.js.map +1 -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/libraries.js +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.map +1 -1
- package/dist/tools/read/space.js +0 -2
- 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.js +3 -1
- package/dist/tools/registry/core.js.map +1 -1
- package/dist/tools/schema.d.ts +6 -4
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +9 -5
- 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/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/vectorize.d.ts.map +1 -1
- package/dist/tools/vector/vectorize.js +6 -4
- package/dist/tools/vector/vectorize.js.map +1 -1
- package/dist/tools/video-host.d.ts.map +1 -1
- package/dist/tools/video-host.js +5 -3
- package/dist/tools/video-host.js.map +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 +9 -9
- package/src/canvas/noise/render.ts +1 -1
- package/src/canvas/noise/shader.ts +13 -5
- package/src/canvas/noise/tile.ts +2 -1
- 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 +4 -4
- package/src/canvas/renderer/methods.ts +1 -0
- package/src/canvas/renderer/pipeline.ts +21 -3
- package/src/canvas/renderer/retained-backing.ts +2 -1
- package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
- package/src/canvas/renderer.ts +36 -11
- package/src/canvas/scene.ts +4 -3
- package/src/canvas/shaders/compile.ts +14 -3
- package/src/canvas/shaders/draw.ts +11 -4
- package/src/canvas/shaders/effect.ts +8 -19
- 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 +2 -1
- 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 +2 -2
- package/src/editor/clipboard.ts +74 -20
- package/src/editor/components/properties.ts +3 -2
- package/src/editor/eyedropper.ts +14 -4
- package/src/editor/history/atomic-tool.ts +3 -2
- package/src/editor/structure/state.ts +2 -1
- package/src/editor/text.ts +2 -1
- package/src/editor/variables.ts +3 -3
- package/src/figma-api/fresh-read.ts +57 -0
- package/src/figma-api/graph-ref.ts +13 -0
- package/src/figma-api/index.ts +12 -4
- package/src/figma-api/pending-layout.ts +7 -3
- package/src/figma-api/pending-sync.ts +4 -1
- package/src/figma-api/proxy.ts +2 -1
- package/src/figma-api/reactions.ts +91 -10
- package/src/figma-api/variables/index.ts +5 -4
- 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/plan/index.ts +6 -5
- package/src/io/formats/design-tokens/plan/styles.ts +37 -10
- package/src/io/formats/design-tokens/styles.ts +10 -7
- package/src/io/formats/design-tokens/sync/drift.ts +6 -4
- package/src/io/formats/design-tokens/values.ts +15 -8
- package/src/io/formats/drawio/warnings.ts +28 -9
- package/src/io/formats/fig/export/index.ts +36 -3
- package/src/io/formats/fig/export/patch/index.ts +4 -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/html/index.ts +9 -3
- package/src/io/formats/html/vectors.ts +1 -0
- package/src/io/formats/mermaid/layers.ts +2 -2
- package/src/io/formats/pdf/export.ts +1 -0
- package/src/io/formats/pdf/prepare.ts +6 -6
- package/src/io/formats/pen/index.ts +15 -4
- package/src/io/formats/raster/render.ts +12 -4
- package/src/io/formats/svg/defs.ts +26 -14
- package/src/io/formats/svg/effects.ts +2 -2
- package/src/io/formats/svg/export.ts +17 -3
- package/src/io/formats/svg/filter.ts +12 -2
- package/src/io/formats/svg/grain.ts +1 -1
- package/src/io/formats/svg/import.ts +6 -3
- package/src/io/formats/svg/text/export.ts +10 -8
- package/src/io/formats/svg/text/layout.ts +2 -2
- package/src/io/formats.ts +18 -5
- package/src/io/index.ts +1 -0
- package/src/io/subgraph.ts +4 -1
- package/src/io/types.ts +10 -0
- package/src/kiwi/fig/session/options.ts +4 -1
- package/src/layout/yoga-helpers.ts +8 -0
- package/src/layout.ts +47 -1
- package/src/lint/linter.ts +1 -1
- package/src/pairdraw-api/comments.ts +6 -0
- package/src/pairdraw-api/index.ts +7 -9
- package/src/rpc/read-commands.ts +4 -4
- package/src/rpc/variables-command.ts +2 -2
- package/src/text/font/provider.ts +26 -0
- package/src/text/font/{status.ts → readiness.ts} +13 -9
- package/src/text/index.ts +2 -1
- package/src/text/prepare.ts +9 -4
- package/src/tools/analyze/responsive/index.ts +8 -15
- package/src/tools/analyze/responsive/widths.ts +63 -0
- package/src/tools/analyze.ts +2 -0
- package/src/tools/codegen/tokens.ts +4 -2
- package/src/tools/comments.ts +6 -4
- package/src/tools/component-catalog.ts +5 -3
- package/src/tools/create/html.ts +0 -3
- package/src/tools/create/icons.ts +1 -1
- package/src/tools/create/svg.ts +4 -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/html-host.ts +5 -3
- package/src/tools/image-ai/apply.ts +0 -2
- package/src/tools/image-ai/service.ts +5 -3
- package/src/tools/index.ts +2 -0
- package/src/tools/modify/effects.ts +1 -1
- 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 +3 -2
- package/src/tools/modify/text.ts +15 -11
- package/src/tools/prompts/codegen.md +2 -1
- package/src/tools/read/css.ts +365 -0
- package/src/tools/read/reactions.ts +3 -2
- package/src/tools/read/space.ts +0 -2
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/core.ts +3 -2
- package/src/tools/schema.ts +14 -5
- package/src/tools/script/host.ts +6 -3
- package/src/tools/variables/collections.ts +1 -1
- package/src/tools/variables/values.ts +16 -5
- package/src/tools/vector/vectorize.ts +10 -4
- package/src/tools/video-host.ts +5 -3
- 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
|
@@ -104,7 +104,8 @@ function strokeOutlinePath(r, node, outline, spread) {
|
|
|
104
104
|
* Skia blur rectangles and rounded rectangles analytically.
|
|
105
105
|
*/
|
|
106
106
|
function drawMaskShadow(r, canvas, effect, blendMode, draw) {
|
|
107
|
-
|
|
107
|
+
const color = r.renderColor(effect.color);
|
|
108
|
+
r.auxFill.setColor(r.color4f(color.r, color.g, color.b, color.a));
|
|
108
109
|
r.auxFill.setMaskFilter(r.getCachedMaskBlur(blurSigma(effect.radius)));
|
|
109
110
|
r.auxFill.setImageFilter(null);
|
|
110
111
|
setPaintBlendMode(r, r.auxFill, blendMode);
|
|
@@ -174,7 +175,8 @@ function clipOutShapeKnockout(r, canvas, node, outline) {
|
|
|
174
175
|
*/
|
|
175
176
|
function drawShapeInnerShadow(r, canvas, node, effect, spread, isolated = false) {
|
|
176
177
|
const sp = spread;
|
|
177
|
-
|
|
178
|
+
const color = r.renderColor(effect.color);
|
|
179
|
+
r.auxFill.setColor(r.ck.Color4f(color.r, color.g, color.b, color.a));
|
|
178
180
|
r.auxFill.setImageFilter(r.getCachedDecalBlur(blurSigma(effect.radius)));
|
|
179
181
|
canvas.save();
|
|
180
182
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape.js","names":[],"sources":["../../../src/canvas/shadows/shape.ts"],"sourcesContent":["import type { Canvas, Path } from 'canvaskit-wasm'\n\nimport type { BlendMode, ShadowEffect, SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { blurSigma } from '@pairdraw/scene-graph/geometry'\n\nimport { setPaintBlendMode } from '#core/canvas/blend'\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport { drawOutline, makeNodeShapePath, nodeHasRadius, withNodeOutline } from '#core/canvas/shapes'\nimport { sideStrokeRRects, strokeAlignShare } from '#core/canvas/strokes/sides'\n\nimport { fillsCastShadow, paintCastsShadow } from './silhouette'\n\n/** Whether the node's fill outline is its whole shadow: it casts from a fill and no stroke reaches past it. */\nexport function castsFromOwnShape(node: SceneNode): boolean {\n return (\n node.type !== 'TEXT' &&\n node.type !== 'BOOLEAN_OPERATION' &&\n !isPartialArc(node) &&\n fillsCastShadow(node) &&\n node.strokes.every((stroke) => !paintCastsShadow(stroke) || stroke.align === 'INSIDE')\n )\n}\n\n/** Whether a layer's drop shadow comes from its own outline alone, which the paths below draw. */\nexport function castsOwnShapeDropShadow(node: SceneNode, spread: number): boolean {\n return regularStrokeOutline(node, spread) !== null || castsFromOwnShape(node)\n}\n\nconst OUTLINE_SHAPE_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'RECTANGLE',\n 'ROUNDED_RECTANGLE',\n 'ELLIPSE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'SECTION'\n])\n\n/**\n * A pie, donut, or open arc. The shadow paths below draw ellipses as ovals, so these take the\n * silhouette, which draws the arc itself.\n */\nfunction isPartialArc(node: SceneNode): boolean {\n const arc = node.type === 'ELLIPSE' ? node.arcData : null\n if (!arc) return false\n return arc.innerRadius > 0 || Math.abs(arc.endingAngle - arc.startingAngle) < 2 * Math.PI - 1e-6\n}\n\n/** Distances from each side of a rectangle: top, right, bottom, left. */\ntype Sides = readonly [number, number, number, number]\n\nconst evenSides = (distance: number): Sides => [distance, distance, distance, distance]\n\n/** How far a shape's stroke reaches past each side of it (`outset`) and into it (`inset`). */\nexport interface StrokeOutline {\n outset: Sides\n inset: Sides\n /** Every side reaches as far, so the outline is the shape itself grown. */\n even: boolean\n align: Stroke['align']\n}\n\nfunction sideOutline([top, right, bottom, left]: Sides, align: Stroke['align']): StrokeOutline {\n const share = strokeAlignShare(align)\n return {\n outset: [top * share, right * share, bottom * share, left * share],\n inset: [top * (1 - share), right * (1 - share), bottom * (1 - share), left * (1 - share)],\n even: false,\n align\n }\n}\n\n/**\n * For a rectangle, ellipse, or frame with at most one plain stroke, the outline that stroke\n * gives it; null when the outline is not the shape grown, as with dashes or a sharp corner the\n * stroke does not miter. Sides of their own weights give the ring of `sideStrokeRRects`, but\n * measured on Figma 126, a shadow with a spread grows every side by the layer's single weight.\n */\nexport function regularStrokeOutline(node: SceneNode, spread: number): StrokeOutline | null {\n if (!OUTLINE_SHAPE_TYPES.has(node.type) || isPartialArc(node)) return null\n const strokes = node.strokes.filter(paintCastsShadow)\n if (strokes.length === 0) return evenOutline(0, 'INSIDE')\n const [stroke] = strokes\n if (strokes.length > 1 || stroke.dashPattern?.length) return null\n const sharp = node.type !== 'ELLIPSE' && !nodeHasRadius(node)\n if (node.independentStrokeWeights && node.type !== 'ELLIPSE') {\n const sides: Sides = [\n node.borderTopWeight,\n node.borderRightWeight,\n node.borderBottomWeight,\n node.borderLeftWeight\n ]\n if (sides.every((weight) => weight === sides[0])) return evenOutline(sides[0], stroke.align)\n if (spread !== 0) return evenOutline(node.strokeWeight, stroke.align)\n return sideOutline(sides, stroke.align)\n }\n if (sharp && (stroke.join ?? node.strokeJoin) !== 'MITER') return null\n return evenOutline(stroke.weight, stroke.align)\n}\n\nfunction evenOutline(weight: number, align: Stroke['align']): StrokeOutline {\n const outset = weight * strokeAlignShare(align)\n return { outset: evenSides(outset), inset: evenSides(weight - outset), even: true, align }\n}\n\n/** The outline the node's stroke gives it, grown further by `spread`. */\nfunction strokeOutlinePath(\n r: SkiaRenderer,\n node: SceneNode,\n outline: StrokeOutline,\n spread: number\n): Path {\n if (outline.even) return makeNodeShapePath(r, node, outline.outset[0] + spread)\n const builder = new r.ck.PathBuilder()\n builder.addRRect(sideStrokeRRects(node, outline.align, spread).outer)\n return builder.detachAndDelete()\n}\n\n/**\n * Draws what `draw` paints with `r.auxFill` as a shadow, offset and blurred as a mask, which lets\n * Skia blur rectangles and rounded rectangles analytically.\n */\nfunction drawMaskShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n blendMode: BlendMode | undefined,\n draw: () => void\n): void {\n r.auxFill.setColor(r.color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a))\n r.auxFill.setMaskFilter(r.getCachedMaskBlur(blurSigma(effect.radius)))\n r.auxFill.setImageFilter(null)\n setPaintBlendMode(r, r.auxFill, blendMode)\n canvas.save()\n try {\n canvas.translate(effect.offset.x, effect.offset.y)\n draw()\n } finally {\n canvas.restore()\n r.auxFill.setMaskFilter(null)\n r.auxFill.setBlendMode(r.ck.BlendMode.SrcOver)\n }\n}\n\n/** Draws a shadow cast by the node's fill outline grown by `spread`. */\nexport function drawShapeDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n blendMode: BlendMode | undefined\n): void {\n drawMaskShadow(r, canvas, effect, blendMode, () =>\n withNodeOutline(r, node, (outline) => drawOutline(canvas, outline, r.auxFill), spread)\n )\n}\n\n/** Whether the stroke reaches past the shape on any side, so it grows the shadow. */\nexport function strokeGrowsOutline(outline: StrokeOutline): boolean {\n return outline.outset.some((distance) => distance > 0)\n}\n\n/** Draws a shadow cast by the shape grown by its stroke and the spread. */\nexport function drawOutlineDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n outline: StrokeOutline,\n spread: number,\n blendMode: BlendMode | undefined\n): void {\n drawMaskShadow(r, canvas, effect, blendMode, () => {\n if (outline.even) {\n const grow = outline.outset[0] + spread\n withNodeOutline(r, node, (shape) => drawOutline(canvas, shape, r.auxFill), grow)\n } else canvas.drawRRect(sideStrokeRRects(node, outline.align, spread).outer, r.auxFill)\n })\n}\n\n/** Draws the shadow of a stroke without a fill: the ring between its outline and its inner edge. */\nexport function drawRingDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n outline: StrokeOutline,\n spread: number,\n blendMode: BlendMode | undefined\n): void {\n const builder = new r.ck.PathBuilder()\n if (outline.even) {\n const outer = strokeOutlinePath(r, node, outline, spread)\n builder.addPath(outer)\n outer.delete()\n const inset = outline.inset[0] + spread\n if (inset * 2 < Math.min(node.width, node.height)) {\n const inner = makeNodeShapePath(r, node, -inset)\n builder.addPath(inner)\n inner.delete()\n }\n } else {\n const { outer, inner } = sideStrokeRRects(node, outline.align, spread)\n builder.addRRect(outer)\n if (inner) builder.addRRect(inner)\n }\n const ring = builder.detachAndDelete()\n ring.setFillType(r.ck.FillType.EvenOdd)\n try {\n drawMaskShadow(r, canvas, effect, blendMode, () => canvas.drawPath(ring, r.auxFill))\n } finally {\n ring.delete()\n }\n}\n\n/** Clips out the area a shape hides its shadow under: the shape grown by its stroke. */\nexport function clipOutShapeKnockout(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n outline: StrokeOutline | null\n): void {\n const path = outline ? strokeOutlinePath(r, node, outline, 0) : makeNodeShapePath(r, node)\n canvas.clipPath(path, r.ck.ClipOp.Difference, true)\n path.delete()\n}\n\n/**\n * Draws an inner shadow: everything outside the shape, moved by the shadow's offset and grown\n * into the shape by its spread, blurred and clipped to the shape. `isolated` says the shape's fills\n * sit in a layer of their own, as `isolatesInnerShadows` has them.\n */\nexport function drawShapeInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n isolated = false\n): void {\n const sp = spread\n r.auxFill.setColor(r.ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a))\n r.auxFill.setImageFilter(r.getCachedDecalBlur(blurSigma(effect.radius)))\n\n canvas.save()\n try {\n const expand = effect.radius * 2\n const { x: offsetX, y: offsetY } = effect.offset\n const spreadPadding = sp < 0 ? -sp : 0\n const area = new r.ck.PathBuilder()\n area.addRect(\n r.ck.LTRBRect(\n Math.min(-expand, -expand + offsetX - spreadPadding),\n Math.min(-expand, -expand + offsetY - spreadPadding),\n Math.max(node.width + expand, node.width + expand + offsetX + spreadPadding),\n Math.max(node.height + expand, node.height + expand + offsetY + spreadPadding)\n )\n )\n const shrunk = makeNodeShapePath(r, node, -sp)\n const moved = new r.ck.PathBuilder()\n moved.addPath(shrunk, r.ck.Matrix.translated(offsetX, offsetY))\n shrunk.delete()\n const areaPath = area.detachAndDelete()\n const shapePath = moved.detachAndDelete()\n const shadowPath = r.ck.Path.MakeFromOp(areaPath, shapePath, r.ck.PathOp.Difference)\n areaPath.delete()\n shapePath.delete()\n if (!shadowPath) return\n if (isolated) {\n // Alone over the fills, the shadow takes the fill out from under it before it is clipped,\n // so the outline's antialiased edge applies once and no fill shows through it.\n r.auxFill.setBlendMode(r.ck.BlendMode.DstOut)\n canvas.drawPath(shadowPath, r.auxFill)\n r.auxFill.setBlendMode(r.ck.BlendMode.Plus)\n } else {\n setPaintBlendMode(r, r.auxFill, effect.blendMode)\n }\n r.clipNodeShape(canvas, node)\n canvas.drawPath(shadowPath, r.auxFill)\n shadowPath.delete()\n } finally {\n canvas.restore()\n r.auxFill.setImageFilter(null)\n r.auxFill.setBlendMode(r.ck.BlendMode.SrcOver)\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,kBAAkB,MAA0B;CAC1D,OACE,KAAK,SAAS,UACd,KAAK,SAAS,uBACd,CAAC,aAAa,IAAI,KAClB,gBAAgB,IAAI,KACpB,KAAK,QAAQ,OAAO,WAAW,CAAC,iBAAiB,MAAM,KAAK,OAAO,UAAU,QAAQ;AAEzF;;AAGA,SAAgB,wBAAwB,MAAiB,QAAyB;CAChF,OAAO,qBAAqB,MAAM,MAAM,MAAM,QAAQ,kBAAkB,IAAI;AAC9E;AAEA,MAAM,sCAAsD,IAAI,IAAuB;CACrF;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;AAMD,SAAS,aAAa,MAA0B;CAC9C,MAA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C,YAAY;EACjB,IAAI,UAAU;GAGZ,EAAE,QAAQ,aAAa,EAAE,GAAG,UAAU,MAAM;GAC5C,OAAO,SAAS,YAAY,EAAE,OAAO;GACrC,EAAE,QAAQ,aAAa,EAAE,GAAG,UAAU,IAAI;EAC5C,OACE,kBAAkB,GAAG,EAAE,SAAS,OAAO,SAAS;EAElD,EAAE,cAAc,QAAQ,IAAI;EAC5B,OAAO,SAAS,YAAY,EAAE,OAAO;EACrC,WAAW,OAAO;CACpB,UAAU;EACR,OAAO,QAAQ;EACf,EAAE,QAAQ,eAAe,IAAI;EAC7B,EAAE,QAAQ,aAAa,EAAE,GAAG,UAAU,OAAO;CAC/C;AACF"}
|
|
1
|
+
{"version":3,"file":"shape.js","names":[],"sources":["../../../src/canvas/shadows/shape.ts"],"sourcesContent":["import type { Canvas, Path } from 'canvaskit-wasm'\n\nimport type { BlendMode, ShadowEffect, SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { blurSigma } from '@pairdraw/scene-graph/geometry'\n\nimport { setPaintBlendMode } from '#core/canvas/blend'\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport { drawOutline, makeNodeShapePath, nodeHasRadius, withNodeOutline } from '#core/canvas/shapes'\nimport { sideStrokeRRects, strokeAlignShare } from '#core/canvas/strokes/sides'\n\nimport { fillsCastShadow, paintCastsShadow } from './silhouette'\n\n/** Whether the node's fill outline is its whole shadow: it casts from a fill and no stroke reaches past it. */\nexport function castsFromOwnShape(node: SceneNode): boolean {\n return (\n node.type !== 'TEXT' &&\n node.type !== 'BOOLEAN_OPERATION' &&\n !isPartialArc(node) &&\n fillsCastShadow(node) &&\n node.strokes.every((stroke) => !paintCastsShadow(stroke) || stroke.align === 'INSIDE')\n )\n}\n\n/** Whether a layer's drop shadow comes from its own outline alone, which the paths below draw. */\nexport function castsOwnShapeDropShadow(node: SceneNode, spread: number): boolean {\n return regularStrokeOutline(node, spread) !== null || castsFromOwnShape(node)\n}\n\nconst OUTLINE_SHAPE_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'RECTANGLE',\n 'ROUNDED_RECTANGLE',\n 'ELLIPSE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'SECTION'\n])\n\n/**\n * A pie, donut, or open arc. The shadow paths below draw ellipses as ovals, so these take the\n * silhouette, which draws the arc itself.\n */\nfunction isPartialArc(node: SceneNode): boolean {\n const arc = node.type === 'ELLIPSE' ? node.arcData : null\n if (!arc) return false\n return arc.innerRadius > 0 || Math.abs(arc.endingAngle - arc.startingAngle) < 2 * Math.PI - 1e-6\n}\n\n/** Distances from each side of a rectangle: top, right, bottom, left. */\ntype Sides = readonly [number, number, number, number]\n\nconst evenSides = (distance: number): Sides => [distance, distance, distance, distance]\n\n/** How far a shape's stroke reaches past each side of it (`outset`) and into it (`inset`). */\nexport interface StrokeOutline {\n outset: Sides\n inset: Sides\n /** Every side reaches as far, so the outline is the shape itself grown. */\n even: boolean\n align: Stroke['align']\n}\n\nfunction sideOutline([top, right, bottom, left]: Sides, align: Stroke['align']): StrokeOutline {\n const share = strokeAlignShare(align)\n return {\n outset: [top * share, right * share, bottom * share, left * share],\n inset: [top * (1 - share), right * (1 - share), bottom * (1 - share), left * (1 - share)],\n even: false,\n align\n }\n}\n\n/**\n * For a rectangle, ellipse, or frame with at most one plain stroke, the outline that stroke\n * gives it; null when the outline is not the shape grown, as with dashes or a sharp corner the\n * stroke does not miter. Sides of their own weights give the ring of `sideStrokeRRects`, but\n * measured on Figma 126, a shadow with a spread grows every side by the layer's single weight.\n */\nexport function regularStrokeOutline(node: SceneNode, spread: number): StrokeOutline | null {\n if (!OUTLINE_SHAPE_TYPES.has(node.type) || isPartialArc(node)) return null\n const strokes = node.strokes.filter(paintCastsShadow)\n if (strokes.length === 0) return evenOutline(0, 'INSIDE')\n const [stroke] = strokes\n if (strokes.length > 1 || stroke.dashPattern?.length) return null\n const sharp = node.type !== 'ELLIPSE' && !nodeHasRadius(node)\n if (node.independentStrokeWeights && node.type !== 'ELLIPSE') {\n const sides: Sides = [\n node.borderTopWeight,\n node.borderRightWeight,\n node.borderBottomWeight,\n node.borderLeftWeight\n ]\n if (sides.every((weight) => weight === sides[0])) return evenOutline(sides[0], stroke.align)\n if (spread !== 0) return evenOutline(node.strokeWeight, stroke.align)\n return sideOutline(sides, stroke.align)\n }\n if (sharp && (stroke.join ?? node.strokeJoin) !== 'MITER') return null\n return evenOutline(stroke.weight, stroke.align)\n}\n\nfunction evenOutline(weight: number, align: Stroke['align']): StrokeOutline {\n const outset = weight * strokeAlignShare(align)\n return { outset: evenSides(outset), inset: evenSides(weight - outset), even: true, align }\n}\n\n/** The outline the node's stroke gives it, grown further by `spread`. */\nfunction strokeOutlinePath(\n r: SkiaRenderer,\n node: SceneNode,\n outline: StrokeOutline,\n spread: number\n): Path {\n if (outline.even) return makeNodeShapePath(r, node, outline.outset[0] + spread)\n const builder = new r.ck.PathBuilder()\n builder.addRRect(sideStrokeRRects(node, outline.align, spread).outer)\n return builder.detachAndDelete()\n}\n\n/**\n * Draws what `draw` paints with `r.auxFill` as a shadow, offset and blurred as a mask, which lets\n * Skia blur rectangles and rounded rectangles analytically.\n */\nfunction drawMaskShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n blendMode: BlendMode | undefined,\n draw: () => void\n): void {\n const color = r.renderColor(effect.color)\n r.auxFill.setColor(r.color4f(color.r, color.g, color.b, color.a))\n r.auxFill.setMaskFilter(r.getCachedMaskBlur(blurSigma(effect.radius)))\n r.auxFill.setImageFilter(null)\n setPaintBlendMode(r, r.auxFill, blendMode)\n canvas.save()\n try {\n canvas.translate(effect.offset.x, effect.offset.y)\n draw()\n } finally {\n canvas.restore()\n r.auxFill.setMaskFilter(null)\n r.auxFill.setBlendMode(r.ck.BlendMode.SrcOver)\n }\n}\n\n/** Draws a shadow cast by the node's fill outline grown by `spread`. */\nexport function drawShapeDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n blendMode: BlendMode | undefined\n): void {\n drawMaskShadow(r, canvas, effect, blendMode, () =>\n withNodeOutline(r, node, (outline) => drawOutline(canvas, outline, r.auxFill), spread)\n )\n}\n\n/** Whether the stroke reaches past the shape on any side, so it grows the shadow. */\nexport function strokeGrowsOutline(outline: StrokeOutline): boolean {\n return outline.outset.some((distance) => distance > 0)\n}\n\n/** Draws a shadow cast by the shape grown by its stroke and the spread. */\nexport function drawOutlineDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n outline: StrokeOutline,\n spread: number,\n blendMode: BlendMode | undefined\n): void {\n drawMaskShadow(r, canvas, effect, blendMode, () => {\n if (outline.even) {\n const grow = outline.outset[0] + spread\n withNodeOutline(r, node, (shape) => drawOutline(canvas, shape, r.auxFill), grow)\n } else canvas.drawRRect(sideStrokeRRects(node, outline.align, spread).outer, r.auxFill)\n })\n}\n\n/** Draws the shadow of a stroke without a fill: the ring between its outline and its inner edge. */\nexport function drawRingDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n outline: StrokeOutline,\n spread: number,\n blendMode: BlendMode | undefined\n): void {\n const builder = new r.ck.PathBuilder()\n if (outline.even) {\n const outer = strokeOutlinePath(r, node, outline, spread)\n builder.addPath(outer)\n outer.delete()\n const inset = outline.inset[0] + spread\n if (inset * 2 < Math.min(node.width, node.height)) {\n const inner = makeNodeShapePath(r, node, -inset)\n builder.addPath(inner)\n inner.delete()\n }\n } else {\n const { outer, inner } = sideStrokeRRects(node, outline.align, spread)\n builder.addRRect(outer)\n if (inner) builder.addRRect(inner)\n }\n const ring = builder.detachAndDelete()\n ring.setFillType(r.ck.FillType.EvenOdd)\n try {\n drawMaskShadow(r, canvas, effect, blendMode, () => canvas.drawPath(ring, r.auxFill))\n } finally {\n ring.delete()\n }\n}\n\n/** Clips out the area a shape hides its shadow under: the shape grown by its stroke. */\nexport function clipOutShapeKnockout(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n outline: StrokeOutline | null\n): void {\n const path = outline ? strokeOutlinePath(r, node, outline, 0) : makeNodeShapePath(r, node)\n canvas.clipPath(path, r.ck.ClipOp.Difference, true)\n path.delete()\n}\n\n/**\n * Draws an inner shadow: everything outside the shape, moved by the shadow's offset and grown\n * into the shape by its spread, blurred and clipped to the shape. `isolated` says the shape's fills\n * sit in a layer of their own, as `isolatesInnerShadows` has them.\n */\nexport function drawShapeInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n isolated = false\n): void {\n const sp = spread\n const color = r.renderColor(effect.color)\n r.auxFill.setColor(r.ck.Color4f(color.r, color.g, color.b, color.a))\n r.auxFill.setImageFilter(r.getCachedDecalBlur(blurSigma(effect.radius)))\n\n canvas.save()\n try {\n const expand = effect.radius * 2\n const { x: offsetX, y: offsetY } = effect.offset\n const spreadPadding = sp < 0 ? -sp : 0\n const area = new r.ck.PathBuilder()\n area.addRect(\n r.ck.LTRBRect(\n Math.min(-expand, -expand + offsetX - spreadPadding),\n Math.min(-expand, -expand + offsetY - spreadPadding),\n Math.max(node.width + expand, node.width + expand + offsetX + spreadPadding),\n Math.max(node.height + expand, node.height + expand + offsetY + spreadPadding)\n )\n )\n const shrunk = makeNodeShapePath(r, node, -sp)\n const moved = new r.ck.PathBuilder()\n moved.addPath(shrunk, r.ck.Matrix.translated(offsetX, offsetY))\n shrunk.delete()\n const areaPath = area.detachAndDelete()\n const shapePath = moved.detachAndDelete()\n const shadowPath = r.ck.Path.MakeFromOp(areaPath, shapePath, r.ck.PathOp.Difference)\n areaPath.delete()\n shapePath.delete()\n if (!shadowPath) return\n if (isolated) {\n // Alone over the fills, the shadow takes the fill out from under it before it is clipped,\n // so the outline's antialiased edge applies once and no fill shows through it.\n r.auxFill.setBlendMode(r.ck.BlendMode.DstOut)\n canvas.drawPath(shadowPath, r.auxFill)\n r.auxFill.setBlendMode(r.ck.BlendMode.Plus)\n } else {\n setPaintBlendMode(r, r.auxFill, effect.blendMode)\n }\n r.clipNodeShape(canvas, node)\n canvas.drawPath(shadowPath, r.auxFill)\n shadowPath.delete()\n } finally {\n canvas.restore()\n r.auxFill.setImageFilter(null)\n r.auxFill.setBlendMode(r.ck.BlendMode.SrcOver)\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,kBAAkB,MAA0B;CAC1D,OACE,KAAK,SAAS,UACd,KAAK,SAAS,uBACd,CAAC,aAAa,IAAI,KAClB,gBAAgB,IAAI,KACpB,KAAK,QAAQ,OAAO,WAAW,CAAC,iBAAiB,MAAM,KAAK,OAAO,UAAU,QAAQ;AAEzF;;AAGA,SAAgB,wBAAwB,MAAiB,QAAyB;CAChF,OAAO,qBAAqB,MAAM,MAAM,MAAM,QAAQ,kBAAkB,IAAI;AAC9E;AAEA,MAAM,sCAAsD,IAAI,IAAuB;CACrF;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;AAMD,SAAS,aAAa,MAA0B;CAC9C,MAAM,MAAM,KAAK,SAAS,YAAY,KAAK,UAAU;CACrD,IAAI,CAAC,KAAK,OAAO;CACjB,OAAO,IAAI,cAAc,KAAK,KAAK,IAAI,IAAI,cAAc,IAAI,aAAa,IAAI,IAAI,KAAK,KAAK;AAC9F;AAKA,MAAM,aAAa,aAA4B;CAAC;CAAU;CAAU;CAAU;AAAQ;AAWtF,SAAS,YAAY,CAAC,KAAK,OAAO,QAAQ,OAAc,OAAuC;CAC7F,MAAM,QAAQ,iBAAiB,KAAK;CACpC,OAAO;EACL,QAAQ;GAAC,MAAM;GAAO,QAAQ;GAAO,SAAS;GAAO,OAAO;EAAK;EACjE,OAAO;GAAC,OAAO,IAAI;GAAQ,SAAS,IAAI;GAAQ,UAAU,IAAI;GAAQ,QAAQ,IAAI;EAAM;EACxF,MAAM;EACN;CACF;AACF;;;;;;;AAQA,SAAgB,qBAAqB,MAAi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mappings":";;;;;KAwCY;;;;;;;
|
|
1
|
+
{"version":3,"file":"shadows.d.ts","names":[],"sources":["../../src/canvas/shadows.ts"],"mappings":";;;;;KAwCY;;;;;;;iBAuVI,qBAAqB,MAAM;;;;;iBAgB3B,cACd,GAAG,cACH,QAAQ,QACR,MAAM,WACN,OAAO,YACP,MAAM;;;;;iBA+BQ,mBACd,GAAG,cACH,QAAQ,QACR,OAAO,YACP,MAAM,WACN"}
|
package/dist/canvas/shadows.js
CHANGED
|
@@ -53,7 +53,8 @@ function spreadFilter(r, spread) {
|
|
|
53
53
|
/** Draws a shadow cast by whatever `draw` paints: its alpha is the outline, offset and blurred. */
|
|
54
54
|
function drawSilhouetteDropShadow(r, canvas, effect, spread, bounds, blendMode, draw) {
|
|
55
55
|
const ck = r.ck;
|
|
56
|
-
const
|
|
56
|
+
const drawn = r.renderColor(effect.color);
|
|
57
|
+
const color = ck.Color4f(drawn.r, drawn.g, drawn.b, drawn.a);
|
|
57
58
|
const sigma = blurSigma(effect.radius);
|
|
58
59
|
const morphology = spreadFilter(r, spread);
|
|
59
60
|
const filter = morphology ? ck.ImageFilter.MakeDropShadowOnly(effect.offset.x, effect.offset.y, sigma, sigma, color, morphology) : r.getCachedDropShadow(effect.offset.x, effect.offset.y, sigma, color);
|
|
@@ -179,7 +180,8 @@ function drawSilhouetteInnerShadow(r, canvas, effect, bounds, draw) {
|
|
|
179
180
|
r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver);
|
|
180
181
|
draw();
|
|
181
182
|
r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcIn);
|
|
182
|
-
|
|
183
|
+
const drawn = r.renderColor(effect.color);
|
|
184
|
+
tintFilter = ck.ColorFilter.MakeBlend(ck.Color4f(drawn.r, drawn.g, drawn.b, drawn.a), ck.BlendMode.SrcIn);
|
|
183
185
|
r.effectLayerPaint.setColorFilter(tintFilter);
|
|
184
186
|
canvas.saveLayer(r.effectLayerPaint, bounds);
|
|
185
187
|
restoreCount++;
|
|
@@ -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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AQ,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;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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ACF;;;;;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":";;;;;;;;;;;;;;;AAqBA,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,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AI,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;;AAmC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;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,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,SAAS,qBAAqB,MAAiB,aAAoC;CACjF,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K,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,SAAS,qBAAqB,MAAiB,aAAoC;CACjF,MAAM,MAAM,KAAK,UAAU,MACxB,SAAS,eAAe,KAAK,SAAS,cAAc,KAAK,QAAQ,KAAK,MACzE;CACA,OAAO,KAAK,MAAM,iBAAiB,KAAA,IAAY,IAAI,MAAM,eAAe,KAAK;AAC/E;AAEA,SAAS,yBAAyB,MAA2B;CAC3D,OAAO,gBAAgB,IAAI,CA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EhD,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,
|