@m3e/web 2.1.0 → 2.1.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.
package/dist/core.js CHANGED
@@ -1616,6 +1616,9 @@ function isAttachInternalsMixin(value) {
1616
1616
  return hasKeys(value, internals);
1617
1617
  }
1618
1618
  const _internals = Symbol("_internals");
1619
+ // Since flushing custom state doesn't flush in Safari (affecting all iOS browsers),
1620
+ // a copy of custom state is retained locally so components can correctly read after write.
1621
+ const _customState = Symbol("_customState");
1619
1622
  /**
1620
1623
  * Mixin to augment an element with behavior that attaches to `ElementInternals`.
1621
1624
  * @template T The type of the base class.
@@ -1624,9 +1627,17 @@ const _internals = Symbol("_internals");
1624
1627
  * @returns {Constructor<AttachInternalsMixin> & T} A constructor that implements `AttachInternalsMixin`.
1625
1628
  */
1626
1629
  function AttachInternals(base, formAssociated) {
1630
+ var _a;
1627
1631
  class _AttachInternals extends base {
1632
+ constructor() {
1633
+ super(...arguments);
1634
+ // Since flushing custom state doesn't flush in Safari (affecting all iOS browsers),
1635
+ // a copy of custom state is retained locally so components can correctly read after write.
1636
+ /** @private */
1637
+ this[_a] = new Set();
1638
+ }
1628
1639
  /** @internal */
1629
- get [internals]() {
1640
+ get [(_a = _customState, internals)]() {
1630
1641
  return this[_internals] ?? (this[_internals] = this.attachInternals());
1631
1642
  }
1632
1643
  }
@@ -1641,6 +1652,13 @@ function AttachInternals(base, formAssociated) {
1641
1652
  * @returns {boolean} Whether `element` has `state`.
1642
1653
  */
1643
1654
  function hasCustomState(element, state) {
1655
+ // Since flushing custom state doesn't flush in Safari (affecting all iOS browsers),
1656
+ // a copy of custom state is retained locally so components can correctly read after write.
1657
+ if (_customState in element) {
1658
+ return element[_customState].has(state);
1659
+ }
1660
+ // This should never get called due to needing a local copy of custom state
1661
+ // since reading after write to flush doesn't work in Safari (affecting all iOS browsers).
1644
1662
  return element[internals].states.has(state);
1645
1663
  }
1646
1664
  /**
@@ -1649,8 +1667,13 @@ function hasCustomState(element, state) {
1649
1667
  * @param {string} state The custom state to add.
1650
1668
  */
1651
1669
  function addCustomState(element, state) {
1670
+ // Since flushing custom state doesn't flush in Safari (affecting all iOS browsers),
1671
+ // a copy of custom state is retained locally so components can correctly read after write.
1672
+ if (_customState in element) {
1673
+ element[_customState].add(state);
1674
+ }
1652
1675
  element[internals]?.states.add(state);
1653
- element[internals]?.states.has(state); // flush
1676
+ element[internals]?.states.has(state); // flush (even though this doesn't work in Safari)
1654
1677
  }
1655
1678
  /**
1656
1679
  * Convenience function used to delete custom state from an element.
@@ -1659,8 +1682,13 @@ function addCustomState(element, state) {
1659
1682
  * @returns {boolean} Whether `state` was removed from `element`.
1660
1683
  */
1661
1684
  function deleteCustomState(element, state) {
1685
+ // Since flushing custom state doesn't flush in Safari (affecting all iOS browsers),
1686
+ // a copy of custom state is retained locally so components can correctly read after write.
1687
+ if (_customState in element) {
1688
+ element[_customState].delete(state);
1689
+ }
1662
1690
  if (element[internals]?.states.delete(state)) {
1663
- element[internals]?.states.has(state); // flush
1691
+ element[internals]?.states.has(state); // flush (even though this doesn't work in Safari)
1664
1692
  return true;
1665
1693
  }
1666
1694
  return false;