@auscera/design-labs 0.0.0-stage → 0.1.0

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.
Files changed (57) hide show
  1. package/apps/workspace/.skills/design-labs/SKILL.md +63 -0
  2. package/apps/workspace/.skills/design-labs/references/commands.md +38 -0
  3. package/apps/workspace/AGENTS.md +9 -0
  4. package/apps/workspace/app/(lab)/compare/page.tsx +2 -0
  5. package/apps/workspace/app/(lab)/lab.css +412 -0
  6. package/apps/workspace/app/(lab)/layout.tsx +21 -0
  7. package/apps/workspace/app/(lab)/page.tsx +2 -0
  8. package/apps/workspace/app/api/annotations/route.ts +94 -0
  9. package/apps/workspace/app/api/versions/events/route.ts +63 -0
  10. package/apps/workspace/app/api/versions/route.ts +7 -0
  11. package/apps/workspace/components/animated-icons.tsx +72 -0
  12. package/apps/workspace/components/dotmatrix-loader.css +1228 -0
  13. package/apps/workspace/components/glass-controls.tsx +47 -0
  14. package/apps/workspace/components/lab-providers.tsx +17 -0
  15. package/apps/workspace/components/molecules/brand-lockup.tsx +13 -0
  16. package/apps/workspace/components/molecules/pane-url-popover.css +92 -0
  17. package/apps/workspace/components/molecules/pane-url-popover.tsx +191 -0
  18. package/apps/workspace/components/pane-preferences.tsx +75 -0
  19. package/apps/workspace/components/pane-viewport.css +34 -0
  20. package/apps/workspace/components/pane-viewport.tsx +199 -0
  21. package/apps/workspace/components/preview-pane.css +293 -0
  22. package/apps/workspace/components/preview-pane.tsx +662 -0
  23. package/apps/workspace/components/ui/dotm-triangle-11.tsx +170 -0
  24. package/apps/workspace/components/ui/dotmatrix-core.tsx +1649 -0
  25. package/apps/workspace/components/ui/dotmatrix-hooks.ts +224 -0
  26. package/apps/workspace/components/version-select.tsx +220 -0
  27. package/apps/workspace/components/workspace.tsx +313 -0
  28. package/apps/workspace/eslint.config.mjs +3 -0
  29. package/apps/workspace/lab.config.json +1 -0
  30. package/apps/workspace/lib/annotation-export.ts +28 -0
  31. package/apps/workspace/lib/annotation-types.ts +38 -0
  32. package/apps/workspace/lib/device-presets.ts +103 -0
  33. package/apps/workspace/lib/use-annotation-bridge.ts +130 -0
  34. package/apps/workspace/lib/version-types.ts +12 -0
  35. package/apps/workspace/lib/website-url.ts +78 -0
  36. package/apps/workspace/next-env.d.ts +6 -0
  37. package/apps/workspace/next.config.mjs +1 -0
  38. package/apps/workspace/package.json +35 -0
  39. package/apps/workspace/public/apple-touch-icon.png +0 -0
  40. package/apps/workspace/public/brand/design-labs-script.LICENSE.txt +93 -0
  41. package/apps/workspace/public/brand/design-labs-script.woff2 +0 -0
  42. package/apps/workspace/public/brand/logo.webp +0 -0
  43. package/apps/workspace/public/brand/wordmark.css +42 -0
  44. package/apps/workspace/public/favicon.ico +0 -0
  45. package/apps/workspace/public/icon-192.png +0 -0
  46. package/apps/workspace/public/icon-512.png +0 -0
  47. package/apps/workspace/public/preview-bridge.js +411 -0
  48. package/apps/workspace/public/site.webmanifest +1 -0
  49. package/apps/workspace/scripts/annotation-store.mjs +308 -0
  50. package/apps/workspace/scripts/lab.mjs +414 -0
  51. package/apps/workspace/scripts/migrate.mjs +2 -0
  52. package/apps/workspace/scripts/prepare-preview.mjs +203 -0
  53. package/apps/workspace/tsconfig.json +24 -0
  54. package/package.json +9 -3
  55. package/scripts/install.mjs +67 -0
  56. package/scripts/update.mjs +204 -0
  57. package/README.md +0 -3
