@xihan-ui/web-components 1.0.0-alpha.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,76 @@
1
+ import { r as PropertyValues } from "./types-BvWWqMd_.js";
2
+ import { t as XhReactiveElement } from "./element-DRoFjrYO.js";
3
+ import { BackgroundEffect, BackgroundQuality, BackgroundSurface, MorphOptions, ParamValue, PointCloud } from "@xihan-ui/backgrounds";
4
+ //#region src/backgrounds.d.ts
5
+ /**
6
+ * `<xh-background>` —— 视觉画面宿主。
7
+ *
8
+ * 元素自身就是画布的容器:内容照常写在里面,效果铺在内容底下,
9
+ * 画布是 pointer-events: none,不会挡住里面的交互。
10
+ *
11
+ * @customElement xh-background
12
+ * @attr {string} effect - 效果名,须先注册(defineXhBackground 会把内置效果一并注册)
13
+ * @attr {'auto'|'high'|'balanced'|'eco'} quality - 画质档位
14
+ * @attr {object} params - 效果参数,JSON 对象
15
+ * @attr {boolean} paused - 暂停绘制
16
+ * @attr {boolean} pointer - 是否绑定指针事件,写 "false" 关闭
17
+ * @attr {boolean} reduced-motion - 是否尊重系统的减弱动态效果,写 "false" 关闭
18
+ * @attr {boolean} pause-offscreen - 滚出视口是否暂停,写 "false" 关闭
19
+ */
20
+ declare class XhBackgroundElement extends XhReactiveElement {
21
+ static properties: {
22
+ effect: {};
23
+ quality: {};
24
+ params: {
25
+ type: ObjectConstructor;
26
+ };
27
+ paused: {
28
+ type: BooleanConstructor;
29
+ };
30
+ pointer: {
31
+ converter: {
32
+ fromAttribute: (value: string | null) => boolean | undefined;
33
+ };
34
+ };
35
+ reducedMotion: {
36
+ attribute: string;
37
+ converter: {
38
+ fromAttribute: (value: string | null) => boolean | undefined;
39
+ };
40
+ };
41
+ pauseOffscreen: {
42
+ attribute: string;
43
+ converter: {
44
+ fromAttribute: (value: string | null) => boolean | undefined;
45
+ };
46
+ };
47
+ };
48
+ effect?: string | BackgroundEffect;
49
+ quality?: BackgroundQuality;
50
+ params?: Record<string, ParamValue>;
51
+ paused?: boolean;
52
+ pointer?: boolean;
53
+ reducedMotion?: boolean;
54
+ pauseOffscreen?: boolean;
55
+ private surface;
56
+ private appliedEffect;
57
+ /** 记住上次生效的画质:setQuality 会重建着色器程序,不能每次更新都调一遍。 */
58
+ private appliedQuality;
59
+ /** 画面还没建起来时先收着,建好后补发。 */
60
+ private pendingCloud;
61
+ /** 换点云。属性传不了二进制,只能用 JS 调。 */
62
+ setCloud(cloud: PointCloud, options?: MorphOptions): void;
63
+ /** 拿底层画面实例,用于自定义调度或调参。 */
64
+ getSurface(): BackgroundSurface | null;
65
+ connectedCallback(): void;
66
+ disconnectedCallback(): void;
67
+ protected updated(_changed: PropertyValues): void;
68
+ }
69
+ /**
70
+ * 注册 `<xh-background>`,并把内置效果一并注册进效果注册表——
71
+ * 元素只认效果名字,注册表空着的话任何 effect 属性都解析不出来。
72
+ */
73
+ declare function defineXhBackground(): void;
74
+ //#endregion
75
+ export { XhBackgroundElement, defineXhBackground };
76
+ //# sourceMappingURL=backgrounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backgrounds.d.ts","names":[],"sources":["../src/backgrounds.ts"],"mappings":";;;;;;;;;;;;;;;;;;;cA+Ca,4BAA4B;SACvB;;;;;;;;;;;QApBO,gBAAA;;;;;;QAAA,gBAAA;;;;;;QAAA,gBAAA;;;;EA8Bf,kBAAkB;EAClB,UAAU;EACV,SAAS,eAAe;EACxB;EACA;EACA;EACA;UAEA;UACA;;UAEA;;UAEA;;EAGR,SAAS,OAAO,YAAY,UAAU;;EAQtC,cAAc;EAIL;EAOA;YAOU,QAAQ,UAAU;;;;;;iBAuDvB"}
@@ -0,0 +1,120 @@
1
+ import { t as defineElement } from "./registry-DR6I2_zF.js";
2
+ import { n as version, t as XhReactiveElement } from "./element-xjYY5Oe2.js";
3
+ import { DIAGNOSTIC_CODES, reportDiagnostic } from "@xihan-ui/kernel";
4
+ import { createBackgroundSurface, registerBuiltinEffects } from "@xihan-ui/backgrounds";
5
+ //#region src/backgrounds.ts
6
+ /** 属性缺席翻成 undefined(走引擎默认值),写成 "false" 才是关。 */
7
+ const optionalBool = { fromAttribute: (value) => value === null ? void 0 : value !== "false" };
8
+ /**
9
+ * `<xh-background>` —— 视觉画面宿主。
10
+ *
11
+ * 元素自身就是画布的容器:内容照常写在里面,效果铺在内容底下,
12
+ * 画布是 pointer-events: none,不会挡住里面的交互。
13
+ *
14
+ * @customElement xh-background
15
+ * @attr {string} effect - 效果名,须先注册(defineXhBackground 会把内置效果一并注册)
16
+ * @attr {'auto'|'high'|'balanced'|'eco'} quality - 画质档位
17
+ * @attr {object} params - 效果参数,JSON 对象
18
+ * @attr {boolean} paused - 暂停绘制
19
+ * @attr {boolean} pointer - 是否绑定指针事件,写 "false" 关闭
20
+ * @attr {boolean} reduced-motion - 是否尊重系统的减弱动态效果,写 "false" 关闭
21
+ * @attr {boolean} pause-offscreen - 滚出视口是否暂停,写 "false" 关闭
22
+ */
23
+ var XhBackgroundElement = class extends XhReactiveElement {
24
+ static properties = {
25
+ effect: {},
26
+ quality: {},
27
+ params: { type: Object },
28
+ paused: { type: Boolean },
29
+ pointer: { converter: optionalBool },
30
+ reducedMotion: {
31
+ attribute: "reduced-motion",
32
+ converter: optionalBool
33
+ },
34
+ pauseOffscreen: {
35
+ attribute: "pause-offscreen",
36
+ converter: optionalBool
37
+ }
38
+ };
39
+ surface = null;
40
+ appliedEffect;
41
+ /** 记住上次生效的画质:setQuality 会重建着色器程序,不能每次更新都调一遍。 */
42
+ appliedQuality;
43
+ /** 画面还没建起来时先收着,建好后补发。 */
44
+ pendingCloud = null;
45
+ /** 换点云。属性传不了二进制,只能用 JS 调。 */
46
+ setCloud(cloud, options) {
47
+ if (this.surface === null) this.pendingCloud = {
48
+ cloud,
49
+ options
50
+ };
51
+ else this.surface.setCloud(cloud, options);
52
+ }
53
+ /** 拿底层画面实例,用于自定义调度或调参。 */
54
+ getSurface() {
55
+ return this.surface;
56
+ }
57
+ connectedCallback() {
58
+ if (getComputedStyle(this).display === "inline") this.style.display = "block";
59
+ super.connectedCallback();
60
+ }
61
+ disconnectedCallback() {
62
+ super.disconnectedCallback();
63
+ this.surface?.destroy();
64
+ this.surface = null;
65
+ this.appliedEffect = void 0;
66
+ }
67
+ updated(_changed) {
68
+ if (this.effect === void 0) return;
69
+ if (this.surface === null) {
70
+ try {
71
+ this.surface = createBackgroundSurface(this, {
72
+ effect: this.effect,
73
+ params: this.params,
74
+ quality: this.quality,
75
+ pointer: this.pointer,
76
+ autoplay: this.paused !== true,
77
+ respectReducedMotion: this.reducedMotion,
78
+ pauseOffscreen: this.pauseOffscreen
79
+ });
80
+ } catch (error) {
81
+ reportDiagnostic({
82
+ code: DIAGNOSTIC_CODES.warn,
83
+ level: "error",
84
+ message: `[visual] <xh-background> 创建失败:${error.message}`
85
+ });
86
+ return;
87
+ }
88
+ this.appliedEffect = this.effect;
89
+ this.appliedQuality = this.quality;
90
+ if (this.pendingCloud !== null) {
91
+ this.surface.setCloud(this.pendingCloud.cloud, this.pendingCloud.options);
92
+ this.pendingCloud = null;
93
+ }
94
+ return;
95
+ }
96
+ if (this.effect !== this.appliedEffect) {
97
+ this.surface.setEffect(this.effect);
98
+ this.appliedEffect = this.effect;
99
+ }
100
+ if (this.quality !== void 0 && this.quality !== this.appliedQuality) {
101
+ this.surface.setQuality(this.quality);
102
+ this.appliedQuality = this.quality;
103
+ }
104
+ if (this.params !== void 0) this.surface.setParams(this.params);
105
+ if (this.paused === true) this.surface.pause();
106
+ else this.surface.play();
107
+ }
108
+ };
109
+ /**
110
+ * 注册 `<xh-background>`,并把内置效果一并注册进效果注册表——
111
+ * 元素只认效果名字,注册表空着的话任何 effect 属性都解析不出来。
112
+ */
113
+ function defineXhBackground() {
114
+ registerBuiltinEffects();
115
+ defineElement("xh-background", XhBackgroundElement, version);
116
+ }
117
+ //#endregion
118
+ export { XhBackgroundElement, defineXhBackground };
119
+
120
+ //# sourceMappingURL=backgrounds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backgrounds.js","names":["VERSION"],"sources":["../src/backgrounds.ts"],"sourcesContent":["// @xihan-ui/web-components/backgrounds —— 视觉层的 Web Components 适配。\n//\n// 与主入口和 /define 都分开:@xihan-ui/backgrounds 是可选 peer,不用视觉效果的应用不会\n// 因为装了本包而多出一个 WebGL 引擎。用之前先装 @xihan-ui/backgrounds。\n//\n// ```html\n// <xh-background effect=\"aurora\" quality=\"balanced\" style=\"height: 180px\">\n// <h3>卡片标题</h3>\n// </xh-background>\n// ```\n\nimport type {\n BackgroundEffect,\n BackgroundQuality,\n BackgroundSurface,\n MorphOptions,\n ParamValue,\n PointCloud,\n} from '@xihan-ui/backgrounds'\nimport type { PropertyValues } from './reactive'\nimport { createBackgroundSurface, registerBuiltinEffects } from '@xihan-ui/backgrounds'\nimport { DIAGNOSTIC_CODES, reportDiagnostic } from '@xihan-ui/kernel'\nimport { version as VERSION } from '../package.json'\nimport { XhReactiveElement } from './reactive'\nimport { defineElement } from './runtime/registry'\n\n/** 属性缺席翻成 undefined(走引擎默认值),写成 \"false\" 才是关。 */\nconst optionalBool = {\n fromAttribute: (value: string | null): boolean | undefined =>\n value === null ? undefined : value !== 'false',\n}\n\n/**\n * `<xh-background>` —— 视觉画面宿主。\n *\n * 元素自身就是画布的容器:内容照常写在里面,效果铺在内容底下,\n * 画布是 pointer-events: none,不会挡住里面的交互。\n *\n * @customElement xh-background\n * @attr {string} effect - 效果名,须先注册(defineXhBackground 会把内置效果一并注册)\n * @attr {'auto'|'high'|'balanced'|'eco'} quality - 画质档位\n * @attr {object} params - 效果参数,JSON 对象\n * @attr {boolean} paused - 暂停绘制\n * @attr {boolean} pointer - 是否绑定指针事件,写 \"false\" 关闭\n * @attr {boolean} reduced-motion - 是否尊重系统的减弱动态效果,写 \"false\" 关闭\n * @attr {boolean} pause-offscreen - 滚出视口是否暂停,写 \"false\" 关闭\n */\nexport class XhBackgroundElement extends XhReactiveElement {\n static override properties = {\n effect: {},\n quality: {},\n params: { type: Object },\n paused: { type: Boolean },\n pointer: { converter: optionalBool },\n reducedMotion: { attribute: 'reduced-motion', converter: optionalBool },\n pauseOffscreen: { attribute: 'pause-offscreen', converter: optionalBool },\n }\n\n declare effect?: string | BackgroundEffect\n declare quality?: BackgroundQuality\n declare params?: Record<string, ParamValue>\n declare paused?: boolean\n declare pointer?: boolean\n declare reducedMotion?: boolean\n declare pauseOffscreen?: boolean\n\n private surface: BackgroundSurface | null = null\n private appliedEffect: string | BackgroundEffect | undefined\n /** 记住上次生效的画质:setQuality 会重建着色器程序,不能每次更新都调一遍。 */\n private appliedQuality: BackgroundQuality | undefined\n /** 画面还没建起来时先收着,建好后补发。 */\n private pendingCloud: { cloud: PointCloud, options?: MorphOptions } | null = null\n\n /** 换点云。属性传不了二进制,只能用 JS 调。 */\n setCloud(cloud: PointCloud, options?: MorphOptions): void {\n if (this.surface === null)\n this.pendingCloud = { cloud, options }\n else\n this.surface.setCloud(cloud, options)\n }\n\n /** 拿底层画面实例,用于自定义调度或调参。 */\n getSurface(): BackgroundSurface | null {\n return this.surface\n }\n\n override connectedCallback(): void {\n // 自定义元素默认是行内元素,行内元素量不出高度,画布会一直是 0×0\n if (getComputedStyle(this).display === 'inline')\n this.style.display = 'block'\n super.connectedCallback()\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n this.surface?.destroy()\n this.surface = null\n this.appliedEffect = undefined\n }\n\n protected override updated(_changed: PropertyValues): void {\n if (this.effect === undefined)\n return\n\n if (this.surface === null) {\n try {\n this.surface = createBackgroundSurface(this, {\n effect: this.effect,\n params: this.params,\n quality: this.quality,\n pointer: this.pointer,\n autoplay: this.paused !== true,\n respectReducedMotion: this.reducedMotion,\n pauseOffscreen: this.pauseOffscreen,\n })\n }\n catch (error) {\n // 效果名没注册就把整页带崩不划算,报出来即可\n reportDiagnostic({\n code: DIAGNOSTIC_CODES.warn,\n level: 'error',\n message: `[visual] <xh-background> 创建失败:${(error as Error).message}`,\n })\n return\n }\n this.appliedEffect = this.effect\n this.appliedQuality = this.quality\n if (this.pendingCloud !== null) {\n this.surface.setCloud(this.pendingCloud.cloud, this.pendingCloud.options)\n this.pendingCloud = null\n }\n return\n }\n\n if (this.effect !== this.appliedEffect) {\n this.surface.setEffect(this.effect)\n this.appliedEffect = this.effect\n }\n if (this.quality !== undefined && this.quality !== this.appliedQuality) {\n this.surface.setQuality(this.quality)\n this.appliedQuality = this.quality\n }\n if (this.params !== undefined)\n this.surface.setParams(this.params)\n if (this.paused === true)\n this.surface.pause()\n else\n this.surface.play()\n }\n}\n\n/**\n * 注册 `<xh-background>`,并把内置效果一并注册进效果注册表——\n * 元素只认效果名字,注册表空着的话任何 effect 属性都解析不出来。\n */\nexport function defineXhBackground(): void {\n registerBuiltinEffects()\n defineElement('xh-background', XhBackgroundElement, VERSION)\n}\n"],"mappings":";;;;;;AA2BA,MAAM,eAAe,EACnB,gBAAgB,UACd,UAAU,OAAO,KAAA,IAAY,UAAU,QAC3C;;;;;;;;;;;;;;;;AAiBA,IAAa,sBAAb,cAAyC,kBAAkB;CACzD,OAAgB,aAAa;EAC3B,QAAQ,CAAC;EACT,SAAS,CAAC;EACV,QAAQ,EAAE,MAAM,OAAO;EACvB,QAAQ,EAAE,MAAM,QAAQ;EACxB,SAAS,EAAE,WAAW,aAAa;EACnC,eAAe;GAAE,WAAW;GAAkB,WAAW;EAAa;EACtE,gBAAgB;GAAE,WAAW;GAAmB,WAAW;EAAa;CAC1E;CAUA,UAA4C;CAC5C;;CAEA;;CAEA,eAA6E;;CAG7E,SAAS,OAAmB,SAA8B;EACxD,IAAI,KAAK,YAAY,MACnB,KAAK,eAAe;GAAE;GAAO;EAAQ;OAErC,KAAK,QAAQ,SAAS,OAAO,OAAO;CACxC;;CAGA,aAAuC;EACrC,OAAO,KAAK;CACd;CAEA,oBAAmC;EAEjC,IAAI,iBAAiB,IAAI,CAAC,CAAC,YAAY,UACrC,KAAK,MAAM,UAAU;EACvB,MAAM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