@pacem/pacem-ui 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 (56) hide show
  1. package/LICENSE +191 -0
  2. package/NOTICE +4 -0
  3. package/dist/browser/pacem-ui.js +6343 -0
  4. package/dist/browser/pacem-ui.js.map +1 -0
  5. package/dist/browser/pacem-ui.min.js +2 -0
  6. package/dist/browser/pacem-ui.min.js.map +1 -0
  7. package/dist/bundle/pacem-ui.min.mjs +168 -0
  8. package/dist/bundle/pacem-ui.mjs +6276 -0
  9. package/dist/bundle/pacem-ui.mjs.map +7 -0
  10. package/dist/esm/adapter.js +360 -0
  11. package/dist/esm/anchor.js +149 -0
  12. package/dist/esm/balloon.js +583 -0
  13. package/dist/esm/binder.js +678 -0
  14. package/dist/esm/blade.js +31 -0
  15. package/dist/esm/bottom-sheet.js +277 -0
  16. package/dist/esm/button.js +100 -0
  17. package/dist/esm/buttonset.js +41 -0
  18. package/dist/esm/calendar.js +662 -0
  19. package/dist/esm/collapse.js +72 -0
  20. package/dist/esm/dialog-abstractions.js +61 -0
  21. package/dist/esm/dialog.js +102 -0
  22. package/dist/esm/divider.js +48 -0
  23. package/dist/esm/icon.js +131 -0
  24. package/dist/esm/image.js +109 -0
  25. package/dist/esm/index-components-ui.js +41 -0
  26. package/dist/esm/index-components.js +1 -0
  27. package/dist/esm/index-iife.js +3 -0
  28. package/dist/esm/index.js +1 -0
  29. package/dist/esm/infinite-scroller.js +137 -0
  30. package/dist/esm/iterative.js +45 -0
  31. package/dist/esm/lightbox-abstractions.js +6 -0
  32. package/dist/esm/lightbox.js +203 -0
  33. package/dist/esm/loader.js +100 -0
  34. package/dist/esm/markdown-svc.js +235 -0
  35. package/dist/esm/markdown.js +35 -0
  36. package/dist/esm/marquee.js +87 -0
  37. package/dist/esm/media-query.js +85 -0
  38. package/dist/esm/menu.js +165 -0
  39. package/dist/esm/pager.js +111 -0
  40. package/dist/esm/picture.js +157 -0
  41. package/dist/esm/progressbar.js +54 -0
  42. package/dist/esm/sidebar.js +60 -0
  43. package/dist/esm/slideshow.js +27 -0
  44. package/dist/esm/social-twitter.js +39 -0
  45. package/dist/esm/sticky-header.js +113 -0
  46. package/dist/esm/tabs.js +187 -0
  47. package/dist/esm/ticker.js +78 -0
  48. package/dist/esm/toast.js +171 -0
  49. package/dist/esm/toc.js +171 -0
  50. package/dist/esm/tuner.js +200 -0
  51. package/dist/esm/types.js +7 -0
  52. package/dist/esm/vibration.js +33 -0
  53. package/dist/esm/view.js +206 -0
  54. package/dist/esm/window.js +181 -0
  55. package/package.json +38 -0
  56. package/typings/index.d.ts +1165 -0
