@cos-design/spring-mass 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 +33 -33
- 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 +27 -27
- 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,6 +1,6 @@
|
|
|
1
|
-
import { bindVisibilityPause as e } from "@cos-design/shared";
|
|
1
|
+
import { bindVisibilityPause as e, readNumberAttr as t, readStringAttr as n } from "@cos-design/shared";
|
|
2
2
|
import './element.css';//#region src/components/springMass/core/engine.ts
|
|
3
|
-
var
|
|
3
|
+
var r = "cos-spring-mass", i = (e, t, n, r) => {
|
|
4
4
|
let i = Math.max(3, Math.min(n, 10)), a = Math.max(3, Math.min(r, 8)), o = e * .16, s = t * .18, c = (e - o * 2) / (i - 1), l = (t - s * 2) / (a - 1), u = [];
|
|
5
5
|
for (let e = 0; e < a; e++) for (let t = 0; t < i; t++) {
|
|
6
6
|
let n = e === 0 && (t === 0 || t === i - 1) || e === a - 1 && (t === 0 || t === i - 1);
|
|
@@ -38,7 +38,7 @@ var t = "cos-spring-mass", n = (e, t, n, r) => {
|
|
|
38
38
|
springs: d
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
|
-
function
|
|
41
|
+
function a(t, n = {}) {
|
|
42
42
|
let a = {
|
|
43
43
|
width: 560,
|
|
44
44
|
height: 400,
|
|
@@ -48,16 +48,16 @@ function r(r, i = {}) {
|
|
|
48
48
|
damping: .9,
|
|
49
49
|
color: "#a78bfa",
|
|
50
50
|
hint: "拖拽网格质点,观察弹簧回弹",
|
|
51
|
-
...
|
|
52
|
-
}, o = !1, s = 0, c = null, l =
|
|
51
|
+
...n
|
|
52
|
+
}, o = !1, s = 0, c = null, l = i(a.width ?? 560, a.height ?? 400, a.cols ?? 6, a.rows ?? 5), u = null, d = {
|
|
53
53
|
x: 0,
|
|
54
54
|
y: 0
|
|
55
55
|
}, f = document.createElement("div"), p = document.createElement("canvas");
|
|
56
|
-
p.className = `${
|
|
56
|
+
p.className = `${r}__canvas`;
|
|
57
57
|
let m = document.createElement("div");
|
|
58
|
-
m.className = `${
|
|
58
|
+
m.className = `${r}__hint`, f.append(p, m), t.appendChild(f);
|
|
59
59
|
let h = () => {
|
|
60
|
-
l =
|
|
60
|
+
l = i(a.width ?? 560, a.height ?? 400, a.cols ?? 6, a.rows ?? 5), u = null;
|
|
61
61
|
}, g = (e, t) => {
|
|
62
62
|
let n = -1, r = 20;
|
|
63
63
|
return l.nodes.forEach((i, a) => {
|
|
@@ -93,10 +93,10 @@ function r(r, i = {}) {
|
|
|
93
93
|
s && cancelAnimationFrame(s), s = 0, c?.(), c = null;
|
|
94
94
|
}, T = () => {
|
|
95
95
|
if (w(), o) return;
|
|
96
|
-
let
|
|
97
|
-
f.className =
|
|
96
|
+
let t = a.width ?? 560, n = a.height ?? 400, i = a.color ?? "#a78bfa", h = a.damping ?? .9, g = Math.max(.04, Math.min(a.stiffness ?? .22, .8));
|
|
97
|
+
f.className = r, f.style.width = `${t}px`, f.style.height = `${n}px`, p.style.width = `${t}px`, p.style.height = `${n}px`, m.textContent = a.hint ?? "拖拽网格质点,观察弹簧回弹";
|
|
98
98
|
let _ = window.devicePixelRatio || 1;
|
|
99
|
-
p.width =
|
|
99
|
+
p.width = t * _, p.height = n * _;
|
|
100
100
|
let v = p.getContext("2d");
|
|
101
101
|
if (!v) return;
|
|
102
102
|
v.setTransform(_, 0, 0, _, 0, 0);
|
|
@@ -105,29 +105,29 @@ function r(r, i = {}) {
|
|
|
105
105
|
y = e;
|
|
106
106
|
});
|
|
107
107
|
let b = () => {
|
|
108
|
-
let { nodes: e, springs:
|
|
108
|
+
let { nodes: e, springs: r } = l;
|
|
109
109
|
if (u) {
|
|
110
110
|
let t = e[u.index];
|
|
111
111
|
t.x = d.x + u.ox, t.y = d.y + u.oy, t.vx = 0, t.vy = 0;
|
|
112
112
|
}
|
|
113
|
-
for (let
|
|
114
|
-
let
|
|
115
|
-
!
|
|
113
|
+
for (let t of r) {
|
|
114
|
+
let n = e[t.a], r = e[t.b], i = r.x - n.x, a = r.y - n.y, o = Math.hypot(i, a) || .001, s = (o - t.rest) * g, c = i / o * s, l = a / o * s, d = u?.index === t.a, f = u?.index === t.b;
|
|
115
|
+
!n.pinned && !d && (n.vx += c, n.vy += l), !r.pinned && !f && (r.vx -= c, r.vy -= l);
|
|
116
116
|
}
|
|
117
|
-
for (let
|
|
118
|
-
let i = e[
|
|
119
|
-
if (i.pinned || u?.index ===
|
|
117
|
+
for (let r = 0; r < e.length; r++) {
|
|
118
|
+
let i = e[r];
|
|
119
|
+
if (i.pinned || u?.index === r) {
|
|
120
120
|
i.vx = 0, i.vy = 0;
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
|
-
i.vx *= h, i.vy *= h, i.x += i.vx, i.y += i.vy, i.x < 10 ? (i.x = 10, i.vx *= -.4) : i.x >
|
|
123
|
+
i.vx *= h, i.vy *= h, i.x += i.vx, i.y += i.vy, i.x < 10 ? (i.x = 10, i.vx *= -.4) : i.x > t - 10 && (i.x = t - 10, i.vx *= -.4), i.y < 10 ? (i.y = 10, i.vy *= -.4) : i.y > n - 10 && (i.y = n - 10, i.vy *= -.4);
|
|
124
124
|
}
|
|
125
125
|
}, x = () => {
|
|
126
|
-
let { nodes: e, springs:
|
|
127
|
-
v.fillStyle = "#0f172a", v.fillRect(0, 0,
|
|
128
|
-
for (let a of
|
|
129
|
-
let
|
|
130
|
-
v.beginPath(), v.moveTo(
|
|
126
|
+
let { nodes: e, springs: r } = l;
|
|
127
|
+
v.fillStyle = "#0f172a", v.fillRect(0, 0, t, n);
|
|
128
|
+
for (let a of r) {
|
|
129
|
+
let r = e[a.a], o = e[a.b], s = Math.hypot(o.x - r.x, o.y - r.y) || 1, c = Math.min(1, Math.abs(s - a.rest) / a.rest);
|
|
130
|
+
v.beginPath(), v.moveTo(r.x, r.y), v.lineTo(o.x, o.y), v.strokeStyle = i, v.globalAlpha = .22 + c * .55, v.lineWidth = a.rest > Math.max(t, n) * .2 ? 1 : 1.6, v.stroke(), v.globalAlpha = 1;
|
|
131
131
|
}
|
|
132
132
|
e.forEach((e, t) => {
|
|
133
133
|
v.beginPath(), v.arc(e.x, e.y, e.pinned ? 6 : 8, 0, Math.PI * 2), v.fillStyle = e.pinned ? "#64748b" : i, v.fill(), v.strokeStyle = "rgb(255 255 255 / 28%)", v.lineWidth = 1, v.stroke(), u?.index === t && (v.beginPath(), v.arc(e.x, e.y, 13, 0, Math.PI * 2), v.strokeStyle = i, v.globalAlpha = .45, v.lineWidth = 2, v.stroke(), v.globalAlpha = 1);
|
|
@@ -152,12 +152,12 @@ function r(r, i = {}) {
|
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
|
154
154
|
//#region src/components/springMass/element/index.ts
|
|
155
|
-
var
|
|
156
|
-
function
|
|
157
|
-
let
|
|
158
|
-
return e
|
|
155
|
+
var o = "cos-spring-mass";
|
|
156
|
+
function s(e) {
|
|
157
|
+
let r = {};
|
|
158
|
+
return n(r, e, "color", "color"), n(r, e, "hint", "hint"), t(r, e, "width", "width"), t(r, e, "height", "height"), t(r, e, "cols", "cols"), t(r, e, "rows", "rows"), t(r, e, "stiffness", "stiffness"), t(r, e, "damping", "damping"), r;
|
|
159
159
|
}
|
|
160
|
-
var
|
|
160
|
+
var c = class extends HTMLElement {
|
|
161
161
|
ctrl = null;
|
|
162
162
|
static get observedAttributes() {
|
|
163
163
|
return [
|
|
@@ -172,15 +172,15 @@ var o = class extends HTMLElement {
|
|
|
172
172
|
];
|
|
173
173
|
}
|
|
174
174
|
connectedCallback() {
|
|
175
|
-
this.ctrl =
|
|
175
|
+
this.ctrl = a(this, s(this));
|
|
176
176
|
}
|
|
177
177
|
disconnectedCallback() {
|
|
178
178
|
this.ctrl?.destroy(), this.ctrl = null;
|
|
179
179
|
}
|
|
180
180
|
attributeChangedCallback() {
|
|
181
|
-
this.ctrl?.update(
|
|
181
|
+
this.ctrl?.update(s(this));
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
|
-
typeof customElements < "u" && !customElements.get("cos-spring-mass") && customElements.define(
|
|
184
|
+
typeof customElements < "u" && !customElements.get("cos-spring-mass") && customElements.define(o, c);
|
|
185
185
|
//#endregion
|
|
186
|
-
export {
|
|
186
|
+
export { c as CosSpringMassElement, 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,7 +1,7 @@
|
|
|
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 { bindVisibilityPause as s
|
|
2
|
+
import { bindVisibilityPause as s } from "@cos-design/shared";
|
|
3
3
|
import './vue.css';//#region src/components/springMass/core/engine.ts
|
|
4
|
-
var
|
|
4
|
+
var c = "cos-spring-mass", l = (e, t, n, r) => {
|
|
5
5
|
let i = Math.max(3, Math.min(n, 10)), a = Math.max(3, Math.min(r, 8)), o = e * .16, s = t * .18, c = (e - o * 2) / (i - 1), l = (t - s * 2) / (a - 1), u = [];
|
|
6
6
|
for (let e = 0; e < a; e++) for (let t = 0; t < i; t++) {
|
|
7
7
|
let n = e === 0 && (t === 0 || t === i - 1) || e === a - 1 && (t === 0 || t === i - 1);
|
|
@@ -39,7 +39,7 @@ var l = "cos-spring-mass", u = (e, t, n, r) => {
|
|
|
39
39
|
springs: d
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
function
|
|
42
|
+
function u(e, t = {}) {
|
|
43
43
|
let n = {
|
|
44
44
|
width: 560,
|
|
45
45
|
height: 400,
|
|
@@ -50,15 +50,15 @@ function d(e, t = {}) {
|
|
|
50
50
|
color: "#a78bfa",
|
|
51
51
|
hint: "拖拽网格质点,观察弹簧回弹",
|
|
52
52
|
...t
|
|
53
|
-
}, r = !1, i = 0, a = null, o =
|
|
53
|
+
}, r = !1, i = 0, a = null, o = l(n.width ?? 560, n.height ?? 400, n.cols ?? 6, n.rows ?? 5), u = null, d = {
|
|
54
54
|
x: 0,
|
|
55
55
|
y: 0
|
|
56
56
|
}, f = document.createElement("div"), p = document.createElement("canvas");
|
|
57
|
-
p.className = `${
|
|
57
|
+
p.className = `${c}__canvas`;
|
|
58
58
|
let m = document.createElement("div");
|
|
59
|
-
m.className = `${
|
|
59
|
+
m.className = `${c}__hint`, f.append(p, m), e.appendChild(f);
|
|
60
60
|
let h = () => {
|
|
61
|
-
o =
|
|
61
|
+
o = l(n.width ?? 560, n.height ?? 400, n.cols ?? 6, n.rows ?? 5), u = null;
|
|
62
62
|
}, g = (e, t) => {
|
|
63
63
|
let n = -1, r = 20;
|
|
64
64
|
return o.nodes.forEach((i, a) => {
|
|
@@ -72,7 +72,7 @@ function d(e, t = {}) {
|
|
|
72
72
|
let a = g(r, i);
|
|
73
73
|
if (a < 0) return;
|
|
74
74
|
let s = o.nodes[a];
|
|
75
|
-
|
|
75
|
+
u = {
|
|
76
76
|
index: a,
|
|
77
77
|
ox: s.x - r,
|
|
78
78
|
oy: s.y - i
|
|
@@ -81,7 +81,7 @@ function d(e, t = {}) {
|
|
|
81
81
|
let n = p.getBoundingClientRect();
|
|
82
82
|
d.x = e - n.left, d.y = t - n.top;
|
|
83
83
|
}, y = () => {
|
|
84
|
-
|
|
84
|
+
u = null;
|
|
85
85
|
}, b = (e) => _(e.clientX, e.clientY), x = (e) => v(e.clientX, e.clientY), S = (e) => {
|
|
86
86
|
let t = e.touches[0];
|
|
87
87
|
t && _(t.clientX, t.clientY);
|
|
@@ -94,8 +94,8 @@ function d(e, t = {}) {
|
|
|
94
94
|
i && cancelAnimationFrame(i), i = 0, a?.(), a = null;
|
|
95
95
|
}, T = () => {
|
|
96
96
|
if (w(), r) return;
|
|
97
|
-
let e = n.width ?? 560, t = n.height ?? 400,
|
|
98
|
-
f.className =
|
|
97
|
+
let e = n.width ?? 560, t = n.height ?? 400, l = n.color ?? "#a78bfa", h = n.damping ?? .9, g = Math.max(.04, Math.min(n.stiffness ?? .22, .8));
|
|
98
|
+
f.className = c, f.style.width = `${e}px`, f.style.height = `${t}px`, p.style.width = `${e}px`, p.style.height = `${t}px`, m.textContent = n.hint ?? "拖拽网格质点,观察弹簧回弹";
|
|
99
99
|
let _ = window.devicePixelRatio || 1;
|
|
100
100
|
p.width = e * _, p.height = t * _;
|
|
101
101
|
let v = p.getContext("2d");
|
|
@@ -107,17 +107,17 @@ function d(e, t = {}) {
|
|
|
107
107
|
});
|
|
108
108
|
let b = () => {
|
|
109
109
|
let { nodes: n, springs: r } = o;
|
|
110
|
-
if (
|
|
111
|
-
let e = n[
|
|
112
|
-
e.x = d.x +
|
|
110
|
+
if (u) {
|
|
111
|
+
let e = n[u.index];
|
|
112
|
+
e.x = d.x + u.ox, e.y = d.y + u.oy, e.vx = 0, e.vy = 0;
|
|
113
113
|
}
|
|
114
114
|
for (let e of r) {
|
|
115
|
-
let t = n[e.a], r = n[e.b], i = r.x - t.x, a = r.y - t.y, o = Math.hypot(i, a) || .001, s = (o - e.rest) * g,
|
|
116
|
-
!t.pinned && !d && (t.vx +=
|
|
115
|
+
let t = n[e.a], r = n[e.b], i = r.x - t.x, a = r.y - t.y, o = Math.hypot(i, a) || .001, s = (o - e.rest) * g, c = i / o * s, l = a / o * s, d = u?.index === e.a, f = u?.index === e.b;
|
|
116
|
+
!t.pinned && !d && (t.vx += c, t.vy += l), !r.pinned && !f && (r.vx -= c, r.vy -= l);
|
|
117
117
|
}
|
|
118
118
|
for (let r = 0; r < n.length; r++) {
|
|
119
119
|
let i = n[r];
|
|
120
|
-
if (i.pinned ||
|
|
120
|
+
if (i.pinned || u?.index === r) {
|
|
121
121
|
i.vx = 0, i.vy = 0;
|
|
122
122
|
continue;
|
|
123
123
|
}
|
|
@@ -128,10 +128,10 @@ function d(e, t = {}) {
|
|
|
128
128
|
v.fillStyle = "#0f172a", v.fillRect(0, 0, e, t);
|
|
129
129
|
for (let i of r) {
|
|
130
130
|
let r = n[i.a], a = n[i.b], o = Math.hypot(a.x - r.x, a.y - r.y) || 1, s = Math.min(1, Math.abs(o - i.rest) / i.rest);
|
|
131
|
-
v.beginPath(), v.moveTo(r.x, r.y), v.lineTo(a.x, a.y), v.strokeStyle =
|
|
131
|
+
v.beginPath(), v.moveTo(r.x, r.y), v.lineTo(a.x, a.y), v.strokeStyle = l, v.globalAlpha = .22 + s * .55, v.lineWidth = i.rest > Math.max(e, t) * .2 ? 1 : 1.6, v.stroke(), v.globalAlpha = 1;
|
|
132
132
|
}
|
|
133
133
|
n.forEach((e, t) => {
|
|
134
|
-
v.beginPath(), v.arc(e.x, e.y, e.pinned ? 6 : 8, 0, Math.PI * 2), v.fillStyle = e.pinned ? "#64748b" :
|
|
134
|
+
v.beginPath(), v.arc(e.x, e.y, e.pinned ? 6 : 8, 0, Math.PI * 2), v.fillStyle = e.pinned ? "#64748b" : l, v.fill(), v.strokeStyle = "rgb(255 255 255 / 28%)", v.lineWidth = 1, v.stroke(), u?.index === t && (v.beginPath(), v.arc(e.x, e.y, 13, 0, Math.PI * 2), v.strokeStyle = l, v.globalAlpha = .45, v.lineWidth = 2, v.stroke(), v.globalAlpha = 1);
|
|
135
135
|
});
|
|
136
136
|
}, S = () => {
|
|
137
137
|
i = requestAnimationFrame(S), !(y || r) && (b(), x());
|
|
@@ -153,7 +153,7 @@ function d(e, t = {}) {
|
|
|
153
153
|
}
|
|
154
154
|
//#endregion
|
|
155
155
|
//#region src/components/springMass/vue/SpringMass.vue
|
|
156
|
-
var
|
|
156
|
+
var d = /* @__PURE__ */ t({
|
|
157
157
|
__name: "SpringMass",
|
|
158
158
|
props: {
|
|
159
159
|
width: {},
|
|
@@ -165,18 +165,18 @@ var f = /* @__PURE__ */ t({
|
|
|
165
165
|
color: {},
|
|
166
166
|
hint: {}
|
|
167
167
|
},
|
|
168
|
-
setup(t, { expose: s, emit:
|
|
169
|
-
let
|
|
168
|
+
setup(t, { expose: s, emit: c }) {
|
|
169
|
+
let l = t, d = a(), f = null, p = () => ({ ...l });
|
|
170
170
|
return n(() => {
|
|
171
|
-
|
|
172
|
-
}), o(() =>
|
|
173
|
-
|
|
171
|
+
d.value && (f = u(d.value, p()));
|
|
172
|
+
}), o(() => ({ ...l }), () => f?.update(p()), { deep: !0 }), r(() => {
|
|
173
|
+
f?.destroy(), f = null;
|
|
174
174
|
}), s({}), (t, n) => (i(), e("div", {
|
|
175
175
|
ref_key: "hostRef",
|
|
176
|
-
ref:
|
|
176
|
+
ref: d,
|
|
177
177
|
class: "cos-springMass-host"
|
|
178
178
|
}, null, 512));
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
181
|
//#endregion
|
|
182
|
-
export {
|
|
182
|
+
export { d as SpringMass };
|
|
@@ -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/spring-mass",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "SpringMass 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
|
+
}
|