@webtides/element-library 0.3.1 → 0.5.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.
Files changed (252) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/README.md +72 -56
  3. package/all.js +16 -0
  4. package/catalog.js +17 -1
  5. package/custom-elements.json +15912 -10065
  6. package/package.json +1 -1
  7. package/src/components/accordion/accordion.changelog.md +11 -0
  8. package/src/components/accordion/accordion.js +15 -3
  9. package/src/components/accordion/accordion.readme.md +27 -1
  10. package/src/components/accordion/accordion.style.js +19 -0
  11. package/src/components/app-bar/app-bar.changelog.md +24 -0
  12. package/src/components/app-bar/app-bar.define.js +3 -0
  13. package/src/components/app-bar/app-bar.js +91 -0
  14. package/src/components/app-bar/app-bar.readme.md +130 -0
  15. package/src/components/app-bar/app-bar.style.js +103 -0
  16. package/src/components/app-frame/app-frame.changelog.md +59 -0
  17. package/src/components/app-frame/app-frame.define.js +3 -0
  18. package/src/components/app-frame/app-frame.events.js +6 -0
  19. package/src/components/app-frame/app-frame.js +1085 -0
  20. package/src/components/app-frame/app-frame.readme.md +425 -0
  21. package/src/components/app-frame/app-frame.style.js +534 -0
  22. package/src/components/button/button.changelog.md +21 -0
  23. package/src/components/button/button.events.js +3 -0
  24. package/src/components/button/button.js +145 -3
  25. package/src/components/button/button.readme.md +72 -4
  26. package/src/components/button/button.style.js +167 -8
  27. package/src/components/button-group/button-group.changelog.md +10 -0
  28. package/src/components/button-group/button-group.readme.md +2 -0
  29. package/src/components/button-group/button-group.style.js +6 -2
  30. package/src/components/checkbox-group-field/checkbox-group-field.changelog.md +6 -0
  31. package/src/components/checkbox-group-field/checkbox-group-field.js +7 -2
  32. package/src/components/checkbox-group-field/checkbox-group-field.readme.md +23 -1
  33. package/src/components/combobox-field/combobox-field.changelog.md +6 -0
  34. package/src/components/combobox-field/combobox-field.readme.md +8 -0
  35. package/src/components/combobox-field/combobox-field.style.js +2 -0
  36. package/src/components/date-field/date-field.changelog.md +6 -0
  37. package/src/components/date-field/date-field.readme.md +10 -0
  38. package/src/components/date-field/date-field.style.js +8 -3
  39. package/src/components/description-list/description-list.changelog.md +42 -0
  40. package/src/components/description-list/description-list.define.js +3 -0
  41. package/src/components/description-list/description-list.js +49 -0
  42. package/src/components/description-list/description-list.readme.md +161 -0
  43. package/src/components/description-list/description-list.style.js +169 -0
  44. package/src/components/dialog/dialog.changelog.md +7 -0
  45. package/src/components/dialog/dialog.readme.md +5 -0
  46. package/src/components/dialog/dialog.style.js +17 -2
  47. package/src/components/divider/divider.changelog.md +6 -0
  48. package/src/components/divider/divider.readme.md +1 -1
  49. package/src/components/divider/divider.style.js +6 -0
  50. package/src/components/drawer/drawer.changelog.md +7 -0
  51. package/src/components/drawer/drawer.readme.md +7 -6
  52. package/src/components/drawer/drawer.style.js +35 -2
  53. package/src/components/dropdown/dropdown.readme.md +6 -1
  54. package/src/components/file-field/file-field.changelog.md +8 -0
  55. package/src/components/file-field/file-field.js +135 -5
  56. package/src/components/file-field/file-field.readme.md +35 -6
  57. package/src/components/file-field/file-field.style.js +71 -0
  58. package/src/components/form-field/form-field.js +1 -1
  59. package/src/components/input-field/input-field.changelog.md +10 -0
  60. package/src/components/input-field/input-field.js +192 -14
  61. package/src/components/input-field/input-field.readme.md +88 -2
  62. package/src/components/input-field/input-field.style.js +2 -0
  63. package/src/components/list/list.changelog.md +30 -0
  64. package/src/components/list/list.define.js +3 -0
  65. package/src/components/list/list.js +68 -0
  66. package/src/components/list/list.readme.md +123 -0
  67. package/src/components/list/list.style.js +56 -0
  68. package/src/components/list-item/list-item.changelog.md +40 -0
  69. package/src/components/list-item/list-item.define.js +3 -0
  70. package/src/components/list-item/list-item.js +130 -0
  71. package/src/components/list-item/list-item.readme.md +144 -0
  72. package/src/components/list-item/list-item.style.js +246 -0
  73. package/src/components/menu/menu.changelog.md +44 -0
  74. package/src/components/menu/menu.define.js +3 -0
  75. package/src/components/menu/menu.events.js +5 -0
  76. package/src/components/menu/menu.js +793 -0
  77. package/src/components/menu/menu.readme.md +313 -0
  78. package/src/components/menu/menu.style.js +59 -0
  79. package/src/components/menu-group/menu-group.changelog.md +20 -0
  80. package/src/components/menu-group/menu-group.define.js +3 -0
  81. package/src/components/menu-group/menu-group.js +44 -0
  82. package/src/components/menu-group/menu-group.readme.md +74 -0
  83. package/src/components/menu-group/menu-group.style.js +38 -0
  84. package/src/components/menu-item/menu-item.changelog.md +32 -0
  85. package/src/components/menu-item/menu-item.define.js +3 -0
  86. package/src/components/menu-item/menu-item.js +168 -0
  87. package/src/components/menu-item/menu-item.readme.md +132 -0
  88. package/src/components/menu-item/menu-item.style.js +117 -0
  89. package/src/components/nav/nav.changelog.md +35 -0
  90. package/src/components/nav/nav.define.js +3 -0
  91. package/src/components/nav/nav.js +212 -0
  92. package/src/components/nav/nav.readme.md +248 -0
  93. package/src/components/nav/nav.style.js +269 -0
  94. package/src/components/nav-item/nav-item.changelog.md +25 -0
  95. package/src/components/nav-item/nav-item.define.js +3 -0
  96. package/src/components/nav-item/nav-item.js +75 -0
  97. package/src/components/nav-item/nav-item.readme.md +111 -0
  98. package/src/components/nav-item/nav-item.style.js +159 -0
  99. package/src/components/otp-field/otp-field.changelog.md +6 -0
  100. package/src/components/otp-field/otp-field.readme.md +8 -0
  101. package/src/components/otp-field/otp-field.style.js +8 -3
  102. package/src/components/pagination/pagination.changelog.md +8 -0
  103. package/src/components/pagination/pagination.js +123 -49
  104. package/src/components/pagination/pagination.readme.md +24 -6
  105. package/src/components/pagination/pagination.style.js +11 -1
  106. package/src/components/password-field/password-field.changelog.md +7 -0
  107. package/src/components/password-field/password-field.readme.md +11 -1
  108. package/src/components/password-field/password-field.style.js +2 -0
  109. package/src/components/popover/popover.changelog.md +6 -0
  110. package/src/components/popover/popover.style.js +1 -0
  111. package/src/components/radio-field/radio-field.changelog.md +6 -0
  112. package/src/components/radio-field/radio-field.js +7 -2
  113. package/src/components/radio-field/radio-field.readme.md +23 -1
  114. package/src/components/scroll-to-top/scroll-to-top.changelog.md +7 -5
  115. package/src/components/scroll-to-top/scroll-to-top.js +16 -12
  116. package/src/components/scroll-to-top/scroll-to-top.readme.md +2 -0
  117. package/src/components/segmented-field/segmented-field.changelog.md +27 -0
  118. package/src/components/segmented-field/segmented-field.define.js +3 -0
  119. package/src/components/segmented-field/segmented-field.js +175 -0
  120. package/src/components/segmented-field/segmented-field.readme.md +140 -0
  121. package/src/components/segmented-field/segmented-field.style.js +193 -0
  122. package/src/components/splitter/splitter.changelog.md +24 -0
  123. package/src/components/splitter/splitter.define.js +3 -0
  124. package/src/components/splitter/splitter.events.js +4 -0
  125. package/src/components/splitter/splitter.js +237 -0
  126. package/src/components/splitter/splitter.readme.md +164 -0
  127. package/src/components/splitter/splitter.style.js +100 -0
  128. package/src/components/status-bar/status-bar.changelog.md +25 -0
  129. package/src/components/status-bar/status-bar.define.js +3 -0
  130. package/src/components/status-bar/status-bar.js +74 -0
  131. package/src/components/status-bar/status-bar.readme.md +139 -0
  132. package/src/components/status-bar/status-bar.style.js +122 -0
  133. package/src/components/tab-group/tab-group.changelog.md +7 -0
  134. package/src/components/tab-group/tab-group.js +30 -9
  135. package/src/components/tab-group/tab-group.readme.md +14 -0
  136. package/src/components/textarea-field/textarea-field.changelog.md +6 -0
  137. package/src/components/textarea-field/textarea-field.js +14 -1
  138. package/src/components/textarea-field/textarea-field.readme.md +23 -1
  139. package/src/components/toast/toast.changelog.md +6 -0
  140. package/src/components/toast/toast.readme.md +5 -3
  141. package/src/components/toast/toast.style.js +22 -6
  142. package/src/components/toolbar/toolbar.changelog.md +24 -0
  143. package/src/components/toolbar/toolbar.define.js +3 -0
  144. package/src/components/toolbar/toolbar.js +233 -0
  145. package/src/components/toolbar/toolbar.readme.md +156 -0
  146. package/src/components/toolbar/toolbar.style.js +49 -0
  147. package/src/components/tooltip/tooltip.changelog.md +11 -0
  148. package/src/components/tooltip/tooltip.js +51 -4
  149. package/src/components/tooltip/tooltip.readme.md +26 -1
  150. package/src/components/tree/tree.changelog.md +23 -0
  151. package/src/components/tree/tree.define.js +3 -0
  152. package/src/components/tree/tree.js +138 -0
  153. package/src/components/tree/tree.readme.md +119 -0
  154. package/src/components/tree/tree.style.js +16 -0
  155. package/src/components/tree-item/tree-item.changelog.md +23 -0
  156. package/src/components/tree-item/tree-item.define.js +3 -0
  157. package/src/components/tree-item/tree-item.events.js +3 -0
  158. package/src/components/tree-item/tree-item.js +246 -0
  159. package/src/components/tree-item/tree-item.readme.md +128 -0
  160. package/src/components/tree-item/tree-item.style.js +226 -0
  161. package/src/styles/appearance.style.js +47 -0
  162. package/src/styles/choice-group.style.js +27 -1
  163. package/src/styles/input-control.style.js +87 -0
  164. package/src/styles/modal.style.js +14 -1
  165. package/src/styles/native.css +100 -0
  166. package/src/styles/size.style.js +41 -0
  167. package/src/utils/floating.js +15 -1
  168. package/src/utils/focus.js +69 -0
  169. package/src/utils/options.js +35 -0
  170. package/src/utils/scroll.js +24 -0
  171. package/src/utils/text-entry-attributes.js +13 -0
  172. package/types/all.d.ts +16 -0
  173. package/types/src/components/accordion/accordion.d.ts +3 -1
  174. package/types/src/components/app-bar/app-bar.d.ts +43 -0
  175. package/types/src/components/app-bar/app-bar.define.d.ts +1 -0
  176. package/types/src/components/app-bar/app-bar.style.d.ts +2 -0
  177. package/types/src/components/app-frame/app-frame.d.ts +497 -0
  178. package/types/src/components/app-frame/app-frame.define.d.ts +1 -0
  179. package/types/src/components/app-frame/app-frame.events.d.ts +7 -0
  180. package/types/src/components/app-frame/app-frame.style.d.ts +8 -0
  181. package/types/src/components/button/button.d.ts +61 -0
  182. package/types/src/components/button/button.events.d.ts +4 -0
  183. package/types/src/components/checkbox-group-field/checkbox-group-field.d.ts +5 -2
  184. package/types/src/components/combobox-field/combobox-field.d.ts +10 -0
  185. package/types/src/components/date-field/date-field.d.ts +10 -0
  186. package/types/src/components/description-list/description-list.d.ts +34 -0
  187. package/types/src/components/description-list/description-list.define.d.ts +1 -0
  188. package/types/src/components/description-list/description-list.style.d.ts +2 -0
  189. package/types/src/components/file-field/file-field.d.ts +68 -3
  190. package/types/src/components/form-field/form-field.d.ts +1 -1
  191. package/types/src/components/input-field/input-field.d.ts +99 -0
  192. package/types/src/components/list/list.d.ts +41 -0
  193. package/types/src/components/list/list.define.d.ts +1 -0
  194. package/types/src/components/list/list.style.d.ts +2 -0
  195. package/types/src/components/list-item/list-item.d.ts +64 -0
  196. package/types/src/components/list-item/list-item.define.d.ts +1 -0
  197. package/types/src/components/list-item/list-item.style.d.ts +2 -0
  198. package/types/src/components/menu/menu.d.ts +362 -0
  199. package/types/src/components/menu/menu.define.d.ts +1 -0
  200. package/types/src/components/menu/menu.events.d.ts +6 -0
  201. package/types/src/components/menu/menu.style.d.ts +2 -0
  202. package/types/src/components/menu-group/menu-group.d.ts +24 -0
  203. package/types/src/components/menu-group/menu-group.define.d.ts +1 -0
  204. package/types/src/components/menu-group/menu-group.style.d.ts +2 -0
  205. package/types/src/components/menu-item/menu-item.d.ts +80 -0
  206. package/types/src/components/menu-item/menu-item.define.d.ts +1 -0
  207. package/types/src/components/menu-item/menu-item.style.d.ts +2 -0
  208. package/types/src/components/nav/nav.d.ts +103 -0
  209. package/types/src/components/nav/nav.define.d.ts +1 -0
  210. package/types/src/components/nav/nav.style.d.ts +2 -0
  211. package/types/src/components/nav-item/nav-item.d.ts +39 -0
  212. package/types/src/components/nav-item/nav-item.define.d.ts +1 -0
  213. package/types/src/components/nav-item/nav-item.style.d.ts +2 -0
  214. package/types/src/components/otp-field/otp-field.d.ts +10 -0
  215. package/types/src/components/pagination/pagination.d.ts +31 -2
  216. package/types/src/components/password-field/password-field.d.ts +10 -0
  217. package/types/src/components/radio-field/radio-field.d.ts +5 -2
  218. package/types/src/components/scroll-to-top/scroll-to-top.d.ts +6 -5
  219. package/types/src/components/segmented-field/segmented-field.d.ts +85 -0
  220. package/types/src/components/segmented-field/segmented-field.define.d.ts +1 -0
  221. package/types/src/components/segmented-field/segmented-field.style.d.ts +2 -0
  222. package/types/src/components/splitter/splitter.d.ts +127 -0
  223. package/types/src/components/splitter/splitter.define.d.ts +1 -0
  224. package/types/src/components/splitter/splitter.events.d.ts +5 -0
  225. package/types/src/components/splitter/splitter.style.d.ts +2 -0
  226. package/types/src/components/status-bar/status-bar.d.ts +44 -0
  227. package/types/src/components/status-bar/status-bar.define.d.ts +1 -0
  228. package/types/src/components/status-bar/status-bar.style.d.ts +2 -0
  229. package/types/src/components/tab-group/tab-group.d.ts +17 -0
  230. package/types/src/components/textarea-field/textarea-field.d.ts +7 -0
  231. package/types/src/components/toolbar/toolbar.d.ts +96 -0
  232. package/types/src/components/toolbar/toolbar.define.d.ts +1 -0
  233. package/types/src/components/toolbar/toolbar.style.d.ts +2 -0
  234. package/types/src/components/tooltip/tooltip.d.ts +26 -0
  235. package/types/src/components/tree/tree.d.ts +62 -0
  236. package/types/src/components/tree/tree.define.d.ts +1 -0
  237. package/types/src/components/tree/tree.style.d.ts +2 -0
  238. package/types/src/components/tree-item/tree-item.d.ts +106 -0
  239. package/types/src/components/tree-item/tree-item.define.d.ts +1 -0
  240. package/types/src/components/tree-item/tree-item.events.d.ts +4 -0
  241. package/types/src/components/tree-item/tree-item.style.d.ts +2 -0
  242. package/types/src/styles/appearance.style.d.ts +31 -0
  243. package/types/src/styles/choice-group.style.d.ts +1 -1
  244. package/types/src/styles/input-control.style.d.ts +15 -0
  245. package/types/src/styles/modal.style.d.ts +5 -0
  246. package/types/src/styles/size.style.d.ts +24 -0
  247. package/types/src/utils/floating.d.ts +11 -0
  248. package/types/src/utils/focus.d.ts +25 -0
  249. package/types/src/utils/options.d.ts +17 -0
  250. package/types/src/utils/scroll.d.ts +11 -0
  251. package/types/src/utils/text-entry-attributes.d.ts +10 -0
  252. package/web-types.json +2935 -308
