suncy-my-npm-test 1.0.46 → 1.0.48

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.
@@ -0,0 +1,193 @@
1
+ import { createApp as x, h as w, openBlock as m, createElementBlock as g, normalizeClass as E, createElementVNode as l, toDisplayString as f, renderSlot as h, createTextVNode as S, createCommentVNode as A, ref as k, computed as D } from "vue";
2
+ function N(o, { shadow: n = !0, styles: s = [] } = {}) {
3
+ const e = s.join("");
4
+ class i extends HTMLElement {
5
+ static observedAttributes = o.props ? Object.keys(o.props) : [];
6
+ constructor() {
7
+ super(), n && this.attachShadow({ mode: "open" }), this._app = null, this._props = {}, this._mounted = !1;
8
+ }
9
+ connectedCallback() {
10
+ this.mount();
11
+ }
12
+ disconnectedCallback() {
13
+ this.unmount();
14
+ }
15
+ attributeChangedCallback(t, a, r) {
16
+ a !== r && (this._props[t] = this.parseAttribute(t, r), this._mounted && this.updateProps());
17
+ }
18
+ // 解析属性值
19
+ parseAttribute(t, a) {
20
+ const r = o.props && o.props[t];
21
+ if (a != null) {
22
+ if (r) {
23
+ if (r === Boolean)
24
+ return a !== "false" && a !== null;
25
+ if (r === Number)
26
+ return Number(a);
27
+ if (r === Array || r === Object)
28
+ try {
29
+ return JSON.parse(a);
30
+ } catch {
31
+ return a;
32
+ }
33
+ }
34
+ return a;
35
+ }
36
+ }
37
+ // 序列化属性值
38
+ serializeAttribute(t) {
39
+ return t == null ? null : typeof t == "boolean" ? t ? "" : null : typeof t == "object" ? JSON.stringify(t) : String(t);
40
+ }
41
+ mount() {
42
+ if (this._mounted) return;
43
+ if (this._props = {}, o.props)
44
+ for (const r of Object.keys(o.props)) {
45
+ const d = this.getAttribute(r);
46
+ this._props[r] = this.parseAttribute(r, d);
47
+ }
48
+ const t = n ? this.shadowRoot : this;
49
+ if (e) {
50
+ const r = document.createElement("style");
51
+ r.textContent = e, t.appendChild(r);
52
+ }
53
+ const a = x({
54
+ ...o,
55
+ props: Object.keys(this._props),
56
+ setup(r, { attrs: d, slots: c, emit: L }) {
57
+ const v = (u, p) => {
58
+ this.dispatchEvent(
59
+ new CustomEvent(u, {
60
+ detail: p,
61
+ bubbles: !0,
62
+ composed: !0
63
+ })
64
+ );
65
+ }, y = (u, ...p) => {
66
+ const C = u.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
67
+ v(C, p[0]);
68
+ };
69
+ return o.setup ? o.setup(r, { attrs: d, slots: c, emit: y }) : {};
70
+ },
71
+ render() {
72
+ return w(o, this.$props);
73
+ }
74
+ });
75
+ a.mount(t), this._app = a, this._mounted = !0;
76
+ }
77
+ unmount() {
78
+ this._app && (this._app.unmount(), this._app = null), this._mounted = !1;
79
+ }
80
+ updateProps() {
81
+ this._app && this._app._instance && Object.assign(this._app._instance.props, this._props);
82
+ }
83
+ // 暴露一些方法供外部调用
84
+ get vueInstance() {
85
+ return this._app ? this._app._instance : null;
86
+ }
87
+ }
88
+ return i;
89
+ }
90
+ const O = ".hello-world[data-v-c907aa73]{padding:20px;border-radius:8px;font-family:Arial,sans-serif;transition:all .3s ease}.hello-world.light[data-v-c907aa73]{background-color:#fff;color:#333;border:1px solid #e0e0e0}.hello-world.dark[data-v-c907aa73]{background-color:#333;color:#fff;border:1px solid #555555}.hello-world h1[data-v-c907aa73]{margin:0 0 16px;color:#42b983}.content[data-v-c907aa73]{margin-bottom:16px;padding:12px;background-color:#0000000d;border-radius:4px}.dark .content[data-v-c907aa73]{background-color:#ffffff1a}button[data-v-c907aa73],input[data-v-c907aa73]{margin:8px 4px;padding:8px 16px;border:1px solid #ddd;border-radius:4px;font-size:14px}.dark button[data-v-c907aa73],.dark input[data-v-c907aa73]{background-color:#444;color:#fff;border-color:#666}button[data-v-c907aa73]{background-color:#42b983;color:#fff;border:none;cursor:pointer;transition:background-color .3s}button[data-v-c907aa73]:hover{background-color:#3aa876}.details[data-v-c907aa73]{margin-top:16px;padding:12px;background-color:#42b9831a;border-radius:4px}.actions[data-v-c907aa73]{margin-top:20px;padding-top:16px;border-top:1px solid #eee}.dark .actions[data-v-c907aa73]{border-top-color:#555}", j = (o, n) => {
91
+ const s = o.__vccOpts || o;
92
+ for (const [e, i] of n)
93
+ s[e] = i;
94
+ return s;
95
+ }, I = {
96
+ name: "HelloWorld",
97
+ // Web Components 的属性声明
98
+ props: {
99
+ msg: {
100
+ type: String,
101
+ default: "Hello World"
102
+ },
103
+ value: {
104
+ type: String,
105
+ default: ""
106
+ },
107
+ theme: {
108
+ type: String,
109
+ default: "light",
110
+ validator: (o) => ["light", "dark"].includes(o)
111
+ },
112
+ count: {
113
+ type: Number,
114
+ default: 0
115
+ }
116
+ },
117
+ // 自定义事件
118
+ emits: ["click", "input", "count-changed"],
119
+ setup(o, { emit: n }) {
120
+ const s = k(!1), e = k(o.count), i = D(() => `${o.msg} (${e.value})`);
121
+ return {
122
+ showDetails: s,
123
+ internalCount: e,
124
+ message: i,
125
+ handleClick: () => {
126
+ n("click", { message: "Button clicked!" });
127
+ },
128
+ handleInput: (c) => {
129
+ n("input", c.target.value);
130
+ },
131
+ increment: () => {
132
+ e.value++, n("count-changed", e.value);
133
+ },
134
+ decrement: () => {
135
+ e.value--, n("count-changed", e.value);
136
+ },
137
+ toggleDetails: () => {
138
+ s.value = !s.value;
139
+ }
140
+ };
141
+ }
142
+ }, H = { class: "content" }, W = ["value"], z = {
143
+ key: 0,
144
+ class: "details"
145
+ }, B = { class: "actions" };
146
+ function T(o, n, s, e, i, b) {
147
+ return m(), g("div", {
148
+ class: E(["hello-world", s.theme])
149
+ }, [
150
+ l("h1", null, f(s.msg), 1),
151
+ l("div", H, [
152
+ h(o.$slots, "default", {}, () => [
153
+ n[5] || (n[5] = S("Default Content", -1))
154
+ ], !0),
155
+ h(o.$slots, "footer", {}, void 0, !0)
156
+ ]),
157
+ l("button", {
158
+ onClick: n[0] || (n[0] = (...t) => e.handleClick && e.handleClick(...t))
159
+ }, "Click me"),
160
+ l("input", {
161
+ value: s.value,
162
+ onInput: n[1] || (n[1] = (...t) => e.handleInput && e.handleInput(...t)),
163
+ placeholder: "Type something..."
164
+ }, null, 40, W),
165
+ e.showDetails ? (m(), g("div", z, [
166
+ l("p", null, "Count: " + f(s.count), 1),
167
+ l("button", {
168
+ onClick: n[2] || (n[2] = (...t) => e.increment && e.increment(...t))
169
+ }, "+"),
170
+ l("button", {
171
+ onClick: n[3] || (n[3] = (...t) => e.decrement && e.decrement(...t))
172
+ }, "-")
173
+ ])) : A("", !0),
174
+ l("div", B, [
175
+ h(o.$slots, "actions", {}, () => [
176
+ l("button", {
177
+ onClick: n[4] || (n[4] = (...t) => e.toggleDetails && e.toggleDetails(...t))
178
+ }, f(e.showDetails ? "Hide" : "Show") + " Details", 1)
179
+ ], !0)
180
+ ])
181
+ ], 2);
182
+ }
183
+ const V = /* @__PURE__ */ j(I, [["render", T], ["styles", [O]], ["__scopeId", "data-v-c907aa73"]]), J = [], _ = N(V, {
184
+ shadow: !0,
185
+ styles: J
186
+ });
187
+ customElements.define("hello-world", _);
188
+ typeof window < "u" && (window.MyVueWebComponents = {
189
+ HelloWorldElement: _
190
+ });
191
+ export {
192
+ _ as HelloWorldElement
193
+ };
@@ -0,0 +1 @@
1
+ (function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i.MyVueWebComponents={},i.Vue))})(this,(function(i,t){"use strict";function b(n,{shadow:r=!0,styles:s=[]}={}){const o=s.join("");class d extends HTMLElement{static observedAttributes=n.props?Object.keys(n.props):[];constructor(){super(),r&&this.attachShadow({mode:"open"}),this._app=null,this._props={},this._mounted=!1}connectedCallback(){this.mount()}disconnectedCallback(){this.unmount()}attributeChangedCallback(e,l,a){l!==a&&(this._props[e]=this.parseAttribute(e,a),this._mounted&&this.updateProps())}parseAttribute(e,l){const a=n.props&&n.props[e];if(l!=null){if(a){if(a===Boolean)return l!=="false"&&l!==null;if(a===Number)return Number(l);if(a===Array||a===Object)try{return JSON.parse(l)}catch{return l}}return l}}serializeAttribute(e){return e==null?null:typeof e=="boolean"?e?"":null:typeof e=="object"?JSON.stringify(e):String(e)}mount(){if(this._mounted)return;if(this._props={},n.props)for(const a of Object.keys(n.props)){const c=this.getAttribute(a);this._props[a]=this.parseAttribute(a,c)}const e=r?this.shadowRoot:this;if(o){const a=document.createElement("style");a.textContent=o,e.appendChild(a)}const l=t.createApp({...n,props:Object.keys(this._props),setup(a,{attrs:c,slots:u,emit:W}){const w=(f,h)=>{this.dispatchEvent(new CustomEvent(f,{detail:h,bubbles:!0,composed:!0}))},N=(f,...h)=>{const V=f.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase();w(V,h[0])};return n.setup?n.setup(a,{attrs:c,slots:u,emit:N}):{}},render(){return t.h(n,this.$props)}});l.mount(e),this._app=l,this._mounted=!0}unmount(){this._app&&(this._app.unmount(),this._app=null),this._mounted=!1}updateProps(){this._app&&this._app._instance&&Object.assign(this._app._instance.props,this._props)}get vueInstance(){return this._app?this._app._instance:null}}return d}const g=".hello-world[data-v-c907aa73]{padding:20px;border-radius:8px;font-family:Arial,sans-serif;transition:all .3s ease}.hello-world.light[data-v-c907aa73]{background-color:#fff;color:#333;border:1px solid #e0e0e0}.hello-world.dark[data-v-c907aa73]{background-color:#333;color:#fff;border:1px solid #555555}.hello-world h1[data-v-c907aa73]{margin:0 0 16px;color:#42b983}.content[data-v-c907aa73]{margin-bottom:16px;padding:12px;background-color:#0000000d;border-radius:4px}.dark .content[data-v-c907aa73]{background-color:#ffffff1a}button[data-v-c907aa73],input[data-v-c907aa73]{margin:8px 4px;padding:8px 16px;border:1px solid #ddd;border-radius:4px;font-size:14px}.dark button[data-v-c907aa73],.dark input[data-v-c907aa73]{background-color:#444;color:#fff;border-color:#666}button[data-v-c907aa73]{background-color:#42b983;color:#fff;border:none;cursor:pointer;transition:background-color .3s}button[data-v-c907aa73]:hover{background-color:#3aa876}.details[data-v-c907aa73]{margin-top:16px;padding:12px;background-color:#42b9831a;border-radius:4px}.actions[data-v-c907aa73]{margin-top:20px;padding-top:16px;border-top:1px solid #eee}.dark .actions[data-v-c907aa73]{border-top-color:#555}",k=(n,r)=>{const s=n.__vccOpts||n;for(const[o,d]of r)s[o]=d;return s},y={name:"HelloWorld",props:{msg:{type:String,default:"Hello World"},value:{type:String,default:""},theme:{type:String,default:"light",validator:n=>["light","dark"].includes(n)},count:{type:Number,default:0}},emits:["click","input","count-changed"],setup(n,{emit:r}){const s=t.ref(!1),o=t.ref(n.count),d=t.computed(()=>`${n.msg} (${o.value})`);return{showDetails:s,internalCount:o,message:d,handleClick:()=>{r("click",{message:"Button clicked!"})},handleInput:u=>{r("input",u.target.value)},increment:()=>{o.value++,r("count-changed",o.value)},decrement:()=>{o.value--,r("count-changed",o.value)},toggleDetails:()=>{s.value=!s.value}}}},_={class:"content"},C=["value"],x={key:0,class:"details"},E={class:"actions"};function S(n,r,s,o,d,m){return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["hello-world",s.theme])},[t.createElementVNode("h1",null,t.toDisplayString(s.msg),1),t.createElementVNode("div",_,[t.renderSlot(n.$slots,"default",{},()=>[r[5]||(r[5]=t.createTextVNode("Default Content",-1))],!0),t.renderSlot(n.$slots,"footer",{},void 0,!0)]),t.createElementVNode("button",{onClick:r[0]||(r[0]=(...e)=>o.handleClick&&o.handleClick(...e))},"Click me"),t.createElementVNode("input",{value:s.value,onInput:r[1]||(r[1]=(...e)=>o.handleInput&&o.handleInput(...e)),placeholder:"Type something..."},null,40,C),o.showDetails?(t.openBlock(),t.createElementBlock("div",x,[t.createElementVNode("p",null,"Count: "+t.toDisplayString(s.count),1),t.createElementVNode("button",{onClick:r[2]||(r[2]=(...e)=>o.increment&&o.increment(...e))},"+"),t.createElementVNode("button",{onClick:r[3]||(r[3]=(...e)=>o.decrement&&o.decrement(...e))},"-")])):t.createCommentVNode("",!0),t.createElementVNode("div",E,[t.renderSlot(n.$slots,"actions",{},()=>[t.createElementVNode("button",{onClick:r[4]||(r[4]=(...e)=>o.toggleDetails&&o.toggleDetails(...e))},t.toDisplayString(o.showDetails?"Hide":"Show")+" Details",1)],!0)])],2)}const p=b(k(y,[["render",S],["styles",[g]],["__scopeId","data-v-c907aa73"]]),{shadow:!0,styles:[]});customElements.define("hello-world",p),typeof window<"u"&&(window.MyVueWebComponents={HelloWorldElement:p}),i.HelloWorldElement=p,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "suncy-my-npm-test",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/suncy-my-npm-test.umd.js",
7
7
  "module": "./dist/suncy-my-npm-test.es.js",
