@yaks/ui 0.0.0-stage → 0.2.36

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 (776) hide show
  1. package/Address.css +9 -0
  2. package/Address.js +32 -0
  3. package/Address.js.map +1 -0
  4. package/Address.ts +35 -0
  5. package/Annotated.css +17 -0
  6. package/Annotated.js +27 -0
  7. package/Annotated.js.map +1 -0
  8. package/Annotated.ts +32 -0
  9. package/AppShell.css +133 -0
  10. package/AppShell.js +90 -0
  11. package/AppShell.js.map +1 -0
  12. package/AppShell.ts +75 -0
  13. package/At.css +16 -0
  14. package/At.js +28 -0
  15. package/At.js.map +1 -0
  16. package/At.ts +37 -0
  17. package/Attachments.css +110 -0
  18. package/Attachments.js +119 -0
  19. package/Attachments.js.map +1 -0
  20. package/Attachments.ts +158 -0
  21. package/Badge.css +41 -0
  22. package/Badge.js +49 -0
  23. package/Badge.js.map +1 -0
  24. package/Badge.ts +38 -0
  25. package/Body.css +61 -0
  26. package/Body.js +103 -0
  27. package/Body.js.map +1 -0
  28. package/Body.ts +144 -0
  29. package/Button.css +121 -0
  30. package/Button.js +161 -0
  31. package/Button.js.map +1 -0
  32. package/Button.ts +92 -0
  33. package/Card.css +173 -0
  34. package/Card.js +165 -0
  35. package/Card.js.map +1 -0
  36. package/Card.ts +185 -0
  37. package/Cards.css +16 -0
  38. package/Cards.js +36 -0
  39. package/Cards.js.map +1 -0
  40. package/Cards.ts +64 -0
  41. package/Catalog.css +53 -0
  42. package/Catalog.js +55 -0
  43. package/Catalog.js.map +1 -0
  44. package/Catalog.ts +77 -0
  45. package/Chart.css +55 -0
  46. package/Chart.js +54 -0
  47. package/Chart.js.map +1 -0
  48. package/Chart.ts +62 -0
  49. package/Check.css +27 -0
  50. package/Check.js +77 -0
  51. package/Check.js.map +1 -0
  52. package/Check.ts +109 -0
  53. package/Chip.css +64 -0
  54. package/Chip.js +100 -0
  55. package/Chip.js.map +1 -0
  56. package/Chip.ts +66 -0
  57. package/Chips.css +10 -0
  58. package/Chips.js +41 -0
  59. package/Chips.js.map +1 -0
  60. package/Chips.ts +49 -0
  61. package/Choices.css +59 -0
  62. package/Choices.js +56 -0
  63. package/Choices.js.map +1 -0
  64. package/Choices.ts +73 -0
  65. package/Combobox.js +115 -0
  66. package/Combobox.js.map +1 -0
  67. package/Combobox.ts +230 -0
  68. package/Composer.css +247 -0
  69. package/Composer.js +222 -0
  70. package/Composer.js.map +1 -0
  71. package/Composer.ts +249 -0
  72. package/Contents.css +87 -0
  73. package/Contents.js +85 -0
  74. package/Contents.js.map +1 -0
  75. package/Contents.ts +117 -0
  76. package/Copy.css +28 -0
  77. package/Copy.js +62 -0
  78. package/Copy.js.map +1 -0
  79. package/Copy.ts +76 -0
  80. package/Doc.css +29 -0
  81. package/Doc.js +46 -0
  82. package/Doc.js.map +1 -0
  83. package/Doc.ts +64 -0
  84. package/Dock.css +157 -0
  85. package/Dock.js +229 -0
  86. package/Dock.js.map +1 -0
  87. package/Dock.ts +234 -0
  88. package/Dot.css +132 -0
  89. package/Dot.js +91 -0
  90. package/Dot.js.map +1 -0
  91. package/Dot.ts +72 -0
  92. package/Drop.css +133 -0
  93. package/Drop.js +148 -0
  94. package/Drop.js.map +1 -0
  95. package/Drop.ts +162 -0
  96. package/Edit.css +32 -0
  97. package/Edit.js +77 -0
  98. package/Edit.js.map +1 -0
  99. package/Edit.ts +72 -0
  100. package/Empty.css +32 -0
  101. package/Empty.js +45 -0
  102. package/Empty.js.map +1 -0
  103. package/Empty.ts +61 -0
  104. package/ErrorNotice.css +107 -0
  105. package/ErrorNotice.js +127 -0
  106. package/ErrorNotice.js.map +1 -0
  107. package/ErrorNotice.ts +133 -0
  108. package/Field.css +42 -0
  109. package/Field.js +186 -0
  110. package/Field.js.map +1 -0
  111. package/Field.ts +251 -0
  112. package/Form.css +95 -0
  113. package/Form.js +158 -0
  114. package/Form.js.map +1 -0
  115. package/Form.ts +212 -0
  116. package/Gallery.css +42 -0
  117. package/Gallery.js +57 -0
  118. package/Gallery.js.map +1 -0
  119. package/Gallery.ts +89 -0
  120. package/Group.css +8 -0
  121. package/Group.js +25 -0
  122. package/Group.js.map +1 -0
  123. package/Group.ts +40 -0
  124. package/Head.css +108 -0
  125. package/Head.js +124 -0
  126. package/Head.js.map +1 -0
  127. package/Head.ts +161 -0
  128. package/Icon.css +14 -0
  129. package/Icon.js +79 -0
  130. package/Icon.js.map +1 -0
  131. package/Icon.ts +78 -0
  132. package/IconButton.css +32 -0
  133. package/IconButton.js +74 -0
  134. package/IconButton.js.map +1 -0
  135. package/IconButton.ts +55 -0
  136. package/Id.css +29 -0
  137. package/Id.js +42 -0
  138. package/Id.js.map +1 -0
  139. package/Id.ts +31 -0
  140. package/Identity.css +122 -0
  141. package/Identity.js +88 -0
  142. package/Identity.js.map +1 -0
  143. package/Identity.ts +100 -0
  144. package/Index.css +68 -0
  145. package/Index.js +66 -0
  146. package/Index.js.map +1 -0
  147. package/Index.ts +63 -0
  148. package/LICENSE +202 -0
  149. package/Layer.css +82 -0
  150. package/Layer.js +86 -0
  151. package/Layer.js.map +1 -0
  152. package/Layer.ts +85 -0
  153. package/Lightbox.css +86 -0
  154. package/Lightbox.js +69 -0
  155. package/Lightbox.js.map +1 -0
  156. package/Lightbox.ts +79 -0
  157. package/Loading.css +22 -0
  158. package/Loading.js +75 -0
  159. package/Loading.js.map +1 -0
  160. package/Loading.ts +87 -0
  161. package/Logo.css +32 -0
  162. package/Logo.js +69 -0
  163. package/Logo.js.map +1 -0
  164. package/Logo.ts +81 -0
  165. package/Match.css +7 -0
  166. package/Match.js +51 -0
  167. package/Match.js.map +1 -0
  168. package/Match.ts +53 -0
  169. package/Menu.css +202 -0
  170. package/Menu.js +197 -0
  171. package/Menu.js.map +1 -0
  172. package/Menu.ts +233 -0
  173. package/Meter.css +49 -0
  174. package/Meter.js +149 -0
  175. package/Meter.js.map +1 -0
  176. package/Meter.ts +126 -0
  177. package/Metrics.css +43 -0
  178. package/Metrics.js +72 -0
  179. package/Metrics.js.map +1 -0
  180. package/Metrics.ts +66 -0
  181. package/Modal.css +94 -0
  182. package/Modal.js +114 -0
  183. package/Modal.js.map +1 -0
  184. package/Modal.ts +149 -0
  185. package/ModalDOM.css +23 -0
  186. package/More.css +135 -0
  187. package/More.js +135 -0
  188. package/More.js.map +1 -0
  189. package/More.ts +157 -0
  190. package/Notes.css +51 -0
  191. package/Notes.js +64 -0
  192. package/Notes.js.map +1 -0
  193. package/Notes.ts +95 -0
  194. package/Notice.css +30 -0
  195. package/Notice.js +50 -0
  196. package/Notice.js.map +1 -0
  197. package/Notice.ts +40 -0
  198. package/Overlay.css +8 -0
  199. package/Overlay.js +25 -0
  200. package/Overlay.js.map +1 -0
  201. package/Overlay.ts +33 -0
  202. package/Pager.css +33 -0
  203. package/Pager.js +44 -0
  204. package/Pager.js.map +1 -0
  205. package/Pager.ts +56 -0
  206. package/Pairs.css +50 -0
  207. package/Pairs.js +45 -0
  208. package/Pairs.js.map +1 -0
  209. package/Pairs.ts +88 -0
  210. package/Palette.css +77 -0
  211. package/Palette.js +41 -0
  212. package/Palette.js.map +1 -0
  213. package/Palette.ts +44 -0
  214. package/Panes.css +68 -0
  215. package/Panes.js +100 -0
  216. package/Panes.js.map +1 -0
  217. package/Panes.ts +97 -0
  218. package/Passage.css +58 -0
  219. package/Passage.js +80 -0
  220. package/Passage.js.map +1 -0
  221. package/Passage.ts +112 -0
  222. package/Peek.css +75 -0
  223. package/Peek.js +51 -0
  224. package/Peek.js.map +1 -0
  225. package/Peek.ts +74 -0
  226. package/Pills.css +127 -0
  227. package/Pills.js +119 -0
  228. package/Pills.js.map +1 -0
  229. package/Pills.ts +131 -0
  230. package/Plan.css +73 -0
  231. package/Plan.js +62 -0
  232. package/Plan.js.map +1 -0
  233. package/Plan.ts +80 -0
  234. package/Popover.css +47 -0
  235. package/Popover.js +62 -0
  236. package/Popover.js.map +1 -0
  237. package/Popover.ts +80 -0
  238. package/Preview.css +89 -0
  239. package/Preview.js +84 -0
  240. package/Preview.js.map +1 -0
  241. package/Preview.ts +98 -0
  242. package/Prop.css +117 -0
  243. package/Prop.js +94 -0
  244. package/Prop.js.map +1 -0
  245. package/Prop.ts +91 -0
  246. package/Quote.css +55 -0
  247. package/Quote.js +79 -0
  248. package/Quote.js.map +1 -0
  249. package/Quote.ts +85 -0
  250. package/README.md +596 -2
  251. package/Report.css +76 -0
  252. package/Report.js +105 -0
  253. package/Report.js.map +1 -0
  254. package/Report.ts +118 -0
  255. package/Rows.css +289 -0
  256. package/Rows.js +265 -0
  257. package/Rows.js.map +1 -0
  258. package/Rows.ts +337 -0
  259. package/Save.css +112 -0
  260. package/Save.js +100 -0
  261. package/Save.js.map +1 -0
  262. package/Save.ts +102 -0
  263. package/Section.css +52 -0
  264. package/Section.js +73 -0
  265. package/Section.js.map +1 -0
  266. package/Section.ts +86 -0
  267. package/Select.css +140 -0
  268. package/Select.js +208 -0
  269. package/Select.js.map +1 -0
  270. package/Select.ts +238 -0
  271. package/Shell.css +292 -0
  272. package/Shell.js +197 -0
  273. package/Shell.js.map +1 -0
  274. package/Shell.ts +193 -0
  275. package/SideNav.css +105 -0
  276. package/SideNav.js +197 -0
  277. package/SideNav.js.map +1 -0
  278. package/SideNav.ts +189 -0
  279. package/Skip.css +11 -0
  280. package/Skip.js +18 -0
  281. package/Skip.js.map +1 -0
  282. package/Skip.ts +16 -0
  283. package/Spark.css +14 -0
  284. package/Spark.js +84 -0
  285. package/Spark.js.map +1 -0
  286. package/Spark.ts +67 -0
  287. package/Stack.css +13 -0
  288. package/Stack.js +20 -0
  289. package/Stack.js.map +1 -0
  290. package/Stack.ts +31 -0
  291. package/Stamp.css +11 -0
  292. package/Stamp.js +40 -0
  293. package/Stamp.js.map +1 -0
  294. package/Stamp.ts +62 -0
  295. package/State.css +10 -0
  296. package/State.js +38 -0
  297. package/State.js.map +1 -0
  298. package/State.ts +38 -0
  299. package/Surface.css +139 -0
  300. package/Surface.js +79 -0
  301. package/Surface.js.map +1 -0
  302. package/Surface.ts +55 -0
  303. package/Table.css +147 -0
  304. package/Table.js +289 -0
  305. package/Table.js.map +1 -0
  306. package/Table.ts +343 -0
  307. package/Tabs.css +100 -0
  308. package/Tabs.js +108 -0
  309. package/Tabs.js.map +1 -0
  310. package/Tabs.ts +111 -0
  311. package/Tile.css +164 -0
  312. package/Tile.js +211 -0
  313. package/Tile.js.map +1 -0
  314. package/Tile.ts +174 -0
  315. package/Time.css +5 -0
  316. package/Time.js +80 -0
  317. package/Time.js.map +1 -0
  318. package/Time.ts +105 -0
  319. package/Timeline.css +35 -0
  320. package/Timeline.js +55 -0
  321. package/Timeline.js.map +1 -0
  322. package/Timeline.ts +84 -0
  323. package/Tip.css +18 -0
  324. package/Tip.js +24 -0
  325. package/Tip.js.map +1 -0
  326. package/Tip.ts +29 -0
  327. package/Toast.css +25 -0
  328. package/Toast.js +32 -0
  329. package/Toast.js.map +1 -0
  330. package/Toast.ts +34 -0
  331. package/Toolbar.css +66 -0
  332. package/Toolbar.js +58 -0
  333. package/Toolbar.js.map +1 -0
  334. package/Toolbar.ts +68 -0
  335. package/Transcript.css +221 -0
  336. package/Transcript.js +254 -0
  337. package/Transcript.js.map +1 -0
  338. package/Transcript.ts +296 -0
  339. package/Turns.css +49 -0
  340. package/Turns.js +58 -0
  341. package/Turns.js.map +1 -0
  342. package/Turns.ts +67 -0
  343. package/Value.css +33 -0
  344. package/Value.js +60 -0
  345. package/Value.js.map +1 -0
  346. package/Value.ts +48 -0
  347. package/_dist/Address.d.ts +3 -0
  348. package/_dist/Address.d.ts.map +1 -0
  349. package/_dist/Annotated.d.ts +3 -0
  350. package/_dist/Annotated.d.ts.map +1 -0
  351. package/_dist/AppShell.d.ts +3 -0
  352. package/_dist/AppShell.d.ts.map +1 -0
  353. package/_dist/At.d.ts +14 -0
  354. package/_dist/At.d.ts.map +1 -0
  355. package/_dist/Attachments.d.ts +6 -0
  356. package/_dist/Attachments.d.ts.map +1 -0
  357. package/_dist/Badge.d.ts +19 -0
  358. package/_dist/Badge.d.ts.map +1 -0
  359. package/_dist/Body.d.ts +5 -0
  360. package/_dist/Body.d.ts.map +1 -0
  361. package/_dist/Button.d.ts +18 -0
  362. package/_dist/Button.d.ts.map +1 -0
  363. package/_dist/Card.d.ts +28 -0
  364. package/_dist/Card.d.ts.map +1 -0
  365. package/_dist/Cards.d.ts +15 -0
  366. package/_dist/Cards.d.ts.map +1 -0
  367. package/_dist/Catalog.d.ts +3 -0
  368. package/_dist/Catalog.d.ts.map +1 -0
  369. package/_dist/Chart.d.ts +5 -0
  370. package/_dist/Chart.d.ts.map +1 -0
  371. package/_dist/Check.d.ts +17 -0
  372. package/_dist/Check.d.ts.map +1 -0
  373. package/_dist/Chip.d.ts +22 -0
  374. package/_dist/Chip.d.ts.map +1 -0
  375. package/_dist/Chips.d.ts +15 -0
  376. package/_dist/Chips.d.ts.map +1 -0
  377. package/_dist/Choices.d.ts +3 -0
  378. package/_dist/Choices.d.ts.map +1 -0
  379. package/_dist/Combobox.d.ts +55 -0
  380. package/_dist/Combobox.d.ts.map +1 -0
  381. package/_dist/Composer.d.ts +15 -0
  382. package/_dist/Composer.d.ts.map +1 -0
  383. package/_dist/Contents.d.ts +20 -0
  384. package/_dist/Contents.d.ts.map +1 -0
  385. package/_dist/Copy.d.ts +24 -0
  386. package/_dist/Copy.d.ts.map +1 -0
  387. package/_dist/Doc.d.ts +3 -0
  388. package/_dist/Doc.d.ts.map +1 -0
  389. package/_dist/Dock.d.ts +29 -0
  390. package/_dist/Dock.d.ts.map +1 -0
  391. package/_dist/Dot.d.ts +16 -0
  392. package/_dist/Dot.d.ts.map +1 -0
  393. package/_dist/Drop.d.ts +27 -0
  394. package/_dist/Drop.d.ts.map +1 -0
  395. package/_dist/Edit.d.ts +3 -0
  396. package/_dist/Edit.d.ts.map +1 -0
  397. package/_dist/Empty.d.ts +16 -0
  398. package/_dist/Empty.d.ts.map +1 -0
  399. package/_dist/ErrorNotice.d.ts +16 -0
  400. package/_dist/ErrorNotice.d.ts.map +1 -0
  401. package/_dist/Field.d.ts +53 -0
  402. package/_dist/Field.d.ts.map +1 -0
  403. package/_dist/Form.d.ts +44 -0
  404. package/_dist/Form.d.ts.map +1 -0
  405. package/_dist/Gallery.d.ts +3 -0
  406. package/_dist/Gallery.d.ts.map +1 -0
  407. package/_dist/Group.d.ts +14 -0
  408. package/_dist/Group.d.ts.map +1 -0
  409. package/_dist/Head.d.ts +13 -0
  410. package/_dist/Head.d.ts.map +1 -0
  411. package/_dist/Icon.d.ts +23 -0
  412. package/_dist/Icon.d.ts.map +1 -0
  413. package/_dist/IconButton.d.ts +8 -0
  414. package/_dist/IconButton.d.ts.map +1 -0
  415. package/_dist/Id.d.ts +3 -0
  416. package/_dist/Id.d.ts.map +1 -0
  417. package/_dist/Identity.d.ts +15 -0
  418. package/_dist/Identity.d.ts.map +1 -0
  419. package/_dist/Index.d.ts +3 -0
  420. package/_dist/Index.d.ts.map +1 -0
  421. package/_dist/Layer.d.ts +8 -0
  422. package/_dist/Layer.d.ts.map +1 -0
  423. package/_dist/Lightbox.d.ts +27 -0
  424. package/_dist/Lightbox.d.ts.map +1 -0
  425. package/_dist/Loading.d.ts +24 -0
  426. package/_dist/Loading.d.ts.map +1 -0
  427. package/_dist/Logo.d.ts +26 -0
  428. package/_dist/Logo.d.ts.map +1 -0
  429. package/_dist/Match.d.ts +5 -0
  430. package/_dist/Match.d.ts.map +1 -0
  431. package/_dist/Menu.d.ts +23 -0
  432. package/_dist/Menu.d.ts.map +1 -0
  433. package/_dist/Meter.d.ts +10 -0
  434. package/_dist/Meter.d.ts.map +1 -0
  435. package/_dist/Metrics.d.ts +3 -0
  436. package/_dist/Metrics.d.ts.map +1 -0
  437. package/_dist/Modal.d.ts +32 -0
  438. package/_dist/Modal.d.ts.map +1 -0
  439. package/_dist/More.d.ts +29 -0
  440. package/_dist/More.d.ts.map +1 -0
  441. package/_dist/Notes.d.ts +3 -0
  442. package/_dist/Notes.d.ts.map +1 -0
  443. package/_dist/Notice.d.ts +15 -0
  444. package/_dist/Notice.d.ts.map +1 -0
  445. package/_dist/Overlay.d.ts +3 -0
  446. package/_dist/Overlay.d.ts.map +1 -0
  447. package/_dist/Pager.d.ts +3 -0
  448. package/_dist/Pager.d.ts.map +1 -0
  449. package/_dist/Pairs.d.ts +3 -0
  450. package/_dist/Pairs.d.ts.map +1 -0
  451. package/_dist/Palette.d.ts +3 -0
  452. package/_dist/Palette.d.ts.map +1 -0
  453. package/_dist/Panes.d.ts +3 -0
  454. package/_dist/Panes.d.ts.map +1 -0
  455. package/_dist/Passage.d.ts +3 -0
  456. package/_dist/Passage.d.ts.map +1 -0
  457. package/_dist/Peek.d.ts +3 -0
  458. package/_dist/Peek.d.ts.map +1 -0
  459. package/_dist/Pills.d.ts +3 -0
  460. package/_dist/Pills.d.ts.map +1 -0
  461. package/_dist/Plan.d.ts +4 -0
  462. package/_dist/Plan.d.ts.map +1 -0
  463. package/_dist/Popover.d.ts +3 -0
  464. package/_dist/Popover.d.ts.map +1 -0
  465. package/_dist/Preview.d.ts +8 -0
  466. package/_dist/Preview.d.ts.map +1 -0
  467. package/_dist/Prop.d.ts +7 -0
  468. package/_dist/Prop.d.ts.map +1 -0
  469. package/_dist/Quote.d.ts +3 -0
  470. package/_dist/Quote.d.ts.map +1 -0
  471. package/_dist/Report.d.ts +8 -0
  472. package/_dist/Report.d.ts.map +1 -0
  473. package/_dist/Rows.d.ts +36 -0
  474. package/_dist/Rows.d.ts.map +1 -0
  475. package/_dist/Save.d.ts +4 -0
  476. package/_dist/Save.d.ts.map +1 -0
  477. package/_dist/Section.d.ts +3 -0
  478. package/_dist/Section.d.ts.map +1 -0
  479. package/_dist/Select.d.ts +29 -0
  480. package/_dist/Select.d.ts.map +1 -0
  481. package/_dist/Shell.d.ts +3 -0
  482. package/_dist/Shell.d.ts.map +1 -0
  483. package/_dist/SideNav.d.ts +31 -0
  484. package/_dist/SideNav.d.ts.map +1 -0
  485. package/_dist/Skip.d.ts +3 -0
  486. package/_dist/Skip.d.ts.map +1 -0
  487. package/_dist/Spark.d.ts +9 -0
  488. package/_dist/Spark.d.ts.map +1 -0
  489. package/_dist/Stack.d.ts +11 -0
  490. package/_dist/Stack.d.ts.map +1 -0
  491. package/_dist/Stamp.d.ts +3 -0
  492. package/_dist/Stamp.d.ts.map +1 -0
  493. package/_dist/State.d.ts +16 -0
  494. package/_dist/State.d.ts.map +1 -0
  495. package/_dist/Surface.d.ts +7 -0
  496. package/_dist/Surface.d.ts.map +1 -0
  497. package/_dist/Table.d.ts +10 -0
  498. package/_dist/Table.d.ts.map +1 -0
  499. package/_dist/Tabs.d.ts +30 -0
  500. package/_dist/Tabs.d.ts.map +1 -0
  501. package/_dist/Tile.d.ts +3 -0
  502. package/_dist/Tile.d.ts.map +1 -0
  503. package/_dist/Time.d.ts +24 -0
  504. package/_dist/Time.d.ts.map +1 -0
  505. package/_dist/Timeline.d.ts +3 -0
  506. package/_dist/Timeline.d.ts.map +1 -0
  507. package/_dist/Tip.d.ts +3 -0
  508. package/_dist/Tip.d.ts.map +1 -0
  509. package/_dist/Toast.d.ts +5 -0
  510. package/_dist/Toast.d.ts.map +1 -0
  511. package/_dist/Toolbar.d.ts +3 -0
  512. package/_dist/Toolbar.d.ts.map +1 -0
  513. package/_dist/Transcript.d.ts +35 -0
  514. package/_dist/Transcript.d.ts.map +1 -0
  515. package/_dist/Turns.d.ts +3 -0
  516. package/_dist/Turns.d.ts.map +1 -0
  517. package/_dist/Value.d.ts +3 -0
  518. package/_dist/Value.d.ts.map +1 -0
  519. package/_dist/ahead.d.ts +41 -0
  520. package/_dist/ahead.d.ts.map +1 -0
  521. package/_dist/chart-marks.d.ts +75 -0
  522. package/_dist/chart-marks.d.ts.map +1 -0
  523. package/_dist/clock.d.ts +4 -0
  524. package/_dist/clock.d.ts.map +1 -0
  525. package/_dist/contents-browser.d.ts +29 -0
  526. package/_dist/contents-browser.d.ts.map +1 -0
  527. package/_dist/contributions.d.ts +5 -0
  528. package/_dist/contributions.d.ts.map +1 -0
  529. package/_dist/copy-browser.d.ts +4 -0
  530. package/_dist/copy-browser.d.ts.map +1 -0
  531. package/_dist/el.d.ts +58 -0
  532. package/_dist/el.d.ts.map +1 -0
  533. package/_dist/everforest.d.ts +8 -0
  534. package/_dist/everforest.d.ts.map +1 -0
  535. package/_dist/float.d.ts +55 -0
  536. package/_dist/float.d.ts.map +1 -0
  537. package/_dist/gouache.d.ts +9 -0
  538. package/_dist/gouache.d.ts.map +1 -0
  539. package/_dist/guide.d.ts +38 -0
  540. package/_dist/guide.d.ts.map +1 -0
  541. package/_dist/halved.d.ts +3 -0
  542. package/_dist/halved.d.ts.map +1 -0
  543. package/_dist/history.d.ts +15 -0
  544. package/_dist/history.d.ts.map +1 -0
  545. package/_dist/interaction.d.ts +15 -0
  546. package/_dist/interaction.d.ts.map +1 -0
  547. package/_dist/kit.d.ts +30 -0
  548. package/_dist/kit.d.ts.map +1 -0
  549. package/_dist/ledger.d.ts +3 -0
  550. package/_dist/ledger.d.ts.map +1 -0
  551. package/_dist/linen.d.ts +8 -0
  552. package/_dist/linen.d.ts.map +1 -0
  553. package/_dist/menus-browser.d.ts +2 -0
  554. package/_dist/menus-browser.d.ts.map +1 -0
  555. package/_dist/menus.d.ts +6 -0
  556. package/_dist/menus.d.ts.map +1 -0
  557. package/_dist/mod.d.ts +47 -0
  558. package/_dist/mod.d.ts.map +1 -0
  559. package/_dist/modal-browser.d.ts +2 -0
  560. package/_dist/modal-browser.d.ts.map +1 -0
  561. package/_dist/modal-head.d.ts +43 -0
  562. package/_dist/modal-head.d.ts.map +1 -0
  563. package/_dist/navigate.d.ts +170 -0
  564. package/_dist/navigate.d.ts.map +1 -0
  565. package/_dist/overlays.d.ts +16 -0
  566. package/_dist/overlays.d.ts.map +1 -0
  567. package/_dist/palette-browser.d.ts +3 -0
  568. package/_dist/palette-browser.d.ts.map +1 -0
  569. package/_dist/panes-browser.d.ts +4 -0
  570. package/_dist/panes-browser.d.ts.map +1 -0
  571. package/_dist/paper.d.ts +6 -0
  572. package/_dist/paper.d.ts.map +1 -0
  573. package/_dist/parts.d.ts +102 -0
  574. package/_dist/parts.d.ts.map +1 -0
  575. package/_dist/pencil.d.ts +6 -0
  576. package/_dist/pencil.d.ts.map +1 -0
  577. package/_dist/placement.d.ts +12 -0
  578. package/_dist/placement.d.ts.map +1 -0
  579. package/_dist/relative.d.ts +41 -0
  580. package/_dist/relative.d.ts.map +1 -0
  581. package/_dist/rosepine.d.ts +8 -0
  582. package/_dist/rosepine.d.ts.map +1 -0
  583. package/_dist/routes.d.ts +20 -0
  584. package/_dist/routes.d.ts.map +1 -0
  585. package/_dist/sheet.d.ts +44 -0
  586. package/_dist/sheet.d.ts.map +1 -0
  587. package/_dist/slide.d.ts +4 -0
  588. package/_dist/slide.d.ts.map +1 -0
  589. package/_dist/stock.d.ts +21 -0
  590. package/_dist/stock.d.ts.map +1 -0
  591. package/_dist/store.d.ts +2 -0
  592. package/_dist/store.d.ts.map +1 -0
  593. package/_dist/theme.d.ts +102 -0
  594. package/_dist/theme.d.ts.map +1 -0
  595. package/_dist/ui.d.ts +2 -0
  596. package/_dist/ui.d.ts.map +1 -0
  597. package/_dist/video-cover.d.ts +3 -0
  598. package/_dist/video-cover.d.ts.map +1 -0
  599. package/_dist/viewport.d.ts +14 -0
  600. package/_dist/viewport.d.ts.map +1 -0
  601. package/_dist/wear.d.ts +5 -0
  602. package/_dist/wear.d.ts.map +1 -0
  603. package/ahead.js +81 -0
  604. package/ahead.js.map +1 -0
  605. package/ahead.ts +102 -0
  606. package/base.css +220 -0
  607. package/base.js +129 -0
  608. package/base.js.map +1 -0
  609. package/base.ts +127 -0
  610. package/chart-marks.js +156 -0
  611. package/chart-marks.js.map +1 -0
  612. package/chart-marks.ts +221 -0
  613. package/clock.js +41 -0
  614. package/clock.js.map +1 -0
  615. package/clock.ts +39 -0
  616. package/contents-browser.js +122 -0
  617. package/contents-browser.js.map +1 -0
  618. package/contents-browser.ts +135 -0
  619. package/contributions.js +28 -0
  620. package/contributions.js.map +1 -0
  621. package/contributions.ts +21 -0
  622. package/copy-browser.js +39 -0
  623. package/copy-browser.js.map +1 -0
  624. package/copy-browser.ts +44 -0
  625. package/deno.json +1 -0
  626. package/derived.css +64 -0
  627. package/el.js +176 -0
  628. package/el.js.map +1 -0
  629. package/el.ts +240 -0
  630. package/everforest.css +65 -0
  631. package/everforest.js +54 -0
  632. package/everforest.js.map +1 -0
  633. package/everforest.ts +52 -0
  634. package/float.js +182 -0
  635. package/float.js.map +1 -0
  636. package/float.ts +222 -0
  637. package/gouache.css +62 -0
  638. package/gouache.js +54 -0
  639. package/gouache.js.map +1 -0
  640. package/gouache.ts +52 -0
  641. package/guide.js +124 -0
  642. package/guide.js.map +1 -0
  643. package/guide.ts +222 -0
  644. package/halved.js +88 -0
  645. package/halved.js.map +1 -0
  646. package/halved.ts +102 -0
  647. package/history.js +11 -0
  648. package/history.js.map +1 -0
  649. package/history.ts +22 -0
  650. package/interaction.js +23 -0
  651. package/interaction.js.map +1 -0
  652. package/interaction.ts +43 -0
  653. package/kit.js +345 -0
  654. package/kit.js.map +1 -0
  655. package/kit.ts +408 -0
  656. package/ledger/Button.css +22 -0
  657. package/ledger/Head.css +72 -0
  658. package/ledger/Tabs.css +19 -0
  659. package/ledger/Tile.css +12 -0
  660. package/ledger.js +52 -0
  661. package/ledger.js.map +1 -0
  662. package/ledger.ts +34 -0
  663. package/linen.css +71 -0
  664. package/linen.js +54 -0
  665. package/linen.js.map +1 -0
  666. package/linen.ts +52 -0
  667. package/lucide.d.ts +4 -0
  668. package/menus-browser.js +72 -0
  669. package/menus-browser.js.map +1 -0
  670. package/menus-browser.ts +75 -0
  671. package/menus.js +84 -0
  672. package/menus.js.map +1 -0
  673. package/menus.ts +90 -0
  674. package/mod.js +46 -0
  675. package/mod.js.map +1 -0
  676. package/mod.ts +78 -0
  677. package/modal-browser.js +29 -0
  678. package/modal-browser.js.map +1 -0
  679. package/modal-browser.ts +31 -0
  680. package/modal-head.js +75 -0
  681. package/modal-head.js.map +1 -0
  682. package/modal-head.ts +81 -0
  683. package/navigate.js +934 -0
  684. package/navigate.js.map +1 -0
  685. package/navigate.ts +1177 -0
  686. package/overlays.js +177 -0
  687. package/overlays.js.map +1 -0
  688. package/overlays.ts +257 -0
  689. package/package.json +280 -4
  690. package/palette-browser.js +52 -0
  691. package/palette-browser.js.map +1 -0
  692. package/palette-browser.ts +54 -0
  693. package/panes-browser.js +40 -0
  694. package/panes-browser.js.map +1 -0
  695. package/panes-browser.ts +59 -0
  696. package/paper/base.css +28 -0
  697. package/paper/grain.css +18 -0
  698. package/paper.js +14 -0
  699. package/paper.js.map +1 -0
  700. package/paper.ts +16 -0
  701. package/parts.js +102 -0
  702. package/parts.js.map +1 -0
  703. package/parts.ts +117 -0
  704. package/pencil/Address.css +5 -0
  705. package/pencil/At.css +14 -0
  706. package/pencil/Body.css +10 -0
  707. package/pencil/Button.css +81 -0
  708. package/pencil/Card.css +175 -0
  709. package/pencil/Chart.css +31 -0
  710. package/pencil/Check.css +66 -0
  711. package/pencil/Chip.css +100 -0
  712. package/pencil/Chips.css +6 -0
  713. package/pencil/Copy.css +33 -0
  714. package/pencil/Drop.css +145 -0
  715. package/pencil/Empty.css +48 -0
  716. package/pencil/Field.css +42 -0
  717. package/pencil/Form.css +88 -0
  718. package/pencil/Loading.css +14 -0
  719. package/pencil/Menu.css +26 -0
  720. package/pencil/More.css +41 -0
  721. package/pencil/Report.css +11 -0
  722. package/pencil/Rows.css +48 -0
  723. package/pencil/SideNav.css +173 -0
  724. package/pencil/State.css +28 -0
  725. package/pencil/Surface.css +69 -0
  726. package/pencil/Tabs.css +137 -0
  727. package/pencil/base.css +19 -0
  728. package/pencil/paper.webp +0 -0
  729. package/pencil/pencil.svg +181 -0
  730. package/pencil.js +81 -0
  731. package/pencil.js.map +1 -0
  732. package/pencil.ts +34 -0
  733. package/placement.js +62 -0
  734. package/placement.js.map +1 -0
  735. package/placement.ts +93 -0
  736. package/relative.js +150 -0
  737. package/relative.js.map +1 -0
  738. package/relative.ts +186 -0
  739. package/resizes.js +23 -0
  740. package/resizes.js.map +1 -0
  741. package/resizes.ts +37 -0
  742. package/rosepine.css +59 -0
  743. package/rosepine.js +54 -0
  744. package/rosepine.js.map +1 -0
  745. package/rosepine.ts +52 -0
  746. package/routes.js +136 -0
  747. package/routes.js.map +1 -0
  748. package/routes.ts +190 -0
  749. package/sheet.js +7 -0
  750. package/sheet.js.map +1 -0
  751. package/sheet.ts +72 -0
  752. package/slide.js +37 -0
  753. package/slide.js.map +1 -0
  754. package/slide.ts +41 -0
  755. package/stock.js +38 -0
  756. package/stock.js.map +1 -0
  757. package/stock.ts +54 -0
  758. package/store.js +6 -0
  759. package/store.js.map +1 -0
  760. package/store.ts +14 -0
  761. package/theme.js +21 -0
  762. package/theme.js.map +1 -0
  763. package/theme.ts +159 -0
  764. package/ui.js +2 -0
  765. package/ui.js.map +1 -0
  766. package/ui.ts +2 -0
  767. package/video-cover.js +55 -0
  768. package/video-cover.js.map +1 -0
  769. package/video-cover.ts +72 -0
  770. package/viewport.js +56 -0
  771. package/viewport.js.map +1 -0
  772. package/viewport.ts +61 -0
  773. package/wear-build.ts +12 -0
  774. package/wear.js +40 -0
  775. package/wear.js.map +1 -0
  776. package/wear.ts +65 -0