@@ -0,0 +1,1085 @@
1
+ import { TemplateElement, defineElement, html } from '@webtides/element-js';
2
+ import { define as defineDrawer } from '../drawer/drawer.js';
3
+ import { define as defineSplitter } from '../splitter/splitter.js';
4
+ import { activeElement, containsFocusable } from '../../utils/focus.js';
5
+ import { hasSlotted } from '../../utils/slots.js';
6
+ import style, { DEFAULT_STEP, STEPS } from './app-frame.style.js';
7
+ import Events from './app-frame.events.js';
8
+
9
+ /** The regions the page can leave out by the width of the frame. */
10
+ const REGIONS = ['header', 'navigation', 'aside', 'footer'];
11
+
12
+ /** The regions whose width the user can set by dragging their edge. */
13
+ const RESIZABLE = ['navigation', 'aside'];
14
+
15
+ /** What opens and closes the navigation where it is a drawer: any element with this attribute. */
16
+ const TOGGLE = '[data-navigation-toggle]';
17
+
18
+ /** What the user types into: the controls an on-screen keyboard opens for. */
19
+ const TYPED_INTO =
20
+ 'input, textarea, select, [contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]';
21
+
22
+ /**
23
+ * The least a part of the viewport is covered by, in pixels, for it to be taken as covered by an
24
+ * on-screen keyboard. Less is a scrollbar, or a height that is rounded.
25
+ */
26
+ const KEYBOARD = 80;
27
+
28
+ /**
29
+ * How long, in milliseconds, a scroll of the document is taken for the doing of something else
30
+ * than a tap on the status bar: after a finger that dragged the page has left the screen, after a
31
+ * wheel or a key, after a keyboard has come or gone, and after the viewport has changed its size.
32
+ * A page that was dragged swings back for that long.
33
+ */
34
+ const SETTLE = 700;
35
+
36
+ /**
37
+ * How long, in milliseconds, a scroll of the document is taken to go on after it was last heard
38
+ * of, where the browser does not say when it is over (`scrollend`). iOS is on its way to the
39
+ * top for a second and a half after a tap on the status bar, and takes the document back there
40
+ * for as long.
41
+ */
42
+ const LONGEST = 2000;
43
+
44
+ /**
45
+ * How long, in milliseconds, after the frame has put the document on its pixel a scroll back to
46
+ * zero is the browser that takes the pixel away again, and no tap.
47
+ */
48
+ const ECHO = 200;
49
+
50
+ /**
51
+ * The frame of an application: it fills what the browser shows and lays out five regions, a
52
+ * header, a footer, a navigation at the start side, an aside at the end side, and the content.
53
+ * The header and the footer stay in view, and the content scrolls between them.
54
+ *
55
+ * The frame knows regions, not what they mean. The page writes the elements that say so, the
56
+ * landmarks, and slots them: `<header slot="header">`, `<nav slot="navigation" aria-label="…">`,
57
+ * `<main id="…">`, `<aside slot="aside">`, `<footer slot="footer">`. The frame adds the layout,
58
+ * the room for the notch and the home indicator of a phone, and a link that skips to the content
59
+ * as the first stop of the Tab key. That link lies in the one landmark the frame has of its own,
60
+ * a navigation the page names (`skip-landmark-label`): content of a page belongs into a landmark.
61
+ *
62
+ * From the width `wide-from` names, the navigation and the aside are columns beside the content,
63
+ * and each scrolls on its own. Where the frame is narrow, the content and the aside are one
64
+ * column that scrolls, and the navigation does not show: it opens as a drawer from the start
65
+ * edge, from any element with `data-navigation-toggle`. The page writes the navigation once.
66
+ *
67
+ * The width is the one of the frame, and the stylesheet alone decides: a server-rendered frame
68
+ * has its layout before the script has run.
69
+ *
70
+ * `resizable` names the columns whose width the user sets by dragging their edge, an
71
+ * `el-splitter` of the frame. `navigation-size` and `aside-size` are those widths: the frame tells
72
+ * of them, and the page keeps them and gives them back.
73
+ *
74
+ * Where a browser lays its on-screen keyboard over the page, the frame is as high as what shows
75
+ * above the keyboard, and where that part is: the header stays in view, and the field the user
76
+ * types into does. That needs the script.
77
+ *
78
+ * With `status-bar-tap` a tap on the status bar of an iPhone brings the content to its top, as it
79
+ * does in an application. iOS scrolls the document for that tap and never a region, so the frame
80
+ * keeps the document scrolled by one pixel there, and hears it go back. The document snaps to
81
+ * that pixel: a script of the page that scrolls the window does not move it, and is no tap.
82
+ *
83
+ * @element el-app-frame
84
+ *
85
+ * @fires {CustomEvent<{ open: boolean }>} app-frame-navigation-toggle - Fired when the drawer of
86
+ * the navigation opens or closes, with the new state in `detail.open`.
87
+ * @fires {CustomEvent<{ region: 'navigation'|'aside', size: number }>} app-frame-resize - Fired
88
+ * with every change the user makes to the width of a column: while its edge is dragged, and
89
+ * with every key. The new width in pixels is in `detail.size`.
90
+ * @fires {CustomEvent<{ region: 'navigation'|'aside', size: number }>} app-frame-resize-end -
91
+ * Fired once the user has set a width: when the pointer lets go of the edge, and with every
92
+ * key. The width to keep is in `detail.size`.
93
+ * @fires {CustomEvent} app-frame-status-bar-tap - Fired when the user has tapped the status bar of
94
+ * an iPhone, with `status-bar-tap`. The frame scrolls its content to the top after it, unless a
95
+ * listener calls `preventDefault()`: a view whose columns scroll brings those to their tops.
96
+ *
97
+ * @slot - The content of the view: the `main` of the page, with an id for the skip link.
98
+ * @slot header - The region at the top, an app bar as a rule. Left out while it is empty.
99
+ * @slot navigation - The region at the start side, and the content of the drawer where the frame
100
+ * is narrow. Left out while it is empty.
101
+ * @slot aside - The region at the end side. Left out while it is empty.
102
+ * @slot footer - The region at the lower edge. Left out while it is empty.
103
+ *
104
+ * @csspart base - The frame: the grid of the regions.
105
+ * @csspart skip-landmark - The landmark the skip link lies in: a `<nav>`.
106
+ * @csspart skip-link - The link that skips to the content. It shows while it has the focus.
107
+ * @csspart header - The region at the top. Its surface reaches under the status bar of a phone.
108
+ * @csspart navigation - The region at the start side, where the frame is wide.
109
+ * @csspart body - The content and the aside. Where the frame is narrow, it is what scrolls.
110
+ * @csspart content - The region of the content. Where the frame is wide, it is what scrolls.
111
+ * @csspart aside - The region at the end side.
112
+ * @csspart footer - The region at the lower edge. Its surface reaches under the home indicator.
113
+ * @csspart drawer - The surface of the drawer the navigation is in where the frame is narrow.
114
+ * @csspart drawer-header - The header of that drawer, with its title and its close button.
115
+ * @csspart drawer-title - The title of that drawer.
116
+ * @csspart drawer-close-button - The close button of that drawer.
117
+ * @csspart drawer-body - The body of that drawer: the navigation of the page is in it.
118
+ * @csspart navigation-splitter - The edge of the navigation the user drags, an `el-splitter`.
119
+ * @csspart aside-splitter - The edge of the aside the user drags, an `el-splitter`.
120
+ *
121
+ * @cssproperty --el-app-frame-navigation-size - The width of the navigation where the frame is
122
+ * wide, and of its drawer where it is narrow. Default `16rem`. `auto` is the width of what is
123
+ * in it.
124
+ * @cssproperty --el-app-frame-aside-size - The width of the aside where the frame is wide.
125
+ * Default `20rem`.
126
+ * @cssproperty --el-app-frame-navigation-min-size - The least width of a navigation that is
127
+ * resizable. Default `10rem`.
128
+ * @cssproperty --el-app-frame-navigation-max-size - The greatest width of a navigation that is
129
+ * resizable. Default `min(30rem, 40cqi)`: two fifths of the width of the frame at most.
130
+ * @cssproperty --el-app-frame-aside-min-size - The least width of an aside that is resizable.
131
+ * Default `10rem`.
132
+ * @cssproperty --el-app-frame-aside-max-size - The greatest width of an aside that is resizable.
133
+ * Default `min(30rem, 40cqi)`.
134
+ *
135
+ * @cssstate navigation-open - Set while the drawer of the navigation is open.
136
+ * @cssstate keyboard - Set while an on-screen keyboard covers a part of the viewport, and the
137
+ * frame is as high as what shows above it.
138
+ *
139
+ * @property {string} skipLabel - The text of the link that skips to the content. Default
140
+ * `'Skip to content'`.
141
+ * @property {string} skipLandmarkLabel - The name of the landmark that link lies in, a
142
+ * navigation, for assistive technology. It has to differ from the names of the other
143
+ * navigations of the page. Default `'Skip link'`.
144
+ * @property {'30rem'|'40rem'|'48rem'|'64rem'|'80rem'} wideFrom - The width of the frame from
145
+ * which the navigation and the aside are columns beside the content. One of the steps the
146
+ * stylesheet knows, another value is the default. Default `'48rem'`.
147
+ * @property {string} narrowOnly - The regions that are there only where the frame is narrow, as
148
+ * their names with a space between them: `header`, `navigation`, `aside`, `footer`. A bar of
149
+ * destinations in the footer of a phone, for example (`narrow-only="footer"`). Default `''`.
150
+ * @property {string} wideOnly - The regions that are there only where the frame is wide, named
151
+ * the same way. Default `''`.
152
+ * @property {'drawer'|'bar'} narrowNavigation - What the navigation is where the frame is narrow.
153
+ * `drawer`: it does not show, and opens as a drawer. `bar`: its region lies at the lower edge,
154
+ * for an `el-nav` whose destinations are a bar there and a rail in the column of the wide
155
+ * frame. Default `'drawer'`.
156
+ * @property {boolean} navigationOpen - Whether the drawer of the navigation is open. It is one
157
+ * only where the frame is narrow: elsewhere the property is `false`. Reflected to the
158
+ * `navigation-open` attribute.
159
+ * @property {string} navigationLabel - The title of the drawer of the navigation, and its name
160
+ * for assistive technology. Default `'Navigation'`.
161
+ * @property {string} closeLabel - The name of the close button of that drawer. Default
162
+ * `'Close'`.
163
+ * @property {string} resizable - The columns whose width the user sets by dragging their edge,
164
+ * as their names with a space between them: `navigation`, `aside`. Default `''`.
165
+ * @property {number} navigationSize - The width of the navigation where the frame is wide, in
166
+ * pixels: the one the user has set, or the one the page has kept. `0` is the width of the
167
+ * stylesheet (`--el-app-frame-navigation-size`). Default `0`.
168
+ * @property {number} asideSize - The width of the aside where the frame is wide, in pixels. `0`
169
+ * is the width of the stylesheet (`--el-app-frame-aside-size`). Default `0`.
170
+ * @property {string} asideLabel - The name of the aside for assistive technology, on the edge
171
+ * that sizes it. The edge of the navigation has `navigation-label`. Default `'Aside'`.
172
+ * @property {boolean} statusBarTap - Whether a tap on the status bar of an iPhone brings the
173
+ * content to its top. The document of the page is one pixel higher than the viewport then, and
174
+ * snaps to that pixel. Default `false`.
175
+ */
176
+ export default class AppFrame extends TemplateElement {
177
+ /**
178
+ * Tells of every change of a size: of the frame, which can make it wide or narrow, and of a
179
+ * region, which can make it scroll or stop it from scrolling.
180
+ * @private
181
+ * @type {ResizeObserver | undefined}
182
+ */
183
+ _resizeObserver = undefined;
184
+
185
+ /**
186
+ * Whether the navigation is in a drawer: the frame is narrow, and has a navigation there.
187
+ * Only the script knows, so a server and the first render in the browser have the region.
188
+ * @private
189
+ */
190
+ _inDrawer = false;
191
+
192
+ /**
193
+ * What the frame has said of its drawer last, so it says a change once.
194
+ * @private
195
+ */
196
+ _saidOpen = false;
197
+
198
+ /**
199
+ * Whether the script has started. The edges to drag are there from then on: they do nothing
200
+ * before, and a server leaves them out.
201
+ * @private
202
+ */
203
+ _started = false;
204
+
205
+ /**
206
+ * The height of what scrolls the content, as it was last: a field the user types into is
207
+ * brought back into view when that height gets less.
208
+ * @private
209
+ */
210
+ _scrollerSize = 0;
211
+
212
+ /**
213
+ * Whether an on-screen keyboard covers a part of the viewport, as the frame has said last
214
+ * (`:state(keyboard)`). Kept here, and not read back from the states of the element: WebKit
215
+ * forgets what was added to them a moment later (`states.has()` is `false`), while the state
216
+ * still matches.
217
+ * @private
218
+ */
219
+ _keyboard = false;
220
+
221
+ /**
222
+ * Tells of a visual viewport that changes: an on-screen keyboard that comes or goes, or the
223
+ * page that the browser moves behind it.
224
+ * @private
225
+ * @param {Event} event
226
+ */
227
+ _onViewport = (event) => {
228
+ // A viewport that changes its size is not the doing of a tap on the status bar, whatever
229
+ // the document does next. One that moves says nothing: it does so for that tap as well.
230
+ if (event.type === 'resize') this._quiet();
231
+ this._syncViewport();
232
+ };
233
+
234
+ /**
235
+ * What the frame keeps while it listens for a tap on the status bar: the element that makes
236
+ * the document one pixel higher than the viewport, whether the document snaps to that pixel
237
+ * and what the page had in the place of that rule, whether a script can move the document all
238
+ * the same, how many fingers are on the screen, until when a scroll of the document is
239
+ * somebody else's, whether the document is scrolling and when it was last heard of, when the
240
+ * frame has put it on its pixel last, and the timer that does so.
241
+ * @private
242
+ * @type {{ sentinel: HTMLElement, snaps: boolean, snapBefore: string, held: boolean, touches: number, dragged: boolean, quietUntil: number, scrolling: boolean, scrolledAt: number, armedAt: number, timer: number } | undefined}
243
+ */
244
+ _statusBar = undefined;
245
+
246
+ /** @private */
247
+ _onDocumentScroll = () => this._onStatusBarScroll();
248
+
249
+ /**
250
+ * The scroll of the document is over: it can have its pixel back.
251
+ * @private
252
+ */
253
+ _onDocumentScrollEnd = () => {
254
+ const state = this._statusBar;
255
+ if (!state) return;
256
+ state.scrolling = false;
257
+ if (window.scrollY < 1) this._arm();
258
+ };
259
+
260
+ /**
261
+ * A finger has come or gone. One that has dragged the document, from the header or the
262
+ * footer, leaves a page that swings back: for that moment a scroll is not a tap. One that has
263
+ * scrolled the content has moved no document, and a tap right after it counts.
264
+ * @private
265
+ * @param {TouchEvent} event
266
+ */
267
+ _onTouch = (event) => {
268
+ const state = this._statusBar;
269
+ if (!state) return;
270
+ state.touches = event.touches.length;
271
+ if (state.touches > 0 || !state.dragged) return;
272
+ state.dragged = false;
273
+ this._quiet();
274
+ };
275
+
276
+ /**
277
+ * A wheel or a key: over the header they scroll the document, as the tap does.
278
+ * @private
279
+ */
280
+ _onInput = () => this._quiet();
281
+
282
+ constructor() {
283
+ super({
284
+ styles: [style],
285
+ shadowRender: true,
286
+ propertyOptions: { navigationOpen: { reflect: true } },
287
+ });
288
+ }
289
+
290
+ properties() {
291
+ return {
292
+ skipLabel: 'Skip to content',
293
+ skipLandmarkLabel: 'Skip link',
294
+ wideFrom: DEFAULT_STEP,
295
+ narrowOnly: '',
296
+ wideOnly: '',
297
+ narrowNavigation: 'drawer',
298
+ navigationOpen: false,
299
+ navigationLabel: 'Navigation',
300
+ closeLabel: 'Close',
301
+ resizable: '',
302
+ navigationSize: 0,
303
+ asideSize: 0,
304
+ asideLabel: 'Aside',
305
+ statusBarTap: false,
306
+ };
307
+ }
308
+
309
+ connected() {
310
+ this._resizeObserver = new ResizeObserver(() => {
311
+ this._syncView();
312
+ this._syncTabStops();
313
+ this._syncEdges();
314
+ this._syncFocus();
315
+ });
316
+ this._observeSizes();
317
+ this._syncView();
318
+ this._started = true;
319
+ if (this._resizable().length > 0) this.requestUpdate();
320
+
321
+ window.visualViewport?.addEventListener('resize', this._onViewport);
322
+ window.visualViewport?.addEventListener('scroll', this._onViewport);
323
+ this._syncViewport();
324
+ this._syncStatusBar();
325
+ }
326
+
327
+ disconnected() {
328
+ this._resizeObserver?.disconnect();
329
+ window.visualViewport?.removeEventListener('resize', this._onViewport);
330
+ window.visualViewport?.removeEventListener('scroll', this._onViewport);
331
+ this._syncStatusBar();
332
+ }
333
+
334
+ afterUpdate() {
335
+ // A render can have brought or taken the drawer, and with it a region to watch.
336
+ this._observeSizes();
337
+ this._syncToggles();
338
+ this._syncEdges();
339
+ }
340
+
341
+ watch() {
342
+ return {
343
+ narrowNavigation: () => this._syncView(),
344
+ wideOnly: () => this._syncView(),
345
+ statusBarTap: () => this._syncStatusBar(),
346
+ navigationOpen: () => {
347
+ // There is a drawer to open only where the frame is narrow.
348
+ if (this.navigationOpen && !this._inDrawer) {
349
+ this.navigationOpen = false;
350
+ return;
351
+ }
352
+ if (this.navigationOpen) this._internals.states.add('navigation-open');
353
+ else this._internals.states.delete('navigation-open');
354
+ this._syncToggles();
355
+ if (this.navigationOpen === this._saidOpen) return;
356
+ this._saidOpen = this.navigationOpen;
357
+ this.dispatch(Events.NAVIGATION_TOGGLE, { open: this.navigationOpen });
358
+ },
359
+ };
360
+ }
361
+
362
+ events() {
363
+ return {
364
+ this: {
365
+ click: (event) => this._onClick(event),
366
+ },
367
+ // A template element does not render again when a child comes, goes or changes its
368
+ // `slot` attribute. The slot tells of all three, and the event bubbles to the base.
369
+ "[part~='base']": {
370
+ slotchange: () => {
371
+ this.requestUpdate();
372
+ this._observeSizes();
373
+ this._syncView();
374
+ },
375
+ },
376
+ "[part~='skip-link']": {
377
+ click: (event) => this._onSkip(event),
378
+ },
379
+ // The drawer is a part of the frame. What it says of itself stays in the frame, and
380
+ // the frame says it in its own words.
381
+ 'el-drawer': {
382
+ 'drawer-show': (event) => event.stopPropagation(),
383
+ 'drawer-after-show': (event) => event.stopPropagation(),
384
+ 'drawer-initial-focus': (event) => event.stopPropagation(),
385
+ 'drawer-request-close': (event) => event.stopPropagation(),
386
+ 'drawer-hide': (event) => {
387
+ event.stopPropagation();
388
+ // Closed by its own button, by Escape or by a click beside it.
389
+ this.navigationOpen = false;
390
+ },
391
+ 'drawer-after-hide': (event) => event.stopPropagation(),
392
+ },
393
+ // And so are the edges of the columns.
394
+ 'el-splitter': {
395
+ 'splitter-resize': (event) => this._onResize(event, Events.RESIZE),
396
+ 'splitter-resize-end': (event) => this._onResize(event, Events.RESIZE_END),
397
+ },
398
+ };
399
+ }
400
+
401
+ /**
402
+ * Whether the frame is wide: the navigation, the content and the aside are beside each other.
403
+ * The stylesheet decides, by the width of the frame and its `wide-from`; this reads what it
404
+ * has decided, so the width is written in one place.
405
+ * @returns {boolean}
406
+ */
407
+ get wide() {
408
+ const base = this.$refs.base;
409
+ if (!base) return false;
410
+ return getComputedStyle(base).getPropertyValue('--_el-app-frame-view').trim() === 'wide';
411
+ }
412
+
413
+ /**
414
+ * The element that scrolls the content: the region of the content where the frame is wide,
415
+ * the column of the content and the aside where it is narrow. For a page that sets the scroll
416
+ * back after a change of the view, or brings a position back. The window does not scroll in a
417
+ * frame.
418
+ * @returns {HTMLElement | undefined}
419
+ */
420
+ get scroller() {
421
+ return this.wide ? this.$refs.content : this.$refs.body;
422
+ }
423
+
424
+ /**
425
+ * The element of the page the skip link leads to: its `main`, or the first element that is in
426
+ * no named slot.
427
+ * @private
428
+ * @returns {Element | undefined}
429
+ */
430
+ _content() {
431
+ const inDefaultSlot = [...this.children].filter((child) => !child.getAttribute('slot'));
432
+ return inDefaultSlot.find((child) => child.localName === 'main') ?? inDefaultSlot[0];
433
+ }
434
+
435
+ /**
436
+ * The names of regions in an attribute of the page, and nothing else.
437
+ * @private
438
+ * @param {string} names
439
+ * @returns {string[]}
440
+ */
441
+ _regionsOf(names) {
442
+ return String(names ?? '')
443
+ .split(/\s+/)
444
+ .filter((name) => REGIONS.includes(name));
445
+ }
446
+
447
+ /**
448
+ * The columns the page lets the user size.
449
+ * @private
450
+ * @returns {string[]}
451
+ */
452
+ _resizable() {
453
+ return this._regionsOf(this.resizable).filter((name) => RESIZABLE.includes(name));
454
+ }
455
+
456
+ /**
457
+ * An edge says the width of its column, and the least and the greatest one. The stylesheet
458
+ * has them, in any unit, and the edge needs pixels: they are read from the column as it is
459
+ * laid out. A limit that is no length there, a percentage, is none for the edge. The
460
+ * stylesheet keeps it all the same, and the width is read again after every change.
461
+ * @private
462
+ */
463
+ _syncEdges() {
464
+ for (const edge of this.shadowRoot?.querySelectorAll('el-splitter') ?? []) {
465
+ const region = this.shadowRoot.querySelector(`[part~='${edge.dataset.region}']`);
466
+ // A column that is not laid out, where the frame is narrow, has no width to say.
467
+ if (!region || !this.wide || getComputedStyle(region).display === 'none') continue;
468
+
469
+ const { inlineSize, minInlineSize, maxInlineSize } = getComputedStyle(region);
470
+ const pixels = (length, otherwise) => (length.endsWith('px') ? Math.round(parseFloat(length)) : otherwise);
471
+ const value = pixels(inlineSize, 0);
472
+ const min = pixels(minInlineSize, 0);
473
+ const max = pixels(maxInlineSize, Math.round(this.$refs.base.getBoundingClientRect().width));
474
+ if (edge.value !== value) edge.value = value;
475
+ if (edge.min !== min) edge.min = min;
476
+ if (edge.max !== max) edge.max = max;
477
+ }
478
+ }
479
+
480
+ /**
481
+ * The user has moved an edge: the column takes the width, and the frame tells of it in its
482
+ * own words.
483
+ * @private
484
+ * @param {CustomEvent<{ value: number }>} event
485
+ * @param {string} name - The event of the frame.
486
+ */
487
+ _onResize(event, name) {
488
+ event.stopPropagation();
489
+
490
+ const region = event.currentTarget.dataset.region;
491
+ const size = event.detail.value;
492
+ if (region === 'aside') this.asideSize = size;
493
+ else this.navigationSize = size;
494
+ this.dispatch(name, { region, size });
495
+ }
496
+
497
+ /**
498
+ * A browser that lays its on-screen keyboard over the page leaves the layout as it is: the
499
+ * frame is as high as the viewport, and its lower part is under the keyboard. To show the
500
+ * field the user types into, the browser moves the page up behind the keyboard, and the
501
+ * header leaves the screen with it.
502
+ *
503
+ * The visual viewport is what shows. While it is less high than the layout by more than a
504
+ * scrollbar, and the user types into something, the frame takes its place and its height:
505
+ * the header is at the top of what shows, the footer above the keyboard, and the content
506
+ * scrolls between them. The browser tells of the viewport once it has moved it, so for the
507
+ * moment the keyboard comes in the regions are on their way.
508
+ *
509
+ * A viewport that shows less is no keyboard by itself. Safari on iOS makes the visual
510
+ * viewport less high while a finger pulls the page past its top, by the length of the pull
511
+ * and with the numbers of a keyboard. A keyboard is there for a field, so the frame takes
512
+ * one that has the focus for the sign.
513
+ *
514
+ * Only a frame that fills the viewport follows, and not while the user has zoomed in: what
515
+ * shows is a part of the page then, by the will of the user.
516
+ * @private
517
+ */
518
+ _syncViewport() {
519
+ const viewport = window.visualViewport;
520
+ if (!viewport) return;
521
+
522
+ const covered =
523
+ getComputedStyle(this).position === 'fixed' &&
524
+ Math.abs(viewport.scale - 1) < 0.01 &&
525
+ document.documentElement.clientHeight - viewport.height > KEYBOARD &&
526
+ this._isTyping();
527
+
528
+ if (!covered) {
529
+ if (!this._keyboard) return;
530
+ this._keyboard = false;
531
+ this._internals.states.delete('keyboard');
532
+ this.style.removeProperty('--_el-app-frame-visible-start');
533
+ this.style.removeProperty('--_el-app-frame-visible-size');
534
+ // The document is where the keyboard has left it: back by its pixel, for a tap on
535
+ // the status bar.
536
+ this._quiet();
537
+ this._arm();
538
+ return;
539
+ }
540
+
541
+ // The browser moves the page behind the keyboard, to show the field: it is free to.
542
+ this._snap(false);
543
+ this.style.setProperty('--_el-app-frame-visible-start', `${viewport.offsetTop}px`);
544
+ this.style.setProperty('--_el-app-frame-visible-size', `${viewport.height}px`);
545
+ this._keyboard = true;
546
+ this._internals.states.add('keyboard');
547
+ this._showFocus();
548
+ }
549
+
550
+ /**
551
+ * Whether the user types into something: a field or a text they edit has the focus, in the
552
+ * page or in a shadow root that is open, or a frame with another page has it, which keeps
553
+ * to itself what has the focus in it. An on-screen keyboard is there for one of these.
554
+ * @private
555
+ * @returns {boolean}
556
+ */
557
+ _isTyping() {
558
+ return activeElement()?.matches?.(`${TYPED_INTO}, iframe`) === true;
559
+ }
560
+
561
+ /**
562
+ * Whether the frame listens for a tap on the status bar: the page asks for it, the frame
563
+ * fills the viewport, and the browser is one of iOS, which has that tap and nothing that
564
+ * tells of it. `-webkit-touch-callout` is a property only its WebKit knows.
565
+ * @private
566
+ * @returns {boolean}
567
+ */
568
+ _wantsStatusBarTap() {
569
+ const asked = this.statusBarTap === true || this.statusBarTap === 'true' || this.statusBarTap === '';
570
+ return (
571
+ asked &&
572
+ this.isConnected &&
573
+ getComputedStyle(this).position === 'fixed' &&
574
+ CSS.supports('-webkit-touch-callout', 'none') &&
575
+ CSS.supports('block-size', '100dvh')
576
+ );
577
+ }
578
+
579
+ /**
580
+ * Starts or stops listening for a tap on the status bar.
581
+ *
582
+ * iOS scrolls the document to its top for that tap, and a frame leaves the document nothing
583
+ * to scroll. So an element makes the document one pixel higher than what the browser shows,
584
+ * and the document rests scrolled down by that pixel: it snaps there. The frame is fixed to
585
+ * the viewport and does not move with it. A tap takes the document back to zero, past the
586
+ * snap, which the frame hears.
587
+ * @private
588
+ */
589
+ _syncStatusBar() {
590
+ const wanted = this._wantsStatusBarTap();
591
+ if (wanted === !!this._statusBar) return;
592
+
593
+ if (!wanted) {
594
+ const { sentinel, timer } = this._statusBar;
595
+ this._snap(false);
596
+ this._statusBar = undefined;
597
+ clearTimeout(timer);
598
+ sentinel.remove();
599
+ window.removeEventListener('scroll', this._onDocumentScroll);
600
+ window.removeEventListener('scrollend', this._onDocumentScrollEnd);
601
+ for (const type of ['touchstart', 'touchend', 'touchcancel']) {
602
+ window.removeEventListener(type, this._onTouch, true);
603
+ }
604
+ for (const type of ['wheel', 'keydown']) window.removeEventListener(type, this._onInput, true);
605
+ return;
606
+ }
607
+
608
+ // An element of its own tree, so its rules need no stylesheet of the page. On paper there
609
+ // is no viewport, and it would add a sheet. The element in it is where the document
610
+ // snaps to: one pixel down.
611
+ const sentinel = document.createElement('div');
612
+ sentinel.setAttribute('data-el-app-frame-sentinel', '');
613
+ sentinel.setAttribute('aria-hidden', 'true');
614
+ sentinel.attachShadow({ mode: 'open' }).innerHTML = `<style>
615
+ :host {
616
+ position: absolute;
617
+ inset-block-start: 0;
618
+ inset-inline-start: 0;
619
+ inline-size: 1px;
620
+ block-size: calc(100dvh + 1px);
621
+ visibility: hidden;
622
+ pointer-events: none;
623
+ }
624
+ div {
625
+ position: absolute;
626
+ inset-block-start: 1px;
627
+ inset-inline-start: 0;
628
+ inline-size: 1px;
629
+ block-size: 1px;
630
+ scroll-snap-align: start;
631
+ }
632
+ @media print {
633
+ :host {
634
+ display: none;
635
+ }
636
+ }
637
+ </style><div></div>`;
638
+ document.body.append(sentinel);
639
+
640
+ this._statusBar = {
641
+ sentinel,
642
+ snaps: false,
643
+ snapBefore: '',
644
+ held: false,
645
+ touches: 0,
646
+ dragged: false,
647
+ quietUntil: 0,
648
+ scrolling: false,
649
+ scrolledAt: 0,
650
+ armedAt: 0,
651
+ timer: 0,
652
+ };
653
+ window.addEventListener('scroll', this._onDocumentScroll, { passive: true });
654
+ window.addEventListener('scrollend', this._onDocumentScrollEnd);
655
+ for (const type of ['touchstart', 'touchend', 'touchcancel']) {
656
+ window.addEventListener(type, this._onTouch, { capture: true, passive: true });
657
+ }
658
+ for (const type of ['wheel', 'keydown']) {
659
+ window.addEventListener(type, this._onInput, { capture: true, passive: true });
660
+ }
661
+ this._snap(true);
662
+ // The browser may put the scroll of a page back while it loads: not a tap either.
663
+ this._quiet();
664
+ this._arm();
665
+ }
666
+
667
+ /**
668
+ * Makes the document snap to its one pixel, or lets it go.
669
+ *
670
+ * What snaps is where a scroll ends, also the one of a script: `window.scrollTo(0, 0)` of a
671
+ * router leaves the document on its pixel. And a finger that has dragged the page lets it go
672
+ * back there. The tap on the status bar is the one scroll iOS does not snap.
673
+ *
674
+ * The rule is one for the element of the document, the only place the browser reads it for
675
+ * the viewport: the frame writes it there, and puts back what the page had.
676
+ * @private
677
+ * @param {boolean} on
678
+ */
679
+ _snap(on) {
680
+ const state = this._statusBar;
681
+ if (!state || state.snaps === on) return;
682
+ state.snaps = on;
683
+
684
+ const root = document.documentElement;
685
+ if (on) {
686
+ state.snapBefore = root.style.scrollSnapType;
687
+ root.style.scrollSnapType = 'y mandatory';
688
+ return;
689
+ }
690
+ root.style.scrollSnapType = state.snapBefore;
691
+ if (root.getAttribute('style') === '') root.removeAttribute('style');
692
+ }
693
+
694
+ /**
695
+ * From now on, for a moment, a scroll of the document is not the doing of a tap on the status
696
+ * bar: a finger drags the page, a keyboard moves it, the phone is turned.
697
+ * @private
698
+ */
699
+ _quiet() {
700
+ if (this._statusBar) this._statusBar.quietUntil = performance.now() + SETTLE;
701
+ }
702
+
703
+ /**
704
+ * Whether something else than a tap on the status bar is moving the document.
705
+ * @private
706
+ * @returns {boolean}
707
+ */
708
+ _isMoved() {
709
+ const { touches, quietUntil } = this._statusBar;
710
+ return touches > 0 || performance.now() < quietUntil || this._keyboard;
711
+ }
712
+
713
+ /**
714
+ * Whether the document is scrolling: it has scrolled, and the browser has not said that this
715
+ * is over. A browser that never says so is given the time the longest scroll takes.
716
+ * @private
717
+ * @returns {boolean}
718
+ */
719
+ _isScrolling() {
720
+ const { scrolling, scrolledAt } = this._statusBar;
721
+ return scrolling && performance.now() - scrolledAt < LONGEST;
722
+ }
723
+
724
+ /**
725
+ * Scrolls the document down by its one pixel, once nothing else moves it and its scroll is
726
+ * over: iOS takes the document back to the top for as long as it is on its way there. Until
727
+ * then it looks again: a finger can stay on the screen for long.
728
+ *
729
+ * And it asks what tells the tap from a script: whether a script can scroll the document to
730
+ * zero. Where the browser snaps the scroll of a script, it cannot. Where it can, the two look
731
+ * the same, and the frame takes no scroll for the tap.
732
+ * @private
733
+ */
734
+ _arm() {
735
+ const state = this._statusBar;
736
+ if (!state) return;
737
+ clearTimeout(state.timer);
738
+
739
+ const now = performance.now();
740
+ if (this._isMoved() || this._isScrolling()) {
741
+ const scrolls = this._isScrolling() ? state.scrolledAt + LONGEST - now : 0;
742
+ const wait = Math.max(state.quietUntil - now, scrolls, 150) + 50;
743
+ state.timer = setTimeout(() => this._arm(), wait);
744
+ return;
745
+ }
746
+ this._snap(true);
747
+ state.armedAt = now;
748
+ // At once, also where the page asks for a scroll that takes its time.
749
+ if (window.scrollY < 1) window.scrollTo({ top: 1, behavior: 'instant' });
750
+ window.scrollTo({ top: 0, behavior: 'instant' });
751
+ state.held = window.scrollY >= 1;
752
+ if (!state.held) window.scrollTo({ top: 1, behavior: 'instant' });
753
+ }
754
+
755
+ /**
756
+ * The document has scrolled. At zero, with nothing else that moves it, the user has tapped
757
+ * the status bar: the content goes to its top, as the document of a page would.
758
+ *
759
+ * A script of the page does not get the document there, a router that sets the scroll of the
760
+ * window back after a change of the view for one: the document snaps to its pixel.
761
+ * @private
762
+ */
763
+ _onStatusBarScroll() {
764
+ const state = this._statusBar;
765
+ if (!state) return;
766
+ const now = performance.now();
767
+ // The document moves under a finger: a drag, and no tap when the finger has gone.
768
+ if (state.touches > 0) state.dragged = true;
769
+ // The tap is the first thing a document at rest does. What follows it is iOS on its way
770
+ // to the top, which takes the document back there until it has arrived.
771
+ const first = !this._isScrolling();
772
+ state.scrolling = true;
773
+ state.scrolledAt = now;
774
+ if (window.scrollY >= 1) return;
775
+
776
+ const taken = now - state.armedAt < ECHO;
777
+ if (first && !taken && state.held && !this._isMoved()) {
778
+ // Built by hand: dispatch() of element-js does not say whether a listener has
779
+ // prevented the default.
780
+ const event = new CustomEvent(Events.STATUS_BAR_TAP, { bubbles: true, composed: true, cancelable: true });
781
+ this.dispatchEvent(event);
782
+ if (!event.defaultPrevented) {
783
+ const calm = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
784
+ this.scroller?.scrollTo({ top: 0, behavior: calm ? 'auto' : 'smooth' });
785
+ }
786
+ }
787
+ // Back by the pixel, for the next tap, once this scroll is over.
788
+ clearTimeout(state.timer);
789
+ state.timer = setTimeout(() => this._arm(), 50);
790
+ }
791
+
792
+ /**
793
+ * The regions have changed their sizes. Where what scrolls the content got less high, a
794
+ * keyboard has come in or the window got smaller, and the field the user types into may be
795
+ * out of view now.
796
+ * @private
797
+ */
798
+ _syncFocus() {
799
+ const size = this.scroller?.clientHeight ?? 0;
800
+ const less = size < this._scrollerSize;
801
+ this._scrollerSize = size;
802
+ if (less) this._showFocus();
803
+ }
804
+
805
+ /**
806
+ * Brings the field the user types into back into view, in the region that scrolls it. A
807
+ * field in a dialog or a popover is in the top layer and in no region: the browser shows it.
808
+ * @private
809
+ */
810
+ _showFocus() {
811
+ const active = activeElement();
812
+ if (!active?.matches?.(TYPED_INTO)) return;
813
+
814
+ for (let node = active; node && node !== this; node = node.assignedSlot ?? node.parentNode ?? node.host) {
815
+ if (node === document) return;
816
+ if (node instanceof Element && node.matches(':modal, :popover-open')) return;
817
+ }
818
+ active.scrollIntoView({ block: 'nearest', inline: 'nearest' });
819
+ }
820
+
821
+ /**
822
+ * Takes what the stylesheet has decided: where the frame is narrow and has a navigation
823
+ * there, the navigation is in a drawer. Where it is wide again, the drawer goes, open or
824
+ * not: the platform takes a dialog that leaves the page out of the top layer, and the drawer
825
+ * gives the scroll of the page back.
826
+ * @private
827
+ */
828
+ _syncView() {
829
+ if (!this.$refs.base) return;
830
+
831
+ const inDrawer =
832
+ !this.wide &&
833
+ this.narrowNavigation !== 'bar' &&
834
+ hasSlotted(this, 'navigation') &&
835
+ !this._regionsOf(this.wideOnly).includes('navigation');
836
+ if (inDrawer === this._inDrawer) return;
837
+
838
+ this._inDrawer = inDrawer;
839
+ if (!inDrawer) this.navigationOpen = false;
840
+ this.requestUpdate();
841
+ }
842
+
843
+ /**
844
+ * The elements of the page that open and close the navigation.
845
+ * @private
846
+ * @returns {HTMLElement[]}
847
+ */
848
+ _toggles() {
849
+ return [...this.querySelectorAll(TOGGLE)];
850
+ }
851
+
852
+ /**
853
+ * A toggle says whether the navigation is open, and is not there where there is no drawer to
854
+ * open. An `el-button` reads that from the stylesheet of the frame, before the script has
855
+ * run; any other element is hidden here.
856
+ * @private
857
+ */
858
+ _syncToggles() {
859
+ for (const toggle of this._toggles()) {
860
+ toggle.setAttribute('aria-expanded', this.navigationOpen ? 'true' : 'false');
861
+ if (toggle.localName !== 'el-button') toggle.hidden = !this._inDrawer;
862
+ }
863
+ }
864
+
865
+ /**
866
+ * A click on a toggle opens or closes the drawer. A click on a link in the open drawer closes
867
+ * it: the user has chosen where to go, also where the page changes the view without loading.
868
+ * @private
869
+ * @param {MouseEvent} event
870
+ */
871
+ _onClick(event) {
872
+ const path = event.composedPath().filter((node) => node instanceof Element);
873
+
874
+ if (path.some((node) => node.matches(TOGGLE))) {
875
+ if (this._inDrawer) this.navigationOpen = !this.navigationOpen;
876
+ return;
877
+ }
878
+
879
+ if (!this.navigationOpen) return;
880
+ const inNavigation = path.some(
881
+ (node) => node.parentNode === this && node.getAttribute('slot') === 'navigation',
882
+ );
883
+ if (inNavigation && path.some((node) => node.matches('a[href]'))) this.navigationOpen = false;
884
+ }
885
+
886
+ /**
887
+ * The regions that can scroll, each with the elements of the page that are in it.
888
+ * @private
889
+ * @returns {Array<[HTMLElement, Element[]]>}
890
+ */
891
+ _regions() {
892
+ return ['body', 'navigation', 'content', 'aside']
893
+ .map((name) => this.shadowRoot.querySelector(`[part~='${name}']`))
894
+ .filter(Boolean)
895
+ .map((region) => [
896
+ region,
897
+ [...region.querySelectorAll('slot')].flatMap((slot) => slot.assignedElements({ flatten: true })),
898
+ ]);
899
+ }
900
+
901
+ /**
902
+ * Watches the sizes of the frame, of the regions and of what the page has put into them.
903
+ * @private
904
+ */
905
+ _observeSizes() {
906
+ if (!this._resizeObserver) return;
907
+ this._resizeObserver.disconnect();
908
+ this._resizeObserver.observe(this);
909
+ for (const [region, elements] of this._regions()) {
910
+ this._resizeObserver.observe(region);
911
+ for (const element of elements) this._resizeObserver.observe(element);
912
+ }
913
+ }
914
+
915
+ /**
916
+ * A region that scrolls and has nothing in it that takes the focus is a stop of the Tab key
917
+ * itself: without one the keyboard cannot scroll it. Some browsers do that by themselves, and
918
+ * this does it for the others.
919
+ * @private
920
+ */
921
+ _syncTabStops() {
922
+ for (const [region, elements] of this._regions()) {
923
+ const { overflowY } = getComputedStyle(region);
924
+ const scrolls =
925
+ (overflowY === 'auto' || overflowY === 'scroll') && region.scrollHeight > region.clientHeight;
926
+
927
+ if (scrolls && !elements.some(containsFocusable)) {
928
+ region.setAttribute('tabindex', '0');
929
+ } else if (region.getAttribute('tabindex') === '0') {
930
+ region.removeAttribute('tabindex');
931
+ }
932
+ }
933
+ }
934
+
935
+ /**
936
+ * After the skip link the content is in view from its start, the keys scroll it, and the Tab
937
+ * key goes on inside of it: the region of the content has the focus.
938
+ *
939
+ * The link is a link to the id of the content, which a browser follows before the script has
940
+ * run. From then on the script does the same and leaves the address alone: a page that keeps
941
+ * its route in the fragment would lose it.
942
+ * @private
943
+ * @param {MouseEvent} event
944
+ */
945
+ _onSkip(event) {
946
+ event.preventDefault();
947
+
948
+ const region = this.$refs.content;
949
+ const scroller = this.scroller;
950
+ // The region scrolls itself where the frame is wide, and is a part of what scrolls where
951
+ // it is narrow.
952
+ scroller.scrollTop =
953
+ scroller === region
954
+ ? 0
955
+ : scroller.scrollTop + region.getBoundingClientRect().top - scroller.getBoundingClientRect().top;
956
+
957
+ // Where the region is no stop of the Tab key, it takes the focus for this moment only.
958
+ if (!region.hasAttribute('tabindex')) {
959
+ region.setAttribute('tabindex', '-1');
960
+ region.addEventListener(
961
+ 'blur',
962
+ () => {
963
+ if (region.getAttribute('tabindex') === '-1') region.removeAttribute('tabindex');
964
+ },
965
+ { once: true },
966
+ );
967
+ }
968
+ region.focus({ preventScroll: true });
969
+ }
970
+
971
+ /**
972
+ * The navigation: a region of the frame, or the content of a drawer where the frame is
973
+ * narrow. One slot either way, so the page writes the navigation once and no node is moved.
974
+ * @private
975
+ */
976
+ navigationTemplate() {
977
+ if (this._inDrawer) {
978
+ return html`
979
+ <el-drawer
980
+ class="drawer"
981
+ placement="start"
982
+ exportparts="base:drawer, header:drawer-header, title:drawer-title, close-button:drawer-close-button, body:drawer-body"
983
+ label="${this.navigationLabel}"
984
+ close-label="${this.closeLabel}"
985
+ open="${this.navigationOpen ? 'true' : 'false'}"
986
+ >
987
+ <slot name="navigation"></slot>
988
+ </el-drawer>
989
+ `;
990
+ }
991
+
992
+ return html`
993
+ <div part="navigation" class="navigation" ?hidden="${!hasSlotted(this, 'navigation')}">
994
+ <slot name="navigation"></slot>
995
+ </div>
996
+ `;
997
+ }
998
+
999
+ /**
1000
+ * The edge of a column the user drags: an `el-splitter` at the side that faces the content.
1001
+ * Only where the page asks for it, the column is there, and the script runs. Where the
1002
+ * navigation is a drawer, it has no edge.
1003
+ * @private
1004
+ * @param {'navigation'|'aside'} region
1005
+ */
1006
+ edgeTemplate(region) {
1007
+ if (!this._started || !this._resizable().includes(region) || !hasSlotted(this, region)) return '';
1008
+ if (region === 'navigation' && this._inDrawer) return '';
1009
+
1010
+ return html`
1011
+ <el-splitter
1012
+ part="${region}-splitter"
1013
+ class="edge edge--${region}"
1014
+ data-region="${region}"
1015
+ placement="${region === 'aside' ? 'start' : 'end'}"
1016
+ label="${region === 'aside' ? this.asideLabel : this.navigationLabel}"
1017
+ ></el-splitter>
1018
+ `;
1019
+ }
1020
+
1021
+ template() {
1022
+ const id = this._content()?.id;
1023
+ // The stylesheet reads the step from the frame, not from the host: a value it does not
1024
+ // know is the default here, and a server writes it as the browser does.
1025
+ const step = STEPS.includes(this.wideFrom) ? this.wideFrom : DEFAULT_STEP;
1026
+ // The widths the user has set, or the page has kept: the stylesheet reads them from the
1027
+ // frame, so a server-rendered frame has them before the script has run.
1028
+ const sizes = [
1029
+ ['navigation', this.navigationSize],
1030
+ ['aside', this.asideSize],
1031
+ ]
1032
+ .filter(([, size]) => Number(size) > 0)
1033
+ .map(([region, size]) => `--_el-app-frame-${region}-size: ${Math.round(Number(size))}px;`)
1034
+ .join(' ');
1035
+
1036
+ // The link lies in a landmark of the frame: a tool that checks a page finds the content
1037
+ // outside of one otherwise, and it cannot see that this is a skip link, which may stand
1038
+ // alone. It knows one by its place in front of the first link that leads elsewhere, and a
1039
+ // link in a shadow root is in front of nothing in the document.
1040
+ return html`
1041
+ <nav part="skip-landmark" class="skip-landmark" aria-label="${this.skipLandmarkLabel}">
1042
+ <a part="skip-link" class="skip" href="#${id || ''}">${this.skipLabel}</a>
1043
+ </nav>
1044
+ <div
1045
+ part="base"
1046
+ ref="base"
1047
+ class="frame ${hasSlotted(this, 'header') ? 'frame--header' : ''} ${
1048
+ hasSlotted(this, 'footer') ? 'frame--footer' : ''
1049
+ } ${hasSlotted(this, 'navigation') ? 'frame--navigation' : ''} ${
1050
+ hasSlotted(this, 'aside') ? 'frame--aside' : ''
1051
+ }"
1052
+ data-wide-from="${step}"
1053
+ data-narrow-only="${this._regionsOf(this.narrowOnly).join(' ')}"
1054
+ data-wide-only="${this._regionsOf(this.wideOnly).join(' ')}"
1055
+ data-narrow-navigation="${this.narrowNavigation === 'bar' ? 'bar' : 'drawer'}"
1056
+ data-resizable="${this._resizable().join(' ')}"
1057
+ style="${sizes || null}"
1058
+ >
1059
+ <div part="header" class="header" ?hidden="${!hasSlotted(this, 'header')}">
1060
+ <slot name="header"></slot>
1061
+ </div>
1062
+ ${this.navigationTemplate()} ${this.edgeTemplate('navigation')}
1063
+ <div part="body" ref="body" class="body">
1064
+ <div part="content" ref="content" class="content"><slot></slot></div>
1065
+ ${this.edgeTemplate('aside')}
1066
+ <div part="aside" class="aside" ?hidden="${!hasSlotted(this, 'aside')}">
1067
+ <slot name="aside"></slot>
1068
+ </div>
1069
+ </div>
1070
+ <div part="footer" class="footer" ?hidden="${!hasSlotted(this, 'footer')}">
1071
+ <slot name="footer"></slot>
1072
+ </div>
1073
+ </div>
1074
+ `;
1075
+ }
1076
+ }
1077
+
1078
+ export function define() {
1079
+ // The drawer the navigation is in where the frame is narrow, and the edges of its columns.
1080
+ defineDrawer();
1081
+ defineSplitter();
1082
+ defineElement('el-app-frame', AppFrame);
1083
+ }
1084
+
1085
+ export { Events };