@zhaomushan/screen-aurora 1.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/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @zhaomushan/screen-aurora
2
+
3
+ Vue 3 **全屏极光网格背景**:Canvas 柔光色块缓慢流动,`pointer-events: none`,不阻挡页面点击。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @zhaomushan/screen-aurora vue
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```vue
14
+ <script setup lang="ts">
15
+ import { AuroraScreen } from "@zhaomushan/screen-aurora";
16
+ import "@zhaomushan/screen-aurora/style.css";
17
+ </script>
18
+
19
+ <template>
20
+ <AuroraScreen
21
+ v-model="on"
22
+ :speed="1"
23
+ :opacity="0.85"
24
+ :colors="['#4a6fa5', '#7c3aed', '#22d3ee']"
25
+ :z-index="0"
26
+ />
27
+ <main>你的页面内容</main>
28
+ </template>
29
+ ```
30
+
31
+ ## Props
32
+
33
+ | 属性 | 说明 | 默认 |
34
+ |------|------|------|
35
+ | `modelValue` / `active` | 是否播放 | `true` |
36
+ | `speed` | 流动速度 | `1` |
37
+ | `opacity` | 光斑强度 | `0.85` |
38
+ | `blobCount` | 色块数量 3–8 | `5` |
39
+ | `colors` | 十六进制色板 | 内置蓝紫青 |
40
+ | `zIndex` | 层级 | `0` |
41
+
42
+ ## 发版
43
+
44
+ ```bash
45
+ cd packages/screen-aurora
46
+ npm run build
47
+ npm publish --access public
48
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue"),$=["#4a6fa5","#7c3aed","#22d3ee","#6366f1","#a855f7"];function w(s,t={}){var C;const o=s.getContext("2d",{alpha:!0});if(!o)throw new Error("Canvas 2D not available");const e=o;let r=0,l=0,d=0,c=0,f=Math.max(.2,t.speed??1),m=Math.min(1,Math.max(.15,t.opacity??.85));const M=((C=t.colors)!=null&&C.length?t.colors:$).slice(0,8),_=Math.min(8,Math.max(3,t.blobCount??5)),b=Array.from({length:_},(n,a)=>({nx:.2+Math.random()*.6,ny:.2+Math.random()*.6,radius:.22+Math.random()*.18,phase:Math.random()*Math.PI*2,color:M[a%M.length]}));function h(){const n=Math.min(window.devicePixelRatio||1,2),a=s.getBoundingClientRect();r=Math.max(1,a.width),l=Math.max(1,a.height),s.width=Math.floor(r*n),s.height=Math.floor(l*n),e.setTransform(n,0,0,n,0,0)}function y(){c+=.007*f,e.clearRect(0,0,r,l),e.globalCompositeOperation="lighter";const n=Math.min(r,l);for(const a of b){const u=(a.nx+.12*Math.sin(c+a.phase)+.08*Math.cos(c*.6))*r,g=(a.ny+.1*Math.cos(c*.85+a.phase*1.2))*l,x=a.radius*n*(.95+.05*Math.sin(c*.5+a.phase)),p=e.createRadialGradient(u,g,0,u,g,x);p.addColorStop(0,S(a.color,m)),p.addColorStop(.45,S(a.color,m*.35)),p.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=p,e.beginPath(),e.arc(u,g,x,0,Math.PI*2),e.fill()}e.globalCompositeOperation="source-over",d=requestAnimationFrame(y)}function A(){v(),h(),y(),window.addEventListener("resize",h)}function v(){cancelAnimationFrame(d),window.removeEventListener("resize",h),e.clearRect(0,0,r,l)}function E(n){f=Math.max(.2,Math.min(3,n))}function O(n){m=Math.min(1,Math.max(.15,n))}function R(n){n.length&&b.forEach((a,u)=>{a.color=n[u%n.length]})}return{start:A,stop:v,resize:h,setSpeed:E,setOpacity:O,setColors:R}}function S(s,t){const o=s.replace("#","").trim();if(o.length===3){const e=parseInt(o[0]+o[0],16),r=parseInt(o[1]+o[1],16),l=parseInt(o[2]+o[2],16);return`rgba(${e},${r},${l},${t})`}if(o.length===6){const e=parseInt(o.slice(0,2),16),r=parseInt(o.slice(2,4),16),l=parseInt(o.slice(4,6),16);return`rgba(${e},${r},${l},${t})`}return s}const I=i.defineComponent({__name:"AuroraScreen",props:{modelValue:{type:Boolean,default:!0},active:{type:Boolean},speed:{default:1},opacity:{default:.85},blobCount:{default:5},colors:{},zIndex:{default:0}},emits:["update:modelValue"],setup(s){const t=s,o=i.ref(null);let e=null;const r=i.computed(()=>t.active??t.modelValue),l=i.computed(()=>({zIndex:String(t.zIndex)}));function d(){var c;e&&(e.setSpeed(t.speed),e.setOpacity(t.opacity),(c=t.colors)!=null&&c.length&&e.setColors(t.colors))}return i.watch(()=>[r.value,t.speed,t.opacity,t.colors,t.blobCount],()=>{e&&(r.value?(d(),e.start()):e.stop())},{deep:!0}),i.onMounted(()=>{const c=o.value;c&&(e=w(c,{speed:t.speed,opacity:t.opacity,blobCount:t.blobCount,colors:t.colors}),r.value&&e.start())}),i.onBeforeUnmount(()=>{e==null||e.stop(),e=null}),(c,f)=>(i.openBlock(),i.createElementBlock("div",{class:"sa-root",style:i.normalizeStyle(l.value),"aria-hidden":"true"},[i.createElementVNode("canvas",{ref_key:"canvasRef",ref:o},null,512)],4))}}),z={install(s){s.component("AuroraScreen",I)}};exports.AuroraScreen=I;exports.createAuroraEngine=w;exports.default=z;
@@ -0,0 +1,70 @@
1
+ import { App } from 'vue';
2
+ import { ComponentOptionsMixin } from 'vue';
3
+ import { ComponentProvideOptions } from 'vue';
4
+ import { DefineComponent } from 'vue';
5
+ import { PublicProps } from 'vue';
6
+
7
+ declare type __VLS_Props = {
8
+ modelValue?: boolean;
9
+ active?: boolean;
10
+ speed?: number;
11
+ opacity?: number;
12
+ blobCount?: number;
13
+ colors?: string[];
14
+ zIndex?: number;
15
+ };
16
+
17
+ export declare type AuroraBlob = {
18
+ nx: number;
19
+ ny: number;
20
+ radius: number;
21
+ phase: number;
22
+ color: string;
23
+ };
24
+
25
+ export declare type AuroraOptions = {
26
+ colors?: string[];
27
+ speed?: number;
28
+ blobCount?: number;
29
+ opacity?: number;
30
+ };
31
+
32
+ export declare const AuroraScreen: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
33
+ "update:modelValue": (value: boolean) => any;
34
+ }, string, PublicProps, Readonly<__VLS_Props> & Readonly<{
35
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
36
+ }>, {
37
+ modelValue: boolean;
38
+ speed: number;
39
+ opacity: number;
40
+ blobCount: number;
41
+ zIndex: number;
42
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {
43
+ canvasRef: HTMLCanvasElement;
44
+ }, HTMLDivElement>;
45
+
46
+ export declare type AuroraScreenProps = {
47
+ modelValue?: boolean;
48
+ active?: boolean;
49
+ speed?: number;
50
+ opacity?: number;
51
+ blobCount?: number;
52
+ colors?: string[];
53
+ zIndex?: number;
54
+ };
55
+
56
+ export declare function createAuroraEngine(canvas: HTMLCanvasElement, options?: AuroraOptions): {
57
+ start: () => void;
58
+ stop: () => void;
59
+ resize: () => void;
60
+ setSpeed: (v: number) => void;
61
+ setOpacity: (v: number) => void;
62
+ setColors: (list: string[]) => void;
63
+ };
64
+
65
+ declare const plugin: {
66
+ install(app: App): void;
67
+ };
68
+ export default plugin;
69
+
70
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,121 @@
1
+ import { defineComponent as R, ref as $, computed as v, watch as z, onMounted as O, onBeforeUnmount as B, openBlock as L, createElementBlock as P, normalizeStyle as V, createElementVNode as k } from "vue";
2
+ const F = ["#4a6fa5", "#7c3aed", "#22d3ee", "#6366f1", "#a855f7"];
3
+ function D(s, t = {}) {
4
+ var x;
5
+ const o = s.getContext("2d", { alpha: !0 });
6
+ if (!o) throw new Error("Canvas 2D not available");
7
+ const e = o;
8
+ let r = 0, l = 0, u = 0, c = 0, p = Math.max(0.2, t.speed ?? 1), f = Math.min(1, Math.max(0.15, t.opacity ?? 0.85));
9
+ const g = ((x = t.colors) != null && x.length ? t.colors : F).slice(
10
+ 0,
11
+ 8
12
+ ), S = Math.min(8, Math.max(3, t.blobCount ?? 5)), M = Array.from({ length: S }, (n, a) => ({
13
+ nx: 0.2 + Math.random() * 0.6,
14
+ ny: 0.2 + Math.random() * 0.6,
15
+ radius: 0.22 + Math.random() * 0.18,
16
+ phase: Math.random() * Math.PI * 2,
17
+ color: g[a % g.length]
18
+ }));
19
+ function d() {
20
+ const n = Math.min(window.devicePixelRatio || 1, 2), a = s.getBoundingClientRect();
21
+ r = Math.max(1, a.width), l = Math.max(1, a.height), s.width = Math.floor(r * n), s.height = Math.floor(l * n), e.setTransform(n, 0, 0, n, 0, 0);
22
+ }
23
+ function b() {
24
+ c += 7e-3 * p, e.clearRect(0, 0, r, l), e.globalCompositeOperation = "lighter";
25
+ const n = Math.min(r, l);
26
+ for (const a of M) {
27
+ const i = (a.nx + 0.12 * Math.sin(c + a.phase) + 0.08 * Math.cos(c * 0.6)) * r, m = (a.ny + 0.1 * Math.cos(c * 0.85 + a.phase * 1.2)) * l, C = a.radius * n * (0.95 + 0.05 * Math.sin(c * 0.5 + a.phase)), h = e.createRadialGradient(i, m, 0, i, m, C);
28
+ h.addColorStop(0, w(a.color, f)), h.addColorStop(0.45, w(a.color, f * 0.35)), h.addColorStop(1, "rgba(0,0,0,0)"), e.fillStyle = h, e.beginPath(), e.arc(i, m, C, 0, Math.PI * 2), e.fill();
29
+ }
30
+ e.globalCompositeOperation = "source-over", u = requestAnimationFrame(b);
31
+ }
32
+ function I() {
33
+ y(), d(), b(), window.addEventListener("resize", d);
34
+ }
35
+ function y() {
36
+ cancelAnimationFrame(u), window.removeEventListener("resize", d), e.clearRect(0, 0, r, l);
37
+ }
38
+ function A(n) {
39
+ p = Math.max(0.2, Math.min(3, n));
40
+ }
41
+ function E(n) {
42
+ f = Math.min(1, Math.max(0.15, n));
43
+ }
44
+ function _(n) {
45
+ n.length && M.forEach((a, i) => {
46
+ a.color = n[i % n.length];
47
+ });
48
+ }
49
+ return { start: I, stop: y, resize: d, setSpeed: A, setOpacity: E, setColors: _ };
50
+ }
51
+ function w(s, t) {
52
+ const o = s.replace("#", "").trim();
53
+ if (o.length === 3) {
54
+ const e = parseInt(o[0] + o[0], 16), r = parseInt(o[1] + o[1], 16), l = parseInt(o[2] + o[2], 16);
55
+ return `rgba(${e},${r},${l},${t})`;
56
+ }
57
+ if (o.length === 6) {
58
+ const e = parseInt(o.slice(0, 2), 16), r = parseInt(o.slice(2, 4), 16), l = parseInt(o.slice(4, 6), 16);
59
+ return `rgba(${e},${r},${l},${t})`;
60
+ }
61
+ return s;
62
+ }
63
+ const T = /* @__PURE__ */ R({
64
+ __name: "AuroraScreen",
65
+ props: {
66
+ modelValue: { type: Boolean, default: !0 },
67
+ active: { type: Boolean },
68
+ speed: { default: 1 },
69
+ opacity: { default: 0.85 },
70
+ blobCount: { default: 5 },
71
+ colors: {},
72
+ zIndex: { default: 0 }
73
+ },
74
+ emits: ["update:modelValue"],
75
+ setup(s) {
76
+ const t = s, o = $(null);
77
+ let e = null;
78
+ const r = v(() => t.active ?? t.modelValue), l = v(() => ({
79
+ zIndex: String(t.zIndex)
80
+ }));
81
+ function u() {
82
+ var c;
83
+ e && (e.setSpeed(t.speed), e.setOpacity(t.opacity), (c = t.colors) != null && c.length && e.setColors(t.colors));
84
+ }
85
+ return z(
86
+ () => [r.value, t.speed, t.opacity, t.colors, t.blobCount],
87
+ () => {
88
+ e && (r.value ? (u(), e.start()) : e.stop());
89
+ },
90
+ { deep: !0 }
91
+ ), O(() => {
92
+ const c = o.value;
93
+ c && (e = D(c, {
94
+ speed: t.speed,
95
+ opacity: t.opacity,
96
+ blobCount: t.blobCount,
97
+ colors: t.colors
98
+ }), r.value && e.start());
99
+ }), B(() => {
100
+ e == null || e.stop(), e = null;
101
+ }), (c, p) => (L(), P("div", {
102
+ class: "sa-root",
103
+ style: V(l.value),
104
+ "aria-hidden": "true"
105
+ }, [
106
+ k("canvas", {
107
+ ref_key: "canvasRef",
108
+ ref: o
109
+ }, null, 512)
110
+ ], 4));
111
+ }
112
+ }), q = {
113
+ install(s) {
114
+ s.component("AuroraScreen", T);
115
+ }
116
+ };
117
+ export {
118
+ T as AuroraScreen,
119
+ D as createAuroraEngine,
120
+ q as default
121
+ };
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .sa-root{position:fixed;top:0;right:0;bottom:0;left:0;width:100%;height:100%;pointer-events:none;overflow:hidden}.sa-root canvas{display:block;width:100%;height:100%}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@zhaomushan/screen-aurora",
3
+ "version": "1.0.0",
4
+ "description": "Vue 3 full-screen aurora mesh background — canvas, pointer-events passthrough",
5
+ "license": "ISC",
6
+ "author": "zhaomushan",
7
+ "type": "module",
8
+ "main": "dist/index.cjs",
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "./style.css": "./dist/style.css"
23
+ },
24
+ "files": ["dist", "README.md"],
25
+ "sideEffects": ["**/*.css", "dist/style.css"],
26
+ "publishConfig": { "access": "public" },
27
+ "scripts": {
28
+ "build": "vite build",
29
+ "prepublishOnly": "npm run build"
30
+ },
31
+ "keywords": [
32
+ "vue",
33
+ "vue3",
34
+ "aurora",
35
+ "background",
36
+ "canvas",
37
+ "fullscreen",
38
+ "mesh-gradient",
39
+ "pointer-events"
40
+ ],
41
+ "peerDependencies": { "vue": ">=3.4.0" },
42
+ "devDependencies": {
43
+ "@vitejs/plugin-vue": "^5.2.4",
44
+ "typescript": "^5.8.3",
45
+ "vite": "^6.3.5",
46
+ "vite-plugin-dts": "^4.5.4",
47
+ "vue": "^3.5.16"
48
+ }
49
+ }