@clypra-studio/engine 1.6.0 → 1.8.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.
@@ -889,7 +889,26 @@ function legacyLayerToNode(layer, index) {
889
889
  lineHeight: resolveNumericProperty(text?.lineHeight, 1.2),
890
890
  letterSpacing: resolveNumericProperty(text?.letterSpacing, 0),
891
891
  overflow: text?.overflow,
892
- 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
893
912
  },
894
913
  backgroundPanel: text?.backgroundColor || text?.backgroundPanel ? {
895
914
  color: text?.backgroundPanel?.color ?? text?.backgroundColor ? resolveStringProperty(
@@ -934,9 +953,10 @@ function legacyLayerToNode(layer, index) {
934
953
  charFillColors: Array.isArray(text?.charFillColors) ? clone2(text.charFillColors) : void 0,
935
954
  splitAnimator: text?.splitAnimator ? clone2(text.splitAnimator) : void 0,
936
955
  textEffectRef: text?.styleRef ? clone2(text.styleRef) : void 0,
937
- // Kept as optional metadata for compatibility with role-based editor
938
- // customizations. The canonical renderer does not depend on roles.
939
- ...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
940
960
  };
941
961
  }
942
962
  function inferControls(nodes) {
@@ -1091,6 +1111,86 @@ function normalizeTextTemplateArtifact(input) {
1091
1111
  } : void 0
1092
1112
  };
1093
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" && control.type !== "font") 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
+ } else if (control.type === "font") {
1156
+ const explicitFont = customization?.layerFontFamilies?.[control.target.nodeId];
1157
+ let roleFont;
1158
+ if (role === "secondary" || labelLower.includes("secondary")) {
1159
+ roleFont = customization?.secondaryFontFamily;
1160
+ } else {
1161
+ roleFont = customization?.primaryFontFamily;
1162
+ }
1163
+ values[control.id] = explicitFont ?? roleFont ?? values[control.id] ?? control.defaultValue;
1164
+ }
1165
+ }
1166
+ for (const node of artifact.document?.nodes || []) {
1167
+ if (node.type === "text") {
1168
+ const role = node.role || "";
1169
+ const textKey = `text-${node.id}`;
1170
+ const fontKey = `font-${node.id}`;
1171
+ const colorKey = `color-${node.id}`;
1172
+ const explicitText = customization?.layerTexts?.[node.id];
1173
+ const roleText = role === "secondary" ? customization?.secondaryText : role === "accent" ? customization?.accentText : customization?.primaryText;
1174
+ const resolvedText = explicitText ?? roleText ?? (firstTextNode && node.id === firstTextNode.id ? targetFallbackText : void 0) ?? values[textKey] ?? node.text;
1175
+ if (resolvedText !== void 0) {
1176
+ values[textKey] = resolvedText;
1177
+ }
1178
+ const explicitFont = customization?.layerFontFamilies?.[node.id];
1179
+ const roleFont = role === "secondary" ? customization?.secondaryFontFamily : customization?.primaryFontFamily;
1180
+ const resolvedFont = explicitFont ?? roleFont ?? values[fontKey] ?? node.style?.fontFamily;
1181
+ if (resolvedFont !== void 0) {
1182
+ values[fontKey] = resolvedFont;
1183
+ }
1184
+ const explicitColor = customization?.layerColors?.[node.id];
1185
+ const roleColor = role === "secondary" ? customization?.secondaryColor : customization?.primaryColor;
1186
+ const resolvedColor = explicitColor ?? roleColor ?? values[colorKey] ?? node.style?.textColor;
1187
+ if (resolvedColor !== void 0) {
1188
+ values[colorKey] = resolvedColor;
1189
+ }
1190
+ }
1191
+ }
1192
+ return values;
1193
+ }
1094
1194
 
1095
1195
  // src/textTemplates/compiler.ts
1096
1196
  function clone3(value) {
@@ -1299,6 +1399,24 @@ function compileTextTemplate(artifact, context) {
1299
1399
  const node = findNode(document.nodes, control.target.nodeId);
1300
1400
  if (node) setPath(node, control.target.propertyPath, resolvedControls[control.id]);
1301
1401
  }
1402
+ if (context.controlValues) {
1403
+ for (const node of document.nodes || []) {
1404
+ if (node.type === "text") {
1405
+ const textVal = context.controlValues[`text-${node.id}`];
1406
+ if (typeof textVal === "string") {
1407
+ node.text = textVal;
1408
+ }
1409
+ const fontVal = context.controlValues[`font-${node.id}`];
1410
+ if (typeof fontVal === "string") {
1411
+ node.style = { ...node.style, fontFamily: fontVal };
1412
+ }
1413
+ const colorVal = context.controlValues[`color-${node.id}`];
1414
+ if (typeof colorVal === "string") {
1415
+ node.style = { ...node.style, textColor: colorVal };
1416
+ }
1417
+ }
1418
+ }
1419
+ }
1302
1420
  const time = mapTime(context.time, artifact, context.clipDuration);
1303
1421
  const flexPositions = /* @__PURE__ */ new Map();
1304
1422
  const containers = (document.nodes || []).filter((n) => n.type === "container");
@@ -1686,6 +1804,25 @@ function letterSpacedText(ctx, text, x, y, maxWidth, letterSpacing) {
1686
1804
  }
1687
1805
  ctx.textAlign = align;
1688
1806
  }
