m3-svelte 5.3.3 → 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
- let cancelRipples: (() => void)[] = $state([]);
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 ripple = (e: MouseEvent) => {
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
- const rect = parent.getBoundingClientRect();
26
- const x = e.clientX - rect.left;
27
- const y = e.clientY - rect.top;
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
- cancelRipples.push(() => {
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
- parent.addEventListener("pointerdown", ripple);
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", ripple);
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
- cancelRipples.forEach((cancel) => cancel());
134
- cancelRipples = [];
154
+ pointerRipples.forEach((cancel) => cancel());
155
+ pointerRipples = [];
135
156
  }}
136
157
  ondragend={() => {
137
- cancelRipples.forEach((cancel) => cancel());
138
- cancelRipples = [];
158
+ pointerRipples.forEach((cancel) => cancel());
159
+ pointerRipples = [];
160
+ }}
161
+ onkeyup={() => {
162
+ keyboardRipples.forEach((cancel) => cancel());
163
+ keyboardRipples = [];
139
164
  }}
140
165
  />
141
166
 
@@ -1,13 +1,20 @@
1
1
  @theme {
2
2
  --*: initial;
3
3
  --spacing: 0.25rem;
4
- --font-mono: var(--m3-font-mono);
4
+
5
5
  --breakpoint-m: 37.5rem; /* ≅ sm */
6
- --breakpoint-x: 52.5rem; /* ≅ md */
6
+ --breakpoint-x: 52.5rem; /* expanded; ≅ md */
7
7
  --breakpoint-l: 75rem; /* ≅ lg, xl */
8
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;
9
14
  }
10
15
  @theme inline {
16
+ --font-mono: var(--m3-font-mono);
17
+
11
18
  --shadow-1: var(--m3-util-elevation-1);
12
19
  --shadow-2: var(--m3-util-elevation-2);
13
20
  --shadow-3: var(--m3-util-elevation-3);
@@ -91,6 +98,7 @@
91
98
  --color-on-tertiary-container-subtle: rgb(var(--m3-scheme-on-tertiary-container-subtle));
92
99
  --color-error-container-subtle: rgb(var(--m3-scheme-error-container-subtle));
93
100
  --color-on-error-container-subtle: rgb(var(--m3-scheme-on-error-container-subtle));
101
+ --color-util-background: var(--m3-util-background);
94
102
  }
95
103
 
96
104
  @utility transition-fast-spatial {
@@ -159,3 +167,9 @@
159
167
  @utility m3-font-body-small {
160
168
  --: "";
161
169
  }
170
+
171
+ @layer base {
172
+ :root {
173
+ box-sizing: border-box;
174
+ }
175
+ }
@@ -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 `--m3-scheme-${kebabCase}: ${red} ${green} ${blue};`;
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)))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "m3-svelte",
3
- "version": "5.3.3",
3
+ "version": "5.3.6",
4
4
  "license": "Apache-2.0 OR GPL-3.0-only",
5
5
  "repository": "KTibow/m3-svelte",
6
6
  "author": {