babylonjs-addons 7.32.4 → 7.34.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,1384 @@
1
1
  (function webpackUniversalModuleDefinition(root, factory) {
2
2
  if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory();
3
+ module.exports = factory(require("babylonjs"));
4
4
  else if(typeof define === 'function' && define.amd)
5
- define("babylonjs-addons", [], factory);
5
+ define("babylonjs-addons", ["babylonjs"], factory);
6
6
  else if(typeof exports === 'object')
7
- exports["babylonjs-addons"] = factory();
7
+ exports["babylonjs-addons"] = factory(require("babylonjs"));
8
8
  else
9
- root["ADDONS"] = factory();
10
- })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), () => {
9
+ root["ADDONS"] = factory(root["BABYLON"]);
10
+ })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), (__WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math__) => {
11
11
  return /******/ (() => { // webpackBootstrap
12
12
  /******/ "use strict";
13
13
  /******/ var __webpack_modules__ = ({
14
14
 
15
+ /***/ "../../../dev/addons/src/htmlMesh/fitStrategy.ts":
16
+ /*!*******************************************************!*\
17
+ !*** ../../../dev/addons/src/htmlMesh/fitStrategy.ts ***!
18
+ \*******************************************************/
19
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
20
+
21
+ __webpack_require__.r(__webpack_exports__);
22
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
23
+ /* harmony export */ FitStrategy: () => (/* binding */ FitStrategy)
24
+ /* harmony export */ });
25
+ var FitStrategyContain = {
26
+ wrapElement: function (element) {
27
+ var sizingElement = document.createElement("div");
28
+ sizingElement.style.display = "flex";
29
+ sizingElement.style.justifyContent = "center";
30
+ sizingElement.style.alignItems = "center";
31
+ var scalingElement = document.createElement("div");
32
+ scalingElement.style.visibility = "hidden";
33
+ scalingElement.appendChild(element);
34
+ sizingElement.appendChild(scalingElement);
35
+ return sizingElement;
36
+ },
37
+ updateSize: function (sizingElement, width, height) {
38
+ var scalingElement = sizingElement.firstElementChild;
39
+ sizingElement.style.width = "".concat(width, "px");
40
+ sizingElement.style.height = "".concat(height, "px");
41
+ var _a = [scalingElement.offsetWidth, scalingElement.offsetHeight], childWidth = _a[0], childHeight = _a[1];
42
+ var scale = Math.min(width / childWidth, height / childHeight);
43
+ scalingElement.style.transform = "scale(".concat(scale, ")");
44
+ scalingElement.style.visibility = "visible";
45
+ },
46
+ };
47
+ var FitStrategyCover = {
48
+ wrapElement: function (element) {
49
+ var sizingElement = document.createElement("div");
50
+ sizingElement.style.display = "flex";
51
+ sizingElement.style.justifyContent = "center";
52
+ sizingElement.style.alignItems = "center";
53
+ sizingElement.style.overflow = "hidden";
54
+ var scalingElement = document.createElement("div");
55
+ scalingElement.style.visibility = "hidden";
56
+ scalingElement.appendChild(element);
57
+ sizingElement.appendChild(scalingElement);
58
+ return sizingElement;
59
+ },
60
+ updateSize: function (sizingElement, width, height) {
61
+ var scalingElement = sizingElement.firstElementChild;
62
+ sizingElement.style.width = "".concat(width, "px");
63
+ sizingElement.style.height = "".concat(height, "px");
64
+ var _a = [scalingElement.offsetWidth, scalingElement.offsetHeight], childWidth = _a[0], childHeight = _a[1];
65
+ var scale = Math.max(width / childWidth, height / childHeight);
66
+ scalingElement.style.transform = "scale(".concat(scale, ")");
67
+ scalingElement.style.visibility = "visible";
68
+ },
69
+ };
70
+ var FitStrategyStretch = {
71
+ wrapElement: function (element) {
72
+ var sizingElement = document.createElement("div");
73
+ sizingElement.style.display = "flex";
74
+ sizingElement.style.justifyContent = "center";
75
+ sizingElement.style.alignItems = "center";
76
+ var scalingElement = document.createElement("div");
77
+ scalingElement.style.visibility = "hidden";
78
+ scalingElement.appendChild(element);
79
+ sizingElement.appendChild(scalingElement);
80
+ return sizingElement;
81
+ },
82
+ updateSize: function (sizingElement, width, height) {
83
+ var scalingElement = sizingElement.firstElementChild;
84
+ sizingElement.style.width = "".concat(width, "px");
85
+ sizingElement.style.height = "".concat(height, "px");
86
+ var _a = [scalingElement.offsetWidth, scalingElement.offsetHeight], childWidth = _a[0], childHeight = _a[1];
87
+ scalingElement.style.transform = "scale(".concat(width / childWidth, ", ").concat(height / childHeight, ")");
88
+ scalingElement.style.visibility = "visible";
89
+ },
90
+ };
91
+ var FitStrategyNone = {
92
+ wrapElement: function (element) {
93
+ return element;
94
+ },
95
+ updateSize: function (sizingElement, width, height) {
96
+ if (sizingElement) {
97
+ sizingElement.style.width = "".concat(width, "px");
98
+ sizingElement.style.height = "".concat(height, "px");
99
+ }
100
+ },
101
+ };
102
+ var FitStrategy = {
103
+ CONTAIN: FitStrategyContain,
104
+ COVER: FitStrategyCover,
105
+ STRETCH: FitStrategyStretch,
106
+ NONE: FitStrategyNone,
107
+ };
108
+
109
+
110
+ /***/ }),
111
+
112
+ /***/ "../../../dev/addons/src/htmlMesh/htmlMesh.ts":
113
+ /*!****************************************************!*\
114
+ !*** ../../../dev/addons/src/htmlMesh/htmlMesh.ts ***!
115
+ \****************************************************/
116
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
117
+
118
+ __webpack_require__.r(__webpack_exports__);
119
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
120
+ /* harmony export */ HtmlMesh: () => (/* binding */ HtmlMesh)
121
+ /* harmony export */ });
122
+ /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! tslib */ "../../../../node_modules/tslib/tslib.es6.mjs");
123
+ /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/logger */ "babylonjs/Maths/math");
124
+ /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__);
125
+ /* harmony import */ var _pointerEventsCaptureBehavior__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./pointerEventsCaptureBehavior */ "../../../dev/addons/src/htmlMesh/pointerEventsCaptureBehavior.ts");
126
+ /* harmony import */ var _fitStrategy__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./fitStrategy */ "../../../dev/addons/src/htmlMesh/fitStrategy.ts");
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+ /**
136
+ * This class represents HTML content that we want to render as though it is part of the scene. The HTML content is actually
137
+ * rendered below the canvas, but a depth mask is created by this class that writes to the depth buffer but does not
138
+ * write to the color buffer, effectively punching a hole in the canvas. CSS transforms are used to scale, translate, and rotate
139
+ * the HTML content so that it matches the camera and mesh orientation. The class supports interactions in editable and non-editable mode.
140
+ * In non-editable mode (the default), events are passed to the HTML content when the pointer is over the mask (and not occluded by other meshes
141
+ * in the scene).
142
+ * #HVHYJC#5
143
+ * #B17TC7#112
144
+ */
145
+ var HtmlMesh = /** @class */ (function (_super) {
146
+ (0,tslib__WEBPACK_IMPORTED_MODULE_3__.__extends)(HtmlMesh, _super);
147
+ /**
148
+ * Contruct an instance of HtmlMesh
149
+ * @param scene
150
+ * @param id The id of the mesh. Will be used as the id of the HTML element as well.
151
+ * @param options object with optional parameters
152
+ */
153
+ function HtmlMesh(scene, id, _a) {
154
+ var _b = _a === void 0 ? {} : _a, _c = _b.captureOnPointerEnter, captureOnPointerEnter = _c === void 0 ? true : _c, _d = _b.isCanvasOverlay, isCanvasOverlay = _d === void 0 ? false : _d, _e = _b.fitStrategy, fitStrategy = _e === void 0 ? _fitStrategy__WEBPACK_IMPORTED_MODULE_2__.FitStrategy.NONE : _e;
155
+ var _this = _super.call(this, id, scene) || this;
156
+ // Override the super class's _isEnabled property so we can control when the mesh
157
+ // is enabled. I.e., we don't want to render the mesh until there is content to show.
158
+ _this._enabled = false;
159
+ // The mesh is ready when content has been set and the content size has been set
160
+ // The former is done by the user, the latter is done by the renderer.
161
+ _this._ready = false;
162
+ /**
163
+ * @internal
164
+ */
165
+ _this._isCanvasOverlay = false;
166
+ _this._requiresUpdate = true;
167
+ _this._inverseScaleMatrix = null;
168
+ _this._captureOnPointerEnter = true;
169
+ _this._pointerEventCaptureBehavior = null;
170
+ _this._sourceWidth = null;
171
+ _this._sourceHeight = null;
172
+ _this._fitStrategy = _fitStrategy__WEBPACK_IMPORTED_MODULE_2__.FitStrategy.NONE;
173
+ // Requires a browser to work. Bail if we aren't running in a browser
174
+ if (typeof document === "undefined") {
175
+ babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__.Logger.Warn("Creating an instance of an HtmlMesh with id ".concat(id, " outside of a browser. The mesh will not be visible."));
176
+ return _this;
177
+ }
178
+ _this._fitStrategy = fitStrategy;
179
+ _this._isCanvasOverlay = isCanvasOverlay;
180
+ _this._createMask();
181
+ _this._element = _this._createElement();
182
+ // Set enabled by default, so this will show as soon as it's ready
183
+ _this.setEnabled(true);
184
+ _this._captureOnPointerEnter = captureOnPointerEnter;
185
+ // Create a behavior to capture pointer events
186
+ _this._pointerEventCaptureBehavior = new _pointerEventsCaptureBehavior__WEBPACK_IMPORTED_MODULE_1__.PointerEventsCaptureBehavior(_this.capturePointerEvents.bind(_this), _this.releasePointerEvents.bind(_this), {
187
+ captureOnPointerEnter: _this._captureOnPointerEnter,
188
+ });
189
+ _this.addBehavior(_this._pointerEventCaptureBehavior);
190
+ return _this;
191
+ }
192
+ Object.defineProperty(HtmlMesh.prototype, "isHtmlMesh", {
193
+ /**
194
+ * Helps identifying a html mesh from a regular mesh
195
+ */
196
+ get: function () {
197
+ return true;
198
+ },
199
+ enumerable: false,
200
+ configurable: true
201
+ });
202
+ Object.defineProperty(HtmlMesh.prototype, "sourceWidth", {
203
+ /**
204
+ * Return the source width of the content in pixels
205
+ */
206
+ get: function () {
207
+ return this._sourceWidth;
208
+ },
209
+ enumerable: false,
210
+ configurable: true
211
+ });
212
+ Object.defineProperty(HtmlMesh.prototype, "sourceHeight", {
213
+ /**
214
+ * Return the source height of the content in pixels
215
+ */
216
+ get: function () {
217
+ return this._sourceHeight;
218
+ },
219
+ enumerable: false,
220
+ configurable: true
221
+ });
222
+ Object.defineProperty(HtmlMesh.prototype, "width", {
223
+ /**
224
+ * The width of the content in pixels
225
+ */
226
+ get: function () {
227
+ return this._width;
228
+ },
229
+ enumerable: false,
230
+ configurable: true
231
+ });
232
+ Object.defineProperty(HtmlMesh.prototype, "height", {
233
+ /**
234
+ * The height of the content in pixels
235
+ */
236
+ get: function () {
237
+ return this._height;
238
+ },
239
+ enumerable: false,
240
+ configurable: true
241
+ });
242
+ Object.defineProperty(HtmlMesh.prototype, "element", {
243
+ /**
244
+ * The HTML element that is being rendered as a mesh
245
+ */
246
+ get: function () {
247
+ return this._element;
248
+ },
249
+ enumerable: false,
250
+ configurable: true
251
+ });
252
+ Object.defineProperty(HtmlMesh.prototype, "requiresUpdate", {
253
+ /**
254
+ * True if the mesh has been moved, rotated, or scaled since the last time this
255
+ * property was read. This property is reset to false after reading.
256
+ */
257
+ get: function () {
258
+ return this._requiresUpdate;
259
+ },
260
+ enumerable: false,
261
+ configurable: true
262
+ });
263
+ Object.defineProperty(HtmlMesh.prototype, "captureOnPointerEnter", {
264
+ /**
265
+ * Enable capture for the pointer when entering the mesh area
266
+ */
267
+ set: function (captureOnPointerEnter) {
268
+ this._captureOnPointerEnter = captureOnPointerEnter;
269
+ if (this._pointerEventCaptureBehavior) {
270
+ this._pointerEventCaptureBehavior.captureOnPointerEnter = captureOnPointerEnter;
271
+ }
272
+ },
273
+ enumerable: false,
274
+ configurable: true
275
+ });
276
+ /**
277
+ * Disposes of the mesh and the HTML element
278
+ */
279
+ HtmlMesh.prototype.dispose = function () {
280
+ var _a;
281
+ _super.prototype.dispose.call(this);
282
+ (_a = this._element) === null || _a === void 0 ? void 0 : _a.remove();
283
+ this._element = undefined;
284
+ if (this._pointerEventCaptureBehavior) {
285
+ this._pointerEventCaptureBehavior.dispose();
286
+ this._pointerEventCaptureBehavior = null;
287
+ }
288
+ };
289
+ /**
290
+ * @internal
291
+ */
292
+ HtmlMesh.prototype._markAsUpdated = function () {
293
+ this._requiresUpdate = false;
294
+ };
295
+ /**
296
+ * Sets the content of the element to the specified content adjusting the mesh scale to match and making it visible.
297
+ * If the the specified content is undefined, then it will make the mesh invisible. In either case it will clear the
298
+ * element content first.
299
+ * @param element The element to render as a mesh
300
+ * @param width The width of the mesh in Babylon units
301
+ * @param height The height of the mesh in Babylon units
302
+ */
303
+ HtmlMesh.prototype.setContent = function (element, width, height) {
304
+ // If content is changed, we are no longer ready
305
+ this._setAsReady(false);
306
+ // Also invalidate the source width and height
307
+ this._sourceWidth = null;
308
+ this._sourceHeight = null;
309
+ if (!this._element) {
310
+ return;
311
+ }
312
+ this._width = width;
313
+ this._height = height;
314
+ this._requiresUpdate = true;
315
+ this.scaling.setAll(1);
316
+ if (element) {
317
+ this._element.appendChild(this._fitStrategy.wrapElement(element));
318
+ this._updateScaleIfNecessary();
319
+ }
320
+ if (this.sourceWidth && this.sourceHeight) {
321
+ this._setAsReady(true);
322
+ }
323
+ };
324
+ // Overides BABYLON.Mesh.setEnabled
325
+ HtmlMesh.prototype.setEnabled = function (enabled) {
326
+ // Capture requested enabled state
327
+ this._enabled = enabled;
328
+ // If disabling or enabling and we are ready
329
+ if (!enabled || this._ready) {
330
+ this._doSetEnabled(enabled);
331
+ }
332
+ };
333
+ /**
334
+ * Sets the content size in pixels
335
+ * @param width width of the source
336
+ * @param height height of the source
337
+ */
338
+ HtmlMesh.prototype.setContentSizePx = function (width, height) {
339
+ this._sourceWidth = width;
340
+ this._sourceHeight = height;
341
+ if (!this._element || !this._element.firstElementChild) {
342
+ return;
343
+ }
344
+ this._fitStrategy.updateSize(this._element.firstElementChild, width, height);
345
+ this._updateScaleIfNecessary();
346
+ if (this.width && this.height) {
347
+ this._setAsReady(true);
348
+ }
349
+ };
350
+ HtmlMesh.prototype._setAsReady = function (ready) {
351
+ this._ready = ready;
352
+ if (ready) {
353
+ this._doSetEnabled(this._enabled);
354
+ }
355
+ else {
356
+ this._doSetEnabled(false);
357
+ }
358
+ };
359
+ HtmlMesh.prototype._doSetEnabled = function (enabled) {
360
+ var _this = this;
361
+ var _a;
362
+ if (!this._element) {
363
+ return;
364
+ }
365
+ //if enabled, then start listening for changes to the
366
+ // scaling, rotation, and position. otherwise stop listening
367
+ if (enabled && !this._worldMatrixUpdateObserver) {
368
+ this._worldMatrixUpdateObserver = this.onAfterWorldMatrixUpdateObservable.add(function () {
369
+ _this._requiresUpdate = true;
370
+ });
371
+ }
372
+ else if (!enabled) {
373
+ (_a = this._worldMatrixUpdateObserver) === null || _a === void 0 ? void 0 : _a.remove();
374
+ this._worldMatrixUpdateObserver = null;
375
+ }
376
+ // If enabled, then revert the content element display
377
+ // otherwise hide it
378
+ this._element.style.display = enabled ? "" : "none";
379
+ // Capture the content z index
380
+ this._setElementZIndex(this.position.z * -10000);
381
+ _super.prototype.setEnabled.call(this, enabled);
382
+ };
383
+ HtmlMesh.prototype._updateScaleIfNecessary = function () {
384
+ // If we have setContent before, the content scale is baked into the mesh. If we don't reset the vertices to
385
+ // the original size, then we will multiply the scale when we bake the scale below. By applying the inverse, we back out
386
+ // the scaling that has been done so we are starting from the same point.
387
+ // First reset the scale to 1
388
+ this.scaling.setAll(1);
389
+ // Then back out the original vertices changes to match the content scale
390
+ if (this._inverseScaleMatrix) {
391
+ this.bakeTransformIntoVertices(this._inverseScaleMatrix);
392
+ // Clear out the matrix so it doesn't get applied again unless we scale
393
+ this._inverseScaleMatrix = null;
394
+ }
395
+ // Set scale to match content. Note we can't just scale the mesh, because that will scale the content as well
396
+ // What we need to do is compute a scale matrix and then bake that into the mesh vertices. This will leave the
397
+ // mesh scale at 1, so our content will stay it's original width and height until we scale the mesh.
398
+ var scaleX = this._width || 1;
399
+ var scaleY = this._height || 1;
400
+ var scaleMatrix = babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__.Matrix.Scaling(scaleX, scaleY, 1);
401
+ this.bakeTransformIntoVertices(scaleMatrix);
402
+ // Get an inverse of the scale matrix that we can use to back out the scale changes we have made so
403
+ // we don't multiply the scale.
404
+ this._inverseScaleMatrix = new babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__.Matrix();
405
+ scaleMatrix.invertToRef(this._inverseScaleMatrix);
406
+ };
407
+ HtmlMesh.prototype._createMask = function () {
408
+ var vertexData = (0,babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__.CreatePlaneVertexData)({ width: 1, height: 1 });
409
+ vertexData.applyToMesh(this);
410
+ var scene = this.getScene();
411
+ this.checkCollisions = true;
412
+ var depthMask = new babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__.StandardMaterial("".concat(this.id, "-mat"), scene);
413
+ if (!this._isCanvasOverlay) {
414
+ depthMask.backFaceCulling = false;
415
+ depthMask.disableColorWrite = true;
416
+ depthMask.disableLighting = true;
417
+ }
418
+ this.material = depthMask;
419
+ // Optimization - Freeze material since it never needs to change
420
+ this.material.freeze();
421
+ };
422
+ HtmlMesh.prototype._setElementZIndex = function (zIndex) {
423
+ if (this._element) {
424
+ this._element.style.zIndex = "".concat(zIndex);
425
+ }
426
+ };
427
+ /**
428
+ * Callback used by the PointerEventsCaptureBehavior to capture pointer events
429
+ */
430
+ HtmlMesh.prototype.capturePointerEvents = function () {
431
+ if (!this._element) {
432
+ return;
433
+ }
434
+ // Enable dom content to capture pointer events
435
+ this._element.style.pointerEvents = "auto";
436
+ // Supress events outside of the dom content
437
+ document.getElementsByTagName("body")[0].style.pointerEvents = "none";
438
+ };
439
+ /**
440
+ * Callback used by the PointerEventsCaptureBehavior to release pointer events
441
+ */
442
+ HtmlMesh.prototype.releasePointerEvents = function () {
443
+ if (!this._element) {
444
+ return;
445
+ }
446
+ // Enable pointer events on canvas
447
+ document.getElementsByTagName("body")[0].style.pointerEvents = "auto";
448
+ // Disable pointer events on dom content
449
+ this._element.style.pointerEvents = "none";
450
+ };
451
+ HtmlMesh.prototype._createElement = function () {
452
+ // Requires a browser to work. Bail if we aren't running in a browser
453
+ if (typeof document === "undefined") {
454
+ return;
455
+ }
456
+ var div = document.createElement("div");
457
+ div.id = this.id;
458
+ div.style.backgroundColor = this._isCanvasOverlay ? "transparent" : "#000";
459
+ div.style.zIndex = "1";
460
+ div.style.position = "absolute";
461
+ div.style.pointerEvents = "none";
462
+ div.style.backfaceVisibility = "hidden";
463
+ return div;
464
+ };
465
+ return HtmlMesh;
466
+ }(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_0__.Mesh));
467
+
468
+
469
+
470
+ /***/ }),
471
+
472
+ /***/ "../../../dev/addons/src/htmlMesh/htmlMeshRenderer.ts":
473
+ /*!************************************************************!*\
474
+ !*** ../../../dev/addons/src/htmlMesh/htmlMeshRenderer.ts ***!
475
+ \************************************************************/
476
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
477
+
478
+ __webpack_require__.r(__webpack_exports__);
479
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
480
+ /* harmony export */ HtmlMeshRenderer: () => (/* binding */ HtmlMeshRenderer)
481
+ /* harmony export */ });
482
+ /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/logger */ "babylonjs/Maths/math");
483
+ /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
484
+
485
+
486
+
487
+
488
+ var _positionUpdateFailMessage = "Failed to update html mesh renderer position due to failure to get canvas rect. HtmlMesh instances may not render correctly";
489
+ var babylonUnitsToPixels = 100;
490
+ // Returns a function that ensures that HtmlMeshes are rendered before all other meshes.
491
+ // Note this will only be applied to group 0.
492
+ // If neither mesh is an HtmlMesh, then the default render order is used
493
+ // This prevents HtmlMeshes from appearing in front of other meshes when they are behind them
494
+ var renderOrderFunc = function (defaultRenderOrder) {
495
+ return function (subMeshA, subMeshB) {
496
+ var meshA = subMeshA.getMesh();
497
+ var meshB = subMeshB.getMesh();
498
+ // Use property check instead of instanceof since it is less expensive and
499
+ // this will be called many times per frame
500
+ var meshAIsHtmlMesh = meshA["isHtmlMesh"];
501
+ var meshBIsHtmlMesh = meshB["isHtmlMesh"];
502
+ if (meshAIsHtmlMesh) {
503
+ return meshBIsHtmlMesh ? (meshA.absolutePosition.z <= meshB.absolutePosition.z ? 1 : -1) : -1;
504
+ }
505
+ else {
506
+ return meshBIsHtmlMesh ? 1 : defaultRenderOrder(subMeshA, subMeshB);
507
+ }
508
+ };
509
+ };
510
+ /**
511
+ * An instance of this is required to render HtmlMeshes in the scene.
512
+ * if using HtmlMeshes, you must not set render order for group 0 using
513
+ * scene.setRenderingOrder. You must instead pass the compare functions
514
+ * to the HtmlMeshRenderer constructor. If you do not, then your render
515
+ * order will be overwritten if the HtmlMeshRenderer is created after and
516
+ * the HtmlMeshes will not render correctly (they will appear in front of
517
+ * meshes that are actually in front of them) if the HtmlMeshRenderer is
518
+ * created before.
519
+ */
520
+ var HtmlMeshRenderer = /** @class */ (function () {
521
+ /**
522
+ * Contruct an instance of HtmlMeshRenderer
523
+ * @param scene
524
+ * @param options object containing the following optional properties:
525
+ * @returns
526
+ */
527
+ function HtmlMeshRenderer(scene, _a) {
528
+ var _b = _a === void 0 ? {} : _a, _c = _b.parentContainerId, parentContainerId = _c === void 0 ? null : _c, _d = _b._containerId, _containerId = _d === void 0 ? "css-container" : _d, _e = _b.enableOverlayRender, enableOverlayRender = _e === void 0 ? true : _e, _f = _b.defaultOpaqueRenderOrder, defaultOpaqueRenderOrder = _f === void 0 ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.RenderingGroup.PainterSortCompare : _f, _g = _b.defaultAlphaTestRenderOrder, defaultAlphaTestRenderOrder = _g === void 0 ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.RenderingGroup.PainterSortCompare : _g, _h = _b.defaultTransparentRenderOrder, defaultTransparentRenderOrder = _h === void 0 ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.RenderingGroup.defaultTransparentSortCompare : _h;
529
+ var _this = this;
530
+ this._cache = {
531
+ cameraData: { fov: 0, position: new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Vector3(), style: "" },
532
+ htmlMeshData: new WeakMap(),
533
+ };
534
+ this._width = 0;
535
+ this._height = 0;
536
+ this._heightHalf = 0;
537
+ // Create some refs to avoid creating new objects every frame
538
+ this._temp = {
539
+ scaleTransform: new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Vector3(),
540
+ rotationTransform: new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Quaternion(),
541
+ positionTransform: new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Vector3(),
542
+ objectMatrix: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Matrix.Identity(),
543
+ cameraWorldMatrix: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Matrix.Identity(),
544
+ cameraRotationMatrix: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Matrix.Identity(),
545
+ cameraWorldMatrixAsArray: new Array(16),
546
+ };
547
+ // Keep track of DPR so we can resize if DPR changes
548
+ // Otherwise the DOM content will scale, but the mesh won't
549
+ this._lastDevicePixelRatio = window.devicePixelRatio;
550
+ // Keep track of camera matrix changes so we only update the
551
+ // DOM element styles when necessary
552
+ this._cameraMatrixUpdated = true;
553
+ // Keep track of position changes so we only update the DOM element
554
+ // styles when necessary
555
+ this._previousCanvasDocumentPosition = {
556
+ top: 0,
557
+ left: 0,
558
+ };
559
+ this._renderObserver = null;
560
+ this._onCameraMatrixChanged = function (camera) {
561
+ _this._cameraWorldMatrix = camera.getWorldMatrix();
562
+ _this._cameraMatrixUpdated = true;
563
+ };
564
+ // Requires a browser to work. Only init if we are in a browser
565
+ if (typeof document === "undefined") {
566
+ return;
567
+ }
568
+ this._containerId = _containerId;
569
+ this._init(scene, parentContainerId, enableOverlayRender, defaultOpaqueRenderOrder, defaultAlphaTestRenderOrder, defaultTransparentRenderOrder);
570
+ }
571
+ /**
572
+ * Dispose of the HtmlMeshRenderer
573
+ */
574
+ HtmlMeshRenderer.prototype.dispose = function () {
575
+ var _a, _b;
576
+ if (this._renderObserver) {
577
+ this._renderObserver.remove();
578
+ this._renderObserver = null;
579
+ }
580
+ (_a = this._overlayElements) === null || _a === void 0 ? void 0 : _a.container.remove();
581
+ this._overlayElements = null;
582
+ (_b = this._inSceneElements) === null || _b === void 0 ? void 0 : _b.container.remove();
583
+ this._inSceneElements = null;
584
+ };
585
+ HtmlMeshRenderer.prototype._init = function (scene, parentContainerId, enableOverlayRender, defaultOpaqueRenderOrder, defaultAlphaTestRenderOrder, defaultTransparentRenderOrder) {
586
+ var _this = this;
587
+ var _a;
588
+ // Requires a browser to work. Only init if we are in a browser
589
+ if (typeof document === "undefined") {
590
+ return;
591
+ }
592
+ // Create the DOM containers
593
+ var parentContainer = parentContainerId ? document.getElementById(parentContainerId) : document.body;
594
+ if (!parentContainer) {
595
+ parentContainer = document.body;
596
+ }
597
+ // if the container already exists, then remove it
598
+ var inSceneContainerId = "".concat(this._containerId, "_in_scene");
599
+ this._inSceneElements = this._createRenderLayerElements(inSceneContainerId);
600
+ parentContainer.insertBefore(this._inSceneElements.container, parentContainer.firstChild);
601
+ if (enableOverlayRender) {
602
+ var overlayContainerId = "".concat(this._containerId, "_overlay");
603
+ this._overlayElements = this._createRenderLayerElements(overlayContainerId);
604
+ var zIndex = +((_a = scene.getEngine().getRenderingCanvas().style.zIndex) !== null && _a !== void 0 ? _a : "0") + 1;
605
+ this._overlayElements.container.style.zIndex = "".concat(zIndex);
606
+ this._overlayElements.container.style.pointerEvents = "none";
607
+ parentContainer.insertBefore(this._overlayElements.container, parentContainer.firstChild);
608
+ }
609
+ this._engine = scene.getEngine();
610
+ var clientRect = this._engine.getRenderingCanvasClientRect();
611
+ if (!clientRect) {
612
+ throw new Error("Failed to get client rect for rendering canvas");
613
+ }
614
+ // Set the size and resize behavior
615
+ this._setSize(clientRect.width, clientRect.height);
616
+ this._engine.onResizeObservable.add(function () {
617
+ var clientRect = _this._engine.getRenderingCanvasClientRect();
618
+ if (clientRect) {
619
+ _this._setSize(clientRect.width, clientRect.height);
620
+ }
621
+ });
622
+ var projectionObs;
623
+ var matrixObs;
624
+ var observeCamera = function () {
625
+ var camera = scene.activeCamera;
626
+ if (camera) {
627
+ projectionObs = camera.onProjectionMatrixChangedObservable.add(function () {
628
+ _this._onCameraMatrixChanged(camera);
629
+ });
630
+ matrixObs = camera.onViewMatrixChangedObservable.add(function () {
631
+ _this._onCameraMatrixChanged(camera);
632
+ });
633
+ }
634
+ };
635
+ observeCamera();
636
+ scene.onActiveCameraChanged.add(function () {
637
+ var _a, _b;
638
+ if (projectionObs) {
639
+ (_a = scene.activeCamera) === null || _a === void 0 ? void 0 : _a.onProjectionMatrixChangedObservable.remove(projectionObs);
640
+ }
641
+ if (matrixObs) {
642
+ (_b = scene.activeCamera) === null || _b === void 0 ? void 0 : _b.onViewMatrixChangedObservable.remove(matrixObs);
643
+ }
644
+ observeCamera();
645
+ });
646
+ // We need to make sure that HtmlMeshes are rendered before all other meshes
647
+ // so that they don't appear in front of meshes that are actually in front of them
648
+ // Updating the render order isn't ideal, but it is the only way to acheive this
649
+ // The implication is that an app using the HtmlMeshRendered must set the scene render order
650
+ // via the HtmlMeshRendered constructor
651
+ var opaqueRenderOrder = renderOrderFunc(defaultOpaqueRenderOrder);
652
+ var alphaTestRenderOrder = renderOrderFunc(defaultAlphaTestRenderOrder);
653
+ var transparentRenderOrder = renderOrderFunc(defaultTransparentRenderOrder);
654
+ scene.setRenderingOrder(0, opaqueRenderOrder, alphaTestRenderOrder, transparentRenderOrder);
655
+ this._renderObserver = scene.onBeforeRenderObservable.add(function () {
656
+ _this._render(scene, scene.activeCamera);
657
+ });
658
+ };
659
+ HtmlMeshRenderer.prototype._createRenderLayerElements = function (containerId) {
660
+ var existingContainer = document.getElementById(containerId);
661
+ if (existingContainer) {
662
+ existingContainer.remove();
663
+ }
664
+ var container = document.createElement("div");
665
+ container.id = containerId;
666
+ container.style.position = "absolute";
667
+ container.style.width = "100%";
668
+ container.style.height = "100%";
669
+ container.style.zIndex = "-1";
670
+ var domElement = document.createElement("div");
671
+ domElement.style.overflow = "hidden";
672
+ var cameraElement = document.createElement("div");
673
+ cameraElement.style.webkitTransformStyle = "preserve-3d";
674
+ cameraElement.style.transformStyle = "preserve-3d";
675
+ cameraElement.style.pointerEvents = "none";
676
+ domElement.appendChild(cameraElement);
677
+ container.appendChild(domElement);
678
+ return {
679
+ container: container,
680
+ domElement: domElement,
681
+ cameraElement: cameraElement,
682
+ };
683
+ };
684
+ HtmlMeshRenderer.prototype._getSize = function () {
685
+ return {
686
+ width: this._width,
687
+ height: this._height,
688
+ };
689
+ };
690
+ HtmlMeshRenderer.prototype._setSize = function (width, height) {
691
+ this._width = width;
692
+ this._height = height;
693
+ this._heightHalf = this._height / 2;
694
+ if (!this._inSceneElements || !this._overlayElements) {
695
+ return;
696
+ }
697
+ var domElements = [this._inSceneElements.domElement, this._overlayElements.domElement, this._inSceneElements.cameraElement, this._overlayElements.cameraElement];
698
+ domElements.forEach(function (dom) {
699
+ if (dom) {
700
+ dom.style.width = "".concat(width, "px");
701
+ dom.style.height = "".concat(height, "px");
702
+ }
703
+ });
704
+ };
705
+ // prettier-ignore
706
+ HtmlMeshRenderer.prototype._getCameraCSSMatrix = function (matrix) {
707
+ var elements = matrix.m;
708
+ return "matrix3d(".concat(this._epsilon(elements[0]), ",").concat(this._epsilon(-elements[1]), ",").concat(this._epsilon(elements[2]), ",").concat(this._epsilon(elements[3]), ",").concat(this._epsilon(elements[4]), ",").concat(this._epsilon(-elements[5]), ",").concat(this._epsilon(elements[6]), ",").concat(this._epsilon(elements[7]), ",").concat(this._epsilon(elements[8]), ",").concat(this._epsilon(-elements[9]), ",").concat(this._epsilon(elements[10]), ",").concat(this._epsilon(elements[11]), ",").concat(this._epsilon(elements[12]), ",").concat(this._epsilon(-elements[13]), ",").concat(this._epsilon(elements[14]), ",").concat(this._epsilon(elements[15]), ")");
709
+ };
710
+ // Convert a Babylon world matrix to a CSS matrix
711
+ // This also handles conversion from BJS left handed coords
712
+ // to CSS right handed coords
713
+ // prettier-ignore
714
+ HtmlMeshRenderer.prototype._getHtmlContentCSSMatrix = function (matrix, useRightHandedSystem) {
715
+ var elements = matrix.m;
716
+ // In a right handed coordinate system, the elements 11 to 14 have to change their direction
717
+ var direction = useRightHandedSystem ? -1 : 1;
718
+ var matrix3d = "matrix3d(".concat(this._epsilon(elements[0]), ",").concat(this._epsilon(elements[1]), ",").concat(this._epsilon(elements[2] * -direction), ",").concat(this._epsilon(elements[3]), ",").concat(this._epsilon(-elements[4]), ",").concat(this._epsilon(-elements[5]), ",").concat(this._epsilon(elements[6] * direction), ",").concat(this._epsilon(-elements[7]), ",").concat(this._epsilon(elements[8] * -direction), ",").concat(this._epsilon(elements[9] * -direction), ",").concat(this._epsilon(elements[10]), ",").concat(this._epsilon(elements[11] * direction), ",").concat(this._epsilon(elements[12] * direction), ",").concat(this._epsilon(elements[13] * direction), ",").concat(this._epsilon(elements[14] * direction), ",").concat(this._epsilon(elements[15]), ")");
719
+ return matrix3d;
720
+ };
721
+ HtmlMeshRenderer.prototype._getTransformationMatrix = function (htmlMesh, useRightHandedSystem) {
722
+ var _a;
723
+ // Get the camera world matrix
724
+ // Make sure the camera world matrix is up to date
725
+ if (!this._cameraWorldMatrix) {
726
+ this._cameraWorldMatrix = (_a = htmlMesh.getScene().activeCamera) === null || _a === void 0 ? void 0 : _a.getWorldMatrix();
727
+ }
728
+ if (!this._cameraWorldMatrix) {
729
+ return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Matrix.Identity();
730
+ }
731
+ var objectWorldMatrix = htmlMesh.getWorldMatrix();
732
+ // Scale the object matrix by the base scale factor for the mesh
733
+ // which is the ratio of the mesh width/height to the renderer
734
+ // width/height divided by the babylon units to pixels ratio
735
+ var widthScaleFactor = 1;
736
+ var heightScaleFactor = 1;
737
+ if (htmlMesh.sourceWidth && htmlMesh.sourceHeight) {
738
+ widthScaleFactor = htmlMesh.width / (htmlMesh.sourceWidth / babylonUnitsToPixels);
739
+ heightScaleFactor = htmlMesh.height / (htmlMesh.sourceHeight / babylonUnitsToPixels);
740
+ }
741
+ // Apply the scale to the object's world matrix. Note we aren't scaling
742
+ // the object, just getting a matrix as though it were scaled, so we can
743
+ // scale the content
744
+ var scaleTransform = this._temp.scaleTransform;
745
+ var rotationTransform = this._temp.rotationTransform;
746
+ var positionTransform = this._temp.positionTransform;
747
+ var scaledAndTranslatedObjectMatrix = this._temp.objectMatrix;
748
+ objectWorldMatrix.decompose(scaleTransform, rotationTransform, positionTransform);
749
+ scaleTransform.x *= widthScaleFactor;
750
+ scaleTransform.y *= heightScaleFactor;
751
+ babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Matrix.ComposeToRef(scaleTransform, rotationTransform, positionTransform, scaledAndTranslatedObjectMatrix);
752
+ // Adjust direction of 12 and 13 of the transformation matrix based on the handedness of the system
753
+ var direction = useRightHandedSystem ? -1 : 1;
754
+ // Adjust translation values to be from camera vs world origin
755
+ // Note that we are also adjusting these values to be pixels vs Babylon units
756
+ var position = htmlMesh.getAbsolutePosition();
757
+ scaledAndTranslatedObjectMatrix.setRowFromFloats(3, (-this._cameraWorldMatrix.m[12] + position.x) * babylonUnitsToPixels * direction, (-this._cameraWorldMatrix.m[13] + position.y) * babylonUnitsToPixels * direction, (this._cameraWorldMatrix.m[14] - position.z) * babylonUnitsToPixels, this._cameraWorldMatrix.m[15] * 0.00001 * babylonUnitsToPixels);
758
+ // Adjust other values to be pixels vs Babylon units
759
+ scaledAndTranslatedObjectMatrix.multiplyAtIndex(3, babylonUnitsToPixels);
760
+ scaledAndTranslatedObjectMatrix.multiplyAtIndex(7, babylonUnitsToPixels);
761
+ scaledAndTranslatedObjectMatrix.multiplyAtIndex(11, babylonUnitsToPixels);
762
+ return scaledAndTranslatedObjectMatrix;
763
+ };
764
+ HtmlMeshRenderer.prototype._renderHtmlMesh = function (htmlMesh, useRightHandedSystem) {
765
+ var _a, _b;
766
+ if (!htmlMesh.element || !htmlMesh.element.firstElementChild) {
767
+ // nothing to render, so bail
768
+ return;
769
+ }
770
+ // We need to ensure html mesh data is initialized before
771
+ // computing the base scale factor
772
+ var htmlMeshData = this._cache.htmlMeshData.get(htmlMesh);
773
+ if (!htmlMeshData) {
774
+ htmlMeshData = { style: "" };
775
+ this._cache.htmlMeshData.set(htmlMesh, htmlMeshData);
776
+ }
777
+ var cameraElement = htmlMesh._isCanvasOverlay ? (_a = this._overlayElements) === null || _a === void 0 ? void 0 : _a.cameraElement : (_b = this._inSceneElements) === null || _b === void 0 ? void 0 : _b.cameraElement;
778
+ if (htmlMesh.element.parentNode !== cameraElement) {
779
+ cameraElement.appendChild(htmlMesh.element);
780
+ }
781
+ // If the htmlMesh content has changed, update the base scale factor
782
+ if (htmlMesh.requiresUpdate) {
783
+ this._updateBaseScaleFactor(htmlMesh);
784
+ }
785
+ // Get the transformation matrix for the html mesh
786
+ var scaledAndTranslatedObjectMatrix = this._getTransformationMatrix(htmlMesh, useRightHandedSystem);
787
+ var style = "translate(-50%, -50%) ".concat(this._getHtmlContentCSSMatrix(scaledAndTranslatedObjectMatrix, useRightHandedSystem));
788
+ // In a right handed system, screens are on the wrong side of the mesh, so we have to rotate by Math.PI which results in the matrix3d seen below
789
+ style += "".concat(useRightHandedSystem ? "matrix3d(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1)" : "");
790
+ if (htmlMeshData.style !== style) {
791
+ htmlMesh.element.style.webkitTransform = style;
792
+ htmlMesh.element.style.transform = style;
793
+ }
794
+ htmlMesh._markAsUpdated();
795
+ };
796
+ HtmlMeshRenderer.prototype._render = function (scene, camera) {
797
+ var _this = this;
798
+ var _a, _b, _c, _d, _e, _f;
799
+ var needsUpdate = false;
800
+ var useRightHandedSystem = scene.useRightHandedSystem;
801
+ // Update the container position and size if necessary
802
+ this._updateContainerPositionIfNeeded();
803
+ // Check for a camera change
804
+ if (this._cameraMatrixUpdated) {
805
+ this._cameraMatrixUpdated = false;
806
+ needsUpdate = true;
807
+ }
808
+ // If the camera position has changed, then we also need to update
809
+ if (camera.position.x !== this._cache.cameraData.position.x ||
810
+ camera.position.y !== this._cache.cameraData.position.y ||
811
+ camera.position.z !== this._cache.cameraData.position.z) {
812
+ this._cache.cameraData.position.copyFrom(camera.position);
813
+ needsUpdate = true;
814
+ }
815
+ // Check for a dpr change
816
+ if (window.devicePixelRatio !== this._lastDevicePixelRatio) {
817
+ this._lastDevicePixelRatio = window.devicePixelRatio;
818
+ babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Logger.Log("In render - dpr changed: ", this._lastDevicePixelRatio);
819
+ needsUpdate = true;
820
+ }
821
+ // Check if any meshes need to be updated
822
+ var meshesNeedingUpdate = scene.meshes.filter(function (mesh) { return mesh["isHtmlMesh"] && (needsUpdate || mesh.requiresUpdate); });
823
+ needsUpdate = needsUpdate || meshesNeedingUpdate.length > 0;
824
+ if (!needsUpdate) {
825
+ return;
826
+ }
827
+ // Get a projection matrix for the camera
828
+ var projectionMatrix = camera.getProjectionMatrix();
829
+ var fov = projectionMatrix.m[5] * this._heightHalf;
830
+ if (this._cache.cameraData.fov !== fov) {
831
+ if (camera.mode == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Camera.PERSPECTIVE_CAMERA) {
832
+ [(_a = this._overlayElements) === null || _a === void 0 ? void 0 : _a.domElement, (_b = this._inSceneElements) === null || _b === void 0 ? void 0 : _b.domElement].forEach(function (el) {
833
+ if (el) {
834
+ el.style.webkitPerspective = fov + "px";
835
+ el.style.perspective = fov + "px";
836
+ }
837
+ });
838
+ }
839
+ else {
840
+ [(_c = this._overlayElements) === null || _c === void 0 ? void 0 : _c.domElement, (_d = this._inSceneElements) === null || _d === void 0 ? void 0 : _d.domElement].forEach(function (el) {
841
+ if (el) {
842
+ el.style.webkitPerspective = "";
843
+ el.style.perspective = "";
844
+ }
845
+ });
846
+ }
847
+ this._cache.cameraData.fov = fov;
848
+ }
849
+ // Get the CSS matrix for the camera (which will include any camera rotation)
850
+ if (camera.parent === null) {
851
+ camera.computeWorldMatrix();
852
+ }
853
+ var cameraMatrixWorld = this._temp.cameraWorldMatrix;
854
+ cameraMatrixWorld.copyFrom(camera.getWorldMatrix());
855
+ var cameraRotationMatrix = this._temp.cameraRotationMatrix;
856
+ cameraMatrixWorld.getRotationMatrix().transposeToRef(cameraRotationMatrix);
857
+ var cameraMatrixWorldAsArray = this._temp.cameraWorldMatrixAsArray;
858
+ cameraMatrixWorld.copyToArray(cameraMatrixWorldAsArray);
859
+ // For a few values, we have to adjust the direction based on the handedness of the system
860
+ var direction = useRightHandedSystem ? 1 : -1;
861
+ cameraMatrixWorldAsArray[1] = cameraRotationMatrix.m[1];
862
+ cameraMatrixWorldAsArray[2] = cameraRotationMatrix.m[2] * direction;
863
+ cameraMatrixWorldAsArray[4] = cameraRotationMatrix.m[4] * direction;
864
+ cameraMatrixWorldAsArray[6] = cameraRotationMatrix.m[6] * direction;
865
+ cameraMatrixWorldAsArray[8] = cameraRotationMatrix.m[8] * direction;
866
+ cameraMatrixWorldAsArray[9] = cameraRotationMatrix.m[9] * direction;
867
+ babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Matrix.FromArrayToRef(cameraMatrixWorldAsArray, 0, cameraMatrixWorld);
868
+ var cameraCSSMatrix = this._getCameraCSSMatrix(cameraMatrixWorld);
869
+ var style = cameraCSSMatrix;
870
+ if (this._cache.cameraData.style !== style) {
871
+ [(_e = this._inSceneElements) === null || _e === void 0 ? void 0 : _e.cameraElement, (_f = this._overlayElements) === null || _f === void 0 ? void 0 : _f.cameraElement].forEach(function (el) {
872
+ if (el) {
873
+ el.style.webkitTransform = style;
874
+ el.style.transform = style;
875
+ }
876
+ });
877
+ this._cache.cameraData.style = style;
878
+ }
879
+ // _Render objects if necessary
880
+ meshesNeedingUpdate.forEach(function (mesh) {
881
+ _this._renderHtmlMesh(mesh, useRightHandedSystem);
882
+ });
883
+ };
884
+ HtmlMeshRenderer.prototype._updateBaseScaleFactor = function (htmlMesh) {
885
+ // Get screen width and height
886
+ var screenWidth = this._width;
887
+ var screenHeight = this._height;
888
+ // Calculate aspect ratios
889
+ var htmlMeshAspectRatio = (htmlMesh.width || 1) / (htmlMesh.height || 1);
890
+ var screenAspectRatio = screenWidth / screenHeight;
891
+ // Adjust screen dimensions based on aspect ratios
892
+ if (htmlMeshAspectRatio > screenAspectRatio) {
893
+ // If the HTML mesh is wider relative to its height than the screen, adjust the screen width
894
+ screenWidth = screenHeight * htmlMeshAspectRatio;
895
+ }
896
+ else {
897
+ // If the HTML mesh is taller relative to its width than the screen, adjust the screen height
898
+ screenHeight = screenWidth / htmlMeshAspectRatio;
899
+ }
900
+ // Set content to fill screen so we get max resolution when it is shrunk to fit the mesh
901
+ htmlMesh.setContentSizePx(screenWidth, screenHeight);
902
+ };
903
+ HtmlMeshRenderer.prototype._updateContainerPositionIfNeeded = function () {
904
+ var _this = this;
905
+ var _a, _b;
906
+ // Determine if the canvas has moved on the screen
907
+ var canvasRect = this._engine.getRenderingCanvasClientRect();
908
+ // canvas rect may be null if layout not complete
909
+ if (!canvasRect) {
910
+ babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__.Logger.Warn(_positionUpdateFailMessage);
911
+ return;
912
+ }
913
+ var scrollTop = window.scrollY;
914
+ var scrollLeft = window.scrollX;
915
+ var canvasDocumentTop = canvasRect.top + scrollTop;
916
+ var canvasDocumentLeft = canvasRect.left + scrollLeft;
917
+ if (this._previousCanvasDocumentPosition.top !== canvasDocumentTop || this._previousCanvasDocumentPosition.left !== canvasDocumentLeft) {
918
+ this._previousCanvasDocumentPosition.top = canvasDocumentTop;
919
+ this._previousCanvasDocumentPosition.left = canvasDocumentLeft;
920
+ [(_a = this._inSceneElements) === null || _a === void 0 ? void 0 : _a.container, (_b = this._overlayElements) === null || _b === void 0 ? void 0 : _b.container].forEach(function (container) {
921
+ if (!container) {
922
+ return;
923
+ }
924
+ // set the top and left of the css container to match the canvas
925
+ var containerParent = container.offsetParent;
926
+ var parentRect = containerParent.getBoundingClientRect();
927
+ var parentDocumentTop = parentRect.top + scrollTop;
928
+ var parentDocumentLeft = parentRect.left + scrollLeft;
929
+ var ancestorMarginsAndPadding = _this._getAncestorMarginsAndPadding(containerParent);
930
+ // Add the body margin
931
+ var bodyStyle = window.getComputedStyle(document.body);
932
+ var bodyMarginTop = parseInt(bodyStyle.marginTop, 10);
933
+ var bodyMarginLeft = parseInt(bodyStyle.marginLeft, 10);
934
+ container.style.top = "".concat(canvasDocumentTop - parentDocumentTop - ancestorMarginsAndPadding.marginTop + ancestorMarginsAndPadding.paddingTop + bodyMarginTop, "px");
935
+ container.style.left = "".concat(canvasDocumentLeft - parentDocumentLeft - ancestorMarginsAndPadding.marginLeft + ancestorMarginsAndPadding.paddingLeft + bodyMarginLeft, "px");
936
+ });
937
+ }
938
+ };
939
+ HtmlMeshRenderer.prototype._epsilon = function (value) {
940
+ return Math.abs(value) < 1e-10 ? 0 : value;
941
+ };
942
+ // Get total margins and padding for an element, excluding the body and document margins
943
+ HtmlMeshRenderer.prototype._getAncestorMarginsAndPadding = function (element) {
944
+ var marginTop = 0;
945
+ var marginLeft = 0;
946
+ var paddingTop = 0;
947
+ var paddingLeft = 0;
948
+ while (element && element !== document.body && element !== document.documentElement) {
949
+ var style = window.getComputedStyle(element);
950
+ marginTop += parseInt(style.marginTop, 10);
951
+ marginLeft += parseInt(style.marginLeft, 10);
952
+ paddingTop += parseInt(style.paddingTop, 10);
953
+ paddingLeft += parseInt(style.paddingLeft, 10);
954
+ element = element.offsetParent;
955
+ }
956
+ return { marginTop: marginTop, marginLeft: marginLeft, paddingTop: paddingTop, paddingLeft: paddingLeft };
957
+ };
958
+ return HtmlMeshRenderer;
959
+ }());
960
+
961
+
962
+
963
+ /***/ }),
964
+
965
+ /***/ "../../../dev/addons/src/htmlMesh/index.ts":
966
+ /*!*************************************************!*\
967
+ !*** ../../../dev/addons/src/htmlMesh/index.ts ***!
968
+ \*************************************************/
969
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
970
+
971
+ __webpack_require__.r(__webpack_exports__);
972
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
973
+ /* harmony export */ FitStrategy: () => (/* reexport safe */ _fitStrategy__WEBPACK_IMPORTED_MODULE_3__.FitStrategy),
974
+ /* harmony export */ HtmlMesh: () => (/* reexport safe */ _htmlMesh__WEBPACK_IMPORTED_MODULE_1__.HtmlMesh),
975
+ /* harmony export */ HtmlMeshRenderer: () => (/* reexport safe */ _htmlMeshRenderer__WEBPACK_IMPORTED_MODULE_0__.HtmlMeshRenderer),
976
+ /* harmony export */ PointerEventsCaptureBehavior: () => (/* reexport safe */ _pointerEventsCaptureBehavior__WEBPACK_IMPORTED_MODULE_2__.PointerEventsCaptureBehavior)
977
+ /* harmony export */ });
978
+ /* harmony import */ var _htmlMeshRenderer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./htmlMeshRenderer */ "../../../dev/addons/src/htmlMesh/htmlMeshRenderer.ts");
979
+ /* harmony import */ var _htmlMesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./htmlMesh */ "../../../dev/addons/src/htmlMesh/htmlMesh.ts");
980
+ /* harmony import */ var _pointerEventsCaptureBehavior__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./pointerEventsCaptureBehavior */ "../../../dev/addons/src/htmlMesh/pointerEventsCaptureBehavior.ts");
981
+ /* harmony import */ var _fitStrategy__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./fitStrategy */ "../../../dev/addons/src/htmlMesh/fitStrategy.ts");
982
+
983
+
984
+
985
+
986
+ // Export public classes and functions
987
+
988
+
989
+
990
+ /***/ }),
991
+
992
+ /***/ "../../../dev/addons/src/htmlMesh/pointerEventsCapture.ts":
993
+ /*!****************************************************************!*\
994
+ !*** ../../../dev/addons/src/htmlMesh/pointerEventsCapture.ts ***!
995
+ \****************************************************************/
996
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
997
+
998
+ __webpack_require__.r(__webpack_exports__);
999
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1000
+ /* harmony export */ getCapturingId: () => (/* binding */ getCapturingId),
1001
+ /* harmony export */ releaseCurrent: () => (/* binding */ releaseCurrent),
1002
+ /* harmony export */ requestCapture: () => (/* binding */ requestCapture),
1003
+ /* harmony export */ requestRelease: () => (/* binding */ requestRelease)
1004
+ /* harmony export */ });
1005
+ /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Maths/math");
1006
+ /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
1007
+
1008
+ var captureRequestQueue = [];
1009
+ // Key is request id, value is object with capture and release callbacks
1010
+ var pendingRequestCallbacks = new Map();
1011
+ // Keep track of release requests with no matching capture request
1012
+ // in case the release request arrived before the capture to avoid
1013
+ // the capture request never getting released.
1014
+ var unmatchedReleaseRequests = [];
1015
+ var currentOwner = null; // Called on first capture or release request
1016
+ /**
1017
+ * Get the id of the object currently capturing pointer events
1018
+ * @returns The id of the object currently capturing pointer events
1019
+ * or null if no object is capturing pointer events
1020
+ */
1021
+ var getCapturingId = function () {
1022
+ return currentOwner;
1023
+ };
1024
+ /**
1025
+ * Request that the object with the given id capture pointer events. If there is no current
1026
+ * owner, then the request is granted immediately. If there is a current owner, then the request
1027
+ * is queued until the current owner releases pointer events.
1028
+ * @param requestId An id to identify the request. This id will be used to match the capture
1029
+ * request with the release request.
1030
+ * @param captureCallback The callback to call when the request is granted and the object is capturing
1031
+ * @param releaseCallback The callback to call when the object is no longer capturing pointer events
1032
+ */
1033
+ var requestCapture = function (requestId, captureCallback, releaseCallback) {
1034
+ debugLog("In pointerEventsCapture.requestCapture - Pointer events capture requested for ".concat(requestId));
1035
+ // If there is a release for this request, then ignore the request
1036
+ if (removeUnmatchedRequest(requestId)) {
1037
+ debugLog("In pointerEventsCapture.requestCapture - Capture request matched previous release request ".concat(requestId, ". Cancelling capture request"));
1038
+ return;
1039
+ }
1040
+ else if (requestId !== currentOwner) {
1041
+ // if the request is not already in the queue, add it to the queue
1042
+ enqueueCaptureRequest(requestId, captureCallback, releaseCallback);
1043
+ }
1044
+ if (!currentOwner) {
1045
+ // If there is no current owner, go ahead and grant the request
1046
+ transferPointerEventsOwnership();
1047
+ }
1048
+ // If the request id is the current owner, do nothing
1049
+ };
1050
+ /**
1051
+ * Release pointer events from the object with the given id. If the object is the current owner
1052
+ * then pointer events are released immediately. If the object is not the current owner, then the
1053
+ * associated capture request is removed from the queue. If there is no matching capture request
1054
+ * in the queue, then the release request is added to a list of unmatched release requests and will
1055
+ * negate the next capture request with the same id. This is to guard against the possibility that
1056
+ * the release request arrived before the capture request.
1057
+ * @param requestId The id which should match the id of the capture request
1058
+ */
1059
+ var requestRelease = function (requestId) {
1060
+ debugLog("In pointerEventsCapture.requestRelease - Pointer events release requested for ".concat(requestId));
1061
+ // if the requestId is the current capture holder release it
1062
+ if (!requestId || requestId === currentOwner) {
1063
+ transferPointerEventsOwnership();
1064
+ }
1065
+ else if (cancelRequest(requestId)) {
1066
+ // if the request is in the queue, but not the current capture holder, remove it and it's callbacks
1067
+ pendingRequestCallbacks.delete(requestId);
1068
+ }
1069
+ else {
1070
+ debugLog("In pointerEventsCapture.requestRelease - Received release request ".concat(requestId, " but no matching capture request was received"));
1071
+ // request was not current and not in queue, likely because we received a release
1072
+ // request before the capture. Add it to the unmatched list to guard against this possibility
1073
+ if (!unmatchedReleaseRequests.includes(requestId)) {
1074
+ unmatchedReleaseRequests.push(requestId);
1075
+ }
1076
+ }
1077
+ };
1078
+ /**
1079
+ * Relase pointer events from the current owner
1080
+ */
1081
+ var releaseCurrent = function () {
1082
+ requestRelease(currentOwner);
1083
+ };
1084
+ var enqueueCaptureRequest = function (requestId, capture, release) {
1085
+ debugLog("In pointerEventsCapture.enqueueCaptureRequest - Enqueueing capture request for ".concat(requestId));
1086
+ if (!captureRequestQueue.includes(requestId)) {
1087
+ captureRequestQueue.push(requestId);
1088
+ pendingRequestCallbacks.set(requestId, { capture: capture, release: release });
1089
+ }
1090
+ };
1091
+ // Removes the request from the queue if it exists. Returns true
1092
+ // if the request was found and removed, otherwise false
1093
+ var cancelRequest = function (requestId) {
1094
+ var removed = false;
1095
+ captureRequestQueue = captureRequestQueue.filter(function (id) {
1096
+ if (id !== requestId) {
1097
+ return true;
1098
+ }
1099
+ else {
1100
+ removed = true;
1101
+ debugLog("In pointerEventsCapture.cancelRequest - Canceling pointer events capture request ".concat(requestId));
1102
+ return false;
1103
+ }
1104
+ });
1105
+ return removed;
1106
+ };
1107
+ var removeUnmatchedRequest = function (requestId) {
1108
+ var removed = false;
1109
+ unmatchedReleaseRequests = unmatchedReleaseRequests.filter(function (id) {
1110
+ if (id !== requestId) {
1111
+ return true;
1112
+ }
1113
+ else {
1114
+ removed = true;
1115
+ return false;
1116
+ }
1117
+ });
1118
+ return removed;
1119
+ };
1120
+ var transferPointerEventsOwnership = function () {
1121
+ var newOwnerId = nextCaptureRequest();
1122
+ debugLog("In pointerEventsCapture.transferPointerEventsOwnership - Transferrring pointer events from ".concat(currentOwner, " to ").concat(newOwnerId));
1123
+ // Release the current owner
1124
+ doRelease();
1125
+ if (newOwnerId) {
1126
+ doCapture(newOwnerId);
1127
+ }
1128
+ };
1129
+ var doRelease = function () {
1130
+ var _a;
1131
+ debugLog("In pointerEventsCapture.doRelease - Releasing pointer events from ".concat(currentOwner));
1132
+ if (currentOwner) {
1133
+ // call the release callback
1134
+ (_a = pendingRequestCallbacks.get(currentOwner)) === null || _a === void 0 ? void 0 : _a.release();
1135
+ // And remove the callbacks
1136
+ pendingRequestCallbacks.delete(currentOwner);
1137
+ currentOwner = null;
1138
+ }
1139
+ };
1140
+ var doCapture = function (newOwnerId) {
1141
+ var _a;
1142
+ if (newOwnerId) {
1143
+ // call the capture callback
1144
+ (_a = pendingRequestCallbacks.get(newOwnerId)) === null || _a === void 0 ? void 0 : _a.capture();
1145
+ }
1146
+ currentOwner = newOwnerId;
1147
+ debugLog("In pointerEventsCapture.doCapture - Pointer events now captured by ".concat(newOwnerId));
1148
+ };
1149
+ var nextCaptureRequest = function () {
1150
+ return captureRequestQueue.length > 0 ? captureRequestQueue.shift() : null;
1151
+ };
1152
+ var debugLog = function (message) {
1153
+ // If we are runnning in a test runner (in node, so window is not defined)
1154
+ // or if the debug flag is set, then log the message
1155
+ if (typeof window === "undefined" || window["pointer-events-capture-debug"]) {
1156
+ babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__.Tools.Log("".concat(performance.now(), " - game.scene.pointerEvents - ").concat(message, "\ncurrentOwner: ").concat(currentOwner, "\nqueue: ").concat(captureRequestQueue, "\nunmatched: ").concat(unmatchedReleaseRequests));
1157
+ }
1158
+ };
1159
+ // #endregion Debugging support
1160
+
1161
+
1162
+ /***/ }),
1163
+
1164
+ /***/ "../../../dev/addons/src/htmlMesh/pointerEventsCaptureBehavior.ts":
1165
+ /*!************************************************************************!*\
1166
+ !*** ../../../dev/addons/src/htmlMesh/pointerEventsCaptureBehavior.ts ***!
1167
+ \************************************************************************/
1168
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1169
+
1170
+ __webpack_require__.r(__webpack_exports__);
1171
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1172
+ /* harmony export */ PointerEventsCaptureBehavior: () => (/* binding */ PointerEventsCaptureBehavior)
1173
+ /* harmony export */ });
1174
+ /* harmony import */ var babylonjs_Misc_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/logger */ "babylonjs/Maths/math");
1175
+ /* harmony import */ var babylonjs_Misc_logger__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_logger__WEBPACK_IMPORTED_MODULE_0__);
1176
+ /* harmony import */ var _pointerEventsCapture__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./pointerEventsCapture */ "../../../dev/addons/src/htmlMesh/pointerEventsCapture.ts");
1177
+
1178
+
1179
+ // Module level variable for holding the current scene
1180
+ var _scene = null;
1181
+ // Module level variable to hold the count of behavior instances that are currently capturing pointer events
1182
+ // on entry. This is used to determine if we need to start or stop observing pointer movement.
1183
+ var captureOnEnterCount = 0;
1184
+ // Map used to store instance of the PointerEventsCaptureBehavior for a mesh
1185
+ // We do this because this gets checked on pointer move and we don't want to
1186
+ // use getBehaviorByName() because that is a linear search
1187
+ var meshToBehaviorMap = new WeakMap();
1188
+ var startCaptureOnEnter = function (scene) {
1189
+ // If we are not in a browser, do nothing
1190
+ if (typeof document === "undefined") {
1191
+ return;
1192
+ }
1193
+ if (captureOnEnterCount === 0) {
1194
+ document.addEventListener("pointermove", onPointerMove);
1195
+ document.addEventListener("touchstart", onPointerMove);
1196
+ _scene = _scene !== null && _scene !== void 0 ? _scene : scene;
1197
+ babylonjs_Misc_logger__WEBPACK_IMPORTED_MODULE_0__.Logger.Log("PointerEventsCaptureBehavior: Starting observation of pointer move events.");
1198
+ _scene.onDisposeObservable.add(doStopCaptureOnEnter);
1199
+ }
1200
+ captureOnEnterCount++;
1201
+ };
1202
+ var doStopCaptureOnEnter = function () {
1203
+ document.removeEventListener("pointermove", onPointerMove);
1204
+ document.removeEventListener("touchstart", onPointerMove);
1205
+ _scene = null;
1206
+ babylonjs_Misc_logger__WEBPACK_IMPORTED_MODULE_0__.Logger.Log("PointerEventsCaptureBehavior: Stopping observation of pointer move events.");
1207
+ captureOnEnterCount = 0;
1208
+ };
1209
+ var stopCaptureOnEnter = function () {
1210
+ // If we are not in a browser, do nothing
1211
+ if (typeof document === "undefined") {
1212
+ return;
1213
+ }
1214
+ // If we are not observing pointer movement, do nothing
1215
+ if (!_scene) {
1216
+ return;
1217
+ }
1218
+ captureOnEnterCount--;
1219
+ if (captureOnEnterCount <= 0) {
1220
+ doStopCaptureOnEnter();
1221
+ }
1222
+ };
1223
+ // Module level function used to determine if an entered mesh should capture pointer events
1224
+ var onPointerMove = function (evt) {
1225
+ if (!_scene) {
1226
+ return;
1227
+ }
1228
+ var canvasRect = _scene.getEngine().getRenderingCanvasClientRect();
1229
+ if (!canvasRect) {
1230
+ return;
1231
+ }
1232
+ // Get the object that contains the client X and Y from either the pointer event or from the
1233
+ // TouchEvent touch
1234
+ var _a = "touches" in evt ? evt.touches[0] : evt, clientX = _a.clientX, clientY = _a.clientY;
1235
+ // get the picked mesh, if any
1236
+ var pointerScreenX = clientX - canvasRect.left;
1237
+ var pointerScreenY = clientY - canvasRect.top;
1238
+ var pointerCaptureBehavior;
1239
+ var pickResult = _scene.pick(pointerScreenX, pointerScreenY, function (mesh) {
1240
+ // If the mesh has an instance of PointerEventsCaptureBehavior attached to it,
1241
+ // and capture on pointer enter is true, then we want to pick it
1242
+ var pointerCaptureBehavior = meshToBehaviorMap.get(mesh);
1243
+ return mesh.isEnabled() && typeof pointerCaptureBehavior !== "undefined" && pointerCaptureBehavior._captureOnPointerEnter;
1244
+ });
1245
+ var pickedMesh;
1246
+ if (pickResult.hit) {
1247
+ pickedMesh = pickResult.pickedMesh;
1248
+ }
1249
+ else {
1250
+ pickedMesh = null;
1251
+ }
1252
+ var capturingIdAsInt = parseInt((0,_pointerEventsCapture__WEBPACK_IMPORTED_MODULE_1__.getCapturingId)() || "");
1253
+ // if the picked mesh is the current capturing mesh, do nothing
1254
+ if (pickedMesh && pickedMesh.uniqueId === capturingIdAsInt) {
1255
+ return;
1256
+ }
1257
+ // If there is a capturing mesh and it is not the current picked mesh, or no
1258
+ // mesh is picked, release the capturing mesh
1259
+ if (capturingIdAsInt && (!pickedMesh || pickedMesh.uniqueId !== capturingIdAsInt)) {
1260
+ (0,_pointerEventsCapture__WEBPACK_IMPORTED_MODULE_1__.releaseCurrent)();
1261
+ }
1262
+ // If there is a picked mesh and it is not the current capturing mesh, capture
1263
+ // the pointer events. Note that the current capturing mesh has already been
1264
+ // released above
1265
+ if (pickedMesh) {
1266
+ pointerCaptureBehavior = meshToBehaviorMap.get(pickedMesh);
1267
+ pointerCaptureBehavior.capturePointerEvents();
1268
+ }
1269
+ };
1270
+ /**
1271
+ * Behavior for any content that can capture pointer events, i.e. bypass the Babylon pointer event handling
1272
+ * and receive pointer events directly. It will register the capture triggers and negotiate the capture and
1273
+ * release of pointer events. Curerntly this applies only to HtmlMesh
1274
+ */
1275
+ var PointerEventsCaptureBehavior = /** @class */ (function () {
1276
+ function PointerEventsCaptureBehavior(_captureCallback, _releaseCallback, _a) {
1277
+ var _b = _a === void 0 ? {} : _a, _c = _b.captureOnPointerEnter, captureOnPointerEnter = _c === void 0 ? true : _c;
1278
+ this._captureCallback = _captureCallback;
1279
+ this._releaseCallback = _releaseCallback;
1280
+ /** gets or sets behavior's name */
1281
+ this.name = "PointerEventsCaptureBehavior";
1282
+ this._attachedMesh = null;
1283
+ this._captureOnPointerEnter = captureOnPointerEnter;
1284
+ // Warn if we are not in a browser
1285
+ if (typeof document === "undefined") {
1286
+ babylonjs_Misc_logger__WEBPACK_IMPORTED_MODULE_0__.Logger.Warn("Creating an instance of PointerEventsCaptureBehavior outside of a browser. The behavior will not work.");
1287
+ }
1288
+ }
1289
+ Object.defineProperty(PointerEventsCaptureBehavior.prototype, "attachedMesh", {
1290
+ /**
1291
+ * Gets or sets the mesh that the behavior is attached to
1292
+ */
1293
+ get: function () {
1294
+ return this._attachedMesh;
1295
+ },
1296
+ set: function (value) {
1297
+ this._attachedMesh = value;
1298
+ },
1299
+ enumerable: false,
1300
+ configurable: true
1301
+ });
1302
+ Object.defineProperty(PointerEventsCaptureBehavior.prototype, "captureOnPointerEnter", {
1303
+ /**
1304
+ * Set if the behavior should capture pointer events when the pointer enters the mesh
1305
+ */
1306
+ set: function (captureOnPointerEnter) {
1307
+ if (this._captureOnPointerEnter === captureOnPointerEnter) {
1308
+ return;
1309
+ }
1310
+ this._captureOnPointerEnter = captureOnPointerEnter;
1311
+ if (this._attachedMesh) {
1312
+ if (this._captureOnPointerEnter) {
1313
+ startCaptureOnEnter(this._attachedMesh.getScene());
1314
+ }
1315
+ else {
1316
+ stopCaptureOnEnter();
1317
+ }
1318
+ }
1319
+ },
1320
+ enumerable: false,
1321
+ configurable: true
1322
+ });
1323
+ /**
1324
+ * Function called when the behavior needs to be initialized (before attaching it to a target)
1325
+ */
1326
+ PointerEventsCaptureBehavior.prototype.init = function () { };
1327
+ /**
1328
+ * Called when the behavior is attached to a target
1329
+ * @param mesh defines the target where the behavior is attached to
1330
+ */
1331
+ PointerEventsCaptureBehavior.prototype.attach = function (mesh) {
1332
+ // Add a reference to this behavior on the mesh. We do this so we can get a
1333
+ // reference to the behavior in the onPointerMove function without relying on
1334
+ // getBehaviorByName(), which does a linear search of the behaviors array.
1335
+ this.attachedMesh = mesh;
1336
+ meshToBehaviorMap.set(mesh, this);
1337
+ if (this._captureOnPointerEnter) {
1338
+ startCaptureOnEnter(mesh.getScene());
1339
+ }
1340
+ };
1341
+ /**
1342
+ * Called when the behavior is detached from its target
1343
+ */
1344
+ PointerEventsCaptureBehavior.prototype.detach = function () {
1345
+ if (!this.attachedMesh) {
1346
+ return;
1347
+ }
1348
+ // Remove the reference to this behavior from the mesh
1349
+ meshToBehaviorMap.delete(this.attachedMesh);
1350
+ if (this._captureOnPointerEnter) {
1351
+ stopCaptureOnEnter();
1352
+ }
1353
+ this.attachedMesh = null;
1354
+ };
1355
+ /**
1356
+ * Dispose the behavior
1357
+ */
1358
+ PointerEventsCaptureBehavior.prototype.dispose = function () {
1359
+ this.detach();
1360
+ };
1361
+ // Release pointer events
1362
+ PointerEventsCaptureBehavior.prototype.releasePointerEvents = function () {
1363
+ if (!this.attachedMesh) {
1364
+ return;
1365
+ }
1366
+ (0,_pointerEventsCapture__WEBPACK_IMPORTED_MODULE_1__.requestRelease)(this.attachedMesh.uniqueId.toString());
1367
+ };
1368
+ // Capture pointer events
1369
+ PointerEventsCaptureBehavior.prototype.capturePointerEvents = function () {
1370
+ if (!this.attachedMesh) {
1371
+ return;
1372
+ }
1373
+ (0,_pointerEventsCapture__WEBPACK_IMPORTED_MODULE_1__.requestCapture)(this.attachedMesh.uniqueId.toString(), this._captureCallback, this._releaseCallback);
1374
+ };
1375
+ return PointerEventsCaptureBehavior;
1376
+ }());
1377
+
1378
+
1379
+
1380
+ /***/ }),
1381
+
15
1382
  /***/ "../../../dev/addons/src/index.ts":
