vrembem 3.0.6 → 3.0.9

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.
@@ -1,5 +1,5 @@
1
1
  function _extends() {
2
- _extends = Object.assign || function (target) {
2
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
3
3
  for (var i = 1; i < arguments.length; i++) {
4
4
  var source = arguments[i];
5
5
 
@@ -12,7 +12,6 @@ function _extends() {
12
12
 
13
13
  return target;
14
14
  };
15
-
16
15
  return _extends.apply(this, arguments);
17
16
  }
18
17
 
@@ -151,7 +150,20 @@ class Collection {
151
150
 
152
151
  }
153
152
 
154
- var focusableSelectors = ['a[href]:not([tabindex^="-"])', 'area[href]:not([tabindex^="-"])', 'input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])', 'input[type="radio"]:not([disabled]):not([tabindex^="-"])', 'select:not([disabled]):not([tabindex^="-"])', 'textarea:not([disabled]):not([tabindex^="-"])', 'button:not([disabled]):not([tabindex^="-"])', 'iframe:not([tabindex^="-"])', 'audio[controls]:not([tabindex^="-"])', 'video[controls]:not([tabindex^="-"])', '[contenteditable]:not([tabindex^="-"])', '[tabindex]:not([tabindex^="-"])'];
153
+ var focusableSelectors = [
154
+ 'a[href]:not([tabindex^="-"])',
155
+ 'area[href]:not([tabindex^="-"])',
156
+ 'input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])',
157
+ 'input[type="radio"]:not([disabled]):not([tabindex^="-"])',
158
+ 'select:not([disabled]):not([tabindex^="-"])',
159
+ 'textarea:not([disabled]):not([tabindex^="-"])',
160
+ 'button:not([disabled]):not([tabindex^="-"])',
161
+ 'iframe:not([tabindex^="-"])',
162
+ 'audio[controls]:not([tabindex^="-"])',
163
+ 'video[controls]:not([tabindex^="-"])',
164
+ '[contenteditable]:not([tabindex^="-"])',
165
+ '[tabindex]:not([tabindex^="-"])',
166
+ ];
155
167
 
156
168
  var _focusable = /*#__PURE__*/_classPrivateFieldLooseKey("focusable");
157
169
 
@@ -297,29 +309,25 @@ function getPrefix() {
297
309
  }
298
310
 
299
311
  function localStore(key, enable = true) {
300
- function getStore() {
301
- const value = localStorage.getItem(key);
302
- return value ? JSON.parse(value) : {};
303
- }
304
-
305
- function setStore(obj) {
306
- localStorage.setItem(key, JSON.stringify(obj));
307
- }
308
-
309
- return new Proxy(getStore(), {
310
- set: (target, property, value) => {
311
- console.log('localStore() => set');
312
+ const local = localStorage.getItem(key);
313
+ const store = local ? JSON.parse(local) : {};
314
+ return {
315
+ get(prop) {
316
+ return prop ? store[prop] : store;
317
+ },
312
318
 
313
- if (value === undefined) {
314
- delete target[property];
319
+ set(prop, value) {
320
+ if (value) {
321
+ store[prop] = value;
315
322
  } else {
316
- target[property] = value;
323
+ delete store[prop];
317
324
  }
318
325
 
319
- if (enable) setStore(target);
320
- return true;
326
+ if (enable) localStorage.setItem(key, JSON.stringify(store));
327
+ return store;
321
328
  }
322
- });
329
+
330
+ };
323
331
  }
324
332
 
325
333
  /**
@@ -633,7 +641,7 @@ async function deregister$2(obj, close = true) {
633
641
  } // Remove entry from local store.
634
642
 
635
643
 
636
- this.store[entry.id] = undefined; // Unmount the MatchMedia functionality.
644
+ this.store.set(entry.id); // Unmount the MatchMedia functionality.
637
645
 
638
646
  entry.unmountBreakpoint(); // Delete properties from collection entry.
639
647
 
@@ -737,9 +745,9 @@ async function initialState(entry) {
737
745
  // 1. If a store state is available, restore from local store.
738
746
  // 2. If opened state class is set, set state to opened.
739
747
  // 3. Else, initialize default state.
740
- if (this.store[entry.id]) {
748
+ if (this.store.get(entry.id)) {
741
749
  // Restore drawers to saved inline state.
742
- if (this.store[entry.id] === 'opened') {
750
+ if (this.store.get(entry.id) === 'opened') {
743
751
  await entry.open(false, false);
744
752
  } else {
745
753
  await entry.close(false, false);
@@ -897,9 +905,9 @@ async function toModal(entry) {
897
905
 
898
906
  entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
899
907
 
900
- if (!this.store[entry.id] && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
908
+ if (!this.store.get(entry.id) && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
901
909
  // Save the opened state in local store.
902
- this.store[entry.id] = 'opened';
910
+ this.store.set(entry.id, 'opened');
903
911
  } // Modal drawer defaults to closed state.
904
912
 
905
913
 
@@ -980,7 +988,7 @@ async function register$2(el, dialog) {
980
988
  __state = value; // Save 'opened' and 'closed' states to store if mode is inline.
981
989
 
982
990
  if (value === 'opened' || value === 'closed') {
983
- if (this.mode === 'inline') root.store[this.id] = this.state;
991
+ if (this.mode === 'inline') root.store.set(this.id, this.state);
984
992
  }
985
993
  },
986
994
 
@@ -1235,14 +1243,6 @@ function updateFocusState() {
1235
1243
  }
1236
1244
  }
1237
1245
 
1238
- function updateStackIndex(stack) {
1239
- stack.forEach((entry, index) => {
1240
- entry.el.style.zIndex = null;
1241
- const value = getComputedStyle(entry.el)['z-index'];
1242
- entry.el.style.zIndex = parseInt(value) + index + 1;
1243
- });
1244
- }
1245
-
1246
1246
  async function handleClick$1(event) {
1247
1247
  // If an open or replace button was clicked, open or replace the modal.
1248
1248
  let trigger = event.target.closest(`[data-${this.settings.dataOpen}], [data-${this.settings.dataReplace}]`);
@@ -1299,14 +1299,8 @@ async function deregister$1(obj, close = true) {
1299
1299
  if (close && entry.state === 'opened') {
1300
1300
  await entry.close(false);
1301
1301
  } else {
1302
- // Get index of modal in stack array.
1303
- const stackIndex = this.stack.findIndex(item => {
1304
- return item.id === entry.id;
1305
- }); // Remove modal from stack array.
1306
-
1307
- if (stackIndex >= 0) {
1308
- this.stack.splice(stackIndex, 1);
1309
- }
1302
+ // Remove modal from stack.
1303
+ this.stack.remove(entry);
1310
1304
  } // Return teleported modal if a reference has been set.
1311
1305
 
1312
1306
 
@@ -1333,29 +1327,15 @@ async function open$1(query, transition, focus = true) {
1333
1327
  const config = _extends({}, this.settings, modal.settings); // Add transition parameter to configuration.
1334
1328
 
1335
1329
 
1336
- if (transition !== undefined) config.transition = transition; // Check if modal is already in the stack.
1337
-
1338
- const index = this.stack.findIndex(entry => {
1339
- return entry.id === modal.id;
1340
- }); // If modal is already open.
1341
-
1342
- if (index >= 0) {
1343
- // Remove modal from stack array.
1344
- this.stack.splice(index, 1); // Move back to end of stack.
1345
-
1346
- this.stack.push(modal);
1347
- } // If modal is closed.
1330
+ if (transition !== undefined) config.transition = transition; // Maybe add modal to top of stack.
1348
1331
 
1332
+ this.stack.moveToTop(modal); // If modal is closed.
1349
1333
 
1350
1334
  if (modal.state === 'closed') {
1351
1335
  // Update modal state.
1352
- modal.state = 'opening'; // Apply z-index styles based on stack length.
1353
-
1354
- modal.el.style.zIndex = null;
1355
- const value = getComputedStyle(modal.el)['z-index'];
1356
- modal.el.style.zIndex = parseInt(value) + this.stack.length + 1; // Store modal in stack array.
1336
+ modal.state = 'opening'; // Add modal to stack.
1357
1337
 
1358
- this.stack.push(modal); // Run the open transition.
1338
+ this.stack.add(modal); // Run the open transition.
1359
1339
 
1360
1340
  await openTransition(modal.el, config); // Update modal state.
1361
1341
 
@@ -1391,15 +1371,9 @@ async function close$1(query, transition, focus = true) {
1391
1371
 
1392
1372
  document.activeElement.blur(); // Run the close transition.
1393
1373
 
1394
- await closeTransition(modal.el, config); // Remove z-index styles.
1395
-
1396
- modal.el.style.zIndex = null; // Get index of modal in stack array.
1397
-
1398
- const index = this.stack.findIndex(entry => {
1399
- return entry.id === modal.id;
1400
- }); // Remove modal from stack array.
1374
+ await closeTransition(modal.el, config); // Remove modal from stack.
1401
1375
 
1402
- this.stack.splice(index, 1); // Update focus if the focus param is true.
1376
+ this.stack.remove(modal); // Update focus if the focus param is true.
1403
1377
 
1404
1378
  if (focus) {
1405
1379
  updateFocusState.call(this);
@@ -1420,7 +1394,7 @@ async function close$1(query, transition, focus = true) {
1420
1394
 
1421
1395
  async function closeAll$1(exclude, transition) {
1422
1396
  const result = [];
1423
- await Promise.all(this.stack.map(async modal => {
1397
+ await Promise.all(this.stack.value.map(async modal => {
1424
1398
  if (exclude && exclude === modal.id) {
1425
1399
  Promise.resolve();
1426
1400
  } else {
@@ -1554,6 +1528,74 @@ async function register$1(el, dialog) {
1554
1528
  return entry;
1555
1529
  }
1556
1530
 
1531
+ function stack(settings) {
1532
+ const stackArray = [];
1533
+ return {
1534
+ get value() {
1535
+ return [...stackArray];
1536
+ },
1537
+
1538
+ get top() {
1539
+ return stackArray[stackArray.length - 1];
1540
+ },
1541
+
1542
+ updateIndex() {
1543
+ stackArray.forEach((entry, index) => {
1544
+ entry.el.style.zIndex = null;
1545
+ const value = getComputedStyle(entry.el)['z-index'];
1546
+ entry.el.style.zIndex = parseInt(value) + index + 1;
1547
+ });
1548
+ },
1549
+
1550
+ updateGlobalState() {
1551
+ updateGlobalState(this.top, settings);
1552
+ this.updateIndex();
1553
+ },
1554
+
1555
+ add(entry) {
1556
+ // Apply z-index styles based on stack length.
1557
+ entry.el.style.zIndex = null;
1558
+ const value = getComputedStyle(entry.el)['z-index'];
1559
+ entry.el.style.zIndex = parseInt(value) + stackArray.length + 1; // Move back to end of stack.
1560
+
1561
+ stackArray.push(entry); // Update the global state.
1562
+
1563
+ this.updateGlobalState();
1564
+ },
1565
+
1566
+ remove(entry) {
1567
+ // Get the index of the entry.
1568
+ const index = stackArray.findIndex(item => {
1569
+ return item.id === entry.id;
1570
+ }); // If entry is in stack...
1571
+
1572
+ if (index >= 0) {
1573
+ // Remove z-index styles.
1574
+ entry.el.style.zIndex = null; // Remove entry from stack array.
1575
+
1576
+ stackArray.splice(index, 1); // Update the global state.
1577
+
1578
+ this.updateGlobalState();
1579
+ }
1580
+ },
1581
+
1582
+ moveToTop(entry) {
1583
+ // Get the index of the entry.
1584
+ const index = stackArray.findIndex(item => {
1585
+ return item.id === entry.id;
1586
+ }); // If entry is in stack...
1587
+
1588
+ if (index >= 0) {
1589
+ // Remove entry from stack array.
1590
+ stackArray.splice(index, 1); // Add entry back to top of stack.
1591
+
1592
+ this.add(entry);
1593
+ }
1594
+ }
1595
+
1596
+ };
1597
+ }
1598
+
1557
1599
  var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
1558
1600
 
1559
1601
  var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
@@ -1572,27 +1614,16 @@ class Modal extends Collection {
1572
1614
  this.defaults = defaults$1;
1573
1615
  this.settings = _extends({}, this.defaults, options);
1574
1616
  this.trigger = null;
1575
- this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
1617
+ this.focusTrap = new FocusTrap(); // Setup stack module.
1576
1618
 
1577
- this.stack = new Proxy([], {
1578
- set: (target, property, value) => {
1579
- target[property] = value; // Update global state if stack length changed.
1580
-
1581
- if (property === 'length') {
1582
- updateGlobalState(this.active, this.settings);
1583
- updateStackIndex(this.stack);
1584
- }
1585
-
1586
- return true;
1587
- }
1588
- });
1619
+ this.stack = stack(this.settings);
1589
1620
  _classPrivateFieldLooseBase(this, _handleClick)[_handleClick] = handleClick$1.bind(this);
1590
1621
  _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(this);
1591
1622
  if (this.settings.autoInit) this.init();
1592
1623
  }
1593
1624
 
1594
1625
  get active() {
1595
- return this.stack[this.stack.length - 1];
1626
+ return this.stack.top;
1596
1627
  }
1597
1628
 
1598
1629
  async init(options) {
@@ -2190,17 +2221,17 @@ function contains(parent, child) {
2190
2221
  return true;
2191
2222
  } // then fallback to custom implementation with Shadow DOM support
2192
2223
  else if (rootNode && isShadowRoot(rootNode)) {
2193
- var next = child;
2224
+ var next = child;
2194
2225
 
2195
- do {
2196
- if (next && parent.isSameNode(next)) {
2197
- return true;
2198
- } // $FlowFixMe[prop-missing]: need a better way to handle this...
2226
+ do {
2227
+ if (next && parent.isSameNode(next)) {
2228
+ return true;
2229
+ } // $FlowFixMe[prop-missing]: need a better way to handle this...
2199
2230
 
2200
2231
 
2201
- next = next.parentNode || next.host;
2202
- } while (next);
2203
- } // Give up, the result is false
2232
+ next = next.parentNode || next.host;
2233
+ } while (next);
2234
+ } // Give up, the result is false
2204
2235
 
2205
2236
 
2206
2237
  return false;
@@ -3257,11 +3288,11 @@ var offset$1 = {
3257
3288
 
3258
3289
  function popperOffsets(_ref) {
3259
3290
  var state = _ref.state,
3260
- name = _ref.name; // Offsets are the actual position the popper needs to have to be
3291
+ name = _ref.name;
3292
+ // Offsets are the actual position the popper needs to have to be
3261
3293
  // properly positioned near its reference element
3262
3294
  // This is the most basic placement, and will be adjusted by
3263
3295
  // the modifiers in the next step
3264
-
3265
3296
  state.modifiersData[name] = computeOffsets({
3266
3297
  reference: state.rects.reference,
3267
3298
  element: state.rects.popper,
@@ -4019,4 +4050,4 @@ class Popover extends Collection {
4019
4050
  }
4020
4051
 
4021
4052
  export { Checkbox, Drawer, Modal, Popover, index as core };
4022
- //# sourceMappingURL=scripts.modern.js.map
4053
+ //# sourceMappingURL=scripts.modern.mjs.map