@clypra-studio/engine 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -879,7 +879,8 @@ function legacyLayerToNode(layer, index) {
879
879
  style: {
880
880
  fontFamily: resolveStringProperty(text?.fontFamily, "Inter Variable"),
881
881
  fontSize: resolveNumericProperty(text?.fontSize, 48),
882
- fontWeight: resolveStringProperty(text?.fontWeight, "400"),
882
+ fontWeight: resolveAnimatableValue(text?.fontWeight, 400),
883
+ fontStyle: text?.fontStyle === "italic" ? "italic" : "normal",
883
884
  textColor: resolveStringProperty(
884
885
  text?.color ?? text?.textColor,
885
886
  "#FFFFFF"
@@ -888,7 +889,26 @@ function legacyLayerToNode(layer, index) {
888
889
  lineHeight: resolveNumericProperty(text?.lineHeight, 1.2),
889
890
  letterSpacing: resolveNumericProperty(text?.letterSpacing, 0),
890
891
  overflow: text?.overflow,
891
- verticalAlign: text?.verticalAlign
892
+ verticalAlign: text?.verticalAlign,
893
+ strokeColor: text?.stroke?.color ?? text?.strokeColor ? resolveStringProperty(text?.stroke?.color ?? text?.strokeColor, "#000000") : void 0,
894
+ strokeWidth: text?.stroke?.width ?? text?.strokeWidth ? resolveNumericProperty(text?.stroke?.width ?? text?.strokeWidth, 0) : void 0,
895
+ shadowColor: text?.shadow?.color ?? text?.shadowColor ? resolveStringProperty(text?.shadow?.color ?? text?.shadowColor, "#000000") : void 0,
896
+ shadowBlur: text?.shadow?.blur ?? text?.shadowBlur ? resolveNumericProperty(text?.shadow?.blur ?? text?.shadowBlur, 0) : void 0,
897
+ shadowOffsetX: text?.shadow?.offsetX ?? text?.shadowOffsetX ? resolveNumericProperty(text?.shadow?.offsetX ?? text?.shadowOffsetX, 0) : void 0,
898
+ shadowOffsetY: text?.shadow?.offsetY ?? text?.shadowOffsetY ? resolveNumericProperty(text?.shadow?.offsetY ?? text?.shadowOffsetY, 0) : void 0,
899
+ stroke: text?.stroke ? {
900
+ color: resolveStringProperty(text.stroke.color, "#000000"),
901
+ width: resolveNumericProperty(text.stroke.width, 1)
902
+ } : void 0,
903
+ shadow: text?.shadow ? {
904
+ color: resolveStringProperty(text.shadow.color, "#000000"),
905
+ blur: resolveNumericProperty(text.shadow.blur, 0),
906
+ offsetX: resolveNumericProperty(text.shadow.offsetX, 0),
907
+ offsetY: resolveNumericProperty(text.shadow.offsetY, 0)
908
+ } : void 0,
909
+ fontId: text?.fontId || layer?.fontId ? resolveStringProperty(text?.fontId ?? layer?.fontId, "") : void 0,
910
+ backgroundColor: text?.backgroundColor || layer?.backgroundColor ? resolveStringProperty(text?.backgroundColor ?? layer?.backgroundColor, "") : void 0,
911
+ background: text?.background || layer?.background ? clone2(text?.background ?? layer?.background) : void 0
892
912
  },
893
913
  backgroundPanel: text?.backgroundColor || text?.backgroundPanel ? {
894
914
  color: text?.backgroundPanel?.color ?? text?.backgroundColor ? resolveStringProperty(
@@ -933,9 +953,10 @@ function legacyLayerToNode(layer, index) {
933
953
  charFillColors: Array.isArray(text?.charFillColors) ? clone2(text.charFillColors) : void 0,
934
954
  splitAnimator: text?.splitAnimator ? clone2(text.splitAnimator) : void 0,
935
955
  textEffectRef: text?.styleRef ? clone2(text.styleRef) : void 0,
936
- // Kept as optional metadata for compatibility with role-based editor
937
- // customizations. The canonical renderer does not depend on roles.
938
- ...layer?.role ? { role: String(layer.role) } : {}
956
+ role: layer?.role || text?.role || text?.textRole ? String(layer?.role ?? text?.role ?? text?.textRole) : void 0,
957
+ textRole: text?.textRole || (layer?.role === "primary" || layer?.role === "secondary" ? "title" : void 0),
958
+ fontId: text?.fontId || layer?.fontId ? resolveStringProperty(text?.fontId ?? layer?.fontId, "") : void 0,
959
+ maxWidth: resolveNumericProperty(text?.maxWidth ?? layer?.maxWidth, 0) || void 0
939
960
  };
940
961
  }
941
962
  function inferControls(nodes) {
@@ -1090,6 +1111,51 @@ function normalizeTextTemplateArtifact(input) {
1090
1111
  } : void 0
1091
1112
  };
1092
1113
  }
1114
+ function resolveTemplateControlValues(artifact, optionsOrCustomization, fallbackText) {
1115
+ if (!artifact?.controls) return {};
1116
+ const options = optionsOrCustomization && ("customization" in optionsOrCustomization || "templateControlValues" in optionsOrCustomization || "fallbackText" in optionsOrCustomization) ? optionsOrCustomization : {
1117
+ customization: optionsOrCustomization,
1118
+ fallbackText
1119
+ };
1120
+ const customization = options.customization;
1121
+ const existingValues = options.templateControlValues;
1122
+ const targetFallbackText = options.fallbackText;
1123
+ const firstTextNode = artifact.document?.nodes?.find(
1124
+ (candidate) => candidate.type === "text"
1125
+ );
1126
+ const values = { ...existingValues || {} };
1127
+ for (const control of artifact.controls) {
1128
+ if (control.type !== "text" && control.type !== "color") continue;
1129
+ const node = artifact.document?.nodes?.find(
1130
+ (candidate) => candidate.id === control.target.nodeId
1131
+ );
1132
+ const role = node?.role || "";
1133
+ const labelLower = (control.label || "").toLowerCase();
1134
+ if (control.type === "text") {
1135
+ const explicitText = customization?.layerTexts?.[control.target.nodeId];
1136
+ let roleText;
1137
+ if (role === "primary" || labelLower.includes("primary")) {
1138
+ roleText = customization?.primaryText;
1139
+ } else if (role === "secondary" || labelLower.includes("secondary")) {
1140
+ roleText = customization?.secondaryText;
1141
+ } else if (role === "accent" || labelLower.includes("accent")) {
1142
+ roleText = customization?.accentText;
1143
+ }
1144
+ const firstNodeFallback = targetFallbackText !== void 0 && firstTextNode && control.target.nodeId === firstTextNode.id ? targetFallbackText : void 0;
1145
+ values[control.id] = explicitText ?? roleText ?? firstNodeFallback ?? values[control.id] ?? control.defaultValue;
1146
+ } else if (control.type === "color") {
1147
+ const explicitColor = customization?.layerColors?.[control.target.nodeId];
1148
+ let roleColor;
1149
+ if (role === "secondary" || labelLower.includes("secondary")) {
1150
+ roleColor = customization?.secondaryColor;
1151
+ } else {
1152
+ roleColor = customization?.primaryColor;
1153
+ }
1154
+ values[control.id] = explicitColor ?? roleColor ?? values[control.id] ?? control.defaultValue;
1155
+ }
1156
+ }
1157
+ return values;
1158
+ }
1093
1159
 
1094
1160
  // src/textTemplates/compiler.ts
1095
1161
  function clone3(value) {
@@ -1685,16 +1751,90 @@ function letterSpacedText(ctx, text, x, y, maxWidth, letterSpacing) {
1685
1751
  }
1686
1752
  ctx.textAlign = align;
1687
1753
  }
1754
+ function letterSpacedStrokeText(ctx, text, x, y, maxWidth, letterSpacing) {
1755
+ if (!letterSpacing) {
1756
+ ctx.strokeText(text, x, y, maxWidth);
1757
+ return;
1758
+ }
1759
+ const glyphs = Array.from(text);
1760
+ const widths = glyphs.map((glyph) => ctx.measureText(glyph).width);
1761
+ const total = widths.reduce((sum, value) => sum + value, 0) + Math.max(0, glyphs.length - 1) * letterSpacing;
1762
+ const align = ctx.textAlign;
1763
+ let cursor = x;
1764
+ if (align === "center") cursor -= total / 2;
1765
+ if (align === "right") cursor -= total;
1766
+ ctx.textAlign = "left";
1767
+ for (let index = 0; index < glyphs.length; index += 1) {
1768
+ ctx.strokeText(glyphs[index], cursor, y);
1769
+ cursor += widths[index] + letterSpacing;
1770
+ }
1771
+ ctx.textAlign = align;
1772
+ }
1773
+ var FONT_ALIAS_MAP = {
1774
+ "inter": "Inter Variable",
1775
+ "inter variable": "Inter Variable",
1776
+ "outfit": "Outfit Variable",
1777
+ "outfit variable": "Outfit Variable",
1778
+ "playfair display": "Playfair Display Variable",
1779
+ "playfair display variable": "Playfair Display Variable",
1780
+ "montserrat": "Montserrat Variable",
1781
+ "montserrat variable": "Montserrat Variable",
1782
+ "roboto": "Roboto Variable",
1783
+ "roboto variable": "Roboto Variable",
1784
+ "roboto condensed": "Roboto Condensed Variable",
1785
+ "roboto condensed variable": "Roboto Condensed Variable",
1786
+ "raleway": "Raleway Variable",
1787
+ "raleway variable": "Raleway Variable",
1788
+ "space grotesk": "Space Grotesk Variable",
1789
+ "space grotesk variable": "Space Grotesk Variable",
1790
+ "nunito": "Nunito Variable",
1791
+ "nunito variable": "Nunito Variable",
1792
+ "open sans": "Open Sans Variable",
1793
+ "open sans variable": "Open Sans Variable",
1794
+ "oswald": "Oswald Variable",
1795
+ "oswald variable": "Oswald Variable",
1796
+ "geist": "Geist Variable",
1797
+ "geist variable": "Geist Variable",
1798
+ "dancing script": "Dancing Script Variable",
1799
+ "dancing script variable": "Dancing Script Variable"
1800
+ };
1801
+ function resolveTemplateFontFamily(family) {
1802
+ if (!family) return "sans-serif";
1803
+ const clean = String(family).trim().replace(/^["']|["']$/g, "");
1804
+ const lower = clean.toLowerCase();
1805
+ return FONT_ALIAS_MAP[lower] || clean;
1806
+ }
1807
+ function constructFontStack(fontStyle, fontWeight, fontSize, rawFamily) {
1808
+ const canonical = resolveTemplateFontFamily(rawFamily);
1809
+ const cleanRaw = String(rawFamily || "").trim().replace(/^["']|["']$/g, "");
1810
+ const style = fontStyle === "italic" ? "italic" : "normal";
1811
+ const weight = fontWeight ?? 400;
1812
+ if (canonical && cleanRaw && canonical.toLowerCase() !== cleanRaw.toLowerCase()) {
1813
+ return `${style} ${weight} ${fontSize}px "${canonical}", "${cleanRaw}", sans-serif`;
1814
+ }
1815
+ return `${style} ${weight} ${fontSize}px "${canonical || cleanRaw || "sans-serif"}", sans-serif`;
1816
+ }
1688
1817
  function drawTextLayer(ctx, layer, style) {
1689
1818
  const text = layer.text ?? "";
1690
1819
  const fontSize = finite2(style.fontSize, 48);
1691
1820
  const fontWeight = style.fontWeight ?? 400;
1692
- const fontStyle = "normal";
1693
- const fontFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
1694
- ctx.font = `${fontStyle} ${fontWeight} ${fontSize}px "${fontFamily}"`;
1821
+ const fontStyle = style.fontStyle || "normal";
1822
+ const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
1823
+ ctx.font = constructFontStack(fontStyle, fontWeight, fontSize, rawFamily);
1695
1824
  ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
1696
1825
  ctx.textAlign = style.textAlign ?? "left";
1697
1826
  ctx.textBaseline = style.verticalAlign === "top" ? "top" : style.verticalAlign === "bottom" ? "bottom" : "middle";
1827
+ const shadowColor = style.shadow?.color ?? style.shadowColor;
1828
+ const shadowBlur = finite2(style.shadow?.blur ?? style.shadowBlur, 0);
1829
+ const shadowOffsetX = finite2(style.shadow?.offsetX ?? style.shadowOffsetX, 0);
1830
+ const shadowOffsetY = finite2(style.shadow?.offsetY ?? style.shadowOffsetY, 0);
1831
+ const hasShadow = !!shadowColor && (shadowBlur > 0 || shadowOffsetX !== 0 || shadowOffsetY !== 0);
1832
+ if (hasShadow) {
1833
+ ctx.shadowColor = cssColor(shadowColor, "#000000");
1834
+ ctx.shadowBlur = shadowBlur;
1835
+ ctx.shadowOffsetX = shadowOffsetX;
1836
+ ctx.shadowOffsetY = shadowOffsetY;
1837
+ }
1698
1838
  const lineHeight = fontSize * finite2(style.lineHeight, 1.2);
1699
1839
  const maxWidth = Math.max(1, layer.width);
1700
1840
  const lines = style.overflow === "wrap" ? wrapText(ctx, text, maxWidth) : [text];
@@ -1704,12 +1844,30 @@ function drawTextLayer(ctx, layer, style) {
1704
1844
  for (let index = 0; index < lines.length; index += 1) {
1705
1845
  letterSpacedText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
1706
1846
  }
1847
+ if (hasShadow) {
1848
+ ctx.shadowColor = "transparent";
1849
+ ctx.shadowBlur = 0;
1850
+ ctx.shadowOffsetX = 0;
1851
+ ctx.shadowOffsetY = 0;
1852
+ }
1853
+ const strokeColor = style.stroke?.color ?? style.strokeColor;
1854
+ const strokeWidth = finite2(style.stroke?.width ?? style.strokeWidth, 0);
1855
+ if (strokeWidth > 0 && strokeColor) {
1856
+ ctx.strokeStyle = cssColor(strokeColor, "#000000");
1857
+ ctx.lineWidth = strokeWidth;
1858
+ ctx.lineJoin = "round";
1859
+ for (let index = 0; index < lines.length; index += 1) {
1860
+ letterSpacedStrokeText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
1861
+ }
1862
+ }
1707
1863
  }
1708
1864
  function drawSplitTextLayer(ctx, layer, style, animator, progress) {
1709
1865
  const text = layer.text ?? "";
1710
1866
  const fontSize = finite2(style.fontSize, 48);
1711
- const fontFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
1712
- ctx.font = `normal ${style.fontWeight ?? 400} ${fontSize}px "${fontFamily}"`;
1867
+ const fontWeight = style.fontWeight ?? 400;
1868
+ const fontStyle = style.fontStyle || "normal";
1869
+ const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
1870
+ ctx.font = constructFontStack(fontStyle, fontWeight, fontSize, rawFamily);
1713
1871
  ctx.textBaseline = "middle";
1714
1872
  ctx.textAlign = "left";
1715
1873
  ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
@@ -1799,9 +1957,9 @@ function renderTextTemplateToCanvas(ctx, input) {
1799
1957
  // Measure with the exact Canvas context that will draw the layer. This
1800
1958
  // makes auto-sized nodes use loaded font metrics instead of a fixed box.
1801
1959
  measureText: (text, style) => {
1802
- const family = String(style.fontFamily || "sans-serif").replace(/"/g, "");
1960
+ const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
1803
1961
  ctx.save();
1804
- ctx.font = `${style.fontWeight ?? 400} ${finite2(style.fontSize, 48)}px "${family}"`;
1962
+ ctx.font = constructFontStack(style.fontStyle, style.fontWeight, finite2(style.fontSize, 48), rawFamily);
1805
1963
  const width = ctx.measureText(text).width + Math.max(0, text.length - 1) * finite2(style.letterSpacing, 0);
1806
1964
  ctx.restore();
1807
1965
  return { width };
@@ -1886,13 +2044,15 @@ export {
1886
2044
  TEXT_TEMPLATE_RENDERER_VERSION,
1887
2045
  canonicalTemplateHash,
1888
2046
  normalizeTextTemplateArtifact,
2047
+ resolveTemplateControlValues,
1889
2048
  validateTextTemplateArtifact,
1890
2049
  assertValidTextTemplateArtifact,
1891
2050
  compileTextTemplate,
1892
2051
  renderTextEffectToCanvas,
1893
2052
  resolveTextTemplateArtifact,
1894
2053
  getTextTemplateControls,
2054
+ resolveTemplateFontFamily,
1895
2055
  renderTextTemplateToCanvas,
1896
2056
  renderCanonicalToCanvas
1897
2057
  };
1898
- //# sourceMappingURL=chunk-Q7XYDP4X.js.map
2058
+ //# sourceMappingURL=chunk-7VLGHWCA.js.map