@poveste/plugin-vue 0.2.1 → 0.3.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,70 +1,73 @@
1
- import { applyState as f } from "@poveste/shared";
2
- import { isRef as c, unref as p, watch as l } from "@poveste/vendors/vue";
3
- import { isRef as m, unref as w, watch as y } from "vue";
4
- const i = (n) => n !== null && typeof n == "object";
5
- function o(n, e = /* @__PURE__ */ new WeakMap()) {
6
- const t = m(n) ? w(n) : n;
7
- if (typeof t == "symbol")
8
- return t.toString();
9
- if (!i(t))
10
- return t;
11
- if (e.has(t))
12
- return e.get(t);
13
- if (Array.isArray(t)) {
14
- const r = [];
15
- return e.set(t, r), r.push(...t.map((u) => o(u, e))), r;
16
- } else {
17
- const r = {};
18
- return e.set(t, r), h(t, r, e), r;
19
- }
1
+ import { isRef as e, unref as t, watch as n } from "@poveste/vendors/vue";
2
+ import { isRef as r, unref as i, watch as a } from "vue";
3
+ import { applyState as o } from "@poveste/shared";
4
+ //#region src/client/app/util.ts
5
+ var s = (e) => typeof e == "object" && !!e;
6
+ function c(e, t = /* @__PURE__ */ new WeakMap()) {
7
+ let n = r(e) ? i(e) : e;
8
+ if (typeof n == "symbol") return n.toString();
9
+ if (!s(n)) return n;
10
+ if (t.has(n)) return t.get(n);
11
+ if (Array.isArray(n)) {
12
+ let e = [];
13
+ return t.set(n, e), e.push(...n.map((e) => c(e, t))), e;
14
+ }
15
+ {
16
+ let e = {};
17
+ return t.set(n, e), l(n, e, t), e;
18
+ }
20
19
  }
21
- function h(n, e, t = /* @__PURE__ */ new WeakMap()) {
22
- Object.keys(n).forEach((r) => {
23
- e[r] = o(n[r], t);
24
- });
20
+ function l(e, t, n = /* @__PURE__ */ new WeakMap()) {
21
+ Object.keys(e).forEach((r) => {
22
+ t[r] = c(e[r], n);
23
+ });
25
24
  }
26
- function a(n, e = /* @__PURE__ */ new WeakMap()) {
27
- const t = c(n) ? p(n) : n;
28
- if (typeof t == "symbol")
29
- return t.toString();
30
- if (!i(t))
31
- return t;
32
- if (e.has(t))
33
- return e.get(t);
34
- if (Array.isArray(t)) {
35
- const r = [];
36
- return e.set(t, r), r.push(...t.map((u) => a(u, e))), r;
37
- } else {
38
- const r = {};
39
- return e.set(t, r), d(t, r, e), r;
40
- }
25
+ function u(n, r = /* @__PURE__ */ new WeakMap()) {
26
+ let i = e(n) ? t(n) : n;
27
+ if (typeof i == "symbol") return i.toString();
28
+ if (!s(i)) return i;
29
+ if (r.has(i)) return r.get(i);
30
+ if (Array.isArray(i)) {
31
+ let e = [];
32
+ return r.set(i, e), e.push(...i.map((e) => u(e, r))), e;
33
+ }
34
+ {
35
+ let e = {};
36
+ return r.set(i, e), d(i, e, r), e;
37
+ }
41
38
  }
42
- function d(n, e, t = /* @__PURE__ */ new WeakMap()) {
43
- Object.keys(n).forEach((r) => {
44
- e[r] = o(n[r], t);
45
- });
39
+ function d(e, t, n = /* @__PURE__ */ new WeakMap()) {
40
+ Object.keys(e).forEach((r) => {
41
+ t[r] = c(e[r], n);
42
+ });
46
43
  }
47
- function A(n, e) {
48
- let t = !1;
49
- const r = l(() => n, (s) => {
50
- s != null && (t ? t = !1 : (t = !0, f(e, a(s))));
51
- }, {
52
- deep: !0,
53
- immediate: !0
54
- }), u = y(() => e, (s) => {
55
- s != null && (t ? t = !1 : (t = !0, f(n, o(s))));
56
- }, {
57
- deep: !0,
58
- immediate: !0
59
- });
60
- return {
61
- stop() {
62
- r(), u();
63
- }
64
- };
44
+ function f(e, t) {
45
+ let r = !1, i = n(() => e, (e) => {
46
+ if (e != null) {
47
+ if (r) {
48
+ r = !1;
49
+ return;
50
+ }
51
+ r = o(t, u(e));
52
+ }
53
+ }, {
54
+ deep: !0,
55
+ immediate: !0
56
+ }), s = a(() => t, (t) => {
57
+ if (t != null) {
58
+ if (r) {
59
+ r = !1;
60
+ return;
61
+ }
62
+ r = o(e, c(t));
63
+ }
64
+ }, {
65
+ deep: !0,
66
+ immediate: !0
67
+ });
68
+ return { stop() {
69
+ i(), s();
70
+ } };
65
71
  }
66
- export {
67
- a as _toRawDeep,
68
- A as syncStateBundledAndExternal,
69
- o as toRawDeep
70
- };
72
+ //#endregion
73
+ export { u as _toRawDeep, f as syncStateBundledAndExternal, c as toRawDeep };
@@ -1,10 +1,5 @@
1
+ import { generateSourceCode as e, getTagName as t } from "./codegen.js";
2
+ import n from "./app/MountStory.js";
3
+ import r from "./app/RenderStory.js";
1
4
  import "./app/index.js";
2
- import { generateSourceCode as o, getTagName as a } from "./codegen.js";
3
- import { default as m } from "./app/MountStory.js";
4
- import { default as d } from "./app/RenderStory.js";
5
- export {
6
- m as MountStory,
7
- d as RenderStory,
8
- o as generateSourceCode,
9
- a as getTagName
10
- };
5
+ export { n as MountStory, r as RenderStory, e as generateSourceCode, t as getTagName };
@@ -1,196 +1,149 @@
1
- import { createAutoBuildingObject as K, indent as _, voidElements as N, serializeJs as P } from "@poveste/shared";
2
- import { camelCase as M, pascalCase as U } from "change-case";
3
- import { Text as W, vModelText as z, vModelSelect as D, vModelRadio as F, vModelCheckbox as E, vModelDynamic as J } from "vue";
4
- async function I(t) {
5
- const o = t.slots().default?.({ state: t.state ?? {} }) ?? [], a = Array.isArray(o) ? o : [o], b = [];
6
- for (const L in a) {
7
- const g = a[L];
8
- b.push(...(await x(g, t.state?._hPropState?.[L])).lines);
9
- }
10
- return b.join(`
11
- `);
1
+ import { Text as e, vModelCheckbox as t, vModelDynamic as n, vModelRadio as r, vModelSelect as i, vModelText as a } from "vue";
2
+ import { createAutoBuildingObject as o, indent as s, serializeJs as c, voidElements as l } from "@poveste/shared";
3
+ import { camelCase as u, pascalCase as d } from "change-case";
4
+ //#region src/client/codegen.ts
5
+ async function f(e) {
6
+ let t = e.slots().default?.({ state: e.state ?? {} }) ?? [], n = Array.isArray(t) ? t : [t], r = [];
7
+ for (let t in n) {
8
+ let i = n[t];
9
+ r.push(...(await p(i, e.state?._hPropState?.[t])).lines);
10
+ }
11
+ return r.join("\n");
12
12
  }
13
- async function x(t, o = null) {
14
- if (t.type === W)
15
- return {
16
- // @ts-expect-error TODO
17
- lines: [t.children],
18
- isText: !0
19
- };
20
- const a = [];
21
- if (typeof t.type == "object" || typeof t.type == "string") {
22
- let g = function(e, s, i = null) {
23
- let n = "";
24
- for (const y in s.modifiers)
25
- s.modifiers[y] && (n += `.${y}`);
26
- let u = "";
27
- s.arg && (u = `:${s.arg}`), i && (i = i.replace(/^\$(setup|props|data)\./g, ""));
28
- const r = i ? [i] : V(s.value), l = [], f = `v-${e}${u}${n}="`;
29
- r.length > 1 ? (l.push(`${f}${r[0]}`), l.push(...r.slice(1, r.length - 1)), l.push(`${r[r.length - 1]}"`), $ = !0) : l.push(`${f}${r[0] ?? ""}"`), p.push(l);
30
- }, S = function(e, s) {
31
- if (typeof s != "string" || t.dynamicProps?.includes(e)) {
32
- let i = ":";
33
- e.startsWith("on") && (i = "@");
34
- const n = i === "@" ? `${e[2].toLowerCase()}${e.slice(3)}` : e, r = [`onUpdate:${e}`, `onUpdate:${M(e)}`].find((f) => t.dynamicProps?.includes(f) || t.props && f in t.props);
35
- if (i === ":" && r) {
36
- m.push(r);
37
- const y = t.props[r].toString();
38
- let C;
39
- const w = /\(\$event\) => (.*?) = \$event/.exec(y);
40
- w && (C = w[1]);
41
- const T = `${e === "modelValue" ? "model" : e}Modifiers`, B = t.props[T] ?? {};
42
- m.push(T), g("model", {
43
- arg: e === "modelValue" ? null : e,
44
- modifiers: B,
45
- value: s
46
- }, C);
47
- return;
48
- }
49
- if (typeof s > "u")
50
- return;
51
- let l;
52
- if (typeof s == "string" && s.startsWith("{{") && s.endsWith("}}"))
53
- l = A(s.substring(2, s.length - 2).trim()).split(`
54
- `);
55
- else if (typeof s == "function") {
56
- let f = A(s.toString().replace(/'/g, "\\'").replace(/"/g, "'"));
57
- const y = /function (\S+)\(/.exec(f);
58
- y ? l = [y[1]] : (f.startsWith("($event) => ") && (f = f.substring(12)), l = f.split(`
59
- `));
60
- } else
61
- l = V(s);
62
- if (l.length > 1) {
63
- $ = !0;
64
- const f = [`${i}${n}="${l[0]}`];
65
- f.push(...l.slice(1, l.length - 1)), f.push(`${l[l.length - 1]}"`), p.push(f);
66
- } else
67
- p.push([`${i}${n}="${l[0]}"`]);
68
- } else t.type?.props?.[e]?.type === Boolean ? p.push([e]) : p.push([`${e}="${s}"`]);
69
- };
70
- var b = g, L = S;
71
- t.type?.__asyncLoader && !t.type.__asyncResolved && await t.type.__asyncLoader();
72
- const p = [];
73
- let $ = !1;
74
- const m = [
75
- "key"
76
- ];
77
- if (t.dirs) {
78
- for (const e of t.dirs)
79
- if (e.dir === z || e.dir === D || e.dir === F || e.dir === E || e.dir === J) {
80
- const i = [`onUpdate:${e.arg ?? "modelValue"}`, `onUpdate:${M(e.arg ?? "modelValue")}`].find((r) => t.props[r]), n = t.props[i];
81
- let u = null;
82
- if (n) {
83
- m.push(i);
84
- const r = n.toString(), l = /\(\$event\) => (.*?) = \$event/.exec(r);
85
- l && (u = l[1]);
86
- }
87
- g("model", e, u);
88
- } else if (e.instance._ || e.instance.$) {
89
- const s = e.instance.$ ?? e.instance._;
90
- let i;
91
- for (const n of [s.directives, s.appContext.directives]) {
92
- for (const u in n)
93
- if (n[u] === e.dir) {
94
- i = u;
95
- break;
96
- }
97
- if (i) break;
98
- }
99
- if (!i) {
100
- for (const n in s.setupState)
101
- if (s.setupState[n] === e.dir) {
102
- i = n.replace(/^v(\w)/, (u, r) => r.toLowerCase());
103
- break;
104
- }
105
- }
106
- i && g(i, e);
107
- }
108
- }
109
- for (const e in t.props) {
110
- if (m.includes(e) || o && e in o)
111
- continue;
112
- const s = t.props[e];
113
- S(e, s);
114
- }
115
- if (o)
116
- for (const e in o)
117
- S(e, o[e]);
118
- p.length > 1 && ($ = !0);
119
- const d = O(t);
120
- let j = !1;
121
- const c = [];
122
- if (typeof t.children == "string")
123
- d === "pre" ? c.push(t.children) : c.push(...t.children.split(`
124
- `)), j = !0;
125
- else if (Array.isArray(t.children)) {
126
- let e;
127
- for (const s of t.children) {
128
- const i = await x(s);
129
- if (i.isText) {
130
- e === void 0 && (e = !0);
131
- const n = i.lines[0];
132
- !c.length || /^\s/.test(n) ? c.push(n.trim()) : c[c.length - 1] += n;
133
- } else
134
- e === void 0 && (e = !1), c.push(...i.lines);
135
- }
136
- e !== void 0 && (j = e);
137
- }
138
- if (t.children && typeof t.children == "object" && !Array.isArray(t.children)) {
139
- for (const e in t.children)
140
- if (typeof t.children[e] == "function") {
141
- const s = K((r) => `{{ ${r} }}`, (r, l) => {
142
- if (l === "__v_isRef")
143
- return () => !1;
144
- }), i = t.children[e](s.proxy), n = [];
145
- for (const r of i)
146
- n.push(...(await x(r)).lines);
147
- const u = Object.keys(s.cache);
148
- u.length ? (c.push(`<template #${e}="{ ${u.join(", ")} }">`), c.push(..._(n)), c.push("</template>")) : e === "default" ? c.push(...n) : (c.push(`<template #${e}>`), c.push(..._(n)), c.push("</template>"));
149
- }
150
- }
151
- const h = [`<${d}`];
152
- if ($) {
153
- for (const e of p)
154
- h.push(..._(e));
155
- c.length > 0 && h.push(">");
156
- } else
157
- p.length === 1 && (h[0] += ` ${p[0]}`), c.length > 0 && (h[0] += ">");
158
- const k = N.includes(d.toLowerCase());
159
- c.length > 0 ? c.length === 1 && h.length === 1 && !p.length && j ? a.push(`${h[0]}${c[0]}</${d}>`) : (a.push(...h), a.push(..._(c)), a.push(`</${d}>`)) : h.length > 1 ? (a.push(...h), a.push(k ? ">" : "/>")) : a.push(`${h[0]}${k ? "" : " /"}>`);
160
- } else if (t?.shapeFlag & 16)
161
- for (const g of t.children)
162
- a.push(...(await x(g)).lines);
163
- return {
164
- lines: a
165
- };
13
+ async function p(c, d = null) {
14
+ if (c.type === e) return {
15
+ lines: [c.children],
16
+ isText: !0
17
+ };
18
+ let f = [];
19
+ if (typeof c.type == "object" || typeof c.type == "string") {
20
+ c.type?.__asyncLoader && !c.type.__asyncResolved && await c.type.__asyncLoader();
21
+ let e = [], h = !1, v = ["key"];
22
+ function y(t, n, r = null) {
23
+ let i = "";
24
+ for (let e in n.modifiers) n.modifiers[e] && (i += `.${e}`);
25
+ let a = "";
26
+ n.arg && (a = `:${n.arg}`), r &&= r.replace(/^\$(?:setup|props|data)\./g, "");
27
+ let o = r ? [r] : g(n.value), s = [], c = `v-${t}${a}${i}="`;
28
+ o.length > 1 ? (s.push(`${c}${o[0]}`), s.push(...o.slice(1, o.length - 1)), s.push(`${o[o.length - 1]}"`), h = !0) : s.push(`${c}${o[0] ?? ""}"`), e.push(s);
29
+ }
30
+ if (c.dirs) {
31
+ for (let e of c.dirs) if (e.dir === a || e.dir === i || e.dir === r || e.dir === t || e.dir === n) {
32
+ let t = [`onUpdate:${e.arg ?? "modelValue"}`, `onUpdate:${u(e.arg ?? "modelValue")}`].find((e) => c.props[e]), n = c.props[t], r = null;
33
+ if (n) {
34
+ v.push(t);
35
+ let e = n.toString(), i = /\(\$event\) => (.*?) = \$event/.exec(e);
36
+ i && (r = i[1]);
37
+ }
38
+ y("model", e, r);
39
+ } else if (e.instance._ || e.instance.$) {
40
+ let t = e.instance.$ ?? e.instance._, n;
41
+ for (let r of [t.directives, t.appContext.directives]) {
42
+ for (let t in r) if (r[t] === e.dir) {
43
+ n = t;
44
+ break;
45
+ }
46
+ if (n) break;
47
+ }
48
+ if (!n) {
49
+ for (let r in t.setupState) if (t.setupState[r] === e.dir) {
50
+ n = r.replace(/^v(\w)/, (e, t) => t.toLowerCase());
51
+ break;
52
+ }
53
+ }
54
+ n && y(n, e);
55
+ }
56
+ }
57
+ function b(t, n) {
58
+ if (typeof n != "string" || c.dynamicProps?.includes(t)) {
59
+ let r = ":";
60
+ t.startsWith("on") && (r = "@");
61
+ let i = r === "@" ? `${t[2].toLowerCase()}${t.slice(3)}` : t, a = [`onUpdate:${t}`, `onUpdate:${u(t)}`].find((e) => c.dynamicProps?.includes(e) || c.props && e in c.props);
62
+ if (r === ":" && a) {
63
+ v.push(a);
64
+ let e = c.props[a].toString(), r, i = /\(\$event\) => (.*?) = \$event/.exec(e);
65
+ i && (r = i[1]);
66
+ let o = `${t === "modelValue" ? "model" : t}Modifiers`, s = c.props[o] ?? {};
67
+ v.push(o), y("model", {
68
+ arg: t === "modelValue" ? null : t,
69
+ modifiers: s,
70
+ value: n
71
+ }, r);
72
+ return;
73
+ }
74
+ if (n === void 0) return;
75
+ let o;
76
+ if (typeof n == "string" && n.startsWith("{{") && n.endsWith("}}")) o = _(n.substring(2, n.length - 2).trim()).split("\n");
77
+ else if (typeof n == "function") {
78
+ let e = _(n.toString().replace(/'/g, "\\'").replace(/"/g, "'")), t = /function (\S+)\(/.exec(e);
79
+ t ? o = [t[1]] : (e.startsWith("($event) => ") && (e = e.substring(12)), o = e.split("\n"));
80
+ } else o = g(n);
81
+ if (o.length > 1) {
82
+ h = !0;
83
+ let t = [`${r}${i}="${o[0]}`];
84
+ t.push(...o.slice(1, o.length - 1)), t.push(`${o[o.length - 1]}"`), e.push(t);
85
+ } else e.push([`${r}${i}="${o[0]}"`]);
86
+ } else c.type?.props?.[t]?.type === Boolean ? e.push([t]) : e.push([`${t}="${n}"`]);
87
+ }
88
+ for (let e in c.props) {
89
+ if (v.includes(e) || d && e in d) continue;
90
+ let t = c.props[e];
91
+ b(e, t);
92
+ }
93
+ if (d) for (let e in d) b(e, d[e]);
94
+ e.length > 1 && (h = !0);
95
+ let x = m(c), S = !1, C = [];
96
+ if (typeof c.children == "string") x === "pre" ? C.push(c.children) : C.push(...c.children.split("\n")), S = !0;
97
+ else if (Array.isArray(c.children)) {
98
+ let e;
99
+ for (let t of c.children) {
100
+ let n = await p(t);
101
+ if (n.isText) {
102
+ e === void 0 && (e = !0);
103
+ let t = n.lines[0];
104
+ !C.length || /^\s/.test(t) ? C.push(t.trim()) : C[C.length - 1] += t;
105
+ } else e === void 0 && (e = !1), C.push(...n.lines);
106
+ }
107
+ e !== void 0 && (S = e);
108
+ }
109
+ if (c.children && typeof c.children == "object" && !Array.isArray(c.children)) {
110
+ for (let e in c.children) if (typeof c.children[e] == "function") {
111
+ let t = o((e) => `{{ ${e} }}`, (e, t) => {
112
+ if (t === "__v_isRef") return () => !1;
113
+ }), n = c.children[e](t.proxy), r = [];
114
+ for (let e of n) r.push(...(await p(e)).lines);
115
+ let i = Object.keys(t.cache);
116
+ i.length ? (C.push(`<template #${e}="{ ${i.join(", ")} }">`), C.push(...s(r)), C.push("</template>")) : e === "default" ? C.push(...r) : (C.push(`<template #${e}>`), C.push(...s(r)), C.push("</template>"));
117
+ }
118
+ }
119
+ let w = [`<${x}`];
120
+ if (h) {
121
+ for (let t of e) w.push(...s(t));
122
+ C.length > 0 && w.push(">");
123
+ } else e.length === 1 && (w[0] += ` ${e[0]}`), C.length > 0 && (w[0] += ">");
124
+ let T = l.includes(x.toLowerCase());
125
+ C.length > 0 ? C.length === 1 && w.length === 1 && !e.length && S ? f.push(`${w[0]}${C[0]}</${x}>`) : (f.push(...w), f.push(...s(C)), f.push(`</${x}>`)) : w.length > 1 ? (f.push(...w), f.push(T ? ">" : "/>")) : f.push(`${w[0]}${T ? "" : " /"}>`);
126
+ } else if (c?.shapeFlag & 16) for (let e of c.children) f.push(...(await p(e)).lines);
127
+ return { lines: f };
166
128
  }
167
- function O(t) {
168
- if (typeof t.type == "string")
169
- return t.type;
170
- if (t.type?.__asyncResolved) {
171
- const o = t.type?.__asyncResolved;
172
- return o.name ?? R(o.__file);
173
- } else {
174
- if (t.type?.name)
175
- return t.type.name;
176
- if (t.type?.__file)
177
- return R(t.type.__file);
178
- }
179
- return "Anonymous";
129
+ function m(e) {
130
+ if (typeof e.type == "string") return e.type;
131
+ if (e.type?.__asyncResolved) {
132
+ let t = e.type?.__asyncResolved;
133
+ return t.name ?? h(t.__file);
134
+ }
135
+ return e.type?.name ? e.type.name : e.type?.__file ? h(e.type.__file) : "Anonymous";
180
136
  }
181
- function R(t) {
182
- const o = /([^/]+)\.vue$/.exec(t);
183
- return o ? U(o[1]) : "Anonymous";
137
+ function h(e) {
138
+ let t = /([^/]+)\.vue$/.exec(e);
139
+ return t ? d(t[1]) : "Anonymous";
184
140
  }
185
- function V(t) {
186
- const o = !!t?.__autoBuildingObject, a = P(t);
187
- return o ? [A(a.__autoBuildingObjectGetKey)] : A(a).split(`
188
- `);
141
+ function g(e) {
142
+ let t = !!e?.__autoBuildingObject, n = c(e);
143
+ return t ? [_(n.__autoBuildingObjectGetKey)] : _(n).split("\n");
189
144
  }
190
- function A(t) {
191
- return t.replace(/\$setup\./g, "");
145
+ function _(e) {
146
+ return e.replace(/\$setup\./g, "");
192
147
  }
193
- export {
194
- I as generateSourceCode,
195
- O as getTagName
196
- };
148
+ //#endregion
149
+ export { f as generateSourceCode, m as getTagName };