pacem 0.21.0-dilmun → 0.21.0-gerasa

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 (53) hide show
  1. package/dist/css/pacem-dark-content.min.css +1 -1
  2. package/dist/css/pacem-dark-shell.min.css +1 -1
  3. package/dist/css/pacem-dark.min.css +1 -1
  4. package/dist/css/pacem-light-content.min.css +1 -1
  5. package/dist/css/pacem-light-shell.min.css +1 -1
  6. package/dist/css/pacem-light.min.css +1 -1
  7. package/dist/css/pacem-phousys-content.min.css +1 -1
  8. package/dist/css/pacem-phousys-shell.min.css +1 -1
  9. package/dist/css/pacem-phousys.min.css +1 -1
  10. package/dist/js/azure-maps.d.ts +1 -1
  11. package/dist/js/pacem-2d.d.ts +25 -6
  12. package/dist/js/pacem-2d.js +141 -115
  13. package/dist/js/pacem-2d.min.js +2 -2
  14. package/dist/js/pacem-3d.d.ts +1 -1
  15. package/dist/js/pacem-3d.js +1 -1
  16. package/dist/js/pacem-3d.min.js +1 -1
  17. package/dist/js/pacem-charts.d.ts +1 -1
  18. package/dist/js/pacem-charts.js +1 -1
  19. package/dist/js/pacem-charts.min.js +1 -1
  20. package/dist/js/pacem-cms.d.ts +1 -1
  21. package/dist/js/pacem-cms.js +1 -1
  22. package/dist/js/pacem-cms.min.js +1 -1
  23. package/dist/js/pacem-core.d.ts +1 -1
  24. package/dist/js/pacem-core.js +1 -1
  25. package/dist/js/pacem-core.min.js +1 -1
  26. package/dist/js/pacem-foundation.d.ts +1 -1
  27. package/dist/js/pacem-foundation.js +1 -1
  28. package/dist/js/pacem-foundation.min.js +1 -1
  29. package/dist/js/pacem-fx.d.ts +1 -1
  30. package/dist/js/pacem-fx.js +1 -1
  31. package/dist/js/pacem-fx.min.js +1 -1
  32. package/dist/js/pacem-logging.d.ts +1 -1
  33. package/dist/js/pacem-logging.js +1 -1
  34. package/dist/js/pacem-logging.min.js +1 -1
  35. package/dist/js/pacem-maps.d.ts +1 -1
  36. package/dist/js/pacem-maps.js +1 -1
  37. package/dist/js/pacem-maps.min.js +1 -1
  38. package/dist/js/pacem-networking.js +1 -1
  39. package/dist/js/pacem-networking.min.js +1 -1
  40. package/dist/js/pacem-numerical.d.ts +1 -1
  41. package/dist/js/pacem-numerical.js +1 -1
  42. package/dist/js/pacem-numerical.min.js +1 -1
  43. package/dist/js/pacem-plus.d.ts +1 -1
  44. package/dist/js/pacem-plus.js +1 -1
  45. package/dist/js/pacem-plus.min.js +1 -1
  46. package/dist/js/pacem-scaffolding.d.ts +1 -1
  47. package/dist/js/pacem-scaffolding.js +1 -1
  48. package/dist/js/pacem-scaffolding.min.js +1 -1
  49. package/dist/js/pacem-ui.d.ts +1 -1
  50. package/dist/js/pacem-ui.js +1 -1
  51. package/dist/js/pacem-ui.min.js +1 -1
  52. package/dist/js/swagger-types.d.ts +1 -1
  53. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -102,6 +102,9 @@ declare namespace Pacem.Drawing {
102
102
  class DrawableEvent extends UI2DEvent<Drawable> {
103
103
  constructor(type: string, args: Drawable, originalEvent: MouseEvent | TouchEvent | KeyboardEvent, m: Matrix2D);
104
104
  }
105
+ class StageEvent extends UI2DEvent<Stage> {
106
+ constructor(type: string, args: Stage, originalEvent: MouseEvent | TouchEvent | KeyboardEvent, m?: Matrix2D);
107
+ }
105
108
  }