package/navigate.ts ADDED
@@ -0,0 +1,1177 @@
1
+ /**
2
+ * Moving between a site's server-drawn pages without loading a new document.
3
+ * A link to a page of the same origin is fetched, and the page it answers is
4
+ * laid over the one on screen (`morph`): a node that stands in both pages
5
+ * keeps its place, its listeners and its loaded image, and only what differs
6
+ * is changed. The sidebar and the header of a shell stay as they were, and an
7
+ * image beside a link never loads again.
8
+ *
9
+ * A page takes part by loading the navigator in a script marked
10
+ * `data-navigate` (`TAKES`, `start`); a link to a page that
11
+ * does not load it, a failed fetch or an answer that is not HTML is followed
12
+ * as the browser would follow it, and so is one whose swap fails.
13
+ *
14
+ * What scripts do across a swap:
15
+ *
16
+ * - A script with a `src` runs once in the document's life, the first time a
17
+ * page names it. One that binds elements as it loads binds what each swap
18
+ * brings on `yak-page` too, once an element (`arrived`), and once
19
+ * across the copies of it pages from different releases name (`hold`).
20
+ * - A script written into the page is the page's own: it runs after every
21
+ * swap that lands on its page. Before each swap the document hears
22
+ * `yak-leave`, and such a script takes back there what it set going (a
23
+ * listener on the window, a timer), most simply by adding its listeners
24
+ * with a signal it aborts then (`leaving`).
25
+ * - A script marked `data-stays` holds its page (a socket, a mounted app)
26
+ * and cannot be taken back: a page holding one is left by loading the next.
27
+ * It still draws in place what it draws itself (`DRAW`), since it is not
28
+ * left.
29
+ *
30
+ * A region a script draws for the whole tab rather than for one page (an
31
+ * overlay over every page) is marked `data-kept` (`KEPT`): where the next page
32
+ * has it too, by its id, a swap leaves it as it stands, open, typed in and
33
+ * drawn, and its script goes on drawing it.
34
+ *
35
+ * @module
36
+ */
37
+
38
+ import { slideIn } from './slide.js'
39
+ import { type Clock, system } from '@yaks/fp'
40
+ import { rayOf } from '@yaks/trace/browser'
41
+ import type { HistoryPort } from './history.ts'
42
+ import { type Result, result } from './interaction.js'
43
+ import { AHEAD, lookingAhead, WARM, warmer } from './ahead.js'
44
+
45
+ export { AHEAD, lookingAhead, WARM }
46
+
47
+ /** What a swap did to the nodes on screen: those kept in place, those made
48
+ * from the new page, those taken away. */
49
+ export type Tally = { kept: number; made: number; dropped: number }
50
+
51
+ /** The mark on the script that loads the navigator: a page wearing it
52
+ * takes part. */
53
+ export let TAKES = 'data-navigate'
54
+ /** The mark on a region a script draws across pages, which a swap leaves
55
+ * as it is where the next page has it too. */
56
+ export let KEPT = 'data-kept'
57
+ /** Heard on the document before a swap, by the page it takes away. */
58
+ export let LEAVE = 'yak-leave'
59
+ /** Heard on the document after a swap, by the page it brought. */
60
+ export let PAGE = 'yak-page'
61
+
62
+ let ELEMENT = 1
63
+ let TEXT = 3
64
+ let COMMENT = 8
65
+
66
+ let el = (n: Node): Element | null =>
67
+ n.nodeType == ELEMENT ? n as Element : null
68
+
69
+ // What makes a node the same node in both pages, where something does: its
70
+ // id, its `data-key`, the address an image, script, video, sound, frame, link
71
+ // or anchor names. A video kept by its address goes on playing where the
72
+ // nodes before it changed.
73
+ let SOURCED = new Set(['img', 'script', 'video', 'audio', 'iframe'])
74
+ let keyOf = (n: Node): string | null => {
75
+ let e = el(n)
76
+ if (!e) return null
77
+ let tag = e.localName
78
+ if (e.id) return `${tag}#${e.id}`
79
+ let key = e.getAttribute('data-key')
80
+ if (key != null) return `${tag}[${key}]`
81
+ let at = SOURCED.has(tag)
82
+ ? e.getAttribute('src')
83
+ : tag == 'a' || tag == 'link'
84
+ ? e.getAttribute('href')
85
+ : null
86
+ return at ? `${tag} ${e.getAttribute('rel') ?? ''} ${at}` : null
87
+ }
88
+
89
+ let alike = (a: Node, b: Node) =>
90
+ a.nodeType == b.nodeType &&
91
+ (a.nodeType != ELEMENT ||
92
+ (a as Element).localName == (b as Element).localName)
93
+
94
+ let size = (n: Node): number => {
95
+ let count = 1
96
+ for (let c of n.childNodes) count += size(c)
97
+ return count
98
+ }
99
+
100
+ // A form control whose value the page sends: set as the property too, since
101
+ // the attribute alone no longer moves what a control shows once it is drawn.
102
+ let control = (a: Element, b: Element) => {
103
+ let input = a as HTMLInputElement
104
+ if (a.localName == 'input') {
105
+ let value = b.getAttribute('value')
106
+ if (value != a.getAttribute('value')) input.value = value ?? ''
107
+ let checked = b.hasAttribute('checked')
108
+ if (checked != a.hasAttribute('checked')) input.checked = checked
109
+ }
110
+ if (a.localName == 'option') {
111
+ let selected = b.hasAttribute('selected')
112
+ if (selected != a.hasAttribute('selected')) {
113
+ ;(a as HTMLOptionElement).selected = selected
114
+ }
115
+ }
116
+ if (a.localName == 'textarea' && a.textContent != b.textContent) {
117
+ ;(a as HTMLTextAreaElement).value = b.textContent ?? ''
118
+ }
119
+ }
120
+
121
+ let attributes = (a: Element, b: Element, o: Morphing) => {
122
+ control(a, b)
123
+ for (let { name } of [...a.attributes]) {
124
+ if (!b.hasAttribute(name) && !o.keeps?.(a, name)) a.removeAttribute(name)
125
+ }
126
+ for (let { name, value } of [...b.attributes]) {
127
+ if (a.getAttribute(name) != value) a.setAttribute(name, value)
128
+ }
129
+ }
130
+
131
+ /** Options for `morph`: `leave` names a node of the old page that stays where
132
+ * the new page has nothing for it (a stylesheet a script put in the head), and
133
+ * `keeps` an attribute of one that stays where the new page has no word on it
134
+ * (a fold the person opened, redrawn from rows). */
135
+ export type Morphing = {
136
+ leave?: (n: Node) => boolean
137
+ keeps?: (e: Element, name: string) => boolean
138
+ }
139
+
140
+ /** Make `was` the same as `next` in place, keeping every node of `was` that
141
+ * stands in `next` (by `keyOf`, else by its kind at its place), and answer
142
+ * what was kept, made and dropped. Nodes are made in `was`'s document. */
143
+ /// import { parseHTML } from 'linkedom'
144
+ /// let { document } = parseHTML('<ul><li id="a">A</li><li>B</li></ul>')
145
+ /// let next = parseHTML('<ul><li id="a">A</li><li>C</li></ul>').document
146
+ /// let a = document.getElementById('a')
147
+ /// morph(document.querySelector('ul'), next.querySelector('ul'))
148
+ /// document.querySelector('ul').outerHTML -> '<ul><li id="a">A</li><li>C</li></ul>'
149
+ /// document.getElementById('a') == a -> true
150
+ export let morph = (
151
+ was: Node,
152
+ next: Node,
153
+ o: Morphing = {},
154
+ tally: Tally = { kept: 0, made: 0, dropped: 0 },
155
+ ): Tally => {
156
+ if (was.nodeType == TEXT || was.nodeType == COMMENT) {
157
+ if (was.nodeValue != next.nodeValue) was.nodeValue = next.nodeValue
158
+ tally.kept++
159
+ return tally
160
+ }
161
+ let a = el(was), b = el(next)
162
+ if (a && b) {
163
+ if (a.isEqualNode(b)) {
164
+ tally.kept += size(a)
165
+ return tally
166
+ }
167
+ attributes(a, b, o)
168
+ if (a.localName == 'script') {
169
+ if (!b.hasAttribute('src')) a.textContent = b.textContent
170
+ tally.kept++
171
+ return tally
172
+ }
173
+ if (a.localName == 'template') {
174
+ if (a.innerHTML != b.innerHTML) a.innerHTML = b.innerHTML
175
+ tally.kept++
176
+ return tally
177
+ }
178
+ }
179
+ tally.kept++
180
+ children(was, next, o, tally)
181
+ return tally
182
+ }
183
+
184
+ let children = (was: Node, next: Node, o: Morphing, tally: Tally) => {
185
+ let doc = was.ownerDocument ?? was as Document
186
+ let old = [...was.childNodes]
187
+ let keyed = new Map<string, Node>()
188
+ for (let n of old) {
189
+ let key = keyOf(n)
190
+ if (key && !keyed.has(key)) keyed.set(key, n)
191
+ }
192
+ let used = new Set<Node>()
193
+ let at = 0
194
+ let pairs: [Node, Node][] = []
195
+ let wanted = [...next.childNodes].map((n) => {
196
+ let key = keyOf(n)
197
+ let match: Node | undefined
198
+ if (key) {
199
+ match = keyed.get(key)
200
+ if (match && (used.has(match) || !alike(match, n))) match = undefined
201
+ } else {
202
+ while (at < old.length && (used.has(old[at]) || keyOf(old[at]))) at++
203
+ if (at < old.length && alike(old[at], n)) match = old[at++]
204
+ }
205
+ if (!match) {
206
+ let made = doc.importNode(n, true)
207
+ tally.made += size(made)
208
+ return made
209
+ }
210
+ used.add(match)
211
+ pairs.push([match, n])
212
+ return match
213
+ })
214
+ let ref = was.firstChild
215
+ for (let n of wanted) {
216
+ while (ref && !used.has(ref)) ref = ref.nextSibling
217
+ if (n == ref) ref = ref.nextSibling
218
+ else was.insertBefore(n, ref)
219
+ }
220
+ for (let n of old) {
221
+ if (used.has(n) || o.leave?.(n)) continue
222
+ tally.dropped += size(n)
223
+ n.parentNode?.removeChild(n)
224
+ }
225
+ for (let [a, b] of pairs) {
226
+ if (kept(a, b)) tally.kept += size(a)
227
+ else morph(a, b, o, tally)
228
+ }
229
+ }
230
+
231
+ // A region both pages mark as a script's own: left as it stands.
232
+ let kept = (a: Node, b: Node) =>
233
+ !!el(a)?.hasAttribute(KEPT) && !!el(b)?.hasAttribute(KEPT)
234
+
235
+ // What a head keeps of the page before: what a script or the browser put
236
+ // there and a later page has no word on.
237
+ let leaveInHead = (n: Node) => {
238
+ let e = el(n)
239
+ if (!e) return false
240
+ let rel = e.getAttribute('rel') ?? ''
241
+ return (e.localName == 'script' && e.hasAttribute('src')) ||
242
+ e.localName == 'style' ||
243
+ (e.localName == 'link' && /stylesheet|preload|modulepreload/.test(rel))
244
+ }
245
+
246
+ let RUNS = /^(|module|text\/javascript|application\/javascript)$/
247
+
248
+ /** The scripts of a document that run, as nodes. */
249
+ let scripts = (doc: Document): HTMLScriptElement[] =>
250
+ [...doc.querySelectorAll('script')].filter((s) =>
251
+ RUNS.test(s.getAttribute('type') ?? '')
252
+ )
253
+
254
+ /** Where a script's `src` leads, whole, or null for one written in. */
255
+ let source = (s: Element, base: string): string | null => {
256
+ let src = s.getAttribute('src')
257
+ return src ? new URL(src, base).href : null
258
+ }
259
+
260
+ /** A script that runs: a new element in place of one the parser wrote,
261
+ * which a document never runs once it was parsed elsewhere. */
262
+ export let rerun = (s: Element): void => {
263
+ let doc = s.ownerDocument
264
+ let fresh = doc.createElement('script')
265
+ for (let { name, value } of [...s.attributes]) fresh.setAttribute(name, value)
266
+ fresh.textContent = s.textContent
267
+ if (fresh.hasAttribute('src')) (fresh as HTMLScriptElement).async = false
268
+ s.replaceWith(fresh)
269
+ }
270
+
271
+ /** A page's scripts that hold it (`data-stays`): one standing means the
272
+ * page is left by loading the next. */
273
+ export let stays = (doc: Document): boolean =>
274
+ !!doc.querySelector('script[data-stays]')
275
+
276
+ /**
277
+ * Lay the page `next` over `doc`: its head and its body changed in place
278
+ * (`morph`), the scripts it names for the first time run, and every script
279
+ * written into it run again. `ran` holds the addresses of the scripts that
280
+ * have run in `doc`, and gains those run now; `run` runs one; `base` is the
281
+ * address relative ones are read against.
282
+ */
283
+ export let swap = (
284
+ doc: Document,
285
+ next: Document,
286
+ ran: Set<string>,
287
+ run: (s: Element) => void = rerun,
288
+ base: string = doc.baseURI,
289
+ ): Tally => {
290
+ let before = new Set(scripts(doc))
291
+ attributes(doc.documentElement, next.documentElement, {})
292
+ let tally = morph(doc.head, next.head, { leave: leaveInHead })
293
+ morph(doc.body, next.body, {}, tally)
294
+ for (let s of scripts(doc)) {
295
+ let src = source(s, base)
296
+ if (src && (before.has(s) || ran.has(src))) continue
297
+ if (src) ran.add(src)
298
+ run(s)
299
+ }
300
+ return tally
301
+ }
302
+
303
+ /** The scripts with a `src` a document has run, read against `base`. */
304
+ export let sources = (
305
+ doc: Document,
306
+ base: string = doc.baseURI,
307
+ ): Set<string> =>
308
+ new Set(
309
+ scripts(doc).map((s) => source(s, base)).filter((s) => s != null),
310
+ )
311
+
312
+ // What each element is bound as, and how to let it go, across every copy of
313
+ // a script the document runs: kept on the element, so each copy sees them.
314
+ let BOUND = Symbol.for('@yaks/ui/navigate bound')
315
+ type Holding = { [BOUND]?: Map<string, (() => void) | void> }
316
+
317
+ /**
318
+ * Bind `e` as `name` once, across every copy of a script its document runs.
319
+ * A script's file is named by its content, so a swap to a page a newer
320
+ * release drew runs that release's copy of it beside the one already
321
+ * running, over the elements the swap left in place: two bindings of one
322
+ * element answer each event twice and draw over each other. The newer copy
323
+ * takes the element over where the older answered how to let go (`bind`'s
324
+ * answer), and otherwise leaves it to the older. Answers whether `bind` ran.
325
+ */
326
+ export let hold = (
327
+ e: Element,
328
+ name: string,
329
+ bind: () => (() => void) | void,
330
+ ): boolean => {
331
+ let held = (e as Element & Holding)[BOUND] ??= new Map()
332
+ if (held.has(name)) {
333
+ let stop = held.get(name)
334
+ if (!stop) return false
335
+ stop()
336
+ }
337
+ held.set(name, bind())
338
+ return true
339
+ }
340
+
341
+ /** Run `bind` over the document now and over every page a swap brings,
342
+ * each element once, across every copy of the script (`hold`): `of`
343
+ * selects them. For a script with a `src`, which runs once. */
344
+ export let arrived = <E extends Element>(
345
+ of: string,
346
+ bind: (e: E) => void,
347
+ doc: Document = document,
348
+ ): void => {
349
+ let each = () => {
350
+ for (let e of doc.querySelectorAll<E>(of)) hold(e, of, () => void bind(e))
351
+ }
352
+ each()
353
+ doc.addEventListener(PAGE, each)
354
+ }
355
+
356
+ /** A signal aborted when the page leaves (`yak-leave`), for a script written
357
+ * into a page to add its listeners with. */
358
+ export let leaving = (doc: Document = document): AbortSignal => {
359
+ let leave = new AbortController()
360
+ doc.addEventListener(LEAVE, () => leave.abort(), { once: true })
361
+ return leave.signal
362
+ }
363
+
364
+ /** What `start` needs of the window around it: the idle callback where the
365
+ * browser has one, else a timer stands for it. */
366
+ export type Browsing =
367
+ & Pick<
368
+ Window,
369
+ 'document' | 'location' | 'addEventListener' | 'fetch' | 'scrollTo'
370
+ >
371
+ & Partial<Pick<Window, 'requestIdleCallback'>>
372
+ & {
373
+ DOMParser: typeof DOMParser
374
+ /** Whether a link belongs to this navigator. */
375
+ follows?: (link: HTMLAnchorElement) => boolean
376
+ /** Prepare the files of a held document while its link is on screen. */
377
+ prepare?: (page: Document, at: URL) => void
378
+ /** Open a READY page as a document when the current page has its own
379
+ * scripts and styles. The address has already moved to the answer. */
380
+ enter?: (html: string, opening: Entering) => void
381
+ }
382
+
383
+ /** What a ready document knows about the press that opens it. */
384
+ export type Entering = {
385
+ url: string
386
+ from: 'held' | 'fetch'
387
+ began: number
388
+ wait: number
389
+ drawn?: () => void
390
+ }
391
+
392
+ /** Where a click's time went, in milliseconds: waiting for the page whole
393
+ * and parsed (nothing, for one already held), and laying it over the page. */
394
+ export type Phases = { wait: number; swap: number }
395
+
396
+ /** Where the page a swap drew came from: fetched on the click (`fetch`),
397
+ * held already, fetched ahead or opened before (`held`), the answer
398
+ * asked for after drawing a held one or a frame, laid over it (`fresh`),
399
+ * its frame, until it comes (`framed`, `FRAME`), or drawn in place by the
400
+ * page on screen from what the tab holds (`drawn`, `DRAW`). */
401
+ export type From = 'fetch' | 'held' | 'fresh' | 'framed' | 'drawn'
402
+
403
+ /** Heard on the document before a press or Back fetches anything, its detail
404
+ * a `Drawing`: a page that can show `to` itself, from what the tab holds,
405
+ * sets `draw` to do so. The navigator then moves the address and the focus
406
+ * as it would for a page it fetched, and fetches nothing. The page stays the
407
+ * page: nothing leaves, no script runs again, and it keeps where it was
408
+ * scrolled; the document hears `SHOWN` in place of `PAGE`. */
409
+ export let DRAW = 'yak-draw'
410
+
411
+ /** Heard on the document once a press or Back was drawn in place (`DRAW`),
412
+ * its detail a `Swapped`. */
413
+ export let SHOWN = 'yak-shown'
414
+
415
+ /** The detail of `DRAW`: where the press leads, and how the page on screen
416
+ * draws it, where it can. `draw` changes the document in place, at once.
417
+ * A view can put the content's focus after paint when it keeps its layout. */
418
+ export type Drawing = {
419
+ to: URL
420
+ /** The destination's fetched frame, when it supplies data for an in-place draw. */
421
+ from?: Document
422
+ draw?: () => void
423
+ focusAfterPaint?: boolean
424
+ }
425
+
426
+ /** What a swap said once done: when the click was (`began`, on the clock
427
+ * `start` was given), how long it took to the new page, in milliseconds,
428
+ * where that time went, where the page came from, and what changed. The
429
+ * detail of `yak-page`. */
430
+ export type Swapped = {
431
+ ms: number
432
+ began: number
433
+ phases: Phases
434
+ from: From
435
+ tally: Tally
436
+ url: string
437
+ }
438
+
439
+ /** A client that can put an HTML answer at its Content-Location. */
440
+ export let NAVIGATE = 'x-yak-navigate'
441
+
442
+ /** How long a page held stays good enough to draw without asking for it
443
+ * again, in milliseconds, and how many pages are held. */
444
+ export let FRESH = 10_000
445
+ export let HELD = 24
446
+ /** How long a pointer stays over a link before its page is asked for. */
447
+ export let INTENT = 60
448
+ /** The mark on a link whose page is kept ready: asked for ahead (`AHEAD`) as
449
+ * soon as the page holding the link is drawn and the browser is idle, and
450
+ * held, so a press on it draws at once and asks for it again after. For a
451
+ * page its server is slow to answer, where a finger's touch gives too little
452
+ * head start. */
453
+ export let READY = 'data-ready'
454
+ /** A menu link whose page is held while the browser is idle, after READY
455
+ * links. */
456
+ export let HOLD = 'data-hold'
457
+ // Bound the work a long sidebar can start in the background.
458
+ let HOLDS = 10
459
+ /** The header on an answer to a look ahead (`AHEAD`) that left out what
460
+ * opening the page does (marking what it shows read): the page is asked for
461
+ * again once it is opened. */
462
+ export let AGAIN = 'x-yak-again'
463
+ type Visit = {
464
+ to: URL
465
+ allowed: () => boolean
466
+ view: () => Element | null
467
+ accepts?: (page: Document) => boolean
468
+ result?: Promise<VisitResult>
469
+ }
470
+ export type VisitResult =
471
+ | 'opened'
472
+ | 'deferred'
473
+ | 'superseded'
474
+ | 'navigator unavailable'
475
+ | 'different origin'
476
+ | 'no page response'
477
+ | 'page cannot be opened in place'
478
+ | 'destination absent from page'
479
+ | 'page could not be drawn'
480
+ | `HTTP ${number}`
481
+ let VISIT = 'yak-visit'
482
+
483
+ /** Open a proposed page with the document's navigator. Check that the person
484
+ * is still ready for it when the destination is drawn. */
485
+ export let visit = (
486
+ doc: Document,
487
+ to: URL,
488
+ allowed: Visit['allowed'],
489
+ view: Visit['view'],
490
+ accepts?: Visit['accepts'],
491
+ ): Promise<VisitResult> => {
492
+ let asked: Visit = { to, allowed, view, accepts }
493
+ tell(doc, VISIT, asked)
494
+ return asked.result ?? Promise.resolve('navigator unavailable')
495
+ }
496
+
497
+ /** Heard on the document as a click sets out for a page it does not hold,
498
+ * its detail when (`{ began }`): the frame drawn then is the click's first. */
499
+ export let GOING = 'yak-going'
500
+
501
+ // Where a page's content is: what its skip link names, else its `main`.
502
+ let content = (doc: Document) => {
503
+ let to = doc.querySelector('a.Skip[href^="#"]')?.getAttribute('href')
504
+ return (to && to.length > 1 ? doc.getElementById(to.slice(1)) : null) ??
505
+ doc.querySelector('main')
506
+ }
507
+
508
+ let page = (url: URL | Location) => url.pathname + url.search
509
+
510
+ // Resolve against the current address even when the document has a base.
511
+ let closeLayer = (location: Browsing['location'], to: URL) => {
512
+ if (location.hash && location.hash != to.hash) {
513
+ location.replace(new URL('#', location.href).href)
514
+ }
515
+ }
516
+
517
+ // An event told to the whole document, made by its own window.
518
+ let tell = (doc: Document, type: string, detail?: unknown) => {
519
+ let view = (doc.defaultView ?? globalThis) as typeof globalThis
520
+ doc.dispatchEvent(new view.CustomEvent(type, { bubbles: true, detail }))
521
+ }
522
+
523
+ // Links the navigator can follow are same-origin page links in this tab.
524
+ let destination = (
525
+ link: HTMLAnchorElement,
526
+ base: string,
527
+ here: string,
528
+ ): URL | null => {
529
+ if (
530
+ link.hasAttribute('download') || (link.target && link.target != '_self')
531
+ ) {
532
+ return null
533
+ }
534
+ let to = new URL(link.getAttribute('href')!, base)
535
+ if (to.origin != new URL(base).origin) return null
536
+ if (page(to) == here && (to.hash || to.href.endsWith('#'))) return null
537
+ return to
538
+ }
539
+
540
+ let followed = (
541
+ e: MouseEvent | Event,
542
+ base: string,
543
+ here: string,
544
+ readyOnly = false,
545
+ follows?: Browsing['follows'],
546
+ ): URL | null => {
547
+ let link = (e.target as Element | null)?.closest?.('a[href]') as
548
+ | HTMLAnchorElement
549
+ | null
550
+ let m = e as MouseEvent
551
+ if (
552
+ !link || e.defaultPrevented || m.button > 0 || m.metaKey || m.ctrlKey ||
553
+ m.shiftKey || m.altKey || (readyOnly && !link.hasAttribute(READY)) ||
554
+ follows?.(link) === false
555
+ ) return null
556
+ return destination(link, base, here)
557
+ }
558
+
559
+ /** A page answered: its document's words, parsed as it arrived so a click
560
+ * spends nothing on that, where it was answered from, and whether it asks to
561
+ * be asked for again once opened (`AGAIN`). */
562
+ type Answer = {
563
+ text: string
564
+ page: Document
565
+ url: string
566
+ again: boolean
567
+ status: number
568
+ received: number
569
+ ray?: string
570
+ }
571
+ /** A page held: its answer, or null where it cannot be swapped in, when it
572
+ * was asked for, whether it was only looked ahead at, whether a click has
573
+ * taken it up, and how to stop asking for it. */
574
+ type Held = {
575
+ answer: Promise<Answer | null>
576
+ received?: Answer
577
+ at: number
578
+ ahead: boolean
579
+ used?: boolean
580
+ stop: AbortController
581
+ }
582
+
583
+ let enterable = (answer: Answer) =>
584
+ answer.status >= 200 && answer.status < 300 &&
585
+ !answer.again && !!answer.page.querySelector(`script[${TAKES}]`)
586
+
587
+ /** The mark on a link saying what the page it opens is called, and on a
588
+ * page the title that says what the page is: a click waiting for its page
589
+ * writes the one into the other at once (`going`). */
590
+ export let NAMES = 'data-names'
591
+ export let TITLE = 'data-title'
592
+
593
+ // What a click shows in its own frame while its page is on its way, from
594
+ // what the page holds: a layer the address opened (a phone's menu) closes,
595
+ // the link pressed takes the current link's marks in its list (its
596
+ // `aria-current` and the classes it wears for it), the page's title says
597
+ // the name the link gives its page (`NAMES`), and the content waits
598
+ // (`aria-busy`). The page, once laid over, says it all again.
599
+ let going = (win: Browsing, link: Element, to: URL) => {
600
+ let doc = win.document
601
+ closeLayer(win.location, to)
602
+ let was = link.closest('nav')?.querySelector('a[aria-current="page"]')
603
+ if (was && was != link) {
604
+ let marks = [...was.classList].filter((c) => !link.classList.contains(c))
605
+ was.classList.remove(...marks)
606
+ was.removeAttribute('aria-current')
607
+ link.classList.add(...marks)
608
+ link.setAttribute('aria-current', 'page')
609
+ }
610
+ let names = link.getAttribute(NAMES)
611
+ let title = names && doc.querySelector(`[${TITLE}]`)
612
+ if (title) title.textContent = names
613
+ content(doc)?.setAttribute('aria-busy', 'true')
614
+ }
615
+
616
+ /** The mark on a template holding the frame the pages under a path share,
617
+ * its value the path (`/admin`), or several space-separated paths. The
618
+ * template holds what those pages show before their own content, such as a
619
+ * heading over an empty body. A press on a link
620
+ * to one of them whose page has not come yet, held or not, puts the frame
621
+ * in place of what stands beside the template, in the press's own frame,
622
+ * its titles (`TITLE`) saying what the link names its page (`NAMES`), and
623
+ * lays the page over it when it comes. */
624
+ export let FRAME = 'data-frame'
625
+
626
+ // The frame of the page at `to`, where the page on screen holds one.
627
+ let frameOf = (doc: Document, to: URL) =>
628
+ [...doc.querySelectorAll<HTMLTemplateElement>(`template[${FRAME}]`)]
629
+ .find((t) => {
630
+ return t.getAttribute(FRAME)!.split(/\s+/).some((under) =>
631
+ under && (to.pathname == under || to.pathname.startsWith(`${under}/`))
632
+ )
633
+ })
634
+
635
+ // Put `frame` in place of what stands beside it, titled `names`.
636
+ let framed = (frame: HTMLTemplateElement, names?: string | null): Tally => {
637
+ let region = frame.parentElement!
638
+ let made = frame.content.cloneNode(true) as DocumentFragment
639
+ if (names != null) {
640
+ for (let title of made.querySelectorAll(`[${TITLE}]`)) {
641
+ title.textContent = names
642
+ }
643
+ }
644
+ let frames = [...region.children].filter((e) =>
645
+ e.matches(`template[${FRAME}]`)
646
+ )
647
+ let tally = {
648
+ kept: frames.length,
649
+ made: made.childNodes.length,
650
+ dropped: region.childNodes.length - frames.length,
651
+ }
652
+ // Another press or Back may need a different frame before this page comes.
653
+ region.replaceChildren(...frames, made)
654
+ return tally
655
+ }
656
+
657
+ /**
658
+ * Follow the links of `win`'s pages in place: a click on a link to another
659
+ * page of the same origin, and Back and Forward between such pages, `swap`
660
+ * it in. The new page's content (`content`) starts at its top and takes the
661
+ * focus, as a new document would. Answers `go`, which visits an address the
662
+ * same way.
663
+ *
664
+ * A page is drawn in the frame of the click when it is held: opened before
665
+ * (the `HELD` opened last), or fetched ahead, one at a time, as a pointer
666
+ * rests on its link, presses it, a finger touches it or the keyboard comes
667
+ * to it (`AHEAD`), and let go of if the pointer moves on before it arrives.
668
+ * A held page older than `FRESH`, or one whose answer asked (`AGAIN`), is
669
+ * asked for again once drawn, and laid over what was drawn where it
670
+ * changed. A click on a page not held draws what it can of that page at
671
+ * once, from what the page holds (`going`), and its frame where the page
672
+ * holds one (`FRAME`), and the rest when it comes.
673
+ * Links marked `READY` or `HOLD` are asked for as the browser idles.
674
+ * A page with its own document scripts can supply `enter` to open only its
675
+ * READY links this way, keeping that document's ordinary links with the
676
+ * browser. Each usable answer stands until a refresh replaces it or the
677
+ * server no longer serves the page.
678
+ * A page that draws the address itself (`DRAW`) is drawn in place, with no
679
+ * fetch. Sending a form makes every held page old: still drawn at once, and
680
+ * asked for again.
681
+ */
682
+ export let start = (
683
+ win: Browsing,
684
+ history: HistoryPort,
685
+ now: Clock['now'] = () => performance.now(),
686
+ after: Clock['after'] = system.after,
687
+ ): (
688
+ to: URL,
689
+ pop?: boolean,
690
+ pressed?: Result,
691
+ began?: number,
692
+ ) => Promise<void> => {
693
+ let doc = win.document
694
+ let ran = sources(doc, win.location.href)
695
+ let here = page(win.location)
696
+ let turn = 0
697
+ let pages = new Map<string, Held>()
698
+ let warmLink = warmer(win, now, FRESH, HELD)
699
+ // Back and Forward have already moved the address: the page loads there.
700
+ let load = (to: URL, pop = false) =>
701
+ pop ? win.location.replace(to.href) : win.location.assign(to.href)
702
+ let fetched = async (
703
+ to: URL,
704
+ ahead: boolean,
705
+ signal: AbortSignal,
706
+ denied: () => void,
707
+ ): Promise<Answer | null> => {
708
+ let answer = await win.fetch(to.href, {
709
+ headers: {
710
+ accept: 'text/html',
711
+ [NAVIGATE]: '1',
712
+ ...ahead ? { [AHEAD]: 'prefetch' } : {},
713
+ },
714
+ credentials: 'same-origin',
715
+ signal,
716
+ }).catch(() => null)
717
+ if (!answer) return null
718
+ if ([401, 403, 404, 410].includes(answer.status)) denied()
719
+ if (!answer.headers.get('content-type')?.includes('text/html')) return null
720
+ let url = new URL(answer.url || to.href)
721
+ if (url.origin != to.origin) return null
722
+ let location = answer.ok && answer.headers.get('content-location')
723
+ let at = location && URL.parse(location, url)
724
+ if (at && at.origin == url.origin) url = at
725
+ let text = await answer.text().catch(() => null)
726
+ if (text == null) return null
727
+ let received = now()
728
+ let page = new win.DOMParser().parseFromString(text, 'text/html')
729
+ let again = answer.headers.has(AGAIN)
730
+ let held = {
731
+ text,
732
+ page,
733
+ url: url.href,
734
+ again,
735
+ status: answer.status,
736
+ received,
737
+ ray: rayOf(answer.headers.get('cf-ray')),
738
+ }
739
+ if (!signal.aborted && win.prepare && enterable(held)) {
740
+ try {
741
+ win.prepare(page, url)
742
+ } catch (error) {
743
+ globalThis.reportError?.(error)
744
+ }
745
+ }
746
+ return held
747
+ }
748
+ let keep = (key: string, held: Held) => {
749
+ pages.delete(key)
750
+ pages.set(key, held)
751
+ for (let old of pages.keys()) {
752
+ if (pages.size <= HELD) break
753
+ pages.delete(old)
754
+ }
755
+ }
756
+ let ask = (to: URL, ahead = false, previous?: Held): Held => {
757
+ let key = page(to)
758
+ let stop = new AbortController()
759
+ let held: Held = {
760
+ answer: fetched(to, ahead, stop.signal, () => {
761
+ if (previous && pages.get(key) == previous) pages.delete(key)
762
+ }),
763
+ at: now(),
764
+ ahead,
765
+ stop,
766
+ }
767
+ if (!previous) keep(key, held)
768
+ held.answer.then((answer) => {
769
+ if (answer) held.received = answer
770
+ if (pages.get(key) != (previous ?? held)) return
771
+ if (!previous) {
772
+ if (!answer) pages.delete(key)
773
+ } else if (answer && enterable(answer)) {
774
+ keep(key, held)
775
+ } else if (answer && answer.status >= 200 && answer.status < 300) {
776
+ pages.delete(key)
777
+ }
778
+ })
779
+ return held
780
+ }
781
+ let fresh = (held: Held | undefined): held is Held =>
782
+ !!held && now() - held.at < FRESH
783
+ // Put the page at `at` on screen by `change`, as a new document comes: the
784
+ // page leaving hears it, the address moves, the content starts at its top
785
+ // and takes the focus, and the page that came hears it; false where it
786
+ // cannot be. A page drawn in place (`DRAW`) leaves nothing and keeps its
787
+ // scroll.
788
+ let land = (
789
+ at: URL,
790
+ change: () => Tally,
791
+ from: From,
792
+ began: number,
793
+ wait: number,
794
+ pop: boolean,
795
+ focusAfterPaint = false,
796
+ ) => {
797
+ let lap = now()
798
+ let fetched = from != 'drawn'
799
+ let first = from != 'fresh'
800
+ let tally: Tally
801
+ try {
802
+ if (fetched) tell(doc, LEAVE)
803
+ // The focus, which moves to the content below, lets go first. A focused
804
+ // node the change removes (the pressed link) makes the browser restyle
805
+ // the whole page there and then to move the focus off it: 40–75 ms of
806
+ // a press on a page of 4,000 elements.
807
+ if (first && !pop) (doc.activeElement as HTMLElement | null)?.blur?.()
808
+ tally = change()
809
+ } catch (error) {
810
+ // A page half laid over is no page: the next loads as a document, and
811
+ // the reporter hears why (M-37965).
812
+ globalThis.reportError?.(error)
813
+ return false
814
+ }
815
+ // A layer the old address opened (`#menu`, shown by `:target`) closes,
816
+ // as it would on a new document: writing history leaves `:target` be.
817
+ if (first) closeLayer(win.location, at)
818
+ if (first && !pop) {
819
+ history.write({ path: at.pathname + at.search + at.hash, state: null })
820
+ }
821
+ here = page(at)
822
+ if (first && !pop) {
823
+ let target = at.hash &&
824
+ doc.getElementById(decodeURIComponent(at.hash.slice(1)))
825
+ let main = content(doc) as HTMLElement | null
826
+ if (target) target.scrollIntoView()
827
+ else if (fetched) {
828
+ win.scrollTo({ top: 0, left: 0, behavior: 'instant' })
829
+ if (main) main.scrollTop = 0
830
+ }
831
+ let view = doc.defaultView
832
+ if (main && focusAfterPaint && view?.requestAnimationFrame) {
833
+ let focused = doc.activeElement
834
+ let mine = turn
835
+ view.requestAnimationFrame(() =>
836
+ view.setTimeout(() => {
837
+ let active = doc.activeElement
838
+ if (
839
+ mine == turn && main.isConnected &&
840
+ (active == focused || active == doc.body || !active)
841
+ ) {
842
+ main.focus({ preventScroll: true })
843
+ }
844
+ })
845
+ )
846
+ } else main?.focus?.({ preventScroll: true })
847
+ }
848
+ let end = now()
849
+ let phases = { wait, swap: end - lap }
850
+ let detail: Swapped = {
851
+ ms: end - began,
852
+ began,
853
+ phases,
854
+ from,
855
+ tally,
856
+ url: at.href,
857
+ }
858
+ tell(doc, fetched ? PAGE : SHOWN, detail)
859
+ readying()
860
+ return true
861
+ }
862
+ // Draw `answer` as the page at `to`; false where it cannot be.
863
+ let draw = (
864
+ to: URL,
865
+ answer: Answer,
866
+ from: From,
867
+ began: number,
868
+ wait: number,
869
+ pop: boolean,
870
+ visit?: Visit,
871
+ ) => {
872
+ if (!answer.page.querySelector(`script[${TAKES}]`)) return false
873
+ let at = new URL(answer.url)
874
+ at.hash = to.hash
875
+ let change = () => swap(doc, answer.page, ran, rerun, at.href)
876
+ let drawn = land(at, change, from, began, wait, pop)
877
+ if (drawn && visit) slideIn(visit.view())
878
+ return drawn
879
+ }
880
+ // The page at `to` laid over its frame as it comes, pressed at `began`, or
881
+ // loaded where it cannot be; left be where another press came since.
882
+ let laid = async (to: URL, using: Held, began: number, mine: number) => {
883
+ let answer = await using.answer
884
+ if (mine != turn) return
885
+ let wait = answer ? Math.max(0, answer.received - began) : 0
886
+ if (!answer || !draw(to, answer, 'fresh', began, wait, true)) {
887
+ load(answer ? new URL(answer.url) : to, true)
888
+ }
889
+ }
890
+ // How the page on screen draws `to` itself, where it can (`DRAW`).
891
+ let drawing = (to: URL, from?: Document) => {
892
+ let asked: Drawing = { to, from }
893
+ tell(doc, DRAW, asked)
894
+ let own = asked.draw
895
+ return own && {
896
+ change: () => (own(), { kept: 0, made: 0, dropped: 0 }),
897
+ focusAfterPaint: asked.focusAfterPaint,
898
+ }
899
+ }
900
+ let go = async (
901
+ to: URL,
902
+ pop = false,
903
+ pressed?: Result,
904
+ began = now(),
905
+ own = drawing(to),
906
+ names?: string | null,
907
+ ) => {
908
+ let mine = ++turn
909
+ if (
910
+ own &&
911
+ land(new URL(to), own.change, 'drawn', began, 0, pop, own.focusAfterPaint)
912
+ ) {
913
+ return pressed?.drawn(0)
914
+ }
915
+ if (stays(doc)) {
916
+ pressed?.leaving()
917
+ return load(to, pop)
918
+ }
919
+ let held = pages.get(page(to))
920
+ if (win.enter && !held) {
921
+ pressed?.leaving()
922
+ return load(to, pop)
923
+ }
924
+ let from: Entering['from'] = held?.received ? 'held' : 'fetch'
925
+ // Taken up before anything moves the focus, which lets go of a look
926
+ // ahead nobody took up (`left`).
927
+ let using = held ?? ask(to)
928
+ using.used = true
929
+ // Its frame now, and the page laid over it as it comes, the address
930
+ // already moved.
931
+ let frame = !win.enter && !held?.received && frameOf(doc, to)
932
+ if (
933
+ frame &&
934
+ land(new URL(to), () => framed(frame, names), 'framed', began, 0, pop)
935
+ ) {
936
+ pressed?.drawn(0)
937
+ return laid(to, using, began, mine)
938
+ }
939
+ let answer = await using.answer
940
+ if (mine != turn) return pressed?.cancel()
941
+ let wait = answer ? Math.max(0, answer.received - began) : 0
942
+ if (win.enter && answer && enterable(answer)) {
943
+ let at = new URL(answer.url)
944
+ at.hash = to.hash
945
+ history.write({ path: page(at) + at.hash, state: null })
946
+ try {
947
+ closed = true
948
+ stopRefresh?.()
949
+ return win.enter(answer.text, {
950
+ url: at.href,
951
+ from,
952
+ began,
953
+ wait,
954
+ drawn: pressed && (() => pressed.drawn(wait, answer.ray)),
955
+ })
956
+ } catch (error) {
957
+ globalThis.reportError?.(error)
958
+ pressed?.leaving()
959
+ return load(at, true)
960
+ }
961
+ }
962
+ if (
963
+ win.enter || !answer ||
964
+ !draw(to, answer, from, began, wait, pop)
965
+ ) {
966
+ pressed?.leaving()
967
+ return load(answer ? new URL(answer.url) : to, pop)
968
+ }
969
+ pressed?.drawn(wait, answer.ray)
970
+ if (!held || (fresh(held) && !(held.ahead && answer.again))) return
971
+ let again = now()
972
+ let newer = await ask(to).answer
973
+ if (mine != turn || !newer || newer.text == answer.text) return
974
+ if (!draw(to, newer, 'fresh', again, now() - again, true)) {
975
+ load(new URL(newer.url), true)
976
+ }
977
+ }
978
+ doc.addEventListener(VISIT, (event) => {
979
+ let asked = (event as CustomEvent<Visit>).detail
980
+ let { to, allowed, view, accepts } = asked
981
+ let ready = () => allowed() && !stays(doc)
982
+ asked.result = (async (): Promise<VisitResult> => {
983
+ if (to.origin != win.location.origin) return 'different origin'
984
+ if (!allowed()) return 'deferred'
985
+ if (to.href == win.location.href) return 'opened'
986
+ let began = now()
987
+ let show = (
988
+ own: NonNullable<ReturnType<typeof drawing>>,
989
+ wait: number,
990
+ ): VisitResult => {
991
+ let shown = land(to, own.change, 'drawn', began, wait, false)
992
+ if (shown) slideIn(view())
993
+ return shown ? 'opened' : 'page could not be drawn'
994
+ }
995
+ // A page that draws `to` itself is not left, so nothing holds it.
996
+ let own = drawing(to)
997
+ if (own) {
998
+ turn++
999
+ return show(own, 0)
1000
+ }
1001
+ if (!ready()) return 'deferred'
1002
+ let mine = ++turn
1003
+ let held = pages.get(page(to))
1004
+ let using = held ?? ask(to)
1005
+ using.used = true
1006
+ let answer = await using.answer
1007
+ if (mine != turn) return 'superseded'
1008
+ if (!ready()) return 'deferred'
1009
+ if (
1010
+ held &&
1011
+ (!answer || !enterable(answer) || accepts?.(answer.page) === false)
1012
+ ) {
1013
+ using = ask(to)
1014
+ using.used = true
1015
+ answer = await using.answer
1016
+ }
1017
+ if (mine != turn) return 'superseded'
1018
+ if (!ready()) return 'deferred'
1019
+ if (!answer) return 'no page response'
1020
+ if (answer.status < 200 || answer.status >= 300) {
1021
+ return `HTTP ${answer.status}`
1022
+ }
1023
+ if (!enterable(answer)) return 'page cannot be opened in place'
1024
+ if (accepts?.(answer.page) === false) {
1025
+ if (pages.get(page(to)) == using) pages.delete(page(to))
1026
+ return 'destination absent from page'
1027
+ }
1028
+ let wait = now() - began
1029
+ own = drawing(to, answer.page)
1030
+ if (own) return show(own, wait)
1031
+ return draw(to, answer, 'fetch', began, wait, false, asked)
1032
+ ? 'opened'
1033
+ : 'page could not be drawn'
1034
+ })()
1035
+ })
1036
+ let readyLinks = () => {
1037
+ let linked = (mark: string) =>
1038
+ [...doc.querySelectorAll<HTMLAnchorElement>(`a[${mark}][href]`)]
1039
+ .filter((link) => !link.closest('[hidden]'))
1040
+ let targets = new Map<string, URL>()
1041
+ let add = (mark: string, most: number) => {
1042
+ for (let link of linked(mark)) {
1043
+ if (most <= 0) break
1044
+ let to = destination(link, win.location.href, here)
1045
+ if (!to) continue
1046
+ let key = page(to)
1047
+ if (key == here || targets.has(key) || drawing(to)) continue
1048
+ targets.set(key, to)
1049
+ most--
1050
+ }
1051
+ }
1052
+ add(READY, Infinity)
1053
+ if (!win.enter) {
1054
+ add(HOLD, HOLDS)
1055
+ for (let link of linked(WARM).slice(0, HOLDS)) warmLink(link)
1056
+ }
1057
+ return targets
1058
+ }
1059
+ let closed = false, warming = false
1060
+ let stopRefresh: (() => void) | undefined
1061
+ let visible = () => doc.visibilityState != 'hidden'
1062
+ let warm = async () => {
1063
+ let from: string
1064
+ do {
1065
+ from = here
1066
+ if (closed || stays(doc) || !visible()) break
1067
+ for (let [key, to] of readyLinks()) {
1068
+ if (closed || from != here || stays(doc) || !visible()) break
1069
+ if (drawing(to)) continue
1070
+ let held = pages.get(key)
1071
+ if (!held || (win.enter && held.received && !fresh(held))) {
1072
+ await ask(to, true, held).answer
1073
+ }
1074
+ }
1075
+ } while (from != here)
1076
+ warming = false
1077
+ if (
1078
+ win.enter && !closed && visible() &&
1079
+ doc.querySelector(`a[${READY}][href]`)
1080
+ ) {
1081
+ stopRefresh = after(FRESH, readying)
1082
+ }
1083
+ }
1084
+ let readying = () => {
1085
+ if (closed || warming) return
1086
+ stopRefresh?.()
1087
+ warming = true
1088
+ if (win.enter) void warm()
1089
+ else if (win.requestIdleCallback) win.requestIdleCallback(() => void warm())
1090
+ else after(0, () => void warm())
1091
+ }
1092
+ doc.addEventListener('visibilitychange', () => {
1093
+ if (!visible()) stopRefresh?.()
1094
+ else readying()
1095
+ })
1096
+ win.addEventListener('pageshow', (e: PageTransitionEvent) => {
1097
+ if (e.persisted) readying()
1098
+ })
1099
+ if (win.enter || doc.readyState == 'complete') readying()
1100
+ else {
1101
+ // The page's other modules register its in-place views as it loads.
1102
+ doc.addEventListener('DOMContentLoaded', readying, { once: true })
1103
+ win.addEventListener('load', readying, { once: true })
1104
+ }
1105
+ // The one page being looked ahead at, which a pointer moving on, or
1106
+ // another look ahead, lets go of unless a click took it up.
1107
+ let looking: { key: string; held: Held } | undefined
1108
+ let drop = () => {
1109
+ if (!looking) return
1110
+ let { key, held } = looking
1111
+ looking = undefined
1112
+ if (held.used) return
1113
+ held.stop.abort()
1114
+ if (pages.get(key) == held) pages.delete(key)
1115
+ }
1116
+ let ahead = (e: Event) => {
1117
+ let link = (e.target as Element | null)?.closest?.(`a[${WARM}][href]`)
1118
+ if (link && !e.defaultPrevented) warmLink(link)
1119
+ let to = followed(e, win.location.href, here, !!win.enter, win.follows)
1120
+ if (!to || pages.has(page(to)) || drawing(to)) return
1121
+ drop()
1122
+ let key = page(to), held = ask(to, true)
1123
+ looking = { key, held }
1124
+ held.answer.then(() => looking?.held == held && (looking = undefined))
1125
+ }
1126
+ // A pointer passing over a link on its way elsewhere does not ask for it;
1127
+ // one that stays `INTENT` milliseconds, or presses, does.
1128
+ let hovering: ReturnType<typeof setTimeout> | undefined
1129
+ win.addEventListener('pointerover', (e: PointerEvent) => {
1130
+ if (e.pointerType != 'mouse') return
1131
+ clearTimeout(hovering)
1132
+ hovering = setTimeout(() => ahead(e), INTENT)
1133
+ })
1134
+ // Leaving the link (or the keyboard leaving it) before its page came.
1135
+ let left = (e: Event) => {
1136
+ let link = (e.target as Element | null)?.closest?.('a[href]')
1137
+ let into = (e as MouseEvent).relatedTarget as Node | null
1138
+ if (!link || (into && link.contains(into))) return
1139
+ clearTimeout(hovering)
1140
+ let to = new URL(link.getAttribute('href')!, win.location.href)
1141
+ if (looking?.key == page(to)) drop()
1142
+ }
1143
+ win.addEventListener('pointerout', (e: PointerEvent) => {
1144
+ if (e.pointerType == 'mouse') left(e)
1145
+ })
1146
+ win.addEventListener('focusout', left)
1147
+ // A touch the browser takes for a scroll is no press.
1148
+ win.addEventListener('pointercancel', left)
1149
+ win.addEventListener('focusin', ahead)
1150
+ win.addEventListener('mousedown', ahead)
1151
+ win.addEventListener('touchstart', ahead, { passive: true })
1152
+ win.addEventListener('submit', () => {
1153
+ for (let held of pages.values()) held.at = -Infinity
1154
+ })
1155
+ win.addEventListener('click', (e: MouseEvent) => {
1156
+ let began = Math.min(now(), e.timeStamp)
1157
+ let to = followed(e, win.location.href, here, !!win.enter, win.follows)
1158
+ if (!to) return
1159
+ let pressed = result(doc, e)
1160
+ e.preventDefault()
1161
+ let own = drawing(to)
1162
+ let link = (e.target as Element).closest('a[href]')!
1163
+ if (!own && !pages.get(page(to))?.received) {
1164
+ going(win, link, to)
1165
+ tell(doc, GOING, { began })
1166
+ }
1167
+ go(to, false, pressed, began, own, link.getAttribute(NAMES))
1168
+ })
1169
+ if (!win.enter) {
1170
+ history.listen(({ path }) => {
1171
+ let to = new URL(path, win.location.href)
1172
+ if (page(to) == here) return
1173
+ go(to, true)
1174
+ })
1175
+ }
1176
+ return go
1177
+ }