@auscera/design-labs 0.0.0-stage → 0.1.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/apps/workspace/.skills/design-labs/SKILL.md +63 -0
- package/apps/workspace/.skills/design-labs/references/commands.md +38 -0
- package/apps/workspace/AGENTS.md +9 -0
- package/apps/workspace/app/(lab)/compare/page.tsx +2 -0
- package/apps/workspace/app/(lab)/lab.css +412 -0
- package/apps/workspace/app/(lab)/layout.tsx +21 -0
- package/apps/workspace/app/(lab)/page.tsx +2 -0
- package/apps/workspace/app/api/annotations/route.ts +94 -0
- package/apps/workspace/app/api/versions/events/route.ts +63 -0
- package/apps/workspace/app/api/versions/route.ts +7 -0
- package/apps/workspace/components/animated-icons.tsx +72 -0
- package/apps/workspace/components/dotmatrix-loader.css +1228 -0
- package/apps/workspace/components/glass-controls.tsx +47 -0
- package/apps/workspace/components/lab-providers.tsx +17 -0
- package/apps/workspace/components/molecules/brand-lockup.tsx +13 -0
- package/apps/workspace/components/molecules/pane-url-popover.css +92 -0
- package/apps/workspace/components/molecules/pane-url-popover.tsx +191 -0
- package/apps/workspace/components/pane-preferences.tsx +75 -0
- package/apps/workspace/components/pane-viewport.css +34 -0
- package/apps/workspace/components/pane-viewport.tsx +199 -0
- package/apps/workspace/components/preview-pane.css +293 -0
- package/apps/workspace/components/preview-pane.tsx +662 -0
- package/apps/workspace/components/ui/dotm-triangle-11.tsx +170 -0
- package/apps/workspace/components/ui/dotmatrix-core.tsx +1649 -0
- package/apps/workspace/components/ui/dotmatrix-hooks.ts +224 -0
- package/apps/workspace/components/version-select.tsx +220 -0
- package/apps/workspace/components/workspace.tsx +313 -0
- package/apps/workspace/eslint.config.mjs +3 -0
- package/apps/workspace/lab.config.json +1 -0
- package/apps/workspace/lib/annotation-export.ts +28 -0
- package/apps/workspace/lib/annotation-types.ts +38 -0
- package/apps/workspace/lib/device-presets.ts +103 -0
- package/apps/workspace/lib/use-annotation-bridge.ts +130 -0
- package/apps/workspace/lib/version-types.ts +12 -0
- package/apps/workspace/lib/website-url.ts +78 -0
- package/apps/workspace/next-env.d.ts +6 -0
- package/apps/workspace/next.config.mjs +1 -0
- package/apps/workspace/package.json +35 -0
- package/apps/workspace/public/apple-touch-icon.png +0 -0
- package/apps/workspace/public/brand/design-labs-script.LICENSE.txt +93 -0
- package/apps/workspace/public/brand/design-labs-script.woff2 +0 -0
- package/apps/workspace/public/brand/logo.webp +0 -0
- package/apps/workspace/public/brand/wordmark.css +42 -0
- package/apps/workspace/public/favicon.ico +0 -0
- package/apps/workspace/public/icon-192.png +0 -0
- package/apps/workspace/public/icon-512.png +0 -0
- package/apps/workspace/public/preview-bridge.js +411 -0
- package/apps/workspace/public/site.webmanifest +1 -0
- package/apps/workspace/scripts/annotation-store.mjs +308 -0
- package/apps/workspace/scripts/lab.mjs +414 -0
- package/apps/workspace/scripts/migrate.mjs +2 -0
- package/apps/workspace/scripts/prepare-preview.mjs +203 -0
- package/apps/workspace/tsconfig.json +24 -0
- package/package.json +13 -3
- package/scripts/install.mjs +71 -0
- package/scripts/update.mjs +155 -0
- package/README.md +0 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { motion, useReducedMotion } from "framer-motion";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
export function GlassToggle({
|
|
5
|
+
value,
|
|
6
|
+
onChange,
|
|
7
|
+
}: {
|
|
8
|
+
value: "landing" | "dashboard";
|
|
9
|
+
onChange: (value: "landing" | "dashboard") => void;
|
|
10
|
+
}) {
|
|
11
|
+
const id = useId();
|
|
12
|
+
const reduced = useReducedMotion();
|
|
13
|
+
return (
|
|
14
|
+
<nav className="category-tabs glass-toggle" aria-label="Website category">
|
|
15
|
+
{(["landing", "dashboard"] as const).map((c) => (
|
|
16
|
+
<button key={c} aria-pressed={value === c} onClick={() => onChange(c)}>
|
|
17
|
+
{value === c && (
|
|
18
|
+
<motion.span
|
|
19
|
+
aria-hidden
|
|
20
|
+
className="glass-toggle-thumb"
|
|
21
|
+
layoutId={id}
|
|
22
|
+
transition={
|
|
23
|
+
reduced
|
|
24
|
+
? { duration: 0 }
|
|
25
|
+
: { type: "spring", stiffness: 350, damping: 28 }
|
|
26
|
+
}
|
|
27
|
+
/>
|
|
28
|
+
)}
|
|
29
|
+
<span className="glass-toggle-label">
|
|
30
|
+
{c === "landing" ? "Landing pages" : "Dashboards"}
|
|
31
|
+
</span>
|
|
32
|
+
</button>
|
|
33
|
+
))}
|
|
34
|
+
</nav>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
export function EmptyState({ children }: { children: React.ReactNode }) {
|
|
38
|
+
return (
|
|
39
|
+
<div className="empty-state centered-empty">
|
|
40
|
+
<div className="empty-animation" aria-hidden>
|
|
41
|
+
<DotmTriangle11 size={48} dotSize={4} speed={1.2} bloom />
|
|
42
|
+
</div>
|
|
43
|
+
<div>{children}</div>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
import { DotmTriangle11 } from "./ui/dotm-triangle-11";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { PanePreferencesProvider } from "./pane-preferences";
|
|
5
|
+
export function LabProviders({ children }: { children: React.ReactNode }) {
|
|
6
|
+
const [client] = useState(
|
|
7
|
+
() =>
|
|
8
|
+
new QueryClient({
|
|
9
|
+
defaultOptions: { queries: { retry: 1, refetchOnWindowFocus: false } },
|
|
10
|
+
}),
|
|
11
|
+
);
|
|
12
|
+
return (
|
|
13
|
+
<QueryClientProvider client={client}>
|
|
14
|
+
<PanePreferencesProvider>{children}</PanePreferencesProvider>
|
|
15
|
+
</QueryClientProvider>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Image from "next/image";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
|
|
4
|
+
/** Brand molecule: connected words stay intact on either side of the symbol. */
|
|
5
|
+
export function BrandLockup() {
|
|
6
|
+
return (
|
|
7
|
+
<Link className="brand dl-brand-lockup" href="/" aria-label="Design Labs home">
|
|
8
|
+
<span className="dl-brand-word dl-brand-design" aria-hidden="true">Design</span>
|
|
9
|
+
<Image src="/brand/logo.webp" width={48} height={48} alt="" priority />
|
|
10
|
+
<span className="dl-brand-word dl-brand-labs" aria-hidden="true">Labs</span>
|
|
11
|
+
</Link>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
.pane-url-popover {
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: 450;
|
|
4
|
+
padding: 14px;
|
|
5
|
+
overflow: auto;
|
|
6
|
+
overscroll-behavior: contain;
|
|
7
|
+
border: 1px solid var(--lab-pill-border);
|
|
8
|
+
border-radius: 18px;
|
|
9
|
+
color: var(--lab-text);
|
|
10
|
+
background: linear-gradient(
|
|
11
|
+
to bottom,
|
|
12
|
+
var(--lab-pill-from),
|
|
13
|
+
var(--lab-panel)
|
|
14
|
+
);
|
|
15
|
+
box-shadow:
|
|
16
|
+
inset 0 1px 0 var(--lab-pill-bevel),
|
|
17
|
+
0 12px 30px rgba(0, 0, 0, 0.6);
|
|
18
|
+
backdrop-filter: blur(20px);
|
|
19
|
+
font-size: 12px;
|
|
20
|
+
scrollbar-width: thin;
|
|
21
|
+
}
|
|
22
|
+
.pane-url-heading {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: space-between;
|
|
26
|
+
gap: 12px;
|
|
27
|
+
margin-bottom: 12px;
|
|
28
|
+
}
|
|
29
|
+
.pane-url-heading strong {
|
|
30
|
+
font-size: 12px;
|
|
31
|
+
font-weight: 550;
|
|
32
|
+
}
|
|
33
|
+
.pane-url-popover .button {
|
|
34
|
+
min-height: 30px;
|
|
35
|
+
padding: 6px 10px;
|
|
36
|
+
gap: 6px;
|
|
37
|
+
font-size: 11px;
|
|
38
|
+
}
|
|
39
|
+
.pane-url-heading .button {
|
|
40
|
+
padding: 7px;
|
|
41
|
+
}
|
|
42
|
+
.pane-url-popover form {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
gap: 8px;
|
|
46
|
+
}
|
|
47
|
+
.pane-url-popover label {
|
|
48
|
+
color: var(--lab-muted);
|
|
49
|
+
font-size: 11px;
|
|
50
|
+
}
|
|
51
|
+
.pane-url-popover input {
|
|
52
|
+
display: block;
|
|
53
|
+
width: 100%;
|
|
54
|
+
min-width: 0;
|
|
55
|
+
min-height: 38px;
|
|
56
|
+
padding: 9px 13px;
|
|
57
|
+
border: 1px solid var(--lab-line);
|
|
58
|
+
border-radius: 9999px;
|
|
59
|
+
color: var(--lab-text);
|
|
60
|
+
background: var(--lab-canvas);
|
|
61
|
+
font: inherit;
|
|
62
|
+
}
|
|
63
|
+
.pane-url-popover input::placeholder {
|
|
64
|
+
color: var(--lab-text);
|
|
65
|
+
opacity: 0.45;
|
|
66
|
+
}
|
|
67
|
+
.pane-url-popover input:focus-visible {
|
|
68
|
+
outline: 1px solid var(--lab-text);
|
|
69
|
+
outline-offset: 2px;
|
|
70
|
+
}
|
|
71
|
+
.pane-url-popover input:-webkit-autofill {
|
|
72
|
+
-webkit-text-fill-color: var(--lab-text);
|
|
73
|
+
-webkit-box-shadow: 0 0 0 100px var(--lab-canvas) inset;
|
|
74
|
+
caret-color: var(--lab-text);
|
|
75
|
+
}
|
|
76
|
+
.pane-url-popover p {
|
|
77
|
+
margin: 0;
|
|
78
|
+
font-size: 11px;
|
|
79
|
+
line-height: 1.55;
|
|
80
|
+
overflow-wrap: anywhere;
|
|
81
|
+
}
|
|
82
|
+
.pane-url-hint {
|
|
83
|
+
color: var(--lab-muted);
|
|
84
|
+
}
|
|
85
|
+
.pane-url-error {
|
|
86
|
+
color: var(--lab-text);
|
|
87
|
+
}
|
|
88
|
+
.pane-url-footer {
|
|
89
|
+
display: flex;
|
|
90
|
+
justify-content: flex-end;
|
|
91
|
+
padding-top: 4px;
|
|
92
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { ArrowUpRight, X } from "../animated-icons";
|
|
6
|
+
import { normalizeWebsiteUrl } from "../../lib/website-url";
|
|
7
|
+
import "./pane-url-popover.css";
|
|
8
|
+
|
|
9
|
+
type PaneUrlPopoverProps = {
|
|
10
|
+
anchor: HTMLElement;
|
|
11
|
+
initialValue: string;
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
onSubmit: (url: string) => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Non-modal URL entry, shared by the pane action and its website picker. */
|
|
17
|
+
export function PaneUrlPopover({
|
|
18
|
+
anchor,
|
|
19
|
+
initialValue,
|
|
20
|
+
onClose,
|
|
21
|
+
onSubmit,
|
|
22
|
+
}: PaneUrlPopoverProps) {
|
|
23
|
+
const id = useId();
|
|
24
|
+
const panel = useRef<HTMLDivElement>(null);
|
|
25
|
+
const input = useRef<HTMLInputElement>(null);
|
|
26
|
+
const close = useRef(onClose);
|
|
27
|
+
close.current = onClose;
|
|
28
|
+
const [value, setValue] = useState(initialValue);
|
|
29
|
+
const [error, setError] = useState("");
|
|
30
|
+
const [position, setPosition] = useState<{
|
|
31
|
+
left: number;
|
|
32
|
+
top: number;
|
|
33
|
+
width: number;
|
|
34
|
+
maxHeight: number;
|
|
35
|
+
}>();
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const panelElement = panel.current;
|
|
39
|
+
const place = () => {
|
|
40
|
+
const rect = anchor.getBoundingClientRect();
|
|
41
|
+
const viewport = window.visualViewport;
|
|
42
|
+
const left = viewport?.offsetLeft || 0;
|
|
43
|
+
const top = viewport?.offsetTop || 0;
|
|
44
|
+
const width = viewport?.width || window.innerWidth;
|
|
45
|
+
const height = viewport?.height || window.innerHeight;
|
|
46
|
+
const panelWidth = Math.max(0, Math.min(400, width - 24));
|
|
47
|
+
const wantedHeight = panel.current?.scrollHeight || 230;
|
|
48
|
+
const below = top + height - rect.bottom - 18;
|
|
49
|
+
const above = rect.top - top - 18;
|
|
50
|
+
const upward = below < wantedHeight && above > below;
|
|
51
|
+
const available = Math.max(0, upward ? above : below);
|
|
52
|
+
const maxHeight = Math.min(wantedHeight, available);
|
|
53
|
+
setPosition({
|
|
54
|
+
left: Math.max(
|
|
55
|
+
left + 12,
|
|
56
|
+
Math.min(rect.left, left + width - panelWidth - 12),
|
|
57
|
+
),
|
|
58
|
+
top: upward
|
|
59
|
+
? Math.max(top + 12, rect.top - maxHeight - 6)
|
|
60
|
+
: rect.bottom + 6,
|
|
61
|
+
width: panelWidth,
|
|
62
|
+
maxHeight,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const dismiss = (event: PointerEvent) => {
|
|
66
|
+
if (
|
|
67
|
+
!panel.current?.contains(event.target as Node) &&
|
|
68
|
+
!anchor.contains(event.target as Node)
|
|
69
|
+
)
|
|
70
|
+
close.current();
|
|
71
|
+
};
|
|
72
|
+
const escape = (event: KeyboardEvent) => {
|
|
73
|
+
if (event.key !== "Escape") return;
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
event.stopPropagation();
|
|
76
|
+
close.current();
|
|
77
|
+
};
|
|
78
|
+
const blur = () => close.current();
|
|
79
|
+
place();
|
|
80
|
+
const observer = new ResizeObserver(place);
|
|
81
|
+
if (panel.current) observer.observe(panel.current);
|
|
82
|
+
observer.observe(anchor);
|
|
83
|
+
document.addEventListener("pointerdown", dismiss);
|
|
84
|
+
document.addEventListener("keydown", escape, true);
|
|
85
|
+
window.addEventListener("resize", place);
|
|
86
|
+
window.addEventListener("scroll", place, true);
|
|
87
|
+
window.addEventListener("blur", blur);
|
|
88
|
+
window.visualViewport?.addEventListener("resize", place);
|
|
89
|
+
window.visualViewport?.addEventListener("scroll", place);
|
|
90
|
+
return () => {
|
|
91
|
+
observer.disconnect();
|
|
92
|
+
document.removeEventListener("pointerdown", dismiss);
|
|
93
|
+
document.removeEventListener("keydown", escape, true);
|
|
94
|
+
window.removeEventListener("resize", place);
|
|
95
|
+
window.removeEventListener("scroll", place, true);
|
|
96
|
+
window.removeEventListener("blur", blur);
|
|
97
|
+
window.visualViewport?.removeEventListener("resize", place);
|
|
98
|
+
window.visualViewport?.removeEventListener("scroll", place);
|
|
99
|
+
queueMicrotask(() => {
|
|
100
|
+
// StrictMode replays effects without removing the popup. Only restore
|
|
101
|
+
// the trigger after a real unmount, so it cannot steal the input focus.
|
|
102
|
+
if (panelElement && !panelElement.isConnected && anchor.isConnected) {
|
|
103
|
+
anchor.focus({ preventScroll: true });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
}, [anchor]);
|
|
108
|
+
|
|
109
|
+
const visible = Boolean(position);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!visible) return;
|
|
112
|
+
// The positioning render has now committed visibility before focusing.
|
|
113
|
+
input.current?.focus({ preventScroll: true });
|
|
114
|
+
input.current?.select();
|
|
115
|
+
}, [visible]);
|
|
116
|
+
|
|
117
|
+
return createPortal(
|
|
118
|
+
<div
|
|
119
|
+
ref={panel}
|
|
120
|
+
className="pane-url-popover"
|
|
121
|
+
role="dialog"
|
|
122
|
+
aria-label="Website URL entry"
|
|
123
|
+
style={{ ...position, visibility: position ? "visible" : "hidden" }}
|
|
124
|
+
>
|
|
125
|
+
<div className="pane-url-heading">
|
|
126
|
+
<strong>Website address</strong>
|
|
127
|
+
<button
|
|
128
|
+
className="button"
|
|
129
|
+
type="button"
|
|
130
|
+
aria-label="Close URL entry"
|
|
131
|
+
onClick={onClose}
|
|
132
|
+
>
|
|
133
|
+
<X size={14} aria-hidden />
|
|
134
|
+
</button>
|
|
135
|
+
</div>
|
|
136
|
+
<form
|
|
137
|
+
aria-label="Open website URL"
|
|
138
|
+
onSubmit={(event) => {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
try {
|
|
141
|
+
const url = normalizeWebsiteUrl(value);
|
|
142
|
+
setError("");
|
|
143
|
+
onSubmit(url);
|
|
144
|
+
} catch (failure) {
|
|
145
|
+
setError(
|
|
146
|
+
failure instanceof Error
|
|
147
|
+
? failure.message
|
|
148
|
+
: "Enter a valid website address.",
|
|
149
|
+
);
|
|
150
|
+
input.current?.focus();
|
|
151
|
+
}
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
<label htmlFor={id}>Website URL</label>
|
|
155
|
+
<input
|
|
156
|
+
ref={input}
|
|
157
|
+
id={id}
|
|
158
|
+
type="text"
|
|
159
|
+
inputMode="url"
|
|
160
|
+
name="website"
|
|
161
|
+
autoCapitalize="none"
|
|
162
|
+
autoComplete="url"
|
|
163
|
+
spellCheck={false}
|
|
164
|
+
placeholder="https://example.com"
|
|
165
|
+
maxLength={8192}
|
|
166
|
+
value={value}
|
|
167
|
+
aria-invalid={Boolean(error)}
|
|
168
|
+
aria-describedby={error ? `${id}-error ${id}-hint` : `${id}-hint`}
|
|
169
|
+
onChange={(event) => {
|
|
170
|
+
setValue(event.target.value);
|
|
171
|
+
if (error) setError("");
|
|
172
|
+
}}
|
|
173
|
+
/>
|
|
174
|
+
{error && (
|
|
175
|
+
<p className="pane-url-error" id={`${id}-error`} role="alert">
|
|
176
|
+
{error}
|
|
177
|
+
</p>
|
|
178
|
+
)}
|
|
179
|
+
<p className="pane-url-hint" id={`${id}-hint`}>
|
|
180
|
+
If a website blocks its preview, use Open in new tab.
|
|
181
|
+
</p>
|
|
182
|
+
<div className="pane-url-footer">
|
|
183
|
+
<button className="button" type="submit">
|
|
184
|
+
Open website <ArrowUpRight size={14} aria-hidden />
|
|
185
|
+
</button>
|
|
186
|
+
</div>
|
|
187
|
+
</form>
|
|
188
|
+
</div>,
|
|
189
|
+
document.body,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
+
import type { TargetContext } from "../lib/annotation-types";
|
|
4
|
+
type Preference = {
|
|
5
|
+
sourceMode: "version" | "url";
|
|
6
|
+
url: string;
|
|
7
|
+
responsive: boolean;
|
|
8
|
+
size: { width: number; height: number };
|
|
9
|
+
tools: boolean;
|
|
10
|
+
draft?: { id?: string; comment: string; target: TargetContext };
|
|
11
|
+
};
|
|
12
|
+
const initial: Preference = {
|
|
13
|
+
sourceMode: "version",
|
|
14
|
+
url: "",
|
|
15
|
+
responsive: false,
|
|
16
|
+
size: { width: 390, height: 844 },
|
|
17
|
+
tools: false,
|
|
18
|
+
};
|
|
19
|
+
const Context = createContext<
|
|
20
|
+
| {
|
|
21
|
+
values: Record<string, Preference>;
|
|
22
|
+
update: (id: string, patch: Partial<Preference>) => void;
|
|
23
|
+
}
|
|
24
|
+
| undefined
|
|
25
|
+
>(undefined);
|
|
26
|
+
export function PanePreferencesProvider({
|
|
27
|
+
children,
|
|
28
|
+
}: {
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
}) {
|
|
31
|
+
const [values, setValues] = useState<Record<string, Preference>>({});
|
|
32
|
+
const [hydrated, setHydrated] = useState(false);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
try {
|
|
35
|
+
const saved = localStorage.getItem("design-labs:pane-preferences:v1");
|
|
36
|
+
if (saved) { const parsed = JSON.parse(saved); if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) setValues(parsed); }
|
|
37
|
+
} catch { /* Unavailable or invalid browser storage: keep in-memory state. */ }
|
|
38
|
+
setHydrated(true);
|
|
39
|
+
}, []);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!hydrated) return;
|
|
42
|
+
try { localStorage.setItem("design-labs:pane-preferences:v1", JSON.stringify(values)); } catch { /* Keep the current session usable. */ }
|
|
43
|
+
}, [values, hydrated]);
|
|
44
|
+
return (
|
|
45
|
+
<Context.Provider
|
|
46
|
+
value={{
|
|
47
|
+
values,
|
|
48
|
+
update: (id, patch) =>
|
|
49
|
+
setValues((old) => ({
|
|
50
|
+
...old,
|
|
51
|
+
[id]: { ...initial, ...old[id], ...patch },
|
|
52
|
+
})),
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{children}
|
|
56
|
+
</Context.Provider>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
export function usePanePreference(id: string) {
|
|
60
|
+
const context = useContext(Context);
|
|
61
|
+
if (!context) throw Error("Pane preference provider missing");
|
|
62
|
+
return [
|
|
63
|
+
{ ...initial, ...context.values[id] },
|
|
64
|
+
(patch: Partial<Preference>) => context.update(id, patch),
|
|
65
|
+
] as const;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useClonePanePreference() {
|
|
69
|
+
const context = useContext(Context);
|
|
70
|
+
if (!context) throw Error("Pane preference provider missing");
|
|
71
|
+
return (from: string, to: string) => {
|
|
72
|
+
const value = { ...initial, ...context.values[from] };
|
|
73
|
+
context.update(to, { ...value, tools: false, draft: undefined });
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
.pane-viewport { position:relative;display:flex;flex:1;align-items:stretch;min-width:0;min-height:0;overflow:hidden;background:var(--lab-canvas) }
|
|
2
|
+
.preview-scaled-slot { position:relative;flex:1;min-width:0;min-height:0 }
|
|
3
|
+
.preview-canvas-frame { position:relative;width:100%;height:100%;overflow:hidden;transform-origin:top left }
|
|
4
|
+
.pane-preview iframe,.workspace-pane .pane-preview iframe { display:block;width:100%;height:100%;min-height:0;flex:none;border:0 }
|
|
5
|
+
.pane-viewport.is-responsive { align-items:center;justify-content:center;padding:20px }
|
|
6
|
+
.is-responsive .preview-scaled-slot { flex:none;max-width:none }
|
|
7
|
+
.is-responsive .preview-canvas-frame { flex:none;transform:scale(var(--preview-scale));box-shadow:0 0 0 1px var(--lab-line) }
|
|
8
|
+
.preview-resize-handle { position:absolute;z-index:4;border:0;padding:0;border-radius:4px;background:transparent;color:var(--lab-muted);touch-action:none }
|
|
9
|
+
.preview-resize-handle::after { content:"";position:absolute;background:currentColor;border-radius:9999px;opacity:.65;transition:opacity 120ms }
|
|
10
|
+
.preview-resize-handle:hover::after,.preview-resize-handle:focus-visible::after { opacity:1 }
|
|
11
|
+
.preview-resize-handle:focus-visible { outline:2px solid var(--lab-text);outline-offset:1px }
|
|
12
|
+
.handle-left,.handle-right { top:0;width:18px;height:100%;cursor:ew-resize }
|
|
13
|
+
.handle-left { left:-19px }.handle-right { right:-19px }
|
|
14
|
+
.handle-left::after,.handle-right::after { width:3px;height:32px;top:calc(50% - 16px);left:7px }
|
|
15
|
+
.handle-bottom { left:0;bottom:-19px;width:100%;height:18px;cursor:ns-resize }
|
|
16
|
+
.handle-bottom::after { height:3px;width:32px;left:calc(50% - 16px);top:7px }
|
|
17
|
+
.handle-bottom-left,.handle-bottom-right { width:18px;height:18px;bottom:-19px }
|
|
18
|
+
.handle-bottom-left { left:-19px;cursor:nesw-resize }.handle-bottom-right { right:-19px;cursor:nwse-resize }
|
|
19
|
+
.handle-bottom-left::after,.handle-bottom-right::after { width:9px;height:9px;top:1px;background:transparent;border-bottom:2px solid currentColor;border-radius:1px }
|
|
20
|
+
.handle-bottom-left::after { border-left:2px solid currentColor;right:1px }.handle-bottom-right::after { border-right:2px solid currentColor;left:1px }
|
|
21
|
+
.preview-scale-readout { position:absolute;bottom:3px;left:5px;font-size:9px;line-height:12px;color:var(--lab-muted);pointer-events:none;font-variant-numeric:tabular-nums }
|
|
22
|
+
.preview-drag-shield { position:absolute;inset:0;z-index:5;cursor:grabbing;touch-action:none }
|
|
23
|
+
.device-controls { display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0 }
|
|
24
|
+
.device-preset-trigger,.device-rotate { display:inline-flex;align-items:center;justify-content:center;gap:7px;min-height:30px;padding:5px 10px;border:1px solid var(--lab-pill-border);border-radius:9999px;color:var(--lab-text);background:linear-gradient(to bottom,var(--lab-pill-from),var(--lab-pill-to));box-shadow:inset 0 1px 0 var(--lab-pill-bevel),0 3px 7px rgba(0,0,0,.5);backdrop-filter:blur(20px);font:inherit;font-size:11px;cursor:pointer;transition:transform 150ms,background 150ms }
|
|
25
|
+
.device-preset-trigger { max-width:220px;white-space:nowrap }.device-preset-trigger span { overflow:hidden;text-overflow:ellipsis }.device-preset-trigger svg,.device-rotate svg { flex:none }
|
|
26
|
+
.device-rotate { width:30px;padding:0;flex:none }.device-preset-trigger:hover,.device-rotate:hover { background:var(--lab-pill-hover) }.device-preset-trigger:active,.device-rotate:active { transform:scale(.95) }
|
|
27
|
+
.device-preset-trigger:focus-visible,.device-rotate:focus-visible,.device-dimensions input:focus-visible { outline:2px solid var(--lab-text);outline-offset:2px }
|
|
28
|
+
.device-dimensions { display:flex;align-items:center;gap:3px;color:var(--lab-muted) }.device-dimension-field { display:flex;align-items:center;gap:5px;font-size:11px }
|
|
29
|
+
.device-dimensions input { width:52px;min-height:28px;padding:4px;border:1px solid var(--lab-line);border-radius:7px;background:var(--lab-panel);color:var(--lab-text);font:inherit;font-size:11px;text-align:center;font-variant-numeric:tabular-nums;appearance:textfield;-moz-appearance:textfield }
|
|
30
|
+
.device-dimensions input::-webkit-inner-spin-button,.device-dimensions input::-webkit-outer-spin-button { -webkit-appearance:none;margin:0 }
|
|
31
|
+
.device-menu { position:fixed;z-index:350;overflow-y:auto;overscroll-behavior:contain;padding:6px;border:1px solid var(--lab-pill-border);border-radius:16px;color:var(--lab-text);background:var(--lab-panel);box-shadow:inset 0 1px 0 var(--lab-pill-bevel),0 12px 30px rgba(0,0,0,.65);font-size:12px;scrollbar-width:none }
|
|
32
|
+
.device-menu::-webkit-scrollbar { display:none }.device-group-label { padding:12px 10px 5px;color:var(--lab-muted);font-size:10px;font-weight:600;letter-spacing:.02em }
|
|
33
|
+
.device-option { display:flex;align-items:center;gap:7px;min-height:34px;padding:7px 10px;border-radius:9999px;cursor:pointer;white-space:nowrap }.device-option>span { flex:1;overflow:hidden;text-overflow:ellipsis }.device-option small { color:var(--lab-muted);font-size:10px;font-variant-numeric:tabular-nums }.device-option svg { flex:none }.device-option.is-active,.device-option[aria-selected="true"] { background:var(--lab-pill-hover) }
|
|
34
|
+
@media (prefers-reduced-motion:reduce) { .preview-resize-handle::after,.device-preset-trigger,.device-rotate { transition:none }.device-preset-trigger:active,.device-rotate:active { transform:none } }
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useRef, useState, type CSSProperties, type KeyboardEvent, type PointerEvent as ReactPointerEvent, type ReactNode } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { Check, ChevronDown, RotateCw } from "./animated-icons";
|
|
6
|
+
import { clampViewport, DEVICE_GROUPS, DEVICE_PRESETS, VIEWPORT_LIMITS, type ViewportSize } from "../lib/device-presets";
|
|
7
|
+
import "./pane-viewport.css";
|
|
8
|
+
|
|
9
|
+
export type { ViewportSize } from "../lib/device-presets";
|
|
10
|
+
type Edge = "left" | "right" | "bottom" | "bottom left" | "bottom right";
|
|
11
|
+
|
|
12
|
+
/** The iframe and annotation layer stay mounted when responsive mode changes. */
|
|
13
|
+
export function PaneViewport({ responsive, size, onSizeChange, children }: {
|
|
14
|
+
responsive: boolean;
|
|
15
|
+
size: ViewportSize;
|
|
16
|
+
onSizeChange: (size: ViewportSize) => void;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}) {
|
|
19
|
+
const stage = useRef<HTMLDivElement>(null);
|
|
20
|
+
const [space, setSpace] = useState({ width: 0, height: 0 });
|
|
21
|
+
const [dragging, setDragging] = useState(false);
|
|
22
|
+
const cleanupDrag = useRef<(() => void) | null>(null);
|
|
23
|
+
const callback = useRef(onSizeChange);
|
|
24
|
+
callback.current = onSizeChange;
|
|
25
|
+
const safeSize = clampViewport(size);
|
|
26
|
+
const scale = space.width && space.height ? Math.max(0.01, Math.min(1, (space.width - 40) / safeSize.width, (space.height - 40) / safeSize.height)) : 1;
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const element = stage.current;
|
|
30
|
+
if (!element) return;
|
|
31
|
+
const measure = () => setSpace({ width: element.clientWidth, height: element.clientHeight });
|
|
32
|
+
measure();
|
|
33
|
+
const observer = new ResizeObserver(measure);
|
|
34
|
+
observer.observe(element);
|
|
35
|
+
return () => observer.disconnect();
|
|
36
|
+
}, []);
|
|
37
|
+
useEffect(() => () => cleanupDrag.current?.(), []);
|
|
38
|
+
useEffect(() => { if (!responsive) cleanupDrag.current?.(); }, [responsive]);
|
|
39
|
+
|
|
40
|
+
function startDrag(event: ReactPointerEvent<HTMLButtonElement>, edge: Edge) {
|
|
41
|
+
if (event.button !== 0) return;
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
cleanupDrag.current?.();
|
|
44
|
+
const handle = event.currentTarget;
|
|
45
|
+
handle.setPointerCapture(event.pointerId);
|
|
46
|
+
const start = { x: event.clientX, y: event.clientY, ...safeSize, scale };
|
|
47
|
+
setDragging(true);
|
|
48
|
+
const move = (next: PointerEvent) => {
|
|
49
|
+
if (next.pointerId !== event.pointerId) return;
|
|
50
|
+
const dx = (next.clientX - start.x) / start.scale;
|
|
51
|
+
const dy = (next.clientY - start.y) / start.scale;
|
|
52
|
+
callback.current(clampViewport({
|
|
53
|
+
width: start.width + (edge.includes("left") ? -dx * 2 : edge.includes("right") ? dx * 2 : 0),
|
|
54
|
+
height: start.height + (edge.includes("bottom") ? dy : 0),
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
const stop = (next?: PointerEvent) => {
|
|
58
|
+
if (next && next.pointerId !== event.pointerId) return;
|
|
59
|
+
window.removeEventListener("pointermove", move);
|
|
60
|
+
window.removeEventListener("pointerup", stop);
|
|
61
|
+
window.removeEventListener("pointercancel", stop);
|
|
62
|
+
window.removeEventListener("blur", blur);
|
|
63
|
+
if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
|
|
64
|
+
cleanupDrag.current = null;
|
|
65
|
+
setDragging(false);
|
|
66
|
+
};
|
|
67
|
+
const blur = () => stop();
|
|
68
|
+
cleanupDrag.current = stop;
|
|
69
|
+
window.addEventListener("pointermove", move);
|
|
70
|
+
window.addEventListener("pointerup", stop);
|
|
71
|
+
window.addEventListener("pointercancel", stop);
|
|
72
|
+
window.addEventListener("blur", blur);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function resizeWithKeys(event: KeyboardEvent<HTMLButtonElement>, edge: Edge) {
|
|
76
|
+
if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) return;
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
const step = event.shiftKey ? 10 : 1;
|
|
79
|
+
const horizontal = event.key === "ArrowLeft" ? -step : event.key === "ArrowRight" ? step : 0;
|
|
80
|
+
const vertical = event.key === "ArrowUp" ? -step : event.key === "ArrowDown" ? step : 0;
|
|
81
|
+
onSizeChange(clampViewport({
|
|
82
|
+
width: safeSize.width + (edge.includes("left") ? -horizontal : edge.includes("right") ? horizontal : 0),
|
|
83
|
+
height: safeSize.height + (edge.includes("bottom") ? vertical : 0),
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const frameStyle = responsive ? {
|
|
88
|
+
width: safeSize.width,
|
|
89
|
+
height: safeSize.height,
|
|
90
|
+
"--preview-scale": scale,
|
|
91
|
+
} as CSSProperties : { "--preview-scale": 1 } as CSSProperties;
|
|
92
|
+
return (
|
|
93
|
+
<div ref={stage} className={`pane-viewport${responsive ? " is-responsive" : ""}${dragging ? " is-resizing" : ""}`}>
|
|
94
|
+
<div className="preview-scaled-slot" style={responsive ? { width: safeSize.width * scale, height: safeSize.height * scale } : undefined}>
|
|
95
|
+
<div className="preview-canvas-frame pane-preview" style={frameStyle}>{children}</div>
|
|
96
|
+
{responsive && (["left", "right", "bottom", "bottom left", "bottom right"] as Edge[]).map((edge) => (
|
|
97
|
+
<button key={edge} className={`preview-resize-handle handle-${edge.replace(" ", "-")}`} type="button"
|
|
98
|
+
aria-label={`Resize preview ${edge}`} title={`Resize ${edge} · arrow keys, Shift for 10 px`}
|
|
99
|
+
onPointerDown={(event) => startDrag(event, edge)} onKeyDown={(event) => resizeWithKeys(event, edge)} />
|
|
100
|
+
))}
|
|
101
|
+
</div>
|
|
102
|
+
{responsive && <span className="preview-scale-readout" aria-live="off">{Math.round(scale * 100)}%</span>}
|
|
103
|
+
{dragging && <div className="preview-drag-shield" aria-hidden />}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Compact per-pane dimensions and a grouped, dark device preset list. */
|
|
109
|
+
export function DeviceControls({ size, onChange }: { size: ViewportSize; onChange: (size: ViewportSize) => void }) {
|
|
110
|
+
const id = useId();
|
|
111
|
+
const trigger = useRef<HTMLButtonElement>(null);
|
|
112
|
+
const menu = useRef<HTMLDivElement>(null);
|
|
113
|
+
const [open, setOpen] = useState(false);
|
|
114
|
+
const [active, setActive] = useState(0);
|
|
115
|
+
const [presetId, setPresetId] = useState<string | null>(null);
|
|
116
|
+
const [draft, setDraft] = useState({ width: String(size.width), height: String(size.height) });
|
|
117
|
+
const [position, setPosition] = useState({ left: 0, top: 0, width: 300, maxHeight: 400 });
|
|
118
|
+
const selected = DEVICE_PRESETS.findIndex((device) => device.id === presetId && device.width === size.width && device.height === size.height);
|
|
119
|
+
useEffect(() => setDraft({ width: String(size.width), height: String(size.height) }), [size.width, size.height]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (!open) return;
|
|
122
|
+
const place = () => {
|
|
123
|
+
const rect = trigger.current?.getBoundingClientRect();
|
|
124
|
+
if (!rect) return;
|
|
125
|
+
const width = Math.min(320, window.innerWidth - 24);
|
|
126
|
+
const below = window.innerHeight - rect.bottom - 12;
|
|
127
|
+
const above = rect.top - 12;
|
|
128
|
+
const upward = below < 280 && above > below;
|
|
129
|
+
const maxHeight = Math.max(48, Math.min(460, upward ? above : below));
|
|
130
|
+
setPosition({ left: Math.max(12, Math.min(rect.left, window.innerWidth - width - 12)), top: upward ? rect.top - maxHeight - 6 : rect.bottom + 6, width, maxHeight });
|
|
131
|
+
};
|
|
132
|
+
const dismiss = (event: PointerEvent) => { if (!trigger.current?.contains(event.target as Node) && !menu.current?.contains(event.target as Node)) setOpen(false); };
|
|
133
|
+
const blur = () => setOpen(false);
|
|
134
|
+
place();
|
|
135
|
+
window.addEventListener("resize", place);
|
|
136
|
+
window.addEventListener("scroll", place, true);
|
|
137
|
+
window.addEventListener("blur", blur);
|
|
138
|
+
document.addEventListener("pointerdown", dismiss);
|
|
139
|
+
return () => {
|
|
140
|
+
window.removeEventListener("resize", place);
|
|
141
|
+
window.removeEventListener("scroll", place, true);
|
|
142
|
+
window.removeEventListener("blur", blur);
|
|
143
|
+
document.removeEventListener("pointerdown", dismiss);
|
|
144
|
+
};
|
|
145
|
+
}, [open]);
|
|
146
|
+
useEffect(() => { if (open) menu.current?.querySelector(`[data-device-index="${active}"]`)?.scrollIntoView({ block: "nearest" }); }, [open, active]);
|
|
147
|
+
function choose(index: number) {
|
|
148
|
+
setPresetId(index > 0 ? DEVICE_PRESETS[index - 1].id : null);
|
|
149
|
+
if (index > 0) onChange(clampViewport(DEVICE_PRESETS[index - 1]));
|
|
150
|
+
setOpen(false);
|
|
151
|
+
trigger.current?.focus();
|
|
152
|
+
}
|
|
153
|
+
function commit(axis: "width" | "height") {
|
|
154
|
+
setPresetId(null);
|
|
155
|
+
const value = Number(draft[axis]);
|
|
156
|
+
const next = clampViewport({ ...size, [axis]: draft[axis].trim() && Number.isFinite(value) ? value : size[axis] });
|
|
157
|
+
setDraft({ width: String(next.width), height: String(next.height) });
|
|
158
|
+
onChange(next);
|
|
159
|
+
}
|
|
160
|
+
let index = 0;
|
|
161
|
+
return (
|
|
162
|
+
<div className="device-controls" aria-label="Responsive viewport controls">
|
|
163
|
+
<button ref={trigger} className="device-preset-trigger" type="button" role="combobox" aria-label="Preview device"
|
|
164
|
+
aria-expanded={open} aria-haspopup="listbox" aria-controls={open ? id : undefined} aria-activedescendant={open ? `${id}-${active}` : undefined}
|
|
165
|
+
onClick={() => { setActive(selected + 1); setOpen(!open); }}
|
|
166
|
+
onKeyDown={(event) => {
|
|
167
|
+
const count = DEVICE_PRESETS.length + 1;
|
|
168
|
+
if (["ArrowDown", "ArrowUp", "Home", "End", "Enter", " ", "Escape"].includes(event.key)) event.preventDefault();
|
|
169
|
+
if (event.key === "Escape" || event.key === "Tab") setOpen(false);
|
|
170
|
+
else if (event.key === "Enter" || event.key === " ") { if (open) choose(active); else { setActive(selected + 1); setOpen(true); } }
|
|
171
|
+
else if (event.key === "ArrowDown" || event.key === "ArrowUp") { setOpen(true); setActive((value) => (value + (event.key === "ArrowDown" ? 1 : -1) + count) % count); }
|
|
172
|
+
else if (event.key === "Home" || event.key === "End") { setOpen(true); setActive(event.key === "Home" ? 0 : count - 1); }
|
|
173
|
+
}}>
|
|
174
|
+
<span>{DEVICE_PRESETS[selected]?.label ?? "Responsive"}</span><ChevronDown size={13} aria-hidden />
|
|
175
|
+
</button>
|
|
176
|
+
<div className="device-dimensions">
|
|
177
|
+
{(["width", "height"] as const).map((axis, axisIndex) => <span key={axis} className="device-dimension-field">
|
|
178
|
+
{axisIndex === 1 && <span aria-hidden>×</span>}
|
|
179
|
+
<input type="number" inputMode="numeric" aria-label={`Preview ${axis}`} value={draft[axis]} min={axis === "width" ? VIEWPORT_LIMITS.minWidth : VIEWPORT_LIMITS.minHeight} max={axis === "width" ? VIEWPORT_LIMITS.maxWidth : VIEWPORT_LIMITS.maxHeight}
|
|
180
|
+
onChange={(event) => setDraft((value) => ({ ...value, [axis]: event.target.value }))} onBlur={() => commit(axis)}
|
|
181
|
+
onKeyDown={(event) => { if (event.key === "Enter") { event.preventDefault(); commit(axis); event.currentTarget.blur(); } }} />
|
|
182
|
+
</span>)}
|
|
183
|
+
</div>
|
|
184
|
+
<button type="button" className="device-rotate" aria-label="Rotate preview" title="Rotate preview" onClick={() => { setPresetId(null); onChange(clampViewport({ width: size.height, height: size.width })); }}><RotateCw size={14} aria-hidden /></button>
|
|
185
|
+
{open && createPortal(<div ref={menu} id={id} className="device-menu" role="listbox" aria-label="Preview devices" style={position}>
|
|
186
|
+
<div id={`${id}-0`} role="option" aria-selected={selected < 0} data-device-index={0} className={`device-option${active === 0 ? " is-active" : ""}`} onPointerMove={() => setActive(0)} onPointerDown={(event) => event.preventDefault()} onClick={() => choose(0)}><span>Responsive</span>{selected < 0 && <Check size={13} aria-hidden />}</div>
|
|
187
|
+
{DEVICE_GROUPS.map((group) => <div key={group.label} role="group" aria-label={group.label}>
|
|
188
|
+
<div className="device-group-label" aria-hidden>{group.label}</div>
|
|
189
|
+
{group.devices.map((device) => {
|
|
190
|
+
const optionIndex = ++index;
|
|
191
|
+
return <div key={device.id} id={`${id}-${optionIndex}`} data-device-index={optionIndex} role="option" aria-selected={selected === optionIndex - 1} className={`device-option${active === optionIndex ? " is-active" : ""}`} onPointerMove={() => setActive(optionIndex)} onPointerDown={(event) => event.preventDefault()} onClick={() => choose(optionIndex)}>
|
|
192
|
+
<span>{device.label}</span><small>{device.width} × {device.height}</small>{selected === optionIndex - 1 && <Check size={13} aria-hidden />}
|
|
193
|
+
</div>;
|
|
194
|
+
})}
|
|
195
|
+
</div>)}
|
|
196
|
+
</div>, document.body)}
|
|
197
|
+
</div>
|
|
198
|
+
);
|
|
199
|
+
}
|