@cos-design/spotlight 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.
- package/dist/core/packages/shared/src/element-options.d.ts +19 -0
- package/dist/core/packages/shared/src/index.d.ts +2 -0
- package/dist/element/index.js +32 -35
- package/dist/element/packages/shared/src/element-options.d.ts +19 -0
- package/dist/element/packages/shared/src/index.d.ts +2 -0
- package/dist/react/packages/shared/src/element-options.d.ts +19 -0
- package/dist/react/packages/shared/src/index.d.ts +2 -0
- package/dist/vue/index.js +22 -29
- package/dist/vue/packages/shared/src/element-options.d.ts +19 -0
- package/dist/vue/packages/shared/src/index.d.ts +2 -0
- package/package.json +3 -3
|
@@ -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/element/index.js
CHANGED
|
@@ -1,87 +1,84 @@
|
|
|
1
|
+
import { readJsonAttr as e, readNumberAttr as t, readPropertyOverride as n, readStringAttr as r } from "@cos-design/shared";
|
|
1
2
|
import './element.css';//#region src/components/spotlight/core/engine.ts
|
|
2
|
-
var
|
|
3
|
-
function
|
|
4
|
-
let
|
|
3
|
+
var i = "cos-spotlight";
|
|
4
|
+
function a(e, t = {}) {
|
|
5
|
+
let n = {
|
|
5
6
|
radius: 120,
|
|
6
7
|
dimColor: "rgba(0, 0, 0, 0.85)",
|
|
7
8
|
defaultContent: "隐藏内容",
|
|
8
|
-
...
|
|
9
|
-
},
|
|
10
|
-
|
|
9
|
+
...t
|
|
10
|
+
}, r = document.createElement("div");
|
|
11
|
+
r.className = i;
|
|
11
12
|
let a = document.createElement("div");
|
|
12
|
-
a.className = `${
|
|
13
|
+
a.className = `${i}__content`;
|
|
13
14
|
let o = document.createElement("div");
|
|
14
|
-
o.className = `${
|
|
15
|
+
o.className = `${i}__overlay`, r.append(a, o), e.appendChild(r);
|
|
15
16
|
let s = (e) => {
|
|
16
|
-
let t =
|
|
17
|
-
|
|
17
|
+
let t = r.getBoundingClientRect();
|
|
18
|
+
r.style.setProperty("--spot-x", `${e.clientX - t.left}px`), r.style.setProperty("--spot-y", `${e.clientY - t.top}px`);
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
r.addEventListener("mousemove", s);
|
|
20
21
|
let c = () => {
|
|
21
|
-
if (
|
|
22
|
-
|
|
22
|
+
if (n.slotElement) {
|
|
23
|
+
n.slotElement.parentElement !== a && (a.replaceChildren(), a.appendChild(n.slotElement));
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
|
-
if (a.childNodes.length > 0 ||
|
|
26
|
+
if (a.childNodes.length > 0 || n.defaultContent == null) return;
|
|
26
27
|
let e = document.createElement("span");
|
|
27
|
-
e.className = `${
|
|
28
|
+
e.className = `${r.className}__placeholder`, e.textContent = n.defaultContent, a.replaceChildren(e);
|
|
28
29
|
}, l = () => {
|
|
29
|
-
|
|
30
|
+
r.style.setProperty("--spot-radius", `${n.radius ?? 120}px`), r.style.setProperty("--dim-color", n.dimColor ?? "rgba(0, 0, 0, 0.85)"), c();
|
|
30
31
|
};
|
|
31
32
|
return l(), {
|
|
32
33
|
update(e) {
|
|
33
|
-
|
|
34
|
-
...
|
|
34
|
+
n = {
|
|
35
|
+
...n,
|
|
35
36
|
...e
|
|
36
37
|
}, l();
|
|
37
38
|
},
|
|
38
39
|
getSlot: () => a,
|
|
39
40
|
destroy() {
|
|
40
|
-
|
|
41
|
+
r.removeEventListener("mousemove", s), r.remove();
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
//#endregion
|
|
45
46
|
//#region src/components/spotlight/element/index.ts
|
|
46
|
-
var
|
|
47
|
-
function
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
t.slotElement = JSON.parse(e.getAttribute("slot-element") ?? "null");
|
|
51
|
-
} catch {}
|
|
52
|
-
let n = e._slotElement;
|
|
53
|
-
return n !== void 0 && (t.slotElement = n), t;
|
|
47
|
+
var o = "cos-spotlight";
|
|
48
|
+
function s(i) {
|
|
49
|
+
let a = {};
|
|
50
|
+
return r(a, i, "dimColor", "dim-color"), r(a, i, "defaultContent", "default-content"), t(a, i, "radius", "radius"), e(a, i, "slotElement", "slot-element"), n(a, i, "slotElement", "_slotElement"), a;
|
|
54
51
|
}
|
|
55
|
-
var
|
|
52
|
+
var c = class extends HTMLElement {
|
|
56
53
|
ctrl = null;
|
|
57
54
|
_slotElement;
|
|
58
55
|
get slotElement() {
|
|
59
56
|
return this._slotElement;
|
|
60
57
|
}
|
|
61
58
|
set slotElement(e) {
|
|
62
|
-
this._slotElement = e, this.ctrl?.update(
|
|
59
|
+
this._slotElement = e, this.ctrl?.update(s(this));
|
|
63
60
|
}
|
|
64
61
|
static get observedAttributes() {
|
|
65
62
|
return [
|
|
66
63
|
"radius",
|
|
67
64
|
"dim-color",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
65
|
+
"default-content",
|
|
66
|
+
"slot-element"
|
|
70
67
|
];
|
|
71
68
|
}
|
|
72
69
|
connectedCallback() {
|
|
73
|
-
this.ctrl =
|
|
70
|
+
this.ctrl = a(this, s(this));
|
|
74
71
|
}
|
|
75
72
|
disconnectedCallback() {
|
|
76
73
|
this.ctrl?.destroy(), this.ctrl = null;
|
|
77
74
|
}
|
|
78
75
|
attributeChangedCallback() {
|
|
79
|
-
this.ctrl?.update(
|
|
76
|
+
this.ctrl?.update(s(this));
|
|
80
77
|
}
|
|
81
78
|
getSlot() {
|
|
82
79
|
return this.ctrl?.getSlot();
|
|
83
80
|
}
|
|
84
81
|
};
|
|
85
|
-
typeof customElements < "u" && !customElements.get("cos-spotlight") && customElements.define(
|
|
82
|
+
typeof customElements < "u" && !customElements.get("cos-spotlight") && customElements.define(o, c);
|
|
86
83
|
//#endregion
|
|
87
|
-
export {
|
|
84
|
+
export { c as CosSpotlightElement, o 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,25 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { optionsFingerprint as p } from "@cos-design/shared";
|
|
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";
|
|
3
2
|
import './vue.css';//#region src/components/spotlight/core/engine.ts
|
|
4
|
-
var
|
|
5
|
-
function
|
|
3
|
+
var s = "cos-spotlight";
|
|
4
|
+
function c(e, t = {}) {
|
|
6
5
|
let n = {
|
|
7
6
|
radius: 120,
|
|
8
7
|
dimColor: "rgba(0, 0, 0, 0.85)",
|
|
9
8
|
defaultContent: "隐藏内容",
|
|
10
9
|
...t
|
|
11
10
|
}, r = document.createElement("div");
|
|
12
|
-
r.className =
|
|
11
|
+
r.className = s;
|
|
13
12
|
let i = document.createElement("div");
|
|
14
|
-
i.className = `${
|
|
13
|
+
i.className = `${s}__content`;
|
|
15
14
|
let a = document.createElement("div");
|
|
16
|
-
a.className = `${
|
|
15
|
+
a.className = `${s}__overlay`, r.append(i, a), e.appendChild(r);
|
|
17
16
|
let o = (e) => {
|
|
18
17
|
let t = r.getBoundingClientRect();
|
|
19
18
|
r.style.setProperty("--spot-x", `${e.clientX - t.left}px`), r.style.setProperty("--spot-y", `${e.clientY - t.top}px`);
|
|
20
19
|
};
|
|
21
20
|
r.addEventListener("mousemove", o);
|
|
22
|
-
let
|
|
21
|
+
let c = () => {
|
|
23
22
|
if (n.slotElement) {
|
|
24
23
|
n.slotElement.parentElement !== i && (i.replaceChildren(), i.appendChild(n.slotElement));
|
|
25
24
|
return;
|
|
@@ -27,15 +26,15 @@ function h(e, t = {}) {
|
|
|
27
26
|
if (i.childNodes.length > 0 || n.defaultContent == null) return;
|
|
28
27
|
let e = document.createElement("span");
|
|
29
28
|
e.className = `${r.className}__placeholder`, e.textContent = n.defaultContent, i.replaceChildren(e);
|
|
30
|
-
},
|
|
31
|
-
r.style.setProperty("--spot-radius", `${n.radius ?? 120}px`), r.style.setProperty("--dim-color", n.dimColor ?? "rgba(0, 0, 0, 0.85)"),
|
|
29
|
+
}, l = () => {
|
|
30
|
+
r.style.setProperty("--spot-radius", `${n.radius ?? 120}px`), r.style.setProperty("--dim-color", n.dimColor ?? "rgba(0, 0, 0, 0.85)"), c();
|
|
32
31
|
};
|
|
33
|
-
return
|
|
32
|
+
return l(), {
|
|
34
33
|
update(e) {
|
|
35
34
|
n = {
|
|
36
35
|
...n,
|
|
37
36
|
...e
|
|
38
|
-
},
|
|
37
|
+
}, l();
|
|
39
38
|
},
|
|
40
39
|
getSlot: () => i,
|
|
41
40
|
destroy() {
|
|
@@ -45,7 +44,7 @@ function h(e, t = {}) {
|
|
|
45
44
|
}
|
|
46
45
|
//#endregion
|
|
47
46
|
//#region src/components/spotlight/vue/Spotlight.vue
|
|
48
|
-
var
|
|
47
|
+
var l = /* @__PURE__ */ t({
|
|
49
48
|
__name: "Spotlight",
|
|
50
49
|
props: {
|
|
51
50
|
radius: {},
|
|
@@ -53,24 +52,18 @@ var g = /* @__PURE__ */ a({
|
|
|
53
52
|
defaultContent: {},
|
|
54
53
|
slotElement: {}
|
|
55
54
|
},
|
|
56
|
-
setup(
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}), f(() => p(g), () => y?.update(b())), s(() => {
|
|
64
|
-
y?.destroy(), y = null, v.value = null;
|
|
65
|
-
}), m({ getSlot: () => y?.getSlot?.() }), (o, s) => (c(), r("div", {
|
|
55
|
+
setup(t, { expose: s, emit: l }) {
|
|
56
|
+
let u = t, d = a(), f = null, p = () => ({ ...u });
|
|
57
|
+
return n(() => {
|
|
58
|
+
d.value && (f = c(d.value, p()));
|
|
59
|
+
}), o(() => ({ ...u }), () => f?.update(p()), { deep: !0 }), r(() => {
|
|
60
|
+
f?.destroy(), f = null;
|
|
61
|
+
}), s({ getSlot: () => f?.getSlot() }), (t, n) => (i(), e("div", {
|
|
66
62
|
ref_key: "hostRef",
|
|
67
|
-
ref:
|
|
63
|
+
ref: d,
|
|
68
64
|
class: "cos-spotlight-host"
|
|
69
|
-
},
|
|
70
|
-
key: 0,
|
|
71
|
-
to: v.value
|
|
72
|
-
}, [u(o.$slots, "default", {}, () => [i("span", null, d(a.defaultContent ?? "隐藏内容"), 1)])], 8, ["to"])) : n("", !0)], 512));
|
|
65
|
+
}, null, 512));
|
|
73
66
|
}
|
|
74
67
|
});
|
|
75
68
|
//#endregion
|
|
76
|
-
export {
|
|
69
|
+
export { l as Spotlight };
|
|
@@ -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/spotlight",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Spotlight 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.
|
|
87
|
+
"@cos-design/shared": "4.1.0"
|
|
88
88
|
}
|
|
89
|
-
}
|
|
89
|
+
}
|