@pairdraw/design-jsx 0.0.0-stage → 0.16.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.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/chunks/attributes.js +32 -0
  4. package/dist/chunks/attributes.js.map +1 -0
  5. package/dist/chunks/behaviours/elements.js +321 -0
  6. package/dist/chunks/behaviours/elements.js.map +1 -0
  7. package/dist/chunks/behaviours/render.js +368 -0
  8. package/dist/chunks/behaviours/render.js.map +1 -0
  9. package/dist/chunks/component-properties.js +809 -0
  10. package/dist/chunks/component-properties.js.map +1 -0
  11. package/dist/chunks/components.js +78 -0
  12. package/dist/chunks/components.js.map +1 -0
  13. package/dist/chunks/connectors.js +290 -0
  14. package/dist/chunks/connectors.js.map +1 -0
  15. package/dist/chunks/effects.js +57 -0
  16. package/dist/chunks/effects.js.map +1 -0
  17. package/dist/chunks/elements.js +618 -0
  18. package/dist/chunks/elements.js.map +1 -0
  19. package/dist/chunks/export/behaviours.js +113 -0
  20. package/dist/chunks/export/behaviours.js.map +1 -0
  21. package/dist/chunks/export/bindings.js +273 -0
  22. package/dist/chunks/export/bindings.js.map +1 -0
  23. package/dist/chunks/export/decoration.js +96 -0
  24. package/dist/chunks/export/decoration.js.map +1 -0
  25. package/dist/chunks/export/font.js +17 -0
  26. package/dist/chunks/export/font.js.map +1 -0
  27. package/dist/chunks/export/icons.js +34 -0
  28. package/dist/chunks/export/icons.js.map +1 -0
  29. package/dist/chunks/export/index.js +1390 -0
  30. package/dist/chunks/export/index.js.map +1 -0
  31. package/dist/chunks/fields.js +1065 -0
  32. package/dist/chunks/fields.js.map +1 -0
  33. package/dist/chunks/index.js +438 -0
  34. package/dist/chunks/index.js.map +1 -0
  35. package/dist/chunks/jsx-dev-runtime.js +16 -0
  36. package/dist/chunks/jsx-dev-runtime.js.map +1 -0
  37. package/dist/index.d.ts +543 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +11 -0
  40. package/dist/jsx-dev-runtime.d.ts +2 -0
  41. package/dist/jsx-dev-runtime.js +2 -0
  42. package/dist/jsx-runtime.d.ts +44 -0
  43. package/dist/jsx-runtime.d.ts.map +1 -0
  44. package/dist/jsx-runtime.js +2 -0
  45. package/dist/tree.d.ts +261 -0
  46. package/dist/tree.d.ts.map +1 -0
  47. package/package.json +66 -4
  48. package/src/attributes.ts +30 -0
  49. package/src/behaviours/elements.ts +47 -0
  50. package/src/behaviours/index.ts +253 -0
  51. package/src/behaviours/render.ts +144 -0
  52. package/src/component-properties.ts +428 -0
  53. package/src/components.ts +109 -0
  54. package/src/connectors.ts +316 -0
  55. package/src/definitions.ts +277 -0
  56. package/src/effects.ts +80 -0
  57. package/src/elements.ts +321 -0
  58. package/src/enums.ts +182 -0
  59. package/src/export/behaviours.ts +143 -0
  60. package/src/export/bindings.ts +155 -0
  61. package/src/export/decoration.ts +39 -0
  62. package/src/export/font.ts +25 -0
  63. package/src/export/helpers.ts +75 -0
  64. package/src/export/icons.ts +42 -0
  65. package/src/export/index.ts +297 -0
  66. package/src/export/paint.ts +276 -0
  67. package/src/export/props.ts +369 -0
  68. package/src/export/state.ts +52 -0
  69. package/src/export/text.ts +155 -0
  70. package/src/export/value.ts +99 -0
  71. package/src/export/variables.ts +393 -0
  72. package/src/fields.ts +39 -0
  73. package/src/figjam-text.ts +37 -0
  74. package/src/global.d.ts +4 -0
  75. package/src/helpers.ts +135 -0
  76. package/src/index.ts +155 -0
  77. package/src/jsx-dev-runtime.ts +1 -0
  78. package/src/jsx-runtime.ts +51 -0
  79. package/src/mini-react.ts +23 -0
  80. package/src/overrides/effects.ts +39 -0
  81. package/src/overrides/fills.ts +56 -0
  82. package/src/overrides/state.ts +55 -0
  83. package/src/overrides/strokes.ts +109 -0
  84. package/src/overrides/text.ts +116 -0
  85. package/src/overrides/vector.ts +122 -0
  86. package/src/paints.ts +230 -0
  87. package/src/props-overrides.ts +481 -0
  88. package/src/reconcile.ts +134 -0
  89. package/src/reference/authoring.md +76 -0
  90. package/src/reference/examples.ts +49 -0
  91. package/src/reference.ts +19 -0
  92. package/src/refs.ts +48 -0
  93. package/src/render.ts +147 -0
  94. package/src/renderer.ts +598 -0
  95. package/src/scalar-bindings.ts +36 -0
  96. package/src/schema.ts +213 -0
  97. package/src/services.ts +36 -0
  98. package/src/shapes-with-text.ts +73 -0
  99. package/src/stickies.ts +72 -0
  100. package/src/streaming/index.ts +47 -0
  101. package/src/streaming/literals.ts +82 -0
  102. package/src/streaming/projection.ts +189 -0
  103. package/src/text-content.ts +233 -0
  104. package/src/transform.ts +78 -0
  105. package/src/tree.ts +285 -0
  106. package/src/types.ts +13 -0
  107. package/src/variables/graph.ts +265 -0
  108. package/src/variables/index.ts +124 -0
  109. package/src/variables/props.ts +77 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decoration.js","names":[],"sources":["../../../src/overrides/text.ts","../../../src/export/decoration.ts"],"sourcesContent":["import { uniqBy } from 'es-toolkit'\nimport * as v from 'valibot'\n\nimport type { Fill, SceneNode, TextLength } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\nimport { percentLength, pixelLength } from '@pairdraw/scene-graph/text'\n\nimport { TEXT_DECORATION_STYLE } from '../enums'\nimport { parseScriptInput } from '../schema'\nimport { fillFromValue, isFillValue } from './fills'\n\n/** Lengths that follow the font unless set take `'auto'`, as in CSS. */\nexport const AUTO = 'auto'\n/** The decoration colour that follows the text's, as in CSS. */\nexport const CURRENT_COLOR = 'currentColor'\n\n/** A percent of the font size, such as `'150%'`, which follows the size as in Figma. */\nconst PERCENT_LENGTH = /^(-?\\d+(?:\\.\\d+)?)%$/\n\n/** A line height or letter spacing a prop gives: pixels as a number, or a percent string. */\nexport function textLengthProp(value: unknown): TextLength | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) return pixelLength(value)\n const match = typeof value === 'string' ? PERCENT_LENGTH.exec(value.trim()) : null\n return match ? percentLength(Number(match[1])) : undefined\n}\n\n/** A line height or letter spacing as a prop writes it. */\nexport function textLengthJSX(length: TextLength): number | `${number}%` {\n return length.unit === 'PIXELS' ? length.value : `${length.value}%`\n}\n\nconst lengthSchema = v.pipe(v.number(), v.finite())\nconst autoLengthSchema = v.union([lengthSchema, v.literal(AUTO)])\n/** An OpenType feature or axis tag: four printable ASCII characters, such as `tnum` or `wght`. */\nconst openTypeTagSchema = v.pipe(\n v.string(),\n v.regex(/^[\\x20-\\x7E]{4}$/, 'Expected a four-character tag')\n)\n\nconst textPropsSchema = v.object({\n // Read by TEXT_DECORATION_STYLE, so an unknown style warns rather than failing the render.\n textDecorationStyle: v.optional(v.string()),\n textDecorationColor: v.optional(\n v.custom<string | Color | Fill>(isFillValue, 'Expected a colour or a paint')\n ),\n textDecorationThickness: v.optional(autoLengthSchema),\n textUnderlineOffset: v.optional(autoLengthSchema),\n textDecorationSkipInk: v.optional(v.boolean()),\n fontFeatures: v.optional(\n v.pipe(\n v.record(openTypeTagSchema, v.boolean()),\n // Tags are stored in capitals, so `liga` and `LIGA` are the same feature.\n v.check((features) => {\n const tags = Object.keys(features)\n return uniqBy(tags, (tag) => tag.toUpperCase()).length === tags.length\n }, 'Expected each feature tag once, in any case')\n )\n ),\n fontVariations: v.optional(v.record(openTypeTagSchema, lengthSchema)),\n lang: v.optional(v.nullable(v.pipe(v.string(), v.trim(), v.nonEmpty()))),\n fontOpticalSizing: v.optional(v.picklist([AUTO, 'none'])),\n paragraphSpacing: v.optional(lengthSchema),\n listSpacing: v.optional(lengthSchema),\n paragraphIndent: v.optional(lengthSchema),\n hangingList: v.optional(v.boolean())\n})\n\nfunction autoLength(value: number | typeof AUTO): number | null {\n return value === AUTO ? null : value\n}\n\n/**\n * The decoration details, font settings, and text-wide paragraph spacing a `<Text>` or `<Span>`\n * sets. Font settings replace the ones around them as a whole, as CSS's do.\n */\nexport function applyTextDetailOverrides(\n props: Record<string, unknown>,\n o: Partial<SceneNode>\n): void {\n const parsed = parseScriptInput('Invalid <Text> props', textPropsSchema, props)\n const color = parsed.textDecorationColor\n const style = TEXT_DECORATION_STYLE.parse(parsed.textDecorationStyle)\n if (style) o.textDecorationStyle = style\n if (color !== undefined) {\n o.textDecorationFills =\n typeof color === 'string' && color.toLowerCase() === CURRENT_COLOR.toLowerCase()\n ? []\n : [fillFromValue(color)]\n }\n if (parsed.textDecorationThickness !== undefined)\n o.textDecorationThickness = autoLength(parsed.textDecorationThickness)\n if (parsed.textUnderlineOffset !== undefined)\n o.textUnderlineOffset = autoLength(parsed.textUnderlineOffset)\n if (parsed.textDecorationSkipInk !== undefined)\n o.textDecorationSkipInk = parsed.textDecorationSkipInk\n if (parsed.fontFeatures) {\n // The scene keeps feature tags as Figma does, in capitals.\n o.fontFeatures = Object.entries(parsed.fontFeatures).map(([tag, enabled]) => ({\n tag: tag.toUpperCase(),\n enabled\n }))\n }\n if (parsed.fontVariations) {\n o.fontVariations = Object.entries(parsed.fontVariations).map(([axis, value]) => ({\n axis,\n value\n }))\n }\n if (parsed.lang !== undefined) o.textLanguage = parsed.lang\n if (parsed.fontOpticalSizing !== undefined)\n o.opticalSizeFromFontSize = parsed.fontOpticalSizing === AUTO\n if (parsed.paragraphSpacing !== undefined) o.paragraphSpacing = parsed.paragraphSpacing\n if (parsed.listSpacing !== undefined) o.listSpacing = parsed.listSpacing\n if (parsed.paragraphIndent !== undefined) o.paragraphIndent = parsed.paragraphIndent\n if (parsed.hangingList !== undefined) o.hangingList = parsed.hangingList\n}\n","import type { CharacterStyleOverride, SceneNode } from '@pairdraw/scene-graph'\n\nimport { TEXT_DECORATION_STYLE } from '../enums'\nimport { AUTO, CURRENT_COLOR } from '../overrides/text'\nimport { paintPropValue } from './paint'\nimport type { JSXProp } from './value'\n\ntype DecorationStyle = Pick<\n CharacterStyleOverride,\n | 'textDecorationStyle'\n | 'textDecorationFills'\n | 'textDecorationThickness'\n | 'textUnderlineOffset'\n | 'textDecorationSkipInk'\n>\n\n/**\n * The decoration details set in `style`, as `<Text>` and `<Span>` write them. A decoration\n * painted with more than one paint keeps only its first, the one `textDecorationColor` holds.\n */\nexport function collectDecorationProps(\n style: DecorationStyle,\n node: SceneNode,\n props: JSXProp[]\n): void {\n const { textDecorationFills: fills } = style\n if (style.textDecorationStyle !== undefined)\n props.push(['textDecorationStyle', TEXT_DECORATION_STYLE.print(style.textDecorationStyle)])\n if (fills) {\n const fill = fills.at(0)\n props.push(['textDecorationColor', fill ? paintPropValue(fill, node) : CURRENT_COLOR])\n }\n if (style.textDecorationThickness !== undefined)\n props.push(['textDecorationThickness', style.textDecorationThickness ?? AUTO])\n if (style.textUnderlineOffset !== undefined)\n props.push(['textUnderlineOffset', style.textUnderlineOffset ?? AUTO])\n if (style.textDecorationSkipInk !== undefined)\n props.push(['textDecorationSkipInk', style.textDecorationSkipInk])\n}\n"],"mappings":";;;;;;;AAYA,MAAa,OAAO;;AAEpB,MAAa,gBAAgB;;AAG7B,MAAM,iBAAiB;;AAGvB,SAAgB,eAAe,OAAwC;CACrE,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO,YAAY,KAAK;CACjF,MAAM,QAAQ,OAAO,UAAU,WAAW,eAAe,KAAK,MAAM,KAAK,CAAC,IAAI;CAC9E,OAAO,QAAQ,cAAc,OAAO,MAAM,EAAE,CAAC,IAAI,KAAA;AACnD;;AAGA,SAAgB,cAAc,QAA2C;CACvE,OAAO,OAAO,SAAS,WAAW,OAAO,QAAQ,GAAG,OAAO,MAAM;AACnE;AAEA,MAAM,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AAClD,MAAM,mBAAmB,EAAE,MAAM,CAAC,cAAc,EAAE,QAAQ,IAAI,CAAC,CAAC;;AAEhE,MAAM,oBAAoB,EAAE,KAC1B,EAAE,OAAO,GACT,EAAE,MAAM,oBAAoB,+BAA+B,CAC7D;AAEA,MAAM,kBAAkB,EAAE,OAAO;CAE/B,qBAAqB,EAAE,SAAS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I,MAAM,wBAAwB,KAAA,GAChC,MAAM,KAAK,CAAC,uBAAuB,MAAM,uBAAA,MAA2B,CAAC;CACvE,IAAI,MAAM,0BAA0B,KAAA,GAClC,MAAM,KAAK,CAAC,yBAAyB,MAAM,qBAAqB,CAAC;AACrE"}
@@ -0,0 +1,17 @@
1
+ //#region src/export/font.ts
2
+ /** The font settings a `<Text>` or `<Span>` writes, by their scene fields. */
3
+ const FONT_SETTING_FIELDS = [
4
+ "fontFeatures",
5
+ "fontVariations",
6
+ "textLanguage"
7
+ ];
8
+ /** The font settings set in `style`, as `<Text>` and `<Span>` write them. */
9
+ function collectFontSettingProps(style, props) {
10
+ if (style.fontFeatures) props.push(["fontFeatures", Object.fromEntries(style.fontFeatures.map(({ tag, enabled }) => [tag.toLowerCase(), enabled]))]);
11
+ if (style.fontVariations) props.push(["fontVariations", Object.fromEntries(style.fontVariations.map(({ axis, value }) => [axis, value]))]);
12
+ if (style.textLanguage !== void 0) props.push(["lang", style.textLanguage]);
13
+ }
14
+ //#endregion
15
+ export { FONT_SETTING_FIELDS, collectFontSettingProps };
16
+
17
+ //# sourceMappingURL=font.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font.js","names":[],"sources":["../../../src/export/font.ts"],"sourcesContent":["import type { CharacterStyleOverride } from '@pairdraw/scene-graph'\n\nimport type { JSXProp } from './value'\n\n/** The font settings a `<Text>` or `<Span>` writes, by their scene fields. */\nexport const FONT_SETTING_FIELDS = ['fontFeatures', 'fontVariations', 'textLanguage'] as const\n\ntype FontSettings = Pick<CharacterStyleOverride, (typeof FONT_SETTING_FIELDS)[number]>\n\n/** The font settings set in `style`, as `<Text>` and `<Span>` write them. */\nexport function collectFontSettingProps(style: FontSettings, props: JSXProp[]): void {\n if (style.fontFeatures) {\n props.push([\n 'fontFeatures',\n Object.fromEntries(style.fontFeatures.map(({ tag, enabled }) => [tag.toLowerCase(), enabled]))\n ])\n }\n if (style.fontVariations) {\n props.push([\n 'fontVariations',\n Object.fromEntries(style.fontVariations.map(({ axis, value }) => [axis, value]))\n ])\n }\n if (style.textLanguage !== undefined) props.push(['lang', style.textLanguage])\n}\n"],"mappings":";;AAKA,MAAa,sBAAsB;CAAC;CAAgB;CAAkB;AAAc;;AAKpF,SAAgB,wBAAwB,OAAqB,OAAwB;CACnF,IAAI,MAAM,cACR,MAAM,KAAK,CACT,gBACA,OAAO,YAAY,MAAM,aAAa,KAAK,EAAE,KAAK,cAAc,CAAC,IAAI,YAAY,GAAG,OAAO,CAAC,CAAC,CAC/F,CAAC;CAEH,IAAI,MAAM,gBACR,MAAM,KAAK,CACT,kBACA,OAAO,YAAY,MAAM,eAAe,KAAK,EAAE,MAAM,YAAY,CAAC,MAAM,KAAK,CAAC,CAAC,CACjF,CAAC;CAEH,IAAI,MAAM,iBAAiB,KAAA,GAAW,MAAM,KAAK,CAAC,QAAQ,MAAM,YAAY,CAAC;AAC/E"}
@@ -0,0 +1,34 @@
1
+ import { colorToHex } from "@pairdraw/scene-graph/color";
2
+ import { isIconModified, isNamedIcon, isPlacedIconName, readIcon, readIconTint } from "@pairdraw/scene-graph/icons";
3
+ //#region src/export/icons.ts
4
+ /** The color an icon's tinted paths have, as `<Icon color>` takes it. */
5
+ function tintColor(graph, frame) {
6
+ for (const path of graph.getChildren(frame.id)) {
7
+ const tint = readIconTint(path);
8
+ const paint = tint.includes("fill") ? path.fills[0] : void 0;
9
+ const stroke = tint.includes("stroke") ? path.strokes[0] : void 0;
10
+ const color = paint?.color ?? stroke?.color;
11
+ if (color) return colorToHex(color);
12
+ }
13
+ return null;
14
+ }
15
+ /**
16
+ * An icon frame as `<Icon>` props: its name and size, its color when it is not black, and its
17
+ * layer name when someone renamed it. `null` for a layer that is not an icon, or no longer draws
18
+ * one because its paths were edited.
19
+ */
20
+ function iconProps(node, graph) {
21
+ const icon = readIcon(node);
22
+ if (!icon || !isNamedIcon(icon) || isIconModified(graph, node)) return null;
23
+ const color = tintColor(graph, node);
24
+ return [
25
+ ["name", icon.name],
26
+ ["size", Math.round(Math.min(node.width, node.height))],
27
+ ...color && color.toLowerCase() !== "#000000" ? [["color", color]] : [],
28
+ ...isPlacedIconName(node.name, icon.name) ? [] : [["label", node.name]]
29
+ ];
30
+ }
31
+ //#endregion
32
+ export { iconProps };
33
+
34
+ //# sourceMappingURL=icons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icons.js","names":[],"sources":["../../../src/export/icons.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport {\n isIconModified,\n isPlacedIconName,\n isNamedIcon,\n readIcon,\n readIconTint\n} from '@pairdraw/scene-graph/icons'\n\nimport type { JSXProp } from './props'\n\n/** The color an icon's tinted paths have, as `<Icon color>` takes it. */\nfunction tintColor(graph: SceneGraph, frame: SceneNode): string | null {\n for (const path of graph.getChildren(frame.id)) {\n const tint = readIconTint(path)\n const paint = tint.includes('fill') ? path.fills[0] : undefined\n const stroke = tint.includes('stroke') ? path.strokes[0] : undefined\n const color = paint?.color ?? stroke?.color\n if (color) return colorToHex(color)\n }\n return null\n}\n\n/**\n * An icon frame as `<Icon>` props: its name and size, its color when it is not black, and its\n * layer name when someone renamed it. `null` for a layer that is not an icon, or no longer draws\n * one because its paths were edited.\n */\nexport function iconProps(node: SceneNode, graph: SceneGraph): JSXProp[] | null {\n const icon = readIcon(node)\n // An icon whose paths were edited exports as the paths it draws, which <Icon> would lose, as\n // does one drawn from a set of our own, which its name alone does not draw.\n if (!icon || !isNamedIcon(icon) || isIconModified(graph, node)) return null\n const color = tintColor(graph, node)\n return [\n ['name', icon.name],\n ['size', Math.round(Math.min(node.width, node.height))],\n ...(color && color.toLowerCase() !== '#000000' ? [['color', color] as JSXProp] : []),\n ...(isPlacedIconName(node.name, icon.name) ? [] : [['label', node.name] as JSXProp])\n ]\n}\n"],"mappings":";;;;AAaA,SAAS,UAAU,OAAmB,OAAiC;CACrE,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,EAAE,GAAG;EAC9C,MAAM,OAAO,aAAa,IAAI;EAC9B,MAAM,QAAQ,KAAK,SAAS,MAAM,IAAI,KAAK,MAAM,KAAK,KAAA;EACtD,MAAM,SAAS,KAAK,SAAS,QAAQ,IAAI,KAAK,QAAQ,KAAK,KAAA;EAC3D,MAAM,QAAQ,OAAO,SAAS,QAAQ;EACtC,IAAI,OAAO,OAAO,WAAW,KAAK;CACpC;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,UAAU,MAAiB,OAAqC;CAC9E,MAAM,OAAO,SAAS,IAAI;CAG1B,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,KAAK,eAAe,OAAO,IAAI,GAAG,OAAO;CACvE,MAAM,QAAQ,UAAU,OAAO,IAAI;CACnC,OAAO;EACL,CAAC,QAAQ,KAAK,IAAI;EAClB,CAAC,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,OAAO,KAAK,MAAM,CAAC,CAAC;EACtD,GAAI,SAAS,MAAM,YAAY,MAAM,YAAY,CAAC,CAAC,SAAS,KAAK,CAAY,IAAI,CAAC;EAClF,GAAI,iBAAiB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,IAAI,CAAY;CACpF;AACF"}