miral 0.0.3 → 0.0.5

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/src/Assets.tsx DELETED
@@ -1,41 +0,0 @@
1
- type AssetsProps = {
2
- className?: string;
3
- files: Record<string, string>;
4
- };
5
-
6
- export const Assets = ({ className, files }: AssetsProps) => (
7
- <section className={className}>
8
- <h1>Assets</h1>
9
- {!Object.keys(files).length && <p>No assets found.</p>}
10
- <div className="gl:grid gl:grid-cols-[repeat(auto-fill,minmax(min(100%,12rem),1fr))] gl:gap-4">
11
- {Object.entries(files)
12
- .sort(([a], [b]) => a.localeCompare(b))
13
- .map(([path, url]) => (
14
- <figure
15
- key={path}
16
- className="gl:grid gl:content-start gl:gap-1.5 gl:m-0"
17
- >
18
- <figcaption className="gl:text-left gl:wrap-anywhere">
19
- <a href={url} download={path.split("/").at(-1)}>
20
- {path.split("/").at(-1)}
21
- </a>
22
- </figcaption>
23
- <div className="gl:grid gl:place-items-center gl:min-h-32 gl:p-4 gl:border gl:border-solid gl:border-edge gl:rounded-lg">
24
- {/\.(avif|bmp|gif|ico|jpe?g|png|svg|webp)$/i.test(path) ? (
25
- <img
26
- className="gl:w-full gl:h-32 gl:object-contain"
27
- src={url}
28
- alt=""
29
- loading="lazy"
30
- />
31
- ) : (
32
- <a href={url} download={path.split("/").at(-1)}>
33
- Download
34
- </a>
35
- )}
36
- </div>
37
- </figure>
38
- ))}
39
- </div>
40
- </section>
41
- );
package/src/Controls.tsx DELETED
@@ -1,147 +0,0 @@
1
- import type React from "react";
2
- import type * as z from "zod/mini";
3
- export type Values = Record<string, string | number | boolean>;
4
-
5
- type ControlsProps = {
6
- schema: z.ZodMiniObject;
7
- values: Values;
8
- onChange: (values: Values) => void;
9
- };
10
-
11
- export const Controls = ({ schema, values, onChange }: ControlsProps) => {
12
- return (
13
- <section
14
- className="gl:border-t gl:border-edge gl:text-sm/[1.5] gl:font-normal gl:group-data-isolated/shell:hidden"
15
- aria-labelledby="preview-props-heading"
16
- >
17
- <h2
18
- id="preview-props-heading"
19
- className="gl:m-0 gl:px-4 gl:py-2 gl:text-[length:inherit] gl:font-semibold"
20
- >
21
- Props
22
- </h2>
23
- <form
24
- className="gl:max-h-[30dvh] gl:overflow-auto gl:px-4 gl:pb-2"
25
- onSubmit={preventSubmit}
26
- >
27
- {Object.entries(schema.shape).map(([name, field]) => {
28
- const definition = field._zod.def;
29
- const optional = definition.type === "optional";
30
-
31
- const inner =
32
- optional && "innerType" in definition
33
- ? (definition.innerType as z.ZodMiniType)._zod.def
34
- : definition;
35
-
36
- let options: string[] = [];
37
-
38
- if ("entries" in inner)
39
- options = Object.values(inner.entries as Record<string, string>);
40
- else if ("values" in inner) options = inner.values as string[];
41
-
42
- const value = values[name];
43
-
44
- const handleChange = (
45
- event: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>,
46
- ) => {
47
- const text = event.currentTarget.value;
48
- const next = { ...values };
49
-
50
- if (
51
- event.currentTarget instanceof HTMLInputElement &&
52
- event.currentTarget.type === "checkbox"
53
- )
54
- next[name] = event.currentTarget.checked;
55
- else if (inner.type === "boolean") next[name] = text === "true";
56
- else if (inner.type === "number") next[name] = Number(text);
57
- else next[name] = text;
58
-
59
- if (text === "" && optional) delete next[name];
60
-
61
- if (schema.safeParse(next).success) onChange(next);
62
- };
63
-
64
- if (inner.type === "boolean" && optional) {
65
- return (
66
- <div
67
- key={name}
68
- className="preview-prop-row"
69
- role="radiogroup"
70
- aria-label={name}
71
- >
72
- <span aria-hidden="true">{name}</span>
73
- <div className="gl:flex gl:w-fit gl:border gl:border-solid gl:border-edge gl:rounded-sm">
74
- {[
75
- ["", "Default"],
76
- ["true", "On"],
77
- ["false", "Off"],
78
- ].map(([choice, label]) => (
79
- <label
80
- key={choice}
81
- className="gl:relative gl:py-[0.2rem] gl:px-2 gl:cursor-pointer gl:has-checked:text-paper gl:has-checked:bg-ink gl:focus-within:outline-2 gl:focus-within:outline-solid gl:focus-within:outline-ink gl:focus-within:outline-offset-2"
82
- >
83
- <input
84
- className="gl:absolute gl:inset-0 gl:m-0 gl:opacity-0 gl:cursor-pointer"
85
- type="radio"
86
- name={name}
87
- value={choice}
88
- checked={String(value ?? "") === choice}
89
- onChange={handleChange}
90
- />
91
- {label}
92
- </label>
93
- ))}
94
- </div>
95
- </div>
96
- );
97
- }
98
-
99
- if (inner.type === "boolean") {
100
- return (
101
- <label key={name} className="preview-prop-row">
102
- {name}
103
- <input
104
- className="gl:justify-self-start gl:accent-ink"
105
- type="checkbox"
106
- checked={value === true}
107
- onChange={handleChange}
108
- />
109
- </label>
110
- );
111
- }
112
-
113
- if (options.length) {
114
- return (
115
- <label key={name} className="preview-prop-row">
116
- {name}
117
- <select value={String(value ?? "")} onChange={handleChange}>
118
- {optional && <option value="">Default</option>}
119
- {options.map((item) => (
120
- <option key={item}>{item}</option>
121
- ))}
122
- </select>
123
- </label>
124
- );
125
- }
126
-
127
- if (inner.type !== "string" && inner.type !== "number") return null;
128
-
129
- return (
130
- <label key={name} className="preview-prop-row">
131
- {name}
132
- <input
133
- type={inner.type === "number" ? "number" : "text"}
134
- value={String(value ?? "")}
135
- onChange={handleChange}
136
- />
137
- </label>
138
- );
139
- })}
140
- </form>
141
- </section>
142
- );
143
- };
144
-
145
- function preventSubmit(event: React.FormEvent) {
146
- event.preventDefault();
147
- }
package/src/Nav.tsx DELETED
@@ -1,99 +0,0 @@
1
- import type React from "react";
2
-
3
- type NavProps = {
4
- title?: string;
5
- className?: string;
6
- entries: { path: string; name: string; section: string }[];
7
- activePath?: string;
8
- assetsPath?: string;
9
- names: string[];
10
- selected: string;
11
- theme: string;
12
- layout: string;
13
- isolated: boolean;
14
- link: (params: Record<string, string>) => string;
15
- onLinkClick: React.MouseEventHandler<HTMLAnchorElement>;
16
- };
17
-
18
- export const Nav = ({
19
- title,
20
- className,
21
- entries,
22
- activePath,
23
- assetsPath,
24
- names,
25
- selected,
26
- theme,
27
- layout,
28
- isolated,
29
- link,
30
- onLinkClick,
31
- }: NavProps) => (
32
- <nav
33
- className={[
34
- "gl:overflow-auto gl:wrap-anywhere gl:py-[1.375rem] gl:px-3 gl:border-e gl:border-divider gl:[font-family:Inter,system-ui,sans-serif] gl:transition-opacity gl:duration-200 gl:ease-out gl:group-data-isolated/shell:opacity-0 gl:motion-reduce:transition-none gl:[@media(max-width:600px)]:max-h-[25dvh]",
35
- className,
36
- ]
37
- .filter(Boolean)
38
- .join(" ")}
39
- inert={isolated}
40
- aria-label="Component catalog"
41
- >
42
- {!!title && (
43
- <h1 className="gl:mx-2 gl:mt-0 gl:mb-[1.625rem] gl:text-2xl/[1.1] gl:font-bold gl:tracking-[-0.045em]">
44
- {title}
45
- </h1>
46
- )}
47
- {Array.from(new Set(entries.map((item) => item.section))).map((section) => (
48
- <section key={section} className="gl:[section+&]:mt-[1.375rem]">
49
- <h2 className="gl:mx-2 gl:mt-0 gl:mb-1.5 gl:text-muted gl:text-[0.71875rem]/[1.4] gl:font-[650] gl:tracking-[0.075em] gl:uppercase">
50
- {section}
51
- </h2>
52
- {entries
53
- .filter((item) => item.section === section)
54
- .map((item) => (
55
- <div key={item.path}>
56
- <a
57
- aria-current={
58
- item.path === activePath && selected === "Preview"
59
- ? "page"
60
- : undefined
61
- }
62
- href={link({ component: item.path, theme, layout })}
63
- onClick={onLinkClick}
64
- >
65
- {item.name}
66
- </a>
67
- {item.path === activePath &&
68
- names.map((name) => (
69
- <a
70
- key={name}
71
- className="gl:ms-2 gl:ps-3.5 gl:rounded-l-none"
72
- onClick={onLinkClick}
73
- aria-current={selected === name ? "page" : undefined}
74
- href={link({
75
- component: item.path,
76
- example: name,
77
- theme,
78
- layout,
79
- })}
80
- >
81
- {name.replace(/([a-z])([A-Z])/g, "$1 $2")}
82
- </a>
83
- ))}
84
- </div>
85
- ))}
86
- </section>
87
- ))}
88
- {!!assetsPath && (
89
- <a
90
- className="gl:mt-4"
91
- href={link({ component: assetsPath, theme, layout })}
92
- aria-current={activePath === assetsPath ? "page" : undefined}
93
- onClick={onLinkClick}
94
- >
95
- Assets
96
- </a>
97
- )}
98
- </nav>
99
- );
package/src/Spinner.tsx DELETED
@@ -1,15 +0,0 @@
1
- type SpinnerProps = { className?: string };
2
-
3
- export const Spinner = ({ className }: SpinnerProps) => (
4
- <span
5
- className={[
6
- "gl:fixed gl:inset-0 gl:z-2 gl:m-auto gl:inline-block gl:box-border gl:size-[1em] gl:pointer-events-none gl:rounded-full gl:border-2 gl:border-solid gl:border-current gl:border-r-transparent gl:text-ink gl:motion-safe:animate-spin gl:motion-safe:[animation-duration:700ms]",
7
- className,
8
- ]
9
- .filter(Boolean)
10
- .join(" ")}
11
- data-glasso-spinner
12
- role="status"
13
- aria-label="Loading"
14
- />
15
- );
package/src/Toolbar.tsx DELETED
@@ -1,269 +0,0 @@
1
- import React from "react";
2
- import { Icon } from "./icons.tsx";
3
-
4
- type Position = { x: number; y: number };
5
-
6
- type ToolbarProps = {
7
- children: React.ReactNode;
8
- hidden: boolean;
9
- isolated: boolean;
10
- className?: string;
11
- };
12
-
13
- const storageKey = "glasso.preview:" + location.pathname + ":toolbar";
14
- const guideKey = storageKey + ":guide-seen";
15
-
16
- function read(key: string) {
17
- try {
18
- const value = localStorage.getItem(key);
19
- return value;
20
- } catch {
21
- return null;
22
- }
23
- }
24
-
25
- function save(key: string, value: string) {
26
- try {
27
- localStorage.setItem(key, value);
28
- } catch {
29
- /* Storage can be disabled. */
30
- }
31
- }
32
-
33
- function readPosition(): Position | null {
34
- try {
35
- const value = JSON.parse(read(storageKey) ?? "null");
36
-
37
- if (value && Number.isFinite(value.x) && Number.isFinite(value.y))
38
- return { x: value.x, y: value.y };
39
- } catch {
40
- /* Ignore invalid saved coordinates. */
41
- }
42
-
43
- return null;
44
- }
45
-
46
- function constrain(position: Position, element: HTMLElement) {
47
- const x = Math.max(
48
- 0,
49
- Math.min(
50
- position.x,
51
- document.documentElement.clientWidth - element.offsetWidth - 4,
52
- ),
53
- );
54
-
55
- const y = Math.max(
56
- 0,
57
- Math.min(position.y, window.innerHeight - element.offsetHeight - 4),
58
- );
59
-
60
- return { x, y };
61
- }
62
-
63
- const shortcuts = [
64
- ["Cycle layout", "Shift + L"],
65
- ["Switch theme", "Shift + T"],
66
- ["Toggle full screen", "Shift + F"],
67
- ["Exit full screen", "Esc"],
68
- ["Show or hide toolbar", "Shift + C"],
69
- ];
70
-
71
- export const Toolbar = ({
72
- children,
73
- hidden,
74
- isolated,
75
- className,
76
- }: ToolbarProps) => {
77
- const dock = React.useRef<HTMLDivElement>(null);
78
- const drag = React.useRef<Position | null>(null);
79
- const [position, setPosition] = React.useState(readPosition);
80
- const [guide, setGuide] = React.useState(() => read(guideKey) !== "1");
81
- const [dragging, setDragging] = React.useState(false);
82
-
83
- React.useEffect(() => {
84
- if (guide && !hidden && !isolated) save(guideKey, "1");
85
- }, [guide, hidden, isolated]);
86
-
87
- React.useLayoutEffect(() => {
88
- const element = dock.current;
89
- if (!element) return;
90
-
91
- const fit = () =>
92
- setPosition((current) => {
93
- if (!current) return current;
94
-
95
- const next = constrain(current, element);
96
- if (next.x === current.x && next.y === current.y) return current;
97
- return next;
98
- });
99
-
100
- fit();
101
-
102
- const observer = new ResizeObserver(fit);
103
-
104
- observer.observe(element);
105
- window.addEventListener("resize", fit);
106
-
107
- return () => {
108
- observer.disconnect();
109
- window.removeEventListener("resize", fit);
110
- };
111
- }, []);
112
-
113
- const handlePointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {
114
- if (event.button !== 0 || !event.isPrimary || !dock.current) return;
115
-
116
- const rect = dock.current.getBoundingClientRect();
117
-
118
- drag.current = {
119
- x: event.clientX - rect.left,
120
- y: event.clientY - rect.top,
121
- };
122
-
123
- event.currentTarget.setPointerCapture(event.pointerId);
124
- setDragging(true);
125
- };
126
-
127
- const handlePointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {
128
- if (
129
- !drag.current ||
130
- !dock.current ||
131
- !event.currentTarget.hasPointerCapture(event.pointerId)
132
- )
133
- return;
134
-
135
- const next = constrain(
136
- { x: event.clientX - drag.current.x, y: event.clientY - drag.current.y },
137
- dock.current,
138
- );
139
-
140
- setPosition(next);
141
- };
142
-
143
- const handlePointerUp = (event: React.PointerEvent<HTMLButtonElement>) => {
144
- if (
145
- !drag.current ||
146
- !dock.current ||
147
- !event.currentTarget.hasPointerCapture(event.pointerId)
148
- )
149
- return;
150
-
151
- const next = constrain(
152
- { x: event.clientX - drag.current.x, y: event.clientY - drag.current.y },
153
- dock.current,
154
- );
155
-
156
- setPosition(next);
157
- save(storageKey, JSON.stringify(next));
158
- };
159
-
160
- const handleLostPointerCapture = () => {
161
- drag.current = null;
162
- setDragging(false);
163
- };
164
-
165
- const handleGripKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
166
- if (
167
- !dock.current ||
168
- !["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)
169
- )
170
- return;
171
-
172
- event.preventDefault();
173
-
174
- const rect = dock.current.getBoundingClientRect();
175
-
176
- const next = constrain(
177
- {
178
- x:
179
- rect.left +
180
- 16 *
181
- (Number(event.key === "ArrowRight") -
182
- Number(event.key === "ArrowLeft")),
183
- y:
184
- rect.top +
185
- 16 *
186
- (Number(event.key === "ArrowDown") -
187
- Number(event.key === "ArrowUp")),
188
- },
189
- dock.current,
190
- );
191
-
192
- setPosition(next);
193
- save(storageKey, JSON.stringify(next));
194
- };
195
-
196
- const handleDismissClick = () => setGuide(false);
197
- return (
198
- <div
199
- ref={dock}
200
- className={[
201
- "gl:group/dock gl:fixed gl:top-3 gl:right-3 gl:w-max gl:max-w-screen gl:text-ink gl:text-sm/[1.5] gl:font-normal gl:transition-[opacity,transform,translate,scale] gl:duration-[160ms] gl:ease-out gl:data-hidden:opacity-0 gl:data-hidden:-translate-y-1 gl:data-hidden:scale-[0.98] gl:data-hidden:pointer-events-none gl:motion-reduce:transition-none",
202
- className,
203
- ]
204
- .filter(Boolean)
205
- .join(" ")}
206
- data-hidden={hidden || undefined}
207
- data-dragging={dragging || undefined}
208
- inert={hidden}
209
- style={
210
- position
211
- ? { left: position.x, top: position.y, right: "auto" }
212
- : undefined
213
- }
214
- >
215
- <div
216
- className="preview-toolbar gl:w-max gl:ms-auto gl:flex gl:items-center gl:p-[0.2rem] gl:border gl:border-solid gl:border-edge gl:rounded-[0.65rem] gl:bg-paper gl:text-ink"
217
- role="group"
218
- aria-label="Preview settings"
219
- >
220
- <button
221
- type="button"
222
- className="gl:cursor-grab gl:touch-none gl:select-none gl:group-data-dragging/dock:cursor-grabbing"
223
- title="Move toolbar · Drag or use arrow keys"
224
- aria-label="Move toolbar"
225
- onKeyDown={handleGripKeyDown}
226
- onPointerDown={handlePointerDown}
227
- onPointerMove={handlePointerMove}
228
- onPointerUp={handlePointerUp}
229
- onLostPointerCapture={handleLostPointerCapture}
230
- >
231
- <Icon name="grip" />
232
- </button>
233
- {children}
234
- </div>
235
- {guide && (
236
- <aside
237
- className="gl:mt-[0.35rem] gl:p-[0.65rem] gl:border gl:border-solid gl:border-edge gl:rounded-[0.65rem] gl:bg-paper gl:max-h-[calc(100dvh-3.5rem)] gl:overflow-auto"
238
- aria-label="Preview shortcuts"
239
- >
240
- <div className="gl:flex gl:gap-[0.35rem] gl:justify-between">
241
- <strong className="gl:font-[650]">Preview shortcuts</strong>
242
- <button
243
- type="button"
244
- className="gl:cursor-pointer"
245
- aria-label="Dismiss shortcut guide"
246
- onClick={handleDismissClick}
247
- >
248
- <Icon name="close" />
249
- </button>
250
- </div>
251
- <p className="gl:m-0 gl:mt-1">Drag the handle to move the toolbar.</p>
252
- <dl className="gl:m-0 gl:mt-2 gl:flex gl:flex-col gl:gap-[0.35rem] gl:justify-between">
253
- {shortcuts.map(([label, keys]) => (
254
- <div
255
- key={keys}
256
- className="gl:flex gl:gap-[0.35rem] gl:justify-between"
257
- >
258
- <dt>{label}</dt>
259
- <dd className="gl:m-0">
260
- <kbd className="gl:[font:inherit]">{keys}</kbd>
261
- </dd>
262
- </div>
263
- ))}
264
- </dl>
265
- </aside>
266
- )}
267
- </div>
268
- );
269
- };