miral 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -33
- package/dist/Assets.js +4 -0
- package/dist/Controls.js +55 -0
- package/dist/Nav.js +17 -0
- package/dist/Spinner.js +7 -0
- package/dist/Toolbar.js +139 -0
- package/dist/Viewer.js +364 -0
- package/dist/cli.js +214 -0
- package/dist/icons.js +12 -0
- package/{src → dist}/theme.css +1 -1
- package/package.json +25 -9
- package/src/Assets.tsx +0 -41
- package/src/Controls.tsx +0 -147
- package/src/Nav.tsx +0 -99
- package/src/Spinner.tsx +0 -15
- package/src/Toolbar.tsx +0 -271
- package/src/Viewer.tsx +0 -643
- package/src/cli.js +0 -206
- package/src/icons.tsx +0 -31
package/src/cli.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { parseArgs } from "node:util";
|
|
6
|
-
import tailwind from "@tailwindcss/vite";
|
|
7
|
-
import react from "@vitejs/plugin-react";
|
|
8
|
-
import { build, createServer, parseSync } from "vite";
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
positionals: [command, directory],
|
|
12
|
-
values,
|
|
13
|
-
} = parseArgs({
|
|
14
|
-
allowPositionals: true,
|
|
15
|
-
options: { port: { type: "string" }, outDir: { type: "string" } },
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (!["preview", "build"].includes(command)) {
|
|
19
|
-
console.error(
|
|
20
|
-
"Usage: miral preview [directory] [--port 9000] | miral build [directory] [--outDir dist]",
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const root = path.resolve(directory ?? ".");
|
|
27
|
-
const htmlId = path.join(root, "index.html");
|
|
28
|
-
const entry = "/@miral/viewer.tsx";
|
|
29
|
-
|
|
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>Miral</title></head><body><div id="root"></div><script type="module" src="/@miral/viewer.tsx"></script></body></html>';
|
|
32
|
-
|
|
33
|
-
const sources = new Map([
|
|
34
|
-
[path.join(root, entry), "./Viewer.tsx"],
|
|
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
|
-
]);
|
|
42
|
-
|
|
43
|
-
const sourceFiles = new Map(
|
|
44
|
-
Array.from(sources, ([id, file]) => [
|
|
45
|
-
fileURLToPath(new URL(file, import.meta.url)),
|
|
46
|
-
id,
|
|
47
|
-
]),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const viewer = {
|
|
51
|
-
name: "miral-preview",
|
|
52
|
-
enforce: "pre",
|
|
53
|
-
resolveId(id, importer) {
|
|
54
|
-
if (id === "/__miral-viewer.css")
|
|
55
|
-
return fileURLToPath(new URL("./theme.css", import.meta.url));
|
|
56
|
-
|
|
57
|
-
if (id === htmlId || sources.has(id)) return id;
|
|
58
|
-
|
|
59
|
-
const candidate = id.startsWith("/")
|
|
60
|
-
? path.join(root, id)
|
|
61
|
-
: path.resolve(path.dirname(importer ?? htmlId), id);
|
|
62
|
-
|
|
63
|
-
if (sources.has(candidate)) return candidate;
|
|
64
|
-
},
|
|
65
|
-
transform(source, id) {
|
|
66
|
-
if (id === path.join(root, "miral.config.ts")) {
|
|
67
|
-
const { program } = parseSync(id, source);
|
|
68
|
-
|
|
69
|
-
const config = program.body.find(
|
|
70
|
-
(node) => node.type === "ExportDefaultDeclaration",
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
let object = config?.declaration;
|
|
74
|
-
|
|
75
|
-
while (
|
|
76
|
-
object?.type === "TSAsExpression" ||
|
|
77
|
-
object?.type === "TSSatisfiesExpression"
|
|
78
|
-
)
|
|
79
|
-
object = object.expression;
|
|
80
|
-
|
|
81
|
-
const property = object?.properties?.find(
|
|
82
|
-
(item) => (item.key?.name ?? item.key?.value) === "assetsDir",
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (!property) return;
|
|
86
|
-
|
|
87
|
-
const directory = property.value?.value;
|
|
88
|
-
|
|
89
|
-
if (typeof directory !== "string" || !directory.trim())
|
|
90
|
-
this.error(
|
|
91
|
-
"Use a directory path string literal for assetsDir in miral.config.ts.",
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const pattern = path.posix.join(directory, "**/*");
|
|
95
|
-
|
|
96
|
-
const glob =
|
|
97
|
-
pattern.startsWith(".") || pattern.startsWith("/")
|
|
98
|
-
? pattern
|
|
99
|
-
: "./" + pattern;
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
source +
|
|
103
|
-
"\nexport const assetFiles = import.meta.glob(" +
|
|
104
|
-
JSON.stringify(glob) +
|
|
105
|
-
', { eager: true, query: "?url", import: "default" });'
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!id.endsWith(".mira.tsx?miral-section")) return;
|
|
110
|
-
|
|
111
|
-
const { program } = parseSync(id.split("?")[0], source);
|
|
112
|
-
|
|
113
|
-
for (const statement of program.body) {
|
|
114
|
-
if (
|
|
115
|
-
statement.type !== "ExportNamedDeclaration" ||
|
|
116
|
-
statement.declaration?.type !== "VariableDeclaration"
|
|
117
|
-
)
|
|
118
|
-
continue;
|
|
119
|
-
|
|
120
|
-
const field = statement.declaration.declarations.find(
|
|
121
|
-
(item) => item.id.name === "section",
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
if (!field) continue;
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
field.init?.type !== "Literal" ||
|
|
128
|
-
typeof field.init.value !== "string"
|
|
129
|
-
)
|
|
130
|
-
this.error("Use a string literal for section in " + id.split("?")[0]);
|
|
131
|
-
|
|
132
|
-
return "export default " + JSON.stringify(field.init.value.trim());
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return 'export default ""';
|
|
136
|
-
},
|
|
137
|
-
async load(id) {
|
|
138
|
-
if (id === htmlId) return html;
|
|
139
|
-
|
|
140
|
-
const file = sources.get(id);
|
|
141
|
-
|
|
142
|
-
if (file) {
|
|
143
|
-
const result = await readFile(new URL(file, import.meta.url), "utf8");
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
handleHotUpdate({ file, server, modules }) {
|
|
148
|
-
const id = sourceFiles.get(file);
|
|
149
|
-
if (!id) return;
|
|
150
|
-
|
|
151
|
-
const module = server.moduleGraph.getModuleById(id);
|
|
152
|
-
if (module) return [...modules, module];
|
|
153
|
-
},
|
|
154
|
-
configureServer(server) {
|
|
155
|
-
server.watcher.add([...sourceFiles.keys()]);
|
|
156
|
-
|
|
157
|
-
server.middlewares.use(async (request, response, next) => {
|
|
158
|
-
const url = new URL(request.url, "http://localhost");
|
|
159
|
-
if (!["/", "/index.html"].includes(url.pathname)) return next();
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
response.setHeader("Content-Type", "text/html");
|
|
163
|
-
response.end(await server.transformIndexHtml(url.pathname, html));
|
|
164
|
-
} catch (error) {
|
|
165
|
-
next(error);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const config = {
|
|
172
|
-
root,
|
|
173
|
-
base: "./",
|
|
174
|
-
configFile: false,
|
|
175
|
-
plugins: [viewer, react(), tailwind({ optimize: false })],
|
|
176
|
-
optimizeDeps: {
|
|
177
|
-
entries: ["**/*.mira.tsx", "!**/dist/**"],
|
|
178
|
-
include: [
|
|
179
|
-
"react",
|
|
180
|
-
"react-dom/client",
|
|
181
|
-
"react/jsx-runtime",
|
|
182
|
-
"react/jsx-dev-runtime",
|
|
183
|
-
],
|
|
184
|
-
},
|
|
185
|
-
resolve: { dedupe: ["react", "react-dom"] },
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
if (command === "build") {
|
|
189
|
-
await build({
|
|
190
|
-
...config,
|
|
191
|
-
build: {
|
|
192
|
-
cssTarget: "esnext",
|
|
193
|
-
outDir: path.resolve(values.outDir ?? "dist"),
|
|
194
|
-
emptyOutDir: false,
|
|
195
|
-
rolldownOptions: { input: htmlId },
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
const server = await createServer({
|
|
200
|
-
...config,
|
|
201
|
-
server: { port: Number(values.port ?? 9000), strictPort: true },
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
await server.listen();
|
|
205
|
-
server.printUrls();
|
|
206
|
-
}
|
package/src/icons.tsx
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const paths = {
|
|
2
|
-
phone:
|
|
3
|
-
"M8 2.5h8a2 2 0 0 1 2 2v15a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2v-15a2 2 0 0 1 2-2Z M10.5 18.5h3",
|
|
4
|
-
tablet:
|
|
5
|
-
"M5.5 2.5h13a2 2 0 0 1 2 2v15a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2v-15a2 2 0 0 1 2-2Z M12 5.5h.01",
|
|
6
|
-
desktop: "M2 3h20v14H2z M12 17v4 M7 21h10",
|
|
7
|
-
sun: "M16 12a4 4 0 1 1-8 0 4 4 0 0 1 8 0z M12 2v2m0 16v2M2 12h2m16 0h2M5 5l1.5 1.5m11 11L19 19M5 19l1.5-1.5m11-11L19 5",
|
|
8
|
-
moon: "M21 14a9 9 0 0 1-11-11 9.2 9.2 0 1 0 11 11z",
|
|
9
|
-
expand: "M4 9V4h5m6 0h5v5m0 6v5h-5m-6 0H4v-5",
|
|
10
|
-
grip: "M9 6h.1M15 6h.1M9 12h.1M15 12h.1M9 18h.1M15 18h.1",
|
|
11
|
-
close: "M6 6l12 12M18 6L6 18",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type IconProps = { name: keyof typeof paths; className?: string };
|
|
15
|
-
|
|
16
|
-
export const Icon = ({ name, className }: IconProps) => (
|
|
17
|
-
<svg
|
|
18
|
-
className={className}
|
|
19
|
-
aria-hidden="true"
|
|
20
|
-
width="1em"
|
|
21
|
-
height="1em"
|
|
22
|
-
viewBox="0 0 24 24"
|
|
23
|
-
fill="none"
|
|
24
|
-
stroke="currentColor"
|
|
25
|
-
strokeWidth={name === "grip" ? 3 : 2}
|
|
26
|
-
strokeLinecap="round"
|
|
27
|
-
strokeLinejoin="round"
|
|
28
|
-
>
|
|
29
|
-
<path d={paths[name]} />
|
|
30
|
-
</svg>
|
|
31
|
-
);
|