html2canvas-pro 1.6.7 → 2.0.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/README.md +1 -0
- package/demo/image-smoothing-demo.html +256 -0
- package/demo/refactoring-test.html +602 -0
- package/dist/html2canvas-pro.esm.js +3391 -1491
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +3394 -1490
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +5 -4
- package/dist/lib/__tests__/index.js +8 -2
- package/dist/lib/__tests__/index.js.map +1 -1
- package/dist/lib/config.js +72 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/core/__tests__/cache-storage.js +6 -3
- package/dist/lib/core/__tests__/cache-storage.js.map +1 -1
- package/dist/lib/core/__tests__/cache-storage.test.js +158 -0
- package/dist/lib/core/__tests__/cache-storage.test.js.map +1 -0
- package/dist/lib/core/__tests__/validator.js +296 -0
- package/dist/lib/core/__tests__/validator.js.map +1 -0
- package/dist/lib/core/cache-storage.js +130 -11
- package/dist/lib/core/cache-storage.js.map +1 -1
- package/dist/lib/core/context.js +5 -2
- package/dist/lib/core/context.js.map +1 -1
- package/dist/lib/core/debugger.js +3 -0
- package/dist/lib/core/debugger.js.map +1 -1
- package/dist/lib/core/origin-checker.js +54 -0
- package/dist/lib/core/origin-checker.js.map +1 -0
- package/dist/lib/core/performance-monitor.js +208 -0
- package/dist/lib/core/performance-monitor.js.map +1 -0
- package/dist/lib/core/validator.js +501 -0
- package/dist/lib/core/validator.js.map +1 -0
- package/dist/lib/css/index.js +4 -0
- package/dist/lib/css/index.js.map +1 -1
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js +7 -1
- package/dist/lib/css/property-descriptors/__tests__/background-tests.js.map +1 -1
- package/dist/lib/css/property-descriptors/__tests__/clip-path.test.js +273 -0
- package/dist/lib/css/property-descriptors/__tests__/clip-path.test.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-integration.test.js +142 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-integration.test.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-performance.test.js +167 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering-performance.test.js.map +1 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering.test.js +61 -0
- package/dist/lib/css/property-descriptors/__tests__/image-rendering.test.js.map +1 -0
- package/dist/lib/css/property-descriptors/clip-path.js +190 -0
- package/dist/lib/css/property-descriptors/clip-path.js.map +1 -0
- package/dist/lib/css/property-descriptors/image-rendering.js +34 -0
- package/dist/lib/css/property-descriptors/image-rendering.js.map +1 -0
- package/dist/lib/css/types/__tests__/image-tests.js +7 -1
- package/dist/lib/css/types/__tests__/image-tests.js.map +1 -1
- package/dist/lib/css/types/color-math.js +26 -0
- package/dist/lib/css/types/color-math.js.map +1 -0
- package/dist/lib/css/types/color-spaces/srgb.js +6 -6
- package/dist/lib/css/types/color-spaces/srgb.js.map +1 -1
- package/dist/lib/css/types/color-utilities.js +13 -22
- package/dist/lib/css/types/color-utilities.js.map +1 -1
- package/dist/lib/dom/__tests__/dom-normalizer.test.js +113 -0
- package/dist/lib/dom/__tests__/dom-normalizer.test.js.map +1 -0
- package/dist/lib/dom/__tests__/element-container.test.js +109 -0
- package/dist/lib/dom/__tests__/element-container.test.js.map +1 -0
- package/dist/lib/dom/document-cloner.js +3 -3
- package/dist/lib/dom/document-cloner.js.map +1 -1
- package/dist/lib/dom/dom-normalizer.js +116 -0
- package/dist/lib/dom/dom-normalizer.js.map +1 -0
- package/dist/lib/dom/element-container.js +32 -15
- package/dist/lib/dom/element-container.js.map +1 -1
- package/dist/lib/dom/node-parser.js +16 -20
- package/dist/lib/dom/node-parser.js.map +1 -1
- package/dist/lib/dom/node-type-guards.js +44 -0
- package/dist/lib/dom/node-type-guards.js.map +1 -0
- package/dist/lib/dom/replaced-elements/iframe-element-container.js +5 -4
- package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +1 -1
- package/dist/lib/index.js +148 -41
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/render/canvas/__tests__/background-renderer.test.js +65 -0
- package/dist/lib/render/canvas/__tests__/background-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/__tests__/border-renderer.test.js +23 -0
- package/dist/lib/render/canvas/__tests__/border-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/__tests__/effects-renderer.test.js +30 -0
- package/dist/lib/render/canvas/__tests__/effects-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/__tests__/text-renderer.test.js +310 -0
- package/dist/lib/render/canvas/__tests__/text-renderer.test.js.map +1 -0
- package/dist/lib/render/canvas/background-renderer.js +222 -0
- package/dist/lib/render/canvas/background-renderer.js.map +1 -0
- package/dist/lib/render/canvas/border-renderer.js +185 -0
- package/dist/lib/render/canvas/border-renderer.js.map +1 -0
- package/dist/lib/render/canvas/canvas-renderer.js +61 -689
- package/dist/lib/render/canvas/canvas-renderer.js.map +1 -1
- package/dist/lib/render/canvas/effects-renderer.js +94 -0
- package/dist/lib/render/canvas/effects-renderer.js.map +1 -0
- package/dist/lib/render/canvas/text-renderer.js +575 -0
- package/dist/lib/render/canvas/text-renderer.js.map +1 -0
- package/dist/lib/render/effects.js +17 -1
- package/dist/lib/render/effects.js.map +1 -1
- package/dist/lib/render/renderer-interface.js +3 -0
- package/dist/lib/render/renderer-interface.js.map +1 -0
- package/dist/lib/render/stacking-context.js +131 -0
- package/dist/lib/render/stacking-context.js.map +1 -1
- package/dist/types/config.d.ts +54 -0
- package/dist/types/core/__tests__/cache-storage.test.d.ts +1 -0
- package/dist/types/core/__tests__/validator.d.ts +1 -0
- package/dist/types/core/cache-storage.d.ts +42 -1
- package/dist/types/core/context.d.ts +5 -1
- package/dist/types/core/origin-checker.d.ts +33 -0
- package/dist/types/core/performance-monitor.d.ts +131 -0
- package/dist/types/core/validator.d.ts +132 -0
- package/dist/types/css/index.d.ts +4 -0
- package/dist/types/css/property-descriptors/__tests__/clip-path.test.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/image-rendering-integration.test.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/image-rendering-performance.test.d.ts +1 -0
- package/dist/types/css/property-descriptors/__tests__/image-rendering.test.d.ts +1 -0
- package/dist/types/css/property-descriptors/clip-path.d.ts +62 -0
- package/dist/types/css/property-descriptors/image-rendering.d.ts +8 -0
- package/dist/types/css/types/color-math.d.ts +12 -0
- package/dist/types/css/types/color-utilities.d.ts +2 -3
- package/dist/types/dom/__tests__/dom-normalizer.test.d.ts +1 -0
- package/dist/types/dom/__tests__/element-container.test.d.ts +1 -0
- package/dist/types/dom/dom-normalizer.d.ts +62 -0
- package/dist/types/dom/element-container.d.ts +20 -1
- package/dist/types/dom/node-parser.d.ts +2 -7
- package/dist/types/dom/node-type-guards.d.ts +33 -0
- package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +4 -1
- package/dist/types/index.d.ts +48 -3
- package/dist/types/render/canvas/__tests__/background-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/__tests__/border-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/__tests__/effects-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/__tests__/text-renderer.test.d.ts +1 -0
- package/dist/types/render/canvas/background-renderer.d.ts +87 -0
- package/dist/types/render/canvas/border-renderer.d.ts +67 -0
- package/dist/types/render/canvas/canvas-renderer.d.ts +19 -23
- package/dist/types/render/canvas/effects-renderer.d.ts +65 -0
- package/dist/types/render/canvas/text-renderer.d.ts +75 -0
- package/dist/types/render/effects.d.ts +15 -1
- package/dist/types/render/renderer-interface.d.ts +26 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-renderer.test.js","sourceRoot":"","sources":["../../../../../src/render/canvas/__tests__/background-renderer.test.ts"],"names":[],"mappings":";;AAAA,mCAA4B;AAC5B,gEAA4F;AAC5F,mDAAgD;AAChD,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ACH,OAAO;YACP,MAAM;YACN,OAAO,EAAE;gBACL,KAAK,EAAE,GAAG;gBACV,MAAM,EAAE,GAAG;gBACX,KAAK,EAAE,CAAC;aACX;SACJ,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,wCAAkB,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAA,WAAE,EAAC,QAAQ,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const assert_1 = require("assert");
|
|
4
|
+
const border_renderer_1 = require("../border-renderer");
|
|
5
|
+
describe('BorderRenderer', () => {
|
|
6
|
+
it('should be instantiated', () => {
|
|
7
|
+
const ctx = {
|
|
8
|
+
strokeStyle: '',
|
|
9
|
+
save: () => { },
|
|
10
|
+
restore: () => { }
|
|
11
|
+
};
|
|
12
|
+
const deps = {
|
|
13
|
+
ctx
|
|
14
|
+
};
|
|
15
|
+
const pathCallbacks = {
|
|
16
|
+
path: () => { },
|
|
17
|
+
formatPath: () => { }
|
|
18
|
+
};
|
|
19
|
+
const renderer = new border_renderer_1.BorderRenderer(deps, pathCallbacks);
|
|
20
|
+
(0, assert_1.ok)(renderer);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=border-renderer.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"border-renderer.test.js","sourceRoot":"","sources":["../../../../../src/render/canvas/__tests__/border-renderer.test.ts"],"names":[],"mappings":";;AAAA,mCAA4B;AAC5B,wDAA+F;AAE/F,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAC9B,MAAM,GAAG,GAAG;YACR,WAAW,EAAE,EAAE;YACf,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;YACd,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;SACmB,CAAC;QAEzC,MAAM,IAAI,GAA+B;YACrC,GAAG;SACN,CAAC;QAEF,MAAM,aAAa,GAAkB;YACjC,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;YACd,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;SACvB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,gCAAc,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACzD,IAAA,WAAE,EAAC,QAAQ,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const assert_1 = require("assert");
|
|
4
|
+
const effects_renderer_1 = require("../effects-renderer");
|
|
5
|
+
describe('EffectsRenderer', () => {
|
|
6
|
+
it('should be instantiated', () => {
|
|
7
|
+
const ctx = {
|
|
8
|
+
shadowOffsetX: 0,
|
|
9
|
+
shadowOffsetY: 0,
|
|
10
|
+
shadowBlur: 0,
|
|
11
|
+
shadowColor: '',
|
|
12
|
+
globalAlpha: 1,
|
|
13
|
+
save: () => { },
|
|
14
|
+
restore: () => { }
|
|
15
|
+
};
|
|
16
|
+
const deps = {
|
|
17
|
+
ctx
|
|
18
|
+
};
|
|
19
|
+
const pathCallback = {
|
|
20
|
+
path: () => { }
|
|
21
|
+
};
|
|
22
|
+
const renderer = new effects_renderer_1.EffectsRenderer(deps, pathCallback);
|
|
23
|
+
(0, assert_1.ok)(renderer);
|
|
24
|
+
// Test public methods exist
|
|
25
|
+
(0, assert_1.strictEqual)(typeof renderer.applyEffects, 'function');
|
|
26
|
+
(0, assert_1.strictEqual)(typeof renderer.applyEffect, 'function');
|
|
27
|
+
(0, assert_1.strictEqual)(typeof renderer.popEffect, 'function');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=effects-renderer.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects-renderer.test.js","sourceRoot":"","sources":["../../../../../src/render/canvas/__tests__/effects-renderer.test.ts"],"names":[],"mappings":";;AAAA,mCAAyC;AACzC,0DAAwG;AAExG,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAC9B,MAAM,GAAG,GAAG;YACR,aAAa,EAAE,CAAC;YAChB,aAAa,EAAE,CAAC;YAChB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,EAAE;YACf,WAAW,EAAE,CAAC;YACd,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;YACd,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;SACmB,CAAC;QAEzC,MAAM,IAAI,GAAgC;YACtC,GAAG;SACN,CAAC;QAEF,MAAM,YAAY,GAAwB;YACtC,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;SACjB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,kCAAe,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACzD,IAAA,WAAE,EAAC,QAAQ,CAAC,CAAC;QAEb,4BAA4B;QAC5B,IAAA,oBAAW,EAAC,OAAO,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QACtD,IAAA,oBAAW,EAAC,OAAO,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACrD,IAAA,oBAAW,EAAC,OAAO,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const assert_1 = require("assert");
|
|
4
|
+
const text_renderer_1 = require("../text-renderer");
|
|
5
|
+
const context_1 = require("../../../core/context");
|
|
6
|
+
const bounds_1 = require("../../../css/layout/bounds");
|
|
7
|
+
const text_1 = require("../../../css/layout/text");
|
|
8
|
+
const config_1 = require("../../../config");
|
|
9
|
+
const createMockContext = () => {
|
|
10
|
+
const mockWindow = {
|
|
11
|
+
document: {
|
|
12
|
+
createElement: (_name) => {
|
|
13
|
+
let _href = '';
|
|
14
|
+
return {
|
|
15
|
+
set href(value) {
|
|
16
|
+
_href = value;
|
|
17
|
+
},
|
|
18
|
+
get href() {
|
|
19
|
+
return _href;
|
|
20
|
+
},
|
|
21
|
+
get protocol() {
|
|
22
|
+
return 'http:';
|
|
23
|
+
},
|
|
24
|
+
get hostname() {
|
|
25
|
+
return 'localhost';
|
|
26
|
+
},
|
|
27
|
+
get port() {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
location: { href: 'http://localhost/' }
|
|
34
|
+
};
|
|
35
|
+
const config = new config_1.Html2CanvasConfig({ window: mockWindow });
|
|
36
|
+
return new context_1.Context({
|
|
37
|
+
logging: false,
|
|
38
|
+
imageTimeout: 15000,
|
|
39
|
+
useCORS: false,
|
|
40
|
+
allowTaint: false
|
|
41
|
+
}, new bounds_1.Bounds(0, 0, 800, 600), config);
|
|
42
|
+
};
|
|
43
|
+
describe('TextRenderer', () => {
|
|
44
|
+
it('should be instantiated', () => {
|
|
45
|
+
const ctx = {
|
|
46
|
+
fillStyle: '',
|
|
47
|
+
font: '',
|
|
48
|
+
save: () => { },
|
|
49
|
+
restore: () => { }
|
|
50
|
+
};
|
|
51
|
+
const deps = {
|
|
52
|
+
ctx,
|
|
53
|
+
context: createMockContext(),
|
|
54
|
+
options: { scale: 1 }
|
|
55
|
+
};
|
|
56
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
57
|
+
(0, assert_1.ok)(renderer);
|
|
58
|
+
// Test public methods exist
|
|
59
|
+
(0, assert_1.strictEqual)(typeof renderer.renderTextNode, 'function');
|
|
60
|
+
(0, assert_1.strictEqual)(typeof renderer.renderTextWithLetterSpacing, 'function');
|
|
61
|
+
(0, assert_1.strictEqual)(typeof renderer.createFontStyle, 'function');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('hasCJKCharacters', () => {
|
|
65
|
+
it('should return true for Chinese characters', () => {
|
|
66
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('快照'), true);
|
|
67
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('截图'), true);
|
|
68
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('中文'), true);
|
|
69
|
+
});
|
|
70
|
+
it('should return true for Japanese characters', () => {
|
|
71
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('ひらがな'), true); // Hiragana
|
|
72
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('カタカナ'), true); // Katakana
|
|
73
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('漢字'), true); // Kanji
|
|
74
|
+
});
|
|
75
|
+
it('should return true for Korean characters', () => {
|
|
76
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('한글'), true);
|
|
77
|
+
});
|
|
78
|
+
it('should return true for CJK punctuation and symbols', () => {
|
|
79
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('。'), true); // CJK full stop (U+3002)
|
|
80
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('、'), true); // CJK comma (U+3001)
|
|
81
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('「」'), true); // CJK brackets
|
|
82
|
+
});
|
|
83
|
+
it('should return true for fullwidth characters (U+FF01–U+FFEF)', () => {
|
|
84
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('!'), true); // Fullwidth ! (U+FF01, range start)
|
|
85
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('A'), true); // Fullwidth A (U+FF21)
|
|
86
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('1'), true); // Fullwidth 1 (U+FF11)
|
|
87
|
+
});
|
|
88
|
+
it('should return false for Latin characters', () => {
|
|
89
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('Hello'), false);
|
|
90
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('SOS'), false);
|
|
91
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('abc123'), false);
|
|
92
|
+
});
|
|
93
|
+
it('should return false for empty string', () => {
|
|
94
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)(''), false);
|
|
95
|
+
});
|
|
96
|
+
it('should return true for mixed text containing CJK', () => {
|
|
97
|
+
(0, assert_1.strictEqual)((0, text_renderer_1.hasCJKCharacters)('SOS 快照'), true);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe('renderTextWithLetterSpacing', () => {
|
|
101
|
+
it('should apply letterSpacing to each character x position (Issue #73 Bug1)', () => {
|
|
102
|
+
const fillCalls = [];
|
|
103
|
+
const measureResults = { A: 10, B: 12, C: 8 };
|
|
104
|
+
const ctx = {
|
|
105
|
+
fillStyle: '',
|
|
106
|
+
font: '',
|
|
107
|
+
textBaseline: 'alphabetic',
|
|
108
|
+
fillText(text, x, y) {
|
|
109
|
+
fillCalls.push({ text, x, y });
|
|
110
|
+
},
|
|
111
|
+
measureText(text) {
|
|
112
|
+
return { width: measureResults[text] ?? 10 };
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const deps = {
|
|
116
|
+
ctx,
|
|
117
|
+
context: createMockContext(),
|
|
118
|
+
options: { scale: 1 }
|
|
119
|
+
};
|
|
120
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
121
|
+
const bounds = new bounds_1.Bounds(100, 50, 200, 25);
|
|
122
|
+
const text = new text_1.TextBounds('ABC', bounds);
|
|
123
|
+
const letterSpacing = 5;
|
|
124
|
+
const baseline = 20;
|
|
125
|
+
renderer.renderTextWithLetterSpacing(text, letterSpacing, baseline);
|
|
126
|
+
// Verify letter spacing is added between characters
|
|
127
|
+
// A: x=100, B: x=100+10+5=115, C: x=115+12+5=132
|
|
128
|
+
(0, assert_1.strictEqual)(fillCalls.length, 3);
|
|
129
|
+
(0, assert_1.strictEqual)(fillCalls[0].text, 'A');
|
|
130
|
+
(0, assert_1.strictEqual)(fillCalls[0].x, 100);
|
|
131
|
+
(0, assert_1.strictEqual)(fillCalls[1].text, 'B');
|
|
132
|
+
(0, assert_1.strictEqual)(fillCalls[1].x, 115); // 100 + measureText('A').width(10) + letterSpacing(5)
|
|
133
|
+
(0, assert_1.strictEqual)(fillCalls[2].text, 'C');
|
|
134
|
+
(0, assert_1.strictEqual)(fillCalls[2].x, 132); // 115 + measureText('B').width(12) + letterSpacing(5)
|
|
135
|
+
// Verify y position uses baseline
|
|
136
|
+
fillCalls.forEach((call) => {
|
|
137
|
+
(0, assert_1.strictEqual)(call.y, bounds.top + baseline); // 50 + 20 = 70
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
it('should use ideographic baseline for CJK characters (Issue #73 Bug2)', () => {
|
|
141
|
+
const baselineChanges = [];
|
|
142
|
+
let currentBaseline = 'alphabetic';
|
|
143
|
+
const ctx = {
|
|
144
|
+
fillStyle: '',
|
|
145
|
+
font: '',
|
|
146
|
+
get textBaseline() {
|
|
147
|
+
return currentBaseline;
|
|
148
|
+
},
|
|
149
|
+
set textBaseline(value) {
|
|
150
|
+
currentBaseline = value;
|
|
151
|
+
baselineChanges.push(value);
|
|
152
|
+
},
|
|
153
|
+
fillText(_text, _x, _y) { },
|
|
154
|
+
measureText(_text) {
|
|
155
|
+
return { width: 25 };
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const deps = {
|
|
159
|
+
ctx,
|
|
160
|
+
context: createMockContext(),
|
|
161
|
+
options: { scale: 1 }
|
|
162
|
+
};
|
|
163
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
164
|
+
const bounds = new bounds_1.Bounds(0, 0, 100, 25);
|
|
165
|
+
const text = new text_1.TextBounds('快照', bounds);
|
|
166
|
+
renderer.renderTextWithLetterSpacing(text, 10, 20);
|
|
167
|
+
// Should have switched to ideographic for each CJK char and restored
|
|
168
|
+
// Pattern: [ideographic, alphabetic, ideographic, alphabetic]
|
|
169
|
+
(0, assert_1.ok)(baselineChanges.includes('ideographic'), 'should switch to ideographic baseline for CJK');
|
|
170
|
+
// Should restore alphabetic after each CJK char
|
|
171
|
+
const ideographicIdx = baselineChanges.indexOf('ideographic');
|
|
172
|
+
(0, assert_1.strictEqual)(baselineChanges[ideographicIdx + 1], 'alphabetic');
|
|
173
|
+
});
|
|
174
|
+
it('should not change textBaseline for non-CJK characters', () => {
|
|
175
|
+
const baselineChanges = [];
|
|
176
|
+
let currentBaseline = 'alphabetic';
|
|
177
|
+
const ctx = {
|
|
178
|
+
fillStyle: '',
|
|
179
|
+
font: '',
|
|
180
|
+
get textBaseline() {
|
|
181
|
+
return currentBaseline;
|
|
182
|
+
},
|
|
183
|
+
set textBaseline(value) {
|
|
184
|
+
currentBaseline = value;
|
|
185
|
+
baselineChanges.push(value);
|
|
186
|
+
},
|
|
187
|
+
fillText(_text, _x, _y) { },
|
|
188
|
+
measureText(_text) {
|
|
189
|
+
return { width: 10 };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const deps = {
|
|
193
|
+
ctx,
|
|
194
|
+
context: createMockContext(),
|
|
195
|
+
options: { scale: 1 }
|
|
196
|
+
};
|
|
197
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
198
|
+
const bounds = new bounds_1.Bounds(0, 0, 100, 25);
|
|
199
|
+
const text = new text_1.TextBounds('ABC', bounds);
|
|
200
|
+
renderer.renderTextWithLetterSpacing(text, 5, 20);
|
|
201
|
+
// Should not switch to ideographic for Latin characters
|
|
202
|
+
(0, assert_1.ok)(!baselineChanges.includes('ideographic'), 'should not switch to ideographic for Latin text');
|
|
203
|
+
});
|
|
204
|
+
it('should render whole string in one call when letterSpacing is 0', () => {
|
|
205
|
+
const fillCalls = [];
|
|
206
|
+
const ctx = {
|
|
207
|
+
fillStyle: '',
|
|
208
|
+
font: '',
|
|
209
|
+
textBaseline: 'alphabetic',
|
|
210
|
+
fillText(text, x, y) {
|
|
211
|
+
fillCalls.push({ text, x, y });
|
|
212
|
+
},
|
|
213
|
+
measureText(_text) {
|
|
214
|
+
return { width: 30 };
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const deps = {
|
|
218
|
+
ctx,
|
|
219
|
+
context: createMockContext(),
|
|
220
|
+
options: { scale: 1 }
|
|
221
|
+
};
|
|
222
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
223
|
+
const bounds = new bounds_1.Bounds(10, 20, 100, 25);
|
|
224
|
+
const text = new text_1.TextBounds('Hello', bounds);
|
|
225
|
+
renderer.renderTextWithLetterSpacing(text, 0, 22);
|
|
226
|
+
(0, assert_1.deepStrictEqual)(fillCalls, [{ text: 'Hello', x: 10, y: 42 }]);
|
|
227
|
+
});
|
|
228
|
+
it('should handle negative letterSpacing correctly', () => {
|
|
229
|
+
const fillCalls = [];
|
|
230
|
+
const ctx = {
|
|
231
|
+
fillStyle: '',
|
|
232
|
+
font: '',
|
|
233
|
+
textBaseline: 'alphabetic',
|
|
234
|
+
fillText(text, x, _y) {
|
|
235
|
+
fillCalls.push({ text, x });
|
|
236
|
+
},
|
|
237
|
+
measureText(_text) {
|
|
238
|
+
return { width: 10 };
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const deps = {
|
|
242
|
+
ctx,
|
|
243
|
+
context: createMockContext(),
|
|
244
|
+
options: { scale: 1 }
|
|
245
|
+
};
|
|
246
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
247
|
+
const bounds = new bounds_1.Bounds(100, 0, 50, 20);
|
|
248
|
+
const text = new text_1.TextBounds('AB', bounds);
|
|
249
|
+
renderer.renderTextWithLetterSpacing(text, -3, 15);
|
|
250
|
+
// A: x=100, B: x=100 + 10 + (-3) = 107
|
|
251
|
+
(0, assert_1.strictEqual)(fillCalls[0].x, 100);
|
|
252
|
+
(0, assert_1.strictEqual)(fillCalls[1].x, 107);
|
|
253
|
+
});
|
|
254
|
+
it('should handle mixed CJK and Latin text with correct baseline per character', () => {
|
|
255
|
+
const baselineAtRender = {};
|
|
256
|
+
let currentBaseline = 'alphabetic';
|
|
257
|
+
const ctx = {
|
|
258
|
+
fillStyle: '',
|
|
259
|
+
font: '',
|
|
260
|
+
get textBaseline() {
|
|
261
|
+
return currentBaseline;
|
|
262
|
+
},
|
|
263
|
+
set textBaseline(value) {
|
|
264
|
+
currentBaseline = value;
|
|
265
|
+
},
|
|
266
|
+
fillText(text, _x, _y) {
|
|
267
|
+
baselineAtRender[text] = currentBaseline;
|
|
268
|
+
},
|
|
269
|
+
measureText(_text) {
|
|
270
|
+
return { width: 12 };
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const deps = {
|
|
274
|
+
ctx,
|
|
275
|
+
context: createMockContext(),
|
|
276
|
+
options: { scale: 1 }
|
|
277
|
+
};
|
|
278
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
279
|
+
const bounds = new bounds_1.Bounds(0, 0, 200, 25);
|
|
280
|
+
// Mixed: Latin 'A', CJK '快', Latin 'B'
|
|
281
|
+
const text = new text_1.TextBounds('A快B', bounds);
|
|
282
|
+
renderer.renderTextWithLetterSpacing(text, 5, 20);
|
|
283
|
+
(0, assert_1.strictEqual)(baselineAtRender['A'], 'alphabetic', 'Latin char should use alphabetic baseline');
|
|
284
|
+
(0, assert_1.strictEqual)(baselineAtRender['快'], 'ideographic', 'CJK char should use ideographic baseline');
|
|
285
|
+
(0, assert_1.strictEqual)(baselineAtRender['B'], 'alphabetic', 'Latin char after CJK should restore alphabetic baseline');
|
|
286
|
+
});
|
|
287
|
+
it('should handle empty string without errors', () => {
|
|
288
|
+
const ctx = {
|
|
289
|
+
fillStyle: '',
|
|
290
|
+
font: '',
|
|
291
|
+
textBaseline: 'alphabetic',
|
|
292
|
+
fillText(_text, _x, _y) { },
|
|
293
|
+
measureText(_text) {
|
|
294
|
+
return { width: 0 };
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const deps = {
|
|
298
|
+
ctx,
|
|
299
|
+
context: createMockContext(),
|
|
300
|
+
options: { scale: 1 }
|
|
301
|
+
};
|
|
302
|
+
const renderer = new text_renderer_1.TextRenderer(deps);
|
|
303
|
+
const bounds = new bounds_1.Bounds(0, 0, 100, 25);
|
|
304
|
+
const text = new text_1.TextBounds('', bounds);
|
|
305
|
+
// Should not throw
|
|
306
|
+
renderer.renderTextWithLetterSpacing(text, 5, 20);
|
|
307
|
+
renderer.renderTextWithLetterSpacing(text, 0, 20);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
//# sourceMappingURL=text-renderer.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-renderer.test.js","sourceRoot":"","sources":["../../../../../src/render/canvas/__tests__/text-renderer.test.ts"],"names":[],"mappings":";;AAAA,mCAA0D;AAC1D,oDAA4F;AAC5F,mDAAgD;AAChD,uDAAoD;AACpD,mDAAsD;AACtD,4CAAoD;AAEpD,MAAM,iBAAiB,GAAG,GAAY,EAAE;IACpC,MAAM,UAAU,GAAG;QACf,QAAQ,EAAE;YACN,aAAa,EAAE,CAAC,KAAa,EAAE,EAAE;gBAC7B,IAAI,KAAK,GAAG,EAAE,CAAC;gBACf,OAAO;oBACH,IAAI,IAAI,CAAC,KAAa;wBAClB,KAAK,GAAG,KAAK,CAAC;oBAClB,CAAC;oBACD,IAAI,IAAI;wBACJ,OAAO,KAAK,CAAC;oBACjB,CAAC;oBACD,IAAI,QAAQ;wBACR,OAAO,OAAO,CAAC;oBACnB,CAAC;oBACD,IAAI,QAAQ;wBACR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GAAG,CAAC,EAAE,aAAa,EAAE,0CAA0C,CAAC,CAAC;QAC9F,IAAA,oBAAW,EAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,yDAAyD,CAAC,CAAC;IAChH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACjD,MAAM,GAAG,GAAG;YACR,SAAS,EAAE,EAAE;YACb,IAAI,EAAE,EAAE;YACR,YAAY,EAAE,YAAkC;YAChD,QAAQ,CAAC,KAAa,EAAE,EAAU,EAAE,EAAU,IAAG,CAAC;YAClD,WAAW,CAAC,KAAa;gBACrB,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;YACxB,CAAC;SACmC,CAAC;QAEzC,MAAM,IAAI,GAA6B;YACnC,GAAG;YACH,OAAO,EAAE,iBAAiB,EAAE;YAC5B,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;SACxB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,IAAI,iBAAU,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAExC,mBAAmB;QACnB,QAAQ,CAAC,2BAA2B,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAClD,QAAQ,CAAC,2BAA2B,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Background Renderer
|
|
4
|
+
*
|
|
5
|
+
* Handles rendering of element backgrounds including:
|
|
6
|
+
* - Background colors
|
|
7
|
+
* - Background images (URL)
|
|
8
|
+
* - Linear gradients
|
|
9
|
+
* - Radial gradients
|
|
10
|
+
* - Background patterns and repeats
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.BackgroundRenderer = void 0;
|
|
14
|
+
const image_1 = require("../../css/types/image");
|
|
15
|
+
const background_1 = require("../background");
|
|
16
|
+
const gradient_1 = require("../../css/types/functions/gradient");
|
|
17
|
+
const length_percentage_1 = require("../../css/types/length-percentage");
|
|
18
|
+
const color_utilities_1 = require("../../css/types/color-utilities");
|
|
19
|
+
const bezier_curve_1 = require("../bezier-curve");
|
|
20
|
+
const image_rendering_1 = require("../../css/property-descriptors/image-rendering");
|
|
21
|
+
/**
|
|
22
|
+
* Background Renderer
|
|
23
|
+
*
|
|
24
|
+
* Specialized renderer for element backgrounds.
|
|
25
|
+
* Extracted from CanvasRenderer to improve code organization and maintainability.
|
|
26
|
+
*/
|
|
27
|
+
class BackgroundRenderer {
|
|
28
|
+
constructor(deps) {
|
|
29
|
+
this.ctx = deps.ctx;
|
|
30
|
+
this.context = deps.context;
|
|
31
|
+
this.canvas = deps.canvas;
|
|
32
|
+
// Options stored in deps but not needed as instance property
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Render background images for a container
|
|
36
|
+
* Supports URL images, linear gradients, and radial gradients
|
|
37
|
+
*
|
|
38
|
+
* @param container - Element container with background styles
|
|
39
|
+
*/
|
|
40
|
+
async renderBackgroundImage(container) {
|
|
41
|
+
let index = container.styles.backgroundImage.length - 1;
|
|
42
|
+
for (const backgroundImage of container.styles.backgroundImage.slice(0).reverse()) {
|
|
43
|
+
if (backgroundImage.type === 0 /* CSSImageType.URL */) {
|
|
44
|
+
await this.renderBackgroundURLImage(container, backgroundImage, index);
|
|
45
|
+
}
|
|
46
|
+
else if ((0, image_1.isLinearGradient)(backgroundImage)) {
|
|
47
|
+
this.renderLinearGradient(container, backgroundImage, index);
|
|
48
|
+
}
|
|
49
|
+
else if ((0, image_1.isRadialGradient)(backgroundImage)) {
|
|
50
|
+
this.renderRadialGradient(container, backgroundImage, index);
|
|
51
|
+
}
|
|
52
|
+
index--;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Render a URL-based background image
|
|
57
|
+
*/
|
|
58
|
+
async renderBackgroundURLImage(container, backgroundImage, index) {
|
|
59
|
+
let image;
|
|
60
|
+
const url = backgroundImage.url;
|
|
61
|
+
try {
|
|
62
|
+
image = await this.context.cache.match(url);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
this.context.logger.error(`Error loading background-image ${url}`);
|
|
66
|
+
}
|
|
67
|
+
if (image) {
|
|
68
|
+
const imageWidth = isNaN(image.width) || image.width === 0 ? 1 : image.width;
|
|
69
|
+
const imageHeight = isNaN(image.height) || image.height === 0 ? 1 : image.height;
|
|
70
|
+
const [path, x, y, width, height] = (0, background_1.calculateBackgroundRendering)(container, index, [
|
|
71
|
+
imageWidth,
|
|
72
|
+
imageHeight,
|
|
73
|
+
imageWidth / imageHeight
|
|
74
|
+
]);
|
|
75
|
+
const pattern = this.ctx.createPattern(this.resizeImage(image, width, height, container.styles.imageRendering), 'repeat');
|
|
76
|
+
this.renderRepeat(path, pattern, x, y);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Render a linear gradient background
|
|
81
|
+
*/
|
|
82
|
+
renderLinearGradient(container, backgroundImage, index) {
|
|
83
|
+
const [path, x, y, width, height] = (0, background_1.calculateBackgroundRendering)(container, index, [null, null, null]);
|
|
84
|
+
const [lineLength, x0, x1, y0, y1] = (0, gradient_1.calculateGradientDirection)(backgroundImage.angle, width, height);
|
|
85
|
+
const ownerDocument = this.canvas.ownerDocument ?? document;
|
|
86
|
+
const canvas = ownerDocument.createElement('canvas');
|
|
87
|
+
canvas.width = width;
|
|
88
|
+
canvas.height = height;
|
|
89
|
+
const ctx = canvas.getContext('2d');
|
|
90
|
+
const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
91
|
+
(0, gradient_1.processColorStops)(backgroundImage.stops, lineLength || 1).forEach((colorStop) => gradient.addColorStop(colorStop.stop, (0, color_utilities_1.asString)(colorStop.color)));
|
|
92
|
+
ctx.fillStyle = gradient;
|
|
93
|
+
ctx.fillRect(0, 0, width, height);
|
|
94
|
+
if (width > 0 && height > 0) {
|
|
95
|
+
const pattern = this.ctx.createPattern(canvas, 'repeat');
|
|
96
|
+
this.renderRepeat(path, pattern, x, y);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Render a radial gradient background
|
|
101
|
+
*/
|
|
102
|
+
renderRadialGradient(container, backgroundImage, index) {
|
|
103
|
+
const [path, left, top, width, height] = (0, background_1.calculateBackgroundRendering)(container, index, [null, null, null]);
|
|
104
|
+
const position = backgroundImage.position.length === 0 ? [length_percentage_1.FIFTY_PERCENT] : backgroundImage.position;
|
|
105
|
+
const x = (0, length_percentage_1.getAbsoluteValue)(position[0], width);
|
|
106
|
+
const y = (0, length_percentage_1.getAbsoluteValue)(position[position.length - 1], height);
|
|
107
|
+
let [rx, ry] = (0, gradient_1.calculateRadius)(backgroundImage, x, y, width, height);
|
|
108
|
+
// Handle edge case where radial gradient size is 0
|
|
109
|
+
// Use a minimum value of 0.01 to ensure gradient is still rendered
|
|
110
|
+
if (rx === 0 || ry === 0) {
|
|
111
|
+
rx = Math.max(rx, 0.01);
|
|
112
|
+
ry = Math.max(ry, 0.01);
|
|
113
|
+
}
|
|
114
|
+
if (rx > 0 && ry > 0) {
|
|
115
|
+
const radialGradient = this.ctx.createRadialGradient(left + x, top + y, 0, left + x, top + y, rx);
|
|
116
|
+
(0, gradient_1.processColorStops)(backgroundImage.stops, rx * 2).forEach((colorStop) => radialGradient.addColorStop(colorStop.stop, (0, color_utilities_1.asString)(colorStop.color)));
|
|
117
|
+
this.path(path);
|
|
118
|
+
this.ctx.fillStyle = radialGradient;
|
|
119
|
+
if (rx !== ry) {
|
|
120
|
+
// transforms for elliptical radial gradient
|
|
121
|
+
const midX = container.bounds.left + 0.5 * container.bounds.width;
|
|
122
|
+
const midY = container.bounds.top + 0.5 * container.bounds.height;
|
|
123
|
+
const f = ry / rx;
|
|
124
|
+
const invF = 1 / f;
|
|
125
|
+
this.ctx.save();
|
|
126
|
+
this.ctx.translate(midX, midY);
|
|
127
|
+
this.ctx.transform(1, 0, 0, f, 0, 0);
|
|
128
|
+
this.ctx.translate(-midX, -midY);
|
|
129
|
+
this.ctx.fillRect(left, invF * (top - midY) + midY, width, height * invF);
|
|
130
|
+
this.ctx.restore();
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
this.ctx.fill();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Render a repeating pattern with offset
|
|
139
|
+
*
|
|
140
|
+
* @param path - Path to fill
|
|
141
|
+
* @param pattern - Canvas pattern or gradient
|
|
142
|
+
* @param offsetX - X offset for pattern
|
|
143
|
+
* @param offsetY - Y offset for pattern
|
|
144
|
+
*/
|
|
145
|
+
renderRepeat(path, pattern, offsetX, offsetY) {
|
|
146
|
+
this.path(path);
|
|
147
|
+
this.ctx.fillStyle = pattern;
|
|
148
|
+
this.ctx.translate(offsetX, offsetY);
|
|
149
|
+
this.ctx.fill();
|
|
150
|
+
this.ctx.translate(-offsetX, -offsetY);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Resize an image to target dimensions
|
|
154
|
+
*
|
|
155
|
+
* @param image - Source image
|
|
156
|
+
* @param width - Target width
|
|
157
|
+
* @param height - Target height
|
|
158
|
+
* @param imageRendering - CSS image-rendering property value
|
|
159
|
+
* @returns Resized canvas or original image
|
|
160
|
+
*/
|
|
161
|
+
resizeImage(image, width, height, imageRendering) {
|
|
162
|
+
// https://github.com/niklasvh/html2canvas/pull/2911
|
|
163
|
+
// if (image.width === width && image.height === height) {
|
|
164
|
+
// return image;
|
|
165
|
+
// }
|
|
166
|
+
const ownerDocument = this.canvas.ownerDocument ?? document;
|
|
167
|
+
const canvas = ownerDocument.createElement('canvas');
|
|
168
|
+
canvas.width = Math.max(1, width);
|
|
169
|
+
canvas.height = Math.max(1, height);
|
|
170
|
+
const ctx = canvas.getContext('2d');
|
|
171
|
+
// Apply image smoothing based on CSS image-rendering property
|
|
172
|
+
if (imageRendering === image_rendering_1.IMAGE_RENDERING.PIXELATED || imageRendering === image_rendering_1.IMAGE_RENDERING.CRISP_EDGES) {
|
|
173
|
+
this.context.logger.debug(`Disabling image smoothing for background image due to CSS image-rendering`);
|
|
174
|
+
ctx.imageSmoothingEnabled = false;
|
|
175
|
+
}
|
|
176
|
+
else if (imageRendering === image_rendering_1.IMAGE_RENDERING.SMOOTH) {
|
|
177
|
+
this.context.logger.debug(`Enabling image smoothing for background image due to CSS image-rendering: smooth`);
|
|
178
|
+
ctx.imageSmoothingEnabled = true;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// AUTO: inherit from main renderer context
|
|
182
|
+
ctx.imageSmoothingEnabled = this.ctx.imageSmoothingEnabled;
|
|
183
|
+
}
|
|
184
|
+
// Inherit quality setting
|
|
185
|
+
if (this.ctx.imageSmoothingQuality) {
|
|
186
|
+
ctx.imageSmoothingQuality = this.ctx.imageSmoothingQuality;
|
|
187
|
+
}
|
|
188
|
+
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
|
|
189
|
+
return canvas;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a canvas path from path array
|
|
193
|
+
*
|
|
194
|
+
* @param paths - Array of path points
|
|
195
|
+
*/
|
|
196
|
+
path(paths) {
|
|
197
|
+
this.ctx.beginPath();
|
|
198
|
+
this.formatPath(paths);
|
|
199
|
+
this.ctx.closePath();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Format path points into canvas path
|
|
203
|
+
*
|
|
204
|
+
* @param paths - Array of path points
|
|
205
|
+
*/
|
|
206
|
+
formatPath(paths) {
|
|
207
|
+
paths.forEach((point, index) => {
|
|
208
|
+
const start = (0, bezier_curve_1.isBezierCurve)(point) ? point.start : point;
|
|
209
|
+
if (index === 0) {
|
|
210
|
+
this.ctx.moveTo(start.x, start.y);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.ctx.lineTo(start.x, start.y);
|
|
214
|
+
}
|
|
215
|
+
if ((0, bezier_curve_1.isBezierCurve)(point)) {
|
|
216
|
+
this.ctx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.BackgroundRenderer = BackgroundRenderer;
|
|
222
|
+
//# sourceMappingURL=background-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-renderer.js","sourceRoot":"","sources":["../../../../src/render/canvas/background-renderer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAKH,iDAAsG;AACtG,8CAA6D;AAC7D,iEAAoH;AACpH,yEAAoF;AACpF,qEAA2D;AAC3D,kDAAgD;AAEhD,oFAAiF;AAgBjF;;;;;GAKG;AACH,MAAa,kBAAkB;IAK3B,YAAY,IAAoC;QAC5C,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,6DAA6D;IACjE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,qBAAqB,CAAC,SAA2B;QACnD,IAAI,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;QACxD,KAAK,MAAM,eAAe,IAAI,SAAS,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,E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