miral 0.0.3 → 0.0.4
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/README.md +9 -9
- package/package.json +2 -2
- package/src/Assets.tsx +5 -5
- package/src/Controls.tsx +7 -7
- package/src/Nav.tsx +6 -6
- package/src/Spinner.tsx +2 -2
- package/src/Toolbar.tsx +15 -13
- package/src/Viewer.tsx +26 -29
- package/src/cli.js +15 -15
- package/src/theme.css +14 -14
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Miral
|
|
2
2
|
|
|
3
3
|
Like storybook, but opinionated, much simpler, and without interaction testing.
|
|
4
4
|
Built on `vite`, `react`, and `tailwind`.
|
|
@@ -6,8 +6,8 @@ Built on `vite`, `react`, and `tailwind`.
|
|
|
6
6
|
## Usage
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npx
|
|
10
|
-
npx
|
|
9
|
+
npx miral preview
|
|
10
|
+
npx miral build
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Open `http://localhost:9000` for development. Serve the generated `dist/` directory with any static HTTP server. Asset
|
|
@@ -16,7 +16,7 @@ URLs are relative, so the catalog can also run under a subdirectory. Use `--port
|
|
|
16
16
|
|
|
17
17
|
## Sidebar
|
|
18
18
|
|
|
19
|
-
Place an optional `
|
|
19
|
+
Place an optional `miral.config.ts` in the directory scanned by `preview` or `build`.
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
22
|
export default {
|
|
@@ -27,15 +27,15 @@ export default {
|
|
|
27
27
|
};
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
`title` sets the optional H1 at the top of the sidebar and the browser tab title (`My UI kit |
|
|
30
|
+
`title` sets the optional H1 at the top of the sidebar and the browser tab title (`My UI kit | Miral`). The tab shows `Miral` when the title is empty or omitted. `order` lists sections. `componentOrder` orders components within each section. Unlisted names follow in alphabetical order. Omit either list to use alphabetical order throughout that level.
|
|
31
31
|
|
|
32
|
-
Use an optional string literal `assetsDir` to add an Assets story at the end of the sidebar. Set the path relative to `
|
|
32
|
+
Use an optional string literal `assetsDir` to add an Assets story at the end of the sidebar. Set the path relative to `miral.config.ts`. Each file in that directory and its subdirectories gets a card with its filename. Image cards also show a preview.
|
|
33
33
|
|
|
34
34
|
## Preview files
|
|
35
35
|
|
|
36
|
-
Place `*.
|
|
36
|
+
Place `*.mira.tsx` files anywhere in the project. The filename names the component. Declare a section with a string literal, such as `export const section = "Metrics"`. Files without a section appear under `Elements`.
|
|
37
37
|
|
|
38
|
-
Without `
|
|
38
|
+
Without `miral.config.ts`, sections and their entries sort alphabetically. If no file declares a section, all entries appear in one alphabetical `Elements` list.
|
|
39
39
|
|
|
40
40
|
```tsx
|
|
41
41
|
import * as z from "zod/mini";
|
|
@@ -52,4 +52,4 @@ props. Supply `defaults` for required editable fields. String, number, boolean,
|
|
|
52
52
|
controls. Use a wrapper component to provide callbacks, children, form providers, or sample data. Other capitalized
|
|
53
53
|
component exports appear below Playground. Import project styles in preview files when needed.
|
|
54
54
|
|
|
55
|
-
To style the preview iframe, import a project stylesheet with Vite’s `?url` suffix in `
|
|
55
|
+
To style the preview iframe, import a project stylesheet with Vite’s `?url` suffix in `miral.config.ts` and export its URL as the `stylesheet` option. Miral supplies its own styles and icons for the catalog controls.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miral",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Like Storybook, but much simpler.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"node": ">=24.0.0"
|
|
9
9
|
},
|
|
10
10
|
"bin": {
|
|
11
|
-
"
|
|
11
|
+
"miral": "src/cli.js"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"src"
|
package/src/Assets.tsx
CHANGED
|
@@ -7,23 +7,23 @@ export const Assets = ({ className, files }: AssetsProps) => (
|
|
|
7
7
|
<section className={className}>
|
|
8
8
|
<h1>Assets</h1>
|
|
9
9
|
{!Object.keys(files).length && <p>No assets found.</p>}
|
|
10
|
-
<div className="
|
|
10
|
+
<div className="miral:grid miral:grid-cols-[repeat(auto-fill,minmax(min(100%,12rem),1fr))] miral:gap-4">
|
|
11
11
|
{Object.entries(files)
|
|
12
12
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
13
13
|
.map(([path, url]) => (
|
|
14
14
|
<figure
|
|
15
15
|
key={path}
|
|
16
|
-
className="
|
|
16
|
+
className="miral:grid miral:content-start miral:gap-1.5 miral:m-0"
|
|
17
17
|
>
|
|
18
|
-
<figcaption className="
|
|
18
|
+
<figcaption className="miral:text-left miral:wrap-anywhere">
|
|
19
19
|
<a href={url} download={path.split("/").at(-1)}>
|
|
20
20
|
{path.split("/").at(-1)}
|
|
21
21
|
</a>
|
|
22
22
|
</figcaption>
|
|
23
|
-
<div className="
|
|
23
|
+
<div className="miral:grid miral:place-items-center miral:min-h-32 miral:p-4 miral:border miral:border-solid miral:border-edge miral:rounded-lg">
|
|
24
24
|
{/\.(avif|bmp|gif|ico|jpe?g|png|svg|webp)$/i.test(path) ? (
|
|
25
25
|
<img
|
|
26
|
-
className="
|
|
26
|
+
className="miral:w-full miral:h-32 miral:object-contain"
|
|
27
27
|
src={url}
|
|
28
28
|
alt=""
|
|
29
29
|
loading="lazy"
|
package/src/Controls.tsx
CHANGED
|
@@ -11,17 +11,17 @@ type ControlsProps = {
|
|
|
11
11
|
export const Controls = ({ schema, values, onChange }: ControlsProps) => {
|
|
12
12
|
return (
|
|
13
13
|
<section
|
|
14
|
-
className="
|
|
14
|
+
className="miral:border-t miral:border-edge miral:text-sm/[1.5] miral:font-normal miral:group-data-isolated/shell:hidden"
|
|
15
15
|
aria-labelledby="preview-props-heading"
|
|
16
16
|
>
|
|
17
17
|
<h2
|
|
18
18
|
id="preview-props-heading"
|
|
19
|
-
className="
|
|
19
|
+
className="miral:m-0 miral:px-4 miral:py-2 miral:text-[length:inherit] miral:font-semibold"
|
|
20
20
|
>
|
|
21
21
|
Props
|
|
22
22
|
</h2>
|
|
23
23
|
<form
|
|
24
|
-
className="
|
|
24
|
+
className="miral:max-h-[30dvh] miral:overflow-auto miral:px-4 miral:pb-2"
|
|
25
25
|
onSubmit={preventSubmit}
|
|
26
26
|
>
|
|
27
27
|
{Object.entries(schema.shape).map(([name, field]) => {
|
|
@@ -70,7 +70,7 @@ export const Controls = ({ schema, values, onChange }: ControlsProps) => {
|
|
|
70
70
|
aria-label={name}
|
|
71
71
|
>
|
|
72
72
|
<span aria-hidden="true">{name}</span>
|
|
73
|
-
<div className="
|
|
73
|
+
<div className="miral:flex miral:w-fit miral:border miral:border-solid miral:border-edge miral:rounded-sm">
|
|
74
74
|
{[
|
|
75
75
|
["", "Default"],
|
|
76
76
|
["true", "On"],
|
|
@@ -78,10 +78,10 @@ export const Controls = ({ schema, values, onChange }: ControlsProps) => {
|
|
|
78
78
|
].map(([choice, label]) => (
|
|
79
79
|
<label
|
|
80
80
|
key={choice}
|
|
81
|
-
className="
|
|
81
|
+
className="miral:relative miral:py-[0.2rem] miral:px-2 miral:cursor-pointer miral:has-checked:text-paper miral:has-checked:bg-ink miral:focus-within:outline-2 miral:focus-within:outline-solid miral:focus-within:outline-ink miral:focus-within:outline-offset-2"
|
|
82
82
|
>
|
|
83
83
|
<input
|
|
84
|
-
className="
|
|
84
|
+
className="miral:absolute miral:inset-0 miral:m-0 miral:opacity-0 miral:cursor-pointer"
|
|
85
85
|
type="radio"
|
|
86
86
|
name={name}
|
|
87
87
|
value={choice}
|
|
@@ -101,7 +101,7 @@ export const Controls = ({ schema, values, onChange }: ControlsProps) => {
|
|
|
101
101
|
<label key={name} className="preview-prop-row">
|
|
102
102
|
{name}
|
|
103
103
|
<input
|
|
104
|
-
className="
|
|
104
|
+
className="miral:justify-self-start miral:accent-ink"
|
|
105
105
|
type="checkbox"
|
|
106
106
|
checked={value === true}
|
|
107
107
|
onChange={handleChange}
|
package/src/Nav.tsx
CHANGED
|
@@ -31,7 +31,7 @@ export const Nav = ({
|
|
|
31
31
|
}: NavProps) => (
|
|
32
32
|
<nav
|
|
33
33
|
className={[
|
|
34
|
-
"
|
|
34
|
+
"miral:overflow-auto miral:wrap-anywhere miral:py-[1.375rem] miral:px-3 miral:border-e miral:border-divider miral:[font-family:Inter,system-ui,sans-serif] miral:transition-opacity miral:duration-200 miral:ease-out miral:group-data-isolated/shell:opacity-0 miral:motion-reduce:transition-none miral:[@media(max-width:600px)]:max-h-[25dvh]",
|
|
35
35
|
className,
|
|
36
36
|
]
|
|
37
37
|
.filter(Boolean)
|
|
@@ -40,13 +40,13 @@ export const Nav = ({
|
|
|
40
40
|
aria-label="Component catalog"
|
|
41
41
|
>
|
|
42
42
|
{!!title && (
|
|
43
|
-
<h1 className="
|
|
43
|
+
<h1 className="miral:mx-2 miral:mt-0 miral:mb-[1.625rem] miral:text-2xl/[1.1] miral:font-bold miral:tracking-[-0.045em]">
|
|
44
44
|
{title}
|
|
45
45
|
</h1>
|
|
46
46
|
)}
|
|
47
47
|
{Array.from(new Set(entries.map((item) => item.section))).map((section) => (
|
|
48
|
-
<section key={section} className="
|
|
49
|
-
<h2 className="
|
|
48
|
+
<section key={section} className="miral:[section+&]:mt-[1.375rem]">
|
|
49
|
+
<h2 className="miral:mx-2 miral:mt-0 miral:mb-1.5 miral:text-muted miral:text-[0.71875rem]/[1.4] miral:font-[650] miral:tracking-[0.075em] miral:uppercase">
|
|
50
50
|
{section}
|
|
51
51
|
</h2>
|
|
52
52
|
{entries
|
|
@@ -68,7 +68,7 @@ export const Nav = ({
|
|
|
68
68
|
names.map((name) => (
|
|
69
69
|
<a
|
|
70
70
|
key={name}
|
|
71
|
-
className="
|
|
71
|
+
className="miral:ms-2 miral:ps-3.5 miral:rounded-l-none"
|
|
72
72
|
onClick={onLinkClick}
|
|
73
73
|
aria-current={selected === name ? "page" : undefined}
|
|
74
74
|
href={link({
|
|
@@ -87,7 +87,7 @@ export const Nav = ({
|
|
|
87
87
|
))}
|
|
88
88
|
{!!assetsPath && (
|
|
89
89
|
<a
|
|
90
|
-
className="
|
|
90
|
+
className="miral:mt-4"
|
|
91
91
|
href={link({ component: assetsPath, theme, layout })}
|
|
92
92
|
aria-current={activePath === assetsPath ? "page" : undefined}
|
|
93
93
|
onClick={onLinkClick}
|
package/src/Spinner.tsx
CHANGED
|
@@ -3,12 +3,12 @@ type SpinnerProps = { className?: string };
|
|
|
3
3
|
export const Spinner = ({ className }: SpinnerProps) => (
|
|
4
4
|
<span
|
|
5
5
|
className={[
|
|
6
|
-
"
|
|
6
|
+
"miral:fixed miral:inset-0 miral:z-2 miral:m-auto miral:inline-block miral:box-border miral:size-[1em] miral:pointer-events-none miral:rounded-full miral:border-2 miral:border-solid miral:border-current miral:border-r-transparent miral:text-ink miral:motion-safe:animate-spin miral:motion-safe:[animation-duration:700ms]",
|
|
7
7
|
className,
|
|
8
8
|
]
|
|
9
9
|
.filter(Boolean)
|
|
10
10
|
.join(" ")}
|
|
11
|
-
data-
|
|
11
|
+
data-miral-spinner
|
|
12
12
|
role="status"
|
|
13
13
|
aria-label="Loading"
|
|
14
14
|
/>
|
package/src/Toolbar.tsx
CHANGED
|
@@ -10,7 +10,7 @@ type ToolbarProps = {
|
|
|
10
10
|
className?: string;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const storageKey = "
|
|
13
|
+
const storageKey = "miral.preview:" + location.pathname + ":toolbar";
|
|
14
14
|
const guideKey = storageKey + ":guide-seen";
|
|
15
15
|
|
|
16
16
|
function read(key: string) {
|
|
@@ -198,7 +198,7 @@ export const Toolbar = ({
|
|
|
198
198
|
<div
|
|
199
199
|
ref={dock}
|
|
200
200
|
className={[
|
|
201
|
-
"
|
|
201
|
+
"miral:group/dock miral:fixed miral:top-3 miral:right-3 miral:w-max miral:max-w-screen miral:text-ink miral:text-sm/[1.5] miral:font-normal miral:transition-[opacity,transform,translate,scale] miral:duration-[160ms] miral:ease-out miral:data-hidden:opacity-0 miral:data-hidden:-translate-y-1 miral:data-hidden:scale-[0.98] miral:data-hidden:pointer-events-none miral:motion-reduce:transition-none",
|
|
202
202
|
className,
|
|
203
203
|
]
|
|
204
204
|
.filter(Boolean)
|
|
@@ -213,13 +213,13 @@ export const Toolbar = ({
|
|
|
213
213
|
}
|
|
214
214
|
>
|
|
215
215
|
<div
|
|
216
|
-
className="preview-toolbar
|
|
216
|
+
className="preview-toolbar miral:w-max miral:ms-auto miral:flex miral:items-center miral:p-[0.2rem] miral:border miral:border-solid miral:border-edge miral:rounded-[0.65rem] miral:bg-paper miral:text-ink"
|
|
217
217
|
role="group"
|
|
218
218
|
aria-label="Preview settings"
|
|
219
219
|
>
|
|
220
220
|
<button
|
|
221
221
|
type="button"
|
|
222
|
-
className="
|
|
222
|
+
className="miral:cursor-grab miral:touch-none miral:select-none miral:group-data-dragging/dock:cursor-grabbing"
|
|
223
223
|
title="Move toolbar · Drag or use arrow keys"
|
|
224
224
|
aria-label="Move toolbar"
|
|
225
225
|
onKeyDown={handleGripKeyDown}
|
|
@@ -234,30 +234,32 @@ export const Toolbar = ({
|
|
|
234
234
|
</div>
|
|
235
235
|
{guide && (
|
|
236
236
|
<aside
|
|
237
|
-
className="
|
|
237
|
+
className="miral:mt-[0.35rem] miral:p-[0.65rem] miral:border miral:border-solid miral:border-edge miral:rounded-[0.65rem] miral:bg-paper miral:max-h-[calc(100dvh-3.5rem)] miral:overflow-auto"
|
|
238
238
|
aria-label="Preview shortcuts"
|
|
239
239
|
>
|
|
240
|
-
<div className="
|
|
241
|
-
<strong className="
|
|
240
|
+
<div className="miral:flex miral:gap-[0.35rem] miral:justify-between">
|
|
241
|
+
<strong className="miral:font-[650]">Preview shortcuts</strong>
|
|
242
242
|
<button
|
|
243
243
|
type="button"
|
|
244
|
-
className="
|
|
244
|
+
className="miral:cursor-pointer"
|
|
245
245
|
aria-label="Dismiss shortcut guide"
|
|
246
246
|
onClick={handleDismissClick}
|
|
247
247
|
>
|
|
248
248
|
<Icon name="close" />
|
|
249
249
|
</button>
|
|
250
250
|
</div>
|
|
251
|
-
<p className="
|
|
252
|
-
|
|
251
|
+
<p className="miral:m-0 miral:mt-1">
|
|
252
|
+
Drag the handle to move the toolbar.
|
|
253
|
+
</p>
|
|
254
|
+
<dl className="miral:m-0 miral:mt-2 miral:flex miral:flex-col miral:gap-[0.35rem] miral:justify-between">
|
|
253
255
|
{shortcuts.map(([label, keys]) => (
|
|
254
256
|
<div
|
|
255
257
|
key={keys}
|
|
256
|
-
className="
|
|
258
|
+
className="miral:flex miral:gap-[0.35rem] miral:justify-between"
|
|
257
259
|
>
|
|
258
260
|
<dt>{label}</dt>
|
|
259
|
-
<dd className="
|
|
260
|
-
<kbd className="
|
|
261
|
+
<dd className="miral:m-0">
|
|
262
|
+
<kbd className="miral:[font:inherit]">{keys}</kbd>
|
|
261
263
|
</dd>
|
|
262
264
|
</div>
|
|
263
265
|
))}
|
package/src/Viewer.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { createRoot } from "react-dom/client";
|
|
3
3
|
import type * as z from "zod/mini";
|
|
4
4
|
import { Icon } from "./icons.tsx";
|
|
5
|
-
import "/
|
|
5
|
+
import "/__miral-viewer.css";
|
|
6
6
|
|
|
7
7
|
import { Assets } from "./Assets.tsx";
|
|
8
8
|
import { Controls, type Values } from "./Controls.tsx";
|
|
@@ -20,18 +20,18 @@ type ExampleModule = {
|
|
|
20
20
|
} & Record<string, unknown>;
|
|
21
21
|
|
|
22
22
|
const modules = import.meta.glob<ExampleModule>([
|
|
23
|
-
"/**/*.
|
|
23
|
+
"/**/*.mira.tsx",
|
|
24
24
|
"!/**/node_modules/**",
|
|
25
25
|
"!/**/dist/**",
|
|
26
26
|
"!/**/.git/**",
|
|
27
27
|
]);
|
|
28
28
|
|
|
29
29
|
const sections = import.meta.glob<string>(
|
|
30
|
-
["/**/*.
|
|
31
|
-
{ eager: true, query: "?
|
|
30
|
+
["/**/*.mira.tsx", "!/**/node_modules/**", "!/**/dist/**", "!/**/.git/**"],
|
|
31
|
+
{ eager: true, query: "?miral-section", import: "default" },
|
|
32
32
|
);
|
|
33
33
|
|
|
34
|
-
type
|
|
34
|
+
type MiralConfig = {
|
|
35
35
|
title?: string;
|
|
36
36
|
assetsDir?: string;
|
|
37
37
|
stylesheet?: string;
|
|
@@ -40,11 +40,11 @@ type GlassoConfig = {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const configs = import.meta.glob<{
|
|
43
|
-
default:
|
|
43
|
+
default: MiralConfig;
|
|
44
44
|
assetFiles?: Record<string, string>;
|
|
45
|
-
}>("/
|
|
45
|
+
}>("/miral.config.ts", { eager: true });
|
|
46
46
|
|
|
47
|
-
const config = configs["/
|
|
47
|
+
const config = configs["/miral.config.ts"];
|
|
48
48
|
|
|
49
49
|
const {
|
|
50
50
|
title,
|
|
@@ -55,7 +55,7 @@ const {
|
|
|
55
55
|
|
|
56
56
|
const catalogTitle = title?.trim();
|
|
57
57
|
|
|
58
|
-
document.title = catalogTitle ? `${catalogTitle} |
|
|
58
|
+
document.title = catalogTitle ? `${catalogTitle} | Miral` : "Miral";
|
|
59
59
|
|
|
60
60
|
const assets = config?.assetFiles;
|
|
61
61
|
const assetsEntry = { path: "assets", name: "Assets", section: "" };
|
|
@@ -79,7 +79,7 @@ const entries = Object.keys(modules)
|
|
|
79
79
|
return {
|
|
80
80
|
path,
|
|
81
81
|
section,
|
|
82
|
-
name: parts.at(-1)?.replace(/\.
|
|
82
|
+
name: parts.at(-1)?.replace(/\.mira\.tsx$/, "") ?? path,
|
|
83
83
|
};
|
|
84
84
|
})
|
|
85
85
|
.sort(
|
|
@@ -230,7 +230,7 @@ function animateIsolation(canvas: HTMLIFrameElement, open: boolean) {
|
|
|
230
230
|
|
|
231
231
|
const FrameLoading = () => {
|
|
232
232
|
React.useLayoutEffect(() => {
|
|
233
|
-
parent.postMessage({ type: "
|
|
233
|
+
parent.postMessage({ type: "miral-loading" }, location.origin);
|
|
234
234
|
}, []);
|
|
235
235
|
|
|
236
236
|
return null;
|
|
@@ -401,10 +401,7 @@ const Viewer = () => {
|
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
if (frame)
|
|
404
|
-
parent.postMessage(
|
|
405
|
-
{ type: "glasso-shortcut", action },
|
|
406
|
-
location.origin,
|
|
407
|
-
);
|
|
404
|
+
parent.postMessage({ type: "miral-shortcut", action }, location.origin);
|
|
408
405
|
else runShortcut(action);
|
|
409
406
|
};
|
|
410
407
|
|
|
@@ -413,7 +410,7 @@ const Viewer = () => {
|
|
|
413
410
|
!frame &&
|
|
414
411
|
event.source === iframe.current?.contentWindow &&
|
|
415
412
|
event.origin === location.origin &&
|
|
416
|
-
event.data?.type === "
|
|
413
|
+
event.data?.type === "miral-shortcut"
|
|
417
414
|
)
|
|
418
415
|
runShortcut(event.data.action);
|
|
419
416
|
};
|
|
@@ -438,7 +435,7 @@ const Viewer = () => {
|
|
|
438
435
|
if (
|
|
439
436
|
event.origin !== location.origin ||
|
|
440
437
|
event.source !== parent ||
|
|
441
|
-
event.data?.type !== "
|
|
438
|
+
event.data?.type !== "miral-settings"
|
|
442
439
|
)
|
|
443
440
|
return;
|
|
444
441
|
|
|
@@ -449,7 +446,7 @@ const Viewer = () => {
|
|
|
449
446
|
};
|
|
450
447
|
|
|
451
448
|
window.addEventListener("message", receive);
|
|
452
|
-
parent.postMessage({ type: "
|
|
449
|
+
parent.postMessage({ type: "miral-ready" }, location.origin);
|
|
453
450
|
|
|
454
451
|
return () => {
|
|
455
452
|
window.removeEventListener("message", receive);
|
|
@@ -462,7 +459,7 @@ const Viewer = () => {
|
|
|
462
459
|
|
|
463
460
|
const sync = () =>
|
|
464
461
|
iframe.current?.contentWindow?.postMessage(
|
|
465
|
-
{ type: "
|
|
462
|
+
{ type: "miral-settings", theme, values },
|
|
466
463
|
location.origin,
|
|
467
464
|
);
|
|
468
465
|
|
|
@@ -473,10 +470,10 @@ const Viewer = () => {
|
|
|
473
470
|
)
|
|
474
471
|
return;
|
|
475
472
|
|
|
476
|
-
if (event.data?.type === "
|
|
473
|
+
if (event.data?.type === "miral-ready") {
|
|
477
474
|
setFrameLoading(false);
|
|
478
475
|
sync();
|
|
479
|
-
} else if (event.data?.type === "
|
|
476
|
+
} else if (event.data?.type === "miral-loading") {
|
|
480
477
|
setFrameLoading(true);
|
|
481
478
|
}
|
|
482
479
|
};
|
|
@@ -509,11 +506,11 @@ const Viewer = () => {
|
|
|
509
506
|
|
|
510
507
|
if (frame && entry) {
|
|
511
508
|
const Component = page[selected] as React.ComponentType<Values>;
|
|
512
|
-
if (!Component) return <p>Export Preview from {entry.name}.
|
|
509
|
+
if (!Component) return <p>Export Preview from {entry.name}.mira.tsx.</p>;
|
|
513
510
|
|
|
514
511
|
return (
|
|
515
512
|
<main
|
|
516
|
-
className="
|
|
513
|
+
className="miral:box-border miral:min-h-dvh miral:bg-paper miral:text-ink miral:data-[layout=centered]:grid miral:data-[layout=centered]:place-items-center miral:data-[layout=centered]:p-4 miral:data-[layout=padded]:p-4"
|
|
517
514
|
data-layout={
|
|
518
515
|
(selected === "Playground" ? page.playgroundLayout : page.layout) ??
|
|
519
516
|
"centered"
|
|
@@ -534,7 +531,7 @@ const Viewer = () => {
|
|
|
534
531
|
|
|
535
532
|
return (
|
|
536
533
|
<div
|
|
537
|
-
className="preview-shell
|
|
534
|
+
className="preview-shell miral:group/shell"
|
|
538
535
|
data-isolated={isolated || undefined}
|
|
539
536
|
>
|
|
540
537
|
{!!entry && frameLoading && <Spinner />}
|
|
@@ -551,11 +548,11 @@ const Viewer = () => {
|
|
|
551
548
|
link={link}
|
|
552
549
|
onLinkClick={handleLinkClick}
|
|
553
550
|
/>
|
|
554
|
-
<main className="
|
|
551
|
+
<main className="miral:flex miral:min-h-0 miral:flex-col miral:[@media(max-width:600px)]:flex-1">
|
|
555
552
|
{!!entry && (
|
|
556
553
|
<>
|
|
557
554
|
<div
|
|
558
|
-
className="
|
|
555
|
+
className="miral:sticky miral:top-0 miral:z-1 miral:transition-opacity miral:duration-200 miral:ease-out miral:group-data-isolated/shell:opacity-0 miral:motion-reduce:transition-none"
|
|
559
556
|
inert={isolated}
|
|
560
557
|
>
|
|
561
558
|
<Toolbar hidden={toolbarHidden} isolated={isolated}>
|
|
@@ -596,9 +593,9 @@ const Viewer = () => {
|
|
|
596
593
|
</button>
|
|
597
594
|
</Toolbar>
|
|
598
595
|
</div>
|
|
599
|
-
<div className="
|
|
596
|
+
<div className="miral:flex-1 miral:overflow-auto" ref={stage}>
|
|
600
597
|
<div
|
|
601
|
-
className="
|
|
598
|
+
className="miral:h-full miral:overflow-clip"
|
|
602
599
|
style={
|
|
603
600
|
size
|
|
604
601
|
? { width: size[0] * scale, height: size[1] * scale }
|
|
@@ -607,7 +604,7 @@ const Viewer = () => {
|
|
|
607
604
|
>
|
|
608
605
|
<iframe
|
|
609
606
|
key={frameUrl}
|
|
610
|
-
className="
|
|
607
|
+
className="miral:block miral:origin-top-left miral:transition-none miral:max-w-none miral:border-0 miral:bg-paper miral:group-has-[[data-dragging]]/shell:pointer-events-none miral:group-data-isolated/shell:fixed miral:group-data-isolated/shell:inset-0 miral:group-data-isolated/shell:w-full miral:group-data-isolated/shell:h-dvh miral:group-data-isolated/shell:z-1"
|
|
611
608
|
ref={iframe}
|
|
612
609
|
style={{
|
|
613
610
|
transform:
|
package/src/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ const {
|
|
|
17
17
|
|
|
18
18
|
if (!["preview", "build"].includes(command)) {
|
|
19
19
|
console.error(
|
|
20
|
-
"Usage:
|
|
20
|
+
"Usage: miral preview [directory] [--port 9000] | miral build [directory] [--outDir dist]",
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
process.exit(1);
|
|
@@ -25,19 +25,19 @@ if (!["preview", "build"].includes(command)) {
|
|
|
25
25
|
|
|
26
26
|
const root = path.resolve(directory ?? ".");
|
|
27
27
|
const htmlId = path.join(root, "index.html");
|
|
28
|
-
const entry = "/@
|
|
28
|
+
const entry = "/@miral/viewer.tsx";
|
|
29
29
|
|
|
30
30
|
const html =
|
|
31
|
-
'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>
|
|
31
|
+
'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Miral</title></head><body><div id="root"></div><script type="module" src="/@miral/viewer.tsx"></script></body></html>';
|
|
32
32
|
|
|
33
33
|
const sources = new Map([
|
|
34
34
|
[path.join(root, entry), "./Viewer.tsx"],
|
|
35
|
-
[path.join(root, "@
|
|
36
|
-
[path.join(root, "@
|
|
37
|
-
[path.join(root, "@
|
|
38
|
-
[path.join(root, "@
|
|
39
|
-
[path.join(root, "@
|
|
40
|
-
[path.join(root, "@
|
|
35
|
+
[path.join(root, "@miral/icons.tsx"), "./icons.tsx"],
|
|
36
|
+
[path.join(root, "@miral/Assets.tsx"), "./Assets.tsx"],
|
|
37
|
+
[path.join(root, "@miral/Nav.tsx"), "./Nav.tsx"],
|
|
38
|
+
[path.join(root, "@miral/Spinner.tsx"), "./Spinner.tsx"],
|
|
39
|
+
[path.join(root, "@miral/Toolbar.tsx"), "./Toolbar.tsx"],
|
|
40
|
+
[path.join(root, "@miral/Controls.tsx"), "./Controls.tsx"],
|
|
41
41
|
]);
|
|
42
42
|
|
|
43
43
|
const sourceFiles = new Map(
|
|
@@ -48,10 +48,10 @@ const sourceFiles = new Map(
|
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
const viewer = {
|
|
51
|
-
name: "
|
|
51
|
+
name: "miral-preview",
|
|
52
52
|
enforce: "pre",
|
|
53
53
|
resolveId(id, importer) {
|
|
54
|
-
if (id === "/
|
|
54
|
+
if (id === "/__miral-viewer.css")
|
|
55
55
|
return fileURLToPath(new URL("./theme.css", import.meta.url));
|
|
56
56
|
|
|
57
57
|
if (id === htmlId || sources.has(id)) return id;
|
|
@@ -63,7 +63,7 @@ const viewer = {
|
|
|
63
63
|
if (sources.has(candidate)) return candidate;
|
|
64
64
|
},
|
|
65
65
|
transform(source, id) {
|
|
66
|
-
if (id === path.join(root, "
|
|
66
|
+
if (id === path.join(root, "miral.config.ts")) {
|
|
67
67
|
const { program } = parseSync(id, source);
|
|
68
68
|
|
|
69
69
|
const config = program.body.find(
|
|
@@ -88,7 +88,7 @@ const viewer = {
|
|
|
88
88
|
|
|
89
89
|
if (typeof directory !== "string" || !directory.trim())
|
|
90
90
|
this.error(
|
|
91
|
-
"Use a directory path string literal for assetsDir in
|
|
91
|
+
"Use a directory path string literal for assetsDir in miral.config.ts.",
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
const pattern = path.posix.join(directory, "**/*");
|
|
@@ -106,7 +106,7 @@ const viewer = {
|
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
if (!id.endsWith(".
|
|
109
|
+
if (!id.endsWith(".mira.tsx?miral-section")) return;
|
|
110
110
|
|
|
111
111
|
const { program } = parseSync(id.split("?")[0], source);
|
|
112
112
|
|
|
@@ -174,7 +174,7 @@ const config = {
|
|
|
174
174
|
configFile: false,
|
|
175
175
|
plugins: [viewer, react(), tailwind({ optimize: false })],
|
|
176
176
|
optimizeDeps: {
|
|
177
|
-
entries: ["**/*.
|
|
177
|
+
entries: ["**/*.mira.tsx", "!**/dist/**"],
|
|
178
178
|
include: [
|
|
179
179
|
"react",
|
|
180
180
|
"react-dom/client",
|
package/src/theme.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@layer theme, components, utilities;
|
|
2
|
-
@import "tailwindcss/theme.css" layer(theme) prefix(
|
|
3
|
-
@import "tailwindcss/utilities.css" layer(utilities) prefix(
|
|
2
|
+
@import "tailwindcss/theme.css" layer(theme) prefix(miral);
|
|
3
|
+
@import "tailwindcss/utilities.css" layer(utilities) prefix(miral) source(none);
|
|
4
4
|
@source "./*.tsx";
|
|
5
5
|
|
|
6
6
|
@theme inline {
|
|
@@ -16,52 +16,52 @@
|
|
|
16
16
|
--paper: light-dark(white, #121212);
|
|
17
17
|
--ink: light-dark(#121212, white);
|
|
18
18
|
--border: light-dark(#bfbfbf, #606060);
|
|
19
|
-
@apply
|
|
19
|
+
@apply miral:scheme-light;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
:root.dark {
|
|
23
|
-
@apply
|
|
23
|
+
@apply miral:scheme-dark;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
body {
|
|
27
|
-
@apply
|
|
27
|
+
@apply miral:m-0;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
@layer components {
|
|
31
31
|
.preview-shell {
|
|
32
|
-
@apply
|
|
32
|
+
@apply miral:grid miral:grid-cols-[fit-content(35%)_minmax(0,1fr)] miral:h-dvh miral:bg-paper miral:text-ink miral:[font-family:system-ui,sans-serif] miral:text-[0.9375rem]/[1.4] miral:[@media(max-width:600px)]:flex miral:[@media(max-width:600px)]:flex-col;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
.preview-shell,
|
|
36
36
|
.preview-shell * {
|
|
37
|
-
@apply
|
|
37
|
+
@apply miral:box-border;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
.preview-shell :is(button, input, select) {
|
|
41
|
-
@apply
|
|
41
|
+
@apply miral:[font:inherit] miral:text-inherit;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
.preview-shell button {
|
|
45
|
-
@apply
|
|
45
|
+
@apply miral:border-0 miral:bg-none miral:bg-transparent miral:p-0;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
.preview-shell :is(nav a, button):focus-visible {
|
|
49
|
-
@apply
|
|
49
|
+
@apply miral:outline-2 miral:outline-solid miral:outline-ink miral:outline-offset-1;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
.preview-shell nav a {
|
|
53
|
-
@apply
|
|
53
|
+
@apply miral:block miral:rounded-sm miral:px-2 miral:py-[0.3125rem] miral:text-sm/[1.4] miral:tracking-[-0.012em] miral:text-inherit miral:no-underline miral:aria-[current]:font-bold miral:[&:not([aria-current]):hover]:bg-hover;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
.preview-toolbar button {
|
|
57
|
-
@apply
|
|
57
|
+
@apply miral:grid miral:place-items-center miral:h-8 miral:min-w-8 miral:px-[0.35rem] miral:rounded-[0.4rem] miral:cursor-pointer miral:aria-pressed:text-paper miral:aria-pressed:bg-ink miral:[&:not([aria-pressed=true]):hover]:bg-hover;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
.preview-prop-row {
|
|
61
|
-
@apply
|
|
61
|
+
@apply miral:grid miral:grid-cols-[minmax(0,9rem)_minmax(0,14rem)] miral:gap-4 miral:items-center miral:min-h-10 miral:border-t miral:border-edge miral:wrap-anywhere;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
.preview-prop-row > :is(input, select) {
|
|
65
|
-
@apply
|
|
65
|
+
@apply miral:min-w-0 miral:border miral:border-solid miral:border-edge miral:rounded-sm miral:p-1 miral:bg-paper;
|
|
66
66
|
}
|
|
67
67
|
}
|