@pixerate/editor 0.161.0 → 0.162.1
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/agent/index.cjs +36 -35
- package/dist/agent/index.js +7 -6
- package/dist/animation/index.cjs +5 -4
- package/dist/animation/index.js +4 -3
- package/dist/animation-editor/index.cjs +63 -62
- package/dist/animation-editor/index.js +7 -6
- package/dist/{brushstrokeRender-Q4LI22QV.js → brushstrokeRender-7LXCU7PD.js} +2 -2
- package/dist/{brushstrokeRender-5WANQIG4.cjs → brushstrokeRender-VO4ZTWVA.cjs} +5 -5
- package/dist/canvas/index.cjs +40 -39
- package/dist/canvas/index.js +7 -6
- package/dist/chart/index.cjs +88 -87
- package/dist/chart/index.js +7 -6
- package/dist/{chunk-LQLZHP6F.js → chunk-36OKQDCF.js} +7 -4
- package/dist/{chunk-AKDWAWSY.cjs → chunk-3IHNXRUV.cjs} +45 -45
- package/dist/{chunk-72BGL3I2.js → chunk-3VLOOO3G.js} +1 -1
- package/dist/{chunk-TVO6W2Q6.cjs → chunk-4NGVHHJB.cjs} +17 -17
- package/dist/chunk-4VU4CP7R.js +769 -0
- package/dist/{chunk-MHEXLG3M.cjs → chunk-5AARIS3R.cjs} +37 -37
- package/dist/{chunk-DBIVICAO.js → chunk-7CKPUUN4.js} +1 -1
- package/dist/{chunk-57JLBGJ5.cjs → chunk-7YBDRJXT.cjs} +8 -8
- package/dist/{chunk-KY3FYKP3.js → chunk-BQWGN5WH.js} +1 -1
- package/dist/{chunk-LEUZ4FRC.cjs → chunk-CIPIESX4.cjs} +3 -3
- package/dist/chunk-CJE5MOIS.js +347 -0
- package/dist/{chunk-5QBRAIVK.js → chunk-CX6JLDFC.js} +3 -3
- package/dist/{chunk-R3QY7PPL.js → chunk-DTSTNRPH.js} +1 -1
- package/dist/{chunk-6LUYFHHN.cjs → chunk-EQ46F75O.cjs} +51 -51
- package/dist/{chunk-UKCJ43YL.cjs → chunk-ES3UEVUT.cjs} +130 -898
- package/dist/{chunk-UM3RPYC5.js → chunk-EVPZ5IKN.js} +1 -1
- package/dist/{chunk-XNQ5EFB4.cjs → chunk-EY22AY6R.cjs} +16 -16
- package/dist/chunk-FKUKJ3XA.cjs +347 -0
- package/dist/{chunk-YABNLNY7.js → chunk-GLMP22FT.js} +3 -3
- package/dist/{chunk-SUF6WRXR.cjs → chunk-GTELFJRE.cjs} +2 -2
- package/dist/{chunk-AY65VQSU.js → chunk-H3OEM3Q2.js} +1 -1
- package/dist/{chunk-4YWAEV4W.cjs → chunk-HDGBM7EA.cjs} +26 -26
- package/dist/{chunk-H5XX4KHB.js → chunk-HLOKB7WW.js} +5 -3
- package/dist/{chunk-QMI5HZWA.cjs → chunk-JCXMJUQO.cjs} +5 -5
- package/dist/{chunk-WPPJH6X4.cjs → chunk-LL3H5XUH.cjs} +6 -4
- package/dist/{chunk-4T44CJ5K.cjs → chunk-NA4UVVJ4.cjs} +15 -15
- package/dist/{chunk-Q6PA362P.js → chunk-NO5QQDHZ.js} +2 -2
- package/dist/{chunk-3YDQLQH2.cjs → chunk-PA3IMPPS.cjs} +81 -81
- package/dist/{chunk-WNAAWLZ5.js → chunk-QY4KUDMY.js} +2 -2
- package/dist/{chunk-AA34BA7G.js → chunk-QYZGBVNC.js} +30 -798
- package/dist/chunk-S6X2QRVU.cjs +769 -0
- package/dist/{chunk-6UPGM3JB.js → chunk-SET6KJOP.js} +2 -2
- package/dist/{chunk-GNK7SESQ.cjs → chunk-V7GWZIZK.cjs} +7 -4
- package/dist/{chunk-EYVVIZJ3.cjs → chunk-WTW7QRTS.cjs} +1 -1
- package/dist/{chunk-SSCL7QQ4.js → chunk-XDCFJEU7.js} +2 -2
- package/dist/{chunk-JGKCC5OF.cjs → chunk-YQ5C5BVK.cjs} +10 -9
- package/dist/{chunk-A5UCR2TO.js → chunk-YXKLVD56.js} +10 -9
- package/dist/{chunk-45XXVHVG.js → chunk-ZZGPYNS2.js} +1 -1
- package/dist/color/index.cjs +6 -2
- package/dist/color/index.d.cts +1 -0
- package/dist/color/index.d.ts +1 -0
- package/dist/color/index.js +28 -24
- package/dist/color/suggest.d.cts +12 -0
- package/dist/color/suggest.d.ts +12 -0
- package/dist/effects/index.cjs +37 -13
- package/dist/effects/index.js +29 -5
- package/dist/effects/ui.d.cts +20 -3
- package/dist/effects/ui.d.ts +20 -3
- package/dist/export/index.cjs +6 -5
- package/dist/export/index.js +5 -4
- package/dist/extensions/index.cjs +9 -8
- package/dist/extensions/index.js +8 -7
- package/dist/gradient/index.cjs +28 -26
- package/dist/gradient/index.js +7 -5
- package/dist/image-editor/index.cjs +641 -640
- package/dist/image-editor/index.js +7 -6
- package/dist/index.cjs +15 -14
- package/dist/index.js +9 -8
- package/dist/paint/index.cjs +2 -2
- package/dist/paint/index.js +1 -1
- package/dist/paint-editor/index.cjs +136 -135
- package/dist/paint-editor/index.js +8 -7
- package/dist/typography/accessibility.d.cts +44 -0
- package/dist/typography/accessibility.d.ts +44 -0
- package/dist/typography/catalog.d.cts +98 -0
- package/dist/typography/catalog.d.ts +98 -0
- package/dist/typography/index.cjs +1099 -0
- package/dist/typography/index.d.cts +16 -0
- package/dist/typography/index.d.ts +16 -0
- package/dist/typography/index.js +1099 -0
- package/dist/typography/metrics.d.cts +31 -0
- package/dist/typography/metrics.d.ts +31 -0
- package/dist/typography/picker.d.cts +132 -0
- package/dist/typography/picker.d.ts +132 -0
- package/dist/typography/registry.d.cts +66 -0
- package/dist/typography/registry.d.ts +66 -0
- package/dist/typography/scale.d.cts +62 -0
- package/dist/typography/scale.d.ts +62 -0
- package/dist/typography/segment.d.cts +26 -0
- package/dist/typography/segment.d.ts +26 -0
- package/dist/typography/stack.d.cts +26 -0
- package/dist/typography/stack.d.ts +26 -0
- package/dist/typography/tools.d.cts +34 -0
- package/dist/typography/tools.d.ts +34 -0
- package/dist/typography/types.d.cts +96 -0
- package/dist/typography/types.d.ts +96 -0
- package/dist/typography/weight.d.cts +13 -0
- package/dist/typography/weight.d.ts +13 -0
- package/dist/vector/index.cjs +951 -950
- package/dist/vector/index.js +6 -5
- package/dist/video-editor/index.cjs +5 -4
- package/dist/video-editor/index.js +4 -3
- package/package.json +13 -3
- package/skills/README.md +1 -0
- package/skills/pixerate-chart/SKILL.md +92 -9
- package/skills/pixerate-paint-editor/SKILL.md +0 -2
- package/skills/pixerate-typography/SKILL.md +91 -0
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkJCXMJUQOcjs = require('./chunk-JCXMJUQO.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -29,7 +29,7 @@ var _chunkGF2RBSDMcjs = require('./chunk-GF2RBSDM.cjs');
|
|
|
29
29
|
var _chunkDWJJI6RTcjs = require('./chunk-DWJJI6RT.cjs');
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _chunkCIPIESX4cjs = require('./chunk-CIPIESX4.cjs');
|
|
33
33
|
|
|
34
34
|
// src/vector/blend.ts
|
|
35
35
|
var lerpN = (a, b, t) => a + (b - a) * t;
|
|
@@ -37,7 +37,7 @@ var lerpP = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
|
37
37
|
var toP = (v) => [v.x, v.y];
|
|
38
38
|
var mapP = (m, p) => [m[0] * p[0] + m[2] * p[1] + m[4], m[1] * p[0] + m[3] * p[1] + m[5]];
|
|
39
39
|
var curvesOf = (c) => Math.max(0, (c.pts.length - 1) / 3) | 0;
|
|
40
|
-
function subpathToMorphContour(sp, m =
|
|
40
|
+
function subpathToMorphContour(sp, m = _chunkJCXMJUQOcjs.IDENTITY_MATRIX) {
|
|
41
41
|
const n = sp.anchors.length;
|
|
42
42
|
if (!n) return null;
|
|
43
43
|
const first = mapP(m, toP(sp.anchors[0]));
|
|
@@ -67,8 +67,8 @@ function isStraight(p0, p1, p2, p3) {
|
|
|
67
67
|
const u2 = along(p2);
|
|
68
68
|
return off(p1) < tol && off(p2) < tol && u1 >= -1e-9 && u1 <= 1 + 1e-9 && u2 >= -1e-9 && u2 <= 1 + 1e-9;
|
|
69
69
|
}
|
|
70
|
-
function morphContourToSubpath(c, m =
|
|
71
|
-
const pts =
|
|
70
|
+
function morphContourToSubpath(c, m = _chunkJCXMJUQOcjs.IDENTITY_MATRIX, closed = c.closed) {
|
|
71
|
+
const pts = _chunkJCXMJUQOcjs.isIdentityMatrix.call(void 0, m) ? c.pts : c.pts.map((p) => mapP(m, p));
|
|
72
72
|
const curves = curvesOf(c);
|
|
73
73
|
const dropLast = closed && c.closed && curves > 0;
|
|
74
74
|
const count = dropLast ? curves : curves + 1;
|
|
@@ -84,7 +84,7 @@ function morphContourToSubpath(c, m = _chunkQMI5HZWAcjs.IDENTITY_MATRIX, closed
|
|
|
84
84
|
anchors[(k + 1) % count].in = { x: p2[0], y: p2[1] };
|
|
85
85
|
}
|
|
86
86
|
for (const a of anchors) {
|
|
87
|
-
const type =
|
|
87
|
+
const type = _chunkJCXMJUQOcjs.inferAnchorType.call(void 0, a);
|
|
88
88
|
if (type !== "corner") a.type = type;
|
|
89
89
|
}
|
|
90
90
|
const isClosed = closed && curves > 0;
|
|
@@ -267,7 +267,7 @@ function bestStart(fixed, free, useShapeContext) {
|
|
|
267
267
|
return best;
|
|
268
268
|
}
|
|
269
269
|
function placeIn(c, from, to) {
|
|
270
|
-
const b =
|
|
270
|
+
const b = _chunkJCXMJUQOcjs.unionBounds.call(void 0, [boundsOfPoints(c.pts)]);
|
|
271
271
|
const p = b ? [b.x + b.width / 2, b.y + b.height / 2] : c.pts[0];
|
|
272
272
|
if (!from || !to) return p;
|
|
273
273
|
const fx = from.width > 0 ? (p[0] - from.x) / from.width : 0.5;
|
|
@@ -452,11 +452,11 @@ function interpolateRigidMatrix(a, b, t) {
|
|
|
452
452
|
function interpolateVectorColor(a, b, t) {
|
|
453
453
|
if (t <= 0) return a;
|
|
454
454
|
if (t >= 1) return b;
|
|
455
|
-
return _nullishCoalesce(
|
|
455
|
+
return _nullishCoalesce(_chunkCIPIESX4cjs.mixColorsOklab.call(void 0, a, b, t), () => ( (t < 0.5 ? a : b)));
|
|
456
456
|
}
|
|
457
457
|
function resampleGradientStops(g, offsets) {
|
|
458
458
|
return offsets.map((offset) => {
|
|
459
|
-
const s =
|
|
459
|
+
const s = _chunkJCXMJUQOcjs.sampleVectorGradient.call(void 0, g, offset);
|
|
460
460
|
return s.opacity < 1 ? { offset, color: s.color, opacity: Math.round(s.opacity * 1e4) / 1e4 } : { offset, color: s.color };
|
|
461
461
|
});
|
|
462
462
|
}
|
|
@@ -467,11 +467,11 @@ function lerpAngle(a, b, t) {
|
|
|
467
467
|
var lerpPoint = (a, b, t) => ({ x: lerpN(a.x, b.x, t), y: lerpN(a.y, b.y, t) });
|
|
468
468
|
var sameColourModel = (a, b) => (_nullishCoalesce(a.interpolation, () => ( "srgb"))) === (_nullishCoalesce(b.interpolation, () => ( "srgb"))) && (_nullishCoalesce(a.smoothness, () => ( 0))) === (_nullishCoalesce(b.smoothness, () => ( 0)));
|
|
469
469
|
function lerpStops(a, b, t) {
|
|
470
|
-
let stopsA =
|
|
471
|
-
let stopsB =
|
|
470
|
+
let stopsA = _chunkJCXMJUQOcjs.sortedVectorGradientStops.call(void 0, a);
|
|
471
|
+
let stopsB = _chunkJCXMJUQOcjs.sortedVectorGradientStops.call(void 0, b);
|
|
472
472
|
const resampled = stopsA.length !== stopsB.length || !sameColourModel(a, b);
|
|
473
473
|
if (resampled) {
|
|
474
|
-
const offs = [...
|
|
474
|
+
const offs = [..._chunkJCXMJUQOcjs.expandVectorGradientStops.call(void 0, a), ..._chunkJCXMJUQOcjs.expandVectorGradientStops.call(void 0, b), ...stopsA, ...stopsB].map((s) => s.offset).filter(Number.isFinite).sort((x, y) => x - y);
|
|
475
475
|
const common = offs.filter((o, i) => i === 0 || o - offs[i - 1] > 1e-4);
|
|
476
476
|
stopsA = resampleGradientStops(a, common);
|
|
477
477
|
stopsB = resampleGradientStops(b, common);
|
|
@@ -498,8 +498,8 @@ function lerpGradient(a, b, t) {
|
|
|
498
498
|
}
|
|
499
499
|
if (near.spread && near.spread !== "pad") out.spread = near.spread;
|
|
500
500
|
if (near.strokeMode && near.strokeMode !== "within") out.strokeMode = near.strokeMode;
|
|
501
|
-
const ea =
|
|
502
|
-
const eb =
|
|
501
|
+
const ea = _chunkJCXMJUQOcjs.hasExplicitGradientGeometry.call(void 0, a);
|
|
502
|
+
const eb = _chunkJCXMJUQOcjs.hasExplicitGradientGeometry.call(void 0, b);
|
|
503
503
|
if (!ea && !eb) {
|
|
504
504
|
if (a.angle !== void 0 || b.angle !== void 0 || a.type === "linear" || a.type === "reflected") {
|
|
505
505
|
const fallback = a.type === "linear" || a.type === "reflected" ? 180 : 90;
|
|
@@ -512,10 +512,10 @@ function lerpGradient(a, b, t) {
|
|
|
512
512
|
}
|
|
513
513
|
return out;
|
|
514
514
|
}
|
|
515
|
-
const pa =
|
|
516
|
-
const pb =
|
|
515
|
+
const pa = _chunkJCXMJUQOcjs.vectorGradientPoints.call(void 0, a);
|
|
516
|
+
const pb = _chunkJCXMJUQOcjs.vectorGradientPoints.call(void 0, b);
|
|
517
517
|
if (pa.units !== pb.units) {
|
|
518
|
-
const src =
|
|
518
|
+
const src = _chunkJCXMJUQOcjs.explicitVectorGradient.call(void 0, near);
|
|
519
519
|
return { ...src, stops: out.stops, ...out.interpolation ? { interpolation: out.interpolation } : {}, ...out.smoothness ? { smoothness: out.smoothness } : {} };
|
|
520
520
|
}
|
|
521
521
|
out.start = lerpPoint(pa.start, pb.start, t);
|
|
@@ -535,14 +535,14 @@ function solidLike(color, like) {
|
|
|
535
535
|
function interpolateVectorPaint(a, b, t) {
|
|
536
536
|
if (t <= 0) return a;
|
|
537
537
|
if (t >= 1) return b;
|
|
538
|
-
const pa =
|
|
539
|
-
const pb =
|
|
538
|
+
const pa = _chunkJCXMJUQOcjs.hasPaint.call(void 0, a);
|
|
539
|
+
const pb = _chunkJCXMJUQOcjs.hasPaint.call(void 0, b);
|
|
540
540
|
if (!pa && !pb) return t < 0.5 ? a : b;
|
|
541
541
|
if (typeof a === "string" && pa && typeof b === "string" && pb) return interpolateVectorColor(a, b, t);
|
|
542
542
|
if (!pa && typeof b === "string") return interpolateVectorColor("transparent", b, t);
|
|
543
543
|
if (!pb && typeof a === "string") return interpolateVectorColor(a, "transparent", t);
|
|
544
|
-
const ga = pa &&
|
|
545
|
-
const gb = pb &&
|
|
544
|
+
const ga = pa && _chunkJCXMJUQOcjs.isVectorGradient.call(void 0, a) ? a : null;
|
|
545
|
+
const gb = pb && _chunkJCXMJUQOcjs.isVectorGradient.call(void 0, b) ? b : null;
|
|
546
546
|
if (ga && gb) return _nullishCoalesce(lerpGradient(ga, gb, t), () => ( (t < 0.5 ? a : b)));
|
|
547
547
|
if (gb) return _nullishCoalesce(lerpGradient(solidLike(pa ? a : null, gb), gb, t), () => ( b));
|
|
548
548
|
if (ga) return _nullishCoalesce(lerpGradient(ga, solidLike(pb ? b : null, ga), t), () => ( a));
|
|
@@ -553,8 +553,8 @@ function interpolateWidthProfiles(a, b, t) {
|
|
|
553
553
|
const at = [..._nullishCoalesce(a, () => ( [])), ..._nullishCoalesce(b, () => ( [])), { t: 0 }, { t: 1 }].map((p) => p.t).sort((x, y) => x - y);
|
|
554
554
|
const ts = at.filter((v, i) => i === 0 || v - at[i - 1] > 1e-6);
|
|
555
555
|
return ts.map((pos) => {
|
|
556
|
-
const x =
|
|
557
|
-
const y =
|
|
556
|
+
const x = _chunkJCXMJUQOcjs.widthProfileAt.call(void 0, a, pos);
|
|
557
|
+
const y = _chunkJCXMJUQOcjs.widthProfileAt.call(void 0, b, pos);
|
|
558
558
|
return { t: pos, left: lerpN(x.left, y.left, t), right: lerpN(x.right, y.right, t) };
|
|
559
559
|
});
|
|
560
560
|
}
|
|
@@ -597,7 +597,7 @@ function reversedStyle(s) {
|
|
|
597
597
|
out.endArrow = s.startArrow;
|
|
598
598
|
out.startArrowScale = s.endArrowScale;
|
|
599
599
|
out.endArrowScale = s.startArrowScale;
|
|
600
|
-
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile =
|
|
600
|
+
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile = _chunkJCXMJUQOcjs.reverseWidthProfile.call(void 0, s.strokeWidthProfile);
|
|
601
601
|
for (const k of ["startArrow", "endArrow", "startArrowScale", "endArrowScale"]) if (out[k] === void 0) delete out[k];
|
|
602
602
|
return out;
|
|
603
603
|
}
|
|
@@ -623,19 +623,19 @@ function styleOf(n) {
|
|
|
623
623
|
return out;
|
|
624
624
|
}
|
|
625
625
|
function contoursOf(node, m) {
|
|
626
|
-
return
|
|
626
|
+
return _chunkJCXMJUQOcjs.expandVectorCorners.call(void 0, node.subpaths).map((sp) => subpathToMorphContour(sp, m)).filter((c) => !!c);
|
|
627
627
|
}
|
|
628
|
-
function preparePathMorph(a, b, options, ma =
|
|
628
|
+
function preparePathMorph(a, b, options, ma = _chunkJCXMJUQOcjs.nodeMatrix.call(void 0, a), mb = _chunkJCXMJUQOcjs.nodeMatrix.call(void 0, b)) {
|
|
629
629
|
const corr = correspondMorphContours(contoursOf(a, ma), contoursOf(b, mb), options);
|
|
630
630
|
const sim = procrustes(corr.a, corr.b);
|
|
631
631
|
const styleA = styleOf(a);
|
|
632
632
|
const styleB = corr.reversed ? reversedStyle(styleOf(b)) : styleOf(b);
|
|
633
|
-
const rigid = !
|
|
633
|
+
const rigid = !_chunkJCXMJUQOcjs.isIdentityMatrix.call(void 0, ma) || !_chunkJCXMJUQOcjs.isIdentityMatrix.call(void 0, mb);
|
|
634
634
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
635
635
|
return (t) => {
|
|
636
636
|
const contours = interpolateMorphContours(corr.a, corr.b, t, { linear: options.linear, rigidity: options.rigidity, similarity: sim });
|
|
637
|
-
const m = rigid ? interpolateRigidMatrix(ma, mb, t) :
|
|
638
|
-
const back = rigid ?
|
|
637
|
+
const m = rigid ? interpolateRigidMatrix(ma, mb, t) : _chunkJCXMJUQOcjs.IDENTITY_MATRIX;
|
|
638
|
+
const back = rigid ? _chunkJCXMJUQOcjs.invertMatrix.call(void 0, m) : _chunkJCXMJUQOcjs.IDENTITY_MATRIX;
|
|
639
639
|
const subpaths = contours.map((c, k) => {
|
|
640
640
|
const closed = t <= 0 ? corr.a[k].closed : t >= 1 ? corr.b[k].closed : corr.a[k].closed && corr.b[k].closed;
|
|
641
641
|
return morphContourToSubpath({ closed: corr.a[k].closed && corr.b[k].closed, pts: c.pts }, back, closed);
|
|
@@ -643,14 +643,14 @@ function preparePathMorph(a, b, options, ma = _chunkQMI5HZWAcjs.nodeMatrix.call(
|
|
|
643
643
|
const node = { id, type: "path", subpaths, ...interpolateVectorStyle(styleA, styleB, t) };
|
|
644
644
|
const opacity = lerpN(_nullishCoalesce(a.opacity, () => ( 1)), _nullishCoalesce(b.opacity, () => ( 1)), t);
|
|
645
645
|
if (opacity < 1) node.opacity = opacity;
|
|
646
|
-
if (rigid && !
|
|
646
|
+
if (rigid && !_chunkJCXMJUQOcjs.isIdentityMatrix.call(void 0, m)) node.transform = m;
|
|
647
647
|
return node;
|
|
648
648
|
};
|
|
649
649
|
}
|
|
650
|
-
function flattenPaths(node, parent =
|
|
651
|
-
const m =
|
|
650
|
+
function flattenPaths(node, parent = _chunkJCXMJUQOcjs.IDENTITY_MATRIX) {
|
|
651
|
+
const m = _chunkJCXMJUQOcjs.multiplyMatrices.call(void 0, _chunkJCXMJUQOcjs.nodeMatrix.call(void 0, node), parent);
|
|
652
652
|
if (node.type === "path") return [{ path: node, m, opacity: 1 }];
|
|
653
|
-
if (node.type === "text" || node.type === "instance") return flattenPaths(
|
|
653
|
+
if (node.type === "text" || node.type === "instance") return flattenPaths(_chunkJCXMJUQOcjs.expandVectorAppearance.call(void 0, node), parent);
|
|
654
654
|
const o = _nullishCoalesce(node.opacity, () => ( 1));
|
|
655
655
|
return node.children.filter((c) => c.visible !== false).flatMap((c) => flattenPaths(c, m)).map((e) => ({ ...e, opacity: e.opacity * o }));
|
|
656
656
|
}
|
|
@@ -672,8 +672,8 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
672
672
|
}
|
|
673
673
|
const pa = flattenPaths(a);
|
|
674
674
|
const pb = flattenPaths(b);
|
|
675
|
-
const ba =
|
|
676
|
-
const bb =
|
|
675
|
+
const ba = _chunkJCXMJUQOcjs.unionBounds.call(void 0, pa.map((e) => placedBounds(e.path, e.m)));
|
|
676
|
+
const bb = _chunkJCXMJUQOcjs.unionBounds.call(void 0, pb.map((e) => placedBounds(e.path, e.m)));
|
|
677
677
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
678
678
|
const parts = [];
|
|
679
679
|
const opacities = [];
|
|
@@ -685,10 +685,10 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
685
685
|
parts.push(preparePathMorph(x.path, y.path, sub, x.m, y.m));
|
|
686
686
|
opacities.push([x.opacity, y.opacity]);
|
|
687
687
|
} else if (x) {
|
|
688
|
-
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m,
|
|
688
|
+
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m, _chunkJCXMJUQOcjs.IDENTITY_MATRIX));
|
|
689
689
|
opacities.push([x.opacity, x.opacity]);
|
|
690
690
|
} else if (y) {
|
|
691
|
-
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub,
|
|
691
|
+
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub, _chunkJCXMJUQOcjs.IDENTITY_MATRIX, y.m));
|
|
692
692
|
opacities.push([y.opacity, y.opacity]);
|
|
693
693
|
}
|
|
694
694
|
}
|
|
@@ -11,10 +11,10 @@ var _chunkYN6JKAUEcjs = require('./chunk-YN6JKAUE.cjs');
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkNA4UVVJ4cjs = require('./chunk-NA4UVVJ4.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _chunkLL3H5XUHcjs = require('./chunk-LL3H5XUH.cjs');
|
|
18
18
|
|
|
19
19
|
// src/export/images.ts
|
|
20
20
|
var DOCX_IMAGE_TYPES = {
|
|
@@ -1028,12 +1028,12 @@ var DocxBuilder = (_class2 = class {
|
|
|
1028
1028
|
this.drop("node", "chart", "chart has no spec");
|
|
1029
1029
|
return;
|
|
1030
1030
|
}
|
|
1031
|
-
const spec =
|
|
1032
|
-
const written =
|
|
1031
|
+
const spec = _chunkLL3H5XUHcjs.normalizeChartSpec.call(void 0, raw).spec;
|
|
1032
|
+
const written = _chunkNA4UVVJ4cjs.chartToOoxml.call(void 0, spec);
|
|
1033
1033
|
for (const issue of written.issues) this.drop("node", "chart", issue);
|
|
1034
1034
|
const name = `chart${this.charts.length + 1}.xml`;
|
|
1035
1035
|
this.charts.push(written.xml);
|
|
1036
|
-
const relId = this.rels.add(
|
|
1036
|
+
const relId = this.rels.add(_chunkNA4UVVJ4cjs.CHART_OOXML_RELATIONSHIP, `charts/${name}`);
|
|
1037
1037
|
let width = _nullishCoalesce(pixelAttr(_optionalChain([node, 'access', _91 => _91.attrs, 'optionalAccess', _92 => _92.width])), () => ( MAX_IMAGE_WIDTH_PX));
|
|
1038
1038
|
let height = _nullishCoalesce(pixelAttr(_optionalChain([node, 'access', _93 => _93.attrs, 'optionalAccess', _94 => _94.height])), () => ( 320));
|
|
1039
1039
|
if (width > MAX_IMAGE_WIDTH_PX) {
|
|
@@ -1050,8 +1050,8 @@ var DocxBuilder = (_class2 = class {
|
|
|
1050
1050
|
drawing.empty("wp:extent", { cx, cy }).empty("wp:effectExtent", { l: 0, t: 0, r: 0, b: 0 });
|
|
1051
1051
|
drawing.empty("wp:docPr", { id, name: `Chart ${id}`, descr: title || void 0, title: title || void 0 });
|
|
1052
1052
|
drawing.empty("wp:cNvGraphicFramePr");
|
|
1053
|
-
drawing.open("a:graphic").open("a:graphicData", { uri:
|
|
1054
|
-
drawing.empty("c:chart", { "xmlns:c":
|
|
1053
|
+
drawing.open("a:graphic").open("a:graphicData", { uri: _chunkNA4UVVJ4cjs.CHART_OOXML_NS });
|
|
1054
|
+
drawing.empty("c:chart", { "xmlns:c": _chunkNA4UVVJ4cjs.CHART_OOXML_NS, "r:id": relId });
|
|
1055
1055
|
drawing.close("a:graphicData").close("a:graphic").close("wp:inline").close("w:drawing").close("w:r");
|
|
1056
1056
|
this.report.written.paragraphs++;
|
|
1057
1057
|
w.open("w:p");
|
|
@@ -1384,7 +1384,7 @@ var DocxBuilder = (_class2 = class {
|
|
|
1384
1384
|
if (people) add("word/people.xml", people, `${CT_WML}people+xml`);
|
|
1385
1385
|
parts.push({ name: "word/_rels/document.xml.rels", data: this.rels.xml() });
|
|
1386
1386
|
for (const file of this.media) parts.push({ name: `word/media/${file.name}`, data: file.bytes });
|
|
1387
|
-
this.charts.forEach((xml, i) => add(`word/charts/chart${i + 1}.xml`, xml,
|
|
1387
|
+
this.charts.forEach((xml, i) => add(`word/charts/chart${i + 1}.xml`, xml, _chunkNA4UVVJ4cjs.CHART_OOXML_CONTENT_TYPE));
|
|
1388
1388
|
add("docProps/core.xml", this.coreXml(now), "application/vnd.openxmlformats-package.core-properties+xml");
|
|
1389
1389
|
const app = new XmlWriter();
|
|
1390
1390
|
app.open("Properties", { xmlns: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" });
|
|
@@ -6,15 +6,15 @@ var _chunkA6QWKBJPcjs = require('./chunk-A6QWKBJP.cjs');
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkS6X2QRVUcjs = require('./chunk-S6X2QRVU.cjs');
|
|
10
10
|
|
|
11
11
|
// src/animation/color.ts
|
|
12
12
|
function rgbToOklab2(r, g, b, alpha = 1) {
|
|
13
|
-
const lab =
|
|
13
|
+
const lab = _chunkS6X2QRVUcjs.rgbToOklab.call(void 0, { r, g, b, a: alpha });
|
|
14
14
|
return { l: lab.l, a: lab.a, b: lab.b, alpha: lab.alpha };
|
|
15
15
|
}
|
|
16
16
|
function oklabToRgb2(color) {
|
|
17
|
-
const c =
|
|
17
|
+
const c = _chunkS6X2QRVUcjs.oklabToRgb.call(void 0, { l: color.l, a: color.a, b: color.b, alpha: color.alpha });
|
|
18
18
|
const clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
19
19
|
return {
|
|
20
20
|
r: clamp01(c.r),
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// src/typography/weight.ts
|
|
2
|
+
function normalizeFontWeight(weight) {
|
|
3
|
+
if (weight === void 0 || weight === "normal") return 400;
|
|
4
|
+
if (weight === "bold") return 700;
|
|
5
|
+
if (typeof weight !== "number" || !Number.isFinite(weight)) return 400;
|
|
6
|
+
return Math.min(9, Math.max(1, Math.round(weight / 100))) * 100;
|
|
7
|
+
}
|
|
8
|
+
function isFontWeight(value) {
|
|
9
|
+
return value === "normal" || value === "bold" || typeof value === "number" && value >= 100 && value <= 900 && value % 100 === 0;
|
|
10
|
+
}
|
|
11
|
+
function nearestFontWeight(wanted, available) {
|
|
12
|
+
const target = normalizeFontWeight(wanted);
|
|
13
|
+
const weights = [...new Set(available.map((w) => normalizeFontWeight(w)))].sort((a, b) => a - b);
|
|
14
|
+
if (!weights.length) return target;
|
|
15
|
+
if (weights.includes(target)) return target;
|
|
16
|
+
const lighter = weights.filter((w) => w < target).reverse();
|
|
17
|
+
const heavier = weights.filter((w) => w > target);
|
|
18
|
+
if (target === 400 && weights.includes(500)) return 500;
|
|
19
|
+
if (target === 500 && weights.includes(400)) return 400;
|
|
20
|
+
if (target <= 500) return lighter[0] ?? heavier[0];
|
|
21
|
+
return heavier[0] ?? lighter[0];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/typography/registry.ts
|
|
25
|
+
function fontHasWeight(font, weight) {
|
|
26
|
+
const w = normalizeFontWeight(weight);
|
|
27
|
+
const ws = font.weights.map((x) => normalizeFontWeight(x));
|
|
28
|
+
if (font.isVariable && ws.length) return w >= Math.min(...ws) && w <= Math.max(...ws);
|
|
29
|
+
return ws.includes(w);
|
|
30
|
+
}
|
|
31
|
+
function filterFonts(fonts, filter = {}) {
|
|
32
|
+
const q = filter.query?.trim().toLowerCase() ?? "";
|
|
33
|
+
const kept = fonts.filter(
|
|
34
|
+
(f) => (!filter.category || f.category === filter.category) && (!filter.source || f.source === filter.source) && (filter.weight === void 0 || fontHasWeight(f, filter.weight)) && (!filter.style || f.styles.includes(filter.style)) && (filter.isVariable === void 0 || !!f.isVariable === filter.isVariable) && (!q || f.family.toLowerCase().includes(q))
|
|
35
|
+
);
|
|
36
|
+
if (!q) return kept;
|
|
37
|
+
const starts = kept.filter((f) => f.family.toLowerCase().startsWith(q));
|
|
38
|
+
return [...starts, ...kept.filter((f) => !f.family.toLowerCase().startsWith(q))];
|
|
39
|
+
}
|
|
40
|
+
function findFont(fonts, family) {
|
|
41
|
+
const lower = family.trim().toLowerCase();
|
|
42
|
+
return fonts.find((f) => f.family.toLowerCase() === lower);
|
|
43
|
+
}
|
|
44
|
+
function combineFontProviders(providers, options = {}) {
|
|
45
|
+
const owner = async (family) => {
|
|
46
|
+
for (const p of providers) if (await p.hasFont(family)) return p;
|
|
47
|
+
for (const p of providers) if (findFont(await p.listFonts(), family)) return p;
|
|
48
|
+
return void 0;
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
id: options.id ?? "fonts",
|
|
52
|
+
async listFonts() {
|
|
53
|
+
const seen = /* @__PURE__ */ new Set();
|
|
54
|
+
const out = [];
|
|
55
|
+
for (const p of providers) {
|
|
56
|
+
for (const f of await p.listFonts()) {
|
|
57
|
+
const key = f.family.toLowerCase();
|
|
58
|
+
if (seen.has(key)) continue;
|
|
59
|
+
seen.add(key);
|
|
60
|
+
out.push(f);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
},
|
|
65
|
+
async hasFont(family) {
|
|
66
|
+
for (const p of providers) if (await p.hasFont(family)) return true;
|
|
67
|
+
return false;
|
|
68
|
+
},
|
|
69
|
+
async loadFont(family, weight, style) {
|
|
70
|
+
for (const p of providers) {
|
|
71
|
+
if (!p.loadFont) continue;
|
|
72
|
+
if (findFont(await p.listFonts(), family)) return p.loadFont(family, weight, style);
|
|
73
|
+
}
|
|
74
|
+
return !!await owner(family);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function ensureFontsLoaded(provider, specs) {
|
|
79
|
+
const result = { loaded: [], failed: [] };
|
|
80
|
+
const seen = /* @__PURE__ */ new Set();
|
|
81
|
+
await Promise.all(
|
|
82
|
+
specs.map(async (s) => {
|
|
83
|
+
const key = `${s.family.toLowerCase()}|${normalizeFontWeight(s.weight)}|${s.style ?? "normal"}`;
|
|
84
|
+
if (seen.has(key)) return;
|
|
85
|
+
seen.add(key);
|
|
86
|
+
const ok = provider.loadFont ? await provider.loadFont(s.family, s.weight, s.style).catch(() => false) : await provider.hasFont(s.family);
|
|
87
|
+
(ok ? result.loaded : result.failed).push(s.family);
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/typography/catalog.ts
|
|
94
|
+
var ALL = ["macos", "windows", "ios", "android", "linux"];
|
|
95
|
+
var R = [400, 700];
|
|
96
|
+
var NI = ["normal", "italic"];
|
|
97
|
+
var N = ["normal"];
|
|
98
|
+
var sys = (family, category, platforms, weights = R, styles = NI, isVariable) => ({
|
|
99
|
+
family,
|
|
100
|
+
category,
|
|
101
|
+
weights,
|
|
102
|
+
styles,
|
|
103
|
+
source: "system",
|
|
104
|
+
platforms,
|
|
105
|
+
...isVariable ? { isVariable } : {}
|
|
106
|
+
});
|
|
107
|
+
var SYSTEM_FONT_CATALOG = [
|
|
108
|
+
// Sans-serif
|
|
109
|
+
sys("Arial", "sans-serif", ["macos", "windows", "ios"]),
|
|
110
|
+
sys("Helvetica", "sans-serif", ["macos", "ios"], [300, 400, 700]),
|
|
111
|
+
sys("Helvetica Neue", "sans-serif", ["macos", "ios"], [100, 200, 300, 400, 500, 700]),
|
|
112
|
+
sys("Segoe UI", "sans-serif", ["windows"], [300, 400, 600, 700, 900]),
|
|
113
|
+
sys("Roboto", "sans-serif", ["android"], [100, 300, 400, 500, 700, 900]),
|
|
114
|
+
sys("Verdana", "sans-serif", ["macos", "windows"]),
|
|
115
|
+
sys("Tahoma", "sans-serif", ["macos", "windows"], R, N),
|
|
116
|
+
sys("Trebuchet MS", "sans-serif", ["macos", "windows"]),
|
|
117
|
+
sys("Calibri", "sans-serif", ["windows"], [300, 400, 700]),
|
|
118
|
+
sys("Candara", "sans-serif", ["windows"], [300, 400, 700]),
|
|
119
|
+
sys("Optima", "sans-serif", ["macos"], [400, 700, 800]),
|
|
120
|
+
sys("Gill Sans", "sans-serif", ["macos"], [300, 400, 600]),
|
|
121
|
+
sys("Avenir", "sans-serif", ["macos", "ios"], [300, 400, 500, 800, 900]),
|
|
122
|
+
sys("Avenir Next", "sans-serif", ["macos", "ios"], [200, 400, 500, 600, 700, 800]),
|
|
123
|
+
sys("Futura", "sans-serif", ["macos", "ios"], [400, 500, 700]),
|
|
124
|
+
sys("Century Gothic", "sans-serif", ["windows"]),
|
|
125
|
+
sys("Noto Sans", "sans-serif", ["android", "linux"], [100, 200, 300, 400, 500, 600, 700, 800, 900], NI, true),
|
|
126
|
+
sys("DejaVu Sans", "sans-serif", ["linux"], [200, 400, 700]),
|
|
127
|
+
sys("Liberation Sans", "sans-serif", ["linux"]),
|
|
128
|
+
sys("Ubuntu", "sans-serif", ["linux"], [300, 400, 500, 700]),
|
|
129
|
+
sys("Cantarell", "sans-serif", ["linux"], [100, 200, 300, 400, 500, 600, 700, 800], N, true),
|
|
130
|
+
// Serif
|
|
131
|
+
sys("Georgia", "serif", ["macos", "windows", "ios"]),
|
|
132
|
+
sys("Times New Roman", "serif", ["macos", "windows", "ios"]),
|
|
133
|
+
sys("Times", "serif", ["macos", "ios"]),
|
|
134
|
+
sys("Cambria", "serif", ["windows"]),
|
|
135
|
+
sys("Constantia", "serif", ["windows"]),
|
|
136
|
+
sys("Sitka Text", "serif", ["windows"], [400, 600, 700], NI, true),
|
|
137
|
+
sys("Charter", "serif", ["macos", "ios"], [400, 700, 900]),
|
|
138
|
+
sys("Iowan Old Style", "serif", ["macos", "ios"], [400, 700, 900]),
|
|
139
|
+
sys("Palatino", "serif", ["macos"]),
|
|
140
|
+
sys("Palatino Linotype", "serif", ["windows"]),
|
|
141
|
+
sys("Baskerville", "serif", ["macos", "ios"], [400, 600, 700]),
|
|
142
|
+
sys("Hoefler Text", "serif", ["macos"], [400, 900]),
|
|
143
|
+
sys("Garamond", "serif", ["windows"]),
|
|
144
|
+
sys("Book Antiqua", "serif", ["windows"]),
|
|
145
|
+
sys("Noto Serif", "serif", ["android", "linux"], [100, 200, 300, 400, 500, 600, 700, 800, 900], NI, true),
|
|
146
|
+
sys("DejaVu Serif", "serif", ["linux"]),
|
|
147
|
+
sys("Liberation Serif", "serif", ["linux"]),
|
|
148
|
+
// Monospace
|
|
149
|
+
sys("Menlo", "monospace", ["macos"]),
|
|
150
|
+
sys("Monaco", "monospace", ["macos"], [400], N),
|
|
151
|
+
sys("SF Mono", "monospace", ["macos"], [300, 400, 500, 600, 700, 800]),
|
|
152
|
+
sys("Consolas", "monospace", ["windows"]),
|
|
153
|
+
sys("Cascadia Code", "monospace", ["windows"], [200, 300, 400, 500, 600, 700], NI, true),
|
|
154
|
+
sys("Cascadia Mono", "monospace", ["windows"], [200, 300, 400, 500, 600, 700], NI, true),
|
|
155
|
+
sys("Courier New", "monospace", ["macos", "windows", "ios"]),
|
|
156
|
+
sys("Lucida Console", "monospace", ["windows"], [400], N),
|
|
157
|
+
sys("DejaVu Sans Mono", "monospace", ["linux"]),
|
|
158
|
+
sys("Liberation Mono", "monospace", ["linux"]),
|
|
159
|
+
sys("Ubuntu Mono", "monospace", ["linux"]),
|
|
160
|
+
sys("Droid Sans Mono", "monospace", ["android"], [400], N),
|
|
161
|
+
// Display
|
|
162
|
+
sys("Impact", "display", ["macos", "windows"], [400], N),
|
|
163
|
+
sys("Copperplate", "display", ["macos"], [300, 400, 700], N),
|
|
164
|
+
sys("Rockwell", "display", ["macos", "windows"]),
|
|
165
|
+
sys("Didot", "display", ["macos", "ios"], [400, 700]),
|
|
166
|
+
sys("Bodoni 72", "display", ["macos", "ios"], [400, 700]),
|
|
167
|
+
sys("Arial Black", "display", ["macos", "windows"], [900], N),
|
|
168
|
+
// Handwriting
|
|
169
|
+
sys("Comic Sans MS", "handwriting", ["macos", "windows"]),
|
|
170
|
+
sys("Segoe Print", "handwriting", ["windows"], R, N),
|
|
171
|
+
sys("Segoe Script", "handwriting", ["windows"], R, N),
|
|
172
|
+
sys("Bradley Hand", "handwriting", ["macos", "ios"], [700], N),
|
|
173
|
+
sys("Brush Script MT", "handwriting", ["macos", "windows"], [400], ["italic"]),
|
|
174
|
+
sys("Snell Roundhand", "handwriting", ["macos", "ios"], [400, 700, 900], N),
|
|
175
|
+
sys("Noteworthy", "handwriting", ["macos", "ios"], [300, 700], N)
|
|
176
|
+
];
|
|
177
|
+
var FONT_PLATFORMS = ALL;
|
|
178
|
+
function guessFontCategory(family) {
|
|
179
|
+
const known = findFont(SYSTEM_FONT_CATALOG, family);
|
|
180
|
+
if (known) return known.category;
|
|
181
|
+
const lower = family.toLowerCase();
|
|
182
|
+
if (lower === "monospace" || lower === "ui-monospace" || /\bmono|code|courier|consol/.test(lower)) return "monospace";
|
|
183
|
+
if (lower === "cursive" || /script|hand|brush|marker/.test(lower)) return "handwriting";
|
|
184
|
+
if (lower === "fantasy" || /display|poster/.test(lower)) return "display";
|
|
185
|
+
if (/sans/.test(lower)) return "sans-serif";
|
|
186
|
+
if (lower === "serif" || lower === "ui-serif" || /serif|times|garamond|georgia|baskerville|caslon|bodoni|didot/.test(lower)) return "serif";
|
|
187
|
+
return "sans-serif";
|
|
188
|
+
}
|
|
189
|
+
function createCatalogFontProvider(fonts, options = {}) {
|
|
190
|
+
const list = [...fonts];
|
|
191
|
+
return {
|
|
192
|
+
id: options.id ?? "catalog",
|
|
193
|
+
listFonts: async () => list.map((f) => ({ ...f })),
|
|
194
|
+
hasFont: (family) => !!findFont(list, family),
|
|
195
|
+
loadFont: async (family) => !!findFont(list, family)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function weightFromStyleName(style = "") {
|
|
199
|
+
const s = style.toLowerCase();
|
|
200
|
+
if (/thin|hairline/.test(s)) return 100;
|
|
201
|
+
if (/extra ?light|ultra ?light/.test(s)) return 200;
|
|
202
|
+
if (/light/.test(s)) return 300;
|
|
203
|
+
if (/medium/.test(s)) return 500;
|
|
204
|
+
if (/semi ?bold|demi ?bold/.test(s)) return 600;
|
|
205
|
+
if (/extra ?bold|ultra ?bold/.test(s)) return 800;
|
|
206
|
+
if (/black|heavy/.test(s)) return 900;
|
|
207
|
+
if (/bold/.test(s)) return 700;
|
|
208
|
+
return 400;
|
|
209
|
+
}
|
|
210
|
+
function createSystemFontProvider(options = {}) {
|
|
211
|
+
const catalog = (options.catalog ?? SYSTEM_FONT_CATALOG).filter((f) => !options.platform || !f.platforms || f.platforms.includes(options.platform));
|
|
212
|
+
let local = null;
|
|
213
|
+
const localFonts = () => {
|
|
214
|
+
if (!options.queryLocalFonts) return Promise.resolve(null);
|
|
215
|
+
local ??= options.queryLocalFonts().then((entries) => {
|
|
216
|
+
const byFamily = /* @__PURE__ */ new Map();
|
|
217
|
+
for (const e of entries) {
|
|
218
|
+
const key = e.family.toLowerCase();
|
|
219
|
+
const known = findFont(SYSTEM_FONT_CATALOG, e.family);
|
|
220
|
+
const entry = byFamily.get(key) ?? { family: known?.family ?? e.family, category: known?.category ?? guessFontCategory(e.family), weights: [], styles: [], source: "system" };
|
|
221
|
+
const w = weightFromStyleName(e.style);
|
|
222
|
+
if (!entry.weights.includes(w)) entry.weights.push(w);
|
|
223
|
+
const st = /italic/i.test(e.style ?? "") ? "italic" : /oblique/i.test(e.style ?? "") ? "oblique" : "normal";
|
|
224
|
+
if (!entry.styles.includes(st)) entry.styles.push(st);
|
|
225
|
+
byFamily.set(key, entry);
|
|
226
|
+
}
|
|
227
|
+
for (const f of byFamily.values()) f.weights.sort((a, b) => normalizeFontWeight(a) - normalizeFontWeight(b));
|
|
228
|
+
return [...byFamily.values()];
|
|
229
|
+
}).catch(() => null);
|
|
230
|
+
return local;
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
id: options.id ?? "system",
|
|
234
|
+
async listFonts() {
|
|
235
|
+
return (await localFonts() ?? catalog).map((f) => ({ ...f }));
|
|
236
|
+
},
|
|
237
|
+
async hasFont(family) {
|
|
238
|
+
return !!findFont(await localFonts() ?? catalog, family);
|
|
239
|
+
},
|
|
240
|
+
async loadFont(family) {
|
|
241
|
+
return !!findFont(await localFonts() ?? catalog, family);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
var weightRange = (w) => Array.isArray(w) ? [w[0], w[1]] : [normalizeFontWeight(w), normalizeFontWeight(w)];
|
|
246
|
+
var cssWeight = (w) => {
|
|
247
|
+
const [lo, hi] = weightRange(w);
|
|
248
|
+
return lo === hi ? String(lo) : `${lo} ${hi}`;
|
|
249
|
+
};
|
|
250
|
+
function fontFaceCss(def) {
|
|
251
|
+
return def.sources.map(
|
|
252
|
+
(s) => [
|
|
253
|
+
"@font-face {",
|
|
254
|
+
` font-family: "${def.family.replace(/"/g, '\\"')}";`,
|
|
255
|
+
` src: url("${s.url.replace(/"/g, "%22")}")${s.format ? ` format("${s.format}")` : ""};`,
|
|
256
|
+
` font-weight: ${cssWeight(s.weight)};`,
|
|
257
|
+
` font-style: ${s.style ?? "normal"};`,
|
|
258
|
+
` font-display: ${def.display ?? "swap"};`,
|
|
259
|
+
...s.unicodeRange ? [` unicode-range: ${s.unicodeRange};`] : [],
|
|
260
|
+
"}"
|
|
261
|
+
].join("\n")
|
|
262
|
+
).join("\n");
|
|
263
|
+
}
|
|
264
|
+
function webFontSummary(def) {
|
|
265
|
+
const weights = /* @__PURE__ */ new Set();
|
|
266
|
+
let isVariable = false;
|
|
267
|
+
for (const s of def.sources) {
|
|
268
|
+
const [lo, hi] = weightRange(s.weight);
|
|
269
|
+
if (lo !== hi) isVariable = true;
|
|
270
|
+
weights.add(lo);
|
|
271
|
+
weights.add(hi);
|
|
272
|
+
}
|
|
273
|
+
const styles = [...new Set(def.sources.map((s) => s.style ?? "normal"))];
|
|
274
|
+
return { family: def.family, category: def.category, weights: [...weights].sort((a, b) => a - b), styles, source: "web", ...isVariable ? { isVariable } : {} };
|
|
275
|
+
}
|
|
276
|
+
function createWebFontProvider(options) {
|
|
277
|
+
const defs = [...options.fonts];
|
|
278
|
+
const cache = /* @__PURE__ */ new Map();
|
|
279
|
+
const done = /* @__PURE__ */ new Set();
|
|
280
|
+
const g = globalThis;
|
|
281
|
+
const createFace = options.createFontFace ?? (g.FontFace ? (family, source, descriptors) => new g.FontFace(family, source, descriptors) : void 0);
|
|
282
|
+
const set = () => options.fontFaceSet ?? g.document?.fonts;
|
|
283
|
+
const def = (family) => defs.find((d) => d.family.toLowerCase() === family.trim().toLowerCase());
|
|
284
|
+
const key = (family, weight, style) => `${family.toLowerCase()}|${normalizeFontWeight(weight)}|${style ?? "normal"}`;
|
|
285
|
+
function pickSource(d, weight, style) {
|
|
286
|
+
const wanted = normalizeFontWeight(weight);
|
|
287
|
+
const st = style ?? "normal";
|
|
288
|
+
const sameStyle = d.sources.filter((s) => (s.style ?? "normal") === st);
|
|
289
|
+
const pool = sameStyle.length ? sameStyle : d.sources;
|
|
290
|
+
const inRange = pool.find((s) => {
|
|
291
|
+
const [lo, hi] = weightRange(s.weight);
|
|
292
|
+
return wanted >= lo && wanted <= hi;
|
|
293
|
+
});
|
|
294
|
+
if (inRange) return inRange;
|
|
295
|
+
const best = nearestFontWeight(wanted, pool.map((s) => weightRange(s.weight)[0]));
|
|
296
|
+
return pool.find((s) => weightRange(s.weight)[0] === best);
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
id: options.id ?? "web",
|
|
300
|
+
listFonts: async () => defs.map(webFontSummary),
|
|
301
|
+
hasFont: (family) => !!def(family),
|
|
302
|
+
loaded: (family, weight, style) => done.has(key(family, weight, style)),
|
|
303
|
+
loadFont(family, weight, style) {
|
|
304
|
+
const k = key(family, weight, style);
|
|
305
|
+
const cached = cache.get(k);
|
|
306
|
+
if (cached) return cached;
|
|
307
|
+
const d = def(family);
|
|
308
|
+
const source = d && pickSource(d, weight, style);
|
|
309
|
+
if (!d || !source || !createFace) return Promise.resolve(false);
|
|
310
|
+
const face = createFace(d.family, `url("${source.url.replace(/"/g, "%22")}")${source.format ? ` format("${source.format}")` : ""}`, {
|
|
311
|
+
weight: cssWeight(source.weight),
|
|
312
|
+
style: source.style ?? "normal",
|
|
313
|
+
display: d.display ?? "swap",
|
|
314
|
+
...source.unicodeRange ? { unicodeRange: source.unicodeRange } : {}
|
|
315
|
+
});
|
|
316
|
+
const promise = face.load().then(() => {
|
|
317
|
+
set()?.add(face);
|
|
318
|
+
done.add(k);
|
|
319
|
+
return true;
|
|
320
|
+
}).catch(() => {
|
|
321
|
+
cache.delete(k);
|
|
322
|
+
return false;
|
|
323
|
+
});
|
|
324
|
+
cache.set(k, promise);
|
|
325
|
+
return promise;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export {
|
|
331
|
+
normalizeFontWeight,
|
|
332
|
+
isFontWeight,
|
|
333
|
+
nearestFontWeight,
|
|
334
|
+
fontHasWeight,
|
|
335
|
+
filterFonts,
|
|
336
|
+
findFont,
|
|
337
|
+
combineFontProviders,
|
|
338
|
+
ensureFontsLoaded,
|
|
339
|
+
SYSTEM_FONT_CATALOG,
|
|
340
|
+
FONT_PLATFORMS,
|
|
341
|
+
guessFontCategory,
|
|
342
|
+
createCatalogFontProvider,
|
|
343
|
+
createSystemFontProvider,
|
|
344
|
+
fontFaceCss,
|
|
345
|
+
webFontSummary,
|
|
346
|
+
createWebFontProvider
|
|
347
|
+
};
|