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
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { strictEqual } from 'assert';
|
|
2
|
-
import { color } from '../color';
|
|
3
|
-
import { asString, isTransparent, pack } from '../color-utilities';
|
|
4
|
-
import { Parser } from '../../syntax/parser';
|
|
5
|
-
import { Context } from '../../../core/context';
|
|
6
|
-
|
|
7
|
-
const parse = (value: string) => color.parse({} as Context, Parser.parseValue(value));
|
|
8
|
-
|
|
9
|
-
describe('types', () => {
|
|
10
|
-
describe('<color>', () => {
|
|
11
|
-
describe('parsing', () => {
|
|
12
|
-
it('#000', () => strictEqual(parse('#000'), pack(0, 0, 0, 1)));
|
|
13
|
-
it('#0000', () => strictEqual(parse('#0000'), pack(0, 0, 0, 0)));
|
|
14
|
-
it('#000f', () => strictEqual(parse('#000f'), pack(0, 0, 0, 1)));
|
|
15
|
-
it('#fff', () => strictEqual(parse('#fff'), pack(255, 255, 255, 1)));
|
|
16
|
-
it('#000000', () => strictEqual(parse('#000000'), pack(0, 0, 0, 1)));
|
|
17
|
-
it('#00000000', () => strictEqual(parse('#00000000'), pack(0, 0, 0, 0)));
|
|
18
|
-
it('#ffffff', () => strictEqual(parse('#ffffff'), pack(255, 255, 255, 1)));
|
|
19
|
-
it('#ffffffff', () => strictEqual(parse('#ffffffff'), pack(255, 255, 255, 1)));
|
|
20
|
-
it('#7FFFD4', () => strictEqual(parse('#7FFFD4'), pack(127, 255, 212, 1)));
|
|
21
|
-
it('#f0ffff', () => strictEqual(parse('#f0ffff'), pack(240, 255, 255, 1)));
|
|
22
|
-
it('transparent', () => strictEqual(parse('transparent'), pack(0, 0, 0, 0)));
|
|
23
|
-
it('bisque', () => strictEqual(parse('bisque'), pack(255, 228, 196, 1)));
|
|
24
|
-
it('BLUE', () => strictEqual(parse('BLUE'), pack(0, 0, 255, 1)));
|
|
25
|
-
it('rgb(1, 3, 5)', () => strictEqual(parse('rgb(1, 3, 5)'), pack(1, 3, 5, 1)));
|
|
26
|
-
it('rgb(0% 0% 0%)', () => strictEqual(parse('rgb(0% 0% 0%)'), pack(0, 0, 0, 1)));
|
|
27
|
-
it('rgb(50% 50% 50%)', () => strictEqual(parse('rgb(50% 50% 50%)'), pack(128, 128, 128, 1)));
|
|
28
|
-
it('rgba(50% 50% 50% 50%)', () => strictEqual(parse('rgba(50% 50% 50% 50%)'), pack(128, 128, 128, 0.5)));
|
|
29
|
-
it('rgb(100% 100% 100%)', () => strictEqual(parse('rgb(100% 100% 100%)'), pack(255, 255, 255, 1)));
|
|
30
|
-
it('rgb(222 111 50)', () => strictEqual(parse('rgb(222 111 50)'), pack(222, 111, 50, 1)));
|
|
31
|
-
it('rgba(200, 3, 5, 1)', () => strictEqual(parse('rgba(200, 3, 5, 1)'), pack(200, 3, 5, 1)));
|
|
32
|
-
it('rgba(222, 111, 50, 0.22)', () =>
|
|
33
|
-
strictEqual(parse('rgba(222, 111, 50, 0.22)'), pack(222, 111, 50, 0.22)));
|
|
34
|
-
it('rgba(222 111 50 0.123)', () => strictEqual(parse('rgba(222 111 50 0.123)'), pack(222, 111, 50, 0.123)));
|
|
35
|
-
it('hsl(270,60%,70%)', () => strictEqual(parse('hsl(270,60%,70%)'), parse('rgb(178,132,224)')));
|
|
36
|
-
it('hsl(270, 60%, 70%)', () => strictEqual(parse('hsl(270, 60%, 70%)'), parse('rgb(178,132,224)')));
|
|
37
|
-
it('hsl(270 60% 70%)', () => strictEqual(parse('hsl(270 60% 70%)'), parse('rgb(178,132,224)')));
|
|
38
|
-
it('hsl(270deg, 60%, 70%)', () => strictEqual(parse('hsl(270deg, 60%, 70%)'), parse('rgb(178,132,224)')));
|
|
39
|
-
it('hsl(4.71239rad, 60%, 70%)', () =>
|
|
40
|
-
strictEqual(parse('hsl(4.71239rad, 60%, 70%)'), parse('rgb(178,132,224)')));
|
|
41
|
-
it('hsl(.75turn, 60%, 70%)', () => strictEqual(parse('hsl(.75turn, 60%, 70%)'), parse('rgb(178,132,224)')));
|
|
42
|
-
it('hsla(.75turn, 60%, 70%, 50%)', () =>
|
|
43
|
-
strictEqual(parse('hsl(.75turn, 60%, 70%, 50%)'), parse('rgba(178,132,224, 0.5)')));
|
|
44
|
-
it('oklch(0.93 0.39 28deg)', () => strictEqual(parse('oklch(0.93 0.39 28deg)'), pack(255, 0, 23, 1)));
|
|
45
|
-
it('oklch(0.93 0.39 28)', () => strictEqual(parse('oklch(0.93 0.39 28)'), pack(255, 0, 23, 1)));
|
|
46
|
-
it('oklch(0.63 0.26 27.65)', () => strictEqual(parse('oklch(0.63 0.26 27.65)'), pack(255, 0, 20, 1)));
|
|
47
|
-
it('oklch(0.57 0.23 145.62)', () => strictEqual(parse('oklch(0.57 0.23 145.62)'), pack(0, 151, 0, 1)));
|
|
48
|
-
it('oklch(0.57 0.23 145.62 / 0.5)', () =>
|
|
49
|
-
strictEqual(parse('oklch(0.57 0.23 145.62 / 0.5)'), pack(0, 151, 0, 0.5)));
|
|
50
|
-
it('oklab(0.4 0.11 0.05)', () => strictEqual(parse('oklab(0.4 0.11 0.05)'), pack(124, 37, 37, 1)));
|
|
51
|
-
it('oklab(0.57 -0.19 0.13)', () => strictEqual(parse('oklab(0.57 -0.19 0.13)'), pack(0, 151, 0, 1)));
|
|
52
|
-
it('oklab(0.57 -0.19 0.13 / 50%)', () =>
|
|
53
|
-
strictEqual(parse('oklab(0.57 -0.19 0.13 / 50%)'), pack(0, 151, 0, 0.5)));
|
|
54
|
-
it('lab(53 -66.2 60.96)', () => strictEqual(parse('lab(53 -66.2 60.96)'), pack(0, 151, 0, 1)));
|
|
55
|
-
it('lab(63 -41.52 -25.36)', () => strictEqual(parse('lab(63 -41.52 -25.36)'), pack(0, 173, 196, 1)));
|
|
56
|
-
it('lab(63 -41.52 -25.36 / 0.5)', () =>
|
|
57
|
-
strictEqual(parse('lab(63 -41.52 -25.36 / 0.5)'), pack(0, 173, 196, 0.5)));
|
|
58
|
-
it('lch(29.2345% 44.2 27)', () => strictEqual(parse('lch(29.2345% 44.2 27)'), pack(125, 35, 41, 1)));
|
|
59
|
-
it('lch(52.2345% 72.2 56.2)', () => strictEqual(parse('lch(52.2345% 72.2 56.2)'), pack(198, 93, 6, 1)));
|
|
60
|
-
it('color(srgb 1 0 0)', () => strictEqual(parse('color(srgb 1 0 0)'), pack(255, 0, 0, 1)));
|
|
61
|
-
it('color(srgb 1 0 0 / .5)', () => strictEqual(parse('color(srgb 1 0 0 / .5)'), pack(255, 0, 0, 0.5)));
|
|
62
|
-
it('color(srgb 0.5 0 0.5)', () => strictEqual(parse('color(srgb 0.5 0 0.5)'), pack(128, 0, 128, 1)));
|
|
63
|
-
it('color(xyz 0.11 0.17 0.24)', () =>
|
|
64
|
-
strictEqual(parse('color(xyz 0.11 0.17 0.24)'), pack(0, 130, 131, 1)));
|
|
65
|
-
it('color(xyz-d65 0.11 0.17 0.24)', () =>
|
|
66
|
-
strictEqual(parse('color(xyz-d65 0.11 0.17 0.24)'), pack(0, 130, 131, 1)));
|
|
67
|
-
it('color(xyz-d50 0.11 0.17 0.24)', () =>
|
|
68
|
-
strictEqual(parse('color(xyz-d50 0.11 0.17 0.24)'), pack(0, 131, 150, 1)));
|
|
69
|
-
it('color(srgb-linear 0.23 0.59 0.13)', () =>
|
|
70
|
-
strictEqual(parse('color(srgb-linear 0.23 0.59 0.13)'), pack(132, 202, 101, 1)));
|
|
71
|
-
it('color(display-p3 0.47 0.47 0.47)', () =>
|
|
72
|
-
strictEqual(parse('color(display-p3 0.47 0.47 0.47)'), pack(120, 120, 120, 1)));
|
|
73
|
-
it('color(display-p3 1 1 1)', () => strictEqual(parse('color(display-p3 1 1 1)'), pack(255, 255, 255, 1)));
|
|
74
|
-
it('color(display-p3 -0.1 -0.1 -0.1) ', () =>
|
|
75
|
-
strictEqual(parse('color(display-p3 -0.1 -0.1 -0.1)'), pack(0, 0, 0, 1)));
|
|
76
|
-
it('color(display-p3 0.238 0.532 0.611)', () =>
|
|
77
|
-
strictEqual(parse('color(display-p3 0.238 0.532 0.611)'), pack(5, 138, 158, 1)));
|
|
78
|
-
it('color(display-p3 1 0 0)', () => strictEqual(parse('color(display-p3 1 0 0)'), pack(255, 0, 0, 1)));
|
|
79
|
-
it('color(display-p3 0 1 0)', () => strictEqual(parse('color(display-p3 0 1 0)'), pack(0, 255, 0, 1)));
|
|
80
|
-
it('color(display-p3 0 0 1)', () => strictEqual(parse('color(display-p3 0 0 1)'), pack(0, 0, 255, 1)));
|
|
81
|
-
it('color(a98-rgb 1 0.5 0)', () => strictEqual(parse('color(a98-rgb 1 0.5 0)'), pack(255, 129, 0, 1)));
|
|
82
|
-
it('color(a98-rgb 1 0.22548 0.9854)', () =>
|
|
83
|
-
strictEqual(parse('color(a98-rgb 1 0.22548 0.9854)'), pack(255, 55, 255, 1)));
|
|
84
|
-
it('color(prophoto-rgb 1 0.5 0)', () =>
|
|
85
|
-
strictEqual(parse('color(prophoto-rgb 1 0.5 0)'), pack(255, 99, 0, 1)));
|
|
86
|
-
it('color(rec2020 0.17 0.31 0.5)', () =>
|
|
87
|
-
strictEqual(parse('color(rec2020 0.17 0.31 0.5)'), pack(0, 97, 144, 1)));
|
|
88
|
-
it('color(rec2020 1 0 0)', () => strictEqual(parse('color(rec2020 1 0 0)'), pack(255, 0, 0, 1)));
|
|
89
|
-
it('color(rec2020 0 1 0)', () => strictEqual(parse('color(rec2020 0 1 0)'), pack(0, 255, 0, 1)));
|
|
90
|
-
it('color(rec2020 0 0 1)', () => strictEqual(parse('color(rec2020 0 0 1)'), pack(0, 0, 255, 1)));
|
|
91
|
-
it('color(from #0000FF srgb r g b)', () =>
|
|
92
|
-
strictEqual(parse('color(from #0000FF srgb r b g)'), pack(0, 255, 0, 1)));
|
|
93
|
-
it('color(from #0000FF srgb b 0 0)', () =>
|
|
94
|
-
strictEqual(parse('color(from #0000FF srgb b 0 0)'), pack(255, 0, 0, 1)));
|
|
95
|
-
it('color(from green srgb r g b)', () =>
|
|
96
|
-
strictEqual(parse('color(from green srgb r g b)'), pack(0, 128, 0, 1)));
|
|
97
|
-
it('color(from lime srgb r g b)', () =>
|
|
98
|
-
strictEqual(parse('color(from lime srgb r g b)'), pack(0, 255, 0, 1)));
|
|
99
|
-
it('color(from green srgb r calc(g * 2) b)', () =>
|
|
100
|
-
strictEqual(parse('color(from green srgb r calc(g * 2) b)'), pack(0, 255, 0, 1)));
|
|
101
|
-
it('color(from hsl(0 100% 50%) xyz x y z)', () =>
|
|
102
|
-
strictEqual(parse('color(from hsl(0 100% 50%) xyz x y z)'), pack(255, 0, 0, 1)));
|
|
103
|
-
it('color(from hsl(0 100% 50%) xyz 0.75 0.6554 0.1)', () =>
|
|
104
|
-
strictEqual(parse('color(from hsl(0 100% 50%) xyz 0.75 0.6554 0.1)'), pack(255, 189, 31, 1)));
|
|
105
|
-
it('color(from hsl(0 100% 50%) srgb 0.749938 0 0.609579)', () =>
|
|
106
|
-
strictEqual(parse('color(from hsl(0 100% 50%) srgb 0.749938 0 0.609579)'), pack(191, 0, 155, 1)));
|
|
107
|
-
it('color(from hsl(0 100% 50%) display-p3 r g b)', () =>
|
|
108
|
-
strictEqual(parse('color(from hsl(0 100% 50%) display-p3 r g b)'), pack(255, 0, 0, 1)));
|
|
109
|
-
it('color(from lab(52.14 -26.38 -20.37) display-p3 r g b)', () =>
|
|
110
|
-
strictEqual(parse('color(from lab(52.14 -26.38 -20.37) display-p3 r g b)'), pack(5, 138, 158, 1)));
|
|
111
|
-
it('color(from lab(52.14 -26.38 -20.37) display-p3 r g calc(r / 2))', () =>
|
|
112
|
-
strictEqual(
|
|
113
|
-
parse('color(from lab(52.14 -26.38 -20.37) display-p3 r g calc(r / 2))'),
|
|
114
|
-
pack(5, 138, 0, 1)
|
|
115
|
-
));
|
|
116
|
-
it('color(from lab(52.14 -26.38 -20.37) a98-rgb r g b)', () =>
|
|
117
|
-
strictEqual(parse('color(from lab(52.14 -26.38 -20.37) a98-rgb r g b)'), pack(5, 138, 158, 1)));
|
|
118
|
-
it('color(from hsl(0 100% 50%) prophoto-rgb r g b)', () =>
|
|
119
|
-
strictEqual(parse('color(from hsl(0 100% 50%) prophoto-rgb r g b)'), pack(255, 0, 0, 1)));
|
|
120
|
-
it('color(from hsl(0 100% 50%) prophoto-rgb calc(r / 2) g b)', () =>
|
|
121
|
-
strictEqual(parse('color(from hsl(0 100% 50%) prophoto-rgb calc(r / 2) g b)'), pack(132, 83, 11, 1)));
|
|
122
|
-
it('color(from lab(52.14 -26.38 -20.37) rec2020 r g b)', () =>
|
|
123
|
-
strictEqual(parse('color(from lab(52.14 -26.38 -20.37) rec2020 r g b)'), pack(5, 138, 158, 1)));
|
|
124
|
-
it('color(from hsl(0 100% 50%) rec2020 calc(r / 2) g 0)', () =>
|
|
125
|
-
strictEqual(parse('color(from hsl(0 100% 50%) rec2020 calc(r / 2) g 0)'), pack(135, 68, 0, 1)));
|
|
126
|
-
});
|
|
127
|
-
describe('util', () => {
|
|
128
|
-
describe('isTransparent', () => {
|
|
129
|
-
it('transparent', () => strictEqual(isTransparent(parse('transparent')), true));
|
|
130
|
-
it('#000', () => strictEqual(isTransparent(parse('#000')), false));
|
|
131
|
-
it('#000f', () => strictEqual(isTransparent(parse('#000f')), false));
|
|
132
|
-
it('#0001', () => strictEqual(isTransparent(parse('#0001')), false));
|
|
133
|
-
it('#0000', () => strictEqual(isTransparent(parse('#0000')), true));
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('toString', () => {
|
|
137
|
-
it('transparent', () => strictEqual(asString(parse('transparent')), 'rgba(0,0,0,0)'));
|
|
138
|
-
it('#000', () => strictEqual(asString(parse('#000')), 'rgb(0,0,0)'));
|
|
139
|
-
it('#000f', () => strictEqual(asString(parse('#000f')), 'rgb(0,0,0)'));
|
|
140
|
-
it('#000f', () => strictEqual(asString(parse('#000c')), 'rgba(0,0,0,0.8)'));
|
|
141
|
-
it('#fff', () => strictEqual(asString(parse('#fff')), 'rgb(255,255,255)'));
|
|
142
|
-
it('#ffff', () => strictEqual(asString(parse('#ffff')), 'rgb(255,255,255)'));
|
|
143
|
-
it('#fffc', () => strictEqual(asString(parse('#fffc')), 'rgba(255,255,255,0.8)'));
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { deepStrictEqual } from 'assert';
|
|
2
|
-
import { Parser } from '../../syntax/parser';
|
|
3
|
-
import { CSSImageType, image } from '../image';
|
|
4
|
-
import { color } from '../color';
|
|
5
|
-
import { pack } from '../color-utilities';
|
|
6
|
-
import { FLAG_INTEGER, TokenType } from '../../syntax/tokenizer';
|
|
7
|
-
import { deg } from '../angle';
|
|
8
|
-
|
|
9
|
-
const parse = (context: Context, value: string) => image.parse(context, Parser.parseValue(value));
|
|
10
|
-
const colorParse = (context: Context, value: string) => color.parse(context, Parser.parseValue(value));
|
|
11
|
-
|
|
12
|
-
vi.mock('../../../core/features');
|
|
13
|
-
|
|
14
|
-
vi.mock('../../../core/context');
|
|
15
|
-
import { Context } from '../../../core/context';
|
|
16
|
-
|
|
17
|
-
import { Html2CanvasConfig } from '../../../config';
|
|
18
|
-
|
|
19
|
-
describe('types', () => {
|
|
20
|
-
let context: Context;
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
const mockWindow = {
|
|
23
|
-
location: { href: 'http://example.com' },
|
|
24
|
-
document: { createElement: () => ({ href: '' }) }
|
|
25
|
-
} as any;
|
|
26
|
-
const config = new Html2CanvasConfig({ window: mockWindow });
|
|
27
|
-
context = new Context({} as any, {} as any, config);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('<image>', () => {
|
|
31
|
-
describe('parsing', () => {
|
|
32
|
-
describe('url', () => {
|
|
33
|
-
it('url(test.jpg)', () =>
|
|
34
|
-
deepStrictEqual(parse(context, 'url(http://example.com/test.jpg)'), {
|
|
35
|
-
url: 'http://example.com/test.jpg',
|
|
36
|
-
type: CSSImageType.URL
|
|
37
|
-
}));
|
|
38
|
-
it('url("test.jpg")', () =>
|
|
39
|
-
deepStrictEqual(parse(context, 'url("http://example.com/test.jpg")'), {
|
|
40
|
-
url: 'http://example.com/test.jpg',
|
|
41
|
-
type: CSSImageType.URL
|
|
42
|
-
}));
|
|
43
|
-
});
|
|
44
|
-
describe('linear-gradient', () => {
|
|
45
|
-
it('linear-gradient(#f69d3c, #3f87a6)', () =>
|
|
46
|
-
deepStrictEqual(parse(context, 'linear-gradient(#f69d3c, #3f87a6)'), {
|
|
47
|
-
angle: deg(180),
|
|
48
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
49
|
-
stops: [
|
|
50
|
-
{ color: pack(0xf6, 0x9d, 0x3c, 1), stop: null },
|
|
51
|
-
{ color: pack(0x3f, 0x87, 0xa6, 1), stop: null }
|
|
52
|
-
]
|
|
53
|
-
}));
|
|
54
|
-
it('linear-gradient(yellow, blue)', () =>
|
|
55
|
-
deepStrictEqual(parse(context, 'linear-gradient(yellow, blue)'), {
|
|
56
|
-
angle: deg(180),
|
|
57
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
58
|
-
stops: [
|
|
59
|
-
{ color: colorParse(context, 'yellow'), stop: null },
|
|
60
|
-
{ color: colorParse(context, 'blue'), stop: null }
|
|
61
|
-
]
|
|
62
|
-
}));
|
|
63
|
-
it('linear-gradient(to bottom, yellow, blue)', () =>
|
|
64
|
-
deepStrictEqual(parse(context, 'linear-gradient(to bottom, yellow, blue)'), {
|
|
65
|
-
angle: deg(180),
|
|
66
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
67
|
-
stops: [
|
|
68
|
-
{ color: colorParse(context, 'yellow'), stop: null },
|
|
69
|
-
{ color: colorParse(context, 'blue'), stop: null }
|
|
70
|
-
]
|
|
71
|
-
}));
|
|
72
|
-
it('linear-gradient(180deg, yellow, blue)', () =>
|
|
73
|
-
deepStrictEqual(parse(context, 'linear-gradient(180deg, yellow, blue)'), {
|
|
74
|
-
angle: deg(180),
|
|
75
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
76
|
-
stops: [
|
|
77
|
-
{ color: colorParse(context, 'yellow'), stop: null },
|
|
78
|
-
{ color: colorParse(context, 'blue'), stop: null }
|
|
79
|
-
]
|
|
80
|
-
}));
|
|
81
|
-
it('linear-gradient(to top, blue, yellow)', () =>
|
|
82
|
-
deepStrictEqual(parse(context, 'linear-gradient(to top, blue, yellow)'), {
|
|
83
|
-
angle: 0,
|
|
84
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
85
|
-
stops: [
|
|
86
|
-
{ color: colorParse(context, 'blue'), stop: null },
|
|
87
|
-
{ color: colorParse(context, 'yellow'), stop: null }
|
|
88
|
-
]
|
|
89
|
-
}));
|
|
90
|
-
it('linear-gradient(to top right, blue, yellow)', () =>
|
|
91
|
-
deepStrictEqual(parse(context, 'linear-gradient(to top right, blue, yellow)'), {
|
|
92
|
-
angle: [
|
|
93
|
-
{ type: TokenType.PERCENTAGE_TOKEN, number: 100, flags: 4 },
|
|
94
|
-
{ type: TokenType.NUMBER_TOKEN, number: 0, flags: 4 }
|
|
95
|
-
],
|
|
96
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
97
|
-
stops: [
|
|
98
|
-
{ color: colorParse(context, 'blue'), stop: null },
|
|
99
|
-
{ color: colorParse(context, 'yellow'), stop: null }
|
|
100
|
-
]
|
|
101
|
-
}));
|
|
102
|
-
it('linear-gradient(to bottom, yellow 0%, blue 100%)', () =>
|
|
103
|
-
deepStrictEqual(parse(context, 'linear-gradient(to bottom, yellow 0%, blue 100%)'), {
|
|
104
|
-
angle: deg(180),
|
|
105
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
106
|
-
stops: [
|
|
107
|
-
{
|
|
108
|
-
color: colorParse(context, 'yellow'),
|
|
109
|
-
stop: {
|
|
110
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
111
|
-
number: 0,
|
|
112
|
-
flags: FLAG_INTEGER
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
color: colorParse(context, 'blue'),
|
|
117
|
-
stop: {
|
|
118
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
119
|
-
number: 100,
|
|
120
|
-
flags: FLAG_INTEGER
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
]
|
|
124
|
-
}));
|
|
125
|
-
it('linear-gradient(to top left, lightpink, lightpink 5px, white 5px, white 10px)', () =>
|
|
126
|
-
deepStrictEqual(
|
|
127
|
-
parse(context, 'linear-gradient(to top left, lightpink, lightpink 5px, white 5px, white 10px)'),
|
|
128
|
-
{
|
|
129
|
-
angle: [
|
|
130
|
-
{ type: TokenType.PERCENTAGE_TOKEN, number: 100, flags: 4 },
|
|
131
|
-
{ type: TokenType.PERCENTAGE_TOKEN, number: 100, flags: 4 }
|
|
132
|
-
],
|
|
133
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
134
|
-
stops: [
|
|
135
|
-
{ color: colorParse(context, 'lightpink'), stop: null },
|
|
136
|
-
{
|
|
137
|
-
color: colorParse(context, 'lightpink'),
|
|
138
|
-
stop: {
|
|
139
|
-
type: TokenType.DIMENSION_TOKEN,
|
|
140
|
-
number: 5,
|
|
141
|
-
flags: FLAG_INTEGER,
|
|
142
|
-
unit: 'px'
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
color: colorParse(context, 'white'),
|
|
147
|
-
stop: {
|
|
148
|
-
type: TokenType.DIMENSION_TOKEN,
|
|
149
|
-
number: 5,
|
|
150
|
-
flags: FLAG_INTEGER,
|
|
151
|
-
unit: 'px'
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
color: colorParse(context, 'white'),
|
|
156
|
-
stop: {
|
|
157
|
-
type: TokenType.DIMENSION_TOKEN,
|
|
158
|
-
number: 10,
|
|
159
|
-
flags: FLAG_INTEGER,
|
|
160
|
-
unit: 'px'
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
]
|
|
164
|
-
}
|
|
165
|
-
));
|
|
166
|
-
});
|
|
167
|
-
describe('-prefix-linear-gradient', () => {
|
|
168
|
-
it('-webkit-linear-gradient(left, #cedbe9 0%, #aac5de 17%, #3a8bc2 84%, #26558b 100%)', () =>
|
|
169
|
-
deepStrictEqual(
|
|
170
|
-
parse(
|
|
171
|
-
context,
|
|
172
|
-
'-webkit-linear-gradient(left, #cedbe9 0%, #aac5de 17%, #3a8bc2 84%, #26558b 100%)'
|
|
173
|
-
),
|
|
174
|
-
{
|
|
175
|
-
angle: deg(90),
|
|
176
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
177
|
-
stops: [
|
|
178
|
-
{
|
|
179
|
-
color: colorParse(context, '#cedbe9'),
|
|
180
|
-
stop: {
|
|
181
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
182
|
-
number: 0,
|
|
183
|
-
flags: FLAG_INTEGER
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
color: colorParse(context, '#aac5de'),
|
|
188
|
-
stop: {
|
|
189
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
190
|
-
number: 17,
|
|
191
|
-
flags: FLAG_INTEGER
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
color: colorParse(context, '#3a8bc2'),
|
|
196
|
-
stop: {
|
|
197
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
198
|
-
number: 84,
|
|
199
|
-
flags: FLAG_INTEGER
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
color: colorParse(context, '#26558b'),
|
|
204
|
-
stop: {
|
|
205
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
206
|
-
number: 100,
|
|
207
|
-
flags: FLAG_INTEGER
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
]
|
|
211
|
-
}
|
|
212
|
-
));
|
|
213
|
-
it('-moz-linear-gradient(top, #cce5f4 0%, #00263c 100%)', () =>
|
|
214
|
-
deepStrictEqual(parse(context, '-moz-linear-gradient(top, #cce5f4 0%, #00263c 100%)'), {
|
|
215
|
-
angle: deg(180),
|
|
216
|
-
type: CSSImageType.LINEAR_GRADIENT,
|
|
217
|
-
stops: [
|
|
218
|
-
{
|
|
219
|
-
color: colorParse(context, '#cce5f4'),
|
|
220
|
-
stop: {
|
|
221
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
222
|
-
number: 0,
|
|
223
|
-
flags: FLAG_INTEGER
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
color: colorParse(context, '#00263c'),
|
|
228
|
-
stop: {
|
|
229
|
-
type: TokenType.PERCENTAGE_TOKEN,
|
|
230
|
-
number: 100,
|
|
231
|
-
flags: FLAG_INTEGER
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
]
|
|
235
|
-
}));
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
package/src/css/types/angle.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { CSSValue, isIdentToken } from '../syntax/parser';
|
|
2
|
-
import { TokenType } from '../syntax/tokenizer';
|
|
3
|
-
import { ITypeDescriptor } from '../type-descriptor';
|
|
4
|
-
import { HUNDRED_PERCENT, ZERO_LENGTH } from './length-percentage';
|
|
5
|
-
import { GradientCorner } from './image';
|
|
6
|
-
import { Context } from '../../core/context';
|
|
7
|
-
|
|
8
|
-
const DEG = 'deg';
|
|
9
|
-
const GRAD = 'grad';
|
|
10
|
-
const RAD = 'rad';
|
|
11
|
-
const TURN = 'turn';
|
|
12
|
-
|
|
13
|
-
export const angle: ITypeDescriptor<number> = {
|
|
14
|
-
name: 'angle',
|
|
15
|
-
parse: (_context: Context, value: CSSValue): number => {
|
|
16
|
-
if (value.type === TokenType.DIMENSION_TOKEN) {
|
|
17
|
-
switch (value.unit) {
|
|
18
|
-
case DEG:
|
|
19
|
-
return (Math.PI * value.number) / 180;
|
|
20
|
-
case GRAD:
|
|
21
|
-
return (Math.PI / 200) * value.number;
|
|
22
|
-
case RAD:
|
|
23
|
-
return value.number;
|
|
24
|
-
case TURN:
|
|
25
|
-
return Math.PI * 2 * value.number;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
throw new Error(`Unsupported angle type`);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const isAngle = (value: CSSValue): boolean => {
|
|
34
|
-
if (value.type === TokenType.DIMENSION_TOKEN) {
|
|
35
|
-
if (value.unit === DEG || value.unit === GRAD || value.unit === RAD || value.unit === TURN) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return false;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const parseNamedSide = (tokens: CSSValue[]): number | GradientCorner => {
|
|
43
|
-
const sideOrCorner = tokens
|
|
44
|
-
.filter(isIdentToken)
|
|
45
|
-
.map((ident) => ident.value)
|
|
46
|
-
.join(' ');
|
|
47
|
-
|
|
48
|
-
switch (sideOrCorner) {
|
|
49
|
-
case 'to bottom right':
|
|
50
|
-
case 'to right bottom':
|
|
51
|
-
case 'left top':
|
|
52
|
-
case 'top left':
|
|
53
|
-
return [ZERO_LENGTH, ZERO_LENGTH];
|
|
54
|
-
case 'to top':
|
|
55
|
-
case 'bottom':
|
|
56
|
-
return deg(0);
|
|
57
|
-
case 'to bottom left':
|
|
58
|
-
case 'to left bottom':
|
|
59
|
-
case 'right top':
|
|
60
|
-
case 'top right':
|
|
61
|
-
return [ZERO_LENGTH, HUNDRED_PERCENT];
|
|
62
|
-
case 'to right':
|
|
63
|
-
case 'left':
|
|
64
|
-
return deg(90);
|
|
65
|
-
case 'to top left':
|
|
66
|
-
case 'to left top':
|
|
67
|
-
case 'right bottom':
|
|
68
|
-
case 'bottom right':
|
|
69
|
-
return [HUNDRED_PERCENT, HUNDRED_PERCENT];
|
|
70
|
-
case 'to bottom':
|
|
71
|
-
case 'top':
|
|
72
|
-
return deg(180);
|
|
73
|
-
case 'to top right':
|
|
74
|
-
case 'to right top':
|
|
75
|
-
case 'left bottom':
|
|
76
|
-
case 'bottom left':
|
|
77
|
-
return [HUNDRED_PERCENT, ZERO_LENGTH];
|
|
78
|
-
case 'to left':
|
|
79
|
-
case 'right':
|
|
80
|
-
return deg(270);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return 0;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const deg = (deg: number): number => (Math.PI * deg) / 180;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Color mathematics utilities
|
|
3
|
-
* Extracted to break circular dependency between srgb.ts and color-utilities.ts
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clamp a value between min and max
|
|
8
|
-
*/
|
|
9
|
-
export const clamp = (value: number, min: number, max: number): number => {
|
|
10
|
-
return Math.min(Math.max(value, min), max);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Multiply two 3x3 matrices
|
|
15
|
-
*/
|
|
16
|
-
export const multiplyMatrices = (A: number[], B: number[]): [number, number, number] => {
|
|
17
|
-
return [
|
|
18
|
-
A[0] * B[0] + A[1] * B[1] + A[2] * B[2],
|
|
19
|
-
A[3] * B[0] + A[4] * B[1] + A[5] * B[2],
|
|
20
|
-
A[6] * B[0] + A[7] * B[1] + A[8] * B[2]
|
|
21
|
-
];
|
|
22
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A98-RGB related functions
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { multiplyMatrices, packSrgbLinear } from '../color-utilities';
|
|
6
|
-
import { xyz2rgbLinear } from './srgb';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Convert XYZ to a98 linear
|
|
10
|
-
*
|
|
11
|
-
* @param xyz
|
|
12
|
-
*/
|
|
13
|
-
export const xyz2a98Linear = (xyz: [number, number, number]): [number, number, number] => {
|
|
14
|
-
return multiplyMatrices(
|
|
15
|
-
[
|
|
16
|
-
2.0415879038107465, -0.5650069742788596, -0.34473135077832956, -0.9692436362808795, 1.8759675015077202,
|
|
17
|
-
0.04155505740717557, 0.013444280632031142, -0.11836239223101838, 1.0151749943912054
|
|
18
|
-
],
|
|
19
|
-
xyz
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Convert XYZ to a98 linear
|
|
25
|
-
*
|
|
26
|
-
* @param a98
|
|
27
|
-
*/
|
|
28
|
-
export const a98Linear2xyz = (a98: [number, number, number]): [number, number, number] => {
|
|
29
|
-
return multiplyMatrices(
|
|
30
|
-
[
|
|
31
|
-
0.5766690429101305, 0.1855582379065463, 0.1882286462349947, 0.29734497525053605, 0.6273635662554661,
|
|
32
|
-
0.0752914584939978, 0.02703136138641234, 0.07068885253582723, 0.9913375368376388
|
|
33
|
-
],
|
|
34
|
-
a98
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Convert A98 RGB to rgb linear
|
|
40
|
-
*
|
|
41
|
-
* @param rgb
|
|
42
|
-
*/
|
|
43
|
-
export const a982a98Linear = (rgb: [number, number, number]): [number, number, number] => {
|
|
44
|
-
const mapped = rgb.map((c: number) => {
|
|
45
|
-
const sign = c < 0 ? -1 : 1,
|
|
46
|
-
abs = Math.abs(c);
|
|
47
|
-
return sign * abs ** (563 / 256);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return [mapped[0], mapped[1], mapped[2]];
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Convert A98 RGB Linear to A98
|
|
55
|
-
*
|
|
56
|
-
* @param rgb
|
|
57
|
-
*/
|
|
58
|
-
export const a98Linear2a98 = (rgb: [number, number, number]): [number, number, number] => {
|
|
59
|
-
const mapped = rgb.map((c: number) => {
|
|
60
|
-
const sign = c < 0 ? -1 : 1,
|
|
61
|
-
abs = Math.abs(c);
|
|
62
|
-
return sign * abs ** (256 / 563);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return [mapped[0], mapped[1], mapped[2]];
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Convert XYZ to A98
|
|
70
|
-
*
|
|
71
|
-
* @param args
|
|
72
|
-
*/
|
|
73
|
-
export const a98FromXYZ = (args: [number, number, number, number]): [number, number, number, number] => {
|
|
74
|
-
const [r, g, b] = a98Linear2a98(xyz2a98Linear([args[0], args[1], args[2]]));
|
|
75
|
-
return [r, g, b, args[3]];
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Convert A98 to XYZ and Pack
|
|
80
|
-
*
|
|
81
|
-
* @param args
|
|
82
|
-
*/
|
|
83
|
-
export const convertA98rgb = (args: number[]): number => {
|
|
84
|
-
const srgb_linear = xyz2rgbLinear(a98Linear2xyz(a982a98Linear([args[0], args[1], args[2]])));
|
|
85
|
-
return packSrgbLinear([srgb_linear[0], srgb_linear[1], srgb_linear[2], args[3]]);
|
|
86
|
-
};
|