@visactor/vrender 0.19.13 → 0.19.14
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/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/dist/index.es.js +509 -13
- package/dist/index.js +511 -12
- package/dist/index.min.js +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1299,6 +1299,18 @@
|
|
|
1299
1299
|
};
|
|
1300
1300
|
var isObject$1 = isObject;
|
|
1301
1301
|
|
|
1302
|
+
const isObjectLike = value => "object" == typeof value && null !== value;
|
|
1303
|
+
var isObjectLike$1 = isObjectLike;
|
|
1304
|
+
|
|
1305
|
+
const isPlainObject = function (value) {
|
|
1306
|
+
if (!isObjectLike$1(value) || !isType$1(value, "Object")) return !1;
|
|
1307
|
+
if (null === Object.getPrototypeOf(value)) return !0;
|
|
1308
|
+
let proto = value;
|
|
1309
|
+
for (; null !== Object.getPrototypeOf(proto);) proto = Object.getPrototypeOf(proto);
|
|
1310
|
+
return Object.getPrototypeOf(value) === proto;
|
|
1311
|
+
};
|
|
1312
|
+
var isPlainObject$1 = isPlainObject;
|
|
1313
|
+
|
|
1302
1314
|
const isUndefined = value => void 0 === value;
|
|
1303
1315
|
var isUndefined$1 = isUndefined;
|
|
1304
1316
|
|
|
@@ -1312,6 +1324,11 @@
|
|
|
1312
1324
|
const isArray = value => Array.isArray ? Array.isArray(value) : isType$1(value, "Array");
|
|
1313
1325
|
var isArray$1 = isArray;
|
|
1314
1326
|
|
|
1327
|
+
const isArrayLike = function (value) {
|
|
1328
|
+
return null !== value && "function" != typeof value && Number.isFinite(value.length);
|
|
1329
|
+
};
|
|
1330
|
+
var isArrayLike$1 = isArrayLike;
|
|
1331
|
+
|
|
1315
1332
|
const isNumber = function (value) {
|
|
1316
1333
|
let fuzzy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
|
|
1317
1334
|
const type = typeof value;
|
|
@@ -1332,6 +1349,56 @@
|
|
|
1332
1349
|
has = (object, key) => null != object && hasOwnProperty.call(object, key);
|
|
1333
1350
|
var has$1 = has;
|
|
1334
1351
|
|
|
1352
|
+
function baseMerge(target, source) {
|
|
1353
|
+
let shallowArray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
|
|
1354
|
+
if (source) {
|
|
1355
|
+
if (target === source) return;
|
|
1356
|
+
if (isValid$1(source) && "object" == typeof source) {
|
|
1357
|
+
const iterable = Object(source),
|
|
1358
|
+
props = [];
|
|
1359
|
+
for (const key in iterable) props.push(key);
|
|
1360
|
+
let {
|
|
1361
|
+
length: length
|
|
1362
|
+
} = props,
|
|
1363
|
+
propIndex = -1;
|
|
1364
|
+
for (; length--;) {
|
|
1365
|
+
const key = props[++propIndex];
|
|
1366
|
+
isValid$1(iterable[key]) && "object" == typeof iterable[key] ? baseMergeDeep(target, source, key, shallowArray) : assignMergeValue(target, key, iterable[key]);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
function baseMergeDeep(target, source, key) {
|
|
1372
|
+
let shallowArray = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !1;
|
|
1373
|
+
const objValue = target[key],
|
|
1374
|
+
srcValue = source[key];
|
|
1375
|
+
let newValue = source[key],
|
|
1376
|
+
isCommon = !0;
|
|
1377
|
+
if (isArray$1(srcValue)) {
|
|
1378
|
+
if (shallowArray) newValue = [];else if (isArray$1(objValue)) newValue = objValue;else if (isArrayLike$1(objValue)) {
|
|
1379
|
+
newValue = new Array(objValue.length);
|
|
1380
|
+
let index = -1;
|
|
1381
|
+
const length = objValue.length;
|
|
1382
|
+
for (; ++index < length;) newValue[index] = objValue[index];
|
|
1383
|
+
}
|
|
1384
|
+
} else isPlainObject$1(srcValue) ? (newValue = objValue, "function" != typeof objValue && "object" == typeof objValue || (newValue = {})) : isCommon = !1;
|
|
1385
|
+
isCommon && baseMerge(newValue, srcValue, shallowArray), assignMergeValue(target, key, newValue);
|
|
1386
|
+
}
|
|
1387
|
+
function assignMergeValue(target, key, value) {
|
|
1388
|
+
(void 0 !== value && !eq(target[key], value) || void 0 === value && !(key in target)) && (target[key] = value);
|
|
1389
|
+
}
|
|
1390
|
+
function eq(value, other) {
|
|
1391
|
+
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
1392
|
+
}
|
|
1393
|
+
function merge(target) {
|
|
1394
|
+
let sourceIndex = -1;
|
|
1395
|
+
const length = arguments.length <= 1 ? 0 : arguments.length - 1;
|
|
1396
|
+
for (; ++sourceIndex < length;) {
|
|
1397
|
+
baseMerge(target, sourceIndex + 1 < 1 || arguments.length <= sourceIndex + 1 ? undefined : arguments[sourceIndex + 1], !0);
|
|
1398
|
+
}
|
|
1399
|
+
return target;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1335
1402
|
function arrayEqual(a, b) {
|
|
1336
1403
|
if (!isArray$1(a) || !isArray$1(b)) return !1;
|
|
1337
1404
|
if (a.length !== b.length) return !1;
|
|
@@ -1457,7 +1524,8 @@
|
|
|
1457
1524
|
return x >= 1 ? halfPi$1 : x <= -1 ? -halfPi$1 : Math.asin(x);
|
|
1458
1525
|
}
|
|
1459
1526
|
function pointAt(x1, y1, x2, y2, t) {
|
|
1460
|
-
let x,
|
|
1527
|
+
let x = x2,
|
|
1528
|
+
y = y2;
|
|
1461
1529
|
return "number" == typeof x1 && "number" == typeof x2 && (x = (1 - t) * x1 + t * x2), "number" == typeof y1 && "number" == typeof y2 && (y = (1 - t) * y1 + t * y2), {
|
|
1462
1530
|
x: x,
|
|
1463
1531
|
y: y
|
|
@@ -3919,6 +3987,7 @@
|
|
|
3919
3987
|
keepDirIn3d: !0
|
|
3920
3988
|
});
|
|
3921
3989
|
const DefaultRichTextAttribute = Object.assign(Object.assign(Object.assign({}, DefaultAttribute), DefaultTextStyle), {
|
|
3990
|
+
editable: !1,
|
|
3922
3991
|
width: 300,
|
|
3923
3992
|
height: 300,
|
|
3924
3993
|
ellipsis: !0,
|
|
@@ -12920,10 +12989,10 @@
|
|
|
12920
12989
|
strokeOpacity: strokeOpacity
|
|
12921
12990
|
}, config);
|
|
12922
12991
|
}
|
|
12923
|
-
doUpdateFrameCache() {
|
|
12992
|
+
doUpdateFrameCache(tc) {
|
|
12924
12993
|
var _a;
|
|
12925
12994
|
const {
|
|
12926
|
-
textConfig = [],
|
|
12995
|
+
textConfig: _tc = [],
|
|
12927
12996
|
maxWidth: maxWidth,
|
|
12928
12997
|
maxHeight: maxHeight,
|
|
12929
12998
|
width: width,
|
|
@@ -12937,7 +13006,8 @@
|
|
|
12937
13006
|
singleLine: singleLine,
|
|
12938
13007
|
disableAutoWrapLine: disableAutoWrapLine
|
|
12939
13008
|
} = this.attribute,
|
|
12940
|
-
paragraphs = []
|
|
13009
|
+
paragraphs = [],
|
|
13010
|
+
textConfig = null != tc ? tc : _tc;
|
|
12941
13011
|
for (let i = 0; i < textConfig.length; i++) if ("image" in textConfig[i]) {
|
|
12942
13012
|
const config = this.combinedStyleToCharacter(textConfig[i]),
|
|
12943
13013
|
iconCache = config.id && this._frameCache && this._frameCache.icons && this._frameCache.icons.get(config.id);
|
|
@@ -13929,7 +13999,7 @@
|
|
|
13929
13999
|
x: x,
|
|
13930
14000
|
y: y
|
|
13931
14001
|
} = attribute;
|
|
13932
|
-
width = null != width ? width : x1 - x, height = null != height ? height : y1 - y, aabbBounds.set(0, 0, width || 0, height || 0);
|
|
14002
|
+
width = null != width ? width : x1 - x, height = null != height ? height : y1 - y, (isFinite(width) || isFinite(height) || isFinite(x) || isFinite(y)) && aabbBounds.set(0, 0, width || 0, height || 0);
|
|
13933
14003
|
}
|
|
13934
14004
|
const tb1 = this.tempAABBBounds1,
|
|
13935
14005
|
tb2 = this.tempAABBBounds2;
|
|
@@ -13944,7 +14014,8 @@
|
|
|
13944
14014
|
width: width,
|
|
13945
14015
|
height: height,
|
|
13946
14016
|
path: path,
|
|
13947
|
-
clip = groupTheme.clip
|
|
14017
|
+
clip = groupTheme.clip,
|
|
14018
|
+
display: display
|
|
13948
14019
|
} = attribute;
|
|
13949
14020
|
path && path.length ? path.forEach(g => {
|
|
13950
14021
|
aabbBounds.union(g.AABBBounds);
|
|
@@ -17070,10 +17141,10 @@
|
|
|
17070
17141
|
this.order = 1;
|
|
17071
17142
|
}
|
|
17072
17143
|
afterDrawItem(graphic, renderService, drawContext, drawContribution, params) {
|
|
17073
|
-
return (graphic.attribute.shadowRootIdx > 0 || !graphic.attribute.shadowRootIdx) && this.drawItem(graphic, renderService, drawContext, drawContribution, params), !1;
|
|
17144
|
+
return null == graphic.attribute.shadowRootIdx && graphic.shadowRoot && graphic.shadowRoot.attribute.shadowRootIdx < 0 || (graphic.attribute.shadowRootIdx > 0 || !graphic.attribute.shadowRootIdx || graphic.shadowRoot && graphic.shadowRoot.attribute.shadowRootIdx > 0) && this.drawItem(graphic, renderService, drawContext, drawContribution, params), !1;
|
|
17074
17145
|
}
|
|
17075
17146
|
beforeDrawItem(graphic, renderService, drawContext, drawContribution, params) {
|
|
17076
|
-
return graphic.attribute.shadowRootIdx < 0 && this.drawItem(graphic, renderService, drawContext, drawContribution, params), !1;
|
|
17147
|
+
return null == graphic.attribute.shadowRootIdx && graphic.shadowRoot && graphic.shadowRoot.attribute.shadowRootIdx > 0 || (graphic.attribute.shadowRootIdx < 0 || graphic.shadowRoot && graphic.shadowRoot.attribute.shadowRootIdx < 0) && this.drawItem(graphic, renderService, drawContext, drawContribution, params), !1;
|
|
17077
17148
|
}
|
|
17078
17149
|
drawItem(graphic, renderService, drawContext, drawContribution, params) {
|
|
17079
17150
|
if (!graphic.shadowRoot) return !1;
|
|
@@ -20290,6 +20361,424 @@
|
|
|
20290
20361
|
return points = simplifyDouglasPeucker(points = highestQuality ? points : simplifyRadialDist(points, sqTolerance), sqTolerance);
|
|
20291
20362
|
}
|
|
20292
20363
|
|
|
20364
|
+
function findCursorIndexIgnoreLinebreak(textConfig, cursorIndex) {
|
|
20365
|
+
let index = 0;
|
|
20366
|
+
for (index = 0; index < textConfig.length; index++) {
|
|
20367
|
+
const c = textConfig[index];
|
|
20368
|
+
if (c.text && "\n" === c.text || cursorIndex--, cursorIndex < 0) break;
|
|
20369
|
+
}
|
|
20370
|
+
return index;
|
|
20371
|
+
}
|
|
20372
|
+
class EditModule {
|
|
20373
|
+
constructor(container) {
|
|
20374
|
+
this.handleKeyDown = e => {
|
|
20375
|
+
"Delete" !== e.key && "Backspace" !== e.key || this.handleInput({
|
|
20376
|
+
data: null,
|
|
20377
|
+
type: "Backspace"
|
|
20378
|
+
});
|
|
20379
|
+
}, this.handleCompositionStart = () => {
|
|
20380
|
+
const {
|
|
20381
|
+
textConfig = []
|
|
20382
|
+
} = this.currRt.attribute,
|
|
20383
|
+
cursorIndex = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex),
|
|
20384
|
+
lastConfig = textConfig[cursorIndex];
|
|
20385
|
+
textConfig.splice(cursorIndex + 1, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
20386
|
+
text: ""
|
|
20387
|
+
})), this.isComposing = !0;
|
|
20388
|
+
}, this.handleCompositionEnd = () => {
|
|
20389
|
+
this.isComposing = !1;
|
|
20390
|
+
const {
|
|
20391
|
+
textConfig = []
|
|
20392
|
+
} = this.currRt.attribute,
|
|
20393
|
+
curIdx = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex + 1),
|
|
20394
|
+
lastConfig = textConfig[curIdx];
|
|
20395
|
+
textConfig.splice(curIdx, 1);
|
|
20396
|
+
const text = lastConfig.text,
|
|
20397
|
+
textList = Array.from(text.toString());
|
|
20398
|
+
for (let i = 0; i < textList.length; i++) textConfig.splice(i + curIdx, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
20399
|
+
text: textList[i]
|
|
20400
|
+
}));
|
|
20401
|
+
this.currRt.setAttributes({
|
|
20402
|
+
textConfig: textConfig
|
|
20403
|
+
}), this.onChangeCbList.forEach(cb => {
|
|
20404
|
+
cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt, "right");
|
|
20405
|
+
});
|
|
20406
|
+
}, this.handleInput = ev => {
|
|
20407
|
+
if (!this.currRt) return;
|
|
20408
|
+
let str = ev.data;
|
|
20409
|
+
"Backspace" === ev.type || str || (str = "\n");
|
|
20410
|
+
const {
|
|
20411
|
+
textConfig = []
|
|
20412
|
+
} = this.currRt.attribute;
|
|
20413
|
+
let startIdx = this.selectionStartCursorIdx,
|
|
20414
|
+
endIdx = this.cursorIndex;
|
|
20415
|
+
startIdx > endIdx && ([startIdx, endIdx] = [endIdx, startIdx]), this.selectionStartCursorIdx = startIdx, this.cursorIndex = startIdx, startIdx = findCursorIndexIgnoreLinebreak(textConfig, startIdx);
|
|
20416
|
+
const delta = this.selectionStartCursorIdx - startIdx;
|
|
20417
|
+
endIdx = findCursorIndexIgnoreLinebreak(textConfig, endIdx);
|
|
20418
|
+
const lastConfig = textConfig[startIdx + (this.isComposing ? 1 : 0)];
|
|
20419
|
+
let currConfig = lastConfig;
|
|
20420
|
+
"Backspace" !== ev.type || this.isComposing ? (startIdx !== endIdx && textConfig.splice(startIdx + 1, endIdx - startIdx), this.isComposing || (currConfig = Object.assign(Object.assign({}, lastConfig), {
|
|
20421
|
+
text: ""
|
|
20422
|
+
}), startIdx += 1, textConfig.splice(startIdx, 0, currConfig)), currConfig.text = str) : startIdx !== endIdx ? textConfig.splice(startIdx + 1, endIdx - startIdx) : (textConfig.splice(startIdx, 1), startIdx -= 1), this.currRt.setAttributes({
|
|
20423
|
+
textConfig: textConfig
|
|
20424
|
+
}), this.isComposing ? this.onInputCbList.forEach(cb => {
|
|
20425
|
+
cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
|
|
20426
|
+
}) : this.onChangeCbList.forEach(cb => {
|
|
20427
|
+
cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
|
|
20428
|
+
});
|
|
20429
|
+
}, this.container = null != container ? container : document.body;
|
|
20430
|
+
const textAreaDom = document.createElement("textarea");
|
|
20431
|
+
textAreaDom.autocomplete = "off", textAreaDom.innerText = "", this.applyStyle(textAreaDom), this.container.append(textAreaDom), this.textAreaDom = textAreaDom, this.isComposing = !1, this.onInputCbList = [], this.onChangeCbList = [];
|
|
20432
|
+
}
|
|
20433
|
+
onInput(cb) {
|
|
20434
|
+
this.onInputCbList.push(cb);
|
|
20435
|
+
}
|
|
20436
|
+
onChange(cb) {
|
|
20437
|
+
this.onChangeCbList.push(cb);
|
|
20438
|
+
}
|
|
20439
|
+
applyStyle(textAreaDom) {
|
|
20440
|
+
textAreaDom.setAttribute("style", "width: 100px; height: 30px; left: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;"), textAreaDom.addEventListener("input", this.handleInput), textAreaDom.addEventListener("compositionstart", this.handleCompositionStart), textAreaDom.addEventListener("compositionend", this.handleCompositionEnd), window.addEventListener("keydown", this.handleKeyDown);
|
|
20441
|
+
}
|
|
20442
|
+
moveTo(x, y, rt, cursorIndex, selectionStartCursorIdx) {
|
|
20443
|
+
this.textAreaDom.style.left = `${x}px`, this.textAreaDom.style.top = `${y}px`, setTimeout(() => {
|
|
20444
|
+
this.textAreaDom.focus(), this.textAreaDom.setSelectionRange(0, 0);
|
|
20445
|
+
}), this.currRt = rt, this.cursorIndex = cursorIndex, this.selectionStartCursorIdx = selectionStartCursorIdx;
|
|
20446
|
+
}
|
|
20447
|
+
release() {
|
|
20448
|
+
this.textAreaDom.removeEventListener("input", this.handleInput), this.textAreaDom.removeEventListener("compositionstart", this.handleCompositionStart), this.textAreaDom.removeEventListener("compositionend", this.handleCompositionEnd), window.removeEventListener("keydown", this.handleKeyDown);
|
|
20449
|
+
}
|
|
20450
|
+
}
|
|
20451
|
+
|
|
20452
|
+
class Selection {
|
|
20453
|
+
constructor(cacheSelectionStartCursorIdx, cacheCurCursorIdx, selectionStartCursorIdx, curCursorIdx, rt) {
|
|
20454
|
+
this.curCursorIdx = curCursorIdx, this.selectionStartCursorIdx = selectionStartCursorIdx, this.cacheCurCursorIdx = cacheCurCursorIdx, this.cacheSelectionStartCursorIdx = cacheSelectionStartCursorIdx, this.rt = rt;
|
|
20455
|
+
}
|
|
20456
|
+
hasFormat(key) {
|
|
20457
|
+
return null != this.getFormat(key);
|
|
20458
|
+
}
|
|
20459
|
+
getFormat(key) {
|
|
20460
|
+
if (!this.rt) return null;
|
|
20461
|
+
const config = this.rt.attribute.textConfig,
|
|
20462
|
+
val = config[this.selectionStartCursorIdx + 1][key];
|
|
20463
|
+
if (null == val) return null;
|
|
20464
|
+
for (let i = this.selectionStartCursorIdx + 2; i <= this.curCursorIdx; i++) {
|
|
20465
|
+
if (val !== config[i][key]) return null;
|
|
20466
|
+
}
|
|
20467
|
+
return val;
|
|
20468
|
+
}
|
|
20469
|
+
getAllFormat(key) {
|
|
20470
|
+
if (!this.rt) return [];
|
|
20471
|
+
const config = this.rt.attribute.textConfig,
|
|
20472
|
+
val = config[this.selectionStartCursorIdx + 1][key],
|
|
20473
|
+
set = new Set();
|
|
20474
|
+
set.add(val);
|
|
20475
|
+
for (let i = this.selectionStartCursorIdx + 2; i <= this.curCursorIdx; i++) {
|
|
20476
|
+
const item = config[i];
|
|
20477
|
+
set.add(item[key]);
|
|
20478
|
+
}
|
|
20479
|
+
return Array.from(set.values());
|
|
20480
|
+
}
|
|
20481
|
+
}
|
|
20482
|
+
const FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND";
|
|
20483
|
+
const FORMAT_ELEMENT_COMMAND = "FORMAT_ELEMENT_COMMAND";
|
|
20484
|
+
class RichTextEditPlugin {
|
|
20485
|
+
constructor() {
|
|
20486
|
+
this.name = "RichTextEditPlugin", this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(), this.key = this.name + this._uid, this.editing = !1, this.pointerDown = !1, this.handleInput = (text, isComposing, cursorIdx, rt, orient) => {
|
|
20487
|
+
const p = this.getPointByColumnIdx(cursorIdx, rt, orient);
|
|
20488
|
+
this.hideSelection(), this.setCursor(p.x, p.y1, p.y2), this.updateCbs.forEach(cb => cb("input", this));
|
|
20489
|
+
}, this.handleChange = (text, isComposing, cursorIdx, rt, orient) => {
|
|
20490
|
+
const p = this.getPointByColumnIdx(cursorIdx, rt, orient);
|
|
20491
|
+
this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx, this.setCursorAndTextArea(p.x, p.y1, p.y2, rt), this.hideSelection(), this.updateCbs.forEach(cb => cb("change", this));
|
|
20492
|
+
}, this.handleMove = e => {
|
|
20493
|
+
this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave), this.showSelection(e));
|
|
20494
|
+
}, this.handlePointerDown = e => {
|
|
20495
|
+
this.editing ? this.onFocus(e) : this.deFocus(e), this.applyUpdate(), this.pointerDown = !0, this.updateCbs.forEach(cb => cb(this.editing ? "onfocus" : "defocus", this));
|
|
20496
|
+
}, this.handlePointerUp = e => {
|
|
20497
|
+
this.pointerDown = !1;
|
|
20498
|
+
}, this.handleEnter = e => {
|
|
20499
|
+
this.editing = !0, this.pluginService.stage.setCursor("text");
|
|
20500
|
+
}, this.handleLeave = e => {
|
|
20501
|
+
this.editing = !1, this.pluginService.stage.setCursor("default");
|
|
20502
|
+
}, this.commandCbs = new Map(), this.commandCbs.set(FORMAT_TEXT_COMMAND, [this.formatTextCommandCb]), this.updateCbs = [];
|
|
20503
|
+
}
|
|
20504
|
+
getSelection() {
|
|
20505
|
+
return this.selectionStartCursorIdx && this.curCursorIdx && this.selectionStartCursorIdx !== this.curCursorIdx && this.currRt ? new Selection(this.selectionStartCursorIdx, this.curCursorIdx, findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.selectionStartCursorIdx), findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.curCursorIdx), this.currRt) : null;
|
|
20506
|
+
}
|
|
20507
|
+
formatTextCommandCb(payload, p) {
|
|
20508
|
+
const rt = p.currRt;
|
|
20509
|
+
if (!rt) return;
|
|
20510
|
+
const selectionData = p.getSelection();
|
|
20511
|
+
if (!selectionData) return;
|
|
20512
|
+
const {
|
|
20513
|
+
selectionStartCursorIdx: selectionStartCursorIdx,
|
|
20514
|
+
curCursorIdx: curCursorIdx
|
|
20515
|
+
} = selectionData,
|
|
20516
|
+
config = rt.attribute.textConfig.slice(selectionStartCursorIdx + 1, curCursorIdx + 1);
|
|
20517
|
+
"bold" === payload ? config.forEach(item => item.fontWeight = "bold") : "italic" === payload ? config.forEach(item => item.fontStyle = "italic") : "underline" === payload ? config.forEach(item => item.underline = !0) : "lineThrough" === payload ? config.forEach(item => item.lineThrough = !0) : isObject$1(payload) && config.forEach(item => merge(item, payload)), rt.setAttributes(rt.attribute);
|
|
20518
|
+
}
|
|
20519
|
+
dispatchCommand(command, payload) {
|
|
20520
|
+
const cbs = this.commandCbs.get(command);
|
|
20521
|
+
cbs && cbs.forEach(cb => cb(payload, this)), this.updateCbs.forEach(cb => cb("dispatch", this));
|
|
20522
|
+
}
|
|
20523
|
+
registerCommand(command, cb) {
|
|
20524
|
+
(this.commandCbs.get(command) || []).push(cb);
|
|
20525
|
+
}
|
|
20526
|
+
registerUpdateListener(cb) {
|
|
20527
|
+
(this.updateCbs || []).push(cb);
|
|
20528
|
+
}
|
|
20529
|
+
activate(context) {
|
|
20530
|
+
this.pluginService = context, this.editModule = new EditModule(), context.stage.on("pointermove", this.handleMove), context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp), context.stage.on("pointerleave", this.handlePointerUp), this.editModule.onInput(this.handleInput), this.editModule.onChange(this.handleChange);
|
|
20531
|
+
}
|
|
20532
|
+
showSelection(e) {
|
|
20533
|
+
const cache = e.target.getFrameCache();
|
|
20534
|
+
if (cache && this.editBg && this.pointerDown) {
|
|
20535
|
+
let p0 = this.lastPoint,
|
|
20536
|
+
p1 = this.getEventPosition(e),
|
|
20537
|
+
line1Info = this.getLineByPoint(cache, p1);
|
|
20538
|
+
const column1 = this.getColumnByLinePoint(line1Info, p1),
|
|
20539
|
+
y1 = line1Info.top,
|
|
20540
|
+
y2 = line1Info.top + line1Info.height;
|
|
20541
|
+
let x = column1.left + column1.width,
|
|
20542
|
+
cursorIndex = this.getColumnIndex(cache, column1);
|
|
20543
|
+
p1.x < column1.left + column1.width / 2 && (x = column1.left, cursorIndex -= 1), p1.x = x, p1.y = (y1 + y2) / 2;
|
|
20544
|
+
let line0Info = this.getLineByPoint(cache, p0);
|
|
20545
|
+
if ((p0.y > p1.y || p0.y === p1.y && p0.x > p1.x) && ([p0, p1] = [p1, p0], [line1Info, line0Info] = [line0Info, line1Info]), this.editBg.removeAllChild(), line0Info === line1Info) {
|
|
20546
|
+
const column0 = this.getColumnByLinePoint(line0Info, p0);
|
|
20547
|
+
this.editBg.setAttributes({
|
|
20548
|
+
x: p0.x,
|
|
20549
|
+
y: line0Info.top,
|
|
20550
|
+
width: p1.x - p0.x,
|
|
20551
|
+
height: column0.height,
|
|
20552
|
+
fill: "#336df4",
|
|
20553
|
+
fillOpacity: .2
|
|
20554
|
+
});
|
|
20555
|
+
} else {
|
|
20556
|
+
this.editBg.setAttributes({
|
|
20557
|
+
x: 0,
|
|
20558
|
+
y: line0Info.top,
|
|
20559
|
+
width: 0,
|
|
20560
|
+
height: 0
|
|
20561
|
+
});
|
|
20562
|
+
const startIdx = cache.lines.findIndex(item => item === line0Info),
|
|
20563
|
+
endIdx = cache.lines.findIndex(item => item === line1Info);
|
|
20564
|
+
let y = 0;
|
|
20565
|
+
for (let i = startIdx; i <= endIdx; i++) {
|
|
20566
|
+
const line = cache.lines[i];
|
|
20567
|
+
if (i === startIdx) {
|
|
20568
|
+
const p = line.paragraphs[line.paragraphs.length - 1];
|
|
20569
|
+
this.editBg.add(createRect({
|
|
20570
|
+
x: p0.x,
|
|
20571
|
+
y: y,
|
|
20572
|
+
width: p.left + p.width - p0.x,
|
|
20573
|
+
height: line.height,
|
|
20574
|
+
fill: "#336df4",
|
|
20575
|
+
fillOpacity: .2
|
|
20576
|
+
}));
|
|
20577
|
+
} else if (i === endIdx) {
|
|
20578
|
+
const p = line.paragraphs[0];
|
|
20579
|
+
this.editBg.add(createRect({
|
|
20580
|
+
x: p.left,
|
|
20581
|
+
y: y,
|
|
20582
|
+
width: p1.x - p.left,
|
|
20583
|
+
height: line.height,
|
|
20584
|
+
fill: "#336df4",
|
|
20585
|
+
fillOpacity: .2
|
|
20586
|
+
}));
|
|
20587
|
+
} else {
|
|
20588
|
+
const p0 = line.paragraphs[0],
|
|
20589
|
+
p1 = line.paragraphs[line.paragraphs.length - 1];
|
|
20590
|
+
this.editBg.add(createRect({
|
|
20591
|
+
x: p0.left,
|
|
20592
|
+
y: y,
|
|
20593
|
+
width: p1.left + p1.width - p0.left,
|
|
20594
|
+
height: line.height,
|
|
20595
|
+
fill: "#336df4",
|
|
20596
|
+
fillOpacity: .2
|
|
20597
|
+
}));
|
|
20598
|
+
}
|
|
20599
|
+
y += line.height;
|
|
20600
|
+
}
|
|
20601
|
+
}
|
|
20602
|
+
this.curCursorIdx = cursorIndex, this.setCursorAndTextArea(x, y1 + 2, y2 - 2, e.target), this.applyUpdate(), this.updateCbs.forEach(cb => cb("selection", this));
|
|
20603
|
+
}
|
|
20604
|
+
}
|
|
20605
|
+
hideSelection() {
|
|
20606
|
+
this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
|
|
20607
|
+
fill: "transparent"
|
|
20608
|
+
}));
|
|
20609
|
+
}
|
|
20610
|
+
isRichtext(e) {
|
|
20611
|
+
return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
|
|
20612
|
+
}
|
|
20613
|
+
getEventPosition(e) {
|
|
20614
|
+
const p = this.pluginService.stage.eventPointTransform(e),
|
|
20615
|
+
p1 = {
|
|
20616
|
+
x: 0,
|
|
20617
|
+
y: 0
|
|
20618
|
+
};
|
|
20619
|
+
return e.target.globalTransMatrix.transformPoint(p, p1), p1;
|
|
20620
|
+
}
|
|
20621
|
+
getLineByPoint(cache, p1) {
|
|
20622
|
+
let lineInfo = cache.lines[0];
|
|
20623
|
+
for (let i = 0; i < cache.lines.length && !(lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y); i++) lineInfo = cache.lines[i + 1];
|
|
20624
|
+
return lineInfo;
|
|
20625
|
+
}
|
|
20626
|
+
getColumnByLinePoint(lineInfo, p1) {
|
|
20627
|
+
let columnInfo = lineInfo.paragraphs[0];
|
|
20628
|
+
for (let i = 0; i < lineInfo.paragraphs.length && !(columnInfo.left <= p1.x && columnInfo.left + columnInfo.width >= p1.x); i++) columnInfo = lineInfo.paragraphs[i];
|
|
20629
|
+
return columnInfo;
|
|
20630
|
+
}
|
|
20631
|
+
onFocus(e) {
|
|
20632
|
+
this.deFocus(e);
|
|
20633
|
+
const target = e.target;
|
|
20634
|
+
this.tryUpdateRichtext(target);
|
|
20635
|
+
const shadowRoot = target.attachShadow();
|
|
20636
|
+
shadowRoot.setAttributes({
|
|
20637
|
+
shadowRootIdx: -1
|
|
20638
|
+
});
|
|
20639
|
+
const cache = target.getFrameCache();
|
|
20640
|
+
if (!cache) return;
|
|
20641
|
+
if (!this.editLine) {
|
|
20642
|
+
const line = createLine({
|
|
20643
|
+
x: 0,
|
|
20644
|
+
y: 0,
|
|
20645
|
+
lineWidth: 1,
|
|
20646
|
+
stroke: "black"
|
|
20647
|
+
});
|
|
20648
|
+
line.animate().to({
|
|
20649
|
+
opacity: 1
|
|
20650
|
+
}, 10, "linear").wait(700).to({
|
|
20651
|
+
opacity: 0
|
|
20652
|
+
}, 10, "linear").wait(700).loop(1 / 0), this.editLine = line;
|
|
20653
|
+
const g = createGroup({
|
|
20654
|
+
x: 0,
|
|
20655
|
+
y: 0,
|
|
20656
|
+
width: 0,
|
|
20657
|
+
height: 0
|
|
20658
|
+
});
|
|
20659
|
+
this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
|
|
20660
|
+
}
|
|
20661
|
+
const p1 = this.getEventPosition(e),
|
|
20662
|
+
lineInfo = this.getLineByPoint(cache, p1);
|
|
20663
|
+
if (lineInfo) {
|
|
20664
|
+
const columnInfo = this.getColumnByLinePoint(lineInfo, p1);
|
|
20665
|
+
if (!columnInfo) return;
|
|
20666
|
+
let y1 = lineInfo.top,
|
|
20667
|
+
y2 = lineInfo.top + lineInfo.height,
|
|
20668
|
+
x = columnInfo.left + columnInfo.width;
|
|
20669
|
+
y1 += 2, y2 -= 2;
|
|
20670
|
+
let cursorIndex = this.getColumnIndex(cache, columnInfo);
|
|
20671
|
+
p1.x < columnInfo.left + columnInfo.width / 2 && (x = columnInfo.left, cursorIndex -= 1), this.lastPoint = {
|
|
20672
|
+
x: x,
|
|
20673
|
+
y: (y1 + y2) / 2
|
|
20674
|
+
}, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex, this.setCursorAndTextArea(x, y1, y2, target);
|
|
20675
|
+
}
|
|
20676
|
+
}
|
|
20677
|
+
getPointByColumnIdx(idx, rt, orient) {
|
|
20678
|
+
const cache = rt.getFrameCache(),
|
|
20679
|
+
{
|
|
20680
|
+
lineInfo: lineInfo,
|
|
20681
|
+
columnInfo: columnInfo
|
|
20682
|
+
} = this.getColumnByIndex(cache, idx);
|
|
20683
|
+
let y1 = lineInfo.top,
|
|
20684
|
+
y2 = lineInfo.top + lineInfo.height;
|
|
20685
|
+
return y1 += 2, y2 -= 2, {
|
|
20686
|
+
x: columnInfo.left + ("left" === orient ? 0 : columnInfo.width),
|
|
20687
|
+
y1: y1,
|
|
20688
|
+
y2: y2
|
|
20689
|
+
};
|
|
20690
|
+
}
|
|
20691
|
+
getColumnIndex(cache, cInfo) {
|
|
20692
|
+
let inputIndex = -1;
|
|
20693
|
+
for (let i = 0; i < cache.lines.length; i++) {
|
|
20694
|
+
const line = cache.lines[i];
|
|
20695
|
+
for (let j = 0; j < line.paragraphs.length; j++) if (inputIndex++, cInfo === line.paragraphs[j]) return inputIndex;
|
|
20696
|
+
}
|
|
20697
|
+
return -1;
|
|
20698
|
+
}
|
|
20699
|
+
getColumnByIndex(cache, index) {
|
|
20700
|
+
let inputIndex = -1;
|
|
20701
|
+
for (let i = 0; i < cache.lines.length; i++) {
|
|
20702
|
+
const lineInfo = cache.lines[i];
|
|
20703
|
+
for (let j = 0; j < lineInfo.paragraphs.length; j++) {
|
|
20704
|
+
const columnInfo = lineInfo.paragraphs[j];
|
|
20705
|
+
if (inputIndex++, inputIndex === index) return {
|
|
20706
|
+
lineInfo: lineInfo,
|
|
20707
|
+
columnInfo: columnInfo
|
|
20708
|
+
};
|
|
20709
|
+
}
|
|
20710
|
+
}
|
|
20711
|
+
return null;
|
|
20712
|
+
}
|
|
20713
|
+
setCursorAndTextArea(x, y1, y2, rt) {
|
|
20714
|
+
this.editLine.setAttributes({
|
|
20715
|
+
points: [{
|
|
20716
|
+
x: x,
|
|
20717
|
+
y: y1
|
|
20718
|
+
}, {
|
|
20719
|
+
x: x,
|
|
20720
|
+
y: y2
|
|
20721
|
+
}]
|
|
20722
|
+
});
|
|
20723
|
+
const out = {
|
|
20724
|
+
x: 0,
|
|
20725
|
+
y: 0
|
|
20726
|
+
};
|
|
20727
|
+
rt.globalTransMatrix.getInverse().transformPoint({
|
|
20728
|
+
x: x,
|
|
20729
|
+
y: y1
|
|
20730
|
+
}, out);
|
|
20731
|
+
const {
|
|
20732
|
+
left: left,
|
|
20733
|
+
top: top
|
|
20734
|
+
} = this.pluginService.stage.window.getBoundingClientRect();
|
|
20735
|
+
out.x += left, out.y += top, this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
|
|
20736
|
+
}
|
|
20737
|
+
setCursor(x, y1, y2) {
|
|
20738
|
+
this.editLine.setAttributes({
|
|
20739
|
+
points: [{
|
|
20740
|
+
x: x,
|
|
20741
|
+
y: y1
|
|
20742
|
+
}, {
|
|
20743
|
+
x: x,
|
|
20744
|
+
y: y2
|
|
20745
|
+
}]
|
|
20746
|
+
});
|
|
20747
|
+
}
|
|
20748
|
+
applyUpdate() {
|
|
20749
|
+
this.pluginService.stage.renderNextFrame();
|
|
20750
|
+
}
|
|
20751
|
+
deFocus(e) {
|
|
20752
|
+
e.target.detachShadow(), this.currRt = null, this.editLine && (this.editLine.parent.removeChild(this.editLine), this.editLine.release(), this.editLine = null, this.editBg.parent.removeChild(this.editBg), this.editBg.release(), this.editBg = null);
|
|
20753
|
+
}
|
|
20754
|
+
splitText(text) {
|
|
20755
|
+
return Array.from(text);
|
|
20756
|
+
}
|
|
20757
|
+
tryUpdateRichtext(richtext) {
|
|
20758
|
+
if (!richtext.getFrameCache().lines.every(line => line.paragraphs.every(item => !(item.text && isString$1(item.text) && this.splitText(item.text).length > 1)))) {
|
|
20759
|
+
const tc = [];
|
|
20760
|
+
richtext.attribute.textConfig.forEach(item => {
|
|
20761
|
+
const textList = this.splitText(item.text.toString());
|
|
20762
|
+
if (isString$1(item.text) && textList.length > 1) for (let i = 0; i < textList.length; i++) {
|
|
20763
|
+
const t = textList[i];
|
|
20764
|
+
tc.push(Object.assign(Object.assign({}, item), {
|
|
20765
|
+
text: t
|
|
20766
|
+
}));
|
|
20767
|
+
} else tc.push(item);
|
|
20768
|
+
}), richtext.setAttributes({
|
|
20769
|
+
textConfig: tc
|
|
20770
|
+
}), richtext.doUpdateFrameCache(tc);
|
|
20771
|
+
}
|
|
20772
|
+
}
|
|
20773
|
+
onSelect() {}
|
|
20774
|
+
deactivate(context) {
|
|
20775
|
+
context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown), context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp);
|
|
20776
|
+
}
|
|
20777
|
+
release() {
|
|
20778
|
+
this.editModule.release();
|
|
20779
|
+
}
|
|
20780
|
+
}
|
|
20781
|
+
|
|
20293
20782
|
class DefaultGraphicAllocate {
|
|
20294
20783
|
constructor() {
|
|
20295
20784
|
this.pools = [];
|
|
@@ -25927,13 +26416,20 @@
|
|
|
25927
26416
|
} catch (err) {}
|
|
25928
26417
|
function makeUpCanvas$3(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, offscreen, pixelRatio) {
|
|
25929
26418
|
const dpr = null != pixelRatio ? pixelRatio : SystemInfo.pixelRatio;
|
|
25930
|
-
canvasIdLists.forEach((id, i) => {
|
|
26419
|
+
if (canvasIdLists.forEach((id, i) => {
|
|
25931
26420
|
let _canvas;
|
|
25932
26421
|
offscreen ? _canvas = lynx.createOffscreenCanvas() : (_canvas = ng ? lynx.createCanvasNG(id) : lynx.createCanvas(id), ng && _canvas.attachToCanvasView(id)), _canvas.width = domref.width * dpr, _canvas.height = domref.height * dpr;
|
|
25933
26422
|
const ctx = _canvas.getContext("2d"),
|
|
25934
26423
|
canvas = new CanvasWrapEnableWH(_canvas, ctx, dpr, domref.width, domref.height, id);
|
|
25935
|
-
canvasMap.set(id, canvas), i
|
|
25936
|
-
})
|
|
26424
|
+
canvasMap.set(id, canvas), i > freeCanvasIdx && freeCanvasList.push(canvas);
|
|
26425
|
+
}), !freeCanvasList.length && lynx.createOffscreenCanvas) {
|
|
26426
|
+
const _canvas = lynx.createOffscreenCanvas();
|
|
26427
|
+
_canvas.width = domref.width * dpr, _canvas.height = domref.height * dpr;
|
|
26428
|
+
const ctx = _canvas.getContext("2d"),
|
|
26429
|
+
id = Math.random().toString(),
|
|
26430
|
+
canvas = new CanvasWrapEnableWH(_canvas, ctx, dpr, domref.width, domref.height, id);
|
|
26431
|
+
canvasMap.set(id, canvas), freeCanvasList.push(canvas);
|
|
26432
|
+
}
|
|
25937
26433
|
}
|
|
25938
26434
|
function createImageElement(src) {
|
|
25939
26435
|
let isSvg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
|
|
@@ -28600,7 +29096,7 @@
|
|
|
28600
29096
|
|
|
28601
29097
|
const roughModule = _roughModule;
|
|
28602
29098
|
|
|
28603
|
-
const version = "0.19.
|
|
29099
|
+
const version = "0.19.14";
|
|
28604
29100
|
preLoadAllModule();
|
|
28605
29101
|
if (isBrowserEnv()) {
|
|
28606
29102
|
loadBrowserEnv(container);
|
|
@@ -28751,6 +29247,8 @@
|
|
|
28751
29247
|
exports.EventManager = EventManager;
|
|
28752
29248
|
exports.EventSystem = EventSystem;
|
|
28753
29249
|
exports.EventTarget = EventTarget;
|
|
29250
|
+
exports.FORMAT_ELEMENT_COMMAND = FORMAT_ELEMENT_COMMAND;
|
|
29251
|
+
exports.FORMAT_TEXT_COMMAND = FORMAT_TEXT_COMMAND;
|
|
28754
29252
|
exports.FadeInPlus = FadeInPlus;
|
|
28755
29253
|
exports.FederatedEvent = FederatedEvent;
|
|
28756
29254
|
exports.FederatedMouseEvent = FederatedMouseEvent;
|
|
@@ -28851,6 +29349,7 @@
|
|
|
28851
29349
|
exports.RenderService = RenderService;
|
|
28852
29350
|
exports.ResourceLoader = ResourceLoader;
|
|
28853
29351
|
exports.RichText = RichText;
|
|
29352
|
+
exports.RichTextEditPlugin = RichTextEditPlugin;
|
|
28854
29353
|
exports.RichTextRender = RichTextRender;
|
|
28855
29354
|
exports.RotateBySphereAnimate = RotateBySphereAnimate;
|
|
28856
29355
|
exports.SVG_ATTRIBUTE_MAP = SVG_ATTRIBUTE_MAP;
|