@nmnmcc/standard 0.4.0 → 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 (47) hide show
  1. package/README.md +45 -68
  2. package/dist/Extend.js +1 -1
  3. package/dist/{Standard-BPpzr5SM.js → Standard-BC6CfFOv.js} +116 -159
  4. package/dist/Standard.js +1 -1
  5. package/dist/Ui-DSgtM8Tf.js +591 -0
  6. package/dist/Ui.d.ts +4 -4
  7. package/dist/Ui.js +1 -1
  8. package/dist/index.js +2 -2
  9. package/dist/standard/page/page.d.ts +4 -6
  10. package/dist/standard/page/page.d.ts.map +1 -1
  11. package/dist/standard/tokens/tokens.d.ts +20 -103
  12. package/dist/standard/tokens/tokens.d.ts.map +1 -1
  13. package/dist/standard.css +1 -1
  14. package/dist/ui/flap/flap.d.ts +10 -10
  15. package/dist/ui/flap/flap.d.ts.map +1 -1
  16. package/dist/ui/modal/modal.d.ts +4 -1
  17. package/dist/ui/modal/modal.d.ts.map +1 -1
  18. package/dist/ui/navigator/navigator.d.ts +58 -59
  19. package/dist/ui/navigator/navigator.d.ts.map +1 -1
  20. package/dist/ui/notice/notice.d.ts +6 -1
  21. package/dist/ui/notice/notice.d.ts.map +1 -1
  22. package/dist/ui/sheet/sheet.d.ts +9 -9
  23. package/dist/ui/toasts/toasts.d.ts +8 -7
  24. package/dist/ui/toasts/toasts.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/standard/page/page.module.css +85 -47
  27. package/src/standard/page/page.module.d.css.ts +4 -2
  28. package/src/standard/page/page.ts +83 -1
  29. package/src/standard/tokens/tokens.ts +20 -268
  30. package/src/ui/dialog/dialog.module.css +24 -11
  31. package/src/ui/flap/flap.module.css +108 -52
  32. package/src/ui/flap/flap.module.d.css.ts +6 -1
  33. package/src/ui/flap/flap.ts +140 -13
  34. package/src/ui/modal/modal.module.css +73 -22
  35. package/src/ui/modal/modal.module.d.css.ts +1 -0
  36. package/src/ui/modal/modal.ts +21 -15
  37. package/src/ui/navigator/navigator.module.css +334 -176
  38. package/src/ui/navigator/navigator.module.d.css.ts +2 -10
  39. package/src/ui/navigator/navigator.ts +111 -106
  40. package/src/ui/notice/notice.ts +7 -2
  41. package/src/ui/popover/popover.ts +3 -3
  42. package/src/ui/sheet/sheet.module.css +51 -58
  43. package/src/ui/sheet/sheet.ts +9 -9
  44. package/src/ui/toasts/toasts.module.css +70 -11
  45. package/src/ui/toasts/toasts.module.d.css.ts +1 -0
  46. package/src/ui/toasts/toasts.ts +148 -4
  47. package/dist/Ui-B9xQqqNT.js +0 -468
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `sheet`: the place next to the page.
2
+ * `sheet`: a task or some detail, at the side of the window.
3
3
  *
4
4
  * @since 0.4.0
5
5
  */
@@ -11,14 +11,14 @@ import styles from "./sheet.module.css"
11
11
 
