@expressivecss/expressive 0.1.0 → 0.2.0

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.
@@ -34,6 +34,7 @@ var Expressive = (() => {
34
34
  Chips: () => Chips,
35
35
  Collapsible: () => Collapsible,
36
36
  Datepicker: () => Datepicker,
37
+ Dialogs: () => Dialogs,
37
38
  Dropdown: () => Dropdown,
38
39
  FloatingActionButton: () => FloatingActionButton,
39
40
  FormSelect: () => FormSelect,
@@ -1892,6 +1893,74 @@ var Expressive = (() => {
1892
1893
  }
1893
1894
  };
1894
1895
 
1896
+ // src/ts/behaviors/dialogs.ts
1897
+ var _Dialogs = class _Dialogs {
1898
+ static Init() {
1899
+ Utils.onDocumentReady(() => {
1900
+ document.addEventListener("pointerdown", _Dialogs._onPointerDown, { passive: true });
1901
+ document.addEventListener("pointerup", _Dialogs._onPointerUp, { passive: true });
1902
+ document.addEventListener("pointercancel", _Dialogs._onPointerCancel, { passive: true });
1903
+ });
1904
+ }
1905
+ static _onPointerDown(event) {
1906
+ if (!_Dialogs._isPrimaryPress(event)) {
1907
+ _Dialogs._down = null;
1908
+ return;
1909
+ }
1910
+ const dialog = _Dialogs._backdropDialog(event);
1911
+ if (!dialog || !_Dialogs._lightDismissible(dialog) || !_Dialogs._outside(event, dialog)) {
1912
+ _Dialogs._down = null;
1913
+ return;
1914
+ }
1915
+ _Dialogs._down = { dialog, pointerId: event.pointerId };
1916
+ }
1917
+ static _onPointerUp(event) {
1918
+ const started = _Dialogs._down;
1919
+ _Dialogs._down = null;
1920
+ if (!started || started.pointerId !== event.pointerId) return;
1921
+ if (!event.isPrimary) return;
1922
+ if (!started.dialog.isConnected || !started.dialog.open) return;
1923
+ if (!_Dialogs._lightDismissible(started.dialog)) return;
1924
+ if (_Dialogs._backdropDialog(event) !== started.dialog) return;
1925
+ if (_Dialogs._outside(event, started.dialog)) {
1926
+ started.dialog.close();
1927
+ }
1928
+ }
1929
+ static _onPointerCancel() {
1930
+ _Dialogs._down = null;
1931
+ }
1932
+ /** Backdrop hits retarget to the dialog itself, never a child. */
1933
+ static _backdropDialog(event) {
1934
+ const target = event.target;
1935
+ if (!(target instanceof HTMLDialogElement) || !target.open) return null;
1936
+ return target;
1937
+ }
1938
+ static _outside(event, dialog) {
1939
+ const rect = dialog.getBoundingClientRect();
1940
+ return event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom;
1941
+ }
1942
+ static _isPrimaryPress(event) {
1943
+ if (!event.isPrimary) return false;
1944
+ return event.pointerType !== "mouse" || event.button === 0;
1945
+ }
1946
+ static _lightDismissible(dialog) {
1947
+ const value = _Dialogs._closedBy(dialog);
1948
+ if (value === "none" || value === "closerequest") return false;
1949
+ if (value === "any" && "closedBy" in HTMLDialogElement.prototype) return false;
1950
+ return true;
1951
+ }
1952
+ // Read the attribute only. The IDL default for an unset closedby is
1953
+ // "closerequest" (Escape, no light dismiss) — treating that as an
1954
+ // author opt-out made every dialog undismissable from the scrim.
1955
+ static _closedBy(dialog) {
1956
+ const attr = dialog.getAttribute("closedby");
1957
+ if (attr === "any" || attr === "closerequest" || attr === "none") return attr;
1958
+ return null;
1959
+ }
1960
+ };
1961
+ _Dialogs._down = null;
1962
+ var Dialogs = _Dialogs;
1963
+
1895
1964
  // src/ts/behaviors/forms.ts
1896
1965
  var Forms = class _Forms {
1897
1966
  /**
@@ -7436,7 +7505,7 @@ var Expressive = (() => {
7436
7505
  }
7437
7506
 
7438
7507
  // src/ts/index.ts
7439
- var version = "0.1.0";
7508
+ var version = "0.2.0";
7440
7509
  if (typeof document !== "undefined") {
7441
7510
  document.addEventListener("keydown", Utils.docHandleKeydown, true);
7442
7511
  document.addEventListener("keyup", Utils.docHandleKeyup, true);
@@ -7448,6 +7517,7 @@ var Expressive = (() => {
7448
7517
  Waves.Init();
7449
7518
  Range.Init();
7450
7519
  Cards.Init();
7520
+ Dialogs.Init();
7451
7521
  return __toCommonJS(index_exports);
7452
7522
  })();
7453
7523
  //# sourceMappingURL=expressive.js.map