docgen-utils 1.0.18 → 1.0.20
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/README.md +63 -18
- package/dist/bundle.js +3466 -2528
- package/dist/bundle.min.js +242 -252
- package/dist/cli.js +3644 -2544
- package/dist/packages/cli/commands/export-docs.js +1 -1
- package/dist/packages/cli/commands/export-docs.js.map +1 -1
- package/dist/packages/cli/commands/export-slides.d.ts.map +1 -1
- package/dist/packages/cli/commands/export-slides.js +11 -7
- package/dist/packages/cli/commands/export-slides.js.map +1 -1
- package/dist/packages/cli/index.js.map +1 -1
- package/dist/packages/docs/common.d.ts +1 -0
- package/dist/packages/docs/common.d.ts.map +1 -1
- package/dist/packages/docs/convert.d.ts.map +1 -1
- package/dist/packages/docs/convert.js +6 -15
- package/dist/packages/docs/convert.js.map +1 -1
- package/dist/packages/docs/import-docx.d.ts.map +1 -1
- package/dist/packages/docs/import-docx.js +168 -82
- package/dist/packages/docs/import-docx.js.map +1 -1
- package/dist/packages/docs/parse-colors.d.ts +0 -5
- package/dist/packages/docs/parse-colors.d.ts.map +1 -1
- package/dist/packages/docs/parse-colors.js +2 -2
- package/dist/packages/docs/parse-colors.js.map +1 -1
- package/dist/packages/docs/parse-css.d.ts +0 -9
- package/dist/packages/docs/parse-css.d.ts.map +1 -1
- package/dist/packages/docs/parse-css.js +4 -6
- package/dist/packages/docs/parse-css.js.map +1 -1
- package/dist/packages/docs/parse-helpers.d.ts +0 -1
- package/dist/packages/docs/parse-helpers.d.ts.map +1 -1
- package/dist/packages/docs/parse-helpers.js +1 -1
- package/dist/packages/docs/parse-helpers.js.map +1 -1
- package/dist/packages/docs/parse-inline.d.ts +0 -13
- package/dist/packages/docs/parse-inline.d.ts.map +1 -1
- package/dist/packages/docs/parse-inline.js +7 -7
- package/dist/packages/docs/parse-inline.js.map +1 -1
- package/dist/packages/docs/parse-layout.d.ts.map +1 -1
- package/dist/packages/docs/parse-layout.js +1 -14
- package/dist/packages/docs/parse-layout.js.map +1 -1
- package/dist/packages/docs/parse-special.js +1 -1
- package/dist/packages/docs/parse-special.js.map +1 -1
- package/dist/packages/docs/parse.d.ts.map +1 -1
- package/dist/packages/docs/parse.js +76 -30
- package/dist/packages/docs/parse.js.map +1 -1
- package/dist/packages/shared/fetch-with-proxy.d.ts +13 -8
- package/dist/packages/shared/fetch-with-proxy.d.ts.map +1 -1
- package/dist/packages/shared/fetch-with-proxy.js +189 -22
- package/dist/packages/shared/fetch-with-proxy.js.map +1 -1
- package/dist/packages/shared/zip-guard.d.ts +37 -0
- package/dist/packages/shared/zip-guard.d.ts.map +1 -0
- package/dist/packages/shared/zip-guard.js +101 -0
- package/dist/packages/shared/zip-guard.js.map +1 -0
- package/dist/packages/slides/convert.d.ts +1 -3
- package/dist/packages/slides/convert.d.ts.map +1 -1
- package/dist/packages/slides/convert.js +8 -74
- package/dist/packages/slides/convert.js.map +1 -1
- package/dist/packages/slides/createPresentation.d.ts +1 -1
- package/dist/packages/slides/createPresentation.d.ts.map +1 -1
- package/dist/packages/slides/createPresentation.js +1 -10
- package/dist/packages/slides/createPresentation.js.map +1 -1
- package/dist/packages/slides/import-pptx.d.ts.map +1 -1
- package/dist/packages/slides/import-pptx.js +5 -7
- package/dist/packages/slides/import-pptx.js.map +1 -1
- package/dist/packages/slides/parse.d.ts +0 -22
- package/dist/packages/slides/parse.d.ts.map +1 -1
- package/dist/packages/slides/parse.js +38 -42
- package/dist/packages/slides/parse.js.map +1 -1
- package/dist/packages/slides/transform.d.ts.map +1 -1
- package/dist/packages/slides/transform.js +1 -5
- package/dist/packages/slides/transform.js.map +1 -1
- package/dist/packages/slides/vendor/VENDORING.md +2 -2
- package/package.json +16 -10
- package/dist/packages/cli/commands/common.d.ts +0 -2
- package/dist/packages/cli/commands/common.d.ts.map +0 -1
- package/dist/packages/cli/commands/common.js +0 -22
- package/dist/packages/cli/commands/common.js.map +0 -1
|
@@ -8,29 +8,7 @@
|
|
|
8
8
|
* The main export is `parseSlideHtml(doc)` which walks the DOM tree and returns
|
|
9
9
|
* a `ParsedSlide` intermediate representation consumed by the rendering layer.
|
|
10
10
|
*/
|
|
11
|
-
import type { GradientFillProps } from './vendor/pptxgen.d.ts';
|
|
12
11
|
import type { ParsedSlide } from './common';
|
|
13
|
-
/** Convert pixel value to inches. */
|
|
14
|
-
export declare function pxToInch(px: number): number;
|
|
15
|
-
/** Convert a CSS pixel string (e.g. "16px") to points. */
|
|
16
|
-
export declare function pxToPoints(pxStr: string): number;
|
|
17
|
-
/**
|
|
18
|
-
* Convert an `rgb()` / `rgba()` color string to a 6-char hex string.
|
|
19
|
-
* Returns `'FFFFFF'` for transparent or unparseable values.
|
|
20
|
-
*/
|
|
21
|
-
export declare function rgbToHex(rgbStr: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Extract transparency percentage from an `rgba()` string.
|
|
24
|
-
* Returns `null` for opaque or non-rgba values, otherwise 0-100.
|
|
25
|
-
*/
|
|
26
|
-
export declare function extractAlpha(rgbStr: string): number | null;
|
|
27
|
-
/**
|
|
28
|
-
* Parse a CSS gradient string (`linear-gradient(...)` or `radial-gradient(...)`)
|
|
29
|
-
* into a PptxGenJS-compatible `GradientFillProps` object.
|
|
30
|
-
*
|
|
31
|
-
* Returns `null` if the string does not contain a recognized gradient.
|
|
32
|
-
*/
|
|
33
|
-
export declare function parseCssGradient(gradientStr: string): GradientFillProps | null;
|
|
34
12
|
/**
|
|
35
13
|
* Parse a live browser DOM `Document` into a `ParsedSlide` intermediate
|
|
36
14
|
* representation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../packages/slides/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../packages/slides/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,KAAK,EACV,WAAW,EAgBZ,MAAM,UAAU,CAAC;AAk5DlB;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,WAAW,CAytEzD"}
|
|
@@ -19,21 +19,21 @@ const PX_PER_IN = 96;
|
|
|
19
19
|
// ---------------------------------------------------------------------------
|
|
20
20
|
const SINGLE_WEIGHT_FONTS = ['impact'];
|
|
21
21
|
// ---------------------------------------------------------------------------
|
|
22
|
-
//
|
|
22
|
+
// Internal helper functions
|
|
23
23
|
// ---------------------------------------------------------------------------
|
|
24
24
|
/** Convert pixel value to inches. */
|
|
25
|
-
|
|
25
|
+
function pxToInch(px) {
|
|
26
26
|
return px / PX_PER_IN;
|
|
27
27
|
}
|
|
28
28
|
/** Convert a CSS pixel string (e.g. "16px") to points. */
|
|
29
|
-
|
|
29
|
+
function pxToPoints(pxStr) {
|
|
30
30
|
return parseFloat(pxStr) * PT_PER_PX;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Convert an `rgb()` / `rgba()` color string to a 6-char hex string.
|
|
34
34
|
* Returns `'FFFFFF'` for transparent or unparseable values.
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
function rgbToHex(rgbStr) {
|
|
37
37
|
// Remove !important suffix if present
|
|
38
38
|
rgbStr = rgbStr.replace(/\s*!important\s*$/i, '').trim();
|
|
39
39
|
if (rgbStr === 'rgba(0, 0, 0, 0)' || rgbStr === 'transparent')
|
|
@@ -64,7 +64,7 @@ function isFullyTransparent(colorStr) {
|
|
|
64
64
|
* Extract transparency percentage from an `rgba()` string.
|
|
65
65
|
* Returns `null` for opaque or non-rgba values, otherwise 0-100.
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
function extractAlpha(rgbStr) {
|
|
68
68
|
const match = rgbStr.match(/rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)/);
|
|
69
69
|
if (!match || !match[4])
|
|
70
70
|
return null;
|
|
@@ -354,7 +354,7 @@ function renderRepeatingGradientPatternAsImage(bgImage, bgSize, bgPosition, widt
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
// ---------------------------------------------------------------------------
|
|
357
|
-
// parseCssGradient (
|
|
357
|
+
// parseCssGradient (internal, used within this module)
|
|
358
358
|
// ---------------------------------------------------------------------------
|
|
359
359
|
/**
|
|
360
360
|
* Parse a CSS gradient string (`linear-gradient(...)` or `radial-gradient(...)`)
|
|
@@ -362,7 +362,7 @@ function renderRepeatingGradientPatternAsImage(bgImage, bgSize, bgPosition, widt
|
|
|
362
362
|
*
|
|
363
363
|
* Returns `null` if the string does not contain a recognized gradient.
|
|
364
364
|
*/
|
|
365
|
-
|
|
365
|
+
function parseCssGradient(gradientStr) {
|
|
366
366
|
const colorToHex = (colorStr) => {
|
|
367
367
|
colorStr = colorStr.trim().toLowerCase();
|
|
368
368
|
// Remove !important suffix if present
|
|
@@ -444,10 +444,30 @@ export function parseCssGradient(gradientStr) {
|
|
|
444
444
|
}
|
|
445
445
|
return null;
|
|
446
446
|
};
|
|
447
|
+
// Shared helper: parse color stops from a gradient parts array.
|
|
448
|
+
// Prevents divide-by-zero when there is only one color stop.
|
|
449
|
+
const parseColorStops = (colorStops) => {
|
|
450
|
+
return colorStops.map((stop, idx) => {
|
|
451
|
+
const posMatch = stop.match(/([\d.]+)%\s*$/);
|
|
452
|
+
const position = posMatch
|
|
453
|
+
? parseFloat(posMatch[1])
|
|
454
|
+
: (idx / Math.max(colorStops.length - 1, 1)) * 100;
|
|
455
|
+
const colorPart = posMatch
|
|
456
|
+
? stop.replace(/([\d.]+)%\s*$/, '').trim()
|
|
457
|
+
: stop.trim();
|
|
458
|
+
const stopData = { color: colorToHex(colorPart), position };
|
|
459
|
+
const transparency = extractTransparency(colorPart);
|
|
460
|
+
if (transparency !== null)
|
|
461
|
+
stopData.transparency = transparency;
|
|
462
|
+
return stopData;
|
|
463
|
+
});
|
|
464
|
+
};
|
|
447
465
|
// Try linear-gradient
|
|
448
466
|
const linearContent = extractGradientContent(gradientStr, 'linear-gradient(');
|
|
449
467
|
if (linearContent) {
|
|
450
468
|
const parts = splitGradientParts(linearContent);
|
|
469
|
+
if (parts.length === 0)
|
|
470
|
+
return null;
|
|
451
471
|
let cssAngle = 180;
|
|
452
472
|
let colorStops = parts;
|
|
453
473
|
const angleMatch = parts[0].match(/^([\d.]+)deg$/);
|
|
@@ -474,26 +494,15 @@ export function parseCssGradient(gradientStr) {
|
|
|
474
494
|
cssAngle = dirMap[dir] ?? 180;
|
|
475
495
|
colorStops = parts.slice(1);
|
|
476
496
|
}
|
|
477
|
-
const stops = colorStops
|
|
478
|
-
const posMatch = stop.match(/([\d.]+)%\s*$/);
|
|
479
|
-
const position = posMatch
|
|
480
|
-
? parseFloat(posMatch[1])
|
|
481
|
-
: (idx / (colorStops.length - 1)) * 100;
|
|
482
|
-
const colorPart = posMatch
|
|
483
|
-
? stop.replace(/([\d.]+)%\s*$/, '').trim()
|
|
484
|
-
: stop.trim();
|
|
485
|
-
const stopData = { color: colorToHex(colorPart), position };
|
|
486
|
-
const transparency = extractTransparency(colorPart);
|
|
487
|
-
if (transparency !== null)
|
|
488
|
-
stopData.transparency = transparency;
|
|
489
|
-
return stopData;
|
|
490
|
-
});
|
|
497
|
+
const stops = parseColorStops(colorStops);
|
|
491
498
|
return { type: 'linear', angle: cssAngle, stops };
|
|
492
499
|
}
|
|
493
500
|
// Try radial-gradient
|
|
494
501
|
const radialContent = extractGradientContent(gradientStr, 'radial-gradient(');
|
|
495
502
|
if (radialContent) {
|
|
496
503
|
const parts = splitGradientParts(radialContent);
|
|
504
|
+
if (parts.length === 0)
|
|
505
|
+
return null;
|
|
497
506
|
let centerX = 50;
|
|
498
507
|
let centerY = 50;
|
|
499
508
|
let colorStops = parts;
|
|
@@ -506,20 +515,7 @@ export function parseCssGradient(gradientStr) {
|
|
|
506
515
|
else if (parts[0].includes('circle') || parts[0].includes('ellipse')) {
|
|
507
516
|
colorStops = parts.slice(1);
|
|
508
517
|
}
|
|
509
|
-
const stops = colorStops
|
|
510
|
-
const posMatch2 = stop.match(/([\d.]+)%\s*$/);
|
|
511
|
-
const position = posMatch2
|
|
512
|
-
? parseFloat(posMatch2[1])
|
|
513
|
-
: (idx / (colorStops.length - 1)) * 100;
|
|
514
|
-
const colorPart = posMatch2
|
|
515
|
-
? stop.replace(/([\d.]+)%\s*$/, '').trim()
|
|
516
|
-
: stop.trim();
|
|
517
|
-
const stopData = { color: colorToHex(colorPart), position };
|
|
518
|
-
const transparency = extractTransparency(colorPart);
|
|
519
|
-
if (transparency !== null)
|
|
520
|
-
stopData.transparency = transparency;
|
|
521
|
-
return stopData;
|
|
522
|
-
});
|
|
518
|
+
const stops = parseColorStops(colorStops);
|
|
523
519
|
return { type: 'radial', centerX, centerY, stops };
|
|
524
520
|
}
|
|
525
521
|
return null;
|
|
@@ -1611,7 +1607,7 @@ function extractPseudoElements(el, win) {
|
|
|
1611
1607
|
continue;
|
|
1612
1608
|
// Parse gradient(s) — a single background-image property may contain multiple gradients
|
|
1613
1609
|
let gradient = null;
|
|
1614
|
-
|
|
1610
|
+
const extraPseudoGradients = [];
|
|
1615
1611
|
if (hasGradient) {
|
|
1616
1612
|
const gradParts = splitCssBackgroundGradients(bgImage);
|
|
1617
1613
|
if (gradParts.length > 0)
|
|
@@ -2597,7 +2593,7 @@ export function parseSlideHtml(doc) {
|
|
|
2597
2593
|
}
|
|
2598
2594
|
const hasBg = computed.backgroundColor && computed.backgroundColor !== 'rgba(0, 0, 0, 0)';
|
|
2599
2595
|
// Check for clip-path: polygon() — store for custom geometry
|
|
2600
|
-
const clipPathValue = computed.clipPath || computed.webkitClipPath;
|
|
2596
|
+
const clipPathValue = computed.clipPath || computed.webkitClipPath || '';
|
|
2601
2597
|
const clipPathPolygon = parseClipPathPolygon(clipPathValue);
|
|
2602
2598
|
// Check for background images or gradients
|
|
2603
2599
|
const elBgImage = computed.backgroundImage;
|
|
@@ -2605,7 +2601,7 @@ export function parseSlideHtml(doc) {
|
|
|
2605
2601
|
let bgImageSize = null;
|
|
2606
2602
|
let bgImagePosition = null;
|
|
2607
2603
|
let bgGradient = null;
|
|
2608
|
-
|
|
2604
|
+
const extraDivGradients = [];
|
|
2609
2605
|
if (elBgImage && elBgImage !== 'none') {
|
|
2610
2606
|
if (elBgImage.includes('linear-gradient') ||
|
|
2611
2607
|
elBgImage.includes('radial-gradient')) {
|
|
@@ -2848,7 +2844,7 @@ export function parseSlideHtml(doc) {
|
|
|
2848
2844
|
const alignItems = computed.alignItems;
|
|
2849
2845
|
const justifyContent = computed.justifyContent;
|
|
2850
2846
|
let valign = 'top';
|
|
2851
|
-
let align
|
|
2847
|
+
let align;
|
|
2852
2848
|
if (isFlexContainer) {
|
|
2853
2849
|
const flexDirection = computed.flexDirection || 'row';
|
|
2854
2850
|
if (flexDirection === 'row' || flexDirection === 'row-reverse') {
|
|
@@ -3587,7 +3583,7 @@ export function parseSlideHtml(doc) {
|
|
|
3587
3583
|
const isLast = idx === liElements.length - 1;
|
|
3588
3584
|
const runs = parseInlineFormatting(li, { breakLine: false }, [], (x) => x, win);
|
|
3589
3585
|
if (runs.length > 0) {
|
|
3590
|
-
runs[0].text = runs[0].text.replace(/^[
|
|
3586
|
+
runs[0].text = runs[0].text.replace(/^[•\-*\u25AA\u25B8]\s*/, '');
|
|
3591
3587
|
if (hasNativeBullets) {
|
|
3592
3588
|
runs[0].options.bullet = { indent: textIndent };
|
|
3593
3589
|
}
|
|
@@ -3720,7 +3716,7 @@ export function parseSlideHtml(doc) {
|
|
|
3720
3716
|
}
|
|
3721
3717
|
}
|
|
3722
3718
|
if (el.tagName !== 'LI' &&
|
|
3723
|
-
/^[
|
|
3719
|
+
/^[•\-*\u25AA\u25B8\u25CB\u25CF\u25C6\u25C7\u25A0\u25A1]\s/.test(text.trimStart())) {
|
|
3724
3720
|
errors.push(`Text element <${el.tagName.toLowerCase()}> starts with bullet symbol "${text.substring(0, 20)}...". ` +
|
|
3725
3721
|
'Use <ul> or <ol> lists instead of manual bullet symbols.');
|
|
3726
3722
|
return;
|
|
@@ -3730,7 +3726,7 @@ export function parseSlideHtml(doc) {
|
|
|
3730
3726
|
const fontSizePx = parseFloat(computed.fontSize);
|
|
3731
3727
|
const lineHeightPx = parseFloat(computed.lineHeight);
|
|
3732
3728
|
const lineHeightMultiplier = fontSizePx > 0 && !isNaN(lineHeightPx) ? lineHeightPx / fontSizePx : 1.0;
|
|
3733
|
-
|
|
3729
|
+
const textAlign = computed.textAlign === 'start' ? 'left' : computed.textAlign;
|
|
3734
3730
|
let valign = null;
|
|
3735
3731
|
const checkFlexParent = (parent) => {
|
|
3736
3732
|
if (!parent)
|