@pacem/pacem 1.0.0-abel

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +191 -0
  2. package/NOTICE +4 -0
  3. package/dist/browser/pacem-2d.js +2755 -0
  4. package/dist/browser/pacem-2d.js.map +6 -0
  5. package/dist/browser/pacem-2d.min.js +7 -0
  6. package/dist/browser/pacem-2d.min.js.map +6 -0
  7. package/dist/browser/pacem-3d.js +7723 -0
  8. package/dist/browser/pacem-3d.js.map +6 -0
  9. package/dist/browser/pacem-3d.min.js +7 -0
  10. package/dist/browser/pacem-3d.min.js.map +6 -0
  11. package/dist/browser/pacem-charts.js +1628 -0
  12. package/dist/browser/pacem-charts.js.map +6 -0
  13. package/dist/browser/pacem-charts.min.js +7 -0
  14. package/dist/browser/pacem-charts.min.js.map +6 -0
  15. package/dist/browser/pacem-cms.js +2220 -0
  16. package/dist/browser/pacem-cms.js.map +6 -0
  17. package/dist/browser/pacem-cms.min.js +7 -0
  18. package/dist/browser/pacem-cms.min.js.map +6 -0
  19. package/dist/browser/pacem-core.js +9104 -0
  20. package/dist/browser/pacem-core.js.map +6 -0
  21. package/dist/browser/pacem-core.min.js +7 -0
  22. package/dist/browser/pacem-core.min.js.map +6 -0
  23. package/dist/browser/pacem-foundation.js +2138 -0
  24. package/dist/browser/pacem-foundation.js.map +6 -0
  25. package/dist/browser/pacem-foundation.min.js +7 -0
  26. package/dist/browser/pacem-foundation.min.js.map +6 -0
  27. package/dist/browser/pacem-fx.js +870 -0
  28. package/dist/browser/pacem-fx.js.map +6 -0
  29. package/dist/browser/pacem-fx.min.js +7 -0
  30. package/dist/browser/pacem-fx.min.js.map +6 -0
  31. package/dist/browser/pacem-logging.js +175 -0
  32. package/dist/browser/pacem-logging.js.map +6 -0
  33. package/dist/browser/pacem-logging.min.js +7 -0
  34. package/dist/browser/pacem-logging.min.js.map +6 -0
  35. package/dist/browser/pacem-maps.js +3642 -0
  36. package/dist/browser/pacem-maps.js.map +6 -0
  37. package/dist/browser/pacem-maps.min.js +7 -0
  38. package/dist/browser/pacem-maps.min.js.map +6 -0
  39. package/dist/browser/pacem-media.js +284 -0
  40. package/dist/browser/pacem-media.js.map +6 -0
  41. package/dist/browser/pacem-media.min.js +7 -0
  42. package/dist/browser/pacem-media.min.js.map +6 -0
  43. package/dist/browser/pacem-networking.js +434 -0
  44. package/dist/browser/pacem-networking.js.map +6 -0
  45. package/dist/browser/pacem-networking.min.js +7 -0
  46. package/dist/browser/pacem-networking.min.js.map +6 -0
  47. package/dist/browser/pacem-numerical.js +2627 -0
  48. package/dist/browser/pacem-numerical.js.map +6 -0
  49. package/dist/browser/pacem-numerical.min.js +7 -0
  50. package/dist/browser/pacem-numerical.min.js.map +6 -0
  51. package/dist/browser/pacem-plus.js +2373 -0
  52. package/dist/browser/pacem-plus.js.map +6 -0
  53. package/dist/browser/pacem-plus.min.js +7 -0
  54. package/dist/browser/pacem-plus.min.js.map +6 -0
  55. package/dist/browser/pacem-scaffolding.js +10435 -0
  56. package/dist/browser/pacem-scaffolding.js.map +6 -0
  57. package/dist/browser/pacem-scaffolding.min.js +7 -0
  58. package/dist/browser/pacem-scaffolding.min.js.map +6 -0
  59. package/dist/browser/pacem-ui.js +6348 -0
  60. package/dist/browser/pacem-ui.js.map +6 -0
  61. package/dist/browser/pacem-ui.min.js +7 -0
  62. package/dist/browser/pacem-ui.min.js.map +6 -0
  63. package/dist/bundle/pacem.min.mjs +997 -0
  64. package/dist/bundle/pacem.mjs +47067 -0
  65. package/dist/bundle/pacem.mjs.map +12 -0
  66. package/dist/typings/index.d.ts +9757 -0
  67. package/package.json +130 -0
