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.
- package/dist/html2canvas-pro.esm.js +21 -7
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +21 -7
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +3 -3
- package/dist/lib/core/cache-storage.js +2 -2
- package/dist/lib/core/features.js +2 -2
- package/dist/lib/render/canvas/background-renderer.js +6 -0
- package/dist/lib/render/canvas/canvas-renderer.js +5 -1
- package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
- package/package.json +3 -11
- package/dist/lib/invariant.js +0 -9
- package/dist/types/invariant.d.ts +0 -1
- package/src/__tests__/index.ts +0 -99
- package/src/config.ts +0 -107
- package/src/core/__mocks__/cache-storage.ts +0 -1
- package/src/core/__mocks__/context.ts +0 -19
- package/src/core/__mocks__/features.ts +0 -8
- package/src/core/__mocks__/logger.ts +0 -17
- package/src/core/__tests__/cache-storage.test.ts +0 -205
- package/src/core/__tests__/cache-storage.ts +0 -278
- package/src/core/__tests__/logger.ts +0 -29
- package/src/core/__tests__/validator.ts +0 -359
- package/src/core/bitwise.ts +0 -1
- package/src/core/cache-storage.ts +0 -315
- package/src/core/context.ts +0 -31
- package/src/core/debugger.ts +0 -32
- package/src/core/features.ts +0 -222
- package/src/core/logger.ts +0 -64
- package/src/core/origin-checker.ts +0 -57
- package/src/core/performance-monitor.ts +0 -241
- package/src/core/render-element.ts +0 -272
- package/src/core/util.ts +0 -1
- package/src/core/validator.ts +0 -593
- package/src/css/index.ts +0 -427
- package/src/css/layout/__mocks__/bounds.ts +0 -6
- package/src/css/layout/bounds.ts +0 -79
- package/src/css/layout/text.ts +0 -161
- package/src/css/property-descriptor.ts +0 -49
- package/src/css/property-descriptors/__tests__/background-tests.ts +0 -65
- package/src/css/property-descriptors/__tests__/clip-path.test.ts +0 -280
- package/src/css/property-descriptors/__tests__/font-family.ts +0 -25
- package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +0 -153
- package/src/css/property-descriptors/__tests__/image-rendering-performance.test.ts +0 -175
- package/src/css/property-descriptors/__tests__/image-rendering.test.ts +0 -72
- package/src/css/property-descriptors/__tests__/paint-order.ts +0 -87
- package/src/css/property-descriptors/__tests__/text-shadow.ts +0 -94
- package/src/css/property-descriptors/__tests__/transform-tests.ts +0 -18
- package/src/css/property-descriptors/background-clip.ts +0 -30
- package/src/css/property-descriptors/background-color.ts +0 -9
- package/src/css/property-descriptors/background-image.ts +0 -27
- package/src/css/property-descriptors/background-origin.ts +0 -31
- package/src/css/property-descriptors/background-position.ts +0 -38
- package/src/css/property-descriptors/background-repeat.ts +0 -44
- package/src/css/property-descriptors/background-size.ts +0 -27
- package/src/css/property-descriptors/border-color.ts +0 -13
- package/src/css/property-descriptors/border-radius.ts +0 -19
- package/src/css/property-descriptors/border-style.ts +0 -34
- package/src/css/property-descriptors/border-width.ts +0 -20
- package/src/css/property-descriptors/box-shadow.ts +0 -60
- package/src/css/property-descriptors/clip-path.ts +0 -271
- package/src/css/property-descriptors/color.ts +0 -9
- package/src/css/property-descriptors/content.ts +0 -26
- package/src/css/property-descriptors/counter-increment.ts +0 -43
- package/src/css/property-descriptors/counter-reset.ts +0 -36
- package/src/css/property-descriptors/direction.ts +0 -23
- package/src/css/property-descriptors/display.ts +0 -117
- package/src/css/property-descriptors/duration.ts +0 -14
- package/src/css/property-descriptors/float.ts +0 -29
- package/src/css/property-descriptors/font-family.ts +0 -38
- package/src/css/property-descriptors/font-size.ts +0 -9
- package/src/css/property-descriptors/font-style.ts +0 -25
- package/src/css/property-descriptors/font-variant.ts +0 -12
- package/src/css/property-descriptors/font-weight.ts +0 -26
- package/src/css/property-descriptors/image-rendering.ts +0 -33
- package/src/css/property-descriptors/letter-spacing.ts +0 -25
- package/src/css/property-descriptors/line-break.ts +0 -22
- package/src/css/property-descriptors/line-height.ts +0 -22
- package/src/css/property-descriptors/list-style-image.ts +0 -19
- package/src/css/property-descriptors/list-style-position.ts +0 -22
- package/src/css/property-descriptors/list-style-type.ts +0 -179
- package/src/css/property-descriptors/margin.ts +0 -13
- package/src/css/property-descriptors/mix-blend-mode.ts +0 -35
- package/src/css/property-descriptors/object-fit.ts +0 -39
- package/src/css/property-descriptors/opacity.ts +0 -15
- package/src/css/property-descriptors/overflow-wrap.ts +0 -22
- package/src/css/property-descriptors/overflow.ts +0 -34
- package/src/css/property-descriptors/padding.ts +0 -14
- package/src/css/property-descriptors/paint-order.ts +0 -42
- package/src/css/property-descriptors/position.ts +0 -30
- package/src/css/property-descriptors/quotes.ts +0 -57
- package/src/css/property-descriptors/rotate.ts +0 -34
- package/src/css/property-descriptors/text-align.ts +0 -26
- package/src/css/property-descriptors/text-decoration-color.ts +0 -9
- package/src/css/property-descriptors/text-decoration-line.ts +0 -38
- package/src/css/property-descriptors/text-decoration-style.ts +0 -32
- package/src/css/property-descriptors/text-decoration-thickness.ts +0 -30
- package/src/css/property-descriptors/text-overflow.ts +0 -23
- package/src/css/property-descriptors/text-shadow.ts +0 -52
- package/src/css/property-descriptors/text-transform.ts +0 -27
- package/src/css/property-descriptors/text-underline-offset.ts +0 -27
- package/src/css/property-descriptors/transform-origin.ts +0 -29
- package/src/css/property-descriptors/transform.ts +0 -74
- package/src/css/property-descriptors/visibility.ts +0 -25
- package/src/css/property-descriptors/webkit-line-clamp.ts +0 -30
- package/src/css/property-descriptors/webkit-text-stroke-color.ts +0 -8
- package/src/css/property-descriptors/webkit-text-stroke-width.ts +0 -15
- package/src/css/property-descriptors/word-break.ts +0 -25
- package/src/css/property-descriptors/writing-mode.ts +0 -37
- package/src/css/property-descriptors/z-index.ts +0 -27
- package/src/css/syntax/__tests__/tokernizer-tests.ts +0 -29
- package/src/css/syntax/parser.ts +0 -188
- package/src/css/syntax/tokenizer.ts +0 -822
- package/src/css/type-descriptor.ts +0 -7
- package/src/css/types/__tests__/color-tests.ts +0 -147
- package/src/css/types/__tests__/image-tests.ts +0 -239
- package/src/css/types/angle.ts +0 -86
- package/src/css/types/color-math.ts +0 -22
- package/src/css/types/color-spaces/a98.ts +0 -86
- package/src/css/types/color-spaces/p3.ts +0 -92
- package/src/css/types/color-spaces/pro-photo.ts +0 -87
- package/src/css/types/color-spaces/rec2020.ts +0 -90
- package/src/css/types/color-spaces/srgb.ts +0 -87
- package/src/css/types/color-utilities.ts +0 -452
- package/src/css/types/color.ts +0 -485
- package/src/css/types/functions/-prefix-linear-gradient.ts +0 -35
- package/src/css/types/functions/-prefix-radial-gradient.ts +0 -106
- package/src/css/types/functions/-webkit-gradient.ts +0 -69
- package/src/css/types/functions/__tests__/radial-gradient.ts +0 -69
- package/src/css/types/functions/counter.ts +0 -511
- package/src/css/types/functions/gradient.ts +0 -206
- package/src/css/types/functions/linear-gradient.ts +0 -28
- package/src/css/types/functions/radial-gradient.ts +0 -101
- package/src/css/types/image.ts +0 -120
- package/src/css/types/index.ts +0 -1
- package/src/css/types/length-percentage.ts +0 -137
- package/src/css/types/length.ts +0 -7
- package/src/css/types/time.ts +0 -20
- package/src/dom/__mocks__/document-cloner.ts +0 -22
- package/src/dom/__tests__/dom-normalizer.test.ts +0 -133
- package/src/dom/__tests__/element-container.test.ts +0 -129
- package/src/dom/document-cloner.ts +0 -929
- package/src/dom/dom-normalizer.ts +0 -133
- package/src/dom/element-container.ts +0 -75
- package/src/dom/elements/li-element-container.ts +0 -10
- package/src/dom/elements/ol-element-container.ts +0 -12
- package/src/dom/elements/select-element-container.ts +0 -10
- package/src/dom/elements/textarea-element-container.ts +0 -9
- package/src/dom/node-parser.ts +0 -177
- package/src/dom/node-type-guards.ts +0 -70
- package/src/dom/replaced-elements/canvas-element-container.ts +0 -15
- package/src/dom/replaced-elements/iframe-element-container.ts +0 -55
- package/src/dom/replaced-elements/image-element-container.ts +0 -16
- package/src/dom/replaced-elements/index.ts +0 -5
- package/src/dom/replaced-elements/input-element-container.ts +0 -105
- package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
- package/src/dom/replaced-elements/svg-element-container.ts +0 -23
- package/src/dom/text-container.ts +0 -42
- package/src/global.d.ts +0 -19
- package/src/index.ts +0 -82
- package/src/invariant.ts +0 -5
- package/src/options.ts +0 -55
- package/src/render/__tests__/object-fit.test.ts +0 -85
- package/src/render/background.ts +0 -298
- package/src/render/bezier-curve.ts +0 -47
- package/src/render/border.ts +0 -165
- package/src/render/bound-curves.ts +0 -388
- package/src/render/box-sizing.ts +0 -31
- package/src/render/canvas/__tests__/background-renderer.test.ts +0 -72
- package/src/render/canvas/__tests__/border-renderer.test.ts +0 -24
- package/src/render/canvas/__tests__/effects-renderer.test.ts +0 -32
- package/src/render/canvas/__tests__/text-renderer.test.ts +0 -471
- package/src/render/canvas/background-renderer.ts +0 -271
- package/src/render/canvas/border-renderer.ts +0 -224
- package/src/render/canvas/canvas-path.ts +0 -31
- package/src/render/canvas/canvas-renderer.ts +0 -641
- package/src/render/canvas/effects-renderer.ts +0 -130
- package/src/render/canvas/foreignobject-renderer.ts +0 -53
- package/src/render/canvas/text-renderer.ts +0 -700
- package/src/render/effects.ts +0 -75
- package/src/render/font-metrics.ts +0 -72
- package/src/render/object-fit.ts +0 -100
- package/src/render/path.ts +0 -37
- package/src/render/renderer-interface.ts +0 -28
- package/src/render/stacking-context.ts +0 -386
- package/src/render/vector.ts +0 -19
package/src/render/background.ts
DELETED
|
@@ -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;
|
package/src/render/border.ts
DELETED
|
@@ -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
|
-
};
|