html2canvas-pro 2.1.0 → 2.1.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.
Files changed (186) hide show
  1. package/dist/html2canvas-pro.esm.js +21 -7
  2. package/dist/html2canvas-pro.esm.js.map +1 -1
  3. package/dist/html2canvas-pro.js +21 -7
  4. package/dist/html2canvas-pro.js.map +1 -1
  5. package/dist/html2canvas-pro.min.js +3 -3
  6. package/dist/lib/core/cache-storage.js +2 -2
  7. package/dist/lib/core/features.js +2 -2
  8. package/dist/lib/render/canvas/background-renderer.js +6 -0
  9. package/dist/lib/render/canvas/canvas-renderer.js +5 -1
  10. package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
  11. package/package.json +3 -11
  12. package/dist/lib/invariant.js +0 -9
  13. package/dist/types/invariant.d.ts +0 -1
  14. package/src/__tests__/index.ts +0 -99
  15. package/src/config.ts +0 -107
  16. package/src/core/__mocks__/cache-storage.ts +0 -1
  17. package/src/core/__mocks__/context.ts +0 -19
  18. package/src/core/__mocks__/features.ts +0 -8
  19. package/src/core/__mocks__/logger.ts +0 -17
  20. package/src/core/__tests__/cache-storage.test.ts +0 -205
  21. package/src/core/__tests__/cache-storage.ts +0 -278
  22. package/src/core/__tests__/logger.ts +0 -29
  23. package/src/core/__tests__/validator.ts +0 -359
  24. package/src/core/bitwise.ts +0 -1
  25. package/src/core/cache-storage.ts +0 -315
  26. package/src/core/context.ts +0 -31
  27. package/src/core/debugger.ts +0 -32
  28. package/src/core/features.ts +0 -222
  29. package/src/core/logger.ts +0 -64
  30. package/src/core/origin-checker.ts +0 -57
  31. package/src/core/performance-monitor.ts +0 -241
  32. package/src/core/render-element.ts +0 -272
  33. package/src/core/util.ts +0 -1
  34. package/src/core/validator.ts +0 -593
  35. package/src/css/index.ts +0 -427
  36. package/src/css/layout/__mocks__/bounds.ts +0 -6
  37. package/src/css/layout/bounds.ts +0 -79
  38. package/src/css/layout/text.ts +0 -161
  39. package/src/css/property-descriptor.ts +0 -49
  40. package/src/css/property-descriptors/__tests__/background-tests.ts +0 -65
  41. package/src/css/property-descriptors/__tests__/clip-path.test.ts +0 -280
  42. package/src/css/property-descriptors/__tests__/font-family.ts +0 -25
  43. package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +0 -153
  44. package/src/css/property-descriptors/__tests__/image-rendering-performance.test.ts +0 -175
  45. package/src/css/property-descriptors/__tests__/image-rendering.test.ts +0 -72
  46. package/src/css/property-descriptors/__tests__/paint-order.ts +0 -87
  47. package/src/css/property-descriptors/__tests__/text-shadow.ts +0 -94
  48. package/src/css/property-descriptors/__tests__/transform-tests.ts +0 -18
  49. package/src/css/property-descriptors/background-clip.ts +0 -30
  50. package/src/css/property-descriptors/background-color.ts +0 -9
  51. package/src/css/property-descriptors/background-image.ts +0 -27
  52. package/src/css/property-descriptors/background-origin.ts +0 -31
  53. package/src/css/property-descriptors/background-position.ts +0 -38
  54. package/src/css/property-descriptors/background-repeat.ts +0 -44
  55. package/src/css/property-descriptors/background-size.ts +0 -27
  56. package/src/css/property-descriptors/border-color.ts +0 -13
  57. package/src/css/property-descriptors/border-radius.ts +0 -19
  58. package/src/css/property-descriptors/border-style.ts +0 -34
  59. package/src/css/property-descriptors/border-width.ts +0 -20
  60. package/src/css/property-descriptors/box-shadow.ts +0 -60
  61. package/src/css/property-descriptors/clip-path.ts +0 -271
  62. package/src/css/property-descriptors/color.ts +0 -9
  63. package/src/css/property-descriptors/content.ts +0 -26
  64. package/src/css/property-descriptors/counter-increment.ts +0 -43
  65. package/src/css/property-descriptors/counter-reset.ts +0 -36
  66. package/src/css/property-descriptors/direction.ts +0 -23
  67. package/src/css/property-descriptors/display.ts +0 -117
  68. package/src/css/property-descriptors/duration.ts +0 -14
  69. package/src/css/property-descriptors/float.ts +0 -29
  70. package/src/css/property-descriptors/font-family.ts +0 -38
  71. package/src/css/property-descriptors/font-size.ts +0 -9
  72. package/src/css/property-descriptors/font-style.ts +0 -25
  73. package/src/css/property-descriptors/font-variant.ts +0 -12
  74. package/src/css/property-descriptors/font-weight.ts +0 -26
  75. package/src/css/property-descriptors/image-rendering.ts +0 -33
  76. package/src/css/property-descriptors/letter-spacing.ts +0 -25
  77. package/src/css/property-descriptors/line-break.ts +0 -22
  78. package/src/css/property-descriptors/line-height.ts +0 -22
  79. package/src/css/property-descriptors/list-style-image.ts +0 -19
  80. package/src/css/property-descriptors/list-style-position.ts +0 -22
  81. package/src/css/property-descriptors/list-style-type.ts +0 -179
  82. package/src/css/property-descriptors/margin.ts +0 -13
  83. package/src/css/property-descriptors/mix-blend-mode.ts +0 -35
  84. package/src/css/property-descriptors/object-fit.ts +0 -39
  85. package/src/css/property-descriptors/opacity.ts +0 -15
  86. package/src/css/property-descriptors/overflow-wrap.ts +0 -22
  87. package/src/css/property-descriptors/overflow.ts +0 -34
  88. package/src/css/property-descriptors/padding.ts +0 -14
  89. package/src/css/property-descriptors/paint-order.ts +0 -42
  90. package/src/css/property-descriptors/position.ts +0 -30
  91. package/src/css/property-descriptors/quotes.ts +0 -57
  92. package/src/css/property-descriptors/rotate.ts +0 -34
  93. package/src/css/property-descriptors/text-align.ts +0 -26
  94. package/src/css/property-descriptors/text-decoration-color.ts +0 -9
  95. package/src/css/property-descriptors/text-decoration-line.ts +0 -38
  96. package/src/css/property-descriptors/text-decoration-style.ts +0 -32
  97. package/src/css/property-descriptors/text-decoration-thickness.ts +0 -30
  98. package/src/css/property-descriptors/text-overflow.ts +0 -23
  99. package/src/css/property-descriptors/text-shadow.ts +0 -52
  100. package/src/css/property-descriptors/text-transform.ts +0 -27
  101. package/src/css/property-descriptors/text-underline-offset.ts +0 -27
  102. package/src/css/property-descriptors/transform-origin.ts +0 -29
  103. package/src/css/property-descriptors/transform.ts +0 -74
  104. package/src/css/property-descriptors/visibility.ts +0 -25
  105. package/src/css/property-descriptors/webkit-line-clamp.ts +0 -30
  106. package/src/css/property-descriptors/webkit-text-stroke-color.ts +0 -8
  107. package/src/css/property-descriptors/webkit-text-stroke-width.ts +0 -15
  108. package/src/css/property-descriptors/word-break.ts +0 -25
  109. package/src/css/property-descriptors/writing-mode.ts +0 -37
  110. package/src/css/property-descriptors/z-index.ts +0 -27
  111. package/src/css/syntax/__tests__/tokernizer-tests.ts +0 -29
  112. package/src/css/syntax/parser.ts +0 -188
  113. package/src/css/syntax/tokenizer.ts +0 -822
  114. package/src/css/type-descriptor.ts +0 -7
  115. package/src/css/types/__tests__/color-tests.ts +0 -147
  116. package/src/css/types/__tests__/image-tests.ts +0 -239
  117. package/src/css/types/angle.ts +0 -86
  118. package/src/css/types/color-math.ts +0 -22
  119. package/src/css/types/color-spaces/a98.ts +0 -86
  120. package/src/css/types/color-spaces/p3.ts +0 -92
  121. package/src/css/types/color-spaces/pro-photo.ts +0 -87
  122. package/src/css/types/color-spaces/rec2020.ts +0 -90
  123. package/src/css/types/color-spaces/srgb.ts +0 -87
  124. package/src/css/types/color-utilities.ts +0 -452
  125. package/src/css/types/color.ts +0 -485
  126. package/src/css/types/functions/-prefix-linear-gradient.ts +0 -35
  127. package/src/css/types/functions/-prefix-radial-gradient.ts +0 -106
  128. package/src/css/types/functions/-webkit-gradient.ts +0 -69
  129. package/src/css/types/functions/__tests__/radial-gradient.ts +0 -69
  130. package/src/css/types/functions/counter.ts +0 -511
  131. package/src/css/types/functions/gradient.ts +0 -206
  132. package/src/css/types/functions/linear-gradient.ts +0 -28
  133. package/src/css/types/functions/radial-gradient.ts +0 -101
  134. package/src/css/types/image.ts +0 -120
  135. package/src/css/types/index.ts +0 -1
  136. package/src/css/types/length-percentage.ts +0 -137
  137. package/src/css/types/length.ts +0 -7
  138. package/src/css/types/time.ts +0 -20
  139. package/src/dom/__mocks__/document-cloner.ts +0 -22
  140. package/src/dom/__tests__/dom-normalizer.test.ts +0 -133
  141. package/src/dom/__tests__/element-container.test.ts +0 -129
  142. package/src/dom/document-cloner.ts +0 -929
  143. package/src/dom/dom-normalizer.ts +0 -133
  144. package/src/dom/element-container.ts +0 -75
  145. package/src/dom/elements/li-element-container.ts +0 -10
  146. package/src/dom/elements/ol-element-container.ts +0 -12
  147. package/src/dom/elements/select-element-container.ts +0 -10
  148. package/src/dom/elements/textarea-element-container.ts +0 -9
  149. package/src/dom/node-parser.ts +0 -177
  150. package/src/dom/node-type-guards.ts +0 -70
  151. package/src/dom/replaced-elements/canvas-element-container.ts +0 -15
  152. package/src/dom/replaced-elements/iframe-element-container.ts +0 -55
  153. package/src/dom/replaced-elements/image-element-container.ts +0 -16
  154. package/src/dom/replaced-elements/index.ts +0 -5
  155. package/src/dom/replaced-elements/input-element-container.ts +0 -105
  156. package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
  157. package/src/dom/replaced-elements/svg-element-container.ts +0 -23
  158. package/src/dom/text-container.ts +0 -42
  159. package/src/global.d.ts +0 -19
  160. package/src/index.ts +0 -82
  161. package/src/invariant.ts +0 -5
  162. package/src/options.ts +0 -55
  163. package/src/render/__tests__/object-fit.test.ts +0 -85
  164. package/src/render/background.ts +0 -298
  165. package/src/render/bezier-curve.ts +0 -47
  166. package/src/render/border.ts +0 -165
  167. package/src/render/bound-curves.ts +0 -388
  168. package/src/render/box-sizing.ts +0 -31
  169. package/src/render/canvas/__tests__/background-renderer.test.ts +0 -72
  170. package/src/render/canvas/__tests__/border-renderer.test.ts +0 -24
  171. package/src/render/canvas/__tests__/effects-renderer.test.ts +0 -32
  172. package/src/render/canvas/__tests__/text-renderer.test.ts +0 -471
  173. package/src/render/canvas/background-renderer.ts +0 -271
  174. package/src/render/canvas/border-renderer.ts +0 -224
  175. package/src/render/canvas/canvas-path.ts +0 -31
  176. package/src/render/canvas/canvas-renderer.ts +0 -641
  177. package/src/render/canvas/effects-renderer.ts +0 -130
  178. package/src/render/canvas/foreignobject-renderer.ts +0 -53
  179. package/src/render/canvas/text-renderer.ts +0 -700
  180. package/src/render/effects.ts +0 -75
  181. package/src/render/font-metrics.ts +0 -72
  182. package/src/render/object-fit.ts +0 -100
  183. package/src/render/path.ts +0 -37
  184. package/src/render/renderer-interface.ts +0 -28
  185. package/src/render/stacking-context.ts +0 -386
  186. package/src/render/vector.ts +0 -19
