source: imaps-frontend/node_modules/html2canvas/dist/lib/css/layout/text.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 5.4 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.segmentGraphemes = exports.parseTextBounds = exports.TextBounds = void 0;
4var css_line_break_1 = require("css-line-break");
5var text_segmentation_1 = require("text-segmentation");
6var bounds_1 = require("./bounds");
7var features_1 = require("../../core/features");
8var TextBounds = /** @class */ (function () {
9 function TextBounds(text, bounds) {
10 this.text = text;
11 this.bounds = bounds;
12 }
13 return TextBounds;
14}());
15exports.TextBounds = TextBounds;
16var parseTextBounds = function (context, value, styles, node) {
17 var textList = breakText(value, styles);
18 var textBounds = [];
19 var offset = 0;
20 textList.forEach(function (text) {
21 if (styles.textDecorationLine.length || text.trim().length > 0) {
22 if (features_1.FEATURES.SUPPORT_RANGE_BOUNDS) {
23 var clientRects = createRange(node, offset, text.length).getClientRects();
24 if (clientRects.length > 1) {
25 var subSegments = exports.segmentGraphemes(text);
26 var subOffset_1 = 0;
27 subSegments.forEach(function (subSegment) {
28 textBounds.push(new TextBounds(subSegment, bounds_1.Bounds.fromDOMRectList(context, createRange(node, subOffset_1 + offset, subSegment.length).getClientRects())));
29 subOffset_1 += subSegment.length;
30 });
31 }
32 else {
33 textBounds.push(new TextBounds(text, bounds_1.Bounds.fromDOMRectList(context, clientRects)));
34 }
35 }
36 else {
37 var replacementNode = node.splitText(text.length);
38 textBounds.push(new TextBounds(text, getWrapperBounds(context, node)));
39 node = replacementNode;
40 }
41 }
42 else if (!features_1.FEATURES.SUPPORT_RANGE_BOUNDS) {
43 node = node.splitText(text.length);
44 }
45 offset += text.length;
46 });
47 return textBounds;
48};
49exports.parseTextBounds = parseTextBounds;
50var getWrapperBounds = function (context, node) {
51 var ownerDocument = node.ownerDocument;
52 if (ownerDocument) {
53 var wrapper = ownerDocument.createElement('html2canvaswrapper');
54 wrapper.appendChild(node.cloneNode(true));
55 var parentNode = node.parentNode;
56 if (parentNode) {
57 parentNode.replaceChild(wrapper, node);
58 var bounds = bounds_1.parseBounds(context, wrapper);
59 if (wrapper.firstChild) {
60 parentNode.replaceChild(wrapper.firstChild, wrapper);
61 }
62 return bounds;
63 }
64 }
65 return bounds_1.Bounds.EMPTY;
66};
67var createRange = function (node, offset, length) {
68 var ownerDocument = node.ownerDocument;
69 if (!ownerDocument) {
70 throw new Error('Node has no owner document');
71 }
72 var range = ownerDocument.createRange();
73 range.setStart(node, offset);
74 range.setEnd(node, offset + length);
75 return range;
76};
77var segmentGraphemes = function (value) {
78 if (features_1.FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
79 // eslint-disable-next-line @typescript-eslint/no-explicit-any
80 var segmenter = new Intl.Segmenter(void 0, { granularity: 'grapheme' });
81 // eslint-disable-next-line @typescript-eslint/no-explicit-any
82 return Array.from(segmenter.segment(value)).map(function (segment) { return segment.segment; });
83 }
84 return text_segmentation_1.splitGraphemes(value);
85};
86exports.segmentGraphemes = segmentGraphemes;
87var segmentWords = function (value, styles) {
88 if (features_1.FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
89 // eslint-disable-next-line @typescript-eslint/no-explicit-any
90 var segmenter = new Intl.Segmenter(void 0, {
91 granularity: 'word'
92 });
93 // eslint-disable-next-line @typescript-eslint/no-explicit-any
94 return Array.from(segmenter.segment(value)).map(function (segment) { return segment.segment; });
95 }
96 return breakWords(value, styles);
97};
98var breakText = function (value, styles) {
99 return styles.letterSpacing !== 0 ? exports.segmentGraphemes(value) : segmentWords(value, styles);
100};
101// https://drafts.csswg.org/css-text/#word-separator
102var wordSeparators = [0x0020, 0x00a0, 0x1361, 0x10100, 0x10101, 0x1039, 0x1091];
103var breakWords = function (str, styles) {
104 var breaker = css_line_break_1.LineBreaker(str, {
105 lineBreak: styles.lineBreak,
106 wordBreak: styles.overflowWrap === "break-word" /* BREAK_WORD */ ? 'break-word' : styles.wordBreak
107 });
108 var words = [];
109 var bk;
110 var _loop_1 = function () {
111 if (bk.value) {
112 var value = bk.value.slice();
113 var codePoints = css_line_break_1.toCodePoints(value);
114 var word_1 = '';
115 codePoints.forEach(function (codePoint) {
116 if (wordSeparators.indexOf(codePoint) === -1) {
117 word_1 += css_line_break_1.fromCodePoint(codePoint);
118 }
119 else {
120 if (word_1.length) {
121 words.push(word_1);
122 }
123 words.push(css_line_break_1.fromCodePoint(codePoint));
124 word_1 = '';
125 }
126 });
127 if (word_1.length) {
128 words.push(word_1);
129 }
130 }
131 };
132 while (!(bk = breaker.next()).done) {
133 _loop_1();
134 }
135 return words;
136};
137//# sourceMappingURL=text.js.map
Note: See TracBrowser for help on using the repository browser.