mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
9fda3e1ede | |||
6521a487d7 | |||
0476d06515 | |||
74696faf47 | |||
1cc853a318 | |||
04787ee88a | |||
ba2b1cd8e9 | |||
d9222075da | |||
101c32ed71 | |||
ddffaecf6d | |||
fd22a01a3c | |||
ed57781594 | |||
eeda86bd5e |
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@ -101,22 +101,26 @@ jobs:
|
|||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
name: OSX Safari Stable
|
name: OSX Safari Stable
|
||||||
targetBrowser: Safari_Stable
|
targetBrowser: Safari_Stable
|
||||||
- os: macos-latest
|
- os: macos-10.15
|
||||||
name: iOS Simulator Safari 12
|
name: iOS Simulator Safari 12
|
||||||
targetBrowser: Safari_IOS_12
|
targetBrowser: Safari_IOS_12
|
||||||
xcode: /Applications/Xcode_10.3.app
|
xcode: /Applications/Xcode_10.3.app
|
||||||
- os: macos-latest
|
- os: macos-10.15
|
||||||
name: iOS Simulator Safari 13
|
name: iOS Simulator Safari 13
|
||||||
targetBrowser: Safari_IOS_13
|
targetBrowser: Safari_IOS_13
|
||||||
xcode: /Applications/Xcode_11.6_beta.app
|
xcode: /Applications/Xcode_11.7.app
|
||||||
- os: macos-latest
|
- os: macos-10.15
|
||||||
name: iOS Simulator Safari 14
|
name: iOS Simulator Safari 14
|
||||||
targetBrowser: Safari_IOS_14
|
targetBrowser: Safari_IOS_14
|
||||||
xcode: /Applications/Xcode_12_beta.app
|
xcode: /Applications/Xcode_12.4.app
|
||||||
|
- os: macos-11
|
||||||
|
name: iOS Simulator Safari 15.0
|
||||||
|
targetBrowser: Safari_IOS_15_0
|
||||||
|
xcode: /Applications/Xcode_13.0.app
|
||||||
- os: macos-11
|
- os: macos-11
|
||||||
name: iOS Simulator Safari 15
|
name: iOS Simulator Safari 15
|
||||||
targetBrowser: Safari_IOS_15
|
targetBrowser: Safari_IOS_15
|
||||||
xcode: /Applications/Xcode_13.0.app
|
xcode: /Applications/Xcode_13.2.app
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
name: Windows Internet Explorer 9 (Emulated)
|
name: Windows Internet Explorer 9 (Emulated)
|
||||||
targetBrowser: IE_9
|
targetBrowser: IE_9
|
||||||
|
75
CHANGELOG.md
75
CHANGELOG.md
@ -2,6 +2,48 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
# [1.4.0](https://github.com/niklasvh/html2canvas/compare/v1.3.4...v1.4.0) (2022-01-01)
|
||||||
|
|
||||||
|
|
||||||
|
### feat
|
||||||
|
|
||||||
|
* use native text segmenter where available (#2782) ([6521a48](https://github.com/niklasvh/html2canvas/commit/6521a487d78172f7179f7c973c1a3af40eb92009)), closes [#2782](https://github.com/niklasvh/html2canvas/issues/2782)
|
||||||
|
|
||||||
|
### fix
|
||||||
|
|
||||||
|
* adopted stylesheets (#2785) ([74696fa](https://github.com/niklasvh/html2canvas/commit/74696faf47c07b48b9c9587db0b999da1c08a8be)), closes [#2785](https://github.com/niklasvh/html2canvas/issues/2785)
|
||||||
|
* ios text wrapping with 0 width rect (#2786) ([0476d06](https://github.com/niklasvh/html2canvas/commit/0476d065158c33d2020a9f602b3043e5e2f90c75)), closes [#2786](https://github.com/niklasvh/html2canvas/issues/2786)
|
||||||
|
* reduce SLICE_STACK_SIZE to 50k (#2784) ([1cc853a](https://github.com/niklasvh/html2canvas/commit/1cc853a3186853eaca00af060f651697dc3497a9)), closes [#2784](https://github.com/niklasvh/html2canvas/issues/2784)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [1.3.4](https://github.com/niklasvh/html2canvas/compare/v1.3.3...v1.3.4) (2021-12-29)
|
||||||
|
|
||||||
|
|
||||||
|
### ci
|
||||||
|
|
||||||
|
* add ios 15.0 testing (#2780) ([d922207](https://github.com/niklasvh/html2canvas/commit/d9222075daaed08884491b0563fc899ee0ced731)), closes [#2780](https://github.com/niklasvh/html2canvas/issues/2780)
|
||||||
|
|
||||||
|
### fix
|
||||||
|
|
||||||
|
* ios 15 font rendering crash (#2645) ([ba2b1cd](https://github.com/niklasvh/html2canvas/commit/ba2b1cd8e9a9d7932675d7abffce1526a609e769)), closes [#2645](https://github.com/niklasvh/html2canvas/issues/2645)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [1.3.3](https://github.com/niklasvh/html2canvas/compare/v1.3.2...v1.3.3) (2021-11-23)
|
||||||
|
|
||||||
|
|
||||||
|
### ci
|
||||||
|
|
||||||
|
* fix macos action runners (#2757) ([ed57781](https://github.com/niklasvh/html2canvas/commit/ed577815949b6a565df54f2101cf6f0fb731c290)), closes [#2757](https://github.com/niklasvh/html2canvas/issues/2757)
|
||||||
|
|
||||||
|
### fix
|
||||||
|
|
||||||
|
* "offsets" text when font is big ([fd22a01](https://github.com/niklasvh/html2canvas/commit/fd22a01a3c9e39293f47caaed0c0e13d2dc8170c))
|
||||||
|
* const enums (#2651) ([eeda86b](https://github.com/niklasvh/html2canvas/commit/eeda86bd5e81fb4e97675fe9bee3d4d15899997f)), closes [#2651](https://github.com/niklasvh/html2canvas/issues/2651)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [1.3.2](https://github.com/niklasvh/html2canvas/compare/v1.3.1...v1.3.2) (2021-08-15)
|
## [1.3.2](https://github.com/niklasvh/html2canvas/compare/v1.3.1...v1.3.2) (2021-08-15)
|
||||||
|
|
||||||
|
|
||||||
@ -211,9 +253,14 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
|
|
||||||
* update www deps (#2525) ([2a013e2](https://github.com/niklasvh/html2canvas/commit/2a013e20c814b7dbaea98f54f0bde8f553eb79a2)), closes [#2525](https://github.com/niklasvh/html2canvas/issues/2525)
|
* update www deps (#2525) ([2a013e2](https://github.com/niklasvh/html2canvas/commit/2a013e20c814b7dbaea98f54f0bde8f553eb79a2)), closes [#2525](https://github.com/niklasvh/html2canvas/issues/2525)
|
||||||
|
|
||||||
|
### feat
|
||||||
|
|
||||||
|
* add support for border-style dashed, dotted, double (#2531) ([72cd528](https://github.com/niklasvh/html2canvas/commit/72cd5284296e4cdb3fe88f2982ec7528604b6618))
|
||||||
|
|
||||||
### fix
|
### fix
|
||||||
|
|
||||||
* opacity with overflow hidden (#2450) ([82b7da5](https://github.com/niklasvh/html2canvas/commit/82b7da558c342e7f53d298bb1d843a5db86c3b21)), closes [#2450](https://github.com/niklasvh/html2canvas/issues/2450)
|
* opacity with overflow hidden (#2450) ([82b7da5](https://github.com/niklasvh/html2canvas/commit/82b7da558c342e7f53d298bb1d843a5db86c3b21)), closes [#2450](https://github.com/niklasvh/html2canvas/issues/2450)
|
||||||
|
* top right border radius (#2522) ([ba17267](https://github.com/niklasvh/html2canvas/commit/ba172678f07f962e9f54b398df087e86217d7a13))
|
||||||
|
|
||||||
### test
|
### test
|
||||||
|
|
||||||
@ -361,16 +408,16 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
* Fix white space appearing on element rendering (Fix #1438)
|
* Fix white space appearing on element rendering (Fix #1438)
|
||||||
* Reset canvas transform on finish (Fix #1494)
|
* Reset canvas transform on finish (Fix #1494)
|
||||||
|
|
||||||
# v1.0.0-alpha.11 - 1.4.2018
|
# v1.0.0-alpha.11 - 1.4.2018
|
||||||
* Fix IE11 member not found error
|
* Fix IE11 member not found error
|
||||||
* Support blob image resources in non-foreignObjectRendering mode
|
* Support blob image resources in non-foreignObjectRendering mode
|
||||||
|
|
||||||
# v1.0.0-alpha.10 - 15.2.2018
|
# v1.0.0-alpha.10 - 15.2.2018
|
||||||
* Re-introduce `onclone` option (Fix #1434)
|
* Re-introduce `onclone` option (Fix #1434)
|
||||||
* Add `ignoreElements` predicate function option
|
* Add `ignoreElements` predicate function option
|
||||||
* Fix version console logging
|
* Fix version console logging
|
||||||
|
|
||||||
# v1.0.0-alpha.9 - 7.1.2018
|
# v1.0.0-alpha.9 - 7.1.2018
|
||||||
* Fix dynamic style sheets
|
* Fix dynamic style sheets
|
||||||
* Fix > 50% border-radius values
|
* Fix > 50% border-radius values
|
||||||
|
|
||||||
@ -382,7 +429,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
* Fix form input rendering (#1338)
|
* Fix form input rendering (#1338)
|
||||||
* Improve word line breaking algorithm
|
* Improve word line breaking algorithm
|
||||||
|
|
||||||
# v1.0.0-alpha.6 - 28.12.2017
|
# v1.0.0-alpha.6 - 28.12.2017
|
||||||
* Fix list-style: none (#1340)
|
* Fix list-style: none (#1340)
|
||||||
* Extend supported values for pseudo element content
|
* Extend supported values for pseudo element content
|
||||||
|
|
||||||
@ -392,7 +439,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
* Fix overflow: auto
|
* Fix overflow: auto
|
||||||
* Added support for rendering list-style
|
* Added support for rendering list-style
|
||||||
|
|
||||||
v1.0.0-alpha.4 - 12.12.2017
|
v1.0.0-alpha.4 - 12.12.2017
|
||||||
* Fix rendering with multiple fonts defined (Fix #796)
|
* Fix rendering with multiple fonts defined (Fix #796)
|
||||||
* Add support for radial-gradients
|
* Add support for radial-gradients
|
||||||
* Fix logging option (#1302)
|
* Fix logging option (#1302)
|
||||||
@ -414,8 +461,8 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
##### Breaking Changes #####
|
##### Breaking Changes #####
|
||||||
* Remove deprecated onrendered callback, calling `html2canvas` returns a `Promise<HTMLCanvasElement>`
|
* Remove deprecated onrendered callback, calling `html2canvas` returns a `Promise<HTMLCanvasElement>`
|
||||||
* Removed option `type`, same results can be achieved by assigning `x`, `y`, `scrollX`, `scrollY`, `width` and `height` properties.
|
* Removed option `type`, same results can be achieved by assigning `x`, `y`, `scrollX`, `scrollY`, `width` and `height` properties.
|
||||||
|
|
||||||
## New featues / fixes
|
## New featues / fixes
|
||||||
* Add support for scaling canvas (defaults to device pixel ratio)
|
* Add support for scaling canvas (defaults to device pixel ratio)
|
||||||
* Add support for multiple text-shadows
|
* Add support for multiple text-shadows
|
||||||
* Add support for multiple text-decorations
|
* Add support for multiple text-decorations
|
||||||
@ -424,7 +471,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
* Correctly handle px and percentage values in linear-gradients
|
* Correctly handle px and percentage values in linear-gradients
|
||||||
* Correctly support all angle types for linear-gradients
|
* Correctly support all angle types for linear-gradients
|
||||||
* Add support for multiple values for background-repeat, background-position and background-size
|
* Add support for multiple values for background-repeat, background-position and background-size
|
||||||
|
|
||||||
# v0.5.0-beta4 - 23.1.2016
|
# v0.5.0-beta4 - 23.1.2016
|
||||||
* Fix logger requiring access to window object
|
* Fix logger requiring access to window object
|
||||||
* Derequire browserify build
|
* Derequire browserify build
|
||||||
@ -444,11 +491,11 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
* Fix transparent colors breaking gradients
|
* Fix transparent colors breaking gradients
|
||||||
* Preserve scrolling positions on render
|
* Preserve scrolling positions on render
|
||||||
|
|
||||||
# v0.5.0-alpha2 - 3.2.2015
|
# v0.5.0-alpha2 - 3.2.2015
|
||||||
* Switch to using browserify for building
|
* Switch to using browserify for building
|
||||||
* Fix (#517) Chrome stretches background images with 'auto' or single attributes
|
* Fix (#517) Chrome stretches background images with 'auto' or single attributes
|
||||||
|
|
||||||
# v0.5.0-alpha - 19.1.2015
|
# v0.5.0-alpha - 19.1.2015
|
||||||
* Complete rewrite of library
|
* Complete rewrite of library
|
||||||
* Switched interface to return Promise
|
* Switched interface to return Promise
|
||||||
* Uses hidden iframe window to perform rendering, allowing async rendering and doesn't force the viewport to be scrolled to the top anymore.
|
* Uses hidden iframe window to perform rendering, allowing async rendering and doesn't force the viewport to be scrolled to the top anymore.
|
||||||
@ -459,14 +506,14 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
* Changed format for proxy requests, permitting binary responses with CORS headers as well
|
* Changed format for proxy requests, permitting binary responses with CORS headers as well
|
||||||
* Fixed many layering issues (see z-index tests)
|
* Fixed many layering issues (see z-index tests)
|
||||||
|
|
||||||
# v0.4.1 - 7.9.2013
|
# v0.4.1 - 7.9.2013
|
||||||
* Added support for bower
|
* Added support for bower
|
||||||
* Improved z-index ordering
|
* Improved z-index ordering
|
||||||
* Basic implementation for CSS transformations
|
* Basic implementation for CSS transformations
|
||||||
* Fixed inline text in top element
|
* Fixed inline text in top element
|
||||||
* Basic implementation for text-shadow
|
* Basic implementation for text-shadow
|
||||||
|
|
||||||
# v0.4.0 - 30.1.2013
|
# v0.4.0 - 30.1.2013
|
||||||
* Added rendering tests with <a href="https://github.com/niklasvh/webdriver.js">webdriver</a>
|
* Added rendering tests with <a href="https://github.com/niklasvh/webdriver.js">webdriver</a>
|
||||||
* Switched to using grunt for building
|
* Switched to using grunt for building
|
||||||
* Removed support for IE<9, including any FlashCanvas bits
|
* Removed support for IE<9, including any FlashCanvas bits
|
||||||
@ -476,7 +523,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|||||||
* Support for placeholder rendering
|
* Support for placeholder rendering
|
||||||
* Reformatted all tests to small units to test specific features
|
* Reformatted all tests to small units to test specific features
|
||||||
|
|
||||||
# v0.3.4 - 26.6.2012
|
# v0.3.4 - 26.6.2012
|
||||||
|
|
||||||
* Removed (last?) jQuery dependencies (<a href="https://github.com/niklasvh/html2canvas/commit/343b86705fe163766fcf735eb0217130e4bd5b17">niklasvh</a>)
|
* Removed (last?) jQuery dependencies (<a href="https://github.com/niklasvh/html2canvas/commit/343b86705fe163766fcf735eb0217130e4bd5b17">niklasvh</a>)
|
||||||
* SVG-powered rendering (<a href="https://github.com/niklasvh/html2canvas/commit/67d3e0d0f59a5a654caf71a2e3be6494ff146c75">niklasvh</a>)
|
* SVG-powered rendering (<a href="https://github.com/niklasvh/html2canvas/commit/67d3e0d0f59a5a654caf71a2e3be6494ff146c75">niklasvh</a>)
|
||||||
|
@ -34,19 +34,25 @@ module.exports = function(config) {
|
|||||||
base: 'MobileSafari',
|
base: 'MobileSafari',
|
||||||
name: 'iPhone 8',
|
name: 'iPhone 8',
|
||||||
platform: 'iOS',
|
platform: 'iOS',
|
||||||
sdk: '13.6'
|
sdk: '13.7'
|
||||||
},
|
},
|
||||||
Safari_IOS_14: {
|
Safari_IOS_14: {
|
||||||
base: 'MobileSafari',
|
base: 'MobileSafari',
|
||||||
name: 'iPhone 8',
|
name: 'iPhone 8',
|
||||||
platform: 'iOS',
|
platform: 'iOS',
|
||||||
sdk: '14.0'
|
sdk: '14.4'
|
||||||
|
},
|
||||||
|
Safari_IOS_15_0: {
|
||||||
|
base: 'MobileSafari',
|
||||||
|
name: 'iPhone 13',
|
||||||
|
platform: 'iOS',
|
||||||
|
sdk: '15.0'
|
||||||
},
|
},
|
||||||
Safari_IOS_15: {
|
Safari_IOS_15: {
|
||||||
base: 'MobileSafari',
|
base: 'MobileSafari',
|
||||||
name: 'iPhone 8',
|
name: 'iPhone 13',
|
||||||
platform: 'iOS',
|
platform: 'iOS',
|
||||||
sdk: '15.0'
|
sdk: '15.2'
|
||||||
},
|
},
|
||||||
SauceLabs_IE9: {
|
SauceLabs_IE9: {
|
||||||
base: 'SauceLabs',
|
base: 'SauceLabs',
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "html2canvas",
|
"name": "html2canvas",
|
||||||
"version": "1.3.2",
|
"version": "1.4.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
"module": "dist/html2canvas.esm.js",
|
"module": "dist/html2canvas.esm.js",
|
||||||
"typings": "dist/types/index.d.ts",
|
"typings": "dist/types/index.d.ts",
|
||||||
"browser": "dist/html2canvas.js",
|
"browser": "dist/html2canvas.js",
|
||||||
"version": "1.3.2",
|
"version": "1.4.0",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Niklas von Hertzen",
|
"name": "Niklas von Hertzen",
|
||||||
"email": "niklasvh@gmail.com",
|
"email": "niklasvh@gmail.com",
|
||||||
|
@ -211,5 +211,12 @@ export const FEATURES = {
|
|||||||
const value = 'withCredentials' in new XMLHttpRequest();
|
const value = 'withCredentials' in new XMLHttpRequest();
|
||||||
Object.defineProperty(FEATURES, 'SUPPORT_CORS_XHR', {value});
|
Object.defineProperty(FEATURES, 'SUPPORT_CORS_XHR', {value});
|
||||||
return value;
|
return value;
|
||||||
|
},
|
||||||
|
get SUPPORT_NATIVE_TEXT_SEGMENTATION(): boolean {
|
||||||
|
'use strict';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const value = !!(typeof Intl !== 'undefined' && (Intl as any).Segmenter);
|
||||||
|
Object.defineProperty(FEATURES, 'SUPPORT_NATIVE_TEXT_SEGMENTATION', {value});
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ export class Bounds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fromDOMRectList(context: Context, domRectList: DOMRectList): Bounds {
|
static fromDOMRectList(context: Context, domRectList: DOMRectList): Bounds {
|
||||||
const domRect = domRectList[0];
|
const domRect = Array.from(domRectList).find((rect) => rect.width !== 0);
|
||||||
return domRect
|
return domRect
|
||||||
? new Bounds(
|
? new Bounds(
|
||||||
domRect.x + context.windowBounds.left,
|
domRect.x + context.windowBounds.left,
|
||||||
|
@ -28,15 +28,24 @@ export const parseTextBounds = (
|
|||||||
textList.forEach((text) => {
|
textList.forEach((text) => {
|
||||||
if (styles.textDecorationLine.length || text.trim().length > 0) {
|
if (styles.textDecorationLine.length || text.trim().length > 0) {
|
||||||
if (FEATURES.SUPPORT_RANGE_BOUNDS) {
|
if (FEATURES.SUPPORT_RANGE_BOUNDS) {
|
||||||
if (!FEATURES.SUPPORT_WORD_BREAKING) {
|
const clientRects = createRange(node, offset, text.length).getClientRects();
|
||||||
textBounds.push(
|
if (clientRects.length > 1) {
|
||||||
new TextBounds(
|
const subSegments = segmentGraphemes(text);
|
||||||
text,
|
let subOffset = 0;
|
||||||
Bounds.fromDOMRectList(context, createRange(node, offset, text.length).getClientRects())
|
subSegments.forEach((subSegment) => {
|
||||||
)
|
textBounds.push(
|
||||||
);
|
new TextBounds(
|
||||||
|
subSegment,
|
||||||
|
Bounds.fromDOMRectList(
|
||||||
|
context,
|
||||||
|
createRange(node, subOffset + offset, subSegment.length).getClientRects()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
subOffset += subSegment.length;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
textBounds.push(new TextBounds(text, getRangeBounds(context, node, offset, text.length)));
|
textBounds.push(new TextBounds(text, Bounds.fromDOMRectList(context, clientRects)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const replacementNode = node.splitText(text.length);
|
const replacementNode = node.splitText(text.length);
|
||||||
@ -82,12 +91,32 @@ const createRange = (node: Text, offset: number, length: number): Range => {
|
|||||||
return range;
|
return range;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getRangeBounds = (context: Context, node: Text, offset: number, length: number): Bounds => {
|
export const segmentGraphemes = (value: string): string[] => {
|
||||||
return Bounds.fromClientRect(context, createRange(node, offset, length).getBoundingClientRect());
|
if (FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const segmenter = new (Intl as any).Segmenter(void 0, {granularity: 'grapheme'});
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return Array.from(segmenter.segment(value)).map((segment: any) => segment.segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return splitGraphemes(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const segmentWords = (value: string, styles: CSSParsedDeclaration): string[] => {
|
||||||
|
if (FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const segmenter = new (Intl as any).Segmenter(void 0, {
|
||||||
|
granularity: 'word'
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return Array.from(segmenter.segment(value)).map((segment: any) => segment.segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return breakWords(value, styles);
|
||||||
};
|
};
|
||||||
|
|
||||||
const breakText = (value: string, styles: CSSParsedDeclaration): string[] => {
|
const breakText = (value: string, styles: CSSParsedDeclaration): string[] => {
|
||||||
return styles.letterSpacing !== 0 ? splitGraphemes(value) : breakWords(value, styles);
|
return styles.letterSpacing !== 0 ? segmentGraphemes(value) : segmentWords(value, styles);
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-text/#word-separator
|
// https://drafts.csswg.org/css-text/#word-separator
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {IPropertyListDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyListDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {CSSValue, isIdentToken} from '../syntax/parser';
|
import {CSSValue, isIdentToken} from '../syntax/parser';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum BACKGROUND_CLIP {
|
export const enum BACKGROUND_CLIP {
|
||||||
BORDER_BOX = 0,
|
BORDER_BOX = 0,
|
||||||
PADDING_BOX = 1,
|
PADDING_BOX = 1,
|
||||||
CONTENT_BOX = 2
|
CONTENT_BOX = 2
|
||||||
|
@ -3,7 +3,7 @@ import {CSSValue, isIdentToken, parseFunctionArgs} from '../syntax/parser';
|
|||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export type BackgroundRepeat = BACKGROUND_REPEAT[];
|
export type BackgroundRepeat = BACKGROUND_REPEAT[];
|
||||||
|
|
||||||
export enum BACKGROUND_REPEAT {
|
export const enum BACKGROUND_REPEAT {
|
||||||
REPEAT = 0,
|
REPEAT = 0,
|
||||||
NO_REPEAT = 1,
|
NO_REPEAT = 1,
|
||||||
REPEAT_X = 2,
|
REPEAT_X = 2,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum BORDER_STYLE {
|
export const enum BORDER_STYLE {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
SOLID = 1,
|
SOLID = 1,
|
||||||
DASHED = 2,
|
DASHED = 2,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum FLOAT {
|
export const enum FLOAT {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
LEFT = 1,
|
LEFT = 1,
|
||||||
RIGHT = 2,
|
RIGHT = 2,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum FONT_STYLE {
|
export const enum FONT_STYLE {
|
||||||
NORMAL = 'normal',
|
NORMAL = 'normal',
|
||||||
ITALIC = 'italic',
|
ITALIC = 'italic',
|
||||||
OBLIQUE = 'oblique'
|
OBLIQUE = 'oblique'
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum LIST_STYLE_POSITION {
|
export const enum LIST_STYLE_POSITION {
|
||||||
INSIDE = 0,
|
INSIDE = 0,
|
||||||
OUTSIDE = 1
|
OUTSIDE = 1
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum LIST_STYLE_TYPE {
|
export const enum LIST_STYLE_TYPE {
|
||||||
NONE = -1,
|
NONE = -1,
|
||||||
DISC = 0,
|
DISC = 0,
|
||||||
CIRCLE = 1,
|
CIRCLE = 1,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {IPropertyListDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyListDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {CSSValue, isIdentToken} from '../syntax/parser';
|
import {CSSValue, isIdentToken} from '../syntax/parser';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum OVERFLOW {
|
export const enum OVERFLOW {
|
||||||
VISIBLE = 0,
|
VISIBLE = 0,
|
||||||
HIDDEN = 1,
|
HIDDEN = 1,
|
||||||
SCROLL = 2,
|
SCROLL = 2,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {IPropertyListDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyListDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {CSSValue, isIdentToken} from '../syntax/parser';
|
import {CSSValue, isIdentToken} from '../syntax/parser';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum PAINT_ORDER_LAYER {
|
export const enum PAINT_ORDER_LAYER {
|
||||||
FILL,
|
FILL,
|
||||||
STROKE,
|
STROKE,
|
||||||
MARKERS
|
MARKERS
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum POSITION {
|
export const enum POSITION {
|
||||||
STATIC = 0,
|
STATIC = 0,
|
||||||
RELATIVE = 1,
|
RELATIVE = 1,
|
||||||
ABSOLUTE = 2,
|
ABSOLUTE = 2,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum TEXT_ALIGN {
|
export const enum TEXT_ALIGN {
|
||||||
LEFT = 0,
|
LEFT = 0,
|
||||||
CENTER = 1,
|
CENTER = 1,
|
||||||
RIGHT = 2
|
RIGHT = 2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum TEXT_TRANSFORM {
|
export const enum TEXT_TRANSFORM {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
LOWERCASE = 1,
|
LOWERCASE = 1,
|
||||||
UPPERCASE = 2,
|
UPPERCASE = 2,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
import {IPropertyIdentValueDescriptor, PropertyDescriptorParsingType} from '../IPropertyDescriptor';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
export enum VISIBILITY {
|
export const enum VISIBILITY {
|
||||||
VISIBLE = 0,
|
VISIBLE = 0,
|
||||||
HIDDEN = 1,
|
HIDDEN = 1,
|
||||||
COLLAPSE = 2
|
COLLAPSE = 2
|
||||||
|
@ -657,7 +657,7 @@ export class Tokenizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private consumeStringSlice(count: number): string {
|
private consumeStringSlice(count: number): string {
|
||||||
const SLICE_STACK_SIZE = 60000;
|
const SLICE_STACK_SIZE = 50000;
|
||||||
let value = '';
|
let value = '';
|
||||||
while (count > 0) {
|
while (count > 0) {
|
||||||
const amount = Math.min(SLICE_STACK_SIZE, count);
|
const amount = Math.min(SLICE_STACK_SIZE, count);
|
||||||
|
@ -10,7 +10,7 @@ import {radialGradient} from './functions/radial-gradient';
|
|||||||
import {prefixRadialGradient} from './functions/-prefix-radial-gradient';
|
import {prefixRadialGradient} from './functions/-prefix-radial-gradient';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
|
|
||||||
export enum CSSImageType {
|
export const enum CSSImageType {
|
||||||
URL,
|
URL,
|
||||||
LINEAR_GRADIENT,
|
LINEAR_GRADIENT,
|
||||||
RADIAL_GRADIENT
|
RADIAL_GRADIENT
|
||||||
@ -56,12 +56,12 @@ export interface CSSLinearGradientImage extends ICSSGradientImage {
|
|||||||
type: CSSImageType.LINEAR_GRADIENT;
|
type: CSSImageType.LINEAR_GRADIENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum CSSRadialShape {
|
export const enum CSSRadialShape {
|
||||||
CIRCLE,
|
CIRCLE,
|
||||||
ELLIPSE
|
ELLIPSE
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum CSSRadialExtent {
|
export const enum CSSRadialExtent {
|
||||||
CLOSEST_SIDE,
|
CLOSEST_SIDE,
|
||||||
FARTHEST_SIDE,
|
FARTHEST_SIDE,
|
||||||
CLOSEST_CORNER,
|
CLOSEST_CORNER,
|
||||||
|
@ -2,12 +2,14 @@ import {Bounds} from '../css/layout/bounds';
|
|||||||
import {
|
import {
|
||||||
isBodyElement,
|
isBodyElement,
|
||||||
isCanvasElement,
|
isCanvasElement,
|
||||||
|
isCustomElement,
|
||||||
isElementNode,
|
isElementNode,
|
||||||
isHTMLElementNode,
|
isHTMLElementNode,
|
||||||
isIFrameElement,
|
isIFrameElement,
|
||||||
isImageElement,
|
isImageElement,
|
||||||
isScriptElement,
|
isScriptElement,
|
||||||
isSelectElement,
|
isSelectElement,
|
||||||
|
isSlotElement,
|
||||||
isStyleElement,
|
isStyleElement,
|
||||||
isSVGElementNode,
|
isSVGElementNode,
|
||||||
isTextareaElement,
|
isTextareaElement,
|
||||||
@ -63,7 +65,7 @@ export class DocumentCloner {
|
|||||||
throw new Error('Cloned element does not have an owner document');
|
throw new Error('Cloned element does not have an owner document');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.documentElement = this.cloneNode(element.ownerDocument.documentElement) as HTMLElement;
|
this.documentElement = this.cloneNode(element.ownerDocument.documentElement, false) as HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
toIFrame(ownerDocument: Document, windowSize: Bounds): Promise<HTMLIFrameElement> {
|
toIFrame(ownerDocument: Document, windowSize: Bounds): Promise<HTMLIFrameElement> {
|
||||||
@ -160,6 +162,17 @@ export class DocumentCloner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isCustomElement(clone)) {
|
||||||
|
return this.createCustomElementClone(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
createCustomElementClone(node: HTMLElement): HTMLElement {
|
||||||
|
const clone = document.createElement('html2canvascustomelement');
|
||||||
|
copyCSSStyles(node.style, clone);
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +244,20 @@ export class DocumentCloner {
|
|||||||
return clonedCanvas;
|
return clonedCanvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneNode(node: Node): Node {
|
appendChildNode(clone: HTMLElement | SVGElement, child: Node, copyStyles: boolean): void {
|
||||||
|
if (
|
||||||
|
!isElementNode(child) ||
|
||||||
|
(!isScriptElement(child) &&
|
||||||
|
!child.hasAttribute(IGNORE_ATTRIBUTE) &&
|
||||||
|
(typeof this.options.ignoreElements !== 'function' || !this.options.ignoreElements(child)))
|
||||||
|
) {
|
||||||
|
if (!this.options.copyStyles || !isElementNode(child) || !isStyleElement(child)) {
|
||||||
|
clone.appendChild(this.cloneNode(child, copyStyles));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cloneNode(node: Node, copyStyles: boolean): Node {
|
||||||
if (isTextNode(node)) {
|
if (isTextNode(node)) {
|
||||||
return document.createTextNode(node.data);
|
return document.createTextNode(node.data);
|
||||||
}
|
}
|
||||||
@ -260,16 +286,22 @@ export class DocumentCloner {
|
|||||||
const counters = this.counters.parse(new CSSParsedCounterDeclaration(this.context, style));
|
const counters = this.counters.parse(new CSSParsedCounterDeclaration(this.context, style));
|
||||||
const before = this.resolvePseudoContent(node, clone, styleBefore, PseudoElementType.BEFORE);
|
const before = this.resolvePseudoContent(node, clone, styleBefore, PseudoElementType.BEFORE);
|
||||||
|
|
||||||
for (let child = node.firstChild; child; child = child.nextSibling) {
|
if (isCustomElement(node)) {
|
||||||
if (
|
copyStyles = true;
|
||||||
!isElementNode(child) ||
|
}
|
||||||
(!isScriptElement(child) &&
|
|
||||||
!child.hasAttribute(IGNORE_ATTRIBUTE) &&
|
for (
|
||||||
(typeof this.options.ignoreElements !== 'function' || !this.options.ignoreElements(child)))
|
let child = node.shadowRoot ? node.shadowRoot.firstChild : node.firstChild;
|
||||||
) {
|
child;
|
||||||
if (!this.options.copyStyles || !isElementNode(child) || !isStyleElement(child)) {
|
child = child.nextSibling
|
||||||
clone.appendChild(this.cloneNode(child));
|
) {
|
||||||
|
if (isElementNode(child) && isSlotElement(child) && typeof child.assignedNodes === 'function') {
|
||||||
|
const assignedNodes = child.assignedNodes() as ChildNode[];
|
||||||
|
if (assignedNodes.length) {
|
||||||
|
assignedNodes.forEach((assignedNode) => this.appendChildNode(clone, assignedNode, copyStyles));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.appendChildNode(clone, child, copyStyles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +316,10 @@ export class DocumentCloner {
|
|||||||
|
|
||||||
this.counters.pop(counters);
|
this.counters.pop(counters);
|
||||||
|
|
||||||
if (style && (this.options.copyStyles || isSVGElementNode(node)) && !isIFrameElement(node)) {
|
if (
|
||||||
|
(style && (this.options.copyStyles || isSVGElementNode(node)) && !isIFrameElement(node)) ||
|
||||||
|
copyStyles
|
||||||
|
) {
|
||||||
copyCSSStyles(style, clone);
|
copyCSSStyles(style, clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,3 +131,5 @@ export const isScriptElement = (node: Element): node is HTMLScriptElement => nod
|
|||||||
export const isTextareaElement = (node: Element): node is HTMLTextAreaElement => node.tagName === 'TEXTAREA';
|
export const isTextareaElement = (node: Element): node is HTMLTextAreaElement => node.tagName === 'TEXTAREA';
|
||||||
export const isSelectElement = (node: Element): node is HTMLSelectElement => node.tagName === 'SELECT';
|
export const isSelectElement = (node: Element): node is HTMLSelectElement => node.tagName === 'SELECT';
|
||||||
export const isSlotElement = (node: Element): node is HTMLSlotElement => node.tagName === 'SLOT';
|
export const isSlotElement = (node: Element): node is HTMLSlotElement => node.tagName === 'SLOT';
|
||||||
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
||||||
|
export const isCustomElement = (node: Element): node is HTMLElement => node.tagName.indexOf('-') > 0;
|
||||||
|
@ -2,7 +2,7 @@ import {ElementPaint, parseStackingContexts, StackingContext} from '../stacking-
|
|||||||
import {asString, Color, isTransparent} from '../../css/types/color';
|
import {asString, Color, isTransparent} from '../../css/types/color';
|
||||||
import {ElementContainer, FLAGS} from '../../dom/element-container';
|
import {ElementContainer, FLAGS} from '../../dom/element-container';
|
||||||
import {BORDER_STYLE} from '../../css/property-descriptors/border-style';
|
import {BORDER_STYLE} from '../../css/property-descriptors/border-style';
|
||||||
import {CSSParsedDeclaration} from '../../css/index';
|
import {CSSParsedDeclaration} from '../../css';
|
||||||
import {TextContainer} from '../../dom/text-container';
|
import {TextContainer} from '../../dom/text-container';
|
||||||
import {Path, transformPath} from '../path';
|
import {Path, transformPath} from '../path';
|
||||||
import {BACKGROUND_CLIP} from '../../css/property-descriptors/background-clip';
|
import {BACKGROUND_CLIP} from '../../css/property-descriptors/background-clip';
|
||||||
@ -18,12 +18,12 @@ import {
|
|||||||
} from '../border';
|
} from '../border';
|
||||||
import {calculateBackgroundRendering, getBackgroundValueForIndex} from '../background';
|
import {calculateBackgroundRendering, getBackgroundValueForIndex} from '../background';
|
||||||
import {isDimensionToken} from '../../css/syntax/parser';
|
import {isDimensionToken} from '../../css/syntax/parser';
|
||||||
import {TextBounds} from '../../css/layout/text';
|
import {segmentGraphemes, TextBounds} from '../../css/layout/text';
|
||||||
import {ImageElementContainer} from '../../dom/replaced-elements/image-element-container';
|
import {ImageElementContainer} from '../../dom/replaced-elements/image-element-container';
|
||||||
import {contentBox} from '../box-sizing';
|
import {contentBox} from '../box-sizing';
|
||||||
import {CanvasElementContainer} from '../../dom/replaced-elements/canvas-element-container';
|
import {CanvasElementContainer} from '../../dom/replaced-elements/canvas-element-container';
|
||||||
import {SVGElementContainer} from '../../dom/replaced-elements/svg-element-container';
|
import {SVGElementContainer} from '../../dom/replaced-elements/svg-element-container';
|
||||||
import {ReplacedElementContainer} from '../../dom/replaced-elements/index';
|
import {ReplacedElementContainer} from '../../dom/replaced-elements';
|
||||||
import {EffectTarget, IElementEffect, isClipEffect, isOpacityEffect, isTransformEffect} from '../effects';
|
import {EffectTarget, IElementEffect, isClipEffect, isOpacityEffect, isTransformEffect} from '../effects';
|
||||||
import {contains} from '../../core/bitwise';
|
import {contains} from '../../core/bitwise';
|
||||||
import {calculateGradientDirection, calculateRadius, processColorStops} from '../../css/types/functions/gradient';
|
import {calculateGradientDirection, calculateRadius, processColorStops} from '../../css/types/functions/gradient';
|
||||||
@ -44,7 +44,6 @@ import {PAINT_ORDER_LAYER} from '../../css/property-descriptors/paint-order';
|
|||||||
import {Renderer} from '../renderer';
|
import {Renderer} from '../renderer';
|
||||||
import {Context} from '../../core/context';
|
import {Context} from '../../core/context';
|
||||||
import {DIRECTION} from '../../css/property-descriptors/direction';
|
import {DIRECTION} from '../../css/property-descriptors/direction';
|
||||||
import {splitGraphemes} from 'text-segmentation';
|
|
||||||
|
|
||||||
export type RenderConfigurations = RenderOptions & {
|
export type RenderConfigurations = RenderOptions & {
|
||||||
backgroundColor: Color | null;
|
backgroundColor: Color | null;
|
||||||
@ -149,7 +148,7 @@ export class CanvasRenderer extends Renderer {
|
|||||||
if (letterSpacing === 0) {
|
if (letterSpacing === 0) {
|
||||||
this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
|
this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
|
||||||
} else {
|
} else {
|
||||||
const letters = splitGraphemes(text.text);
|
const letters = segmentGraphemes(text.text);
|
||||||
letters.reduce((left, letter) => {
|
letters.reduce((left, letter) => {
|
||||||
this.ctx.fillText(letter, left, text.bounds.top + baseline);
|
this.ctx.fillText(letter, left, text.bounds.top + baseline);
|
||||||
|
|
||||||
@ -162,7 +161,7 @@ export class CanvasRenderer extends Renderer {
|
|||||||
const fontVariant = styles.fontVariant
|
const fontVariant = styles.fontVariant
|
||||||
.filter((variant) => variant === 'normal' || variant === 'small-caps')
|
.filter((variant) => variant === 'normal' || variant === 'small-caps')
|
||||||
.join('');
|
.join('');
|
||||||
const fontFamily = styles.fontFamily.join(', ');
|
const fontFamily = fixIOSSystemFonts(styles.fontFamily).join(', ');
|
||||||
const fontSize = isDimensionToken(styles.fontSize)
|
const fontSize = isDimensionToken(styles.fontSize)
|
||||||
? `${styles.fontSize.number}${styles.fontSize.unit}`
|
? `${styles.fontSize.number}${styles.fontSize.unit}`
|
||||||
: `${styles.fontSize.number}px`;
|
: `${styles.fontSize.number}px`;
|
||||||
@ -947,3 +946,12 @@ const canvasTextAlign = (textAlign: TEXT_ALIGN): CanvasTextAlign => {
|
|||||||
return 'left';
|
return 'left';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// see https://github.com/niklasvh/html2canvas/pull/2645
|
||||||
|
const iOSBrokenFonts = ['-apple-system', 'system-ui'];
|
||||||
|
|
||||||
|
const fixIOSSystemFonts = (fontFamilies: string[]): string[] => {
|
||||||
|
return /iPhone OS 15_(0|1)/.test(window.navigator.userAgent)
|
||||||
|
? fontFamilies.filter((fontFamily) => iOSBrokenFonts.indexOf(fontFamily) === -1)
|
||||||
|
: fontFamilies;
|
||||||
|
};
|
||||||
|
@ -27,6 +27,7 @@ export class FontMetrics {
|
|||||||
container.style.fontSize = fontSize;
|
container.style.fontSize = fontSize;
|
||||||
container.style.margin = '0';
|
container.style.margin = '0';
|
||||||
container.style.padding = '0';
|
container.style.padding = '0';
|
||||||
|
container.style.whiteSpace = 'nowrap';
|
||||||
|
|
||||||
body.appendChild(container);
|
body.appendChild(container);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {BezierCurve} from './bezier-curve';
|
import {BezierCurve} from './bezier-curve';
|
||||||
import {Vector} from './vector';
|
import {Vector} from './vector';
|
||||||
export enum PathType {
|
export const enum PathType {
|
||||||
VECTOR = 0,
|
VECTOR = 0,
|
||||||
BEZIER_CURVE = 1
|
BEZIER_CURVE = 1
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,13 @@
|
|||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.apple-system {
|
||||||
|
font-family: -apple-system, Arial;
|
||||||
|
}
|
||||||
|
|
||||||
|
.system-ui {
|
||||||
|
font-family: system-ui, Arial;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -32,5 +39,7 @@
|
|||||||
</p><p> 〔13〕 法捷耶夫(一九○一——一九五六),苏联名作家。他所作的小说《毁灭》于一九二七年出版,内容是描写苏联国内战争时期由苏联远东滨海边区工人、农民和革命知识分子所组成的一支游击队同国内反革命白卫军以及日本武装干涉军进行斗争的故事。这部小说曾由鲁迅译为汉文。
|
</p><p> 〔13〕 法捷耶夫(一九○一——一九五六),苏联名作家。他所作的小说《毁灭》于一九二七年出版,内容是描写苏联国内战争时期由苏联远东滨海边区工人、农民和革命知识分子所组成的一支游击队同国内反革命白卫军以及日本武装干涉军进行斗争的故事。这部小说曾由鲁迅译为汉文。
|
||||||
</p><p> 〔14〕 见鲁迅《集外集·自嘲》(《鲁迅全集》第7卷,人民文学出版社1981年版,第147页)。</p>
|
</p><p> 〔14〕 见鲁迅《集外集·自嘲》(《鲁迅全集》第7卷,人民文学出版社1981年版,第147页)。</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="apple-system">中文</div>
|
||||||
|
<div class="system-ui">中文</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -149,6 +149,6 @@
|
|||||||
<span>[AB / CD]</span>
|
<span>[AB / CD]</span>
|
||||||
</div>
|
</div>
|
||||||
<div>Emojis 🤷🏾♂️👨👩👧👦 :)</div>
|
<div>Emojis 🤷🏾♂️👨👩👧👦 :)</div>
|
||||||
<div style="letter-spacing: 2px">Emojis with letter-spacing 🤷🏾♂️👨👩👧👦 :)</div>
|
<div style="letter-spacing: 2px">Emojis with letter-spacing 🤷🏾♂️👨👩👧👦 :) ❤️❤️❤️👨❤️💋👨👨❤️👨</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -40,6 +40,10 @@ class AutonomousCustomElement extends HTMLElement {
|
|||||||
wrapper.appendChild(img);
|
wrapper.appendChild(img);
|
||||||
wrapper.appendChild(info);
|
wrapper.appendChild(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectedCallback() {
|
||||||
|
this.shadowRoot.adoptedStyleSheets = [sheet];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('autonomous-custom-element', AutonomousCustomElement);
|
customElements.define('autonomous-custom-element', AutonomousCustomElement);
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Web components tests</title>
|
<title>Web components tests</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<script>
|
||||||
|
const sheet = new CSSStyleSheet();
|
||||||
|
sheet.replaceSync('* { color: red !important; }')
|
||||||
|
</script>
|
||||||
<script type="text/javascript" src="../../test.js"></script>
|
<script type="text/javascript" src="../../test.js"></script>
|
||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
|
2
www/.gitignore
vendored
2
www/.gitignore
vendored
@ -9,3 +9,5 @@ yarn-error.log
|
|||||||
src/results.json
|
src/results.json
|
||||||
static/tests/preview.js
|
static/tests/preview.js
|
||||||
src/preview.js
|
src/preview.js
|
||||||
|
.docusaurus
|
||||||
|
build/
|
||||||
|
Reference in New Issue
Block a user