@@ -0,0 +1,78 @@
1
+ const ADDRESS_HINT =
2
+ "Enter a valid website address, such as example.com or http://localhost:3000.";
3
+
4
+ /** Convert an entered address to an explicit, browser-safe HTTP(S) URL. */
5
+ export function normalizeWebsiteUrl(input: string): string {
6
+ if (typeof input !== "string") {
7
+ throw new Error("Remove control characters from the website address.");
8
+ }
9
+ for (let index = 0; index < input.length; index++) {
10
+ const code = input.charCodeAt(index);
11
+ if (code < 32 || code === 127) {
12
+ throw new Error("Remove control characters from the website address.");
13
+ }
14
+ }
15
+ const entered = input.trim();
16
+ if (!entered) throw new Error("Enter a website address.");
17
+ if (entered.length > 8192) {
18
+ throw new Error("The website address is too long.");
19
+ }
20
+ if (/\s|\\/.test(entered)) {
21
+ throw new Error("Remove spaces and backslashes from the website address.");
22
+ }
23
+
24
+ let address = entered;
25
+ if (!/^https?:\/\//i.test(address)) {
26
+ if (address.startsWith("/") || /^https?:/i.test(address)) {
27
+ throw new Error(ADDRESS_HINT);
28
+ }
29
+ const authority = address.split(/[/?#]/, 1)[0];
30
+ // A colon in a bare address can only introduce a numeric port or belong to
31
+ // bracketed IPv6. This excludes schemes such as javascript:, data: or file:.
32
+ if (!/^(?:[^:[\]]+|\[[0-9a-f:.]+\])(?::\d+)?$/i.test(authority)) {
33
+ throw new Error("Use an http:// or https:// website address.");
34
+ }
35
+ const local =
36
+ /^(?:(?:[a-z0-9-]+\.)*localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|\[::1\])(?::\d+)?$/i.test(
37
+ authority,
38
+ );
39
+ address = `${local ? "http" : "https"}://${address}`;
40
+ }
41
+
42
+ let parsed: URL;
43
+ try {
44
+ parsed = new URL(address);
45
+ } catch {
46
+ throw new Error(ADDRESS_HINT);
47
+ }
48
+ if (!["http:", "https:"].includes(parsed.protocol)) {
49
+ throw new Error("Use an http:// or https:// website address.");
50
+ }
51
+ const enteredAuthority = address
52
+ .replace(/^https?:\/\//i, "")
53
+ .split(/[/?#]/, 1)[0];
54
+ if (enteredAuthority.includes("@") || parsed.username || parsed.password) {
55
+ throw new Error(
56
+ "Remove the username and password from the website address.",
57
+ );
58
+ }
59
+ const host = parsed.hostname;
60
+ if (!host) throw new Error(ADDRESS_HINT);
61
+ if (!host.startsWith("[")) {
62
+ const domain = host.endsWith(".") ? host.slice(0, -1) : host;
63
+ if (
64
+ domain.length > 253 ||
65
+ !domain
66
+ .split(".")
67
+ .every((label) => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(label))
68
+ ) {
69
+ throw new Error(ADDRESS_HINT);
70
+ }
71
+ }
72
+ return parsed.href;
73
+ }
74
+
75
+ /** Keep the entered path, query and fragment visible in the compact pane label. */
76
+ export function formatWebsiteUrl(url: string): string {
77
+ return url.replace(/^https?:\/\//i, "");
78
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/image-types/global" />
3
+ /// <reference path="./.next/types/routes.d.ts" />
4
+
5
+ // NOTE: This file should not be edited
6
+ // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -0,0 +1 @@
1
+ export default { reactStrictMode: true };
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@design-labs/workspace",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "node scripts/lab.mjs dev",
7
+ "build": "next build",
8
+ "start": "next start -p 3001",
9
+ "lint": "eslint",
10
+ "check-types": "tsc --noEmit"
11
+ },
12
+ "dependencies": {
13
+ "@animateicons/react": "^0.13.0",
14
+ "@tanstack/react-query": "5.90.3",
15
+ "clsx": "^2.1.1",
16
+ "framer-motion": "^12.4.3",
17
+ "lucide-react": "^0.475.0",
18
+ "next": "15.5.29",
19
+ "react": "19.0.0",
20
+ "react-dom": "19.0.0",
21
+ "tailwind-merge": "^3.0.1"
22
+ },
23
+ "devDependencies": {
24
+ "@eslint/eslintrc": "^3.3.1",
25
+ "@tailwindcss/postcss": "^4.0.6",
26
+ "@types/node": "^22.13.0",
27
+ "@types/react": "^19.0.0",
28
+ "@types/react-dom": "^19.0.0",
29
+ "eslint": "^9.20.0",
30
+ "eslint-config-next": "15.5.29",
31
+ "postcss": "^8.5.2",
32
+ "tailwindcss": "^4.0.6",
33
+ "typescript": "^5.7.3"
34
+ }
35
+ }
@@ -0,0 +1,93 @@
1
+ Copyright 2014 The Damion Project Authors (https://github.com/googlefonts/damionFont)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://openfontlicense.org
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,42 @@
1
+ /* Design Labs Script: renamed Damion derivative. See adjacent OFL license. */
2
+ @font-face {
3
+ font-family: "Design Labs Script";
4
+ src: url('/brand/design-labs-script.woff2') format('woff2');
5
+ font-style: normal;
6
+ font-weight: 400;
7
+ font-display: swap;
8
+ }
9
+ :root { --brand-wordmark-font: "Design Labs Script", "Brush Script MT", cursive; }
10
+ .dl-brand-lockup {
11
+ display: grid;
12
+ grid-template-columns: minmax(0, 1fr) var(--brand-logo-size, 48px) minmax(0, 1fr);
13
+ align-items: center;
14
+ gap: var(--brand-lockup-gap, 10px);
15
+ width: var(--brand-lockup-width, 300px);
16
+ max-width: 100%;
17
+ font-size: var(--brand-wordmark-size, 34px);
18
+ line-height: 1.15;
19
+ font-weight: 400;
20
+ letter-spacing: 0;
21
+ }
22
+ .dl-brand-word, .dl-brand-script {
23
+ font-family: var(--brand-wordmark-font);
24
+ font-style: normal;
25
+ font-weight: 400;
26
+ font-synthesis: none;
27
+ font-kerning: normal;
28
+ font-feature-settings: "kern" 1, "liga" 1;
29
+ letter-spacing: 0;
30
+ }
31
+ .dl-brand-lockup .dl-brand-word {
32
+ display: block;
33
+ white-space: nowrap;
34
+ padding: .1em .13em .18em;
35
+ }
36
+ .dl-brand-design { justify-self: end; }
37
+ .dl-brand-labs { justify-self: start; }
38
+ .dl-brand-lockup > img {
39
+ width: var(--brand-logo-size, 48px);
40
+ height: var(--brand-logo-size, 48px);
41
+ object-fit: contain;
42
+ }
@@ -0,0 +1,411 @@
1
+ /* Design Labs preview-only DOM bridge. Original source snapshots stay unchanged. */
2
+ (() => {
3
+ "use strict";
4
+ const script = document.currentScript;
5
+ if (!(script instanceof HTMLScriptElement) || window.parent === window)
6
+ return;
7
+ let labOrigin;
8
+ try {
9
+ const allowed = new URL(script.dataset.labOrigin || "");
10
+ if (
11
+ !["http:", "https:"].includes(allowed.protocol) ||
12
+ allowed.origin !== script.dataset.labOrigin
13
+ )
14
+ return;
15
+ labOrigin = allowed.origin;
16
+ } catch {
17
+ return;
18
+ }
19
+ const validSession = (value) =>
20
+ typeof value === "string" && /^[A-Za-z0-9:_-]{16,128}$/.test(value);
21
+ const configuredSession = validSession(script.dataset.session)
22
+ ? script.dataset.session
23
+ : undefined;
24
+ let session = configuredSession;
25
+ const prior = window.__designLabsPreviewBridgeV1;
26
+ if (prior && typeof prior.destroy === "function") prior.destroy();
27
+ let inspecting = false;
28
+ let pins = [];
29
+ let disposed = false;
30
+ let timer;
31
+ let hovered;
32
+ let animationFrame;
33
+ const overlay = document.createElement("div");
34
+ overlay.dataset.designLabsOverlay = "true";
35
+ overlay.style.cssText =
36
+ "position:fixed;inset:0;pointer-events:none;z-index:2147483646;";
37
+ const shadow = overlay.attachShadow({ mode: "open" });
38
+ const style = document.createElement("style");
39
+ style.textContent =
40
+ ":host{all:initial}.outline{box-sizing:border-box;position:fixed;pointer-events:none;border:2px solid #4f96ff;background:rgba(79,150,255,.08);border-radius:2px;display:none}.label{position:absolute;left:0;bottom:100%;padding:3px 6px;background:#1670d8;color:white;font:12px/1.4 ui-monospace,monospace;white-space:nowrap;border-radius:4px 4px 0 0}";
41
+ const outline = document.createElement("div");
42
+ outline.className = "outline";
43
+ const outlineLabel = document.createElement("span");
44
+ outlineLabel.className = "label";
45
+ outline.append(outlineLabel);
46
+ shadow.append(style, outline);
47
+ document.documentElement.append(overlay);
48
+ const viewport = () => ({
49
+ width: Math.max(1, window.innerWidth),
50
+ height: Math.max(1, window.innerHeight),
51
+ });
52
+ const bounds = (element) => {
53
+ const rect = element.getBoundingClientRect();
54
+ return { x: rect.x, y: rect.y, width: rect.width, height: rect.height };
55
+ };
56
+ const emit = (type, data = {}) => {
57
+ if (disposed || !session) return;
58
+ window.parent.postMessage(
59
+ { channel: "design-labs", session, type, ...data },
60
+ labOrigin,
61
+ );
62
+ };
63
+ const resolve = (selector) => {
64
+ try {
65
+ return document.querySelector(selector);
66
+ } catch {
67
+ return undefined;
68
+ }
69
+ };
70
+ function isOverlay(element) {
71
+ return element === overlay || overlay.contains(element);
72
+ }
73
+ function selectorFor(element) {
74
+ if (element.id) {
75
+ const id = "#" + CSS.escape(element.id);
76
+ if (document.querySelectorAll(id).length === 1) return id;
77
+ }
78
+ const testId = element.getAttribute("data-testid");
79
+ if (testId) {
80
+ const candidate = `[data-testid="${CSS.escape(testId)}"]`;
81
+ if (document.querySelectorAll(candidate).length === 1) return candidate;
82
+ }
83
+ const parts = [];
84
+ let node = element;
85
+ while (node instanceof Element && parts.length < 12) {
86
+ let part = node.localName;
87
+ if (!part) break;
88
+ const parent = node.parentElement;
89
+ if (parent) {
90
+ const same = [...parent.children].filter(
91
+ (sibling) => sibling.localName === node.localName,
92
+ );
93
+ if (same.length > 1) part += `:nth-of-type(${same.indexOf(node) + 1})`;
94
+ }
95
+ parts.unshift(part);
96
+ const candidate = parts.join(" > ");
97
+ if (document.querySelectorAll(candidate).length === 1) return candidate;
98
+ node = parent;
99
+ }
100
+ return parts.join(" > ");
101
+ }
102
+ function cleanClone(element) {
103
+ const clone = element.cloneNode(true);
104
+ if (!(clone instanceof Element)) return undefined;
105
+ const forbidden = "script,style,iframe,object,embed,template,textarea";
106
+ if (clone.matches(forbidden)) {
107
+ const replacement = document.createElement(
108
+ clone.localName === "textarea" ? "textarea" : "div",
109
+ );
110
+ return replacement;
111
+ }
112
+ clone.querySelectorAll(forbidden).forEach((node) => node.remove());
113
+ for (const node of [clone, ...clone.querySelectorAll("*")]) {
114
+ for (const attribute of [...node.attributes]) {
115
+ if (
116
+ /^on/i.test(attribute.name) ||
117
+ /^(value|checked|selected|srcdoc|nonce|integrity)$/i.test(
118
+ attribute.name,
119
+ ) ||
120
+ /(?:password|secret|token|authorization|credential)/i.test(
121
+ attribute.name,
122
+ )
123
+ )
124
+ node.removeAttribute(attribute.name);
125
+ else if (/^(href|src|action|formaction)$/i.test(attribute.name)) {
126
+ if (/^\s*(javascript:|data:)/i.test(attribute.value))
127
+ node.removeAttribute(attribute.name);
128
+ else {
129
+ try {
130
+ const url = new URL(attribute.value, location.href);
131
+ if (url.search || url.hash)
132
+ node.setAttribute(attribute.name, url.pathname);
133
+ } catch {
134
+ node.removeAttribute(attribute.name);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ if (node.matches("input,textarea,select")) {
140
+ node.removeAttribute("value");
141
+ if (node.localName !== "input") node.replaceChildren();
142
+ }
143
+ if (node.hasAttribute("contenteditable")) node.replaceChildren();
144
+ }
145
+ return clone;
146
+ }
147
+ function context(element) {
148
+ const clone = cleanClone(element);
149
+ const computed = getComputedStyle(element);
150
+ const styles = {};
151
+ for (const key of [
152
+ "display",
153
+ "position",
154
+ "color",
155
+ "backgroundColor",
156
+ "fontFamily",
157
+ "fontSize",
158
+ "fontWeight",
159
+ "lineHeight",
160
+ "padding",
161
+ "margin",
162
+ "borderRadius",
163
+ "width",
164
+ "height",
165
+ "gap",
166
+ "alignItems",
167
+ "justifyContent",
168
+ ])
169
+ styles[key] = String(computed[key]).slice(0, 500);
170
+ const result = {
171
+ selector: selectorFor(element),
172
+ tag: element.localName,
173
+ text: clone
174
+ ? (clone.textContent || "").replace(/\s+/g, " ").trim().slice(0, 2000)
175
+ : "",
176
+ html: clone ? clone.outerHTML.slice(0, 16000) : "",
177
+ styles,
178
+ bounds: bounds(element),
179
+ viewport: viewport(),
180
+ pathname: location.pathname,
181
+ };
182
+ const component = element.closest("[data-component],[data-component-name]");
183
+ const source = element.closest("[data-source-file]");
184
+ if (component)
185
+ result.component = (
186
+ component.getAttribute("data-component") ||
187
+ component.getAttribute("data-component-name") ||
188
+ ""
189
+ ).slice(0, 160);
190
+ if (source)
191
+ result.sourceFile = (source.getAttribute("data-source-file") || "").slice(
192
+ 0,
193
+ 1000,
194
+ );
195
+ return result;
196
+ }
197
+ const normalizedText = (value) =>
198
+ value.replace(/\s+/g, " ").trim().slice(0, 2000);
199
+ function resolvePin(pin) {
200
+ const element = resolve(pin.selector);
201
+ if (!(element instanceof Element) || isOverlay(element)) return undefined;
202
+ if (pin.tag !== undefined && element.localName !== pin.tag.toLowerCase())
203
+ return undefined;
204
+ if (pin.text !== undefined) {
205
+ const clone = cleanClone(element);
206
+ if (normalizedText(clone?.textContent || "") !== normalizedText(pin.text))
207
+ return undefined;
208
+ }
209
+ return element;
210
+ }
211
+ function paint(element) {
212
+ if (!inspecting || !(element instanceof Element) || isOverlay(element)) {
213
+ outline.style.display = "none";
214
+ return;
215
+ }
216
+ const rect = bounds(element);
217
+ outline.style.cssText = `display:block;left:${rect.x}px;top:${rect.y}px;width:${rect.width}px;height:${rect.height}px;`;
218
+ outlineLabel.textContent =
219
+ element.localName + (element.id ? "#" + element.id.slice(0, 60) : "");
220
+ }
221
+ function publish() {
222
+ if (disposed || !session) return;
223
+ emit("location", { pathname: location.pathname, viewport: viewport() });
224
+ emit("pins", {
225
+ items: pins.map((pin) => {
226
+ const element = resolvePin(pin);
227
+ return element instanceof Element
228
+ ? { ...pin, found: true, bounds: bounds(element) }
229
+ : { ...pin, found: false };
230
+ }),
231
+ });
232
+ if (hovered) paint(hovered);
233
+ }
234
+ function schedule() {
235
+ clearTimeout(timer);
236
+ timer = setTimeout(publish, 50);
237
+ }
238
+ function pointer(event) {
239
+ if (!inspecting) return;
240
+ hovered = event.target instanceof Element ? event.target : undefined;
241
+ cancelAnimationFrame(animationFrame);
242
+ animationFrame = requestAnimationFrame(() => paint(hovered));
243
+ }
244
+ function pick(event) {
245
+ if (!inspecting || event.button !== 0) return;
246
+ const element = event.target;
247
+ if (!(element instanceof Element) || isOverlay(element)) return;
248
+ event.preventDefault();
249
+ event.stopPropagation();
250
+ event.stopImmediatePropagation();
251
+ inspecting = false;
252
+ hovered = undefined;
253
+ outline.style.display = "none";
254
+ emit("target", { target: context(element) });
255
+ }
256
+ function key(event) {
257
+ if (inspecting && event.key === "Escape") {
258
+ event.preventDefault();
259
+ event.stopPropagation();
260
+ inspecting = false;
261
+ hovered = undefined;
262
+ outline.style.display = "none";
263
+ emit("cancel");
264
+ }
265
+ }
266
+ function message(event) {
267
+ if (event.source !== window.parent || event.origin !== labOrigin) return;
268
+ const data = event.data;
269
+ if (
270
+ !data ||
271
+ typeof data !== "object" ||
272
+ data.channel !== "design-labs" ||
273
+ !validSession(data.session)
274
+ )
275
+ return;
276
+ if (data.type === "init") {
277
+ if (configuredSession && data.session !== configuredSession) return;
278
+ if (session !== data.session) {
279
+ inspecting = false;
280
+ hovered = undefined;
281
+ pins = [];
282
+ outline.style.display = "none";
283
+ }
284
+ session = data.session;
285
+ emit("ready");
286
+ publish();
287
+ return;
288
+ }
289
+ if (data.session !== session) return;
290
+ if (data.type === "inspect" && typeof data.enabled === "boolean") {
291
+ inspecting = data.enabled;
292
+ if (!inspecting) {
293
+ hovered = undefined;
294
+ outline.style.display = "none";
295
+ }
296
+ } else if (
297
+ data.type === "pins" &&
298
+ Array.isArray(data.items) &&
299
+ data.items.length <= 1000
300
+ ) {
301
+ pins = data.items
302
+ .filter(
303
+ (item) =>
304
+ item &&
305
+ typeof item.id === "string" &&
306
+ item.id.length <= 100 &&
307
+ typeof item.selector === "string" &&
308
+ item.selector.length <= 2000 &&
309
+ (item.tag === undefined ||
310
+ (typeof item.tag === "string" && item.tag.length <= 64)) &&
311
+ (item.text === undefined ||
312
+ (typeof item.text === "string" && item.text.length <= 2000)),
313
+ )
314
+ .map((item) => ({
315
+ id: item.id,
316
+ selector: item.selector,
317
+ tag: item.tag,
318
+ text: item.text,
319
+ }));
320
+ schedule();
321
+ } else if (
322
+ data.type === "locate" &&
323
+ typeof data.selector === "string" &&
324
+ data.selector.length <= 2000
325
+ ) {
326
+ const element = resolvePin(
327
+ pins.find((pin) => pin.selector === data.selector) || {
328
+ selector: data.selector,
329
+ },
330
+ );
331
+ if (element instanceof Element)
332
+ element.scrollIntoView({
333
+ behavior: matchMedia("(prefers-reduced-motion: reduce)").matches
334
+ ? "auto"
335
+ : "smooth",
336
+ block: "center",
337
+ inline: "nearest",
338
+ });
339
+ emit("located", {
340
+ selector: data.selector,
341
+ found: element instanceof Element,
342
+ });
343
+ schedule();
344
+ } else if (data.type === "dispose") destroy();
345
+ }
346
+ const observer = new MutationObserver((records) => {
347
+ if (
348
+ records.some(
349
+ (record) =>
350
+ !(record.target instanceof Element) || !isOverlay(record.target),
351
+ )
352
+ )
353
+ schedule();
354
+ });
355
+ observer.observe(document.documentElement, {
356
+ childList: true,
357
+ subtree: true,
358
+ attributes: true,
359
+ });
360
+ const originalPush = history.pushState;
361
+ const originalReplace = history.replaceState;
362
+ const patchedPush = function (...args) {
363
+ const result = originalPush.apply(this, args);
364
+ schedule();
365
+ return result;
366
+ };
367
+ const patchedReplace = function (...args) {
368
+ const result = originalReplace.apply(this, args);
369
+ schedule();
370
+ return result;
371
+ };
372
+ history.pushState = patchedPush;
373
+ history.replaceState = patchedReplace;
374
+ window.addEventListener("message", message);
375
+ document.addEventListener("pointermove", pointer, {
376
+ passive: true,
377
+ capture: true,
378
+ });
379
+ document.addEventListener("click", pick, true);
380
+ document.addEventListener("keydown", key, true);
381
+ window.addEventListener("scroll", schedule, true);
382
+ window.addEventListener("resize", schedule);
383
+ window.addEventListener("popstate", schedule);
384
+ window.addEventListener("hashchange", schedule);
385
+ function destroy() {
386
+ if (disposed) return;
387
+ disposed = true;
388
+ clearTimeout(timer);
389
+ cancelAnimationFrame(animationFrame);
390
+ observer.disconnect();
391
+ overlay.remove();
392
+ window.removeEventListener("message", message);
393
+ document.removeEventListener("pointermove", pointer, true);
394
+ document.removeEventListener("click", pick, true);
395
+ document.removeEventListener("keydown", key, true);
396
+ window.removeEventListener("scroll", schedule, true);
397
+ window.removeEventListener("resize", schedule);
398
+ window.removeEventListener("popstate", schedule);
399
+ window.removeEventListener("hashchange", schedule);
400
+ if (history.pushState === patchedPush) history.pushState = originalPush;
401
+ if (history.replaceState === patchedReplace)
402
+ history.replaceState = originalReplace;
403
+ if (window.__designLabsPreviewBridgeV1?.destroy === destroy)
404
+ delete window.__designLabsPreviewBridgeV1;
405
+ }
406
+ window.__designLabsPreviewBridgeV1 = { destroy };
407
+ if (session) {
408
+ emit("ready");
409
+ publish();
410
+ }
411
+ })();
@@ -0,0 +1 @@
1
+ {"name": "Design Labs", "short_name": "Design Labs", "icons": [{"src": "/icon-192.png", "sizes": "192x192", "type": "image/png"}, {"src": "/icon-512.png", "sizes": "512x512", "type": "image/png"}], "theme_color": "#000000", "background_color": "#000000", "display": "standalone"}