html2canvas-pro 2.1.1 → 2.2.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.
Files changed (90) hide show
  1. package/dist/html2canvas-pro.esm.js +10226 -10540
  2. package/dist/html2canvas-pro.esm.js.map +1 -1
  3. package/dist/html2canvas-pro.js +10869 -11185
  4. package/dist/html2canvas-pro.js.map +1 -1
  5. package/dist/html2canvas-pro.min.js +8 -8
  6. package/dist/lib/config.js +0 -22
  7. package/dist/lib/core/cache-storage.js +1 -38
  8. package/dist/lib/core/constants.js +25 -0
  9. package/dist/lib/core/context.js +1 -0
  10. package/dist/lib/core/features.js +1 -0
  11. package/dist/lib/core/validator.js +3 -3
  12. package/dist/lib/css/grouped/background-styles.js +36 -0
  13. package/dist/lib/css/grouped/border-styles.js +75 -0
  14. package/dist/lib/css/grouped/font-styles.js +93 -0
  15. package/dist/lib/css/grouped/layout-styles.js +127 -0
  16. package/dist/lib/css/index.js +74 -46
  17. package/dist/lib/css/layout/text.js +7 -6
  18. package/dist/lib/css/property-descriptors/background-blend-mode.js +41 -0
  19. package/dist/lib/css/property-descriptors/border-image-repeat.js +42 -0
  20. package/dist/lib/css/property-descriptors/border-image-slice.js +45 -0
  21. package/dist/lib/css/property-descriptors/border-image-source.js +21 -0
  22. package/dist/lib/css/property-descriptors/border-radius.js +1 -1
  23. package/dist/lib/css/property-descriptors/box-decoration-break.js +18 -0
  24. package/dist/lib/css/property-descriptors/counter-increment.js +17 -12
  25. package/dist/lib/css/property-descriptors/counter-reset.js +4 -12
  26. package/dist/lib/css/property-descriptors/filter.js +76 -0
  27. package/dist/lib/css/property-descriptors/font-variant-ligatures.js +34 -0
  28. package/dist/lib/css/property-descriptors/object-fit.js +1 -1
  29. package/dist/lib/css/property-descriptors/object-position.js +42 -0
  30. package/dist/lib/css/property-descriptors/visibility.js +1 -1
  31. package/dist/lib/css/property-descriptors/zoom.js +18 -0
  32. package/dist/lib/css/syntax/parser.js +0 -1
  33. package/dist/lib/css/types/color.js +5 -1
  34. package/dist/lib/css/types/functions/repeating-linear-gradient.js +9 -0
  35. package/dist/lib/css/types/image.js +12 -2
  36. package/dist/lib/css/types/length-percentage.js +6 -2
  37. package/dist/lib/css/types/safe-eval.js +80 -0
  38. package/dist/lib/dom/document-cloner.js +23 -163
  39. package/dist/lib/dom/slot-cloner.js +176 -0
  40. package/dist/lib/index.js +1 -17
  41. package/dist/lib/render/canvas/background-renderer.js +165 -32
  42. package/dist/lib/render/canvas/border-image-renderer.js +153 -0
  43. package/dist/lib/render/canvas/canvas-renderer.js +34 -189
  44. package/dist/lib/render/canvas/content-renderer.js +202 -0
  45. package/dist/lib/render/canvas/effects-renderer.js +3 -0
  46. package/dist/lib/render/canvas/text/text-decoration-renderer.js +99 -0
  47. package/dist/lib/render/canvas/text-renderer.js +100 -224
  48. package/dist/lib/render/effects.js +38 -3
  49. package/dist/lib/render/object-fit.js +19 -15
  50. package/dist/lib/render/stacking-context.js +11 -0
  51. package/dist/types/config.d.ts +0 -10
  52. package/dist/types/core/cache-storage.d.ts +0 -24
  53. package/dist/types/core/constants.d.ts +22 -0
  54. package/dist/types/core/context.d.ts +3 -0
  55. package/dist/types/core/performance-monitor.d.ts +4 -4
  56. package/dist/types/core/validator.d.ts +6 -8
  57. package/dist/types/css/grouped/background-styles.d.ts +16 -0
  58. package/dist/types/css/grouped/border-styles.d.ts +31 -0
  59. package/dist/types/css/grouped/font-styles.d.ts +35 -0
  60. package/dist/types/css/grouped/layout-styles.d.ts +46 -0
  61. package/dist/types/css/index.d.ts +30 -0
  62. package/dist/types/css/property-descriptors/background-blend-mode.d.ts +23 -0
  63. package/dist/types/css/property-descriptors/border-image-repeat.d.ts +12 -0
  64. package/dist/types/css/property-descriptors/border-image-slice.d.ts +10 -0
  65. package/dist/types/css/property-descriptors/border-image-source.d.ts +4 -0
  66. package/dist/types/css/property-descriptors/box-decoration-break.d.ts +6 -0
  67. package/dist/types/css/property-descriptors/counter-increment.d.ts +3 -0
  68. package/dist/types/css/property-descriptors/filter.d.ts +3 -0
  69. package/dist/types/css/property-descriptors/font-variant-ligatures.d.ts +14 -0
  70. package/dist/types/css/property-descriptors/object-position.d.ts +4 -0
  71. package/dist/types/css/property-descriptors/zoom.d.ts +3 -0
  72. package/dist/types/css/types/functions/repeating-linear-gradient.d.ts +4 -0
  73. package/dist/types/css/types/image.d.ts +4 -2
  74. package/dist/types/css/types/safe-eval.d.ts +8 -0
  75. package/dist/types/dom/document-cloner.d.ts +3 -44
  76. package/dist/types/dom/slot-cloner.d.ts +66 -0
  77. package/dist/types/index.d.ts +3 -7
  78. package/dist/types/options.d.ts +11 -0
  79. package/dist/types/render/canvas/background-renderer.d.ts +23 -0
  80. package/dist/types/render/canvas/border-image-renderer.d.ts +18 -0
  81. package/dist/types/render/canvas/canvas-renderer.d.ts +1 -0
  82. package/dist/types/render/canvas/content-renderer.d.ts +44 -0
  83. package/dist/types/render/canvas/text/text-decoration-renderer.d.ts +18 -0
  84. package/dist/types/render/canvas/text-renderer.d.ts +12 -1
  85. package/dist/types/render/effects.d.ts +12 -2
  86. package/dist/types/render/object-fit.d.ts +2 -1
  87. package/dist/types/render/renderer-interface.d.ts +11 -9
  88. package/package.json +5 -10
  89. package/dist/lib/dom/replaced-elements/pseudo-elements.js +0 -0
  90. package/dist/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Html2CanvasConfig = void 0;
