@zephyr_zz/zephyr-ui 0.0.19 → 0.0.20

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,7 +1,8 @@
1
1
  import { App } from 'vue';
2
2
  import { default as ZzButton } from './button';
3
3
  import { default as ZephyrEditor } from './editor';
4
- export { ZzButton, ZephyrEditor };
4
+ import { default as ZephyrWrapper } from './wrapper';
5
+ export { ZzButton, ZephyrEditor, ZephyrWrapper };
5
6
  declare const _default: {
6
7
  install(app: App): void;
7
8
  };
@@ -0,0 +1,37 @@
1
+ import { VNode } from 'vue';
2
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
3
+ is: {
4
+ type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
5
+ default: null;
6
+ };
7
+ show: {
8
+ type: BooleanConstructor;
9
+ default: boolean;
10
+ };
11
+ isProps: {
12
+ type: ObjectConstructor;
13
+ default: () => {};
14
+ };
15
+ }>, () => VNode<import('vue').RendererNode, import('vue').RendererElement, {
16
+ [key: string]: any;
17
+ }> | VNode<import('vue').RendererNode, import('vue').RendererElement, {
18
+ [key: string]: any;
19
+ }>[] | null | undefined, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
20
+ is: {
21
+ type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
22
+ default: null;
23
+ };
24
+ show: {
25
+ type: BooleanConstructor;
26
+ default: boolean;
27
+ };
28
+ isProps: {
29
+ type: ObjectConstructor;
30
+ default: () => {};
31
+ };
32
+ }>> & Readonly<{}>, {
33
+ is: string | Function | Record<string, any>;
34
+ show: boolean;
35
+ isProps: Record<string, any>;
36
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
37
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { default as ZephyrWrapper } from './index.vue';
2
+ export default ZephyrWrapper;
@@ -0,0 +1,41 @@
1
+ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<import('vue').ExtractPropTypes<{
2
+ is: {
3
+ type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
4
+ default: null;
5
+ };
6
+ show: {
7
+ type: BooleanConstructor;
8
+ default: boolean;
9
+ };
10
+ isProps: {
11
+ type: ObjectConstructor;
12
+ default: () => {};
13
+ };
14
+ }>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
15
+ is: {
16
+ type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
17
+ default: null;
18
+ };
19
+ show: {
20
+ type: BooleanConstructor;
21
+ default: boolean;
22
+ };
23
+ isProps: {
24
+ type: ObjectConstructor;
25
+ default: () => {};
26
+ };
27
+ }>> & Readonly<{}>, {
28
+ is: string | Function | Record<string, any>;
29
+ show: boolean;
30
+ isProps: Record<string, any>;
31
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {
32
+ wrapperRef: HTMLDivElement;
33
+ }, HTMLDivElement>, Partial<Record<string, (_: {}) => any>> & {
34
+ default?(_: {}): any;
35
+ }>;
36
+ export default _default;
37
+ type __VLS_WithTemplateSlots<T, S> = T & {
38
+ new (): {
39
+ $slots: S;
40
+ };
41
+ };
@@ -1,41 +1,41 @@
1
1
  import './index.css';
2
- import { defineComponent as d, createElementBlock as m, openBlock as p, normalizeClass as z, renderSlot as T, ref as L, onMounted as k, onUnmounted as w } from "vue";
3
- import * as l from "monaco-editor-core";
4
- import { shikiToMonaco as B } from "@shikijs/monaco";
5
- import { createHighlighter as E } from "shiki";
6
- const Z = {
2
+ import { defineComponent as v, createElementBlock as B, openBlock as C, normalizeClass as W, renderSlot as _, ref as $, onMounted as S, onUnmounted as Z, isVNode as O, h as j, nextTick as H, getCurrentScope as I, onScopeDispose as M, getCurrentInstance as R, computed as k, shallowRef as w, watch as L, toValue as V, createElementVNode as A, createCommentVNode as N, createVNode as D, unref as T, normalizeProps as G, guardReactiveProps as F, createSlots as U, renderList as q, withCtx as J } from "vue";
3
+ import * as p from "monaco-editor-core";
4
+ import { shikiToMonaco as Q } from "@shikijs/monaco";
5
+ import { createHighlighter as X } from "shiki";
6
+ const Y = {
7
7
  name: "ZzButton"
8
- }, C = /* @__PURE__ */ d({
9
- ...Z,
8
+ }, K = /* @__PURE__ */ v({
9
+ ...Y,
10
10
  props: {
11
11
  type: {
12
12
  type: String,
13
13
  default: "primary"
14
14
  }
15
15
  },
16
- setup(o) {
17
- return (e, i) => (p(), m("button", {
18
- class: z(["zz-button", `zz-button--${o.type}`])
16
+ setup(t) {
17
+ return (e, n) => (C(), B("button", {
18
+ class: W(["zz-button", `zz-button--${t.type}`])
19
19
  }, [
20
- T(e.$slots, "default", {}, void 0, !0)
20
+ _(e.$slots, "default", {}, void 0, !0)
21
21
  ], 2));
22
22
  }
23
- }), f = (o, e) => {
24
- const i = o.__vccOpts || o;
25
- for (const [r, s] of e)
26
- i[r] = s;
27
- return i;
28
- }, c = /* @__PURE__ */ f(C, [["__scopeId", "data-v-7c55743a"]]);
29
- c.install = (o) => {
30
- o.component("ZzButton", c);
23
+ }), E = (t, e) => {
24
+ const n = t.__vccOpts || t;
25
+ for (const [i, a] of e)
26
+ n[i] = a;
27
+ return n;
28
+ }, b = /* @__PURE__ */ E(K, [["__scopeId", "data-v-7c55743a"]]);
29
+ b.install = (t) => {
30
+ t.component("ZzButton", b);
31
31
  };
32
- class b {
32
+ class ee {
33
33
  highlighter = null;
34
34
  constructor() {
35
35
  }
36
36
  async init() {
37
37
  try {
38
- const e = await E({
38
+ const e = await X({
39
39
  themes: ["github-dark", "vitesse-dark"],
40
40
  // 示例
41
41
  langs: ["ts", "vue"]
@@ -59,29 +59,29 @@ class b {
59
59
  }
60
60
  // 注册语言
61
61
  registerLanguage(e) {
62
- return new Promise((i, r) => {
62
+ return new Promise((n, i) => {
63
63
  try {
64
- this.highlighter && !this.getLanguages().includes(e) && this.highlighter.loadLanguage(e), i(!0);
65
- } catch (s) {
66
- r(s);
64
+ this.highlighter && !this.getLanguages().includes(e) && this.highlighter.loadLanguage(e), n(!0);
65
+ } catch (a) {
66
+ i(a);
67
67
  }
68
68
  });
69
69
  }
70
70
  // 注册主题
71
71
  registerTheme(e) {
72
- return new Promise((i, r) => {
72
+ return new Promise((n, i) => {
73
73
  try {
74
- this.highlighter && !this.getThemes().includes(e) && this.highlighter.loadTheme(e), i(!0);
75
- } catch (s) {
76
- r(s);
74
+ this.highlighter && !this.getThemes().includes(e) && this.highlighter.loadTheme(e), n(!0);
75
+ } catch (a) {
76
+ i(a);
77
77
  }
78
78
  });
79
79
  }
80
80
  }
81
- const x = {
81
+ const te = {
82
82
  name: "ZephyrEditor"
83
- }, I = /* @__PURE__ */ d({
84
- ...x,
83
+ }, oe = /* @__PURE__ */ v({
84
+ ...te,
85
85
  props: {
86
86
  modelValue: {
87
87
  type: String,
@@ -93,69 +93,246 @@ const x = {
93
93
  }
94
94
  },
95
95
  emits: ["update:modelValue", "load"],
96
- setup(o, { expose: e, emit: i }) {
97
- const r = o, s = i;
98
- let n = null;
99
- const h = L(null);
100
- let a = null;
101
- const _ = (t, g) => {
102
- a && l.languages.registerCompletionItemProvider(t, g);
103
- }, y = (t) => {
104
- if (n)
105
- return n.registerTheme(t).then(() => {
106
- l.editor.setTheme(t);
107
- }).catch((g) => {
108
- console.error(g);
96
+ setup(t, { expose: e, emit: n }) {
97
+ const i = t, a = n;
98
+ let r = null;
99
+ const u = $(null);
100
+ let s = null;
101
+ const c = (o, h) => {
102
+ s && p.languages.registerCompletionItemProvider(o, h);
103
+ }, l = (o) => {
104
+ if (r)
105
+ return r.registerTheme(o).then(() => {
106
+ p.editor.setTheme(o);
107
+ }).catch((h) => {
108
+ console.error(h);
109
109
  });
110
- }, v = (t) => {
111
- if (n)
112
- return n.registerLanguage(t).then(() => {
113
- l.languages.register(t);
110
+ }, d = (o) => {
111
+ if (r)
112
+ return r.registerLanguage(o).then(() => {
113
+ p.languages.register(o);
114
114
  });
115
115
  };
116
- return k(async () => {
117
- if (h.value) {
118
- n = new b();
116
+ return S(async () => {
117
+ if (u.value) {
118
+ r = new ee();
119
119
  try {
120
- await n.init();
121
- const t = n.getHighlighter();
122
- if (!t) return;
123
- r.options?.language && (await n.registerLanguage(r.options?.language), l.languages.register({ id: r.options?.language })), r.options?.theme && (await n.registerTheme(r.options?.theme), l.editor.setTheme(r.options?.theme)), B(t, l), a = l.editor.create(h.value, {
124
- value: r.modelValue,
125
- ...r.options || {}
126
- }), a.onDidChangeModelContent(() => {
127
- s("update:modelValue", a?.getValue());
128
- }), s("load", { state: "success", editor: a, highlighter: n, highlighterInstance: t });
129
- } catch (t) {
130
- console.log("editor is init failed", t), s("load", { state: "error", error: t });
120
+ await r.init();
121
+ const o = r.getHighlighter();
122
+ if (!o) return;
123
+ i.options?.language && (await r.registerLanguage(i.options?.language), p.languages.register({ id: i.options?.language })), i.options?.theme && (await r.registerTheme(i.options?.theme), p.editor.setTheme(i.options?.theme)), Q(o, p), s = p.editor.create(u.value, {
124
+ value: i.modelValue,
125
+ ...i.options || {}
126
+ }), s.onDidChangeModelContent(() => {
127
+ a("update:modelValue", s?.getValue());
128
+ }), a("load", { state: "success", editor: s, highlighter: r, highlighterInstance: o });
129
+ } catch (o) {
130
+ console.log("editor is init failed", o), a("load", { state: "error", error: o });
131
131
  }
132
132
  }
133
- }), w(() => {
134
- a && a.dispose();
133
+ }), Z(() => {
134
+ s && s.dispose();
135
135
  }), e({
136
136
  // 注册提示词
137
- registerCompletionItemProvider: _,
137
+ registerCompletionItemProvider: c,
138
138
  // 注册/切换主题
139
- changeTheme: y,
139
+ changeTheme: l,
140
140
  // 注册语言
141
- registerLanguage: v
142
- }), (t, g) => (p(), m("div", {
141
+ registerLanguage: d
142
+ }), (o, h) => (C(), B("div", {
143
143
  class: "zephyr-editor_container",
144
144
  ref_key: "monacoEditorRef",
145
- ref: h
145
+ ref: u
146
146
  }, null, 512));
147
147
  }
148
- }), u = /* @__PURE__ */ f(I, [["__scopeId", "data-v-3ceef597"]]);
149
- u.install = (o) => {
150
- o.component("ZzButton", u);
148
+ }), z = /* @__PURE__ */ E(oe, [["__scopeId", "data-v-3ceef597"]]);
149
+ z.install = (t) => {
150
+ t.component("ZzButton", z);
151
151
  };
152
- const V = [c, u], M = {
153
- install(o) {
154
- V.forEach((e) => o.component(e.name || "ZzButton", e));
152
+ const ne = /* @__PURE__ */ v({
153
+ name: "wrapperHelper",
154
+ props: {
155
+ is: {
156
+ type: [String, Object, Function],
157
+ default: null
158
+ },
159
+ show: {
160
+ type: Boolean,
161
+ default: !0
162
+ },
163
+ isProps: {
164
+ type: Object,
165
+ default: () => ({})
166
+ }
167
+ },
168
+ setup(t, {
169
+ slots: e
170
+ }) {
171
+ return () => {
172
+ const {
173
+ is: n,
174
+ show: i,
175
+ isProps: a
176
+ } = t;
177
+ if (!i) return null;
178
+ if (!n) return e.default?.();
179
+ let r = null, u = {
180
+ ...a
181
+ }, s = {};
182
+ if (O(n))
183
+ r = n.type, u = {
184
+ ...n.props,
185
+ ...a
186
+ }, s = n.children || {};
187
+ else if (typeof n == "function") {
188
+ const l = n();
189
+ O(l) ? (r = l.type, u = {
190
+ ...l.props,
191
+ ...a
192
+ }, s = l.children || {}) : r = l;
193
+ } else (typeof n == "object" || typeof n == "string") && (r = n);
194
+ const c = {};
195
+ e.default && (c.default = () => e.default());
196
+ for (const l in e)
197
+ l !== "default" && (c[l] = () => e[l]());
198
+ return typeof s == "object" && Object.assign(c, s), j(r, u, c);
199
+ };
200
+ }
201
+ });
202
+ function re(t, e) {
203
+ return I() ? (M(t, e), !0) : !1;
204
+ }
205
+ const ie = typeof window < "u" && typeof document < "u";
206
+ typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
207
+ function se(t) {
208
+ return Array.isArray(t) ? t : [t];
209
+ }
210
+ function ae(t) {
211
+ return R();
212
+ }
213
+ function ue(t, e = !0, n) {
214
+ ae() ? S(t, n) : e ? t() : H(t);
215
+ }
216
+ const P = ie ? window : void 0;
217
+ function g(t) {
218
+ var e;
219
+ const n = V(t);
220
+ return (e = n?.$el) !== null && e !== void 0 ? e : n;
221
+ }
222
+ // @__NO_SIDE_EFFECTS__
223
+ function le() {
224
+ const t = w(!1), e = R();
225
+ return e && S(() => {
226
+ t.value = !0;
227
+ }, e), t;
228
+ }
229
+ // @__NO_SIDE_EFFECTS__
230
+ function ce(t) {
231
+ const e = /* @__PURE__ */ le();
232
+ return k(() => (e.value, !!t()));
233
+ }
234
+ function de(t, e, n = {}) {
235
+ const { window: i = P, ...a } = n;
236
+ let r;
237
+ const u = /* @__PURE__ */ ce(() => i && "ResizeObserver" in i), s = () => {
238
+ r && (r.disconnect(), r = void 0);
239
+ }, c = L(k(() => {
240
+ const d = V(t);
241
+ return Array.isArray(d) ? d.map((o) => g(o)) : [g(d)];
242
+ }), (d) => {
243
+ if (s(), u.value && i) {
244
+ r = new ResizeObserver(e);
245
+ for (const o of d) o && r.observe(o, a);
246
+ }
247
+ }, {
248
+ immediate: !0,
249
+ flush: "post"
250
+ }), l = () => {
251
+ s(), c();
252
+ };
253
+ return re(l), {
254
+ isSupported: u,
255
+ stop: l
256
+ };
257
+ }
258
+ function he(t, e = {
259
+ width: 0,
260
+ height: 0
261
+ }, n = {}) {
262
+ const { window: i = P, box: a = "content-box" } = n, r = k(() => {
263
+ var o;
264
+ return (o = g(t)) === null || o === void 0 || (o = o.namespaceURI) === null || o === void 0 ? void 0 : o.includes("svg");
265
+ }), u = w(e.width), s = w(e.height), { stop: c } = de(t, ([o]) => {
266
+ const h = a === "border-box" ? o.borderBoxSize : a === "content-box" ? o.contentBoxSize : o.devicePixelContentBoxSize;
267
+ if (i && r.value) {
268
+ const m = g(t);
269
+ if (m) {
270
+ const f = m.getBoundingClientRect();
271
+ u.value = f.width, s.value = f.height;
272
+ }
273
+ } else if (h) {
274
+ const m = se(h);
275
+ u.value = m.reduce((f, { inlineSize: y }) => f + y, 0), s.value = m.reduce((f, { blockSize: y }) => f + y, 0);
276
+ } else
277
+ u.value = o.contentRect.width, s.value = o.contentRect.height;
278
+ }, n);
279
+ ue(() => {
280
+ const o = g(t);
281
+ o && (u.value = "offsetWidth" in o ? o.offsetWidth : e.width, s.value = "offsetHeight" in o ? o.offsetHeight : e.height);
282
+ });
283
+ const l = L(() => g(t), (o) => {
284
+ u.value = o ? e.width : 0, s.value = o ? e.height : 0;
285
+ });
286
+ function d() {
287
+ c(), l();
288
+ }
289
+ return {
290
+ width: u,
291
+ height: s,
292
+ stop: d
293
+ };
294
+ }
295
+ const pe = { class: "zephyr-ui_wrapper" }, fe = {
296
+ name: "ZephyrWrapper"
297
+ }, x = /* @__PURE__ */ v({
298
+ ...fe,
299
+ props: {
300
+ is: { type: [String, Object, Function], default: null },
301
+ show: { type: Boolean, default: !0 },
302
+ isProps: { type: Object, default: () => ({}) }
303
+ },
304
+ setup(t) {
305
+ const e = t, n = $(), { height: i } = he(n);
306
+ return (a, r) => (C(), B("div", pe, [
307
+ A("div", {
308
+ class: "zephyr-wrapper_container",
309
+ ref_key: "wrapperRef",
310
+ ref: n
311
+ }, [
312
+ D(T(ne), G(F(e)), U({ _: 2 }, [
313
+ q(Object.keys(a.$slots), (u, s) => ({
314
+ name: u,
315
+ fn: J(() => [
316
+ _(a.$slots, u)
317
+ ])
318
+ }))
319
+ ]), 1040)
320
+ ], 512),
321
+ T(i) ? N("", !0) : _(a.$slots, "default", { key: 0 })
322
+ ]));
323
+ }
324
+ });
325
+ x.install = (t) => {
326
+ t.component("ZephyrWrapper", x);
327
+ };
328
+ const ge = [b, z, x], _e = {
329
+ install(t) {
330
+ ge.forEach((e) => t.component(e.name || "ZzButton", e));
155
331
  }
156
332
  };
157
333
  export {
158
- u as ZephyrEditor,
159
- c as ZzButton,
160
- M as default
334
+ z as ZephyrEditor,
335
+ x as ZephyrWrapper,
336
+ b as ZzButton,
337
+ _e as default
161
338
  };
@@ -1,2 +1,2 @@
1
- (function(a,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue"),require("monaco-editor-core"),require("@shikijs/monaco"),require("shiki")):typeof define=="function"&&define.amd?define(["exports","vue","monaco-editor-core","@shikijs/monaco","shiki"],n):(a=typeof globalThis<"u"?globalThis:a||self,n(a.ZephyrUI={},a.Vue,a.monaco,a.monaco$1,a.shiki))})(this,(function(a,n,_,y,z){"use strict";var p=document.createElement("style");p.textContent=`.zz-button[data-v-7c55743a]{padding:8px 16px;border:none;border-radius:4px;cursor:pointer;font-weight:500;transition:.2s}.zz-button--primary[data-v-7c55743a]{background:#409eff;color:#fff}.zz-button--success[data-v-7c55743a]{background:#67c23a;color:#fff}.zz-button--warning[data-v-7c55743a]{background:#e6a23c;color:#fff}.zz-button--danger[data-v-7c55743a]{background:#f56c6c;color:#fff}.zephyr-editor_container[data-v-3ceef597]{width:100%;height:100%}
2
- /*$vite$:1*/`,document.head.appendChild(p);function b(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const o=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,o.get?o:{enumerable:!0,get:()=>t[i]})}}return e.default=t,Object.freeze(e)}const u=b(_),k={name:"ZzButton"},v=n.defineComponent({...k,props:{type:{type:String,default:"primary"}},setup(t){return(e,i)=>(n.openBlock(),n.createElementBlock("button",{class:n.normalizeClass(["zz-button",`zz-button--${t.type}`])},[n.renderSlot(e.$slots,"default",{},void 0,!0)],2))}}),m=(t,e)=>{const i=t.__vccOpts||t;for(const[o,c]of e)i[o]=c;return i},h=m(v,[["__scopeId","data-v-7c55743a"]]);h.install=t=>{t.component("ZzButton",h)};class T{highlighter=null;constructor(){}async init(){try{const e=await z.createHighlighter({themes:["github-dark","vitesse-dark"],langs:["ts","vue"]});this.highlighter=e}catch(e){console.log("高亮器初始化失败",e)}}getHighlighter(){return this.highlighter}getLanguages(){return this.highlighter?.getLoadedLanguages()||[]}getThemes(){return this.highlighter?.getLoadedThemes()||[]}registerLanguage(e){return new Promise((i,o)=>{try{this.highlighter&&!this.getLanguages().includes(e)&&this.highlighter.loadLanguage(e),i(!0)}catch(c){o(c)}})}registerTheme(e){return new Promise((i,o)=>{try{this.highlighter&&!this.getThemes().includes(e)&&this.highlighter.loadTheme(e),i(!0)}catch(c){o(c)}})}}const w={name:"ZephyrEditor"},B=n.defineComponent({...w,props:{modelValue:{type:String,default:""},options:{type:Object,default:null}},emits:["update:modelValue","load"],setup(t,{expose:e,emit:i}){const o=t,c=i;let s=null;const f=n.ref(null);let l=null;const Z=(r,g)=>{l&&u.languages.registerCompletionItemProvider(r,g)},j=r=>{if(s)return s.registerTheme(r).then(()=>{u.editor.setTheme(r)}).catch(g=>{console.error(g)})},C=r=>{if(s)return s.registerLanguage(r).then(()=>{u.languages.register(r)})};return n.onMounted(async()=>{if(f.value){s=new T;try{await s.init();const r=s.getHighlighter();if(!r)return;o.options?.language&&(await s.registerLanguage(o.options?.language),u.languages.register({id:o.options?.language})),o.options?.theme&&(await s.registerTheme(o.options?.theme),u.editor.setTheme(o.options?.theme)),y.shikiToMonaco(r,u),l=u.editor.create(f.value,{value:o.modelValue,...o.options||{}}),l.onDidChangeModelContent(()=>{c("update:modelValue",l?.getValue())}),c("load",{state:"success",editor:l,highlighter:s,highlighterInstance:r})}catch(r){console.log("editor is init failed",r),c("load",{state:"error",error:r})}}}),n.onUnmounted(()=>{l&&l.dispose()}),e({registerCompletionItemProvider:Z,changeTheme:j,registerLanguage:C}),(r,g)=>(n.openBlock(),n.createElementBlock("div",{class:"zephyr-editor_container",ref_key:"monacoEditorRef",ref:f},null,512))}}),d=m(B,[["__scopeId","data-v-3ceef597"]]);d.install=t=>{t.component("ZzButton",d)};const E=[h,d],L={install(t){E.forEach(e=>t.component(e.name||"ZzButton",e))}};a.ZephyrEditor=d,a.ZzButton=h,a.default=L,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(u,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("monaco-editor-core"),require("@shikijs/monaco"),require("shiki")):typeof define=="function"&&define.amd?define(["exports","vue","monaco-editor-core","@shikijs/monaco","shiki"],e):(u=typeof globalThis<"u"?globalThis:u||self,e(u.ZephyrUI={},u.Vue,u.monaco,u.monaco$1,u.shiki))})(this,(function(u,e,O,T,j){"use strict";var C=document.createElement("style");C.textContent=`.zz-button[data-v-7c55743a]{padding:8px 16px;border:none;border-radius:4px;cursor:pointer;font-weight:500;transition:.2s}.zz-button--primary[data-v-7c55743a]{background:#409eff;color:#fff}.zz-button--success[data-v-7c55743a]{background:#67c23a;color:#fff}.zz-button--warning[data-v-7c55743a]{background:#e6a23c;color:#fff}.zz-button--danger[data-v-7c55743a]{background:#f56c6c;color:#fff}.zephyr-editor_container[data-v-3ceef597]{width:100%;height:100%}
2
+ /*$vite$:1*/`,document.head.appendChild(C);function x(o){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const r in o)if(r!=="default"){const i=Object.getOwnPropertyDescriptor(o,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:()=>o[r]})}}return t.default=o,Object.freeze(t)}const p=x(O),$={name:"ZzButton"},E=e.defineComponent({...$,props:{type:{type:String,default:"primary"}},setup(o){return(t,r)=>(e.openBlock(),e.createElementBlock("button",{class:e.normalizeClass(["zz-button",`zz-button--${o.type}`])},[e.renderSlot(t.$slots,"default",{},void 0,!0)],2))}}),S=(o,t)=>{const r=o.__vccOpts||o;for(const[i,c]of t)r[i]=c;return r},w=S(E,[["__scopeId","data-v-7c55743a"]]);w.install=o=>{o.component("ZzButton",w)};class R{highlighter=null;constructor(){}async init(){try{const t=await j.createHighlighter({themes:["github-dark","vitesse-dark"],langs:["ts","vue"]});this.highlighter=t}catch(t){console.log("高亮器初始化失败",t)}}getHighlighter(){return this.highlighter}getLanguages(){return this.highlighter?.getLoadedLanguages()||[]}getThemes(){return this.highlighter?.getLoadedThemes()||[]}registerLanguage(t){return new Promise((r,i)=>{try{this.highlighter&&!this.getLanguages().includes(t)&&this.highlighter.loadLanguage(t),r(!0)}catch(c){i(c)}})}registerTheme(t){return new Promise((r,i)=>{try{this.highlighter&&!this.getThemes().includes(t)&&this.highlighter.loadTheme(t),r(!0)}catch(c){i(c)}})}}const V={name:"ZephyrEditor"},v=e.defineComponent({...V,props:{modelValue:{type:String,default:""},options:{type:Object,default:null}},emits:["update:modelValue","load"],setup(o,{expose:t,emit:r}){const i=o,c=r;let s=null;const l=e.ref(null);let a=null;const f=(n,g)=>{a&&p.languages.registerCompletionItemProvider(n,g)},d=n=>{if(s)return s.registerTheme(n).then(()=>{p.editor.setTheme(n)}).catch(g=>{console.error(g)})},h=n=>{if(s)return s.registerLanguage(n).then(()=>{p.languages.register(n)})};return e.onMounted(async()=>{if(l.value){s=new R;try{await s.init();const n=s.getHighlighter();if(!n)return;i.options?.language&&(await s.registerLanguage(i.options?.language),p.languages.register({id:i.options?.language})),i.options?.theme&&(await s.registerTheme(i.options?.theme),p.editor.setTheme(i.options?.theme)),T.shikiToMonaco(n,p),a=p.editor.create(l.value,{value:i.modelValue,...i.options||{}}),a.onDidChangeModelContent(()=>{c("update:modelValue",a?.getValue())}),c("load",{state:"success",editor:a,highlighter:s,highlighterInstance:n})}catch(n){console.log("editor is init failed",n),c("load",{state:"error",error:n})}}}),e.onUnmounted(()=>{a&&a.dispose()}),t({registerCompletionItemProvider:f,changeTheme:d,registerLanguage:h}),(n,g)=>(e.openBlock(),e.createElementBlock("div",{class:"zephyr-editor_container",ref_key:"monacoEditorRef",ref:l},null,512))}}),b=S(v,[["__scopeId","data-v-3ceef597"]]);b.install=o=>{o.component("ZzButton",b)};const P=e.defineComponent({name:"wrapperHelper",props:{is:{type:[String,Object,Function],default:null},show:{type:Boolean,default:!0},isProps:{type:Object,default:()=>({})}},setup(o,{slots:t}){return()=>{const{is:r,show:i,isProps:c}=o;if(!i)return null;if(!r)return t.default?.();let s=null,l={...c},a={};if(e.isVNode(r))s=r.type,l={...r.props,...c},a=r.children||{};else if(typeof r=="function"){const d=r();e.isVNode(d)?(s=d.type,l={...d.props,...c},a=d.children||{}):s=d}else(typeof r=="object"||typeof r=="string")&&(s=r);const f={};t.default&&(f.default=()=>t.default());for(const d in t)d!=="default"&&(f[d]=()=>t[d]());return typeof a=="object"&&Object.assign(f,a),e.h(s,l,f)}}});function Z(o,t){return e.getCurrentScope()?(e.onScopeDispose(o,t),!0):!1}const L=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;function M(o){return Array.isArray(o)?o:[o]}function W(o){return e.getCurrentInstance()}function I(o,t=!0,r){W()?e.onMounted(o,r):t?o():e.nextTick(o)}const B=L?window:void 0;function m(o){var t;const r=e.toValue(o);return(t=r?.$el)!==null&&t!==void 0?t:r}function H(){const o=e.shallowRef(!1),t=e.getCurrentInstance();return t&&e.onMounted(()=>{o.value=!0},t),o}function N(o){const t=H();return e.computed(()=>(t.value,!!o()))}function A(o,t,r={}){const{window:i=B,...c}=r;let s;const l=N(()=>i&&"ResizeObserver"in i),a=()=>{s&&(s.disconnect(),s=void 0)},f=e.watch(e.computed(()=>{const h=e.toValue(o);return Array.isArray(h)?h.map(n=>m(n)):[m(h)]}),h=>{if(a(),l.value&&i){s=new ResizeObserver(t);for(const n of h)n&&s.observe(n,c)}},{immediate:!0,flush:"post"}),d=()=>{a(),f()};return Z(d),{isSupported:l,stop:d}}function D(o,t={width:0,height:0},r={}){const{window:i=B,box:c="content-box"}=r,s=e.computed(()=>{var n;return(n=m(o))===null||n===void 0||(n=n.namespaceURI)===null||n===void 0?void 0:n.includes("svg")}),l=e.shallowRef(t.width),a=e.shallowRef(t.height),{stop:f}=A(o,([n])=>{const g=c==="border-box"?n.borderBoxSize:c==="content-box"?n.contentBoxSize:n.devicePixelContentBoxSize;if(i&&s.value){const _=m(o);if(_){const y=_.getBoundingClientRect();l.value=y.width,a.value=y.height}}else if(g){const _=M(g);l.value=_.reduce((y,{inlineSize:k})=>y+k,0),a.value=_.reduce((y,{blockSize:k})=>y+k,0)}else l.value=n.contentRect.width,a.value=n.contentRect.height},r);I(()=>{const n=m(o);n&&(l.value="offsetWidth"in n?n.offsetWidth:t.width,a.value="offsetHeight"in n?n.offsetHeight:t.height)});const d=e.watch(()=>m(o),n=>{l.value=n?t.width:0,a.value=n?t.height:0});function h(){f(),d()}return{width:l,height:a,stop:h}}const q={class:"zephyr-ui_wrapper"},G={name:"ZephyrWrapper"},z=e.defineComponent({...G,props:{is:{type:[String,Object,Function],default:null},show:{type:Boolean,default:!0},isProps:{type:Object,default:()=>({})}},setup(o){const t=o,r=e.ref(),{height:i}=D(r);return(c,s)=>(e.openBlock(),e.createElementBlock("div",q,[e.createElementVNode("div",{class:"zephyr-wrapper_container",ref_key:"wrapperRef",ref:r},[e.createVNode(e.unref(P),e.normalizeProps(e.guardReactiveProps(t)),e.createSlots({_:2},[e.renderList(Object.keys(c.$slots),(l,a)=>({name:l,fn:e.withCtx(()=>[e.renderSlot(c.$slots,l)])}))]),1040)],512),e.unref(i)?e.createCommentVNode("",!0):e.renderSlot(c.$slots,"default",{key:0})]))}});z.install=o=>{o.component("ZephyrWrapper",z)};const U=[w,b,z],F={install(o){U.forEach(t=>o.component(t.name||"ZzButton",t))}};u.ZephyrEditor=b,u.ZephyrWrapper=z,u.ZzButton=w,u.default=F,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "types": "./dist/types/index.d.ts"
12
12
  }
13
13
  },
14
- "version": "0.0.19",
14
+ "version": "0.0.20",
15
15
  "type": "module",
16
16
  "scripts": {
17
17
  "dev": "vite",
@@ -20,13 +20,16 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@shikijs/monaco": "1.29.2",
23
+ "@vueuse/core": "^14.0.0",
23
24
  "monaco-editor-core": "0.52.2",
24
25
  "shiki": "1.29.2"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@types/node": "^24.6.0",
28
29
  "@vitejs/plugin-vue": "^6.0.1",
30
+ "@vitejs/plugin-vue-jsx": "^5.1.1",
29
31
  "@vue/tsconfig": "^0.8.1",
32
+ "element-plus": "^2.11.5",
30
33
  "sass": "^1.93.2",
31
34
  "sass-embedded": "^1.93.2",
32
35
  "typescript": "~5.9.3",