@@ -0,0 +1,2755 @@
1
+ /**
2
+ * @pacem/pacem v1.0.0-abel (https://js.pacem.it)
3
+ * Copyright 2026 Pacem (https://pacem.it)
4
+ * Licensed under Apache-2.0
5
+ */
6
+ (function (pacemFoundation, pacemCore) {
7
+ 'use strict';
8
+
9
+ const TAG_MIDDLE_NAME = "2d";
10
+
11
+ function isDrawable(object) {
12
+ return !pacemCore.Utils.isNull(object) && 'stage' in object;
13
+ }
14
+ function isUiObject(object) {
15
+ return /*'transformMatrix' in object &&*/ isDrawable(object);
16
+ }
17
+ function isGradient(object) {
18
+ return 'stops' in object && pacemCore.Utils.isArray(object.stops);
19
+ }
20
+ function isLinearGradient(object) {
21
+ return isGradient(object) && 'start' in object && pacemFoundation.Point.isPoint(object.start)
22
+ && 'end' in object && pacemFoundation.Point.isPoint(object.end);
23
+ }
24
+ function isRadialGradient(object) {
25
+ return isGradient(object) && 'center' in object && pacemFoundation.Point.isPoint(object.center)
26
+ && 'radius' in object && typeof object.radius === 'number';
27
+ }
28
+ class PresentationState {
29
+ static combine(lhs, rhs, precomputedMatrix = null) {
30
+ return {
31
+ opacity: (lhs.opacity ?? 1) * (rhs.opacity ?? 1),
32
+ transformMatrix: precomputedMatrix ?? pacemFoundation.Matrix2D.multiply(rhs.transformMatrix, lhs.transformMatrix),
33
+ dashArray: lhs.dashArray ?? rhs.dashArray,
34
+ fill: lhs.fill ?? rhs.fill,
35
+ lineCap: lhs.lineCap ?? rhs.lineCap,
36
+ lineJoin: lhs.lineJoin ?? rhs.lineJoin,
37
+ lineWidth: lhs.lineWidth ?? rhs.lineWidth,
38
+ stroke: lhs.stroke ?? rhs.stroke
39
+ };
40
+ }
41
+ }
42
+ function isPresentationObject(object) {
43
+ return isUiObject(object)
44
+ && ('fill' in object
45
+ || 'transformMatrix' in object
46
+ || 'stroke' in object
47
+ || 'lineJoin' in object
48
+ || 'dashArray' in object
49
+ || 'lineWidth' in object
50
+ || 'opacity' in object
51
+ || 'lineCap' in object);
52
+ }
53
+ function isShape(object) {
54
+ return isUiObject(object) && 'pathData' in object;
55
+ }
56
+ function isGroup(object) {
57
+ return isUiObject(object) && 'childDrawables' in object && !pacemCore.Utils.isNullOrEmpty(object['childDrawables']);
58
+ }
59
+ function isText(object) {
60
+ return isUiObject(object) && 'text' in object && typeof object['text'] === 'string';
61
+ }
62
+ function isImage(object) {
63
+ return isUiObject(object) && 'src' in object && typeof object['src'] === 'string';
64
+ }
65
+ class UI2DEvent extends pacemCore.CustomUIEvent {
66
+ constructor(type, eventInit, originalEvent, transformMatrix) {
67
+ super(type, eventInit, originalEvent);
68
+ this.#transformMatrix = transformMatrix;
69
+ }
70
+ #transformMatrix;
71
+ /** Gets the screen transform matrix. */
72
+ get transformMatrix() {
73
+ return this.#transformMatrix;
74
+ }
75
+ project(pt = { x: this.screenX, y: this.screenY }) {
76
+ return pacemFoundation.Matrix2D.multiply(pt, this.#transformMatrix);
77
+ }
78
+ }
79
+ class Shape {
80
+ static empty() {
81
+ return { pathData: '', vertices: [], boundingRect: { x: 0, y: 0, width: 0, height: 0 } };
82
+ }
83
+ }
84
+ class DragEvent extends UI2DEvent {
85
+ }
86
+ class DrawableEvent extends UI2DEvent {
87
+ constructor(type, args, originalEvent, m) {
88
+ super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, m);
89
+ }
90
+ }
91
+ class StageEvent extends UI2DEvent {
92
+ constructor(type, args, originalEvent, m = args.transformMatrix) {
93
+ super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, m);
94
+ }
95
+ }
96
+
97
+ var drawing = /*#__PURE__*/Object.freeze({
98
+ __proto__: null,
99
+ DragEvent: DragEvent,
100
+ DrawableEvent: DrawableEvent,
101
+ PresentationState: PresentationState,
102
+ Shape: Shape,
103
+ StageEvent: StageEvent,
104
+ UI2DEvent: UI2DEvent,
105
+ isDrawable: isDrawable,
106
+ isGroup: isGroup,
107
+ isImage: isImage,
108
+ isLinearGradient: isLinearGradient,
109
+ isPresentationObject: isPresentationObject,
110
+ isRadialGradient: isRadialGradient,
111
+ isShape: isShape,
112
+ isText: isText,
113
+ isUiObject: isUiObject
114
+ });
115
+
116
+ var __decorate$d = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
117
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
118
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
119
+ 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;
120
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
121
+ };
122
+ //namespace Pacem.Components.Drawing {
123
+ // group [1] := align x,[3] := align y,[6] := slice
124
+ const ASPECTRATIO_PATTERN = /^\s*[xX]\s*([Mm](in|ax|id))\s*[yY]\s*([Mm](in|ax|id))(\s+(none|slice|meet))?\s*$/;
125
+ const aspectRatioPropertyConverter = {
126
+ convert: (attr) => {
127
+ const regArr = ASPECTRATIO_PATTERN.exec(attr);
128
+ if (regArr && regArr.length >= 4) {
129
+ return {
130
+ x: regArr[1].toLowerCase(),
131
+ y: regArr[3].toLowerCase(),
132
+ slice: regArr[6] === 'slice'
133
+ };
134
+ }
135
+ return 'none';
136
+ },
137
+ convertBack: (val) => {
138
+ if (pacemCore.Utils.isNull(val) || typeof val === 'string') {
139
+ return 'none';
140
+ }
141
+ return `xM${(val.x.substring(1))}YM${(val.y.substring(1))} ${(val.slice ? 'slice' : 'meet')}`;
142
+ }
143
+ };
144
+ const DEFAULT_STAGE_OPTIONS = {
145
+ panControl: true,
146
+ zoomControl: true,
147
+ panModifiers: [pacemCore.EventKeyModifier.AltKey],
148
+ zoomModifiers: [pacemCore.EventKeyModifier.AltKey],
149
+ clickModifiers: []
150
+ };
151
+ function getStageOptions(stage) {
152
+ const options = stage instanceof Pacem2DElement ? stage.options : {};
153
+ return pacemCore.Utils.extend({}, DEFAULT_STAGE_OPTIONS, options);
154
+ }
155
+ let Pacem2DElement = class Pacem2DElement extends pacemCore.Components.PacemItemsContainerElement {
156
+ constructor() {
157
+ super(...arguments);
158
+ this.#transformMatrix = pacemFoundation.Matrix2D.identity;
159
+ this.#options = DEFAULT_STAGE_OPTIONS;
160
+ this._resizeHandler = (evt) => {
161
+ this.#size = { x: evt.detail.left, y: evt.detail.top, width: evt.detail.width, height: evt.detail.height };
162
+ const adapter = this.adapter;
163
+ if (!pacemCore.Utils.isNull(adapter)) {
164
+ this._invalidateSize();
165
+ }
166
+ };
167
+ this._zoomHandler = (evt) => {
168
+ // only trusted ui interaction
169
+ if (!evt.isTrusted) {
170
+ return;
171
+ }
172
+ const opts = this.#options;
173
+ if (opts.zoomControl && pacemCore.CustomEventUtils.matchModifiers(evt, opts.zoomModifiers)) {
174
+ // prevent anything
175
+ pacemCore.avoidHandler(evt);
176
+ const zoomingOut = evt.deltaY < 0;
177
+ // center change?
178
+ const factor = .1, sign = zoomingOut ? -1 : 1, factorWSign = factor * sign, scale = 1 + factorWSign;
179
+ const stageRect = pacemCore.Utils.offsetRect(evt.currentTarget), pt = { x: evt.clientX, y: evt.clientY };
180
+ this._zoom(scale, stageRect, pt);
181
+ }
182
+ };
183
+ this._panHandler = (evt) => {
184
+ const state = this.#panningStart, actual = this._getPanPoint(evt);
185
+ if (!pacemCore.Utils.isNullOrEmpty(state && state.point) && !pacemCore.Utils.isNull(actual)) {
186
+ pacemCore.avoidHandler(evt);
187
+ const factor = state.factor, vbox = state.box, start = state.point;
188
+ this.viewbox = {
189
+ x: vbox.x - factor * (actual.x - start.x),
190
+ y: vbox.y - factor * (actual.y - start.y),
191
+ width: vbox.width,
192
+ height: vbox.height
193
+ };
194
+ }
195
+ };
196
+ this._panStartHandler = (evt) => {
197
+ const opts = this.#options;
198
+ if (!opts.panControl) {
199
+ return;
200
+ }
201
+ // only trusted ui interaction
202
+ if (!evt.isTrusted) {
203
+ return;
204
+ }
205
+ const size = this.#size, vbox = this.viewbox || { x: 0, y: 0, width: size.width, height: size.height }, start = this._getPanPoint(evt);
206
+ if (start) {
207
+ pacemCore.avoidHandler(evt);
208
+ this._stage.style.pointerEvents = 'none';
209
+ const aspectRatio = this._getActualAspectRatio();
210
+ const wBased = vbox.width / size.width, hBased = vbox.height / size.height, factor = aspectRatio.slice ? Math.min(wBased, hBased) : Math.max(wBased, hBased);
211
+ this.#panningStart = { point: start, box: vbox, factor };
212
+ }
213
+ };
214
+ this._panEndHandler = (evt) => {
215
+ this._stage.style.pointerEvents = '';
216
+ this.#panningStart = null;
217
+ };
218
+ }
219
+ get stage() {
220
+ return this._stage;
221
+ }
222
+ snapshot(bgColor, type, quality) {
223
+ const adapter = this.adapter;
224
+ if (pacemCore.Utils.isNull(adapter)) {
225
+ return Promise.resolve(null);
226
+ }
227
+ return adapter.snapshot(this, bgColor, type, quality);
228
+ }
229
+ #originalViewBox;
230
+ #transformMatrix;
231
+ get transformMatrix() {
232
+ return this.#transformMatrix;
233
+ }
234
+ _transformMatrixScale() {
235
+ const sizeObj = this.#size || pacemCore.Utils.offsetRect(this._stage);
236
+ var origVbox = this.#originalViewBox || sizeObj;
237
+ const vbox = this.viewbox || origVbox;
238
+ const aspectRatio = this.aspectRatio || 'none';
239
+ const mode = aspectRatio === 'none' ? 'stretch' : (aspectRatio.slice ? 'cover' : 'contain');
240
+ const actual = pacemFoundation.Rect.findTransform(vbox, origVbox, mode);
241
+ return actual.a;
242
+ }
243
+ validate(item) {
244
+ return item instanceof DrawableElement && /* only direct items */ pacemCore.Utils.isNull(item.parent);
245
+ }
246
+ draw(item, redraw = false) {
247
+ const adapter = this.adapter;
248
+ if (!this.disabled && !pacemCore.Utils.isNull(adapter)) {
249
+ let cancelable = new CustomEvent('predraw', { cancelable: true });
250
+ this.dispatchEvent(cancelable);
251
+ if (!cancelable.defaultPrevented) {
252
+ adapter.draw(this, item, redraw);
253
+ this.dispatchEvent(new CustomEvent('draw'));
254
+ }
255
+ }
256
+ }
257
+ _drawDebounced(item, force = false) {
258
+ if (!pacemCore.Utils.isNull(item) && isGroup(item)) {
259
+ this.draw(item, force);
260
+ }
261
+ else {
262
+ this.draw(item);
263
+ }
264
+ }
265
+ requestDraw(item, redraw = false) {
266
+ this._drawDebounced(item, redraw);
267
+ }
268
+ _buildUpDatasourceFromDOM() {
269
+ this.datasource = (this.items || []).slice();
270
+ }
271
+ #options;
272
+ #size;
273
+ _getActualAspectRatio() {
274
+ const aspectRatio = this.aspectRatio || 'none';
275
+ const alignmentX = aspectRatio === 'none' ? 'mid' : aspectRatio.x;
276
+ const alignmentY = aspectRatio === 'none' ? 'mid' : aspectRatio.y;
277
+ const slice = aspectRatio === 'none' ? false : aspectRatio.slice;
278
+ return { x: alignmentX, y: alignmentY, slice };
279
+ }
280
+ _zoomFromValue(scale) {
281
+ const sizeObj = this.#size;
282
+ if (pacemCore.Utils.isNull(sizeObj)) {
283
+ return;
284
+ }
285
+ const sizeRect = sizeObj;
286
+ const origVbox = this.#originalViewBox || sizeRect, vbox = this.viewbox || origVbox;
287
+ const aspectRatio = this.aspectRatio || 'none';
288
+ const mode = aspectRatio === 'none' ? 'stretch' : (aspectRatio.slice ? 'cover' : 'contain');
289
+ const actual = pacemFoundation.Rect.findTransform(vbox, sizeRect, mode);
290
+ const original = pacemFoundation.Rect.findTransform(origVbox, sizeRect, mode);
291
+ const actualScale = actual.a;
292
+ const origScale = original.a;
293
+ const targetScale = origScale * scale;
294
+ const incrementalInverseScale = actualScale / targetScale;
295
+ this._zoom(incrementalInverseScale);
296
+ }
297
+ _zoom(scale, stageRect, pt) {
298
+ if (pacemCore.Utils.isNull(stageRect)) {
299
+ stageRect = pacemCore.Utils.offsetRect(this._stage);
300
+ }
301
+ if (pacemCore.Utils.isNull(pt)) {
302
+ pt = { x: stageRect.x + stageRect.width * .5, y: stageRect.y + stageRect.height * .5 };
303
+ }
304
+ const sizeObj = this.#size, vbox = this.viewbox || sizeObj;
305
+ const vsize = Math.min(vbox.width, vbox.height), targetWidth = vsize * scale, targetHeight = vsize * scale;
306
+ if (targetWidth > 0 && targetHeight > 0) {
307
+ const aspectRatio = this._getActualAspectRatio();
308
+ const alignmentX = aspectRatio.x;
309
+ const alignmentY = aspectRatio.y;
310
+ const slice = aspectRatio.slice;
311
+ // offset
312
+ const vboxRatio = vbox.width / vbox.height, size = slice ? Math.max(stageRect.width, stageRect.height) : Math.min(stageRect.width, stageRect.height);
313
+ let
314
+ // to be adjusted based on aspectRatio
315
+ adjX, adjY;
316
+ switch (alignmentX) {
317
+ case 'mid':
318
+ adjX = (targetWidth - vbox.width) * (pt.x - stageRect.x - .5 * (stageRect.width - size)) / (size * vboxRatio);
319
+ break;
320
+ case 'max':
321
+ adjX = (targetWidth - vbox.width) * (pt.x - stageRect.x - (stageRect.width - size)) / (size * vboxRatio);
322
+ break;
323
+ default:
324
+ adjX = (targetWidth - vbox.width) * (pt.x - stageRect.x) / (size * vboxRatio);
325
+ break;
326
+ }
327
+ switch (alignmentY) {
328
+ case 'mid':
329
+ adjY = (targetHeight - vbox.height) * (pt.y - stageRect.y - .5 * (stageRect.height - size)) / (size * vboxRatio);
330
+ break;
331
+ case 'max':
332
+ adjY = (targetHeight - vbox.height) * (pt.y - stageRect.y - (stageRect.height - size)) / (size * vboxRatio);
333
+ break;
334
+ default:
335
+ adjY = (targetHeight - vbox.height) * (pt.y - stageRect.y) / (size * vboxRatio);
336
+ break;
337
+ }
338
+ const targetX = vbox.x - adjX, targetY = vbox.y - adjY;
339
+ this.viewbox = { x: targetX, y: targetY, width: targetWidth, height: targetHeight };
340
+ }
341
+ }
342
+ _getPanPoint(evt) {
343
+ const opts = this.#options;
344
+ if (evt instanceof MouseEvent && pacemCore.CustomEventUtils.matchModifiers(evt, opts.panModifiers)) {
345
+ return pacemCore.CustomEventUtils.getEventCoordinates(evt).page;
346
+ }
347
+ return null;
348
+ }
349
+ #panningStart;
350
+ _invalidateSize() {
351
+ this.adapter.invalidateSize(this, this.#size);
352
+ const prevTransformMatrix = this.#transformMatrix;
353
+ this.#transformMatrix = this.adapter.getTransformMatrix(this);
354
+ this.dispatchEvent(new pacemCore.PropertyChangeEvent({ propertyName: 'transformMatrix', currentValue: this.#transformMatrix, oldValue: prevTransformMatrix }));
355
+ this.zoom = this._transformMatrixScale();
356
+ this.dispatchEvent(new pacemCore.Components.ResizeEvent(this.#size));
357
+ }
358
+ viewActivatedCallback() {
359
+ super.viewActivatedCallback();
360
+ const adapter = this.adapter;
361
+ if (!pacemCore.Utils.isNull(adapter)) {
362
+ adapter.initialize(this);
363
+ this._invalidateSize();
364
+ // request draw right away
365
+ this._drawDebounced();
366
+ }
367
+ const resize = this._resize;
368
+ resize.addEventListener(pacemCore.Components.ResizeEventName, this._resizeHandler, false);
369
+ const stage = this._stage;
370
+ resize.target = stage;
371
+ const options = { capture: false, passive: true };
372
+ // zooming
373
+ stage.addEventListener('wheel', this._zoomHandler, false);
374
+ // panning
375
+ stage.addEventListener('mousedown', this._panStartHandler, false);
376
+ stage.addEventListener('touchstart', this._panStartHandler, options);
377
+ window.addEventListener('mousemove', this._panHandler, false);
378
+ window.addEventListener('mouseup', this._panEndHandler, false);
379
+ window.addEventListener('touchmove', this._panHandler, options);
380
+ window.addEventListener('touchend', this._panEndHandler, options);
381
+ }
382
+ propertyChangedCallback(name, old, val, first) {
383
+ super.propertyChangedCallback(name, old, val, first);
384
+ switch (name) {
385
+ case 'adapter':
386
+ if (!pacemCore.Utils.isNull(old)) {
387
+ old.dispose(this);
388
+ }
389
+ if (!pacemCore.Utils.isNull(val)) {
390
+ val.initialize(this);
391
+ this._invalidateSize();
392
+ this._drawDebounced();
393
+ }
394
+ break;
395
+ case 'aspectRatio':
396
+ if (!pacemCore.Utils.isNull(this.adapter)) {
397
+ this._invalidateSize();
398
+ }
399
+ break;
400
+ case 'viewbox':
401
+ if (!pacemCore.Utils.isNull(this.adapter)) {
402
+ this._invalidateSize();
403
+ }
404
+ this.#originalViewBox ??= (this.viewbox || null);
405
+ break;
406
+ case 'items':
407
+ this._buildUpDatasourceFromDOM();
408
+ break;
409
+ case 'zoom':
410
+ if (val !== this._transformMatrixScale()) {
411
+ this._zoomFromValue(val);
412
+ }
413
+ break;
414
+ case 'options':
415
+ this.#options = getStageOptions(this); // Utils.extend({}, DEFAULT_STAGE_OPTIONS, val || {});
416
+ break;
417
+ case 'disabled':
418
+ case 'datasource':
419
+ this._drawDebounced();
420
+ break;
421
+ }
422
+ }
423
+ disconnectedCallback() {
424
+ const resizer = this._resize, stage = this._stage;
425
+ if (!pacemCore.Utils.isNull(resizer)) {
426
+ resizer.removeEventListener(pacemCore.Components.ResizeEventName, this._resizeHandler, false);
427
+ }
428
+ if (!pacemCore.Utils.isNull(stage)) {
429
+ // zooming
430
+ stage.removeEventListener('wheel', this._zoomHandler, false);
431
+ // panning
432
+ stage.removeEventListener('mousedown', this._panStartHandler, false);
433
+ stage.removeEventListener('touchstart', this._panStartHandler);
434
+ window.removeEventListener('mousemove', this._panHandler, false);
435
+ window.removeEventListener('mouseup', this._panEndHandler, false);
436
+ window.removeEventListener('touchmove', this._panHandler);
437
+ window.removeEventListener('touchend', this._panEndHandler);
438
+ }
439
+ if (!pacemCore.Utils.isNull(this.adapter)) {
440
+ this.adapter.dispose(this);
441
+ }
442
+ super.disconnectedCallback();
443
+ }
444
+ };
445
+ __decorate$d([
446
+ pacemCore.Watch({ converter: pacemCore.PropertyConverters.Element })
447
+ ], Pacem2DElement.prototype, "adapter", void 0);
448
+ __decorate$d([
449
+ pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.Rect })
450
+ ], Pacem2DElement.prototype, "viewbox", void 0);
451
+ __decorate$d([
452
+ pacemCore.Watch({ emit: false, reflectBack: true, converter: aspectRatioPropertyConverter })
453
+ ], Pacem2DElement.prototype, "aspectRatio", void 0);
454
+ __decorate$d([
455
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Json })
456
+ ], Pacem2DElement.prototype, "datasource", void 0);
457
+ __decorate$d([
458
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Json })
459
+ ], Pacem2DElement.prototype, "options", void 0);
460
+ __decorate$d([
461
+ pacemCore.Watch({ converter: pacemCore.PropertyConverters.Number })
462
+ ], Pacem2DElement.prototype, "zoom", void 0);
463
+ __decorate$d([
464
+ pacemCore.ViewChild('.' + pacemCore.PCSS + '-2d')
465
+ ], Pacem2DElement.prototype, "_stage", void 0);
466
+ __decorate$d([
467
+ pacemCore.ViewChild(pacemCore.P + '-resize')
468
+ ], Pacem2DElement.prototype, "_resize", void 0);
469
+ __decorate$d([
470
+ pacemCore.Debounce(true)
471
+ ], Pacem2DElement.prototype, "_drawDebounced", null);
472
+ Pacem2DElement = __decorate$d([
473
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME, shadow: true, template: `<${pacemCore.P}-resize watch-position="true"></${pacemCore.P}-resize><div class="${pacemCore.PCSS}-2d" part="container"></div><slot></slot>` })
474
+ ], Pacem2DElement);
475
+
476
+ var __decorate$c = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
477
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
478
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
479
+ 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;
480
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
481
+ };
482
+ class DrawableElement extends pacemCore.Components.PacemCrossItemsContainerElement {
483
+ validate(_) {
484
+ // by default no children allowed (Group will except)
485
+ return false;
486
+ }
487
+ findContainer() {
488
+ // override
489
+ return this.parent || this.stage;
490
+ }
491
+ get stage() {
492
+ return this['_scene'] = this['_scene'] || pacemCore.CustomElementUtils.findAncestorOfType(this, Pacem2DElement);
493
+ }
494
+ get parent() {
495
+ return this['_drawableParent'] = this['_drawableParent'] || pacemCore.CustomElementUtils.findAncestor(this, i => i instanceof DrawableElement);
496
+ }
497
+ disconnectedCallback() {
498
+ delete this['_scene'];
499
+ delete this['_drawableParent'];
500
+ super.disconnectedCallback();
501
+ }
502
+ propertyChangedCallback(name, old, val, first) {
503
+ super.propertyChangedCallback(name, old, val, first);
504
+ if (!first) {
505
+ switch (name) {
506
+ case 'hide':
507
+ this.stage?.draw(this);
508
+ break;
509
+ }
510
+ }
511
+ }
512
+ }
513
+ __decorate$c([
514
+ pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.String })
515
+ ], DrawableElement.prototype, "tag", void 0);
516
+ __decorate$c([
517
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Boolean })
518
+ ], DrawableElement.prototype, "inert", void 0);
519
+
520
+ var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
521
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
522
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
523
+ 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;
524
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
525
+ };
526
+ //namespace Pacem.Components.Drawing {
527
+ const DEG2RAD = Math.PI / 180.0;
528
+ class UiElement extends DrawableElement {
529
+ #transformMatrix = pacemFoundation.Matrix2D.identity;
530
+ viewActivatedCallback() {
531
+ super.viewActivatedCallback();
532
+ this._updateTransformMatrix();
533
+ }
534
+ propertyChangedCallback(name, old, val, first) {
535
+ super.propertyChangedCallback(name, old, val, first);
536
+ if (!first) {
537
+ switch (name) {
538
+ case 'rotate':
539
+ case 'scaleX':
540
+ case 'scaleY':
541
+ case 'translateX':
542
+ case 'translateY':
543
+ this._updateTransformMatrix();
544
+ // flow down
545
+ case 'opacity':
546
+ this.stage?.draw(this);
547
+ break;
548
+ }
549
+ }
550
+ }
551
+ _updateTransformMatrix() {
552
+ let rotation = DEG2RAD * (this.rotate ?? 0), cos = Math.cos(rotation), sin = Math.sin(rotation), a = (this.scaleX ?? 1) * cos, b = -sin, c = sin, d = (this.scaleY ?? 1) * cos, e = this.translateX ?? 0, f = this.translateY ?? 0;
553
+ this.#transformMatrix = { a, b, c, d, e, f };
554
+ }
555
+ /** @internal */
556
+ get transformMatrix() {
557
+ const m = this.#transformMatrix;
558
+ return { a: m.a, b: m.b, c: m.c, d: m.d, e: m.e, f: m.f };
559
+ }
560
+ }
561
+ __decorate$b([
562
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
563
+ ], UiElement.prototype, "rotate", void 0);
564
+ __decorate$b([
565
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
566
+ ], UiElement.prototype, "scaleX", void 0);
567
+ __decorate$b([
568
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
569
+ ], UiElement.prototype, "scaleY", void 0);
570
+ __decorate$b([
571
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
572
+ ], UiElement.prototype, "translateX", void 0);
573
+ __decorate$b([
574
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
575
+ ], UiElement.prototype, "translateY", void 0);
576
+ __decorate$b([
577
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
578
+ ], UiElement.prototype, "opacity", void 0);
579
+ class PresentationElement extends UiElement {
580
+ propertyChangedCallback(name, old, val, first) {
581
+ super.propertyChangedCallback(name, old, val, first);
582
+ if (!first) {
583
+ switch (name) {
584
+ case 'stroke':
585
+ case 'lineWidth':
586
+ case 'lineJoin':
587
+ case 'lineCap':
588
+ case 'dashArray':
589
+ case 'fill':
590
+ if (!pacemCore.Utils.isNull(this.stage)) {
591
+ this.stage.draw(this);
592
+ }
593
+ break;
594
+ }
595
+ }
596
+ }
597
+ }
598
+ __decorate$b([
599
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
600
+ ], PresentationElement.prototype, "stroke", void 0);
601
+ __decorate$b([
602
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
603
+ ], PresentationElement.prototype, "fill", void 0);
604
+ __decorate$b([
605
+ pacemCore.Watch({
606
+ emit: false, converter: {
607
+ convert: (attr) => attr?.split(',').map(i => parseInt(i)).filter(i => !Number.isNaN(i)),
608
+ convertBack: (prop) => prop?.join(',')
609
+ }
610
+ })
611
+ ], PresentationElement.prototype, "dashArray", void 0);
612
+ __decorate$b([
613
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
614
+ ], PresentationElement.prototype, "lineWidth", void 0);
615
+ __decorate$b([
616
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
617
+ ], PresentationElement.prototype, "lineJoin", void 0);
618
+ __decorate$b([
619
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
620
+ ], PresentationElement.prototype, "lineCap", void 0);
621
+ class ShapeElement extends PresentationElement {
622
+ propertyChangedCallback(name, old, val, first) {
623
+ super.propertyChangedCallback(name, old, val, first);
624
+ if (!first) {
625
+ switch (name) {
626
+ case 'data':
627
+ this.stage?.draw(this);
628
+ break;
629
+ }
630
+ }
631
+ }
632
+ viewActivatedCallback() {
633
+ super.viewActivatedCallback();
634
+ this.recomputeShape();
635
+ }
636
+ recomputeShape() {
637
+ const { pathData, vertices, boundingRect } = this.getShapeGeometry();
638
+ this.#vertices = vertices;
639
+ this.#boundingRect = boundingRect;
640
+ this.data = pathData;
641
+ }
642
+ get pathData() {
643
+ return this.data;
644
+ }
645
+ #boundingRect;
646
+ get boundingRect() {
647
+ return this.#boundingRect;
648
+ }
649
+ #vertices;
650
+ get vertices() {
651
+ return this.#vertices;
652
+ }
653
+ }
654
+ __decorate$b([
655
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
656
+ ], ShapeElement.prototype, "data", void 0);
657
+
658
+ var __decorate$a = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
659
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
660
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
661
+ 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;
662
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
663
+ };
664
+ //namespace Pacem.Components.Drawing {
665
+ let PacemGroupElement = class PacemGroupElement extends PresentationElement {
666
+ validate(item) {
667
+ return item instanceof DrawableElement && item.parent === this;
668
+ }
669
+ #children = [];
670
+ get childDrawables() {
671
+ return this.#children;
672
+ }
673
+ propertyChangedCallback(name, old, val, first) {
674
+ super.propertyChangedCallback(name, old, val, first);
675
+ switch (name) {
676
+ case 'items':
677
+ case 'datasource':
678
+ this.#children = (val || []);
679
+ const scene = this.stage;
680
+ if (!pacemCore.Utils.isNull(scene)) {
681
+ scene.draw(this, true);
682
+ }
683
+ break;
684
+ }
685
+ }
686
+ };
687
+ __decorate$a([
688
+ pacemCore.Watch({ emit: false })
689
+ ], PacemGroupElement.prototype, "datasource", void 0);
690
+ PacemGroupElement = __decorate$a([
691
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-group' })
692
+ ], PacemGroupElement);
693
+
694
+ var __decorate$9 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
695
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
696
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
697
+ 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;
698
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
699
+ };
700
+ var PacemEllipseElement_1, PacemCircleElement_1;
701
+ //namespace Pacem.Components.Drawing {
702
+ function full(c, rx, ry) {
703
+ const d = 2 * rx, cx = c.x, cy = c.y;
704
+ return {
705
+ pathData: `M ${cx} ${cy} m ${-rx},0 a ${rx},${ry} 0 1,1 ${d},0 a ${rx},${ry} 0 1,1 ${-d},0`,
706
+ vertices: [],
707
+ boundingRect: { x: cx - rx, y: cy - ry, width: 2 * rx, height: 2 * ry }
708
+ };
709
+ }
710
+ function sect(c, rx, ry, start, end) {
711
+ const degToRad = Math.PI / 180;
712
+ const s = degToRad * start, e = degToRad * end;
713
+ //
714
+ const polar = (theta) => rx * ry / Math.sqrt(Math.pow(Math.cos(theta) * ry, 2) + Math.pow(Math.sin(theta) * rx, 2));
715
+ const rhoStart = polar(s), rhoEnd = polar(e);
716
+ const cartesian = (rho, theta) => {
717
+ return { x: rho * Math.cos(theta), y: rho * Math.sin(theta) };
718
+ };
719
+ const cartStart = cartesian(rhoStart, s), cartEnd = cartesian(rhoEnd, e);
720
+ const p0 = { x: c.x + cartStart.x, y: c.y + cartStart.y }, p1 = { x: c.x + cartEnd.x, y: c.y + cartEnd.y };
721
+ let boundingRect = pacemFoundation.Rect.expand(c, p0, p1);
722
+ if (end < start)
723
+ end += 360;
724
+ if (start <= 0 && end > 0 || end >= 360) {
725
+ boundingRect = pacemFoundation.Rect.expand(boundingRect, { x: c.x + rx, y: c.y });
726
+ }
727
+ if (start <= 90 && end > 90 || end >= 450) {
728
+ boundingRect = pacemFoundation.Rect.expand(boundingRect, { x: c.x, y: c.y + ry });
729
+ }
730
+ if (start <= 180 && end > 180 || end >= 540) {
731
+ boundingRect = pacemFoundation.Rect.expand(boundingRect, { x: c.x - rx, y: c.y });
732
+ }
733
+ if (start <= 270 && end > 270 || end >= 630) {
734
+ boundingRect = pacemFoundation.Rect.expand(boundingRect, { x: c.x, y: c.y - ry });
735
+ }
736
+ const flag = e - s > Math.PI ? '1' : '0';
737
+ return {
738
+ pathData: `M ${p0.x} ${p0.y} A ${rx},${ry} 0 ${flag},1 ${p1.x},${p1.y} L ${c.x},${c.y} Z`, vertices: [p0, p1], boundingRect
739
+ };
740
+ }
741
+ function getShapeGeometry(c, rx, ry, start, end) {
742
+ start ??= 0, end ??= 0;
743
+ start %= 360;
744
+ end %= 360;
745
+ while (start < 0)
746
+ start += 360;
747
+ while (end < start)
748
+ end += 360;
749
+ const threesixty = (start - end).isCloseTo(0);
750
+ return threesixty ? full(c, rx, ry) : sect(c, rx, ry, start, end);
751
+ }
752
+ let PacemEllipseElement = PacemEllipseElement_1 = class PacemEllipseElement extends ShapeElement {
753
+ propertyChangedCallback(name, old, val, first) {
754
+ super.propertyChangedCallback(name, old, val, first);
755
+ if (!first) {
756
+ switch (name) {
757
+ case 'center':
758
+ case 'rx':
759
+ case 'ry':
760
+ case 'start':
761
+ case 'end':
762
+ this.recomputeShape();
763
+ break;
764
+ }
765
+ }
766
+ }
767
+ getPathData() {
768
+ const a = this.rx, b = this.ry, c = this.center, s = this.start ?? 0, e = this.end ?? 0;
769
+ if (!pacemCore.Utils.isNull(c) && !pacemCore.Utils.isNull(a) && !pacemCore.Utils.isNull(b)) {
770
+ return PacemEllipseElement_1.getPathData(c, a, b, s, e);
771
+ }
772
+ return null;
773
+ }
774
+ getShapeGeometry() {
775
+ const center = this.center ?? { x: 0, y: 0 };
776
+ const a = this.rx ?? 0, b = this.ry ?? 0;
777
+ return getShapeGeometry(center, a, b, this.start, this.end);
778
+ }
779
+ static getPathData(c = { x: NaN, y: NaN }, rx = NaN, ry = NaN, start, end) {
780
+ const { pathData } = getShapeGeometry(c, rx, ry, start, end);
781
+ return pathData;
782
+ }
783
+ };
784
+ __decorate$9([
785
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Point })
786
+ ], PacemEllipseElement.prototype, "center", void 0);
787
+ __decorate$9([
788
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
789
+ ], PacemEllipseElement.prototype, "rx", void 0);
790
+ __decorate$9([
791
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
792
+ ], PacemEllipseElement.prototype, "ry", void 0);
793
+ __decorate$9([
794
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
795
+ ], PacemEllipseElement.prototype, "start", void 0);
796
+ __decorate$9([
797
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
798
+ ], PacemEllipseElement.prototype, "end", void 0);
799
+ PacemEllipseElement = PacemEllipseElement_1 = __decorate$9([
800
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-ellipse' })
801
+ ], PacemEllipseElement);
802
+ let PacemCircleElement = PacemCircleElement_1 = class PacemCircleElement extends ShapeElement {
803
+ propertyChangedCallback(name, old, val, first) {
804
+ super.propertyChangedCallback(name, old, val, first);
805
+ if (!first) {
806
+ switch (name) {
807
+ case 'center':
808
+ case 'radius':
809
+ case 'start':
810
+ case 'end':
811
+ this.recomputeShape();
812
+ break;
813
+ }
814
+ }
815
+ }
816
+ getPathData() {
817
+ const r = this.radius, c = this.center;
818
+ if (!pacemCore.Utils.isNull(c) && !pacemCore.Utils.isNull(r)) {
819
+ return PacemCircleElement_1.getPathData(c, r, this.start, this.end);
820
+ }
821
+ return null;
822
+ }
823
+ getShapeGeometry() {
824
+ const center = this.center ?? { x: 0, y: 0 };
825
+ const r = this.radius ?? 0;
826
+ return getShapeGeometry(center, r, r, this.start, this.end);
827
+ }
828
+ static getPathData(c = { x: NaN, y: NaN }, r = NaN, start, end) {
829
+ return PacemEllipseElement.getPathData(c, r, r, start, end);
830
+ }
831
+ };
832
+ __decorate$9([
833
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Point })
834
+ ], PacemCircleElement.prototype, "center", void 0);
835
+ __decorate$9([
836
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
837
+ ], PacemCircleElement.prototype, "radius", void 0);
838
+ __decorate$9([
839
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
840
+ ], PacemCircleElement.prototype, "start", void 0);
841
+ __decorate$9([
842
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
843
+ ], PacemCircleElement.prototype, "end", void 0);
844
+ PacemCircleElement = PacemCircleElement_1 = __decorate$9([
845
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-circle' })
846
+ ], PacemCircleElement);
847
+
848
+ var __decorate$8 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
849
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
850
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
851
+ 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;
852
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
853
+ };
854
+ var PacemRectElement_1;
855
+ //namespace Pacem.Components.Drawing {
856
+ /*
857
+ r="4" // every corner has a rx equalt o ry equal to 8 units
858
+ r="4,8 cut" // every corner has a rx equal to 4px and a ry equal to 8px (cut corners)
859
+ r="4,8 cut 5,6 3,20% round 50%,4" // top-left corner has a rx equal to 4px and a ry equal to 8px (cut corner), top-right corner has a rx equal to 5px and a ry equal to 6px,
860
+ // bottom-right corner has a rx equal to 3px and a ry equal to 20% the height,
861
+ // bottom-left corner has a rx equal to 50% the width and a ry equal to 4px.
862
+
863
+ */
864
+ function parseCornerRadius(radius) {
865
+ const rx = radius[2], ry = radius[4] ?? rx, type = radius[6] === 'cut' ? CornerType.Cut : CornerType.Rounded;
866
+ return { rx: parseCornerRadiusComponent(rx), ry: parseCornerRadiusComponent(ry), type };
867
+ }
868
+ function parseCornerRadiusComponent(radius) {
869
+ const val = parseFloat(radius);
870
+ return { value: val, unit: radius.endsWith('%') ? 'pct' : 'u' };
871
+ }
872
+ function stringifyCornerRadiusComponent(radius) {
873
+ return `${radius.value}${radius.unit === 'pct' ? '%' : ''}`;
874
+ }
875
+ const CORNERS_PATTERN = /(([\d\.]+%?)(\s*,?\s*([\d\.]+%?))?(\s+(cut|round))?)/g;
876
+ function parseCornerRadii(radii) {
877
+ let numbers;
878
+ const acc = [];
879
+ while (numbers = CORNERS_PATTERN.exec(radii)) {
880
+ acc.push(numbers);
881
+ }
882
+ switch (acc.length) {
883
+ case 1:
884
+ const single = parseCornerRadius(acc[0]);
885
+ return [single, single, single, single];
886
+ case 4:
887
+ const topLeft = parseCornerRadius(acc[0]);
888
+ const topRight = parseCornerRadius(acc[1]);
889
+ const bottomRight = parseCornerRadius(acc[2]);
890
+ const bottomLeft = parseCornerRadius(acc[3]);
891
+ return [topLeft, topRight, bottomRight, bottomLeft];
892
+ default:
893
+ return null;
894
+ }
895
+ }
896
+ function stringifyCornerRadii(radii) {
897
+ const topLeft = radii[0], topRight = radii[1], bottomRight = radii[2], bottomLeft = radii[3];
898
+ const tlX = stringifyCornerRadiusComponent(topLeft.rx), tlY = stringifyCornerRadiusComponent(topLeft.ry);
899
+ const trX = stringifyCornerRadiusComponent(topRight.rx), trY = stringifyCornerRadiusComponent(topRight.ry);
900
+ const brX = stringifyCornerRadiusComponent(bottomRight.rx), brY = stringifyCornerRadiusComponent(bottomRight.ry);
901
+ const blX = stringifyCornerRadiusComponent(bottomLeft.rx), blY = stringifyCornerRadiusComponent(bottomLeft.ry);
902
+ return `${tlX},${tlY} ${trX},${trY} ${brX},${brY} ${blX},${blY}`;
903
+ }
904
+ var CornerType;
905
+ (function (CornerType) {
906
+ CornerType["Rounded"] = "rounded";
907
+ CornerType["Cut"] = "cut";
908
+ })(CornerType || (CornerType = {}));
909
+ let PacemRectElement = PacemRectElement_1 = class PacemRectElement extends ShapeElement {
910
+ propertyChangedCallback(name, old, val, first) {
911
+ super.propertyChangedCallback(name, old, val, first);
912
+ if (!first && (name === 'x' || name === 'y' || name === 'w' || name === 'h' || name === 'r' || name === 'cornerType')) {
913
+ this.recomputeShape();
914
+ }
915
+ }
916
+ getPathData() {
917
+ const x = this.x, y = this.y, w = this.w, h = this.h;
918
+ let r = this.r ?? { rx: { value: 0 }, ry: { value: 0 }, type: CornerType.Rounded };
919
+ if (!pacemCore.Utils.isArray(r)) {
920
+ r = [r, r, r, r];
921
+ }
922
+ // forgiving behavior
923
+ r = r.map(i => { return typeof i === 'number' ? { rx: { value: i }, ry: { value: i }, type: this.cornerType } : i; });
924
+ if (!pacemCore.Utils.isNull(x) && !pacemCore.Utils.isNull(y) && !pacemCore.Utils.isNull(w) && !pacemCore.Utils.isNull(h)) {
925
+ return PacemRectElement_1.getPathData(x, y, w, h, r);
926
+ }
927
+ return null;
928
+ }
929
+ getShapeGeometry() {
930
+ const x = this.x, y = this.y, x1 = x + this.w, y1 = y + this.h;
931
+ return {
932
+ pathData: this.getPathData(), vertices: [{ x, y }, { x: x1, y }, { x: x1, y: y1 }, { x, y: y1 }], boundingRect: { x, y, width: this.w, height: this.h }
933
+ };
934
+ }
935
+ static getPathData(x = NaN, y = NaN, w = NaN, h = NaN, r = null) {
936
+ if (!r) {
937
+ return `M ${x} ${y} h ${w} v ${h} h ${-w} z`;
938
+ }
939
+ if (!pacemCore.Utils.isArray(r)) {
940
+ r = [r, r, r, r];
941
+ }
942
+ const tl = r[0], tr = r[1], br = r[2], bl = r[3];
943
+ const vx = (rx) => rx.unit === 'pct' ? rx.value * .01 * w : rx.value;
944
+ const vy = (ry) => ry.unit === 'pct' ? ry.value * .01 * h : ry.value;
945
+ const tlX = vx(tl.rx), tlY = vy(tl.ry);
946
+ const trX = vx(tr.rx), trY = vy(tr.ry);
947
+ const brX = vx(br.rx), brY = vy(br.ry);
948
+ const blX = vx(bl.rx), blY = vy(bl.ry);
949
+ let retval = `M ${x},${y + tlY}`;
950
+ // top-left
951
+ switch (tl.type) {
952
+ case 'cut':
953
+ retval += ` l ${tlX},${-tlY}`;
954
+ break;
955
+ default:
956
+ retval += ` a ${tlX} ${tlY} 0 0 1 ${tlX} ${-tlY}`;
957
+ break;
958
+ }
959
+ retval += ` h ${w - tlX - trX}`;
960
+ // top-right
961
+ switch (tr.type) {
962
+ case 'cut':
963
+ retval += ` l ${trX},${trY}`;
964
+ break;
965
+ default:
966
+ retval += ` a ${trX} ${trY} 0 0 1 ${trX} ${trY}`;
967
+ break;
968
+ }
969
+ retval += ` v ${h - trY - brY}`;
970
+ // bottom-right
971
+ switch (br.type) {
972
+ case 'cut':
973
+ retval += ` l ${-brX},${brY}`;
974
+ break;
975
+ default:
976
+ retval += ` a ${brX} ${brY} 0 0 1 ${-brX} ${brY}`;
977
+ break;
978
+ }
979
+ retval += ` h ${-(w - brX - blX)}`;
980
+ // bottom-left
981
+ switch (bl.type) {
982
+ case 'cut':
983
+ retval += ` l ${-blX},${-blY}`;
984
+ break;
985
+ default:
986
+ retval += ` a ${blX} ${blY} 0 0 1 ${-blX} ${-blY}`;
987
+ break;
988
+ }
989
+ return retval + ' z';
990
+ }
991
+ };
992
+ __decorate$8([
993
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
994
+ ], PacemRectElement.prototype, "x", void 0);
995
+ __decorate$8([
996
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
997
+ ], PacemRectElement.prototype, "y", void 0);
998
+ __decorate$8([
999
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1000
+ ], PacemRectElement.prototype, "w", void 0);
1001
+ __decorate$8([
1002
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1003
+ ], PacemRectElement.prototype, "h", void 0);
1004
+ __decorate$8([
1005
+ pacemCore.Watch({
1006
+ emit: false, converter: {
1007
+ convert: attr => parseCornerRadii(attr),
1008
+ convertBack: (radii) => stringifyCornerRadii(radii)
1009
+ }
1010
+ })
1011
+ ], PacemRectElement.prototype, "r", void 0);
1012
+ __decorate$8([
1013
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1014
+ ], PacemRectElement.prototype, "cornerType", void 0);
1015
+ PacemRectElement = PacemRectElement_1 = __decorate$8([
1016
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-rect' })
1017
+ ], PacemRectElement);
1018
+
1019
+ var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1020
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1021
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1022
+ 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;
1023
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1024
+ };
1025
+ var PacemLineElement_1;
1026
+ //namespace Pacem.Components.Drawing {
1027
+ let PacemLineElement = PacemLineElement_1 = class PacemLineElement extends ShapeElement {
1028
+ propertyChangedCallback(name, old, val, first) {
1029
+ super.propertyChangedCallback(name, old, val, first);
1030
+ if (!first) {
1031
+ switch (name) {
1032
+ case 'from':
1033
+ case 'to':
1034
+ this.recomputeShape();
1035
+ break;
1036
+ }
1037
+ }
1038
+ }
1039
+ getShapeGeometry() {
1040
+ const from = this.from, to = this.to;
1041
+ if (pacemCore.Utils.isNull(from) || pacemCore.Utils.isNull(to)) {
1042
+ return Shape.empty();
1043
+ }
1044
+ const x0 = from.x, y0 = from.y, x1 = to.x, y1 = to.y;
1045
+ const boundingRect = { x: Math.min(x0, x1), y: Math.min(y0, y1), width: Math.abs(x0 - x1), height: Math.abs(y0 - y1) };
1046
+ return { pathData: this.getPathData(), vertices: [from, to], boundingRect };
1047
+ }
1048
+ getPathData() {
1049
+ const from = this.from, to = this.to;
1050
+ if (!pacemCore.Utils.isNull(from) && !pacemCore.Utils.isNull(to)) {
1051
+ return PacemLineElement_1.getPathData(from, to);
1052
+ }
1053
+ return null;
1054
+ }
1055
+ static getPathData(from = { x: NaN, y: NaN }, to = { x: NaN, y: NaN }) {
1056
+ const x0 = from.x, y0 = from.y, x1 = to.x, y1 = to.y;
1057
+ return `M ${x0} ${y0} L ${x1} ${y1}`;
1058
+ }
1059
+ };
1060
+ __decorate$7([
1061
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Point })
1062
+ ], PacemLineElement.prototype, "from", void 0);
1063
+ __decorate$7([
1064
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Point })
1065
+ ], PacemLineElement.prototype, "to", void 0);
1066
+ PacemLineElement = PacemLineElement_1 = __decorate$7([
1067
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-line' })
1068
+ ], PacemLineElement);
1069
+
1070
+ var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1071
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1072
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1073
+ 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;
1074
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1075
+ };
1076
+ //namespace Pacem.Components.Drawing {
1077
+ let PacemPathElement = class PacemPathElement extends ShapeElement {
1078
+ constructor() {
1079
+ super(...arguments);
1080
+ this.getPathData = () => this.d;
1081
+ }
1082
+ propertyChangedCallback(name, old, val, first) {
1083
+ super.propertyChangedCallback(name, old, val, first);
1084
+ if (name === 'd' && !first) {
1085
+ this.recomputeShape();
1086
+ }
1087
+ }
1088
+ getShapeGeometry() {
1089
+ return { pathData: this.getPathData(), /* TODO: parse d */ boundingRect: null, vertices: [] };
1090
+ }
1091
+ };
1092
+ __decorate$6([
1093
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1094
+ ], PacemPathElement.prototype, "d", void 0);
1095
+ PacemPathElement = __decorate$6([
1096
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-path' })
1097
+ ], PacemPathElement);
1098
+
1099
+ var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1100
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1101
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1102
+ 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;
1103
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1104
+ };
1105
+ var PacemPolygonElement_1;
1106
+ //namespace Pacem.Components.Drawing {
1107
+ let PacemPolygonElement = PacemPolygonElement_1 = class PacemPolygonElement extends ShapeElement {
1108
+ propertyChangedCallback(name, old, val, first) {
1109
+ super.propertyChangedCallback(name, old, val, first);
1110
+ if (!first) {
1111
+ switch (name) {
1112
+ case 'radius':
1113
+ case 'starIndent':
1114
+ case 'sides':
1115
+ this.recomputeShape();
1116
+ break;
1117
+ }
1118
+ }
1119
+ }
1120
+ getPathData() {
1121
+ const sides = this.sides, radius = this.radius, center = this.center;
1122
+ if (!pacemCore.Utils.isNull(sides) && !pacemCore.Utils.isNull(radius)) {
1123
+ return PacemPolygonElement_1.getPathData(center, radius, sides, this.starIndent);
1124
+ }
1125
+ return null;
1126
+ }
1127
+ getShapeGeometry() {
1128
+ const c = this.center ?? { x: 0, y: 0 }, r = this.radius ?? 0, sides = this.sides ?? 3, si = this.starIndent;
1129
+ if (sides < 3) {
1130
+ return Shape.empty();
1131
+ }
1132
+ return PacemPolygonElement_1.getShapeGeometry(c, r, sides, si);
1133
+ }
1134
+ static getShapeGeometry(center, radius, sides, starIndent = .0) {
1135
+ const p0 = { x: center.x, y: center.y - radius };
1136
+ let retval = `M ${p0.x} ${(p0.y)}`;
1137
+ const vertices = [p0];
1138
+ const theta = 2 * Math.PI / sides, theta2 = .5 * theta, isStar = starIndent > 0, apothem = radius * Math.cos(theta2);
1139
+ for (let j = 1; j < sides; j++) {
1140
+ const angle = j * theta, x = center.x + Math.sin(angle) * radius, y = center.y - Math.cos(angle) * radius;
1141
+ if (isStar) {
1142
+ const innerRadius = apothem * (1.0 - starIndent);
1143
+ const angle2 = angle - theta2, x1 = center.x + Math.sin(angle2) * innerRadius, y1 = center.y - Math.cos(angle2) * innerRadius;
1144
+ retval += ` L ${x1} ${y1} L ${x} ${y}`;
1145
+ vertices.push({ x: x1, y: y1 });
1146
+ }
1147
+ else {
1148
+ retval += ` L ${x} ${y}`;
1149
+ }
1150
+ vertices.push({ x, y });
1151
+ }
1152
+ if (isStar) {
1153
+ const innerRadius = apothem * (1.0 - starIndent);
1154
+ const angle2 = 2 * Math.PI - theta2, x1 = center.x + Math.sin(angle2) * innerRadius, y1 = center.y - Math.cos(angle2) * innerRadius;
1155
+ retval += ` L ${x1} ${y1}`;
1156
+ vertices.push({ x: x1, y: y1 });
1157
+ }
1158
+ vertices.push(p0);
1159
+ const width = radius * 2;
1160
+ return {
1161
+ pathData: retval + ' Z', vertices, boundingRect: { x: p0.x - radius, y: p0.y, width, height: width }
1162
+ };
1163
+ }
1164
+ static getPathData(center, radius, sides, starIndent = .0) {
1165
+ const { pathData } = PacemPolygonElement_1.getShapeGeometry(center, radius, sides, starIndent);
1166
+ return pathData;
1167
+ }
1168
+ };
1169
+ __decorate$5([
1170
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1171
+ ], PacemPolygonElement.prototype, "sides", void 0);
1172
+ __decorate$5([
1173
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1174
+ ], PacemPolygonElement.prototype, "radius", void 0);
1175
+ __decorate$5([
1176
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Point })
1177
+ ], PacemPolygonElement.prototype, "center", void 0);
1178
+ __decorate$5([
1179
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1180
+ ], PacemPolygonElement.prototype, "starIndent", void 0);
1181
+ PacemPolygonElement = PacemPolygonElement_1 = __decorate$5([
1182
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-polygon' })
1183
+ ], PacemPolygonElement);
1184
+
1185
+ var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1186
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1187
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1188
+ 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;
1189
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1190
+ };
1191
+ var PacemPolylineElement_1;
1192
+ //namespace Pacem.Components.Drawing {
1193
+ const PointArrayOrJsonConverter = {
1194
+ convert: (attr) => {
1195
+ const arr = pacemFoundation.parseAsNumericalArray(attr);
1196
+ if (arr.length % 2 === 0) {
1197
+ const retval = [];
1198
+ for (let j = 0; j < arr.length; j += 2) {
1199
+ retval.push({ x: arr[j], y: arr[j + 1] });
1200
+ }
1201
+ return retval;
1202
+ }
1203
+ return JSON.parse(attr);
1204
+ },
1205
+ convertBack: (prop) => JSON.stringify(prop)
1206
+ };
1207
+ let PacemPolylineElement = PacemPolylineElement_1 = class PacemPolylineElement extends ShapeElement {
1208
+ propertyChangedCallback(name, old, val, first) {
1209
+ super.propertyChangedCallback(name, old, val, first);
1210
+ if (!first) {
1211
+ switch (name) {
1212
+ case 'points':
1213
+ case 'closed':
1214
+ this.recomputeShape();
1215
+ break;
1216
+ }
1217
+ }
1218
+ }
1219
+ static getShapeGeometry(points, closed) {
1220
+ if (pacemCore.Utils.isNullOrEmpty(points)) {
1221
+ return Shape.empty();
1222
+ }
1223
+ let d = '';
1224
+ let xmin = Number.MAX_VALUE, ymin = Number.MAX_VALUE, xmax = Number.MIN_VALUE, ymax = Number.MIN_VALUE;
1225
+ for (let j = 0; j < points.length; j++) {
1226
+ const { x, y } = points[j];
1227
+ d += `${(j === 0 ? 'M' : 'L')} ${x} ${y} `;
1228
+ xmin = Math.min(xmin, x);
1229
+ xmax = Math.max(xmax, x);
1230
+ ymin = Math.min(ymin, y);
1231
+ ymax = Math.max(ymax, y);
1232
+ }
1233
+ const boundingRect = { x: xmin, y: ymin, width: xmax - xmin, height: ymax - ymin };
1234
+ if (closed) {
1235
+ d += 'Z';
1236
+ }
1237
+ return { pathData: d, vertices: points, boundingRect };
1238
+ }
1239
+ getShapeGeometry() {
1240
+ return PacemPolylineElement_1.getShapeGeometry(this.points, this.closed);
1241
+ }
1242
+ getPathData() {
1243
+ const { pathData } = this.getShapeGeometry();
1244
+ return pathData;
1245
+ }
1246
+ static getPathData(points, closed) {
1247
+ const { pathData } = PacemPolylineElement_1.getShapeGeometry(points, closed);
1248
+ return pathData;
1249
+ }
1250
+ };
1251
+ __decorate$4([
1252
+ pacemCore.Watch({ emit: false, converter: PointArrayOrJsonConverter })
1253
+ ], PacemPolylineElement.prototype, "points", void 0);
1254
+ __decorate$4([
1255
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Boolean })
1256
+ ], PacemPolylineElement.prototype, "closed", void 0);
1257
+ PacemPolylineElement = PacemPolylineElement_1 = __decorate$4([
1258
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-polyline' })
1259
+ ], PacemPolylineElement);
1260
+
1261
+ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1262
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1263
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1264
+ 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;
1265
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1266
+ };
1267
+ //namespace Pacem.Components.Drawing {
1268
+ let PacemImageElement = class PacemImageElement extends UiElement {
1269
+ propertyChangedCallback(name, old, val, first) {
1270
+ super.propertyChangedCallback(name, old, val, first);
1271
+ if (!first) {
1272
+ switch (name) {
1273
+ case 'src':
1274
+ case 'x':
1275
+ case 'y':
1276
+ case 'width':
1277
+ case 'height':
1278
+ this.stage?.draw(this);
1279
+ break;
1280
+ }
1281
+ }
1282
+ }
1283
+ };
1284
+ __decorate$3([
1285
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1286
+ ], PacemImageElement.prototype, "src", void 0);
1287
+ __decorate$3([
1288
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1289
+ ], PacemImageElement.prototype, "x", void 0);
1290
+ __decorate$3([
1291
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1292
+ ], PacemImageElement.prototype, "y", void 0);
1293
+ __decorate$3([
1294
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1295
+ ], PacemImageElement.prototype, "width", void 0);
1296
+ __decorate$3([
1297
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1298
+ ], PacemImageElement.prototype, "height", void 0);
1299
+ PacemImageElement = __decorate$3([
1300
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-image' })
1301
+ ], PacemImageElement);
1302
+
1303
+ var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1304
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1305
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1306
+ 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;
1307
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1308
+ };
1309
+ //namespace Pacem.Components.Drawing {
1310
+ let PacemTextElement = class PacemTextElement extends UiElement {
1311
+ propertyChangedCallback(name, old, val, first) {
1312
+ if (!first) {
1313
+ switch (name) {
1314
+ case 'text':
1315
+ case 'color':
1316
+ case 'fontFamily':
1317
+ case 'fontSize':
1318
+ case 'fontWeight':
1319
+ case 'fontStyle':
1320
+ case 'anchor':
1321
+ if (!pacemCore.Utils.isNull(this.stage)) {
1322
+ this.stage.draw(this);
1323
+ }
1324
+ break;
1325
+ }
1326
+ }
1327
+ }
1328
+ };
1329
+ __decorate$2([
1330
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1331
+ ], PacemTextElement.prototype, "text", void 0);
1332
+ __decorate$2([
1333
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1334
+ ], PacemTextElement.prototype, "color", void 0);
1335
+ __decorate$2([
1336
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1337
+ ], PacemTextElement.prototype, "fontFamily", void 0);
1338
+ __decorate$2([
1339
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Number })
1340
+ ], PacemTextElement.prototype, "fontSize", void 0);
1341
+ __decorate$2([
1342
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1343
+ ], PacemTextElement.prototype, "fontWeight", void 0);
1344
+ __decorate$2([
1345
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1346
+ ], PacemTextElement.prototype, "fontStyle", void 0);
1347
+ __decorate$2([
1348
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Point })
1349
+ ], PacemTextElement.prototype, "anchor", void 0);
1350
+ __decorate$2([
1351
+ pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.String })
1352
+ ], PacemTextElement.prototype, "textAnchor", void 0);
1353
+ PacemTextElement = __decorate$2([
1354
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-text' })
1355
+ ], PacemTextElement);
1356
+
1357
+ //namespace Pacem.Components.Drawing {
1358
+ class AdapterUtils {
1359
+ static stageDispatch(stage, type, evt) {
1360
+ if (stage instanceof EventTarget) {
1361
+ stage.dispatchEvent(new StageEvent('stage' + type, stage, evt, stage.transformMatrix));
1362
+ }
1363
+ }
1364
+ static isValidViewbox(viewbox) {
1365
+ return !pacemCore.Utils.isNullOrEmpty(viewbox) && pacemFoundation.Rect.isRect(viewbox) && Number.isFinite(viewbox.x) // isFinite includes NaN check
1366
+ && Number.isFinite(viewbox.y) && Number.isFinite(viewbox.width) && Number.isFinite(viewbox.height);
1367
+ }
1368
+ static itemDispatch(target, type, offset) {
1369
+ if (pacemCore.Utils.isNull(target?.stage)) {
1370
+ return false;
1371
+ }
1372
+ var dragArgs, originalEvent, evtType;
1373
+ if (offset instanceof Event) {
1374
+ originalEvent = offset;
1375
+ }
1376
+ else {
1377
+ dragArgs = { item: target, offset: offset };
1378
+ }
1379
+ if (typeof type === 'string') {
1380
+ evtType = type;
1381
+ }
1382
+ else {
1383
+ evtType = type.type;
1384
+ originalEvent = type.originalEvent;
1385
+ }
1386
+ const m = target.stage.transformMatrix;
1387
+ const evt = () => offset instanceof Event
1388
+ ? new DrawableEvent(evtType, target, originalEvent, m)
1389
+ : new DragEvent(evtType, { detail: dragArgs, cancelable: evtType === pacemCore.UI.DragDropEventType.Init || evtType === pacemCore.UI.DragDropEventType.Drag }, originalEvent, m);
1390
+ const itemevt = offset instanceof Event
1391
+ ? new DrawableEvent('item' + evtType, target, originalEvent, m)
1392
+ : new DragEvent('item' + evtType, { detail: dragArgs, cancelable: evtType === pacemCore.UI.DragDropEventType.Init || evtType === pacemCore.UI.DragDropEventType.Drag }, originalEvent, m);
1393
+ var prevent = false;
1394
+ if (target instanceof EventTarget) {
1395
+ const evnt = evt();
1396
+ target.dispatchEvent(evnt);
1397
+ prevent = evnt.defaultPrevented;
1398
+ }
1399
+ target.stage.dispatchEvent(itemevt);
1400
+ // was the event (in one of its forms) rejected?
1401
+ return prevent || itemevt.defaultPrevented;
1402
+ }
1403
+ }
1404
+
1405
+ const JPEG_QUALITY = .9;
1406
+ class Pacem2DAdapterElement extends pacemCore.PacemEventTarget {
1407
+ constructor() {
1408
+ super(...arguments);
1409
+ this.DefaultShapeValues = {
1410
+ stroke: "#000",
1411
+ lineWidth: 1,
1412
+ fill: "#fff"
1413
+ };
1414
+ }
1415
+ snapshotElement(element, bgColor, type, quality) {
1416
+ const jpeg = !pacemCore.Utils.isNullOrEmpty(bgColor), mime = type ?? (jpeg ? 'image/jpeg' : null), compression = quality ?? (jpeg ? JPEG_QUALITY : null);
1417
+ return pacemCore.Utils.snapshotElement(element, bgColor, mime, compression);
1418
+ }
1419
+ }
1420
+
1421
+ var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
1422
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1423
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1424
+ 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;
1425
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1426
+ };
1427
+ //namespace Pacem.Components.Drawing {
1428
+ const CANVAS_SCENE_VAR = 'pacem:2d-canvas-scene';
1429
+ const PARENT_MATRIX_VAR = 'pacem:2d-parent-matrix';
1430
+ const WORLD_MATRIX_VAR = 'pacem:2d-world-matrix';
1431
+ const SETVAR$1 = pacemCore.CustomElementUtils.setAttachedPropertyValue, GETVAR$1 = pacemCore.CustomElementUtils.getAttachedPropertyValue;
1432
+ function isNone(fillOrStroke) {
1433
+ return fillOrStroke === 'none' || pacemCore.Utils.isNullOrEmpty(fillOrStroke);
1434
+ }
1435
+ function fallback$1(v, f) {
1436
+ return pacemCore.Utils.isNull(v) ? f : v;
1437
+ }
1438
+ /** Implementation postponed. Focus on SVG adapter. */
1439
+ let PacemCanvasAdapterElement = class PacemCanvasAdapterElement extends Pacem2DAdapterElement {
1440
+ constructor() {
1441
+ super(...arguments);
1442
+ this._pointer = {
1443
+ page: { x: Number.NaN, y: Number.NaN }, screen: { x: Number.NaN, y: Number.NaN }, client: { x: Number.NaN, y: Number.NaN }
1444
+ };
1445
+ this._dragInitHandler = (evt) => {
1446
+ const hitTarget = this._hitTarget;
1447
+ if (pacemCore.Utils.isNull(hitTarget) || !isUiObject(hitTarget) || !hitTarget.draggable) {
1448
+ evt.preventDefault();
1449
+ return;
1450
+ }
1451
+ const args = evt.detail, drawable = hitTarget, initialMatrix = hitTarget.transformMatrix ?? pacemFoundation.Matrix2D.identity, parentMatrix = GETVAR$1(hitTarget, PARENT_MATRIX_VAR, pacemFoundation.Matrix2D.identity);
1452
+ args.data = {
1453
+ item: drawable,
1454
+ initialTransformMatrix: initialMatrix,
1455
+ parentMatrix
1456
+ };
1457
+ const reject = AdapterUtils.itemDispatch(drawable, evt, { x: 0, y: 0 });
1458
+ if (reject) {
1459
+ // reject dragging
1460
+ evt.preventDefault();
1461
+ }
1462
+ };
1463
+ this._draggingHandler = (evt) => {
1464
+ pacemCore.avoidHandler(evt);
1465
+ this._dragging = true;
1466
+ const args = evt.detail;
1467
+ const data = args.data;
1468
+ const screenOffset = { x: args.currentPosition.x - args.origin.x, y: args.currentPosition.y - args.origin.y };
1469
+ const offset = {
1470
+ x: screenOffset.x * data.parentMatrix.a + data.initialTransformMatrix.e,
1471
+ y: screenOffset.y * data.parentMatrix.d + data.initialTransformMatrix.f
1472
+ };
1473
+ //console.log(`current pos: ${args.currentPosition.x},${args.currentPosition.y}`);
1474
+ //console.log(`origin pos: ${args.origin.x},${args.origin.y}`);
1475
+ //console.log(`screen offset: ${screenOffset.x},${screenOffset.y}`);
1476
+ //console.log(`offset: ${offset.x},${offset.y}`);
1477
+ //console.log(data.item.transformMatrix);
1478
+ //console.log(GETVAR(data.item, PARENT_MATRIX_VAR));
1479
+ //console.log(GETVAR(data.item, WORLD_MATRIX_VAR));
1480
+ //console.log(data.initialTransformMatrix);
1481
+ const stageTransformMatrix = data.item.stage.transformMatrix;
1482
+ const rejected = AdapterUtils.itemDispatch(data.item, evt, { x: screenOffset.x * stageTransformMatrix.a + stageTransformMatrix.e, y: screenOffset.y * stageTransformMatrix.d + stageTransformMatrix.f });
1483
+ if (!rejected) {
1484
+ if (data.item instanceof UiElement) {
1485
+ data.item.translateX = offset.x;
1486
+ data.item.translateY = offset.y;
1487
+ }
1488
+ else {
1489
+ const init = data.initialTransformMatrix, actual = { a: init.a, b: init.b, c: init.c, d: init.d, e: offset.x, f: offset.y };
1490
+ pacemCore.Utils.extend(data.item, { transformMatrix: actual });
1491
+ }
1492
+ // console.log(data.item.transformMatrix);
1493
+ }
1494
+ };
1495
+ this._dragEndHandler = (evt) => {
1496
+ this._dragging = false;
1497
+ const args = evt.detail, data = args.data, transform = data.item.transformMatrix;
1498
+ AdapterUtils.itemDispatch(data.item, evt, { x: transform.e, y: transform.f });
1499
+ };
1500
+ // #endregion
1501
+ this._mouseleaveHandler = (evt) => {
1502
+ if (this._dragging) {
1503
+ return;
1504
+ }
1505
+ const hitTarget = this._hitTarget;
1506
+ if (pacemCore.Utils.isNull(hitTarget)) {
1507
+ return;
1508
+ }
1509
+ this._scopeEvent = evt;
1510
+ const nap = { x: Number.NaN, y: Number.NaN };
1511
+ this._pointer = { page: nap, screen: nap, client: nap };
1512
+ const canvas = evt.srcElement;
1513
+ const stage = GETVAR$1(canvas, CANVAS_SCENE_VAR);
1514
+ this._requestDraw(stage);
1515
+ };
1516
+ this._mousemoveHandler = (evt) => {
1517
+ this._scopeEvent = evt;
1518
+ this._pointer = pacemCore.CustomEventUtils.getEventCoordinates(evt);
1519
+ const canvas = evt.srcElement;
1520
+ const stage = GETVAR$1(canvas, CANVAS_SCENE_VAR);
1521
+ this._requestDraw(stage);
1522
+ if (!this._dragging) {
1523
+ if (!pacemCore.Utils.isNull(this._hitTarget)) {
1524
+ AdapterUtils.stageDispatch(stage, 'move', evt);
1525
+ }
1526
+ }
1527
+ };
1528
+ this._mouseDownUpHandler = (evt) => {
1529
+ this._scopeEvent = evt;
1530
+ this._pointer = pacemCore.CustomEventUtils.getEventCoordinates(evt);
1531
+ const canvas = evt.target;
1532
+ if (canvas instanceof HTMLCanvasElement) {
1533
+ const stage = GETVAR$1(canvas, CANVAS_SCENE_VAR), hitTarget = this._hitTarget;
1534
+ const type = evt.type.replace(/^(mouse|touch)/, ''), fineType = type === 'end' ? 'click' : type;
1535
+ const opts = getStageOptions(stage);
1536
+ if (pacemCore.CustomEventUtils.matchModifiers(evt, opts.clickModifiers)) {
1537
+ if (!pacemCore.Utils.isNull(hitTarget) && hitTarget.stage === stage) {
1538
+ AdapterUtils.itemDispatch(hitTarget, fineType, evt);
1539
+ }
1540
+ else {
1541
+ AdapterUtils.stageDispatch(stage, fineType, evt);
1542
+ }
1543
+ }
1544
+ }
1545
+ };
1546
+ this._scenes = new WeakMap();
1547
+ this._handles = new WeakMap();
1548
+ }
1549
+ snapshot(stage, backgroundColor, type, quality) {
1550
+ const scenes = this._scenes;
1551
+ if (scenes.has(stage)) {
1552
+ const ctx2d = scenes.get(stage).context, srcCanvas = ctx2d.canvas;
1553
+ return this.snapshotElement(srcCanvas, backgroundColor, type, quality);
1554
+ }
1555
+ else {
1556
+ return Promise.resolve(null);
1557
+ }
1558
+ }
1559
+ getCanvas(stage) {
1560
+ const scenes = this._scenes;
1561
+ if (scenes.has(stage)) {
1562
+ const ctx2d = scenes.get(stage).context;
1563
+ return ctx2d.canvas;
1564
+ }
1565
+ else {
1566
+ return null;
1567
+ }
1568
+ }
1569
+ _getScreenInverseMatrix(m, offset) {
1570
+ return pacemFoundation.Matrix2D.invert({ a: m.a, b: m.b, c: m.c, d: m.d, e: m.e + offset.x, f: m.f + offset.y });
1571
+ }
1572
+ getTransformMatrix(scene) {
1573
+ const scenes = this._scenes;
1574
+ if (scenes.has(scene)) {
1575
+ return scenes.get(scene).screenInverseMatrix;
1576
+ }
1577
+ return pacemFoundation.Matrix2D.identity;
1578
+ }
1579
+ #dragger;
1580
+ viewActivatedCallback() {
1581
+ super.viewActivatedCallback();
1582
+ const dragDrop = this.#dragger = document.createElement(pacemCore.P + '-drag-drop');
1583
+ dragDrop.mode = pacemCore.UI.DragDataMode.Copy;
1584
+ dragDrop.dropBehavior = pacemCore.UI.DropBehavior.None;
1585
+ dragDrop.spillBehavior = pacemCore.UI.DropTargetMissedBehavior.None;
1586
+ const floater = document.createElement('div');
1587
+ floater.hidden = true;
1588
+ dragDrop.floater = floater;
1589
+ // append
1590
+ const shell = pacemCore.CustomElementUtils.findAncestorShell(this);
1591
+ shell.appendChild(dragDrop);
1592
+ dragDrop.addEventListener(pacemCore.UI.DragDropEventType.Init, this._dragInitHandler, false);
1593
+ dragDrop.addEventListener(pacemCore.UI.DragDropEventType.Drag, this._draggingHandler, false);
1594
+ dragDrop.addEventListener(pacemCore.UI.DragDropEventType.End, this._dragEndHandler, false);
1595
+ }
1596
+ disconnectedCallback() {
1597
+ const dragger = this.#dragger;
1598
+ if (!pacemCore.Utils.isNull(dragger)) {
1599
+ dragger.removeEventListener(pacemCore.UI.DragDropEventType.Init, this._dragInitHandler, false);
1600
+ dragger.removeEventListener(pacemCore.UI.DragDropEventType.Drag, this._draggingHandler, false);
1601
+ dragger.removeEventListener(pacemCore.UI.DragDropEventType.End, this._dragEndHandler, false);
1602
+ dragger.remove();
1603
+ }
1604
+ super.disconnectedCallback();
1605
+ }
1606
+ invalidateSize(scene, size) {
1607
+ const scenes = this._scenes;
1608
+ if (!pacemCore.Utils.isNull(scene) && !pacemCore.Utils.isNullOrEmpty(size)) {
1609
+ if (scenes.has(scene)) {
1610
+ const tuple = scenes.get(scene), ctx = tuple.context;
1611
+ ctx.canvas.width = size.width;
1612
+ ctx.canvas.height = size.height;
1613
+ const offset = tuple.offset = pacemCore.Utils.offsetRect(ctx.canvas);
1614
+ // transform matrix
1615
+ const stage = { x: 0, y: 0, width: size.width, height: size.height }, aspectRatio = scene.aspectRatio, viewbox = scene.viewbox;
1616
+ if (AdapterUtils.isValidViewbox(viewbox)) {
1617
+ // defaults to the equivalent of SVG's xMidYMid meet
1618
+ let mode = 'contain', align = 'center', valign = 'middle';
1619
+ if (typeof aspectRatio === 'object') {
1620
+ mode = aspectRatio.slice ? 'cover' : 'contain';
1621
+ switch (aspectRatio.x) {
1622
+ case 'min':
1623
+ align = 'left';
1624
+ break;
1625
+ case 'max':
1626
+ align = 'right';
1627
+ break;
1628
+ }
1629
+ switch (aspectRatio.y) {
1630
+ case 'min':
1631
+ valign = 'top';
1632
+ break;
1633
+ case 'max':
1634
+ valign = 'bottom';
1635
+ break;
1636
+ }
1637
+ }
1638
+ // mimic svg viewbox
1639
+ const mscale = pacemFoundation.Rect.findTransform({ x: 0, y: 0, width: viewbox.width, height: viewbox.height }, stage, mode, align, valign);
1640
+ const m = pacemFoundation.Matrix2D.translate(mscale, { x: -mscale.a * viewbox.x, y: -mscale.a * viewbox.y });
1641
+ tuple.transformMatrix = m;
1642
+ tuple.screenInverseMatrix = this._getScreenInverseMatrix(m, offset);
1643
+ }
1644
+ else {
1645
+ tuple.transformMatrix = pacemFoundation.Matrix2D.identity;
1646
+ }
1647
+ }
1648
+ }
1649
+ this._requestDraw(scene);
1650
+ }
1651
+ getHitTarget(stage) {
1652
+ const target = this._hitTarget;
1653
+ if (!pacemCore.Utils.isNull(target) && target.stage === stage) {
1654
+ return target;
1655
+ }
1656
+ return null;
1657
+ }
1658
+ initialize(scene) {
1659
+ if (pacemCore.Utils.isNull(scene)) {
1660
+ throw 'Provided scene is null or undefined.';
1661
+ }
1662
+ const scenes = this._scenes;
1663
+ const dragger = this.#dragger;
1664
+ // already in the store?
1665
+ if (scenes.has(scene)) {
1666
+ const canvas = scenes.get(scene).context.canvas;
1667
+ if (!pacemCore.Utils.isNull(dragger)) {
1668
+ dragger.register(canvas);
1669
+ }
1670
+ return canvas;
1671
+ }
1672
+ const stage = scene.stage;
1673
+ // empty stage DOM
1674
+ stage.innerHTML = '';
1675
+ const canvas = document.createElement('canvas');
1676
+ canvas.setAttribute('part', 'stage');
1677
+ SETVAR$1(canvas, CANVAS_SCENE_VAR, scene);
1678
+ const context = canvas.getContext('2d');
1679
+ canvas.addEventListener('mousemove', this._mousemoveHandler, false);
1680
+ canvas.addEventListener('mouseleave', this._mouseleaveHandler, false);
1681
+ canvas.addEventListener('touchstart', this._mouseDownUpHandler, { passive: true });
1682
+ canvas.addEventListener('touchmove', this._mouseDownUpHandler, { passive: true });
1683
+ canvas.addEventListener('touchend', this._mouseDownUpHandler, { passive: true });
1684
+ canvas.addEventListener('click', this._mouseDownUpHandler, false);
1685
+ canvas.addEventListener('mousedown', this._mouseDownUpHandler, false);
1686
+ canvas.addEventListener('mouseup', this._mouseDownUpHandler, false);
1687
+ stage.appendChild(canvas);
1688
+ scenes.set(scene, { context, transformMatrix: pacemFoundation.Matrix2D.identity, offset: pacemCore.Utils.offsetRect(canvas), screenInverseMatrix: pacemFoundation.Matrix2D.identity });
1689
+ if (!pacemCore.Utils.isNull(dragger)) {
1690
+ dragger.register(canvas);
1691
+ }
1692
+ return canvas;
1693
+ }
1694
+ dispose(scene) {
1695
+ const scenes = this._scenes;
1696
+ if (scenes.has(scene)) {
1697
+ var tuple = scenes.get(scene), context = tuple.context, canvas = context.canvas;
1698
+ const dragger = this.#dragger;
1699
+ if (!pacemCore.Utils.isNull(dragger)) {
1700
+ dragger.unregister(canvas);
1701
+ }
1702
+ canvas.removeEventListener('click', this._mouseDownUpHandler, false);
1703
+ canvas.removeEventListener('touchend', this._mouseDownUpHandler, false);
1704
+ canvas.removeEventListener('mousedown', this._mouseDownUpHandler, false);
1705
+ canvas.removeEventListener('mouseup', this._mouseDownUpHandler, false);
1706
+ // canvas.removeEventListener('touchmove', this._mouseDownUpHandler);
1707
+ canvas.removeEventListener('touchstart', this._mouseDownUpHandler);
1708
+ canvas.removeEventListener('mouseleave', this._mouseleaveHandler, false);
1709
+ canvas.removeEventListener('mousemove', this._mousemoveHandler, false);
1710
+ // remove
1711
+ canvas.remove();
1712
+ scenes.delete(scene);
1713
+ }
1714
+ }
1715
+ _requestDraw(scene) {
1716
+ const handles = this._handles;
1717
+ if (handles.has(scene)) {
1718
+ cancelAnimationFrame(handles.get(scene));
1719
+ }
1720
+ const throttle = () => {
1721
+ this.draw(scene);
1722
+ return requestAnimationFrame(() => { });
1723
+ };
1724
+ handles.set(scene, throttle());
1725
+ }
1726
+ #canvasCssStyle;
1727
+ draw(scene) {
1728
+ const scenes = this._scenes, handles = this._handles;
1729
+ if (!pacemCore.Utils.isNull(scene)) {
1730
+ if (scene.adapter !== this) {
1731
+ // not a pertinent stage anymore
1732
+ if (scenes.has(scene)) {
1733
+ scenes.delete(scene);
1734
+ handles.get(scene);
1735
+ }
1736
+ return;
1737
+ }
1738
+ if (!scenes.has(scene)) {
1739
+ // forgiving behavior (call initialize() if it's the case)
1740
+ this.initialize(scene);
1741
+ return;
1742
+ }
1743
+ if (handles.has(scene)) {
1744
+ // already in the drawing loop, reset
1745
+ cancelAnimationFrame(handles.get(scene));
1746
+ }
1747
+ const formerHitTarget = this._hitTarget;
1748
+ const items = scene.datasource || [];
1749
+ // reset hit target
1750
+ this._hitTarget = null;
1751
+ // clear stage
1752
+ const tuple = scenes.get(scene), context = tuple.context, canvas = context.canvas;
1753
+ this.#canvasCssStyle = getComputedStyle(canvas);
1754
+ context.resetTransform();
1755
+ context.clearRect(0, 0, canvas.width, canvas.height);
1756
+ // viewbox
1757
+ const m = tuple.transformMatrix;
1758
+ context.setTransform(m);
1759
+ // hit test
1760
+ const pointer = this._pointer, offset = tuple.offset, point = Number.isNaN(pointer.page.x) || Number.isNaN(pointer.page.y) ? null : { x: pointer.page.x - offset.x, y: pointer.page.y - offset.y };
1761
+ // draw recursively
1762
+ for (let drawable of items) {
1763
+ this._draw(scene, context, drawable, { transformMatrix: m }, point);
1764
+ }
1765
+ // check hit target
1766
+ const currentHitTarget = this._hitTarget;
1767
+ if (currentHitTarget != formerHitTarget) {
1768
+ if (!pacemCore.Utils.isNull(formerHitTarget)) {
1769
+ if (formerHitTarget instanceof Element) {
1770
+ formerHitTarget.dispatchEvent(new DrawableEvent('out', formerHitTarget, this._scopeEvent, m));
1771
+ }
1772
+ scene.dispatchEvent(new DrawableEvent('itemout', formerHitTarget, this._scopeEvent, m));
1773
+ }
1774
+ if (!pacemCore.Utils.isNull(currentHitTarget)) {
1775
+ if (currentHitTarget instanceof Element) {
1776
+ currentHitTarget.dispatchEvent(new DrawableEvent('over', currentHitTarget, this._scopeEvent, m));
1777
+ }
1778
+ scene.dispatchEvent(new DrawableEvent('itemover', currentHitTarget, this._scopeEvent, m));
1779
+ }
1780
+ }
1781
+ // do not loop
1782
+ // this._requestDraw(scene);
1783
+ }
1784
+ }
1785
+ _draw(scene, ctx, item, state, point) {
1786
+ item.stage ??= scene;
1787
+ if (isDrawable(item)) {
1788
+ if (item.hide) {
1789
+ return;
1790
+ }
1791
+ }
1792
+ // store parent matrix value for dragging purposes
1793
+ if (isUiObject(item) && item.draggable && !item.hide && !item.inert) {
1794
+ SETVAR$1(item, PARENT_MATRIX_VAR, ctx.getTransform().inverse());
1795
+ }
1796
+ let t;
1797
+ if (isUiObject(item)) {
1798
+ t = item.transformMatrix;
1799
+ if (!pacemCore.Utils.isNull(t) && !pacemFoundation.Matrix2D.isIdentity(t)) {
1800
+ ctx.transform(t.a, t.b, t.c, t.d, t.e, t.f);
1801
+ }
1802
+ }
1803
+ let contextPresentationState = state;
1804
+ if (isPresentationObject(item)) {
1805
+ //const stateWithWorldTransformMatrix = Utils.extend({}, state, { transformMatrix: ctx.getTransform() });
1806
+ contextPresentationState = PresentationState.combine(item, state, ctx.getTransform());
1807
+ // set presentation state
1808
+ this._setPresentationState(ctx, contextPresentationState);
1809
+ }
1810
+ if (isShape(item) || item instanceof ShapeElement) {
1811
+ this._drawShape(ctx, item, point);
1812
+ }
1813
+ else if (isText(item) || item instanceof PacemTextElement) {
1814
+ this._drawText(ctx, item, point);
1815
+ }
1816
+ else if (isImage(item) || item instanceof PacemImageElement) {
1817
+ this._drawImage(ctx, item, point);
1818
+ }
1819
+ else if (isGroup(item) || item instanceof PacemGroupElement) {
1820
+ for (let child of item.childDrawables || []) {
1821
+ this._draw(scene, ctx, child, contextPresentationState, point);
1822
+ }
1823
+ }
1824
+ // store global matrix value for debugging purposes
1825
+ if (isUiObject(item) && item.draggable && !item.hide && !item.inert) {
1826
+ SETVAR$1(item, WORLD_MATRIX_VAR, ctx.getTransform().inverse());
1827
+ }
1828
+ // reset presentation state
1829
+ this._setPresentationState(ctx, state);
1830
+ }
1831
+ _setPresentationState(ctx, item) {
1832
+ ctx.setTransform(item.transformMatrix);
1833
+ if (!pacemCore.Utils.isNullOrEmpty(item.stroke) && !isNone(item.stroke)) {
1834
+ ctx.strokeStyle = item.stroke;
1835
+ }
1836
+ else {
1837
+ ctx.strokeStyle = 'transparent';
1838
+ }
1839
+ if (!pacemCore.Utils.isNullOrEmpty(item.lineWidth)) {
1840
+ ctx.lineWidth = item.lineWidth;
1841
+ }
1842
+ else {
1843
+ ctx.lineWidth = 0;
1844
+ }
1845
+ if (!pacemCore.Utils.isNullOrEmpty(item.dashArray)) {
1846
+ ctx.setLineDash(item.dashArray);
1847
+ }
1848
+ else {
1849
+ ctx.setLineDash([]);
1850
+ }
1851
+ if (!pacemCore.Utils.isNullOrEmpty(item.lineCap)) {
1852
+ ctx.lineCap = item.lineCap;
1853
+ }
1854
+ else {
1855
+ ctx.lineCap = 'butt';
1856
+ }
1857
+ if (!pacemCore.Utils.isNullOrEmpty(item.lineJoin)) {
1858
+ ctx.lineJoin = item.lineJoin;
1859
+ }
1860
+ else {
1861
+ ctx.lineJoin = 'miter';
1862
+ }
1863
+ if (typeof item.fill === 'object' && !pacemCore.Utils.isNullOrEmpty(item.fill)) {
1864
+ const { stops } = item.fill;
1865
+ let gradient;
1866
+ if (isLinearGradient(item.fill)) {
1867
+ // linear gradient
1868
+ const { start, end } = item.fill;
1869
+ gradient = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
1870
+ }
1871
+ else if (isRadialGradient(item.fill)) {
1872
+ // radial gradient
1873
+ const { center, radius } = item.fill;
1874
+ gradient = ctx.createRadialGradient(center.x, center.y, radius, center.x, center.y, radius);
1875
+ }
1876
+ else {
1877
+ throw new Error('Unmanaged gradient type.');
1878
+ }
1879
+ for (let stop of stops) {
1880
+ gradient.addColorStop(stop.offset, stop.color);
1881
+ }
1882
+ ctx.fillStyle = gradient;
1883
+ }
1884
+ else if (!pacemCore.Utils.isNullOrEmpty(item.fill) && typeof item.fill === 'string' && !isNone(item.fill)) {
1885
+ ctx.fillStyle = item.fill;
1886
+ }
1887
+ else {
1888
+ ctx.fillStyle = 'transparent';
1889
+ }
1890
+ if (!pacemCore.Utils.isNullOrEmpty(item.opacity)) {
1891
+ ctx.globalAlpha = item.opacity;
1892
+ }
1893
+ else {
1894
+ ctx.globalAlpha = 1.0;
1895
+ }
1896
+ }
1897
+ _drawImage(ctx, item, point) {
1898
+ const CANVAS_IMAGESOURCE_VAR = 'pacem:2d-canvas-imagesrc';
1899
+ let img = GETVAR$1(item, CANVAS_IMAGESOURCE_VAR);
1900
+ const imgLoadHandler = () => {
1901
+ let dw = img.naturalWidth, dh = img.naturalHeight, w = item.width, h = item.height;
1902
+ if (w > 0 && h > 0) ;
1903
+ else if (w > 0) {
1904
+ h = dh * w / dw;
1905
+ }
1906
+ else if (h > 0) {
1907
+ w = dw * h / dh;
1908
+ }
1909
+ else {
1910
+ w = dw;
1911
+ h = dh;
1912
+ }
1913
+ if (!this._dragging
1914
+ && !item.inert /* is hit-test visible? */
1915
+ && !pacemCore.Utils.isNull(point)) {
1916
+ const path2D = new Path2D(`M ${item.x} ${item.y} h ${w} v ${h} H ${item.x} Z`);
1917
+ if (ctx.isPointInPath(path2D, point.x, point.y)) {
1918
+ // overwrite current hit-target (last one wins)
1919
+ this._hitTarget = item;
1920
+ }
1921
+ }
1922
+ ctx.globalAlpha = fallback$1(item.opacity, 1);
1923
+ ctx.drawImage(img, item.x, item.y, w, h);
1924
+ };
1925
+ if (pacemCore.Utils.isNull(img)) {
1926
+ img = new Image();
1927
+ img.src = item.src;
1928
+ img.onload = () => {
1929
+ SETVAR$1(item, CANVAS_IMAGESOURCE_VAR, img);
1930
+ imgLoadHandler();
1931
+ };
1932
+ }
1933
+ else {
1934
+ imgLoadHandler();
1935
+ }
1936
+ }
1937
+ _drawText(ctx, item, point) {
1938
+ const defaults = this.DefaultShapeValues;
1939
+ const color = ctx.fillStyle = fallback$1(item.color, defaults.stroke);
1940
+ ctx.getTransform(); const fontSize = item.fontSize > 0 ? `${item.fontSize}px` : this.#canvasCssStyle.fontSize, fontStyle = item.fontStyle || this.#canvasCssStyle.fontStyle, fontWeight = item.fontWeight || this.#canvasCssStyle.fontWeight;
1941
+ ctx.font = `${fontStyle} ${fontWeight} ${fontSize} ${(item.fontFamily ?? this.#canvasCssStyle.fontFamily)}`;
1942
+ ctx.textAlign = item.textAnchor === 'middle' ? 'center' : item.textAnchor;
1943
+ ctx.fillText(item.text, item.anchor.x, item.anchor.y);
1944
+ ctx.globalAlpha = fallback$1(item.opacity, 1);
1945
+ const hasColor = !isNone(color);
1946
+ if (!this._dragging
1947
+ && !item.inert /* is hit-test visible? */
1948
+ && !pacemCore.Utils.isNull(point)) {
1949
+ const bbox = ctx.measureText(item.text);
1950
+ const width = bbox.width, height = bbox.actualBoundingBoxAscent + bbox.actualBoundingBoxDescent, x = item.anchor.x - bbox.actualBoundingBoxLeft, y = item.anchor.y - bbox.actualBoundingBoxAscent;
1951
+ const path2D = new Path2D(`M ${x} ${y} h ${width} v ${height} H ${x} z`);
1952
+ if (hasColor && ctx.isPointInPath(path2D, point.x, point.y)) {
1953
+ // overwrite current hit-target (last one wins)
1954
+ this._hitTarget = item;
1955
+ }
1956
+ }
1957
+ }
1958
+ _drawShape(ctx, item, point) {
1959
+ if (pacemCore.Utils.isNullOrEmpty(item?.pathData)) {
1960
+ return;
1961
+ }
1962
+ ctx.beginPath();
1963
+ // Path2D
1964
+ const hasFill = typeof ctx.fillStyle !== 'string' || !isNone(ctx.fillStyle), hasStroke = typeof ctx.strokeStyle !== 'string' || !isNone(ctx.strokeStyle);
1965
+ var path2D = new Path2D(item.pathData);
1966
+ if (!this._dragging
1967
+ && !item.inert /* is hit-test visible? */
1968
+ && !pacemCore.Utils.isNull(point)) {
1969
+ if ((hasFill && ctx.isPointInPath(path2D, point.x, point.y))
1970
+ || (hasStroke && ctx.isPointInStroke(path2D, point.x, point.y))) {
1971
+ // overwrite current hit-target (last one wins)
1972
+ this._hitTarget = item;
1973
+ }
1974
+ }
1975
+ if (hasStroke) {
1976
+ ctx.stroke(path2D);
1977
+ }
1978
+ if (hasFill) {
1979
+ ctx.fill(path2D);
1980
+ }
1981
+ const hasEnoughVertices = !pacemCore.Utils.isNullOrEmpty(item.vertices) && item.vertices.length > 1, hasMarkerEnd = !pacemCore.Utils.isNull(item.markerEnd), hasMarkerStart = !pacemCore.Utils.isNull(item.markerStart), hasMarkerMid = !pacemCore.Utils.isNull(item.markerMid);
1982
+ if (hasMarkerEnd || hasMarkerMid || hasMarkerStart) {
1983
+ if (!hasEnoughVertices) {
1984
+ this.log(pacemCore.Logging.LogLevel.Warn, "Not enough vertices were explicited in order to make markers renderable.");
1985
+ }
1986
+ }
1987
+ // WebGL: we can render markers only if vertices are explicit
1988
+ if (hasEnoughVertices) {
1989
+ const matrix = ctx.getTransform();
1990
+ if (hasMarkerStart) {
1991
+ const marker = item.markerEnd, from = item.vertices[1], to = item.vertices[0];
1992
+ const orientation = Math.atan2(to.y - from.y, to.x - from.x);
1993
+ this._drawMarker(ctx, marker, to, orientation);
1994
+ }
1995
+ if (hasMarkerMid) {
1996
+ const marker = item.markerEnd;
1997
+ for (let j = 1; j < item.vertices.length - 1; j++) {
1998
+ // reset transform, just in case
1999
+ ctx.setTransform(matrix);
2000
+ const from = item.vertices[j], to = item.vertices[j + 1];
2001
+ const orientation = Math.atan2(to.y - from.y, to.x - from.x);
2002
+ this._drawMarker(ctx, marker, to, orientation);
2003
+ }
2004
+ }
2005
+ if (hasMarkerEnd) {
2006
+ // reset transform, just in case
2007
+ ctx.setTransform(matrix);
2008
+ const marker = item.markerEnd, from = item.vertices[item.vertices.length - 2], to = item.vertices[item.vertices.length - 1];
2009
+ const orientation = Math.atan2(to.y - from.y, to.x - from.x);
2010
+ this._drawMarker(ctx, marker, to, orientation);
2011
+ }
2012
+ }
2013
+ }
2014
+ _drawMarker(ctx, marker, point, orientation) {
2015
+ const defaults = this.DefaultShapeValues;
2016
+ const refX = marker.ref?.x || 0, refY = marker.ref?.y || 0;
2017
+ const width = (marker.width || 1) * ctx.lineWidth, height = (marker.width || 1) * ctx.lineWidth;
2018
+ let viewbox = marker.viewbox, stage = { x: 0, y: 0, width: width, height: height };
2019
+ if (pacemCore.Utils.isNull(viewbox)) {
2020
+ viewbox = stage;
2021
+ }
2022
+ // prepare
2023
+ const mscale = { a: stage.width / viewbox.width, d: stage.height / viewbox.height }; // Rect.findTransform({ x: 0, y: 0, width: viewbox.width, height: viewbox.height }, stage, 'stretch', 'left', 'top');
2024
+ // execute
2025
+ ctx.translate(point.x, point.y);
2026
+ ctx.rotate(orientation);
2027
+ ctx.scale(mscale.a, mscale.d);
2028
+ ctx.translate(-refX, -refY);
2029
+ ctx.fillStyle = fallback$1(marker.fill, defaults.fill);
2030
+ ctx.strokeStyle = fallback$1(marker.stroke, defaults.stroke);
2031
+ // Path2D
2032
+ const hasMarkerFill = !isNone(marker.fill), hasMarkerStroke = !isNone(marker.stroke);
2033
+ var markerPath2D = new Path2D(marker.pathData);
2034
+ if (hasMarkerFill) {
2035
+ ctx.fill(markerPath2D);
2036
+ }
2037
+ if (hasMarkerStroke) {
2038
+ ctx.stroke(markerPath2D);
2039
+ }
2040
+ }
2041
+ };
2042
+ PacemCanvasAdapterElement = __decorate$1([
2043
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-canvas-adapter' })
2044
+ ], PacemCanvasAdapterElement);
2045
+
2046
+ var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
2047
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2048
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2049
+ 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;
2050
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2051
+ };
2052
+ //namespace Pacem.Components.Drawing {
2053
+ const SVG_NS = 'http://www.w3.org/2000/svg', DRAWABLE_VAR = 'pacem:2-svg-drawable', STAGE_VAR = 'pacem:2d-svg-stage', GETVAR = pacemCore.CustomElementUtils.getAttachedPropertyValue, SETVAR = pacemCore.CustomElementUtils.setAttachedPropertyValue, DELVAR = pacemCore.CustomElementUtils.deleteAttachedPropertyValue;
2054
+ function fallback(v, f) {
2055
+ return pacemCore.Utils.isNull(v) ? f : v;
2056
+ }
2057
+ function replaceChildAt(parent, newChild, targetIndex) {
2058
+ if (targetIndex >= parent.children.length) {
2059
+ parent.appendChild(newChild);
2060
+ return null;
2061
+ }
2062
+ else {
2063
+ return parent.replaceChild(newChild, parent.children.item(targetIndex));
2064
+ }
2065
+ }
2066
+ let PacemSvgAdapterElement = class PacemSvgAdapterElement extends Pacem2DAdapterElement {
2067
+ constructor() {
2068
+ super(...arguments);
2069
+ this._hitTarget = null;
2070
+ this._dragInitHandler = (evt) => {
2071
+ const args = evt.detail, el = args.element, drawable = GETVAR(el, DRAWABLE_VAR), stageTransformMatrix = drawable.stage.transformMatrix, initialMatrix = drawable.transformMatrix ?? pacemFoundation.Matrix2D.identity;
2072
+ args.data = {
2073
+ stageTransformMatrix, item: drawable,
2074
+ initialTransformMatrix: initialMatrix
2075
+ };
2076
+ const reject = AdapterUtils.itemDispatch(drawable, evt, { x: 0, y: 0 });
2077
+ if (reject) {
2078
+ // reject dragging
2079
+ evt.preventDefault();
2080
+ }
2081
+ };
2082
+ this._draggingHandler = (evt) => {
2083
+ pacemCore.avoidHandler(evt);
2084
+ this.#dragging = true;
2085
+ const el = evt.detail.element;
2086
+ const data = evt.detail.data;
2087
+ const args = evt.detail;
2088
+ const screenOffset = { x: (args.currentPosition.x - args.origin.x) * data.stageTransformMatrix.a, y: (args.currentPosition.y - args.origin.y) * data.stageTransformMatrix.d };
2089
+ const offset = {
2090
+ x: screenOffset.x + data.initialTransformMatrix.e,
2091
+ y: screenOffset.y + data.initialTransformMatrix.f
2092
+ },
2093
+ // this is not correct when item or any of its parents have been rotated!
2094
+ stageOffset = {
2095
+ x: screenOffset.x + data.stageTransformMatrix.e,
2096
+ y: screenOffset.y + data.stageTransformMatrix.f
2097
+ };
2098
+ //console.log(`current pos: ${args.currentPosition.x},${args.currentPosition.y}`);
2099
+ //console.log(`origin pos: ${args.origin.x},${args.origin.y}`);
2100
+ //console.log(`offset: ${offset.x},${offset.y}`);
2101
+ //console.log(data.stageTransformMatrix);
2102
+ //console.log(el.style.transform); console.log(data.initialTransformMatrix);
2103
+ const rejected = AdapterUtils.itemDispatch(data.item, evt, stageOffset);
2104
+ if (!rejected) {
2105
+ const init = data.initialTransformMatrix;
2106
+ el.style.transform = `matrix(${init.a},${init.b},${init.c},${init.d},${offset.x},${offset.y})`;
2107
+ }
2108
+ };
2109
+ this._dragEndHandler = (evt) => {
2110
+ this.#dragging = false;
2111
+ const args = evt.detail, el = args.element, data = args.data, transform = pacemCore.Utils.deserializeTransform(el.style);
2112
+ // store transform
2113
+ const offset = { x: transform.e, y: transform.f };
2114
+ if (data.item instanceof UiElement) {
2115
+ data.item.translateX = offset.x;
2116
+ data.item.translateY = offset.y;
2117
+ }
2118
+ else {
2119
+ const init = data.initialTransformMatrix, actual = { a: init.a, b: init.b, c: init.c, d: init.d, e: offset.x, f: offset.y };
2120
+ pacemCore.Utils.extend(data.item, { transformMatrix: actual });
2121
+ }
2122
+ el.style.transform = '';
2123
+ AdapterUtils.itemDispatch(data.item, evt, offset);
2124
+ };
2125
+ this._mouseleaveHandler = (evt) => {
2126
+ if (this.#dragging) {
2127
+ return;
2128
+ }
2129
+ const hitTarget = this._hitTarget;
2130
+ if (pacemCore.Utils.isNull(hitTarget)) {
2131
+ return;
2132
+ }
2133
+ this._hitTarget = null;
2134
+ if (!pacemCore.Utils.isNull(hitTarget)) {
2135
+ this.#dragger.unregister(this._items.get(hitTarget));
2136
+ AdapterUtils.itemDispatch(hitTarget, 'out', evt);
2137
+ }
2138
+ };
2139
+ this._mousemoveHandler = (evt) => {
2140
+ var pt = pacemCore.CustomEventUtils.getEventCoordinates(evt).client;
2141
+ if (!this.#dragging) {
2142
+ // not dragging around
2143
+ var d = null;
2144
+ const root = evt.target.getRootNode();
2145
+ root.elementsFromPoint(pt.x, pt.y).find(i => {
2146
+ d = GETVAR(i, DRAWABLE_VAR);
2147
+ return d && !d.inert;
2148
+ });
2149
+ var old = this._hitTarget, val = d;
2150
+ if (pacemCore.Utils.isNull(d && d.stage) || !this._scenes.has(d.stage) || d.inert) {
2151
+ val = null;
2152
+ }
2153
+ const hitTarget = this._hitTarget = val;
2154
+ if (val !== old) {
2155
+ if (!pacemCore.Utils.isNull(old)) {
2156
+ this.#dragger.unregister(this._items.get(old));
2157
+ AdapterUtils.itemDispatch(old, 'out', evt);
2158
+ }
2159
+ if (!pacemCore.Utils.isNull(val)) {
2160
+ if (val.draggable) {
2161
+ this.#dragger.register(this._items.get(val));
2162
+ }
2163
+ AdapterUtils.itemDispatch(val, 'over', evt);
2164
+ }
2165
+ }
2166
+ if (pacemCore.Utils.isNull(hitTarget)) {
2167
+ // dispatch only if no hit target
2168
+ const svg = evt.currentTarget;
2169
+ const stage = GETVAR(svg, STAGE_VAR);
2170
+ if (!pacemCore.Utils.isNull(stage)) {
2171
+ AdapterUtils.stageDispatch(stage, 'move', evt);
2172
+ }
2173
+ }
2174
+ }
2175
+ };
2176
+ this._mouseDownUpHandler = (evt) => {
2177
+ const svg = evt.currentTarget;
2178
+ if (svg instanceof SVGSVGElement) {
2179
+ const stage = GETVAR(svg, STAGE_VAR), hitTarget = this._hitTarget;
2180
+ const type = evt.type.replace(/^mouse/, '');
2181
+ const opts = getStageOptions(stage);
2182
+ if (pacemCore.CustomEventUtils.matchModifiers(evt, opts.clickModifiers)) {
2183
+ if (!pacemCore.Utils.isNull(hitTarget) && hitTarget.stage === stage) {
2184
+ AdapterUtils.itemDispatch(hitTarget, type, evt);
2185
+ }
2186
+ else {
2187
+ AdapterUtils.stageDispatch(stage, type, evt);
2188
+ }
2189
+ }
2190
+ }
2191
+ };
2192
+ this._scenes = new WeakMap();
2193
+ this._markers = new WeakMap();
2194
+ this._gradients = new WeakMap();
2195
+ this._items = new WeakMap();
2196
+ }
2197
+ snapshot(stage, background, type, quality) {
2198
+ if (this._scenes.has(stage)) {
2199
+ const svg = this._scenes.get(stage);
2200
+ return this.snapshotElement(svg, background, type, quality);
2201
+ }
2202
+ else {
2203
+ return Promise.resolve(null);
2204
+ }
2205
+ }
2206
+ getTransformMatrix(scene) {
2207
+ const scenes = this._scenes;
2208
+ if (scenes.has(scene)) {
2209
+ return scenes.get(scene).getScreenCTM().inverse();
2210
+ }
2211
+ return pacemFoundation.Matrix2D.identity;
2212
+ }
2213
+ #dragger;
2214
+ viewActivatedCallback() {
2215
+ super.viewActivatedCallback();
2216
+ const dragDrop = this.#dragger = document.createElement(pacemCore.P + '-drag-drop');
2217
+ dragDrop.mode = pacemCore.UI.DragDataMode.Self;
2218
+ // append
2219
+ const shell = pacemCore.CustomElementUtils.findAncestorShell(this);
2220
+ shell.appendChild(dragDrop);
2221
+ dragDrop.addEventListener(pacemCore.UI.DragDropEventType.Init, this._dragInitHandler, false);
2222
+ dragDrop.addEventListener(pacemCore.UI.DragDropEventType.Drag, this._draggingHandler, false);
2223
+ dragDrop.addEventListener(pacemCore.UI.DragDropEventType.End, this._dragEndHandler, false);
2224
+ }
2225
+ disconnectedCallback() {
2226
+ const dragger = this.#dragger;
2227
+ if (!pacemCore.Utils.isNull(dragger)) {
2228
+ dragger.removeEventListener(pacemCore.UI.DragDropEventType.Init, this._dragInitHandler, false);
2229
+ dragger.removeEventListener(pacemCore.UI.DragDropEventType.Drag, this._draggingHandler, false);
2230
+ dragger.removeEventListener(pacemCore.UI.DragDropEventType.End, this._dragEndHandler, false);
2231
+ dragger.remove();
2232
+ }
2233
+ super.disconnectedCallback();
2234
+ }
2235
+ invalidateSize(scene, size) {
2236
+ const scenes = this._scenes;
2237
+ if (!pacemCore.Utils.isNull(scene) && !pacemCore.Utils.isNullOrEmpty(size)) {
2238
+ if (scenes.has(scene)) {
2239
+ var svg = scenes.get(scene);
2240
+ svg.setAttribute('width', size.width + '');
2241
+ svg.setAttribute('height', size.height + '');
2242
+ const rect = scene.viewbox, aspectRatio = scene.aspectRatio;
2243
+ if (AdapterUtils.isValidViewbox(rect)) {
2244
+ svg.setAttribute('viewBox', `${rect.x} ${rect.y} ${rect.width} ${rect.height}`);
2245
+ }
2246
+ else {
2247
+ svg.removeAttribute('viewBox');
2248
+ }
2249
+ if (pacemCore.Utils.isNullOrEmpty(aspectRatio) || typeof aspectRatio === 'string') {
2250
+ svg.removeAttribute('preserveAspectRatio');
2251
+ }
2252
+ else {
2253
+ svg.setAttribute('preserveAspectRatio', `xM${aspectRatio.x.substring(1)}YM${aspectRatio.y.substring(1)} ${(aspectRatio.slice ? 'slice' : 'meet')}`);
2254
+ }
2255
+ }
2256
+ }
2257
+ }
2258
+ initialize(scene) {
2259
+ if (pacemCore.Utils.isNull(scene)) {
2260
+ throw 'Provided scene is null or undefined.';
2261
+ }
2262
+ const scenes = this._scenes;
2263
+ // already in the store?
2264
+ if (scenes.has(scene)) {
2265
+ return scenes.get(scene);
2266
+ }
2267
+ const stage = scene.stage;
2268
+ // empty stage DOM and clear dictionary
2269
+ stage.innerHTML = '';
2270
+ this._items = new WeakMap();
2271
+ var svg = document.createElementNS(SVG_NS, 'svg');
2272
+ svg.setAttribute('part', 'stage');
2273
+ SETVAR(svg, STAGE_VAR, scene);
2274
+ stage.appendChild(svg);
2275
+ scenes.set(scene, svg);
2276
+ svg.addEventListener('mousemove', this._mousemoveHandler, false);
2277
+ svg.addEventListener('click', this._mouseDownUpHandler, false);
2278
+ svg.addEventListener('mousedown', this._mouseDownUpHandler, false);
2279
+ svg.addEventListener('mouseup', this._mouseDownUpHandler, false);
2280
+ svg.addEventListener('mouseleave', this._mouseleaveHandler, false);
2281
+ // draw right away
2282
+ // this.draw(scene);
2283
+ return svg;
2284
+ }
2285
+ dispose(scene) {
2286
+ const scenes = this._scenes;
2287
+ if (scenes.has(scene)) {
2288
+ var svg = scenes.get(scene);
2289
+ svg.removeEventListener('mousemove', this._mousemoveHandler);
2290
+ svg.removeEventListener('click', this._mouseDownUpHandler);
2291
+ svg.removeEventListener('mousedown', this._mouseDownUpHandler);
2292
+ svg.removeEventListener('mouseup', this._mouseDownUpHandler);
2293
+ svg.removeEventListener('mouseleave', this._mouseleaveHandler);
2294
+ // remove
2295
+ DELVAR(svg, STAGE_VAR);
2296
+ svg.remove();
2297
+ scenes.delete(scene);
2298
+ }
2299
+ }
2300
+ getHitTarget(scene) {
2301
+ return this._hitTarget;
2302
+ }
2303
+ draw(scene, item, deepRedraw = false) {
2304
+ const scenes = this._scenes, dict = this._items;
2305
+ if (!pacemCore.Utils.isNull(scene)) {
2306
+ if (scene.adapter === this) {
2307
+ if (!scenes.has(scene)) {
2308
+ // forgiving behavior (call initialize() if it's the case)
2309
+ this.initialize(scene);
2310
+ }
2311
+ }
2312
+ else {
2313
+ if (scenes.has(scene)) {
2314
+ scenes.delete(scene);
2315
+ }
2316
+ return;
2317
+ }
2318
+ }
2319
+ else {
2320
+ return;
2321
+ }
2322
+ var items = scene.datasource, flow = true, parent = scenes.get(scene);
2323
+ // item provided?
2324
+ if (!pacemCore.Utils.isNull(item) && dict.has(item)) {
2325
+ items = [item];
2326
+ parent = dict.get(item).parentNode;
2327
+ flow = false;
2328
+ }
2329
+ if (flow) {
2330
+ // sweep everything, quick and dirty
2331
+ parent.innerHTML = '<defs></defs>';
2332
+ this._markers = new WeakMap();
2333
+ }
2334
+ this._draw(scene, parent, items || [], flow, deepRedraw);
2335
+ }
2336
+ #dragging;
2337
+ _hasItems(object) {
2338
+ return isGroup(object);
2339
+ }
2340
+ _disposeSvg(el) {
2341
+ if (!pacemCore.Utils.isNull(el)) {
2342
+ var drawable = GETVAR(el, DRAWABLE_VAR);
2343
+ DELVAR(el, DRAWABLE_VAR);
2344
+ this._items.delete(drawable);
2345
+ }
2346
+ }
2347
+ _draw(scene, parent, items, flow, deepRedraw) {
2348
+ const dict = this._items;
2349
+ // children counter
2350
+ let j = 0;
2351
+ if (parent.firstElementChild instanceof SVGDefsElement) {
2352
+ j++;
2353
+ }
2354
+ if (!pacemCore.Utils.isNullOrEmpty(items)) {
2355
+ for (let item of items) {
2356
+ item.stage ??= scene;
2357
+ let el;
2358
+ if (!dict.has(item)) {
2359
+ el = this._buildSVGElement(item);
2360
+ SETVAR(el, DRAWABLE_VAR, item);
2361
+ this._disposeSvg(replaceChildAt(parent, el, j));
2362
+ dict.set(item, el);
2363
+ }
2364
+ else {
2365
+ el = dict.get(item);
2366
+ if (el.parentNode !== parent) {
2367
+ this._disposeSvg(replaceChildAt(parent, el, j));
2368
+ }
2369
+ }
2370
+ if (isDrawable(item)) {
2371
+ if (item.hide) {
2372
+ el.setAttribute('display', 'none');
2373
+ }
2374
+ else {
2375
+ el.removeAttribute('display');
2376
+ }
2377
+ el.style.transform = '';
2378
+ }
2379
+ if (isShape(item)) {
2380
+ const path = el;
2381
+ path.setAttribute('d', fallback(item.pathData, 'M0,0'));
2382
+ // markers
2383
+ for (let { marker, suffix } of [{ marker: item.markerStart, suffix: 'start' }, { marker: item.markerEnd, suffix: 'end' }, { marker: item.markerMid, suffix: 'mid' }]) {
2384
+ if (marker) {
2385
+ const markerSvg = this._ensureMarker(parent, marker);
2386
+ path.setAttribute('marker-' + suffix, `url(#${markerSvg.id})`);
2387
+ }
2388
+ else {
2389
+ path.removeAttribute('marker-' + suffix);
2390
+ }
2391
+ }
2392
+ }
2393
+ else if (isText(item)) {
2394
+ const text = el;
2395
+ text.textContent = item.text;
2396
+ text.style.fill = pacemCore.Utils.isNullOrEmpty(item.color) ? '' : item.color;
2397
+ text.style.fontFamily = pacemCore.Utils.isNullOrEmpty(item.fontFamily) ? '' : item.fontFamily;
2398
+ //if (item.fontSize > 0) {
2399
+ // text.setAttribute('font-size', item.fontSize.toString());
2400
+ //} else {
2401
+ // text.removeAttribute('font-size');
2402
+ //}
2403
+ text.style.fontSize = pacemCore.Utils.isNull(item.fontSize) ? '' : item.fontSize + 'px';
2404
+ if (!pacemCore.Utils.isNullOrEmpty(item.fontWeight)) {
2405
+ text.style.fontWeight = item.fontWeight;
2406
+ }
2407
+ if (!pacemCore.Utils.isNullOrEmpty(item.fontStyle)) {
2408
+ text.style.fontStyle = item.fontStyle;
2409
+ }
2410
+ text.setAttribute('text-anchor', fallback(item.textAnchor, 'start'));
2411
+ if (!pacemCore.Utils.isNull(item.anchor)) {
2412
+ text.setAttribute('x', item.anchor.x.toString());
2413
+ text.setAttribute('y', item.anchor.y.toString());
2414
+ }
2415
+ else {
2416
+ text.removeAttribute('x');
2417
+ text.removeAttribute('y');
2418
+ }
2419
+ }
2420
+ else if (isImage(item)) {
2421
+ const img = el;
2422
+ img.setAttribute('href', item.src);
2423
+ img.setAttribute('preserveAspectRatio', 'none');
2424
+ if (item.width > 0) {
2425
+ img.setAttribute('width', '' + item.width);
2426
+ }
2427
+ else {
2428
+ img.removeAttribute('width');
2429
+ }
2430
+ if (item.height > 0) {
2431
+ img.setAttribute('height', '' + item.height);
2432
+ }
2433
+ else {
2434
+ img.removeAttribute('height');
2435
+ }
2436
+ if (!pacemCore.Utils.isNull(item.x)) {
2437
+ img.setAttribute('x', '' + item.x);
2438
+ }
2439
+ else {
2440
+ img.removeAttribute('x');
2441
+ }
2442
+ if (!pacemCore.Utils.isNull(item.y)) {
2443
+ img.setAttribute('y', '' + item.y);
2444
+ }
2445
+ else {
2446
+ img.removeAttribute('y');
2447
+ }
2448
+ }
2449
+ if (isUiObject(item)) {
2450
+ const t = item.transformMatrix;
2451
+ if (pacemCore.Utils.isNull(t) || pacemFoundation.Matrix2D.isIdentity(t)) {
2452
+ el.removeAttribute('transform');
2453
+ }
2454
+ else {
2455
+ el.setAttribute('transform', `matrix(${t.a} ${t.b} ${t.c} ${t.d} ${t.e} ${t.f})`);
2456
+ }
2457
+ const opacity = fallback(item.opacity, 1);
2458
+ if (opacity === 1) {
2459
+ el.removeAttribute('opacity');
2460
+ }
2461
+ else {
2462
+ el.setAttribute('opacity', '' + opacity);
2463
+ }
2464
+ }
2465
+ if (isPresentationObject(item)) {
2466
+ if (pacemCore.Utils.isNullOrEmpty(item.fill)) {
2467
+ el.removeAttribute('fill');
2468
+ }
2469
+ else if (typeof item.fill === 'string') {
2470
+ el.setAttribute('fill', item.fill);
2471
+ }
2472
+ else {
2473
+ const grad = this._ensureGradient(parent, item.fill);
2474
+ el.setAttribute('fill', `url(#${grad.id})`);
2475
+ }
2476
+ if (pacemCore.Utils.isNullOrEmpty(item.stroke)) {
2477
+ el.removeAttribute('stroke');
2478
+ }
2479
+ else {
2480
+ el.setAttribute('stroke', item.stroke);
2481
+ }
2482
+ if (pacemCore.Utils.isNullOrEmpty(item.dashArray)) {
2483
+ el.removeAttribute('stroke-dasharray');
2484
+ }
2485
+ else {
2486
+ el.setAttribute('stroke-dasharray', item.dashArray.join(' '));
2487
+ }
2488
+ if (pacemCore.Utils.isNullOrEmpty(item.lineCap)) {
2489
+ el.removeAttribute('stroke-linecap');
2490
+ }
2491
+ else {
2492
+ el.setAttribute('stroke-linecap', item.lineCap);
2493
+ }
2494
+ if (pacemCore.Utils.isNullOrEmpty(item.lineJoin)) {
2495
+ el.removeAttribute('stroke-linejoin');
2496
+ }
2497
+ else {
2498
+ el.setAttribute('stroke-linejoin', item.lineJoin);
2499
+ }
2500
+ if (pacemCore.Utils.isNullOrEmpty(item.lineWidth)) {
2501
+ el.removeAttribute('stroke-width');
2502
+ }
2503
+ else {
2504
+ el.setAttribute('stroke-width', '' + item.lineWidth);
2505
+ }
2506
+ //let css = '';
2507
+ //if (!Utils.isNullOrEmpty(item.dashArray)) {
2508
+ // css += `stroke-dasharray: ${item.dashArray.join(',')};`;
2509
+ //}
2510
+ //if (!Utils.isNullOrEmpty(item.lineCap)) {
2511
+ // css += `stroke-linecap: ${item.lineCap};`;
2512
+ //}
2513
+ //if (!Utils.isNullOrEmpty(item.lineJoin)) {
2514
+ // css += `stroke-linejoin: ${item.lineJoin};`;
2515
+ //}
2516
+ //el.style.cssText = css;
2517
+ //el.setAttribute('stroke-width', '' + fallback(item.lineWidth, defaults.lineWidth));
2518
+ }
2519
+ // hit test visibility
2520
+ if (item.inert) {
2521
+ el.style.pointerEvents = 'none';
2522
+ }
2523
+ else {
2524
+ el.style.pointerEvents = '';
2525
+ }
2526
+ if ((flow || deepRedraw) && this._hasItems(item)) {
2527
+ // recursion
2528
+ this._draw(scene, el, item.childDrawables, true, deepRedraw);
2529
+ }
2530
+ j++;
2531
+ }
2532
+ }
2533
+ if (flow) {
2534
+ // remove exceeding children (except defs)
2535
+ for (let k = parent.children.length - 1; k >= j; k--) {
2536
+ const el = parent.children.item(k);
2537
+ this._disposeSvg(el);
2538
+ el.remove();
2539
+ }
2540
+ }
2541
+ }
2542
+ _buildSVGElement(item) {
2543
+ if (isShape(item) || item instanceof ShapeElement) {
2544
+ return document.createElementNS(SVG_NS, 'path');
2545
+ }
2546
+ if (isText(item) || item instanceof PacemTextElement) {
2547
+ return document.createElementNS(SVG_NS, 'text');
2548
+ }
2549
+ if (isImage(item) || item instanceof PacemImageElement) {
2550
+ return document.createElementNS(SVG_NS, 'image');
2551
+ }
2552
+ return document.createElementNS(SVG_NS, 'g');
2553
+ }
2554
+ _ensureGradient(parent, gradient) {
2555
+ const store = this._gradients;
2556
+ if (!store.has(parent)) {
2557
+ store.set(parent, new WeakMap());
2558
+ }
2559
+ const map = store.get(parent);
2560
+ // linear or radial?
2561
+ const isLinear = isLinearGradient(gradient), isRadial = isRadialGradient(gradient);
2562
+ if (map.has(gradient)) {
2563
+ const current = map.get(gradient);
2564
+ if ((isLinear && current instanceof SVGLinearGradientElement)
2565
+ || (isRadial && current instanceof SVGRadialGradientElement)) {
2566
+ // remove from DOM
2567
+ current.remove();
2568
+ // remove from memoizer
2569
+ map.delete(gradient);
2570
+ }
2571
+ }
2572
+ if (!map.has(gradient)) {
2573
+ // <defs>
2574
+ let defsContainer = parent;
2575
+ let defs;
2576
+ while (pacemCore.Utils.isNull(defs = defsContainer.querySelector(':scope > defs'))) {
2577
+ const parent1 = defsContainer.parentElement;
2578
+ if (parent1 instanceof SVGElement) {
2579
+ defsContainer = parent1;
2580
+ }
2581
+ else {
2582
+ break;
2583
+ }
2584
+ }
2585
+ if (pacemCore.Utils.isNull(defs)) {
2586
+ throw new Error('Must provide a <defs> element.');
2587
+ }
2588
+ var gradientSvg = null;
2589
+ if (isLinear) {
2590
+ // create linear gradient node
2591
+ gradientSvg = document.createElementNS(SVG_NS, 'linearGradient');
2592
+ }
2593
+ else if (isRadialGradient(gradient)) {
2594
+ // create radial gradient node
2595
+ gradientSvg = document.createElementNS(SVG_NS, 'radialGradient');
2596
+ }
2597
+ else {
2598
+ throw new Error('Unmanaged gradient type.');
2599
+ }
2600
+ gradientSvg.setAttribute('gradientUnits', 'userSpaceOnUse');
2601
+ gradientSvg.setAttribute('id', `grad-${pacemCore.Utils.uniqueCode()}`);
2602
+ defs.appendChild(gradientSvg);
2603
+ map.set(gradient, gradientSvg);
2604
+ }
2605
+ const retval = map.get(gradient);
2606
+ if (isLinear) {
2607
+ // linear
2608
+ retval.setAttribute('x1', gradient.start.x.toString());
2609
+ retval.setAttribute('y1', gradient.start.y.toString());
2610
+ retval.setAttribute('x2', gradient.end.x.toString());
2611
+ retval.setAttribute('y2', gradient.end.y.toString());
2612
+ }
2613
+ else if (isRadial) {
2614
+ retval.setAttribute('cx', gradient.center.x.toString());
2615
+ retval.setAttribute('cy', gradient.center.y.toString());
2616
+ retval.setAttribute('r', gradient.radius.toString());
2617
+ }
2618
+ // stops
2619
+ let j = 0;
2620
+ for (let stop of gradient.stops) {
2621
+ while (retval.children.length <= j) {
2622
+ const stopSvgAdd = document.createElementNS(SVG_NS, 'stop');
2623
+ retval.appendChild(stopSvgAdd);
2624
+ }
2625
+ const stopSvg = retval.children.item(j);
2626
+ stopSvg.setAttribute('offset', (stop.offset * 100) + '%');
2627
+ stopSvg.setAttribute('stop-color', stop.color);
2628
+ if (!pacemCore.Utils.isNull(stop.opacity)) {
2629
+ stopSvg.setAttribute('stop-opacity', stop.opacity.toString());
2630
+ }
2631
+ j++;
2632
+ }
2633
+ while (retval.children.length > gradient.stops.length) {
2634
+ const lastChild = retval.children.item(retval.children.length - 1);
2635
+ retval.removeChild(lastChild);
2636
+ }
2637
+ return retval;
2638
+ }
2639
+ _ensureMarker(parent, marker) {
2640
+ const store = this._markers;
2641
+ if (!store.has(parent)) {
2642
+ store.set(parent, new WeakMap());
2643
+ }
2644
+ const map = store.get(parent);
2645
+ if (!map.has(marker)) {
2646
+ const markerSvg = document.createElementNS(SVG_NS, 'marker');
2647
+ map.set(marker, markerSvg);
2648
+ const markerPath = document.createElementNS(SVG_NS, 'path');
2649
+ markerSvg.appendChild(markerPath);
2650
+ markerSvg.setAttribute('id', 'mark' + pacemCore.Utils.uniqueCode());
2651
+ let defsContainer = parent;
2652
+ let defs;
2653
+ while (pacemCore.Utils.isNull(defs = defsContainer.querySelector(':scope > defs'))) {
2654
+ const parent1 = defsContainer.parentElement;
2655
+ if (parent1 instanceof SVGElement) {
2656
+ defsContainer = parent1;
2657
+ }
2658
+ else {
2659
+ break;
2660
+ }
2661
+ }
2662
+ if (pacemCore.Utils.isNull(defs)) {
2663
+ throw new Error('Must provide a <defs> element.');
2664
+ }
2665
+ defs.appendChild(markerSvg);
2666
+ }
2667
+ const markerSvg = map.get(marker), markerPath = markerSvg.firstElementChild;
2668
+ // marker attributes
2669
+ markerSvg.setAttribute('orient', 'auto-start-reverse');
2670
+ if (!pacemCore.Utils.isNullOrEmpty(marker.viewbox)) {
2671
+ markerSvg.setAttribute('viewBox', `${marker.viewbox.x} ${marker.viewbox.y} ${marker.viewbox.width} ${marker.viewbox.height}`);
2672
+ }
2673
+ else {
2674
+ markerSvg.removeAttribute('viewBox');
2675
+ }
2676
+ if (!pacemCore.Utils.isNullOrEmpty(marker.ref)) {
2677
+ markerSvg.setAttribute('refX', marker.ref.x.toString());
2678
+ markerSvg.setAttribute('refY', marker.ref.y.toString());
2679
+ }
2680
+ else {
2681
+ markerSvg.removeAttribute('refX');
2682
+ markerSvg.removeAttribute('refY');
2683
+ }
2684
+ if (marker.height > 0) {
2685
+ markerSvg.setAttribute('markerHeight', marker.height.toString());
2686
+ }
2687
+ else {
2688
+ markerSvg.removeAttribute('markerHeight');
2689
+ }
2690
+ if (marker.width > 0) {
2691
+ markerSvg.setAttribute('markerWidth', marker.width.toString());
2692
+ }
2693
+ else {
2694
+ markerSvg.removeAttribute('markerWidth');
2695
+ }
2696
+ // path attributes
2697
+ markerPath.setAttribute('d', marker.pathData);
2698
+ if (!pacemCore.Utils.isNullOrEmpty(marker.fill)) {
2699
+ markerPath.setAttribute('fill', marker.fill);
2700
+ }
2701
+ else {
2702
+ markerPath.removeAttribute('fill');
2703
+ }
2704
+ if (!pacemCore.Utils.isNullOrEmpty(marker.stroke)) {
2705
+ markerPath.setAttribute('stroke', marker.stroke);
2706
+ }
2707
+ else {
2708
+ markerPath.removeAttribute('stroke');
2709
+ }
2710
+ return markerSvg;
2711
+ }
2712
+ };
2713
+ PacemSvgAdapterElement = __decorate([
2714
+ pacemCore.CustomElement({ tagName: pacemCore.P + '-' + TAG_MIDDLE_NAME + '-svg-adapter' })
2715
+ ], PacemSvgAdapterElement);
2716
+
2717
+ var indexComponentsDrawing = /*#__PURE__*/Object.freeze({
2718
+ __proto__: null,
2719
+ AdapterUtils: AdapterUtils,
2720
+ get CornerType () { return CornerType; },
2721
+ DrawableElement: DrawableElement,
2722
+ get Pacem2DElement () { return Pacem2DElement; },
2723
+ get PacemCanvasAdapterElement () { return PacemCanvasAdapterElement; },
2724
+ get PacemCircleElement () { return PacemCircleElement; },
2725
+ get PacemEllipseElement () { return PacemEllipseElement; },
2726
+ get PacemGroupElement () { return PacemGroupElement; },
2727
+ get PacemImageElement () { return PacemImageElement; },
2728
+ get PacemLineElement () { return PacemLineElement; },
2729
+ get PacemPathElement () { return PacemPathElement; },
2730
+ get PacemPolygonElement () { return PacemPolygonElement; },
2731
+ get PacemPolylineElement () { return PacemPolylineElement; },
2732
+ get PacemRectElement () { return PacemRectElement; },
2733
+ get PacemSvgAdapterElement () { return PacemSvgAdapterElement; },
2734
+ get PacemTextElement () { return PacemTextElement; },
2735
+ PresentationElement: PresentationElement,
2736
+ ShapeElement: ShapeElement,
2737
+ UiElement: UiElement,
2738
+ getStageOptions: getStageOptions
2739
+ });
2740
+
2741
+ var indexComponents = /*#__PURE__*/Object.freeze({
2742
+ __proto__: null,
2743
+ Drawing: indexComponentsDrawing
2744
+ });
2745
+
2746
+ var Output = /*#__PURE__*/Object.freeze({
2747
+ __proto__: null,
2748
+ Components: indexComponents,
2749
+ Drawing: drawing
2750
+ });
2751
+
2752
+ pacemFoundation.DeepMerger.merge(Output);
2753
+
2754
+ })(Pacem, Pacem);
2755
+ //# sourceMappingURL=pacem-2d.js.map