m3-svelte 5.3.4 → 5.3.6
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
type Ripples = (() => void)[];
|
|
3
|
+
let pointerRipples: Ripples = $state([]);
|
|
4
|
+
let keyboardRipples: Ripples = $state([]);
|
|
3
5
|
|
|
4
6
|
const createRipple = (node: HTMLDivElement) => {
|
|
5
7
|
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
|
@@ -8,24 +10,22 @@
|
|
|
8
10
|
|
|
9
11
|
const parent = node.parentElement!;
|
|
10
12
|
|
|
11
|
-
const
|
|
12
|
-
if (e.button != 0) return;
|
|
13
|
+
const isEnabled = () => {
|
|
13
14
|
if (parent instanceof HTMLButtonElement) {
|
|
14
|
-
if (parent.disabled) return;
|
|
15
|
+
if (parent.disabled) return false;
|
|
15
16
|
}
|
|
16
17
|
if (parent instanceof HTMLLabelElement) {
|
|
17
18
|
const control = parent.control;
|
|
18
|
-
if (control instanceof HTMLInputElement && control.disabled) return;
|
|
19
|
+
if (control instanceof HTMLInputElement && control.disabled) return false;
|
|
19
20
|
}
|
|
20
21
|
if (parent.classList.contains("layer-container")) {
|
|
21
22
|
const input = parent.previousElementSibling;
|
|
22
|
-
if (input instanceof HTMLInputElement && input.disabled) return;
|
|
23
|
+
if (input instanceof HTMLInputElement && input.disabled) return false;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const size = Math.hypot(Math.max(x, rect.width - x), Math.max(y, rect.height - y)) * 2.5;
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
const ripple = (x: number, y: number, width: number, height: number) => {
|
|
28
|
+
const size = Math.hypot(Math.max(x, width - x), Math.max(y, height - y)) * 2.5;
|
|
29
29
|
const speed = Math.max(Math.min(Math.log(size) * 50, 600), 200);
|
|
30
30
|
|
|
31
31
|
const gradient = document.createElementNS("http://www.w3.org/2000/svg", "radialGradient");
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
|
|
104
104
|
node.appendChild(svg);
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
return () => {
|
|
107
107
|
const fade = document.createElementNS("http://www.w3.org/2000/svg", "animate");
|
|
108
108
|
fade.setAttribute("attributeName", "opacity");
|
|
109
109
|
fade.setAttribute("from", "1");
|
|
@@ -115,14 +115,35 @@
|
|
|
115
115
|
circle.appendChild(fade);
|
|
116
116
|
fade.beginElement();
|
|
117
117
|
setTimeout(() => svg.remove(), 800);
|
|
118
|
-
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const pointerdown = (e: PointerEvent) => {
|
|
121
|
+
if (!isEnabled()) return;
|
|
122
|
+
if (e.button != 0) return;
|
|
123
|
+
|
|
124
|
+
const rect = parent.getBoundingClientRect();
|
|
125
|
+
const cancel = ripple(e.clientX - rect.left, e.clientY - rect.top, rect.width, rect.height);
|
|
126
|
+
pointerRipples.push(cancel);
|
|
119
127
|
};
|
|
128
|
+
const keydown = (e: KeyboardEvent) => {
|
|
129
|
+
if (!isEnabled()) return;
|
|
130
|
+
if (e.repeat) return;
|
|
120
131
|
|
|
121
|
-
|
|
132
|
+
const isActivate = e.key == "Enter" || (e.key == " " && parent.tagName == "BUTTON");
|
|
133
|
+
if (!isActivate) return;
|
|
134
|
+
|
|
135
|
+
const rect = parent.getBoundingClientRect();
|
|
136
|
+
const cancel = ripple(rect.width / 2, rect.height / 2, rect.width, rect.height);
|
|
137
|
+
keyboardRipples.push(cancel);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
parent.addEventListener("pointerdown", pointerdown);
|
|
141
|
+
parent.addEventListener("keydown", keydown);
|
|
122
142
|
|
|
123
143
|
return {
|
|
124
144
|
destroy() {
|
|
125
|
-
parent.removeEventListener("pointerdown",
|
|
145
|
+
parent.removeEventListener("pointerdown", pointerdown);
|
|
146
|
+
parent.removeEventListener("keydown", keydown);
|
|
126
147
|
},
|
|
127
148
|
};
|
|
128
149
|
};
|
|
@@ -130,12 +151,16 @@
|
|
|
130
151
|
|
|
131
152
|
<svelte:window
|
|
132
153
|
onpointerup={() => {
|
|
133
|
-
|
|
134
|
-
|
|
154
|
+
pointerRipples.forEach((cancel) => cancel());
|
|
155
|
+
pointerRipples = [];
|
|
135
156
|
}}
|
|
136
157
|
ondragend={() => {
|
|
137
|
-
|
|
138
|
-
|
|
158
|
+
pointerRipples.forEach((cancel) => cancel());
|
|
159
|
+
pointerRipples = [];
|
|
160
|
+
}}
|
|
161
|
+
onkeyup={() => {
|
|
162
|
+
keyboardRipples.forEach((cancel) => cancel());
|
|
163
|
+
keyboardRipples = [];
|
|
139
164
|
}}
|
|
140
165
|
/>
|
|
141
166
|
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
@theme {
|
|
2
2
|
--*: initial;
|
|
3
3
|
--spacing: 0.25rem;
|
|
4
|
+
|
|
4
5
|
--breakpoint-m: 37.5rem; /* ≅ sm */
|
|
5
|
-
--breakpoint-x: 52.5rem; /* ≅ md */
|
|
6
|
+
--breakpoint-x: 52.5rem; /* expanded; ≅ md */
|
|
6
7
|
--breakpoint-l: 75rem; /* ≅ lg, xl */
|
|
7
8
|
--breakpoint-xl: 100rem; /* ≅ 2xl */
|
|
9
|
+
|
|
10
|
+
--container-m: 37.5rem; /* ≅ xl */
|
|
11
|
+
--container-x: 52.5rem; /* ≅ 3xl, 4xl */
|
|
12
|
+
--container-l: 75rem; /* ≅ 6xl, 7xl */
|
|
13
|
+
--container-xl: 100rem;
|
|
8
14
|
}
|
|
9
15
|
@theme inline {
|
|
10
16
|
--font-mono: var(--m3-font-mono);
|
|
@@ -92,6 +98,7 @@
|
|
|
92
98
|
--color-on-tertiary-container-subtle: rgb(var(--m3-scheme-on-tertiary-container-subtle));
|
|
93
99
|
--color-error-container-subtle: rgb(var(--m3-scheme-error-container-subtle));
|
|
94
100
|
--color-on-error-container-subtle: rgb(var(--m3-scheme-on-error-container-subtle));
|
|
101
|
+
--color-util-background: var(--m3-util-background);
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
@utility transition-fast-spatial {
|
|
@@ -160,3 +167,9 @@
|
|
|
160
167
|
@utility m3-font-body-small {
|
|
161
168
|
--: "";
|
|
162
169
|
}
|
|
170
|
+
|
|
171
|
+
@layer base {
|
|
172
|
+
:root {
|
|
173
|
+
box-sizing: border-box;
|
|
174
|
+
}
|
|
175
|
+
}
|
package/package/misc/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ export const genCSS = (light, dark) => {
|
|
|
9
9
|
const red = (argb >> 16) & 255;
|
|
10
10
|
const green = (argb >> 8) & 255;
|
|
11
11
|
const blue = argb & 255;
|
|
12
|
-
return
|
|
12
|
+
return ` --m3-scheme-${kebabCase}: ${red} ${green} ${blue};`;
|
|
13
13
|
};
|
|
14
14
|
const lightColors = colors
|
|
15
15
|
.map((color) => genColorVariable(color.name, color.getArgb(light)))
|