docgen-utils 1.0.21 → 1.0.23
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/bundle.js +310 -68
- package/dist/bundle.min.js +244 -244
- package/dist/cli.js +240 -50
- package/dist/packages/docs/common.d.ts +30 -2
- package/dist/packages/docs/common.d.ts.map +1 -1
- package/dist/packages/docs/common.js +40 -0
- package/dist/packages/docs/common.js.map +1 -1
- package/dist/packages/docs/convert.d.ts.map +1 -1
- package/dist/packages/docs/convert.js +91 -21
- package/dist/packages/docs/convert.js.map +1 -1
- package/dist/packages/docs/parse-css.d.ts.map +1 -1
- package/dist/packages/docs/parse-css.js +10 -3
- package/dist/packages/docs/parse-css.js.map +1 -1
- package/dist/packages/docs/parse.d.ts.map +1 -1
- package/dist/packages/docs/parse.js +185 -19
- package/dist/packages/docs/parse.js.map +1 -1
- package/dist/packages/slides/common.d.ts +16 -0
- package/dist/packages/slides/common.d.ts.map +1 -1
- package/dist/packages/slides/convert.d.ts.map +1 -1
- package/dist/packages/slides/convert.js +57 -29
- package/dist/packages/slides/convert.js.map +1 -1
- package/dist/packages/slides/parse.d.ts.map +1 -1
- package/dist/packages/slides/parse.js +32 -1
- package/dist/packages/slides/parse.js.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -47395,6 +47395,34 @@ var docgen = (() => {
|
|
|
47395
47395
|
var UTF16BE = new Uint8Array([254, 255]);
|
|
47396
47396
|
|
|
47397
47397
|
// packages/docs/common.js
|
|
47398
|
+
function isStyledTableCell(cell) {
|
|
47399
|
+
if (typeof cell !== "object" || Array.isArray(cell))
|
|
47400
|
+
return false;
|
|
47401
|
+
if (!("content" in cell))
|
|
47402
|
+
return false;
|
|
47403
|
+
const styledCell = cell;
|
|
47404
|
+
const content = styledCell.content;
|
|
47405
|
+
if (typeof content === "string")
|
|
47406
|
+
return true;
|
|
47407
|
+
if (Array.isArray(content) && content.length > 0) {
|
|
47408
|
+
const first = content[0];
|
|
47409
|
+
if (typeof first === "object" && first !== null && "type" in first) {
|
|
47410
|
+
return false;
|
|
47411
|
+
}
|
|
47412
|
+
}
|
|
47413
|
+
return true;
|
|
47414
|
+
}
|
|
47415
|
+
function isComplexTableCell(cell) {
|
|
47416
|
+
if (typeof cell !== "object" || Array.isArray(cell))
|
|
47417
|
+
return false;
|
|
47418
|
+
if (!("content" in cell))
|
|
47419
|
+
return false;
|
|
47420
|
+
const content = cell.content;
|
|
47421
|
+
if (!Array.isArray(content) || content.length === 0)
|
|
47422
|
+
return false;
|
|
47423
|
+
const first = content[0];
|
|
47424
|
+
return typeof first === "object" && first !== null && "type" in first;
|
|
47425
|
+
}
|
|
47398
47426
|
var HEADING_LEVEL_MAP = {
|
|
47399
47427
|
1: HeadingLevel.HEADING_1,
|
|
47400
47428
|
2: HeadingLevel.HEADING_2,
|
|
@@ -48705,7 +48733,7 @@ var docgen = (() => {
|
|
|
48705
48733
|
}
|
|
48706
48734
|
}
|
|
48707
48735
|
}
|
|
48708
|
-
|
|
48736
|
+
{
|
|
48709
48737
|
const fillIn = (source) => {
|
|
48710
48738
|
for (const [key2, value] of Object.entries(source)) {
|
|
48711
48739
|
if (value !== void 0 && result[key2] === void 0) {
|
|
@@ -50276,6 +50304,46 @@ var docgen = (() => {
|
|
|
50276
50304
|
}
|
|
50277
50305
|
|
|
50278
50306
|
// packages/docs/parse.js
|
|
50307
|
+
function getDirectRows(tableEl) {
|
|
50308
|
+
const result = [];
|
|
50309
|
+
for (const child of tableEl.children) {
|
|
50310
|
+
const childTag = child.tagName.toLowerCase();
|
|
50311
|
+
if (childTag === "tr") {
|
|
50312
|
+
result.push(child);
|
|
50313
|
+
} else if (childTag === "thead" || childTag === "tbody" || childTag === "tfoot") {
|
|
50314
|
+
for (const grandchild of child.children) {
|
|
50315
|
+
if (grandchild.tagName.toLowerCase() === "tr") {
|
|
50316
|
+
result.push(grandchild);
|
|
50317
|
+
}
|
|
50318
|
+
}
|
|
50319
|
+
}
|
|
50320
|
+
}
|
|
50321
|
+
return result;
|
|
50322
|
+
}
|
|
50323
|
+
function getDirectCells(rowEl) {
|
|
50324
|
+
const result = [];
|
|
50325
|
+
for (const child of rowEl.children) {
|
|
50326
|
+
const childTag = child.tagName.toLowerCase();
|
|
50327
|
+
if (childTag === "td" || childTag === "th") {
|
|
50328
|
+
result.push(child);
|
|
50329
|
+
}
|
|
50330
|
+
}
|
|
50331
|
+
return result;
|
|
50332
|
+
}
|
|
50333
|
+
function cellHasNestedTable(cellEl) {
|
|
50334
|
+
return cellEl.querySelector("table") !== null;
|
|
50335
|
+
}
|
|
50336
|
+
function isLayoutTable(tableEl, cssContext) {
|
|
50337
|
+
const styles = getElementStyles(tableEl, cssContext);
|
|
50338
|
+
const inlineStyle = tableEl.getAttribute("style") || "";
|
|
50339
|
+
if (inlineStyle.includes("border: none") || inlineStyle.includes("border:none")) {
|
|
50340
|
+
return true;
|
|
50341
|
+
}
|
|
50342
|
+
if (styles.border && styles.border.includes("none")) {
|
|
50343
|
+
return true;
|
|
50344
|
+
}
|
|
50345
|
+
return false;
|
|
50346
|
+
}
|
|
50279
50347
|
function createParsedImageElement(imageEl, imageKey) {
|
|
50280
50348
|
const src = imageEl.getAttribute("src")?.trim();
|
|
50281
50349
|
if (!src) {
|
|
@@ -50385,18 +50453,50 @@ var docgen = (() => {
|
|
|
50385
50453
|
}
|
|
50386
50454
|
if (tagName19 === "table") {
|
|
50387
50455
|
const rows = [];
|
|
50388
|
-
|
|
50456
|
+
const directRows = getDirectRows(el);
|
|
50457
|
+
for (const tr of directRows) {
|
|
50389
50458
|
const cells = [];
|
|
50390
|
-
|
|
50459
|
+
const directCells = getDirectCells(tr);
|
|
50460
|
+
for (const cell of directCells) {
|
|
50461
|
+
let cellBackgroundColor;
|
|
50462
|
+
const cellStyles = getElementStyles(cell, cssContext, tr);
|
|
50463
|
+
if (cellStyles.backgroundColor) {
|
|
50464
|
+
const hexBg = extractHexColor(cellStyles.backgroundColor);
|
|
50465
|
+
if (hexBg)
|
|
50466
|
+
cellBackgroundColor = hexBg;
|
|
50467
|
+
}
|
|
50468
|
+
if (!cellBackgroundColor) {
|
|
50469
|
+
const inlineStyle = cell.getAttribute("style") || "";
|
|
50470
|
+
if (inlineStyle) {
|
|
50471
|
+
const bgMatch = inlineStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
|
|
50472
|
+
if (bgMatch) {
|
|
50473
|
+
const hexBg = extractHexColor(bgMatch[1]);
|
|
50474
|
+
if (hexBg)
|
|
50475
|
+
cellBackgroundColor = hexBg;
|
|
50476
|
+
}
|
|
50477
|
+
}
|
|
50478
|
+
}
|
|
50391
50479
|
const runs = extractInlineRuns(cell, cssContext);
|
|
50392
|
-
if (
|
|
50393
|
-
if (
|
|
50394
|
-
|
|
50480
|
+
if (cellBackgroundColor) {
|
|
50481
|
+
if (runs.length > 0) {
|
|
50482
|
+
if (hasInlineFormatting(runs)) {
|
|
50483
|
+
cells.push({ content: runs, backgroundColor: cellBackgroundColor });
|
|
50484
|
+
} else {
|
|
50485
|
+
cells.push({ content: runs.map((r) => r.text).join(""), backgroundColor: cellBackgroundColor });
|
|
50486
|
+
}
|
|
50395
50487
|
} else {
|
|
50396
|
-
cells.push(
|
|
50488
|
+
cells.push({ content: "", backgroundColor: cellBackgroundColor });
|
|
50397
50489
|
}
|
|
50398
50490
|
} else {
|
|
50399
|
-
|
|
50491
|
+
if (runs.length > 0) {
|
|
50492
|
+
if (hasInlineFormatting(runs)) {
|
|
50493
|
+
cells.push(runs);
|
|
50494
|
+
} else {
|
|
50495
|
+
cells.push(runs.map((r) => r.text).join(""));
|
|
50496
|
+
}
|
|
50497
|
+
} else {
|
|
50498
|
+
cells.push("");
|
|
50499
|
+
}
|
|
50400
50500
|
}
|
|
50401
50501
|
}
|
|
50402
50502
|
if (cells.length > 0) {
|
|
@@ -51159,18 +51259,65 @@ var docgen = (() => {
|
|
|
51159
51259
|
}
|
|
51160
51260
|
if (tagName19 === "table") {
|
|
51161
51261
|
const rows = [];
|
|
51162
|
-
|
|
51262
|
+
const directRows = getDirectRows(element);
|
|
51263
|
+
for (const tr of directRows) {
|
|
51163
51264
|
const cells = [];
|
|
51164
|
-
|
|
51165
|
-
|
|
51166
|
-
if (
|
|
51167
|
-
|
|
51168
|
-
|
|
51265
|
+
const directCells = getDirectCells(tr);
|
|
51266
|
+
for (const cell of directCells) {
|
|
51267
|
+
if (cellHasNestedTable(cell)) {
|
|
51268
|
+
const nestedContent = parseContainerContent(cell, cssContext, nextImageKey);
|
|
51269
|
+
if (nestedContent.length > 0) {
|
|
51270
|
+
cells.push({ content: nestedContent });
|
|
51169
51271
|
} else {
|
|
51170
|
-
cells.push(
|
|
51272
|
+
cells.push("");
|
|
51171
51273
|
}
|
|
51172
51274
|
} else {
|
|
51173
|
-
|
|
51275
|
+
let cellBackgroundColor;
|
|
51276
|
+
const cellStylesWithRowParent = getElementStyles(cell, cssContext, tr);
|
|
51277
|
+
if (cellStylesWithRowParent.backgroundColor) {
|
|
51278
|
+
const hexBg = extractHexColor(cellStylesWithRowParent.backgroundColor);
|
|
51279
|
+
if (hexBg)
|
|
51280
|
+
cellBackgroundColor = hexBg;
|
|
51281
|
+
}
|
|
51282
|
+
if (!cellBackgroundColor) {
|
|
51283
|
+
const cellStylesWithTableParent = getElementStyles(cell, cssContext, element);
|
|
51284
|
+
if (cellStylesWithTableParent.backgroundColor) {
|
|
51285
|
+
const hexBg = extractHexColor(cellStylesWithTableParent.backgroundColor);
|
|
51286
|
+
if (hexBg)
|
|
51287
|
+
cellBackgroundColor = hexBg;
|
|
51288
|
+
}
|
|
51289
|
+
}
|
|
51290
|
+
const inlineStyle = cell.getAttribute("style") || "";
|
|
51291
|
+
if (inlineStyle && !cellBackgroundColor) {
|
|
51292
|
+
const bgMatch = inlineStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
|
|
51293
|
+
if (bgMatch) {
|
|
51294
|
+
const hexBg = extractHexColor(bgMatch[1]);
|
|
51295
|
+
if (hexBg)
|
|
51296
|
+
cellBackgroundColor = hexBg;
|
|
51297
|
+
}
|
|
51298
|
+
}
|
|
51299
|
+
const runs = extractInlineRuns(cell, cssContext);
|
|
51300
|
+
if (cellBackgroundColor) {
|
|
51301
|
+
if (runs.length > 0) {
|
|
51302
|
+
if (hasInlineFormatting(runs)) {
|
|
51303
|
+
cells.push({ content: runs, backgroundColor: cellBackgroundColor });
|
|
51304
|
+
} else {
|
|
51305
|
+
cells.push({ content: runs.map((r) => r.text).join(""), backgroundColor: cellBackgroundColor });
|
|
51306
|
+
}
|
|
51307
|
+
} else {
|
|
51308
|
+
cells.push({ content: "", backgroundColor: cellBackgroundColor });
|
|
51309
|
+
}
|
|
51310
|
+
} else {
|
|
51311
|
+
if (runs.length > 0) {
|
|
51312
|
+
if (hasInlineFormatting(runs)) {
|
|
51313
|
+
cells.push(runs);
|
|
51314
|
+
} else {
|
|
51315
|
+
cells.push(runs.map((r) => r.text).join(""));
|
|
51316
|
+
}
|
|
51317
|
+
} else {
|
|
51318
|
+
cells.push("");
|
|
51319
|
+
}
|
|
51320
|
+
}
|
|
51174
51321
|
}
|
|
51175
51322
|
}
|
|
51176
51323
|
if (cells.length > 0) {
|
|
@@ -51321,7 +51468,8 @@ var docgen = (() => {
|
|
|
51321
51468
|
}
|
|
51322
51469
|
}
|
|
51323
51470
|
}
|
|
51324
|
-
|
|
51471
|
+
const noBorders = isLayoutTable(element, cssContext);
|
|
51472
|
+
elements.push({ type: "table", rows, cellPadding, headerBackgroundColor, headerTextColor, evenRowBackgroundColor, hasHeader: hasExplicitHeader ? true : void 0, horizontalBordersOnly: horizontalBordersOnly || void 0, noBorders: noBorders || void 0, columnWidths: calculateColumnWidths(rows, element) });
|
|
51325
51473
|
}
|
|
51326
51474
|
return;
|
|
51327
51475
|
}
|
|
@@ -52598,35 +52746,83 @@ var docgen = (() => {
|
|
|
52598
52746
|
return new TableRow({
|
|
52599
52747
|
tableHeader: isHeaderRow,
|
|
52600
52748
|
children: cells.map((cell, cellIndex) => {
|
|
52601
|
-
|
|
52602
|
-
|
|
52603
|
-
|
|
52604
|
-
|
|
52605
|
-
|
|
52606
|
-
|
|
52607
|
-
|
|
52608
|
-
|
|
52609
|
-
|
|
52610
|
-
|
|
52611
|
-
|
|
52612
|
-
|
|
52613
|
-
|
|
52614
|
-
|
|
52615
|
-
|
|
52616
|
-
|
|
52617
|
-
|
|
52618
|
-
|
|
52619
|
-
|
|
52620
|
-
|
|
52621
|
-
|
|
52622
|
-
|
|
52623
|
-
|
|
52624
|
-
|
|
52625
|
-
|
|
52626
|
-
|
|
52627
|
-
|
|
52749
|
+
let cellContent;
|
|
52750
|
+
let cellBackgroundColor;
|
|
52751
|
+
if (isComplexTableCell(cell)) {
|
|
52752
|
+
cellContent = [];
|
|
52753
|
+
for (const nestedElement of cell.content) {
|
|
52754
|
+
cellContent.push(...convertElementToDocx(nestedElement));
|
|
52755
|
+
}
|
|
52756
|
+
if (cellContent.length === 0) {
|
|
52757
|
+
cellContent = [new Paragraph({ children: [] })];
|
|
52758
|
+
}
|
|
52759
|
+
} else if (isStyledTableCell(cell)) {
|
|
52760
|
+
cellBackgroundColor = cell.backgroundColor;
|
|
52761
|
+
const content = cell.content;
|
|
52762
|
+
const textRuns = typeof content === "string" ? [new TextRun({
|
|
52763
|
+
text: content,
|
|
52764
|
+
bold: isHeaderRow,
|
|
52765
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : void 0
|
|
52766
|
+
})] : content.map((run) => new TextRun({
|
|
52767
|
+
text: run.text,
|
|
52768
|
+
bold: isHeaderRow || run.bold,
|
|
52769
|
+
italics: run.italic,
|
|
52770
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
|
|
52771
|
+
size: run.size,
|
|
52772
|
+
font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : void 0,
|
|
52773
|
+
superScript: run.superscript,
|
|
52774
|
+
subScript: run.subscript,
|
|
52775
|
+
strike: run.strike,
|
|
52776
|
+
characterSpacing: run.letterSpacing,
|
|
52777
|
+
underline: run.underline ? {
|
|
52778
|
+
type: getUnderlineType(run.underline.type),
|
|
52779
|
+
color: run.underline.color
|
|
52780
|
+
} : void 0
|
|
52781
|
+
// Note: Don't apply run-level backgroundColor here - cell background handles it
|
|
52782
|
+
}));
|
|
52783
|
+
cellContent = [new Paragraph({ children: textRuns })];
|
|
52784
|
+
} else if (typeof cell === "string") {
|
|
52785
|
+
const textRuns = [new TextRun({
|
|
52786
|
+
text: cell,
|
|
52787
|
+
bold: isHeaderRow,
|
|
52788
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : void 0
|
|
52789
|
+
})];
|
|
52790
|
+
cellContent = [new Paragraph({ children: textRuns })];
|
|
52791
|
+
} else if (Array.isArray(cell)) {
|
|
52792
|
+
const textRuns = cell.map((run) => new TextRun({
|
|
52793
|
+
text: run.text,
|
|
52794
|
+
bold: isHeaderRow || run.bold,
|
|
52795
|
+
italics: run.italic,
|
|
52796
|
+
color: isHeaderRow && headerTextColor ? headerTextColor : run.color,
|
|
52797
|
+
size: run.size,
|
|
52798
|
+
font: run.fontFamily ? mapToOfficeFont(run.fontFamily) : void 0,
|
|
52799
|
+
superScript: run.superscript,
|
|
52800
|
+
subScript: run.subscript,
|
|
52801
|
+
strike: run.strike,
|
|
52802
|
+
characterSpacing: run.letterSpacing,
|
|
52803
|
+
underline: run.underline ? {
|
|
52804
|
+
type: getUnderlineType(run.underline.type),
|
|
52805
|
+
color: run.underline.color
|
|
52806
|
+
} : void 0,
|
|
52807
|
+
// Preserve inline background colors for badge/pill styling in table cells
|
|
52808
|
+
shading: run.backgroundColor ? {
|
|
52809
|
+
type: ShadingType.CLEAR,
|
|
52810
|
+
fill: run.backgroundColor,
|
|
52811
|
+
color: "auto"
|
|
52812
|
+
} : void 0
|
|
52813
|
+
}));
|
|
52814
|
+
cellContent = [new Paragraph({ children: textRuns })];
|
|
52815
|
+
} else {
|
|
52816
|
+
cellContent = [new Paragraph({ children: [] })];
|
|
52817
|
+
}
|
|
52628
52818
|
let shading;
|
|
52629
|
-
if (
|
|
52819
|
+
if (cellBackgroundColor) {
|
|
52820
|
+
shading = {
|
|
52821
|
+
type: ShadingType.CLEAR,
|
|
52822
|
+
color: "auto",
|
|
52823
|
+
fill: cellBackgroundColor
|
|
52824
|
+
};
|
|
52825
|
+
} else if (isHeaderRow && headerBackgroundColor) {
|
|
52630
52826
|
shading = {
|
|
52631
52827
|
type: ShadingType.CLEAR,
|
|
52632
52828
|
color: "auto",
|
|
@@ -52644,11 +52840,7 @@ var docgen = (() => {
|
|
|
52644
52840
|
const needsSpan = isLastCell && remainingColumns > 0;
|
|
52645
52841
|
const cellColumnSpan = needsSpan ? remainingColumns + 1 : void 0;
|
|
52646
52842
|
return new TableCell({
|
|
52647
|
-
children:
|
|
52648
|
-
new Paragraph({
|
|
52649
|
-
children: textRuns
|
|
52650
|
-
})
|
|
52651
|
-
],
|
|
52843
|
+
children: cellContent,
|
|
52652
52844
|
width: {
|
|
52653
52845
|
size: columnWidths?.[cellIndex] ?? 100 / columnCount,
|
|
52654
52846
|
type: WidthType.PERCENTAGE
|
|
@@ -52968,6 +53160,15 @@ var docgen = (() => {
|
|
|
52968
53160
|
const cell = row[cellIndex];
|
|
52969
53161
|
if (typeof cell === "string") {
|
|
52970
53162
|
children.push(new TextRun({ text: cell }));
|
|
53163
|
+
} else if (isStyledTableCell(cell)) {
|
|
53164
|
+
const content = cell.content;
|
|
53165
|
+
if (typeof content === "string") {
|
|
53166
|
+
children.push(new TextRun({ text: content }));
|
|
53167
|
+
} else {
|
|
53168
|
+
children.push(...inlineRunsToTextRuns(content));
|
|
53169
|
+
}
|
|
53170
|
+
} else if (isComplexTableCell(cell)) {
|
|
53171
|
+
continue;
|
|
52971
53172
|
} else {
|
|
52972
53173
|
children.push(...inlineRunsToTextRuns(cell));
|
|
52973
53174
|
}
|
|
@@ -66933,6 +67134,28 @@ ${generateStylesCss(styleMap, themeFonts)}
|
|
|
66933
67134
|
const imgEl = el;
|
|
66934
67135
|
const natW = imgEl.naturalWidth;
|
|
66935
67136
|
const natH = imgEl.naturalHeight;
|
|
67137
|
+
let objectPosition;
|
|
67138
|
+
const objPos = imgComputed.objectPosition;
|
|
67139
|
+
if (objPos && objectFit === "cover") {
|
|
67140
|
+
const parts = objPos.trim().split(/\s+/);
|
|
67141
|
+
const parseFraction = (val, dimension) => {
|
|
67142
|
+
if (val.endsWith("%")) {
|
|
67143
|
+
return parseFloat(val) / 100;
|
|
67144
|
+
}
|
|
67145
|
+
const px = parseFloat(val);
|
|
67146
|
+
if (!isNaN(px) && dimension > 0) {
|
|
67147
|
+
return px / dimension;
|
|
67148
|
+
}
|
|
67149
|
+
return 0.5;
|
|
67150
|
+
};
|
|
67151
|
+
const displayW = wasClipped ? clippedW : rect2.width;
|
|
67152
|
+
const displayH = wasClipped ? clippedH : rect2.height;
|
|
67153
|
+
const xFrac = parts.length >= 1 ? parseFraction(parts[0], displayW) : 0.5;
|
|
67154
|
+
const yFrac = parts.length >= 2 ? parseFraction(parts[1], displayH) : xFrac;
|
|
67155
|
+
if (Math.abs(xFrac - 0.5) > 1e-3 || Math.abs(yFrac - 0.5) > 1e-3) {
|
|
67156
|
+
objectPosition = [xFrac, yFrac];
|
|
67157
|
+
}
|
|
67158
|
+
}
|
|
66936
67159
|
const imageElement = {
|
|
66937
67160
|
type: isFullSlideImage ? "slideBackgroundImage" : "image",
|
|
66938
67161
|
src: imgSrc,
|
|
@@ -66944,10 +67167,13 @@ ${generateStylesCss(styleMap, themeFonts)}
|
|
|
66944
67167
|
},
|
|
66945
67168
|
sizing: objectFit === "cover" ? { type: "cover" } : null
|
|
66946
67169
|
};
|
|
66947
|
-
if (objectFit === "cover" && natW > 0 && natH > 0
|
|
67170
|
+
if (objectFit === "cover" && natW > 0 && natH > 0) {
|
|
66948
67171
|
imageElement.naturalWidth = natW;
|
|
66949
67172
|
imageElement.naturalHeight = natH;
|
|
66950
67173
|
}
|
|
67174
|
+
if (objectPosition) {
|
|
67175
|
+
imageElement.objectPosition = objectPosition;
|
|
67176
|
+
}
|
|
66951
67177
|
if (imgRectRadius !== null) {
|
|
66952
67178
|
imageElement.rectRadius = imgRectRadius;
|
|
66953
67179
|
}
|
|
@@ -68272,6 +68498,29 @@ ${generateStylesCss(styleMap, themeFonts)}
|
|
|
68272
68498
|
}
|
|
68273
68499
|
return runs;
|
|
68274
68500
|
}
|
|
68501
|
+
function computeCoverCrop(naturalWidth, naturalHeight, boxW, boxH, objectPosition) {
|
|
68502
|
+
const imgRatio = naturalHeight / naturalWidth;
|
|
68503
|
+
const boxRatio = boxH / boxW;
|
|
68504
|
+
const isBoxBased = boxRatio > imgRatio;
|
|
68505
|
+
const effW = isBoxBased ? boxH / imgRatio : boxW;
|
|
68506
|
+
const effH = isBoxBased ? boxH : boxW * imgRatio;
|
|
68507
|
+
const [anchorX, anchorY] = objectPosition ?? [0.5, 0.5];
|
|
68508
|
+
const excessW = effW - boxW;
|
|
68509
|
+
const excessH = effH - boxH;
|
|
68510
|
+
const cropX = excessW * anchorX;
|
|
68511
|
+
const cropY = excessH * anchorY;
|
|
68512
|
+
return {
|
|
68513
|
+
effW,
|
|
68514
|
+
effH,
|
|
68515
|
+
sizing: {
|
|
68516
|
+
type: "crop",
|
|
68517
|
+
x: cropX,
|
|
68518
|
+
y: cropY,
|
|
68519
|
+
w: boxW,
|
|
68520
|
+
h: boxH
|
|
68521
|
+
}
|
|
68522
|
+
};
|
|
68523
|
+
}
|
|
68275
68524
|
function sleep(ms) {
|
|
68276
68525
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
68277
68526
|
}
|
|
@@ -68381,7 +68630,12 @@ ${generateStylesCss(styleMap, themeFonts)}
|
|
|
68381
68630
|
w: el.position.w,
|
|
68382
68631
|
h: el.position.h
|
|
68383
68632
|
};
|
|
68384
|
-
if (el.sizing && el.sizing.type) {
|
|
68633
|
+
if (el.sizing && el.sizing.type === "cover" && el.naturalWidth && el.naturalHeight) {
|
|
68634
|
+
const crop = computeCoverCrop(el.naturalWidth, el.naturalHeight, el.position.w, el.position.h, el.objectPosition);
|
|
68635
|
+
imageOptions.w = crop.effW;
|
|
68636
|
+
imageOptions.h = crop.effH;
|
|
68637
|
+
imageOptions.sizing = crop.sizing;
|
|
68638
|
+
} else if (el.sizing && el.sizing.type) {
|
|
68385
68639
|
imageOptions.sizing = { type: el.sizing.type, w: el.position.w, h: el.position.h };
|
|
68386
68640
|
}
|
|
68387
68641
|
if (el.brightness !== void 0)
|
|
@@ -68423,22 +68677,10 @@ ${generateStylesCss(styleMap, themeFonts)}
|
|
|
68423
68677
|
h: el.position.h
|
|
68424
68678
|
};
|
|
68425
68679
|
if (el.sizing && el.sizing.type === "cover" && el.naturalWidth && el.naturalHeight) {
|
|
68426
|
-
const
|
|
68427
|
-
|
|
68428
|
-
|
|
68429
|
-
|
|
68430
|
-
const effH = isBoxBased ? el.position.h : el.position.w * imgRatio;
|
|
68431
|
-
const cropX = (effW - el.position.w) / 2;
|
|
68432
|
-
const cropY = (effH - el.position.h) / 2;
|
|
68433
|
-
imageOptions.w = effW;
|
|
68434
|
-
imageOptions.h = effH;
|
|
68435
|
-
imageOptions.sizing = {
|
|
68436
|
-
type: "crop",
|
|
68437
|
-
x: cropX,
|
|
68438
|
-
y: cropY,
|
|
68439
|
-
w: el.position.w,
|
|
68440
|
-
h: el.position.h
|
|
68441
|
-
};
|
|
68680
|
+
const crop = computeCoverCrop(el.naturalWidth, el.naturalHeight, el.position.w, el.position.h, el.objectPosition);
|
|
68681
|
+
imageOptions.w = crop.effW;
|
|
68682
|
+
imageOptions.h = crop.effH;
|
|
68683
|
+
imageOptions.sizing = crop.sizing;
|
|
68442
68684
|
} else if (el.sizing && el.sizing.type) {
|
|
68443
68685
|
imageOptions.sizing = { type: el.sizing.type, w: el.position.w, h: el.position.h };
|
|
68444
68686
|
}
|