16
1383
  /*!****************************************!*\
17
1384
  !*** ../../../dev/addons/src/index.ts ***!
@@ -20,9 +1387,461 @@ return /******/ (() => { // webpackBootstrap
20
1387
 
21
1388
  __webpack_require__.r(__webpack_exports__);
22
1389
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
23
- /* harmony export */ empty: () => (/* binding */ empty)
1390
+ /* harmony export */ FitStrategy: () => (/* reexport safe */ _htmlMesh__WEBPACK_IMPORTED_MODULE_0__.FitStrategy),
1391
+ /* harmony export */ HtmlMesh: () => (/* reexport safe */ _htmlMesh__WEBPACK_IMPORTED_MODULE_0__.HtmlMesh),
1392
+ /* harmony export */ HtmlMeshRenderer: () => (/* reexport safe */ _htmlMesh__WEBPACK_IMPORTED_MODULE_0__.HtmlMeshRenderer),
1393
+ /* harmony export */ PointerEventsCaptureBehavior: () => (/* reexport safe */ _htmlMesh__WEBPACK_IMPORTED_MODULE_0__.PointerEventsCaptureBehavior)
1394
+ /* harmony export */ });
1395
+ /* harmony import */ var _htmlMesh__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./htmlMesh */ "../../../dev/addons/src/htmlMesh/index.ts");
1396
+
1397
+
1398
+
1399
+ /***/ }),
1400
+
1401
+ /***/ "babylonjs/Maths/math":
1402
+ /*!****************************************************************************************************!*\
1403
+ !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
1404
+ \****************************************************************************************************/
1405
+ /***/ ((module) => {
1406
+
1407
+ module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math__;
1408
+
1409
+ /***/ }),
1410
+
1411
+ /***/ "../../../../node_modules/tslib/tslib.es6.mjs":
1412
+ /*!****************************************************!*\
1413
+ !*** ../../../../node_modules/tslib/tslib.es6.mjs ***!
1414
+ \****************************************************/
1415
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1416
+
1417
+ __webpack_require__.r(__webpack_exports__);
1418
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1419
+ /* harmony export */ __addDisposableResource: () => (/* binding */ __addDisposableResource),
1420
+ /* harmony export */ __assign: () => (/* binding */ __assign),
1421
+ /* harmony export */ __asyncDelegator: () => (/* binding */ __asyncDelegator),
1422
+ /* harmony export */ __asyncGenerator: () => (/* binding */ __asyncGenerator),
1423
+ /* harmony export */ __asyncValues: () => (/* binding */ __asyncValues),
1424
+ /* harmony export */ __await: () => (/* binding */ __await),
1425
+ /* harmony export */ __awaiter: () => (/* binding */ __awaiter),
1426
+ /* harmony export */ __classPrivateFieldGet: () => (/* binding */ __classPrivateFieldGet),
1427
+ /* harmony export */ __classPrivateFieldIn: () => (/* binding */ __classPrivateFieldIn),
1428
+ /* harmony export */ __classPrivateFieldSet: () => (/* binding */ __classPrivateFieldSet),
1429
+ /* harmony export */ __createBinding: () => (/* binding */ __createBinding),
1430
+ /* harmony export */ __decorate: () => (/* binding */ __decorate),
1431
+ /* harmony export */ __disposeResources: () => (/* binding */ __disposeResources),
1432
+ /* harmony export */ __esDecorate: () => (/* binding */ __esDecorate),
1433
+ /* harmony export */ __exportStar: () => (/* binding */ __exportStar),
1434
+ /* harmony export */ __extends: () => (/* binding */ __extends),
1435
+ /* harmony export */ __generator: () => (/* binding */ __generator),
1436
+ /* harmony export */ __importDefault: () => (/* binding */ __importDefault),
1437
+ /* harmony export */ __importStar: () => (/* binding */ __importStar),
1438
+ /* harmony export */ __makeTemplateObject: () => (/* binding */ __makeTemplateObject),
1439
+ /* harmony export */ __metadata: () => (/* binding */ __metadata),
1440
+ /* harmony export */ __param: () => (/* binding */ __param),
1441
+ /* harmony export */ __propKey: () => (/* binding */ __propKey),
1442
+ /* harmony export */ __read: () => (/* binding */ __read),
1443
+ /* harmony export */ __rest: () => (/* binding */ __rest),
1444
+ /* harmony export */ __rewriteRelativeImportExtension: () => (/* binding */ __rewriteRelativeImportExtension),
1445
+ /* harmony export */ __runInitializers: () => (/* binding */ __runInitializers),
1446
+ /* harmony export */ __setFunctionName: () => (/* binding */ __setFunctionName),
1447
+ /* harmony export */ __spread: () => (/* binding */ __spread),
1448
+ /* harmony export */ __spreadArray: () => (/* binding */ __spreadArray),
1449
+ /* harmony export */ __spreadArrays: () => (/* binding */ __spreadArrays),
1450
+ /* harmony export */ __values: () => (/* binding */ __values),
1451
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
24
1452
  /* harmony export */ });
