html2canvas-pro 2.1.0 → 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.
- package/dist/html2canvas-pro.esm.js +10226 -10526
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +10869 -11171
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +8 -8
- package/dist/lib/config.js +0 -22
- package/dist/lib/core/cache-storage.js +3 -40
- package/dist/lib/core/constants.js +25 -0
- package/dist/lib/core/context.js +1 -0
- package/dist/lib/core/features.js +3 -2
- package/dist/lib/core/validator.js +3 -3
- package/dist/lib/css/grouped/background-styles.js +36 -0
- package/dist/lib/css/grouped/border-styles.js +75 -0
- package/dist/lib/css/grouped/font-styles.js +93 -0
- package/dist/lib/css/grouped/layout-styles.js +127 -0
- package/dist/lib/css/index.js +74 -46
- package/dist/lib/css/layout/text.js +7 -6
- package/dist/lib/css/property-descriptors/background-blend-mode.js +41 -0
- package/dist/lib/css/property-descriptors/border-image-repeat.js +42 -0
- package/dist/lib/css/property-descriptors/border-image-slice.js +45 -0
- package/dist/lib/css/property-descriptors/border-image-source.js +21 -0
- package/dist/lib/css/property-descriptors/border-radius.js +1 -1
- package/dist/lib/css/property-descriptors/box-decoration-break.js +18 -0
- package/dist/lib/css/property-descriptors/counter-increment.js +17 -12
- package/dist/lib/css/property-descriptors/counter-reset.js +4 -12
- package/dist/lib/css/property-descriptors/filter.js +76 -0
- package/dist/lib/css/property-descriptors/font-variant-ligatures.js +34 -0
- package/dist/lib/css/property-descriptors/object-fit.js +1 -1
- package/dist/lib/css/property-descriptors/object-position.js +42 -0
- package/dist/lib/css/property-descriptors/visibility.js +1 -1
- package/dist/lib/css/property-descriptors/zoom.js +18 -0
- package/dist/lib/css/syntax/parser.js +0 -1
- package/dist/lib/css/types/color.js +5 -1
- package/dist/lib/css/types/functions/repeating-linear-gradient.js +9 -0
- package/dist/lib/css/types/image.js +12 -2
- package/dist/lib/css/types/length-percentage.js +6 -2
- package/dist/lib/css/types/safe-eval.js +80 -0
- package/dist/lib/dom/document-cloner.js +23 -163
- package/dist/lib/dom/slot-cloner.js +176 -0
- package/dist/lib/index.js +1 -17
- package/dist/lib/render/canvas/background-renderer.js +169 -30
- package/dist/lib/render/canvas/border-image-renderer.js +153 -0
- package/dist/lib/render/canvas/canvas-renderer.js +39 -190
- package/dist/lib/render/canvas/content-renderer.js +202 -0
- package/dist/lib/render/canvas/effects-renderer.js +3 -0
- package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
- package/dist/lib/render/canvas/text/text-decoration-renderer.js +99 -0
- package/dist/lib/render/canvas/text-renderer.js +100 -224
- package/dist/lib/render/effects.js +38 -3
- package/dist/lib/render/object-fit.js +19 -15
- package/dist/lib/render/stacking-context.js +11 -0
- package/dist/types/config.d.ts +0 -10
- package/dist/types/core/cache-storage.d.ts +0 -24
- package/dist/types/core/constants.d.ts +22 -0
- package/dist/types/core/context.d.ts +3 -0
- package/dist/types/core/performance-monitor.d.ts +4 -4
- package/dist/types/core/validator.d.ts +6 -8
- package/dist/types/css/grouped/background-styles.d.ts +16 -0
- package/dist/types/css/grouped/border-styles.d.ts +31 -0
- package/dist/types/css/grouped/font-styles.d.ts +35 -0
- package/dist/types/css/grouped/layout-styles.d.ts +46 -0
- package/dist/types/css/index.d.ts +30 -0
- package/dist/types/css/property-descriptors/background-blend-mode.d.ts +23 -0
- package/dist/types/css/property-descriptors/border-image-repeat.d.ts +12 -0
- package/dist/types/css/property-descriptors/border-image-slice.d.ts +10 -0
- package/dist/types/css/property-descriptors/border-image-source.d.ts +4 -0
- package/dist/types/css/property-descriptors/box-decoration-break.d.ts +6 -0
- package/dist/types/css/property-descriptors/counter-increment.d.ts +3 -0
- package/dist/types/css/property-descriptors/filter.d.ts +3 -0
- package/dist/types/css/property-descriptors/font-variant-ligatures.d.ts +14 -0
- package/dist/types/css/property-descriptors/object-position.d.ts +4 -0
- package/dist/types/css/property-descriptors/zoom.d.ts +3 -0
- package/dist/types/css/types/functions/repeating-linear-gradient.d.ts +4 -0
- package/dist/types/css/types/image.d.ts +4 -2
- package/dist/types/css/types/safe-eval.d.ts +8 -0
- package/dist/types/dom/document-cloner.d.ts +3 -44
- package/dist/types/dom/slot-cloner.d.ts +66 -0
- package/dist/types/index.d.ts +3 -7
- package/dist/types/options.d.ts +11 -0
- package/dist/types/render/canvas/background-renderer.d.ts +23 -0
- package/dist/types/render/canvas/border-image-renderer.d.ts +18 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +1 -0
- package/dist/types/render/canvas/content-renderer.d.ts +44 -0
- package/dist/types/render/canvas/text/text-decoration-renderer.d.ts +18 -0
- package/dist/types/render/canvas/text-renderer.d.ts +12 -1
- package/dist/types/render/effects.d.ts +12 -2
- package/dist/types/render/object-fit.d.ts +2 -1
- package/dist/types/render/renderer-interface.d.ts +11 -9
- package/package.json +7 -20
- package/dist/lib/dom/replaced-elements/pseudo-elements.js +0 -0
- package/dist/lib/invariant.js +0 -9
- package/dist/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
- 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/effects.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Matrix } from '../css/property-descriptors/transform';
|
|
2
|
-
import { Path } from './path';
|
|
3
|
-
|
|
4
|
-
export const enum EffectType {
|
|
5
|
-
TRANSFORM = 0,
|
|
6
|
-
CLIP = 1,
|
|
7
|
-
OPACITY = 2,
|
|
8
|
-
CLIP_PATH = 3,
|
|
9
|
-
BLEND = 4
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const enum EffectTarget {
|
|
13
|
-
BACKGROUND_BORDERS = 1 << 1,
|
|
14
|
-
CONTENT = 1 << 2
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IElementEffect {
|
|
18
|
-
readonly type: EffectType;
|
|
19
|
-
readonly target: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class TransformEffect implements IElementEffect {
|
|
23
|
-
readonly type: EffectType = EffectType.TRANSFORM;
|
|
24
|
-
readonly target: number = EffectTarget.BACKGROUND_BORDERS | EffectTarget.CONTENT;
|
|
25
|
-
|
|
26
|
-
constructor(
|
|
27
|
-
readonly offsetX: number,
|
|
28
|
-
readonly offsetY: number,
|
|
29
|
-
readonly matrix: Matrix
|
|
30
|
-
) {}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class ClipEffect implements IElementEffect {
|
|
34
|
-
readonly type: EffectType = EffectType.CLIP;
|
|
35
|
-
|
|
36
|
-
constructor(
|
|
37
|
-
readonly path: Path[],
|
|
38
|
-
readonly target: EffectTarget
|
|
39
|
-
) {}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class OpacityEffect implements IElementEffect {
|
|
43
|
-
readonly type: EffectType = EffectType.OPACITY;
|
|
44
|
-
readonly target: number = EffectTarget.BACKGROUND_BORDERS | EffectTarget.CONTENT;
|
|
45
|
-
|
|
46
|
-
constructor(readonly opacity: number) {}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Clips the element and all its descendants to an arbitrary canvas-drawn shape.
|
|
51
|
-
* The `applyClip` callback is responsible for calling beginPath, the shape
|
|
52
|
-
* operations, and ctx.clip() — giving each shape type full control over how
|
|
53
|
-
* the path is constructed (arc, ellipse, lineTo, Path2D, etc.).
|
|
54
|
-
*/
|
|
55
|
-
export class ClipPathEffect implements IElementEffect {
|
|
56
|
-
readonly type: EffectType = EffectType.CLIP_PATH;
|
|
57
|
-
readonly target: number = EffectTarget.BACKGROUND_BORDERS | EffectTarget.CONTENT;
|
|
58
|
-
|
|
59
|
-
constructor(readonly applyClip: (ctx: CanvasRenderingContext2D) => void) {}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export class BlendEffect implements IElementEffect {
|
|
63
|
-
readonly type: EffectType = EffectType.BLEND;
|
|
64
|
-
readonly target: number = EffectTarget.BACKGROUND_BORDERS | EffectTarget.CONTENT;
|
|
65
|
-
|
|
66
|
-
constructor(readonly compositeOperation: GlobalCompositeOperation) {}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export const isTransformEffect = (effect: IElementEffect): effect is TransformEffect =>
|
|
70
|
-
effect.type === EffectType.TRANSFORM;
|
|
71
|
-
export const isClipEffect = (effect: IElementEffect): effect is ClipEffect => effect.type === EffectType.CLIP;
|
|
72
|
-
export const isOpacityEffect = (effect: IElementEffect): effect is OpacityEffect => effect.type === EffectType.OPACITY;
|
|
73
|
-
export const isClipPathEffect = (effect: IElementEffect): effect is ClipPathEffect =>
|
|
74
|
-
effect.type === EffectType.CLIP_PATH;
|
|
75
|
-
export const isBlendEffect = (effect: IElementEffect): effect is BlendEffect => effect.type === EffectType.BLEND;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { SMALL_IMAGE } from '../core/util';
|
|
2
|
-
export interface FontMetric {
|
|
3
|
-
baseline: number;
|
|
4
|
-
middle: number;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const SAMPLE_TEXT = 'Hidden Text';
|
|
8
|
-
|
|
9
|
-
export class FontMetrics {
|
|
10
|
-
private readonly _data: { [key: string]: FontMetric };
|
|
11
|
-
private readonly _document: Document;
|
|
12
|
-
|
|
13
|
-
constructor(document: Document) {
|
|
14
|
-
this._data = {};
|
|
15
|
-
this._document = document;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private parseMetrics(fontFamily: string, fontSize: string): FontMetric {
|
|
19
|
-
const container = this._document.createElement('div');
|
|
20
|
-
const img = this._document.createElement('img');
|
|
21
|
-
const span = this._document.createElement('span');
|
|
22
|
-
|
|
23
|
-
const body = this._document.body as HTMLBodyElement;
|
|
24
|
-
|
|
25
|
-
container.style.visibility = 'hidden';
|
|
26
|
-
container.style.fontFamily = fontFamily;
|
|
27
|
-
container.style.fontSize = fontSize;
|
|
28
|
-
container.style.margin = '0';
|
|
29
|
-
container.style.padding = '0';
|
|
30
|
-
container.style.whiteSpace = 'nowrap';
|
|
31
|
-
|
|
32
|
-
body.appendChild(container);
|
|
33
|
-
|
|
34
|
-
img.src = SMALL_IMAGE;
|
|
35
|
-
img.width = 1;
|
|
36
|
-
img.height = 1;
|
|
37
|
-
|
|
38
|
-
img.style.margin = '0';
|
|
39
|
-
img.style.padding = '0';
|
|
40
|
-
img.style.verticalAlign = 'baseline';
|
|
41
|
-
|
|
42
|
-
span.style.fontFamily = fontFamily;
|
|
43
|
-
span.style.fontSize = fontSize;
|
|
44
|
-
span.style.margin = '0';
|
|
45
|
-
span.style.padding = '0';
|
|
46
|
-
|
|
47
|
-
span.appendChild(this._document.createTextNode(SAMPLE_TEXT));
|
|
48
|
-
container.appendChild(span);
|
|
49
|
-
container.appendChild(img);
|
|
50
|
-
const baseline = img.offsetTop - span.offsetTop + 2;
|
|
51
|
-
|
|
52
|
-
container.removeChild(span);
|
|
53
|
-
container.appendChild(this._document.createTextNode(SAMPLE_TEXT));
|
|
54
|
-
|
|
55
|
-
container.style.lineHeight = 'normal';
|
|
56
|
-
img.style.verticalAlign = 'super';
|
|
57
|
-
|
|
58
|
-
const middle = img.offsetTop - container.offsetTop + 2;
|
|
59
|
-
|
|
60
|
-
body.removeChild(container);
|
|
61
|
-
|
|
62
|
-
return { baseline, middle };
|
|
63
|
-
}
|
|
64
|
-
getMetrics(fontFamily: string, fontSize: string): FontMetric {
|
|
65
|
-
const key = `${fontFamily} ${fontSize}`;
|
|
66
|
-
if (typeof this._data[key] === 'undefined') {
|
|
67
|
-
this._data[key] = this.parseMetrics(fontFamily, fontSize);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this._data[key];
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/render/object-fit.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { OBJECT_FIT, ObjectFit } from '../css/property-descriptors/object-fit';
|
|
2
|
-
|
|
3
|
-
export interface ObjectFitBox {
|
|
4
|
-
left: number;
|
|
5
|
-
top: number;
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface ObjectFitRendering {
|
|
11
|
-
sx: number;
|
|
12
|
-
sy: number;
|
|
13
|
-
sw: number;
|
|
14
|
-
sh: number;
|
|
15
|
-
dx: number;
|
|
16
|
-
dy: number;
|
|
17
|
-
dw: number;
|
|
18
|
-
dh: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const calculateObjectFitRendering = (
|
|
22
|
-
intrinsicWidth: number,
|
|
23
|
-
intrinsicHeight: number,
|
|
24
|
-
box: ObjectFitBox,
|
|
25
|
-
objectFit: ObjectFit
|
|
26
|
-
): ObjectFitRendering => {
|
|
27
|
-
let sx = 0;
|
|
28
|
-
let sy = 0;
|
|
29
|
-
let sw = intrinsicWidth;
|
|
30
|
-
let sh = intrinsicHeight;
|
|
31
|
-
let dx = box.left;
|
|
32
|
-
let dy = box.top;
|
|
33
|
-
let dw = box.width;
|
|
34
|
-
let dh = box.height;
|
|
35
|
-
|
|
36
|
-
const boxRatio = dw / dh;
|
|
37
|
-
const imgRatio = sw / sh;
|
|
38
|
-
|
|
39
|
-
if (objectFit === OBJECT_FIT.CONTAIN) {
|
|
40
|
-
if (imgRatio > boxRatio) {
|
|
41
|
-
dh = dw / imgRatio;
|
|
42
|
-
dy += (box.height - dh) / 2;
|
|
43
|
-
} else {
|
|
44
|
-
dw = dh * imgRatio;
|
|
45
|
-
dx += (box.width - dw) / 2;
|
|
46
|
-
}
|
|
47
|
-
} else if (objectFit === OBJECT_FIT.COVER) {
|
|
48
|
-
if (imgRatio > boxRatio) {
|
|
49
|
-
sw = sh * boxRatio;
|
|
50
|
-
sx += (intrinsicWidth - sw) / 2;
|
|
51
|
-
} else {
|
|
52
|
-
sh = sw / boxRatio;
|
|
53
|
-
sy += (intrinsicHeight - sh) / 2;
|
|
54
|
-
}
|
|
55
|
-
} else if (objectFit === OBJECT_FIT.NONE) {
|
|
56
|
-
if (sw > dw) {
|
|
57
|
-
sx += (sw - dw) / 2;
|
|
58
|
-
sw = dw;
|
|
59
|
-
} else {
|
|
60
|
-
dx += (dw - sw) / 2;
|
|
61
|
-
dw = sw;
|
|
62
|
-
}
|
|
63
|
-
if (sh > dh) {
|
|
64
|
-
sy += (sh - dh) / 2;
|
|
65
|
-
sh = dh;
|
|
66
|
-
} else {
|
|
67
|
-
dy += (dh - sh) / 2;
|
|
68
|
-
dh = sh;
|
|
69
|
-
}
|
|
70
|
-
} else if (objectFit === OBJECT_FIT.SCALE_DOWN) {
|
|
71
|
-
const containW = imgRatio > boxRatio ? dw : dh * imgRatio;
|
|
72
|
-
const noneW = sw > dw ? sw : dw;
|
|
73
|
-
if (containW < noneW) {
|
|
74
|
-
if (imgRatio > boxRatio) {
|
|
75
|
-
dh = dw / imgRatio;
|
|
76
|
-
dy += (box.height - dh) / 2;
|
|
77
|
-
} else {
|
|
78
|
-
dw = dh * imgRatio;
|
|
79
|
-
dx += (box.width - dw) / 2;
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
if (sw > dw) {
|
|
83
|
-
sx += (sw - dw) / 2;
|
|
84
|
-
sw = dw;
|
|
85
|
-
} else {
|
|
86
|
-
dx += (dw - sw) / 2;
|
|
87
|
-
dw = sw;
|
|
88
|
-
}
|
|
89
|
-
if (sh > dh) {
|
|
90
|
-
sy += (sh - dh) / 2;
|
|
91
|
-
sh = dh;
|
|
92
|
-
} else {
|
|
93
|
-
dy += (dh - sh) / 2;
|
|
94
|
-
dh = sh;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return { sx, sy, sw, sh, dx, dy, dw, dh };
|
|
100
|
-
};
|
package/src/render/path.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BezierCurve } from './bezier-curve';
|
|
2
|
-
import { Vector } from './vector';
|
|
3
|
-
export const enum PathType {
|
|
4
|
-
VECTOR = 0,
|
|
5
|
-
BEZIER_CURVE = 1
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface IPath {
|
|
9
|
-
type: PathType;
|
|
10
|
-
add(deltaX: number, deltaY: number): IPath;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const equalPath = (a: Path[], b: Path[]): boolean => {
|
|
14
|
-
if (a.length === b.length) {
|
|
15
|
-
return a.some((v, i) => v === b[i]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return false;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const transformPath = (path: Path[], deltaX: number, deltaY: number, deltaW: number, deltaH: number): Path[] => {
|
|
22
|
-
return path.map((point, index) => {
|
|
23
|
-
switch (index) {
|
|
24
|
-
case 0:
|
|
25
|
-
return point.add(deltaX, deltaY);
|
|
26
|
-
case 1:
|
|
27
|
-
return point.add(deltaX + deltaW, deltaY);
|
|
28
|
-
case 2:
|
|
29
|
-
return point.add(deltaX + deltaW, deltaY + deltaH);
|
|
30
|
-
case 3:
|
|
31
|
-
return point.add(deltaX, deltaY + deltaH);
|
|
32
|
-
}
|
|
33
|
-
return point;
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type Path = Vector | BezierCurve;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base interface for all specialized renderers
|
|
3
|
-
* Each renderer is responsible for rendering a specific aspect of an element
|
|
4
|
-
*/
|
|
5
|
-
export interface IRenderer {
|
|
6
|
-
/**
|
|
7
|
-
* Render the specified aspect of the element
|
|
8
|
-
*/
|
|
9
|
-
render(...args: any[]): void | Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Common dependencies required by renderers
|
|
14
|
-
*/
|
|
15
|
-
export interface RendererDependencies {
|
|
16
|
-
ctx: CanvasRenderingContext2D;
|
|
17
|
-
scale: number;
|
|
18
|
-
options: any; // Will be typed more specifically
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Performance tracking for renderers
|
|
23
|
-
*/
|
|
24
|
-
export interface RenderMetrics {
|
|
25
|
-
renderCount: number;
|
|
26
|
-
totalTime: number;
|
|
27
|
-
averageTime: number;
|
|
28
|
-
}
|