claymorph-ui 0.0.0-stage → 0.4.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 (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -2
  3. package/dist/attach.d.ts +115 -0
  4. package/dist/attach.js +328 -0
  5. package/dist/attach.js.map +1 -0
  6. package/dist/clay.css +1648 -0
  7. package/dist/color.d.ts +5 -0
  8. package/dist/color.js +44 -0
  9. package/dist/color.js.map +1 -0
  10. package/dist/components/action-button.d.ts +31 -0
  11. package/dist/components/action-button.js +158 -0
  12. package/dist/components/action-button.js.map +1 -0
  13. package/dist/components/bars.d.ts +33 -0
  14. package/dist/components/bars.js +135 -0
  15. package/dist/components/bars.js.map +1 -0
  16. package/dist/components/button.d.ts +10 -0
  17. package/dist/components/button.js +36 -0
  18. package/dist/components/button.js.map +1 -0
  19. package/dist/components/card.d.ts +24 -0
  20. package/dist/components/card.js +139 -0
  21. package/dist/components/card.js.map +1 -0
  22. package/dist/components/controls.d.ts +54 -0
  23. package/dist/components/controls.js +310 -0
  24. package/dist/components/controls.js.map +1 -0
  25. package/dist/components/forms.d.ts +41 -0
  26. package/dist/components/forms.js +266 -0
  27. package/dist/components/forms.js.map +1 -0
  28. package/dist/components/group.d.ts +26 -0
  29. package/dist/components/group.js +180 -0
  30. package/dist/components/group.js.map +1 -0
  31. package/dist/components/overlays.d.ts +89 -0
  32. package/dist/components/overlays.js +383 -0
  33. package/dist/components/overlays.js.map +1 -0
  34. package/dist/components/popups.d.ts +55 -0
  35. package/dist/components/popups.js +308 -0
  36. package/dist/components/popups.js.map +1 -0
  37. package/dist/components/slide.d.ts +34 -0
  38. package/dist/components/slide.js +234 -0
  39. package/dist/components/slide.js.map +1 -0
  40. package/dist/components/tabs.d.ts +20 -0
  41. package/dist/components/tabs.js +105 -0
  42. package/dist/components/tabs.js.map +1 -0
  43. package/dist/config.d.ts +48 -0
  44. package/dist/config.js +50 -0
  45. package/dist/config.js.map +1 -0
  46. package/dist/element.d.ts +39 -0
  47. package/dist/element.js +135 -0
  48. package/dist/element.js.map +1 -0
  49. package/dist/engine.d.ts +91 -0
  50. package/dist/engine.js +454 -0
  51. package/dist/engine.js.map +1 -0
  52. package/dist/entries/action-button.d.ts +8 -0
  53. package/dist/entries/action-button.js +8 -0
  54. package/dist/entries/action-button.js.map +1 -0
  55. package/dist/entries/avatar.d.ts +8 -0
  56. package/dist/entries/avatar.js +8 -0
  57. package/dist/entries/avatar.js.map +1 -0
  58. package/dist/entries/badge.d.ts +7 -0
  59. package/dist/entries/badge.js +7 -0
  60. package/dist/entries/badge.js.map +1 -0
  61. package/dist/entries/button-group.d.ts +9 -0
  62. package/dist/entries/button-group.js +9 -0
  63. package/dist/entries/button-group.js.map +1 -0
  64. package/dist/entries/button.d.ts +8 -0
  65. package/dist/entries/button.js +8 -0
  66. package/dist/entries/button.js.map +1 -0
  67. package/dist/entries/card.d.ts +7 -0
  68. package/dist/entries/card.js +7 -0
  69. package/dist/entries/card.js.map +1 -0
  70. package/dist/entries/checkbox.d.ts +9 -0
  71. package/dist/entries/checkbox.js +9 -0
  72. package/dist/entries/checkbox.js.map +1 -0
  73. package/dist/entries/dialog.d.ts +8 -0
  74. package/dist/entries/dialog.js +8 -0
  75. package/dist/entries/dialog.js.map +1 -0
  76. package/dist/entries/input.d.ts +9 -0
  77. package/dist/entries/input.js +9 -0
  78. package/dist/entries/input.js.map +1 -0
  79. package/dist/entries/menu.d.ts +8 -0
  80. package/dist/entries/menu.js +8 -0
  81. package/dist/entries/menu.js.map +1 -0
  82. package/dist/entries/meter.d.ts +8 -0
  83. package/dist/entries/meter.js +8 -0
  84. package/dist/entries/meter.js.map +1 -0
  85. package/dist/entries/popover.d.ts +8 -0
  86. package/dist/entries/popover.js +8 -0
  87. package/dist/entries/popover.js.map +1 -0
  88. package/dist/entries/progress.d.ts +8 -0
  89. package/dist/entries/progress.js +8 -0
  90. package/dist/entries/progress.js.map +1 -0
  91. package/dist/entries/radio.d.ts +9 -0
  92. package/dist/entries/radio.js +9 -0
  93. package/dist/entries/radio.js.map +1 -0
  94. package/dist/entries/segmented.d.ts +8 -0
  95. package/dist/entries/segmented.js +8 -0
  96. package/dist/entries/segmented.js.map +1 -0
  97. package/dist/entries/select.d.ts +8 -0
  98. package/dist/entries/select.js +8 -0
  99. package/dist/entries/select.js.map +1 -0
  100. package/dist/entries/slide-confirm.d.ts +8 -0
  101. package/dist/entries/slide-confirm.js +8 -0
  102. package/dist/entries/slide-confirm.js.map +1 -0
  103. package/dist/entries/slider.d.ts +9 -0
  104. package/dist/entries/slider.js +9 -0
  105. package/dist/entries/slider.js.map +1 -0
  106. package/dist/entries/switch.d.ts +9 -0
  107. package/dist/entries/switch.js +9 -0
  108. package/dist/entries/switch.js.map +1 -0
  109. package/dist/entries/tabs.d.ts +8 -0
  110. package/dist/entries/tabs.js +8 -0
  111. package/dist/entries/tabs.js.map +1 -0
  112. package/dist/entries/toast.d.ts +9 -0
  113. package/dist/entries/toast.js +8 -0
  114. package/dist/entries/toast.js.map +1 -0
  115. package/dist/entries/toggle.d.ts +8 -0
  116. package/dist/entries/toggle.js +8 -0
  117. package/dist/entries/toggle.js.map +1 -0
  118. package/dist/entries/tooltip.d.ts +8 -0
  119. package/dist/entries/tooltip.js +8 -0
  120. package/dist/entries/tooltip.js.map +1 -0
  121. package/dist/highlight.d.ts +26 -0
  122. package/dist/highlight.js +100 -0
  123. package/dist/highlight.js.map +1 -0
  124. package/dist/index.d.ts +29 -0
  125. package/dist/index.js +37 -0
  126. package/dist/shared.d.ts +28 -0
  127. package/dist/shared.js +80 -0
  128. package/dist/shared.js.map +1 -0
  129. package/dist/spring.d.ts +14 -0
  130. package/dist/spring.js +50 -0
  131. package/dist/spring.js.map +1 -0
  132. package/dist/surface.d.ts +88 -0
  133. package/dist/surface.js +240 -0
  134. package/dist/surface.js.map +1 -0
  135. package/package.json +140 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lauro Guedes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,78 @@
1
- # Temporary Holding Version
1
+ # claymorph-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Soft clay web components. One WebGL2 shader draws every surface, with springs that swell, squash and melt parts into each other; [ui-sdk](https://ui-sdk.dev) gives them their keyboard, focus and ARIA. Without WebGL2, plain CSS clay takes over.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install claymorph-ui @ui-sdk/web @ui-sdk/core
9
+ ```
10
+
11
+ `@ui-sdk/web` and `@ui-sdk/core` are peer dependencies, so your app and Clay share one copy.
12
+
13
+ ## Use
14
+
15
+ Load the styles once, then import the elements you use. Each import registers its element and the ui-sdk parts it wraps.
16
+
17
+ ```ts
18
+ import "@ui-sdk/core/web.css"
19
+ import "claymorph-ui/clay.css"
20
+ import "claymorph-ui/button"
21
+ import "claymorph-ui/select"
22
+ ```
23
+
24
+ ```html
25
+ <clay-button color="teal">
26
+ <ui-button><button>Save</button></ui-button>
27
+ </clay-button>
28
+ ```
29
+
30
+ To register everything at once, import the package itself:
31
+
32
+ ```ts
33
+ import "claymorph-ui"
34
+ ```
35
+
36
+ Only what you import ends up in your bundle: the component modules have no side effects, so a bundler drops the rest.
37
+
38
+ ## Elements
39
+
40
+ | Entry | Element |
41
+ | --- | --- |
42
+ | `claymorph-ui/action-button` | `<clay-action-button>` |
43
+ | `claymorph-ui/avatar` | `<clay-avatar>` |
44
+ | `claymorph-ui/badge` | `<clay-badge>` |
45
+ | `claymorph-ui/button` | `<clay-button>` |
46
+ | `claymorph-ui/button-group` | `<clay-button-group>` |
47
+ | `claymorph-ui/card` | `<clay-card>` |
48
+ | `claymorph-ui/checkbox` | `<clay-checkbox>` |
49
+ | `claymorph-ui/dialog` | `<clay-dialog>` |
50
+ | `claymorph-ui/input` | `<clay-input>` |
51
+ | `claymorph-ui/menu` | `<clay-menu>` |
52
+ | `claymorph-ui/meter` | `<clay-meter>` |
53
+ | `claymorph-ui/popover` | `<clay-popover>` |
54
+ | `claymorph-ui/progress` | `<clay-progress>` |
55
+ | `claymorph-ui/radio` | `<clay-radio>` |
56
+ | `claymorph-ui/segmented` | `<clay-segmented>` |
57
+ | `claymorph-ui/select` | `<clay-select>` |
58
+ | `claymorph-ui/slide-confirm` | `<clay-slide-confirm>` |
59
+ | `claymorph-ui/slider` | `<clay-slider>` |
60
+ | `claymorph-ui/switch` | `<clay-switch>` |
61
+ | `claymorph-ui/tabs` | `<clay-tabs>` |
62
+ | `claymorph-ui/toast` | `<clay-toast-region>`, plus `toast` and `createToaster` |
63
+ | `claymorph-ui/toggle` | `<clay-toggle>` |
64
+ | `claymorph-ui/tooltip` | `<clay-tooltip>` |
65
+
66
+ The package root also exports `CLAY` and `SPRINGS`, the material and motion settings, and `getClayEngine`.
67
+
68
+ ## TypeScript
69
+
70
+ Types ship with the package. Each entry adds its element to `HTMLElementTagNameMap`, so `document.querySelector("clay-select")` is typed as `ClaySelect`.
71
+
72
+ ## Browsers
73
+
74
+ Any browser with WebGL2, the Popover API and CSS nesting draws the clay. Without WebGL2, the CSS fallback keeps every element usable and styled.
75
+
76
+ ## License
77
+
78
+ MIT
@@ -0,0 +1,115 @@
1
+ import type { RGB } from "./color.js";
2
+ import type { ClayShape } from "./engine.js";
3
+ import { type Box } from "./shared.js";
4
+ import { Spring } from "./spring.js";
5
+ import { type ClaySurface, type SurfaceOptions } from "./surface.js";
6
+ interface AttachOptions {
7
+ /** The element whose clay the popup grows out of. */
8
+ trigger: () => HTMLElement | null;
9
+ /** The trigger's corner radius, from its measured box. */
10
+ triggerRadius: (box: Box) => number;
11
+ triggerColor: () => RGB;
12
+ color: () => RGB;
13
+ radius: number;
14
+ bevel: number;
15
+ lift: number;
16
+ /** How far the popup melts into the trigger, from 0, a slight waist, to 1, one body. Asked every frame. */
17
+ fuse?: () => number;
18
+ /** Holds the trigger's clay still while the popup is melted onto it. */
19
+ calm?: (on: boolean) => void;
20
+ /** The popup has tucked back into the trigger. */
21
+ onTuck?: () => void;
22
+ }
23
+ /**
24
+ * How far attached parts melt into each other, in px. Across the small gap they're placed at, it
25
+ * bridges them into one body, deep enough that the edge of one flows into the other instead of
26
+ * shading a line between them.
27
+ */
28
+ declare const GLUE = 30;
29
+ /** How far a part pokes out, in px, before it's fully melted on. */
30
+ declare const GRIP: number;
31
+ /** How far colour runs across the joint, in px, so a button and a popup of different colours blend. */
32
+ declare const BLEND = 9;
33
+ /** Opening overshoots a little, like Roll's bead; tucking back in eases all the way, so it can't flicker. */
34
+ declare const OUT: {
35
+ omega: number;
36
+ zeta: number;
37
+ };
38
+ declare const BACK: {
39
+ omega: number;
40
+ zeta: number;
41
+ };
42
+ /**
43
+ * Closing aims a little past all the way in, so the popup slips into its trigger at a steady pace
44
+ * instead of creeping up on the edge.
45
+ */
46
+ declare const PAST = -0.08;
47
+ /** How far the popup still pokes out, in px, when it counts as back inside and the trigger bounces. */
48
+ declare const TUCKED = 4;
49
+ declare const smooth: (edge0: number, edge1: number, x: number) => number;
50
+ /** Which edge of the trigger a popup comes out of. */
51
+ interface Face {
52
+ vertical: boolean;
53
+ /** 1 out of the bottom or right edge, -1 out of the top or left. */
54
+ sign: 1 | -1;
55
+ }
56
+ declare function faceOf(t: Box, popup: Box): Face;
57
+ /**
58
+ * Where the popup starts: a thin sliver just inside the trigger's edge that faces it. It only ever
59
+ * grows outward from there, so nothing of it shows through the button or climbs up beside it.
60
+ */
61
+ declare function seed(t: Box, popup: Box, face?: Face): Box;
62
+ /** How far a box pokes out past the trigger's facing edge, in px. */
63
+ declare function poke(t: Box, box: Box, face: Face): number;
64
+ /**
65
+ * A popup that grows out of its trigger like Roll's bead: it squeezes out of the button, stays melted
66
+ * onto it while open, and slips back in as it closes, when the button gives a little bounce. It's drawn
67
+ * on the popup, which sits in the top layer, with the trigger as a ghost so the real button shows
68
+ * through; the trigger melts the popup into its own clay too, so the joint has no seam.
69
+ */
70
+ declare class Attachment {
71
+ readonly emerge: Spring;
72
+ private trigger;
73
+ private size;
74
+ private reach;
75
+ private tucked;
76
+ private readonly content;
77
+ private readonly options;
78
+ private readonly surface;
79
+ constructor(content: HTMLElement, options: AttachOptions, surface: () => ClaySurface | undefined);
80
+ /** Whether the popup's clay is out of the trigger at all. */
81
+ get out(): boolean;
82
+ /** Follows the popup opening and closing. Returns a function that stops. */
83
+ connect(): () => void;
84
+ surfaceOptions(): SurfaceOptions;
85
+ private measure;
86
+ /** Where the popup's clay is right now, straight from the spring, and how far it pokes out of the trigger. */
87
+ private place;
88
+ /**
89
+ * The popup's clay, in the popup's coordinates. It wears its own colour all the way: the colour
90
+ * blends across the joint, not over time. The trigger asks for it too, and keeps drawing it after
91
+ * the popup itself is hidden.
92
+ */
93
+ private body;
94
+ private get fuse();
95
+ /**
96
+ * Where the popup meets the trigger, a patch that flattens the clay: the trigger's edge and the
97
+ * popup's would otherwise shade a crease across the joint however deep they melt.
98
+ */
99
+ private seam;
100
+ private shapes;
101
+ /**
102
+ * The popup melted into the trigger's own clay, in the trigger's coordinates, so both draw the same
103
+ * joint and the same colour blend with no seam. It's a ghost there: the popup draws itself, shadow
104
+ * and all, from its own canvas, and a second copy under it would show at its edges.
105
+ */
106
+ joint(host: HTMLElement): ClayShape[];
107
+ }
108
+ /** A `fuse` attribute: a number from 0 to 1, and 0 when it's missing or isn't a number. */
109
+ declare function fuseOf(el: Element): number;
110
+ /**
111
+ * Keeps the popup close enough to its trigger to stay melted on, and closer as they fuse, unless the
112
+ * page chose a gap. Returns a function that fits it again.
113
+ */
114
+ declare function hug(content: HTMLElement, fuse?: () => number): () => void;
115
+ export { Attachment, BACK, BLEND, faceOf, fuseOf, GLUE, GRIP, hug, OUT, PAST, poke, seed, smooth, TUCKED, type AttachOptions };
package/dist/attach.js ADDED
@@ -0,0 +1,328 @@
1
+ import { clamp, lerp, lerpBox, watch } from "./shared.js";
2
+ import { Spring } from "./spring.js";
3
+ import { offsetWithin } from "./surface.js";
4
+ /** How far a part pokes out, in px, before it's fully melted on. */
5
+ var GRIP = 20.1;
6
+ /** Opening overshoots a little, like Roll's bead; tucking back in eases all the way, so it can't flicker. */
7
+ var OUT = {
8
+ omega: 13,
9
+ zeta: .6
10
+ };
11
+ var BACK = {
12
+ omega: 15,
13
+ zeta: 1
14
+ };
15
+ /**
16
+ * Closing aims a little past all the way in, so the popup slips into its trigger at a steady pace
17
+ * instead of creeping up on the edge.
18
+ */
19
+ var PAST = -.08;
20
+ var smooth = (edge0, edge1, x) => {
21
+ const t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
22
+ return t * t * (3 - 2 * t);
23
+ };
24
+ function faceOf(t, popup) {
25
+ const dx = popup.x + popup.w / 2 - (t.x + t.w / 2);
26
+ const dy = popup.y + popup.h / 2 - (t.y + t.h / 2);
27
+ const vertical = Math.abs(dy) / Math.max(t.h + popup.h, 1) >= Math.abs(dx) / Math.max(t.w + popup.w, 1);
28
+ return {
29
+ vertical,
30
+ sign: (vertical ? dy : dx) > 0 ? 1 : -1
31
+ };
32
+ }
33
+ /** How deep into the trigger the popup starts, in px: just enough to melt on, not enough to show through. */
34
+ var INSET = 6;
35
+ /**
36
+ * Where the popup starts: a thin sliver just inside the trigger's edge that faces it. It only ever
37
+ * grows outward from there, so nothing of it shows through the button or climbs up beside it.
38
+ */
39
+ function seed(t, popup, face = faceOf(t, popup)) {
40
+ if (face.vertical) {
41
+ const w = Math.min(t.w, popup.w) * .5;
42
+ return {
43
+ x: clamp(popup.x + popup.w / 2, t.x + w / 2, t.x + t.w - w / 2) - w / 2,
44
+ y: face.sign > 0 ? t.y + t.h - INSET : t.y,
45
+ w,
46
+ h: INSET
47
+ };
48
+ }
49
+ const h = Math.min(t.h, popup.h) * .5;
50
+ const y = clamp(popup.y + popup.h / 2, t.y + h / 2, t.y + t.h - h / 2) - h / 2;
51
+ return {
52
+ x: face.sign > 0 ? t.x + t.w - INSET : t.x,
53
+ y,
54
+ w: INSET,
55
+ h
56
+ };
57
+ }
58
+ /** How far a box pokes out past the trigger's facing edge, in px. */
59
+ function poke(t, box, face) {
60
+ if (face.vertical) return face.sign > 0 ? box.y + box.h - (t.y + t.h) : t.y - box.y;
61
+ return face.sign > 0 ? box.x + box.w - (t.x + t.w) : t.x - box.x;
62
+ }
63
+ /**
64
+ * A popup that grows out of its trigger like Roll's bead: it squeezes out of the button, stays melted
65
+ * onto it while open, and slips back in as it closes, when the button gives a little bounce. It's drawn
66
+ * on the popup, which sits in the top layer, with the trigger as a ghost so the real button shows
67
+ * through; the trigger melts the popup into its own clay too, so the joint has no seam.
68
+ */
69
+ var Attachment = class {
70
+ emerge = new Spring(0);
71
+ trigger = null;
72
+ size = {
73
+ w: 0,
74
+ h: 0
75
+ };
76
+ reach = 40;
77
+ tucked = true;
78
+ content;
79
+ options;
80
+ surface;
81
+ constructor(content, options, surface) {
82
+ this.content = content;
83
+ this.options = options;
84
+ this.surface = surface;
85
+ }
86
+ /** Whether the popup's clay is out of the trigger at all. */
87
+ get out() {
88
+ return !this.tucked;
89
+ }
90
+ /** Follows the popup opening and closing. Returns a function that stops. */
91
+ connect() {
92
+ const content = this.content;
93
+ const sync = () => {
94
+ const open = content.hasAttribute("data-open") && !content.hasAttribute("data-ending-style");
95
+ const surface = this.surface();
96
+ if (open && this.emerge.target <= 0) {
97
+ if (surface) {
98
+ surface.ctx.clearRect(0, 0, surface.canvas.width, surface.canvas.height);
99
+ surface.key = "";
100
+ surface.visible = true;
101
+ }
102
+ this.tucked = false;
103
+ this.options.calm?.(true);
104
+ }
105
+ this.emerge.target = open ? 1 : PAST;
106
+ surface?.invalidate();
107
+ };
108
+ const scroll = () => this.surface()?.invalidate();
109
+ addEventListener("scroll", scroll, {
110
+ passive: true,
111
+ capture: true
112
+ });
113
+ const stop = watch(content, [
114
+ "data-open",
115
+ "data-ending-style",
116
+ "data-side"
117
+ ], sync);
118
+ sync();
119
+ return () => {
120
+ stop();
121
+ removeEventListener("scroll", scroll, { capture: true });
122
+ this.options.calm?.(false);
123
+ };
124
+ }
125
+ surfaceOptions() {
126
+ return {
127
+ swell: false,
128
+ calm: true,
129
+ pad: () => this.reach,
130
+ measure: () => this.measure(),
131
+ step: (dt, still) => {
132
+ const back = this.emerge.target <= 0;
133
+ if (back && !this.tucked && !this.content.getClientRects().length) this.emerge.set(PAST);
134
+ const moving = this.emerge.step(dt, back ? BACK : OUT, still);
135
+ if (back && !this.tucked && (this.place()?.poke ?? 0) <= 4) {
136
+ this.tucked = true;
137
+ this.options.calm?.(false);
138
+ this.options.onTuck?.();
139
+ }
140
+ if (moving || this.content.hasAttribute("data-open")) this.surface().stale = true;
141
+ return moving;
142
+ },
143
+ shapes: () => this.shapes()
144
+ };
145
+ }
146
+ measure() {
147
+ const content = this.content;
148
+ const trigger = this.options.trigger();
149
+ if (!trigger || content.getBoundingClientRect().width === 0) return;
150
+ const t = offsetWithin(trigger, content);
151
+ const last = this.trigger;
152
+ this.trigger = t;
153
+ const w = content.offsetWidth;
154
+ const h = content.offsetHeight;
155
+ this.size = {
156
+ w,
157
+ h
158
+ };
159
+ this.reach = Math.ceil(Math.max(32, -t.x, -t.y, t.x + t.w - w, t.y + t.h - h) + 32);
160
+ if (!last || [
161
+ t.x - last.x,
162
+ t.y - last.y,
163
+ t.w - last.w,
164
+ t.h - last.h
165
+ ].some((d) => Math.abs(d) > .02)) this.surface()?.wake();
166
+ }
167
+ /** Where the popup's clay is right now, straight from the spring, and how far it pokes out of the trigger. */
168
+ place() {
169
+ const t = this.trigger;
170
+ if (!t || !this.size.w) return null;
171
+ const e = clamp(this.emerge.x, 0, 1.15);
172
+ const full = {
173
+ x: 0,
174
+ y: 0,
175
+ w: this.size.w,
176
+ h: this.size.h
177
+ };
178
+ const face = faceOf(t, full);
179
+ const box = lerpBox(seed(t, full, face), full, e);
180
+ return {
181
+ box,
182
+ e,
183
+ poke: poke(t, box, face)
184
+ };
185
+ }
186
+ /**
187
+ * The popup's clay, in the popup's coordinates. It wears its own colour all the way: the colour
188
+ * blends across the joint, not over time. The trigger asks for it too, and keeps drawing it after
189
+ * the popup itself is hidden.
190
+ */
191
+ body() {
192
+ const place = this.place();
193
+ if (!place || place.poke <= 0) return null;
194
+ const { box, e, poke } = place;
195
+ const melt = (30 * (1 + this.fuse) + (1 - Math.min(e, 1)) * 10) * smooth(0, GRIP, poke);
196
+ return {
197
+ shape: {
198
+ ...box,
199
+ radius: this.options.radius,
200
+ color: this.options.color(),
201
+ height: .85,
202
+ bevel: this.options.bevel,
203
+ lift: this.options.lift * Math.min(e, 1),
204
+ melt: Math.max(melt, .01),
205
+ blend: 9
206
+ },
207
+ poke
208
+ };
209
+ }
210
+ get fuse() {
211
+ return clamp(this.options.fuse?.() ?? 0, 0, 1);
212
+ }
213
+ /**
214
+ * Where the popup meets the trigger, a patch that flattens the clay: the trigger's edge and the
215
+ * popup's would otherwise shade a crease across the joint however deep they melt.
216
+ */
217
+ seam(t, shape) {
218
+ const strength = smooth(.3, 1, this.emerge.x);
219
+ if (strength < .01) return null;
220
+ const face = faceOf(t, shape);
221
+ const [tl, tw, sl, sw] = face.vertical ? [
222
+ t.x,
223
+ t.w,
224
+ shape.x,
225
+ shape.w
226
+ ] : [
227
+ t.y,
228
+ t.h,
229
+ shape.y,
230
+ shape.h
231
+ ];
232
+ const lo = Math.max(tl, sl);
233
+ const span = Math.min(tl + tw, sl + sw) - lo;
234
+ const inset = Math.min(16, span / 4);
235
+ const edge = face.vertical ? face.sign > 0 ? t.y + t.h : t.y : face.sign > 0 ? t.x + t.w : t.x;
236
+ const near = face.vertical ? face.sign > 0 ? shape.y : shape.y + shape.h : face.sign > 0 ? shape.x : shape.x + shape.w;
237
+ const toward = face.sign > 0 ? [12, 24] : [24, 12];
238
+ const from = Math.min(edge, near) - toward[0];
239
+ const depth = Math.abs(edge - near) + toward[0] + toward[1];
240
+ const across = {
241
+ at: lo + inset,
242
+ size: Math.max(span - inset * 2, 0)
243
+ };
244
+ return {
245
+ ...face.vertical ? {
246
+ x: across.at,
247
+ y: from,
248
+ w: across.size,
249
+ h: depth
250
+ } : {
251
+ x: from,
252
+ y: across.at,
253
+ w: depth,
254
+ h: across.size
255
+ },
256
+ radius: 10,
257
+ color: shape.color,
258
+ height: 0,
259
+ melt: .01,
260
+ blend: 7,
261
+ flatten: strength
262
+ };
263
+ }
264
+ shapes() {
265
+ const t = this.trigger;
266
+ const body = this.body();
267
+ if (!t || !body) return [];
268
+ const seam = this.seam(t, body.shape);
269
+ return [
270
+ {
271
+ ...t,
272
+ radius: this.options.triggerRadius(t),
273
+ color: this.options.triggerColor(),
274
+ height: 1,
275
+ ghost: true,
276
+ blend: 9
277
+ },
278
+ body.shape,
279
+ ...seam ? [seam] : []
280
+ ];
281
+ }
282
+ /**
283
+ * The popup melted into the trigger's own clay, in the trigger's coordinates, so both draw the same
284
+ * joint and the same colour blend with no seam. It's a ghost there: the popup draws itself, shadow
285
+ * and all, from its own canvas, and a second copy under it would show at its edges.
286
+ */
287
+ joint(host) {
288
+ const t = this.trigger;
289
+ const body = this.body();
290
+ if (!t || !body) return [];
291
+ const { shape } = body;
292
+ const sx = t.w / (host.offsetWidth || t.w) || 1;
293
+ const sy = t.h / (host.offsetHeight || t.h) || 1;
294
+ const local = (s) => ({
295
+ ...s,
296
+ x: (s.x - t.x) / sx,
297
+ y: (s.y - t.y) / sy,
298
+ w: s.w / sx,
299
+ h: s.h / sy
300
+ });
301
+ const seam = this.seam(t, shape);
302
+ return [{
303
+ ...local(shape),
304
+ lift: 0,
305
+ ghost: true
306
+ }, ...seam ? [local(seam)] : []];
307
+ }
308
+ };
309
+ /** A `fuse` attribute: a number from 0 to 1, and 0 when it's missing or isn't a number. */
310
+ function fuseOf(el) {
311
+ const value = parseFloat(el.getAttribute("fuse") ?? "");
312
+ return Number.isFinite(value) ? clamp(value, 0, 1) : 0;
313
+ }
314
+ /**
315
+ * Keeps the popup close enough to its trigger to stay melted on, and closer as they fuse, unless the
316
+ * page chose a gap. Returns a function that fits it again.
317
+ */
318
+ function hug(content, fuse = () => 0) {
319
+ const own = !content.hasAttribute("side-offset");
320
+ const fit = () => {
321
+ if (own) content.setAttribute("side-offset", String(Math.round(lerp(4, 0, fuse()))));
322
+ };
323
+ fit();
324
+ return fit;
325
+ }
326
+ export { Attachment, BACK, GRIP, OUT, PAST, faceOf, fuseOf, hug, poke, seed, smooth };
327
+
328
+ //# sourceMappingURL=attach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attach.js","names":[],"sources":["../../../src/clay/attach.ts"],"sourcesContent":["import type { RGB } from \"./color\"\nimport type { ClayShape } from \"./engine\"\nimport { clamp, lerp, lerpBox, watch, type Box } from \"./shared\"\nimport { Spring } from \"./spring\"\nimport { offsetWithin, type ClaySurface, type SurfaceOptions } from \"./surface\"\n\ninterface AttachOptions {\n /** The element whose clay the popup grows out of. */\n trigger: () => HTMLElement | null\n /** The trigger's corner radius, from its measured box. */\n triggerRadius: (box: Box) => number\n triggerColor: () => RGB\n color: () => RGB\n radius: number\n bevel: number\n lift: number\n /** How far the popup melts into the trigger, from 0, a slight waist, to 1, one body. Asked every frame. */\n fuse?: () => number\n /** Holds the trigger's clay still while the popup is melted onto it. */\n calm?: (on: boolean) => void\n /** The popup has tucked back into the trigger. */\n onTuck?: () => void\n}\n\n/**\n * How far attached parts melt into each other, in px. Across the small gap they're placed at, it\n * bridges them into one body, deep enough that the edge of one flows into the other instead of\n * shading a line between them.\n */\nconst GLUE = 30\n\n/** How far a part pokes out, in px, before it's fully melted on. */\nconst GRIP = GLUE * 0.67\n\n/** How far colour runs across the joint, in px, so a button and a popup of different colours blend. */\nconst BLEND = 9\n\n/** Opening overshoots a little, like Roll's bead; tucking back in eases all the way, so it can't flicker. */\nconst OUT = { omega: 13, zeta: 0.6 }\nconst BACK = { omega: 15, zeta: 1 }\n\n/**\n * Closing aims a little past all the way in, so the popup slips into its trigger at a steady pace\n * instead of creeping up on the edge.\n */\nconst PAST = -0.08\n\n/** How far the popup still pokes out, in px, when it counts as back inside and the trigger bounces. */\nconst TUCKED = 4\n\nconst smooth = (edge0: number, edge1: number, x: number) => {\n const t = clamp((x - edge0) / (edge1 - edge0), 0, 1)\n return t * t * (3 - 2 * t)\n}\n\n/** Which edge of the trigger a popup comes out of. */\ninterface Face {\n vertical: boolean\n /** 1 out of the bottom or right edge, -1 out of the top or left. */\n sign: 1 | -1\n}\n\nfunction faceOf(t: Box, popup: Box): Face {\n const dx = popup.x + popup.w / 2 - (t.x + t.w / 2)\n const dy = popup.y + popup.h / 2 - (t.y + t.h / 2)\n const vertical = Math.abs(dy) / Math.max(t.h + popup.h, 1) >= Math.abs(dx) / Math.max(t.w + popup.w, 1)\n return { vertical, sign: (vertical ? dy : dx) > 0 ? 1 : -1 }\n}\n\n/** How deep into the trigger the popup starts, in px: just enough to melt on, not enough to show through. */\nconst INSET = 6\n\n/**\n * Where the popup starts: a thin sliver just inside the trigger's edge that faces it. It only ever\n * grows outward from there, so nothing of it shows through the button or climbs up beside it.\n */\nfunction seed(t: Box, popup: Box, face = faceOf(t, popup)): Box {\n if (face.vertical) {\n const w = Math.min(t.w, popup.w) * 0.5\n const x = clamp(popup.x + popup.w / 2, t.x + w / 2, t.x + t.w - w / 2) - w / 2\n return { x, y: face.sign > 0 ? t.y + t.h - INSET : t.y, w, h: INSET }\n }\n const h = Math.min(t.h, popup.h) * 0.5\n const y = clamp(popup.y + popup.h / 2, t.y + h / 2, t.y + t.h - h / 2) - h / 2\n return { x: face.sign > 0 ? t.x + t.w - INSET : t.x, y, w: INSET, h }\n}\n\n/** How far a box pokes out past the trigger's facing edge, in px. */\nfunction poke(t: Box, box: Box, face: Face) {\n if (face.vertical) return face.sign > 0 ? box.y + box.h - (t.y + t.h) : t.y - box.y\n return face.sign > 0 ? box.x + box.w - (t.x + t.w) : t.x - box.x\n}\n\n/**\n * A popup that grows out of its trigger like Roll's bead: it squeezes out of the button, stays melted\n * onto it while open, and slips back in as it closes, when the button gives a little bounce. It's drawn\n * on the popup, which sits in the top layer, with the trigger as a ghost so the real button shows\n * through; the trigger melts the popup into its own clay too, so the joint has no seam.\n */\nclass Attachment {\n readonly emerge = new Spring(0)\n private trigger: Box | null = null\n private size = { w: 0, h: 0 }\n private reach = 40\n private tucked = true\n private readonly content: HTMLElement\n private readonly options: AttachOptions\n private readonly surface: () => ClaySurface | undefined\n\n constructor(content: HTMLElement, options: AttachOptions, surface: () => ClaySurface | undefined) {\n this.content = content\n this.options = options\n this.surface = surface\n }\n\n /** Whether the popup's clay is out of the trigger at all. */\n get out() {\n return !this.tucked\n }\n\n /** Follows the popup opening and closing. Returns a function that stops. */\n connect() {\n const content = this.content\n const sync = () => {\n const open = content.hasAttribute(\"data-open\") && !content.hasAttribute(\"data-ending-style\")\n const surface = this.surface()\n if (open && this.emerge.target <= 0) {\n if (surface) {\n // The canvas still holds the popup as it last looked; wipe it before the first frame paints it.\n surface.ctx.clearRect(0, 0, surface.canvas.width, surface.canvas.height)\n surface.key = \"\"\n // An opening popup is on screen: don't wait frames for the visibility observer to say so.\n surface.visible = true\n }\n this.tucked = false\n this.options.calm?.(true)\n }\n this.emerge.target = open ? 1 : PAST\n surface?.invalidate()\n }\n const scroll = () => this.surface()?.invalidate()\n addEventListener(\"scroll\", scroll, { passive: true, capture: true })\n const stop = watch(content, [\"data-open\", \"data-ending-style\", \"data-side\"], sync)\n sync()\n return () => {\n stop()\n removeEventListener(\"scroll\", scroll, { capture: true })\n this.options.calm?.(false)\n }\n }\n\n surfaceOptions(): SurfaceOptions {\n return {\n swell: false,\n // Lit like the trigger, which is calm while they're melted together, so the joint matches.\n calm: true,\n pad: () => this.reach,\n measure: () => this.measure(),\n step: (dt, still) => {\n const back = this.emerge.target <= 0\n // Hidden before it tucked back in: the trigger mustn't go on drawing its side of the joint alone.\n if (back && !this.tucked && !this.content.getClientRects().length) this.emerge.set(PAST)\n const moving = this.emerge.step(dt, back ? BACK : OUT, still)\n if (back && !this.tucked && (this.place()?.poke ?? 0) <= TUCKED) {\n this.tucked = true\n this.options.calm?.(false)\n this.options.onTuck?.()\n }\n // The trigger can still be easing out of its hover swell, and ui-sdk places the popup a frame\n // after it opens: keep measuring both while it's open or moving.\n if (moving || this.content.hasAttribute(\"data-open\")) this.surface()!.stale = true\n return moving\n },\n shapes: () => this.shapes(),\n }\n }\n\n private measure() {\n const content = this.content\n const trigger = this.options.trigger()\n // Closed and hidden: keep the last boxes so the popup can tuck back in.\n if (!trigger || content.getBoundingClientRect().width === 0) return\n const t = offsetWithin(trigger, content)\n const last = this.trigger\n this.trigger = t\n const w = content.offsetWidth\n const h = content.offsetHeight\n this.size = { w, h }\n this.reach = Math.ceil(Math.max(32, -t.x, -t.y, t.x + t.w - w, t.y + t.h - h) + 32)\n // The trigger draws its side of the joint before this runs; give it another frame to catch up.\n const moved = !last || [t.x - last.x, t.y - last.y, t.w - last.w, t.h - last.h].some((d) => Math.abs(d) > 0.02)\n if (moved) this.surface()?.wake()\n }\n\n /** Where the popup's clay is right now, straight from the spring, and how far it pokes out of the trigger. */\n private place() {\n const t = this.trigger\n if (!t || !this.size.w) return null\n const e = clamp(this.emerge.x, 0, 1.15)\n const full = { x: 0, y: 0, w: this.size.w, h: this.size.h }\n const face = faceOf(t, full)\n const box = lerpBox(seed(t, full, face), full, e)\n return { box, e, poke: poke(t, box, face) }\n }\n\n /**\n * The popup's clay, in the popup's coordinates. It wears its own colour all the way: the colour\n * blends across the joint, not over time. The trigger asks for it too, and keeps drawing it after\n * the popup itself is hidden.\n */\n private body() {\n const place = this.place()\n if (!place || place.poke <= 0) return null\n const { box, e, poke } = place\n // It melts on as it comes out, so nothing bulges out of the trigger before it does, or after it's back.\n const glue = GLUE * (1 + this.fuse)\n const melt = (glue + (1 - Math.min(e, 1)) * 10) * smooth(0, GRIP, poke)\n const shape: ClayShape = {\n ...box,\n radius: this.options.radius,\n color: this.options.color(),\n height: 0.85,\n bevel: this.options.bevel,\n lift: this.options.lift * Math.min(e, 1),\n melt: Math.max(melt, 0.01),\n blend: BLEND,\n }\n return { shape, poke }\n }\n\n private get fuse() {\n return clamp(this.options.fuse?.() ?? 0, 0, 1)\n }\n\n /**\n * Where the popup meets the trigger, a patch that flattens the clay: the trigger's edge and the\n * popup's would otherwise shade a crease across the joint however deep they melt.\n */\n private seam(t: Box, shape: ClayShape): ClayShape | null {\n // Not while the popup is a thin lip: flattening the middle of it would leave a flat plate.\n const strength = smooth(0.3, 1, this.emerge.x)\n if (strength < 0.01) return null\n const face = faceOf(t, shape)\n const [tl, tw, sl, sw] = face.vertical ? [t.x, t.w, shape.x, shape.w] : [t.y, t.h, shape.y, shape.h]\n const lo = Math.max(tl, sl)\n const span = Math.min(tl + tw, sl + sw) - lo\n // Short of the sides, so the silhouette keeps its rounded edge where the two meet.\n const inset = Math.min(16, span / 4)\n const edge = face.vertical ? (face.sign > 0 ? t.y + t.h : t.y) : face.sign > 0 ? t.x + t.w : t.x\n const near = face.vertical ? (face.sign > 0 ? shape.y : shape.y + shape.h) : face.sign > 0 ? shape.x : shape.x + shape.w\n // Into the trigger a little, and into the popup as deep as its edge is rounded, or what's left of\n // the edge still shades a line below the patch.\n const toward = face.sign > 0 ? [12, 24] : [24, 12]\n const from = Math.min(edge, near) - toward[0]!\n const depth = Math.abs(edge - near) + toward[0]! + toward[1]!\n const across = { at: lo + inset, size: Math.max(span - inset * 2, 0) }\n return {\n ...(face.vertical\n ? { x: across.at, y: from, w: across.size, h: depth }\n : { x: from, y: across.at, w: depth, h: across.size }),\n radius: 10,\n color: shape.color,\n height: 0,\n melt: 0.01,\n blend: 7,\n flatten: strength,\n }\n }\n\n private shapes(): ClayShape[] {\n const t = this.trigger\n const body = this.body()\n if (!t || !body) return []\n const seam = this.seam(t, body.shape)\n return [\n {\n ...t,\n radius: this.options.triggerRadius(t),\n color: this.options.triggerColor(),\n height: 1,\n ghost: true,\n blend: BLEND,\n },\n body.shape,\n ...(seam ? [seam] : []),\n ]\n }\n\n /**\n * The popup melted into the trigger's own clay, in the trigger's coordinates, so both draw the same\n * joint and the same colour blend with no seam. It's a ghost there: the popup draws itself, shadow\n * and all, from its own canvas, and a second copy under it would show at its edges.\n */\n joint(host: HTMLElement): ClayShape[] {\n const t = this.trigger\n const body = this.body()\n if (!t || !body) return []\n const { shape } = body\n // The trigger can be squashed unevenly, as right after the press that opened it.\n const sx = t.w / (host.offsetWidth || t.w) || 1\n const sy = t.h / (host.offsetHeight || t.h) || 1\n const local = (s: ClayShape): ClayShape => ({ ...s, x: (s.x - t.x) / sx, y: (s.y - t.y) / sy, w: s.w / sx, h: s.h / sy })\n const seam = this.seam(t, shape)\n return [{ ...local(shape), lift: 0, ghost: true }, ...(seam ? [local(seam)] : [])]\n }\n}\n\n/** A `fuse` attribute: a number from 0 to 1, and 0 when it's missing or isn't a number. */\nfunction fuseOf(el: Element) {\n const value = parseFloat(el.getAttribute(\"fuse\") ?? \"\")\n return Number.isFinite(value) ? clamp(value, 0, 1) : 0\n}\n\n/**\n * Keeps the popup close enough to its trigger to stay melted on, and closer as they fuse, unless the\n * page chose a gap. Returns a function that fits it again.\n */\nfunction hug(content: HTMLElement, fuse: () => number = () => 0) {\n const own = !content.hasAttribute(\"side-offset\")\n const fit = () => {\n if (own) content.setAttribute(\"side-offset\", String(Math.round(lerp(4, 0, fuse()))))\n }\n fit()\n return fit\n}\n\nexport { Attachment, BACK, BLEND, faceOf, fuseOf, GLUE, GRIP, hug, OUT, PAST, poke, seed, smooth, TUCKED, type AttachOptions }\n"],"mappings":";;;;AAgCA,IAAM,OAAA;;AAMN,IAAM,MAAM;CAAE,OAAO;CAAI,MAAM;AAAI;AACnC,IAAM,OAAO;CAAE,OAAO;CAAI,MAAM;AAAE;;;;;AAMlC,IAAM,OAAO;AAKb,IAAM,UAAU,OAAe,OAAe,MAAc;CAC1D,MAAM,IAAI,OAAO,IAAI,UAAU,QAAQ,QAAQ,GAAG,CAAC;CACnD,OAAO,IAAI,KAAK,IAAI,IAAI;AAC1B;AASA,SAAS,OAAO,GAAQ,OAAkB;CACxC,MAAM,KAAK,MAAM,IAAI,MAAM,IAAI,KAAK,EAAE,IAAI,EAAE,IAAI;CAChD,MAAM,KAAK,MAAM,IAAI,MAAM,IAAI,KAAK,EAAE,IAAI,EAAE,IAAI;CAChD,MAAM,WAAW,KAAK,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,IAAI,MAAM,GAAG,CAAC,KAAK,KAAK,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,IAAI,MAAM,GAAG,CAAC;CACtG,OAAO;EAAE;EAAU,OAAO,WAAW,KAAK,MAAM,IAAI,IAAI;CAAG;AAC7D;;AAGA,IAAM,QAAQ;;;;;AAMd,SAAS,KAAK,GAAQ,OAAY,OAAO,OAAO,GAAG,KAAK,GAAQ;CAC9D,IAAI,KAAK,UAAU;EACjB,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI;EAEnC,OAAO;GAAE,GADC,MAAM,MAAM,IAAI,MAA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