@antv/g-lite 2.5.0 → 2.6.0
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 +1710 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1717 -9
- package/dist/index.js.map +1 -1
- package/dist/index.umd.min.js +7 -7
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +5 -5
- package/types/dom/MutationEvent.d.ts +4 -3
- package/types/dom/MutationEvent.d.ts.map +1 -1
- package/types/dom/index.d.ts +0 -1
- package/types/dom/index.d.ts.map +1 -1
- package/types/index.d.ts +6 -0
- package/types/index.d.ts.map +1 -1
- package/types/plugins/MutationObserver.d.ts +49 -0
- package/types/plugins/MutationObserver.d.ts.map +1 -0
- package/types/plugins/dom-interaction/DOMInteractionPlugin.d.ts +10 -0
- package/types/plugins/dom-interaction/DOMInteractionPlugin.d.ts.map +1 -0
- package/types/plugins/dom-interaction/index.d.ts +7 -0
- package/types/plugins/dom-interaction/index.d.ts.map +1 -0
- package/types/plugins/html-renderer/HTMLRenderingPlugin.d.ts +19 -0
- package/types/plugins/html-renderer/HTMLRenderingPlugin.d.ts.map +1 -0
- package/types/plugins/html-renderer/index.d.ts +7 -0
- package/types/plugins/html-renderer/index.d.ts.map +1 -0
- package/types/plugins/html-renderer/interface.d.ts +2 -0
- package/types/plugins/html-renderer/interface.d.ts.map +1 -0
- package/types/plugins/image-loader/ImagePool.d.ts +37 -0
- package/types/plugins/image-loader/ImagePool.d.ts.map +1 -0
- package/types/plugins/image-loader/ImageSlicer.d.ts +38 -0
- package/types/plugins/image-loader/ImageSlicer.d.ts.map +1 -0
- package/types/plugins/image-loader/LoadImagePlugin.d.ts +9 -0
- package/types/plugins/image-loader/LoadImagePlugin.d.ts.map +1 -0
- package/types/plugins/image-loader/RefCountCache.d.ts +14 -0
- package/types/plugins/image-loader/RefCountCache.d.ts.map +1 -0
- package/types/plugins/image-loader/index.d.ts +9 -0
- package/types/plugins/image-loader/index.d.ts.map +1 -0
- package/types/plugins/mobile-interaction/MobileInteractionPlugin.d.ts +9 -0
- package/types/plugins/mobile-interaction/MobileInteractionPlugin.d.ts.map +1 -0
- package/types/plugins/mobile-interaction/index.d.ts +7 -0
- package/types/plugins/mobile-interaction/index.d.ts.map +1 -0
- package/types/services/OffscreenCanvasCreator.d.ts +1 -1
- package/types/services/SceneGraphService.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.
|
|
5
|
-
* @date 12/
|
|
4
|
+
* @version 2.6.0
|
|
5
|
+
* @date 12/22/2025, 3:02:41 AM
|
|
6
6
|
* @author AntVis
|
|
7
7
|
* @docs https://g.antv.antgroup.com/
|
|
8
8
|
*/
|
|
@@ -9809,7 +9809,7 @@ var EventService = /*#__PURE__*/function () {
|
|
|
9809
9809
|
/**
|
|
9810
9810
|
* used in following scenes:
|
|
9811
9811
|
* - g `ctx.measureText`
|
|
9812
|
-
* -
|
|
9812
|
+
* - canvas-picker `ctx.isPointInPath`
|
|
9813
9813
|
* - g-plugin-device-renderer `ctx.createLinearGradient` and generate texture
|
|
9814
9814
|
*
|
|
9815
9815
|
* @see https://blog.scottlogic.com/2020/03/19/offscreen-canvas.html
|
|
@@ -11214,18 +11214,26 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
|
|
|
11214
11214
|
}, {
|
|
11215
11215
|
key: "notifyMutationObservers",
|
|
11216
11216
|
value: function notifyMutationObservers(canvas) {
|
|
11217
|
-
var mutations =
|
|
11217
|
+
var mutations = new Set();
|
|
11218
11218
|
canvas.getRoot().forEach(function (item) {
|
|
11219
11219
|
(item.mutations || []).forEach(function (mutation) {
|
|
11220
11220
|
if (mutation.type === 'attributes' && mutation._boundsChangeData) {
|
|
11221
|
-
|
|
11221
|
+
if (mutation._boundsChangeData.affectChildren) {
|
|
11222
|
+
item.forEach(function (node) {
|
|
11223
|
+
var newMutation = _objectSpread({}, mutation);
|
|
11224
|
+
newMutation.target = node;
|
|
11225
|
+
mutations.add(newMutation);
|
|
11226
|
+
});
|
|
11227
|
+
} else {
|
|
11228
|
+
mutations.add(mutation);
|
|
11229
|
+
}
|
|
11222
11230
|
}
|
|
11223
11231
|
});
|
|
11224
11232
|
item.mutations = undefined;
|
|
11225
11233
|
});
|
|
11226
|
-
if (mutations.
|
|
11234
|
+
if (mutations.size > 0) {
|
|
11227
11235
|
var event = new CustomEvent(ElementEvent.BOUNDS_CHANGED, {
|
|
11228
|
-
detail: mutations
|
|
11236
|
+
detail: Array.from(mutations)
|
|
11229
11237
|
});
|
|
11230
11238
|
canvas.dispatchEvent(event, true, true);
|
|
11231
11239
|
}
|
|
@@ -11907,12 +11915,12 @@ var getGlobalThis = function getGlobalThis() {
|
|
|
11907
11915
|
|
|
11908
11916
|
/**
|
|
11909
11917
|
* Camera
|
|
11910
|
-
* `
|
|
11918
|
+
* `camera-api` will provide an advanced implementation
|
|
11911
11919
|
*/
|
|
11912
11920
|
runtime.CameraContribution = Camera;
|
|
11913
11921
|
|
|
11914
11922
|
/**
|
|
11915
|
-
* `
|
|
11923
|
+
* `web-animations-api` will provide an AnimationTimeline
|
|
11916
11924
|
*/
|
|
11917
11925
|
runtime.AnimationTimeline = null;
|
|
11918
11926
|
runtime.EasingFunction = null;
|
|
@@ -16154,5 +16162,1697 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
16154
16162
|
}]);
|
|
16155
16163
|
}(EventTarget);
|
|
16156
16164
|
|
|
16157
|
-
|
|
16165
|
+
var uidCounter = 0;
|
|
16166
|
+
var registrationsTable = new WeakMap();
|
|
16167
|
+
var MutationRecord = /*#__PURE__*/function () {
|
|
16168
|
+
function MutationRecord(type, target) {
|
|
16169
|
+
_classCallCheck(this, MutationRecord);
|
|
16170
|
+
this.addedNodes = [];
|
|
16171
|
+
this.attributeName = null;
|
|
16172
|
+
this.attributeNamespace = null;
|
|
16173
|
+
this.nextSibling = null;
|
|
16174
|
+
this.oldValue = null;
|
|
16175
|
+
this.previousSibling = null;
|
|
16176
|
+
this.removedNodes = [];
|
|
16177
|
+
this.type = type;
|
|
16178
|
+
this.target = target;
|
|
16179
|
+
}
|
|
16180
|
+
return _createClass(MutationRecord, null, [{
|
|
16181
|
+
key: "copy",
|
|
16182
|
+
value: function copy(original) {
|
|
16183
|
+
var record = new MutationRecord(original.type, original.target);
|
|
16184
|
+
record.addedNodes = original.addedNodes.slice();
|
|
16185
|
+
record.removedNodes = original.removedNodes.slice();
|
|
16186
|
+
record.previousSibling = original.previousSibling;
|
|
16187
|
+
record.nextSibling = original.nextSibling;
|
|
16188
|
+
record.attributeName = original.attributeName;
|
|
16189
|
+
record.attributeNamespace = original.attributeNamespace;
|
|
16190
|
+
record.oldValue = original.oldValue;
|
|
16191
|
+
return record;
|
|
16192
|
+
}
|
|
16193
|
+
}]);
|
|
16194
|
+
}();
|
|
16195
|
+
var Registration = /*#__PURE__*/function () {
|
|
16196
|
+
function Registration(observer, target, options) {
|
|
16197
|
+
_classCallCheck(this, Registration);
|
|
16198
|
+
this.transientObservedNodes = [];
|
|
16199
|
+
this.observer = observer;
|
|
16200
|
+
this.target = target;
|
|
16201
|
+
this.options = options;
|
|
16202
|
+
}
|
|
16203
|
+
return _createClass(Registration, [{
|
|
16204
|
+
key: "enqueue",
|
|
16205
|
+
value: function enqueue(record) {
|
|
16206
|
+
var records = this.observer.records;
|
|
16207
|
+
var length = records.length;
|
|
16208
|
+
|
|
16209
|
+
// There are cases where we replace the last record with the new record.
|
|
16210
|
+
// For example if the record represents the same mutation we need to use
|
|
16211
|
+
// the one with the oldValue. If we get same record (this can happen as we
|
|
16212
|
+
// walk up the tree) we ignore the new record.
|
|
16213
|
+
if (records.length > 0) {
|
|
16214
|
+
var lastRecord = records[length - 1];
|
|
16215
|
+
var recordToReplaceLast = selectRecord(lastRecord, record);
|
|
16216
|
+
if (recordToReplaceLast) {
|
|
16217
|
+
records[length - 1] = recordToReplaceLast;
|
|
16218
|
+
return;
|
|
16219
|
+
}
|
|
16220
|
+
} else {
|
|
16221
|
+
scheduleCallback(this.observer);
|
|
16222
|
+
}
|
|
16223
|
+
records[length] = record;
|
|
16224
|
+
}
|
|
16225
|
+
}, {
|
|
16226
|
+
key: "addListeners",
|
|
16227
|
+
value: function addListeners() {
|
|
16228
|
+
this.addListeners_(this.target);
|
|
16229
|
+
}
|
|
16230
|
+
}, {
|
|
16231
|
+
key: "addListeners_",
|
|
16232
|
+
value: function addListeners_(node) {
|
|
16233
|
+
var options = this.options;
|
|
16234
|
+
if (options.attributes) node.addEventListener(ElementEvent.ATTR_MODIFIED, this, true);
|
|
16235
|
+
|
|
16236
|
+
// if (options.characterData) node.addEventListener('DOMCharacterDataModified', this, true);
|
|
16237
|
+
|
|
16238
|
+
if (options.childList) node.addEventListener(ElementEvent.INSERTED, this, true);
|
|
16239
|
+
if (options.childList || options.subtree) node.addEventListener(ElementEvent.REMOVED, this, true);
|
|
16240
|
+
}
|
|
16241
|
+
}, {
|
|
16242
|
+
key: "removeListeners",
|
|
16243
|
+
value: function removeListeners() {
|
|
16244
|
+
this.removeListeners_(this.target);
|
|
16245
|
+
}
|
|
16246
|
+
}, {
|
|
16247
|
+
key: "removeListeners_",
|
|
16248
|
+
value: function removeListeners_(node) {
|
|
16249
|
+
var options = this.options;
|
|
16250
|
+
if (options.attributes) node.removeEventListener(ElementEvent.ATTR_MODIFIED, this, true);
|
|
16251
|
+
|
|
16252
|
+
// if (options.characterData) node.removeEventListener('DOMCharacterDataModified', this, true);
|
|
16253
|
+
|
|
16254
|
+
if (options.childList) node.removeEventListener(ElementEvent.INSERTED, this, true);
|
|
16255
|
+
if (options.childList || options.subtree) node.removeEventListener(ElementEvent.REMOVED, this, true);
|
|
16256
|
+
}
|
|
16257
|
+
|
|
16258
|
+
/**
|
|
16259
|
+
* Adds a transient observer on node. The transient observer gets removed
|
|
16260
|
+
* next time we deliver the change records.
|
|
16261
|
+
*/
|
|
16262
|
+
// addTransientObserver(node: Node) {
|
|
16263
|
+
// // Don't add transient observers on the target itself. We already have all
|
|
16264
|
+
// // the required listeners set up on the target.
|
|
16265
|
+
// if (node === this.target) return;
|
|
16266
|
+
|
|
16267
|
+
// this.addListeners_(node);
|
|
16268
|
+
// this.transientObservedNodes.push(node);
|
|
16269
|
+
// let registrations = registrationsTable.get(node);
|
|
16270
|
+
// if (!registrations) registrationsTable.set(node, (registrations = []));
|
|
16271
|
+
|
|
16272
|
+
// // We know that registrations does not contain this because we already
|
|
16273
|
+
// // checked if node === this.target.
|
|
16274
|
+
// registrations.push(this);
|
|
16275
|
+
// }
|
|
16276
|
+
}, {
|
|
16277
|
+
key: "removeTransientObservers",
|
|
16278
|
+
value: function removeTransientObservers() {
|
|
16279
|
+
var transientObservedNodes = this.transientObservedNodes;
|
|
16280
|
+
this.transientObservedNodes = [];
|
|
16281
|
+
transientObservedNodes.forEach(function (node) {
|
|
16282
|
+
// Transient observers are never added to the target.
|
|
16283
|
+
this.removeListeners_(node);
|
|
16284
|
+
var registrations = registrationsTable.get(node);
|
|
16285
|
+
for (var i = 0; i < registrations.length; i++) {
|
|
16286
|
+
if (registrations[i] === this) {
|
|
16287
|
+
registrations.splice(i, 1);
|
|
16288
|
+
// Each node can only have one registered observer associated with
|
|
16289
|
+
// this observer.
|
|
16290
|
+
break;
|
|
16291
|
+
}
|
|
16292
|
+
}
|
|
16293
|
+
}, this);
|
|
16294
|
+
}
|
|
16295
|
+
}, {
|
|
16296
|
+
key: "handleEvent",
|
|
16297
|
+
value: function handleEvent(e) {
|
|
16298
|
+
// Stop propagation since we are managing the propagation manually.
|
|
16299
|
+
// This means that other mutation events on the page will not work
|
|
16300
|
+
// correctly but that is by design.
|
|
16301
|
+
e.stopImmediatePropagation();
|
|
16302
|
+
var record;
|
|
16303
|
+
var target;
|
|
16304
|
+
switch (e.type) {
|
|
16305
|
+
case ElementEvent.ATTR_MODIFIED:
|
|
16306
|
+
// http://dom.spec.whatwg.org/#concept-mo-queue-attributes
|
|
16307
|
+
|
|
16308
|
+
var name = e.attrName;
|
|
16309
|
+
// @ts-ignore
|
|
16310
|
+
var namespace = e.relatedNode.namespaceURI;
|
|
16311
|
+
target = e.target;
|
|
16312
|
+
|
|
16313
|
+
// 1.
|
|
16314
|
+
record = getRecord('attributes', target);
|
|
16315
|
+
record.attributeName = name;
|
|
16316
|
+
record.attributeNamespace = namespace;
|
|
16317
|
+
|
|
16318
|
+
// 2.
|
|
16319
|
+
var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevValue;
|
|
16320
|
+
forEachAncestorAndObserverEnqueueRecord(target, function (options) {
|
|
16321
|
+
// 3.1, 4.2
|
|
16322
|
+
if (!options.attributes) return;
|
|
16323
|
+
|
|
16324
|
+
// 3.2, 4.3
|
|
16325
|
+
if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(namespace) === -1) {
|
|
16326
|
+
return;
|
|
16327
|
+
}
|
|
16328
|
+
// 3.3, 4.4
|
|
16329
|
+
if (options.attributeOldValue) return getRecordWithOldValue(oldValue);
|
|
16330
|
+
|
|
16331
|
+
// 3.4, 4.5
|
|
16332
|
+
return record;
|
|
16333
|
+
});
|
|
16334
|
+
break;
|
|
16335
|
+
|
|
16336
|
+
// case 'DOMCharacterDataModified':
|
|
16337
|
+
// // http://dom.spec.whatwg.org/#concept-mo-queue-characterdata
|
|
16338
|
+
// var target = e.target;
|
|
16339
|
+
|
|
16340
|
+
// // 1.
|
|
16341
|
+
// var record = getRecord('characterData', target);
|
|
16342
|
+
|
|
16343
|
+
// // 2.
|
|
16344
|
+
// var oldValue = e.prevValue;
|
|
16345
|
+
|
|
16346
|
+
// forEachAncestorAndObserverEnqueueRecord(target, function(options) {
|
|
16347
|
+
// // 3.1, 4.2
|
|
16348
|
+
// if (!options.characterData)
|
|
16349
|
+
// return;
|
|
16350
|
+
|
|
16351
|
+
// // 3.2, 4.3
|
|
16352
|
+
// if (options.characterDataOldValue)
|
|
16353
|
+
// return getRecordWithOldValue(oldValue);
|
|
16354
|
+
|
|
16355
|
+
// // 3.3, 4.4
|
|
16356
|
+
// return record;
|
|
16357
|
+
// });
|
|
16358
|
+
|
|
16359
|
+
// break;
|
|
16360
|
+
|
|
16361
|
+
case ElementEvent.REMOVED:
|
|
16362
|
+
// this.addTransientObserver(e.target as Node);
|
|
16363
|
+
// Fall through.
|
|
16364
|
+
case ElementEvent.INSERTED:
|
|
16365
|
+
// http://dom.spec.whatwg.org/#concept-mo-queue-childlist
|
|
16366
|
+
target = e.relatedNode;
|
|
16367
|
+
var changedNode = e.target;
|
|
16368
|
+
var addedNodes;
|
|
16369
|
+
var removedNodes;
|
|
16370
|
+
if (e.type === ElementEvent.INSERTED) {
|
|
16371
|
+
addedNodes = [changedNode];
|
|
16372
|
+
removedNodes = [];
|
|
16373
|
+
} else {
|
|
16374
|
+
addedNodes = [];
|
|
16375
|
+
removedNodes = [changedNode];
|
|
16376
|
+
}
|
|
16377
|
+
var previousSibling = changedNode.previousSibling;
|
|
16378
|
+
var nextSibling = changedNode.nextSibling;
|
|
16379
|
+
|
|
16380
|
+
// 1.
|
|
16381
|
+
record = getRecord('childList', target);
|
|
16382
|
+
record.addedNodes = addedNodes;
|
|
16383
|
+
record.removedNodes = removedNodes;
|
|
16384
|
+
record.previousSibling = previousSibling;
|
|
16385
|
+
record.nextSibling = nextSibling;
|
|
16386
|
+
forEachAncestorAndObserverEnqueueRecord(target, function (options) {
|
|
16387
|
+
// 2.1, 3.2
|
|
16388
|
+
if (!options.childList) return;
|
|
16389
|
+
|
|
16390
|
+
// 2.2, 3.3
|
|
16391
|
+
return record;
|
|
16392
|
+
});
|
|
16393
|
+
}
|
|
16394
|
+
clearRecords();
|
|
16395
|
+
}
|
|
16396
|
+
}]);
|
|
16397
|
+
}();
|
|
16398
|
+
|
|
16399
|
+
/**
|
|
16400
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
|
|
16401
|
+
* @see https://github.com/googlearchive/MutationObservers/blob/master/MutationObserver.js
|
|
16402
|
+
*/
|
|
16403
|
+
var MutationObserver = /*#__PURE__*/function () {
|
|
16404
|
+
function MutationObserver(callback) {
|
|
16405
|
+
_classCallCheck(this, MutationObserver);
|
|
16406
|
+
this.nodes = [];
|
|
16407
|
+
this.records = [];
|
|
16408
|
+
this.uid = uidCounter++;
|
|
16409
|
+
this.callback = callback;
|
|
16410
|
+
}
|
|
16411
|
+
return _createClass(MutationObserver, [{
|
|
16412
|
+
key: "observe",
|
|
16413
|
+
value: function observe(target, options) {
|
|
16414
|
+
// 1.1
|
|
16415
|
+
if (!options.childList && !options.attributes && !options.characterData ||
|
|
16416
|
+
// 1.2
|
|
16417
|
+
options.attributeOldValue && !options.attributes ||
|
|
16418
|
+
// 1.3
|
|
16419
|
+
options.attributeFilter && options.attributeFilter.length && !options.attributes ||
|
|
16420
|
+
// 1.4
|
|
16421
|
+
options.characterDataOldValue && !options.characterData) {
|
|
16422
|
+
throw new SyntaxError();
|
|
16423
|
+
}
|
|
16424
|
+
var registrations = registrationsTable.get(target);
|
|
16425
|
+
if (!registrations) registrationsTable.set(target, registrations = []);
|
|
16426
|
+
|
|
16427
|
+
// 2
|
|
16428
|
+
// If target's list of registered observers already includes a registered
|
|
16429
|
+
// observer associated with the context object, replace that registered
|
|
16430
|
+
// observer's options with options.
|
|
16431
|
+
var registration;
|
|
16432
|
+
for (var i = 0; i < registrations.length; i++) {
|
|
16433
|
+
if (registrations[i].observer === this) {
|
|
16434
|
+
registration = registrations[i];
|
|
16435
|
+
registration.removeListeners();
|
|
16436
|
+
registration.options = options;
|
|
16437
|
+
break;
|
|
16438
|
+
}
|
|
16439
|
+
}
|
|
16440
|
+
|
|
16441
|
+
// 3.
|
|
16442
|
+
// Otherwise, add a new registered observer to target's list of registered
|
|
16443
|
+
// observers with the context object as the observer and options as the
|
|
16444
|
+
// options, and add target to context object's list of nodes on which it
|
|
16445
|
+
// is registered.
|
|
16446
|
+
if (!registration) {
|
|
16447
|
+
registration = new Registration(this, target, options);
|
|
16448
|
+
registrations.push(registration);
|
|
16449
|
+
this.nodes.push(target);
|
|
16450
|
+
}
|
|
16451
|
+
registration.addListeners();
|
|
16452
|
+
}
|
|
16453
|
+
}, {
|
|
16454
|
+
key: "disconnect",
|
|
16455
|
+
value: function disconnect() {
|
|
16456
|
+
var _this = this;
|
|
16457
|
+
this.nodes.forEach(function (node) {
|
|
16458
|
+
var registrations = registrationsTable.get(node);
|
|
16459
|
+
for (var i = 0; i < registrations.length; i++) {
|
|
16460
|
+
var registration = registrations[i];
|
|
16461
|
+
if (registration.observer === _this) {
|
|
16462
|
+
registration.removeListeners();
|
|
16463
|
+
registrations.splice(i, 1);
|
|
16464
|
+
// Each node can only have one registered observer associated with
|
|
16465
|
+
// this observer.
|
|
16466
|
+
break;
|
|
16467
|
+
}
|
|
16468
|
+
}
|
|
16469
|
+
}, this);
|
|
16470
|
+
this.records = [];
|
|
16471
|
+
}
|
|
16472
|
+
}, {
|
|
16473
|
+
key: "takeRecords",
|
|
16474
|
+
value: function takeRecords() {
|
|
16475
|
+
var copyOfRecords = this.records;
|
|
16476
|
+
this.records = [];
|
|
16477
|
+
return copyOfRecords;
|
|
16478
|
+
}
|
|
16479
|
+
}]);
|
|
16480
|
+
}();
|
|
16481
|
+
|
|
16482
|
+
// We keep track of the two (possibly one) records used in a single mutation.
|
|
16483
|
+
var currentRecord;
|
|
16484
|
+
var recordWithOldValue;
|
|
16485
|
+
|
|
16486
|
+
/**
|
|
16487
|
+
* Creates a record without |oldValue| and caches it as |currentRecord| for
|
|
16488
|
+
* later use.
|
|
16489
|
+
*/
|
|
16490
|
+
function getRecord(type, target) {
|
|
16491
|
+
return currentRecord = new MutationRecord(type, target);
|
|
16492
|
+
}
|
|
16493
|
+
|
|
16494
|
+
/**
|
|
16495
|
+
* Gets or creates a record with |oldValue| based in the |currentRecord|
|
|
16496
|
+
*/
|
|
16497
|
+
function getRecordWithOldValue(oldValue) {
|
|
16498
|
+
if (recordWithOldValue) return recordWithOldValue;
|
|
16499
|
+
recordWithOldValue = MutationRecord.copy(currentRecord);
|
|
16500
|
+
recordWithOldValue.oldValue = oldValue;
|
|
16501
|
+
return recordWithOldValue;
|
|
16502
|
+
}
|
|
16503
|
+
function clearRecords() {
|
|
16504
|
+
currentRecord = recordWithOldValue = undefined;
|
|
16505
|
+
}
|
|
16506
|
+
|
|
16507
|
+
/**
|
|
16508
|
+
* Whether the record represents a record from the current
|
|
16509
|
+
* mutation event.
|
|
16510
|
+
*/
|
|
16511
|
+
function recordRepresentsCurrentMutation(record) {
|
|
16512
|
+
return record === recordWithOldValue || record === currentRecord;
|
|
16513
|
+
}
|
|
16514
|
+
|
|
16515
|
+
/**
|
|
16516
|
+
* Selects which record, if any, to replace the last record in the queue.
|
|
16517
|
+
* This returns |null| if no record should be replaced.
|
|
16518
|
+
*/
|
|
16519
|
+
function selectRecord(lastRecord, newRecord) {
|
|
16520
|
+
if (lastRecord === newRecord) return lastRecord;
|
|
16521
|
+
|
|
16522
|
+
// Check if the the record we are adding represents the same record. If
|
|
16523
|
+
// so, we keep the one with the oldValue in it.
|
|
16524
|
+
if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue;
|
|
16525
|
+
return null;
|
|
16526
|
+
}
|
|
16527
|
+
function removeTransientObserversFor(observer) {
|
|
16528
|
+
observer.nodes.forEach(function (node) {
|
|
16529
|
+
var registrations = registrationsTable.get(node);
|
|
16530
|
+
if (!registrations) return;
|
|
16531
|
+
registrations.forEach(function (registration) {
|
|
16532
|
+
if (registration.observer === observer) registration.removeTransientObservers();
|
|
16533
|
+
});
|
|
16534
|
+
});
|
|
16535
|
+
}
|
|
16536
|
+
|
|
16537
|
+
/**
|
|
16538
|
+
* This function is used for the "For each registered observer observer (with
|
|
16539
|
+
* observer's options as options) in target's list of registered observers,
|
|
16540
|
+
* run these substeps:" and the "For each ancestor ancestor of target, and for
|
|
16541
|
+
* each registered observer observer (with options options) in ancestor's list
|
|
16542
|
+
* of registered observers, run these substeps:" part of the algorithms. The
|
|
16543
|
+
* |options.subtree| is checked to ensure that the callback is called
|
|
16544
|
+
* correctly.
|
|
16545
|
+
*
|
|
16546
|
+
* @param {Node} target
|
|
16547
|
+
* @param {function(MutationObserverInit):MutationRecord} callback
|
|
16548
|
+
*/
|
|
16549
|
+
function forEachAncestorAndObserverEnqueueRecord(target, callback) {
|
|
16550
|
+
for (var node = target; node; node = node.parentNode) {
|
|
16551
|
+
var registrations = registrationsTable.get(node);
|
|
16552
|
+
if (registrations) {
|
|
16553
|
+
for (var j = 0; j < registrations.length; j++) {
|
|
16554
|
+
var registration = registrations[j];
|
|
16555
|
+
var _options = registration.options;
|
|
16556
|
+
|
|
16557
|
+
// Only target ignores subtree.
|
|
16558
|
+
if (node !== target && !_options.subtree) continue;
|
|
16559
|
+
var record = callback(_options);
|
|
16560
|
+
if (record) registration.enqueue(record);
|
|
16561
|
+
}
|
|
16562
|
+
}
|
|
16563
|
+
}
|
|
16564
|
+
}
|
|
16565
|
+
|
|
16566
|
+
// This is used to ensure that we never schedule 2 callas to setImmediate
|
|
16567
|
+
var isScheduled = false;
|
|
16568
|
+
|
|
16569
|
+
// Keep track of observers that needs to be notified next time.
|
|
16570
|
+
var scheduledObservers = [];
|
|
16571
|
+
|
|
16572
|
+
/**
|
|
16573
|
+
* Schedules |dispatchCallback| to be called in the future.
|
|
16574
|
+
*/
|
|
16575
|
+
function scheduleCallback(observer) {
|
|
16576
|
+
scheduledObservers.push(observer);
|
|
16577
|
+
if (!isScheduled) {
|
|
16578
|
+
isScheduled = true;
|
|
16579
|
+
// setImmediate(dispatchCallbacks);
|
|
16580
|
+
if (typeof runtime.globalThis !== 'undefined') {
|
|
16581
|
+
runtime.globalThis.setTimeout(dispatchCallbacks);
|
|
16582
|
+
} else {
|
|
16583
|
+
dispatchCallbacks();
|
|
16584
|
+
}
|
|
16585
|
+
}
|
|
16586
|
+
}
|
|
16587
|
+
function dispatchCallbacks() {
|
|
16588
|
+
// http://dom.spec.whatwg.org/#mutation-observers
|
|
16589
|
+
|
|
16590
|
+
isScheduled = false; // Used to allow a new setImmediate call above.
|
|
16591
|
+
|
|
16592
|
+
var observers = scheduledObservers;
|
|
16593
|
+
scheduledObservers = [];
|
|
16594
|
+
// Sort observers based on their creation UID (incremental).
|
|
16595
|
+
observers.sort(function (o1, o2) {
|
|
16596
|
+
return o1.uid - o2.uid;
|
|
16597
|
+
});
|
|
16598
|
+
var anyNonEmpty = false;
|
|
16599
|
+
observers.forEach(function (observer) {
|
|
16600
|
+
// 2.1, 2.2
|
|
16601
|
+
var queue = observer.takeRecords();
|
|
16602
|
+
// 2.3. Remove all transient registered observers whose observer is mo.
|
|
16603
|
+
removeTransientObserversFor(observer);
|
|
16604
|
+
|
|
16605
|
+
// 2.4
|
|
16606
|
+
if (queue.length) {
|
|
16607
|
+
// @ts-ignore
|
|
16608
|
+
observer.callback(queue, observer);
|
|
16609
|
+
anyNonEmpty = true;
|
|
16610
|
+
}
|
|
16611
|
+
});
|
|
16612
|
+
|
|
16613
|
+
// 3.
|
|
16614
|
+
if (anyNonEmpty) dispatchCallbacks();
|
|
16615
|
+
}
|
|
16616
|
+
|
|
16617
|
+
var RefCountCache = /*#__PURE__*/function () {
|
|
16618
|
+
function RefCountCache() {
|
|
16619
|
+
_classCallCheck(this, RefCountCache);
|
|
16620
|
+
this.cacheStore = new Map();
|
|
16621
|
+
}
|
|
16622
|
+
return _createClass(RefCountCache, [{
|
|
16623
|
+
key: "onRefAdded",
|
|
16624
|
+
value: function onRefAdded(ref) {}
|
|
16625
|
+
}, {
|
|
16626
|
+
key: "has",
|
|
16627
|
+
value: function has(key) {
|
|
16628
|
+
return this.cacheStore.has(key);
|
|
16629
|
+
}
|
|
16630
|
+
}, {
|
|
16631
|
+
key: "put",
|
|
16632
|
+
value: function put(key, item, ref) {
|
|
16633
|
+
if (this.cacheStore.has(key)) {
|
|
16634
|
+
return false;
|
|
16635
|
+
}
|
|
16636
|
+
this.cacheStore.set(key, {
|
|
16637
|
+
value: item,
|
|
16638
|
+
counter: new Set([ref.entity])
|
|
16639
|
+
});
|
|
16640
|
+
this.onRefAdded(ref);
|
|
16641
|
+
return true;
|
|
16642
|
+
}
|
|
16643
|
+
}, {
|
|
16644
|
+
key: "get",
|
|
16645
|
+
value: function get(key, ref) {
|
|
16646
|
+
var cacheItem = this.cacheStore.get(key);
|
|
16647
|
+
if (!cacheItem) {
|
|
16648
|
+
return null;
|
|
16649
|
+
}
|
|
16650
|
+
if (!cacheItem.counter.has(ref.entity)) {
|
|
16651
|
+
cacheItem.counter.add(ref.entity);
|
|
16652
|
+
this.onRefAdded(ref);
|
|
16653
|
+
}
|
|
16654
|
+
return cacheItem.value;
|
|
16655
|
+
}
|
|
16656
|
+
}, {
|
|
16657
|
+
key: "update",
|
|
16658
|
+
value: function update(key, value, ref) {
|
|
16659
|
+
var cacheItem = this.cacheStore.get(key);
|
|
16660
|
+
if (!cacheItem) {
|
|
16661
|
+
return false;
|
|
16662
|
+
}
|
|
16663
|
+
cacheItem.value = _objectSpread(_objectSpread({}, cacheItem.value), value);
|
|
16664
|
+
if (!cacheItem.counter.has(ref.entity)) {
|
|
16665
|
+
cacheItem.counter.add(ref.entity);
|
|
16666
|
+
this.onRefAdded(ref);
|
|
16667
|
+
}
|
|
16668
|
+
return true;
|
|
16669
|
+
}
|
|
16670
|
+
}, {
|
|
16671
|
+
key: "release",
|
|
16672
|
+
value: function release(key, ref) {
|
|
16673
|
+
var cacheItem = this.cacheStore.get(key);
|
|
16674
|
+
if (!cacheItem) {
|
|
16675
|
+
return false;
|
|
16676
|
+
}
|
|
16677
|
+
cacheItem.counter["delete"](ref.entity);
|
|
16678
|
+
if (cacheItem.counter.size <= 0) {
|
|
16679
|
+
this.cacheStore["delete"](key);
|
|
16680
|
+
}
|
|
16681
|
+
return true;
|
|
16682
|
+
}
|
|
16683
|
+
}, {
|
|
16684
|
+
key: "releaseRef",
|
|
16685
|
+
value: function releaseRef(ref) {
|
|
16686
|
+
var _this = this;
|
|
16687
|
+
Array.from(this.cacheStore.keys()).forEach(function (key) {
|
|
16688
|
+
_this.release(key, ref);
|
|
16689
|
+
});
|
|
16690
|
+
}
|
|
16691
|
+
}, {
|
|
16692
|
+
key: "getSize",
|
|
16693
|
+
value: function getSize() {
|
|
16694
|
+
return this.cacheStore.size;
|
|
16695
|
+
}
|
|
16696
|
+
}, {
|
|
16697
|
+
key: "clear",
|
|
16698
|
+
value: function clear() {
|
|
16699
|
+
this.cacheStore.clear();
|
|
16700
|
+
}
|
|
16701
|
+
}]);
|
|
16702
|
+
}();
|
|
16703
|
+
|
|
16704
|
+
var tasks = [];
|
|
16705
|
+
var nextFrameTasks = [];
|
|
16706
|
+
var ImageSlicer = /*#__PURE__*/function () {
|
|
16707
|
+
function ImageSlicer() {
|
|
16708
|
+
_classCallCheck(this, ImageSlicer);
|
|
16709
|
+
}
|
|
16710
|
+
return _createClass(ImageSlicer, null, [{
|
|
16711
|
+
key: "stop",
|
|
16712
|
+
value: function stop() {
|
|
16713
|
+
var api = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ImageSlicer.api;
|
|
16714
|
+
if (ImageSlicer.rafId) {
|
|
16715
|
+
api.cancelAnimationFrame(ImageSlicer.rafId);
|
|
16716
|
+
ImageSlicer.rafId = null;
|
|
16717
|
+
}
|
|
16718
|
+
}
|
|
16719
|
+
}, {
|
|
16720
|
+
key: "executeTask",
|
|
16721
|
+
value: function executeTask() {
|
|
16722
|
+
var api = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ImageSlicer.api;
|
|
16723
|
+
if (tasks.length <= 0 && nextFrameTasks.length <= 0) {
|
|
16724
|
+
return;
|
|
16725
|
+
}
|
|
16726
|
+
nextFrameTasks.forEach(function (task) {
|
|
16727
|
+
return task();
|
|
16728
|
+
});
|
|
16729
|
+
nextFrameTasks = tasks.splice(0, ImageSlicer.TASK_NUM_PER_FRAME);
|
|
16730
|
+
ImageSlicer.rafId = api.requestAnimationFrame(function () {
|
|
16731
|
+
ImageSlicer.executeTask(api);
|
|
16732
|
+
});
|
|
16733
|
+
}
|
|
16734
|
+
}, {
|
|
16735
|
+
key: "sliceImage",
|
|
16736
|
+
value: function sliceImage(image, sliceWidth, sliceHeight, rerender) {
|
|
16737
|
+
var overlap = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
16738
|
+
var api = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ImageSlicer.api;
|
|
16739
|
+
var imageWidth = image.naturalWidth || image.width;
|
|
16740
|
+
var imageHeight = image.naturalHeight || image.height;
|
|
16741
|
+
|
|
16742
|
+
// 计算步长(考虑重叠区域)
|
|
16743
|
+
var strideW = sliceWidth - overlap;
|
|
16744
|
+
var strideH = sliceHeight - overlap;
|
|
16745
|
+
|
|
16746
|
+
// 计算网格尺寸
|
|
16747
|
+
var gridCols = Math.ceil(imageWidth / strideW);
|
|
16748
|
+
var gridRows = Math.ceil(imageHeight / strideH);
|
|
16749
|
+
var result = {
|
|
16750
|
+
tileSize: [sliceWidth, sliceHeight],
|
|
16751
|
+
gridSize: [gridRows, gridCols],
|
|
16752
|
+
tiles: Array(gridRows).fill(null).map(function () {
|
|
16753
|
+
return Array(gridCols).fill(null);
|
|
16754
|
+
})
|
|
16755
|
+
};
|
|
16756
|
+
|
|
16757
|
+
// 遍历网格创建切片
|
|
16758
|
+
var _loop = function _loop(row) {
|
|
16759
|
+
var _loop2 = function _loop2(col) {
|
|
16760
|
+
tasks.push(function () {
|
|
16761
|
+
// 计算当前切片的坐标
|
|
16762
|
+
var startX = col * strideW;
|
|
16763
|
+
var startY = row * strideH;
|
|
16764
|
+
|
|
16765
|
+
// 处理最后一列/行的特殊情况
|
|
16766
|
+
var _ref = [Math.min(sliceWidth, imageWidth - startX), Math.min(sliceHeight, imageHeight - startY)],
|
|
16767
|
+
tempSliceWidth = _ref[0],
|
|
16768
|
+
tempSliceHeight = _ref[1];
|
|
16769
|
+
|
|
16770
|
+
// 创建切片canvas
|
|
16771
|
+
var sliceCanvas = api.createCanvas();
|
|
16772
|
+
sliceCanvas.width = sliceWidth;
|
|
16773
|
+
sliceCanvas.height = sliceHeight;
|
|
16774
|
+
var sliceCtx = sliceCanvas.getContext('2d');
|
|
16775
|
+
|
|
16776
|
+
// 将图像部分绘制到切片canvas上
|
|
16777
|
+
sliceCtx.drawImage(image, startX, startY, tempSliceWidth, tempSliceHeight, 0, 0, tempSliceWidth, tempSliceHeight);
|
|
16778
|
+
|
|
16779
|
+
// 存储切片信息
|
|
16780
|
+
result.tiles[row][col] = {
|
|
16781
|
+
x: startX,
|
|
16782
|
+
y: startY,
|
|
16783
|
+
tileX: col,
|
|
16784
|
+
tileY: row,
|
|
16785
|
+
data: sliceCanvas
|
|
16786
|
+
};
|
|
16787
|
+
rerender();
|
|
16788
|
+
});
|
|
16789
|
+
};
|
|
16790
|
+
for (var col = 0; col < gridCols; col++) {
|
|
16791
|
+
_loop2(col);
|
|
16792
|
+
}
|
|
16793
|
+
};
|
|
16794
|
+
for (var row = 0; row < gridRows; row++) {
|
|
16795
|
+
_loop(row);
|
|
16796
|
+
}
|
|
16797
|
+
ImageSlicer.stop();
|
|
16798
|
+
ImageSlicer.executeTask();
|
|
16799
|
+
return result;
|
|
16800
|
+
}
|
|
16801
|
+
}]);
|
|
16802
|
+
}();
|
|
16803
|
+
ImageSlicer.TASK_NUM_PER_FRAME = 10;
|
|
16804
|
+
|
|
16805
|
+
var IMAGE_CACHE = new RefCountCache();
|
|
16806
|
+
IMAGE_CACHE.onRefAdded = function onRefAdded(ref) {
|
|
16807
|
+
var _this = this;
|
|
16808
|
+
ref.addEventListener(ElementEvent.DESTROY, function () {
|
|
16809
|
+
_this.releaseRef(ref);
|
|
16810
|
+
}, {
|
|
16811
|
+
once: true
|
|
16812
|
+
});
|
|
16813
|
+
};
|
|
16814
|
+
var ImagePool = /*#__PURE__*/function () {
|
|
16815
|
+
function ImagePool(context, runtime) {
|
|
16816
|
+
_classCallCheck(this, ImagePool);
|
|
16817
|
+
this.gradientCache = {};
|
|
16818
|
+
this.patternCache = {};
|
|
16819
|
+
this.context = context;
|
|
16820
|
+
this.runtime = runtime;
|
|
16821
|
+
}
|
|
16822
|
+
return _createClass(ImagePool, [{
|
|
16823
|
+
key: "getImageSync",
|
|
16824
|
+
value: function getImageSync(src, ref, callback) {
|
|
16825
|
+
var imageSource = isString(src) ? src : src.src;
|
|
16826
|
+
if (IMAGE_CACHE.has(imageSource)) {
|
|
16827
|
+
var imageCache = IMAGE_CACHE.get(imageSource, ref);
|
|
16828
|
+
if (imageCache.img.complete) {
|
|
16829
|
+
callback === null || callback === void 0 || callback(imageCache);
|
|
16830
|
+
return imageCache;
|
|
16831
|
+
}
|
|
16832
|
+
}
|
|
16833
|
+
this.getOrCreateImage(src, ref).then(function (cache) {
|
|
16834
|
+
callback === null || callback === void 0 || callback(cache);
|
|
16835
|
+
})["catch"](function (reason) {
|
|
16836
|
+
console.error(reason);
|
|
16837
|
+
});
|
|
16838
|
+
return null;
|
|
16839
|
+
}
|
|
16840
|
+
}, {
|
|
16841
|
+
key: "getOrCreateImage",
|
|
16842
|
+
value: function getOrCreateImage(src, ref) {
|
|
16843
|
+
var _this2 = this;
|
|
16844
|
+
var imageSource = isString(src) ? src : src.src;
|
|
16845
|
+
if (!isString(src) && !IMAGE_CACHE.has(imageSource)) {
|
|
16846
|
+
var imageCache = {
|
|
16847
|
+
img: src,
|
|
16848
|
+
size: [src.naturalWidth || src.width, src.naturalHeight || src.height],
|
|
16849
|
+
tileSize: calculateImageTileSize(src)
|
|
16850
|
+
};
|
|
16851
|
+
IMAGE_CACHE.put(imageSource, imageCache, ref);
|
|
16852
|
+
}
|
|
16853
|
+
if (IMAGE_CACHE.has(imageSource)) {
|
|
16854
|
+
var _imageCache = IMAGE_CACHE.get(imageSource, ref);
|
|
16855
|
+
if (_imageCache.img.complete) {
|
|
16856
|
+
return Promise.resolve(_imageCache);
|
|
16857
|
+
}
|
|
16858
|
+
return new Promise(function (resolve, reject) {
|
|
16859
|
+
_imageCache.img.addEventListener('load', function () {
|
|
16860
|
+
_imageCache.size = [_imageCache.img.naturalWidth || _imageCache.img.width, _imageCache.img.naturalHeight || _imageCache.img.height];
|
|
16861
|
+
_imageCache.tileSize = calculateImageTileSize(_imageCache.img);
|
|
16862
|
+
resolve(_imageCache);
|
|
16863
|
+
});
|
|
16864
|
+
_imageCache.img.addEventListener('error', function (ev) {
|
|
16865
|
+
reject(ev);
|
|
16866
|
+
});
|
|
16867
|
+
});
|
|
16868
|
+
}
|
|
16869
|
+
return new Promise(function (resolve, reject) {
|
|
16870
|
+
// @see https://github.com/antvis/g/issues/938
|
|
16871
|
+
var image = _this2.context.config.createImage();
|
|
16872
|
+
if (image) {
|
|
16873
|
+
var _imageCache2 = {
|
|
16874
|
+
img: image,
|
|
16875
|
+
size: [0, 0],
|
|
16876
|
+
tileSize: calculateImageTileSize(image)
|
|
16877
|
+
};
|
|
16878
|
+
IMAGE_CACHE.put(imageSource, _imageCache2, ref);
|
|
16879
|
+
image.onload = function () {
|
|
16880
|
+
_imageCache2.size = [image.naturalWidth || image.width, image.naturalHeight || image.height];
|
|
16881
|
+
_imageCache2.tileSize = calculateImageTileSize(_imageCache2.img);
|
|
16882
|
+
resolve(_imageCache2);
|
|
16883
|
+
};
|
|
16884
|
+
image.onerror = function (ev) {
|
|
16885
|
+
reject(ev);
|
|
16886
|
+
};
|
|
16887
|
+
image.crossOrigin = 'Anonymous';
|
|
16888
|
+
image.src = imageSource;
|
|
16889
|
+
}
|
|
16890
|
+
});
|
|
16891
|
+
}
|
|
16892
|
+
}, {
|
|
16893
|
+
key: "createDownSampledImage",
|
|
16894
|
+
value: function () {
|
|
16895
|
+
var _createDownSampledImage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(src, ref) {
|
|
16896
|
+
var imageCache, enableLargeImageOptimization, _ref, _ref$maxDownSampledIm, maxDownSampledImageSize, _ref$downSamplingRate, downSamplingRateThreshold, createImageBitmapFunc, _imageCache$size, originWidth, originHeight, resizedImage, downSamplingRate, updateCache;
|
|
16897
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
16898
|
+
while (1) switch (_context.prev = _context.next) {
|
|
16899
|
+
case 0:
|
|
16900
|
+
_context.next = 1;
|
|
16901
|
+
return this.getOrCreateImage(src, ref);
|
|
16902
|
+
case 1:
|
|
16903
|
+
imageCache = _context.sent;
|
|
16904
|
+
if (!(typeof imageCache.downSamplingRate !== 'undefined')) {
|
|
16905
|
+
_context.next = 2;
|
|
16906
|
+
break;
|
|
16907
|
+
}
|
|
16908
|
+
return _context.abrupt("return", imageCache);
|
|
16909
|
+
case 2:
|
|
16910
|
+
enableLargeImageOptimization = this.context.config.enableLargeImageOptimization;
|
|
16911
|
+
_ref = typeof enableLargeImageOptimization === 'boolean' ? {} : enableLargeImageOptimization, _ref$maxDownSampledIm = _ref.maxDownSampledImageSize, maxDownSampledImageSize = _ref$maxDownSampledIm === void 0 ? 2048 : _ref$maxDownSampledIm, _ref$downSamplingRate = _ref.downSamplingRateThreshold, downSamplingRateThreshold = _ref$downSamplingRate === void 0 ? 0.5 : _ref$downSamplingRate;
|
|
16912
|
+
createImageBitmapFunc = this.runtime.globalThis.createImageBitmap;
|
|
16913
|
+
_imageCache$size = _slicedToArray(imageCache.size, 2), originWidth = _imageCache$size[0], originHeight = _imageCache$size[1];
|
|
16914
|
+
resizedImage = imageCache.img;
|
|
16915
|
+
downSamplingRate = Math.min((maxDownSampledImageSize + maxDownSampledImageSize) / (originWidth + originHeight), Math.max(0.01, Math.min(downSamplingRateThreshold, 0.5)));
|
|
16916
|
+
updateCache = _objectSpread(_objectSpread({}, imageCache), {}, {
|
|
16917
|
+
downSamplingRate: downSamplingRate
|
|
16918
|
+
});
|
|
16919
|
+
IMAGE_CACHE.update(imageCache.img.src, updateCache, ref);
|
|
16920
|
+
if (!createImageBitmapFunc) {
|
|
16921
|
+
_context.next = 7;
|
|
16922
|
+
break;
|
|
16923
|
+
}
|
|
16924
|
+
_context.prev = 3;
|
|
16925
|
+
_context.next = 4;
|
|
16926
|
+
return createImageBitmapFunc(imageCache.img, {
|
|
16927
|
+
resizeWidth: originWidth * downSamplingRate,
|
|
16928
|
+
resizeHeight: originHeight * downSamplingRate
|
|
16929
|
+
});
|
|
16930
|
+
case 4:
|
|
16931
|
+
resizedImage = _context.sent;
|
|
16932
|
+
_context.next = 6;
|
|
16933
|
+
break;
|
|
16934
|
+
case 5:
|
|
16935
|
+
_context.prev = 5;
|
|
16936
|
+
_context["catch"](3);
|
|
16937
|
+
downSamplingRate = 1;
|
|
16938
|
+
case 6:
|
|
16939
|
+
_context.next = 8;
|
|
16940
|
+
break;
|
|
16941
|
+
case 7:
|
|
16942
|
+
downSamplingRate = 1;
|
|
16943
|
+
case 8:
|
|
16944
|
+
updateCache = _objectSpread(_objectSpread({}, this.getImageSync(src, ref)), {}, {
|
|
16945
|
+
downSampled: resizedImage,
|
|
16946
|
+
downSamplingRate: downSamplingRate
|
|
16947
|
+
});
|
|
16948
|
+
IMAGE_CACHE.update(imageCache.img.src, updateCache, ref);
|
|
16949
|
+
return _context.abrupt("return", updateCache);
|
|
16950
|
+
case 9:
|
|
16951
|
+
case "end":
|
|
16952
|
+
return _context.stop();
|
|
16953
|
+
}
|
|
16954
|
+
}, _callee, this, [[3, 5]]);
|
|
16955
|
+
}));
|
|
16956
|
+
function createDownSampledImage(_x, _x2) {
|
|
16957
|
+
return _createDownSampledImage.apply(this, arguments);
|
|
16958
|
+
}
|
|
16959
|
+
return createDownSampledImage;
|
|
16960
|
+
}()
|
|
16961
|
+
}, {
|
|
16962
|
+
key: "createImageTiles",
|
|
16963
|
+
value: function () {
|
|
16964
|
+
var _createImageTiles = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(src, tiles, rerender, ref) {
|
|
16965
|
+
var imageCache, _ref$ownerDocument$de, requestAnimationFrame, cancelAnimationFrame, updateCache;
|
|
16966
|
+
return _regeneratorRuntime().wrap(function (_context2) {
|
|
16967
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
16968
|
+
case 0:
|
|
16969
|
+
_context2.next = 1;
|
|
16970
|
+
return this.getOrCreateImage(src, ref);
|
|
16971
|
+
case 1:
|
|
16972
|
+
imageCache = _context2.sent;
|
|
16973
|
+
_ref$ownerDocument$de = ref.ownerDocument.defaultView, requestAnimationFrame = _ref$ownerDocument$de.requestAnimationFrame, cancelAnimationFrame = _ref$ownerDocument$de.cancelAnimationFrame;
|
|
16974
|
+
ImageSlicer.api = {
|
|
16975
|
+
requestAnimationFrame: requestAnimationFrame,
|
|
16976
|
+
cancelAnimationFrame: cancelAnimationFrame,
|
|
16977
|
+
createCanvas: function createCanvas() {
|
|
16978
|
+
return OffscreenCanvasCreator.createCanvas();
|
|
16979
|
+
}
|
|
16980
|
+
};
|
|
16981
|
+
updateCache = _objectSpread(_objectSpread({}, imageCache), ImageSlicer.sliceImage(imageCache.img, imageCache.tileSize[0], imageCache.tileSize[0], rerender));
|
|
16982
|
+
IMAGE_CACHE.update(imageCache.img.src, updateCache, ref);
|
|
16983
|
+
return _context2.abrupt("return", updateCache);
|
|
16984
|
+
case 2:
|
|
16985
|
+
case "end":
|
|
16986
|
+
return _context2.stop();
|
|
16987
|
+
}
|
|
16988
|
+
}, _callee2, this);
|
|
16989
|
+
}));
|
|
16990
|
+
function createImageTiles(_x3, _x4, _x5, _x6) {
|
|
16991
|
+
return _createImageTiles.apply(this, arguments);
|
|
16992
|
+
}
|
|
16993
|
+
return createImageTiles;
|
|
16994
|
+
}()
|
|
16995
|
+
}, {
|
|
16996
|
+
key: "releaseImage",
|
|
16997
|
+
value: function releaseImage(src, ref) {
|
|
16998
|
+
IMAGE_CACHE.release(isString(src) ? src : src.src, ref);
|
|
16999
|
+
}
|
|
17000
|
+
}, {
|
|
17001
|
+
key: "releaseImageRef",
|
|
17002
|
+
value: function releaseImageRef(ref) {
|
|
17003
|
+
IMAGE_CACHE.releaseRef(ref);
|
|
17004
|
+
}
|
|
17005
|
+
}, {
|
|
17006
|
+
key: "getOrCreatePatternSync",
|
|
17007
|
+
value: function getOrCreatePatternSync(object, pattern, context, $offscreenCanvas, dpr, min, callback) {
|
|
17008
|
+
var patternKey = this.generatePatternKey(pattern);
|
|
17009
|
+
if (patternKey && this.patternCache[patternKey]) {
|
|
17010
|
+
return this.patternCache[patternKey];
|
|
17011
|
+
}
|
|
17012
|
+
var image = pattern.image,
|
|
17013
|
+
repetition = pattern.repetition,
|
|
17014
|
+
transform = pattern.transform;
|
|
17015
|
+
var src;
|
|
17016
|
+
var needScaleWithDPR = false;
|
|
17017
|
+
// Image URL
|
|
17018
|
+
if (isString(image)) {
|
|
17019
|
+
var imageCache = this.getImageSync(image, object, callback);
|
|
17020
|
+
src = imageCache === null || imageCache === void 0 ? void 0 : imageCache.img;
|
|
17021
|
+
} else if ($offscreenCanvas) {
|
|
17022
|
+
src = $offscreenCanvas;
|
|
17023
|
+
needScaleWithDPR = true;
|
|
17024
|
+
} else {
|
|
17025
|
+
src = image;
|
|
17026
|
+
}
|
|
17027
|
+
|
|
17028
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
|
|
17029
|
+
var canvasPattern = src && context.createPattern(src, repetition);
|
|
17030
|
+
if (canvasPattern) {
|
|
17031
|
+
var mat;
|
|
17032
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform
|
|
17033
|
+
if (transform) {
|
|
17034
|
+
mat = parsedTransformToMat4(parseTransform(transform), new DisplayObject({}));
|
|
17035
|
+
} else {
|
|
17036
|
+
mat = mat4.identity(mat4.create());
|
|
17037
|
+
}
|
|
17038
|
+
if (needScaleWithDPR) {
|
|
17039
|
+
mat4.scale(mat, mat, [1 / dpr, 1 / dpr, 1]);
|
|
17040
|
+
}
|
|
17041
|
+
canvasPattern.setTransform({
|
|
17042
|
+
a: mat[0],
|
|
17043
|
+
b: mat[1],
|
|
17044
|
+
c: mat[4],
|
|
17045
|
+
d: mat[5],
|
|
17046
|
+
e: mat[12] + min[0],
|
|
17047
|
+
f: mat[13] + min[1]
|
|
17048
|
+
});
|
|
17049
|
+
}
|
|
17050
|
+
if (patternKey && canvasPattern) {
|
|
17051
|
+
this.patternCache[patternKey] = canvasPattern;
|
|
17052
|
+
}
|
|
17053
|
+
return canvasPattern;
|
|
17054
|
+
}
|
|
17055
|
+
}, {
|
|
17056
|
+
key: "getOrCreateGradient",
|
|
17057
|
+
value: function getOrCreateGradient(params, context) {
|
|
17058
|
+
var key = this.generateGradientKey(params);
|
|
17059
|
+
var type = params.type,
|
|
17060
|
+
steps = params.steps,
|
|
17061
|
+
min = params.min,
|
|
17062
|
+
width = params.width,
|
|
17063
|
+
height = params.height,
|
|
17064
|
+
angle = params.angle,
|
|
17065
|
+
cx = params.cx,
|
|
17066
|
+
cy = params.cy,
|
|
17067
|
+
size = params.size;
|
|
17068
|
+
if (this.gradientCache[key]) {
|
|
17069
|
+
return this.gradientCache[key];
|
|
17070
|
+
}
|
|
17071
|
+
var gradient = null;
|
|
17072
|
+
if (type === GradientType.LinearGradient) {
|
|
17073
|
+
var _computeLinearGradien = computeLinearGradient(min, width, height, angle),
|
|
17074
|
+
x1 = _computeLinearGradien.x1,
|
|
17075
|
+
y1 = _computeLinearGradien.y1,
|
|
17076
|
+
x2 = _computeLinearGradien.x2,
|
|
17077
|
+
y2 = _computeLinearGradien.y2;
|
|
17078
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
|
|
17079
|
+
gradient = context.createLinearGradient(x1, y1, x2, y2);
|
|
17080
|
+
} else if (type === GradientType.RadialGradient) {
|
|
17081
|
+
var _computeRadialGradien = computeRadialGradient(min, width, height, cx, cy, size),
|
|
17082
|
+
x = _computeRadialGradien.x,
|
|
17083
|
+
y = _computeRadialGradien.y,
|
|
17084
|
+
r = _computeRadialGradien.r;
|
|
17085
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
|
|
17086
|
+
gradient = context.createRadialGradient(x, y, 0, x, y, r);
|
|
17087
|
+
}
|
|
17088
|
+
if (gradient) {
|
|
17089
|
+
steps.forEach(function (_ref2) {
|
|
17090
|
+
var offset = _ref2.offset,
|
|
17091
|
+
color = _ref2.color;
|
|
17092
|
+
if (offset.unit === UnitType.kPercentage) {
|
|
17093
|
+
var _gradient;
|
|
17094
|
+
(_gradient = gradient) === null || _gradient === void 0 || _gradient.addColorStop(offset.value / 100, color.toString());
|
|
17095
|
+
}
|
|
17096
|
+
});
|
|
17097
|
+
this.gradientCache[key] = gradient;
|
|
17098
|
+
}
|
|
17099
|
+
return this.gradientCache[key];
|
|
17100
|
+
}
|
|
17101
|
+
}, {
|
|
17102
|
+
key: "generateGradientKey",
|
|
17103
|
+
value: function generateGradientKey(params) {
|
|
17104
|
+
var type = params.type,
|
|
17105
|
+
min = params.min,
|
|
17106
|
+
width = params.width,
|
|
17107
|
+
height = params.height,
|
|
17108
|
+
steps = params.steps,
|
|
17109
|
+
angle = params.angle,
|
|
17110
|
+
cx = params.cx,
|
|
17111
|
+
cy = params.cy,
|
|
17112
|
+
size = params.size;
|
|
17113
|
+
return "gradient-".concat(type, "-").concat((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0, "-").concat((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0, "-").concat((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0, "-").concat((size === null || size === void 0 ? void 0 : size.toString()) || 0, "-").concat(min[0], "-").concat(min[1], "-").concat(width, "-").concat(height, "-").concat(steps.map(function (_ref3) {
|
|
17114
|
+
var offset = _ref3.offset,
|
|
17115
|
+
color = _ref3.color;
|
|
17116
|
+
return "".concat(offset).concat(color);
|
|
17117
|
+
}).join('-'));
|
|
17118
|
+
}
|
|
17119
|
+
}, {
|
|
17120
|
+
key: "generatePatternKey",
|
|
17121
|
+
value: function generatePatternKey(pattern) {
|
|
17122
|
+
var image = pattern.image,
|
|
17123
|
+
repetition = pattern.repetition;
|
|
17124
|
+
// only generate cache for Image
|
|
17125
|
+
if (isString(image)) {
|
|
17126
|
+
return "pattern-".concat(image, "-").concat(repetition);
|
|
17127
|
+
}
|
|
17128
|
+
if (image.nodeName === 'rect') {
|
|
17129
|
+
return "pattern-".concat(image.entity, "-").concat(repetition);
|
|
17130
|
+
}
|
|
17131
|
+
}
|
|
17132
|
+
}]);
|
|
17133
|
+
}();
|
|
17134
|
+
ImagePool.isSupportTile = !!OffscreenCanvasCreator.createCanvas();
|
|
17135
|
+
function calculateImageTileSize(img) {
|
|
17136
|
+
if (!img.complete) {
|
|
17137
|
+
return [0, 0];
|
|
17138
|
+
}
|
|
17139
|
+
var width = img.naturalWidth || img.width,
|
|
17140
|
+
height = img.naturalHeight || img.height;
|
|
17141
|
+
var tileSize = 256;
|
|
17142
|
+
[256, 512].forEach(function (size) {
|
|
17143
|
+
var rows = Math.ceil(height / size);
|
|
17144
|
+
var cols = Math.ceil(width / size);
|
|
17145
|
+
if (rows * cols < 1e3) {
|
|
17146
|
+
tileSize = size;
|
|
17147
|
+
}
|
|
17148
|
+
});
|
|
17149
|
+
return [tileSize, tileSize];
|
|
17150
|
+
}
|
|
17151
|
+
|
|
17152
|
+
var LoadImagePlugin = /*#__PURE__*/function () {
|
|
17153
|
+
function LoadImagePlugin() {
|
|
17154
|
+
_classCallCheck(this, LoadImagePlugin);
|
|
17155
|
+
}
|
|
17156
|
+
return _createClass(LoadImagePlugin, [{
|
|
17157
|
+
key: "apply",
|
|
17158
|
+
value: function apply(context) {
|
|
17159
|
+
var renderingService = context.renderingService,
|
|
17160
|
+
renderingContext = context.renderingContext,
|
|
17161
|
+
imagePool = context.imagePool;
|
|
17162
|
+
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
17163
|
+
var calculateWithAspectRatio = function calculateWithAspectRatio(object, imageWidth, imageHeight) {
|
|
17164
|
+
var _object$parsedStyle = object.parsedStyle,
|
|
17165
|
+
width = _object$parsedStyle.width,
|
|
17166
|
+
height = _object$parsedStyle.height;
|
|
17167
|
+
if (width && !height) {
|
|
17168
|
+
object.setAttribute('height', imageHeight / imageWidth * width);
|
|
17169
|
+
} else if (!width && height) {
|
|
17170
|
+
object.setAttribute('width', imageWidth / imageHeight * height);
|
|
17171
|
+
}
|
|
17172
|
+
};
|
|
17173
|
+
var handleMounted = function handleMounted(e) {
|
|
17174
|
+
var object = e.target;
|
|
17175
|
+
var nodeName = object.nodeName,
|
|
17176
|
+
attributes = object.attributes;
|
|
17177
|
+
if (nodeName === Shape.IMAGE) {
|
|
17178
|
+
var src = attributes.src,
|
|
17179
|
+
keepAspectRatio = attributes.keepAspectRatio;
|
|
17180
|
+
imagePool.getImageSync(src, object, function (_ref) {
|
|
17181
|
+
var _ref$img = _ref.img,
|
|
17182
|
+
width = _ref$img.width,
|
|
17183
|
+
height = _ref$img.height;
|
|
17184
|
+
if (keepAspectRatio) {
|
|
17185
|
+
calculateWithAspectRatio(object, width, height);
|
|
17186
|
+
}
|
|
17187
|
+
object.dirty();
|
|
17188
|
+
renderingService.dirty();
|
|
17189
|
+
});
|
|
17190
|
+
}
|
|
17191
|
+
};
|
|
17192
|
+
var handleAttributeChanged = function handleAttributeChanged(e) {
|
|
17193
|
+
var object = e.target;
|
|
17194
|
+
var attrName = e.attrName,
|
|
17195
|
+
prevValue = e.prevValue,
|
|
17196
|
+
newValue = e.newValue;
|
|
17197
|
+
if (object.nodeName !== Shape.IMAGE || attrName !== 'src') {
|
|
17198
|
+
return;
|
|
17199
|
+
}
|
|
17200
|
+
if (prevValue !== newValue) {
|
|
17201
|
+
imagePool.releaseImage(prevValue, object);
|
|
17202
|
+
}
|
|
17203
|
+
if (isString(newValue)) {
|
|
17204
|
+
imagePool.getOrCreateImage(newValue, object).then(function (_ref2) {
|
|
17205
|
+
var _ref2$img = _ref2.img,
|
|
17206
|
+
width = _ref2$img.width,
|
|
17207
|
+
height = _ref2$img.height;
|
|
17208
|
+
if (object.attributes.keepAspectRatio) {
|
|
17209
|
+
calculateWithAspectRatio(object, width, height);
|
|
17210
|
+
}
|
|
17211
|
+
object.dirty();
|
|
17212
|
+
renderingService.dirty();
|
|
17213
|
+
})["catch"](function () {
|
|
17214
|
+
//
|
|
17215
|
+
});
|
|
17216
|
+
}
|
|
17217
|
+
};
|
|
17218
|
+
renderingService.hooks.init.tap(LoadImagePlugin.tag, function () {
|
|
17219
|
+
canvas.addEventListener(ElementEvent.MOUNTED, handleMounted);
|
|
17220
|
+
canvas.addEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
17221
|
+
});
|
|
17222
|
+
renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
|
|
17223
|
+
canvas.removeEventListener(ElementEvent.MOUNTED, handleMounted);
|
|
17224
|
+
canvas.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
17225
|
+
});
|
|
17226
|
+
}
|
|
17227
|
+
}]);
|
|
17228
|
+
}();
|
|
17229
|
+
LoadImagePlugin.tag = 'LoadImage';
|
|
17230
|
+
|
|
17231
|
+
var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
17232
|
+
function Plugin() {
|
|
17233
|
+
var _this;
|
|
17234
|
+
_classCallCheck(this, Plugin);
|
|
17235
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
17236
|
+
args[_key] = arguments[_key];
|
|
17237
|
+
}
|
|
17238
|
+
_this = _callSuper(this, Plugin, [].concat(args));
|
|
17239
|
+
_this.name = 'image-loader';
|
|
17240
|
+
return _this;
|
|
17241
|
+
}
|
|
17242
|
+
_inherits(Plugin, _AbstractRendererPlug);
|
|
17243
|
+
return _createClass(Plugin, [{
|
|
17244
|
+
key: "init",
|
|
17245
|
+
value: function init(runtime) {
|
|
17246
|
+
// @ts-ignore
|
|
17247
|
+
this.context.imagePool = new ImagePool(this.context, runtime);
|
|
17248
|
+
this.addRenderingPlugin(new LoadImagePlugin());
|
|
17249
|
+
}
|
|
17250
|
+
}, {
|
|
17251
|
+
key: "destroy",
|
|
17252
|
+
value: function destroy() {
|
|
17253
|
+
this.removeAllRenderingPlugins();
|
|
17254
|
+
}
|
|
17255
|
+
}]);
|
|
17256
|
+
}(AbstractRendererPlugin);
|
|
17257
|
+
|
|
17258
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
17259
|
+
__proto__: null,
|
|
17260
|
+
ImagePool: ImagePool,
|
|
17261
|
+
Plugin: Plugin$3
|
|
17262
|
+
});
|
|
17263
|
+
|
|
17264
|
+
var CANVAS_CAMERA_ID = 'g-canvas-camera';
|
|
17265
|
+
var HTMLRenderingPlugin = /*#__PURE__*/function () {
|
|
17266
|
+
function HTMLRenderingPlugin() {
|
|
17267
|
+
_classCallCheck(this, HTMLRenderingPlugin);
|
|
17268
|
+
this.displayObjectHTMLElementMap = new WeakMap();
|
|
17269
|
+
}
|
|
17270
|
+
return _createClass(HTMLRenderingPlugin, [{
|
|
17271
|
+
key: "joinTransformMatrix",
|
|
17272
|
+
value:
|
|
17273
|
+
/**
|
|
17274
|
+
* ! The reason for adding `offset` is that the `transform-origin` coordinate system of DOM is the local coordinate system of the element, while the `transform-origin` coordinate system of canvas drawing is the local coordinate system of the element's parent element. At the same time, the `transform` attribute value of the DOM element does not include `transform-origin`.
|
|
17275
|
+
*/
|
|
17276
|
+
function joinTransformMatrix(matrix) {
|
|
17277
|
+
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
|
|
17278
|
+
return "matrix(".concat([matrix[0], matrix[1], matrix[4], matrix[5], matrix[12] + offset[0], matrix[13] + offset[1]].join(','), ")");
|
|
17279
|
+
}
|
|
17280
|
+
}, {
|
|
17281
|
+
key: "apply",
|
|
17282
|
+
value: function apply(context, runtime) {
|
|
17283
|
+
var _this = this;
|
|
17284
|
+
var camera = context.camera,
|
|
17285
|
+
renderingContext = context.renderingContext,
|
|
17286
|
+
renderingService = context.renderingService;
|
|
17287
|
+
this.context = context;
|
|
17288
|
+
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
17289
|
+
var nativeHTMLMap = canvas.context.eventService.nativeHTMLMap;
|
|
17290
|
+
var setTransform = function setTransform(object, $el) {
|
|
17291
|
+
$el.style.transform = _this.joinTransformMatrix(object.getWorldTransform(), object.getOrigin());
|
|
17292
|
+
};
|
|
17293
|
+
var handleMounted = function handleMounted(e) {
|
|
17294
|
+
var object = e.target;
|
|
17295
|
+
if (object.nodeName === Shape.HTML) {
|
|
17296
|
+
if (!_this.$camera) {
|
|
17297
|
+
_this.$camera = _this.createCamera(camera);
|
|
17298
|
+
}
|
|
17299
|
+
|
|
17300
|
+
// create DOM element
|
|
17301
|
+
var $el = _this.getOrCreateEl(object);
|
|
17302
|
+
_this.$camera.appendChild($el);
|
|
17303
|
+
Object.keys(object.attributes).forEach(function (name) {
|
|
17304
|
+
_this.updateAttribute(name, object);
|
|
17305
|
+
});
|
|
17306
|
+
setTransform(object, $el);
|
|
17307
|
+
nativeHTMLMap.set($el, object);
|
|
17308
|
+
}
|
|
17309
|
+
};
|
|
17310
|
+
var handleUnmounted = function handleUnmounted(e) {
|
|
17311
|
+
var object = e.target;
|
|
17312
|
+
if (object.nodeName === Shape.HTML && _this.$camera) {
|
|
17313
|
+
var $el = _this.getOrCreateEl(object);
|
|
17314
|
+
if ($el) {
|
|
17315
|
+
$el.remove();
|
|
17316
|
+
nativeHTMLMap["delete"]($el);
|
|
17317
|
+
}
|
|
17318
|
+
}
|
|
17319
|
+
};
|
|
17320
|
+
var handleAttributeChanged = function handleAttributeChanged(e) {
|
|
17321
|
+
var object = e.target;
|
|
17322
|
+
if (object.nodeName === Shape.HTML) {
|
|
17323
|
+
var attrName = e.attrName;
|
|
17324
|
+
_this.updateAttribute(attrName, object);
|
|
17325
|
+
}
|
|
17326
|
+
};
|
|
17327
|
+
var handleBoundsChanged = function handleBoundsChanged(e) {
|
|
17328
|
+
var records = e.detail;
|
|
17329
|
+
for (var i = 0; i < records.length; i++) {
|
|
17330
|
+
var record = records[i];
|
|
17331
|
+
var object = record.target;
|
|
17332
|
+
var nodes = object.nodeName === Shape.FRAGMENT ? object.childNodes : [object];
|
|
17333
|
+
nodes.forEach(function (node) {
|
|
17334
|
+
if (node.nodeName === Shape.HTML) {
|
|
17335
|
+
var $el = _this.getOrCreateEl(node);
|
|
17336
|
+
setTransform(node, $el);
|
|
17337
|
+
}
|
|
17338
|
+
});
|
|
17339
|
+
}
|
|
17340
|
+
};
|
|
17341
|
+
var handleCanvasResize = function handleCanvasResize() {
|
|
17342
|
+
if (_this.$camera) {
|
|
17343
|
+
var _this$context$config = _this.context.config,
|
|
17344
|
+
width = _this$context$config.width,
|
|
17345
|
+
height = _this$context$config.height;
|
|
17346
|
+
_this.$camera.parentElement.style.width = "".concat(width || 0, "px");
|
|
17347
|
+
_this.$camera.parentElement.style.height = "".concat(height || 0, "px");
|
|
17348
|
+
}
|
|
17349
|
+
};
|
|
17350
|
+
renderingService.hooks.init.tap(HTMLRenderingPlugin.tag, function () {
|
|
17351
|
+
canvas.addEventListener(CanvasEvent.RESIZE, handleCanvasResize);
|
|
17352
|
+
canvas.addEventListener(ElementEvent.MOUNTED, handleMounted);
|
|
17353
|
+
canvas.addEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
|
|
17354
|
+
canvas.addEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
17355
|
+
canvas.addEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
17356
|
+
});
|
|
17357
|
+
renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
|
|
17358
|
+
if (_this.$camera && renderingContext.renderReasons.has(RenderReason.CAMERA_CHANGED)) {
|
|
17359
|
+
_this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
|
|
17360
|
+
}
|
|
17361
|
+
});
|
|
17362
|
+
renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
|
|
17363
|
+
// remove camera
|
|
17364
|
+
if (_this.$camera) {
|
|
17365
|
+
_this.$camera.remove();
|
|
17366
|
+
}
|
|
17367
|
+
canvas.removeEventListener(CanvasEvent.RESIZE, handleCanvasResize);
|
|
17368
|
+
canvas.removeEventListener(ElementEvent.MOUNTED, handleMounted);
|
|
17369
|
+
canvas.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
|
|
17370
|
+
canvas.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
17371
|
+
canvas.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
17372
|
+
});
|
|
17373
|
+
}
|
|
17374
|
+
}, {
|
|
17375
|
+
key: "createCamera",
|
|
17376
|
+
value: function createCamera(camera) {
|
|
17377
|
+
var _this$context$config2 = this.context.config,
|
|
17378
|
+
doc = _this$context$config2.document,
|
|
17379
|
+
width = _this$context$config2.width,
|
|
17380
|
+
height = _this$context$config2.height;
|
|
17381
|
+
var $canvas = this.context.contextService.getDomElement();
|
|
17382
|
+
var $container = $canvas.parentNode;
|
|
17383
|
+
if ($container) {
|
|
17384
|
+
var cameraId = CANVAS_CAMERA_ID;
|
|
17385
|
+
var $existedCamera = $container.querySelector("#".concat(cameraId));
|
|
17386
|
+
if (!$existedCamera) {
|
|
17387
|
+
// fix @see https://github.com/antvis/G/issues/1702
|
|
17388
|
+
var $cameraContainer = (doc || document).createElement('div');
|
|
17389
|
+
// HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
|
|
17390
|
+
$cameraContainer.style.overflow = 'hidden';
|
|
17391
|
+
$cameraContainer.style.pointerEvents = 'none';
|
|
17392
|
+
$cameraContainer.style.position = 'absolute';
|
|
17393
|
+
$cameraContainer.style.left = "0px";
|
|
17394
|
+
$cameraContainer.style.top = "0px";
|
|
17395
|
+
$cameraContainer.style.width = "".concat(width || 0, "px");
|
|
17396
|
+
$cameraContainer.style.height = "".concat(height || 0, "px");
|
|
17397
|
+
var $camera = (doc || document).createElement('div');
|
|
17398
|
+
$existedCamera = $camera;
|
|
17399
|
+
$camera.id = cameraId;
|
|
17400
|
+
// use absolute position
|
|
17401
|
+
$camera.style.position = 'absolute';
|
|
17402
|
+
// account for DOM element's offset @see https://github.com/antvis/G/issues/1150
|
|
17403
|
+
$camera.style.left = "".concat($canvas.offsetLeft || 0, "px");
|
|
17404
|
+
$camera.style.top = "".concat($canvas.offsetTop || 0, "px");
|
|
17405
|
+
$camera.style.transformOrigin = 'left top';
|
|
17406
|
+
$camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
|
|
17407
|
+
$camera.style.pointerEvents = 'none';
|
|
17408
|
+
$camera.style.width = "100%";
|
|
17409
|
+
$camera.style.height = "100%";
|
|
17410
|
+
$cameraContainer.appendChild($camera);
|
|
17411
|
+
$container.appendChild($cameraContainer);
|
|
17412
|
+
}
|
|
17413
|
+
return $existedCamera;
|
|
17414
|
+
}
|
|
17415
|
+
return null;
|
|
17416
|
+
}
|
|
17417
|
+
}, {
|
|
17418
|
+
key: "getOrCreateEl",
|
|
17419
|
+
value: function getOrCreateEl(object) {
|
|
17420
|
+
var doc = this.context.config.document;
|
|
17421
|
+
var $existedElement = this.displayObjectHTMLElementMap.get(object);
|
|
17422
|
+
if (!$existedElement) {
|
|
17423
|
+
$existedElement = (doc || document).createElement('div');
|
|
17424
|
+
object.parsedStyle.$el = $existedElement;
|
|
17425
|
+
this.displayObjectHTMLElementMap.set(object, $existedElement);
|
|
17426
|
+
if (object.id) {
|
|
17427
|
+
$existedElement.id = object.id;
|
|
17428
|
+
}
|
|
17429
|
+
if (object.name) {
|
|
17430
|
+
$existedElement.setAttribute('name', object.name);
|
|
17431
|
+
}
|
|
17432
|
+
if (object.className) {
|
|
17433
|
+
$existedElement.className = object.className;
|
|
17434
|
+
}
|
|
17435
|
+
|
|
17436
|
+
// use absolute position
|
|
17437
|
+
$existedElement.style.position = 'absolute';
|
|
17438
|
+
// @see https://github.com/antvis/G/issues/1150
|
|
17439
|
+
$existedElement.style['will-change'] = 'transform';
|
|
17440
|
+
$existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform(), object.getOrigin());
|
|
17441
|
+
}
|
|
17442
|
+
return $existedElement;
|
|
17443
|
+
}
|
|
17444
|
+
}, {
|
|
17445
|
+
key: "updateAttribute",
|
|
17446
|
+
value: function updateAttribute(name, object) {
|
|
17447
|
+
var $el = this.getOrCreateEl(object);
|
|
17448
|
+
switch (name) {
|
|
17449
|
+
case 'innerHTML':
|
|
17450
|
+
var innerHTML = object.parsedStyle.innerHTML;
|
|
17451
|
+
if (isString(innerHTML)) {
|
|
17452
|
+
$el.innerHTML = innerHTML;
|
|
17453
|
+
} else {
|
|
17454
|
+
$el.innerHTML = '';
|
|
17455
|
+
$el.appendChild(innerHTML);
|
|
17456
|
+
}
|
|
17457
|
+
break;
|
|
17458
|
+
case 'x':
|
|
17459
|
+
$el.style.left = "".concat(object.parsedStyle.x, "px");
|
|
17460
|
+
break;
|
|
17461
|
+
case 'y':
|
|
17462
|
+
$el.style.top = "".concat(object.parsedStyle.y, "px");
|
|
17463
|
+
break;
|
|
17464
|
+
case 'transformOrigin':
|
|
17465
|
+
var transformOrigin = object.parsedStyle.transformOrigin;
|
|
17466
|
+
$el.style['transform-origin'] = "".concat(transformOrigin[0].buildCSSText(null, null, ''), " ").concat(transformOrigin[1].buildCSSText(null, null, ''));
|
|
17467
|
+
break;
|
|
17468
|
+
case 'width':
|
|
17469
|
+
var width = object.parsedStyle.width;
|
|
17470
|
+
$el.style.width = isNumber(width) ? "".concat(width, "px") : width.toString();
|
|
17471
|
+
break;
|
|
17472
|
+
case 'height':
|
|
17473
|
+
var height = object.parsedStyle.height;
|
|
17474
|
+
$el.style.height = isNumber(height) ? "".concat(height, "px") : height.toString();
|
|
17475
|
+
break;
|
|
17476
|
+
case 'zIndex':
|
|
17477
|
+
var zIndex = object.parsedStyle.zIndex;
|
|
17478
|
+
$el.style['z-index'] = "".concat(zIndex);
|
|
17479
|
+
break;
|
|
17480
|
+
case 'visibility':
|
|
17481
|
+
var visibility = object.parsedStyle.visibility;
|
|
17482
|
+
$el.style.visibility = visibility;
|
|
17483
|
+
break;
|
|
17484
|
+
case 'pointerEvents':
|
|
17485
|
+
var _object$parsedStyle$p = object.parsedStyle.pointerEvents,
|
|
17486
|
+
pointerEvents = _object$parsedStyle$p === void 0 ? 'auto' : _object$parsedStyle$p;
|
|
17487
|
+
$el.style.pointerEvents = pointerEvents;
|
|
17488
|
+
break;
|
|
17489
|
+
case 'opacity':
|
|
17490
|
+
var opacity = object.parsedStyle.opacity;
|
|
17491
|
+
$el.style.opacity = "".concat(opacity);
|
|
17492
|
+
break;
|
|
17493
|
+
case 'fill':
|
|
17494
|
+
var fill = object.parsedStyle.fill;
|
|
17495
|
+
var color = '';
|
|
17496
|
+
if (isCSSRGB(fill)) {
|
|
17497
|
+
if (fill.isNone) {
|
|
17498
|
+
color = 'transparent';
|
|
17499
|
+
} else {
|
|
17500
|
+
color = object.getAttribute('fill');
|
|
17501
|
+
}
|
|
17502
|
+
} else if (Array.isArray(fill)) {
|
|
17503
|
+
color = object.getAttribute('fill');
|
|
17504
|
+
} else if (isPattern(fill)) ;
|
|
17505
|
+
$el.style.background = color;
|
|
17506
|
+
break;
|
|
17507
|
+
case 'stroke':
|
|
17508
|
+
var stroke = object.parsedStyle.stroke;
|
|
17509
|
+
var borderColor = '';
|
|
17510
|
+
if (isCSSRGB(stroke)) {
|
|
17511
|
+
if (stroke.isNone) {
|
|
17512
|
+
borderColor = 'transparent';
|
|
17513
|
+
} else {
|
|
17514
|
+
borderColor = object.getAttribute('stroke');
|
|
17515
|
+
}
|
|
17516
|
+
} else if (Array.isArray(stroke)) {
|
|
17517
|
+
borderColor = object.getAttribute('stroke');
|
|
17518
|
+
} else if (isPattern(stroke)) ;
|
|
17519
|
+
$el.style['border-color'] = borderColor;
|
|
17520
|
+
$el.style['border-style'] = 'solid';
|
|
17521
|
+
break;
|
|
17522
|
+
case 'lineWidth':
|
|
17523
|
+
var lineWidth = object.parsedStyle.lineWidth;
|
|
17524
|
+
$el.style['border-width'] = "".concat(lineWidth || 0, "px");
|
|
17525
|
+
break;
|
|
17526
|
+
case 'lineDash':
|
|
17527
|
+
$el.style['border-style'] = 'dashed';
|
|
17528
|
+
break;
|
|
17529
|
+
case 'filter':
|
|
17530
|
+
var filter = object.style.filter;
|
|
17531
|
+
$el.style.filter = filter;
|
|
17532
|
+
break;
|
|
17533
|
+
default:
|
|
17534
|
+
if (!isNil(object.style[name]) && object.style[name] !== '') {
|
|
17535
|
+
$el.style[name] = object.style[name];
|
|
17536
|
+
}
|
|
17537
|
+
}
|
|
17538
|
+
}
|
|
17539
|
+
}]);
|
|
17540
|
+
}();
|
|
17541
|
+
HTMLRenderingPlugin.tag = 'HTMLRendering';
|
|
17542
|
+
|
|
17543
|
+
var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
17544
|
+
function Plugin() {
|
|
17545
|
+
var _this;
|
|
17546
|
+
_classCallCheck(this, Plugin);
|
|
17547
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
17548
|
+
args[_key] = arguments[_key];
|
|
17549
|
+
}
|
|
17550
|
+
_this = _callSuper(this, Plugin, [].concat(args));
|
|
17551
|
+
_this.name = 'html-renderer';
|
|
17552
|
+
return _this;
|
|
17553
|
+
}
|
|
17554
|
+
_inherits(Plugin, _AbstractRendererPlug);
|
|
17555
|
+
return _createClass(Plugin, [{
|
|
17556
|
+
key: "init",
|
|
17557
|
+
value: function init() {
|
|
17558
|
+
this.addRenderingPlugin(new HTMLRenderingPlugin());
|
|
17559
|
+
}
|
|
17560
|
+
}, {
|
|
17561
|
+
key: "destroy",
|
|
17562
|
+
value: function destroy() {
|
|
17563
|
+
this.removeAllRenderingPlugins();
|
|
17564
|
+
}
|
|
17565
|
+
}]);
|
|
17566
|
+
}(AbstractRendererPlugin);
|
|
17567
|
+
|
|
17568
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
17569
|
+
__proto__: null,
|
|
17570
|
+
Plugin: Plugin$2
|
|
17571
|
+
});
|
|
17572
|
+
|
|
17573
|
+
// const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
|
17574
|
+
|
|
17575
|
+
/**
|
|
17576
|
+
* listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
|
|
17577
|
+
*/
|
|
17578
|
+
var DOMInteractionPlugin = /*#__PURE__*/function () {
|
|
17579
|
+
function DOMInteractionPlugin() {
|
|
17580
|
+
_classCallCheck(this, DOMInteractionPlugin);
|
|
17581
|
+
}
|
|
17582
|
+
return _createClass(DOMInteractionPlugin, [{
|
|
17583
|
+
key: "apply",
|
|
17584
|
+
value: function apply(context, runtime) {
|
|
17585
|
+
var _this = this;
|
|
17586
|
+
var renderingService = context.renderingService,
|
|
17587
|
+
renderingContext = context.renderingContext,
|
|
17588
|
+
config = context.config;
|
|
17589
|
+
this.context = context;
|
|
17590
|
+
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
17591
|
+
// const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
|
|
17592
|
+
|
|
17593
|
+
var onPointerMove = function onPointerMove(ev) {
|
|
17594
|
+
renderingService.hooks.pointerMove.call(ev);
|
|
17595
|
+
};
|
|
17596
|
+
var onPointerUp = function onPointerUp(ev) {
|
|
17597
|
+
renderingService.hooks.pointerUp.call(ev);
|
|
17598
|
+
};
|
|
17599
|
+
var onPointerDown = function onPointerDown(ev) {
|
|
17600
|
+
renderingService.hooks.pointerDown.call(ev);
|
|
17601
|
+
};
|
|
17602
|
+
var onPointerOver = function onPointerOver(ev) {
|
|
17603
|
+
renderingService.hooks.pointerOver.call(ev);
|
|
17604
|
+
};
|
|
17605
|
+
var onPointerOut = function onPointerOut(ev) {
|
|
17606
|
+
renderingService.hooks.pointerOut.call(ev);
|
|
17607
|
+
};
|
|
17608
|
+
var onPointerCancel = function onPointerCancel(ev) {
|
|
17609
|
+
renderingService.hooks.pointerCancel.call(ev);
|
|
17610
|
+
};
|
|
17611
|
+
var onPointerWheel = function onPointerWheel(ev) {
|
|
17612
|
+
renderingService.hooks.pointerWheel.call(ev);
|
|
17613
|
+
};
|
|
17614
|
+
var onClick = function onClick(ev) {
|
|
17615
|
+
renderingService.hooks.click.call(ev);
|
|
17616
|
+
};
|
|
17617
|
+
var addPointerEventListener = function addPointerEventListener($el) {
|
|
17618
|
+
runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
|
|
17619
|
+
$el.addEventListener('pointerdown', onPointerDown, true);
|
|
17620
|
+
$el.addEventListener('pointerleave', onPointerOut, true);
|
|
17621
|
+
$el.addEventListener('pointerover', onPointerOver, true);
|
|
17622
|
+
runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
|
|
17623
|
+
runtime.globalThis.addEventListener('pointercancel', onPointerCancel, true);
|
|
17624
|
+
};
|
|
17625
|
+
var addTouchEventListener = function addTouchEventListener($el) {
|
|
17626
|
+
$el.addEventListener('touchstart', onPointerDown, true);
|
|
17627
|
+
$el.addEventListener('touchend', onPointerUp, true);
|
|
17628
|
+
$el.addEventListener('touchmove', onPointerMove, true);
|
|
17629
|
+
$el.addEventListener('touchcancel', onPointerCancel, true);
|
|
17630
|
+
};
|
|
17631
|
+
var addMouseEventListener = function addMouseEventListener($el) {
|
|
17632
|
+
runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
|
|
17633
|
+
$el.addEventListener('mousedown', onPointerDown, true);
|
|
17634
|
+
$el.addEventListener('mouseout', onPointerOut, true);
|
|
17635
|
+
$el.addEventListener('mouseover', onPointerOver, true);
|
|
17636
|
+
runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
|
|
17637
|
+
};
|
|
17638
|
+
var removePointerEventListener = function removePointerEventListener($el) {
|
|
17639
|
+
runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
|
|
17640
|
+
$el.removeEventListener('pointerdown', onPointerDown, true);
|
|
17641
|
+
$el.removeEventListener('pointerleave', onPointerOut, true);
|
|
17642
|
+
$el.removeEventListener('pointerover', onPointerOver, true);
|
|
17643
|
+
runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
|
|
17644
|
+
runtime.globalThis.removeEventListener('pointercancel', onPointerCancel, true);
|
|
17645
|
+
};
|
|
17646
|
+
var removeTouchEventListener = function removeTouchEventListener($el) {
|
|
17647
|
+
$el.removeEventListener('touchstart', onPointerDown, true);
|
|
17648
|
+
$el.removeEventListener('touchend', onPointerUp, true);
|
|
17649
|
+
$el.removeEventListener('touchmove', onPointerMove, true);
|
|
17650
|
+
$el.removeEventListener('touchcancel', onPointerCancel, true);
|
|
17651
|
+
};
|
|
17652
|
+
var removeMouseEventListener = function removeMouseEventListener($el) {
|
|
17653
|
+
runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
|
|
17654
|
+
$el.removeEventListener('mousedown', onPointerDown, true);
|
|
17655
|
+
$el.removeEventListener('mouseout', onPointerOut, true);
|
|
17656
|
+
$el.removeEventListener('mouseover', onPointerOver, true);
|
|
17657
|
+
runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
|
|
17658
|
+
};
|
|
17659
|
+
renderingService.hooks.init.tap(DOMInteractionPlugin.tag, function () {
|
|
17660
|
+
var $el = _this.context.contextService.getDomElement();
|
|
17661
|
+
|
|
17662
|
+
// @ts-ignore
|
|
17663
|
+
if (runtime.globalThis.navigator.msPointerEnabled) {
|
|
17664
|
+
// @ts-ignore
|
|
17665
|
+
$el.style.msContentZooming = 'none';
|
|
17666
|
+
// @ts-ignore
|
|
17667
|
+
$el.style.msTouchAction = 'none';
|
|
17668
|
+
} else if (canvas.supportsPointerEvents) {
|
|
17669
|
+
$el.style.touchAction = 'none';
|
|
17670
|
+
}
|
|
17671
|
+
if (canvas.supportsPointerEvents) {
|
|
17672
|
+
addPointerEventListener($el);
|
|
17673
|
+
} else {
|
|
17674
|
+
addMouseEventListener($el);
|
|
17675
|
+
}
|
|
17676
|
+
if (canvas.supportsTouchEvents) {
|
|
17677
|
+
addTouchEventListener($el);
|
|
17678
|
+
}
|
|
17679
|
+
if (config.useNativeClickEvent) {
|
|
17680
|
+
$el.addEventListener('click', onClick, true);
|
|
17681
|
+
}
|
|
17682
|
+
|
|
17683
|
+
// use passive event listeners
|
|
17684
|
+
// @see https://zhuanlan.zhihu.com/p/24555031
|
|
17685
|
+
$el.addEventListener('wheel', onPointerWheel, {
|
|
17686
|
+
passive: true,
|
|
17687
|
+
capture: true
|
|
17688
|
+
});
|
|
17689
|
+
});
|
|
17690
|
+
renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
|
|
17691
|
+
var $el = _this.context.contextService.getDomElement();
|
|
17692
|
+
|
|
17693
|
+
// @ts-ignore
|
|
17694
|
+
if (runtime.globalThis.navigator.msPointerEnabled) {
|
|
17695
|
+
// @ts-ignore
|
|
17696
|
+
$el.style.msContentZooming = '';
|
|
17697
|
+
// @ts-ignore
|
|
17698
|
+
$el.style.msTouchAction = '';
|
|
17699
|
+
} else if (canvas.supportsPointerEvents) {
|
|
17700
|
+
$el.style.touchAction = '';
|
|
17701
|
+
}
|
|
17702
|
+
if (canvas.supportsPointerEvents) {
|
|
17703
|
+
removePointerEventListener($el);
|
|
17704
|
+
} else {
|
|
17705
|
+
removeMouseEventListener($el);
|
|
17706
|
+
}
|
|
17707
|
+
if (canvas.supportsTouchEvents) {
|
|
17708
|
+
removeTouchEventListener($el);
|
|
17709
|
+
}
|
|
17710
|
+
if (config.useNativeClickEvent) {
|
|
17711
|
+
$el.removeEventListener('click', onClick, true);
|
|
17712
|
+
}
|
|
17713
|
+
$el.removeEventListener('wheel', onPointerWheel, true);
|
|
17714
|
+
});
|
|
17715
|
+
}
|
|
17716
|
+
}]);
|
|
17717
|
+
}();
|
|
17718
|
+
DOMInteractionPlugin.tag = 'DOMInteraction';
|
|
17719
|
+
|
|
17720
|
+
var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
17721
|
+
function Plugin() {
|
|
17722
|
+
var _this;
|
|
17723
|
+
_classCallCheck(this, Plugin);
|
|
17724
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
17725
|
+
args[_key] = arguments[_key];
|
|
17726
|
+
}
|
|
17727
|
+
_this = _callSuper(this, Plugin, [].concat(args));
|
|
17728
|
+
_this.name = 'dom-interaction';
|
|
17729
|
+
return _this;
|
|
17730
|
+
}
|
|
17731
|
+
_inherits(Plugin, _AbstractRendererPlug);
|
|
17732
|
+
return _createClass(Plugin, [{
|
|
17733
|
+
key: "init",
|
|
17734
|
+
value: function init() {
|
|
17735
|
+
this.addRenderingPlugin(new DOMInteractionPlugin());
|
|
17736
|
+
}
|
|
17737
|
+
}, {
|
|
17738
|
+
key: "destroy",
|
|
17739
|
+
value: function destroy() {
|
|
17740
|
+
this.removeAllRenderingPlugins();
|
|
17741
|
+
}
|
|
17742
|
+
}]);
|
|
17743
|
+
}(AbstractRendererPlugin);
|
|
17744
|
+
|
|
17745
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
17746
|
+
__proto__: null,
|
|
17747
|
+
Plugin: Plugin$1
|
|
17748
|
+
});
|
|
17749
|
+
|
|
17750
|
+
/**
|
|
17751
|
+
* listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
|
|
17752
|
+
*/
|
|
17753
|
+
var MobileInteractionPlugin = /*#__PURE__*/function () {
|
|
17754
|
+
function MobileInteractionPlugin() {
|
|
17755
|
+
_classCallCheck(this, MobileInteractionPlugin);
|
|
17756
|
+
}
|
|
17757
|
+
return _createClass(MobileInteractionPlugin, [{
|
|
17758
|
+
key: "apply",
|
|
17759
|
+
value: function apply(context) {
|
|
17760
|
+
var renderingService = context.renderingService,
|
|
17761
|
+
contextService = context.contextService,
|
|
17762
|
+
config = context.config;
|
|
17763
|
+
// 获取小程序上下文
|
|
17764
|
+
var canvasEl = contextService.getDomElement();
|
|
17765
|
+
var onPointerDown = function onPointerDown(ev) {
|
|
17766
|
+
renderingService.hooks.pointerDown.call(ev);
|
|
17767
|
+
};
|
|
17768
|
+
var onPointerUp = function onPointerUp(ev) {
|
|
17769
|
+
renderingService.hooks.pointerUp.call(ev);
|
|
17770
|
+
};
|
|
17771
|
+
var onPointerMove = function onPointerMove(ev) {
|
|
17772
|
+
// 触发 G 定义的标准 pointerMove 事件
|
|
17773
|
+
renderingService.hooks.pointerMove.call(ev);
|
|
17774
|
+
};
|
|
17775
|
+
var onPointerOver = function onPointerOver(ev) {
|
|
17776
|
+
renderingService.hooks.pointerOver.call(ev);
|
|
17777
|
+
};
|
|
17778
|
+
var onPointerOut = function onPointerOut(ev) {
|
|
17779
|
+
renderingService.hooks.pointerOut.call(ev);
|
|
17780
|
+
};
|
|
17781
|
+
var onClick = function onClick(ev) {
|
|
17782
|
+
renderingService.hooks.click.call(ev);
|
|
17783
|
+
};
|
|
17784
|
+
var onPointerCancel = function onPointerCancel(ev) {
|
|
17785
|
+
renderingService.hooks.pointerCancel.call(ev);
|
|
17786
|
+
};
|
|
17787
|
+
renderingService.hooks.init.tap(MobileInteractionPlugin.tag, function () {
|
|
17788
|
+
// 基于小程序上下文的事件监听方式,绑定事件监听,可以参考下面基于 DOM 的方式
|
|
17789
|
+
canvasEl.addEventListener('touchstart', onPointerDown, true);
|
|
17790
|
+
canvasEl.addEventListener('touchend', onPointerUp, true);
|
|
17791
|
+
canvasEl.addEventListener('touchmove', onPointerMove, true);
|
|
17792
|
+
canvasEl.addEventListener('touchcancel', onPointerCancel, true);
|
|
17793
|
+
// FIXME: 这里不应该只在 canvasEl 上监听 mousemove 和 mouseup,而应该在更高层级的节点上例如 document 监听。
|
|
17794
|
+
// 否则无法判断是否移出了 canvasEl
|
|
17795
|
+
// canvasEl.addEventListener('mousemove', onPointerMove, true);
|
|
17796
|
+
// canvasEl.addEventListener('mousedown', onPointerDown, true);
|
|
17797
|
+
canvasEl.addEventListener('mouseout', onPointerOut, true);
|
|
17798
|
+
canvasEl.addEventListener('mouseover', onPointerOver, true);
|
|
17799
|
+
// canvasEl.addEventListener('mouseup', onPointerUp, true);
|
|
17800
|
+
|
|
17801
|
+
if (config.useNativeClickEvent) {
|
|
17802
|
+
canvasEl.addEventListener('click', onClick, true);
|
|
17803
|
+
}
|
|
17804
|
+
});
|
|
17805
|
+
renderingService.hooks.destroy.tap(MobileInteractionPlugin.tag, function () {
|
|
17806
|
+
// 基于小程序上下文的事件监听方式,移除事件监听
|
|
17807
|
+
canvasEl.removeEventListener('touchstart', onPointerDown, true);
|
|
17808
|
+
canvasEl.removeEventListener('touchend', onPointerUp, true);
|
|
17809
|
+
canvasEl.removeEventListener('touchmove', onPointerMove, true);
|
|
17810
|
+
canvasEl.removeEventListener('touchcancel', onPointerCancel, true);
|
|
17811
|
+
|
|
17812
|
+
// canvasEl.removeEventListener('mousemove', onPointerMove, true);
|
|
17813
|
+
// canvasEl.removeEventListener('mousedown', onPointerDown, true);
|
|
17814
|
+
canvasEl.removeEventListener('mouseout', onPointerOut, true);
|
|
17815
|
+
canvasEl.removeEventListener('mouseover', onPointerOver, true);
|
|
17816
|
+
// canvasEl.removeEventListener('mouseup', onPointerUp, true);
|
|
17817
|
+
|
|
17818
|
+
if (config.useNativeClickEvent) {
|
|
17819
|
+
canvasEl.removeEventListener('click', onClick, true);
|
|
17820
|
+
}
|
|
17821
|
+
});
|
|
17822
|
+
}
|
|
17823
|
+
}]);
|
|
17824
|
+
}();
|
|
17825
|
+
MobileInteractionPlugin.tag = 'MobileInteraction';
|
|
17826
|
+
|
|
17827
|
+
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
17828
|
+
function Plugin() {
|
|
17829
|
+
var _this;
|
|
17830
|
+
_classCallCheck(this, Plugin);
|
|
17831
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
17832
|
+
args[_key] = arguments[_key];
|
|
17833
|
+
}
|
|
17834
|
+
_this = _callSuper(this, Plugin, [].concat(args));
|
|
17835
|
+
_this.name = 'mobile-interaction';
|
|
17836
|
+
return _this;
|
|
17837
|
+
}
|
|
17838
|
+
_inherits(Plugin, _AbstractRendererPlug);
|
|
17839
|
+
return _createClass(Plugin, [{
|
|
17840
|
+
key: "init",
|
|
17841
|
+
value: function init() {
|
|
17842
|
+
this.addRenderingPlugin(new MobileInteractionPlugin());
|
|
17843
|
+
}
|
|
17844
|
+
}, {
|
|
17845
|
+
key: "destroy",
|
|
17846
|
+
value: function destroy() {
|
|
17847
|
+
this.removeAllRenderingPlugins();
|
|
17848
|
+
}
|
|
17849
|
+
}]);
|
|
17850
|
+
}(AbstractRendererPlugin);
|
|
17851
|
+
|
|
17852
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
17853
|
+
__proto__: null,
|
|
17854
|
+
Plugin: Plugin
|
|
17855
|
+
});
|
|
17856
|
+
|
|
17857
|
+
export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, ClipSpaceNearZ, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, Document, index$1 as DomInteraction, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Fragment, Frustum, GradientType, Group, GroupUpdater, HTML, index$2 as HTMLRenderer, HTMLUpdater, Image, index$3 as ImageLoader, ImagePool, Line, LineUpdater, Mask, index as MobileInteraction, MutationEvent, MutationObserver, MutationRecord, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, Rect, RectUpdater, Rectangle, Registration, RenderReason, RenderingService, Shape, SortReason, Strategy, Text, TextService, TextUpdater, UnitType, attrModifiedEvent, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, destroyEvent, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, insertedEvent, isBrowser, isCSSGradientValue, isCSSRGB, isCanvas, isDisplayObject, isFederatedEvent, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, parseTransform, parsedTransformToMat4, propertyMetadataCache, rad2deg, removedEvent, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg, updateLocalTransform, updateWorldTransform };
|
|
16158
17858
|
//# sourceMappingURL=index.esm.js.map
|