8
+ "unpkg": "./dist/my-vue-webcomponents.umd.js",
8
9
  "exports": {
9
10
  ".": {
10
11
  "import": "./dist/suncy-my-npm-test.es.js",
11
12
  "require": "./dist/suncy-my-npm-test.umd.js"
12
13
  },
13
- "./dist/style.css": "./dist/style.css"
14
+ "./dist/*": "./dist/*",
15
+ "./vue2": "./src/vue2-wrapper.js"
14
16
  },
15
17
  "files": [
16
- "dist"
18
+ "dist",
19
+ "src/vue2-wrapper.js"
17
20
  ],
18
21
  "types": "dist/index.d.ts",
19
22
  "peerDependencies": {
@@ -21,6 +24,7 @@
21
24
  },
22
25
  "scripts": {
23
26
  "dev": "vite",
27
+ "build:wc": "vite build --mode wc",
24
28
  "build": "run-p type-check \"build-only {@}\" --",
25
29
  "build:lib": "vite build --mode lib",
26
30
  "preview": "vite preview",
@@ -0,0 +1,29 @@
1
+ import Vue from 'vue'
2
+
3
+ // Vue 2 兼容性包装
4
+ export const Vue2Plugin = {
5
+ install(Vue, options) {
6
+ // 动态加载 Web Components
7
+ const script = document.createElement('script')
8
+ script.src = options.cdnUrl || './my-vue-webcomponents.umd.js'
9
+ document.head.appendChild(script)
10
+
11
+ // 组件加载完成后注册
12
+ script.onload = () => {
13
+ // 通过全局变量访问组件
14
+ if (window.MyWebComponents && window.MyWebComponents.register) {
15
+ window.MyWebComponents.register()
16
+ }
17
+ }
18
+
19
+ // 也可以提供 Vue 2 组件版本
20
+ // Vue.component('MyButton', {
21
+ // props: ['type'],
22
+ // template: `
23
+ // <my-button :type="type" @click="$emit('click')">
24
+ // <slot></slot>
25
+ // </my-button>
26
+ // `,
27
+ // })
28
+ },
29
+ }
@@ -1 +0,0 @@
1
- h1[data-v-6cb782b8]{font-weight:500;font-size:2.6rem;position:relative;top:-10px}h3[data-v-6cb782b8]{font-size:1.2rem}.greetings h1[data-v-6cb782b8],.greetings h3[data-v-6cb782b8]{text-align:center}@media(min-width:1024px){.greetings h1[data-v-6cb782b8],.greetings h3[data-v-6cb782b8]{text-align:left}}
@@ -1,45 +0,0 @@
1
- import { defineComponent as a, openBlock as c, createElementBlock as i, createElementVNode as o, toDisplayString as p, createTextVNode as n } from "vue";
2
- const d = { class: "greetings" }, _ = { class: "green" }, m = /* @__PURE__ */ a({
3
- __name: "HelloWorld",
4
- props: {
5
- msg: {}
6
- },
7
- setup(t) {
8
- return (r, e) => (c(), i("div", d, [
9
- o("h1", _, p(t.msg), 1),
10
- e[0] || (e[0] = o("h3", null, [
11
- n(" You’ve successfully created a project with "),
12
- o("a", {
13
- href: "https://vite.dev/",
14
- target: "_blank",
15
- rel: "noopener"
16
- }, "Vite"),
17
- n(" + "),
18
- o("a", {
19
- href: "https://vuejs.org/",
20
- target: "_blank",
21
- rel: "noopener"
22
- }, "Vue 3"),
23
- n(". What's next? ")
24
- ], -1)),
25
- e[1] || (e[1] = o("iframe", {
26
- src: "/static/index.html",
27
- width: "100%",
28
- height: "400px"
29
- }, null, -1))
30
- ]));
31
- }
32
- }), u = (t, r) => {
33
- const e = t.__vccOpts || t;
34
- for (const [s, l] of r)
35
- e[s] = l;
36
- return e;
37
- }, g = /* @__PURE__ */ u(m, [["__scopeId", "data-v-6cb782b8"]]), f = {
38
- install(t) {
39
- t.component("HelloWorld", g);
40
- }
41
- };
42
- export {
43
- g as HelloWorld,
44
- f as default
45
- };
@@ -1 +0,0 @@
1
- (function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.SuncyMyNpmTest={},t.Vue))})(this,(function(t,e){"use strict";const l={class:"greetings"},d={class:"green"},r=((n,s)=>{const o=n.__vccOpts||n;for(const[i,a]of s)o[i]=a;return o})(e.defineComponent({__name:"HelloWorld",props:{msg:{}},setup(n){return(s,o)=>(e.openBlock(),e.createElementBlock("div",l,[e.createElementVNode("h1",d,e.toDisplayString(n.msg),1),o[0]||(o[0]=e.createElementVNode("h3",null,[e.createTextVNode(" You’ve successfully created a project with "),e.createElementVNode("a",{href:"https://vite.dev/",target:"_blank",rel:"noopener"},"Vite"),e.createTextVNode(" + "),e.createElementVNode("a",{href:"https://vuejs.org/",target:"_blank",rel:"noopener"},"Vue 3"),e.createTextVNode(". What's next? ")],-1)),o[1]||(o[1]=e.createElementVNode("iframe",{src:"/static/index.html",width:"100%",height:"400px"},null,-1))]))}}),[["__scopeId","data-v-6cb782b8"]]),c={install(n){n.component("HelloWorld",r)}};t.HelloWorld=r,t.default=c,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));