claymorph-ui 0.0.0-stage → 0.4.1
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.
- package/LICENSE +21 -0
- package/README.md +130 -2
- package/dist/attach.d.ts +115 -0
- package/dist/attach.js +328 -0
- package/dist/attach.js.map +1 -0
- package/dist/clay.css +1648 -0
- package/dist/color.d.ts +5 -0
- package/dist/color.js +44 -0
- package/dist/color.js.map +1 -0
- package/dist/components/action-button.d.ts +31 -0
- package/dist/components/action-button.js +158 -0
- package/dist/components/action-button.js.map +1 -0
- package/dist/components/bars.d.ts +33 -0
- package/dist/components/bars.js +135 -0
- package/dist/components/bars.js.map +1 -0
- package/dist/components/button.d.ts +10 -0
- package/dist/components/button.js +36 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/card.d.ts +24 -0
- package/dist/components/card.js +139 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/controls.d.ts +54 -0
- package/dist/components/controls.js +310 -0
- package/dist/components/controls.js.map +1 -0
- package/dist/components/forms.d.ts +41 -0
- package/dist/components/forms.js +266 -0
- package/dist/components/forms.js.map +1 -0
- package/dist/components/group.d.ts +26 -0
- package/dist/components/group.js +180 -0
- package/dist/components/group.js.map +1 -0
- package/dist/components/overlays.d.ts +89 -0
- package/dist/components/overlays.js +383 -0
- package/dist/components/overlays.js.map +1 -0
- package/dist/components/popups.d.ts +55 -0
- package/dist/components/popups.js +308 -0
- package/dist/components/popups.js.map +1 -0
- package/dist/components/slide.d.ts +34 -0
- package/dist/components/slide.js +234 -0
- package/dist/components/slide.js.map +1 -0
- package/dist/components/tabs.d.ts +20 -0
- package/dist/components/tabs.js +105 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/config.d.ts +48 -0
- package/dist/config.js +50 -0
- package/dist/config.js.map +1 -0
- package/dist/element.d.ts +39 -0
- package/dist/element.js +135 -0
- package/dist/element.js.map +1 -0
- package/dist/engine.d.ts +91 -0
- package/dist/engine.js +454 -0
- package/dist/engine.js.map +1 -0
- package/dist/entries/action-button.d.ts +8 -0
- package/dist/entries/action-button.js +8 -0
- package/dist/entries/action-button.js.map +1 -0
- package/dist/entries/avatar.d.ts +8 -0
- package/dist/entries/avatar.js +8 -0
- package/dist/entries/avatar.js.map +1 -0
- package/dist/entries/badge.d.ts +7 -0
- package/dist/entries/badge.js +7 -0
- package/dist/entries/badge.js.map +1 -0
- package/dist/entries/button-group.d.ts +9 -0
- package/dist/entries/button-group.js +9 -0
- package/dist/entries/button-group.js.map +1 -0
- package/dist/entries/button.d.ts +8 -0
- package/dist/entries/button.js +8 -0
- package/dist/entries/button.js.map +1 -0
- package/dist/entries/card.d.ts +7 -0
- package/dist/entries/card.js +7 -0
- package/dist/entries/card.js.map +1 -0
- package/dist/entries/checkbox.d.ts +9 -0
- package/dist/entries/checkbox.js +9 -0
- package/dist/entries/checkbox.js.map +1 -0
- package/dist/entries/dialog.d.ts +8 -0
- package/dist/entries/dialog.js +8 -0
- package/dist/entries/dialog.js.map +1 -0
- package/dist/entries/input.d.ts +9 -0
- package/dist/entries/input.js +9 -0
- package/dist/entries/input.js.map +1 -0
- package/dist/entries/menu.d.ts +8 -0
- package/dist/entries/menu.js +8 -0
- package/dist/entries/menu.js.map +1 -0
- package/dist/entries/meter.d.ts +8 -0
- package/dist/entries/meter.js +8 -0
- package/dist/entries/meter.js.map +1 -0
- package/dist/entries/popover.d.ts +8 -0
- package/dist/entries/popover.js +8 -0
- package/dist/entries/popover.js.map +1 -0
- package/dist/entries/progress.d.ts +8 -0
- package/dist/entries/progress.js +8 -0
- package/dist/entries/progress.js.map +1 -0
- package/dist/entries/radio.d.ts +9 -0
- package/dist/entries/radio.js +9 -0
- package/dist/entries/radio.js.map +1 -0
- package/dist/entries/segmented.d.ts +8 -0
- package/dist/entries/segmented.js +8 -0
- package/dist/entries/segmented.js.map +1 -0
- package/dist/entries/select.d.ts +8 -0
- package/dist/entries/select.js +8 -0
- package/dist/entries/select.js.map +1 -0
- package/dist/entries/slide-confirm.d.ts +8 -0
- package/dist/entries/slide-confirm.js +8 -0
- package/dist/entries/slide-confirm.js.map +1 -0
- package/dist/entries/slider.d.ts +9 -0
- package/dist/entries/slider.js +9 -0
- package/dist/entries/slider.js.map +1 -0
- package/dist/entries/switch.d.ts +9 -0
- package/dist/entries/switch.js +9 -0
- package/dist/entries/switch.js.map +1 -0
- package/dist/entries/tabs.d.ts +8 -0
- package/dist/entries/tabs.js +8 -0
- package/dist/entries/tabs.js.map +1 -0
- package/dist/entries/toast.d.ts +9 -0
- package/dist/entries/toast.js +8 -0
- package/dist/entries/toast.js.map +1 -0
- package/dist/entries/toggle.d.ts +8 -0
- package/dist/entries/toggle.js +8 -0
- package/dist/entries/toggle.js.map +1 -0
- package/dist/entries/tooltip.d.ts +8 -0
- package/dist/entries/tooltip.js +8 -0
- package/dist/entries/tooltip.js.map +1 -0
- package/dist/highlight.d.ts +26 -0
- package/dist/highlight.js +100 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +37 -0
- package/dist/shared.d.ts +28 -0
- package/dist/shared.js +80 -0
- package/dist/shared.js.map +1 -0
- package/dist/spring.d.ts +14 -0
- package/dist/spring.js +50 -0
- package/dist/spring.js.map +1 -0
- package/dist/surface.d.ts +88 -0
- package/dist/surface.js +240 -0
- package/dist/surface.js.map +1 -0
- package/package.json +140 -4
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { ClayElement, NEUTRAL } from "../element.js";
|
|
2
|
+
import { deeper } from "../shared.js";
|
|
3
|
+
// src/clay/components/card.ts
|
|
4
|
+
var LIFT = {
|
|
5
|
+
"1": .7,
|
|
6
|
+
"2": 1.1,
|
|
7
|
+
"3": 1.6
|
|
8
|
+
};
|
|
9
|
+
/** Hold: a soft slab that holds content. `interactive` makes it swell like a button. */
|
|
10
|
+
var ClayCard = class extends ClayElement {
|
|
11
|
+
static observedAttributes = [
|
|
12
|
+
"color",
|
|
13
|
+
"elevation",
|
|
14
|
+
"radius",
|
|
15
|
+
"interactive"
|
|
16
|
+
];
|
|
17
|
+
requires = "";
|
|
18
|
+
attributeChangedCallback(name, old, value) {
|
|
19
|
+
if (name === "radius") {
|
|
20
|
+
if (value === null) this.style.removeProperty("--clay-radius");
|
|
21
|
+
else this.style.setProperty("--clay-radius", `${Number(value)}px`);
|
|
22
|
+
}
|
|
23
|
+
super.attributeChangedCallback(name, old, value);
|
|
24
|
+
}
|
|
25
|
+
surfaceFor() {
|
|
26
|
+
return [[this, {
|
|
27
|
+
swell: this.hasAttribute("interactive"),
|
|
28
|
+
pad: 40,
|
|
29
|
+
shapes: () => this.shapes()
|
|
30
|
+
}]];
|
|
31
|
+
}
|
|
32
|
+
shapes() {
|
|
33
|
+
const surface = this.surfaces[0];
|
|
34
|
+
const { width: w, height: h } = surface;
|
|
35
|
+
const lift = LIFT[this.getAttribute("elevation") ?? "2"] ?? 1.1;
|
|
36
|
+
return [{
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
w,
|
|
40
|
+
h,
|
|
41
|
+
radius: Number(this.getAttribute("radius") ?? 28),
|
|
42
|
+
color: surface.color("--clay-color", NEUTRAL),
|
|
43
|
+
height: .9 - surface.press.x * .3,
|
|
44
|
+
bevel: 22,
|
|
45
|
+
lift: lift + surface.hover.x * .3
|
|
46
|
+
}];
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/** Stamp: a small pressed label. */
|
|
50
|
+
var ClayBadge = class extends ClayElement {
|
|
51
|
+
requires = "";
|
|
52
|
+
surfaceFor() {
|
|
53
|
+
return [[this, {
|
|
54
|
+
swell: false,
|
|
55
|
+
pad: 14,
|
|
56
|
+
shapes: () => this.shapes()
|
|
57
|
+
}]];
|
|
58
|
+
}
|
|
59
|
+
shapes() {
|
|
60
|
+
const surface = this.surfaces[0];
|
|
61
|
+
const { width: w, height: h } = surface;
|
|
62
|
+
return [{
|
|
63
|
+
x: 0,
|
|
64
|
+
y: 0,
|
|
65
|
+
w,
|
|
66
|
+
h,
|
|
67
|
+
radius: h / 2,
|
|
68
|
+
color: surface.color("--clay-color", NEUTRAL),
|
|
69
|
+
height: .9,
|
|
70
|
+
lift: .35
|
|
71
|
+
}];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var STATUS = {
|
|
75
|
+
online: "--clay-success",
|
|
76
|
+
away: "--clay-butter",
|
|
77
|
+
busy: "--clay-danger",
|
|
78
|
+
offline: "--clay-slate"
|
|
79
|
+
};
|
|
80
|
+
/** Frame: an avatar set in a clay ring, with an optional status bead melted onto it. */
|
|
81
|
+
var ClayAvatar = class extends ClayElement {
|
|
82
|
+
static observedAttributes = [
|
|
83
|
+
"color",
|
|
84
|
+
"size",
|
|
85
|
+
"status"
|
|
86
|
+
];
|
|
87
|
+
requires = "ui-avatar";
|
|
88
|
+
surfaceFor() {
|
|
89
|
+
return [[this, {
|
|
90
|
+
swell: false,
|
|
91
|
+
pad: 18,
|
|
92
|
+
shapes: () => this.shapes()
|
|
93
|
+
}]];
|
|
94
|
+
}
|
|
95
|
+
shapes() {
|
|
96
|
+
const surface = this.surfaces[0];
|
|
97
|
+
const { width: w, height: h } = surface;
|
|
98
|
+
const ring = Math.max(3, Math.round(w * .07));
|
|
99
|
+
const color = surface.color("--clay-color", NEUTRAL);
|
|
100
|
+
const shapes = [{
|
|
101
|
+
x: 0,
|
|
102
|
+
y: 0,
|
|
103
|
+
w,
|
|
104
|
+
h,
|
|
105
|
+
radius: w / 2,
|
|
106
|
+
color,
|
|
107
|
+
height: .9,
|
|
108
|
+
lift: .6
|
|
109
|
+
}];
|
|
110
|
+
const status = STATUS[this.getAttribute("status") ?? ""];
|
|
111
|
+
if (status) {
|
|
112
|
+
const d = Math.max(10, w * .26);
|
|
113
|
+
shapes.push({
|
|
114
|
+
x: w * .854 - d / 2,
|
|
115
|
+
y: h * .854 - d / 2,
|
|
116
|
+
w: d,
|
|
117
|
+
h: d,
|
|
118
|
+
radius: d / 2,
|
|
119
|
+
color: surface.color(status),
|
|
120
|
+
height: 1,
|
|
121
|
+
melt: 5,
|
|
122
|
+
lift: .6
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
shapes.push({
|
|
126
|
+
x: ring,
|
|
127
|
+
y: ring,
|
|
128
|
+
w: w - ring * 2,
|
|
129
|
+
h: h - ring * 2,
|
|
130
|
+
radius: (w - ring * 2) / 2,
|
|
131
|
+
color: deeper(color, .2),
|
|
132
|
+
height: -.9
|
|
133
|
+
});
|
|
134
|
+
return shapes;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
export { ClayAvatar, ClayBadge, ClayCard };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.js","names":[],"sources":["../../../../src/clay/components/card.ts"],"sourcesContent":["import type { ClayShape } from \"../engine\"\nimport { ClayElement, NEUTRAL } from \"../element\"\nimport { deeper } from \"../shared\"\nimport type { SurfaceOptions } from \"../surface\"\n\nconst LIFT: Record<string, number> = { \"1\": 0.7, \"2\": 1.1, \"3\": 1.6 }\n\n/** Hold: a soft slab that holds content. `interactive` makes it swell like a button. */\nclass ClayCard extends ClayElement {\n static observedAttributes = [\"color\", \"elevation\", \"radius\", \"interactive\"]\n protected readonly requires = \"\"\n\n attributeChangedCallback(name: string, old: string | null, value: string | null) {\n if (name === \"radius\") {\n if (value === null) this.style.removeProperty(\"--clay-radius\")\n else this.style.setProperty(\"--clay-radius\", `${Number(value)}px`)\n }\n super.attributeChangedCallback(name, old, value)\n }\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [[this, { swell: this.hasAttribute(\"interactive\"), pad: 40, shapes: () => this.shapes() }]]\n }\n\n private shapes(): ClayShape[] {\n const surface = this.surfaces[0]!\n const { width: w, height: h } = surface\n const lift = LIFT[this.getAttribute(\"elevation\") ?? \"2\"] ?? 1.1\n return [\n {\n x: 0,\n y: 0,\n w,\n h,\n radius: Number(this.getAttribute(\"radius\") ?? 28),\n color: surface.color(\"--clay-color\", NEUTRAL),\n height: 0.9 - surface.press.x * 0.3,\n bevel: 22,\n lift: lift + surface.hover.x * 0.3,\n },\n ]\n }\n}\n\n/** Stamp: a small pressed label. */\nclass ClayBadge extends ClayElement {\n protected readonly requires = \"\"\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [[this, { swell: false, pad: 14, shapes: () => this.shapes() }]]\n }\n\n private shapes(): ClayShape[] {\n const surface = this.surfaces[0]!\n const { width: w, height: h } = surface\n return [\n {\n x: 0,\n y: 0,\n w,\n h,\n radius: h / 2,\n color: surface.color(\"--clay-color\", NEUTRAL),\n height: 0.9,\n lift: 0.35,\n },\n ]\n }\n}\n\nconst STATUS: Record<string, string> = {\n online: \"--clay-success\",\n away: \"--clay-butter\",\n busy: \"--clay-danger\",\n offline: \"--clay-slate\",\n}\n\n/** Frame: an avatar set in a clay ring, with an optional status bead melted onto it. */\nclass ClayAvatar extends ClayElement {\n static observedAttributes = [\"color\", \"size\", \"status\"]\n protected readonly requires = \"ui-avatar\"\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [[this, { swell: false, pad: 18, shapes: () => this.shapes() }]]\n }\n\n private shapes(): ClayShape[] {\n const surface = this.surfaces[0]!\n const { width: w, height: h } = surface\n const ring = Math.max(3, Math.round(w * 0.07))\n const color = surface.color(\"--clay-color\", NEUTRAL)\n const shapes: ClayShape[] = [{ x: 0, y: 0, w, h, radius: w / 2, color, height: 0.9, lift: 0.6 }]\n const status = STATUS[this.getAttribute(\"status\") ?? \"\"]\n if (status) {\n const d = Math.max(10, w * 0.26)\n shapes.push({\n x: w * 0.854 - d / 2,\n y: h * 0.854 - d / 2,\n w: d,\n h: d,\n radius: d / 2,\n color: surface.color(status),\n height: 1,\n melt: 5,\n lift: 0.6,\n })\n }\n shapes.push({\n x: ring,\n y: ring,\n w: w - ring * 2,\n h: h - ring * 2,\n radius: (w - ring * 2) / 2,\n color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AO,EAAG;GACxB,QAAQ;EACV,CAAC;EACD,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ClayElement } from "../element.js";
|
|
2
|
+
import { type SurfaceOptions } from "../surface.js";
|
|
3
|
+
/** Slide: a segmented control whose selection is a clay bead rolling along a groove. */
|
|
4
|
+
declare class ClaySegmented extends ClayElement {
|
|
5
|
+
protected readonly requires = "ui-segmented-control";
|
|
6
|
+
private x;
|
|
7
|
+
private w;
|
|
8
|
+
private placed;
|
|
9
|
+
private stop;
|
|
10
|
+
protected setup(): void;
|
|
11
|
+
protected teardown(): void;
|
|
12
|
+
protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]>;
|
|
13
|
+
private item;
|
|
14
|
+
private measure;
|
|
15
|
+
private shapes;
|
|
16
|
+
}
|
|
17
|
+
/** Flip: a switch whose knob rolls across a groove that fills with colour. */
|
|
18
|
+
declare class ClaySwitch extends ClayElement {
|
|
19
|
+
protected readonly requires = "ui-switch";
|
|
20
|
+
private knob;
|
|
21
|
+
private fill;
|
|
22
|
+
private placed;
|
|
23
|
+
private stop;
|
|
24
|
+
protected setup(): void;
|
|
25
|
+
protected teardown(): void;
|
|
26
|
+
protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]>;
|
|
27
|
+
private shapes;
|
|
28
|
+
}
|
|
29
|
+
/** Tick: a checkbox whose dent pushes up into a filled bump when checked. */
|
|
30
|
+
declare class ClayCheckbox extends ClayElement {
|
|
31
|
+
protected readonly requires = "ui-checkbox";
|
|
32
|
+
private fill;
|
|
33
|
+
private placed;
|
|
34
|
+
private stop;
|
|
35
|
+
protected setup(): void;
|
|
36
|
+
protected teardown(): void;
|
|
37
|
+
protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]>;
|
|
38
|
+
private shapes;
|
|
39
|
+
}
|
|
40
|
+
/** Stretch: a slider whose clay ball stretches with speed and drags a filled groove behind it. */
|
|
41
|
+
declare class ClaySlider extends ClayElement {
|
|
42
|
+
protected readonly requires = "ui-slider-thumb";
|
|
43
|
+
private x;
|
|
44
|
+
private grab;
|
|
45
|
+
private placed;
|
|
46
|
+
private track;
|
|
47
|
+
private stop;
|
|
48
|
+
protected setup(): void;
|
|
49
|
+
protected teardown(): void;
|
|
50
|
+
protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]>;
|
|
51
|
+
private measure;
|
|
52
|
+
private shapes;
|
|
53
|
+
}
|
|
54
|
+
export { ClayCheckbox, ClaySegmented, ClaySlider, ClaySwitch };
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { mix } from "../color.js";
|
|
2
|
+
import { SPRINGS } from "../config.js";
|
|
3
|
+
import { ClayElement, NEUTRAL } from "../element.js";
|
|
4
|
+
import { clamp, deeper, watch } from "../shared.js";
|
|
5
|
+
import { Spring } from "../spring.js";
|
|
6
|
+
import { offsetWithin } from "../surface.js";
|
|
7
|
+
// src/clay/components/controls.ts
|
|
8
|
+
/** Slide: a segmented control whose selection is a clay bead rolling along a groove. */
|
|
9
|
+
var ClaySegmented = class extends ClayElement {
|
|
10
|
+
requires = "ui-segmented-control";
|
|
11
|
+
x = new Spring(0);
|
|
12
|
+
w = new Spring(0);
|
|
13
|
+
placed = false;
|
|
14
|
+
stop = null;
|
|
15
|
+
setup() {
|
|
16
|
+
const control = this.querySelector("ui-segmented-control");
|
|
17
|
+
this.stop = watch(control, ["data-checked"], () => this.invalidate());
|
|
18
|
+
}
|
|
19
|
+
teardown() {
|
|
20
|
+
this.stop?.();
|
|
21
|
+
}
|
|
22
|
+
surfaceFor() {
|
|
23
|
+
return [[this, {
|
|
24
|
+
swell: false,
|
|
25
|
+
measure: () => this.measure(),
|
|
26
|
+
step: (dt, still) => [this.x.step(dt, SPRINGS.travel, still), this.w.step(dt, SPRINGS.travel, still)].some(Boolean),
|
|
27
|
+
shapes: () => this.shapes()
|
|
28
|
+
}]];
|
|
29
|
+
}
|
|
30
|
+
item = null;
|
|
31
|
+
measure() {
|
|
32
|
+
const checked = this.querySelector("ui-segmented-control-item[data-checked]");
|
|
33
|
+
this.item = checked ? offsetWithin(checked, this) : null;
|
|
34
|
+
if (!this.item) return;
|
|
35
|
+
this.x.target = this.item.x;
|
|
36
|
+
this.w.target = this.item.w;
|
|
37
|
+
if (!this.placed) {
|
|
38
|
+
this.x.set(this.item.x);
|
|
39
|
+
this.w.set(this.item.w);
|
|
40
|
+
this.placed = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
shapes() {
|
|
44
|
+
const surface = this.surfaces[0];
|
|
45
|
+
const { width: w, height: h } = surface;
|
|
46
|
+
const body = surface.color("--clay-surface", NEUTRAL);
|
|
47
|
+
const shapes = [{
|
|
48
|
+
x: 0,
|
|
49
|
+
y: 0,
|
|
50
|
+
w,
|
|
51
|
+
h,
|
|
52
|
+
radius: h / 2,
|
|
53
|
+
color: body,
|
|
54
|
+
height: .9,
|
|
55
|
+
lift: .55
|
|
56
|
+
}, {
|
|
57
|
+
x: 4,
|
|
58
|
+
y: 4,
|
|
59
|
+
w: w - 8,
|
|
60
|
+
h: h - 8,
|
|
61
|
+
radius: (h - 8) / 2,
|
|
62
|
+
color: deeper(body, .07),
|
|
63
|
+
height: -.8
|
|
64
|
+
}];
|
|
65
|
+
if (this.item) {
|
|
66
|
+
const stretch = clamp(Math.abs(this.x.v) * 9e-4, 0, .22);
|
|
67
|
+
const bw = this.w.x * (1 + stretch);
|
|
68
|
+
const bh = this.item.h * (1 - stretch * .45);
|
|
69
|
+
shapes.push({
|
|
70
|
+
x: this.x.x - (bw - this.w.x) / 2,
|
|
71
|
+
y: this.item.y + (this.item.h - bh) / 2,
|
|
72
|
+
w: bw,
|
|
73
|
+
h: bh,
|
|
74
|
+
radius: bh / 2,
|
|
75
|
+
color: surface.color("--clay-color", NEUTRAL),
|
|
76
|
+
height: 1,
|
|
77
|
+
lift: .5
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return shapes;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/** Flip: a switch whose knob rolls across a groove that fills with colour. */
|
|
84
|
+
var ClaySwitch = class extends ClayElement {
|
|
85
|
+
requires = "ui-switch";
|
|
86
|
+
knob = new Spring(0);
|
|
87
|
+
fill = new Spring(0);
|
|
88
|
+
placed = false;
|
|
89
|
+
stop = null;
|
|
90
|
+
setup() {
|
|
91
|
+
const control = this.querySelector("ui-switch");
|
|
92
|
+
this.stop = watch(control, ["data-checked"], () => this.invalidate());
|
|
93
|
+
}
|
|
94
|
+
teardown() {
|
|
95
|
+
this.stop?.();
|
|
96
|
+
}
|
|
97
|
+
surfaceFor() {
|
|
98
|
+
return [[this, {
|
|
99
|
+
swell: false,
|
|
100
|
+
measure: () => {
|
|
101
|
+
const on = this.querySelector("ui-switch").hasAttribute("data-checked") ? 1 : 0;
|
|
102
|
+
this.knob.target = this.fill.target = on;
|
|
103
|
+
if (!this.placed) {
|
|
104
|
+
this.knob.set(on);
|
|
105
|
+
this.fill.set(on);
|
|
106
|
+
this.placed = true;
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
step: (dt, still) => [this.knob.step(dt, {
|
|
110
|
+
omega: 15,
|
|
111
|
+
zeta: .5
|
|
112
|
+
}, still), this.fill.step(dt, SPRINGS.settle, still)].some(Boolean),
|
|
113
|
+
shapes: () => this.shapes(this.surfaces[0])
|
|
114
|
+
}]];
|
|
115
|
+
}
|
|
116
|
+
shapes(surface) {
|
|
117
|
+
const { width: w, height: h } = surface;
|
|
118
|
+
const body = surface.color("--clay-surface", NEUTRAL);
|
|
119
|
+
const accent = surface.color("--clay-color");
|
|
120
|
+
const d = h - 10;
|
|
121
|
+
const travel = w - 10 - d;
|
|
122
|
+
const cx = 5 + d / 2 + travel * this.knob.x;
|
|
123
|
+
const stretch = clamp(Math.abs(this.knob.v) * .05, 0, .35) + surface.press.x * .22;
|
|
124
|
+
const kw = d * (1 + stretch);
|
|
125
|
+
const kh = d * (1 - stretch * .25);
|
|
126
|
+
return [
|
|
127
|
+
{
|
|
128
|
+
x: 0,
|
|
129
|
+
y: 0,
|
|
130
|
+
w,
|
|
131
|
+
h,
|
|
132
|
+
radius: h / 2,
|
|
133
|
+
color: body,
|
|
134
|
+
height: .85,
|
|
135
|
+
lift: .5
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
x: 3,
|
|
139
|
+
y: 3,
|
|
140
|
+
w: w - 6,
|
|
141
|
+
h: h - 6,
|
|
142
|
+
radius: (h - 6) / 2,
|
|
143
|
+
color: mix(deeper(body, .09), accent, clamp(this.fill.x, 0, 1)),
|
|
144
|
+
height: -.85
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
x: clamp(cx - kw / 2, 4, w - 4 - kw),
|
|
148
|
+
y: h / 2 - kh / 2,
|
|
149
|
+
w: kw,
|
|
150
|
+
h: kh,
|
|
151
|
+
radius: kh / 2,
|
|
152
|
+
color: surface.color("--clay-knob"),
|
|
153
|
+
height: 1,
|
|
154
|
+
lift: .7
|
|
155
|
+
}
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
/** Tick: a checkbox whose dent pushes up into a filled bump when checked. */
|
|
160
|
+
var ClayCheckbox = class extends ClayElement {
|
|
161
|
+
requires = "ui-checkbox";
|
|
162
|
+
fill = new Spring(0);
|
|
163
|
+
placed = false;
|
|
164
|
+
stop = null;
|
|
165
|
+
setup() {
|
|
166
|
+
const control = this.querySelector("ui-checkbox");
|
|
167
|
+
this.stop = watch(control, ["data-checked", "data-indeterminate"], () => this.invalidate());
|
|
168
|
+
}
|
|
169
|
+
teardown() {
|
|
170
|
+
this.stop?.();
|
|
171
|
+
}
|
|
172
|
+
surfaceFor() {
|
|
173
|
+
return [[this, {
|
|
174
|
+
pad: 18,
|
|
175
|
+
measure: () => {
|
|
176
|
+
const on = this.querySelector("ui-checkbox").matches("[data-checked], [data-indeterminate]") ? 1 : 0;
|
|
177
|
+
this.fill.target = on;
|
|
178
|
+
if (!this.placed) {
|
|
179
|
+
this.fill.set(on);
|
|
180
|
+
this.placed = true;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
step: (dt, still) => this.fill.step(dt, {
|
|
184
|
+
omega: 16,
|
|
185
|
+
zeta: .42
|
|
186
|
+
}, still),
|
|
187
|
+
shapes: () => this.shapes(this.surfaces[0])
|
|
188
|
+
}]];
|
|
189
|
+
}
|
|
190
|
+
shapes(surface) {
|
|
191
|
+
const { width: w, height: h } = surface;
|
|
192
|
+
const body = surface.color("--clay-surface", NEUTRAL);
|
|
193
|
+
const f = this.fill.x;
|
|
194
|
+
return [{
|
|
195
|
+
x: 0,
|
|
196
|
+
y: 0,
|
|
197
|
+
w,
|
|
198
|
+
h,
|
|
199
|
+
radius: 9,
|
|
200
|
+
color: body,
|
|
201
|
+
height: .8,
|
|
202
|
+
lift: .45
|
|
203
|
+
}, {
|
|
204
|
+
x: 4,
|
|
205
|
+
y: 4,
|
|
206
|
+
w: w - 8,
|
|
207
|
+
h: h - 8,
|
|
208
|
+
radius: 6,
|
|
209
|
+
color: mix(deeper(body, .1), surface.color("--clay-color"), clamp(f, 0, 1)),
|
|
210
|
+
height: -.85 + 1.75 * f - surface.press.x * .3,
|
|
211
|
+
lift: clamp(f, 0, 1) * .35
|
|
212
|
+
}];
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
/** Stretch: a slider whose clay ball stretches with speed and drags a filled groove behind it. */
|
|
216
|
+
var ClaySlider = class extends ClayElement {
|
|
217
|
+
requires = "ui-slider-thumb";
|
|
218
|
+
x = new Spring(0);
|
|
219
|
+
grab = new Spring(0);
|
|
220
|
+
placed = false;
|
|
221
|
+
track = {
|
|
222
|
+
x: 0,
|
|
223
|
+
y: 0,
|
|
224
|
+
w: 0,
|
|
225
|
+
h: 0
|
|
226
|
+
};
|
|
227
|
+
stop = null;
|
|
228
|
+
setup() {
|
|
229
|
+
const slider = this.querySelector("ui-slider");
|
|
230
|
+
this.stop = watch(slider, ["style", "data-dragging"], () => this.invalidate());
|
|
231
|
+
}
|
|
232
|
+
teardown() {
|
|
233
|
+
this.stop?.();
|
|
234
|
+
}
|
|
235
|
+
surfaceFor() {
|
|
236
|
+
return [[this, {
|
|
237
|
+
swell: false,
|
|
238
|
+
pressTarget: this.querySelector("ui-slider-control") ?? this,
|
|
239
|
+
measure: () => this.measure(),
|
|
240
|
+
step: (dt, still) => [this.x.step(dt, {
|
|
241
|
+
omega: 24,
|
|
242
|
+
zeta: .62
|
|
243
|
+
}, still), this.grab.step(dt, SPRINGS.press, still)].some(Boolean),
|
|
244
|
+
shapes: () => this.shapes(this.surfaces[0])
|
|
245
|
+
}]];
|
|
246
|
+
}
|
|
247
|
+
measure() {
|
|
248
|
+
this.track = offsetWithin(this.querySelector("ui-slider-track"), this);
|
|
249
|
+
const thumb = offsetWithin(this.querySelector("ui-slider-thumb"), this);
|
|
250
|
+
this.x.target = thumb.x + thumb.w / 2;
|
|
251
|
+
this.grab.target = this.querySelector("ui-slider").hasAttribute("data-dragging") ? 1 : 0;
|
|
252
|
+
if (!this.placed) {
|
|
253
|
+
this.x.set(this.x.target);
|
|
254
|
+
this.placed = true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
shapes(surface) {
|
|
258
|
+
const t = this.track;
|
|
259
|
+
const body = surface.color("--clay-surface", NEUTRAL);
|
|
260
|
+
const grab = Math.max(this.grab.x, surface.press.x);
|
|
261
|
+
const d = 26 * (1 + grab * .12);
|
|
262
|
+
const stretch = clamp(Math.abs(this.x.v) * .0012, 0, .3);
|
|
263
|
+
const bw = d * (1 + stretch);
|
|
264
|
+
const bh = d * (1 - stretch * .3);
|
|
265
|
+
const cy = t.y + t.h / 2;
|
|
266
|
+
return [
|
|
267
|
+
{
|
|
268
|
+
x: t.x - 7,
|
|
269
|
+
y: t.y - 7,
|
|
270
|
+
w: t.w + 14,
|
|
271
|
+
h: t.h + 14,
|
|
272
|
+
radius: (t.h + 14) / 2,
|
|
273
|
+
color: body,
|
|
274
|
+
height: .8,
|
|
275
|
+
lift: .5
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
x: t.x,
|
|
279
|
+
y: t.y,
|
|
280
|
+
w: t.w,
|
|
281
|
+
h: t.h,
|
|
282
|
+
radius: t.h / 2,
|
|
283
|
+
color: deeper(body, .09),
|
|
284
|
+
height: -.9
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
x: t.x + 1,
|
|
288
|
+
y: t.y + 1,
|
|
289
|
+
w: Math.max(this.x.x - t.x, t.h),
|
|
290
|
+
h: t.h - 2,
|
|
291
|
+
radius: (t.h - 2) / 2,
|
|
292
|
+
color: surface.color("--clay-color"),
|
|
293
|
+
height: .7
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
x: this.x.x - bw / 2,
|
|
297
|
+
y: cy - bh / 2,
|
|
298
|
+
w: bw,
|
|
299
|
+
h: bh,
|
|
300
|
+
radius: bh / 2,
|
|
301
|
+
color: surface.color("--clay-knob"),
|
|
302
|
+
height: 1,
|
|
303
|
+
lift: .8 + grab * .4
|
|
304
|
+
}
|
|
305
|
+
];
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
export { ClayCheckbox, ClaySegmented, ClaySlider, ClaySwitch };
|
|
309
|
+
|
|
310
|
+
//# sourceMappingURL=controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controls.js","names":[],"sources":["../../../../src/clay/components/controls.ts"],"sourcesContent":["import { mix } from \"../color\"\nimport { 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 ClaySurface, type SurfaceOptions } from \"../surface\"\n\n/** Slide: a segmented control whose selection is a clay bead rolling along a groove. */\nclass ClaySegmented extends ClayElement {\n protected readonly requires = \"ui-segmented-control\"\n private x = new Spring(0)\n private w = new Spring(0)\n private placed = false\n private stop: (() => void) | null = null\n\n protected setup() {\n const control = this.querySelector(\"ui-segmented-control\")!\n this.stop = watch(control, [\"data-checked\"], () => this.invalidate())\n }\n\n protected teardown() {\n this.stop?.()\n }\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [\n [\n this,\n {\n swell: false,\n measure: () => this.measure(),\n step: (dt, still) => [this.x.step(dt, SPRINGS.travel, still), this.w.step(dt, SPRINGS.travel, still)].some(Boolean),\n shapes: () => this.shapes(),\n },\n ],\n ]\n }\n\n private item: { x: number; y: number; w: number; h: number } | null = null\n\n private measure() {\n const checked = this.querySelector<HTMLElement>(\"ui-segmented-control-item[data-checked]\")\n this.item = checked ? offsetWithin(checked, this) : null\n if (!this.item) return\n this.x.target = this.item.x\n this.w.target = this.item.w\n if (!this.placed) {\n this.x.set(this.item.x)\n this.w.set(this.item.w)\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 body = surface.color(\"--clay-surface\", NEUTRAL)\n const shapes: ClayShape[] = [\n { x: 0, y: 0, w, h, radius: h / 2, color: body, height: 0.9, lift: 0.55 },\n { x: 4, y: 4, w: w - 8, h: h - 8, radius: (h - 8) / 2, color: deeper(body, 0.07), height: -0.8 },\n ]\n if (this.item) {\n const stretch = clamp(Math.abs(this.x.v) * 0.0009, 0, 0.22)\n const bw = this.w.x * (1 + stretch)\n const bh = this.item.h * (1 - stretch * 0.45)\n shapes.push({\n x: this.x.x - (bw - this.w.x) / 2,\n y: this.item.y + (this.item.h - bh) / 2,\n w: bw,\n h: bh,\n radius: bh / 2,\n color: surface.color(\"--clay-color\", NEUTRAL),\n height: 1,\n lift: 0.5,\n })\n }\n return shapes\n }\n}\n\n/** Flip: a switch whose knob rolls across a groove that fills with colour. */\nclass ClaySwitch extends ClayElement {\n protected readonly requires = \"ui-switch\"\n private knob = new Spring(0)\n private fill = new Spring(0)\n private placed = false\n private stop: (() => void) | null = null\n\n protected setup() {\n const control = this.querySelector(\"ui-switch\")!\n this.stop = watch(control, [\"data-checked\"], () => this.invalidate())\n }\n\n protected teardown() {\n this.stop?.()\n }\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [\n [\n this,\n {\n swell: false,\n measure: () => {\n const on = this.querySelector(\"ui-switch\")!.hasAttribute(\"data-checked\") ? 1 : 0\n this.knob.target = this.fill.target = on\n if (!this.placed) {\n this.knob.set(on)\n this.fill.set(on)\n this.placed = true\n }\n },\n step: (dt, still) =>\n [this.knob.step(dt, { omega: 15, zeta: 0.5 }, still), this.fill.step(dt, SPRINGS.settle, still)].some(Boolean),\n shapes: () => this.shapes(this.surfaces[0]!),\n },\n ],\n ]\n }\n\n private shapes(surface: ClaySurface): ClayShape[] {\n const { width: w, height: h } = surface\n const body = surface.color(\"--clay-surface\", NEUTRAL)\n const accent = surface.color(\"--clay-color\")\n const d = h - 10\n const travel = w - 10 - d\n const cx = 5 + d / 2 + travel * this.knob.x\n const stretch = clamp(Math.abs(this.knob.v) * 0.05, 0, 0.35) + surface.press.x * 0.22\n const kw = d * (1 + stretch)\n const kh = d * (1 - stretch * 0.25)\n return [\n { x: 0, y: 0, w, h, radius: h / 2, color: body, height: 0.85, lift: 0.5 },\n {\n x: 3,\n y: 3,\n w: w - 6,\n h: h - 6,\n radius: (h - 6) / 2,\n color: mix(deeper(body, 0.09), accent, clamp(this.fill.x, 0, 1)),\n height: -0.85,\n },\n {\n x: clamp(cx - kw / 2, 4, w - 4 - kw),\n y: h / 2 - kh / 2,\n w: kw,\n h: kh,\n radius: kh / 2,\n color: surface.color(\"--clay-knob\"),\n height: 1,\n lift: 0.7,\n },\n ]\n }\n}\n\n/** Tick: a checkbox whose dent pushes up into a filled bump when checked. */\nclass ClayCheckbox extends ClayElement {\n protected readonly requires = \"ui-checkbox\"\n private fill = new Spring(0)\n private placed = false\n private stop: (() => void) | null = null\n\n protected setup() {\n const control = this.querySelector(\"ui-checkbox\")!\n this.stop = watch(control, [\"data-checked\", \"data-indeterminate\"], () => this.invalidate())\n }\n\n protected teardown() {\n this.stop?.()\n }\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [\n [\n this,\n {\n pad: 18,\n measure: () => {\n const box = this.querySelector(\"ui-checkbox\")!\n const on = box.matches(\"[data-checked], [data-indeterminate]\") ? 1 : 0\n this.fill.target = on\n if (!this.placed) {\n this.fill.set(on)\n this.placed = true\n }\n },\n step: (dt, still) => this.fill.step(dt, { omega: 16, zeta: 0.42 }, still),\n shapes: () => this.shapes(this.surfaces[0]!),\n },\n ],\n ]\n }\n\n private shapes(surface: ClaySurface): ClayShape[] {\n const { width: w, height: h } = surface\n const body = surface.color(\"--clay-surface\", NEUTRAL)\n const f = this.fill.x\n return [\n { x: 0, y: 0, w, h, radius: 9, color: body, height: 0.8, lift: 0.45 },\n {\n x: 4,\n y: 4,\n w: w - 8,\n h: h - 8,\n radius: 6,\n color: mix(deeper(body, 0.1), surface.color(\"--clay-color\"), clamp(f, 0, 1)),\n height: -0.85 + 1.75 * f - surface.press.x * 0.3,\n lift: clamp(f, 0, 1) * 0.35,\n },\n ]\n }\n}\n\n/** Stretch: a slider whose clay ball stretches with speed and drags a filled groove behind it. */\nclass ClaySlider extends ClayElement {\n protected readonly requires = \"ui-slider-thumb\"\n private x = new Spring(0)\n private grab = new Spring(0)\n private placed = false\n private track = { x: 0, y: 0, w: 0, h: 0 }\n private stop: (() => void) | null = null\n\n protected setup() {\n const slider = this.querySelector(\"ui-slider\")!\n this.stop = watch(slider, [\"style\", \"data-dragging\"], () => this.invalidate())\n }\n\n protected teardown() {\n this.stop?.()\n }\n\n protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]> {\n return [\n [\n this,\n {\n swell: false,\n pressTarget: this.querySelector<HTMLElement>(\"ui-slider-control\") ?? this,\n measure: () => this.measure(),\n step: (dt, still) =>\n [this.x.step(dt, { omega: 24, zeta: 0.62 }, still), this.grab.step(dt, SPRINGS.press, still)].some(Boolean),\n shapes: () => this.shapes(this.surfaces[0]!),\n },\n ],\n ]\n }\n\n private measure() {\n this.track = offsetWithin(this.querySelector(\"ui-slider-track\")!, this)\n const thumb = offsetWithin(this.querySelector(\"ui-slider-thumb\")!, this)\n this.x.target = thumb.x + thumb.w / 2\n this.grab.target = this.querySelector(\"ui-slider\")!.hasAttribute(\"data-dragging\") ? 1 : 0\n if (!this.placed) {\n this.x.set(this.x.target)\n this.placed = true\n }\n }\n\n private shapes(surface: ClaySurface): ClayShape[] {\n const t = this.track\n const body = surface.color(\"--clay-surface\", NEUTRAL)\n const grab = Math.max(this.grab.x, surface.press.x)\n const d = 26 * (1 + grab * 0.12)\n const stretch = clamp(Math.abs(this.x.v) * 0.0012, 0, 0.3)\n const bw = d * (1 + stretch)\n const bh = d * (1 - stretch * 0.3)\n const cy = t.y + t.h / 2\n return [\n { x: t.x - 7, y: t.y - 7, w: t.w + 14, h: t.h + 14, radius: (t.h + 14) / 2, color: body, height: 0.8, lift: 0.5 },\n { x: t.x, y: t.y, w: t.w, h: t.h, radius: t.h / 2, color: deeper(body, 0.09), height: -0.9 },\n {\n x: t.x + 1,\n y: t.y + 1,\n w: Math.max(this.x.x - t.x, t.h),\n h: t.h - 2,\n radius: (t.h - 2) / 2,\n color: surface.color(\"--clay-color\"),\n height: 0.7,\n },\n {\n x: this.x.x - bw / 2,\n y: cy - bh / 2,\n w: bw,\n h: bh,\n radius: bh / 2,\n color: surface.color(\"--clay-knob\"),\n height: 1,\n lift: 0.8 + grab * 0.4,\n },\n ]\n }\n}\n\nexport { ClayCheckbox, ClaySegmented, ClaySlider, ClaySwitch }\n"],"mappings":";;;;;;;;AASA,IAAM,gBAAN,cAA4B,YAAY;CACtC,WAA8B;CAC9B,IAAY,IAAI,OAAO,CAAC;CACxB,IAAY,IAAI,OAAO,CAAC;CACxB,SAAiB;CACjB,OAAoC;CAEpC,QAAkB;EAChB,MAAM,UAAU,KAAK,cAAc,sBAAsB;EACzD,KAAK,OAAO,MAAM,SAAS,CAAC,cAAc,SAAS,KAAK,WA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AAG,OAAO;IAAM,QAAQ;IAAK,MAAM;GAAI;GAChH;IAAE,GAAG,EAAE;IAAG,GAAG,EAAE;IAAG,GAAG,EAAE;IAAG,GAAG,EAAE;IAAG,QAAQ,EAAE,IAAI;IAAG,OAAO,OAAO,MAAM,GAAI;IAAG,QAAQ;GAAK;GAC3F;IACE,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,KAAK,IAAI,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC/B,GAAG,EAAE,IAAI;IACT,SAAS,EAAE,IAAI,KAAK;IACpB,OAAO,QAAQ,MAAM,cAAc;IACnC,QAAQ;GACV;GACA;IACE,GAAG,KAAK,EAAE,IAAI,KAAK;IACnB,GAAG,KAAK,KAAK;IACb,GAAG;IACH,GAAG;IACH,QAAQ,KAAK;IACb,OAAO,QAAQ,MAAM,aAAa;IAClC,QAAQ;IACR,MAAM,KAAM,OAAO;GACrB;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ClayElement } from "../element.js";
|
|
2
|
+
import { type SurfaceOptions } from "../surface.js";
|
|
3
|
+
/**
|
|
4
|
+
* Type: a text field carved into the clay. Its rim glows while focused and the well gives a little as
|
|
5
|
+
* you type. With `attached`, the label and hint are beads melted onto the rim.
|
|
6
|
+
*/
|
|
7
|
+
declare class ClayInput extends ClayElement {
|
|
8
|
+
static observedAttributes: string[];
|
|
9
|
+
protected readonly requires = "input, textarea";
|
|
10
|
+
private focused;
|
|
11
|
+
private pulse;
|
|
12
|
+
private out;
|
|
13
|
+
private invalid;
|
|
14
|
+
private label;
|
|
15
|
+
private hint;
|
|
16
|
+
private lastVars;
|
|
17
|
+
private reach;
|
|
18
|
+
private cleanup;
|
|
19
|
+
private get field();
|
|
20
|
+
private get attached();
|
|
21
|
+
protected setup(): void;
|
|
22
|
+
protected teardown(): void;
|
|
23
|
+
protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]>;
|
|
24
|
+
private shapes;
|
|
25
|
+
}
|
|
26
|
+
/** Pick: radios carved as dents in the clay. A bead hops into the one you choose. */
|
|
27
|
+
declare class ClayRadio extends ClayElement {
|
|
28
|
+
protected readonly requires = "ui-radio";
|
|
29
|
+
private boxes;
|
|
30
|
+
private x;
|
|
31
|
+
private y;
|
|
32
|
+
private pop;
|
|
33
|
+
private placed;
|
|
34
|
+
private stop;
|
|
35
|
+
protected setup(): void;
|
|
36
|
+
protected teardown(): void;
|
|
37
|
+
protected surfaceFor(): Array<[HTMLElement, SurfaceOptions]>;
|
|
38
|
+
private measure;
|
|
39
|
+
private shapes;
|
|
40
|
+
}
|
|
41
|
+
export { ClayInput, ClayRadio };
|