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
@@ -0,0 +1,105 @@
1
+ import { SPRINGS } from "../config.js";
2
+ import { ClayElement, NEUTRAL } from "../element.js";
3
+ import { clamp, deeper, watch } from "../shared.js";
4
+ import { Spring } from "../spring.js";
5
+ import { offsetWithin } from "../surface.js";
6
+ // src/clay/components/tabs.ts
7
+ /** Shift: tabs whose selection is a clay bead that rolls to the chosen view. */
8
+ var ClayTabs = class extends ClayElement {
9
+ requires = "ui-tabs-list ui-tabs-tab";
10
+ x = new Spring(0);
11
+ y = new Spring(0);
12
+ w = new Spring(0);
13
+ h = new Spring(0);
14
+ placed = false;
15
+ selected = false;
16
+ stop = null;
17
+ get list() {
18
+ return this.querySelector("ui-tabs-list");
19
+ }
20
+ setup() {
21
+ this.stop = watch(this.list, ["data-selected", "data-orientation"], () => this.invalidate());
22
+ }
23
+ teardown() {
24
+ this.stop?.();
25
+ }
26
+ surfaceFor() {
27
+ return [[this.list, {
28
+ swell: false,
29
+ pad: 26,
30
+ measure: () => this.measure(),
31
+ step: (dt, still) => [
32
+ this.x,
33
+ this.y,
34
+ this.w,
35
+ this.h
36
+ ].map((spring) => spring.step(dt, SPRINGS.travel, still)).some(Boolean),
37
+ shapes: () => this.shapes()
38
+ }]];
39
+ }
40
+ measure() {
41
+ const tab = this.list.querySelector("[data-slot='tabs-tab'][data-selected]");
42
+ this.selected = !!tab;
43
+ if (!tab) return;
44
+ const box = offsetWithin(tab, this.list);
45
+ this.x.target = box.x;
46
+ this.y.target = box.y;
47
+ this.w.target = box.w;
48
+ this.h.target = box.h;
49
+ if (!this.placed) {
50
+ for (const spring of [
51
+ this.x,
52
+ this.y,
53
+ this.w,
54
+ this.h
55
+ ]) spring.set(spring.target);
56
+ this.placed = true;
57
+ }
58
+ }
59
+ shapes() {
60
+ const surface = this.surfaces[0];
61
+ const { width: w, height: h } = surface;
62
+ const vertical = this.list.getAttribute("data-orientation") === "vertical";
63
+ const body = surface.color("--clay-surface", NEUTRAL);
64
+ const radius = vertical ? 24 : h / 2;
65
+ const shapes = [{
66
+ x: 0,
67
+ y: 0,
68
+ w,
69
+ h,
70
+ radius,
71
+ color: body,
72
+ height: .9,
73
+ lift: .55,
74
+ bevel: 16
75
+ }, {
76
+ x: 5,
77
+ y: 5,
78
+ w: w - 10,
79
+ h: h - 10,
80
+ radius: radius - 5,
81
+ color: deeper(body, .07),
82
+ height: -.8,
83
+ bevel: 12
84
+ }];
85
+ if (!this.selected) return shapes;
86
+ const speed = vertical ? this.y.v : this.x.v;
87
+ const stretch = clamp(Math.abs(speed) * 9e-4, 0, .22);
88
+ const bw = this.w.x * (vertical ? 1 - stretch * .3 : 1 + stretch);
89
+ const bh = this.h.x * (vertical ? 1 + stretch : 1 - stretch * .45);
90
+ shapes.push({
91
+ x: this.x.x + (this.w.x - bw) / 2,
92
+ y: this.y.x + (this.h.x - bh) / 2,
93
+ w: bw,
94
+ h: bh,
95
+ radius: Math.min(bw, bh) / 2,
96
+ color: surface.color("--clay-color", NEUTRAL),
97
+ height: 1,
98
+ lift: .5
99
+ });
100
+ return shapes;
101
+ }
102
+ };
103
+ export { ClayTabs };
104
+
105
+ //# sourceMappingURL=tabs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tabs.js","names":[],"sources":["../../../../src/clay/components/tabs.ts"],"sourcesContent":["import { SPRINGS } from \"../config\"\nimport type { ClayShape } from \"../engine\"\nimport { ClayElement, NEUTRAL } from \"../element\"\nimport { clamp, deeper, watch } from \"../shared\"\nimport { Spring } from \"../spring\"\nimport { offsetWithin, type SurfaceOptions } from \"../surface\"\n\n/** Shift: tabs whose selection is a clay bead that rolls to the chosen view. */\nclass ClayTabs extends ClayElement {\n protected readonly requires = \"ui-tabs-list ui-tabs-tab\"\n private x = new Spring(0)\n private y = new Spring(0)\n private w = new Spring(0)\n private h = new Spring(0)\n private placed = false\n private selected = false\n private stop: (() => void) | null = null\n\n private get list() {\n return this.querySelector<HTMLElement>(\"ui-tabs-list\")!\n }\n\n protected setup() {\n this.stop = watch(this.list, [\"data-selected\", \"data-orientation\"], () => this.invalidate())\n }\n\n protected teardown() {\n this.stop?.()\n }\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [\n [\n this.list,\n {\n swell: false,\n pad: 26,\n measure: () => this.measure(),\n step: (dt, still) =>\n [this.x, this.y, this.w, this.h].map((spring) => spring.step(dt, SPRINGS.travel, still)).some(Boolean),\n shapes: () => this.shapes(),\n },\n ],\n ]\n }\n\n private measure() {\n const tab = this.list.querySelector<HTMLElement>(\"[data-slot='tabs-tab'][data-selected]\")\n this.selected = !!tab\n if (!tab) return\n const box = offsetWithin(tab, this.list)\n this.x.target = box.x\n this.y.target = box.y\n this.w.target = box.w\n this.h.target = box.h\n if (!this.placed) {\n for (const spring of [this.x, this.y, this.w, this.h]) spring.set(spring.target)\n this.placed = true\n }\n }\n\n private shapes(): ClayShape[] {\n const surface = this.surfaces[0]!\n const { width: w, height: h } = surface\n const vertical = this.list.getAttribute(\"data-orientation\") === \"vertical\"\n const body = surface.color(\"--clay-surface\", NEUTRAL)\n const radius = vertical ? 24 : h / 2\n const shapes: ClayShape[] = [\n { x: 0, y: 0, w, h, radius, color: body, height: 0.9, lift: 0.55, bevel: 16 },\n { x: 5, y: 5, w: w - 10, h: h - 10, radius: radius - 5, color: deeper(body, 0.07), height: -0.8, bevel: 12 },\n ]\n if (!this.selected) return shapes\n const speed = vertical ? this.y.v : this.x.v\n const stretch = clamp(Math.abs(speed) * 0.0009, 0, 0.22)\n const bw = this.w.x * (vertical ? 1 - stretch * 0.3 : 1 + stretch)\n const bh = this.h.x * (vertical ? 1 + stretch : 1 - stretch * 0.45)\n shapes.push({\n x: this.x.x + (this.w.x - bw) / 2,\n y: this.y.x + (this.h.x - bh) / 2,\n w: bw,\n h: bh,\n radius: Math.min(bw, bh) / 2,\n color: surface.color(\"--clay-color\", NEUTRAL),\n height: 1,\n lift: 0.5,\n })\n return shapes\n }\n}\n\nexport { ClayTabs }\n"],"mappings":";;;;;;;AAQA,IAAM,WAAN,cAAuB,YAAY;CACjC,WAA8B;CAC9B,IAAY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MAAM;EAChE,MAAM,OAAO,QAAQ,MAAM,kBAAkB,OAAO;EACpD,MAAM,SAAS,WAAW,KAAK,IAAI;EACnC,MAAM,SAAsB,CAC1B;GAAE,GAAG;GAAG,GAAG;GAAG;GAAG;GAAG;GAAQ,OAAO;GAAM,QAAQ;GAAK,MAAM;GAAM,OAAO;EAAG,GAC5E;GAAE,GAAG;GAAG,GAAG;GAAG,GAAG,IAAI;GAAI,GAAG,IAAI;GAAI,QAAQ,SAAS;GAAG,OAAO,OAAO,MAAM,GAAI;GAAG,QAAQ;GAAM,OAAO;EAAG,CAC7G;EACA,IAAI,CAAC,KAAK,UAAU,OAAO;EAC3B,MAAM,QAAQ,WAAW,KAAK,EAAE,IAAI,KAAK,EAAE;EAC3C,MAAM,UAAU,MAAM,KAAK,IAAI,KAAK,IAAI,MAAQ,GAAG,GAAI;EACvD,MAAM,KAAK,KAAK,EAAE,KAAK,WAAW,IAAI,UAAU,KAAM,IAAI;EAC1D,MAAM,KAAK,KAAK,EAAE,KAAK,WAAW,IAAI,UAAU,IAAI,UAAU;EAC9D,OAAO,KAAK;GACV,GAAG,KAAK,EAAE,KAAK,KAAK,EAAE,IAAI,MAAM;GAChC,GAAG,KAAK,EAAE,KAAK,KAAK,EAAE,IAAI,MAAM;GAChC,GAAG;GACH,GAAG;GACH,QAAQ,KAAK,IAAI,IAAI,EAAE,IAAI;GAC3B,OAAO,QAAQ,MAAM,gBAAgB,OAAO;GAC5C,QAAQ;GACR,MAAM;EACR,CAAC;EACD,OAAO;CACT;AACF"}
@@ -0,0 +1,48 @@
1
+ declare const CLAY: {
2
+ pillow: number;
3
+ steep: number;
4
+ wrap: number;
5
+ subsurface: number;
6
+ ambient: number;
7
+ sheen: number;
8
+ sheenPower: number;
9
+ rim: number;
10
+ grain: number;
11
+ shadow: number;
12
+ shadowBlur: number;
13
+ shadowOffset: number;
14
+ contact: number;
15
+ lightX: number;
16
+ lightY: number;
17
+ lightZ: number;
18
+ pointerLean: number;
19
+ pointerSheen: number;
20
+ glow: number;
21
+ hoverSwell: number;
22
+ pressSquash: number;
23
+ };
24
+ declare const SPRINGS: {
25
+ hover: {
26
+ omega: number;
27
+ zeta: number;
28
+ };
29
+ press: {
30
+ omega: number;
31
+ zeta: number;
32
+ };
33
+ travel: {
34
+ omega: number;
35
+ zeta: number;
36
+ };
37
+ morph: {
38
+ omega: number;
39
+ zeta: number;
40
+ };
41
+ settle: {
42
+ omega: number;
43
+ zeta: number;
44
+ };
45
+ };
46
+ type ClayConfig = typeof CLAY;
47
+ declare const CLAY_DEFAULTS: ClayConfig;
48
+ export { CLAY, CLAY_DEFAULTS, SPRINGS, type ClayConfig };
package/dist/config.js ADDED
@@ -0,0 +1,50 @@
1
+ // src/clay/config.ts
2
+ var CLAY = {
3
+ pillow: .9,
4
+ steep: .85,
5
+ wrap: .45,
6
+ subsurface: .42,
7
+ ambient: .36,
8
+ sheen: .14,
9
+ sheenPower: 12,
10
+ rim: .16,
11
+ grain: .05,
12
+ shadow: .32,
13
+ shadowBlur: 16,
14
+ shadowOffset: 9,
15
+ contact: .3,
16
+ lightX: -.45,
17
+ lightY: -.7,
18
+ lightZ: .95,
19
+ pointerLean: .4,
20
+ pointerSheen: .7,
21
+ glow: .22,
22
+ hoverSwell: .03,
23
+ pressSquash: .07
24
+ };
25
+ var SPRINGS = {
26
+ hover: {
27
+ omega: 17,
28
+ zeta: .42
29
+ },
30
+ press: {
31
+ omega: 16,
32
+ zeta: .55
33
+ },
34
+ travel: {
35
+ omega: 15,
36
+ zeta: .6
37
+ },
38
+ morph: {
39
+ omega: 13,
40
+ zeta: .62
41
+ },
42
+ settle: {
43
+ omega: 9,
44
+ zeta: .75
45
+ }
46
+ };
47
+ var CLAY_DEFAULTS = { ...CLAY };
48
+ export { CLAY, CLAY_DEFAULTS, SPRINGS };
49
+
50
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../../src/clay/config.ts"],"sourcesContent":["const CLAY = {\n pillow: 0.9,\n steep: 0.85,\n wrap: 0.45,\n subsurface: 0.42,\n ambient: 0.36,\n sheen: 0.14,\n sheenPower: 12,\n rim: 0.16,\n grain: 0.05,\n shadow: 0.32,\n shadowBlur: 16,\n shadowOffset: 9,\n contact: 0.3,\n lightX: -0.45,\n lightY: -0.7,\n lightZ: 0.95,\n pointerLean: 0.4,\n pointerSheen: 0.7,\n glow: 0.22,\n hoverSwell: 0.03,\n pressSquash: 0.07,\n}\n\nconst SPRINGS = {\n hover: { omega: 17, zeta: 0.42 },\n press: { omega: 16, zeta: 0.55 },\n travel: { omega: 15, zeta: 0.6 },\n morph: { omega: 13, zeta: 0.62 },\n settle: { omega: 9, zeta: 0.75 },\n}\n\ntype ClayConfig = typeof CLAY\n\nconst CLAY_DEFAULTS: ClayConfig = { ...CLAY }\n\nexport { CLAY, CLAY_DEFAULTS, SPRINGS, type ClayConfig }\n"],"mappings":";AAAA,IAAM,OAAO;CACX,QAAQ;CACR,OAAO;CACP,MAAM;CACN,YAAY;CACZ,SAAS;CACT,OAAO;CACP,YAAY;CACZ,KAAK;CACL,OAAO;CACP,QAAQ;CACR,YAAY;CACZ,cAAc;CACd,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,aAAa;CACb,cAAc;CACd,MAAM;CACN,YAAY;CACZ,aAAa;AACf;AAEA,IAAM,UAAU;CACd,OAAO;EAAE,OAAO;EAAI,MAAM;CAAK;CAC/B,OAAO;EAAE,OAAO;EAAI,MAAM;CAAK;CAC/B,QAAQ;EAAE,OAAO;EAAI,MAAM;CAAI;CAC/B,OAAO;EAAE,OAAO;EAAI,MAAM;CAAK;CAC/B,QAAQ;EAAE,OAAO;EAAG,MAAM;CAAK;AACjC;AAIA,IAAM,gBAA4B,EAAE,GAAG,KAAK"}
@@ -0,0 +1,39 @@
1
+ import type { ClayShape } from "./engine.js";
2
+ import { ClaySurface, type SurfaceOptions } from "./surface.js";
3
+ declare const NEUTRAL: [number, number, number];
4
+ /**
5
+ * A host that gives its ui-sdk children a clay body. Behaviour stays in the children;
6
+ * the element only adds the material and the motion, and works without WebGL2.
7
+ */
8
+ declare abstract class ClayElement extends HTMLElement {
9
+ static observedAttributes: string[];
10
+ protected surfaces: ClaySurface[];
11
+ /** Shapes another element melts into this one's clay, like a tooltip growing out of it. */
12
+ readonly joints: Set<() => ClayShape[]>;
13
+ /** Holds the clay still while something is melted onto it. */
14
+ calm(on: boolean): void;
15
+ /** Squashes the clay and lets it spring back, as when something tucks back into it. */
16
+ bounce(strength?: number): void;
17
+ private started;
18
+ private waiting;
19
+ /** A selector that must match inside the host before setup runs; empty for none. */
20
+ protected abstract readonly requires: string;
21
+ /** Wires behaviour. Runs once per connection, with or without WebGL2. */
22
+ protected setup(): void;
23
+ protected teardown(): void;
24
+ /** Surfaces to attach once setup ran. Each returns null without WebGL2. */
25
+ protected abstract surfaceFor(): Array<[HTMLElement, SurfaceOptions]>;
26
+ connectedCallback(): void;
27
+ disconnectedCallback(): void;
28
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
29
+ protected invalidate(): void;
30
+ refreshTone(): void;
31
+ /** Sets data-tone so text stays readable on whatever colour the clay is. */
32
+ protected updateTone(): void;
33
+ private start;
34
+ /** Adds a surface after setup, for parts that come and go, like toasts. */
35
+ protected attach(host: HTMLElement, options: SurfaceOptions): ClaySurface | null;
36
+ protected detach(surface: ClaySurface): void;
37
+ }
38
+ declare function define(tag: string, element: CustomElementConstructor): void;
39
+ export { ClayElement, define, NEUTRAL };
@@ -0,0 +1,135 @@
1
+ import { luminance, resolveColor } from "./color.js";
2
+ import { ClaySurface } from "./surface.js";
3
+ // src/clay/element.ts
4
+ var PRESETS = /* @__PURE__ */ new Set([
5
+ "neutral",
6
+ "teal",
7
+ "lilac",
8
+ "sky",
9
+ "peach",
10
+ "mint",
11
+ "butter",
12
+ "rose",
13
+ "slate",
14
+ "ink"
15
+ ]);
16
+ var NEUTRAL = [
17
+ .86,
18
+ .89,
19
+ .92
20
+ ];
21
+ var live = /* @__PURE__ */ new Set();
22
+ var themeWatch = false;
23
+ function watchTheme() {
24
+ if (themeWatch) return;
25
+ themeWatch = true;
26
+ const refresh = () => requestAnimationFrame(() => live.forEach((element) => element.refreshTone()));
27
+ if (typeof matchMedia === "function") matchMedia("(prefers-color-scheme: dark)").addEventListener("change", refresh);
28
+ new MutationObserver(refresh).observe(document.documentElement, {
29
+ attributes: true,
30
+ attributeFilter: [
31
+ "data-theme",
32
+ "class",
33
+ "style"
34
+ ]
35
+ });
36
+ }
37
+ /**
38
+ * A host that gives its ui-sdk children a clay body. Behaviour stays in the children;
39
+ * the element only adds the material and the motion, and works without WebGL2.
40
+ */
41
+ var ClayElement = class extends HTMLElement {
42
+ static observedAttributes = ["color"];
43
+ surfaces = [];
44
+ /** Shapes another element melts into this one's clay, like a tooltip growing out of it. */
45
+ joints = /* @__PURE__ */ new Set();
46
+ /** Holds the clay still while something is melted onto it. */
47
+ calm(on) {
48
+ for (const surface of this.surfaces) surface.calm(on);
49
+ }
50
+ /** Squashes the clay and lets it spring back, as when something tucks back into it. */
51
+ bounce(strength = 1) {
52
+ this.surfaces[0]?.bounce(strength);
53
+ }
54
+ started = false;
55
+ waiting = null;
56
+ /** Wires behaviour. Runs once per connection, with or without WebGL2. */
57
+ setup() {}
58
+ teardown() {}
59
+ connectedCallback() {
60
+ queueMicrotask(() => this.start());
61
+ }
62
+ disconnectedCallback() {
63
+ this.waiting?.disconnect();
64
+ this.waiting = null;
65
+ if (!this.started) return;
66
+ this.started = false;
67
+ live.delete(this);
68
+ this.teardown();
69
+ for (const surface of this.surfaces) surface.destroy();
70
+ this.surfaces = [];
71
+ }
72
+ attributeChangedCallback(name, _old, value) {
73
+ if (name === "color") {
74
+ if (value === null) this.style.removeProperty("--clay-color");
75
+ else this.style.setProperty("--clay-color", PRESETS.has(value) ? `var(--clay-${value})` : value);
76
+ if (this.started) this.updateTone();
77
+ }
78
+ this.invalidate();
79
+ }
80
+ invalidate() {
81
+ for (const surface of this.surfaces) surface.invalidate();
82
+ }
83
+ refreshTone() {
84
+ this.updateTone();
85
+ }
86
+ /** Sets data-tone so text stays readable on whatever colour the clay is. */
87
+ updateTone() {
88
+ const css = getComputedStyle(this).getPropertyValue("--clay-color");
89
+ if (!css.trim()) return;
90
+ const l = luminance(resolveColor(css));
91
+ const onWhite = 1.05 / (l + .05);
92
+ const onInk = (l + .05) / .07200000000000001;
93
+ this.dataset.tone = onWhite > onInk ? "dark" : "light";
94
+ }
95
+ start() {
96
+ if (!this.isConnected || this.started) return;
97
+ if (this.requires && !this.querySelector(this.requires)) {
98
+ if (!this.waiting) {
99
+ this.waiting = new MutationObserver(() => this.start());
100
+ this.waiting.observe(this, {
101
+ childList: true,
102
+ subtree: true
103
+ });
104
+ }
105
+ return;
106
+ }
107
+ this.waiting?.disconnect();
108
+ this.waiting = null;
109
+ this.started = true;
110
+ live.add(this);
111
+ watchTheme();
112
+ this.updateTone();
113
+ this.setup();
114
+ for (const [host, options] of this.surfaceFor()) this.attach(host, options);
115
+ }
116
+ /** Adds a surface after setup, for parts that come and go, like toasts. */
117
+ attach(host, options) {
118
+ const surface = ClaySurface.attach(host, {
119
+ owner: this,
120
+ ...options
121
+ });
122
+ if (surface) this.surfaces.push(surface);
123
+ return surface;
124
+ }
125
+ detach(surface) {
126
+ surface.destroy();
127
+ this.surfaces = this.surfaces.filter((other) => other !== surface);
128
+ }
129
+ };
130
+ function define(tag, element) {
131
+ if (typeof customElements !== "undefined" && !customElements.get(tag)) customElements.define(tag, element);
132
+ }
133
+ export { ClayElement, NEUTRAL, define };
134
+
135
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","names":[],"sources":["../../../src/clay/element.ts"],"sourcesContent":["import { luminance, resolveColor } from \"./color\"\nimport type { ClayShape } from \"./engine\"\nimport { ClaySurface, type SurfaceOptions } from \"./surface\"\n\nconst PRESETS = new Set([\n \"neutral\", \"teal\", \"lilac\", \"sky\", \"peach\", \"mint\", \"butter\", \"rose\", \"slate\", \"ink\",\n])\n\nconst NEUTRAL: [number, number, number] = [0.86, 0.89, 0.92]\n\n/** Luminance of --clay-text in the light theme, the ink that light clay carries. */\nconst INK = 0.022\n\nconst live = new Set<ClayElement>()\nlet themeWatch = false\n\nfunction watchTheme() {\n if (themeWatch) return\n themeWatch = true\n const refresh = () => requestAnimationFrame(() => live.forEach((element) => element.refreshTone()))\n if (typeof matchMedia === \"function\") matchMedia(\"(prefers-color-scheme: dark)\").addEventListener(\"change\", refresh)\n new MutationObserver(refresh).observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"data-theme\", \"class\", \"style\"],\n })\n}\n\n/**\n * A host that gives its ui-sdk children a clay body. Behaviour stays in the children;\n * the element only adds the material and the motion, and works without WebGL2.\n */\nabstract class ClayElement extends HTMLElement {\n static observedAttributes = [\"color\"]\n protected surfaces: ClaySurface[] = []\n /** Shapes another element melts into this one's clay, like a tooltip growing out of it. */\n readonly joints = new Set<() => ClayShape[]>()\n\n /** Holds the clay still while something is melted onto it. */\n calm(on: boolean) {\n for (const surface of this.surfaces) surface.calm(on)\n }\n\n /** Squashes the clay and lets it spring back, as when something tucks back into it. */\n bounce(strength = 1) {\n this.surfaces[0]?.bounce(strength)\n }\n private started = false\n private waiting: MutationObserver | null = null\n\n /** A selector that must match inside the host before setup runs; empty for none. */\n protected abstract readonly requires: string\n /** Wires behaviour. Runs once per connection, with or without WebGL2. */\n protected setup(): void {}\n protected teardown(): void {}\n /** Surfaces to attach once setup ran. Each returns null without WebGL2. */\n protected abstract surfaceFor(): Array<[HTMLElement, SurfaceOptions]>\n\n connectedCallback() {\n queueMicrotask(() => this.start())\n }\n\n disconnectedCallback() {\n this.waiting?.disconnect()\n this.waiting = null\n if (!this.started) return\n this.started = false\n live.delete(this)\n this.teardown()\n for (const surface of this.surfaces) surface.destroy()\n this.surfaces = []\n }\n\n attributeChangedCallback(name: string, _old: string | null, value: string | null) {\n if (name === \"color\") {\n if (value === null) this.style.removeProperty(\"--clay-color\")\n else this.style.setProperty(\"--clay-color\", PRESETS.has(value) ? `var(--clay-${value})` : value)\n if (this.started) this.updateTone()\n }\n this.invalidate()\n }\n\n protected invalidate() {\n for (const surface of this.surfaces) surface.invalidate()\n }\n\n refreshTone() {\n this.updateTone()\n }\n\n /** Sets data-tone so text stays readable on whatever colour the clay is. */\n protected updateTone() {\n const css = getComputedStyle(this).getPropertyValue(\"--clay-color\")\n if (!css.trim()) return\n const l = luminance(resolveColor(css))\n const onWhite = 1.05 / (l + 0.05)\n const onInk = (l + 0.05) / (INK + 0.05)\n this.dataset.tone = onWhite > onInk ? \"dark\" : \"light\"\n }\n\n private start() {\n if (!this.isConnected || this.started) return\n if (this.requires && !this.querySelector(this.requires)) {\n if (!this.waiting) {\n this.waiting = new MutationObserver(() => this.start())\n this.waiting.observe(this, { childList: true, subtree: true })\n }\n return\n }\n this.waiting?.disconnect()\n this.waiting = null\n this.started = true\n live.add(this)\n watchTheme()\n this.updateTone()\n this.setup()\n for (const [host, options] of this.surfaceFor()) this.attach(host, options)\n }\n\n /** Adds a surface after setup, for parts that come and go, like toasts. */\n protected attach(host: HTMLElement, options: SurfaceOptions) {\n const surface = ClaySurface.attach(host, { owner: this, ...options })\n if (surface) this.surfaces.push(surface)\n return surface\n }\n\n protected detach(surface: ClaySurface) {\n surface.destroy()\n this.surfaces = this.surfaces.filter((other) => other !== surface)\n }\n}\n\nfunction define(tag: string, element: CustomElementConstructor) {\n if (typeof customElements !== \"undefined\" && !customElements.get(tag)) customElements.define(tag, element)\n}\n\nexport { ClayElement, define, NEUTRAL }\n"],"mappings":";;;AAIA,IAAM,0BAAU,IAAI,IAAI;CACtB;CAAW;CAAQ;CAAS;CAAO;CAAS;CAAQ;CAAU;CAAQ;CAAS;AACjF,CAAC;AAED,IAAM,UAAoC;CAAC;CAAM;CAAM;AAAI;AAK3D,IAAM,uBAAO,IAAI,IAAiB;AAClC,IAAI,aAAa;AAEjB,SAAS,aAAa;CACpB,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RGB } from "./color.js";
2
+ interface ClayShape {
3
+ x: number;
4
+ y: number;
5
+ w: number;
6
+ h: number;
7
+ radius: number;
8
+ color: RGB;
9
+ /** Positive bulges out, negative is a pressed-in well, 0 is flat. */
10
+ height: number;
11
+ /** Melts into the previous shape with this smoothing radius in px. 0 keeps it separate. */
12
+ melt?: number;
13
+ /** Shadow size multiplier; 0 casts none. */
14
+ lift?: number;
15
+ /** Width of the rounded edge in px. Defaults to the pillow share of the short side. */
16
+ bevel?: number;
17
+ /** Lights the clay from inside and haloes it in its own colour, 0 to 1. */
18
+ glow?: number;
19
+ /**
20
+ * Others melt into it but it isn't drawn, and nothing is drawn over it except a solid shape listed
21
+ * before it: for a part that draws itself elsewhere, like the button a popup grows out of.
22
+ */
23
+ ghost?: boolean;
24
+ /** False keeps it out of the shadow, for a part whose own surface casts one, like a popup melted into its button. */
25
+ shadow?: boolean;
26
+ /** How far its colour and height reach into the shapes melted with it, in px. Defaults to a crisp 3. */
27
+ blend?: number;
28
+ /** Fades it, with the shapes melted into it, from 0 to 1. Set on the first shape of a melted group. */
29
+ opacity?: number;
30
+ /**
31
+ * Not a part but a soft patch, 0 to 1, that flattens the clay melted under it: where two melted parts
32
+ * meet, it smooths away the crease between them and leaves the colour blend. Give it a melt so it
33
+ * joins their group; its blend softens its edge.
34
+ */
35
+ flatten?: number;
36
+ }
37
+ interface ClayFrame {
38
+ shapes: ClayShape[];
39
+ pointer: {
40
+ x: number;
41
+ y: number;
42
+ strength: number;
43
+ } | null;
44
+ glow: number;
45
+ light: [number, number, number];
46
+ }
47
+ interface ClayView {
48
+ canvas: HTMLCanvasElement;
49
+ ctx: CanvasRenderingContext2D;
50
+ pad: number;
51
+ width: number;
52
+ height: number;
53
+ visible: boolean;
54
+ dirty: boolean;
55
+ key: string;
56
+ tick(dt: number, still: boolean): boolean;
57
+ frame(): ClayFrame;
58
+ drawn(): void;
59
+ lost(): void;
60
+ }
61
+ declare class ClayEngine {
62
+ private gl;
63
+ private canvas;
64
+ private program;
65
+ private loc;
66
+ private views;
67
+ private scheduled;
68
+ private last;
69
+ private rect;
70
+ private radius;
71
+ private color;
72
+ private heights;
73
+ private melt;
74
+ private lift;
75
+ private bevel;
76
+ private shine;
77
+ private ghost;
78
+ private blend;
79
+ private opacity;
80
+ private flat;
81
+ constructor(canvas: HTMLCanvasElement, gl: WebGL2RenderingContext);
82
+ compile(): boolean;
83
+ add(view: ClayView): void;
84
+ remove(view: ClayView): void;
85
+ invalidateAll(): void;
86
+ wake(): void;
87
+ private frame;
88
+ private draw;
89
+ }
90
+ declare function getClayEngine(): ClayEngine | null;
91
+ export { getClayEngine, type ClayFrame, type ClayShape, type ClayView };