25
- var empty = {};
1453
+ /******************************************************************************
1454
+ Copyright (c) Microsoft Corporation.
1455
+
1456
+ Permission to use, copy, modify, and/or distribute this software for any
1457
+ purpose with or without fee is hereby granted.
1458
+
1459
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1460
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1461
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1462
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1463
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1464
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1465
+ PERFORMANCE OF THIS SOFTWARE.
1466
+ ***************************************************************************** */
1467
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1468
+
1469
+ var extendStatics = function(d, b) {
1470
+ extendStatics = Object.setPrototypeOf ||
1471
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1472
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1473
+ return extendStatics(d, b);
1474
+ };
1475
+
1476
+ function __extends(d, b) {
1477
+ if (typeof b !== "function" && b !== null)
1478
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1479
+ extendStatics(d, b);
1480
+ function __() { this.constructor = d; }
1481
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1482
+ }
1483
+
1484
+ var __assign = function() {
1485
+ __assign = Object.assign || function __assign(t) {
1486
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1487
+ s = arguments[i];
1488
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1489
+ }
1490
+ return t;
1491
+ }
1492
+ return __assign.apply(this, arguments);
1493
+ }
1494
+
1495
+ function __rest(s, e) {
1496
+ var t = {};
1497
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1498
+ t[p] = s[p];
1499
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
1500
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1501
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1502
+ t[p[i]] = s[p[i]];
1503
+ }
1504
+ return t;
1505
+ }
1506
+
1507
+ function __decorate(decorators, target, key, desc) {
1508
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1509
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1510
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1511
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1512
+ }
1513
+
1514
+ function __param(paramIndex, decorator) {
1515
+ return function (target, key) { decorator(target, key, paramIndex); }
1516
+ }
1517
+
1518
+ function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
1519
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
1520
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
1521
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
1522
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
1523
+ var _, done = false;
1524
+ for (var i = decorators.length - 1; i >= 0; i--) {
1525
+ var context = {};
1526
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
1527
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
1528
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
1529
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
1530
+ if (kind === "accessor") {
1531
+ if (result === void 0) continue;
1532
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
1533
+ if (_ = accept(result.get)) descriptor.get = _;
1534
+ if (_ = accept(result.set)) descriptor.set = _;
1535
+ if (_ = accept(result.init)) initializers.unshift(_);
1536
+ }
1537
+ else if (_ = accept(result)) {
1538
+ if (kind === "field") initializers.unshift(_);
1539
+ else descriptor[key] = _;
1540
+ }
1541
+ }
1542
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
1543
+ done = true;
1544
+ };
1545
+
1546
+ function __runInitializers(thisArg, initializers, value) {
1547
+ var useValue = arguments.length > 2;
1548
+ for (var i = 0; i < initializers.length; i++) {
1549
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
1550
+ }
1551
+ return useValue ? value : void 0;
1552
+ };
1553
+
1554
+ function __propKey(x) {
1555
+ return typeof x === "symbol" ? x : "".concat(x);
1556
+ };
1557
+
1558
+ function __setFunctionName(f, name, prefix) {
1559
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
1560
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
1561
+ };
1562
+
1563
+ function __metadata(metadataKey, metadataValue) {
1564
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
1565
+ }
1566
+
1567
+ function __awaiter(thisArg, _arguments, P, generator) {
1568
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1569
+ return new (P || (P = Promise))(function (resolve, reject) {
1570
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1571
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1572
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1573
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1574
+ });
1575
+ }
1576
+
1577
+ function __generator(thisArg, body) {
1578
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1579
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1580
+ function verb(n) { return function (v) { return step([n, v]); }; }
1581
+ function step(op) {
1582
+ if (f) throw new TypeError("Generator is already executing.");
1583
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
1584
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1585
+ if (y = 0, t) op = [op[0] & 2, t.value];
1586
+ switch (op[0]) {
1587
+ case 0: case 1: t = op; break;
1588
+ case 4: _.label++; return { value: op[1], done: false };
1589
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1590
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1591
+ default:
1592
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1593
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1594
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1595
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1596
+ if (t[2]) _.ops.pop();
1597
+ _.trys.pop(); continue;
1598
+ }
1599
+ op = body.call(thisArg, _);
1600
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1601
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1602
+ }
1603
+ }
1604
+
1605
+ var __createBinding = Object.create ? (function(o, m, k, k2) {
1606
+ if (k2 === undefined) k2 = k;
1607
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1608
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1609
+ desc = { enumerable: true, get: function() { return m[k]; } };
1610
+ }
1611
+ Object.defineProperty(o, k2, desc);
1612
+ }) : (function(o, m, k, k2) {
1613
+ if (k2 === undefined) k2 = k;
1614
+ o[k2] = m[k];
1615
+ });
1616
+
1617
+ function __exportStar(m, o) {
1618
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
1619
+ }
1620
+
1621
+ function __values(o) {
1622
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1623
+ if (m) return m.call(o);
1624
+ if (o && typeof o.length === "number") return {
1625
+ next: function () {
1626
+ if (o && i >= o.length) o = void 0;
1627
+ return { value: o && o[i++], done: !o };
1628
+ }
1629
+ };
1630
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1631
+ }
1632
+
1633
+ function __read(o, n) {
1634
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
1635
+ if (!m) return o;
1636
+ var i = m.call(o), r, ar = [], e;
1637
+ try {
1638
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1639
+ }
1640
+ catch (error) { e = { error: error }; }
1641
+ finally {
1642
+ try {
1643
+ if (r && !r.done && (m = i["return"])) m.call(i);
1644
+ }
1645
+ finally { if (e) throw e.error; }
1646
+ }
1647
+ return ar;
1648
+ }
1649
+
1650
+ /** @deprecated */
1651
+ function __spread() {
1652
+ for (var ar = [], i = 0; i < arguments.length; i++)
1653
+ ar = ar.concat(__read(arguments[i]));
1654
+ return ar;
1655
+ }
1656
+
1657
+ /** @deprecated */
1658
+ function __spreadArrays() {
1659
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1660
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
1661
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
1662
+ r[k] = a[j];
1663
+ return r;
1664
+ }
1665
+
1666
+ function __spreadArray(to, from, pack) {
1667
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1668
+ if (ar || !(i in from)) {
1669
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1670
+ ar[i] = from[i];
1671
+ }
1672
+ }
1673
+ return to.concat(ar || Array.prototype.slice.call(from));
1674
+ }
1675
+
1676
+ function __await(v) {
1677
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
1678
+ }
1679
+
1680
+ function __asyncGenerator(thisArg, _arguments, generator) {
1681
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1682
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
1683
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
1684
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
1685
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
1686
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
1687
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
1688
+ function fulfill(value) { resume("next", value); }
1689
+ function reject(value) { resume("throw", value); }
1690
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
1691
+ }
1692
+
1693
+ function __asyncDelegator(o) {
1694
+ var i, p;
1695
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
1696
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
1697
+ }
1698
+
1699
+ function __asyncValues(o) {
1700
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1701
+ var m = o[Symbol.asyncIterator], i;
1702
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
1703
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
1704
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
1705
+ }
1706
+
1707
+ function __makeTemplateObject(cooked, raw) {
1708
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
1709
+ return cooked;
1710
+ };
1711
+
1712
+ var __setModuleDefault = Object.create ? (function(o, v) {
1713
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1714
+ }) : function(o, v) {
1715
+ o["default"] = v;
1716
+ };
1717
+
1718
+ function __importStar(mod) {
1719
+ if (mod && mod.__esModule) return mod;
1720
+ var result = {};
1721
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1722
+ __setModuleDefault(result, mod);
1723
+ return result;
1724
+ }
1725
+
1726
+ function __importDefault(mod) {
1727
+ return (mod && mod.__esModule) ? mod : { default: mod };
1728
+ }
1729
+
1730
+ function __classPrivateFieldGet(receiver, state, kind, f) {
1731
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1732
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1733
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1734
+ }
1735
+
1736
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
1737
+ if (kind === "m") throw new TypeError("Private method is not writable");
1738
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1739
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1740
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1741
+ }
1742
+
1743
+ function __classPrivateFieldIn(state, receiver) {
1744
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
1745
+ return typeof state === "function" ? receiver === state : state.has(receiver);
1746
+ }
1747
+
1748
+ function __addDisposableResource(env, value, async) {
1749
+ if (value !== null && value !== void 0) {
1750
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
1751
+ var dispose, inner;
1752
+ if (async) {
1753
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
1754
+ dispose = value[Symbol.asyncDispose];
1755
+ }
1756
+ if (dispose === void 0) {
1757
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
1758
+ dispose = value[Symbol.dispose];
1759
+ if (async) inner = dispose;
1760
+ }
1761
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
1762
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
1763
+ env.stack.push({ value: value, dispose: dispose, async: async });
1764
+ }
1765
+ else if (async) {
1766
+ env.stack.push({ async: true });
1767
+ }
1768
+ return value;
1769
+ }
1770
+
1771
+ var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1772
+ var e = new Error(message);
1773
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1774
+ };
1775
+
1776
+ function __disposeResources(env) {
1777
+ function fail(e) {
1778
+ env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
1779
+ env.hasError = true;
1780
+ }
1781
+ var r, s = 0;
1782
+ function next() {
1783
+ while (r = env.stack.pop()) {
1784
+ try {
1785
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
1786
+ if (r.dispose) {
1787
+ var result = r.dispose.call(r.value);
1788
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
1789
+ }
1790
+ else s |= 1;
1791
+ }
1792
+ catch (e) {
1793
+ fail(e);
1794
+ }
1795
+ }
1796
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
1797
+ if (env.hasError) throw env.error;
1798
+ }
1799
+ return next();
1800
+ }
1801
+
1802
+ function __rewriteRelativeImportExtension(path, preserveJsx) {
1803
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
1804
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
1805
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
1806
+ });
1807
+ }
1808
+ return path;
1809
+ }
1810
+
1811
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
1812
+ __extends,
1813
+ __assign,
1814
+ __rest,
1815
+ __decorate,
1816
+ __param,
1817
+ __esDecorate,
1818
+ __runInitializers,
1819
+ __propKey,
1820
+ __setFunctionName,
1821
+ __metadata,
1822
+ __awaiter,
1823
+ __generator,
1824
+ __createBinding,
1825
+ __exportStar,
1826
+ __values,
1827
+ __read,
1828
+ __spread,
1829
+ __spreadArrays,
1830
+ __spreadArray,
1831
+ __await,
1832
+ __asyncGenerator,
1833
+ __asyncDelegator,
1834
+ __asyncValues,
1835
+ __makeTemplateObject,
1836
+ __importStar,
1837
+ __importDefault,
1838
+ __classPrivateFieldGet,
1839
+ __classPrivateFieldSet,
1840
+ __classPrivateFieldIn,
1841
+ __addDisposableResource,
1842
+ __disposeResources,
1843
+ __rewriteRelativeImportExtension,
1844
+ });
26
1845
 
