@sankhyalabs/ezui 5.17.2 → 5.18.0-dev.1

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.
@@ -0,0 +1,776 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index$1 = require('./index-1064511f.js');
6
+ const core = require('@sankhyalabs/core');
7
+
8
+ var numeric = function (value, unit) { return Number(value.slice(0, -1 * unit.length)); };
9
+
10
+ var parseValue = function (value) {
11
+ if (value.endsWith('px'))
12
+ { return { value: value, type: 'px', numeric: numeric(value, 'px') } }
13
+ if (value.endsWith('fr'))
14
+ { return { value: value, type: 'fr', numeric: numeric(value, 'fr') } }
15
+ if (value.endsWith('%'))
16
+ { return { value: value, type: '%', numeric: numeric(value, '%') } }
17
+ if (value === 'auto') { return { value: value, type: 'auto' } }
18
+ return null
19
+ };
20
+
21
+ var parse = function (rule) { return rule.split(' ').map(parseValue); };
22
+
23
+ var getSizeAtTrack = function (index, tracks, gap, end) {
24
+ if ( gap === void 0 ) { gap = 0; }
25
+ if ( end === void 0 ) { end = false; }
26
+
27
+ var newIndex = end ? index + 1 : index;
28
+ var trackSum = tracks
29
+ .slice(0, newIndex)
30
+ .reduce(function (accum, value) { return accum + value.numeric; }, 0);
31
+ var gapSum = gap ? index * gap : 0;
32
+
33
+ return trackSum + gapSum
34
+ };
35
+
36
+ var getStyles = function (rule, ownRules, matchedRules) { return ownRules.concat( matchedRules)
37
+ .map(function (r) { return r.style[rule]; })
38
+ .filter(function (style) { return style !== undefined && style !== ''; }); };
39
+
40
+ var getGapValue = function (unit, size) {
41
+ if (size.endsWith(unit)) {
42
+ return Number(size.slice(0, -1 * unit.length))
43
+ }
44
+ return null
45
+ };
46
+
47
+ var firstNonZero = function (tracks) {
48
+ // eslint-disable-next-line no-plusplus
49
+ for (var i = 0; i < tracks.length; i++) {
50
+ if (tracks[i].numeric > 0) {
51
+ return i
52
+ }
53
+ }
54
+ return null
55
+ };
56
+
57
+ var NOOP = function () { return false; };
58
+
59
+ var defaultWriteStyle = function (element, gridTemplateProp, style) {
60
+ // eslint-disable-next-line no-param-reassign
61
+ element.style[gridTemplateProp] = style;
62
+ };
63
+
64
+ var getOption = function (options, propName, def) {
65
+ var value = options[propName];
66
+ if (value !== undefined) {
67
+ return value
68
+ }
69
+ return def
70
+ };
71
+
72
+ function getMatchedCSSRules (el) {
73
+ var ref;
74
+
75
+ return (ref = [])
76
+ .concat.apply(
77
+ ref, Array.from(el.ownerDocument.styleSheets).map(function (s) {
78
+ var rules = [];
79
+
80
+ try {
81
+ rules = Array.from(s.cssRules || []);
82
+ } catch (e) {
83
+ // Ignore results on security error
84
+ }
85
+
86
+ return rules
87
+ })
88
+ )
89
+ .filter(function (r) {
90
+ var matches = false;
91
+ try {
92
+ matches = el.matches(r.selectorText);
93
+ } catch (e) {
94
+ // Ignore matching erros
95
+ }
96
+
97
+ return matches
98
+ });
99
+ }
100
+
101
+ var gridTemplatePropColumns = 'grid-template-columns';
102
+ var gridTemplatePropRows = 'grid-template-rows';
103
+
104
+ var Gutter = function Gutter(direction, options, parentOptions) {
105
+ this.direction = direction;
106
+ this.element = options.element;
107
+ this.track = options.track;
108
+
109
+ if (direction === 'column') {
110
+ this.gridTemplateProp = gridTemplatePropColumns;
111
+ this.gridGapProp = 'grid-column-gap';
112
+ this.cursor = getOption(
113
+ parentOptions,
114
+ 'columnCursor',
115
+ getOption(parentOptions, 'cursor', 'col-resize')
116
+ );
117
+ this.snapOffset = getOption(
118
+ parentOptions,
119
+ 'columnSnapOffset',
120
+ getOption(parentOptions, 'snapOffset', 30)
121
+ );
122
+ this.dragInterval = getOption(
123
+ parentOptions,
124
+ 'columnDragInterval',
125
+ getOption(parentOptions, 'dragInterval', 1)
126
+ );
127
+ this.clientAxis = 'clientX';
128
+ this.optionStyle = getOption(parentOptions, 'gridTemplateColumns');
129
+ } else if (direction === 'row') {
130
+ this.gridTemplateProp = gridTemplatePropRows;
131
+ this.gridGapProp = 'grid-row-gap';
132
+ this.cursor = getOption(
133
+ parentOptions,
134
+ 'rowCursor',
135
+ getOption(parentOptions, 'cursor', 'row-resize')
136
+ );
137
+ this.snapOffset = getOption(
138
+ parentOptions,
139
+ 'rowSnapOffset',
140
+ getOption(parentOptions, 'snapOffset', 30)
141
+ );
142
+ this.dragInterval = getOption(
143
+ parentOptions,
144
+ 'rowDragInterval',
145
+ getOption(parentOptions, 'dragInterval', 1)
146
+ );
147
+ this.clientAxis = 'clientY';
148
+ this.optionStyle = getOption(parentOptions, 'gridTemplateRows');
149
+ }
150
+
151
+ this.onDragStart = getOption(parentOptions, 'onDragStart', NOOP);
152
+ this.onDragEnd = getOption(parentOptions, 'onDragEnd', NOOP);
153
+ this.onDrag = getOption(parentOptions, 'onDrag', NOOP);
154
+ this.writeStyle = getOption(
155
+ parentOptions,
156
+ 'writeStyle',
157
+ defaultWriteStyle
158
+ );
159
+
160
+ this.startDragging = this.startDragging.bind(this);
161
+ this.stopDragging = this.stopDragging.bind(this);
162
+ this.drag = this.drag.bind(this);
163
+
164
+ this.minSizeStart = options.minSizeStart;
165
+ this.minSizeEnd = options.minSizeEnd;
166
+
167
+ if (options.element) {
168
+ this.element.addEventListener('mousedown', this.startDragging);
169
+ this.element.addEventListener('touchstart', this.startDragging);
170
+ }
171
+ };
172
+
173
+ Gutter.prototype.getDimensions = function getDimensions () {
174
+ var ref = this.grid.getBoundingClientRect();
175
+ var width = ref.width;
176
+ var height = ref.height;
177
+ var top = ref.top;
178
+ var bottom = ref.bottom;
179
+ var left = ref.left;
180
+ var right = ref.right;
181
+
182
+ if (this.direction === 'column') {
183
+ this.start = top;
184
+ this.end = bottom;
185
+ this.size = height;
186
+ } else if (this.direction === 'row') {
187
+ this.start = left;
188
+ this.end = right;
189
+ this.size = width;
190
+ }
191
+ };
192
+
193
+ Gutter.prototype.getSizeAtTrack = function getSizeAtTrack$1 (track, end) {
194
+ return getSizeAtTrack(
195
+ track,
196
+ this.computedPixels,
197
+ this.computedGapPixels,
198
+ end
199
+ )
200
+ };
201
+
202
+ Gutter.prototype.getSizeOfTrack = function getSizeOfTrack (track) {
203
+ return this.computedPixels[track].numeric
204
+ };
205
+
206
+ Gutter.prototype.getRawTracks = function getRawTracks () {
207
+ var tracks = getStyles(
208
+ this.gridTemplateProp,
209
+ [this.grid],
210
+ getMatchedCSSRules(this.grid)
211
+ );
212
+ if (!tracks.length) {
213
+ if (this.optionStyle) { return this.optionStyle }
214
+
215
+ throw Error('Unable to determine grid template tracks from styles.')
216
+ }
217
+ return tracks[0]
218
+ };
219
+
220
+ Gutter.prototype.getGap = function getGap () {
221
+ var gap = getStyles(
222
+ this.gridGapProp,
223
+ [this.grid],
224
+ getMatchedCSSRules(this.grid)
225
+ );
226
+ if (!gap.length) {
227
+ return null
228
+ }
229
+ return gap[0]
230
+ };
231
+
232
+ Gutter.prototype.getRawComputedTracks = function getRawComputedTracks () {
233
+ return window.getComputedStyle(this.grid)[this.gridTemplateProp]
234
+ };
235
+
236
+ Gutter.prototype.getRawComputedGap = function getRawComputedGap () {
237
+ return window.getComputedStyle(this.grid)[this.gridGapProp]
238
+ };
239
+
240
+ Gutter.prototype.setTracks = function setTracks (raw) {
241
+ this.tracks = raw.split(' ');
242
+ this.trackValues = parse(raw);
243
+ };
244
+
245
+ Gutter.prototype.setComputedTracks = function setComputedTracks (raw) {
246
+ this.computedTracks = raw.split(' ');
247
+ this.computedPixels = parse(raw);
248
+ };
249
+
250
+ Gutter.prototype.setGap = function setGap (raw) {
251
+ this.gap = raw;
252
+ };
253
+
254
+ Gutter.prototype.setComputedGap = function setComputedGap (raw) {
255
+ this.computedGap = raw;
256
+ this.computedGapPixels = getGapValue('px', this.computedGap) || 0;
257
+ };
258
+
259
+ Gutter.prototype.getMousePosition = function getMousePosition (e) {
260
+ if ('touches' in e) { return e.touches[0][this.clientAxis] }
261
+ return e[this.clientAxis]
262
+ };
263
+
264
+ Gutter.prototype.startDragging = function startDragging (e) {
265
+ if ('button' in e && e.button !== 0) {
266
+ return
267
+ }
268
+
269
+ // Don't actually drag the element. We emulate that in the drag function.
270
+ e.preventDefault();
271
+
272
+ if (this.element) {
273
+ this.grid = this.element.parentNode;
274
+ } else {
275
+ this.grid = e.target.parentNode;
276
+ }
277
+
278
+ this.getDimensions();
279
+ this.setTracks(this.getRawTracks());
280
+ this.setComputedTracks(this.getRawComputedTracks());
281
+ this.setGap(this.getGap());
282
+ this.setComputedGap(this.getRawComputedGap());
283
+
284
+ var trackPercentage = this.trackValues.filter(
285
+ function (track) { return track.type === '%'; }
286
+ );
287
+ var trackFr = this.trackValues.filter(function (track) { return track.type === 'fr'; });
288
+
289
+ this.totalFrs = trackFr.length;
290
+
291
+ if (this.totalFrs) {
292
+ var track = firstNonZero(trackFr);
293
+
294
+ if (track !== null) {
295
+ this.frToPixels =
296
+ this.computedPixels[track].numeric / trackFr[track].numeric;
297
+ }
298
+ }
299
+
300
+ if (trackPercentage.length) {
301
+ var track$1 = firstNonZero(trackPercentage);
302
+
303
+ if (track$1 !== null) {
304
+ this.percentageToPixels =
305
+ this.computedPixels[track$1].numeric /
306
+ trackPercentage[track$1].numeric;
307
+ }
308
+ }
309
+
310
+ // get start of gutter track
311
+ var gutterStart = this.getSizeAtTrack(this.track, false) + this.start;
312
+ this.dragStartOffset = this.getMousePosition(e) - gutterStart;
313
+
314
+ this.aTrack = this.track - 1;
315
+
316
+ if (this.track < this.tracks.length - 1) {
317
+ this.bTrack = this.track + 1;
318
+ } else {
319
+ throw Error(
320
+ ("Invalid track index: " + (this.track) + ". Track must be between two other tracks and only " + (this.tracks.length) + " tracks were found.")
321
+ )
322
+ }
323
+
324
+ this.aTrackStart = this.getSizeAtTrack(this.aTrack, false) + this.start;
325
+ this.bTrackEnd = this.getSizeAtTrack(this.bTrack, true) + this.start;
326
+
327
+ // Set the dragging property of the pair object.
328
+ this.dragging = true;
329
+
330
+ // All the binding. `window` gets the stop events in case we drag out of the elements.
331
+ window.addEventListener('mouseup', this.stopDragging);
332
+ window.addEventListener('touchend', this.stopDragging);
333
+ window.addEventListener('touchcancel', this.stopDragging);
334
+ window.addEventListener('mousemove', this.drag);
335
+ window.addEventListener('touchmove', this.drag);
336
+
337
+ // Disable selection. Disable!
338
+ this.grid.addEventListener('selectstart', NOOP);
339
+ this.grid.addEventListener('dragstart', NOOP);
340
+
341
+ this.grid.style.userSelect = 'none';
342
+ this.grid.style.webkitUserSelect = 'none';
343
+ this.grid.style.MozUserSelect = 'none';
344
+ this.grid.style.pointerEvents = 'none';
345
+
346
+ // Set the cursor at multiple levels
347
+ this.grid.style.cursor = this.cursor;
348
+ window.document.body.style.cursor = this.cursor;
349
+
350
+ this.onDragStart(this.direction, this.track);
351
+ };
352
+
353
+ Gutter.prototype.stopDragging = function stopDragging () {
354
+ this.dragging = false;
355
+
356
+ // Remove the stored event listeners. This is why we store them.
357
+ this.cleanup();
358
+
359
+ this.onDragEnd(this.direction, this.track);
360
+
361
+ if (this.needsDestroy) {
362
+ if (this.element) {
363
+ this.element.removeEventListener(
364
+ 'mousedown',
365
+ this.startDragging
366
+ );
367
+ this.element.removeEventListener(
368
+ 'touchstart',
369
+ this.startDragging
370
+ );
371
+ }
372
+ this.destroyCb();
373
+ this.needsDestroy = false;
374
+ this.destroyCb = null;
375
+ }
376
+ };
377
+
378
+ Gutter.prototype.drag = function drag (e) {
379
+ var mousePosition = this.getMousePosition(e);
380
+
381
+ var gutterSize = this.getSizeOfTrack(this.track);
382
+ var minMousePosition =
383
+ this.aTrackStart +
384
+ this.minSizeStart +
385
+ this.dragStartOffset +
386
+ this.computedGapPixels;
387
+ var maxMousePosition =
388
+ this.bTrackEnd -
389
+ this.minSizeEnd -
390
+ this.computedGapPixels -
391
+ (gutterSize - this.dragStartOffset);
392
+ var minMousePositionOffset = minMousePosition + this.snapOffset;
393
+ var maxMousePositionOffset = maxMousePosition - this.snapOffset;
394
+
395
+ if (mousePosition < minMousePositionOffset) {
396
+ mousePosition = minMousePosition;
397
+ }
398
+
399
+ if (mousePosition > maxMousePositionOffset) {
400
+ mousePosition = maxMousePosition;
401
+ }
402
+
403
+ if (mousePosition < minMousePosition) {
404
+ mousePosition = minMousePosition;
405
+ } else if (mousePosition > maxMousePosition) {
406
+ mousePosition = maxMousePosition;
407
+ }
408
+
409
+ var aTrackSize =
410
+ mousePosition -
411
+ this.aTrackStart -
412
+ this.dragStartOffset -
413
+ this.computedGapPixels;
414
+ var bTrackSize =
415
+ this.bTrackEnd -
416
+ mousePosition +
417
+ this.dragStartOffset -
418
+ gutterSize -
419
+ this.computedGapPixels;
420
+
421
+ if (this.dragInterval > 1) {
422
+ var aTrackSizeIntervaled =
423
+ Math.round(aTrackSize / this.dragInterval) * this.dragInterval;
424
+ bTrackSize -= aTrackSizeIntervaled - aTrackSize;
425
+ aTrackSize = aTrackSizeIntervaled;
426
+ }
427
+
428
+ if (aTrackSize < this.minSizeStart) {
429
+ aTrackSize = this.minSizeStart;
430
+ }
431
+
432
+ if (bTrackSize < this.minSizeEnd) {
433
+ bTrackSize = this.minSizeEnd;
434
+ }
435
+
436
+ if (this.trackValues[this.aTrack].type === 'px') {
437
+ this.tracks[this.aTrack] = aTrackSize + "px";
438
+ } else if (this.trackValues[this.aTrack].type === 'fr') {
439
+ if (this.totalFrs === 1) {
440
+ this.tracks[this.aTrack] = '1fr';
441
+ } else {
442
+ var targetFr = aTrackSize / this.frToPixels;
443
+ this.tracks[this.aTrack] = targetFr + "fr";
444
+ }
445
+ } else if (this.trackValues[this.aTrack].type === '%') {
446
+ var targetPercentage = aTrackSize / this.percentageToPixels;
447
+ this.tracks[this.aTrack] = targetPercentage + "%";
448
+ }
449
+
450
+ if (this.trackValues[this.bTrack].type === 'px') {
451
+ this.tracks[this.bTrack] = bTrackSize + "px";
452
+ } else if (this.trackValues[this.bTrack].type === 'fr') {
453
+ if (this.totalFrs === 1) {
454
+ this.tracks[this.bTrack] = '1fr';
455
+ } else {
456
+ var targetFr$1 = bTrackSize / this.frToPixels;
457
+ this.tracks[this.bTrack] = targetFr$1 + "fr";
458
+ }
459
+ } else if (this.trackValues[this.bTrack].type === '%') {
460
+ var targetPercentage$1 = bTrackSize / this.percentageToPixels;
461
+ this.tracks[this.bTrack] = targetPercentage$1 + "%";
462
+ }
463
+
464
+ var style = this.tracks.join(' ');
465
+ this.writeStyle(this.grid, this.gridTemplateProp, style);
466
+ this.onDrag(this.direction, this.track, style);
467
+ };
468
+
469
+ Gutter.prototype.cleanup = function cleanup () {
470
+ window.removeEventListener('mouseup', this.stopDragging);
471
+ window.removeEventListener('touchend', this.stopDragging);
472
+ window.removeEventListener('touchcancel', this.stopDragging);
473
+ window.removeEventListener('mousemove', this.drag);
474
+ window.removeEventListener('touchmove', this.drag);
475
+
476
+ if (this.grid) {
477
+ this.grid.removeEventListener('selectstart', NOOP);
478
+ this.grid.removeEventListener('dragstart', NOOP);
479
+
480
+ this.grid.style.userSelect = '';
481
+ this.grid.style.webkitUserSelect = '';
482
+ this.grid.style.MozUserSelect = '';
483
+ this.grid.style.pointerEvents = '';
484
+
485
+ this.grid.style.cursor = '';
486
+ }
487
+
488
+ window.document.body.style.cursor = '';
489
+ };
490
+
491
+ Gutter.prototype.destroy = function destroy (immediate, cb) {
492
+ if ( immediate === void 0 ) immediate = true;
493
+
494
+ if (immediate || this.dragging === false) {
495
+ this.cleanup();
496
+ if (this.element) {
497
+ this.element.removeEventListener(
498
+ 'mousedown',
499
+ this.startDragging
500
+ );
501
+ this.element.removeEventListener(
502
+ 'touchstart',
503
+ this.startDragging
504
+ );
505
+ }
506
+
507
+ if (cb) {
508
+ cb();
509
+ }
510
+ } else {
511
+ this.needsDestroy = true;
512
+ if (cb) {
513
+ this.destroyCb = cb;
514
+ }
515
+ }
516
+ };
517
+
518
+ var getTrackOption = function (options, track, defaultValue) {
519
+ if (track in options) {
520
+ return options[track]
521
+ }
522
+
523
+ return defaultValue
524
+ };
525
+
526
+ var createGutter = function (direction, options) { return function (gutterOptions) {
527
+ if (gutterOptions.track < 1) {
528
+ throw Error(
529
+ ("Invalid track index: " + (gutterOptions.track) + ". Track must be between two other tracks.")
530
+ )
531
+ }
532
+
533
+ var trackMinSizes =
534
+ direction === 'column'
535
+ ? options.columnMinSizes || {}
536
+ : options.rowMinSizes || {};
537
+ var trackMinSize = direction === 'column' ? 'columnMinSize' : 'rowMinSize';
538
+
539
+ return new Gutter(
540
+ direction,
541
+ Object.assign({}, {minSizeStart: getTrackOption(
542
+ trackMinSizes,
543
+ gutterOptions.track - 1,
544
+ getOption(
545
+ options,
546
+ trackMinSize,
547
+ getOption(options, 'minSize', 0)
548
+ )
549
+ ),
550
+ minSizeEnd: getTrackOption(
551
+ trackMinSizes,
552
+ gutterOptions.track + 1,
553
+ getOption(
554
+ options,
555
+ trackMinSize,
556
+ getOption(options, 'minSize', 0)
557
+ )
558
+ )},
559
+ gutterOptions),
560
+ options
561
+ )
562
+ }; };
563
+
564
+ var Grid = function Grid(options) {
565
+ var this$1 = this;
566
+
567
+ this.columnGutters = {};
568
+ this.rowGutters = {};
569
+
570
+ this.options = Object.assign({}, {columnGutters: options.columnGutters || [],
571
+ rowGutters: options.rowGutters || [],
572
+ columnMinSizes: options.columnMinSizes || {},
573
+ rowMinSizes: options.rowMinSizes || {}},
574
+ options);
575
+
576
+ this.options.columnGutters.forEach(function (gutterOptions) {
577
+ this$1.columnGutters[gutterOptions.track] = createGutter(
578
+ 'column',
579
+ this$1.options
580
+ )(gutterOptions);
581
+ });
582
+
583
+ this.options.rowGutters.forEach(function (gutterOptions) {
584
+ this$1.rowGutters[gutterOptions.track] = createGutter(
585
+ 'row',
586
+ this$1.options
587
+ )(gutterOptions);
588
+ });
589
+ };
590
+
591
+ Grid.prototype.addColumnGutter = function addColumnGutter (element, track) {
592
+ if (this.columnGutters[track]) {
593
+ this.columnGutters[track].destroy();
594
+ }
595
+
596
+ this.columnGutters[track] = createGutter(
597
+ 'column',
598
+ this.options
599
+ )({
600
+ element: element,
601
+ track: track,
602
+ });
603
+ };
604
+
605
+ Grid.prototype.addRowGutter = function addRowGutter (element, track) {
606
+ if (this.rowGutters[track]) {
607
+ this.rowGutters[track].destroy();
608
+ }
609
+
610
+ this.rowGutters[track] = createGutter(
611
+ 'row',
612
+ this.options
613
+ )({
614
+ element: element,
615
+ track: track,
616
+ });
617
+ };
618
+
619
+ Grid.prototype.removeColumnGutter = function removeColumnGutter (track, immediate) {
620
+ var this$1 = this;
621
+ if ( immediate === void 0 ) immediate = true;
622
+
623
+ if (this.columnGutters[track]) {
624
+ this.columnGutters[track].destroy(immediate, function () {
625
+ delete this$1.columnGutters[track];
626
+ });
627
+ }
628
+ };
629
+
630
+ Grid.prototype.removeRowGutter = function removeRowGutter (track, immediate) {
631
+ var this$1 = this;
632
+ if ( immediate === void 0 ) immediate = true;
633
+
634
+ if (this.rowGutters[track]) {
635
+ this.rowGutters[track].destroy(immediate, function () {
636
+ delete this$1.rowGutters[track];
637
+ });
638
+ }
639
+ };
640
+
641
+ Grid.prototype.handleDragStart = function handleDragStart (e, direction, track) {
642
+ if (direction === 'column') {
643
+ if (this.columnGutters[track]) {
644
+ this.columnGutters[track].destroy();
645
+ }
646
+
647
+ this.columnGutters[track] = createGutter(
648
+ 'column',
649
+ this.options
650
+ )({
651
+ track: track,
652
+ });
653
+ this.columnGutters[track].startDragging(e);
654
+ } else if (direction === 'row') {
655
+ if (this.rowGutters[track]) {
656
+ this.rowGutters[track].destroy();
657
+ }
658
+
659
+ this.rowGutters[track] = createGutter(
660
+ 'row',
661
+ this.options
662
+ )({
663
+ track: track,
664
+ });
665
+ this.rowGutters[track].startDragging(e);
666
+ }
667
+ };
668
+
669
+ Grid.prototype.destroy = function destroy (immediate) {
670
+ var this$1 = this;
671
+ if ( immediate === void 0 ) immediate = true;
672
+
673
+ Object.keys(this.columnGutters).forEach(function (track) { return this$1.columnGutters[track].destroy(immediate, function () {
674
+ delete this$1.columnGutters[track];
675
+ }); }
676
+ );
677
+ Object.keys(this.rowGutters).forEach(function (track) { return this$1.rowGutters[track].destroy(immediate, function () {
678
+ delete this$1.rowGutters[track];
679
+ }); }
680
+ );
681
+ };
682
+
683
+ function index (options) { return new Grid(options); }
684
+
685
+ const ezSplitPanelCss = ".ez-split-gutter{cursor:grab;background-color:transparent}";
686
+
687
+ const SplitPanel = class {
688
+ constructor(hostRef) {
689
+ index$1.registerInstance(this, hostRef);
690
+ this._items = [];
691
+ this.direction = 'column';
692
+ }
693
+ componentDidLoad() {
694
+ this._panelID = core.StringUtils.generateUUID();
695
+ this._element.dataset.panelId = this._panelID;
696
+ let itemsElements = Array.from(this._element.children);
697
+ this._items = itemsElements.filter(child => { var _a; return ((_a = child.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'EZ-SPLIT-ITEM'; });
698
+ let trackCount = 1;
699
+ this._items.forEach((item, index) => {
700
+ item.dataset.trackNumber = trackCount.toString();
701
+ if (this._items.length > 1 && index != this._items.length - 1) {
702
+ this.addItemGutter(item);
703
+ }
704
+ trackCount += 2;
705
+ });
706
+ this.initSplit();
707
+ }
708
+ initSplit() {
709
+ if (!this._items.length) {
710
+ return;
711
+ }
712
+ this._element.style[this.direction == 'row' ? 'grid-template-rows' : 'grid-template-columns'] = this.getGridTemplate();
713
+ index(this.getGutters());
714
+ }
715
+ getGutters() {
716
+ const gutters = {
717
+ columnGutters: [],
718
+ rowGutters: []
719
+ };
720
+ if (!this._items.length) {
721
+ return gutters;
722
+ }
723
+ const proToChange = this.direction == 'row' ? 'rowGutters' : 'columnGutters';
724
+ this._items.forEach((item, index) => {
725
+ if (index == this._items.length - 1)
726
+ return;
727
+ let gutterTrack = item.dataset.trackNumber;
728
+ if (index === (this._items.length - 1)) {
729
+ gutterTrack = this._items.length.toString();
730
+ }
731
+ gutters[proToChange].push({
732
+ track: Number(gutterTrack),
733
+ element: this._element.querySelector(`ez-split-panel[data-panel-id="${this._panelID}"] > [data-item-track="${item.dataset.trackNumber}"]`)
734
+ });
735
+ });
736
+ return gutters;
737
+ }
738
+ addItemGutter(item) {
739
+ const gutter = document.createElement('div');
740
+ gutter.classList.add("ez-split-gutter");
741
+ gutter.classList.add(this.direction);
742
+ gutter.dataset.itemTrack = `${item.dataset.trackNumber}`;
743
+ gutter.dataset.trackNumber = (Number(item.dataset.trackNumber) + 1).toString();
744
+ item.parentNode.insertBefore(gutter, item.nextSibling);
745
+ }
746
+ getElementStyle() {
747
+ const style = {
748
+ 'display': "grid",
749
+ 'height': '100%',
750
+ 'width': '100%'
751
+ };
752
+ return style;
753
+ }
754
+ getGridTemplate() {
755
+ let template = '';
756
+ this._items.forEach((_col, index) => {
757
+ if (index === this._items.length - 1) {
758
+ template += ` 1fr`;
759
+ return;
760
+ }
761
+ if (index === 0) {
762
+ template += `1fr 5px`;
763
+ return;
764
+ }
765
+ template += ` 1fr 5px`;
766
+ });
767
+ return template;
768
+ }
769
+ render() {
770
+ return (index$1.h(index$1.Host, { style: this.getElementStyle() }));
771
+ }
772
+ get _element() { return index$1.getElement(this); }
773
+ };
774
+ SplitPanel.style = ezSplitPanelCss;
775
+
776
+ exports.ez_split_panel = SplitPanel;