@clypra-studio/engine 1.6.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.
@@ -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) {
@@ -3511,6 +3531,25 @@ function letterSpacedText(ctx, text, x, y, maxWidth, letterSpacing) {
3511
3531
  }
3512
3532
  ctx.textAlign = align;
3513
3533
  }
3534
+ function letterSpacedStrokeText(ctx, text, x, y, maxWidth, letterSpacing) {
3535
+ if (!letterSpacing) {
3536
+ ctx.strokeText(text, x, y, maxWidth);
3537
+ return;
3538
+ }
3539
+ const glyphs = Array.from(text);
3540
+ const widths = glyphs.map((glyph) => ctx.measureText(glyph).width);
3541
+ const total = widths.reduce((sum, value) => sum + value, 0) + Math.max(0, glyphs.length - 1) * letterSpacing;
3542
+ const align = ctx.textAlign;
3543
+ let cursor = x;
3544
+ if (align === "center") cursor -= total / 2;
3545
+ if (align === "right") cursor -= total;
3546
+ ctx.textAlign = "left";
3547
+ for (let index = 0; index < glyphs.length; index += 1) {
3548
+ ctx.strokeText(glyphs[index], cursor, y);
3549
+ cursor += widths[index] + letterSpacing;
3550
+ }
3551
+ ctx.textAlign = align;
3552
+ }
3514
3553
  var FONT_ALIAS_MAP = {
3515
3554
  "inter": "Inter Variable",
3516
3555
  "inter variable": "Inter Variable",
@@ -3565,6 +3604,17 @@ function drawTextLayer(ctx, layer2, style) {
3565
3604
  ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
3566
3605
  ctx.textAlign = style.textAlign ?? "left";
3567
3606
  ctx.textBaseline = style.verticalAlign === "top" ? "top" : style.verticalAlign === "bottom" ? "bottom" : "middle";
3607
+ const shadowColor = style.shadow?.color ?? style.shadowColor;
3608
+ const shadowBlur = finite2(style.shadow?.blur ?? style.shadowBlur, 0);
3609
+ const shadowOffsetX = finite2(style.shadow?.offsetX ?? style.shadowOffsetX, 0);
3610
+ const shadowOffsetY = finite2(style.shadow?.offsetY ?? style.shadowOffsetY, 0);
3611
+ const hasShadow = !!shadowColor && (shadowBlur > 0 || shadowOffsetX !== 0 || shadowOffsetY !== 0);
3612
+ if (hasShadow) {
3613
+ ctx.shadowColor = cssColor(shadowColor, "#000000");
3614
+ ctx.shadowBlur = shadowBlur;
3615
+ ctx.shadowOffsetX = shadowOffsetX;
3616
+ ctx.shadowOffsetY = shadowOffsetY;
3617
+ }
3568
3618
  const lineHeight = fontSize * finite2(style.lineHeight, 1.2);
3569
3619
  const maxWidth = Math.max(1, layer2.width);
3570
3620
  const lines = style.overflow === "wrap" ? wrapText(ctx, text, maxWidth) : [text];
@@ -3574,6 +3624,22 @@ function drawTextLayer(ctx, layer2, style) {
3574
3624
  for (let index = 0; index < lines.length; index += 1) {
3575
3625
  letterSpacedText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
3576
3626
  }
3627
+ if (hasShadow) {
3628
+ ctx.shadowColor = "transparent";
3629
+ ctx.shadowBlur = 0;
3630
+ ctx.shadowOffsetX = 0;
3631
+ ctx.shadowOffsetY = 0;
3632
+ }
3633
+ const strokeColor = style.stroke?.color ?? style.strokeColor;
3634
+ const strokeWidth = finite2(style.stroke?.width ?? style.strokeWidth, 0);
3635
+ if (strokeWidth > 0 && strokeColor) {
3636
+ ctx.strokeStyle = cssColor(strokeColor, "#000000");
3637
+ ctx.lineWidth = strokeWidth;
3638
+ ctx.lineJoin = "round";
3639
+ for (let index = 0; index < lines.length; index += 1) {
3640
+ letterSpacedStrokeText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
3641
+ }
3642
+ }
3577
3643
  }
3578
3644
  function drawSplitTextLayer(ctx, layer2, style, animator, progress) {
3579
3645
  const text = layer2.text ?? "";