@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,13 +1,15 @@
1
1
  /**
2
- * `flap`: a readout that rolls to a new value.
2
+ * `flap`: a split-flap readout, as on the departure board of an airport.
3
3
  *
4
4
  * @since 0.4.0
5
5
  */
6
+ import { Effect, Schema, Stream } from "effect"
7
+ import { Component, Mount } from "effect/ui"
6
8
  import type { Html } from "effect/ui/html"
7
9
  import { node, type Node } from "../../Node.ts"
8
10
  import styles from "./flap.module.css"
9
11
 
10
- /** The glyphs on the reel of a split-flap cell, in the order it rolls through them, each with its class. */
12
+ /** The glyphs on the drum of a split-flap cell, in the order its flaps fall, each with its class. */
11
13
  const reel = [
12
14
  ["\u00a0", styles["g-0"]],
13
15
  ["0", styles["g-1"]],
@@ -52,13 +54,125 @@ const reel = [
52
54
  [".", styles["g-40"]]
53
55
  ] as const
54
56
 
57
+ /** Where on the drum the figures are: from the first of them to the last. */
58
+ const figures = { first: 1, last: 10 } as const
59
+ const isFigure = (index: number): boolean => index >= figures.first && index <= figures.last
60
+
61
+ /**
62
+ * The glyph whose flap falls next. A cell that goes from a figure to a
63
+ * figure has a drum of figures only, as the cells for a time or a number
64
+ * have on a real board: after 9 is 0. Any other cell has the whole drum,
65
+ * and after its last glyph is its first.
66
+ */
67
+ const after = (from: number, to: number): number =>
68
+ isFigure(from) && isFigure(to) ? (from === figures.last ? figures.first : from + 1) : (from + 1) % reel.length
69
+
70
+ /** How long one flap takes to fall, in milliseconds: the time a part of a control takes, which is none for anyone who asks for reduced motion. */
71
+ const fallOf = (cell: HTMLElement): number => {
72
+ const time = getComputedStyle(cell).getPropertyValue("--s-quick").trim()
73
+ const amount = Number.parseFloat(time)
74
+ if (Number.isNaN(amount)) return 0
75
+ return time.endsWith("ms") ? amount : amount * 1000
76
+ }
77
+
78
+ /**
79
+ * Turns the drum of one cell, as the drum of a split-flap board turns. A
80
+ * drum turns one way only, so the cell gets to a new glyph by way of every
81
+ * glyph after the one it shows, and round past the last to the first: from
82
+ * 7 to 6 is by way of 8, 9 and 0 to 5. For
83
+ * each of them one flap falls: it is hinged on the line across the middle
84
+ * of the cell, it has the top half of the glyph it leaves on its front and
85
+ * the bottom half of the next one on its back, and it falls from over the
86
+ * top half to over the bottom half, faster as it goes. Behind it is the top
87
+ * half of the next glyph, and under it the bottom half of the one it
88
+ * leaves. It is in shade when it is edge on, and in the light when it lies
89
+ * flat. Each cell turns by itself, so the cells of a readout come to rest
90
+ * one after another.
91
+ *
92
+ * What each face shows is said here, on the face, and not by the cell's
93
+ * class: the class changes at once when the value does, and the faces must
94
+ * not. Where this has not run, the class says it.
95
+ */
96
+ const TurnTheDrum = Mount.make("TurnTheDrum", { args: { to: Schema.Number } }, (cell: HTMLElement, _args, changes) => {
97
+ const part = (name: string) => cell.querySelector<HTMLElement>(`.${name}`)
98
+ const top = part(styles["flap-top"])
99
+ const bottom = part(styles["flap-bottom"])
100
+ const leaf = part(styles["flap-leaf"])
101
+ const front = part(styles["flap-front"])
102
+ const back = part(styles["flap-back"])
103
+ const say = (face: HTMLElement | null, index: number) =>
104
+ face?.style.setProperty("--s-ui-face", JSON.stringify(reel[index]?.[0] ?? reel[0][0]))
105
+ // In shade edge on, in the light flat: one flat colour at a time, never a gradient.
106
+ const lit = "var(--s-fg)"
107
+ const shaded = "color-mix(in oklch, var(--s-fg) 64%, var(--s-bg))"
108
+ let shown: number | undefined
109
+ let target = 0
110
+ let turning = false
111
+
112
+ const rest = (at: number) => {
113
+ turning = false
114
+ for (const face of [top, bottom, front, back]) say(face, at)
115
+ leaf?.style.setProperty("visibility", "hidden")
116
+ }
117
+ const turn = (): void => {
118
+ if (shown === undefined || shown === target) return rest(target)
119
+ const time = fallOf(cell)
120
+ if (leaf === null || !(time > 0)) {
121
+ shown = target
122
+ return rest(target)
123
+ }
124
+ turning = true
125
+ const from = shown
126
+ const next = after(from, target)
127
+ say(top, next)
128
+ say(bottom, from)
129
+ say(front, from)
130
+ say(back, next)
131
+ leaf.style.setProperty("visibility", "visible")
132
+ const timing = { duration: time, easing: "ease-in" }
133
+ front?.animate(
134
+ [{ backgroundColor: lit }, { backgroundColor: shaded, offset: 0.5 }, { backgroundColor: shaded }],
135
+ timing
136
+ )
137
+ back?.animate(
138
+ [{ backgroundColor: shaded }, { backgroundColor: shaded, offset: 0.5 }, { backgroundColor: lit }],
139
+ timing
140
+ )
141
+ const fall = leaf.animate([{ transform: "rotateX(0deg)" }, { transform: "rotateX(-180deg)" }], timing)
142
+ fall.onfinish = () => {
143
+ shown = next
144
+ turn()
145
+ }
146
+ fall.oncancel = () => {
147
+ shown = target
148
+ rest(target)
149
+ }
150
+ }
151
+
152
+ return Stream.runForEach(changes, ({ to }) =>
153
+ Effect.sync(() => {
154
+ target = to
155
+ // The first time it shows what it was made with, and nothing falls.
156
+ if (shown === undefined) {
157
+ shown = to
158
+ rest(to)
159
+ } else if (!turning) turn()
160
+ })
161
+ ).pipe(Effect.as(Component.noop))
162
+ })
163
+
55
164
  export const flap = <Msg>(h: Html.H<Msg>) => ({
56
165
  /**
57
- * A readout of the kind a split-flap board gives: numbers and capital
58
- * letters that roll to a new value through every glyph between. For a
59
- * value that changes while it is watched, such as minutes, a count, or
60
- * where the window is. Keep the text the same length, so each cell keeps
61
- * its place. Anything not on the reel shows as a blank.
166
+ * A readout of the kind the departure board of an airport gives: numbers
167
+ * and capital letters, each in a cell of split flaps. A cell gets to a
168
+ * new glyph as a real one does: its flaps fall one after another, through
169
+ * every glyph on the drum after the one it shows, until the right one is
170
+ * up. The drum turns one way only, so from 7 to 6 is nearly all the way
171
+ * round. A cell that goes from a figure to a figure has a drum of the
172
+ * ten figures; any other has every glyph. Each cell turns by itself, and they come to rest one after
173
+ * another. For a value that changes while it is watched, such as minutes,
174
+ * a count, or a gate. Keep the text the same length, so each cell keeps
175
+ * its place. Anything not on the drum shows as a blank.
62
176
  */
63
177
  flap: (text: string): Node<"inline", Msg> =>
64
178
  node(
@@ -67,12 +181,25 @@ export const flap = <Msg>(h: Html.H<Msg>) => ({
67
181
  .attr("role", "img")
68
182
  .attr("aria-label", text)
69
183
  .children(
70
- [...text.toUpperCase().replaceAll(" ", "\u00a0")].map((glyph) =>
71
- h.span
72
- .class(styles["flap-cell"], reel.find(([on]) => on === glyph)?.[1] ?? reel[0][1])
73
- .attr("aria-hidden", "true")
74
- .children(h.span.class(styles["flap-reel"]).children(reel.map(([on]) => h.span.children(on))))
75
- )
184
+ [...text.toUpperCase().replaceAll(" ", "\u00a0")].map((glyph) => {
185
+ const at = Math.max(
186
+ 0,
187
+ reel.findIndex(([on]) => on === glyph)
188
+ )
189
+ const face = (name: string) => h.span.class(styles["flap-face"], name)
190
+ return (
191
+ h.span
192
+ .class(styles["flap-cell"], reel[at]?.[1] ?? reel[0][1])
193
+ .attr("aria-hidden", "true")
194
+ .onMount(TurnTheDrum({ to: at }))
195
+ // The two halves that are still, and between them the flap that falls, with its two sides.
196
+ .children(
197
+ face(styles["flap-top"]),
198
+ face(styles["flap-bottom"]),
199
+ h.span.class(styles["flap-leaf"]).children(face(styles["flap-front"]), face(styles["flap-back"]))
200
+ )
201
+ )
202
+ })
76
203
  )
77
204
  )
78
205
  })
@@ -2,44 +2,95 @@
2
2
 
3
3
  @layer standard.ui {
4
4
  /*
5
- * Neither is a layer over the page. A sheet is the place next to this one
6
- * on the canvas: the window moves over to it, so the page slides out by
7
- * exactly as much as the sheet slides in, and back again when the sheet
8
- * closes. A dialog comes down into the window from above. Behind a sheet
9
- * nothing is dimmed: the page has moved aside. Behind a dialog the page
10
- * steps back, under a veil of its own ground. And nothing fades: where
11
- * things are says what is going on. Each is told apart from the page by
12
- * its ground: a sheet is a step from the page's, a dialog is the accent.
5
+ * Both are in front of the page. With no navigator, a sheet comes in
6
+ * from the side of the window, and a dialog comes down into it from
7
+ * above. Behind either, a
8
+ * page with a navigator turns away on it, as a door turns on its post,
9
+ * and what is further back takes more of the page's ground: the
10
+ * navigator's stylesheet does that. A page with no navigator has
11
+ * nothing to turn on: there it slides aside for a sheet, by as much as
12
+ * the sheet slides in, and steps back behind a dialog under a veil of
13
+ * its own ground. Each is told apart from the page by its ground: a
14
+ * sheet is a step from the page's, a dialog is the accent.
13
15
  */
14
16
 
15
- .modal {
17
+ /*
18
+ * The `dialog` element is a frame, and nothing of it is seen. It is the
19
+ * part of the window that is not the navigator's, and what is in it is
20
+ * placed in that: at rest, a sheet or a dialog is beside the navigator's
21
+ * bar and never over it. While it turns in or out it is over everything,
22
+ * the navigator too, as a modal `dialog` is: nothing is cut off it. With
23
+ * no navigator the frame is the whole window.
24
+ */
25
+ .modal-frame {
16
26
  position: fixed;
27
+ inset: var(--s-ui-clear-top, 0px) 0 var(--s-ui-clear-bottom, 0px) var(--s-ui-clear-start, 0px);
28
+ inline-size: auto;
29
+ block-size: auto;
17
30
  max-inline-size: none;
18
31
  max-block-size: none;
19
- padding: calc(3 * var(--s-unit));
20
- background: var(--s-bg);
21
- color: var(--s-fg);
22
- overflow-y: auto;
23
- overscroll-behavior: contain;
32
+ background: transparent;
33
+ overflow: visible;
34
+ /* A press in the frame, outside what is in it, is a press outside: it goes past the frame. */
35
+ pointer-events: none;
36
+ /* It stays for as long as what is in it takes to leave. */
24
37
  transition:
25
- translate var(--s-travel) var(--s-glide),
26
38
  display var(--s-travel) allow-discrete,
27
39
  overlay var(--s-travel) allow-discrete;
28
40
 
29
41
  &[open] {
30
- display: grid;
31
- grid-template-columns: minmax(0, 1fr);
32
- align-content: start;
33
- row-gap: calc(3 * var(--s-unit));
34
- translate: 0 0;
42
+ display: block;
35
43
  }
36
44
 
37
- /* It takes presses meant for the page, and shows nothing. */
45
+ /* It shows nothing. */
38
46
  &::backdrop {
39
47
  background: transparent;
40
48
  }
41
49
  }
42
50
 
51
+ .modal {
52
+ position: absolute;
53
+ display: grid;
54
+ grid-template-columns: minmax(0, 1fr);
55
+ align-content: start;
56
+ row-gap: calc(3 * var(--s-unit));
57
+ padding: calc(3 * var(--s-unit));
58
+ background: var(--s-bg);
59
+ color: var(--s-fg);
60
+ overflow-y: auto;
61
+ overscroll-behavior: contain;
62
+ pointer-events: auto;
63
+ transition: translate var(--s-travel) var(--s-glide);
64
+
65
+ [open] > & {
66
+ translate: 0 0;
67
+ }
68
+ }
69
+
70
+ /*
71
+ * With a navigator, neither slides in. Each is the next leaf of the
72
+ * door: it turns in on the navigator, from a quarter of a turn away,
73
+ * where it stands out of the window and none of it is seen, and turns
74
+ * out again the same way. The navigator says where its post is and
75
+ * how a leaf stands before it comes in; a sheet and a dialog each say
76
+ * where that post is from their own corner.
77
+ */
78
+ :global(.s-ui-shell) .modal {
79
+ transform-origin: var(--s-ui-post-x) var(--s-ui-post-y);
80
+ transform: var(--s-ui-flip);
81
+ transition: transform var(--s-travel) var(--s-glide);
82
+
83
+ [open] > & {
84
+ transform: none;
85
+ }
86
+
87
+ @starting-style {
88
+ [open] > & {
89
+ transform: var(--s-ui-flip);
90
+ }
91
+ }
92
+ }
93
+
43
94
  .modal-head {
44
95
  display: grid;
45
96
  grid-template-columns: minmax(0, 1fr) auto;
@@ -60,7 +111,7 @@
60
111
  }
61
112
 
62
113
  @media print {
63
- .modal {
114
+ .modal-frame {
64
115
  display: none;
65
116
  }
66
117
  }
@@ -1,6 +1,7 @@
1
1
  declare const styles: {
2
2
  readonly "modal": string;
3
3
  readonly "modal-body": string;
4
+ readonly "modal-frame": string;
4
5
  readonly "modal-head": string;
5
6
  readonly "modal-title": string;
6
7
  };
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * What a `sheet` and a `dialog` share: a modal `dialog` element with a
3
- * title and the button that closes it.
3
+ * title and the button that closes it. The element itself is a frame that
4
+ * is not seen: the part of the window that is not the navigator's. So what
5
+ * is in it is never over the navigator, though a modal `dialog` is over
6
+ * everything else there is.
4
7
  *
5
8
  * @since 0.4.0
6
9
  */
@@ -28,7 +31,7 @@ export const modal = <Msg, R>(
28
31
  const id = h.id(`s-ui-${name}-title`)
29
32
  return (
30
33
  h.dialog
31
- .class(styles.modal, ...look)
34
+ .class(styles["modal-frame"])
32
35
  .attr("role", options.alert === true ? "alertdialog" : undefined)
33
36
  .attr("aria-labelledby", id)
34
37
  // A question that must be answered isn't dismissed by a press outside it.
@@ -36,20 +39,23 @@ export const modal = <Msg, R>(
36
39
  .modal(options.open)
37
40
  .on("cancel", options.close.onPress)
38
41
  .children(
39
- h.div
40
- .class(styles["modal-head"])
41
- .children(
42
- h.h2.class(styles["modal-title"]).attr("id", id).children(options.title),
43
- content(
44
- button(h).button(
45
- { kind: "secondary", icon: "close", onClick: options.close.onPress },
46
- options.close.label
42
+ // The `dialog` element is only a frame: the part of the window that is not the navigator's. What is seen is this, inside it.
43
+ h.div.class(styles.modal, ...look).children(
44
+ h.div
45
+ .class(styles["modal-head"])
46
+ .children(
47
+ h.h2.class(styles["modal-title"]).attr("id", id).children(options.title),
48
+ content(
49
+ button(h).button(
50
+ { kind: "secondary", icon: "close", onClick: options.close.onPress },
51
+ options.close.label
52
+ )
47
53
  )
48
- )
49
- ),
50
- // Its own box only where a sheet needs one to scroll in; everywhere else its children are laid out as the dialog's own.
51
- h.div.class(styles["modal-body"]).children(inner(children)),
52
- foot
54
+ ),
55
+ // Its own box only where a sheet needs one to scroll in; everywhere else its children are laid out as the dialog's own.
56
+ h.div.class(styles["modal-body"]).children(inner(children)),
57
+ foot
58
+ )
53
59
  )
54
60
  )
55
61
  }