106
109
  declare namespace Pacem.Components.Drawing {
107
110
  interface Stage extends Pacem.Drawing.Stage {
@@ -330,11 +333,31 @@ declare namespace Pacem.Components.Drawing {
330
333
  propertyChangedCallback(name: string, old: any, val: any, first?: boolean): void;
331
334
  }
332
335
  }
336
+ declare namespace Pacem.Components.Drawing {
337
+ class AdapterUtils {
338
+ static stageDispatch(stage: Pacem.Drawing.Stage, type: 'down' | 'up' | 'click' | 'over' | 'out' | 'move', evt: MouseEvent | TouchEvent): void;
339
+ /**
340
+ * Dispatches a UI event related to a `Drawable` and returns a boolean that tells if the event was prevented (true) or not (false).
341
+ * @param target The `Drawable` instance.
342
+ * @param type Short event type name.
343
+ * @param evt The original event.
344
+ */
345
+ static itemDispatch(target: Pacem.Drawing.Drawable, type: 'down' | 'up' | 'click' | 'over' | 'out', evt: MouseEvent | TouchEvent): boolean;
346
+ /**
347
+ * Dispatches a drag event related to a `Drawable` and returns a boolean that tells if the event was prevented (true) or not (false).
348
+ * @param target The `Drawable` instance.
349
+ * @param evt The `DragDropEvent` instance.
350
+ * @param offset The tracked offset.
351
+ */
352
+ static itemDispatch(target: Pacem.Drawing.Drawable, evt: Pacem.UI.DragDropEvent, offset: Point): boolean;
353
+ }
354
+ }
333
355
  declare namespace Pacem.Components.Drawing {
334
356
  /** Implementation postponed. Focus on SVG adapter. */
335
357
  class PacemCanvasAdapterElement extends Pacem2DAdapterElement {
336
358
  #private;
337
359
  snapshot(stage: Pacem2DElement, backgroundColor?: string): PromiseLike<Blob>;
360
+ private _getScreenInverseMatrix;
338
361
  getTransformMatrix(scene: Pacem2DElement): Matrix2D;
339
362
  private _dragger;
340
363
  viewActivatedCallback(): void;
@@ -348,15 +371,12 @@ declare namespace Pacem.Components.Drawing {
348
371
  private _hitTarget;
349
372
  private _pointer;
350
373
  private _scopeEvent;
351
- private _canvasOffset;
352
- private _clickHandler;
353
374
  private _dragging;
354
375
  private _dragInitHandler;
355
376
  private _draggingHandler;
356
377
  private _dragEndHandler;
357
378
  private _mousemoveHandler;
358
- private _touchstartHandler;
359
- private _itemDispatch;
379
+ private _mouseDownUpHandler;
360
380
  private _draw;
361
381
  private _drawImage;
362
382
  private _drawText;
@@ -386,7 +406,6 @@ declare namespace Pacem.Components.Drawing {
386
406
  private _dragEndHandler;
387
407
  private _mousemoveHandler;
388
408
  private _mouseDownUpHandler;
389
- private _itemDispatch;
390
409
  private _hasItems;
391
410
  private _disposeSvg;
392
411
  private _draw;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * pacem v0.21.0-dilmun (https://js.pacem.it)
2
+ * pacem v0.21.0-gerasa (https://js.pacem.it)
3
3
  * Copyright 2022 Pacem (https://pacem.it)
4
4
  * Licensed under MIT
5
5
  */
@@ -81,6 +81,12 @@ var Pacem;
81
81
  }
82
82
  }
83
83
  Drawing.DrawableEvent = DrawableEvent;
84
+ class StageEvent extends UI2DEvent {
85
+ constructor(type, args, originalEvent, m = args.transformMatrix) {
86
+ super(type, { detail: args, bubbles: true, cancelable: true }, originalEvent, m);
87
+ }
88
+ }
89
+ Drawing.StageEvent = StageEvent;
84
90
  })(Drawing = Pacem.Drawing || (Pacem.Drawing = {}));
85
91
  })(Pacem || (Pacem = {}));
86
92
  (function (Pacem) {
@@ -1032,6 +1038,55 @@ var Pacem;
1032
1038
  })(Pacem || (Pacem = {}));
1033
1039
  /// <reference path="../types.ts" />
1034
1040
  var Pacem;
1041
+ (function (Pacem) {
1042
+ var Components;
1043
+ (function (Components) {
1044
+ var Drawing;
1045
+ (function (Drawing) {
1046
+ class AdapterUtils {
1047
+ static stageDispatch(stage, type, evt) {
1048
+ if (stage instanceof EventTarget) {
1049
+ stage.dispatchEvent(new Pacem.Drawing.StageEvent('stage' + type, stage, evt, stage.transformMatrix));
1050
+ }
1051
+ }
1052
+ static itemDispatch(target, type, offset) {
1053
+ if (!Pacem.Utils.isNull(target)) {
1054
+ var dragArgs, originalEvent, evtType;
1055
+ if (offset instanceof Event) {
1056
+ originalEvent = offset;
1057
+ }
1058
+ else {
1059
+ dragArgs = { item: target, offset: offset };
1060
+ }
1061
+ if (typeof type === 'string') {
1062
+ evtType = type;
1063
+ }
1064
+ else {
1065
+ evtType = type.type;
1066
+ originalEvent = type.originalEvent;
1067
+ }
1068
+ const m = target.stage.transformMatrix;
1069
+ const evt = () => offset instanceof Event ? new Pacem.Drawing.DrawableEvent(evtType, target, originalEvent, m) : new Pacem.Drawing.DragEvent(evtType, { detail: dragArgs, cancelable: evtType === Pacem.UI.DragDropEventType.Init || evtType === Pacem.UI.DragDropEventType.Drag }, originalEvent, m), itemevt = offset instanceof Event ? new Pacem.Drawing.DrawableEvent('item' + evtType, target, originalEvent, m) : new Pacem.Drawing.DragEvent('item' + evtType, { detail: dragArgs, cancelable: evtType === Pacem.UI.DragDropEventType.Init || evtType === Pacem.UI.DragDropEventType.Drag }, originalEvent, m);
1070
+ var prevent = false;
1071
+ if (target instanceof EventTarget) {
1072
+ const evnt = evt();
1073
+ target.dispatchEvent(evnt);
1074
+ prevent = evnt.defaultPrevented;
1075
+ }
1076
+ target.stage.dispatchEvent(itemevt);
1077
+ // was the event (in one of its forms) rejected?
1078
+ return prevent || itemevt.defaultPrevented;
1079
+ }
1080
+ return false;
1081
+ }
1082
+ }
1083
+ Drawing.AdapterUtils = AdapterUtils;
1084
+ })(Drawing = Components.Drawing || (Components.Drawing = {}));
1085
+ })(Components = Pacem.Components || (Pacem.Components = {}));
1086
+ })(Pacem || (Pacem = {}));
1087
+ /// <reference path="../types.ts" />
1088
+ /// <reference path="utils.ts" />
1089
+ var Pacem;
1035
1090
  (function (Pacem) {
1036
1091
  var Components;
1037
1092
  (function (Components) {
@@ -1056,20 +1111,6 @@ var Pacem;
1056
1111
  this._pointer = {
1057
1112
  page: { x: 0, y: 0 }, screen: { x: 0, y: 0 }, client: { x: 0, y: 0 }
1058
1113
  };
1059
- this._canvasOffset = { x: 0, y: 0, width: 0, height: 0 };
1060
- this._clickHandler = (evt) => {
1061
- const canvas = evt.srcElement;
1062
- const stage = GETVAR(canvas, CANVAS_SCENE_VAR);
1063
- this.draw(stage);
1064
- const currentHitTarget = this._hitTarget;
1065
- if (!Pacem.Utils.isNull(currentHitTarget)) {
1066
- const m = currentHitTarget.stage.transformMatrix;
1067
- if (currentHitTarget instanceof Element) {
1068
- currentHitTarget.dispatchEvent(new Pacem.Drawing.DrawableEvent('click', currentHitTarget, evt, m));
1069
- }
1070
- currentHitTarget.stage.dispatchEvent(new Pacem.Drawing.DrawableEvent('itemclick', currentHitTarget, evt, m));
1071
- }
1072
- };
1073
1114
  this._dragInitHandler = (evt) => {
1074
1115
  var _a;
1075
1116
  const hitTarget = this._hitTarget;
@@ -1083,7 +1124,7 @@ var Pacem;
1083
1124
  initialTransformMatrix: initialMatrix,
1084
1125
  parentMatrix
1085
1126
  };
1086
- const reject = this._itemDispatch(drawable, evt, { x: 0, y: 0 });
1127
+ const reject = Drawing.AdapterUtils.itemDispatch(drawable, evt, { x: 0, y: 0 });
1087
1128
  if (reject) {
1088
1129
  // reject dragging
1089
1130
  evt.preventDefault();
@@ -1108,14 +1149,15 @@ var Pacem;
1108
1149
  //console.log(GETVAR(data.item, WORLD_MATRIX_VAR));
1109
1150
  //console.log(data.initialTransformMatrix);
1110
1151
  const stageTransformMatrix = data.item.stage.transformMatrix;
1111
- const rejected = this._itemDispatch(data.item, evt, { x: screenOffset.x * stageTransformMatrix.a + stageTransformMatrix.e, y: screenOffset.y * stageTransformMatrix.d + stageTransformMatrix.f });
1152
+ const rejected = Drawing.AdapterUtils.itemDispatch(data.item, evt, { x: screenOffset.x * stageTransformMatrix.a + stageTransformMatrix.e, y: screenOffset.y * stageTransformMatrix.d + stageTransformMatrix.f });
1112
1153
  if (!rejected) {
1113
1154
  if (data.item instanceof Pacem.Components.Drawing.UiElement) {
1114
1155
  data.item.translateX = offset.x;
1115
1156
  data.item.translateY = offset.y;
1116
1157
  }
1117
1158
  else {
1118
- Pacem.Utils.extend(data.item, { transformMatrix: Pacem.Matrix2D.translate(data.initialTransformMatrix, offset) });
1159
+ const init = data.initialTransformMatrix, actual = { a: init.a, b: init.b, c: init.c, d: init.d, e: offset.x, f: offset.y };
1160
+ Pacem.Utils.extend(data.item, { transformMatrix: actual });
1119
1161
  }
1120
1162
  // console.log(data.item.transformMatrix);
1121
1163
  }
@@ -1123,7 +1165,7 @@ var Pacem;
1123
1165
  this._dragEndHandler = (evt) => {
1124
1166
  this._dragging = false;
1125
1167
  const args = evt.detail, data = args.data, transform = data.item.transformMatrix;
1126
- this._itemDispatch(data.item, evt, { x: transform.e, y: transform.f });
1168
+ Drawing.AdapterUtils.itemDispatch(data.item, evt, { x: transform.e, y: transform.f });
1127
1169
  };
1128
1170
  // #endregion
1129
1171
  this._mousemoveHandler = (evt) => {
@@ -1132,12 +1174,25 @@ var Pacem;
1132
1174
  const canvas = evt.srcElement;
1133
1175
  const stage = GETVAR(canvas, CANVAS_SCENE_VAR);
1134
1176
  this._requestDraw(stage);
1177
+ if (!this._dragging) {
1178
+ if (!Pacem.Utils.isNull(this._hitTarget)) {
1179
+ Drawing.AdapterUtils.stageDispatch(stage, 'move', evt);
1180
+ }
1181
+ }
1135
1182
  };
1136
- this._touchstartHandler = (evt) => {
1137
- if (evt.touches.length === 1) {
1138
- this._scopeEvent = evt;
1139
- this._pointer = Pacem.CustomEventUtils.getEventCoordinates(evt);
1140
- // this._modifiers = CustomEventUtils.getEventKeyModifiers(evt);
1183
+ this._mouseDownUpHandler = (evt) => {
1184
+ this._scopeEvent = evt;
1185
+ this._pointer = Pacem.CustomEventUtils.getEventCoordinates(evt);
1186
+ const canvas = evt.target;
1187
+ if (canvas instanceof HTMLCanvasElement) {
1188
+ const stage = GETVAR(canvas, CANVAS_SCENE_VAR), hitTarget = this._hitTarget;
1189
+ const type = evt.type.replace(/^(mouse|touch)/, ''), fineType = type === 'end' ? 'click' : type;
1190
+ if (!Pacem.Utils.isNull(hitTarget) && hitTarget.stage === stage) {
1191
+ Drawing.AdapterUtils.itemDispatch(this._hitTarget, fineType, evt);
1192
+ }
1193
+ else {
1194
+ Drawing.AdapterUtils.stageDispatch(stage, fineType, evt);
1195
+ }
1141
1196
  }
1142
1197
  };
1143
1198
  this._scenes = new WeakMap();
@@ -1153,13 +1208,13 @@ var Pacem;
1153
1208
  return Promise.resolve(null);
1154
1209
  }
1155
1210
  }
1211
+ _getScreenInverseMatrix(m, offset) {
1212
+ return Pacem.Matrix2D.invert({ a: m.a, b: m.b, c: m.c, d: m.d, e: m.e + offset.x, f: m.f + offset.y });
1213
+ }
1156
1214
  getTransformMatrix(scene) {
1157
1215
  const scenes = this._scenes;
1158
1216
  if (scenes.has(scene)) {
1159
- const m = scenes.get(scene).transformMatrix;
1160
- if (!Pacem.Utils.isNull(m)) {
1161
- return Pacem.Matrix2D.invert(m);
1162
- }
1217
+ return scenes.get(scene).screenInverseMatrix;
1163
1218
  }
1164
1219
  return Pacem.Matrix2D.identity;
1165
1220
  }
@@ -1196,7 +1251,7 @@ var Pacem;
1196
1251
  const tuple = scenes.get(scene), ctx = tuple.context;
1197
1252
  ctx.canvas.width = size.width;
1198
1253
  ctx.canvas.height = size.height;
1199
- this._canvasOffset = Pacem.Utils.offsetRect(ctx.canvas);
1254
+ const offset = tuple.offset = Pacem.Utils.offsetRect(ctx.canvas);
1200
1255
  // transform matrix
1201
1256
  const stage = { x: 0, y: 0, width: size.width, height: size.height }, aspectRatio = scene.aspectRatio, viewbox = scene.viewbox;
1202
1257
  if (!Pacem.Utils.isNullOrEmpty(viewbox)) {
@@ -1226,6 +1281,7 @@ var Pacem;
1226
1281
  const mscale = Pacem.Rect.findTransform({ x: 0, y: 0, width: viewbox.width, height: viewbox.height }, stage, mode, align, valign);
1227
1282
  const m = Pacem.Matrix2D.translate(mscale, { x: -mscale.a * viewbox.x, y: -mscale.a * viewbox.y });
1228
1283
  tuple.transformMatrix = m;
1284
+ tuple.screenInverseMatrix = this._getScreenInverseMatrix(m, offset);
1229
1285
  }
1230
1286
  else {
1231
1287
  tuple.transformMatrix = Pacem.Matrix2D.identity;
@@ -1262,12 +1318,14 @@ var Pacem;
1262
1318
  SETVAR(canvas, CANVAS_SCENE_VAR, scene);
1263
1319
  const context = canvas.getContext('2d');
1264
1320
  canvas.addEventListener('mousemove', this._mousemoveHandler, false);
1265
- canvas.addEventListener('touchstart', this._touchstartHandler, { passive: true });
1266
- canvas.addEventListener('touchmove', this._touchstartHandler, { passive: true });
1267
- canvas.addEventListener('touchend', this._clickHandler, { passive: true });
1268
- canvas.addEventListener('click', this._clickHandler, false);
1321
+ canvas.addEventListener('touchstart', this._mouseDownUpHandler, { passive: true });
1322
+ canvas.addEventListener('touchmove', this._mouseDownUpHandler, { passive: true });
1323
+ canvas.addEventListener('touchend', this._mouseDownUpHandler, { passive: true });
1324
+ canvas.addEventListener('click', this._mouseDownUpHandler, false);
1325
+ canvas.addEventListener('mousedown', this._mouseDownUpHandler, false);
1326
+ canvas.addEventListener('mouseup', this._mouseDownUpHandler, false);
1269
1327
  stage.appendChild(canvas);
1270
- scenes.set(scene, { context, transformMatrix: Pacem.Matrix2D.identity });
1328
+ scenes.set(scene, { context, transformMatrix: Pacem.Matrix2D.identity, offset: Pacem.Utils.offsetRect(canvas), screenInverseMatrix: Pacem.Matrix2D.identity });
1271
1329
  if (!Pacem.Utils.isNull(dragger)) {
1272
1330
  dragger.register(canvas);
1273
1331
  }
@@ -1281,10 +1339,12 @@ var Pacem;
1281
1339
  if (!Pacem.Utils.isNull(dragger)) {
1282
1340
  dragger.unregister(canvas);
1283
1341
  }
1284
- canvas.removeEventListener('click', this._clickHandler, false);
1285
- canvas.removeEventListener('touchend', this._clickHandler, false);
1286
- canvas.removeEventListener('touchmove', this._touchstartHandler);
1287
- canvas.removeEventListener('touchstart', this._touchstartHandler);
1342
+ canvas.removeEventListener('click', this._mouseDownUpHandler, false);
1343
+ canvas.removeEventListener('touchend', this._mouseDownUpHandler, false);
1344
+ canvas.removeEventListener('mousedown', this._mouseDownUpHandler, false);
1345
+ canvas.removeEventListener('mouseup', this._mouseDownUpHandler, false);
1346
+ // canvas.removeEventListener('touchmove', this._mouseDownUpHandler);
1347
+ canvas.removeEventListener('touchstart', this._mouseDownUpHandler);
1288
1348
  canvas.removeEventListener('mousemove', this._mousemoveHandler, false);
1289
1349
  // remove
1290
1350
  canvas.remove();
@@ -1296,7 +1356,11 @@ var Pacem;
1296
1356
  if (handles.has(scene)) {
1297
1357
  cancelAnimationFrame(handles.get(scene));
1298
1358
  }
1299
- handles.set(scene, requestAnimationFrame(() => { this.draw(scene); }));
1359
+ const throttle = () => {
1360
+ this.draw(scene);
1361
+ return requestAnimationFrame(() => { });
1362
+ };
1363
+ handles.set(scene, throttle());
1300
1364
  }
1301
1365
  draw(scene) {
1302
1366
  const scenes = this._scenes, handles = this._handles;
@@ -1331,7 +1395,7 @@ var Pacem;
1331
1395
  const m = tuple.transformMatrix;
1332
1396
  context.setTransform(m);
1333
1397
  // hit test
1334
- const pointer = this._pointer, offset = this._canvasOffset, point = { x: pointer.page.x - offset.x, y: pointer.page.y - offset.y };
1398
+ const pointer = this._pointer, offset = tuple.offset, point = { x: pointer.page.x - offset.x, y: pointer.page.y - offset.y };
1335
1399
  // draw recursively
1336
1400
  for (let drawable of items) {
1337
1401
  this._draw(scene, context, drawable, m, point);
@@ -1356,36 +1420,6 @@ var Pacem;
1356
1420
  // this._requestDraw(scene);
1357
1421
  }
1358
1422
  }
1359
- _itemDispatch(target, type, offset) {
1360
- if (!Pacem.Utils.isNull(target)) {
1361
- var dragArgs, originalEvent, evtType;
1362
- if (offset instanceof Event) {
1363
- originalEvent = offset;
1364
- }
1365
- else {
1366
- dragArgs = { item: target, offset: offset };
1367
- }
1368
- if (typeof type === 'string') {
1369
- evtType = type;
1370
- }
1371
- else {
1372
- evtType = type.type;
1373
- originalEvent = type.originalEvent;
1374
- }
1375
- const m = Pacem.Matrix2D.multiply({ a: 1, b: 0, c: 0, d: 1, e: -this._canvasOffset.x, f: -this._canvasOffset.y }, target.stage.transformMatrix);
1376
- const evt = () => offset instanceof Event ? new Pacem.Drawing.DrawableEvent(evtType, target, originalEvent, m) : new Pacem.Drawing.DragEvent(evtType, { detail: dragArgs, cancelable: evtType === Pacem.UI.DragDropEventType.Init || evtType === Pacem.UI.DragDropEventType.Drag }, originalEvent, m), itemevt = offset instanceof Event ? new Pacem.Drawing.DrawableEvent('item' + evtType, target, originalEvent, m) : new Pacem.Drawing.DragEvent('item' + evtType, { detail: dragArgs, cancelable: evtType === Pacem.UI.DragDropEventType.Init || evtType === Pacem.UI.DragDropEventType.Drag }, originalEvent, m);
1377
- var prevent = false;
1378
- if (target instanceof EventTarget) {
1379
- const evnt = evt();
1380
- target.dispatchEvent(evnt);
1381
- prevent = evnt.defaultPrevented;
1382
- }
1383
- target.stage.dispatchEvent(itemevt);
1384
- // was the event (in one of its forms) rejected?
1385
- return prevent || itemevt.defaultPrevented;
1386
- }
1387
- return false;
1388
- }
1389
1423
  _draw(scene, ctx, item, transform, point) {
1390
1424
  var _a;
1391
1425
  (_a = item.stage) !== null && _a !== void 0 ? _a : (item.stage = scene);
@@ -1480,7 +1514,7 @@ var Pacem;
1480
1514
  && !item.inert /* is hit-test visible? */
1481
1515
  && !Pacem.Utils.isNull(point)) {
1482
1516
  const bbox = ctx.measureText(item.text);
1483
- const width = bbox.width, height = bbox.actualBoundingBoxAscent + bbox.actualBoundingBoxDescent, x = item.anchor.x - bbox.actualBoundingBoxLeft, y = item.anchor.y - bbox.actualBoundingBoxAscent;
1517
+ const width = bbox.width, height = bbox.actualBoundingBoxAscent + bbox.actualBoundingBoxDescent, x = Math.round(item.anchor.x - bbox.actualBoundingBoxLeft), y = Math.round(item.anchor.y - bbox.actualBoundingBoxAscent);
1484
1518
  const path2D = new Path2D(`M ${x} ${y} h ${width} v ${height} H ${x} z`);
1485
1519
  if (hasColor && ctx.isPointInPath(path2D, point.x, point.y)) {
1486
1520
  // overwrite current hit-target (last one wins)
@@ -1605,13 +1639,15 @@ var Pacem;
1605
1639
  })(Drawing = Components.Drawing || (Components.Drawing = {}));
1606
1640
  })(Components = Pacem.Components || (Pacem.Components = {}));
1607
1641
  })(Pacem || (Pacem = {}));
1642
+ /// <reference path="../types.ts" />
1643
+ /// <reference path="utils.ts" />
1608
1644
  var Pacem;
1609
1645
  (function (Pacem) {
1610
1646
  var Components;
1611
1647
  (function (Components) {
1612
1648
  var Drawing;
1613
1649
  (function (Drawing) {
1614
- const SVG_NS = 'http://www.w3.org/2000/svg', DRAWABLE_VAR = 'pacem:drawable';
1650
+ const SVG_NS = 'http://www.w3.org/2000/svg', DRAWABLE_VAR = 'pacem:2-svg-drawable', STAGE_VAR = 'pacem:2d-svg-stage', GETVAR = Pacem.CustomElementUtils.getAttachedPropertyValue, SETVAR = Pacem.CustomElementUtils.setAttachedPropertyValue, DELVAR = Pacem.CustomElementUtils.deleteAttachedPropertyValue;
1615
1651
  function fallback(v, f) {
1616
1652
  return Pacem.Utils.isNull(v) ? f : v;
1617
1653
  }
@@ -1629,12 +1665,13 @@ var Pacem;
1629
1665
  super(...arguments);
1630
1666
  this._hitTarget = null;
1631
1667
  this._dragInitHandler = (evt) => {
1632
- const args = evt.detail, el = args.element, drawable = Pacem.CustomElementUtils.getAttachedPropertyValue(el, DRAWABLE_VAR), stageTransformMatrix = drawable.stage.transformMatrix, initialMatrix = drawable.transformMatrix;
1668
+ var _a;
1669
+ const args = evt.detail, el = args.element, drawable = GETVAR(el, DRAWABLE_VAR), stageTransformMatrix = drawable.stage.transformMatrix, initialMatrix = (_a = drawable.transformMatrix) !== null && _a !== void 0 ? _a : Pacem.Matrix2D.identity;
1633
1670
  args.data = {
1634
1671
  stageTransformMatrix, item: drawable,
1635
1672
  initialTransformMatrix: initialMatrix
1636
1673
  };
1637
- const reject = this._itemDispatch(drawable, evt, { x: 0, y: 0 });
1674
+ const reject = Drawing.AdapterUtils.itemDispatch(drawable, evt, { x: 0, y: 0 });
1638
1675
  if (reject) {
1639
1676
  // reject dragging
1640
1677
  evt.preventDefault();
@@ -1659,7 +1696,7 @@ var Pacem;
1659
1696
  //console.log(`offset: ${offset.x},${offset.y}`);
1660
1697
  //console.log(data.stageTransformMatrix);
1661
1698
  //console.log(el.style.transform); console.log(data.initialTransformMatrix);
1662
- const rejected = this._itemDispatch(data.item, evt, stageOffset);
1699
+ const rejected = Drawing.AdapterUtils.itemDispatch(data.item, evt, stageOffset);
1663
1700
  if (!rejected) {
1664
1701
  el.style.transform = `matrix(1,0,0,1,${offset.x},${offset.y})`;
1665
1702
  }
@@ -1674,10 +1711,11 @@ var Pacem;
1674
1711
  data.item.translateY = transform.f;
1675
1712
  }
1676
1713
  else {
1677
- Pacem.Utils.extend(data.item, { transformMatrix: Pacem.Matrix2D.translate(data.initialTransformMatrix, offset) });
1714
+ const init = data.initialTransformMatrix, actual = { a: init.a, b: init.b, c: init.c, d: init.d, e: offset.x, f: offset.y };
1715
+ Pacem.Utils.extend(data.item, { transformMatrix: actual });
1678
1716
  }
1679
1717
  el.style.transform = '';
1680
- this._itemDispatch(data.item, evt, { x: transform.e, y: transform.f });
1718
+ Drawing.AdapterUtils.itemDispatch(data.item, evt, { x: transform.e, y: transform.f });
1681
1719
  };
1682
1720
  this._mousemoveHandler = (evt) => {
1683
1721
  var pt = Pacem.CustomEventUtils.getEventCoordinates(evt).client;
@@ -1685,32 +1723,47 @@ var Pacem;
1685
1723
  // not dragging around
1686
1724
  var d = null;
1687
1725
  var el = document.elementsFromPoint(pt.x, pt.y).find(i => {
1688
- d = Pacem.CustomElementUtils.getAttachedPropertyValue(i, DRAWABLE_VAR);
1726
+ d = GETVAR(i, DRAWABLE_VAR);
1689
1727
  return d && !d.inert;
1690
1728
  });
1691
1729
  var old = this._hitTarget, val = d;
1692
1730
  if (Pacem.Utils.isNull(d && d.stage) || !this._scenes.has(d.stage) || d.inert) {
1693
1731
  val = null;
1694
1732
  }
1695
- this._hitTarget = val;
1733
+ const hitTarget = this._hitTarget = val;
1696
1734
  if (val !== old) {
1697
1735
  if (!Pacem.Utils.isNull(old)) {
1698
1736
  this._dragger.unregister(this._items.get(old));
1699
- this._itemDispatch(old, 'out', evt);
1737
+ Drawing.AdapterUtils.itemDispatch(old, 'out', evt);
1700
1738
  }
1701
1739
  if (!Pacem.Utils.isNull(val)) {
1702
1740
  if (val.draggable) {
1703
1741
  this._dragger.register(this._items.get(val));
1704
1742
  }
1705
- this._itemDispatch(val, 'over', evt);
1743
+ Drawing.AdapterUtils.itemDispatch(val, 'over', evt);
1744
+ }
1745
+ }
1746
+ if (Pacem.Utils.isNull(hitTarget)) {
1747
+ // dispatch only if no hit target
1748
+ const svg = evt.currentTarget;
1749
+ const stage = GETVAR(svg, STAGE_VAR);
1750
+ if (!Pacem.Utils.isNull(stage)) {
1751
+ Drawing.AdapterUtils.stageDispatch(stage, 'move', evt);
1706
1752
  }
1707
1753
  }
1708
1754
  }
1709
1755
  };
1710
1756
  this._mouseDownUpHandler = (evt) => {
1711
- if (!Pacem.Utils.isNull(this._hitTarget)) {
1757
+ const svg = evt.currentTarget;
1758
+ if (svg instanceof SVGSVGElement) {
1759
+ const stage = GETVAR(svg, STAGE_VAR), hitTarget = this._hitTarget;
1712
1760
  const type = evt.type.replace(/^mouse/, '');
1713
- this._itemDispatch(this._hitTarget, type, evt);
1761
+ if (!Pacem.Utils.isNull(hitTarget) && hitTarget.stage === stage) {
1762
+ Drawing.AdapterUtils.itemDispatch(this._hitTarget, type, evt);
1763
+ }
1764
+ else {
1765
+ Drawing.AdapterUtils.stageDispatch(stage, type, evt);
1766
+ }
1714
1767
  }
1715
1768
  };
1716
1769
  this._scenes = new WeakMap();
@@ -1791,6 +1844,7 @@ var Pacem;
1791
1844
  stage.innerHTML = '';
1792
1845
  this._items = new WeakMap();
1793
1846
  var svg = document.createElementNS(SVG_NS, 'svg');
1847
+ SETVAR(svg, STAGE_VAR, scene);
1794
1848
  stage.appendChild(svg);
1795
1849
  scenes.set(scene, svg);
1796
1850
  const options = { passive: false, capture: true };
@@ -1811,6 +1865,7 @@ var Pacem;
1811
1865
  svg.removeEventListener('mousedown', this._mouseDownUpHandler);
1812
1866
  svg.removeEventListener('mouseup', this._mouseDownUpHandler);
1813
1867
  // remove
1868
+ DELVAR(svg, STAGE_VAR);
1814
1869
  svg.remove();
1815
1870
  scenes.delete(scene);
1816
1871
  }
@@ -1853,42 +1908,13 @@ var Pacem;
1853
1908
  }
1854
1909
  this._draw(scene, parent, items || [], flow, deepRedraw);
1855
1910
  }
1856
- _itemDispatch(target, type, offset) {
1857
- if (!Pacem.Utils.isNull(target)) {
1858
- var dragArgs, originalEvent, evtType;
1859
- if (offset instanceof Event) {
1860
- originalEvent = offset;
1861
- }
1862
- else {
1863
- dragArgs = { item: target, offset: offset };
1864
- }
1865
- if (typeof type === 'string') {
1866
- evtType = type;
1867
- }
1868
- else {
1869
- evtType = type.type;
1870
- originalEvent = type.originalEvent;
1871
- }
1872
- const m = target.stage.transformMatrix;
1873
- const evt = () => offset instanceof Event ? new Pacem.Drawing.DrawableEvent(evtType, target, originalEvent, m) : new Pacem.Drawing.DragEvent(evtType, { detail: dragArgs, cancelable: evtType === Pacem.UI.DragDropEventType.Init || evtType === Pacem.UI.DragDropEventType.Drag }, originalEvent, m), itemevt = offset instanceof Event ? new Pacem.Drawing.DrawableEvent('item' + evtType, target, originalEvent, m) : new Pacem.Drawing.DragEvent('item' + evtType, { detail: dragArgs, cancelable: evtType === Pacem.UI.DragDropEventType.Init || evtType === Pacem.UI.DragDropEventType.Drag }, originalEvent, m);
1874
- var prevent = false;
1875
- if (target instanceof EventTarget) {
1876
- const evnt = evt();
1877
- target.dispatchEvent(evnt);
1878
- prevent = evnt.defaultPrevented;
1879
- }
1880
- target.stage.dispatchEvent(itemevt);
1881
- // was the event (in one of its forms) rejected?
1882
- return prevent || itemevt.defaultPrevented;
1883
- }
1884
- return false;
1885
- }
1886
1911
  _hasItems(object) {
1887
1912
  return Pacem.Drawing.isGroup(object);
1888
1913
  }
1889
1914
  _disposeSvg(el) {
1890
1915
  if (!Pacem.Utils.isNull(el)) {
1891
- var drawable = Pacem.CustomElementUtils.getAttachedPropertyValue(el, DRAWABLE_VAR);
1916
+ var drawable = GETVAR(el, DRAWABLE_VAR);
1917
+ DELVAR(el, DRAWABLE_VAR);
1892
1918
  this._items.delete(drawable);
1893
1919
  }
1894
1920
  }
@@ -1906,7 +1932,7 @@ var Pacem;
1906
1932
  let el;
1907
1933
  if (!dict.has(item)) {
1908
1934
  el = this._buildSVGElement(item);
1909
- Pacem.CustomElementUtils.setAttachedPropertyValue(el, DRAWABLE_VAR, item);
1935
+ SETVAR(el, DRAWABLE_VAR, item);
1910
1936
  this._disposeSvg(replaceChildAt(parent, el, j));
1911
1937
  dict.set(item, el);
1912
1938
  }