@@ -1,298 +0,0 @@
1
- import { Bounds } from '../css/layout/bounds';
2
- import { BACKGROUND_ORIGIN } from '../css/property-descriptors/background-origin';
3
- import { ElementContainer } from '../dom/element-container';
4
- import { BACKGROUND_SIZE, BackgroundSizeInfo } from '../css/property-descriptors/background-size';
5
- import { Vector } from './vector';
6
- import { BACKGROUND_REPEAT } from '../css/property-descriptors/background-repeat';
7
- import { getAbsoluteValue, getAbsoluteValueForTuple, isLengthPercentage } from '../css/types/length-percentage';
8
- import { CSSValue, isIdentToken } from '../css/syntax/parser';
9
- import { contentBox, paddingBox } from './box-sizing';
10
- import { Path } from './path';
11
- import { BACKGROUND_CLIP } from '../css/property-descriptors/background-clip';
12
-
13
- export const calculateBackgroundPositioningArea = (
14
- backgroundOrigin: BACKGROUND_ORIGIN,
15
- element: ElementContainer
16
- ): Bounds => {
17
- if (backgroundOrigin === BACKGROUND_ORIGIN.BORDER_BOX) {
18
- return element.bounds;
19
- }
20
-
21
- if (backgroundOrigin === BACKGROUND_ORIGIN.CONTENT_BOX) {
22
- return contentBox(element);
23
- }
24
-
25
- return paddingBox(element);
26
- };
27
-
28
- export const calculateBackgroundPaintingArea = (backgroundClip: BACKGROUND_CLIP, element: ElementContainer): Bounds => {
29
- if (backgroundClip === BACKGROUND_CLIP.BORDER_BOX) {
30
- return element.bounds;
31
- }
32
-
33
- if (backgroundClip === BACKGROUND_CLIP.CONTENT_BOX) {
34
- return contentBox(element);
35
- }
36
-
37
- return paddingBox(element);
38
- };
39
-
40
- export const calculateBackgroundRendering = (
41
- container: ElementContainer,
42
- index: number,
43
- intrinsicSize: [number | null, number | null, number | null]
44
- ): [Path[], number, number, number, number] => {
45
- const backgroundPositioningArea = calculateBackgroundPositioningArea(
46
- getBackgroundValueForIndex(container.styles.backgroundOrigin, index),
47
- container
48
- );
49
-
50
- const backgroundPaintingArea = calculateBackgroundPaintingArea(
51
- getBackgroundValueForIndex(container.styles.backgroundClip, index),
52
- container
53
- );
54
-
55
- const backgroundImageSize = calculateBackgroundSize(
56
- getBackgroundValueForIndex(container.styles.backgroundSize, index),
57
- intrinsicSize,
58
- backgroundPositioningArea
59
- );
60
-
61
- let [sizeWidth, sizeHeight] = backgroundImageSize;
62
-
63
- const position = getAbsoluteValueForTuple(
64
- getBackgroundValueForIndex(container.styles.backgroundPosition, index),
65
- backgroundPositioningArea.width - sizeWidth,
66
- backgroundPositioningArea.height - sizeHeight
67
- );
68
-
69
- const path = calculateBackgroundRepeatPath(
70
- getBackgroundValueForIndex(container.styles.backgroundRepeat, index),
71
- position,
72
- backgroundImageSize,
73
- backgroundPositioningArea,
74
- backgroundPaintingArea
75
- );
76
-
77
- const offsetX = Math.round(backgroundPositioningArea.left + position[0]);
78
- const offsetY = Math.round(backgroundPositioningArea.top + position[1]);
79
-
80
- sizeWidth = Math.max(1, sizeWidth);
81
- sizeHeight = Math.max(1, sizeHeight);
82
-
83
- return [path, offsetX, offsetY, sizeWidth, sizeHeight];
84
- };
85
-
86
- export const isAuto = (token: CSSValue): boolean => isIdentToken(token) && token.value === BACKGROUND_SIZE.AUTO;
87
-
88
- const hasIntrinsicValue = (value: number | null): value is number => typeof value === 'number';
89
-
90
- export const calculateBackgroundSize = (
91
- size: BackgroundSizeInfo[],
92
- [intrinsicWidth, intrinsicHeight, intrinsicProportion]: [number | null, number | null, number | null],
93
- bounds: Bounds
94
- ): [number, number] => {
95
- const [first, second] = size;
96
-
97
- if (!first) {
98
- return [0, 0];
99
- }
100
-
101
- if (isLengthPercentage(first) && second && isLengthPercentage(second)) {
102
- return [getAbsoluteValue(first, bounds.width), getAbsoluteValue(second, bounds.height)];
103
- }
104
-
105
- const hasIntrinsicProportion = hasIntrinsicValue(intrinsicProportion);
106
-
107
- if (isIdentToken(first) && (first.value === BACKGROUND_SIZE.CONTAIN || first.value === BACKGROUND_SIZE.COVER)) {
108
- if (hasIntrinsicValue(intrinsicProportion)) {
109
- const targetRatio = bounds.width / bounds.height;
110
-
111
- return targetRatio < intrinsicProportion !== (first.value === BACKGROUND_SIZE.COVER)
112
- ? [bounds.width, bounds.width / intrinsicProportion]
113
- : [bounds.height * intrinsicProportion, bounds.height];
114
- }
115
-
116
- return [bounds.width, bounds.height];
117
- }
118
-
119
- const hasIntrinsicWidth = hasIntrinsicValue(intrinsicWidth);
120
- const hasIntrinsicHeight = hasIntrinsicValue(intrinsicHeight);
121
- const hasIntrinsicDimensions = hasIntrinsicWidth || hasIntrinsicHeight;
122
-
123
- // If the background-size is auto or auto auto:
124
- if (isAuto(first) && (!second || isAuto(second))) {
125
- // If the image has both horizontal and vertical intrinsic dimensions, it's rendered at that size.
126
- if (hasIntrinsicWidth && hasIntrinsicHeight) {
127
- return [intrinsicWidth as number, intrinsicHeight as number];
128
- }
129
-
130
- // If the image has no intrinsic dimensions and has no intrinsic proportions,
131
- // it's rendered at the size of the background positioning area.
132
-
133
- if (!hasIntrinsicProportion && !hasIntrinsicDimensions) {
134
- return [bounds.width, bounds.height];
135
- }
136
-
137
- // TODO If the image has no intrinsic dimensions but has intrinsic proportions, it's rendered as if contain had been specified instead.
138
-
139
- // If the image has only one intrinsic dimension and has intrinsic proportions, it's rendered at the size corresponding to that one dimension.
140
- // The other dimension is computed using the specified dimension and the intrinsic proportions.
141
- if (hasIntrinsicDimensions && hasIntrinsicProportion) {
142
- const width = hasIntrinsicWidth
143
- ? (intrinsicWidth as number)
144
- : (intrinsicHeight as number) * (intrinsicProportion as number);
145
- const height = hasIntrinsicHeight
146
- ? (intrinsicHeight as number)
147
- : (intrinsicWidth as number) / (intrinsicProportion as number);
148
- return [width, height];
149
- }
150
-
151
- // If the image has only one intrinsic dimension but has no intrinsic proportions,
152
- // it's rendered using the specified dimension and the other dimension of the background positioning area.
153
- const width = hasIntrinsicWidth ? (intrinsicWidth as number) : bounds.width;
154
- const height = hasIntrinsicHeight ? (intrinsicHeight as number) : bounds.height;
155
- return [width, height];
156
- }
157
-
158
- // If the image has intrinsic proportions, it's stretched to the specified dimension.
159
- // The unspecified dimension is computed using the specified dimension and the intrinsic proportions.
160
- if (hasIntrinsicProportion) {
161
- let width = 0;
162
- let height = 0;
163
- if (isLengthPercentage(first)) {
164
- width = getAbsoluteValue(first, bounds.width);
165
- } else if (isLengthPercentage(second)) {
166
- height = getAbsoluteValue(second, bounds.height);
167
- }
168
-
169
- if (isAuto(first)) {
170
- width = height * (intrinsicProportion as number);
171
- } else if (!second || isAuto(second)) {
172
- height = width / (intrinsicProportion as number);
173
- }
174
-
175
- return [width, height];
176
- }
177
-
178
- // If the image has no intrinsic proportions, it's stretched to the specified dimension.
179
- // The unspecified dimension is computed using the image's corresponding intrinsic dimension,
180
- // if there is one. If there is no such intrinsic dimension,
181
- // it becomes the corresponding dimension of the background positioning area.
182
-
183
- let width = null;
184
- let height = null;
185
-
186
- if (isLengthPercentage(first)) {
187
- width = getAbsoluteValue(first, bounds.width);
188
- } else if (second && isLengthPercentage(second)) {
189
- height = getAbsoluteValue(second, bounds.height);
190
- }
191
-
192
- if (width !== null && (!second || isAuto(second))) {
193
- height =
194
- hasIntrinsicWidth && hasIntrinsicHeight
195
- ? (width / (intrinsicWidth as number)) * (intrinsicHeight as number)
196
- : bounds.height;
197
- }
198
-
199
- if (height !== null && isAuto(first)) {
200
- width =
201
- hasIntrinsicWidth && hasIntrinsicHeight
202
- ? (height / (intrinsicHeight as number)) * (intrinsicWidth as number)
203
- : bounds.width;
204
- }
205
-
206
- if (width !== null && height !== null) {
207
- return [width, height];
208
- }
209
-
210
- throw new Error(`Unable to calculate background-size for element`);
211
- };
212
-
213
- export const getBackgroundValueForIndex = <T>(values: T[], index: number): T => {
214
- const value = values[index];
215
- if (typeof value === 'undefined') {
216
- return values[0];
217
- }
218
-
219
- return value;
220
- };
221
-
222
- export const calculateBackgroundRepeatPath = (
223
- repeat: BACKGROUND_REPEAT,
224
- [x, y]: [number, number],
225
- [width, height]: [number, number],
226
- backgroundPositioningArea: Bounds,
227
- backgroundPaintingArea: Bounds
228
- ): [Vector, Vector, Vector, Vector] => {
229
- switch (repeat) {
230
- case BACKGROUND_REPEAT.REPEAT_X:
231
- return [
232
- new Vector(Math.round(backgroundPositioningArea.left), Math.round(backgroundPositioningArea.top + y)),
233
- new Vector(
234
- Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width),
235
- Math.round(backgroundPositioningArea.top + y)
236
- ),
237
- new Vector(
238
- Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width),
239
- Math.round(height + backgroundPositioningArea.top + y)
240
- ),
241
- new Vector(
242
- Math.round(backgroundPositioningArea.left),
243
- Math.round(height + backgroundPositioningArea.top + y)
244
- )
245
- ];
246
- case BACKGROUND_REPEAT.REPEAT_Y:
247
- return [
248
- new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top)),
249
- new Vector(
250
- Math.round(backgroundPositioningArea.left + x + width),
251
- Math.round(backgroundPositioningArea.top)
252
- ),
253
- new Vector(
254
- Math.round(backgroundPositioningArea.left + x + width),
255
- Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top)
256
- ),
257
- new Vector(
258
- Math.round(backgroundPositioningArea.left + x),
259
- Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top)
260
- )
261
- ];
262
- case BACKGROUND_REPEAT.NO_REPEAT:
263
- return [
264
- new Vector(
265
- Math.round(backgroundPositioningArea.left + x),
266
- Math.round(backgroundPositioningArea.top + y)
267
- ),
268
- new Vector(
269
- Math.round(backgroundPositioningArea.left + x + width),
270
- Math.round(backgroundPositioningArea.top + y)
271
- ),
272
- new Vector(
273
- Math.round(backgroundPositioningArea.left + x + width),
274
- Math.round(backgroundPositioningArea.top + y + height)
275
- ),
276
- new Vector(
277
- Math.round(backgroundPositioningArea.left + x),
278
- Math.round(backgroundPositioningArea.top + y + height)
279
- )
280
- ];
281
- default:
282
- return [
283
- new Vector(Math.round(backgroundPaintingArea.left), Math.round(backgroundPaintingArea.top)),
284
- new Vector(
285
- Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width),
286
- Math.round(backgroundPaintingArea.top)
287
- ),
288
- new Vector(
289
- Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width),
290
- Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)
291
- ),
292
- new Vector(
293
- Math.round(backgroundPaintingArea.left),
294
- Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)
295
- )
296
- ];
297
- }
298
- };
@@ -1,47 +0,0 @@
1
- import { Vector } from './vector';
2
- import { IPath, PathType, Path } from './path';
3
-
4
- const lerp = (a: Vector, b: Vector, t: number): Vector => {
5
- return new Vector(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
6
- };
7
-
8
- export class BezierCurve implements IPath {
9
- type: PathType;
10
- start: Vector;
11
- startControl: Vector;
12
- endControl: Vector;
13
- end: Vector;
14
-
15
- constructor(start: Vector, startControl: Vector, endControl: Vector, end: Vector) {
16
- this.type = PathType.BEZIER_CURVE;
17
- this.start = start;
18
- this.startControl = startControl;
19
- this.endControl = endControl;
20
- this.end = end;
21
- }
22
-
23
- subdivide(t: number, firstHalf: boolean): BezierCurve {
24
- const ab = lerp(this.start, this.startControl, t);
25
- const bc = lerp(this.startControl, this.endControl, t);
26
- const cd = lerp(this.endControl, this.end, t);
27
- const abbc = lerp(ab, bc, t);
28
- const bccd = lerp(bc, cd, t);
29
- const dest = lerp(abbc, bccd, t);
30
- return firstHalf ? new BezierCurve(this.start, ab, abbc, dest) : new BezierCurve(dest, bccd, cd, this.end);
31
- }
32
-
33
- add(deltaX: number, deltaY: number): BezierCurve {
34
- return new BezierCurve(
35
- this.start.add(deltaX, deltaY),
36
- this.startControl.add(deltaX, deltaY),
37
- this.endControl.add(deltaX, deltaY),
38
- this.end.add(deltaX, deltaY)
39
- );
40
- }
41
-
42
- reverse(): BezierCurve {
43
- return new BezierCurve(this.end, this.endControl, this.startControl, this.start);
44
- }
45
- }
46
-
47
- export const isBezierCurve = (path: Path): path is BezierCurve => path.type === PathType.BEZIER_CURVE;
@@ -1,165 +0,0 @@
1
- import { Path } from './path';
2
- import { BoundCurves } from './bound-curves';
3
- import { isBezierCurve } from './bezier-curve';
4
-
5
- export const parsePathForBorder = (curves: BoundCurves, borderSide: number): Path[] => {
6
- switch (borderSide) {
7
- case 0:
8
- return createPathFromCurves(
9
- curves.topLeftBorderBox,
10
- curves.topLeftPaddingBox,
11
- curves.topRightBorderBox,
12
- curves.topRightPaddingBox
13
- );
14
- case 1:
15
- return createPathFromCurves(
16
- curves.topRightBorderBox,
17
- curves.topRightPaddingBox,
18
- curves.bottomRightBorderBox,
19
- curves.bottomRightPaddingBox
20
- );
21
- case 2:
22
- return createPathFromCurves(
23
- curves.bottomRightBorderBox,
24
- curves.bottomRightPaddingBox,
25
- curves.bottomLeftBorderBox,
26
- curves.bottomLeftPaddingBox
27
- );
28
- case 3:
29
- default:
30
- return createPathFromCurves(
31
- curves.bottomLeftBorderBox,
32
- curves.bottomLeftPaddingBox,
33
- curves.topLeftBorderBox,
34
- curves.topLeftPaddingBox
35
- );
36
- }
37
- };
38
-
39
- export const parsePathForBorderDoubleOuter = (curves: BoundCurves, borderSide: number): Path[] => {
40
- switch (borderSide) {
41
- case 0:
42
- return createPathFromCurves(
43
- curves.topLeftBorderBox,
44
- curves.topLeftBorderDoubleOuterBox,
45
- curves.topRightBorderBox,
46
- curves.topRightBorderDoubleOuterBox
47
- );
48
- case 1:
49
- return createPathFromCurves(
50
- curves.topRightBorderBox,
51
- curves.topRightBorderDoubleOuterBox,
52
- curves.bottomRightBorderBox,
53
- curves.bottomRightBorderDoubleOuterBox
54
- );
55
- case 2:
56
- return createPathFromCurves(
57
- curves.bottomRightBorderBox,
58
- curves.bottomRightBorderDoubleOuterBox,
59
- curves.bottomLeftBorderBox,
60
- curves.bottomLeftBorderDoubleOuterBox
61
- );
62
- case 3:
63
- default:
64
- return createPathFromCurves(
65
- curves.bottomLeftBorderBox,
66
- curves.bottomLeftBorderDoubleOuterBox,
67
- curves.topLeftBorderBox,
68
- curves.topLeftBorderDoubleOuterBox
69
- );
70
- }
71
- };
72
-
73
- export const parsePathForBorderDoubleInner = (curves: BoundCurves, borderSide: number): Path[] => {
74
- switch (borderSide) {
75
- case 0:
76
- return createPathFromCurves(
77
- curves.topLeftBorderDoubleInnerBox,
78
- curves.topLeftPaddingBox,
79
- curves.topRightBorderDoubleInnerBox,
80
- curves.topRightPaddingBox
81
- );
82
- case 1:
83
- return createPathFromCurves(
84
- curves.topRightBorderDoubleInnerBox,
85
- curves.topRightPaddingBox,
86
- curves.bottomRightBorderDoubleInnerBox,
87
- curves.bottomRightPaddingBox
88
- );
89
- case 2:
90
- return createPathFromCurves(
91
- curves.bottomRightBorderDoubleInnerBox,
92
- curves.bottomRightPaddingBox,
93
- curves.bottomLeftBorderDoubleInnerBox,
94
- curves.bottomLeftPaddingBox
95
- );
96
- case 3:
97
- default:
98
- return createPathFromCurves(
99
- curves.bottomLeftBorderDoubleInnerBox,
100
- curves.bottomLeftPaddingBox,
101
- curves.topLeftBorderDoubleInnerBox,
102
- curves.topLeftPaddingBox
103
- );
104
- }
105
- };
106
-
107
- export const parsePathForBorderStroke = (curves: BoundCurves, borderSide: number): Path[] => {
108
- switch (borderSide) {
109
- case 0:
110
- return createStrokePathFromCurves(curves.topLeftBorderStroke, curves.topRightBorderStroke);
111
- case 1:
112
- return createStrokePathFromCurves(curves.topRightBorderStroke, curves.bottomRightBorderStroke);
113
- case 2:
114
- return createStrokePathFromCurves(curves.bottomRightBorderStroke, curves.bottomLeftBorderStroke);
115
- case 3:
116
- default:
117
- return createStrokePathFromCurves(curves.bottomLeftBorderStroke, curves.topLeftBorderStroke);
118
- }
119
- };
120
-
121
- const createStrokePathFromCurves = (outer1: Path, outer2: Path): Path[] => {
122
- const path = [];
123
- if (isBezierCurve(outer1)) {
124
- path.push(outer1.subdivide(0.5, false));
125
- } else {
126
- path.push(outer1);
127
- }
128
-
129
- if (isBezierCurve(outer2)) {
130
- path.push(outer2.subdivide(0.5, true));
131
- } else {
132
- path.push(outer2);
133
- }
134
-
135
- return path;
136
- };
137
-
138
- const createPathFromCurves = (outer1: Path, inner1: Path, outer2: Path, inner2: Path): Path[] => {
139
- const path = [];
140
- if (isBezierCurve(outer1)) {
141
- path.push(outer1.subdivide(0.5, false));
142
- } else {
143
- path.push(outer1);
144
- }
145
-
146
- if (isBezierCurve(outer2)) {
147
- path.push(outer2.subdivide(0.5, true));
148
- } else {
149
- path.push(outer2);
150
- }
151
-
152
- if (isBezierCurve(inner2)) {
153
- path.push(inner2.subdivide(0.5, true).reverse());
154
- } else {
155
- path.push(inner2);
156
- }
157
-
158
- if (isBezierCurve(inner1)) {
159
- path.push(inner1.subdivide(0.5, false).reverse());
160
- } else {
161
- path.push(inner1);
162
- }
163
-
164
- return path;
165
- };