@cos-design/solar-system 3.5.3 → 4.0.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/index.d.ts +1 -0
- package/dist/core/index.js +126 -0
- package/dist/core/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/core/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/core/packages/shared/src/index.d.ts +11 -0
- package/dist/core/packages/shared/src/math.d.ts +2 -0
- package/dist/core/packages/shared/src/photo.d.ts +15 -0
- package/dist/core/packages/shared/src/pointer.d.ts +14 -0
- package/dist/core/packages/shared/src/react/index.d.ts +30 -0
- package/dist/core/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/core/packages/shared/src/size.d.ts +8 -0
- package/dist/{packages/shared/src/index.d.ts → core/packages/shared/src/visibility.d.ts} +0 -1
- package/dist/core/packages/solarSystem/src/core.d.ts +1 -0
- package/dist/core/packages/solarSystem/src/element.d.ts +1 -0
- package/dist/core/packages/solarSystem/src/react.d.ts +3 -0
- package/dist/core/packages/solarSystem/src/vue.d.ts +2 -0
- package/dist/core/src/components/solarSystem/core/engine.d.ts +2 -0
- package/dist/core/src/components/solarSystem/core/index.d.ts +2 -0
- package/dist/core/src/components/solarSystem/core/types.d.ts +11 -0
- package/dist/core/src/components/solarSystem/element/index.d.ts +9 -0
- package/dist/core/src/components/solarSystem/index.d.ts +3 -0
- package/dist/core/src/components/solarSystem/react/index.d.ts +4 -0
- package/dist/{src → core/src}/vite-env.d.ts +6 -0
- package/dist/element/element.css +1 -0
- package/dist/element/index.d.ts +1 -0
- package/dist/element/index.js +154 -0
- package/dist/element/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/element/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/element/packages/shared/src/index.d.ts +11 -0
- package/dist/element/packages/shared/src/math.d.ts +2 -0
- package/dist/element/packages/shared/src/photo.d.ts +15 -0
- package/dist/element/packages/shared/src/pointer.d.ts +14 -0
- package/dist/element/packages/shared/src/react/index.d.ts +30 -0
- package/dist/element/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/element/packages/shared/src/size.d.ts +8 -0
- package/dist/element/packages/shared/src/visibility.d.ts +2 -0
- package/dist/element/packages/solarSystem/src/core.d.ts +1 -0
- package/dist/element/packages/solarSystem/src/element.d.ts +1 -0
- package/dist/element/packages/solarSystem/src/index.d.ts +3 -0
- package/dist/element/packages/solarSystem/src/react.d.ts +3 -0
- package/dist/element/packages/solarSystem/src/vue.d.ts +2 -0
- package/dist/element/src/components/solarSystem/core/engine.d.ts +2 -0
- package/dist/element/src/components/solarSystem/core/index.d.ts +2 -0
- package/dist/element/src/components/solarSystem/core/types.d.ts +11 -0
- package/dist/element/src/components/solarSystem/element/index.d.ts +9 -0
- package/dist/element/src/components/solarSystem/index.d.ts +3 -0
- package/dist/element/src/components/solarSystem/react/index.d.ts +4 -0
- package/dist/element/src/vite-env.d.ts +45 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +149 -0
- package/dist/react/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/react/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/react/packages/shared/src/index.d.ts +11 -0
- package/dist/react/packages/shared/src/math.d.ts +2 -0
- package/dist/react/packages/shared/src/photo.d.ts +15 -0
- package/dist/react/packages/shared/src/pointer.d.ts +14 -0
- package/dist/react/packages/shared/src/react/index.d.ts +30 -0
- package/dist/react/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/react/packages/shared/src/size.d.ts +8 -0
- package/dist/react/packages/shared/src/visibility.d.ts +2 -0
- package/dist/react/packages/solarSystem/src/core.d.ts +1 -0
- package/dist/react/packages/solarSystem/src/element.d.ts +1 -0
- package/dist/react/packages/solarSystem/src/index.d.ts +3 -0
- package/dist/react/packages/solarSystem/src/react.d.ts +3 -0
- package/dist/react/packages/solarSystem/src/vue.d.ts +2 -0
- package/dist/react/react.css +1 -0
- package/dist/react/src/components/solarSystem/core/engine.d.ts +2 -0
- package/dist/react/src/components/solarSystem/core/index.d.ts +2 -0
- package/dist/react/src/components/solarSystem/core/types.d.ts +11 -0
- package/dist/react/src/components/solarSystem/element/index.d.ts +9 -0
- package/dist/react/src/components/solarSystem/index.d.ts +3 -0
- package/dist/react/src/components/solarSystem/react/index.d.ts +4 -0
- package/dist/react/src/vite-env.d.ts +45 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +150 -0
- package/dist/vue/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/vue/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/vue/packages/shared/src/index.d.ts +11 -0
- package/dist/vue/packages/shared/src/math.d.ts +2 -0
- package/dist/vue/packages/shared/src/photo.d.ts +15 -0
- package/dist/vue/packages/shared/src/pointer.d.ts +14 -0
- package/dist/vue/packages/shared/src/react/index.d.ts +30 -0
- package/dist/vue/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/vue/packages/shared/src/size.d.ts +8 -0
- package/dist/vue/packages/shared/src/visibility.d.ts +2 -0
- package/dist/vue/packages/solarSystem/src/core.d.ts +1 -0
- package/dist/vue/packages/solarSystem/src/element.d.ts +1 -0
- package/dist/vue/packages/solarSystem/src/index.d.ts +3 -0
- package/dist/vue/packages/solarSystem/src/react.d.ts +3 -0
- package/dist/vue/packages/solarSystem/src/vue.d.ts +2 -0
- package/dist/vue/src/components/solarSystem/core/engine.d.ts +2 -0
- package/dist/vue/src/components/solarSystem/core/index.d.ts +2 -0
- package/dist/vue/src/components/solarSystem/core/types.d.ts +11 -0
- package/dist/vue/src/components/solarSystem/element/index.d.ts +9 -0
- package/dist/vue/src/components/solarSystem/index.d.ts +3 -0
- package/dist/vue/src/components/solarSystem/react/index.d.ts +4 -0
- package/dist/vue/src/vite-env.d.ts +45 -0
- package/dist/vue/vue.css +1 -0
- package/package.json +43 -11
- package/dist/index.cjs +0 -1
- package/dist/index.css +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -133
- package/dist/src/components/solarSystem/index.d.ts +0 -9
- /package/dist/{packages → core/packages}/solarSystem/src/index.d.ts +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
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, optionsFingerprint as c } from "@cos-design/shared";
|
|
3
|
+
import './vue.css';//#region src/components/solarSystem/core/engine.ts
|
|
4
|
+
var l = "cos-solar-system", u = [
|
|
5
|
+
{
|
|
6
|
+
name: "Mercury",
|
|
7
|
+
radius: 0,
|
|
8
|
+
orbit: 42,
|
|
9
|
+
speed: 4.8,
|
|
10
|
+
color: "#94a3b8",
|
|
11
|
+
size: 3
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "Venus",
|
|
15
|
+
radius: 0,
|
|
16
|
+
orbit: 58,
|
|
17
|
+
speed: 3.5,
|
|
18
|
+
color: "#fbbf24",
|
|
19
|
+
size: 5
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "Earth",
|
|
23
|
+
radius: 0,
|
|
24
|
+
orbit: 78,
|
|
25
|
+
speed: 3,
|
|
26
|
+
color: "#38bdf8",
|
|
27
|
+
size: 5
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "Mars",
|
|
31
|
+
radius: 0,
|
|
32
|
+
orbit: 98,
|
|
33
|
+
speed: 2.4,
|
|
34
|
+
color: "#f87171",
|
|
35
|
+
size: 4
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "Jupiter",
|
|
39
|
+
radius: 0,
|
|
40
|
+
orbit: 130,
|
|
41
|
+
speed: 1.6,
|
|
42
|
+
color: "#fb923c",
|
|
43
|
+
size: 12
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "Saturn",
|
|
47
|
+
radius: 0,
|
|
48
|
+
orbit: 160,
|
|
49
|
+
speed: 1.2,
|
|
50
|
+
color: "#fcd34d",
|
|
51
|
+
size: 10
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "Moon",
|
|
55
|
+
radius: 0,
|
|
56
|
+
orbit: 14,
|
|
57
|
+
speed: 8,
|
|
58
|
+
color: "#cbd5e1",
|
|
59
|
+
size: 2,
|
|
60
|
+
parent: 2
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
function d(e, t = {}) {
|
|
64
|
+
let n = {
|
|
65
|
+
width: 400,
|
|
66
|
+
height: 400,
|
|
67
|
+
speed: 1,
|
|
68
|
+
showOrbits: !0,
|
|
69
|
+
...t
|
|
70
|
+
}, r = !1, i = 0, a = typeof document < "u" ? document.hidden : !1, o = null, c = u.map((e) => ({
|
|
71
|
+
...e,
|
|
72
|
+
angle: Math.random() * Math.PI * 2
|
|
73
|
+
})), d = Array.from({ length: 80 }, () => ({
|
|
74
|
+
x: Math.random(),
|
|
75
|
+
y: Math.random(),
|
|
76
|
+
alpha: Math.random() * .6
|
|
77
|
+
})), f = document.createElement("div");
|
|
78
|
+
f.className = l;
|
|
79
|
+
let p = document.createElement("canvas");
|
|
80
|
+
p.className = `${l}__canvas`, f.appendChild(p), e.appendChild(f);
|
|
81
|
+
let m = () => {
|
|
82
|
+
let e = n.width ?? 400, t = n.height ?? 400;
|
|
83
|
+
f.style.width = `${e}px`, f.style.height = `${t}px`, p.style.width = `${e}px`, p.style.height = `${t}px`;
|
|
84
|
+
let r = window.devicePixelRatio || 1;
|
|
85
|
+
p.width = e * r, p.height = t * r;
|
|
86
|
+
let i = p.getContext("2d");
|
|
87
|
+
i && i.setTransform(r, 0, 0, r, 0, 0);
|
|
88
|
+
}, h = () => {
|
|
89
|
+
if (r || (i = requestAnimationFrame(h), a)) return;
|
|
90
|
+
let e = p.getContext("2d");
|
|
91
|
+
if (!e) return;
|
|
92
|
+
let t = n.width ?? 400, o = n.height ?? 400, s = n.speed ?? 1, l = n.showOrbits ?? !0, u = t / 2, f = o / 2, m = Math.min(t, o) / 380, g = [];
|
|
93
|
+
e.fillStyle = "#0f172a", e.fillRect(0, 0, t, o), d.forEach((n) => {
|
|
94
|
+
e.fillStyle = `rgba(255,255,255,${n.alpha})`, e.fillRect(n.x * t, n.y * o, 1, 1);
|
|
95
|
+
}), e.beginPath(), e.arc(u, f, 18 * m, 0, Math.PI * 2);
|
|
96
|
+
let _ = e.createRadialGradient(u, f, 0, u, f, 18 * m);
|
|
97
|
+
_.addColorStop(0, "#fef08a"), _.addColorStop(.5, "#fbbf24"), _.addColorStop(1, "#f97316"), e.fillStyle = _, e.shadowColor = "#fbbf24", e.shadowBlur = 24, e.fill(), e.shadowBlur = 0, c.forEach((t, n) => {
|
|
98
|
+
t.angle += t.speed * .008 * s / Math.sqrt(t.orbit);
|
|
99
|
+
let r = u, i = f;
|
|
100
|
+
t.parent !== void 0 && g[t.parent] && (r = g[t.parent].x, i = g[t.parent].y);
|
|
101
|
+
let a = t.orbit * m, o = r + Math.cos(t.angle) * a, c = i + Math.sin(t.angle) * a;
|
|
102
|
+
if (g[n] = {
|
|
103
|
+
x: o,
|
|
104
|
+
y: c
|
|
105
|
+
}, l && t.parent === void 0 && (e.beginPath(), e.arc(r, i, a, 0, Math.PI * 2), e.strokeStyle = "rgba(148, 163, 184, 0.15)", e.lineWidth = 1, e.stroke()), t.name === "Saturn" && (e.beginPath(), e.ellipse(o, c, t.size * m * 1.8, t.size * m * .5, t.angle * .3, 0, Math.PI * 2), e.strokeStyle = "rgba(252, 211, 77, 0.5)", e.lineWidth = 1.5, e.stroke()), e.beginPath(), e.arc(o, c, t.size * m, 0, Math.PI * 2), e.fillStyle = t.color, t.name === "Earth") {
|
|
106
|
+
let n = e.createRadialGradient(o - 2, c - 2, 0, o, c, t.size * m);
|
|
107
|
+
n.addColorStop(0, "#4ade80"), n.addColorStop(.6, t.color), n.addColorStop(1, "#1d4ed8"), e.fillStyle = n;
|
|
108
|
+
}
|
|
109
|
+
e.fill();
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
return m(), o = s((e) => {
|
|
113
|
+
a = e;
|
|
114
|
+
}), h(), {
|
|
115
|
+
update(e) {
|
|
116
|
+
n = {
|
|
117
|
+
...n,
|
|
118
|
+
...e
|
|
119
|
+
}, m();
|
|
120
|
+
},
|
|
121
|
+
destroy() {
|
|
122
|
+
r || (r = !0, cancelAnimationFrame(i), o?.(), f.remove());
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/components/solarSystem/vue/SolarSystem.vue
|
|
128
|
+
var f = /* @__PURE__ */ t({
|
|
129
|
+
__name: "SolarSystem",
|
|
130
|
+
props: {
|
|
131
|
+
width: {},
|
|
132
|
+
height: {},
|
|
133
|
+
speed: {},
|
|
134
|
+
showOrbits: { type: Boolean }
|
|
135
|
+
},
|
|
136
|
+
setup(t, { expose: s, emit: l }) {
|
|
137
|
+
let u = t, f = a(), p = null, m = () => ({ ...u });
|
|
138
|
+
return n(() => {
|
|
139
|
+
f.value && (p = d(f.value, m()));
|
|
140
|
+
}), o(() => c(u), () => p?.update(m())), r(() => {
|
|
141
|
+
p?.destroy(), p = null;
|
|
142
|
+
}), s({}), (t, n) => (i(), e("div", {
|
|
143
|
+
ref_key: "hostRef",
|
|
144
|
+
ref: f,
|
|
145
|
+
class: "cos-solarSystem-host"
|
|
146
|
+
}, null, 512));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
//#endregion
|
|
150
|
+
export { f as SolarSystem };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ElementSize } from './size';
|
|
2
|
+
export interface CanvasBoxSizeInput {
|
|
3
|
+
/** 为 true 时跟随父容器尺寸(需父级有明确高度) */
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
defaultWidth: number;
|
|
8
|
+
defaultHeight: number;
|
|
9
|
+
measured: ElementSize;
|
|
10
|
+
}
|
|
11
|
+
export interface CanvasBoxSize {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
15
|
+
pending: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** 根据 fill / 显式宽高 / 测量结果解析画布逻辑尺寸 */
|
|
18
|
+
export declare const resolveCanvasBoxSize: ({ fill, width, height, defaultWidth, defaultHeight, measured, }: CanvasBoxSizeInput) => CanvasBoxSize;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Apply fill / explicit size to the adapter host and make the engine root fill it. */
|
|
2
|
+
export declare function applyCanvasHostBox(container: HTMLElement, root: HTMLElement, opts: {
|
|
3
|
+
fill: boolean;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}): void;
|
|
7
|
+
/**
|
|
8
|
+
* Size the adapter host (React/Vue div or custom element) so percentage widths
|
|
9
|
+
* don't collapse when the host is a shrink-wrapped flex child. Root fills the host
|
|
10
|
+
* unless `rootFillsHost` is false (e.g. PhotoAlbum sizes itself via CSS variables).
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyBlockHostBox(container: HTMLElement, root: HTMLElement, size: {
|
|
13
|
+
width?: number | string;
|
|
14
|
+
height?: number | string;
|
|
15
|
+
rootFillsHost?: boolean;
|
|
16
|
+
}): void;
|
|
17
|
+
/** Toggle empty-state nodes; author `display:` rules must not override `[hidden]`. */
|
|
18
|
+
export declare function setHidden(el: HTMLElement, hidden: boolean): void;
|
|
19
|
+
/** Stable JSON key for options, ignoring functions (callbacks). */
|
|
20
|
+
export declare function optionsFingerprint(value: unknown): string;
|
|
21
|
+
/** True when non-function fields differ (shallow). */
|
|
22
|
+
export declare function optionsVisualChanged(prev: Record<string, unknown>, next: Record<string, unknown>): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { clamp, lerp } from './math';
|
|
2
|
+
export { bindVisibilityPause } from './visibility';
|
|
3
|
+
export { prefersReducedMotion, bindPrefersReducedMotion } from './reduced-motion';
|
|
4
|
+
export { observeElementSize } from './size';
|
|
5
|
+
export type { ElementSize } from './size';
|
|
6
|
+
export { getRelativePointerPosition } from './pointer';
|
|
7
|
+
export type { PointerPosition } from './pointer';
|
|
8
|
+
export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from './photo';
|
|
9
|
+
export { resolveCanvasBoxSize } from './canvas-box';
|
|
10
|
+
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
|
+
export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 图片预览组件通用照片项 */
|
|
2
|
+
export interface PhotoItem {
|
|
3
|
+
/** 图片地址 */
|
|
4
|
+
src: string;
|
|
5
|
+
/** 图片替代文本 */
|
|
6
|
+
alt?: string;
|
|
7
|
+
/** 照片标题 */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** 照片说明 */
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 线性浏览:当前索引变化(相册 / 胶卷 / 晾绳等) */
|
|
13
|
+
export type PhotoIndexChangeHandler<T = PhotoItem> = (index: number, photo: T) => void;
|
|
14
|
+
/** 环形浏览:正对镜头的面变化(走马灯 / 旋转木马等) */
|
|
15
|
+
export type PhotoFaceChangeHandler<T = PhotoItem> = (index: number, photo?: T) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PointerPosition {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
type PointLike = {
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
8
|
+
};
|
|
9
|
+
/** 相对元素左上角的指针坐标(兼容 mouse / touch / pointer) */
|
|
10
|
+
export declare const getRelativePointerPosition: (element: Element, event: PointLike | {
|
|
11
|
+
touches?: ArrayLike<PointLike>;
|
|
12
|
+
changedTouches?: ArrayLike<PointLike>;
|
|
13
|
+
}) => PointerPosition | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CSSProperties, RefObject } from 'react';
|
|
2
|
+
import { ElementSize } from '../size';
|
|
3
|
+
export type { CanvasBoxSize, CanvasBoxSizeInput } from '../canvas-box';
|
|
4
|
+
export { resolveCanvasBoxSize } from '../canvas-box';
|
|
5
|
+
export interface UseElementSizeOptions {
|
|
6
|
+
/** 为 false 时不观察 */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** 观察元素尺寸(clientWidth / clientHeight) */
|
|
10
|
+
export declare const useElementSize: <T extends Element>(ref: RefObject<T | null>, options?: UseElementSizeOptions) => ElementSize;
|
|
11
|
+
export interface UseCanvasBoxOptions {
|
|
12
|
+
/** 为 true 时铺满父容器(父级需有明确高度) */
|
|
13
|
+
fill?: boolean;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
defaultWidth: number;
|
|
17
|
+
defaultHeight: number;
|
|
18
|
+
}
|
|
19
|
+
export interface UseCanvasBoxResult {
|
|
20
|
+
hostRef: RefObject<HTMLDivElement | null>;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
/** 挂到宿主容器的样式(fill 时为 100%×100%) */
|
|
24
|
+
hostStyle: CSSProperties;
|
|
25
|
+
fill: boolean;
|
|
26
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
27
|
+
pending: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** 画布/效果宿主尺寸:fill 时跟随父容器,否则用显式宽高或默认值 */
|
|
30
|
+
export declare const useCanvasBox: ({ fill, width: widthProp, height: heightProp, defaultWidth, defaultHeight, }: UseCanvasBoxOptions) => UseCanvasBoxResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/solarSystem/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/solarSystem/element';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface SolarSystemOptions {
|
|
2
|
+
width?: number;
|
|
3
|
+
height?: number;
|
|
4
|
+
speed?: number;
|
|
5
|
+
showOrbits?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SolarSystemController {
|
|
8
|
+
update(options: Partial<SolarSystemOptions>): void;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
}
|
|
11
|
+
export type SolarSystemProps = SolarSystemOptions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const TAG = "cos-solar-system";
|
|
2
|
+
declare class CosSolarSystemElement extends HTMLElement {
|
|
3
|
+
private ctrl;
|
|
4
|
+
static get observedAttributes(): string[];
|
|
5
|
+
connectedCallback(): void;
|
|
6
|
+
disconnectedCallback(): void;
|
|
7
|
+
attributeChangedCallback(): void;
|
|
8
|
+
}
|
|
9
|
+
export { CosSolarSystemElement, TAG };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import type { DefineComponent } from 'vue';
|
|
5
|
+
const component: DefineComponent<object, object, unknown>;
|
|
6
|
+
export default component;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '*.module.less' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.png' {
|
|
20
|
+
const src: string;
|
|
21
|
+
export default src;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.jpg' {
|
|
25
|
+
const src: string;
|
|
26
|
+
export default src;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.mp4' {
|
|
30
|
+
const src: string;
|
|
31
|
+
export default src;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.mp3' {
|
|
35
|
+
const src: string;
|
|
36
|
+
export default src;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.svg' {
|
|
40
|
+
import type { FC, SVGProps } from 'react';
|
|
41
|
+
|
|
42
|
+
export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
|
|
43
|
+
const src: string;
|
|
44
|
+
export default src;
|
|
45
|
+
}
|
package/dist/vue/vue.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cos-solar-system{background:#0f172a;border-radius:12px;overflow:hidden}.cos-solar-system__canvas{display:block}
|
package/package.json
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cos-design/solar-system",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "SolarSystem component from cos-design",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"main": "./dist/react/index.cjs",
|
|
7
|
+
"module": "./dist/react/index.js",
|
|
8
|
+
"types": "./dist/react/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"default": "./dist/index.js"
|
|
12
|
+
"types": "./dist/react/index.d.ts",
|
|
13
|
+
"default": "./dist/react/index.js"
|
|
14
14
|
},
|
|
15
15
|
"require": {
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"default": "./dist/index.cjs"
|
|
16
|
+
"types": "./dist/react/index.d.ts",
|
|
17
|
+
"default": "./dist/react/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./vue": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/vue/index.d.ts",
|
|
23
|
+
"default": "./dist/vue/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./core": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/core/index.d.ts",
|
|
29
|
+
"default": "./dist/core/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./element": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/element/index.d.ts",
|
|
35
|
+
"default": "./dist/element/index.js"
|
|
18
36
|
}
|
|
19
37
|
}
|
|
20
38
|
},
|
|
@@ -24,11 +42,13 @@
|
|
|
24
42
|
],
|
|
25
43
|
"sideEffects": [
|
|
26
44
|
"**/*.css",
|
|
27
|
-
"**/*.less"
|
|
45
|
+
"**/*.less",
|
|
46
|
+
"./dist/element/index.js"
|
|
28
47
|
],
|
|
29
48
|
"keywords": [
|
|
30
49
|
"cos-design",
|
|
31
50
|
"react",
|
|
51
|
+
"vue",
|
|
32
52
|
"solarSystem",
|
|
33
53
|
"SolarSystem"
|
|
34
54
|
],
|
|
@@ -45,13 +65,25 @@
|
|
|
45
65
|
"license": "MIT",
|
|
46
66
|
"peerDependencies": {
|
|
47
67
|
"react": ">=18.0.0",
|
|
48
|
-
"react-dom": ">=18.0.0"
|
|
68
|
+
"react-dom": ">=18.0.0",
|
|
69
|
+
"vue": ">=3.4.0"
|
|
49
70
|
},
|
|
50
71
|
"publishConfig": {
|
|
51
72
|
"access": "public",
|
|
52
73
|
"registry": "https://registry.npmjs.org"
|
|
53
74
|
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"react": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"react-dom": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"vue": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
54
86
|
"dependencies": {
|
|
55
|
-
"@cos-design/shared": "
|
|
87
|
+
"@cos-design/shared": "4.0.0"
|
|
56
88
|
}
|
|
57
89
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("@cos-design/shared"),u=require("react/jsx-runtime");var d={solarSystem:`cos-solarSystem-27h8F`,canvas:`cos-canvas-C0nRa`},f=[{name:`Mercury`,radius:0,orbit:42,speed:4.8,color:`#94a3b8`,size:3},{name:`Venus`,radius:0,orbit:58,speed:3.5,color:`#fbbf24`,size:5},{name:`Earth`,radius:0,orbit:78,speed:3,color:`#38bdf8`,size:5},{name:`Mars`,radius:0,orbit:98,speed:2.4,color:`#f87171`,size:4},{name:`Jupiter`,radius:0,orbit:130,speed:1.6,color:`#fb923c`,size:12},{name:`Saturn`,radius:0,orbit:160,speed:1.2,color:`#fcd34d`,size:10},{name:`Moon`,radius:0,orbit:14,speed:8,color:`#cbd5e1`,size:2,parent:2}],p=({width:e=400,height:t=400,speed:n=1,showOrbits:r=!0})=>{let i=(0,c.useRef)(null),a=(0,c.useRef)([]),o=(0,c.useRef)([]);return(0,c.useEffect)(()=>{a.current=f.map(e=>({...e,angle:Math.random()*Math.PI*2})),o.current=Array.from({length:80},()=>({x:Math.random(),y:Math.random(),alpha:Math.random()*.6}))},[]),(0,c.useEffect)(()=>{let s=i.current;if(!s)return;let c=window.devicePixelRatio||1;s.width=e*c,s.height=t*c;let u=s.getContext(`2d`);if(!u)return;u.setTransform(c,0,0,c,0,0);let d=e/2,f=t/2,p=Math.min(e,t)/380,m=0,h=document.hidden,g=(0,l.bindVisibilityPause)(e=>{h=e}),_=()=>{if(m=requestAnimationFrame(_),h)return;let i=a.current,s=[];u.fillStyle=`#0f172a`,u.fillRect(0,0,e,t),o.current.forEach(n=>{u.fillStyle=`rgba(255,255,255,${n.alpha})`,u.fillRect(n.x*e,n.y*t,1,1)}),u.beginPath(),u.arc(d,f,18*p,0,Math.PI*2);let c=u.createRadialGradient(d,f,0,d,f,18*p);c.addColorStop(0,`#fef08a`),c.addColorStop(.5,`#fbbf24`),c.addColorStop(1,`#f97316`),u.fillStyle=c,u.shadowColor=`#fbbf24`,u.shadowBlur=24,u.fill(),u.shadowBlur=0,i.forEach((e,t)=>{e.angle+=e.speed*.008*n/Math.sqrt(e.orbit);let i=d,a=f;e.parent!==void 0&&s[e.parent]&&(i=s[e.parent].x,a=s[e.parent].y);let o=e.orbit*p,c=i+Math.cos(e.angle)*o,l=a+Math.sin(e.angle)*o;if(s[t]={x:c,y:l},r&&e.parent===void 0&&(u.beginPath(),u.arc(i,a,o,0,Math.PI*2),u.strokeStyle=`rgba(148, 163, 184, 0.15)`,u.lineWidth=1,u.stroke()),e.name===`Saturn`&&(u.beginPath(),u.ellipse(c,l,e.size*p*1.8,e.size*p*.5,e.angle*.3,0,Math.PI*2),u.strokeStyle=`rgba(252, 211, 77, 0.5)`,u.lineWidth=1.5,u.stroke()),u.beginPath(),u.arc(c,l,e.size*p,0,Math.PI*2),u.fillStyle=e.color,e.name===`Earth`){let t=u.createRadialGradient(c-2,l-2,0,c,l,e.size*p);t.addColorStop(0,`#4ade80`),t.addColorStop(.6,e.color),t.addColorStop(1,`#1d4ed8`),u.fillStyle=t}u.fill()})};return _(),()=>{cancelAnimationFrame(m),g()}},[t,r,n,e]),(0,u.jsx)(`div`,{className:d.solarSystem,style:{width:e,height:t},children:(0,u.jsx)(`canvas`,{ref:i,className:d.canvas,style:{width:e,height:t}})})};exports.SolarSystem=p,exports.default=p;
|
package/dist/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.cos-solarSystem-27h8F{background:#0f172a;border-radius:12px;overflow:hidden}.cos-canvas-C0nRa{display:block}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { useEffect as e, useRef as t } from "react";
|
|
2
|
-
import { bindVisibilityPause as n } from "@cos-design/shared";
|
|
3
|
-
import { jsx as r } from "react/jsx-runtime";
|
|
4
|
-
import './index.css';var i = {
|
|
5
|
-
solarSystem: "cos-solarSystem-27h8F",
|
|
6
|
-
canvas: "cos-canvas-C0nRa"
|
|
7
|
-
}, a = [
|
|
8
|
-
{
|
|
9
|
-
name: "Mercury",
|
|
10
|
-
radius: 0,
|
|
11
|
-
orbit: 42,
|
|
12
|
-
speed: 4.8,
|
|
13
|
-
color: "#94a3b8",
|
|
14
|
-
size: 3
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
name: "Venus",
|
|
18
|
-
radius: 0,
|
|
19
|
-
orbit: 58,
|
|
20
|
-
speed: 3.5,
|
|
21
|
-
color: "#fbbf24",
|
|
22
|
-
size: 5
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: "Earth",
|
|
26
|
-
radius: 0,
|
|
27
|
-
orbit: 78,
|
|
28
|
-
speed: 3,
|
|
29
|
-
color: "#38bdf8",
|
|
30
|
-
size: 5
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "Mars",
|
|
34
|
-
radius: 0,
|
|
35
|
-
orbit: 98,
|
|
36
|
-
speed: 2.4,
|
|
37
|
-
color: "#f87171",
|
|
38
|
-
size: 4
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: "Jupiter",
|
|
42
|
-
radius: 0,
|
|
43
|
-
orbit: 130,
|
|
44
|
-
speed: 1.6,
|
|
45
|
-
color: "#fb923c",
|
|
46
|
-
size: 12
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "Saturn",
|
|
50
|
-
radius: 0,
|
|
51
|
-
orbit: 160,
|
|
52
|
-
speed: 1.2,
|
|
53
|
-
color: "#fcd34d",
|
|
54
|
-
size: 10
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "Moon",
|
|
58
|
-
radius: 0,
|
|
59
|
-
orbit: 14,
|
|
60
|
-
speed: 8,
|
|
61
|
-
color: "#cbd5e1",
|
|
62
|
-
size: 2,
|
|
63
|
-
parent: 2
|
|
64
|
-
}
|
|
65
|
-
], o = ({ width: o = 400, height: s = 400, speed: c = 1, showOrbits: l = !0 }) => {
|
|
66
|
-
let u = t(null), d = t([]), f = t([]);
|
|
67
|
-
return e(() => {
|
|
68
|
-
d.current = a.map((e) => ({
|
|
69
|
-
...e,
|
|
70
|
-
angle: Math.random() * Math.PI * 2
|
|
71
|
-
})), f.current = Array.from({ length: 80 }, () => ({
|
|
72
|
-
x: Math.random(),
|
|
73
|
-
y: Math.random(),
|
|
74
|
-
alpha: Math.random() * .6
|
|
75
|
-
}));
|
|
76
|
-
}, []), e(() => {
|
|
77
|
-
let e = u.current;
|
|
78
|
-
if (!e) return;
|
|
79
|
-
let t = window.devicePixelRatio || 1;
|
|
80
|
-
e.width = o * t, e.height = s * t;
|
|
81
|
-
let r = e.getContext("2d");
|
|
82
|
-
if (!r) return;
|
|
83
|
-
r.setTransform(t, 0, 0, t, 0, 0);
|
|
84
|
-
let i = o / 2, a = s / 2, p = Math.min(o, s) / 380, m = 0, h = document.hidden, g = n((e) => {
|
|
85
|
-
h = e;
|
|
86
|
-
}), _ = () => {
|
|
87
|
-
if (m = requestAnimationFrame(_), h) return;
|
|
88
|
-
let e = d.current, t = [];
|
|
89
|
-
r.fillStyle = "#0f172a", r.fillRect(0, 0, o, s), f.current.forEach((e) => {
|
|
90
|
-
r.fillStyle = `rgba(255,255,255,${e.alpha})`, r.fillRect(e.x * o, e.y * s, 1, 1);
|
|
91
|
-
}), r.beginPath(), r.arc(i, a, 18 * p, 0, Math.PI * 2);
|
|
92
|
-
let n = r.createRadialGradient(i, a, 0, i, a, 18 * p);
|
|
93
|
-
n.addColorStop(0, "#fef08a"), n.addColorStop(.5, "#fbbf24"), n.addColorStop(1, "#f97316"), r.fillStyle = n, r.shadowColor = "#fbbf24", r.shadowBlur = 24, r.fill(), r.shadowBlur = 0, e.forEach((e, n) => {
|
|
94
|
-
e.angle += e.speed * .008 * c / Math.sqrt(e.orbit);
|
|
95
|
-
let o = i, s = a;
|
|
96
|
-
e.parent !== void 0 && t[e.parent] && (o = t[e.parent].x, s = t[e.parent].y);
|
|
97
|
-
let u = e.orbit * p, d = o + Math.cos(e.angle) * u, f = s + Math.sin(e.angle) * u;
|
|
98
|
-
if (t[n] = {
|
|
99
|
-
x: d,
|
|
100
|
-
y: f
|
|
101
|
-
}, l && e.parent === void 0 && (r.beginPath(), r.arc(o, s, u, 0, Math.PI * 2), r.strokeStyle = "rgba(148, 163, 184, 0.15)", r.lineWidth = 1, r.stroke()), e.name === "Saturn" && (r.beginPath(), r.ellipse(d, f, e.size * p * 1.8, e.size * p * .5, e.angle * .3, 0, Math.PI * 2), r.strokeStyle = "rgba(252, 211, 77, 0.5)", r.lineWidth = 1.5, r.stroke()), r.beginPath(), r.arc(d, f, e.size * p, 0, Math.PI * 2), r.fillStyle = e.color, e.name === "Earth") {
|
|
102
|
-
let t = r.createRadialGradient(d - 2, f - 2, 0, d, f, e.size * p);
|
|
103
|
-
t.addColorStop(0, "#4ade80"), t.addColorStop(.6, e.color), t.addColorStop(1, "#1d4ed8"), r.fillStyle = t;
|
|
104
|
-
}
|
|
105
|
-
r.fill();
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
return _(), () => {
|
|
109
|
-
cancelAnimationFrame(m), g();
|
|
110
|
-
};
|
|
111
|
-
}, [
|
|
112
|
-
s,
|
|
113
|
-
l,
|
|
114
|
-
c,
|
|
115
|
-
o
|
|
116
|
-
]), /* @__PURE__ */ r("div", {
|
|
117
|
-
className: i.solarSystem,
|
|
118
|
-
style: {
|
|
119
|
-
width: o,
|
|
120
|
-
height: s
|
|
121
|
-
},
|
|
122
|
-
children: /* @__PURE__ */ r("canvas", {
|
|
123
|
-
ref: u,
|
|
124
|
-
className: i.canvas,
|
|
125
|
-
style: {
|
|
126
|
-
width: o,
|
|
127
|
-
height: s
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
//#endregion
|
|
133
|
-
export { o as SolarSystem, o as default };
|
|
File without changes
|