@visactor/vrender 0.19.13-beta.1 → 0.19.14-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/dist/index.es.js +507 -12
- package/dist/index.js +509 -11
- 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 +3 -3
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;
|
|
@@ -3919,6 +3986,7 @@
|
|
|
3919
3986
|
keepDirIn3d: !0
|
|
3920
3987
|
});
|
|
3921
3988
|
const DefaultRichTextAttribute = Object.assign(Object.assign(Object.assign({}, DefaultAttribute), DefaultTextStyle), {
|
|
3989
|
+
editable: !1,
|
|
3922
3990
|
width: 300,
|
|
3923
3991
|
height: 300,
|
|
3924
3992
|
ellipsis: !0,
|
|
@@ -12920,10 +12988,10 @@
|
|
|
12920
12988
|
strokeOpacity: strokeOpacity
|
|
12921
12989
|
}, config);
|
|
12922
12990
|
}
|
|
12923
|
-
doUpdateFrameCache() {
|
|
12991
|
+
doUpdateFrameCache(tc) {
|
|
12924
12992
|
var _a;
|
|
12925
12993
|
const {
|
|
12926
|
-
textConfig = [],
|
|
12994
|
+
textConfig: _tc = [],
|
|
12927
12995
|
maxWidth: maxWidth,
|
|
12928
12996
|
maxHeight: maxHeight,
|
|
12929
12997
|
width: width,
|
|
@@ -12937,7 +13005,8 @@
|
|
|
12937
13005
|
singleLine: singleLine,
|
|
12938
13006
|
disableAutoWrapLine: disableAutoWrapLine
|
|
12939
13007
|
} = this.attribute,
|
|
12940
|
-
paragraphs = []
|
|
13008
|
+
paragraphs = [],
|
|
13009
|
+
textConfig = null != tc ? tc : _tc;
|
|
12941
13010
|
for (let i = 0; i < textConfig.length; i++) if ("image" in textConfig[i]) {
|
|
12942
13011
|
const config = this.combinedStyleToCharacter(textConfig[i]),
|
|
12943
13012
|
iconCache = config.id && this._frameCache && this._frameCache.icons && this._frameCache.icons.get(config.id);
|
|
@@ -13929,7 +13998,7 @@
|
|
|
13929
13998
|
x: x,
|
|
13930
13999
|
y: y
|
|
13931
14000
|
} = attribute;
|
|
13932
|
-
width = null != width ? width : x1 - x, height = null != height ? height : y1 - y, aabbBounds.set(0, 0, width || 0, height || 0);
|
|
14001
|
+
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
14002
|
}
|
|
13934
14003
|
const tb1 = this.tempAABBBounds1,
|
|
13935
14004
|
tb2 = this.tempAABBBounds2;
|
|
@@ -13944,7 +14013,8 @@
|
|
|
13944
14013
|
width: width,
|
|
13945
14014
|
height: height,
|
|
13946
14015
|
path: path,
|
|
13947
|
-
clip = groupTheme.clip
|
|
14016
|
+
clip = groupTheme.clip,
|
|
14017
|
+
display: display
|
|
13948
14018
|
} = attribute;
|
|
13949
14019
|
path && path.length ? path.forEach(g => {
|
|
13950
14020
|
aabbBounds.union(g.AABBBounds);
|
|
@@ -17070,10 +17140,10 @@
|
|
|
17070
17140
|
this.order = 1;
|
|
17071
17141
|
}
|
|
17072
17142
|
afterDrawItem(graphic, renderService, drawContext, drawContribution, params) {
|
|
17073
|
-
return (graphic.attribute.shadowRootIdx > 0 || !graphic.attribute.shadowRootIdx) && this.drawItem(graphic, renderService, drawContext, drawContribution, params), !1;
|
|
17143
|
+
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
17144
|
}
|
|
17075
17145
|
beforeDrawItem(graphic, renderService, drawContext, drawContribution, params) {
|
|
17076
|
-
return graphic.attribute.shadowRootIdx < 0 && this.drawItem(graphic, renderService, drawContext, drawContribution, params), !1;
|
|
17146
|
+
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
17147
|
}
|
|
17078
17148
|
drawItem(graphic, renderService, drawContext, drawContribution, params) {
|
|
17079
17149
|
if (!graphic.shadowRoot) return !1;
|
|
@@ -20290,6 +20360,424 @@
|
|
|
20290
20360
|
return points = simplifyDouglasPeucker(points = highestQuality ? points : simplifyRadialDist(points, sqTolerance), sqTolerance);
|
|
20291
20361
|
}
|
|
20292
20362
|
|
|
20363
|
+
function findCursorIndexIgnoreLinebreak(textConfig, cursorIndex) {
|
|
20364
|
+
let index = 0;
|
|
20365
|
+
for (index = 0; index < textConfig.length; index++) {
|
|
20366
|
+
const c = textConfig[index];
|
|
20367
|
+
if (c.text && "\n" === c.text || cursorIndex--, cursorIndex < 0) break;
|
|
20368
|
+
}
|
|
20369
|
+
return index;
|
|
20370
|
+
}
|
|
20371
|
+
class EditModule {
|
|
20372
|
+
constructor(container) {
|
|
20373
|
+
this.handleKeyDown = e => {
|
|
20374
|
+
"Delete" !== e.key && "Backspace" !== e.key || this.handleInput({
|
|
20375
|
+
data: null,
|
|
20376
|
+
type: "Backspace"
|
|
20377
|
+
});
|
|
20378
|
+
}, this.handleCompositionStart = () => {
|
|
20379
|
+
const {
|
|
20380
|
+
textConfig = []
|
|
20381
|
+
} = this.currRt.attribute,
|
|
20382
|
+
cursorIndex = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex),
|
|
20383
|
+
lastConfig = textConfig[cursorIndex];
|
|
20384
|
+
textConfig.splice(cursorIndex + 1, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
20385
|
+
text: ""
|
|
20386
|
+
})), this.isComposing = !0;
|
|
20387
|
+
}, this.handleCompositionEnd = () => {
|
|
20388
|
+
this.isComposing = !1;
|
|
20389
|
+
const {
|
|
20390
|
+
textConfig = []
|
|
20391
|
+
} = this.currRt.attribute,
|
|
20392
|
+
curIdx = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex + 1),
|
|
20393
|
+
lastConfig = textConfig[curIdx];
|
|
20394
|
+
textConfig.splice(curIdx, 1);
|
|
20395
|
+
const text = lastConfig.text,
|
|
20396
|
+
textList = Array.from(text.toString());
|
|
20397
|
+
for (let i = 0; i < textList.length; i++) textConfig.splice(i + curIdx, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
20398
|
+
text: textList[i]
|
|
20399
|
+
}));
|
|
20400
|
+
this.currRt.setAttributes({
|
|
20401
|
+
textConfig: textConfig
|
|
20402
|
+
}), this.onChangeCbList.forEach(cb => {
|
|
20403
|
+
cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt, "right");
|
|
20404
|
+
});
|
|
20405
|
+
}, this.handleInput = ev => {
|
|
20406
|
+
if (!this.currRt) return;
|
|
20407
|
+
let str = ev.data;
|
|
20408
|
+
"Backspace" === ev.type || str || (str = "\n");
|
|
20409
|
+
const {
|
|
20410
|
+
textConfig = []
|
|
20411
|
+
} = this.currRt.attribute;
|
|
20412
|
+
let startIdx = this.selectionStartCursorIdx,
|
|
20413
|
+
endIdx = this.cursorIndex;
|
|
20414
|
+
startIdx > endIdx && ([startIdx, endIdx] = [endIdx, startIdx]), this.selectionStartCursorIdx = startIdx, this.cursorIndex = startIdx, startIdx = findCursorIndexIgnoreLinebreak(textConfig, startIdx);
|
|
20415
|
+
const delta = this.selectionStartCursorIdx - startIdx;
|
|
20416
|
+
endIdx = findCursorIndexIgnoreLinebreak(textConfig, endIdx);
|
|
20417
|
+
const lastConfig = textConfig[startIdx + (this.isComposing ? 1 : 0)];
|
|
20418
|
+
let currConfig = lastConfig;
|
|
20419
|
+
"Backspace" !== ev.type || this.isComposing ? (startIdx !== endIdx && textConfig.splice(startIdx + 1, endIdx - startIdx), this.isComposing || (currConfig = Object.assign(Object.assign({}, lastConfig), {
|
|
20420
|
+
text: ""
|
|
20421
|
+
}), 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({
|
|
20422
|
+
textConfig: textConfig
|
|
20423
|
+
}), this.isComposing ? this.onInputCbList.forEach(cb => {
|
|
20424
|
+
cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
|
|
20425
|
+
}) : this.onChangeCbList.forEach(cb => {
|
|
20426
|
+
cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
|
|
20427
|
+
});
|
|
20428
|
+
}, this.container = null != container ? container : document.body;
|
|
20429
|
+
const textAreaDom = document.createElement("textarea");
|
|
20430
|
+
textAreaDom.autocomplete = "off", textAreaDom.innerText = "", this.applyStyle(textAreaDom), this.container.append(textAreaDom), this.textAreaDom = textAreaDom, this.isComposing = !1, this.onInputCbList = [], this.onChangeCbList = [];
|
|
20431
|
+
}
|
|
20432
|
+
onInput(cb) {
|
|
20433
|
+
this.onInputCbList.push(cb);
|
|
20434
|
+
}
|
|
20435
|
+
onChange(cb) {
|
|
20436
|
+
this.onChangeCbList.push(cb);
|
|
20437
|
+
}
|
|
20438
|
+
applyStyle(textAreaDom) {
|
|
20439
|
+
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);
|
|
20440
|
+
}
|
|
20441
|
+
moveTo(x, y, rt, cursorIndex, selectionStartCursorIdx) {
|
|
20442
|
+
this.textAreaDom.style.left = `${x}px`, this.textAreaDom.style.top = `${y}px`, setTimeout(() => {
|
|
20443
|
+
this.textAreaDom.focus(), this.textAreaDom.setSelectionRange(0, 0);
|
|
20444
|
+
}), this.currRt = rt, this.cursorIndex = cursorIndex, this.selectionStartCursorIdx = selectionStartCursorIdx;
|
|
20445
|
+
}
|
|
20446
|
+
release() {
|
|
20447
|
+
this.textAreaDom.removeEventListener("input", this.handleInput), this.textAreaDom.removeEventListener("compositionstart", this.handleCompositionStart), this.textAreaDom.removeEventListener("compositionend", this.handleCompositionEnd), window.removeEventListener("keydown", this.handleKeyDown);
|
|
20448
|
+
}
|
|
20449
|
+
}
|
|
20450
|
+
|
|
20451
|
+
class Selection {
|
|
20452
|
+
constructor(cacheSelectionStartCursorIdx, cacheCurCursorIdx, selectionStartCursorIdx, curCursorIdx, rt) {
|
|
20453
|
+
this.curCursorIdx = curCursorIdx, this.selectionStartCursorIdx = selectionStartCursorIdx, this.cacheCurCursorIdx = cacheCurCursorIdx, this.cacheSelectionStartCursorIdx = cacheSelectionStartCursorIdx, this.rt = rt;
|
|
20454
|
+
}
|
|
20455
|
+
hasFormat(key) {
|
|
20456
|
+
return null != this.getFormat(key);
|
|
20457
|
+
}
|
|
20458
|
+
getFormat(key) {
|
|
20459
|
+
if (!this.rt) return null;
|
|
20460
|
+
const config = this.rt.attribute.textConfig,
|
|
20461
|
+
val = config[this.selectionStartCursorIdx + 1][key];
|
|
20462
|
+
if (null == val) return null;
|
|
20463
|
+
for (let i = this.selectionStartCursorIdx + 2; i <= this.curCursorIdx; i++) {
|
|
20464
|
+
if (val !== config[i][key]) return null;
|
|
20465
|
+
}
|
|
20466
|
+
return val;
|
|
20467
|
+
}
|
|
20468
|
+
getAllFormat(key) {
|
|
20469
|
+
if (!this.rt) return [];
|
|
20470
|
+
const config = this.rt.attribute.textConfig,
|
|
20471
|
+
val = config[this.selectionStartCursorIdx + 1][key],
|
|
20472
|
+
set = new Set();
|
|
20473
|
+
set.add(val);
|
|
20474
|
+
for (let i = this.selectionStartCursorIdx + 2; i <= this.curCursorIdx; i++) {
|
|
20475
|
+
const item = config[i];
|
|
20476
|
+
set.add(item[key]);
|
|
20477
|
+
}
|
|
20478
|
+
return Array.from(set.values());
|
|
20479
|
+
}
|
|
20480
|
+
}
|
|
20481
|
+
const FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND";
|
|
20482
|
+
const FORMAT_ELEMENT_COMMAND = "FORMAT_ELEMENT_COMMAND";
|
|
20483
|
+
class RichTextEditPlugin {
|
|
20484
|
+
constructor() {
|
|
20485
|
+
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) => {
|
|
20486
|
+
const p = this.getPointByColumnIdx(cursorIdx, rt, orient);
|
|
20487
|
+
this.hideSelection(), this.setCursor(p.x, p.y1, p.y2), this.updateCbs.forEach(cb => cb("input", this));
|
|
20488
|
+
}, this.handleChange = (text, isComposing, cursorIdx, rt, orient) => {
|
|
20489
|
+
const p = this.getPointByColumnIdx(cursorIdx, rt, orient);
|
|
20490
|
+
this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx, this.setCursorAndTextArea(p.x, p.y1, p.y2, rt), this.hideSelection(), this.updateCbs.forEach(cb => cb("change", this));
|
|
20491
|
+
}, this.handleMove = e => {
|
|
20492
|
+
this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave), this.showSelection(e));
|
|
20493
|
+
}, this.handlePointerDown = e => {
|
|
20494
|
+
this.editing ? this.onFocus(e) : this.deFocus(e), this.applyUpdate(), this.pointerDown = !0, this.updateCbs.forEach(cb => cb(this.editing ? "onfocus" : "defocus", this));
|
|
20495
|
+
}, this.handlePointerUp = e => {
|
|
20496
|
+
this.pointerDown = !1;
|
|
20497
|
+
}, this.handleEnter = e => {
|
|
20498
|
+
this.editing = !0, this.pluginService.stage.setCursor("text");
|
|
20499
|
+
}, this.handleLeave = e => {
|
|
20500
|
+
this.editing = !1, this.pluginService.stage.setCursor("default");
|
|
20501
|
+
}, this.commandCbs = new Map(), this.commandCbs.set(FORMAT_TEXT_COMMAND, [this.formatTextCommandCb]), this.updateCbs = [];
|
|
20502
|
+
}
|
|
20503
|
+
getSelection() {
|
|
20504
|
+
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;
|
|
20505
|
+
}
|
|
20506
|
+
formatTextCommandCb(payload, p) {
|
|
20507
|
+
const rt = p.currRt;
|
|
20508
|
+
if (!rt) return;
|
|
20509
|
+
const selectionData = p.getSelection();
|
|
20510
|
+
if (!selectionData) return;
|
|
20511
|
+
const {
|
|
20512
|
+
selectionStartCursorIdx: selectionStartCursorIdx,
|
|
20513
|
+
curCursorIdx: curCursorIdx
|
|
20514
|
+
} = selectionData,
|
|
20515
|
+
config = rt.attribute.textConfig.slice(selectionStartCursorIdx + 1, curCursorIdx + 1);
|
|
20516
|
+
"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);
|
|
20517
|
+
}
|
|
20518
|
+
dispatchCommand(command, payload) {
|
|
20519
|
+
const cbs = this.commandCbs.get(command);
|
|
20520
|
+
cbs && cbs.forEach(cb => cb(payload, this)), this.updateCbs.forEach(cb => cb("dispatch", this));
|
|
20521
|
+
}
|
|
20522
|
+
registerCommand(command, cb) {
|
|
20523
|
+
(this.commandCbs.get(command) || []).push(cb);
|
|
20524
|
+
}
|
|
20525
|
+
registerUpdateListener(cb) {
|
|
20526
|
+
(this.updateCbs || []).push(cb);
|
|
20527
|
+
}
|
|
20528
|
+
activate(context) {
|
|
20529
|
+
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);
|
|
20530
|
+
}
|
|
20531
|
+
showSelection(e) {
|
|
20532
|
+
const cache = e.target.getFrameCache();
|
|
20533
|
+
if (cache && this.editBg && this.pointerDown) {
|
|
20534
|
+
let p0 = this.lastPoint,
|
|
20535
|
+
p1 = this.getEventPosition(e),
|
|
20536
|
+
line1Info = this.getLineByPoint(cache, p1);
|
|
20537
|
+
const column1 = this.getColumnByLinePoint(line1Info, p1),
|
|
20538
|
+
y1 = line1Info.top,
|
|
20539
|
+
y2 = line1Info.top + line1Info.height;
|
|
20540
|
+
let x = column1.left + column1.width,
|
|
20541
|
+
cursorIndex = this.getColumnIndex(cache, column1);
|
|
20542
|
+
p1.x < column1.left + column1.width / 2 && (x = column1.left, cursorIndex -= 1), p1.x = x, p1.y = (y1 + y2) / 2;
|
|
20543
|
+
let line0Info = this.getLineByPoint(cache, p0);
|
|
20544
|
+
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) {
|
|
20545
|
+
const column0 = this.getColumnByLinePoint(line0Info, p0);
|
|
20546
|
+
this.editBg.setAttributes({
|
|
20547
|
+
x: p0.x,
|
|
20548
|
+
y: line0Info.top,
|
|
20549
|
+
width: p1.x - p0.x,
|
|
20550
|
+
height: column0.height,
|
|
20551
|
+
fill: "#336df4",
|
|
20552
|
+
fillOpacity: .2
|
|
20553
|
+
});
|
|
20554
|
+
} else {
|
|
20555
|
+
this.editBg.setAttributes({
|
|
20556
|
+
x: 0,
|
|
20557
|
+
y: line0Info.top,
|
|
20558
|
+
width: 0,
|
|
20559
|
+
height: 0
|
|
20560
|
+
});
|
|
20561
|
+
const startIdx = cache.lines.findIndex(item => item === line0Info),
|
|
20562
|
+
endIdx = cache.lines.findIndex(item => item === line1Info);
|
|
20563
|
+
let y = 0;
|
|
20564
|
+
for (let i = startIdx; i <= endIdx; i++) {
|
|
20565
|
+
const line = cache.lines[i];
|
|
20566
|
+
if (i === startIdx) {
|
|
20567
|
+
const p = line.paragraphs[line.paragraphs.length - 1];
|
|
20568
|
+
this.editBg.add(createRect({
|
|
20569
|
+
x: p0.x,
|
|
20570
|
+
y: y,
|
|
20571
|
+
width: p.left + p.width - p0.x,
|
|
20572
|
+
height: line.height,
|
|
20573
|
+
fill: "#336df4",
|
|
20574
|
+
fillOpacity: .2
|
|
20575
|
+
}));
|
|
20576
|
+
} else if (i === endIdx) {
|
|
20577
|
+
const p = line.paragraphs[0];
|
|
20578
|
+
this.editBg.add(createRect({
|
|
20579
|
+
x: p.left,
|
|
20580
|
+
y: y,
|
|
20581
|
+
width: p1.x - p.left,
|
|
20582
|
+
height: line.height,
|
|
20583
|
+
fill: "#336df4",
|
|
20584
|
+
fillOpacity: .2
|
|
20585
|
+
}));
|
|
20586
|
+
} else {
|
|
20587
|
+
const p0 = line.paragraphs[0],
|
|
20588
|
+
p1 = line.paragraphs[line.paragraphs.length - 1];
|
|
20589
|
+
this.editBg.add(createRect({
|
|
20590
|
+
x: p0.left,
|
|
20591
|
+
y: y,
|
|
20592
|
+
width: p1.left + p1.width - p0.left,
|
|
20593
|
+
height: line.height,
|
|
20594
|
+
fill: "#336df4",
|
|
20595
|
+
fillOpacity: .2
|
|
20596
|
+
}));
|
|
20597
|
+
}
|
|
20598
|
+
y += line.height;
|
|
20599
|
+
}
|
|
20600
|
+
}
|
|
20601
|
+
this.curCursorIdx = cursorIndex, this.setCursorAndTextArea(x, y1 + 2, y2 - 2, e.target), this.applyUpdate(), this.updateCbs.forEach(cb => cb("selection", this));
|
|
20602
|
+
}
|
|
20603
|
+
}
|
|
20604
|
+
hideSelection() {
|
|
20605
|
+
this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
|
|
20606
|
+
fill: "transparent"
|
|
20607
|
+
}));
|
|
20608
|
+
}
|
|
20609
|
+
isRichtext(e) {
|
|
20610
|
+
return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
|
|
20611
|
+
}
|
|
20612
|
+
getEventPosition(e) {
|
|
20613
|
+
const p = this.pluginService.stage.eventPointTransform(e),
|
|
20614
|
+
p1 = {
|
|
20615
|
+
x: 0,
|
|
20616
|
+
y: 0
|
|
20617
|
+
};
|
|
20618
|
+
return e.target.globalTransMatrix.transformPoint(p, p1), p1;
|
|
20619
|
+
}
|
|
20620
|
+
getLineByPoint(cache, p1) {
|
|
20621
|
+
let lineInfo = cache.lines[0];
|
|
20622
|
+
for (let i = 0; i < cache.lines.length && !(lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y); i++) lineInfo = cache.lines[i + 1];
|
|
20623
|
+
return lineInfo;
|
|
20624
|
+
}
|
|
20625
|
+
getColumnByLinePoint(lineInfo, p1) {
|
|
20626
|
+
let columnInfo = lineInfo.paragraphs[0];
|
|
20627
|
+
for (let i = 0; i < lineInfo.paragraphs.length && !(columnInfo.left <= p1.x && columnInfo.left + columnInfo.width >= p1.x); i++) columnInfo = lineInfo.paragraphs[i];
|
|
20628
|
+
return columnInfo;
|
|
20629
|
+
}
|
|
20630
|
+
onFocus(e) {
|
|
20631
|
+
this.deFocus(e);
|
|
20632
|
+
const target = e.target;
|
|
20633
|
+
this.tryUpdateRichtext(target);
|
|
20634
|
+
const shadowRoot = target.attachShadow();
|
|
20635
|
+
shadowRoot.setAttributes({
|
|
20636
|
+
shadowRootIdx: -1
|
|
20637
|
+
});
|
|
20638
|
+
const cache = target.getFrameCache();
|
|
20639
|
+
if (!cache) return;
|
|
20640
|
+
if (!this.editLine) {
|
|
20641
|
+
const line = createLine({
|
|
20642
|
+
x: 0,
|
|
20643
|
+
y: 0,
|
|
20644
|
+
lineWidth: 1,
|
|
20645
|
+
stroke: "black"
|
|
20646
|
+
});
|
|
20647
|
+
line.animate().to({
|
|
20648
|
+
opacity: 1
|
|
20649
|
+
}, 10, "linear").wait(700).to({
|
|
20650
|
+
opacity: 0
|
|
20651
|
+
}, 10, "linear").wait(700).loop(1 / 0), this.editLine = line;
|
|
20652
|
+
const g = createGroup({
|
|
20653
|
+
x: 0,
|
|
20654
|
+
y: 0,
|
|
20655
|
+
width: 0,
|
|
20656
|
+
height: 0
|
|
20657
|
+
});
|
|
20658
|
+
this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
|
|
20659
|
+
}
|
|
20660
|
+
const p1 = this.getEventPosition(e),
|
|
20661
|
+
lineInfo = this.getLineByPoint(cache, p1);
|
|
20662
|
+
if (lineInfo) {
|
|
20663
|
+
const columnInfo = this.getColumnByLinePoint(lineInfo, p1);
|
|
20664
|
+
if (!columnInfo) return;
|
|
20665
|
+
let y1 = lineInfo.top,
|
|
20666
|
+
y2 = lineInfo.top + lineInfo.height,
|
|
20667
|
+
x = columnInfo.left + columnInfo.width;
|
|
20668
|
+
y1 += 2, y2 -= 2;
|
|
20669
|
+
let cursorIndex = this.getColumnIndex(cache, columnInfo);
|
|
20670
|
+
p1.x < columnInfo.left + columnInfo.width / 2 && (x = columnInfo.left, cursorIndex -= 1), this.lastPoint = {
|
|
20671
|
+
x: x,
|
|
20672
|
+
y: (y1 + y2) / 2
|
|
20673
|
+
}, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex, this.setCursorAndTextArea(x, y1, y2, target);
|
|
20674
|
+
}
|
|
20675
|
+
}
|
|
20676
|
+
getPointByColumnIdx(idx, rt, orient) {
|
|
20677
|
+
const cache = rt.getFrameCache(),
|
|
20678
|
+
{
|
|
20679
|
+
lineInfo: lineInfo,
|
|
20680
|
+
columnInfo: columnInfo
|
|
20681
|
+
} = this.getColumnByIndex(cache, idx);
|
|
20682
|
+
let y1 = lineInfo.top,
|
|
20683
|
+
y2 = lineInfo.top + lineInfo.height;
|
|
20684
|
+
return y1 += 2, y2 -= 2, {
|
|
20685
|
+
x: columnInfo.left + ("left" === orient ? 0 : columnInfo.width),
|
|
20686
|
+
y1: y1,
|
|
20687
|
+
y2: y2
|
|
20688
|
+
};
|
|
20689
|
+
}
|
|
20690
|
+
getColumnIndex(cache, cInfo) {
|
|
20691
|
+
let inputIndex = -1;
|
|
20692
|
+
for (let i = 0; i < cache.lines.length; i++) {
|
|
20693
|
+
const line = cache.lines[i];
|
|
20694
|
+
for (let j = 0; j < line.paragraphs.length; j++) if (inputIndex++, cInfo === line.paragraphs[j]) return inputIndex;
|
|
20695
|
+
}
|
|
20696
|
+
return -1;
|
|
20697
|
+
}
|
|
20698
|
+
getColumnByIndex(cache, index) {
|
|
20699
|
+
let inputIndex = -1;
|
|
20700
|
+
for (let i = 0; i < cache.lines.length; i++) {
|
|
20701
|
+
const lineInfo = cache.lines[i];
|
|
20702
|
+
for (let j = 0; j < lineInfo.paragraphs.length; j++) {
|
|
20703
|
+
const columnInfo = lineInfo.paragraphs[j];
|
|
20704
|
+
if (inputIndex++, inputIndex === index) return {
|
|
20705
|
+
lineInfo: lineInfo,
|
|
20706
|
+
columnInfo: columnInfo
|
|
20707
|
+
};
|
|
20708
|
+
}
|
|
20709
|
+
}
|
|
20710
|
+
return null;
|
|
20711
|
+
}
|
|
20712
|
+
setCursorAndTextArea(x, y1, y2, rt) {
|
|
20713
|
+
this.editLine.setAttributes({
|
|
20714
|
+
points: [{
|
|
20715
|
+
x: x,
|
|
20716
|
+
y: y1
|
|
20717
|
+
}, {
|
|
20718
|
+
x: x,
|
|
20719
|
+
y: y2
|
|
20720
|
+
}]
|
|
20721
|
+
});
|
|
20722
|
+
const out = {
|
|
20723
|
+
x: 0,
|
|
20724
|
+
y: 0
|
|
20725
|
+
};
|
|
20726
|
+
rt.globalTransMatrix.getInverse().transformPoint({
|
|
20727
|
+
x: x,
|
|
20728
|
+
y: y1
|
|
20729
|
+
}, out);
|
|
20730
|
+
const {
|
|
20731
|
+
left: left,
|
|
20732
|
+
top: top
|
|
20733
|
+
} = this.pluginService.stage.window.getBoundingClientRect();
|
|
20734
|
+
out.x += left, out.y += top, this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
|
|
20735
|
+
}
|
|
20736
|
+
setCursor(x, y1, y2) {
|
|
20737
|
+
this.editLine.setAttributes({
|
|
20738
|
+
points: [{
|
|
20739
|
+
x: x,
|
|
20740
|
+
y: y1
|
|
20741
|
+
}, {
|
|
20742
|
+
x: x,
|
|
20743
|
+
y: y2
|
|
20744
|
+
}]
|
|
20745
|
+
});
|
|
20746
|
+
}
|
|
20747
|
+
applyUpdate() {
|
|
20748
|
+
this.pluginService.stage.renderNextFrame();
|
|
20749
|
+
}
|
|
20750
|
+
deFocus(e) {
|
|
20751
|
+
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);
|
|
20752
|
+
}
|
|
20753
|
+
splitText(text) {
|
|
20754
|
+
return Array.from(text);
|
|
20755
|
+
}
|
|
20756
|
+
tryUpdateRichtext(richtext) {
|
|
20757
|
+
if (!richtext.getFrameCache().lines.every(line => line.paragraphs.every(item => !(item.text && isString$1(item.text) && this.splitText(item.text).length > 1)))) {
|
|
20758
|
+
const tc = [];
|
|
20759
|
+
richtext.attribute.textConfig.forEach(item => {
|
|
20760
|
+
const textList = this.splitText(item.text.toString());
|
|
20761
|
+
if (isString$1(item.text) && textList.length > 1) for (let i = 0; i < textList.length; i++) {
|
|
20762
|
+
const t = textList[i];
|
|
20763
|
+
tc.push(Object.assign(Object.assign({}, item), {
|
|
20764
|
+
text: t
|
|
20765
|
+
}));
|
|
20766
|
+
} else tc.push(item);
|
|
20767
|
+
}), richtext.setAttributes({
|
|
20768
|
+
textConfig: tc
|
|
20769
|
+
}), richtext.doUpdateFrameCache(tc);
|
|
20770
|
+
}
|
|
20771
|
+
}
|
|
20772
|
+
onSelect() {}
|
|
20773
|
+
deactivate(context) {
|
|
20774
|
+
context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown), context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp);
|
|
20775
|
+
}
|
|
20776
|
+
release() {
|
|
20777
|
+
this.editModule.release();
|
|
20778
|
+
}
|
|
20779
|
+
}
|
|
20780
|
+
|
|
20293
20781
|
class DefaultGraphicAllocate {
|
|
20294
20782
|
constructor() {
|
|
20295
20783
|
this.pools = [];
|
|
@@ -25927,13 +26415,20 @@
|
|
|
25927
26415
|
} catch (err) {}
|
|
25928
26416
|
function makeUpCanvas$3(domref, canvasIdLists, canvasMap, freeCanvasIdx, freeCanvasList, offscreen, pixelRatio) {
|
|
25929
26417
|
const dpr = null != pixelRatio ? pixelRatio : SystemInfo.pixelRatio;
|
|
25930
|
-
canvasIdLists.forEach((id, i) => {
|
|
26418
|
+
if (canvasIdLists.forEach((id, i) => {
|
|
25931
26419
|
let _canvas;
|
|
25932
26420
|
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
26421
|
const ctx = _canvas.getContext("2d"),
|
|
25934
26422
|
canvas = new CanvasWrapEnableWH(_canvas, ctx, dpr, domref.width, domref.height, id);
|
|
25935
|
-
canvasMap.set(id, canvas), i
|
|
25936
|
-
})
|
|
26423
|
+
canvasMap.set(id, canvas), i > freeCanvasIdx && freeCanvasList.push(canvas);
|
|
26424
|
+
}), !freeCanvasList.length && lynx.createOffscreenCanvas) {
|
|
26425
|
+
const _canvas = lynx.createOffscreenCanvas();
|
|
26426
|
+
_canvas.width = domref.width * dpr, _canvas.height = domref.height * dpr;
|
|
26427
|
+
const ctx = _canvas.getContext("2d"),
|
|
26428
|
+
id = Math.random().toString(),
|
|
26429
|
+
canvas = new CanvasWrapEnableWH(_canvas, ctx, dpr, domref.width, domref.height, id);
|
|
26430
|
+
canvasMap.set(id, canvas), freeCanvasList.push(canvas);
|
|
26431
|
+
}
|
|
25937
26432
|
}
|
|
25938
26433
|
function createImageElement(src) {
|
|
25939
26434
|
let isSvg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
|
|
@@ -28600,7 +29095,7 @@
|
|
|
28600
29095
|
|
|
28601
29096
|
const roughModule = _roughModule;
|
|
28602
29097
|
|
|
28603
|
-
const version = "0.19.
|
|
29098
|
+
const version = "0.19.14-alpha.1";
|
|
28604
29099
|
preLoadAllModule();
|
|
28605
29100
|
if (isBrowserEnv()) {
|
|
28606
29101
|
loadBrowserEnv(container);
|
|
@@ -28751,6 +29246,8 @@
|
|
|
28751
29246
|
exports.EventManager = EventManager;
|
|
28752
29247
|
exports.EventSystem = EventSystem;
|
|
28753
29248
|
exports.EventTarget = EventTarget;
|
|
29249
|
+
exports.FORMAT_ELEMENT_COMMAND = FORMAT_ELEMENT_COMMAND;
|
|
29250
|
+
exports.FORMAT_TEXT_COMMAND = FORMAT_TEXT_COMMAND;
|
|
28754
29251
|
exports.FadeInPlus = FadeInPlus;
|
|
28755
29252
|
exports.FederatedEvent = FederatedEvent;
|
|
28756
29253
|
exports.FederatedMouseEvent = FederatedMouseEvent;
|
|
@@ -28851,6 +29348,7 @@
|
|
|
28851
29348
|
exports.RenderService = RenderService;
|
|
28852
29349
|
exports.ResourceLoader = ResourceLoader;
|
|
28853
29350
|
exports.RichText = RichText;
|
|
29351
|
+
exports.RichTextEditPlugin = RichTextEditPlugin;
|
|
28854
29352
|
exports.RichTextRender = RichTextRender;
|
|
28855
29353
|
exports.RotateBySphereAnimate = RotateBySphereAnimate;
|
|
28856
29354
|
exports.SVG_ATTRIBUTE_MAP = SVG_ATTRIBUTE_MAP;
|