4
- exports.setDefaultConfig = setDefaultConfig;
5
- exports.getDefaultConfig = getDefaultConfig;
6
4
  /**
7
5
  * Html2Canvas Configuration
8
6
  *
@@ -49,23 +47,3 @@ class Html2CanvasConfig {
49
47
  }
50
48
  }
51
49
  exports.Html2CanvasConfig = Html2CanvasConfig;
52
- /**
53
- * Default global configuration (for backward compatibility)
54
- * @deprecated Use Html2CanvasConfig instances instead
55
- */
56
- let _defaultConfig = null;
57
- /**
58
- * Set default configuration
59
- * @deprecated Pass configuration directly to html2canvas instead
60
- */
61
- function setDefaultConfig(config) {
62
- console.warn('[html2canvas-pro] setDefaultConfig is deprecated. Pass configuration to html2canvas directly.');
63
- _defaultConfig = config;
64
- }
65
- /**
66
- * Get default configuration
67
- * @deprecated Pass configuration directly to html2canvas instead
68
- */
69
- function getDefaultConfig() {
70
- return _defaultConfig;
71
- }
@@ -1,44 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Cache = exports.CacheStorage = void 0;
3
+ exports.Cache = void 0;
4
4
  const features_1 = require("./features");
5
- /**
6
- * CacheStorage (Deprecated static methods)
7
- *
8
- * @deprecated The static methods of CacheStorage are deprecated.
9
- * Use OriginChecker class instead for instance-based origin checking.
10
- *
11
- * For backward compatibility, these methods remain but should not be used in new code.
12
- */
13
- class CacheStorage {
14
- /**
15
- * @deprecated Use OriginChecker.getOrigin() instead
16
- */
17
- static getOrigin(url) {
18
- const link = CacheStorage._link;
19
- if (!link) {
20
- return 'about:blank';
21
- }
22
- link.href = url;
23
- link.href = link.href; // IE9, LOL! - http://jsfiddle.net/niklasvh/2e48b/
24
- return link.protocol + link.hostname + link.port;
25
- }
26
- /**
27
- * @deprecated Use OriginChecker.isSameOrigin() instead
28
- */
29
- static isSameOrigin(src) {
30
- return CacheStorage.getOrigin(src) === CacheStorage._origin;
31
- }
32
- /**
33
- * @deprecated No longer needed. OriginChecker is created per Context.
34
- */
35
- static setContext(window) {
36
- CacheStorage._link = window.document.createElement('a');
37
- CacheStorage._origin = CacheStorage.getOrigin(window.location.href);
38
- }
39
- }
40
- exports.CacheStorage = CacheStorage;
41
- CacheStorage._origin = 'about:blank';
42
5
  class Cache {
43
6
  constructor(context, _options) {
44
7
  this.context = context;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Shared numeric constants used across html2canvas-pro.
4
+ * Centralising magic numbers for maintainability.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.RESOURCE_KEY_LOG_LENGTH = exports.INLINE_IMAGE_RESOLVE_DELAY_MS = exports.IFRAME_READY_POLL_MS = exports.SHADOW_MASK_OFFSET = exports.DEFAULT_IMAGE_TIMEOUT_MS = exports.MAX_IMAGE_CACHE_SIZE = exports.DEFAULT_IMAGE_CACHE_SIZE = exports.PATTERN_CACHE_MAX = exports.PARSE_CACHE_MAX_PER_DESCRIPTOR = void 0;
8
+ /** Maximum entries in the CSS parse cache per descriptor (LRU). */
9
+ exports.PARSE_CACHE_MAX_PER_DESCRIPTOR = 200;
10
+ /** Maximum cached background-image patterns per render session (LRU). */
11
+ exports.PATTERN_CACHE_MAX = 50;
12
+ /** Maximum size of the image-resource cache (entries). */
13
+ exports.DEFAULT_IMAGE_CACHE_SIZE = 100;
14
+ /** Maximum allowed image-resource cache size. */
15
+ exports.MAX_IMAGE_CACHE_SIZE = 10000;
16
+ /** Default image-load timeout in milliseconds. */
17
+ exports.DEFAULT_IMAGE_TIMEOUT_MS = 15000;
18
+ /** Z-axis mask offset used during box-shadow rendering. */
19
+ exports.SHADOW_MASK_OFFSET = 10000;
20
+ /** Polling interval (ms) when waiting for the cloned iframe to become ready. */
21
+ exports.IFRAME_READY_POLL_MS = 50;
22
+ /** Deferred resolution delay (ms) for inline XML images that may fail to parse. */
23
+ exports.INLINE_IMAGE_RESOLVE_DELAY_MS = 500;
24
+ /** Maximum characters logged for image/resource keys. */
25
+ exports.RESOURCE_KEY_LOG_LENGTH = 256;
@@ -12,6 +12,7 @@ class Context {
12
12
  this.logger = new logger_1.Logger({ id: this.instanceName, enabled: options.logging });
13
13
  this.originChecker = new origin_checker_1.OriginChecker(config.window);
14
14
  this.cache = options.cache ?? config.cache ?? new cache_storage_1.Cache(this, options);
15
+ this.onError = options.onError;
15
16
  }
16
17
  }
17
18
  exports.Context = Context;
@@ -182,6 +182,7 @@ exports.FEATURES = {
182
182
  },
183
183
  get SUPPORT_NATIVE_TEXT_SEGMENTATION() {
184
184
  'use strict';
185
+ // Intl.Segmenter is TC39 Stage 4 but not yet in TS lib types
185
186
  const value = !!(typeof Intl !== 'undefined' && Intl.Segmenter);
186
187
  Object.defineProperty(exports.FEATURES, 'SUPPORT_NATIVE_TEXT_SEGMENTATION', { value });
187
188
  return value;
@@ -391,6 +391,7 @@ class Validator {
391
391
  // Accept real HTMLElement, or any element-like object with the minimal shape
392
392
  // required by the implementation (ownerDocument + defaultView) for backward
393
393
  // compatibility and test environments.
394
+ const el = element;
394
395
  if (typeof HTMLElement !== 'undefined' && element instanceof HTMLElement) {
395
396
  // Real DOM element
396
397
  if (!element.ownerDocument) {
@@ -399,13 +400,13 @@ class Validator {
399
400
  return { valid: true };
400
401
  }
401
402
  // Duck-typing: accept object with ownerDocument and defaultView (minimal contract)
402
- if (!element.ownerDocument) {
403
+ if (!el.ownerDocument) {
403
404
  return {
404
405
  valid: false,
405
406
  error: 'Element must be attached to a document (ownerDocument required)'
406
407
  };
407
408
  }
408
- if (!element.ownerDocument.defaultView) {
409
+ if (!el.ownerDocument.defaultView) {
409
410
  return {
410
411
  valid: false,
411
412
  error: 'Document must be attached to a window (ownerDocument.defaultView required)'
@@ -421,7 +422,6 @@ class Validator {
421
422
  */
422
423
  validateOptions(options) {
423
424
  const errors = [];
424
- // Validate proxy URL only when a non-empty string (allow null/undefined to mean "no proxy")
425
425
  const proxyUrl = options.proxy;
426
426
  if (proxyUrl !== undefined && proxyUrl !== null && typeof proxyUrl === 'string' && proxyUrl.length > 0) {
427
427
  const proxyResult = this.validateUrl(proxyUrl, 'proxy');
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BackgroundStyles = void 0;
4
+ /**
5
+ * Read-only grouped accessor for background-related CSS properties.
6
+ */
7
+ class BackgroundStyles {
8
+ constructor(styles) {
9
+ this.styles = styles;
10
+ }
11
+ get color() {
12
+ return this.styles.backgroundColor;
13
+ }
14
+ get image() {
15
+ return this.styles.backgroundImage;
16
+ }
17
+ get clip() {
18
+ return this.styles.backgroundClip;
19
+ }
20
+ get origin() {
21
+ return this.styles.backgroundOrigin;
22
+ }
23
+ get position() {
24
+ return this.styles.backgroundPosition;
25
+ }
26
+ get repeat() {
27
+ return this.styles.backgroundRepeat;
28
+ }
29
+ get size() {
30
+ return this.styles.backgroundSize;
31
+ }
32
+ get blendMode() {
33
+ return this.styles.backgroundBlendMode;
34
+ }
35
+ }
36
+ exports.BackgroundStyles = BackgroundStyles;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BorderStyles = void 0;
4
+ /**
5
+ * Read-only grouped accessor for border-related CSS properties.
6
+ *
7
+ * Provides structured access: `styles.border.topColor` as an alternative
8
+ * to the flat `styles.borderTopColor`. Both forms remain valid.
9
+ */
10
+ class BorderStyles {
11
+ constructor(styles) {
12
+ this.styles = styles;
13
+ }
14
+ get topColor() {
15
+ return this.styles.borderTopColor;
16
+ }
17
+ get rightColor() {
18
+ return this.styles.borderRightColor;
19
+ }
20
+ get bottomColor() {
21
+ return this.styles.borderBottomColor;
22
+ }
23
+ get leftColor() {
24
+ return this.styles.borderLeftColor;
25
+ }
26
+ get topStyle() {
27
+ return this.styles.borderTopStyle;
28
+ }
29
+ get rightStyle() {
30
+ return this.styles.borderRightStyle;
31
+ }
32
+ get bottomStyle() {
33
+ return this.styles.borderBottomStyle;
34
+ }
35
+ get leftStyle() {
36
+ return this.styles.borderLeftStyle;
37
+ }
38
+ get topWidth() {
39
+ return this.styles.borderTopWidth;
40
+ }
41
+ get rightWidth() {
42
+ return this.styles.borderRightWidth;
43
+ }
44
+ get bottomWidth() {
45
+ return this.styles.borderBottomWidth;
46
+ }
47
+ get leftWidth() {
48
+ return this.styles.borderLeftWidth;
49
+ }
50
+ get topLeftRadius() {
51
+ return this.styles.borderTopLeftRadius;
52
+ }
53
+ get topRightRadius() {
54
+ return this.styles.borderTopRightRadius;
55
+ }
56
+ get bottomRightRadius() {
57
+ return this.styles.borderBottomRightRadius;
58
+ }
59
+ get bottomLeftRadius() {
60
+ return this.styles.borderBottomLeftRadius;
61
+ }
62
+ get imageSource() {
63
+ return this.styles.borderImageSource;
64
+ }
65
+ get imageSlice() {
66
+ return this.styles.borderImageSlice;
67
+ }
68
+ get imageRepeat() {
69
+ return this.styles.borderImageRepeat;
70
+ }
71
+ get boxShadow() {
72
+ return this.styles.boxShadow;
73
+ }
74
+ }
75
+ exports.BorderStyles = BorderStyles;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FontStyles = void 0;
4
+ /**
5
+ * Read-only grouped accessor for font/text-related CSS properties.
6
+ */
7
+ class FontStyles {
8
+ constructor(styles) {
9
+ this.styles = styles;
10
+ }
11
+ get family() {
12
+ return this.styles.fontFamily;
13
+ }
14
+ get size() {
15
+ return this.styles.fontSize;
16
+ }
17
+ get style() {
18
+ return this.styles.fontStyle;
19
+ }
20
+ get variant() {
21
+ return this.styles.fontVariant;
22
+ }
23
+ get weight() {
24
+ return this.styles.fontWeight;
25
+ }
26
+ get ligatures() {
27
+ return this.styles.fontVariantLigatures;
28
+ }
29
+ get color() {
30
+ return this.styles.color;
31
+ }
32
+ get letterSpacing() {
33
+ return this.styles.letterSpacing;
34
+ }
35
+ get lineHeight() {
36
+ return this.styles.lineHeight;
37
+ }
38
+ get textAlign() {
39
+ return this.styles.textAlign;
40
+ }
41
+ get textTransform() {
42
+ return this.styles.textTransform;
43
+ }
44
+ get textOverflow() {
45
+ return this.styles.textOverflow;
46
+ }
47
+ get textShadow() {
48
+ return this.styles.textShadow;
49
+ }
50
+ get textDecorationColor() {
51
+ return this.styles.textDecorationColor;
52
+ }
53
+ get textDecorationLine() {
54
+ return this.styles.textDecorationLine;
55
+ }
56
+ get textDecorationStyle() {
57
+ return this.styles.textDecorationStyle;
58
+ }
59
+ get textDecorationThickness() {
60
+ return this.styles.textDecorationThickness;
61
+ }
62
+ get textUnderlineOffset() {
63
+ return this.styles.textUnderlineOffset;
64
+ }
65
+ get wordBreak() {
66
+ return this.styles.wordBreak;
67
+ }
68
+ get lineBreak() {
69
+ return this.styles.lineBreak;
70
+ }
71
+ get overflowWrap() {
72
+ return this.styles.overflowWrap;
73
+ }
74
+ get writingMode() {
75
+ return this.styles.writingMode;
76
+ }
77
+ get direction() {
78
+ return this.styles.direction;
79
+ }
80
+ get webkitTextStrokeColor() {
81
+ return this.styles.webkitTextStrokeColor;
82
+ }
83
+ get webkitTextStrokeWidth() {
84
+ return this.styles.webkitTextStrokeWidth;
85
+ }
86
+ get webkitLineClamp() {
87
+ return this.styles.webkitLineClamp;
88
+ }
89
+ get paintOrder() {
90
+ return this.styles.paintOrder;
91
+ }
92
+ }
93
+ exports.FontStyles = FontStyles;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LayoutStyles = void 0;
4
+ /**
5
+ * Read-only grouped accessor for layout/display/positioning CSS properties.
6
+ */
7
+ class LayoutStyles {
8
+ constructor(styles) {
9
+ this.styles = styles;
10
+ }
11
+ get display() {
12
+ return this.styles.display;
13
+ }
14
+ get position() {
15
+ return this.styles.position;
16
+ }
17
+ get float() {
18
+ return this.styles.float;
19
+ }
20
+ // Explicit return type avoids name clash with z-index descriptor export.
21
+ get zIndex() {
22
+ return this.styles.zIndex;
23
+ }
24
+ get marginTop() {
25
+ return this.styles.marginTop;
26
+ }
27
+ get marginRight() {
28
+ return this.styles.marginRight;
29
+ }
30
+ get marginBottom() {
31
+ return this.styles.marginBottom;
32
+ }
33
+ get marginLeft() {
34
+ return this.styles.marginLeft;
35
+ }
36
+ get paddingTop() {
37
+ return this.styles.paddingTop;
38
+ }
39
+ get paddingRight() {
40
+ return this.styles.paddingRight;
41
+ }
42
+ get paddingBottom() {
43
+ return this.styles.paddingBottom;
44
+ }
45
+ get paddingLeft() {
46
+ return this.styles.paddingLeft;
47
+ }
48
+ get overflowX() {
49
+ return this.styles.overflowX;
50
+ }
51
+ get overflowY() {
52
+ return this.styles.overflowY;
53
+ }
54
+ get opacity() {
55
+ return this.styles.opacity;
56
+ }
57
+ get visibility() {
58
+ return this.styles.visibility;
59
+ }
60
+ get transform() {
61
+ return this.styles.transform;
62
+ }
63
+ get transformOrigin() {
64
+ return this.styles.transformOrigin;
65
+ }
66
+ get rotate() {
67
+ return this.styles.rotate;
68
+ }
69
+ get zoom() {
70
+ return this.styles.zoom;
71
+ }
72
+ get clipPath() {
73
+ return this.styles.clipPath;
74
+ }
75
+ get mixBlendMode() {
76
+ return this.styles.mixBlendMode;
77
+ }
78
+ get filter() {
79
+ return this.styles.filter;
80
+ }
81
+ get imageRendering() {
82
+ return this.styles.imageRendering;
83
+ }
84
+ get objectFit() {
85
+ return this.styles.objectFit;
86
+ }
87
+ get objectPosition() {
88
+ return this.styles.objectPosition;
89
+ }
90
+ get boxDecorationBreak() {
91
+ return this.styles.boxDecorationBreak;
92
+ }
93
+ get listStyleImage() {
94
+ return this.styles.listStyleImage;
95
+ }
96
+ get listStylePosition() {
97
+ return this.styles.listStylePosition;
98
+ }
99
+ get listStyleType() {
100
+ return this.styles.listStyleType;
101
+ }
102
+ get animationDuration() {
103
+ return this.styles.animationDuration;
104
+ }
105
+ isVisible() {
106
+ return this.styles.isVisible();
107
+ }
108
+ isTransparent() {
109
+ return this.styles.isTransparent();
110
+ }
111
+ isTransformed() {
112
+ return this.styles.isTransformed();
113
+ }
114
+ isPositioned() {
115
+ return this.styles.isPositioned();
116
+ }
117
+ isPositionedWithZIndex() {
118
+ return this.styles.isPositionedWithZIndex();
119
+ }
120
+ isFloating() {
121
+ return this.styles.isFloating();
122
+ }
123
+ isInlineLevel() {
124
+ return this.styles.isInlineLevel();
125
+ }
126
+ }
127
+ exports.LayoutStyles = LayoutStyles;
@@ -73,7 +73,33 @@ const object_fit_1 = require("./property-descriptors/object-fit");
73
73
  const text_overflow_1 = require("./property-descriptors/text-overflow");
74
74
  const image_rendering_1 = require("./property-descriptors/image-rendering");
75
75
  const mix_blend_mode_1 = require("./property-descriptors/mix-blend-mode");
76
+ const filter_1 = require("./property-descriptors/filter");
77
+ const font_variant_ligatures_1 = require("./property-descriptors/font-variant-ligatures");
78
+ const zoom_1 = require("./property-descriptors/zoom");
79
+ const object_position_1 = require("./property-descriptors/object-position");
80
+ const background_blend_mode_1 = require("./property-descriptors/background-blend-mode");
81
+ const border_image_source_1 = require("./property-descriptors/border-image-source");
82
+ const border_image_slice_1 = require("./property-descriptors/border-image-slice");
83
+ const border_image_repeat_1 = require("./property-descriptors/border-image-repeat");
84
+ const box_decoration_break_1 = require("./property-descriptors/box-decoration-break");
85
+ const constants_1 = require("../core/constants");
86
+ const border_styles_1 = require("./grouped/border-styles");
87
+ const background_styles_1 = require("./grouped/background-styles");
88
+ const font_styles_1 = require("./grouped/font-styles");
89
+ const layout_styles_1 = require("./grouped/layout-styles");
76
90
  class CSSParsedDeclaration {
91
+ get border() {
92
+ return this._border ?? (this._border = new border_styles_1.BorderStyles(this));
93
+ }
94
+ get background() {
95
+ return this._background ?? (this._background = new background_styles_1.BackgroundStyles(this));
96
+ }
97
+ get font() {
98
+ return this._font ?? (this._font = new font_styles_1.FontStyles(this));
99
+ }
100
+ get layout() {
101
+ return this._layout ?? (this._layout = new layout_styles_1.LayoutStyles(this));
102
+ }
77
103
  constructor(context, declaration) {
78
104
  const standardProps = CSSParsedDeclaration.standardProps;
79
105
  // Fast path: display:none elements are invisible and their descendants
@@ -205,7 +231,16 @@ CSSParsedDeclaration.standardProps = [
205
231
  ['zIndex', z_index_1.zIndex, 'zIndex'],
206
232
  ['objectFit', object_fit_1.objectFit, 'objectFit'],
207
233
  ['imageRendering', image_rendering_1.imageRendering, 'imageRendering'],
208
- ['mixBlendMode', mix_blend_mode_1.mixBlendMode, 'mixBlendMode']
234
+ ['mixBlendMode', mix_blend_mode_1.mixBlendMode, 'mixBlendMode'],
235
+ ['filter', filter_1.filter, 'filter'],
236
+ ['fontVariantLigatures', font_variant_ligatures_1.fontVariantLigatures, 'fontVariantLigatures'],
237
+ ['zoom', zoom_1.zoom, 'zoom'],
238
+ ['objectPosition', object_position_1.objectPosition, 'objectPosition'],
239
+ ['backgroundBlendMode', background_blend_mode_1.backgroundBlendMode, 'backgroundBlendMode'],
240
+ ['borderImageSource', border_image_source_1.borderImageSource, 'borderImageSource'],
241
+ ['borderImageSlice', border_image_slice_1.borderImageSlice, 'borderImageSlice'],
242
+ ['borderImageRepeat', border_image_repeat_1.borderImageRepeat, 'borderImageRepeat'],
243
+ ['boxDecorationBreak', box_decoration_break_1.boxDecorationBreak, 'boxDecorationBreak']
209
244
  ];
210
245
  class CSSParsedPseudoDeclaration {
211
246
  constructor(context, declaration) {
@@ -222,13 +257,14 @@ class CSSParsedCounterDeclaration {
222
257
  }
223
258
  exports.CSSParsedCounterDeclaration = CSSParsedCounterDeclaration;
224
259
  const parseCache = new Map();
225
- const PARSE_CACHE_MAX_PER_DESCRIPTOR = 200;
226
260
  const parse = (context, descriptor, style) => {
227
261
  const rawValue = style !== null && typeof style !== 'undefined' ? style.toString() : descriptor.initialValue;
228
262
  let valueCache = parseCache.get(descriptor);
229
263
  if (valueCache) {
230
264
  const cached = valueCache.get(rawValue);
231
265
  if (cached !== undefined) {
266
+ valueCache.delete(rawValue);
267
+ valueCache.set(rawValue, cached);
232
268
  return cached;
233
269
  }
234
270
  }
@@ -236,55 +272,47 @@ const parse = (context, descriptor, style) => {
236
272
  tokenizer.write(rawValue);
237
273
  const parser = new parser_1.Parser(tokenizer.read());
238
274
  tokenizer_1.Tokenizer.release(tokenizer);
239
- let result;
240
- switch (descriptor.type) {
241
- case 2 /* PropertyDescriptorParsingType.IDENT_VALUE */: {
242
- const token = parser.parseComponentValue();
243
- result = descriptor.parse(context, (0, parser_1.isIdentToken)(token) ? token.value : descriptor.initialValue);
244
- break;
245
- }
246
- case 0 /* PropertyDescriptorParsingType.VALUE */:
247
- result = descriptor.parse(context, parser.parseComponentValue());
248
- break;
249
- case 1 /* PropertyDescriptorParsingType.LIST */:
250
- result = descriptor.parse(context, parser.parseComponentValues());
251
- break;
252
- case 4 /* PropertyDescriptorParsingType.TOKEN_VALUE */:
253
- result = parser.parseComponentValue();
254
- break;
255
- case 3 /* PropertyDescriptorParsingType.TYPE_VALUE */:
256
- switch (descriptor.format) {
257
- case 'angle':
258
- result = angle_1.angle.parse(context, parser.parseComponentValue());
259
- break;
260
- case 'color':
261
- result = color_2.color.parse(context, parser.parseComponentValue());
262
- break;
263
- case 'image':
264
- result = image_1.image.parse(context, parser.parseComponentValue());
265
- break;
266
- case 'length': {
267
- const length = parser.parseComponentValue();
268
- result = (0, length_1.isLength)(length) ? length : length_percentage_1.ZERO_LENGTH;
269
- break;
270
- }
271
- case 'length-percentage': {
272
- const value = parser.parseComponentValue();
273
- result = (0, length_percentage_1.isLengthPercentage)(value) ? value : length_percentage_1.ZERO_LENGTH;
274
- break;
275
- }
276
- case 'time':
277
- result = time_1.time.parse(context, parser.parseComponentValue());
278
- break;
275
+ // Use IIFE so TS infers the return type of each branch (no `let result: any`)
276
+ const result = (() => {
277
+ switch (descriptor.type) {
278
+ case 2 /* PropertyDescriptorParsingType.IDENT_VALUE */: {
279
+ const token = parser.parseComponentValue();
280
+ return descriptor.parse(context, (0, parser_1.isIdentToken)(token) ? token.value : descriptor.initialValue);
279
281
  }
280
- break;
281
- }
282
+ case 0 /* PropertyDescriptorParsingType.VALUE */:
283
+ return descriptor.parse(context, parser.parseComponentValue());
284
+ case 1 /* PropertyDescriptorParsingType.LIST */:
285
+ return descriptor.parse(context, parser.parseComponentValues());
286
+ case 4 /* PropertyDescriptorParsingType.TOKEN_VALUE */:
287
+ return parser.parseComponentValue();
288
+ case 3 /* PropertyDescriptorParsingType.TYPE_VALUE */:
289
+ switch (descriptor.format) {
290
+ case 'angle':
291
+ return angle_1.angle.parse(context, parser.parseComponentValue());
292
+ case 'color':
293
+ return color_2.color.parse(context, parser.parseComponentValue());
294
+ case 'image':
295
+ return image_1.image.parse(context, parser.parseComponentValue());
296
+ case 'length': {
297
+ const length = parser.parseComponentValue();
298
+ return (0, length_1.isLength)(length) ? length : length_percentage_1.ZERO_LENGTH;
299
+ }
300
+ case 'length-percentage': {
301
+ const value = parser.parseComponentValue();
302
+ return (0, length_percentage_1.isLengthPercentage)(value) ? value : length_percentage_1.ZERO_LENGTH;
303
+ }
304
+ case 'time':
305
+ return time_1.time.parse(context, parser.parseComponentValue());
306
+ }
307
+ }
308
+ })();
282
309
  if (!valueCache) {
283
310
  valueCache = new Map();
284
311
  parseCache.set(descriptor, valueCache);
285
312
  }
286
- if (valueCache.size >= PARSE_CACHE_MAX_PER_DESCRIPTOR) {
287
- valueCache.clear();
313
+ if (valueCache.size >= constants_1.PARSE_CACHE_MAX_PER_DESCRIPTOR) {
314
+ const oldestKey = valueCache.keys().next().value;
315
+ valueCache.delete(oldestKey);
288
316
  }
289
317
  valueCache.set(rawValue, result);
290
318
  return result;
@@ -76,18 +76,19 @@ const createRange = (node, offset, length) => {
76
76
  };
77
77
  const segmentGraphemes = (value) => {
78
78
  if (features_1.FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
79
- const segmenter = new Intl.Segmenter(void 0, { granularity: 'grapheme' });
80
- return Array.from(segmenter.segment(value)).map((segment) => segment.segment);
79
+ // Intl.Segmenter is TC39 Stage 4 but not yet in TS lib types
80
+ const Segmenter = Intl;
81
+ const seg = new Segmenter.Segmenter(void 0, { granularity: 'grapheme' });
82
+ return Array.from(seg.segment(value)).map((s) => s.segment);
81
83
  }
82
84
  return (0, text_segmentation_1.splitGraphemes)(value);
83
85
  };
84
86
  exports.segmentGraphemes = segmentGraphemes;
85
87
  const segmentWords = (value, styles) => {
86
88
  if (features_1.FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
87
- const segmenter = new Intl.Segmenter(void 0, {
88
- granularity: 'word'
89
- });
90
- return Array.from(segmenter.segment(value)).map((segment) => segment.segment);
89
+ const Segmenter = Intl;
90
+ const seg = new Segmenter.Segmenter(void 0, { granularity: 'word' });
91
+ return Array.from(seg.segment(value)).map((s) => s.segment);
91
92
  }
92
93
  return breakWords(value, styles);
93
94
  };