@motionscript/core 0.1.0-alpha.5 → 0.1.0-alpha.6
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/CHANGELOG.md +27 -0
- package/dist/browser/chunks/chunk-2RIYH36X.js +3 -0
- package/dist/browser/chunks/{chunk-QG6C23IJ.js.map → chunk-2RIYH36X.js.map} +4 -4
- package/dist/browser/chunks/chunk-DDJN3QII.js +15 -0
- package/dist/browser/chunks/chunk-DDJN3QII.js.map +7 -0
- package/dist/browser/chunks/chunk-DHB4COFY.js +2 -0
- package/dist/browser/chunks/chunk-DHB4COFY.js.map +7 -0
- package/dist/browser/chunks/chunk-EJDPYDQI.js +5 -0
- package/dist/browser/chunks/chunk-EJDPYDQI.js.map +7 -0
- package/dist/browser/chunks/chunk-XAWE4EAK.js +2 -0
- package/dist/browser/chunks/chunk-XAWE4EAK.js.map +7 -0
- package/dist/browser/component.js +1 -1
- package/dist/browser/component.js.map +4 -4
- package/dist/browser/experimental.js +2 -0
- package/dist/browser/experimental.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/jsx-jsx-dev-runtime.js +1 -1
- package/dist/browser/jsx-jsx-runtime.js +1 -1
- package/dist/browser/manifest.json +2 -1
- package/dist/browser/sdk.js +1 -1
- package/dist/component/api.d.ts +508 -0
- package/dist/component/api.d.ts.map +1 -0
- package/dist/component/api.js +4 -0
- package/dist/component/api.js.map +1 -0
- package/dist/component/builtins/audio.d.ts +26 -0
- package/dist/component/builtins/audio.d.ts.map +1 -0
- package/dist/component/builtins/audio.js +41 -0
- package/dist/component/builtins/audio.js.map +1 -0
- package/dist/component/builtins/canvas3d.d.ts +98 -0
- package/dist/component/builtins/canvas3d.d.ts.map +1 -0
- package/dist/component/builtins/canvas3d.js +21 -0
- package/dist/component/builtins/canvas3d.js.map +1 -0
- package/dist/component/builtins/composite.d.ts +56 -0
- package/dist/component/builtins/composite.d.ts.map +1 -0
- package/dist/component/builtins/composite.js +25 -0
- package/dist/component/builtins/composite.js.map +1 -0
- package/dist/component/builtins/geometry.d.ts +505 -0
- package/dist/component/builtins/geometry.d.ts.map +1 -0
- package/dist/component/builtins/geometry.js +107 -0
- package/dist/component/builtins/geometry.js.map +1 -0
- package/dist/component/builtins/layout.d.ts +88 -0
- package/dist/component/builtins/layout.d.ts.map +1 -0
- package/dist/component/builtins/layout.js +84 -0
- package/dist/component/builtins/layout.js.map +1 -0
- package/dist/component/builtins/media.d.ts +95 -0
- package/dist/component/builtins/media.d.ts.map +1 -0
- package/dist/component/builtins/media.js +149 -0
- package/dist/component/builtins/media.js.map +1 -0
- package/dist/component/builtins/providers.d.ts +23 -0
- package/dist/component/builtins/providers.d.ts.map +1 -0
- package/dist/component/builtins/providers.js +30 -0
- package/dist/component/builtins/providers.js.map +1 -0
- package/dist/component/builtins/text.d.ts +193 -0
- package/dist/component/builtins/text.d.ts.map +1 -0
- package/dist/component/builtins/text.js +113 -0
- package/dist/component/builtins/text.js.map +1 -0
- package/dist/component/builtins/three.d.ts +1085 -0
- package/dist/component/builtins/three.d.ts.map +1 -0
- package/dist/component/builtins/three.js +265 -0
- package/dist/component/builtins/three.js.map +1 -0
- package/dist/component/clip-of.d.ts +5 -0
- package/dist/component/clip-of.d.ts.map +1 -0
- package/dist/component/clip-of.js +33 -0
- package/dist/component/clip-of.js.map +1 -0
- package/dist/component/commands-for.d.ts +19 -0
- package/dist/component/commands-for.d.ts.map +1 -0
- package/dist/component/commands-for.js +5 -0
- package/dist/component/commands-for.js.map +1 -0
- package/dist/component/component-audio.d.ts +9 -0
- package/dist/component/component-audio.d.ts.map +1 -0
- package/dist/component/component-audio.js +18 -0
- package/dist/component/component-audio.js.map +1 -0
- package/dist/component/component2d.d.ts +9 -0
- package/dist/component/component2d.d.ts.map +1 -0
- package/dist/component/component2d.js +239 -0
- package/dist/component/component2d.js.map +1 -0
- package/dist/component/component3d.d.ts +9 -0
- package/dist/component/component3d.d.ts.map +1 -0
- package/dist/component/component3d.js +99 -0
- package/dist/component/component3d.js.map +1 -0
- package/dist/component/factory.d.ts +63 -0
- package/dist/component/factory.d.ts.map +1 -0
- package/dist/component/factory.js +313 -0
- package/dist/component/factory.js.map +1 -0
- package/dist/component/modules/aim.d.ts +30 -0
- package/dist/component/modules/aim.d.ts.map +1 -0
- package/dist/component/modules/aim.js +39 -0
- package/dist/component/modules/aim.js.map +1 -0
- package/dist/component/modules/corners.d.ts +13 -0
- package/dist/component/modules/corners.d.ts.map +1 -0
- package/dist/component/modules/corners.js +12 -0
- package/dist/component/modules/corners.js.map +1 -0
- package/dist/component/modules/flow.d.ts +26 -0
- package/dist/component/modules/flow.d.ts.map +1 -0
- package/dist/component/modules/flow.js +55 -0
- package/dist/component/modules/flow.js.map +1 -0
- package/dist/component/modules/material.d.ts +40 -0
- package/dist/component/modules/material.d.ts.map +1 -0
- package/dist/component/modules/material.js +75 -0
- package/dist/component/modules/material.js.map +1 -0
- package/dist/component/modules/paint.d.ts +71 -0
- package/dist/component/modules/paint.d.ts.map +1 -0
- package/dist/component/modules/paint.js +106 -0
- package/dist/component/modules/paint.js.map +1 -0
- package/dist/component/modules/shapes.d.ts +31 -0
- package/dist/component/modules/shapes.d.ts.map +1 -0
- package/dist/component/modules/shapes.js +43 -0
- package/dist/component/modules/shapes.js.map +1 -0
- package/dist/component/modules/text-layout.d.ts +26 -0
- package/dist/component/modules/text-layout.d.ts.map +1 -0
- package/dist/component/modules/text-layout.js +57 -0
- package/dist/component/modules/text-layout.js.map +1 -0
- package/dist/component/modules/text-style.d.ts +48 -0
- package/dist/component/modules/text-style.d.ts.map +1 -0
- package/dist/component/modules/text-style.js +63 -0
- package/dist/component/modules/text-style.js.map +1 -0
- package/dist/component/modules/three-entries.d.ts +23 -0
- package/dist/component/modules/three-entries.d.ts.map +1 -0
- package/dist/component/modules/three-entries.js +41 -0
- package/dist/component/modules/three-entries.js.map +1 -0
- package/dist/component/modules/view3d.d.ts +55 -0
- package/dist/component/modules/view3d.d.ts.map +1 -0
- package/dist/component/modules/view3d.js +160 -0
- package/dist/component/modules/view3d.js.map +1 -0
- package/dist/component/timeline.d.ts +22 -0
- package/dist/component/timeline.d.ts.map +1 -0
- package/dist/component/timeline.js +128 -0
- package/dist/component/timeline.js.map +1 -0
- package/dist/component/type-def.d.ts +26 -0
- package/dist/component/type-def.d.ts.map +1 -0
- package/dist/component/type-def.js +16 -0
- package/dist/component/type-def.js.map +1 -0
- package/dist/component/types.d.ts +91 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component/types.js +88 -0
- package/dist/component/types.js.map +1 -0
- package/dist/component/views.d.ts +121 -0
- package/dist/component/views.d.ts.map +1 -0
- package/dist/component/views.js +413 -0
- package/dist/component/views.js.map +1 -0
- package/dist/component.d.ts +4 -5
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +3 -5
- package/dist/component.js.map +1 -1
- package/dist/document/audio.d.ts +9 -1
- package/dist/document/audio.d.ts.map +1 -1
- package/dist/document/audio.js +41 -0
- package/dist/document/audio.js.map +1 -1
- package/dist/document/builtins.d.ts.map +1 -1
- package/dist/document/builtins.js +9 -27
- package/dist/document/builtins.js.map +1 -1
- package/dist/document/command-traits.js +3 -0
- package/dist/document/command-traits.js.map +1 -1
- package/dist/document/diff.d.ts.map +1 -1
- package/dist/document/diff.js +3 -3
- package/dist/document/diff.js.map +1 -1
- package/dist/document/doc-index.d.ts.map +1 -1
- package/dist/document/doc-index.js +3 -3
- package/dist/document/doc-index.js.map +1 -1
- package/dist/document/node-descriptor.d.ts +6 -0
- package/dist/document/node-descriptor.d.ts.map +1 -1
- package/dist/document/node-descriptor.js.map +1 -1
- package/dist/document/placement.js +2 -2
- package/dist/document/placement.js.map +1 -1
- package/dist/document/registry.d.ts +6 -11
- package/dist/document/registry.d.ts.map +1 -1
- package/dist/document/registry.js +17 -17
- package/dist/document/registry.js.map +1 -1
- package/dist/document/settled-index.d.ts +49 -0
- package/dist/document/settled-index.d.ts.map +1 -0
- package/dist/document/settled-index.js +247 -0
- package/dist/document/settled-index.js.map +1 -0
- package/dist/document/timeline.d.ts +27 -1
- package/dist/document/timeline.d.ts.map +1 -1
- package/dist/document/timeline.js +98 -2
- package/dist/document/timeline.js.map +1 -1
- package/dist/experimental.d.ts +22 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +20 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/nodes/audio/index.d.ts +2 -2
- package/dist/nodes/audio/index.d.ts.map +1 -1
- package/dist/nodes/audio/index.js +0 -2
- package/dist/nodes/audio/index.js.map +1 -1
- package/dist/nodes/audio/sound-node.d.ts +2 -1
- package/dist/nodes/audio/sound-node.d.ts.map +1 -1
- package/dist/nodes/audio/sound-node.js +3 -0
- package/dist/nodes/audio/sound-node.js.map +1 -1
- package/dist/nodes/index.d.ts +39 -27
- package/dist/nodes/index.d.ts.map +1 -1
- package/dist/nodes/index.js +16 -30
- package/dist/nodes/index.js.map +1 -1
- package/dist/nodes/node/node.d.ts +7 -1
- package/dist/nodes/node/node.d.ts.map +1 -1
- package/dist/nodes/node/node.js +23 -8
- package/dist/nodes/node/node.js.map +1 -1
- package/dist/nodes/root/canvas2d-node.d.ts +2 -1
- package/dist/nodes/root/canvas2d-node.d.ts.map +1 -1
- package/dist/nodes/root/canvas2d-node.js +3 -0
- package/dist/nodes/root/canvas2d-node.js.map +1 -1
- package/dist/nodes/text/richtext-node.d.ts +0 -5
- package/dist/nodes/text/richtext-node.d.ts.map +1 -1
- package/dist/nodes/text/richtext-node.js +5 -71
- package/dist/nodes/text/richtext-node.js.map +1 -1
- package/dist/nodes/text/text-base.d.ts +5 -22
- package/dist/nodes/text/text-base.d.ts.map +1 -1
- package/dist/nodes/text/text-base.js +12 -363
- package/dist/nodes/text/text-base.js.map +1 -1
- package/dist/nodes/text/text-layout.d.ts +87 -0
- package/dist/nodes/text/text-layout.d.ts.map +1 -0
- package/dist/nodes/text/text-layout.js +368 -0
- package/dist/nodes/text/text-layout.js.map +1 -0
- package/dist/nodes/three/canvas3d-node.d.ts +3 -1
- package/dist/nodes/three/canvas3d-node.d.ts.map +1 -1
- package/dist/nodes/three/canvas3d-node.js +6 -0
- package/dist/nodes/three/canvas3d-node.js.map +1 -1
- package/dist/runtime/clip-instance.d.ts +4 -1
- package/dist/runtime/clip-instance.d.ts.map +1 -1
- package/dist/runtime/clip-instance.js +17 -3
- package/dist/runtime/clip-instance.js.map +1 -1
- package/dist/runtime/clip-store.d.ts +9 -0
- package/dist/runtime/clip-store.d.ts.map +1 -1
- package/dist/runtime/clip-store.js +78 -0
- package/dist/runtime/clip-store.js.map +1 -1
- package/dist/runtime/node-picking.d.ts.map +1 -1
- package/dist/runtime/node-picking.js +6 -7
- package/dist/runtime/node-picking.js.map +1 -1
- package/dist/runtime/node-picking3d.d.ts +11 -4
- package/dist/runtime/node-picking3d.d.ts.map +1 -1
- package/dist/runtime/node-picking3d.js +5 -0
- package/dist/runtime/node-picking3d.js.map +1 -1
- package/dist/runtime/text-geometry.d.ts.map +1 -1
- package/dist/runtime/text-geometry.js +7 -3
- package/dist/runtime/text-geometry.js.map +1 -1
- package/dist/sdk/index.d.ts +35 -14
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +47 -42
- package/dist/sdk/index.js.map +1 -1
- package/dist/tween/command.d.ts +12 -0
- package/dist/tween/command.d.ts.map +1 -1
- package/dist/tween/command.js +14 -0
- package/dist/tween/command.js.map +1 -1
- package/package.json +6 -1
- package/dist/browser/chunks/chunk-FUZVFT3W.js +0 -18
- package/dist/browser/chunks/chunk-FUZVFT3W.js.map +0 -7
- package/dist/browser/chunks/chunk-QG6C23IJ.js +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"richtext-node.js","sourceRoot":"","sources":["../../../src/nodes/text/richtext-node.ts"],"names":[],"mappings":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,SAAS;YACzB,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC;YACpC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,IAAI,CAAC;SACzC,CAAC,CAAC,CAAC;IACR,CAAC;CACJ;AAjIuB;IAJnB,QAAQ,CAAC;QACN,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,CAAC,CAAoC,EAAc,EAAE,CACzD,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAClD,CAAC;uCAAoC;AAaT;IAA5B,QAAQ,EAAE;4CAAqC;AACJ;IAA3C,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;0CAAmC;AAChB;IAA5C,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;4CAAqC;AACd;IAAjD,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;2CAAuC;AAC5B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;+CAAwC;AACpB;IAA5C,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;4CAAqC;AACd;IAAjD,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;2CAAuC;AACpB;IAAlD,QAAQ,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;yCAAmC","sourcesContent":["import { RenderContext2D } from \"@/render/render-context2d\";\r\nimport { Graphics2D } from \"@/render/graphics2d\";\r\nimport { SizeConstraints } from \"@/layout/constraints\";\r\nimport { MeasureContext2D } from \"@/render/measure-context\";\r\nimport { FillResolved } from \"@/attributes/shape/fill/union\";\r\nimport type { AssetScope } from \"@/assets/scope\";\r\nimport { StrokeResolved } from \"@/attributes/shape/stroke/stroke\";\r\nimport { Size2D } from \"@/attributes/layout/size\";\r\nimport { PaintNode, PaintProps } from \"@/nodes/2d/paint-node\";\r\nimport { property } from \"@/attributes/properties/decorator\";\r\nimport { NodeConfig } from \"@/nodes/2d/node2d\";\r\nimport { ContextMap } from \"@/util/context\";\r\nimport type { FontStyle, ResolvedTextSpan, TextAlign, TextSpan } from \"@/attributes/text/types\";\r\nimport { textOps } from \"@/attributes/text/ops\";\r\nimport { applyTextDefaults } from \"./default-text-style-node\";\r\n\r\n\r\nexport interface RichTextProps extends PaintProps {\r\n spans: TextSpan | TextSpan[];\r\n /** Default font family inherited by spans that don't set one. */\r\n fontFamily: string;\r\n /** Default font size inherited by spans that don't set one. */\r\n fontSize: number;\r\n /** Default font weight inherited by spans that don't set one. */\r\n fontWeight: number;\r\n /** Default font style inherited by spans that don't set one. */\r\n fontStyle: FontStyle;\r\n /** Default letter spacing inherited by spans that don't set one. */\r\n letterSpacing: number;\r\n /** Line height multiplier applied to each run's font size. */\r\n lineHeight: number;\r\n textAlign: TextAlign;\r\n /**\r\n * Name of a typography preset from `theme.typography` (e.g. `\"body\"`).\r\n * Supplies any node-level default (fontSize, fontWeight, …) not set\r\n * explicitly here, which `runs()` then folds into each span. An explicit prop\r\n * wins over the preset; the preset wins over an inherited `<DefaultTextStyle>`.\r\n */\r\n variant: string;\r\n}\r\n\r\nexport class RichText extends PaintNode<RichTextProps> {\r\n\r\n\r\n\r\n @property({\r\n default: [],\r\n mapper: (v: TextSpan | TextSpan[] | undefined): TextSpan[] =>\r\n v == null ? [] : Array.isArray(v) ? v : [v],\r\n }) declare readonly spans: TextSpan[];\r\n /**\r\n * The family this text is set in. **No default** — it comes from the cascade\r\n * in `applyTextDefaults`: what the author passed, else a `variant` preset,\r\n * else the nearest enclosing `<DefaultTextStyle>`, else the theme's `default`\r\n * typography preset.\r\n *\r\n * A literal default here would sit *under* all four and quietly win whenever\r\n * every one of them was silent, which is precisely the case worth hearing\r\n * about: text set in a face nobody chose is text whose font was never\r\n * declared and so never loaded. Left unset, the renderer says so instead —\r\n * see `requireFontFamily`.\r\n */\r\n @property() declare readonly fontFamily: string;\r\n @property({ default: 48 }) declare readonly fontSize: number;\r\n @property({ default: 400 }) declare readonly fontWeight: number;\r\n @property({ default: 'normal' }) declare readonly fontStyle: FontStyle;\r\n @property({ default: 0 }) declare readonly letterSpacing: number;\r\n @property({ default: 1.2 }) declare readonly lineHeight: number;\r\n @property({ default: 'center' }) declare readonly textAlign: TextAlign;\r\n @property({ default: undefined }) declare readonly variant?: string;\r\n\r\n constructor(props: NodeConfig<RichText, RichTextProps>) {\r\n super(props);\r\n }\r\n\r\n // Inherit text-style defaults from the nearest ancestor <DefaultTextStyle> for\r\n // any default the author didn't set; these node-level defaults are then folded\r\n // into each span. Context-value application (spans are fixed structure), so it\r\n // lives in resolveContext — runs once after the tree + context exist. See Text.\r\n protected override resolveContext(ctx: ContextMap): void {\r\n applyTextDefaults(this, this._props as Record<string, unknown> | undefined, { autofit: false });\r\n }\r\n\r\n // RichText always sizes to its own laid-out spans — it has no children\r\n // to hug — so it ignores the base has-children default and always hugs.\r\n protected override applyDefaultSize(props?: NodeConfig<RichText, RichTextProps>): void {\r\n this.applyProp(\"height\", props?.height ?? \"hug\");\r\n this.applyProp(\"width\", props?.width ?? \"hug\");\r\n }\r\n\r\n /**\r\n * Flatten the nested span tree against this node's defaults, returning\r\n * leaf runs in document order. Children inherit any style fields the\r\n * parent set; explicit fields on a child override them.\r\n */\r\n runs(): ResolvedTextSpan[] {\r\n return textOps.flatten(this.spans, {\r\n fontFamily: this.fontFamily,\r\n fontSize: this.fontSize,\r\n fontWeight: this.fontWeight,\r\n fontStyle: this.fontStyle,\r\n letterSpacing: this.letterSpacing,\r\n fill: this.fill as FillResolved[],\r\n stroke: this.stroke as StrokeResolved[],\r\n });\r\n }\r\n\r\n /**\r\n * Every run's face and paint — a span may name either where the node doesn't.\r\n * {@link runs} is the flattening {@link measure} and the render use too, which\r\n * keeps the declaration and the draw from naming different families.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n for (const run of this.runs()) {\r\n if (run.fontFamily) assets.font(run.fontFamily, run.fontWeight);\r\n assets.fill(run.fill);\r\n for (const stroke of run.stroke) assets.fill(stroke.fill);\r\n }\r\n }\r\n\r\n measure(constraints: SizeConstraints, scope: MeasureContext2D): Partial<Size2D> {\r\n const runs = this.runs();\r\n let lineW = 0;\r\n let maxLineH = 0;\r\n let totalW = 0;\r\n let totalH = 0;\r\n\r\n const finishLine = () => {\r\n if (lineW > totalW) totalW = lineW;\r\n totalH += maxLineH;\r\n lineW = 0;\r\n maxLineH = 0;\r\n };\r\n\r\n for (const run of runs) {\r\n const lh = run.fontSize * this.lineHeight;\r\n const segments = run.text.split(\"\\n\");\r\n for (let i = 0; i < segments.length; i++) {\r\n if (i > 0) finishLine();\r\n // Called unconditionally (even for an empty segment, where\r\n // measureTextCached short-circuits to 0) so an empty run still\r\n // contributes its line height.\r\n lineW += scope.measureText(segments[i], run.fontSize, run.fontFamily, run.fontWeight, run.letterSpacing, run.fontStyle).width;\r\n if (lh > maxLineH) maxLineH = lh;\r\n }\r\n }\r\n finishLine();\r\n\r\n if (totalH === 0) totalH = this.fontSize * this.lineHeight;\r\n\r\n const wm = this.width;\r\n const hm = this.height;\r\n\r\n const resolvedW = typeof wm === \"number\"\r\n ? wm\r\n : wm === \"hug\"\r\n ? totalW\r\n : constraints.maxWidth ?? 0;\r\n\r\n const resolvedH = typeof hm === \"number\"\r\n ? hm\r\n : hm === \"hug\"\r\n ? totalH\r\n : constraints.maxHeight ?? 0;\r\n\r\n return { width: resolvedW, height: resolvedH };\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n ctx.draw(new Graphics2D().richText({\r\n spans: this.runs(),\r\n lineHeight: this.lineHeight,\r\n textAlign: this.textAlign,\r\n width: this.layoutBounds?.width ?? 0,\r\n height: this.layoutBounds?.height ?? 0,\r\n }));\r\n }\r\n}\r\n"]}
|
|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,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAEkB,UAAU,CAAC,GAAoB;QAC9C,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;CACJ;AA9DuB;IAJnB,QAAQ,CAAC;QACN,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,CAAC,CAAoC,EAAc,EAAE,CACzD,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAClD,CAAC;uCAAoC;AAaT;IAA5B,QAAQ,EAAE;4CAAqC;AACJ;IAA3C,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;0CAAmC;AAChB;IAA5C,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;4CAAqC;AACd;IAAjD,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;2CAAuC;AAC5B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;+CAAwC;AACpB;IAA5C,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;4CAAqC;AACd;IAAjD,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;2CAAuC;AACpB;IAAlD,QAAQ,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;yCAAmC","sourcesContent":["import { RenderContext2D } from \"@/render/render-context2d\";\r\nimport { Graphics2D } from \"@/render/graphics2d\";\r\nimport { SizeConstraints } from \"@/layout/constraints\";\r\nimport { MeasureContext2D } from \"@/render/measure-context\";\r\nimport type { AssetScope } from \"@/assets/scope\";\r\nimport { Size2D } from \"@/attributes/layout/size\";\r\nimport { PaintNode, PaintProps } from \"@/nodes/2d/paint-node\";\r\nimport { property } from \"@/attributes/properties/decorator\";\r\nimport { NodeConfig } from \"@/nodes/2d/node2d\";\r\nimport { ContextMap } from \"@/util/context\";\r\nimport type { FontStyle, ResolvedTextSpan, TextAlign, TextSpan } from \"@/attributes/text/types\";\r\nimport { applyTextDefaults } from \"./default-text-style-node\";\r\nimport { declareRichAssets, measureRich, richRuns, richState } from \"./text-layout\";\r\n\r\n\r\nexport interface RichTextProps extends PaintProps {\r\n spans: TextSpan | TextSpan[];\r\n /** Default font family inherited by spans that don't set one. */\r\n fontFamily: string;\r\n /** Default font size inherited by spans that don't set one. */\r\n fontSize: number;\r\n /** Default font weight inherited by spans that don't set one. */\r\n fontWeight: number;\r\n /** Default font style inherited by spans that don't set one. */\r\n fontStyle: FontStyle;\r\n /** Default letter spacing inherited by spans that don't set one. */\r\n letterSpacing: number;\r\n /** Line height multiplier applied to each run's font size. */\r\n lineHeight: number;\r\n textAlign: TextAlign;\r\n /**\r\n * Name of a typography preset from `theme.typography` (e.g. `\"body\"`).\r\n * Supplies any node-level default (fontSize, fontWeight, …) not set\r\n * explicitly here, which `runs()` then folds into each span. An explicit prop\r\n * wins over the preset; the preset wins over an inherited `<DefaultTextStyle>`.\r\n */\r\n variant: string;\r\n}\r\n\r\nexport class RichText extends PaintNode<RichTextProps> {\r\n\r\n\r\n\r\n @property({\r\n default: [],\r\n mapper: (v: TextSpan | TextSpan[] | undefined): TextSpan[] =>\r\n v == null ? [] : Array.isArray(v) ? v : [v],\r\n }) declare readonly spans: TextSpan[];\r\n /**\r\n * The family this text is set in. **No default** — it comes from the cascade\r\n * in `applyTextDefaults`: what the author passed, else a `variant` preset,\r\n * else the nearest enclosing `<DefaultTextStyle>`, else the theme's `default`\r\n * typography preset.\r\n *\r\n * A literal default here would sit *under* all four and quietly win whenever\r\n * every one of them was silent, which is precisely the case worth hearing\r\n * about: text set in a face nobody chose is text whose font was never\r\n * declared and so never loaded. Left unset, the renderer says so instead —\r\n * see `requireFontFamily`.\r\n */\r\n @property() declare readonly fontFamily: string;\r\n @property({ default: 48 }) declare readonly fontSize: number;\r\n @property({ default: 400 }) declare readonly fontWeight: number;\r\n @property({ default: 'normal' }) declare readonly fontStyle: FontStyle;\r\n @property({ default: 0 }) declare readonly letterSpacing: number;\r\n @property({ default: 1.2 }) declare readonly lineHeight: number;\r\n @property({ default: 'center' }) declare readonly textAlign: TextAlign;\r\n @property({ default: undefined }) declare readonly variant?: string;\r\n\r\n constructor(props: NodeConfig<RichText, RichTextProps>) {\r\n super(props);\r\n }\r\n\r\n // Inherit text-style defaults from the nearest ancestor <DefaultTextStyle> for\r\n // any default the author didn't set; these node-level defaults are then folded\r\n // into each span. Context-value application (spans are fixed structure), so it\r\n // lives in resolveContext — runs once after the tree + context exist. See Text.\r\n protected override resolveContext(ctx: ContextMap): void {\r\n applyTextDefaults(this, this._props as Record<string, unknown> | undefined, { autofit: false });\r\n }\r\n\r\n // RichText always sizes to its own laid-out spans — it has no children\r\n // to hug — so it ignores the base has-children default and always hugs.\r\n protected override applyDefaultSize(props?: NodeConfig<RichText, RichTextProps>): void {\r\n this.applyProp(\"height\", props?.height ?? \"hug\");\r\n this.applyProp(\"width\", props?.width ?? \"hug\");\r\n }\r\n\r\n /**\r\n * Flatten the nested span tree against this node's defaults, returning\r\n * leaf runs in document order. Children inherit any style fields the\r\n * parent set; explicit fields on a child override them.\r\n */\r\n runs(): ResolvedTextSpan[] {\r\n return richRuns(this);\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n declareRichAssets(this, assets);\r\n }\r\n\r\n measure(constraints: SizeConstraints, scope: MeasureContext2D): Partial<Size2D> {\r\n return measureRich(this, constraints, scope);\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n ctx.draw(new Graphics2D().richText(richState(this, this.layoutBounds)));\r\n }\r\n}\r\n"]}
|
|
@@ -9,7 +9,7 @@ import { RenderContext2D } from "../../render/render-context2d.js";
|
|
|
9
9
|
import { TextSegment, TextState } from "../../render/descriptors/text.js";
|
|
10
10
|
import type { AssetScope } from "../../assets/scope.js";
|
|
11
11
|
import { PathData } from "../../render/descriptors/path.js";
|
|
12
|
-
import {
|
|
12
|
+
import type { TextSelection } from "./text-selection.js";
|
|
13
13
|
/** The fields a string is shaped and set by, shared by every node that draws glyphs. */
|
|
14
14
|
export interface TextBaseProps extends PaintProps {
|
|
15
15
|
fontSize: number | 'autofit';
|
|
@@ -99,37 +99,20 @@ export declare abstract class TextBase<P extends TextBaseProps = TextBaseProps>
|
|
|
99
99
|
protected resolveContext(ctx: ContextMap): void;
|
|
100
100
|
protected applyDefaultSize(props?: NodeConfig<any, P>): void;
|
|
101
101
|
measure(constraints: SizeConstraints, scope: MeasureContext2D): Partial<Size2D>;
|
|
102
|
-
/**
|
|
103
|
-
* Split the string into contiguous pieces at every style boundary, resolving
|
|
104
|
-
* each piece's effective overrides per the overlap rule: later-created
|
|
105
|
-
* selections win for transform/paint/font; opacity multiplies across all
|
|
106
|
-
* selections covering the piece. Also folds in the Write On reveal window
|
|
107
|
-
* (see below). Returns null when neither is active, so rendering keeps its
|
|
108
|
-
* single-op path.
|
|
109
|
-
*
|
|
110
|
-
* Text-on-path has no pieces in v1 — the string is laid along the path as
|
|
111
|
-
* one run — so a node with a path is answered `null` before anything else.
|
|
112
|
-
*/
|
|
102
|
+
/** The string cut at every style boundary — see {@link textSegments}. */
|
|
113
103
|
protected buildSegments(): TextSegment[] | null;
|
|
114
|
-
/**
|
|
115
|
-
* The node's own face and paint, plus whatever a selection puts on part of the
|
|
116
|
-
* string. Naming a family here is what lets it load *before* layout, rather
|
|
117
|
-
* than being discovered by measuring text against the fallback face.
|
|
118
|
-
*/
|
|
119
104
|
declareAssets(assets: AssetScope): void;
|
|
120
105
|
/**
|
|
121
106
|
* The descriptor this node draws itself as, at the current frame.
|
|
122
107
|
*
|
|
123
|
-
* `@internal` — split out
|
|
124
|
-
*
|
|
125
|
-
* Deriving the two separately is how a caret ends up half a pixel — or, once
|
|
126
|
-
* `'autofit'` or wrapping is in play, half a line — away from its glyph.
|
|
108
|
+
* `@internal` — split out so `node-picking`'s caret geometry is measured
|
|
109
|
+
* from the same state that gets painted.
|
|
127
110
|
*/
|
|
128
111
|
/** @internal */
|
|
129
112
|
_textState(): Partial<TextState>;
|
|
130
113
|
private textOpGraphics;
|
|
131
114
|
protected renderSelf(ctx: RenderContext2D): void;
|
|
132
115
|
protected renderStroke(ctx: RenderContext2D): void;
|
|
133
|
-
private
|
|
116
|
+
private _source;
|
|
134
117
|
}
|
|
135
118
|
//# sourceMappingURL=text-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-base.d.ts","sourceRoot":"","sources":["../../../src/nodes/text/text-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE9H,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"text-base.d.ts","sourceRoot":"","sources":["../../../src/nodes/text/text-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,QAA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S,CAAC;IAQhC,OAAO,CAAC,cAAc;cAKH,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;cAatC,YAAY,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;IAQ3D,OAAO,CAAC,OAAO;CAGlB"}
|
|
@@ -8,8 +8,7 @@ import { textOps } from "../../attributes/text/ops.js";
|
|
|
8
8
|
import { PaintNode } from "../../nodes/2d/paint-node.js";
|
|
9
9
|
import { property } from "../../attributes/properties/decorator.js";
|
|
10
10
|
import { Graphics2D } from "../../render/graphics2d.js";
|
|
11
|
-
import {
|
|
12
|
-
import { AUTOFIT_PROBE_SIZE } from "./text-selection.js";
|
|
11
|
+
import { declareGlyphAssets, measureGlyphs, textSegments, textState } from "./text-layout.js";
|
|
13
12
|
import { applyTextDefaults } from "./default-text-style-node.js";
|
|
14
13
|
/**
|
|
15
14
|
* **A node whose box is the box of some shaped glyphs.**
|
|
@@ -62,268 +61,25 @@ export class TextBase extends PaintNode {
|
|
|
62
61
|
this.applyProp("width", props?.width ?? (autofit ? "fill" : "hug"));
|
|
63
62
|
}
|
|
64
63
|
measure(constraints, scope) {
|
|
65
|
-
|
|
66
|
-
// line box. Size the node to the path (node-local coords, like Path).
|
|
67
|
-
const glyphPath = this.glyphPath;
|
|
68
|
-
if (glyphPath != null) {
|
|
69
|
-
const { width, height } = pathOps.size(glyphPath);
|
|
70
|
-
const wm = this.width;
|
|
71
|
-
const hm = this.height;
|
|
72
|
-
return {
|
|
73
|
-
width: typeof wm === "number" ? wm : wm === "hug" ? width : (constraints.maxWidth ?? width),
|
|
74
|
-
height: typeof hm === "number" ? hm : hm === "hug" ? height : (constraints.maxHeight ?? height),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const measureFontSize = this.fontSize === 'autofit' ? 16 : this.fontSize;
|
|
78
|
-
const paragraphs = this._casedText().split("\n");
|
|
79
|
-
// A styled run changes the box, which is why measuring cannot read the
|
|
80
|
-
// node's five font fields and stop there: one word set two sizes up makes
|
|
81
|
-
// the line taller and the block wider, and a node that hugs its glyphs
|
|
82
|
-
// would hug a box measured for text nobody is looking at. So when
|
|
83
|
-
// selections are live the intrinsic size is summed across the *pieces*,
|
|
84
|
-
// each in its own style - see {@link measureStyledLines}.
|
|
85
|
-
const styled = this.buildSegments();
|
|
86
|
-
const lineStyles = styled === null
|
|
87
|
-
? null
|
|
88
|
-
: measureStyledLines(styled, {
|
|
89
|
-
fontFamily: this.fontFamily,
|
|
90
|
-
fontSize: measureFontSize,
|
|
91
|
-
fontStyle: this.fontStyle,
|
|
92
|
-
fontWeight: this.fontWeight,
|
|
93
|
-
letterSpacing: this.letterSpacing,
|
|
94
|
-
});
|
|
95
|
-
const lineH = measureFontSize * this.lineHeight;
|
|
96
|
-
const intrinsicW = lineStyles
|
|
97
|
-
? Math.max(...lineStyles.map(line => line.runs.reduce((w, run) => w + scope.measureText(run.text, run.fontSize, run.fontFamily, run.fontWeight, run.letterSpacing, run.fontStyle).width, 0)))
|
|
98
|
-
: Math.max(...paragraphs.map(l => scope.measureText(l, measureFontSize, this.fontFamily, this.fontWeight, this.letterSpacing, this.fontStyle).width));
|
|
99
|
-
const wm = this.width;
|
|
100
|
-
const hm = this.height;
|
|
101
|
-
const resolvedW = typeof wm === "number"
|
|
102
|
-
? wm
|
|
103
|
-
: wm === "hug"
|
|
104
|
-
? intrinsicW
|
|
105
|
-
: constraints.maxWidth ?? 0;
|
|
106
|
-
// When wrap is on and the box has a finite width narrower than the text,
|
|
107
|
-
// height needs to account for the extra lines produced by wrapping.
|
|
108
|
-
const wraps = this.wrapsText && resolvedW > 0;
|
|
109
|
-
// Each line is as tall as its tallest run, so raising one word's size
|
|
110
|
-
// opens the leading around it rather than letting it overprint the line
|
|
111
|
-
// above.
|
|
112
|
-
const lineSizes = lineStyles === null
|
|
113
|
-
? null
|
|
114
|
-
: wraps
|
|
115
|
-
? wrappedLineSizes(lineStyles, resolvedW, scope)
|
|
116
|
-
: lineStyles.map(line => Math.max(...line.runs.map(run => run.fontSize)));
|
|
117
|
-
const intrinsicH = lineSizes
|
|
118
|
-
? lineSizes.reduce((h, size) => h + size * this.lineHeight, 0)
|
|
119
|
-
: (wraps
|
|
120
|
-
? paragraphs.reduce((n, p) => n + countWrappedLines(p, resolvedW, measureFontSize, this.fontFamily, this.fontWeight, scope, this.letterSpacing, this.fontStyle), 0)
|
|
121
|
-
: paragraphs.length) * lineH;
|
|
122
|
-
// "fill" still reports the intrinsic wrapped height when measuring —
|
|
123
|
-
// it's layout (not measure) that stretches a fill child to its final
|
|
124
|
-
// box. This lets a hug ancestor see the text's real content height
|
|
125
|
-
// instead of an arbitrary borrowed constraint.
|
|
126
|
-
const resolvedH = typeof hm === "number"
|
|
127
|
-
? hm
|
|
128
|
-
: intrinsicH;
|
|
129
|
-
return { width: resolvedW, height: resolvedH };
|
|
64
|
+
return measureGlyphs(this, this._source(), constraints, scope);
|
|
130
65
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Split the string into contiguous pieces at every style boundary, resolving
|
|
133
|
-
* each piece's effective overrides per the overlap rule: later-created
|
|
134
|
-
* selections win for transform/paint/font; opacity multiplies across all
|
|
135
|
-
* selections covering the piece. Also folds in the Write On reveal window
|
|
136
|
-
* (see below). Returns null when neither is active, so rendering keeps its
|
|
137
|
-
* single-op path.
|
|
138
|
-
*
|
|
139
|
-
* Text-on-path has no pieces in v1 — the string is laid along the path as
|
|
140
|
-
* one run — so a node with a path is answered `null` before anything else.
|
|
141
|
-
*/
|
|
66
|
+
/** The string cut at every style boundary — see {@link textSegments}. */
|
|
142
67
|
buildSegments() {
|
|
143
|
-
|
|
144
|
-
return null;
|
|
145
|
-
const active = this.styledRuns().filter(s => s.ranges.length > 0 && !s.isIdentity);
|
|
146
|
-
const runs = this.styleRuns().filter(r => r.end > r.start);
|
|
147
|
-
const text = this._casedText();
|
|
148
|
-
if (text.length === 0)
|
|
149
|
-
return null;
|
|
150
|
-
// Write On: `start`/`end` are PaintNode's outline-trim fractions
|
|
151
|
-
// everywhere else, but a glyph has no path to trim geometrically — this
|
|
152
|
-
// CanvasKit build can't get glyph outlines at all (see
|
|
153
|
-
// drawTextUnionStroke in the skia-render stroke handler). Glyph nodes
|
|
154
|
-
// reinterpret the same pair as a character-reveal window instead:
|
|
155
|
-
// opacity over a character range rather than a geometric trim.
|
|
156
|
-
const hasReveal = this.start > 0 || this.end < 1;
|
|
157
|
-
// The fast path survives both: a node with no live selection and no
|
|
158
|
-
// reveal window renders as one string, exactly as it did before either
|
|
159
|
-
// existed.
|
|
160
|
-
if (active.length === 0 && runs.length === 0 && !hasReveal)
|
|
161
|
-
return null;
|
|
162
|
-
// Rounded to the nearest whole character — a hard cut, not a fade. Write
|
|
163
|
-
// On reveals one character at a time, the way DaVinci's does; a fractional
|
|
164
|
-
// in-between character read as an opinionated flourish nobody asked for.
|
|
165
|
-
const revealStart = Math.round(this.start * text.length);
|
|
166
|
-
const revealEnd = Math.round(this.end * text.length);
|
|
167
|
-
// The size every piece starts from. `'autofit'` settles on a size the
|
|
168
|
-
// *block* is measured into, which no single piece can be asked for, so
|
|
169
|
-
// the segmented path shapes at the same probe size a selection's
|
|
170
|
-
// `fontSize` override starts from - one number, stated in one place.
|
|
171
|
-
const nodeFontSize = typeof this.fontSize === "number"
|
|
172
|
-
? this.fontSize
|
|
173
|
-
: AUTOFIT_PROBE_SIZE;
|
|
174
|
-
// Boundaries at every range edge so each piece is covered uniformly.
|
|
175
|
-
const cuts = new Set([0, text.length]);
|
|
176
|
-
for (const run of runs) {
|
|
177
|
-
cuts.add(run.start);
|
|
178
|
-
cuts.add(run.end);
|
|
179
|
-
}
|
|
180
|
-
for (const sel of active) {
|
|
181
|
-
for (const r of sel.ranges) {
|
|
182
|
-
cuts.add(r.start);
|
|
183
|
-
cuts.add(r.end);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (hasReveal) {
|
|
187
|
-
cuts.add(revealStart);
|
|
188
|
-
cuts.add(revealEnd);
|
|
189
|
-
}
|
|
190
|
-
const points = [...cuts].filter(c => c >= 0 && c <= text.length).sort((a, b) => a - b);
|
|
191
|
-
const segments = [];
|
|
192
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
193
|
-
const start = points[i];
|
|
194
|
-
const end = points[i + 1];
|
|
195
|
-
if (end <= start)
|
|
196
|
-
continue;
|
|
197
|
-
const seg = {
|
|
198
|
-
text: text.slice(start, end),
|
|
199
|
-
// Every shaping field is stated, not left for the renderer to
|
|
200
|
-
// fill in: a piece whose family or size differs from the node's
|
|
201
|
-
// is the point of the model, and a segment that says nothing
|
|
202
|
-
// about one of them would be a piece the paragraph builder
|
|
203
|
-
// styles from the node while the caret measures from the
|
|
204
|
-
// segment. See {@link TextSegment}.
|
|
205
|
-
fontFamily: this.fontFamily,
|
|
206
|
-
fontSize: nodeFontSize,
|
|
207
|
-
fontStyle: this.fontStyle,
|
|
208
|
-
fontWeight: this.fontWeight,
|
|
209
|
-
letterSpacing: this.letterSpacing,
|
|
210
|
-
textDecoration: this.textDecoration,
|
|
211
|
-
opacity: 1,
|
|
212
|
-
x: 0,
|
|
213
|
-
y: 0,
|
|
214
|
-
scale: 1,
|
|
215
|
-
rotation: 0,
|
|
216
|
-
// Default to the node's paint; selections override below. Each
|
|
217
|
-
// segment is self-contained so the renderer draws runs eagerly.
|
|
218
|
-
fill: this.fill,
|
|
219
|
-
stroke: this.stroke,
|
|
220
|
-
};
|
|
221
|
-
// The document's styling first, so a selection animates *from* it.
|
|
222
|
-
for (const run of runs) {
|
|
223
|
-
if (start < run.start || end > run.end)
|
|
224
|
-
continue;
|
|
225
|
-
if (run.fontFamily !== undefined)
|
|
226
|
-
seg.fontFamily = run.fontFamily;
|
|
227
|
-
if (run.fontSize !== undefined)
|
|
228
|
-
seg.fontSize = run.fontSize;
|
|
229
|
-
if (run.fontStyle !== undefined)
|
|
230
|
-
seg.fontStyle = run.fontStyle;
|
|
231
|
-
if (run.fontWeight !== undefined)
|
|
232
|
-
seg.fontWeight = run.fontWeight;
|
|
233
|
-
if (run.letterSpacing !== undefined)
|
|
234
|
-
seg.letterSpacing = run.letterSpacing;
|
|
235
|
-
if (run.textDecoration !== undefined)
|
|
236
|
-
seg.textDecoration = run.textDecoration;
|
|
237
|
-
if (run.fill !== undefined)
|
|
238
|
-
seg.fill = run.fill;
|
|
239
|
-
if (run.stroke !== undefined)
|
|
240
|
-
seg.stroke = run.stroke;
|
|
241
|
-
}
|
|
242
|
-
// Apply in creation order: opacity multiplies, others last-wins. A
|
|
243
|
-
// shaping field a selection still holds at the node's own value is
|
|
244
|
-
// one it never touched, and must not undo a run's.
|
|
245
|
-
for (const sel of active) {
|
|
246
|
-
if (!sel.ranges.some(r => start >= r.start && end <= r.end))
|
|
247
|
-
continue;
|
|
248
|
-
const o = sel.overrides;
|
|
249
|
-
seg.opacity *= o.opacity;
|
|
250
|
-
seg.x = o.x;
|
|
251
|
-
seg.y = o.y;
|
|
252
|
-
seg.scale = o.scale;
|
|
253
|
-
seg.rotation = o.rotation;
|
|
254
|
-
if (o.fontFamily !== this.fontFamily)
|
|
255
|
-
seg.fontFamily = o.fontFamily;
|
|
256
|
-
if (o.fontSize !== nodeFontSize)
|
|
257
|
-
seg.fontSize = o.fontSize;
|
|
258
|
-
if (o.fontStyle !== this.fontStyle)
|
|
259
|
-
seg.fontStyle = o.fontStyle;
|
|
260
|
-
if (o.fontWeight !== this.fontWeight)
|
|
261
|
-
seg.fontWeight = o.fontWeight;
|
|
262
|
-
if (o.letterSpacing !== this.letterSpacing)
|
|
263
|
-
seg.letterSpacing = o.letterSpacing;
|
|
264
|
-
if (o.fill !== null)
|
|
265
|
-
seg.fill = o.fill;
|
|
266
|
-
if (o.stroke !== null)
|
|
267
|
-
seg.stroke = o.stroke;
|
|
268
|
-
}
|
|
269
|
-
if (hasReveal && !(start >= revealStart && end <= revealEnd)) {
|
|
270
|
-
seg.opacity = 0;
|
|
271
|
-
}
|
|
272
|
-
segments.push(seg);
|
|
273
|
-
}
|
|
274
|
-
return segments;
|
|
68
|
+
return textSegments(this, this._source());
|
|
275
69
|
}
|
|
276
|
-
/**
|
|
277
|
-
* The node's own face and paint, plus whatever a selection puts on part of the
|
|
278
|
-
* string. Naming a family here is what lets it load *before* layout, rather
|
|
279
|
-
* than being discovered by measuring text against the fallback face.
|
|
280
|
-
*/
|
|
281
70
|
declareAssets(assets) {
|
|
282
71
|
super.declareAssets(assets);
|
|
283
|
-
|
|
284
|
-
// whatever is registered; an `undefined` key is not a font to load.
|
|
285
|
-
if (this.fontFamily)
|
|
286
|
-
assets.font(this.fontFamily, this.fontWeight);
|
|
287
|
-
for (const segment of this.buildSegments() ?? []) {
|
|
288
|
-
const family = segment.fontFamily ?? this.fontFamily;
|
|
289
|
-
if (family)
|
|
290
|
-
assets.font(family, segment.fontWeight);
|
|
291
|
-
assets.fill(segment.fill ?? []);
|
|
292
|
-
for (const stroke of segment.stroke ?? [])
|
|
293
|
-
assets.fill(stroke.fill);
|
|
294
|
-
}
|
|
72
|
+
declareGlyphAssets(this, this._source(), assets);
|
|
295
73
|
}
|
|
296
74
|
/**
|
|
297
75
|
* The descriptor this node draws itself as, at the current frame.
|
|
298
76
|
*
|
|
299
|
-
* `@internal` — split out
|
|
300
|
-
*
|
|
301
|
-
* Deriving the two separately is how a caret ends up half a pixel — or, once
|
|
302
|
-
* `'autofit'` or wrapping is in play, half a line — away from its glyph.
|
|
77
|
+
* `@internal` — split out so `node-picking`'s caret geometry is measured
|
|
78
|
+
* from the same state that gets painted.
|
|
303
79
|
*/
|
|
304
80
|
/** @internal */
|
|
305
81
|
_textState() {
|
|
306
|
-
return
|
|
307
|
-
text: this._casedText(),
|
|
308
|
-
fontSize: this.fontSize,
|
|
309
|
-
fontFamily: this.fontFamily,
|
|
310
|
-
fontWeight: this.fontWeight,
|
|
311
|
-
fontStyle: this.fontStyle,
|
|
312
|
-
letterSpacing: this.letterSpacing,
|
|
313
|
-
lineHeight: this.lineHeight,
|
|
314
|
-
textAlign: this.textAlign,
|
|
315
|
-
verticalAlign: this.verticalAlign,
|
|
316
|
-
textDecoration: this.textDecoration,
|
|
317
|
-
wrap: this.wrapsText,
|
|
318
|
-
minFontSize: this.minFontSize,
|
|
319
|
-
width: this.layoutBounds?.width ?? 0,
|
|
320
|
-
height: this.layoutBounds?.height ?? 0,
|
|
321
|
-
// Text-on-path and selection segments are mutually exclusive in v1:
|
|
322
|
-
// `buildSegments` answers null while a path is set, and the single
|
|
323
|
-
// string is laid out along it instead.
|
|
324
|
-
segments: this.buildSegments() ?? undefined,
|
|
325
|
-
path: this.glyphPath,
|
|
326
|
-
};
|
|
82
|
+
return textState(this, this._source(), this.layoutBounds);
|
|
327
83
|
}
|
|
328
84
|
// The bare text op as a Graphics2D (no paint), plus whether selection segments
|
|
329
85
|
// are active. Glyphs have no single fillable silhouette path, so the generic
|
|
@@ -336,11 +92,8 @@ export class TextBase extends PaintNode {
|
|
|
336
92
|
renderSelf(ctx) {
|
|
337
93
|
const { g, segments } = this.textOpGraphics();
|
|
338
94
|
g.shadow(this.shadow);
|
|
339
|
-
// With segments the renderer paints each run
|
|
340
|
-
//
|
|
341
|
-
// fill/stroke ops are omitted to avoid double-painting. Text-on-path uses
|
|
342
|
-
// the normal deferred path, so its node-level fill applies here; its stroke
|
|
343
|
-
// is deferred to renderStroke.
|
|
95
|
+
// With segments the renderer paints each run with its own fill/stroke, so
|
|
96
|
+
// the node-level paint is omitted to avoid double-painting.
|
|
344
97
|
if (!segments) {
|
|
345
98
|
g.fill(this.fill);
|
|
346
99
|
}
|
|
@@ -357,8 +110,8 @@ export class TextBase extends PaintNode {
|
|
|
357
110
|
return;
|
|
358
111
|
ctx.draw(g.stroke(stroke));
|
|
359
112
|
}
|
|
360
|
-
|
|
361
|
-
return
|
|
113
|
+
_source() {
|
|
114
|
+
return { text: this.displayText(), wraps: this.wrapsText, glyphPath: this.glyphPath, selections: this.styledRuns(), runs: this.styleRuns() };
|
|
362
115
|
}
|
|
363
116
|
}
|
|
364
117
|
__decorate([
|
|
@@ -397,108 +150,4 @@ __decorate([
|
|
|
397
150
|
__decorate([
|
|
398
151
|
property({ default: undefined })
|
|
399
152
|
], TextBase.prototype, "variant", void 0);
|
|
400
|
-
/**
|
|
401
|
-
* Split `segments` into lines at every `\n`, resolving each piece against
|
|
402
|
-
* `fallback` for the fields it leaves unstated.
|
|
403
|
-
*
|
|
404
|
-
* A segment can span a line break - the cuts are made at *selection* edges, and
|
|
405
|
-
* a selection over two lines is one range - so the break has to be found inside
|
|
406
|
-
* the piece rather than between pieces. The newline itself joins neither line,
|
|
407
|
-
* which is what makes an empty line come back as a run of `""` (in the node's
|
|
408
|
-
* own style) rather than disappearing from the count.
|
|
409
|
-
*/
|
|
410
|
-
function measureStyledLines(segments, fallback) {
|
|
411
|
-
const lines = [{ runs: [] }];
|
|
412
|
-
for (const segment of segments) {
|
|
413
|
-
const style = {
|
|
414
|
-
fontFamily: segment.fontFamily ?? fallback.fontFamily,
|
|
415
|
-
fontSize: segment.fontSize ?? fallback.fontSize,
|
|
416
|
-
fontStyle: segment.fontStyle ?? fallback.fontStyle,
|
|
417
|
-
fontWeight: segment.fontWeight,
|
|
418
|
-
letterSpacing: segment.letterSpacing,
|
|
419
|
-
};
|
|
420
|
-
const parts = segment.text.split("\n");
|
|
421
|
-
for (let i = 0; i < parts.length; i++) {
|
|
422
|
-
if (i > 0)
|
|
423
|
-
lines.push({ runs: [] });
|
|
424
|
-
lines[lines.length - 1].runs.push({ text: parts[i], ...style });
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
// A line the loop above never wrote a run onto still has to be measured
|
|
428
|
-
// against something, and the node's own style is the only honest answer.
|
|
429
|
-
for (const line of lines) {
|
|
430
|
-
if (line.runs.length === 0)
|
|
431
|
-
line.runs.push({ ...fallback, text: "" });
|
|
432
|
-
}
|
|
433
|
-
return lines;
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* The size each line of `lines` is set at once wrapped to `maxWidth`: the
|
|
437
|
-
* greedy whitespace break {@link countWrappedLines} makes, but with every piece
|
|
438
|
-
* measured in its own style. A word split across two styles is still one word.
|
|
439
|
-
*/
|
|
440
|
-
function wrappedLineSizes(lines, maxWidth, scope) {
|
|
441
|
-
const sizes = [];
|
|
442
|
-
for (const line of lines) {
|
|
443
|
-
const tokens = [];
|
|
444
|
-
for (const run of line.runs) {
|
|
445
|
-
for (const part of run.text.split(/(\s+)/)) {
|
|
446
|
-
if (part.length === 0)
|
|
447
|
-
continue;
|
|
448
|
-
const space = /^\s+$/.test(part);
|
|
449
|
-
const width = scope.measureText(part, run.fontSize, run.fontFamily, run.fontWeight, run.letterSpacing, run.fontStyle).width;
|
|
450
|
-
const last = tokens[tokens.length - 1];
|
|
451
|
-
if (last && !last.space && !space) {
|
|
452
|
-
last.width += width;
|
|
453
|
-
last.size = Math.max(last.size, run.fontSize);
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
tokens.push({ width, size: run.fontSize, space });
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
if (tokens.length === 0) {
|
|
461
|
-
sizes.push(Math.max(...line.runs.map(run => run.fontSize)));
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
let lineW = tokens[0].width;
|
|
465
|
-
let size = tokens[0].size;
|
|
466
|
-
for (const token of tokens.slice(1)) {
|
|
467
|
-
if (lineW + token.width <= maxWidth) {
|
|
468
|
-
lineW += token.width;
|
|
469
|
-
size = Math.max(size, token.size);
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
sizes.push(size);
|
|
473
|
-
lineW = token.space ? 0 : token.width;
|
|
474
|
-
size = token.space ? 0 : token.size;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
sizes.push(size > 0 ? size : Math.max(...line.runs.map(run => run.fontSize)));
|
|
478
|
-
}
|
|
479
|
-
return sizes;
|
|
480
|
-
}
|
|
481
|
-
function countWrappedLines(paragraph, maxWidth, fontSize, fontFamily, fontWeight, scope, letterSpacing = 0, fontStyle = 'normal') {
|
|
482
|
-
if (paragraph.length === 0)
|
|
483
|
-
return 1;
|
|
484
|
-
if (scope.measureText(paragraph, fontSize, fontFamily, fontWeight, letterSpacing, fontStyle).width <= maxWidth)
|
|
485
|
-
return 1;
|
|
486
|
-
const words = paragraph.split(/(\s+)/).filter(s => s.length > 0);
|
|
487
|
-
let lines = 1;
|
|
488
|
-
let lineW = 0;
|
|
489
|
-
for (const word of words) {
|
|
490
|
-
const w = scope.measureText(word, fontSize, fontFamily, fontWeight, letterSpacing, fontStyle).width;
|
|
491
|
-
if (lineW === 0) {
|
|
492
|
-
lineW = w;
|
|
493
|
-
}
|
|
494
|
-
else if (lineW + w <= maxWidth) {
|
|
495
|
-
lineW += w;
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
lines++;
|
|
499
|
-
lineW = /^\s+$/.test(word) ? 0 : w;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return lines;
|
|
503
|
-
}
|
|
504
153
|
//# sourceMappingURL=text-base.js.map
|