@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.
@@ -2718,7 +2718,26 @@ function legacyLayerToNode(layer2, index) {
2718
2718
  lineHeight: resolveNumericProperty(text?.lineHeight, 1.2),
2719
2719
  letterSpacing: resolveNumericProperty(text?.letterSpacing, 0),
2720
2720
  overflow: text?.overflow,
2721
- verticalAlign: text?.verticalAlign
2721
+ verticalAlign: text?.verticalAlign,
2722
+ strokeColor: text?.stroke?.color ?? text?.strokeColor ? resolveStringProperty(text?.stroke?.color ?? text?.strokeColor, "#000000") : void 0,
2723
+ strokeWidth: text?.stroke?.width ?? text?.strokeWidth ? resolveNumericProperty(text?.stroke?.width ?? text?.strokeWidth, 0) : void 0,
2724
+ shadowColor: text?.shadow?.color ?? text?.shadowColor ? resolveStringProperty(text?.shadow?.color ?? text?.shadowColor, "#000000") : void 0,
2725
+ shadowBlur: text?.shadow?.blur ?? text?.shadowBlur ? resolveNumericProperty(text?.shadow?.blur ?? text?.shadowBlur, 0) : void 0,
2726
+ shadowOffsetX: text?.shadow?.offsetX ?? text?.shadowOffsetX ? resolveNumericProperty(text?.shadow?.offsetX ?? text?.shadowOffsetX, 0) : void 0,
2727
+ shadowOffsetY: text?.shadow?.offsetY ?? text?.shadowOffsetY ? resolveNumericProperty(text?.shadow?.offsetY ?? text?.shadowOffsetY, 0) : void 0,
2728
+ stroke: text?.stroke ? {
2729
+ color: resolveStringProperty(text.stroke.color, "#000000"),
2730
+ width: resolveNumericProperty(text.stroke.width, 1)
2731
+ } : void 0,
2732
+ shadow: text?.shadow ? {
2733
+ color: resolveStringProperty(text.shadow.color, "#000000"),
2734
+ blur: resolveNumericProperty(text.shadow.blur, 0),
2735
+ offsetX: resolveNumericProperty(text.shadow.offsetX, 0),
2736
+ offsetY: resolveNumericProperty(text.shadow.offsetY, 0)
2737
+ } : void 0,
2738
+ fontId: text?.fontId || layer2?.fontId ? resolveStringProperty(text?.fontId ?? layer2?.fontId, "") : void 0,
2739
+ backgroundColor: text?.backgroundColor || layer2?.backgroundColor ? resolveStringProperty(text?.backgroundColor ?? layer2?.backgroundColor, "") : void 0,
2740
+ background: text?.background || layer2?.background ? clone(text?.background ?? layer2?.background) : void 0
2722
2741
  },
