@hamur/adapter-vue 0.0.0-stage → 0.0.2
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/LICENSE +22 -0
- package/README.md +32 -2
- package/dist/chunks/browser-index-43pdsfp6.js +69 -0
- package/dist/chunks/browser-index-d1bxd40m.js +320 -0
- package/dist/chunks/browser-index-nhft0ewv.js +161 -0
- package/dist/src/adapter.js +402 -0
- package/dist/src/index.js +1348 -0
- package/dist/src/keepalive.js +6 -0
- package/dist/src/runtime/client.js +20 -0
- package/dist/src/runtime/island.js +45 -0
- package/dist/src/runtime/server.js +238 -0
- package/dist/types/src/adapter.d.ts +2 -0
- package/dist/types/src/async-data.d.ts +14 -0
- package/dist/types/src/client-component.d.ts +12 -0
- package/dist/types/src/client-fallback.d.ts +2 -0
- package/dist/types/src/components/AwaitValue.d.ts +15 -0
- package/dist/types/src/components/ClientFallback.server.d.ts +17 -0
- package/dist/types/src/components/ErrorBoundary.server.d.ts +21 -0
- package/dist/types/src/components/error-code.d.ts +1 -0
- package/dist/types/src/context.d.ts +65 -0
- package/dist/types/src/index.d.ts +329 -0
- package/dist/types/src/island.d.ts +68 -0
- package/dist/types/src/keepalive.d.ts +22 -0
- package/dist/types/src/lazy-hydration.d.ts +10 -0
- package/dist/types/src/markdown-page.d.ts +9 -0
- package/dist/types/src/markdown.d.ts +45 -0
- package/dist/types/src/plugin.d.ts +45 -0
- package/dist/types/src/route-boundary.d.ts +35 -0
- package/dist/types/src/route-boundary.server.d.ts +5 -0
- package/dist/types/src/runtime/client.d.ts +11 -0
- package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
- package/dist/types/src/runtime/hydration.d.ts +8 -0
- package/dist/types/src/runtime/island.d.ts +8 -0
- package/dist/types/src/runtime/server.d.ts +12 -0
- package/dist/types/src/server-island.d.ts +33 -0
- package/dist/types/src/svg.d.ts +10 -0
- package/package.json +64 -4
- package/src/adapter.ts +25 -0
- package/src/async-data.ts +77 -0
- package/src/client-component.ts +39 -0
- package/src/client-fallback.ts +2 -0
- package/src/components/Await.vue +30 -0
- package/src/components/AwaitValue.ts +41 -0
- package/src/components/ClientFallback.server.ts +41 -0
- package/src/components/ClientFallback.vue +31 -0
- package/src/components/ClientOnly.vue +16 -0
- package/src/components/DefaultErrorPage.vue +19 -0
- package/src/components/DevOnly.vue +8 -0
- package/src/components/ErrorBoundary.server.ts +69 -0
- package/src/components/ErrorBoundary.vue +32 -0
- package/src/components/Form.vue +85 -0
- package/src/components/Link.vue +200 -0
- package/src/components/Navigate.vue +16 -0
- package/src/components/Outlet.vue +28 -0
- package/src/components/error-code.ts +7 -0
- package/src/context.ts +391 -0
- package/src/index.ts +1528 -0
- package/src/island.ts +53 -0
- package/src/keepalive.ts +92 -0
- package/src/lazy-hydration.ts +53 -0
- package/src/markdown-page.ts +21 -0
- package/src/markdown.ts +80 -0
- package/src/plugin.ts +398 -0
- package/src/route-boundary.server.ts +29 -0
- package/src/route-boundary.ts +48 -0
- package/src/runtime/client.ts +137 -0
- package/src/runtime/hydration-dev.ts +38 -0
- package/src/runtime/hydration.ts +7 -0
- package/src/runtime/island.ts +60 -0
- package/src/runtime/server.ts +145 -0
- package/src/server-island.ts +38 -0
- package/src/svg.ts +28 -0
- package/src/vue.d.ts +5 -0
- package/src/webmcp.d.ts +18 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/adapter-vue/src/adapter.ts
|
|
3
|
+
import { ADAPTER_CONTRACT, defineAdapter } from "hamur/adapter";
|
|
4
|
+
import { clientComponentModule, serverComponentModule } from "hamur/adapter/build";
|
|
5
|
+
|
|
6
|
+
// packages/adapter-vue/src/plugin.ts
|
|
7
|
+
import { compileScript, compileStyleAsync, compileTemplate, parse } from "vue/compiler-sfc";
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { realpathSync } from "fs";
|
|
10
|
+
import { dirname, extname, join, relative, resolve } from "path";
|
|
11
|
+
import { DiagnosticError } from "hamur/kit";
|
|
12
|
+
import { mergeMappings } from "hamur/adapter/dev";
|
|
13
|
+
var STYLE_NAMESPACE = "hamur-vue-style";
|
|
14
|
+
function hmrFooter(id, hashes, styleCount, compileId) {
|
|
15
|
+
const hmrId = JSON.stringify(id);
|
|
16
|
+
const script = JSON.stringify(hashes.script);
|
|
17
|
+
const template = JSON.stringify(hashes.template);
|
|
18
|
+
const cssModules = JSON.stringify(hashes.cssModules);
|
|
19
|
+
const compile = JSON.stringify(compileId);
|
|
20
|
+
return `
|
|
21
|
+
_sfc_main.__hmrId = ${hmrId};
|
|
22
|
+
_sfc_main.__scriptHash = ${script};
|
|
23
|
+
_sfc_main.__templateHash = ${template};
|
|
24
|
+
_sfc_main.__cssModulesHash = ${cssModules};
|
|
25
|
+
_sfc_main.__styleCount = ${styleCount};
|
|
26
|
+
_sfc_main.__compileId = ${compile};
|
|
27
|
+
globalThis.__VUE_HMR_RUNTIME__?.createRecord(${hmrId}, _sfc_main);
|
|
28
|
+
import.meta.hot.accept((mod) => {
|
|
29
|
+
const hmr = globalThis.__VUE_HMR_RUNTIME__;
|
|
30
|
+
if (!mod || !hmr) return;
|
|
31
|
+
const next = mod.default;
|
|
32
|
+
if (next.__styleCount !== ${styleCount}) return location.reload();
|
|
33
|
+
const maps = _sfc_main.__cssModules;
|
|
34
|
+
for (const name of Object.keys(maps)) delete maps[name];
|
|
35
|
+
next.__cssModules = Object.assign(maps, next.__cssModules);
|
|
36
|
+
if (next.__compileId === ${compile} || next.__scriptHash !== ${script} || (next.__scopeId && !_sfc_main.__scopeId)) hmr.reload(${hmrId}, next);
|
|
37
|
+
else if (next.__templateHash !== ${template} || next.__cssModulesHash !== ${cssModules}) hmr.rerender(${hmrId}, next.render);
|
|
38
|
+
});`;
|
|
39
|
+
}
|
|
40
|
+
var PREPROCESSED = {
|
|
41
|
+
scss: "sass",
|
|
42
|
+
sass: "sass",
|
|
43
|
+
less: "less",
|
|
44
|
+
styl: "stylus",
|
|
45
|
+
stylus: "stylus"
|
|
46
|
+
};
|
|
47
|
+
var PLAIN_LANGS = ["css", "postcss"];
|
|
48
|
+
var SUPPORTED_LANGS = "css, postcss, scss, sass, less, styl, stylus";
|
|
49
|
+
var langOf = (style) => style.lang ?? (style.src ? extname(style.src).slice(1) || "css" : "css");
|
|
50
|
+
function resolveSrc(src, dir) {
|
|
51
|
+
try {
|
|
52
|
+
return Bun.resolveSync(src, dir);
|
|
53
|
+
} catch {
|
|
54
|
+
return resolve(dir, src);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
var scopeIdOf = (path) => `data-v-${Bun.hash(path).toString(16).slice(0, 8)}`;
|
|
58
|
+
var moduleIdOf = (path, index) => Bun.hash(`${path}?${index}`).toString(36).slice(0, 6);
|
|
59
|
+
var SESSION = Date.now().toString(36);
|
|
60
|
+
var compiles = 0;
|
|
61
|
+
var ROOT = 0;
|
|
62
|
+
var ELEMENT = 1;
|
|
63
|
+
var TEXT = 2;
|
|
64
|
+
var ATTRIBUTE = 6;
|
|
65
|
+
var DIRECTIVE = 7;
|
|
66
|
+
var PLAIN_ELEMENT = 0;
|
|
67
|
+
var LOCATOR_ATTRIBUTE = "data-hamur-src";
|
|
68
|
+
function appModuleId(rootDir, buildDir) {
|
|
69
|
+
let real = rootDir;
|
|
70
|
+
try {
|
|
71
|
+
real = realpathSync(rootDir);
|
|
72
|
+
} catch {}
|
|
73
|
+
const roots = [...new Set([rootDir, real])];
|
|
74
|
+
const build = relative(rootDir, buildDir);
|
|
75
|
+
const inBuild = (id) => build !== "" && !build.startsWith("..") && (id === build || id.startsWith(`${build}/`));
|
|
76
|
+
return (path) => {
|
|
77
|
+
if (path.includes("/node_modules/"))
|
|
78
|
+
return;
|
|
79
|
+
for (const root of roots) {
|
|
80
|
+
const id = relative(root, path);
|
|
81
|
+
if (!id.startsWith("..") && !id.startsWith("/"))
|
|
82
|
+
return inBuild(id) ? undefined : id;
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function locateRootElement(file, origin) {
|
|
88
|
+
return (node, { parent }) => {
|
|
89
|
+
if (node.type !== ELEMENT || node.tagType !== PLAIN_ELEMENT || !node.loc || parent?.type !== ROOT)
|
|
90
|
+
return;
|
|
91
|
+
const significant = (parent.children ?? []).filter((child) => {
|
|
92
|
+
const { type, content } = child;
|
|
93
|
+
return type === TEXT ? String(content).trim() !== "" : type === ELEMENT || type === 5;
|
|
94
|
+
});
|
|
95
|
+
if (significant.length !== 1 || significant[0] !== node)
|
|
96
|
+
return;
|
|
97
|
+
const { line, column } = node.loc.start;
|
|
98
|
+
const at = `${file}:${origin.line + line - 1}:${line === 1 ? origin.column + column - 1 : column}`;
|
|
99
|
+
const loc = node.loc;
|
|
100
|
+
(node.props ??= []).push({
|
|
101
|
+
type: ATTRIBUTE,
|
|
102
|
+
name: LOCATOR_ATTRIBUTE,
|
|
103
|
+
nameLoc: loc,
|
|
104
|
+
value: { type: TEXT, content: at, loc },
|
|
105
|
+
loc
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function devOnlyTags(script) {
|
|
110
|
+
const tags = new Set;
|
|
111
|
+
for (const found of script.matchAll(/import\s*\{([^}]*)\}\s*from\s*["']@hamur\/adapter-vue["']/g)) {
|
|
112
|
+
for (const part of found[1].split(",")) {
|
|
113
|
+
const [imported, local = imported] = part.trim().split(/\s+as\s+/).map((name) => name.trim());
|
|
114
|
+
if (imported !== "DevOnly" || !local)
|
|
115
|
+
continue;
|
|
116
|
+
tags.add(local);
|
|
117
|
+
tags.add(local.replace(/\B([A-Z])/g, "-$1").toLowerCase());
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return tags;
|
|
121
|
+
}
|
|
122
|
+
var isFallbackSlot = (child) => {
|
|
123
|
+
const node = child;
|
|
124
|
+
return node.type === ELEMENT && node.tag === "template" && (node.props ?? []).some((prop) => prop.type === DIRECTIVE && prop.name === "slot" && prop.arg?.content === "fallback");
|
|
125
|
+
};
|
|
126
|
+
function dropDevOnlyChildren(tags) {
|
|
127
|
+
return (node) => {
|
|
128
|
+
if (node.type !== ELEMENT || !node.tag || !tags.has(node.tag) || !node.children)
|
|
129
|
+
return;
|
|
130
|
+
node.children = node.children.filter(isFallbackSlot);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
var featureFlags = (dev) => ({
|
|
134
|
+
__VUE_OPTIONS_API__: "true",
|
|
135
|
+
__VUE_PROD_DEVTOOLS__: String(dev),
|
|
136
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false"
|
|
137
|
+
});
|
|
138
|
+
function vueFeatureFlags() {
|
|
139
|
+
return {
|
|
140
|
+
name: "hamur-vue-feature-flags",
|
|
141
|
+
filter: { id: /[\\/]node_modules[\\/](?:vue|@vue[\\/][^\\/]+)[\\/]dist[\\/][^\\/]*esm-bundler\.js$/ },
|
|
142
|
+
transform(code) {
|
|
143
|
+
let contents = code;
|
|
144
|
+
for (const [flag, value] of Object.entries(featureFlags(true)))
|
|
145
|
+
contents = contents.replaceAll(flag, value);
|
|
146
|
+
return contents === code ? undefined : contents;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function vuePlugin(ctx) {
|
|
151
|
+
const blocks = new Map;
|
|
152
|
+
const ssr = ctx.target === "server";
|
|
153
|
+
const appModule = ctx.dev ? appModuleId(ctx.rootDir, ctx.buildDir) : () => {
|
|
154
|
+
return;
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
name: `hamur-vue-${ctx.target}`,
|
|
158
|
+
setup(build) {
|
|
159
|
+
build.config.define = { ...featureFlags(ctx.dev), ...build.config.define };
|
|
160
|
+
if (ssr) {
|
|
161
|
+
const runtime = Bun.resolveSync("vue/dist/vue.runtime.esm-bundler.js", ctx.rootDir);
|
|
162
|
+
const serverRenderer = Bun.resolveSync("@vue/server-renderer/dist/server-renderer.esm-bundler.js", runtime);
|
|
163
|
+
build.onResolve({ filter: /^vue$/ }, () => ({ path: runtime }));
|
|
164
|
+
build.onResolve({ filter: /^vue\/server-renderer$/ }, () => ({ path: serverRenderer }));
|
|
165
|
+
}
|
|
166
|
+
build.onLoad({ filter: /\.vue$/, namespace: "file" }, async ({ path }) => {
|
|
167
|
+
const source = await Bun.file(path).text();
|
|
168
|
+
const { descriptor, errors } = parse(source, { filename: path });
|
|
169
|
+
if (errors.length > 0)
|
|
170
|
+
throw errors[0];
|
|
171
|
+
const scopeId = scopeIdOf(path);
|
|
172
|
+
const id = scopeId.slice("data-v-".length);
|
|
173
|
+
const scoped = descriptor.styles.some((style) => style.scoped);
|
|
174
|
+
const script = descriptor.script || descriptor.scriptSetup ? compileScript(descriptor, { id, isProd: !ctx.dev, genDefaultAs: "_sfc_main", sourceMap: true }) : { content: "const _sfc_main = {};", bindings: undefined, lang: undefined, map: undefined };
|
|
175
|
+
const parts = [
|
|
176
|
+
{ text: script.content, map: script.map }
|
|
177
|
+
];
|
|
178
|
+
const hot = ctx.hmr && !ssr;
|
|
179
|
+
let templateCode = "";
|
|
180
|
+
if (descriptor.template) {
|
|
181
|
+
const devOnly = ctx.dev ? new Set : devOnlyTags(`${descriptor.scriptSetup?.content ?? ""}
|
|
182
|
+
${descriptor.script?.content ?? ""}`);
|
|
183
|
+
const located = appModule(path);
|
|
184
|
+
const nodeTransforms = [
|
|
185
|
+
...devOnly.size ? [dropDevOnlyChildren(devOnly)] : [],
|
|
186
|
+
...located === undefined ? [] : [locateRootElement(located, descriptor.template.loc.start)]
|
|
187
|
+
];
|
|
188
|
+
const template = compileTemplate({
|
|
189
|
+
source: descriptor.template.content,
|
|
190
|
+
filename: path,
|
|
191
|
+
id: scopeId,
|
|
192
|
+
scoped,
|
|
193
|
+
ssr,
|
|
194
|
+
ssrCssVars: descriptor.cssVars,
|
|
195
|
+
compilerOptions: {
|
|
196
|
+
scopeId: scoped ? scopeId : undefined,
|
|
197
|
+
bindingMetadata: script.bindings,
|
|
198
|
+
sourceMap: true,
|
|
199
|
+
...nodeTransforms.length ? { nodeTransforms } : {}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
if (template.errors.length > 0)
|
|
203
|
+
throw template.errors[0];
|
|
204
|
+
templateCode = template.code;
|
|
205
|
+
const renderName = ssr ? "ssrRender" : "render";
|
|
206
|
+
const { start } = descriptor.template.loc;
|
|
207
|
+
parts.push({ text: template.code, map: template.map, sourceLine: start.line - 1, sourceColumn: start.column - 1 }, { text: `_sfc_main.${renderName} = ${renderName};` });
|
|
208
|
+
}
|
|
209
|
+
if (scoped)
|
|
210
|
+
parts.push({ text: `_sfc_main.__scopeId = ${JSON.stringify(scopeId)};` });
|
|
211
|
+
const cssModules = {};
|
|
212
|
+
for (const [index, style] of descriptor.styles.entries()) {
|
|
213
|
+
const lang = langOf(style);
|
|
214
|
+
if (!PLAIN_LANGS.includes(lang) && !(lang in PREPROCESSED))
|
|
215
|
+
throw new DiagnosticError("HAMUR_E4101", `<style lang="${lang}"> is not supported (${SUPPORTED_LANGS})`);
|
|
216
|
+
if (lang in PREPROCESSED && !ctx.preprocessStyle) {
|
|
217
|
+
throw new DiagnosticError("HAMUR_E4102", `<style lang="${lang}"> needs the @hamur/css module: install @hamur/css and ${PREPROCESSED[lang]} and add "@hamur/css" to modules`);
|
|
218
|
+
}
|
|
219
|
+
const block = {
|
|
220
|
+
style,
|
|
221
|
+
scopeId,
|
|
222
|
+
moduleId: moduleIdOf(path, index)
|
|
223
|
+
};
|
|
224
|
+
if (ssr && !style.module)
|
|
225
|
+
continue;
|
|
226
|
+
if (!ssr)
|
|
227
|
+
parts.unshift({ text: `import ${JSON.stringify(`${STYLE_NAMESPACE}:${path}.${index}.css`)};` });
|
|
228
|
+
if (ctx.dev && !ssr && !style.module)
|
|
229
|
+
continue;
|
|
230
|
+
const css = await compileBlock(path, block);
|
|
231
|
+
if (style.module)
|
|
232
|
+
cssModules[style.module === true ? "$style" : style.module] = css.modules ?? {};
|
|
233
|
+
if (ssr || ctx.dev)
|
|
234
|
+
continue;
|
|
235
|
+
block.first = css.code;
|
|
236
|
+
blocks.set(`${path}.${index}.css`, block);
|
|
237
|
+
}
|
|
238
|
+
if (Object.keys(cssModules).length > 0 || hot)
|
|
239
|
+
parts.push({ text: `_sfc_main.__cssModules = ${JSON.stringify(cssModules)};` });
|
|
240
|
+
if (hot) {
|
|
241
|
+
const hash = (text) => Bun.hash(text).toString(16);
|
|
242
|
+
const hashes = {
|
|
243
|
+
script: hash(`${descriptor.script?.content ?? ""}\x00${descriptor.scriptSetup?.content ?? ""}`),
|
|
244
|
+
template: hash(templateCode),
|
|
245
|
+
cssModules: hash(JSON.stringify(cssModules))
|
|
246
|
+
};
|
|
247
|
+
parts.push({ text: hmrFooter(id, hashes, descriptor.styles.length, `${SESSION}.${++compiles}`) });
|
|
248
|
+
}
|
|
249
|
+
parts.push({ text: "export default _sfc_main;" });
|
|
250
|
+
const pieces = [];
|
|
251
|
+
let line = 0;
|
|
252
|
+
for (const { text, map, sourceLine, sourceColumn } of parts) {
|
|
253
|
+
if (map)
|
|
254
|
+
pieces.push({ map, line, sourceLine, sourceColumn });
|
|
255
|
+
line += text.split(`
|
|
256
|
+
`).length;
|
|
257
|
+
}
|
|
258
|
+
let contents = parts.map(({ text }) => text).join(`
|
|
259
|
+
`);
|
|
260
|
+
if (pieces.length > 0) {
|
|
261
|
+
const inline = {
|
|
262
|
+
version: 3,
|
|
263
|
+
sources: [relative(ctx.rootDir, path).split("\\").join("/")],
|
|
264
|
+
sourcesContent: [source],
|
|
265
|
+
names: [],
|
|
266
|
+
mappings: mergeMappings(pieces)
|
|
267
|
+
};
|
|
268
|
+
contents += `
|
|
269
|
+
//# sourceMappingURL=data:application/json;base64,${Buffer.from(JSON.stringify(inline)).toString("base64")}`;
|
|
270
|
+
}
|
|
271
|
+
return { contents, loader: script.lang === "ts" || script.lang === "tsx" ? "ts" : "js" };
|
|
272
|
+
});
|
|
273
|
+
build.onResolve({ filter: new RegExp(`^${STYLE_NAMESPACE}:`) }, ({ path }) => ({
|
|
274
|
+
path: path.slice(STYLE_NAMESPACE.length + 1),
|
|
275
|
+
namespace: STYLE_NAMESPACE
|
|
276
|
+
}));
|
|
277
|
+
build.onLoad({ filter: /.*/, namespace: STYLE_NAMESPACE }, async ({ path }) => {
|
|
278
|
+
if (ctx.dev)
|
|
279
|
+
return { contents: await devBlock(path), loader: "css" };
|
|
280
|
+
const block = blocks.get(path);
|
|
281
|
+
const first = block?.first;
|
|
282
|
+
if (block)
|
|
283
|
+
block.first = undefined;
|
|
284
|
+
return {
|
|
285
|
+
contents: first ?? (block ? (await compileBlock(path.replace(/\.\d+\.css$/, ""), block)).code : ""),
|
|
286
|
+
loader: "css"
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
async function devBlock(path) {
|
|
292
|
+
const sfc = path.replace(/\.\d+\.css$/, "");
|
|
293
|
+
const index = Number(path.slice(sfc.length + 1, -".css".length));
|
|
294
|
+
const style = parse(await Bun.file(sfc).text().catch(() => ""), { filename: sfc }).descriptor.styles[index];
|
|
295
|
+
return style ? (await compileBlock(sfc, { style, scopeId: scopeIdOf(sfc), moduleId: moduleIdOf(sfc, index) })).code : "";
|
|
296
|
+
}
|
|
297
|
+
async function compileBlock(path, { style, scopeId, moduleId }) {
|
|
298
|
+
const lang = langOf(style);
|
|
299
|
+
const file = style.src ? resolveSrc(style.src, dirname(path)) : path;
|
|
300
|
+
let source = style.content;
|
|
301
|
+
if (style.src) {
|
|
302
|
+
source = await readFile(file, "utf8").catch(() => {
|
|
303
|
+
throw new DiagnosticError("HAMUR_E4103", `<style src="${style.src}"> was not found (looked for ${file})`);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
if (lang in PREPROCESSED)
|
|
307
|
+
source = (await ctx.preprocessStyle({ lang, code: source, file })).code;
|
|
308
|
+
const css = await compileStyleAsync({
|
|
309
|
+
source,
|
|
310
|
+
filename: path,
|
|
311
|
+
id: scopeId,
|
|
312
|
+
scoped: style.scoped,
|
|
313
|
+
isProd: !ctx.dev,
|
|
314
|
+
...style.module ? { modules: true, modulesOptions: { generateScopedName: (name) => `_${name}_${moduleId}` } } : {}
|
|
315
|
+
});
|
|
316
|
+
if (css.errors.length > 0)
|
|
317
|
+
throw css.errors[0];
|
|
318
|
+
return css;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
var CLIENT_RUNTIME = join(import.meta.dir + "/../../src", "runtime/client.ts");
|
|
322
|
+
var HYDRATION_DEV = join(import.meta.dir + "/../../src", "runtime/hydration-dev.ts");
|
|
323
|
+
function vueHydrationPlugin() {
|
|
324
|
+
return {
|
|
325
|
+
name: "hamur-vue-hydration",
|
|
326
|
+
filter: { id: new RegExp(`^${CLIENT_RUNTIME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`) },
|
|
327
|
+
transform: (code) => `import ${JSON.stringify(HYDRATION_DEV)}; ${code}`
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// packages/adapter-vue/src/svg.ts
|
|
332
|
+
import { svgCode } from "hamur/adapter";
|
|
333
|
+
function nodeCode(code, node) {
|
|
334
|
+
if (typeof node === "string" || Array.isArray(node))
|
|
335
|
+
return code.value(node);
|
|
336
|
+
return `h(${JSON.stringify(node.tag)}, ${code.props(code.attrs(node))}, [${node.children.map((child) => nodeCode(code, child)).join(", ")}])`;
|
|
337
|
+
}
|
|
338
|
+
function module(svg) {
|
|
339
|
+
const code = svgCode(svg, { title: "props.title", props: "attrs" });
|
|
340
|
+
const children = svg.children.map((child) => nodeCode(code, child));
|
|
341
|
+
const hidden = code.hidden ? `${code.hidden} ? { "aria-hidden": "true" } : {}` : "{}";
|
|
342
|
+
const contents = `import { defineComponent, h, useId } from "vue";
|
|
343
|
+
|
|
344
|
+
export default defineComponent({
|
|
345
|
+
name: "SvgComponent",
|
|
346
|
+
inheritAttrs: false,
|
|
347
|
+
props: { title: { type: String, default: undefined } },
|
|
348
|
+
setup(props, { attrs }) {
|
|
349
|
+
const uid = useId().replace(/[^\\w-]/g, "_");
|
|
350
|
+
return () =>
|
|
351
|
+
h("svg", { ...${code.props(svg.attrs)}, ...(${hidden}), ...attrs }, [...(props.title == null ? [] : [h("title", props.title)])${children.length ? `, ${children.join(", ")}` : ""}]);
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
`;
|
|
355
|
+
return { contents, extension: ".js" };
|
|
356
|
+
}
|
|
357
|
+
var svgComponent = { types: `import("vue").Component`, module };
|
|
358
|
+
|
|
359
|
+
// packages/adapter-vue/src/markdown-page.ts
|
|
360
|
+
import { markdownPageCode } from "hamur/adapter/build";
|
|
361
|
+
function module2(source) {
|
|
362
|
+
const { imports, value, props, head } = markdownPageCode(source);
|
|
363
|
+
const contents = `${imports}import { defineComponent, h } from "vue";
|
|
364
|
+
import { MarkdownRenderer, useHead } from "@hamur/adapter-vue";
|
|
365
|
+
|
|
366
|
+
const value = ${value};
|
|
367
|
+
|
|
368
|
+
export default defineComponent({
|
|
369
|
+
name: "MarkdownPage",
|
|
370
|
+
setup() {
|
|
371
|
+
${head ? ` useHead(${head});
|
|
372
|
+
` : ""} return () => h(MarkdownRenderer, ${props});
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
`;
|
|
376
|
+
return { contents, extension: ".js" };
|
|
377
|
+
}
|
|
378
|
+
var markdownComponent = { module: module2 };
|
|
379
|
+
|
|
380
|
+
// packages/adapter-vue/src/adapter.ts
|
|
381
|
+
var adapter_default = defineAdapter({
|
|
382
|
+
name: "vue",
|
|
383
|
+
contract: ADAPTER_CONTRACT,
|
|
384
|
+
extensions: [".vue"],
|
|
385
|
+
clientEntry: "@hamur/adapter-vue/runtime/client",
|
|
386
|
+
serverEntry: "@hamur/adapter-vue/runtime/server",
|
|
387
|
+
keepAliveOutlet: "@hamur/adapter-vue/runtime/keepalive",
|
|
388
|
+
islandEntry: "@hamur/adapter-vue/runtime/island",
|
|
389
|
+
plugins: (ctx) => [vuePlugin(ctx)],
|
|
390
|
+
transforms: (ctx) => ctx.dev ? [vueFeatureFlags(), ...ctx.target === "client" ? [vueHydrationPlugin()] : []] : [],
|
|
391
|
+
errorPage: "@hamur/adapter-vue/error-page",
|
|
392
|
+
peers: ["vue"],
|
|
393
|
+
stream: false,
|
|
394
|
+
trustedTypesPolicies: ["vue"],
|
|
395
|
+
svgComponent,
|
|
396
|
+
markdownComponent,
|
|
397
|
+
serverComponent: { module: (component) => serverComponentModule(component, "@hamur/adapter-vue/runtime") },
|
|
398
|
+
clientComponent: { module: (component) => clientComponentModule(component, "@hamur/adapter-vue/runtime") }
|
|
399
|
+
});
|
|
400
|
+
export {
|
|
401
|
+
adapter_default as default
|
|
402
|
+
};
|