modern-text 1.3.8 → 1.3.10
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/index.cjs +48 -51
- package/dist/index.js +4 -4
- package/dist/index.mjs +48 -51
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -453,20 +453,7 @@ function parseValueNumber(value, ctx) {
|
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
455
|
function parseColormap(colormap) {
|
|
456
|
-
|
|
457
|
-
return Object.keys(_colormap).reduce((obj, key) => {
|
|
458
|
-
let value = _colormap[key];
|
|
459
|
-
const keyRgb = hexToRgb(key);
|
|
460
|
-
const valueRgb = hexToRgb(value);
|
|
461
|
-
if (keyRgb) {
|
|
462
|
-
key = keyRgb;
|
|
463
|
-
}
|
|
464
|
-
if (valueRgb) {
|
|
465
|
-
value = valueRgb;
|
|
466
|
-
}
|
|
467
|
-
obj[key] = value;
|
|
468
|
-
return obj;
|
|
469
|
-
}, {});
|
|
456
|
+
return isNone(colormap) ? {} : colormap;
|
|
470
457
|
}
|
|
471
458
|
function isNone(val) {
|
|
472
459
|
return !val || val === "none";
|
|
@@ -947,7 +934,11 @@ function background() {
|
|
|
947
934
|
update: (text) => {
|
|
948
935
|
pathSet.paths.length = 0;
|
|
949
936
|
const { style, lineBox, isVertical } = text;
|
|
950
|
-
const {
|
|
937
|
+
const {
|
|
938
|
+
backgroundImage,
|
|
939
|
+
backgroundSize,
|
|
940
|
+
backgroundColormap = "none"
|
|
941
|
+
} = style;
|
|
951
942
|
if (isNone(backgroundImage))
|
|
952
943
|
return;
|
|
953
944
|
const { pathSet: imagePathSet } = parser.parse(backgroundImage);
|
|
@@ -958,7 +949,17 @@ function background() {
|
|
|
958
949
|
} else {
|
|
959
950
|
({ x, y, width, height } = lineBox);
|
|
960
951
|
}
|
|
961
|
-
const
|
|
952
|
+
const colormap = parseColormap(backgroundColormap);
|
|
953
|
+
const paths = imagePathSet.paths.map((p) => {
|
|
954
|
+
const cloned = p.clone();
|
|
955
|
+
if (cloned.style.fill && cloned.style.fill in colormap) {
|
|
956
|
+
cloned.style.fill = colormap[cloned.style.fill];
|
|
957
|
+
}
|
|
958
|
+
if (cloned.style.stroke && cloned.style.stroke in colormap) {
|
|
959
|
+
cloned.style.stroke = colormap[cloned.style.stroke];
|
|
960
|
+
}
|
|
961
|
+
return cloned;
|
|
962
|
+
});
|
|
962
963
|
let scaleX;
|
|
963
964
|
let scaleY;
|
|
964
965
|
if (backgroundSize === "rigid") {
|
|
@@ -1352,41 +1353,37 @@ function listStyle() {
|
|
|
1352
1353
|
}
|
|
1353
1354
|
const imagePathSet = modernPath2d.svgToPath2DSet(image);
|
|
1354
1355
|
const imageBox = imagePathSet.getBoundingBox();
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
}));
|
|
1387
|
-
}
|
|
1388
|
-
});
|
|
1389
|
-
});
|
|
1356
|
+
const char = paragraph.fragments[0]?.characters[0];
|
|
1357
|
+
if (!char) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
const { inlineBox } = char;
|
|
1361
|
+
const scale = size === "cover" ? 1 : parseValueNumber(size, { total: fontSize, fontSize }) / fontSize;
|
|
1362
|
+
const m = new modernPath2d.Matrix3();
|
|
1363
|
+
if (isVertical) {
|
|
1364
|
+
const _scale = fontSize / imageBox.height * scale;
|
|
1365
|
+
m.translate(-imageBox.left, -imageBox.top).rotate(Math.PI / 2).scale(_scale, _scale).translate(
|
|
1366
|
+
inlineBox.left + (inlineBox.width - imageBox.height * _scale) / 2,
|
|
1367
|
+
inlineBox.top - padding
|
|
1368
|
+
);
|
|
1369
|
+
} else {
|
|
1370
|
+
const _scale = fontSize / imageBox.height * scale;
|
|
1371
|
+
m.translate(-imageBox.left, -imageBox.top).scale(_scale, _scale).translate(
|
|
1372
|
+
inlineBox.left - imageBox.width * _scale - padding,
|
|
1373
|
+
inlineBox.top + (inlineBox.height - imageBox.height * _scale) / 2
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
pathSet.paths.push(...imagePathSet.paths.map((p) => {
|
|
1377
|
+
const path = p.clone();
|
|
1378
|
+
path.applyTransform(m);
|
|
1379
|
+
if (path.style.fill && path.style.fill in colormap) {
|
|
1380
|
+
path.style.fill = colormap[path.style.fill];
|
|
1381
|
+
}
|
|
1382
|
+
if (path.style.stroke && path.style.stroke in colormap) {
|
|
1383
|
+
path.style.stroke = colormap[path.style.stroke];
|
|
1384
|
+
}
|
|
1385
|
+
return path;
|
|
1386
|
+
}));
|
|
1390
1387
|
});
|
|
1391
1388
|
}
|
|
1392
1389
|
});
|