2723
2742
  backgroundPanel: text?.backgroundColor || text?.backgroundPanel ? {
2724
2743
  color: text?.backgroundPanel?.color ?? text?.backgroundColor ? resolveStringProperty(
@@ -2763,9 +2782,10 @@ function legacyLayerToNode(layer2, index) {
2763
2782
  charFillColors: Array.isArray(text?.charFillColors) ? clone(text.charFillColors) : void 0,
2764
2783
  splitAnimator: text?.splitAnimator ? clone(text.splitAnimator) : void 0,
2765
2784
  textEffectRef: text?.styleRef ? clone(text.styleRef) : void 0,
2766
- // Kept as optional metadata for compatibility with role-based editor
2767
- // customizations. The canonical renderer does not depend on roles.
2768
- ...layer2?.role ? { role: String(layer2.role) } : {}
2785
+ role: layer2?.role || text?.role || text?.textRole ? String(layer2?.role ?? text?.role ?? text?.textRole) : void 0,
2786
+ textRole: text?.textRole || (layer2?.role === "primary" || layer2?.role === "secondary" ? "title" : void 0),
2787
+ fontId: text?.fontId || layer2?.fontId ? resolveStringProperty(text?.fontId ?? layer2?.fontId, "") : void 0,
2788
+ maxWidth: resolveNumericProperty(text?.maxWidth ?? layer2?.maxWidth, 0) || void 0
2769
2789
  };
2770
2790
  }
2771
2791
  function inferControls(nodes) {
@@ -3128,6 +3148,24 @@ function compileTextTemplate(artifact, context) {
3128
3148
  const node = findNode(document2.nodes, control.target.nodeId);
3129
3149
  if (node) setPath(node, control.target.propertyPath, resolvedControls[control.id]);
3130
3150
  }
3151
+ if (context.controlValues) {
3152
+ for (const node of document2.nodes || []) {
3153
+ if (node.type === "text") {
3154
+ const textVal = context.controlValues[`text-${node.id}`];
3155
+ if (typeof textVal === "string") {
3156
+ node.text = textVal;
3157
+ }
3158
+ const fontVal = context.controlValues[`font-${node.id}`];
3159
+ if (typeof fontVal === "string") {
3160
+ node.style = { ...node.style, fontFamily: fontVal };
3161
+ }
3162
+ const colorVal = context.controlValues[`color-${node.id}`];
3163
+ if (typeof colorVal === "string") {
3164
+ node.style = { ...node.style, textColor: colorVal };
3165
+ }
3166
+ }
3167
+ }
3168
+ }
3131
3169
  const time = mapTime(context.time, artifact, context.clipDuration);
3132
3170
  const flexPositions = /* @__PURE__ */ new Map();
3133
3171
  const containers = (document2.nodes || []).filter((n) => n.type === "container");
@@ -3511,6 +3549,25 @@ function letterSpacedText(ctx, text, x, y, maxWidth, letterSpacing) {
3511
3549
  }
3512
3550
  ctx.textAlign = align;
3513
3551
  }
3552
+ function letterSpacedStrokeText(ctx, text, x, y, maxWidth, letterSpacing) {
3553
+ if (!letterSpacing) {
3554
+ ctx.strokeText(text, x, y, maxWidth);
3555
+ return;
3556
+ }
3557
+ const glyphs = Array.from(text);
3558
+ const widths = glyphs.map((glyph) => ctx.measureText(glyph).width);
3559
+ const total = widths.reduce((sum, value) => sum + value, 0) + Math.max(0, glyphs.length - 1) * letterSpacing;
3560
+ const align = ctx.textAlign;
3561
+ let cursor = x;
3562
+ if (align === "center") cursor -= total / 2;
3563
+ if (align === "right") cursor -= total;
3564
+ ctx.textAlign = "left";
3565
+ for (let index = 0; index < glyphs.length; index += 1) {
3566
+ ctx.strokeText(glyphs[index], cursor, y);
3567
+ cursor += widths[index] + letterSpacing;
3568
+ }
3569
+ ctx.textAlign = align;
3570
+ }
3514
3571
  var FONT_ALIAS_MAP = {
3515
3572
  "inter": "Inter Variable",
3516
3573
  "inter variable": "Inter Variable",
@@ -3565,6 +3622,17 @@ function drawTextLayer(ctx, layer2, style) {
3565
3622
  ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
3566
3623
  ctx.textAlign = style.textAlign ?? "left";
3567
3624
  ctx.textBaseline = style.verticalAlign === "top" ? "top" : style.verticalAlign === "bottom" ? "bottom" : "middle";
3625
+ const shadowColor = style.shadow?.color ?? style.shadowColor;
3626
+ const shadowBlur = finite2(style.shadow?.blur ?? style.shadowBlur, 0);
3627
+ const shadowOffsetX = finite2(style.shadow?.offsetX ?? style.shadowOffsetX, 0);
3628
+ const shadowOffsetY = finite2(style.shadow?.offsetY ?? style.shadowOffsetY, 0);
3629
+ const hasShadow = !!shadowColor && (shadowBlur > 0 || shadowOffsetX !== 0 || shadowOffsetY !== 0);
3630
+ if (hasShadow) {
3631
+ ctx.shadowColor = cssColor(shadowColor, "#000000");
3632
+ ctx.shadowBlur = shadowBlur;
3633
+ ctx.shadowOffsetX = shadowOffsetX;
3634
+ ctx.shadowOffsetY = shadowOffsetY;
3635
+ }
3568
3636
  const lineHeight = fontSize * finite2(style.lineHeight, 1.2);
3569
3637
  const maxWidth = Math.max(1, layer2.width);
3570
3638
  const lines = style.overflow === "wrap" ? wrapText(ctx, text, maxWidth) : [text];
@@ -3574,6 +3642,22 @@ function drawTextLayer(ctx, layer2, style) {
3574
3642
  for (let index = 0; index < lines.length; index += 1) {
3575
3643
  letterSpacedText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
3576
3644
  }
3645
+ if (hasShadow) {
3646
+ ctx.shadowColor = "transparent";
3647
+ ctx.shadowBlur = 0;
3648
+ ctx.shadowOffsetX = 0;
3649
+ ctx.shadowOffsetY = 0;
3650
+ }
3651
+ const strokeColor = style.stroke?.color ?? style.strokeColor;
3652
+ const strokeWidth = finite2(style.stroke?.width ?? style.strokeWidth, 0);
3653
+ if (strokeWidth > 0 && strokeColor) {
3654
+ ctx.strokeStyle = cssColor(strokeColor, "#000000");
3655
+ ctx.lineWidth = strokeWidth;
3656
+ ctx.lineJoin = "round";
3657
+ for (let index = 0; index < lines.length; index += 1) {
3658
+ letterSpacedStrokeText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
3659
+ }
3660
+ }
3577
3661
  }
3578
3662
  function drawSplitTextLayer(ctx, layer2, style, animator, progress) {
3579
3663
  const text = layer2.text ?? "";