27
1846
 
28
1847
  /***/ })
@@ -54,6 +1873,18 @@ var empty = {};
54
1873
  /******/ }
55
1874
  /******/
56
1875
  /************************************************************************/
1876
+ /******/ /* webpack/runtime/compat get default export */
1877
+ /******/ (() => {
1878
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
1879
+ /******/ __webpack_require__.n = (module) => {
1880
+ /******/ var getter = module && module.__esModule ?
1881
+ /******/ () => (module['default']) :
1882
+ /******/ () => (module);
1883
+ /******/ __webpack_require__.d(getter, { a: getter });
1884
+ /******/ return getter;
1885
+ /******/ };
1886
+ /******/ })();
1887
+ /******/
57
1888
  /******/ /* webpack/runtime/define property getters */
58
1889
  /******/ (() => {
59
1890
  /******/ // define getter functions for harmony exports
@@ -107,4 +1938,4 @@ __webpack_exports__ = __webpack_exports__["default"];
107
1938
  /******/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GhhVGVzdFJlbmRlck9yZGVyOiBSZW5kZXJPcmRlckZ1bmN0aW9uLFxyXG4gICAgICAgIGRlZmF1bHRUcmFuc3BhcmVudFJlbmRlck9yZGVyOiBSZW5kZXJPcmRlckZ1bmN0aW9uXHJcbiAgICApOiB2b2lkIHtcclxuICAgICAgICAvLyBSZXF1aXJlcyBhIGJyb3dzZXIgdG8gd29yay4gIE9ubHkgaW5pdCBpZiB3ZSBhcmUgaW4gYSBicm93c2VyXHJcbiAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gXCJ1bmRlZmluZWRcIikge1xyXG4gICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvLyBDcmVhdGUgdGhlIERPTSBjb250YWluZXJzXHJcbiAgICAgICAgbGV0IHBhcmVudENvbnRhaW5lciA9IHBhcmVudENvbnRhaW5lcklkID8gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQocGFyZW50Q29udGFpbmVySWQpIDogZG9jdW1lbnQuYm9keTtcclxuXHJcbiAgICAgICAgaWYgKCFwYXJlbnRDb250YWluZXIpIHtcclxuICAgICAgICAgICAgcGFyZW50Q29udGFpbmVyID0gZG9jdW1lbnQuYm9keTtcclxuICAgICAgICB9XHJcblxyXG4gICAgICAgIC8vIGlmIHRoZSBjb250YWluZXIgYWxyZWFkeSBleGlzdHMsIHRoZW4gcmVtb3ZlIGl0XHJcbiAgICAgICAgY29uc3QgaW5TY2VuZUNvbnRhaW5lcklkID0gYCR7dGhpcy5fY29udGFpbmVySWR9X2luX3NjZW5lYDtcclxuICAgICAgICB0aGlzLl9pblNjZW5lRWxlbWVudHMgPSB0aGlzLl9jcmVhdGVSZW5kZXJMYXllckVsZW1lbnRzKGluU2NlbmVDb250YWluZXJJZCk7XHJcblxyXG4gICAgICAgIHBhcmVudENvbnRhaW5lci5pbnNlcnRCZWZvcmUodGhpcy5faW5TY2VuZUVsZW1lbnRzLmNvbnRhaW5lciwgcGFyZW50Q29udGFpbmVyLmZpcnN0Q2hpbGQpO1xyXG5cclxuICAgICAgICBpZiAoZW5hYmxlT3ZlcmxheVJlbmRlcikge1xyXG4gICAgICAgICAgICBjb25zdCBvdmVybGF5Q29udGFpbmVySWQgPSBgJHt0aGlzLl9jb250YWluZXJJZH1fb3ZlcmxheWA7XHJcbiAgICAgICAgICAgIHRoaXMuX292ZXJsYXlFbGVtZW50cyA9IHRoaXMuX2NyZWF0ZVJlbmRlckxheWVyRWxlbWVudHMob3ZlcmxheUNvbnRhaW5lcklkKTtcclxuICAgICAgICAgICAgY29uc3QgekluZGV4ID0gKyhzY2VuZS5nZXRFbmdpbmUoKS5nZXRSZW5kZXJpbmdDYW52YXMoKSEuc3R5bGUuekluZGV4ID8/IFwiMFwiKSArIDE7XHJcbiAgICAgICAgICAgIHRoaXMuX292ZXJsYXlFbGVtZW50cy5jb250YWluZXIuc3R5bGUuekluZGV4ID0gYCR7ekluZGV4fWA7XHJcbiAgICAgICAgICAgIHRoaXMuX292ZXJsYXlFbGVtZW50cy5jb250YWluZXIuc3R5bGUucG9pbnRlckV2ZW50cyA9IFwibm9uZVwiO1xyXG4gICAgICAgICAgICBwYXJlbnRDb250YWluZXIuaW5zZXJ0QmVmb3JlKHRoaXMuX292ZXJsYXlFbGVtZW50cy5jb250YWluZXIsIHBhcmVudENvbnRhaW5lci5maXJzdENoaWxkKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgdGhpcy5fZW5naW5lID0gc2NlbmUuZ2V0RW5naW5lKCk7XHJcbiAgICAgICAgY29uc3QgY2xpZW50UmVjdCA9IHRoaXMuX2VuZ2luZS5nZXRSZW5kZXJpbmdDYW52YXNDbGllbnRSZWN0KCk7XHJcbiAgICAgICAgaWYgKCFjbGllbnRSZWN0KSB7XHJcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihcIkZhaWxlZCB0byBnZXQgY2xpZW50IHJlY3QgZm9yIHJlbmRlcmluZyBjYW52YXNcIik7XHJcbiAgICA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Q29udGFpbmVyID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoY29udGFpbmVySWQpO1xyXG4gICAgICAgIGlmIChleGlzdGluZ0NvbnRhaW5lcikge1xyXG4gICAgICAgICAgICBleGlzdGluZ0NvbnRhaW5lci5yZW1vdmUoKTtcclxuICAgICAgICB9XHJcbiAgICAgICAgY29uc3QgY29udGFpbmVyID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudChcImRpdlwiKTtcclxuICAgICAgICBjb250YWluZXIuaWQgPSBjb250YWluZXJJZDtcclxuICAgICAgICBjb250YWluZXIuc3R5bGUucG9zaXRpb24gPSBcImFic29sdXRlXCI7XHJcbiAgICAgICAgY29udGFpbmVyLnN0eWxlLndpZHRoID0gXCIxMDAlXCI7XHJcbiAgICAgICAgY29udGFpbmVyLnN0eWxlLmhlaWdodCA9IFwiMTAwJVwiO1xyXG4gICAgICAgIGNvbnRhaW5lci5zdHlsZS56SW5kZXggPSBcIi0xXCI7XHJcblxyXG4gICAgICAgIGNvbnN0IGRvbUVsZW1lbnQgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KFwiZGl2XCIpO1xyXG4gICAgICAgIGRvbUVsZW1lbnQuc3R5bGUub3ZlcmZsb3cgPSBcImhpZGRlblwiO1xyXG5cclxuICAgICAgICBjb25zdCBjYW1lcmFFbGVtZW50ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudChcImRpdlwiKTtcclxuXHJcbiAgICAgICAgY2FtZXJhRWxlbWVudC5zdHlsZS53ZWJraXRUcmFuc2Zvcm1TdHlsZSA9IFwicHJlc2VydmUtM2RcIjtcclxuICAgICAgICBjYW1lcmFFbGVtZW50LnN0eWxlLnRyYW5zZm9ybVN0eWxlID0gXCJwcmVzZXJ2ZS0zZFwiO1xyXG5cclxuICAgICAgICBjYW1lcmFFbGVtZW50LnN0eWxlLnBvaW50ZXJFdmVudHMgPSBcIm5vbmVcIjtcclxuXHJcbiAgICAgICAgZG9tRWxlbWVudC5hc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EuY2FtZXJhRWxlbWVudF07XHJcbiAgICAgICAgZG9tRWxlbWVudHMuZm9yRWFjaCgoZG9tKSA9PiB7XHJcbiAgICAgICAgICAgIGlmIChkb20pIHtcclxuICAgICAgICAgICAgICAgIGRvbS5zdHlsZS53aWR0aCA9IGAke3dpZHRofXB4YDtcclxuICAgICAgICAgICAgICAgIGRvbS5zdHlsZS5oZWlnaHQgPSBgJHtoZWlnaHR9cHhgO1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSk7XHJcbiAgICB9XHJcblxyXG4gICAgLy8gcHJldHRpZXItaWdub3JlXHJcbiAgICBwcm90ZWN0ZWQgX2dldENhbWVyYUNTU01hdHJpeChtYXRyaXg6IE1hdHJpeCk6IHN0cmluZyB7XHJcbiAgICAgICAgY29uc3QgZWxlbWVudHMgPSBtYXRyaXgubTtcclxuICAgICAgICByZXR1cm4gYG1hdHJpeDNkKCR7XHJcbiAgICAgICAgICAgIHRoaXMuX2Vwc2lsb24oIGVsZW1lbnRzWzBdIClcclxuICAgICAgICB9LCR7XHJcbiAgICAgICAgICAgIHRoaXMuX2Vwc2lsb24oIC0gZWxlbWVudHNbMV0gKVxyXG4gICAgICAgIH0sJHtcclxuICAgICAgICAgICAgdGhpcy5fZXBzaWxvbiggZWxlbWVudHNbMl0gKVxyXG4gICAgICAgIH0sJHtcclxuICAgICAgICAgICAgdGhpcy5fZXBzaWxvbiggZWxlbWVudHNbM10gKVxyXG4gICAgICAgIH0sJHtcclxuICAgICAgICAgICAgdGhpcy5fZXBzaWxvbiggZWxlbWVudHNbNF0gKVxyXG4gICAgICAgIH0sJHtcclxuICAgICAgICAgICAgdGhpcy5fZXBzaWxvbiggLSBlbGVtZW50c1s1XSApXHJcbiAgICAgICAgfSwke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCBlbGVtZW50c1s2XSApXHJcbiAgICAgICAgfSwke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCBlbGVtZW50c1s3X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cml4Lm07XHJcbiAgICAgICAgLy8gSW4gYSByaWdodCBoYW5kZWQgY29vcmRpbmF0ZSBzeXN0ZW0sIHRoZSBlbGVtZW50cyAxMSB0byAxNCBoYXZlIHRvIGNoYW5nZSB0aGVpciBkaXJlY3Rpb25cclxuICAgICAgICBjb25zdCBkaXJlY3Rpb24gPSB1c2VSaWdodEhhbmRlZFN5c3RlbSA/IC0xIDogMTtcclxuICAgICAgICBjb25zdCBtYXRyaXgzZCA9IGBtYXRyaXgzZCgke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCBlbGVtZW50c1swXSApXHJcbiAgICAgICAgfSwke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCBlbGVtZW50c1sxXSApXHJcbiAgICAgICAgfSwke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCBlbGVtZW50c1syXSAqIC1kaXJlY3Rpb24gKVxyXG4gICAgICAgIH0sJHtcclxuICAgICAgICAgICAgdGhpcy5fZXBzaWxvbiggZWxlbWVudHNbM10gKVxyXG4gICAgICAgIH0sJHtcclxuICAgICAgICAgICAgdGhpcy5fZXBzaWxvbiggLSBlbGVtZW50c1s0XSApXHJcbiAgICAgICAgfSwke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCAtIGVsZW1lbnRzWzVdIClcclxuICAgICAgICB9LCR7XHJcbiAgICAgICAgICAgIHRoaXMuX2Vwc2lsb24oIGVsZW1lbnRzWzZdICAqIGRpcmVjdGlvbiApXHJcbiAgICAgICAgfSwke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCAtIGVsZW1lbnRzWzddIClcclxuICAgICAgICB9LCR7XHJcbiAgICAgICAgICAgIHRoaXMuX2Vwc2lsb24oIGVsZW1lbnRzWzhdICogLWRpcmVjdGlvbiApXHJcbiAgICAgICAgfSwke1xyXG4gICAgICAgICAgICB0aGlzLl9lcHNpbG9uKCBlbGVtZW50c1s5XSAqIC1kaXJlY3Rp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gIGlmIChjYW1lcmEubW9kZSA9PSBDYW1lcmEuUEVSU1BFQ1RJVkVfQ0FNRVJBKSB7XHJcbiAgICAgICAgICAgICAgICBbdGhpcy5fb3ZlcmxheUVsZW1lbnRzPy5kb21FbGVtZW50LCB0aGlzLl9pblNjZW5lRWxlbWVudHM/LmRvbUVsZW1lbnRdLmZvckVhY2goKGVsKSA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKGVsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGVsLnN0eWxlLndlYmtpdFBlcnNwZWN0aXZlID0gZm92ICsgXCJweFwiO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBlbC5zdHlsZS5wZXJzcGVjdGl2ZSA9IGZvdiArIFwicHhcIjtcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIFt0aGlzLl9vdmVybGF5RWxlbWVudHM/LmRvbUVsZW1lbnQsIHRoaXMuX2luU2NlbmVFbGVtZW50cz8uZG9tRWxlbWVudF0uZm9yRWFjaCgoZWwpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICBpZiAoZWwpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZWwuc3R5bGUud2Via2l0UGVyc3BlY3RpdmUgPSBcIlwiO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBlbC5zdHlsZS5wZXJzcGVjdGl2ZSA9IFwiXCI7XHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgdGhpcy5fY2FjaGUuY2FtZXJhRGF0YS5mb3YgPSBmb3Y7XHJcbiAgICAgICAgfVxyXG5cclxuICAgICAgICAvLyBHZXQgdGhlIENTUyBtYXRyaXggZm9yIHRoZSBjYW1lcmEgKHdoaWNoIHdpbGwgaW5jbHVkZSBhbn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vckVhY2goKGNvbnRhaW5lcikgPT4ge1xyXG4gICAgICAgICAgICAgICAgaWYgKCFjb250YWluZXIpIHtcclxuICAgICAgICAgICAgICAgICAgICByZXR1cm47XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAvLyBzZXQgdGhlIHRvcCBhbmQgbGVmdCBvZiB0aGUgY3NzIGNvbnRhaW5lciB0byBtYXRjaCB0aGUgY2FudmFzXHJcbiAgICAgICAgICAgICAgICBjb25zdCBjb250YWluZXJQYXJlbnQgPSBjb250YWluZXIub2Zmc2V0UGFyZW50IGFzIEhUTUxFbGVtZW50O1xyXG4gICAgICAgICAgICAgICAgY29uc3QgcGFyZW50UmVjdCA9IGNvbnRhaW5lclBhcmVudC5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKTtcclxuICAgICAgICAgICAgICAgIGNvbnN0IHBhcmVudERvY3VtZW50VG9wID0gcGFyZW50UmVjdC50b3AgKyBzY3JvbGxUb3A7XHJcbiAgICAgICAgICAgICAgICBjb25zdCBwYXJlbnREb2N1bWVudExlZnQgPSBwYXJlbnRSZWN0LmxlZnQgKyBzY3JvbGxMZWZ0O1xyXG5cclxuICAgICAgICAgICAgICAgIGNvbnN0IGFuY2VzdG9yTWFyZ2luc0FuZFBhZGRpbmcgPSB0aGlzLl9nZXRBbmNlc3Rvck1hcmdpbnNBbmRQYWRkaW5nKGNvbnRhaW5lclBhcmVudCk7XHJcblxyXG4gICAgICAgICAgICAgICAgLy8gQWRkIHRoZSBib2R5IG1hcmdpblxyXG4gICAgICAgICAgICAgICAgY29uc3QgYm9keVN0eWxlID0gd2luZG93LmdldENvbXB1dGVkU3R5bGUoZG9jdW1lbnQuYm9keSk7XHJcbiAgICAgICAgICAgICAgICBjb25zdCBib2R5TWFyZ2luVG9wID0gcGFyc2VJbnQoYm9keVN0eWxlLm1hcmdpblRvcCwgMTApO1xyXG4gICAgICAgICAgICAgICAgY29uc3QgYm9keU1hcmdpbkxlZnQgPSBwYXJz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