@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.
- package/dist/{chunk-Q7XYDP4X.js → chunk-7VLGHWCA.js} +173 -13
- package/dist/chunk-7VLGHWCA.js.map +1 -0
- package/dist/{index-B1lFl4p2.d.ts → index-9ozUyd9c.d.ts} +1 -1
- package/dist/{index-DrzRbR7G.d.cts → index-CHLTQy2v.d.cts} +1 -1
- package/dist/{index-Cpps1DKP.d.ts → index-CYeaxi3E.d.cts} +47 -2
- package/dist/{index-WsvrOpAy.d.cts → index-_pgmsrBj.d.ts} +47 -2
- package/dist/index.cjs +668 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -12
- package/dist/index.d.ts +75 -12
- package/dist/index.js +515 -18
- package/dist/index.js.map +1 -1
- package/dist/rendering/index.cjs +127 -12
- package/dist/rendering/index.cjs.map +1 -1
- package/dist/rendering/index.d.cts +2 -2
- package/dist/rendering/index.d.ts +2 -2
- package/dist/rendering/index.js +3 -1
- package/dist/textEffects/index.d.cts +2 -2
- package/dist/textEffects/index.d.ts +2 -2
- package/dist/{types-IYwXGYkB.d.cts → types-BsF33bC4.d.cts} +40 -1
- package/dist/{types-IYwXGYkB.d.ts → types-BsF33bC4.d.ts} +40 -1
- package/package.json +1 -1
- package/dist/chunk-Q7XYDP4X.js.map +0 -1
package/dist/rendering/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(rendering_exports, {
|
|
|
25
25
|
renderCanonicalToCanvas: () => renderCanonicalToCanvas,
|
|
26
26
|
renderTextEffectToCanvas: () => renderTextEffectToCanvas,
|
|
27
27
|
renderTextTemplateToCanvas: () => renderTextTemplateToCanvas,
|
|
28
|
+
resolveTemplateFontFamily: () => resolveTemplateFontFamily,
|
|
28
29
|
resolveTextTemplateArtifact: () => resolveTextTemplateArtifact
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(rendering_exports);
|
|
@@ -2707,7 +2708,8 @@ function legacyLayerToNode(layer2, index) {
|
|
|
2707
2708
|
style: {
|
|
2708
2709
|
fontFamily: resolveStringProperty(text?.fontFamily, "Inter Variable"),
|
|
2709
2710
|
fontSize: resolveNumericProperty(text?.fontSize, 48),
|
|
2710
|
-
fontWeight:
|
|
2711
|
+
fontWeight: resolveAnimatableValue(text?.fontWeight, 400),
|
|
2712
|
+
fontStyle: text?.fontStyle === "italic" ? "italic" : "normal",
|
|
2711
2713
|
textColor: resolveStringProperty(
|
|
2712
2714
|
text?.color ?? text?.textColor,
|
|
2713
2715
|
"#FFFFFF"
|
|
@@ -2716,7 +2718,26 @@ function legacyLayerToNode(layer2, index) {
|
|
|
2716
2718
|
lineHeight: resolveNumericProperty(text?.lineHeight, 1.2),
|
|
2717
2719
|
letterSpacing: resolveNumericProperty(text?.letterSpacing, 0),
|
|
2718
2720
|
overflow: text?.overflow,
|
|
2719
|
-
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
|
|
2720
2741
|
},
|
|
2721
2742
|
backgroundPanel: text?.backgroundColor || text?.backgroundPanel ? {
|
|
2722
2743
|
color: text?.backgroundPanel?.color ?? text?.backgroundColor ? resolveStringProperty(
|
|
@@ -2761,9 +2782,10 @@ function legacyLayerToNode(layer2, index) {
|
|
|
2761
2782
|
charFillColors: Array.isArray(text?.charFillColors) ? clone(text.charFillColors) : void 0,
|
|
2762
2783
|
splitAnimator: text?.splitAnimator ? clone(text.splitAnimator) : void 0,
|
|
2763
2784
|
textEffectRef: text?.styleRef ? clone(text.styleRef) : void 0,
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
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
|
|
2767
2789
|
};
|
|
2768
2790
|
}
|
|
2769
2791
|
function inferControls(nodes) {
|
|
@@ -3509,16 +3531,90 @@ function letterSpacedText(ctx, text, x, y, maxWidth, letterSpacing) {
|
|
|
3509
3531
|
}
|
|
3510
3532
|
ctx.textAlign = align;
|
|
3511
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
|
+
}
|
|
3553
|
+
var FONT_ALIAS_MAP = {
|
|
3554
|
+
"inter": "Inter Variable",
|
|
3555
|
+
"inter variable": "Inter Variable",
|
|
3556
|
+
"outfit": "Outfit Variable",
|
|
3557
|
+
"outfit variable": "Outfit Variable",
|
|
3558
|
+
"playfair display": "Playfair Display Variable",
|
|
3559
|
+
"playfair display variable": "Playfair Display Variable",
|
|
3560
|
+
"montserrat": "Montserrat Variable",
|
|
3561
|
+
"montserrat variable": "Montserrat Variable",
|
|
3562
|
+
"roboto": "Roboto Variable",
|
|
3563
|
+
"roboto variable": "Roboto Variable",
|
|
3564
|
+
"roboto condensed": "Roboto Condensed Variable",
|
|
3565
|
+
"roboto condensed variable": "Roboto Condensed Variable",
|
|
3566
|
+
"raleway": "Raleway Variable",
|
|
3567
|
+
"raleway variable": "Raleway Variable",
|
|
3568
|
+
"space grotesk": "Space Grotesk Variable",
|
|
3569
|
+
"space grotesk variable": "Space Grotesk Variable",
|
|
3570
|
+
"nunito": "Nunito Variable",
|
|
3571
|
+
"nunito variable": "Nunito Variable",
|
|
3572
|
+
"open sans": "Open Sans Variable",
|
|
3573
|
+
"open sans variable": "Open Sans Variable",
|
|
3574
|
+
"oswald": "Oswald Variable",
|
|
3575
|
+
"oswald variable": "Oswald Variable",
|
|
3576
|
+
"geist": "Geist Variable",
|
|
3577
|
+
"geist variable": "Geist Variable",
|
|
3578
|
+
"dancing script": "Dancing Script Variable",
|
|
3579
|
+
"dancing script variable": "Dancing Script Variable"
|
|
3580
|
+
};
|
|
3581
|
+
function resolveTemplateFontFamily(family) {
|
|
3582
|
+
if (!family) return "sans-serif";
|
|
3583
|
+
const clean = String(family).trim().replace(/^["']|["']$/g, "");
|
|
3584
|
+
const lower = clean.toLowerCase();
|
|
3585
|
+
return FONT_ALIAS_MAP[lower] || clean;
|
|
3586
|
+
}
|
|
3587
|
+
function constructFontStack(fontStyle, fontWeight, fontSize, rawFamily) {
|
|
3588
|
+
const canonical = resolveTemplateFontFamily(rawFamily);
|
|
3589
|
+
const cleanRaw = String(rawFamily || "").trim().replace(/^["']|["']$/g, "");
|
|
3590
|
+
const style = fontStyle === "italic" ? "italic" : "normal";
|
|
3591
|
+
const weight = fontWeight ?? 400;
|
|
3592
|
+
if (canonical && cleanRaw && canonical.toLowerCase() !== cleanRaw.toLowerCase()) {
|
|
3593
|
+
return `${style} ${weight} ${fontSize}px "${canonical}", "${cleanRaw}", sans-serif`;
|
|
3594
|
+
}
|
|
3595
|
+
return `${style} ${weight} ${fontSize}px "${canonical || cleanRaw || "sans-serif"}", sans-serif`;
|
|
3596
|
+
}
|
|
3512
3597
|
function drawTextLayer(ctx, layer2, style) {
|
|
3513
3598
|
const text = layer2.text ?? "";
|
|
3514
3599
|
const fontSize = finite2(style.fontSize, 48);
|
|
3515
3600
|
const fontWeight = style.fontWeight ?? 400;
|
|
3516
|
-
const fontStyle = "normal";
|
|
3517
|
-
const
|
|
3518
|
-
ctx.font =
|
|
3601
|
+
const fontStyle = style.fontStyle || "normal";
|
|
3602
|
+
const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
|
|
3603
|
+
ctx.font = constructFontStack(fontStyle, fontWeight, fontSize, rawFamily);
|
|
3519
3604
|
ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
|
|
3520
3605
|
ctx.textAlign = style.textAlign ?? "left";
|
|
3521
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
|
+
}
|
|
3522
3618
|
const lineHeight = fontSize * finite2(style.lineHeight, 1.2);
|
|
3523
3619
|
const maxWidth = Math.max(1, layer2.width);
|
|
3524
3620
|
const lines = style.overflow === "wrap" ? wrapText(ctx, text, maxWidth) : [text];
|
|
@@ -3528,12 +3624,30 @@ function drawTextLayer(ctx, layer2, style) {
|
|
|
3528
3624
|
for (let index = 0; index < lines.length; index += 1) {
|
|
3529
3625
|
letterSpacedText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
|
|
3530
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
|
+
}
|
|
3531
3643
|
}
|
|
3532
3644
|
function drawSplitTextLayer(ctx, layer2, style, animator, progress) {
|
|
3533
3645
|
const text = layer2.text ?? "";
|
|
3534
3646
|
const fontSize = finite2(style.fontSize, 48);
|
|
3535
|
-
const
|
|
3536
|
-
|
|
3647
|
+
const fontWeight = style.fontWeight ?? 400;
|
|
3648
|
+
const fontStyle = style.fontStyle || "normal";
|
|
3649
|
+
const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
|
|
3650
|
+
ctx.font = constructFontStack(fontStyle, fontWeight, fontSize, rawFamily);
|
|
3537
3651
|
ctx.textBaseline = "middle";
|
|
3538
3652
|
ctx.textAlign = "left";
|
|
3539
3653
|
ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
|
|
@@ -3623,9 +3737,9 @@ function renderTextTemplateToCanvas(ctx, input) {
|
|
|
3623
3737
|
// Measure with the exact Canvas context that will draw the layer. This
|
|
3624
3738
|
// makes auto-sized nodes use loaded font metrics instead of a fixed box.
|
|
3625
3739
|
measureText: (text, style) => {
|
|
3626
|
-
const
|
|
3740
|
+
const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
|
|
3627
3741
|
ctx.save();
|
|
3628
|
-
ctx.font =
|
|
3742
|
+
ctx.font = constructFontStack(style.fontStyle, style.fontWeight, finite2(style.fontSize, 48), rawFamily);
|
|
3629
3743
|
const width = ctx.measureText(text).width + Math.max(0, text.length - 1) * finite2(style.letterSpacing, 0);
|
|
3630
3744
|
ctx.restore();
|
|
3631
3745
|
return { width };
|
|
@@ -3689,6 +3803,7 @@ function renderCanonicalToCanvas(ctx, input) {
|
|
|
3689
3803
|
renderCanonicalToCanvas,
|
|
3690
3804
|
renderTextEffectToCanvas,
|
|
3691
3805
|
renderTextTemplateToCanvas,
|
|
3806
|
+
resolveTemplateFontFamily,
|
|
3692
3807
|
resolveTextTemplateArtifact
|
|
3693
3808
|
});
|
|
3694
3809
|
//# sourceMappingURL=index.cjs.map
|