@cos-design/wave-button 4.0.0 → 4.1.0

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,19 @@
1
+ /**
2
+ * Web Component attribute → Core options parsing (v4 Element adapters).
3
+ * Keeps behavior consistent across 91 components.
4
+ */
5
+ export type BooleanAttrMode =
6
+ /** `options.key = el.hasAttribute(attr)` — always written */
7
+ 'presence'
8
+ /** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
9
+ | 'optional-true'
10
+ /** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
11
+ | 'optional-undefined';
12
+ export declare const camelToKebabAttr: (name: string) => string;
13
+ export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
14
+ export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
15
+ export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
16
+ export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
17
+ /** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
18
+ export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
19
+ export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
9
9
  export { resolveCanvasBoxSize } from './canvas-box';
10
10
  export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
11
11
  export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
12
+ export type { BooleanAttrMode } from './element-options';
13
+ export { camelToKebabAttr, optionCallbackDispatcher, readBooleanAttr, readJsonAttr, readNumberAttr, readPropertyOverride, readStringAttr, } from './element-options';
@@ -1,18 +1,19 @@
1
+ import { readJsonAttr as e, readPropertyOverride as t, readStringAttr as n } from "@cos-design/shared";
1
2
  import './element.css';//#region src/components/waveButton/core/engine.ts
2
- var e = "cos-wave-button";
3
- function t(t, n = {}) {
4
- let r = {
3
+ var r = "cos-wave-button";
4
+ function i(e, t = {}) {
5
+ let n = {
5
6
  text: "点我试试",
6
7
  color: "#38bdf8",
7
- ...n
8
+ ...t
8
9
  }, i = document.createElement("div");
9
- i.className = e;
10
+ i.className = r;
10
11
  let a = document.createElement("button");
11
- a.type = "button", a.className = `${e}__btn`;
12
+ a.type = "button", a.className = `${r}__btn`;
12
13
  let o = document.createElement("span");
13
- o.className = `${e}__label`, a.append(Object.assign(document.createElement("span"), { className: `${e}__wave` }), Object.assign(document.createElement("span"), { className: `${e}__wave` }), o), i.appendChild(a), t.appendChild(i);
14
+ o.className = `${r}__label`, a.append(Object.assign(document.createElement("span"), { className: `${r}__wave` }), Object.assign(document.createElement("span"), { className: `${r}__wave` }), o), i.appendChild(a), e.appendChild(i);
14
15
  let s = () => {
15
- let e = r.buttonProps ?? {};
16
+ let e = n.buttonProps ?? {};
16
17
  for (let [t, n] of Object.entries(e)) if (!(t === "className" || t === "style" || t === "children")) {
17
18
  if (t.startsWith("on") && typeof n == "function") {
18
19
  let e = t.slice(2).toLowerCase(), r = `cosWave${t}`, i = a[r];
@@ -22,14 +23,14 @@ function t(t, n = {}) {
22
23
  n == null || n === !1 ? a.removeAttribute(t === "disabled" ? "disabled" : t) : n === !0 ? a.setAttribute(t, "") : a.setAttribute(t, String(n));
23
24
  }
24
25
  }, c = () => {
25
- o.textContent = r.text ?? "点我试试", a.style.setProperty("--wave-color", r.color ?? "#38bdf8"), a.className = `${e}__btn${r.className ? ` ${r.className}` : ""}`.trim(), r.style && Object.entries(r.style).forEach(([e, t]) => {
26
+ o.textContent = n.text ?? "点我试试", a.style.setProperty("--wave-color", n.color ?? "#38bdf8"), a.className = `${r}__btn${n.className ? ` ${n.className}` : ""}`.trim(), n.style && Object.entries(n.style).forEach(([e, t]) => {
26
27
  t != null && a.style.setProperty(e.replace(/([A-Z])/g, "-$1").toLowerCase(), String(t));
27
28
  }), s();
28
29
  };
29
30
  return c(), {
30
31
  update(e) {
31
- r = {
32
- ...r,
32
+ n = {
33
+ ...n,
33
34
  ...e
34
35
  }, c();
35
36
  },
@@ -41,23 +42,19 @@ function t(t, n = {}) {
41
42
  }
42
43
  //#endregion
43
44
  //#region src/components/waveButton/element/index.ts
44
- var n = "cos-wave-button";
45
- function r(e) {
46
- let t = {};
47
- if (e.hasAttribute("text") && (t.text = e.getAttribute("text") ?? void 0), e.hasAttribute("color") && (t.color = e.getAttribute("color") ?? void 0), e.hasAttribute("button-props")) try {
48
- t.buttonProps = JSON.parse(e.getAttribute("button-props") ?? "null");
49
- } catch {}
50
- let n = e._buttonProps;
51
- return n !== void 0 && (t.buttonProps = n), t;
45
+ var a = "cos-wave-button";
46
+ function o(r) {
47
+ let i = {};
48
+ return n(i, r, "text", "text"), n(i, r, "color", "color"), e(i, r, "buttonProps", "button-props"), t(i, r, "buttonProps", "_buttonProps"), i;
52
49
  }
53
- var i = class extends HTMLElement {
50
+ var s = class extends HTMLElement {
54
51
  ctrl = null;
55
52
  _buttonProps;
56
53
  get buttonProps() {
57
54
  return this._buttonProps;
58
55
  }
59
56
  set buttonProps(e) {
60
- this._buttonProps = e, this.ctrl?.update(r(this));
57
+ this._buttonProps = e, this.ctrl?.update(o(this));
61
58
  }
62
59
  static get observedAttributes() {
63
60
  return [
@@ -67,18 +64,18 @@ var i = class extends HTMLElement {
67
64
  ];
68
65
  }
69
66
  connectedCallback() {
70
- this.ctrl = t(this, r(this));
67
+ this.ctrl = i(this, o(this));
71
68
  }
72
69
  disconnectedCallback() {
73
70
  this.ctrl?.destroy(), this.ctrl = null;
74
71
  }
75
72
  attributeChangedCallback() {
76
- this.ctrl?.update(r(this));
73
+ this.ctrl?.update(o(this));
77
74
  }
78
75
  getButton() {
79
76
  return this.ctrl?.getButton();
80
77
  }
81
78
  };
82
- typeof customElements < "u" && !customElements.get("cos-wave-button") && customElements.define(n, i);
79
+ typeof customElements < "u" && !customElements.get("cos-wave-button") && customElements.define(a, s);
83
80
  //#endregion
84
- export { i as CosWaveButtonElement, n as TAG };
81
+ export { s as CosWaveButtonElement, a as TAG };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Web Component attribute → Core options parsing (v4 Element adapters).
3
+ * Keeps behavior consistent across 91 components.
4
+ */
5
+ export type BooleanAttrMode =
6
+ /** `options.key = el.hasAttribute(attr)` — always written */
7
+ 'presence'
8
+ /** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
9
+ | 'optional-true'
10
+ /** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
11
+ | 'optional-undefined';
12
+ export declare const camelToKebabAttr: (name: string) => string;
13
+ export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
14
+ export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
15
+ export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
16
+ export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
17
+ /** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
18
+ export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
19
+ export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
9
9
  export { resolveCanvasBoxSize } from './canvas-box';
10
10
  export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
11
11
  export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
12
+ export type { BooleanAttrMode } from './element-options';
13
+ export { camelToKebabAttr, optionCallbackDispatcher, readBooleanAttr, readJsonAttr, readNumberAttr, readPropertyOverride, readStringAttr, } from './element-options';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Web Component attribute → Core options parsing (v4 Element adapters).
3
+ * Keeps behavior consistent across 91 components.
4
+ */
5
+ export type BooleanAttrMode =
6
+ /** `options.key = el.hasAttribute(attr)` — always written */
7
+ 'presence'
8
+ /** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
9
+ | 'optional-true'
10
+ /** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
11
+ | 'optional-undefined';
12
+ export declare const camelToKebabAttr: (name: string) => string;
13
+ export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
14
+ export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
15
+ export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
16
+ export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
17
+ /** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
18
+ export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
19
+ export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
9
9
  export { resolveCanvasBoxSize } from './canvas-box';
10
10
  export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
11
11
  export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
12
+ export type { BooleanAttrMode } from './element-options';
13
+ export { camelToKebabAttr, optionCallbackDispatcher, readBooleanAttr, readJsonAttr, readNumberAttr, readPropertyOverride, readStringAttr, } from './element-options';
package/dist/vue/index.js CHANGED
@@ -1,18 +1,17 @@
1
1
  import { createElementBlock as e, defineComponent as t, onMounted as n, onUnmounted as r, openBlock as i, ref as a, watch as o } from "vue";
2
- import { optionsFingerprint as s } from "@cos-design/shared";
3
2
  import './vue.css';//#region src/components/waveButton/core/engine.ts
4
- var c = "cos-wave-button";
5
- function l(e, t = {}) {
3
+ var s = "cos-wave-button";
4
+ function c(e, t = {}) {
6
5
  let n = {
7
6
  text: "点我试试",
8
7
  color: "#38bdf8",
9
8
  ...t
10
9
  }, r = document.createElement("div");
11
- r.className = c;
10
+ r.className = s;
12
11
  let i = document.createElement("button");
13
- i.type = "button", i.className = `${c}__btn`;
12
+ i.type = "button", i.className = `${s}__btn`;
14
13
  let a = document.createElement("span");
15
- a.className = `${c}__label`, i.append(Object.assign(document.createElement("span"), { className: `${c}__wave` }), Object.assign(document.createElement("span"), { className: `${c}__wave` }), a), r.appendChild(i), e.appendChild(r);
14
+ a.className = `${s}__label`, i.append(Object.assign(document.createElement("span"), { className: `${s}__wave` }), Object.assign(document.createElement("span"), { className: `${s}__wave` }), a), r.appendChild(i), e.appendChild(r);
16
15
  let o = () => {
17
16
  let e = n.buttonProps ?? {};
18
17
  for (let [t, n] of Object.entries(e)) if (!(t === "className" || t === "style" || t === "children")) {
@@ -23,17 +22,17 @@ function l(e, t = {}) {
23
22
  }
24
23
  n == null || n === !1 ? i.removeAttribute(t === "disabled" ? "disabled" : t) : n === !0 ? i.setAttribute(t, "") : i.setAttribute(t, String(n));
25
24
  }
26
- }, s = () => {
27
- a.textContent = n.text ?? "点我试试", i.style.setProperty("--wave-color", n.color ?? "#38bdf8"), i.className = `${c}__btn${n.className ? ` ${n.className}` : ""}`.trim(), n.style && Object.entries(n.style).forEach(([e, t]) => {
25
+ }, c = () => {
26
+ a.textContent = n.text ?? "点我试试", i.style.setProperty("--wave-color", n.color ?? "#38bdf8"), i.className = `${s}__btn${n.className ? ` ${n.className}` : ""}`.trim(), n.style && Object.entries(n.style).forEach(([e, t]) => {
28
27
  t != null && i.style.setProperty(e.replace(/([A-Z])/g, "-$1").toLowerCase(), String(t));
29
28
  }), o();
30
29
  };
31
- return s(), {
30
+ return c(), {
32
31
  update(e) {
33
32
  n = {
34
33
  ...n,
35
34
  ...e
36
- }, s();
35
+ }, c();
37
36
  },
38
37
  getButton: () => i,
39
38
  destroy() {
@@ -43,7 +42,7 @@ function l(e, t = {}) {
43
42
  }
44
43
  //#endregion
45
44
  //#region src/components/waveButton/vue/WaveButton.vue
46
- var u = /* @__PURE__ */ t({
45
+ var l = /* @__PURE__ */ t({
47
46
  __name: "WaveButton",
48
47
  props: {
49
48
  text: {},
@@ -52,18 +51,18 @@ var u = /* @__PURE__ */ t({
52
51
  style: {},
53
52
  buttonProps: {}
54
53
  },
55
- setup(t, { expose: c, emit: u }) {
56
- let d = t, f = a(), p = null, m = () => ({ ...d });
54
+ setup(t, { expose: s, emit: l }) {
55
+ let u = t, d = a(), f = null, p = () => ({ ...u });
57
56
  return n(() => {
58
- f.value && (p = l(f.value, m()));
59
- }), o(() => s(d), () => p?.update(m())), r(() => {
60
- p?.destroy(), p = null;
61
- }), c({ getButton: () => p?.getButton() }), (t, n) => (i(), e("div", {
57
+ d.value && (f = c(d.value, p()));
58
+ }), o(() => ({ ...u }), () => f?.update(p()), { deep: !0 }), r(() => {
59
+ f?.destroy(), f = null;
60
+ }), s({ getButton: () => f?.getButton() }), (t, n) => (i(), e("div", {
62
61
  ref_key: "hostRef",
63
- ref: f,
62
+ ref: d,
64
63
  class: "cos-waveButton-host"
65
64
  }, null, 512));
66
65
  }
67
66
  });
68
67
  //#endregion
69
- export { u as WaveButton };
68
+ export { l as WaveButton };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Web Component attribute → Core options parsing (v4 Element adapters).
3
+ * Keeps behavior consistent across 91 components.
4
+ */
5
+ export type BooleanAttrMode =
6
+ /** `options.key = el.hasAttribute(attr)` — always written */
7
+ 'presence'
8
+ /** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
9
+ | 'optional-true'
10
+ /** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
11
+ | 'optional-undefined';
12
+ export declare const camelToKebabAttr: (name: string) => string;
13
+ export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
14
+ export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
15
+ export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
16
+ export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
17
+ /** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
18
+ export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
19
+ export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
@@ -9,3 +9,5 @@ export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from
9
9
  export { resolveCanvasBoxSize } from './canvas-box';
10
10
  export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
11
11
  export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
12
+ export type { BooleanAttrMode } from './element-options';
13
+ export { camelToKebabAttr, optionCallbackDispatcher, readBooleanAttr, readJsonAttr, readNumberAttr, readPropertyOverride, readStringAttr, } from './element-options';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cos-design/wave-button",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "WaveButton component from cos-design",
5
5
  "type": "module",
6
6
  "main": "./dist/react/index.cjs",
@@ -84,6 +84,6 @@
84
84
  }
85
85
  },
86
86
  "dependencies": {
87
- "@cos-design/shared": "4.0.0"
87
+ "@cos-design/shared": "4.1.0"
88
88
  }
89
- }
89
+ }