@textbus/platform-browser 5.4.3 → 5.4.4
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/_utils/uikit.d.ts +57 -0
- package/dist/index.esm.js +485 -115
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +489 -114
- package/dist/index.js.map +1 -1
- package/dist/magic-input.d.ts +17 -1
- package/dist/types.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -16,6 +16,14 @@ const core = require('@viewfly/core');
|
|
|
16
16
|
function _array_without_holes$2(arr) {
|
|
17
17
|
if (Array.isArray(arr)) return _array_like_to_array$2(arr);
|
|
18
18
|
}
|
|
19
|
+
function _instanceof$4(left, right) {
|
|
20
|
+
"@swc/helpers - instanceof";
|
|
21
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
22
|
+
return !!right[Symbol.hasInstance](left);
|
|
23
|
+
} else {
|
|
24
|
+
return left instanceof right;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
19
27
|
function _iterable_to_array$2(iter) {
|
|
20
28
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
21
29
|
}
|
|
@@ -33,6 +41,247 @@ function _unsupported_iterable_to_array$2(o, minLen) {
|
|
|
33
41
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
34
42
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
|
|
35
43
|
}
|
|
44
|
+
var OVERFLOW_CLIP_VALUES = new Set([
|
|
45
|
+
'auto',
|
|
46
|
+
'hidden',
|
|
47
|
+
'scroll',
|
|
48
|
+
'clip'
|
|
49
|
+
]);
|
|
50
|
+
function rectRight(r) {
|
|
51
|
+
return r.left + r.width;
|
|
52
|
+
}
|
|
53
|
+
function rectBottom(r) {
|
|
54
|
+
return r.top + r.height;
|
|
55
|
+
}
|
|
56
|
+
function isOverflowClipAxis(value) {
|
|
57
|
+
return OVERFLOW_CLIP_VALUES.has(value);
|
|
58
|
+
}
|
|
59
|
+
function readOverflowClipAxes(style) {
|
|
60
|
+
var overflow = style.overflow;
|
|
61
|
+
var overflowX = style.overflowX;
|
|
62
|
+
var overflowY = style.overflowY;
|
|
63
|
+
if (!isOverflowClipAxis(overflow) && !isOverflowClipAxis(overflowX) && !isOverflowClipAxis(overflowY)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
clipX: isOverflowClipAxis(overflowX) || isOverflowClipAxis(overflow),
|
|
68
|
+
clipY: isOverflowClipAxis(overflowY) || isOverflowClipAxis(overflow)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 一次遍历祖先链:缓存 overflow 轴信息,并收集滚动监听目标。
|
|
73
|
+
*/ function getOverflowClipContext(anchor, extraRoot) {
|
|
74
|
+
var _ref, _ref1;
|
|
75
|
+
var _clipAncestors_;
|
|
76
|
+
var clipAncestors = [];
|
|
77
|
+
var scrollContainers = new Set();
|
|
78
|
+
var node = anchor.nodeType === Node.ELEMENT_NODE ? anchor : anchor.parentNode;
|
|
79
|
+
while(node){
|
|
80
|
+
var _node_ownerDocument;
|
|
81
|
+
if (_instanceof$4(node, Element)) {
|
|
82
|
+
var flags = readOverflowClipAxes(getComputedStyle(node));
|
|
83
|
+
if (flags) {
|
|
84
|
+
clipAncestors.push({
|
|
85
|
+
element: node,
|
|
86
|
+
clipX: flags.clipX,
|
|
87
|
+
clipY: flags.clipY
|
|
88
|
+
});
|
|
89
|
+
scrollContainers.add(node);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (node === ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === void 0 ? void 0 : _node_ownerDocument.documentElement)) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
node = node.parentNode;
|
|
96
|
+
}
|
|
97
|
+
var doc = anchor.ownerDocument;
|
|
98
|
+
var documentElement = (_ref = doc === null || doc === void 0 ? void 0 : doc.documentElement) !== null && _ref !== void 0 ? _ref : document.documentElement;
|
|
99
|
+
scrollContainers.add(documentElement);
|
|
100
|
+
if (extraRoot) {
|
|
101
|
+
scrollContainers.add(extraRoot);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
clipAncestors: clipAncestors,
|
|
105
|
+
scrollContainers: _to_consumable_array$2(scrollContainers),
|
|
106
|
+
firstScrollContainer: (_ref1 = (_clipAncestors_ = clipAncestors[0]) === null || _clipAncestors_ === void 0 ? void 0 : _clipAncestors_.element) !== null && _ref1 !== void 0 ? _ref1 : documentElement
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function intersectRect(a, b) {
|
|
110
|
+
var left = Math.max(a.left, b.left);
|
|
111
|
+
var top = Math.max(a.top, b.top);
|
|
112
|
+
var right = Math.min(rectRight(a), rectRight(b));
|
|
113
|
+
var bottom = Math.min(rectBottom(a), rectBottom(b));
|
|
114
|
+
if (left >= right || top >= bottom) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
left: left,
|
|
119
|
+
top: top,
|
|
120
|
+
width: right - left,
|
|
121
|
+
height: bottom - top
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function rectContainsPoint(rect, x, y) {
|
|
125
|
+
return x >= rect.left && x <= rectRight(rect) && y >= rect.top && y <= rectBottom(rect);
|
|
126
|
+
}
|
|
127
|
+
function intersectRectWithClipAncestor(ancestor, visible) {
|
|
128
|
+
var el = ancestor.element;
|
|
129
|
+
var border = el.getBoundingClientRect();
|
|
130
|
+
var left = visible.left;
|
|
131
|
+
var top = visible.top;
|
|
132
|
+
var right = rectRight(visible);
|
|
133
|
+
var bottom = rectBottom(visible);
|
|
134
|
+
if (ancestor.clipX) {
|
|
135
|
+
var clipLeft = border.left + el.clientLeft;
|
|
136
|
+
var clipRight = clipLeft + el.clientWidth;
|
|
137
|
+
left = Math.max(left, clipLeft);
|
|
138
|
+
right = Math.min(right, clipRight);
|
|
139
|
+
}
|
|
140
|
+
if (ancestor.clipY) {
|
|
141
|
+
var clipTop = border.top + el.clientTop;
|
|
142
|
+
var clipBottom = clipTop + el.clientHeight;
|
|
143
|
+
top = Math.max(top, clipTop);
|
|
144
|
+
bottom = Math.min(bottom, clipBottom);
|
|
145
|
+
}
|
|
146
|
+
if (left >= right || top >= bottom) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
left: left,
|
|
151
|
+
top: top,
|
|
152
|
+
width: right - left,
|
|
153
|
+
height: bottom - top
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function getVisibleRectInOverflowClipsFromAncestors(rect, clipAncestors) {
|
|
157
|
+
var visible = rect;
|
|
158
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
159
|
+
try {
|
|
160
|
+
for(var _iterator = clipAncestors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
161
|
+
var ancestor = _step.value;
|
|
162
|
+
var next = intersectRectWithClipAncestor(ancestor, visible);
|
|
163
|
+
if (!next) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
visible = next;
|
|
167
|
+
}
|
|
168
|
+
} catch (err) {
|
|
169
|
+
_didIteratorError = true;
|
|
170
|
+
_iteratorError = err;
|
|
171
|
+
} finally{
|
|
172
|
+
try {
|
|
173
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
174
|
+
_iterator.return();
|
|
175
|
+
}
|
|
176
|
+
} finally{
|
|
177
|
+
if (_didIteratorError) {
|
|
178
|
+
throw _iteratorError;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return visible;
|
|
183
|
+
}
|
|
184
|
+
/** 锚点是否被 CSS 隐藏(opacity / visibility 等);不做点命中,避免 mask 层挡住误判 */ function isCaretAnchorCssVisible(anchor) {
|
|
185
|
+
var anchorEl = anchor.nodeType === Node.ELEMENT_NODE ? anchor : anchor.parentElement;
|
|
186
|
+
if (!(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.isConnected)) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
if (typeof anchorEl.checkVisibility === 'function') {
|
|
190
|
+
return anchorEl.checkVisibility({
|
|
191
|
+
checkOpacity: true,
|
|
192
|
+
checkVisibilityCSS: true
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
var CLIP_INSET_EPSILON = 0.5;
|
|
198
|
+
function clipPathInsetFromVisibleRegion(elRect, visible) {
|
|
199
|
+
var top = Math.max(0, visible.top - elRect.top);
|
|
200
|
+
var left = Math.max(0, visible.left - elRect.left);
|
|
201
|
+
var bottom = Math.max(0, rectBottom(elRect) - rectBottom(visible));
|
|
202
|
+
var right = Math.max(0, rectRight(elRect) - rectRight(visible));
|
|
203
|
+
if (top < CLIP_INSET_EPSILON && left < CLIP_INSET_EPSILON && bottom < CLIP_INSET_EPSILON && right < CLIP_INSET_EPSILON) {
|
|
204
|
+
return 'none';
|
|
205
|
+
}
|
|
206
|
+
return "inset(".concat(top, "px ").concat(right, "px ").concat(bottom, "px ").concat(left, "px)");
|
|
207
|
+
}
|
|
208
|
+
/** 根据行高与内容矩形计算光标盒高度与顶部(视口坐标) */ function measureCaretBoxLayout(contentRect, style) {
|
|
209
|
+
var fontSize = style.fontSize, lineHeight = style.lineHeight;
|
|
210
|
+
var height;
|
|
211
|
+
if (isNaN(+lineHeight)) {
|
|
212
|
+
var f = parseFloat(lineHeight);
|
|
213
|
+
height = isNaN(f) ? parseFloat(fontSize) : f;
|
|
214
|
+
} else {
|
|
215
|
+
height = parseFloat(fontSize) * parseFloat(lineHeight);
|
|
216
|
+
}
|
|
217
|
+
var boxHeight = Math.max(Math.floor(Math.max(height, contentRect.height)), 12);
|
|
218
|
+
var rectTop = contentRect.top;
|
|
219
|
+
if (contentRect.height < height) {
|
|
220
|
+
rectTop -= (height - contentRect.height) / 2;
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
boxHeight: boxHeight,
|
|
224
|
+
rectTop: Math.floor(rectTop)
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/** 测量行内旋转角度(writing-mode 继承) */ function measureInlineCaretRotate(node, initialRotate, writingMode) {
|
|
228
|
+
var rotate = initialRotate;
|
|
229
|
+
if (rotate !== 0) {
|
|
230
|
+
var hackEle = document.createElement('span');
|
|
231
|
+
hackEle.style.cssText = 'display: inline-block; width: 10px; height: 10px; position: relative; contain: layout style size; writing-mode: inherit';
|
|
232
|
+
var pointEle = document.createElement('span');
|
|
233
|
+
pointEle.style.cssText = 'position: absolute; left: 0; top: 0; width:0;height:0';
|
|
234
|
+
hackEle.append(pointEle);
|
|
235
|
+
node.append(hackEle);
|
|
236
|
+
var p1 = pointEle.getBoundingClientRect();
|
|
237
|
+
pointEle.style.right = '0';
|
|
238
|
+
pointEle.style.left = '';
|
|
239
|
+
var p2 = pointEle.getBoundingClientRect();
|
|
240
|
+
rotate = Math.atan2(p1.y - p2.y, p1.x - p2.x) * 180 / Math.PI;
|
|
241
|
+
hackEle.remove();
|
|
242
|
+
}
|
|
243
|
+
if (writingMode === 'vertical-lr' || writingMode === 'vertical-rl') {
|
|
244
|
+
rotate += 90;
|
|
245
|
+
}
|
|
246
|
+
return rotate;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 在 element 样式已写入后调用:计算裁剪、是否移出视口及对外事件数据。
|
|
250
|
+
*/ function computeCaretPresentation(options) {
|
|
251
|
+
var anchor = options.anchor, maskRect = options.maskRect, clipAncestors = options.clipAncestors, maskLeft = options.maskLeft, maskTop = options.maskTop, boxHeight = options.boxHeight, rectTop = options.rectTop, contentRect = options.contentRect, fontSize = options.fontSize, color = options.color, measureElementRect = options.measureElementRect;
|
|
252
|
+
var caretCenterX = contentRect.left + contentRect.width / 2;
|
|
253
|
+
var caretCenterY = rectTop + boxHeight / 2;
|
|
254
|
+
var layoutElRect = {
|
|
255
|
+
left: maskRect.left + maskLeft,
|
|
256
|
+
top: maskRect.top + maskTop,
|
|
257
|
+
width: 2,
|
|
258
|
+
height: boxHeight
|
|
259
|
+
};
|
|
260
|
+
var visibleRect = getVisibleRectInOverflowClipsFromAncestors(layoutElRect, clipAncestors);
|
|
261
|
+
visibleRect = visibleRect ? intersectRect(visibleRect, maskRect) : null;
|
|
262
|
+
var inClipBounds = !!visibleRect && rectContainsPoint(visibleRect, caretCenterX, caretCenterY);
|
|
263
|
+
var outOfView = !inClipBounds || !isCaretAnchorCssVisible(anchor);
|
|
264
|
+
var clipPath = 'none';
|
|
265
|
+
if (!outOfView && visibleRect) {
|
|
266
|
+
clipPath = clipPathInsetFromVisibleRegion(measureElementRect(), visibleRect);
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
outOfView: outOfView,
|
|
270
|
+
clipPath: clipPath,
|
|
271
|
+
layoutElRect: layoutElRect,
|
|
272
|
+
position: {
|
|
273
|
+
left: maskLeft,
|
|
274
|
+
top: rectTop,
|
|
275
|
+
height: boxHeight
|
|
276
|
+
},
|
|
277
|
+
caretColor: color === 'rgba(0, 0, 0, 0)' ? '#000' : color,
|
|
278
|
+
style: {
|
|
279
|
+
height: boxHeight + 'px',
|
|
280
|
+
lineHeight: boxHeight + 'px',
|
|
281
|
+
fontSize: fontSize
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
36
285
|
function createElement(tagName) {
|
|
37
286
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
38
287
|
var el = document.createElement(tagName);
|
|
@@ -213,7 +462,7 @@ function _define_property$6(obj, key, value) {
|
|
|
213
462
|
}
|
|
214
463
|
return obj;
|
|
215
464
|
}
|
|
216
|
-
function _instanceof$
|
|
465
|
+
function _instanceof$3(left, right) {
|
|
217
466
|
"@swc/helpers - instanceof";
|
|
218
467
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
219
468
|
return !!right[Symbol.hasInstance](left);
|
|
@@ -320,7 +569,7 @@ exports.Parser = /*#__PURE__*/ function() {
|
|
|
320
569
|
if (!result) {
|
|
321
570
|
return;
|
|
322
571
|
}
|
|
323
|
-
if (_instanceof$
|
|
572
|
+
if (_instanceof$3(result, core$1.Slot)) {
|
|
324
573
|
result.toDelta().forEach(function(i) {
|
|
325
574
|
return slot.insert(i.insert, i.formats);
|
|
326
575
|
});
|
|
@@ -442,6 +691,15 @@ function _class_call_check$6(instance, Constructor) {
|
|
|
442
691
|
throw new TypeError("Cannot call a class as a function");
|
|
443
692
|
}
|
|
444
693
|
}
|
|
694
|
+
function caretPositionEqual(a, b) {
|
|
695
|
+
if (a === b) {
|
|
696
|
+
return true;
|
|
697
|
+
}
|
|
698
|
+
if (a === null || b === null) {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
return a.left === b.left && a.top === b.top && a.height === b.height;
|
|
702
|
+
}
|
|
445
703
|
var Input = function Input() {
|
|
446
704
|
_class_call_check$6(this, Input);
|
|
447
705
|
};
|
|
@@ -526,7 +784,7 @@ var DomAdapter = /*#__PURE__*/ function(Adapter) {
|
|
|
526
784
|
_this = _call_super$2(this, DomAdapter, arguments), _define_property$5(_this, "onViewUpdated", new stream.Subject()), _define_property$5(_this, "host", createElement('div', {
|
|
527
785
|
styles: {
|
|
528
786
|
cursor: 'text',
|
|
529
|
-
|
|
787
|
+
overflowWrap: 'break-word',
|
|
530
788
|
boxSizing: 'border-box',
|
|
531
789
|
flex: 1,
|
|
532
790
|
outline: 'none'
|
|
@@ -574,7 +832,7 @@ function _define_property$4(obj, key, value) {
|
|
|
574
832
|
}
|
|
575
833
|
return obj;
|
|
576
834
|
}
|
|
577
|
-
function _instanceof$
|
|
835
|
+
function _instanceof$2(left, right) {
|
|
578
836
|
"@swc/helpers - instanceof";
|
|
579
837
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
580
838
|
return !!right[Symbol.hasInstance](left);
|
|
@@ -1081,7 +1339,7 @@ exports.SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1081
1339
|
try {
|
|
1082
1340
|
for(var _iterator = nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1083
1341
|
var node = _step.value;
|
|
1084
|
-
if (_instanceof$
|
|
1342
|
+
if (_instanceof$2(node, Text)) {
|
|
1085
1343
|
continue;
|
|
1086
1344
|
}
|
|
1087
1345
|
if (node.nodeName === 'BR') {
|
|
@@ -1125,7 +1383,7 @@ exports.SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1125
1383
|
try {
|
|
1126
1384
|
for(var _iterator1 = nodes[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
1127
1385
|
var node1 = _step1.value;
|
|
1128
|
-
if (_instanceof$
|
|
1386
|
+
if (_instanceof$2(node1, Element)) {
|
|
1129
1387
|
if (node1.tagName === 'BR') {
|
|
1130
1388
|
var position1 = this.domAdapter.getLocationByNativeNode(node1);
|
|
1131
1389
|
if (position1) {
|
|
@@ -1353,14 +1611,6 @@ function _inherits$1(subClass, superClass) {
|
|
|
1353
1611
|
});
|
|
1354
1612
|
if (superClass) _set_prototype_of$1(subClass, superClass);
|
|
1355
1613
|
}
|
|
1356
|
-
function _instanceof$2(left, right) {
|
|
1357
|
-
"@swc/helpers - instanceof";
|
|
1358
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1359
|
-
return !!right[Symbol.hasInstance](left);
|
|
1360
|
-
} else {
|
|
1361
|
-
return left instanceof right;
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
1614
|
function _possible_constructor_return$1(self, call) {
|
|
1365
1615
|
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
1366
1616
|
return call;
|
|
@@ -1412,7 +1662,13 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1412
1662
|
_define_property$3(this, "caret", void 0);
|
|
1413
1663
|
_define_property$3(this, "_display", void 0);
|
|
1414
1664
|
_define_property$3(this, "flashing", void 0);
|
|
1665
|
+
/** 被 overflow 裁出可视区(不用 display:none,避免触发 Input.hide) */ _define_property$3(this, "caretClippedOut", void 0);
|
|
1415
1666
|
_define_property$3(this, "subscription", void 0);
|
|
1667
|
+
_define_property$3(this, "scrollSubscription", void 0);
|
|
1668
|
+
_define_property$3(this, "scrollRaf", void 0);
|
|
1669
|
+
_define_property$3(this, "clipContext", void 0);
|
|
1670
|
+
_define_property$3(this, "clipContextAnchor", void 0);
|
|
1671
|
+
_define_property$3(this, "scrollListenerAnchor", void 0);
|
|
1416
1672
|
_define_property$3(this, "positionChangeEvent", void 0);
|
|
1417
1673
|
_define_property$3(this, "styleChangeEvent", void 0);
|
|
1418
1674
|
_define_property$3(this, "oldRange", void 0);
|
|
@@ -1429,11 +1685,17 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1429
1685
|
this.timer = null;
|
|
1430
1686
|
this._display = true;
|
|
1431
1687
|
this.flashing = true;
|
|
1688
|
+
this.caretClippedOut = false;
|
|
1432
1689
|
this.subscription = new stream.Subscription();
|
|
1690
|
+
this.scrollSubscription = new stream.Subscription();
|
|
1691
|
+
this.scrollRaf = 0;
|
|
1692
|
+
this.clipContext = null;
|
|
1693
|
+
this.clipContextAnchor = null;
|
|
1694
|
+
this.scrollListenerAnchor = null;
|
|
1433
1695
|
this.positionChangeEvent = new stream.Subject();
|
|
1434
1696
|
this.styleChangeEvent = new stream.Subject();
|
|
1435
1697
|
this.oldRange = null;
|
|
1436
|
-
this.onPositionChange = this.positionChangeEvent.pipe(stream.distinctUntilChanged());
|
|
1698
|
+
this.onPositionChange = this.positionChangeEvent.pipe(stream.distinctUntilChanged(caretPositionEqual));
|
|
1437
1699
|
this.onStyleChange = this.styleChangeEvent.asObservable();
|
|
1438
1700
|
this.elementRef = createElement('div', {
|
|
1439
1701
|
styles: {
|
|
@@ -1474,14 +1736,17 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1474
1736
|
},
|
|
1475
1737
|
set: function set(v) {
|
|
1476
1738
|
this._display = v;
|
|
1477
|
-
this.
|
|
1739
|
+
if (!this.caretClippedOut) {
|
|
1740
|
+
this.caret.style.visibility = v ? 'visible' : 'hidden';
|
|
1741
|
+
}
|
|
1478
1742
|
}
|
|
1479
1743
|
},
|
|
1480
1744
|
{
|
|
1481
1745
|
key: "refresh",
|
|
1482
1746
|
value: function refresh() {
|
|
1483
|
-
|
|
1484
|
-
|
|
1747
|
+
var _this_oldRange;
|
|
1748
|
+
if ((_this_oldRange = this.oldRange) === null || _this_oldRange === void 0 ? void 0 : _this_oldRange.collapsed) {
|
|
1749
|
+
this.updateCursorPosition(this.oldRange);
|
|
1485
1750
|
}
|
|
1486
1751
|
}
|
|
1487
1752
|
},
|
|
@@ -1493,8 +1758,23 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1493
1758
|
if (restart || this.scheduler.lastChangesHasLocalUpdate) {
|
|
1494
1759
|
clearTimeout(this.timer);
|
|
1495
1760
|
}
|
|
1761
|
+
if (range.collapsed && (restart || this.scheduler.lastChangesHasLocalUpdate)) {
|
|
1762
|
+
this._display = true;
|
|
1763
|
+
}
|
|
1496
1764
|
this.updateCursorPosition(range);
|
|
1497
1765
|
if (range.collapsed) {
|
|
1766
|
+
var anchor = range.startContainer.nodeType === Node.ELEMENT_NODE ? range.startContainer : range.startContainer.parentNode;
|
|
1767
|
+
if (anchor) {
|
|
1768
|
+
this.bindScrollListeners(anchor);
|
|
1769
|
+
}
|
|
1770
|
+
if (restart) {
|
|
1771
|
+
requestAnimationFrame(function() {
|
|
1772
|
+
var _this_oldRange;
|
|
1773
|
+
if ((_this_oldRange = _this.oldRange) === null || _this_oldRange === void 0 ? void 0 : _this_oldRange.collapsed) {
|
|
1774
|
+
_this.updateCursorPosition(_this.oldRange);
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1498
1778
|
if (restart || this.scheduler.lastChangesHasLocalUpdate) {
|
|
1499
1779
|
this.display = true;
|
|
1500
1780
|
var toggleShowHide = function toggleShowHide1() {
|
|
@@ -1505,6 +1785,7 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1505
1785
|
this.timer = setTimeout(toggleShowHide, 400);
|
|
1506
1786
|
}
|
|
1507
1787
|
} else {
|
|
1788
|
+
this.unbindScrollListeners();
|
|
1508
1789
|
this.display = false;
|
|
1509
1790
|
clearTimeout(this.timer);
|
|
1510
1791
|
}
|
|
@@ -1513,8 +1794,14 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1513
1794
|
{
|
|
1514
1795
|
key: "hide",
|
|
1515
1796
|
value: function hide() {
|
|
1797
|
+
this.unbindScrollListeners();
|
|
1798
|
+
this.clearClipContext();
|
|
1516
1799
|
this.display = false;
|
|
1517
1800
|
clearTimeout(this.timer);
|
|
1801
|
+
this.caretClippedOut = false;
|
|
1802
|
+
this.elementRef.style.clipPath = 'none';
|
|
1803
|
+
this.elementRef.style.visibility = '';
|
|
1804
|
+
this.caret.style.visibility = '';
|
|
1518
1805
|
this.positionChangeEvent.next(null);
|
|
1519
1806
|
}
|
|
1520
1807
|
},
|
|
@@ -1522,127 +1809,210 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1522
1809
|
key: "destroy",
|
|
1523
1810
|
value: function destroy() {
|
|
1524
1811
|
clearTimeout(this.timer);
|
|
1525
|
-
|
|
1812
|
+
this.unbindScrollListeners();
|
|
1526
1813
|
this.subscription.unsubscribe();
|
|
1527
1814
|
}
|
|
1528
1815
|
},
|
|
1816
|
+
{
|
|
1817
|
+
key: "bindScrollListeners",
|
|
1818
|
+
value: function bindScrollListeners(anchor) {
|
|
1819
|
+
var _this = this;
|
|
1820
|
+
var _anchor_ownerDocument;
|
|
1821
|
+
if (this.scrollListenerAnchor === anchor) {
|
|
1822
|
+
return;
|
|
1823
|
+
}
|
|
1824
|
+
this.unbindScrollListeners();
|
|
1825
|
+
this.scrollListenerAnchor = anchor;
|
|
1826
|
+
var onScroll = function onScroll() {
|
|
1827
|
+
if (!_this.oldRange || _this.scrollRaf) {
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
_this.scrollRaf = requestAnimationFrame(function() {
|
|
1831
|
+
_this.scrollRaf = 0;
|
|
1832
|
+
if (_this.oldRange) {
|
|
1833
|
+
_this.updateCursorPosition(_this.oldRange);
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
};
|
|
1837
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1838
|
+
try {
|
|
1839
|
+
for(var _iterator = this.ensureClipContext(anchor).scrollContainers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1840
|
+
var el = _step.value;
|
|
1841
|
+
this.scrollSubscription.add(stream.fromEvent(el, 'scroll').subscribe(onScroll));
|
|
1842
|
+
}
|
|
1843
|
+
} catch (err) {
|
|
1844
|
+
_didIteratorError = true;
|
|
1845
|
+
_iteratorError = err;
|
|
1846
|
+
} finally{
|
|
1847
|
+
try {
|
|
1848
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1849
|
+
_iterator.return();
|
|
1850
|
+
}
|
|
1851
|
+
} finally{
|
|
1852
|
+
if (_didIteratorError) {
|
|
1853
|
+
throw _iteratorError;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
var win = (_anchor_ownerDocument = anchor.ownerDocument) === null || _anchor_ownerDocument === void 0 ? void 0 : _anchor_ownerDocument.defaultView;
|
|
1858
|
+
if (win) {
|
|
1859
|
+
this.scrollSubscription.add(stream.fromEvent(win, 'scroll').subscribe(onScroll));
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
},
|
|
1863
|
+
{
|
|
1864
|
+
key: "unbindScrollListeners",
|
|
1865
|
+
value: function unbindScrollListeners() {
|
|
1866
|
+
if (this.scrollRaf) {
|
|
1867
|
+
cancelAnimationFrame(this.scrollRaf);
|
|
1868
|
+
this.scrollRaf = 0;
|
|
1869
|
+
}
|
|
1870
|
+
this.scrollSubscription.unsubscribe();
|
|
1871
|
+
this.scrollSubscription = new stream.Subscription();
|
|
1872
|
+
this.scrollListenerAnchor = null;
|
|
1873
|
+
}
|
|
1874
|
+
},
|
|
1875
|
+
{
|
|
1876
|
+
key: "ensureClipContext",
|
|
1877
|
+
value: function ensureClipContext(anchor) {
|
|
1878
|
+
if (this.clipContextAnchor !== anchor) {
|
|
1879
|
+
this.clipContextAnchor = anchor;
|
|
1880
|
+
this.clipContext = getOverflowClipContext(anchor, this.editorMask);
|
|
1881
|
+
}
|
|
1882
|
+
return this.clipContext;
|
|
1883
|
+
}
|
|
1884
|
+
},
|
|
1885
|
+
{
|
|
1886
|
+
key: "clearClipContext",
|
|
1887
|
+
value: function clearClipContext() {
|
|
1888
|
+
this.clipContext = null;
|
|
1889
|
+
this.clipContextAnchor = null;
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1529
1892
|
{
|
|
1530
1893
|
key: "updateCursorPosition",
|
|
1531
1894
|
value: function updateCursorPosition(nativeRange) {
|
|
1532
|
-
var
|
|
1533
|
-
var node =
|
|
1534
|
-
if (
|
|
1895
|
+
var _this = this;
|
|
1896
|
+
var node = this.resolveCaretAnchor(nativeRange);
|
|
1897
|
+
if (!node) {
|
|
1535
1898
|
this.positionChangeEvent.next(null);
|
|
1536
1899
|
return;
|
|
1537
1900
|
}
|
|
1538
|
-
|
|
1539
|
-
if (compositionNode) {
|
|
1540
|
-
nativeRange = nativeRange.cloneRange();
|
|
1541
|
-
nativeRange.selectNodeContents(compositionNode);
|
|
1542
|
-
nativeRange.collapse();
|
|
1543
|
-
}
|
|
1901
|
+
nativeRange = this.normalizeCollapsedRange(nativeRange);
|
|
1544
1902
|
this.caret.style.display = nativeRange.collapsed ? 'block' : 'none';
|
|
1545
1903
|
if (!nativeRange.collapsed) {
|
|
1546
1904
|
return;
|
|
1547
1905
|
}
|
|
1548
|
-
var
|
|
1549
|
-
var
|
|
1550
|
-
var
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1906
|
+
var contentRect = getLayoutRectByRange(nativeRange);
|
|
1907
|
+
var nodeStyle = getComputedStyle(node);
|
|
1908
|
+
var _measureCaretBoxLayout = measureCaretBoxLayout(contentRect, nodeStyle), boxHeight = _measureCaretBoxLayout.boxHeight, rectTop = _measureCaretBoxLayout.rectTop;
|
|
1909
|
+
var maskRect = this.editorMask.getBoundingClientRect();
|
|
1910
|
+
var clipContext = this.ensureClipContext(node);
|
|
1911
|
+
var maskLeft = Math.floor(contentRect.left + contentRect.width / 2 - maskRect.left);
|
|
1912
|
+
var maskTop = Math.floor(rectTop - maskRect.top);
|
|
1913
|
+
var initialRotate = Math.round(Math.atan2(contentRect.width, contentRect.height) * 180 / Math.PI);
|
|
1914
|
+
var rotate = measureInlineCaretRotate(node, initialRotate, nodeStyle.writingMode);
|
|
1915
|
+
this.applyCaretElementLayout(maskLeft, maskTop, boxHeight, nodeStyle.fontSize, rotate);
|
|
1916
|
+
var presentation = computeCaretPresentation({
|
|
1917
|
+
anchor: node,
|
|
1918
|
+
maskRect: maskRect,
|
|
1919
|
+
clipAncestors: clipContext.clipAncestors,
|
|
1920
|
+
maskLeft: maskLeft,
|
|
1921
|
+
maskTop: maskTop,
|
|
1922
|
+
boxHeight: boxHeight,
|
|
1923
|
+
rectTop: rectTop,
|
|
1924
|
+
contentRect: contentRect,
|
|
1925
|
+
fontSize: nodeStyle.fontSize,
|
|
1926
|
+
color: nodeStyle.color,
|
|
1927
|
+
measureElementRect: function measureElementRect() {
|
|
1928
|
+
return _this.elementRef.getBoundingClientRect();
|
|
1557
1929
|
}
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
var
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
var pointEle = document.createElement('span');
|
|
1579
|
-
pointEle.style.cssText = 'position: absolute; left: 0; top: 0; width:0;height:0';
|
|
1580
|
-
hackEle.append(pointEle);
|
|
1581
|
-
node.append(hackEle);
|
|
1582
|
-
var p1 = pointEle.getBoundingClientRect();
|
|
1583
|
-
pointEle.style.right = '0';
|
|
1584
|
-
pointEle.style.left = '';
|
|
1585
|
-
var p2 = pointEle.getBoundingClientRect();
|
|
1586
|
-
var x = p1.x - p2.x;
|
|
1587
|
-
var y = p1.y - p2.y;
|
|
1588
|
-
rotate = Math.atan2(y, x) * 180 / Math.PI;
|
|
1589
|
-
hackEle.remove();
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
if (writingMode === 'vertical-lr' || writingMode === 'vertical-rl') {
|
|
1593
|
-
rotate += 90;
|
|
1930
|
+
});
|
|
1931
|
+
this.applyCaretPresentation(presentation);
|
|
1932
|
+
this.emitCaretPresentation(presentation);
|
|
1933
|
+
this.scrollCaretIntoViewIfNeeded(presentation.layoutElRect, clipContext);
|
|
1934
|
+
}
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
key: "resolveCaretAnchor",
|
|
1938
|
+
value: function resolveCaretAnchor(nativeRange) {
|
|
1939
|
+
var startContainer = nativeRange.startContainer;
|
|
1940
|
+
var node = startContainer.nodeType === Node.ELEMENT_NODE ? startContainer : startContainer.parentNode;
|
|
1941
|
+
return (node === null || node === void 0 ? void 0 : node.nodeType) === Node.ELEMENT_NODE ? node : null;
|
|
1942
|
+
}
|
|
1943
|
+
},
|
|
1944
|
+
{
|
|
1945
|
+
key: "normalizeCollapsedRange",
|
|
1946
|
+
value: function normalizeCollapsedRange(nativeRange) {
|
|
1947
|
+
var compositionNode = this.domRenderer.compositionNode;
|
|
1948
|
+
if (!compositionNode) {
|
|
1949
|
+
return nativeRange;
|
|
1594
1950
|
}
|
|
1951
|
+
var range = nativeRange.cloneRange();
|
|
1952
|
+
range.selectNodeContents(compositionNode);
|
|
1953
|
+
range.collapse();
|
|
1954
|
+
return range;
|
|
1955
|
+
}
|
|
1956
|
+
},
|
|
1957
|
+
{
|
|
1958
|
+
key: "applyCaretElementLayout",
|
|
1959
|
+
value: function applyCaretElementLayout(maskLeft, maskTop, boxHeight, fontSize, rotate) {
|
|
1595
1960
|
Object.assign(this.elementRef.style, {
|
|
1596
|
-
left:
|
|
1597
|
-
top:
|
|
1961
|
+
left: maskLeft + 'px',
|
|
1962
|
+
top: maskTop + 'px',
|
|
1598
1963
|
height: boxHeight + 'px',
|
|
1599
1964
|
lineHeight: boxHeight + 'px',
|
|
1600
1965
|
fontSize: fontSize,
|
|
1601
1966
|
transform: "rotate(".concat(rotate, "deg)")
|
|
1602
1967
|
});
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
this.
|
|
1616
|
-
|
|
1617
|
-
var scrollContainer = this.getScrollContainer(startContainer);
|
|
1618
|
-
var scrollRect = scrollContainer === document.documentElement ? {
|
|
1619
|
-
top: 0,
|
|
1620
|
-
bottom: document.documentElement.clientHeight
|
|
1621
|
-
} : scrollContainer.getBoundingClientRect();
|
|
1622
|
-
var limit = this.getLimit();
|
|
1623
|
-
var top1 = Math.max(limit.top, scrollRect.top);
|
|
1624
|
-
var bottom = Math.min(limit.bottom, scrollRect.bottom);
|
|
1625
|
-
if (selfRect.top < top1) {
|
|
1626
|
-
scrollContainer.scrollTop -= top1 - selfRect.top;
|
|
1627
|
-
} else if (selfRect.bottom > bottom) {
|
|
1628
|
-
scrollContainer.scrollTop += selfRect.bottom - bottom;
|
|
1629
|
-
}
|
|
1968
|
+
}
|
|
1969
|
+
},
|
|
1970
|
+
{
|
|
1971
|
+
key: "applyCaretPresentation",
|
|
1972
|
+
value: function applyCaretPresentation(presentation) {
|
|
1973
|
+
this.caretClippedOut = presentation.outOfView;
|
|
1974
|
+
if (presentation.outOfView) {
|
|
1975
|
+
this.elementRef.style.clipPath = 'none';
|
|
1976
|
+
this.elementRef.style.visibility = 'hidden';
|
|
1977
|
+
this.caret.style.visibility = 'hidden';
|
|
1978
|
+
} else {
|
|
1979
|
+
this.elementRef.style.clipPath = presentation.clipPath;
|
|
1980
|
+
this.elementRef.style.visibility = '';
|
|
1981
|
+
this.caret.style.visibility = this._display ? 'visible' : 'hidden';
|
|
1630
1982
|
}
|
|
1983
|
+
this.caret.style.backgroundColor = presentation.caretColor;
|
|
1631
1984
|
}
|
|
1632
1985
|
},
|
|
1633
1986
|
{
|
|
1634
|
-
key: "
|
|
1635
|
-
value: function
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1987
|
+
key: "emitCaretPresentation",
|
|
1988
|
+
value: function emitCaretPresentation(presentation) {
|
|
1989
|
+
this.styleChangeEvent.next(presentation.style);
|
|
1990
|
+
this.positionChangeEvent.next(presentation.position);
|
|
1991
|
+
}
|
|
1992
|
+
},
|
|
1993
|
+
{
|
|
1994
|
+
key: "scrollCaretIntoViewIfNeeded",
|
|
1995
|
+
value: function scrollCaretIntoViewIfNeeded(layoutElRect, clipContext) {
|
|
1996
|
+
var _scrollContainer_ownerDocument;
|
|
1997
|
+
if (!this.changeFromSelf) {
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
2000
|
+
this.changeFromSelf = false;
|
|
2001
|
+
var scrollContainer = clipContext.firstScrollContainer;
|
|
2002
|
+
var doc = (_scrollContainer_ownerDocument = scrollContainer.ownerDocument) !== null && _scrollContainer_ownerDocument !== void 0 ? _scrollContainer_ownerDocument : document;
|
|
2003
|
+
var scrollRect = scrollContainer === doc.documentElement ? {
|
|
2004
|
+
top: 0,
|
|
2005
|
+
bottom: doc.documentElement.clientHeight
|
|
2006
|
+
} : scrollContainer.getBoundingClientRect();
|
|
2007
|
+
var limit = this.getLimit();
|
|
2008
|
+
var scrollTop = Math.max(limit.top, scrollRect.top);
|
|
2009
|
+
var scrollBottom = Math.min(limit.bottom, scrollRect.bottom);
|
|
2010
|
+
var layoutBottom = layoutElRect.top + layoutElRect.height;
|
|
2011
|
+
if (layoutElRect.top < scrollTop) {
|
|
2012
|
+
scrollContainer.scrollTop -= scrollTop - layoutElRect.top;
|
|
2013
|
+
} else if (layoutBottom > scrollBottom) {
|
|
2014
|
+
scrollContainer.scrollTop += layoutBottom - scrollBottom;
|
|
1644
2015
|
}
|
|
1645
|
-
return document.documentElement;
|
|
1646
2016
|
}
|
|
1647
2017
|
}
|
|
1648
2018
|
]);
|
|
@@ -2538,7 +2908,7 @@ var NativeCaret = /*#__PURE__*/ function() {
|
|
|
2538
2908
|
_define_property$1(this, "_nativeRange", null);
|
|
2539
2909
|
_define_property$1(this, "subs", []);
|
|
2540
2910
|
_define_property$1(this, "positionChangeEvent", new stream.Subject());
|
|
2541
|
-
this.onPositionChange = this.positionChangeEvent.pipe(stream.distinctUntilChanged());
|
|
2911
|
+
this.onPositionChange = this.positionChangeEvent.pipe(stream.distinctUntilChanged(caretPositionEqual));
|
|
2542
2912
|
}
|
|
2543
2913
|
_create_class$1(NativeCaret, [
|
|
2544
2914
|
{
|
|
@@ -3391,11 +3761,16 @@ exports.Input = Input;
|
|
|
3391
3761
|
exports.VIEW_CONTAINER = VIEW_CONTAINER;
|
|
3392
3762
|
exports.VIEW_DOCUMENT = VIEW_DOCUMENT;
|
|
3393
3763
|
exports.VIEW_MASK = VIEW_MASK;
|
|
3764
|
+
exports.caretPositionEqual = caretPositionEqual;
|
|
3765
|
+
exports.computeCaretPresentation = computeCaretPresentation;
|
|
3394
3766
|
exports.createElement = createElement;
|
|
3395
3767
|
exports.getLayoutRectByRange = getLayoutRectByRange;
|
|
3768
|
+
exports.getOverflowClipContext = getOverflowClipContext;
|
|
3396
3769
|
exports.isFirefox = isFirefox;
|
|
3397
3770
|
exports.isMac = isMac;
|
|
3398
3771
|
exports.isMobileBrowser = isMobileBrowser;
|
|
3399
3772
|
exports.isSafari = isSafari;
|
|
3400
3773
|
exports.isWindows = isWindows;
|
|
3774
|
+
exports.measureCaretBoxLayout = measureCaretBoxLayout;
|
|
3775
|
+
exports.measureInlineCaretRotate = measureInlineCaretRotate;
|
|
3401
3776
|
//# sourceMappingURL=index.js.map
|