12
12
  export const sheet = <Msg>(h: Html.H<Msg>) => ({
13
13
  /**
14
- * The place next to the page: a task, some detail, or the app's
15
- * navigation. It isn't a layer over the page. The window moves over to
16
- * it, so the page slides out by exactly as much as the sheet slides in,
17
- * and back again when it closes; nothing is dimmed. It is at the end of
18
- * the page, or with `side: "start"` at its start. On a narrow screen it
19
- * is above the page: it comes down out of the navigator's top bar and
20
- * fills the window down to its tabs, and its button is across the
21
- * bottom, always in view. It keeps the focus inside, gives it back when it
14
+ * A task, some detail, or the app's navigation, at the side of the
15
+ * window. It comes in front of the page, and the page turns away from
16
+ * it on the navigator, as a door turns on its post, and back again when
17
+ * it closes. A page with no navigator slides out by exactly as much as
18
+ * the sheet slides in. It is at the end of the page, or with
19
+ * `side: "start"` at its start. On a narrow screen it fills the window
20
+ * between the navigator's top bar and its tabs, and its button is at
21
+ * its top, beside its title, as on a wide one. It keeps the focus inside, gives it back when it
22
22
  * closes, and asks to close on Escape, on a press outside it, and by its
23
23
  * button. The Model decides: it is open while `open` is true. With
24
24
  * `actions`, what ends the task is across its bottom, edge to edge, as the
@@ -1,36 +1,95 @@
1
- /* toasts: what just happened, at the bottom of the window. */
1
+ /* toasts: what just happened, in the top corner of the window. */
2
2
 
3
3
  @layer standard.ui {
4
- /* The last child of the page: it takes up no room, and stays at the bottom of the window. */
4
+ /*
5
+ * The last child of the page, and the first thing in it: it takes up no
6
+ * room, and stays at the top of the window, under a bar along the top if
7
+ * there is one.
8
+ */
5
9
  .toasts {
6
10
  position: sticky;
7
- inset-block-end: 0;
11
+ order: -1;
12
+ inset-block-start: var(--s-ui-clear-top, 0px);
8
13
  z-index: 1;
9
14
  block-size: 0;
10
- margin-block-start: auto;
11
15
  /* What was just said stays in the window while the page under it changes. */
12
16
  view-transition-name: s-ui-toasts;
17
+
18
+ /* Until the script has put it over everything, it is in the page, where it was made. */
19
+ &:not(:popover-open) {
20
+ display: block;
21
+ }
22
+
23
+ /*
24
+ * Over everything: in the browser's top layer, where no part of the
25
+ * page is over it and it does not turn with the page. It is in the
26
+ * same corner of the window, and still takes no room.
27
+ */
28
+ &:popover-open {
29
+ position: fixed;
30
+ inset: var(--s-ui-clear-top, 0px) 0 auto auto;
31
+ inline-size: min(26rem, 100vi);
32
+ background: transparent;
33
+ overflow: visible;
34
+ }
13
35
  }
14
36
 
37
+ /*
38
+ * In the corner at the end of the line, against the window's edges. The
39
+ * toasts are one under another with no room between them: a hairline
40
+ * tells one from the next.
41
+ */
15
42
  .toasts-list {
16
43
  position: absolute;
17
- inset-block-end: max(calc(2 * var(--s-unit)), env(safe-area-inset-bottom));
18
- inset-inline-start: var(--s-margin);
44
+ inset-block-start: 0;
45
+ inset-inline-end: 0;
19
46
  display: grid;
20
- row-gap: var(--s-unit);
21
- inline-size: min(26rem, 100% - 2 * var(--s-margin));
47
+ inline-size: min(26rem, 100%);
22
48
 
23
49
  & > :global(.s-ui-notice) {
24
- /* Up from under the bottom of the window. */
25
- transition: translate var(--s-move) var(--s-ease);
50
+ max-inline-size: none;
51
+ /*
52
+ * It turns in on the window's edge, as a small door does: from a
53
+ * quarter of a turn out of the window, where none of it is seen, to
54
+ * flat. It is seen from in front of the middle of the window.
55
+ */
56
+ transform-origin: 100% 50%;
57
+ transition: transform var(--s-travel) var(--s-glide);
26
58
 
27
59
  @starting-style {
28
- translate: 0 calc(100% + 6 * var(--s-unit));
60
+ transform: translateX(-50vi) perspective(150vmax) translateX(50vi) rotateY(90deg);
29
61
  }
30
62
  }
63
+
64
+ /* The rule between one toast and the next: a hairline across the top of every toast but the first. It is drawn on the toast, so it turns with it. */
65
+ & > :global(.s-ui-notice) + :global(.s-ui-notice) {
66
+ position: relative;
67
+
68
+ &::before {
69
+ content: "";
70
+ position: absolute;
71
+ inset-block-start: 0;
72
+ inset-inline: 0;
73
+ block-size: var(--s-hair);
74
+ background: color-mix(in oklch, var(--s-fg) 28%, transparent);
75
+ }
76
+ }
77
+ }
78
+
79
+ /* The picture of a toast that was taken away, where the toast was: the script turns it out. It is not a toast any more. */
80
+ .toast-gone {
81
+ position: absolute;
82
+ max-inline-size: none;
83
+ transform-origin: 100% 50%;
84
+ pointer-events: none;
31
85
  }
32
86
  }
33
87
 
88
+ /* In a change of view a toast is over the views that turn, as it is over everything. */
89
+ ::view-transition-group(s-ui-toasts) {
90
+ z-index: 2;
91
+ }
92
+
34
93
  @media print {
35
94
  .toasts {
36
95
  display: none;
@@ -1,4 +1,5 @@
1
1
  declare const styles: {
2
+ readonly "toast-gone": string;
2
3
  readonly "toasts": string;
3
4
  readonly "toasts-list": string;
4
5
  };
@@ -1,16 +1,157 @@
1
1
  /**
2
- * `toasts`: what just happened, said at the bottom of the window.
2
+ * `toasts`: what just happened, said in the top corner of the window.
3
3
  *
4
4
  * @since 0.4.0
5
5
  */
6
+ import { Effect, Stream } from "effect"
7
+ import { Component, Mount } from "effect/ui"
6
8
  import type { Html } from "effect/ui/html"
7
9
  import { type Child, contents as inner, node, type Node } from "../../Node.ts"
8
10
  import styles from "./toasts.module.css"
9
11
 
12
+ /** How a toast stands when it is out: a quarter of a turn out of the window, on the window's edge, seen from in front of the middle of the window. The stylesheet says the same. */
13
+ const out = "translateX(-50vi) perspective(150vmax) translateX(50vi) rotateY(90deg)"
14
+
15
+ /** A time of the stylesheet, such as `260ms` or `0s`, in milliseconds. */
16
+ const millisecondsOf = (time: string): number => {
17
+ const amount = Number.parseFloat(time)
18
+ if (Number.isNaN(amount)) return 0
19
+ return time.trim().endsWith("ms") ? amount : amount * 1000
20
+ }
21
+
22
+ /**
23
+ * Turns a toast out when it is taken away. The stylesheet turns one in,
24
+ * but it can do nothing for one that is no longer there: the Model takes a
25
+ * toast away at once. So where each toast is, is kept here, and when one
26
+ * goes, a picture of it is put where it was and turned out of the window
27
+ * the way it came in. The picture says nothing and takes no press, and is
28
+ * gone when it is out.
29
+ *
30
+ * The toasts under the one that goes do not come up at once: they stay
31
+ * where they are for as long as it takes to turn out, and then they move
32
+ * up into its place.
33
+ */
34
+ const TurnOutWhatGoes = Mount.make("TurnOutWhatGoes", { args: {} }, (list: HTMLElement) =>
35
+ Stream.callback<void>(() =>
36
+ Effect.acquireRelease(
37
+ Effect.sync(() => {
38
+ const places = new Map<globalThis.Node, { left: number; top: number; width: number; height: number }>()
39
+ const look = () => {
40
+ for (const toast of list.children) {
41
+ if (!(toast instanceof HTMLElement)) continue
42
+ // Where it is laid out, not where it is drawn: one that is turning in is drawn somewhere else.
43
+ places.set(toast, {
44
+ left: list.offsetLeft + toast.offsetLeft,
45
+ top: list.offsetTop + toast.offsetTop,
46
+ width: toast.offsetWidth,
47
+ height: toast.offsetHeight
48
+ })
49
+ }
50
+ }
51
+ const leave = (gone: globalThis.Node, under: globalThis.Node | null) => {
52
+ const at = places.get(gone)
53
+ places.delete(gone)
54
+ const corner = list.parentElement
55
+ const style = getComputedStyle(list)
56
+ const time = millisecondsOf(style.getPropertyValue("--s-travel"))
57
+ const move = millisecondsOf(style.getPropertyValue("--s-move"))
58
+ if (at === undefined || corner === null || !(time > 0)) return
59
+ // Those under it are laid out in its place already. They are drawn where they were until it is out, and then move up.
60
+ for (let toast = under; toast !== null; toast = toast.nextSibling) {
61
+ if (!(toast instanceof HTMLElement)) continue
62
+ const down = `0 ${at.height}px`
63
+ toast.animate(
64
+ [
65
+ { translate: down, easing: "linear" },
66
+ { translate: down, offset: time / (time + move), easing: "cubic-bezier(0.2, 0, 0, 1)" },
67
+ { translate: "0 0" }
68
+ ],
69
+ { duration: time + move }
70
+ )
71
+ }
72
+ const picture = gone.cloneNode(true)
73
+ if (!(picture instanceof HTMLElement)) return
74
+ picture.inert = true
75
+ picture.setAttribute("aria-hidden", "true")
76
+ picture.classList.add(styles["toast-gone"])
77
+ picture.style.setProperty("left", `${at.left}px`)
78
+ picture.style.setProperty("top", `${at.top}px`)
79
+ picture.style.setProperty("width", `${at.width}px`)
80
+ picture.style.setProperty("height", `${at.height}px`)
81
+ corner.append(picture)
82
+ const turn = picture.animate([{ transform: "none" }, { transform: out }], {
83
+ duration: time,
84
+ easing: "cubic-bezier(0.6, 0, 0.2, 1)",
85
+ fill: "forwards"
86
+ })
87
+ turn.onfinish = () => picture.remove()
88
+ turn.oncancel = () => picture.remove()
89
+ }
90
+ const changed = new MutationObserver((records) => {
91
+ for (const record of records) record.removedNodes.forEach((gone) => leave(gone, record.nextSibling))
92
+ look()
93
+ })
94
+ const resized = new ResizeObserver(look)
95
+ changed.observe(list, { childList: true })
96
+ resized.observe(list)
97
+ look()
98
+ return () => {
99
+ changed.disconnect()
100
+ resized.disconnect()
101
+ }
102
+ }),
103
+ (stop) => Effect.sync(stop)
104
+ )
105
+ ).pipe(Stream.runDrain, Effect.as(Component.noop))
106
+ )
107
+
108
+ /**
109
+ * Keeps the toasts over everything, whatever else is in the window. A sheet
110
+ * and a dialog are in the browser's top layer, which is over the whole
111
+ * page, and in that layer the last thing to come in is over the others.
112
+ * So the toasts are put in the top layer too, and put in again, last,
113
+ * every time something else comes into it or the window. Nothing is seen
114
+ * of that: they are taken out and put back before the window is drawn.
115
+ */
116
+ const StayOverEverything = Mount.make("StayOverEverything", { args: {} }, (corner: HTMLElement) =>
117
+ Stream.callback<void>(() =>
118
+ Effect.acquireRelease(
119
+ Effect.sync(() => {
120
+ const rise = () => {
121
+ if (!corner.isConnected) return
122
+ if (corner.matches(":popover-open")) corner.hidePopover()
123
+ corner.showPopover()
124
+ }
125
+ // What opens says so, a dialog by its `open` and a popover by its own event. The toasts' own coming and going is not news.
126
+ const opened = (event: Event) => {
127
+ if (event.target !== corner) rise()
128
+ }
129
+ const dialogs = new MutationObserver((records) => {
130
+ if (records.some((record) => record.target !== corner)) rise()
131
+ })
132
+ dialogs.observe(document.body, { attributes: true, attributeFilter: ["open"], subtree: true })
133
+ window.addEventListener("toggle", opened, { capture: true })
134
+ rise()
135
+ return () => {
136
+ dialogs.disconnect()
137
+ window.removeEventListener("toggle", opened, { capture: true })
138
+ }
139
+ }),
140
+ (stop) => Effect.sync(stop)
141
+ )
142
+ ).pipe(Stream.runDrain, Effect.as(Component.noop))
143
+ )
144
+
10
145
  export const toasts = <Msg>(h: Html.H<Msg>) => ({
11
146
  /**
12
- * What just happened, said at the bottom of the window. Its children
13
- * are `s.notice`s the Model holds. Make it the last child of the page.
147
+ * What just happened, said in the top corner of the window, at the end
148
+ * of the line: under a bar along the top, and against the window's edge.
149
+ * Its children are `s.notice`s the Model holds, one under another with
150
+ * only a hairline between them. A toast turns in on the window's edge, as
151
+ * a small door does, and turns out the same way when the Model takes it
152
+ * away. They are over everything else in the window, always: over a
153
+ * sheet, over a dialog, and over whatever is turning. Make it the last
154
+ * child of the page.
14
155
  */
15
156
  toasts: <R = never>(
16
157
  options: { readonly label: string },
@@ -21,6 +162,9 @@ export const toasts = <Msg>(h: Html.H<Msg>) => ({
21
162
  .class(styles.toasts)
22
163
  .attr("role", "region")
23
164
  .attr("aria-label", options.label)
24
- .children(h.div.class(styles["toasts-list"]).children(inner(children)))
165
+ // In the browser's top layer, which is the only place that is over a modal dialog. It is never closed by a press outside it.
166
+ .attr("popover", "manual")
167
+ .onMount(StayOverEverything({}))
168
+ .children(h.div.class(styles["toasts-list"]).onMount(TurnOutWhatGoes({})).children(inner(children)))
25
169
  )
26
170
  })