1807
+ function letterSpacedStrokeText(ctx, text, x, y, maxWidth, letterSpacing) {
1808
+ if (!letterSpacing) {
1809
+ ctx.strokeText(text, x, y, maxWidth);
1810
+ return;
1811
+ }
1812
+ const glyphs = Array.from(text);
1813
+ const widths = glyphs.map((glyph) => ctx.measureText(glyph).width);
1814
+ const total = widths.reduce((sum, value) => sum + value, 0) + Math.max(0, glyphs.length - 1) * letterSpacing;
1815
+ const align = ctx.textAlign;
1816
+ let cursor = x;
1817
+ if (align === "center") cursor -= total / 2;
1818
+ if (align === "right") cursor -= total;
1819
+ ctx.textAlign = "left";
1820
+ for (let index = 0; index < glyphs.length; index += 1) {
1821
+ ctx.strokeText(glyphs[index], cursor, y);
1822
+ cursor += widths[index] + letterSpacing;
1823
+ }
1824
+ ctx.textAlign = align;
1825
+ }
1689
1826
  var FONT_ALIAS_MAP = {
1690
1827
  "inter": "Inter Variable",
1691
1828
  "inter variable": "Inter Variable",
@@ -1740,6 +1877,17 @@ function drawTextLayer(ctx, layer, style) {
1740
1877
  ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
1741
1878
  ctx.textAlign = style.textAlign ?? "left";
1742
1879
  ctx.textBaseline = style.verticalAlign === "top" ? "top" : style.verticalAlign === "bottom" ? "bottom" : "middle";
1880
+ const shadowColor = style.shadow?.color ?? style.shadowColor;
1881
+ const shadowBlur = finite2(style.shadow?.blur ?? style.shadowBlur, 0);
1882
+ const shadowOffsetX = finite2(style.shadow?.offsetX ?? style.shadowOffsetX, 0);
1883
+ const shadowOffsetY = finite2(style.shadow?.offsetY ?? style.shadowOffsetY, 0);
1884
+ const hasShadow = !!shadowColor && (shadowBlur > 0 || shadowOffsetX !== 0 || shadowOffsetY !== 0);
1885
+ if (hasShadow) {
1886
+ ctx.shadowColor = cssColor(shadowColor, "#000000");
1887
+ ctx.shadowBlur = shadowBlur;
1888
+ ctx.shadowOffsetX = shadowOffsetX;
1889
+ ctx.shadowOffsetY = shadowOffsetY;
1890
+ }
1743
1891
  const lineHeight = fontSize * finite2(style.lineHeight, 1.2);
1744
1892
  const maxWidth = Math.max(1, layer.width);
1745
1893
  const lines = style.overflow === "wrap" ? wrapText(ctx, text, maxWidth) : [text];
@@ -1749,6 +1897,22 @@ function drawTextLayer(ctx, layer, style) {
1749
1897
  for (let index = 0; index < lines.length; index += 1) {
1750
1898
  letterSpacedText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
1751
1899
  }
1900
+ if (hasShadow) {
1901
+ ctx.shadowColor = "transparent";
1902
+ ctx.shadowBlur = 0;
1903
+ ctx.shadowOffsetX = 0;
1904
+ ctx.shadowOffsetY = 0;
1905
+ }
1906
+ const strokeColor = style.stroke?.color ?? style.strokeColor;
1907
+ const strokeWidth = finite2(style.stroke?.width ?? style.strokeWidth, 0);
1908
+ if (strokeWidth > 0 && strokeColor) {
1909
+ ctx.strokeStyle = cssColor(strokeColor, "#000000");
1910
+ ctx.lineWidth = strokeWidth;
1911
+ ctx.lineJoin = "round";
1912
+ for (let index = 0; index < lines.length; index += 1) {
1913
+ letterSpacedStrokeText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
1914
+ }
1915
+ }
1752
1916
  }
1753
1917
  function drawSplitTextLayer(ctx, layer, style, animator, progress) {
1754
1918
  const text = layer.text ?? "";
@@ -1933,6 +2097,7 @@ export {
1933
2097
  TEXT_TEMPLATE_RENDERER_VERSION,
1934
2098
  canonicalTemplateHash,
1935
2099
  normalizeTextTemplateArtifact,
2100
+ resolveTemplateControlValues,
1936
2101
  validateTextTemplateArtifact,
1937
2102
  assertValidTextTemplateArtifact,
1938
2103
  compileTextTemplate,
@@ -1943,4 +2108,4 @@ export {
1943
2108
  renderTextTemplateToCanvas,
1944
2109
  renderCanonicalToCanvas
1945
2110
  };
1946
- //# sourceMappingURL=chunk-V5D5SJPO.js.map
2111
+ //# sourceMappingURL=chunk-B2KQXJLS.js.map