@antv/g-lite 2.2.9 → 2.2.11
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/index.esm.js +160 -155
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +160 -155
- package/dist/index.js.map +1 -1
- package/dist/index.umd.min.js +5 -5
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/types/Canvas.d.ts +12 -38
- package/types/Canvas.d.ts.map +1 -1
- package/types/css/StyleValueRegistry.d.ts.map +1 -1
- package/types/css/parser/dimension.d.ts +1 -1
- package/types/css/parser/dimension.d.ts.map +1 -1
- package/types/dom/Node.d.ts +0 -4
- package/types/dom/Node.d.ts.map +1 -1
- package/types/dom/interfaces.d.ts +53 -27
- package/types/dom/interfaces.d.ts.map +1 -1
- package/types/services/EventService.d.ts +0 -1
- package/types/services/EventService.d.ts.map +1 -1
- package/types/services/TextService.d.ts.map +1 -1
- package/types/types.d.ts +33 -47
- package/types/types.d.ts.map +1 -1
- package/types/utils/path.d.ts.map +1 -1
- package/types/utils/raf.d.ts +2 -5
- package/types/utils/raf.d.ts.map +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @antv/g-lite
|
|
3
3
|
* @description A core module for rendering engine implements DOM API.
|
|
4
|
-
* @version 2.2.
|
|
5
|
-
* @date
|
|
4
|
+
* @version 2.2.11
|
|
5
|
+
* @date 12/26/2024, 8:33:47 AM
|
|
6
6
|
* @author AntVis
|
|
7
7
|
* @docs https://g.antv.antgroup.com/
|
|
8
8
|
*/
|
|
@@ -4213,16 +4213,22 @@ function parseDimensionArrayFormat(string, size) {
|
|
|
4213
4213
|
}
|
|
4214
4214
|
return [parsed[0], parsed[1]];
|
|
4215
4215
|
}
|
|
4216
|
-
if (
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4216
|
+
if (size === 4) {
|
|
4217
|
+
if (parsed.length === 1) {
|
|
4218
|
+
return [parsed[0], parsed[0], parsed[0], parsed[0]];
|
|
4219
|
+
}
|
|
4220
|
+
if (parsed.length === 2) {
|
|
4221
|
+
return [parsed[0], parsed[1], parsed[0], parsed[1]];
|
|
4222
|
+
}
|
|
4223
|
+
if (parsed.length === 3) {
|
|
4224
|
+
return [parsed[0], parsed[1], parsed[2], parsed[1]];
|
|
4225
|
+
}
|
|
4226
|
+
return [parsed[0], parsed[1], parsed[2], parsed[3]];
|
|
4221
4227
|
}
|
|
4222
|
-
if (parsed.length ===
|
|
4223
|
-
return [
|
|
4228
|
+
if (size === 'even' && parsed.length % 2 === 1) {
|
|
4229
|
+
return [].concat(_toConsumableArray(parsed), _toConsumableArray(parsed));
|
|
4224
4230
|
}
|
|
4225
|
-
return
|
|
4231
|
+
return parsed;
|
|
4226
4232
|
}
|
|
4227
4233
|
|
|
4228
4234
|
// export function mergeDimensionList(
|
|
@@ -5088,7 +5094,7 @@ function translatePathToString(absolutePath) {
|
|
|
5088
5094
|
case 'C':
|
|
5089
5095
|
return "C ".concat(params[1], " ").concat(params[2], ",").concat(params[3], " ").concat(params[4], ",").concat(params[5] + endOffsetXTemp, " ").concat(params[6] + endOffsetYTemp);
|
|
5090
5096
|
case 'A':
|
|
5091
|
-
return "A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6] +
|
|
5097
|
+
return "A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6], " ").concat(params[7]).concat(useEndOffset ? " L ".concat(params[6] + endOffsetX, ",").concat(params[7] + endOffsetY) : '');
|
|
5092
5098
|
case 'Z':
|
|
5093
5099
|
return 'Z';
|
|
5094
5100
|
default:
|
|
@@ -6425,7 +6431,8 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
6425
6431
|
}
|
|
6426
6432
|
// Polyline
|
|
6427
6433
|
if (list.has('lineDash') && !util.isNil(attributes.lineDash)) {
|
|
6428
|
-
|
|
6434
|
+
// dom标准自动转化奇数长度数组,webgl需要手动处理
|
|
6435
|
+
object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 'even');
|
|
6429
6436
|
}
|
|
6430
6437
|
// @ts-ignore
|
|
6431
6438
|
if (list.has('points') && attributes.points) {
|
|
@@ -8884,11 +8891,6 @@ var Node = /*#__PURE__*/function (_EventTarget) {
|
|
|
8884
8891
|
}
|
|
8885
8892
|
return temp;
|
|
8886
8893
|
}
|
|
8887
|
-
|
|
8888
|
-
/**
|
|
8889
|
-
* iterate current node and its descendants
|
|
8890
|
-
* @param callback - callback to execute for each node, return false to break
|
|
8891
|
-
*/
|
|
8892
8894
|
}, {
|
|
8893
8895
|
key: "forEach",
|
|
8894
8896
|
value: function forEach(callback) {
|
|
@@ -8942,7 +8944,6 @@ var EventService = /*#__PURE__*/function () {
|
|
|
8942
8944
|
function EventService(globalRuntime, context) {
|
|
8943
8945
|
var _this = this;
|
|
8944
8946
|
_classCallCheck(this, EventService);
|
|
8945
|
-
this.emitter = new EventEmitter();
|
|
8946
8947
|
/**
|
|
8947
8948
|
* Store HTML elements in current canvas.
|
|
8948
8949
|
*/
|
|
@@ -9019,7 +9020,7 @@ var EventService = /*#__PURE__*/function () {
|
|
|
9019
9020
|
}
|
|
9020
9021
|
var canvas = _this.context.renderingContext.root.ownerDocument.defaultView;
|
|
9021
9022
|
var clickHistory = trackingData.clicksByButton[from.button];
|
|
9022
|
-
if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.dblClickSpeed) {
|
|
9023
|
+
if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.getConfig().dblClickSpeed) {
|
|
9023
9024
|
++clickHistory.clickCount;
|
|
9024
9025
|
} else {
|
|
9025
9026
|
clickHistory.clickCount = 1;
|
|
@@ -9234,7 +9235,6 @@ var EventService = /*#__PURE__*/function () {
|
|
|
9234
9235
|
}, {
|
|
9235
9236
|
key: "destroy",
|
|
9236
9237
|
value: function destroy() {
|
|
9237
|
-
this.emitter.removeAllListeners();
|
|
9238
9238
|
this.mappingTable = {};
|
|
9239
9239
|
this.mappingState = {};
|
|
9240
9240
|
this.eventPool.clear();
|
|
@@ -9370,7 +9370,6 @@ var EventService = /*#__PURE__*/function () {
|
|
|
9370
9370
|
e.currentTarget = canvas;
|
|
9371
9371
|
this.notifyListeners(e, type);
|
|
9372
9372
|
}
|
|
9373
|
-
this.emitter.emit(type || e.type, e);
|
|
9374
9373
|
}
|
|
9375
9374
|
}, {
|
|
9376
9375
|
key: "propagate",
|
|
@@ -10225,22 +10224,35 @@ var DefaultSceneGraphSelector = /*#__PURE__*/function () {
|
|
|
10225
10224
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
|
|
10226
10225
|
*/
|
|
10227
10226
|
var ElementEvent = /*#__PURE__*/function (ElementEvent) {
|
|
10228
|
-
ElementEvent["REPARENT"] = "reparent";
|
|
10229
|
-
ElementEvent["DESTROY"] = "destroy";
|
|
10230
10227
|
ElementEvent["ATTR_MODIFIED"] = "DOMAttrModified";
|
|
10231
10228
|
ElementEvent["INSERTED"] = "DOMNodeInserted";
|
|
10232
|
-
ElementEvent["REMOVED"] = "removed";
|
|
10233
10229
|
ElementEvent["MOUNTED"] = "DOMNodeInsertedIntoDocument";
|
|
10230
|
+
ElementEvent["REMOVED"] = "removed";
|
|
10234
10231
|
ElementEvent["UNMOUNTED"] = "DOMNodeRemovedFromDocument";
|
|
10232
|
+
ElementEvent["REPARENT"] = "reparent";
|
|
10233
|
+
ElementEvent["DESTROY"] = "destroy";
|
|
10235
10234
|
ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
|
|
10236
10235
|
ElementEvent["CULLED"] = "culled";
|
|
10237
10236
|
return ElementEvent;
|
|
10238
10237
|
}({});
|
|
10239
10238
|
|
|
10239
|
+
// #region EventTarget
|
|
10240
|
+
|
|
10241
|
+
// #region Node
|
|
10242
|
+
|
|
10243
|
+
// #region Element
|
|
10244
|
+
|
|
10245
|
+
// #region AnimationTimeline
|
|
10246
|
+
|
|
10247
|
+
// #region Document
|
|
10248
|
+
|
|
10249
|
+
// #region CSSStyleDeclaration
|
|
10240
10250
|
/**
|
|
10241
10251
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/CSSStyleDeclaration
|
|
10242
10252
|
*/
|
|
10243
10253
|
|
|
10254
|
+
// #region Canvas
|
|
10255
|
+
|
|
10244
10256
|
var MutationEvent = /*#__PURE__*/function (_FederatedEvent) {
|
|
10245
10257
|
function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
|
|
10246
10258
|
var _this;
|
|
@@ -11487,99 +11499,123 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11487
11499
|
} else if (textOverflow && textOverflow !== 'clip') {
|
|
11488
11500
|
ellipsis = textOverflow;
|
|
11489
11501
|
}
|
|
11502
|
+
var chars = Array.from(text);
|
|
11490
11503
|
var lines = [];
|
|
11491
|
-
var
|
|
11492
|
-
var
|
|
11504
|
+
var currentLineIndex = 0;
|
|
11505
|
+
var currentLineWidth = 0;
|
|
11493
11506
|
var cache = {};
|
|
11494
|
-
var calcWidth = function calcWidth(
|
|
11495
|
-
return _this2.getFromCache(
|
|
11507
|
+
var calcWidth = function calcWidth(txt) {
|
|
11508
|
+
return _this2.getFromCache(txt, letterSpacing, cache, context);
|
|
11496
11509
|
};
|
|
11497
|
-
var ellipsisWidth =
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11510
|
+
var ellipsisWidth = calcWidth(ellipsis);
|
|
11511
|
+
|
|
11512
|
+
/**
|
|
11513
|
+
* Find text fragments that will take up as much of the given line width as possible when rendered.
|
|
11514
|
+
*
|
|
11515
|
+
* @see https://github.com/antvis/G/issues/1833
|
|
11516
|
+
*
|
|
11517
|
+
* @param txt - Current line of text
|
|
11518
|
+
* @param textCharIndex - The index of the last character of the current line in the entire text
|
|
11519
|
+
*/
|
|
11520
|
+
function findCharIndexClosestWidthThreshold(txt, textCharIndex, widthThreshold) {
|
|
11521
|
+
while (calcWidth(txt) < widthThreshold && textCharIndex < chars.length - 1) {
|
|
11522
|
+
textCharIndex += 1;
|
|
11523
|
+
txt += chars[textCharIndex];
|
|
11524
|
+
}
|
|
11525
|
+
while (calcWidth(txt) > widthThreshold) {
|
|
11526
|
+
textCharIndex -= 1;
|
|
11527
|
+
txt = txt.slice(0, -1);
|
|
11528
|
+
}
|
|
11529
|
+
return {
|
|
11530
|
+
txt: txt,
|
|
11531
|
+
textCharIndex: textCharIndex
|
|
11532
|
+
};
|
|
11533
|
+
}
|
|
11534
|
+
function appendEllipsis(lineIndex, textCharIndex) {
|
|
11501
11535
|
// If there is not enough space to display the string itself, it is clipped.
|
|
11502
11536
|
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values
|
|
11503
11537
|
if (ellipsisWidth <= 0 || ellipsisWidth > maxWidth) {
|
|
11504
11538
|
return;
|
|
11505
11539
|
}
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
var lastLineWidth = 0;
|
|
11510
|
-
var lastLineIndex = currentLineLength;
|
|
11511
|
-
for (var i = 0; i < currentLineLength; i++) {
|
|
11512
|
-
var width = calcWidth(lines[lineIndex][i]);
|
|
11513
|
-
if (lastLineWidth + width + ellipsisWidth > maxWidth) {
|
|
11514
|
-
lastLineIndex = i;
|
|
11515
|
-
break;
|
|
11516
|
-
}
|
|
11517
|
-
lastLineWidth += width;
|
|
11540
|
+
if (!lines[lineIndex]) {
|
|
11541
|
+
lines[lineIndex] = ellipsis;
|
|
11542
|
+
return;
|
|
11518
11543
|
}
|
|
11519
|
-
|
|
11544
|
+
var result = findCharIndexClosestWidthThreshold(lines[lineIndex], textCharIndex, maxWidth - ellipsisWidth);
|
|
11545
|
+
lines[lineIndex] = result.txt + ellipsis;
|
|
11520
11546
|
}
|
|
11521
|
-
var chars = Array.from(text);
|
|
11522
11547
|
for (var i = 0; i < chars.length; i++) {
|
|
11523
|
-
var
|
|
11524
|
-
var prevChar =
|
|
11525
|
-
var nextChar =
|
|
11526
|
-
var charWidth = calcWidth(
|
|
11527
|
-
if (this.isNewline(
|
|
11528
|
-
currentIndex++;
|
|
11529
|
-
|
|
11548
|
+
var _char2 = chars[i];
|
|
11549
|
+
var prevChar = chars[i - 1];
|
|
11550
|
+
var nextChar = chars[i + 1];
|
|
11551
|
+
var charWidth = calcWidth(_char2);
|
|
11552
|
+
if (this.isNewline(_char2)) {
|
|
11530
11553
|
// exceed maxLines, break immediately
|
|
11531
|
-
if (
|
|
11554
|
+
if (currentLineIndex + 1 >= maxLines) {
|
|
11532
11555
|
parsedStyle.isOverflowing = true;
|
|
11533
11556
|
if (i < chars.length - 1) {
|
|
11534
|
-
appendEllipsis(
|
|
11557
|
+
appendEllipsis(currentLineIndex, i);
|
|
11535
11558
|
}
|
|
11536
11559
|
break;
|
|
11537
11560
|
}
|
|
11538
|
-
|
|
11539
|
-
|
|
11561
|
+
currentLineIndex += 1;
|
|
11562
|
+
currentLineWidth = 0;
|
|
11563
|
+
lines[currentLineIndex] = '';
|
|
11540
11564
|
continue;
|
|
11541
11565
|
}
|
|
11542
|
-
if (
|
|
11543
|
-
|
|
11566
|
+
if (currentLineWidth > 0 && currentLineWidth + charWidth > maxWidth) {
|
|
11567
|
+
var result = findCharIndexClosestWidthThreshold(lines[currentLineIndex], i, maxWidth);
|
|
11568
|
+
if (result.textCharIndex !== i) {
|
|
11569
|
+
lines[currentLineIndex] = result.txt;
|
|
11570
|
+
if (result.textCharIndex === chars.length - 1) {
|
|
11571
|
+
break;
|
|
11572
|
+
}
|
|
11573
|
+
i = result.textCharIndex;
|
|
11574
|
+
_char2 = chars[i];
|
|
11575
|
+
prevChar = chars[i - 1];
|
|
11576
|
+
nextChar = chars[i + 1];
|
|
11577
|
+
charWidth = calcWidth(_char2);
|
|
11578
|
+
}
|
|
11579
|
+
if (currentLineIndex + 1 >= maxLines) {
|
|
11544
11580
|
parsedStyle.isOverflowing = true;
|
|
11545
|
-
appendEllipsis(
|
|
11581
|
+
appendEllipsis(currentLineIndex, i);
|
|
11546
11582
|
break;
|
|
11547
11583
|
}
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
lines[
|
|
11551
|
-
if (this.isBreakingSpace(
|
|
11584
|
+
currentLineIndex += 1;
|
|
11585
|
+
currentLineWidth = 0;
|
|
11586
|
+
lines[currentLineIndex] = '';
|
|
11587
|
+
if (this.isBreakingSpace(_char2)) {
|
|
11552
11588
|
continue;
|
|
11553
11589
|
}
|
|
11554
|
-
if (!this.canBreakInLastChar(
|
|
11590
|
+
if (!this.canBreakInLastChar(_char2)) {
|
|
11555
11591
|
lines = this.trimToBreakable(lines);
|
|
11556
|
-
|
|
11592
|
+
currentLineWidth = this.sumTextWidthByCache(lines[currentLineIndex] || '', cache);
|
|
11557
11593
|
}
|
|
11558
|
-
if (this.shouldBreakByKinsokuShorui(
|
|
11594
|
+
if (this.shouldBreakByKinsokuShorui(_char2, nextChar)) {
|
|
11559
11595
|
lines = this.trimByKinsokuShorui(lines);
|
|
11560
|
-
|
|
11596
|
+
currentLineWidth += calcWidth(prevChar || '');
|
|
11561
11597
|
}
|
|
11562
11598
|
}
|
|
11563
|
-
|
|
11564
|
-
lines[
|
|
11599
|
+
currentLineWidth += charWidth;
|
|
11600
|
+
lines[currentLineIndex] = (lines[currentLineIndex] || '') + _char2;
|
|
11565
11601
|
}
|
|
11566
11602
|
return lines.join('\n');
|
|
11567
11603
|
}
|
|
11568
11604
|
}, {
|
|
11569
11605
|
key: "isBreakingSpace",
|
|
11570
|
-
value: function isBreakingSpace(
|
|
11571
|
-
if (typeof
|
|
11606
|
+
value: function isBreakingSpace(_char3) {
|
|
11607
|
+
if (typeof _char3 !== 'string') {
|
|
11572
11608
|
return false;
|
|
11573
11609
|
}
|
|
11574
|
-
return TEXT_METRICS.BreakingSpaces.indexOf(
|
|
11610
|
+
return TEXT_METRICS.BreakingSpaces.indexOf(_char3.charCodeAt(0)) >= 0;
|
|
11575
11611
|
}
|
|
11576
11612
|
}, {
|
|
11577
11613
|
key: "isNewline",
|
|
11578
|
-
value: function isNewline(
|
|
11579
|
-
if (typeof
|
|
11614
|
+
value: function isNewline(_char4) {
|
|
11615
|
+
if (typeof _char4 !== 'string') {
|
|
11580
11616
|
return false;
|
|
11581
11617
|
}
|
|
11582
|
-
return TEXT_METRICS.Newlines.indexOf(
|
|
11618
|
+
return TEXT_METRICS.Newlines.indexOf(_char4.charCodeAt(0)) >= 0;
|
|
11583
11619
|
}
|
|
11584
11620
|
}, {
|
|
11585
11621
|
key: "trimToBreakable",
|
|
@@ -11598,8 +11634,8 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11598
11634
|
}
|
|
11599
11635
|
}, {
|
|
11600
11636
|
key: "canBreakInLastChar",
|
|
11601
|
-
value: function canBreakInLastChar(
|
|
11602
|
-
if (
|
|
11637
|
+
value: function canBreakInLastChar(_char5) {
|
|
11638
|
+
if (_char5 && LATIN_REGEX.test(_char5)) return false;
|
|
11603
11639
|
return true;
|
|
11604
11640
|
}
|
|
11605
11641
|
}, {
|
|
@@ -11624,7 +11660,8 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11624
11660
|
var width = cache[key];
|
|
11625
11661
|
if (typeof width !== 'number') {
|
|
11626
11662
|
var spacing = key.length * letterSpacing;
|
|
11627
|
-
|
|
11663
|
+
var metrics = context.measureText(key);
|
|
11664
|
+
width = metrics.width + spacing;
|
|
11628
11665
|
cache[key] = width;
|
|
11629
11666
|
}
|
|
11630
11667
|
return width;
|
|
@@ -15311,109 +15348,63 @@ var afterRenderEvent = new CustomEvent(CanvasEvent.AFTER_RENDER);
|
|
|
15311
15348
|
* * `window.devicePixelRatio`
|
|
15312
15349
|
*
|
|
15313
15350
|
* prototype chains: Canvas(Window) -> EventTarget
|
|
15351
|
+
*
|
|
15352
|
+
* @docs https://g.antv.antgroup.com/api/canvas/intro
|
|
15314
15353
|
*/
|
|
15315
15354
|
var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
15316
15355
|
function Canvas(config) {
|
|
15317
15356
|
var _this;
|
|
15318
15357
|
_classCallCheck(this, Canvas);
|
|
15319
15358
|
_this = _callSuper(this, Canvas);
|
|
15320
|
-
|
|
15321
|
-
// create document
|
|
15359
|
+
// #region environment
|
|
15322
15360
|
/**
|
|
15323
15361
|
* window.document
|
|
15324
15362
|
*/
|
|
15325
|
-
/**
|
|
15326
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
|
|
15327
|
-
*/
|
|
15328
|
-
/**
|
|
15329
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
|
|
15330
|
-
*/
|
|
15331
|
-
/**
|
|
15332
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
|
|
15333
|
-
*/
|
|
15334
|
-
/**
|
|
15335
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
|
|
15336
|
-
*/
|
|
15337
|
-
/**
|
|
15338
|
-
* whether the runtime supports PointerEvent?
|
|
15339
|
-
* if not, the event system won't trigger pointer events like `pointerdown`
|
|
15340
|
-
*/
|
|
15341
|
-
/**
|
|
15342
|
-
* whether the runtime supports TouchEvent?
|
|
15343
|
-
* if not, the event system won't trigger touch events like `touchstart`
|
|
15344
|
-
*/
|
|
15345
|
-
/**
|
|
15346
|
-
* is this native event a TouchEvent?
|
|
15347
|
-
*/
|
|
15348
|
-
/**
|
|
15349
|
-
* is this native event a MouseEvent?
|
|
15350
|
-
*/
|
|
15351
15363
|
/**
|
|
15352
15364
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
15353
15365
|
*/
|
|
15354
15366
|
_this.Element = DisplayObject;
|
|
15355
15367
|
_this.inited = false;
|
|
15356
15368
|
_this.context = {};
|
|
15357
|
-
_this.document = new Document();
|
|
15358
|
-
_this.document.defaultView = _this;
|
|
15359
|
-
|
|
15360
|
-
// create registry of custom elements
|
|
15361
|
-
_this.customElements = new CustomElementRegistry();
|
|
15362
15369
|
var container = config.container,
|
|
15363
15370
|
canvas = config.canvas,
|
|
15364
|
-
|
|
15371
|
+
renderer = config.renderer,
|
|
15365
15372
|
width = config.width,
|
|
15366
15373
|
height = config.height,
|
|
15367
|
-
devicePixelRatio = config.devicePixelRatio,
|
|
15368
|
-
renderer = config.renderer,
|
|
15369
15374
|
background = config.background,
|
|
15370
15375
|
cursor = config.cursor,
|
|
15371
|
-
|
|
15376
|
+
supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
|
|
15377
|
+
_config$cleanUpOnDest = config.cleanUpOnDestroy,
|
|
15378
|
+
cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
|
|
15379
|
+
offscreenCanvas = config.offscreenCanvas,
|
|
15380
|
+
devicePixelRatio = config.devicePixelRatio,
|
|
15372
15381
|
requestAnimationFrame = config.requestAnimationFrame,
|
|
15373
15382
|
cancelAnimationFrame = config.cancelAnimationFrame,
|
|
15374
15383
|
createImage = config.createImage,
|
|
15375
|
-
enableLargeImageOptimization = config.enableLargeImageOptimization,
|
|
15376
|
-
supportsPointerEvents = config.supportsPointerEvents,
|
|
15377
15384
|
supportsTouchEvents = config.supportsTouchEvents,
|
|
15378
|
-
|
|
15379
|
-
_config$cleanUpOnDest = config.cleanUpOnDestroy,
|
|
15380
|
-
cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
|
|
15381
|
-
supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
|
|
15382
|
-
useNativeClickEvent = config.useNativeClickEvent,
|
|
15383
|
-
alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas,
|
|
15385
|
+
supportsPointerEvents = config.supportsPointerEvents,
|
|
15384
15386
|
isTouchEvent = config.isTouchEvent,
|
|
15385
15387
|
isMouseEvent = config.isMouseEvent,
|
|
15386
15388
|
dblClickSpeed = config.dblClickSpeed;
|
|
15387
|
-
if (!supportsMutipleCanvasesInOneContainer) {
|
|
15388
|
-
cleanExistedCanvas(container, _this, cleanUpOnDestroy);
|
|
15389
|
-
}
|
|
15390
15389
|
var canvasWidth = width;
|
|
15391
15390
|
var canvasHeight = height;
|
|
15392
|
-
var dpr = devicePixelRatio;
|
|
15391
|
+
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
15392
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
15393
|
+
|
|
15393
15394
|
// use user-defined <canvas> or OffscreenCanvas
|
|
15394
15395
|
if (canvas) {
|
|
15395
15396
|
// infer width & height with dpr
|
|
15396
|
-
dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
15397
|
-
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
15398
15397
|
canvasWidth = width || getWidth(canvas) || canvas.width / dpr;
|
|
15399
15398
|
canvasHeight = height || getHeight(canvas) || canvas.height / dpr;
|
|
15400
15399
|
}
|
|
15401
15400
|
|
|
15402
|
-
// override it in runtime
|
|
15403
|
-
if (offscreenCanvas) {
|
|
15404
|
-
runtime.offscreenCanvas = offscreenCanvas;
|
|
15405
|
-
}
|
|
15406
|
-
|
|
15407
15401
|
/**
|
|
15408
15402
|
* implements `Window` interface
|
|
15409
15403
|
*/
|
|
15404
|
+
_this.customElements = new CustomElementRegistry();
|
|
15410
15405
|
_this.devicePixelRatio = dpr;
|
|
15411
15406
|
_this.requestAnimationFrame = requestAnimationFrame !== null && requestAnimationFrame !== void 0 ? requestAnimationFrame : raf.bind(runtime.globalThis);
|
|
15412
15407
|
_this.cancelAnimationFrame = cancelAnimationFrame !== null && cancelAnimationFrame !== void 0 ? cancelAnimationFrame : caf.bind(runtime.globalThis);
|
|
15413
|
-
|
|
15414
|
-
/**
|
|
15415
|
-
* limits query
|
|
15416
|
-
*/
|
|
15417
15408
|
// the following feature-detect from hammer.js
|
|
15418
15409
|
// @see https://github.com/hammerjs/hammer.js/blob/master/src/inputjs/input-consts.js#L5
|
|
15419
15410
|
_this.supportsTouchEvents = supportsTouchEvents !== null && supportsTouchEvents !== void 0 ? supportsTouchEvents : 'ontouchstart' in runtime.globalThis;
|
|
@@ -15424,25 +15415,36 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
15424
15415
|
_this.isMouseEvent = isMouseEvent !== null && isMouseEvent !== void 0 ? isMouseEvent : function (event) {
|
|
15425
15416
|
return !runtime.globalThis.MouseEvent || event instanceof runtime.globalThis.MouseEvent && (!_this.supportsPointerEvents || !(event instanceof runtime.globalThis.PointerEvent));
|
|
15426
15417
|
};
|
|
15427
|
-
|
|
15428
|
-
|
|
15429
|
-
|
|
15430
|
-
|
|
15418
|
+
|
|
15419
|
+
// override it in runtime
|
|
15420
|
+
if (offscreenCanvas) {
|
|
15421
|
+
runtime.offscreenCanvas = offscreenCanvas;
|
|
15422
|
+
}
|
|
15423
|
+
|
|
15424
|
+
// create document
|
|
15425
|
+
_this.document = new Document();
|
|
15426
|
+
_this.document.defaultView = _this;
|
|
15427
|
+
if (!supportsMutipleCanvasesInOneContainer) {
|
|
15428
|
+
cleanExistedCanvas(container, _this, cleanUpOnDestroy);
|
|
15429
|
+
}
|
|
15430
|
+
_this.initRenderingContext(_objectSpread(_objectSpread({}, config), {}, {
|
|
15431
15431
|
width: canvasWidth,
|
|
15432
15432
|
height: canvasHeight,
|
|
15433
|
-
|
|
15434
|
-
|
|
15435
|
-
devicePixelRatio: dpr,
|
|
15436
|
-
cursor: cursor || 'default',
|
|
15437
|
-
background: background || 'transparent',
|
|
15438
|
-
createImage: createImage,
|
|
15439
|
-
enableLargeImageOptimization: enableLargeImageOptimization,
|
|
15440
|
-
document: document,
|
|
15441
|
-
supportsCSSTransform: supportsCSSTransform,
|
|
15442
|
-
useNativeClickEvent: useNativeClickEvent,
|
|
15433
|
+
background: background !== null && background !== void 0 ? background : 'transparent',
|
|
15434
|
+
cursor: cursor !== null && cursor !== void 0 ? cursor : 'default',
|
|
15443
15435
|
cleanUpOnDestroy: cleanUpOnDestroy,
|
|
15444
|
-
|
|
15445
|
-
|
|
15436
|
+
devicePixelRatio: dpr,
|
|
15437
|
+
requestAnimationFrame: _this.requestAnimationFrame,
|
|
15438
|
+
cancelAnimationFrame: _this.cancelAnimationFrame,
|
|
15439
|
+
supportsTouchEvents: _this.supportsTouchEvents,
|
|
15440
|
+
supportsPointerEvents: _this.supportsPointerEvents,
|
|
15441
|
+
isTouchEvent: _this.isTouchEvent,
|
|
15442
|
+
isMouseEvent: _this.isMouseEvent,
|
|
15443
|
+
dblClickSpeed: dblClickSpeed !== null && dblClickSpeed !== void 0 ? dblClickSpeed : 200,
|
|
15444
|
+
createImage: createImage !== null && createImage !== void 0 ? createImage : function () {
|
|
15445
|
+
return new window.Image();
|
|
15446
|
+
}
|
|
15447
|
+
}));
|
|
15446
15448
|
_this.initDefaultCamera(canvasWidth, canvasHeight, renderer.clipSpaceNearZ);
|
|
15447
15449
|
_this.initRenderer(renderer, true);
|
|
15448
15450
|
return _this;
|
|
@@ -15699,6 +15701,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
15699
15701
|
key: "render",
|
|
15700
15702
|
value: function render(frame) {
|
|
15701
15703
|
var _this4 = this;
|
|
15704
|
+
// console.log('render ----------------------');
|
|
15702
15705
|
if (frame) {
|
|
15703
15706
|
beforeRenderEvent.detail = frame;
|
|
15704
15707
|
afterRenderEvent.detail = frame;
|
|
@@ -15762,6 +15765,8 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
15762
15765
|
} else {
|
|
15763
15766
|
this.context.contextService.initAsync().then(function () {
|
|
15764
15767
|
_this6.initRenderingService(renderer, firstContentfullPaint);
|
|
15768
|
+
})["catch"](function (err) {
|
|
15769
|
+
console.error(err);
|
|
15765
15770
|
});
|
|
15766
15771
|
}
|
|
15767
15772
|
}
|