@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.esm.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
|
*/
|
|
@@ -4192,16 +4192,22 @@ function parseDimensionArrayFormat(string, size) {
|
|
|
4192
4192
|
}
|
|
4193
4193
|
return [parsed[0], parsed[1]];
|
|
4194
4194
|
}
|
|
4195
|
-
if (
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4195
|
+
if (size === 4) {
|
|
4196
|
+
if (parsed.length === 1) {
|
|
4197
|
+
return [parsed[0], parsed[0], parsed[0], parsed[0]];
|
|
4198
|
+
}
|
|
4199
|
+
if (parsed.length === 2) {
|
|
4200
|
+
return [parsed[0], parsed[1], parsed[0], parsed[1]];
|
|
4201
|
+
}
|
|
4202
|
+
if (parsed.length === 3) {
|
|
4203
|
+
return [parsed[0], parsed[1], parsed[2], parsed[1]];
|
|
4204
|
+
}
|
|
4205
|
+
return [parsed[0], parsed[1], parsed[2], parsed[3]];
|
|
4200
4206
|
}
|
|
4201
|
-
if (parsed.length ===
|
|
4202
|
-
return [
|
|
4207
|
+
if (size === 'even' && parsed.length % 2 === 1) {
|
|
4208
|
+
return [].concat(_toConsumableArray(parsed), _toConsumableArray(parsed));
|
|
4203
4209
|
}
|
|
4204
|
-
return
|
|
4210
|
+
return parsed;
|
|
4205
4211
|
}
|
|
4206
4212
|
|
|
4207
4213
|
// export function mergeDimensionList(
|
|
@@ -5067,7 +5073,7 @@ function translatePathToString(absolutePath) {
|
|
|
5067
5073
|
case 'C':
|
|
5068
5074
|
return "C ".concat(params[1], " ").concat(params[2], ",").concat(params[3], " ").concat(params[4], ",").concat(params[5] + endOffsetXTemp, " ").concat(params[6] + endOffsetYTemp);
|
|
5069
5075
|
case 'A':
|
|
5070
|
-
return "A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6] +
|
|
5076
|
+
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) : '');
|
|
5071
5077
|
case 'Z':
|
|
5072
5078
|
return 'Z';
|
|
5073
5079
|
default:
|
|
@@ -6404,7 +6410,8 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
6404
6410
|
}
|
|
6405
6411
|
// Polyline
|
|
6406
6412
|
if (list.has('lineDash') && !isNil(attributes.lineDash)) {
|
|
6407
|
-
|
|
6413
|
+
// dom标准自动转化奇数长度数组,webgl需要手动处理
|
|
6414
|
+
object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 'even');
|
|
6408
6415
|
}
|
|
6409
6416
|
// @ts-ignore
|
|
6410
6417
|
if (list.has('points') && attributes.points) {
|
|
@@ -8863,11 +8870,6 @@ var Node = /*#__PURE__*/function (_EventTarget) {
|
|
|
8863
8870
|
}
|
|
8864
8871
|
return temp;
|
|
8865
8872
|
}
|
|
8866
|
-
|
|
8867
|
-
/**
|
|
8868
|
-
* iterate current node and its descendants
|
|
8869
|
-
* @param callback - callback to execute for each node, return false to break
|
|
8870
|
-
*/
|
|
8871
8873
|
}, {
|
|
8872
8874
|
key: "forEach",
|
|
8873
8875
|
value: function forEach(callback) {
|
|
@@ -8921,7 +8923,6 @@ var EventService = /*#__PURE__*/function () {
|
|
|
8921
8923
|
function EventService(globalRuntime, context) {
|
|
8922
8924
|
var _this = this;
|
|
8923
8925
|
_classCallCheck(this, EventService);
|
|
8924
|
-
this.emitter = new EventEmitter();
|
|
8925
8926
|
/**
|
|
8926
8927
|
* Store HTML elements in current canvas.
|
|
8927
8928
|
*/
|
|
@@ -8998,7 +8999,7 @@ var EventService = /*#__PURE__*/function () {
|
|
|
8998
8999
|
}
|
|
8999
9000
|
var canvas = _this.context.renderingContext.root.ownerDocument.defaultView;
|
|
9000
9001
|
var clickHistory = trackingData.clicksByButton[from.button];
|
|
9001
|
-
if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.dblClickSpeed) {
|
|
9002
|
+
if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.getConfig().dblClickSpeed) {
|
|
9002
9003
|
++clickHistory.clickCount;
|
|
9003
9004
|
} else {
|
|
9004
9005
|
clickHistory.clickCount = 1;
|
|
@@ -9213,7 +9214,6 @@ var EventService = /*#__PURE__*/function () {
|
|
|
9213
9214
|
}, {
|
|
9214
9215
|
key: "destroy",
|
|
9215
9216
|
value: function destroy() {
|
|
9216
|
-
this.emitter.removeAllListeners();
|
|
9217
9217
|
this.mappingTable = {};
|
|
9218
9218
|
this.mappingState = {};
|
|
9219
9219
|
this.eventPool.clear();
|
|
@@ -9349,7 +9349,6 @@ var EventService = /*#__PURE__*/function () {
|
|
|
9349
9349
|
e.currentTarget = canvas;
|
|
9350
9350
|
this.notifyListeners(e, type);
|
|
9351
9351
|
}
|
|
9352
|
-
this.emitter.emit(type || e.type, e);
|
|
9353
9352
|
}
|
|
9354
9353
|
}, {
|
|
9355
9354
|
key: "propagate",
|
|
@@ -10204,22 +10203,35 @@ var DefaultSceneGraphSelector = /*#__PURE__*/function () {
|
|
|
10204
10203
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
|
|
10205
10204
|
*/
|
|
10206
10205
|
var ElementEvent = /*#__PURE__*/function (ElementEvent) {
|
|
10207
|
-
ElementEvent["REPARENT"] = "reparent";
|
|
10208
|
-
ElementEvent["DESTROY"] = "destroy";
|
|
10209
10206
|
ElementEvent["ATTR_MODIFIED"] = "DOMAttrModified";
|
|
10210
10207
|
ElementEvent["INSERTED"] = "DOMNodeInserted";
|
|
10211
|
-
ElementEvent["REMOVED"] = "removed";
|
|
10212
10208
|
ElementEvent["MOUNTED"] = "DOMNodeInsertedIntoDocument";
|
|
10209
|
+
ElementEvent["REMOVED"] = "removed";
|
|
10213
10210
|
ElementEvent["UNMOUNTED"] = "DOMNodeRemovedFromDocument";
|
|
10211
|
+
ElementEvent["REPARENT"] = "reparent";
|
|
10212
|
+
ElementEvent["DESTROY"] = "destroy";
|
|
10214
10213
|
ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
|
|
10215
10214
|
ElementEvent["CULLED"] = "culled";
|
|
10216
10215
|
return ElementEvent;
|
|
10217
10216
|
}({});
|
|
10218
10217
|
|
|
10218
|
+
// #region EventTarget
|
|
10219
|
+
|
|
10220
|
+
// #region Node
|
|
10221
|
+
|
|
10222
|
+
// #region Element
|
|
10223
|
+
|
|
10224
|
+
// #region AnimationTimeline
|
|
10225
|
+
|
|
10226
|
+
// #region Document
|
|
10227
|
+
|
|
10228
|
+
// #region CSSStyleDeclaration
|
|
10219
10229
|
/**
|
|
10220
10230
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/CSSStyleDeclaration
|
|
10221
10231
|
*/
|
|
10222
10232
|
|
|
10233
|
+
// #region Canvas
|
|
10234
|
+
|
|
10223
10235
|
var MutationEvent = /*#__PURE__*/function (_FederatedEvent) {
|
|
10224
10236
|
function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
|
|
10225
10237
|
var _this;
|
|
@@ -11466,99 +11478,123 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11466
11478
|
} else if (textOverflow && textOverflow !== 'clip') {
|
|
11467
11479
|
ellipsis = textOverflow;
|
|
11468
11480
|
}
|
|
11481
|
+
var chars = Array.from(text);
|
|
11469
11482
|
var lines = [];
|
|
11470
|
-
var
|
|
11471
|
-
var
|
|
11483
|
+
var currentLineIndex = 0;
|
|
11484
|
+
var currentLineWidth = 0;
|
|
11472
11485
|
var cache = {};
|
|
11473
|
-
var calcWidth = function calcWidth(
|
|
11474
|
-
return _this2.getFromCache(
|
|
11486
|
+
var calcWidth = function calcWidth(txt) {
|
|
11487
|
+
return _this2.getFromCache(txt, letterSpacing, cache, context);
|
|
11475
11488
|
};
|
|
11476
|
-
var ellipsisWidth =
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11489
|
+
var ellipsisWidth = calcWidth(ellipsis);
|
|
11490
|
+
|
|
11491
|
+
/**
|
|
11492
|
+
* Find text fragments that will take up as much of the given line width as possible when rendered.
|
|
11493
|
+
*
|
|
11494
|
+
* @see https://github.com/antvis/G/issues/1833
|
|
11495
|
+
*
|
|
11496
|
+
* @param txt - Current line of text
|
|
11497
|
+
* @param textCharIndex - The index of the last character of the current line in the entire text
|
|
11498
|
+
*/
|
|
11499
|
+
function findCharIndexClosestWidthThreshold(txt, textCharIndex, widthThreshold) {
|
|
11500
|
+
while (calcWidth(txt) < widthThreshold && textCharIndex < chars.length - 1) {
|
|
11501
|
+
textCharIndex += 1;
|
|
11502
|
+
txt += chars[textCharIndex];
|
|
11503
|
+
}
|
|
11504
|
+
while (calcWidth(txt) > widthThreshold) {
|
|
11505
|
+
textCharIndex -= 1;
|
|
11506
|
+
txt = txt.slice(0, -1);
|
|
11507
|
+
}
|
|
11508
|
+
return {
|
|
11509
|
+
txt: txt,
|
|
11510
|
+
textCharIndex: textCharIndex
|
|
11511
|
+
};
|
|
11512
|
+
}
|
|
11513
|
+
function appendEllipsis(lineIndex, textCharIndex) {
|
|
11480
11514
|
// If there is not enough space to display the string itself, it is clipped.
|
|
11481
11515
|
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values
|
|
11482
11516
|
if (ellipsisWidth <= 0 || ellipsisWidth > maxWidth) {
|
|
11483
11517
|
return;
|
|
11484
11518
|
}
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
var lastLineWidth = 0;
|
|
11489
|
-
var lastLineIndex = currentLineLength;
|
|
11490
|
-
for (var i = 0; i < currentLineLength; i++) {
|
|
11491
|
-
var width = calcWidth(lines[lineIndex][i]);
|
|
11492
|
-
if (lastLineWidth + width + ellipsisWidth > maxWidth) {
|
|
11493
|
-
lastLineIndex = i;
|
|
11494
|
-
break;
|
|
11495
|
-
}
|
|
11496
|
-
lastLineWidth += width;
|
|
11519
|
+
if (!lines[lineIndex]) {
|
|
11520
|
+
lines[lineIndex] = ellipsis;
|
|
11521
|
+
return;
|
|
11497
11522
|
}
|
|
11498
|
-
|
|
11523
|
+
var result = findCharIndexClosestWidthThreshold(lines[lineIndex], textCharIndex, maxWidth - ellipsisWidth);
|
|
11524
|
+
lines[lineIndex] = result.txt + ellipsis;
|
|
11499
11525
|
}
|
|
11500
|
-
var chars = Array.from(text);
|
|
11501
11526
|
for (var i = 0; i < chars.length; i++) {
|
|
11502
|
-
var
|
|
11503
|
-
var prevChar =
|
|
11504
|
-
var nextChar =
|
|
11505
|
-
var charWidth = calcWidth(
|
|
11506
|
-
if (this.isNewline(
|
|
11507
|
-
currentIndex++;
|
|
11508
|
-
|
|
11527
|
+
var _char2 = chars[i];
|
|
11528
|
+
var prevChar = chars[i - 1];
|
|
11529
|
+
var nextChar = chars[i + 1];
|
|
11530
|
+
var charWidth = calcWidth(_char2);
|
|
11531
|
+
if (this.isNewline(_char2)) {
|
|
11509
11532
|
// exceed maxLines, break immediately
|
|
11510
|
-
if (
|
|
11533
|
+
if (currentLineIndex + 1 >= maxLines) {
|
|
11511
11534
|
parsedStyle.isOverflowing = true;
|
|
11512
11535
|
if (i < chars.length - 1) {
|
|
11513
|
-
appendEllipsis(
|
|
11536
|
+
appendEllipsis(currentLineIndex, i);
|
|
11514
11537
|
}
|
|
11515
11538
|
break;
|
|
11516
11539
|
}
|
|
11517
|
-
|
|
11518
|
-
|
|
11540
|
+
currentLineIndex += 1;
|
|
11541
|
+
currentLineWidth = 0;
|
|
11542
|
+
lines[currentLineIndex] = '';
|
|
11519
11543
|
continue;
|
|
11520
11544
|
}
|
|
11521
|
-
if (
|
|
11522
|
-
|
|
11545
|
+
if (currentLineWidth > 0 && currentLineWidth + charWidth > maxWidth) {
|
|
11546
|
+
var result = findCharIndexClosestWidthThreshold(lines[currentLineIndex], i, maxWidth);
|
|
11547
|
+
if (result.textCharIndex !== i) {
|
|
11548
|
+
lines[currentLineIndex] = result.txt;
|
|
11549
|
+
if (result.textCharIndex === chars.length - 1) {
|
|
11550
|
+
break;
|
|
11551
|
+
}
|
|
11552
|
+
i = result.textCharIndex;
|
|
11553
|
+
_char2 = chars[i];
|
|
11554
|
+
prevChar = chars[i - 1];
|
|
11555
|
+
nextChar = chars[i + 1];
|
|
11556
|
+
charWidth = calcWidth(_char2);
|
|
11557
|
+
}
|
|
11558
|
+
if (currentLineIndex + 1 >= maxLines) {
|
|
11523
11559
|
parsedStyle.isOverflowing = true;
|
|
11524
|
-
appendEllipsis(
|
|
11560
|
+
appendEllipsis(currentLineIndex, i);
|
|
11525
11561
|
break;
|
|
11526
11562
|
}
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
lines[
|
|
11530
|
-
if (this.isBreakingSpace(
|
|
11563
|
+
currentLineIndex += 1;
|
|
11564
|
+
currentLineWidth = 0;
|
|
11565
|
+
lines[currentLineIndex] = '';
|
|
11566
|
+
if (this.isBreakingSpace(_char2)) {
|
|
11531
11567
|
continue;
|
|
11532
11568
|
}
|
|
11533
|
-
if (!this.canBreakInLastChar(
|
|
11569
|
+
if (!this.canBreakInLastChar(_char2)) {
|
|
11534
11570
|
lines = this.trimToBreakable(lines);
|
|
11535
|
-
|
|
11571
|
+
currentLineWidth = this.sumTextWidthByCache(lines[currentLineIndex] || '', cache);
|
|
11536
11572
|
}
|
|
11537
|
-
if (this.shouldBreakByKinsokuShorui(
|
|
11573
|
+
if (this.shouldBreakByKinsokuShorui(_char2, nextChar)) {
|
|
11538
11574
|
lines = this.trimByKinsokuShorui(lines);
|
|
11539
|
-
|
|
11575
|
+
currentLineWidth += calcWidth(prevChar || '');
|
|
11540
11576
|
}
|
|
11541
11577
|
}
|
|
11542
|
-
|
|
11543
|
-
lines[
|
|
11578
|
+
currentLineWidth += charWidth;
|
|
11579
|
+
lines[currentLineIndex] = (lines[currentLineIndex] || '') + _char2;
|
|
11544
11580
|
}
|
|
11545
11581
|
return lines.join('\n');
|
|
11546
11582
|
}
|
|
11547
11583
|
}, {
|
|
11548
11584
|
key: "isBreakingSpace",
|
|
11549
|
-
value: function isBreakingSpace(
|
|
11550
|
-
if (typeof
|
|
11585
|
+
value: function isBreakingSpace(_char3) {
|
|
11586
|
+
if (typeof _char3 !== 'string') {
|
|
11551
11587
|
return false;
|
|
11552
11588
|
}
|
|
11553
|
-
return TEXT_METRICS.BreakingSpaces.indexOf(
|
|
11589
|
+
return TEXT_METRICS.BreakingSpaces.indexOf(_char3.charCodeAt(0)) >= 0;
|
|
11554
11590
|
}
|
|
11555
11591
|
}, {
|
|
11556
11592
|
key: "isNewline",
|
|
11557
|
-
value: function isNewline(
|
|
11558
|
-
if (typeof
|
|
11593
|
+
value: function isNewline(_char4) {
|
|
11594
|
+
if (typeof _char4 !== 'string') {
|
|
11559
11595
|
return false;
|
|
11560
11596
|
}
|
|
11561
|
-
return TEXT_METRICS.Newlines.indexOf(
|
|
11597
|
+
return TEXT_METRICS.Newlines.indexOf(_char4.charCodeAt(0)) >= 0;
|
|
11562
11598
|
}
|
|
11563
11599
|
}, {
|
|
11564
11600
|
key: "trimToBreakable",
|
|
@@ -11577,8 +11613,8 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11577
11613
|
}
|
|
11578
11614
|
}, {
|
|
11579
11615
|
key: "canBreakInLastChar",
|
|
11580
|
-
value: function canBreakInLastChar(
|
|
11581
|
-
if (
|
|
11616
|
+
value: function canBreakInLastChar(_char5) {
|
|
11617
|
+
if (_char5 && LATIN_REGEX.test(_char5)) return false;
|
|
11582
11618
|
return true;
|
|
11583
11619
|
}
|
|
11584
11620
|
}, {
|
|
@@ -11603,7 +11639,8 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11603
11639
|
var width = cache[key];
|
|
11604
11640
|
if (typeof width !== 'number') {
|
|
11605
11641
|
var spacing = key.length * letterSpacing;
|
|
11606
|
-
|
|
11642
|
+
var metrics = context.measureText(key);
|
|
11643
|
+
width = metrics.width + spacing;
|
|
11607
11644
|
cache[key] = width;
|
|
11608
11645
|
}
|
|
11609
11646
|
return width;
|
|
@@ -15290,109 +15327,63 @@ var afterRenderEvent = new CustomEvent(CanvasEvent.AFTER_RENDER);
|
|
|
15290
15327
|
* * `window.devicePixelRatio`
|
|
15291
15328
|
*
|
|
15292
15329
|
* prototype chains: Canvas(Window) -> EventTarget
|
|
15330
|
+
*
|
|
15331
|
+
* @docs https://g.antv.antgroup.com/api/canvas/intro
|
|
15293
15332
|
*/
|
|
15294
15333
|
var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
15295
15334
|
function Canvas(config) {
|
|
15296
15335
|
var _this;
|
|
15297
15336
|
_classCallCheck(this, Canvas);
|
|
15298
15337
|
_this = _callSuper(this, Canvas);
|
|
15299
|
-
|
|
15300
|
-
// create document
|
|
15338
|
+
// #region environment
|
|
15301
15339
|
/**
|
|
15302
15340
|
* window.document
|
|
15303
15341
|
*/
|
|
15304
|
-
/**
|
|
15305
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
|
|
15306
|
-
*/
|
|
15307
|
-
/**
|
|
15308
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
|
|
15309
|
-
*/
|
|
15310
|
-
/**
|
|
15311
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
|
|
15312
|
-
*/
|
|
15313
|
-
/**
|
|
15314
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
|
|
15315
|
-
*/
|
|
15316
|
-
/**
|
|
15317
|
-
* whether the runtime supports PointerEvent?
|
|
15318
|
-
* if not, the event system won't trigger pointer events like `pointerdown`
|
|
15319
|
-
*/
|
|
15320
|
-
/**
|
|
15321
|
-
* whether the runtime supports TouchEvent?
|
|
15322
|
-
* if not, the event system won't trigger touch events like `touchstart`
|
|
15323
|
-
*/
|
|
15324
|
-
/**
|
|
15325
|
-
* is this native event a TouchEvent?
|
|
15326
|
-
*/
|
|
15327
|
-
/**
|
|
15328
|
-
* is this native event a MouseEvent?
|
|
15329
|
-
*/
|
|
15330
15342
|
/**
|
|
15331
15343
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
15332
15344
|
*/
|
|
15333
15345
|
_this.Element = DisplayObject;
|
|
15334
15346
|
_this.inited = false;
|
|
15335
15347
|
_this.context = {};
|
|
15336
|
-
_this.document = new Document();
|
|
15337
|
-
_this.document.defaultView = _this;
|
|
15338
|
-
|
|
15339
|
-
// create registry of custom elements
|
|
15340
|
-
_this.customElements = new CustomElementRegistry();
|
|
15341
15348
|
var container = config.container,
|
|
15342
15349
|
canvas = config.canvas,
|
|
15343
|
-
|
|
15350
|
+
renderer = config.renderer,
|
|
15344
15351
|
width = config.width,
|
|
15345
15352
|
height = config.height,
|
|
15346
|
-
devicePixelRatio = config.devicePixelRatio,
|
|
15347
|
-
renderer = config.renderer,
|
|
15348
15353
|
background = config.background,
|
|
15349
15354
|
cursor = config.cursor,
|
|
15350
|
-
|
|
15355
|
+
supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
|
|
15356
|
+
_config$cleanUpOnDest = config.cleanUpOnDestroy,
|
|
15357
|
+
cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
|
|
15358
|
+
offscreenCanvas = config.offscreenCanvas,
|
|
15359
|
+
devicePixelRatio = config.devicePixelRatio,
|
|
15351
15360
|
requestAnimationFrame = config.requestAnimationFrame,
|
|
15352
15361
|
cancelAnimationFrame = config.cancelAnimationFrame,
|
|
15353
15362
|
createImage = config.createImage,
|
|
15354
|
-
enableLargeImageOptimization = config.enableLargeImageOptimization,
|
|
15355
|
-
supportsPointerEvents = config.supportsPointerEvents,
|
|
15356
15363
|
supportsTouchEvents = config.supportsTouchEvents,
|
|
15357
|
-
|
|
15358
|
-
_config$cleanUpOnDest = config.cleanUpOnDestroy,
|
|
15359
|
-
cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
|
|
15360
|
-
supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
|
|
15361
|
-
useNativeClickEvent = config.useNativeClickEvent,
|
|
15362
|
-
alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas,
|
|
15364
|
+
supportsPointerEvents = config.supportsPointerEvents,
|
|
15363
15365
|
isTouchEvent = config.isTouchEvent,
|
|
15364
15366
|
isMouseEvent = config.isMouseEvent,
|
|
15365
15367
|
dblClickSpeed = config.dblClickSpeed;
|
|
15366
|
-
if (!supportsMutipleCanvasesInOneContainer) {
|
|
15367
|
-
cleanExistedCanvas(container, _this, cleanUpOnDestroy);
|
|
15368
|
-
}
|
|
15369
15368
|
var canvasWidth = width;
|
|
15370
15369
|
var canvasHeight = height;
|
|
15371
|
-
var dpr = devicePixelRatio;
|
|
15370
|
+
var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
15371
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
15372
|
+
|
|
15372
15373
|
// use user-defined <canvas> or OffscreenCanvas
|
|
15373
15374
|
if (canvas) {
|
|
15374
15375
|
// infer width & height with dpr
|
|
15375
|
-
dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
|
|
15376
|
-
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
15377
15376
|
canvasWidth = width || getWidth(canvas) || canvas.width / dpr;
|
|
15378
15377
|
canvasHeight = height || getHeight(canvas) || canvas.height / dpr;
|
|
15379
15378
|
}
|
|
15380
15379
|
|
|
15381
|
-
// override it in runtime
|
|
15382
|
-
if (offscreenCanvas) {
|
|
15383
|
-
runtime.offscreenCanvas = offscreenCanvas;
|
|
15384
|
-
}
|
|
15385
|
-
|
|
15386
15380
|
/**
|
|
15387
15381
|
* implements `Window` interface
|
|
15388
15382
|
*/
|
|
15383
|
+
_this.customElements = new CustomElementRegistry();
|
|
15389
15384
|
_this.devicePixelRatio = dpr;
|
|
15390
15385
|
_this.requestAnimationFrame = requestAnimationFrame !== null && requestAnimationFrame !== void 0 ? requestAnimationFrame : raf.bind(runtime.globalThis);
|
|
15391
15386
|
_this.cancelAnimationFrame = cancelAnimationFrame !== null && cancelAnimationFrame !== void 0 ? cancelAnimationFrame : caf.bind(runtime.globalThis);
|
|
15392
|
-
|
|
15393
|
-
/**
|
|
15394
|
-
* limits query
|
|
15395
|
-
*/
|
|
15396
15387
|
// the following feature-detect from hammer.js
|
|
15397
15388
|
// @see https://github.com/hammerjs/hammer.js/blob/master/src/inputjs/input-consts.js#L5
|
|
15398
15389
|
_this.supportsTouchEvents = supportsTouchEvents !== null && supportsTouchEvents !== void 0 ? supportsTouchEvents : 'ontouchstart' in runtime.globalThis;
|
|
@@ -15403,25 +15394,36 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
15403
15394
|
_this.isMouseEvent = isMouseEvent !== null && isMouseEvent !== void 0 ? isMouseEvent : function (event) {
|
|
15404
15395
|
return !runtime.globalThis.MouseEvent || event instanceof runtime.globalThis.MouseEvent && (!_this.supportsPointerEvents || !(event instanceof runtime.globalThis.PointerEvent));
|
|
15405
15396
|
};
|
|
15406
|
-
|
|
15407
|
-
|
|
15408
|
-
|
|
15409
|
-
|
|
15397
|
+
|
|
15398
|
+
// override it in runtime
|
|
15399
|
+
if (offscreenCanvas) {
|
|
15400
|
+
runtime.offscreenCanvas = offscreenCanvas;
|
|
15401
|
+
}
|
|
15402
|
+
|
|
15403
|
+
// create document
|
|
15404
|
+
_this.document = new Document();
|
|
15405
|
+
_this.document.defaultView = _this;
|
|
15406
|
+
if (!supportsMutipleCanvasesInOneContainer) {
|
|
15407
|
+
cleanExistedCanvas(container, _this, cleanUpOnDestroy);
|
|
15408
|
+
}
|
|
15409
|
+
_this.initRenderingContext(_objectSpread(_objectSpread({}, config), {}, {
|
|
15410
15410
|
width: canvasWidth,
|
|
15411
15411
|
height: canvasHeight,
|
|
15412
|
-
|
|
15413
|
-
|
|
15414
|
-
devicePixelRatio: dpr,
|
|
15415
|
-
cursor: cursor || 'default',
|
|
15416
|
-
background: background || 'transparent',
|
|
15417
|
-
createImage: createImage,
|
|
15418
|
-
enableLargeImageOptimization: enableLargeImageOptimization,
|
|
15419
|
-
document: document,
|
|
15420
|
-
supportsCSSTransform: supportsCSSTransform,
|
|
15421
|
-
useNativeClickEvent: useNativeClickEvent,
|
|
15412
|
+
background: background !== null && background !== void 0 ? background : 'transparent',
|
|
15413
|
+
cursor: cursor !== null && cursor !== void 0 ? cursor : 'default',
|
|
15422
15414
|
cleanUpOnDestroy: cleanUpOnDestroy,
|
|
15423
|
-
|
|
15424
|
-
|
|
15415
|
+
devicePixelRatio: dpr,
|
|
15416
|
+
requestAnimationFrame: _this.requestAnimationFrame,
|
|
15417
|
+
cancelAnimationFrame: _this.cancelAnimationFrame,
|
|
15418
|
+
supportsTouchEvents: _this.supportsTouchEvents,
|
|
15419
|
+
supportsPointerEvents: _this.supportsPointerEvents,
|
|
15420
|
+
isTouchEvent: _this.isTouchEvent,
|
|
15421
|
+
isMouseEvent: _this.isMouseEvent,
|
|
15422
|
+
dblClickSpeed: dblClickSpeed !== null && dblClickSpeed !== void 0 ? dblClickSpeed : 200,
|
|
15423
|
+
createImage: createImage !== null && createImage !== void 0 ? createImage : function () {
|
|
15424
|
+
return new window.Image();
|
|
15425
|
+
}
|
|
15426
|
+
}));
|
|
15425
15427
|
_this.initDefaultCamera(canvasWidth, canvasHeight, renderer.clipSpaceNearZ);
|
|
15426
15428
|
_this.initRenderer(renderer, true);
|
|
15427
15429
|
return _this;
|
|
@@ -15678,6 +15680,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
15678
15680
|
key: "render",
|
|
15679
15681
|
value: function render(frame) {
|
|
15680
15682
|
var _this4 = this;
|
|
15683
|
+
// console.log('render ----------------------');
|
|
15681
15684
|
if (frame) {
|
|
15682
15685
|
beforeRenderEvent.detail = frame;
|
|
15683
15686
|
afterRenderEvent.detail = frame;
|
|
@@ -15741,6 +15744,8 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
15741
15744
|
} else {
|
|
15742
15745
|
this.context.contextService.initAsync().then(function () {
|
|
15743
15746
|
_this6.initRenderingService(renderer, firstContentfullPaint);
|
|
15747
|
+
})["catch"](function (err) {
|
|
15748
|
+
console.error(err);
|
|
15744
15749
|
});
|
|
15745
15750
|
}
|
|
15746
15751
|
}
|