@@ -0,0 +1,678 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { P, PCSS, CustomElement, Watch, Utils, PropertyConverters, Components, CustomUIEvent, CustomElementUtils } from '@pacem/pacem-core';
8
+ import { Point } from '@pacem/pacem-foundation';
9
+ import { ElementOrPointPropertyConverter } from './types';
10
+ // namespace Pacem.Components.UI {
11
+ export var BinderAnchor;
12
+ (function (BinderAnchor) {
13
+ BinderAnchor["Auto"] = "auto";
14
+ BinderAnchor["Left"] = "left";
15
+ BinderAnchor["Top"] = "top";
16
+ BinderAnchor["Right"] = "right";
17
+ BinderAnchor["Bottom"] = "bottom";
18
+ BinderAnchor["Center"] = "center";
19
+ })(BinderAnchor || (BinderAnchor = {}));
20
+ export var BinderEnd;
21
+ (function (BinderEnd) {
22
+ BinderEnd["Default"] = "default";
23
+ BinderEnd["Arrow"] = "arrow";
24
+ BinderEnd["FatArrow"] = "fatarrow";
25
+ BinderEnd["None"] = "none";
26
+ })(BinderEnd || (BinderEnd = {}));
27
+ export var BinderTension;
28
+ (function (BinderTension) {
29
+ BinderTension["Mass"] = "mass";
30
+ BinderTension["Path"] = "path";
31
+ })(BinderTension || (BinderTension = {}));
32
+ export const BinderInteractionEventName = 'interact';
33
+ export class BinderInteractionEvent extends CustomUIEvent {
34
+ constructor(orig) {
35
+ super(BinderInteractionEventName, null, orig);
36
+ }
37
+ }
38
+ const UI_BINDERS = 'pacem:components:ui:binders';
39
+ class BindersCollector {
40
+ constructor(element) {
41
+ this.binders = [];
42
+ this.fire = (evt) => {
43
+ for (var binder of this.binders) {
44
+ binder.refresh(this.resize.target, evt.detail);
45
+ }
46
+ };
47
+ const watcher = this.resize = new Components.PacemResizeElement();
48
+ watcher.target = element;
49
+ watcher.watchPosition = true;
50
+ document.body.appendChild(watcher);
51
+ }
52
+ dispose() {
53
+ this.resize.remove();
54
+ }
55
+ }
56
+ class BinderUtils {
57
+ static { this._pageBinders = []; }
58
+ static _updateResizeListener() {
59
+ const binders = this._pageBinders;
60
+ if (Utils.isNull(this._bodyResizeListener)) {
61
+ const resize = this._bodyResizeListener = new Components.PacemResizeElement();
62
+ resize.target = document.body;
63
+ document.body.appendChild(resize);
64
+ document.addEventListener(Components.ResizeEventName, () => {
65
+ for (let binder of binders) {
66
+ binder.invalidateSize();
67
+ }
68
+ }, false);
69
+ }
70
+ this._bodyResizeListener.disabled = binders.length === 0;
71
+ }
72
+ static register(element, binder) {
73
+ var collector = CustomElementUtils.getAttachedPropertyValue(element, UI_BINDERS), binders = this._pageBinders;
74
+ if (Utils.isNull(collector)) {
75
+ collector = new BindersCollector(element);
76
+ CustomElementUtils.setAttachedPropertyValue(element, UI_BINDERS, collector);
77
+ }
78
+ if (collector.binders.indexOf(binder) == -1) {
79
+ if (collector.binders.length === 0) {
80
+ collector.resize.addEventListener(Components.ResizeEventName, collector.fire, false);
81
+ } //else {
82
+ binder.refresh(element, collector.resize.currentSize);
83
+ //}
84
+ collector.binders.push(binder);
85
+ }
86
+ if (binders.indexOf(binder) === -1) {
87
+ binders.push(binder);
88
+ this._updateResizeListener();
89
+ }
90
+ }
91
+ static unregister(element, binder) {
92
+ var collector = CustomElementUtils.getAttachedPropertyValue(element, UI_BINDERS), ndx, binders = this._pageBinders, ndx2;
93
+ if (!Utils.isNull(collector) && (ndx = collector.binders.indexOf(binder)) > -1) {
94
+ collector.binders.splice(ndx, 1);
95
+ if (collector.binders.length === 0) {
96
+ collector.resize.removeEventListener(Components.ResizeEventName, collector.fire, false);
97
+ collector.dispose();
98
+ CustomElementUtils.deleteAttachedPropertyValue(element, UI_BINDERS);
99
+ }
100
+ }
101
+ if ((ndx2 = binders.indexOf(binder)) >= 0) {
102
+ binders.splice(ndx2, 1);
103
+ this._updateResizeListener();
104
+ }
105
+ }
106
+ }
107
+ const STD_EVENTS = ['click', 'dblclick', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'mousedown', 'mouseup', 'mousemove', 'contextmenu'];
108
+ let PacemBinderElement = class PacemBinderElement extends Components.PacemElement {
109
+ constructor() {
110
+ super(...arguments);
111
+ this._broadcastHandler = (evt) => {
112
+ var ui = new BinderInteractionEvent(evt);
113
+ this.dispatchEvent(ui);
114
+ };
115
+ this._state = {};
116
+ }
117
+ connectedCallback() {
118
+ super.connectedCallback();
119
+ this._ensurePath();
120
+ }
121
+ viewActivatedCallback() {
122
+ super.viewActivatedCallback();
123
+ if (this.from instanceof Element)
124
+ BinderUtils.register(this.from, this);
125
+ if (this.to instanceof Element)
126
+ BinderUtils.register(this.to, this);
127
+ }
128
+ propertyChangedCallback(name, old, val, first) {
129
+ super.propertyChangedCallback(name, old, val, first);
130
+ switch (name) {
131
+ case 'from':
132
+ case 'to':
133
+ if (old instanceof Element) {
134
+ BinderUtils.unregister(old, this);
135
+ }
136
+ if (val instanceof Element) {
137
+ // `BinderUtils.register` eventually calls `.refresh`
138
+ BinderUtils.register(val, this);
139
+ }
140
+ else {
141
+ this.refresh(val);
142
+ }
143
+ break;
144
+ case 'fromLimit':
145
+ case 'toLimit':
146
+ case 'fromEnd':
147
+ case 'toEnd':
148
+ case 'tension':
149
+ this._draw();
150
+ break;
151
+ case 'fromAnchor':
152
+ this.refresh(this.from);
153
+ break;
154
+ case 'toAnchor':
155
+ this.refresh(this.to);
156
+ break;
157
+ case 'cssClass':
158
+ if (!Utils.isNull(this._svg)) {
159
+ this._svg.setAttribute('class', PCSS + '-binder ' + this.className);
160
+ }
161
+ break;
162
+ case 'hide':
163
+ if (!first) {
164
+ this._setPathVisibility();
165
+ }
166
+ break;
167
+ }
168
+ }
169
+ disconnectedCallback() {
170
+ if (!Utils.isNull(this._path)) {
171
+ STD_EVENTS.forEach(e => {
172
+ this._path.removeEventListener(e, this._broadcastHandler, false);
173
+ });
174
+ this._svg.remove();
175
+ this._path = undefined;
176
+ }
177
+ if (this.from instanceof Element)
178
+ BinderUtils.unregister(this.from, this);
179
+ if (this.to instanceof Element)
180
+ BinderUtils.unregister(this.to, this);
181
+ super.disconnectedCallback();
182
+ }
183
+ _setPathVisibility(path = this._path, hide = this.hide, interactive = this.interactive) {
184
+ if (!Utils.isNull(path)) {
185
+ if (hide) {
186
+ path.setAttribute('display', 'none');
187
+ }
188
+ else {
189
+ path.removeAttribute('display');
190
+ }
191
+ if (interactive) {
192
+ path.setAttribute('pointer-events', 'visibleStroke');
193
+ path.tabIndex = 0;
194
+ }
195
+ else {
196
+ path.removeAttribute('pointer-events');
197
+ path.tabIndex = -1;
198
+ }
199
+ }
200
+ }
201
+ _ensurePath() {
202
+ if (Utils.isNull(this._path)) {
203
+ let svg = this._svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
204
+ svg.style.position = 'absolute';
205
+ Utils.addClass(svg, PCSS + '-binder ' + this.className);
206
+ svg.style.top = '0';
207
+ svg.style.left = '0';
208
+ svg.style.overflow = 'hidden';
209
+ svg.style.pointerEvents = 'none';
210
+ const path = this._path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
211
+ path.setAttribute('fill', 'none');
212
+ path.setAttribute('display', 'none');
213
+ this._setPathVisibility();
214
+ svg.appendChild(path);
215
+ this.invalidateSize();
216
+ document.body.appendChild(svg);
217
+ STD_EVENTS.forEach(e => {
218
+ path.addEventListener(e, this._broadcastHandler, false);
219
+ });
220
+ }
221
+ }
222
+ invalidateSize() {
223
+ const svg = this._svg;
224
+ if (!Utils.isNull(svg)) {
225
+ svg.setAttribute('width', document.body.scrollWidth.toString());
226
+ svg.setAttribute('height', document.body.scrollHeight.toString());
227
+ }
228
+ }
229
+ _computeAnchorPoints(target, anchor, end, ref, refAnchor, refEnd, tension) {
230
+ var p1, p2, c1, c2;
231
+ const top = target.top, left = target.left, w = target.width, h = target.height, w2 = w / 2, h2 = h / 2;
232
+ const r_top = ref.top, r_left = ref.left, r_w = ref.width, r_h = ref.height, r_w2 = r_w / 2, r_h2 = r_h / 2;
233
+ const p1_center = { x: left + w2, y: top + h2 };
234
+ const p2_center = { x: r_left + r_w2, y: r_top + r_h2 };
235
+ const p1_top = { x: left + w2, y: top };
236
+ const p1_bottom = { x: left + w2, y: top + h };
237
+ const p1_left = { x: left, y: top + h2 };
238
+ const p1_right = { x: left + w, y: top + h2 };
239
+ const p2_top = { x: r_left + r_w2, y: r_top };
240
+ const p2_bottom = { x: r_left + r_w2, y: r_top + r_h };
241
+ const p2_left = { x: r_left, y: r_top + r_h2 };
242
+ const p2_right = { x: r_left + r_w, y: r_top + r_h2 };
243
+ const points = {
244
+ 'p1_top': p1_top,
245
+ 'p1_bottom': p1_bottom,
246
+ 'p1_left': p1_left,
247
+ 'p1_right': p1_right,
248
+ 'p2_top': p2_top,
249
+ 'p2_bottom': p2_bottom,
250
+ 'p2_left': p2_left,
251
+ 'p2_right': p2_right,
252
+ };
253
+ var distance_memoizer = {};
254
+ function getDistance(suffix1, suffix2) {
255
+ const key = suffix1 + '_' + suffix2;
256
+ return distance_memoizer[key] = distance_memoizer[key] || Point.distance(points['p1_' + suffix1], points['p2_' + suffix2]);
257
+ }
258
+ if (anchor == BinderAnchor.Auto || refAnchor == BinderAnchor.Auto) {
259
+ //if (anchor == BinderAnchor.Auto && refAnchor == BinderAnchor.Auto) {
260
+ // algorithm for finding the closest edges (1 atan + 4 distances)
261
+ // 1. compute atan of the segment joining the two centers
262
+ const a = { x: p1_center.x, y: -p1_center.y }, b = { x: p2_center.x, y: -p2_center.y };
263
+ const slope = Math.atan2(b.y - a.y, b.x - a.x) * 180 / Math.PI;
264
+ switch (slope) {
265
+ case 0:
266
+ if (anchor == BinderAnchor.Auto)
267
+ anchor = BinderAnchor.Right;
268
+ if (refAnchor == BinderAnchor.Auto)
269
+ refAnchor = BinderAnchor.Left;
270
+ break;
271
+ case 90:
272
+ if (anchor == BinderAnchor.Auto)
273
+ anchor = BinderAnchor.Top;
274
+ if (refAnchor == BinderAnchor.Auto)
275
+ refAnchor = BinderAnchor.Bottom;
276
+ break;
277
+ case 180:
278
+ if (anchor == BinderAnchor.Auto)
279
+ anchor = BinderAnchor.Left;
280
+ if (refAnchor == BinderAnchor.Auto)
281
+ refAnchor = BinderAnchor.Right;
282
+ break;
283
+ case -90:
284
+ if (anchor == BinderAnchor.Auto)
285
+ anchor = BinderAnchor.Bottom;
286
+ if (refAnchor == BinderAnchor.Auto)
287
+ refAnchor = BinderAnchor.Top;
288
+ break;
289
+ default:
290
+ // 2. compute distances combining the 4 points (compare 4 distances)
291
+ if (slope < 90 && slope > 0) {
292
+ // right | top vs left | bottom
293
+ let top_2_left = getDistance('top', 'left'), right_2_left = getDistance('right', 'left'), right_2_bottom = getDistance('right', 'bottom'), top_2_bottom = getDistance('top', 'bottom');
294
+ var d = Math.min(top_2_left, right_2_left, right_2_bottom, top_2_bottom);
295
+ switch (d) {
296
+ case top_2_left:
297
+ if (anchor == BinderAnchor.Auto)
298
+ anchor = BinderAnchor.Top;
299
+ if (refAnchor == BinderAnchor.Auto)
300
+ refAnchor = BinderAnchor.Left;
301
+ break;
302
+ case top_2_bottom:
303
+ if (anchor == BinderAnchor.Auto)
304
+ anchor = BinderAnchor.Top;
305
+ if (refAnchor == BinderAnchor.Auto)
306
+ refAnchor = BinderAnchor.Bottom;
307
+ break;
308
+ case right_2_bottom:
309
+ if (anchor == BinderAnchor.Auto)
310
+ anchor = BinderAnchor.Right;
311
+ if (refAnchor == BinderAnchor.Auto)
312
+ refAnchor = BinderAnchor.Bottom;
313
+ break;
314
+ default:
315
+ if (anchor == BinderAnchor.Auto)
316
+ anchor = BinderAnchor.Right;
317
+ if (refAnchor == BinderAnchor.Auto)
318
+ refAnchor = BinderAnchor.Left;
319
+ break;
320
+ }
321
+ }
322
+ else if (slope < 180 && slope > 90) {
323
+ // left | top vs right | bottom
324
+ let top_2_right = getDistance('top', 'right'), left_2_right = getDistance('left', 'right'), left_2_bottom = getDistance('left', 'bottom'), top_2_bottom = getDistance('top', 'bottom');
325
+ var d = Math.min(top_2_right, left_2_right, left_2_bottom, top_2_bottom);
326
+ switch (d) {
327
+ case top_2_right:
328
+ if (anchor == BinderAnchor.Auto)
329
+ anchor = BinderAnchor.Top;
330
+ if (refAnchor == BinderAnchor.Auto)
331
+ refAnchor = BinderAnchor.Right;
332
+ break;
333
+ case left_2_right:
334
+ if (anchor == BinderAnchor.Auto)
335
+ anchor = BinderAnchor.Left;
336
+ if (refAnchor == BinderAnchor.Auto)
337
+ refAnchor = BinderAnchor.Right;
338
+ break;
339
+ case left_2_bottom:
340
+ if (anchor == BinderAnchor.Auto)
341
+ anchor = BinderAnchor.Left;
342
+ if (refAnchor == BinderAnchor.Auto)
343
+ refAnchor = BinderAnchor.Bottom;
344
+ break;
345
+ default:
346
+ if (anchor == BinderAnchor.Auto)
347
+ anchor = BinderAnchor.Top;
348
+ if (refAnchor == BinderAnchor.Auto)
349
+ refAnchor = BinderAnchor.Bottom;
350
+ break;
351
+ }
352
+ }
353
+ else if (slope < -90) {
354
+ // left | bottom vs right | top
355
+ let bottom_2_right = getDistance('bottom', 'right'), left_2_right = getDistance('left', 'right'), left_2_top = getDistance('left', 'top'), bottom_2_top = getDistance('bottom', 'top');
356
+ var d = Math.min(bottom_2_right, left_2_right, left_2_top, bottom_2_top);
357
+ switch (d) {
358
+ case bottom_2_right:
359
+ if (anchor == BinderAnchor.Auto)
360
+ anchor = BinderAnchor.Bottom;
361
+ if (refAnchor == BinderAnchor.Auto)
362
+ refAnchor = BinderAnchor.Right;
363
+ break;
364
+ case left_2_right:
365
+ if (anchor == BinderAnchor.Auto)
366
+ anchor = BinderAnchor.Left;
367
+ if (refAnchor == BinderAnchor.Auto)
368
+ refAnchor = BinderAnchor.Right;
369
+ break;
370
+ case left_2_top:
371
+ if (anchor == BinderAnchor.Auto)
372
+ anchor = BinderAnchor.Left;
373
+ if (refAnchor == BinderAnchor.Auto)
374
+ refAnchor = BinderAnchor.Top;
375
+ break;
376
+ default:
377
+ if (anchor == BinderAnchor.Auto)
378
+ anchor = BinderAnchor.Bottom;
379
+ if (refAnchor == BinderAnchor.Auto)
380
+ refAnchor = BinderAnchor.Top;
381
+ break;
382
+ }
383
+ }
384
+ else {
385
+ // right | bottom vs left | top
386
+ let bottom_2_left = getDistance('bottom', 'left'), right_2_left = getDistance('right', 'left'), right_2_top = getDistance('right', 'top'), bottom_2_top = getDistance('bottom', 'top');
387
+ var d = Math.min(bottom_2_left, right_2_left, right_2_top, bottom_2_top);
388
+ switch (d) {
389
+ case bottom_2_left:
390
+ if (anchor == BinderAnchor.Auto)
391
+ anchor = BinderAnchor.Bottom;
392
+ if (refAnchor == BinderAnchor.Auto)
393
+ refAnchor = BinderAnchor.Left;
394
+ break;
395
+ case right_2_left:
396
+ if (anchor == BinderAnchor.Auto)
397
+ anchor = BinderAnchor.Right;
398
+ if (refAnchor == BinderAnchor.Auto)
399
+ refAnchor = BinderAnchor.Left;
400
+ break;
401
+ case right_2_top:
402
+ if (anchor == BinderAnchor.Auto)
403
+ anchor = BinderAnchor.Right;
404
+ if (refAnchor == BinderAnchor.Auto)
405
+ refAnchor = BinderAnchor.Top;
406
+ break;
407
+ default:
408
+ if (anchor == BinderAnchor.Auto)
409
+ anchor = BinderAnchor.Bottom;
410
+ if (refAnchor == BinderAnchor.Auto)
411
+ refAnchor = BinderAnchor.Top;
412
+ break;
413
+ }
414
+ }
415
+ break;
416
+ }
417
+ //}
418
+ }
419
+ function computeF(e) {
420
+ switch (e) {
421
+ case BinderEnd.Arrow:
422
+ case BinderEnd.FatArrow:
423
+ return 2.0;
424
+ default:
425
+ return 1.0;
426
+ }
427
+ }
428
+ const f = computeF(end), refF = computeF(refEnd);
429
+ // anchor points calc
430
+ switch (anchor) {
431
+ case BinderAnchor.Bottom:
432
+ p1 = p1_bottom;
433
+ break;
434
+ case BinderAnchor.Center:
435
+ p1 = { x: left + w2, y: top + h2 };
436
+ c1 = p1;
437
+ break;
438
+ case BinderAnchor.Left:
439
+ p1 = p1_left;
440
+ break;
441
+ case BinderAnchor.Right:
442
+ p1 = p1_right;
443
+ break;
444
+ case BinderAnchor.Top:
445
+ p1 = p1_top;
446
+ break;
447
+ }
448
+ switch (refAnchor) {
449
+ case BinderAnchor.Bottom:
450
+ p2 = p2_bottom;
451
+ break;
452
+ case BinderAnchor.Center:
453
+ p2 = { x: r_left + r_w2, y: r_top + r_h2 };
454
+ c2 = p2;
455
+ break;
456
+ case BinderAnchor.Left:
457
+ p2 = p2_left;
458
+ break;
459
+ case BinderAnchor.Right:
460
+ p2 = p2_right;
461
+ break;
462
+ case BinderAnchor.Top:
463
+ p2 = p2_top;
464
+ break;
465
+ }
466
+ // control points calc
467
+ switch (tension) {
468
+ case BinderTension.Path:
469
+ // adjust the control points based on the path (not on the masses of the element ends)
470
+ const t = .333; // < tension (fraction of the distance)
471
+ switch (anchor) {
472
+ case BinderAnchor.Bottom:
473
+ c1 = { x: p1.x, y: p1.y + Math.abs(f * t * (p2.y - p1.y)) };
474
+ break;
475
+ case BinderAnchor.Left:
476
+ c1 = { x: p1.x - Math.abs(f * t * (p2.x - p1.x)), y: p1.y };
477
+ break;
478
+ case BinderAnchor.Right:
479
+ c1 = { x: p1.x + Math.abs(f * t * (p2.x - p1.x)), y: p1.y };
480
+ break;
481
+ case BinderAnchor.Top:
482
+ c1 = { x: p1.x, y: p1.y - Math.abs(f * t * (p1.y - p2.y)) };
483
+ break;
484
+ }
485
+ switch (refAnchor) {
486
+ case BinderAnchor.Bottom:
487
+ c2 = { x: p2.x, y: p2.y + Math.abs(refF * t * (p2.y - p1.y)) };
488
+ break;
489
+ case BinderAnchor.Left:
490
+ c2 = { x: p2.x - Math.abs(refF * t * (p2.x - p1.x)), y: p2.y };
491
+ break;
492
+ case BinderAnchor.Right:
493
+ c2 = { x: p2.x + Math.abs(refF * t * (p2.x - p1.x)), y: p2.y };
494
+ break;
495
+ case BinderAnchor.Top:
496
+ c2 = { x: p2.x, y: p2.y - Math.abs(refF * t * (p2.y - p1.y)) };
497
+ break;
498
+ }
499
+ break;
500
+ default:
501
+ // control points computed based on the mass (size) of the element ends
502
+ switch (anchor) {
503
+ case BinderAnchor.Bottom:
504
+ c1 = { x: p1.x, y: p1.y + Math.abs(f * (p1_bottom.y - p1_center.y)) };
505
+ break;
506
+ case BinderAnchor.Left:
507
+ c1 = { x: p1.x - Math.abs(f * (p1_center.x - p1_left.x)), y: p1.y };
508
+ break;
509
+ case BinderAnchor.Right:
510
+ c1 = { x: p1.x + Math.abs(f * (p1_right.x - p1_center.x)), y: p1.y };
511
+ break;
512
+ case BinderAnchor.Top:
513
+ c1 = { x: p1.x, y: p1.y - Math.abs(f * (p1_top.y - p1_center.y)) };
514
+ break;
515
+ }
516
+ switch (refAnchor) {
517
+ case BinderAnchor.Bottom:
518
+ c2 = { x: p2.x, y: p2.y + Math.abs(refF * (p2_bottom.y - p2_center.y)) };
519
+ break;
520
+ case BinderAnchor.Left:
521
+ c2 = { x: p2.x - Math.abs(refF * (p2_center.x - p2_left.x)), y: p2.y };
522
+ break;
523
+ case BinderAnchor.Right:
524
+ c2 = { x: p2.x + Math.abs(refF * (p2_right.x - p2_center.x)), y: p2.y };
525
+ break;
526
+ case BinderAnchor.Top:
527
+ c2 = { x: p2.x, y: p2.y - Math.abs(refF * (p2_top.y - p2_center.y)) };
528
+ break;
529
+ }
530
+ }
531
+ return { points: [p1, c1, p2, c2], anchors: [anchor, refAnchor] };
532
+ }
533
+ refresh(element, args) {
534
+ var path;
535
+ if (Utils.isNull(element) || Utils.isNull(path = this._path)) {
536
+ return;
537
+ }
538
+ const draw = !Utils.isNull(this.from) && !Utils.isNull(this.to);
539
+ const leave = Utils.isNull(this.from) && Utils.isNull(this.to);
540
+ if (this.disabled || !draw) {
541
+ path.removeAttribute('d');
542
+ if (leave) {
543
+ return;
544
+ }
545
+ }
546
+ // compute anchor points
547
+ const key = element === this.from ? 'from' : 'to';
548
+ var anchor = (key === 'from' ? this.fromAnchor : this.toAnchor) || BinderAnchor.Auto;
549
+ if (Utils.isNull(args)) {
550
+ if (!(element instanceof Element)) {
551
+ args = { height: 0, width: 0, left: element.x, top: element.y };
552
+ anchor = BinderAnchor.Center;
553
+ }
554
+ else if (key in this._state) {
555
+ args = this._state[key].size;
556
+ }
557
+ }
558
+ if (Utils.isNull(args)) {
559
+ return;
560
+ }
561
+ this._state[key] = { size: args, anchor };
562
+ if (draw) {
563
+ this._draw();
564
+ }
565
+ }
566
+ //@Debounce()
567
+ _draw() {
568
+ var state1 = this._state['from'], state2 = this._state['to'], path = this._path;
569
+ if (Utils.isNull(path)) {
570
+ return;
571
+ }
572
+ if (Utils.isNullOrEmpty(state1)
573
+ || Utils.isNullOrEmpty(state2)
574
+ || (this.from instanceof HTMLElement && !Utils.isVisible(this.from))
575
+ || (this.to instanceof HTMLElement && !Utils.isVisible(this.to))) {
576
+ path.setAttribute('d', '');
577
+ return;
578
+ }
579
+ const { points, anchors } = this._computeAnchorPoints(state1.size, state1.anchor, this.fromEnd, state2.size, state2.anchor, this.toEnd, this.tension), p0 = points[0], c0 = points[1], p1 = points[2], c1 = points[3], anchor0 = anchors[0], anchor1 = anchors[1];
580
+ const x0 = p0.x;
581
+ const y0 = p0.y;
582
+ const cx0 = c0.x;
583
+ const cy0 = c0.y;
584
+ const x1 = p1.x;
585
+ const y1 = p1.y;
586
+ const cx1 = c1.x;
587
+ const cy1 = c1.y;
588
+ let dStart = this._getDefaultEndingPath(x0, y0);
589
+ switch (this.fromEnd) {
590
+ case BinderEnd.Arrow:
591
+ dStart = this._getArrowEndingPath(x0, y0, anchor0);
592
+ break;
593
+ case BinderEnd.FatArrow:
594
+ dStart = this._getFatArrowEndingPath(x0, y0, anchor0);
595
+ break;
596
+ case BinderEnd.None:
597
+ dStart = '';
598
+ break;
599
+ }
600
+ let dEnd = this._getDefaultEndingPath(x1, y1);
601
+ switch (this.toEnd) {
602
+ case BinderEnd.Arrow:
603
+ dEnd = this._getArrowEndingPath(x1, y1, anchor1);
604
+ break;
605
+ case BinderEnd.FatArrow:
606
+ dEnd = this._getFatArrowEndingPath(x1, y1, anchor1);
607
+ break;
608
+ case BinderEnd.None:
609
+ dEnd = '';
610
+ break;
611
+ }
612
+ const d = dStart + `M${x0},${y0} C${cx0},${cy0} ${cx1},${cy1} ${x1},${y1}` + dEnd;
613
+ if (d.indexOf('NaN') === -1) {
614
+ path.setAttribute('d', d);
615
+ }
616
+ if (!Utils.isNullOrEmpty(this.color))
617
+ path.style.stroke = this.color;
618
+ }
619
+ _getDefaultEndingPath(x, y) {
620
+ return `M${x - 2},${y - 2} h4 v4 h-4 z`;
621
+ }
622
+ _getArrowEndingPath(x, y, anchor) {
623
+ switch (anchor) {
624
+ case BinderAnchor.Bottom:
625
+ return `M${x - 4},${y + 4} l4,-4 l4,4`;
626
+ case BinderAnchor.Top:
627
+ return `M${x - 4},${y - 4} l4,4 l4,-4`;
628
+ case BinderAnchor.Left:
629
+ return `M${x - 4},${y - 4} l4,4 l-4,4`;
630
+ case BinderAnchor.Right:
631
+ return `M${x + 4},${y - 4} l-4,4 l4,4`;
632
+ default:
633
+ return '';
634
+ }
635
+ }
636
+ _getFatArrowEndingPath(x, y, anchor) {
637
+ switch (anchor) {
638
+ case BinderAnchor.Bottom:
639
+ case BinderAnchor.Top:
640
+ case BinderAnchor.Left:
641
+ case BinderAnchor.Right:
642
+ return this._getArrowEndingPath(x, y, anchor) + ' z';
643
+ default:
644
+ return '';
645
+ }
646
+ }
647
+ };
648
+ __decorate([
649
+ Watch({ emit: false, converter: ElementOrPointPropertyConverter })
650
+ ], PacemBinderElement.prototype, "from", void 0);
651
+ __decorate([
652
+ Watch({ emit: false, converter: ElementOrPointPropertyConverter })
653
+ ], PacemBinderElement.prototype, "to", void 0);
654
+ __decorate([
655
+ Watch({ emit: false, converter: PropertyConverters.String })
656
+ ], PacemBinderElement.prototype, "fromAnchor", void 0);
657
+ __decorate([
658
+ Watch({ emit: false, converter: PropertyConverters.String })
659
+ ], PacemBinderElement.prototype, "toAnchor", void 0);
660
+ __decorate([
661
+ Watch({ emit: false, converter: PropertyConverters.String })
662
+ ], PacemBinderElement.prototype, "fromEnd", void 0);
663
+ __decorate([
664
+ Watch({ emit: false, converter: PropertyConverters.String })
665
+ ], PacemBinderElement.prototype, "toEnd", void 0);
666
+ __decorate([
667
+ Watch({ emit: false, converter: PropertyConverters.String })
668
+ ], PacemBinderElement.prototype, "tension", void 0);
669
+ __decorate([
670
+ Watch({ emit: false, converter: PropertyConverters.String })
671
+ ], PacemBinderElement.prototype, "color", void 0);
672
+ __decorate([
673
+ Watch({ emit: false, converter: PropertyConverters.Boolean })
674
+ ], PacemBinderElement.prototype, "interactive", void 0);
675
+ PacemBinderElement = __decorate([
676
+ CustomElement({ tagName: P + '-binder' })
677
+ ], PacemBinderElement);
678
+ export { PacemBinderElement };