@primate/vue 0.16.0 → 0.16.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.
@@ -1,4 +1,8 @@
1
1
  declare const _default: {
2
+ client(text: string): {
3
+ js: string;
4
+ css: string;
5
+ };
2
6
  server(text: string): string;
3
7
  };
4
8
  export default _default;
@@ -1,51 +1,61 @@
1
1
  import presets from "@primate/core/build/presets";
2
2
  import transform from "@primate/core/build/transform";
3
- import { compileScript, compileTemplate, parse, } from "vue/compiler-sfc";
3
+ import { compileScript, compileStyle, compileTemplate, parse, } from "vue/compiler-sfc";
4
4
  const genDefaultAs = "__SCRIPT__";
5
5
  const id_size = 8;
6
6
  const analyze = ({ script, scriptSetup }) => {
7
7
  return {
8
8
  has_script: script !== null || scriptSetup !== null,
9
9
  inline: scriptSetup !== null,
10
- is_typescript: script?.lang === "ts" || scriptSetup?.lang === "ts",
10
+ is_ts: script?.lang === "ts" || scriptSetup?.lang === "ts",
11
11
  };
12
12
  };
13
+ const compile_sfc = (text) => {
14
+ const id = crypto.randomUUID().slice(0, id_size);
15
+ const { descriptor } = parse(text);
16
+ const { has_script, inline, is_ts } = analyze(descriptor);
17
+ let module;
18
+ if (inline) {
19
+ const script = compileScript(descriptor, {
20
+ genDefaultAs,
21
+ id,
22
+ inlineTemplate: true,
23
+ });
24
+ module = `
25
+ ${script.content}
26
+ export default { ...__SCRIPT__ };
27
+ `;
28
+ }
29
+ else {
30
+ const template = compileTemplate({
31
+ filename: "",
32
+ id,
33
+ source: descriptor.template?.content ?? "",
34
+ });
35
+ const script = has_script
36
+ ? compileScript(descriptor, { genDefaultAs, id, inlineTemplate: false })
37
+ : { content: `const ${genDefaultAs} = {}` };
38
+ module = `
39
+ ${template.code}
40
+ ${script.content}
41
+ export default { ...__SCRIPT__, render };
42
+ `;
43
+ }
44
+ const js = is_ts ? transform(module, presets.typescript).code : module;
45
+ const css = descriptor.styles.map(style => compileStyle({
46
+ filename: "",
47
+ id,
48
+ source: style.content,
49
+ scoped: style.scoped ?? false,
50
+ }).code).join("\n");
51
+ return { js, css };
52
+ };
13
53
  export default {
54
+ client(text) {
55
+ return compile_sfc(text);
56
+ },
14
57
  server(text) {
15
- const id = crypto.randomUUID().slice(0, id_size);
16
- const { descriptor } = parse(text);
17
- const { has_script, inline, is_typescript } = analyze(descriptor);
18
- let module;
19
- if (inline) {
20
- // for <script setup>, compile with inlineTemplate to get both script and
21
- // render
22
- const script = compileScript(descriptor, {
23
- genDefaultAs,
24
- id,
25
- inlineTemplate: true,
26
- });
27
- module = `
28
- ${script.content}
29
- export default { ...__SCRIPT__ };
30
- `;
31
- }
32
- else {
33
- // For regular components, compile template and script separately
34
- const template = compileTemplate({
35
- filename: "",
36
- id,
37
- source: descriptor.template?.content ?? "",
38
- });
39
- const script = has_script
40
- ? compileScript(descriptor, { genDefaultAs, id, inlineTemplate: false })
41
- : { content: `const ${genDefaultAs} = {}` };
42
- module = `
43
- ${template.code}
44
- ${script.content}
45
- export default { ...__SCRIPT__, render };
46
- `;
47
- }
48
- return is_typescript ? transform(module, presets.typescript).code : module;
58
+ return compile_sfc(text).js;
49
59
  },
50
60
  };
51
61
  //# sourceMappingURL=compile.js.map
@@ -7,8 +7,11 @@ export default frontend({
7
7
  root: {
8
8
  create: create_root,
9
9
  },
10
+ css: {
11
+ filter: /\.vuecss$/,
12
+ },
10
13
  compile: {
11
- client: (text, _, root) => ({ js: root ? text : compile.server(text) }),
14
+ client: (text, _, root) => root ? { js: text, css: "" } : compile.client(text),
12
15
  server: (text, file) => file.path.startsWith("root:") ? text : compile.server(text),
13
16
  },
14
17
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/vue",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Vue for Primate",
5
5
  "homepage": "https://primate.run/docs/frontend/vue",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",