@longzai-intelligence-liquid-glass/css-backdrop 0.0.1
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 +12 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @longzai-intelligence-liquid-glass/css-backdrop
|
|
2
|
+
|
|
3
|
+
Liquid Glass CSS backdrop-filter 降级渲染后端。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun run --cwd packages/css-backdrop lint # 代码检查
|
|
9
|
+
bun run --cwd packages/css-backdrop typecheck # 类型检查(tsgo)
|
|
10
|
+
bun run --cwd packages/css-backdrop test # 单元测试
|
|
11
|
+
bun run --cwd packages/css-backdrop build # 构建(lzi-builder → dist)
|
|
12
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { LiquidGlassParams, LiquidGlassParamsInput, LiquidGlassRenderer, LiquidGlassSize, RendererCapability } from "@longzai-intelligence-liquid-glass/core";
|
|
2
|
+
//#region src/style-object.utils.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* CSS 样式对象(属性名 kebab-case,值字符串)
|
|
5
|
+
*/
|
|
6
|
+
type CssBackdropStyles = {
|
|
7
|
+
/**
|
|
8
|
+
* 样式属性 → 值
|
|
9
|
+
*/
|
|
10
|
+
[property: string]: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 生成液态玻璃降级样式对象
|
|
14
|
+
*
|
|
15
|
+
* @param params - 液态玻璃参数
|
|
16
|
+
* @returns CSS 样式对象
|
|
17
|
+
*/
|
|
18
|
+
declare function createCssBackdropStyles(params: LiquidGlassParams): CssBackdropStyles;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/css-backdrop-renderer.utils.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* 渲染上下文(构造入参)
|
|
23
|
+
*/
|
|
24
|
+
type CssBackdropRendererContext = {
|
|
25
|
+
/**
|
|
26
|
+
* 初始参数
|
|
27
|
+
*/
|
|
28
|
+
params: LiquidGlassParams;
|
|
29
|
+
/**
|
|
30
|
+
* 初始尺寸
|
|
31
|
+
*/
|
|
32
|
+
size: LiquidGlassSize;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* CSS 降级渲染器
|
|
36
|
+
*/
|
|
37
|
+
declare class CssBackdropRenderer implements LiquidGlassRenderer<HTMLElement> {
|
|
38
|
+
/**
|
|
39
|
+
* 后端标识
|
|
40
|
+
*/
|
|
41
|
+
readonly backend: 'css-backdrop';
|
|
42
|
+
/**
|
|
43
|
+
* 宿主元素(mount 后可用)
|
|
44
|
+
*/
|
|
45
|
+
private host;
|
|
46
|
+
/**
|
|
47
|
+
* 当前参数
|
|
48
|
+
*/
|
|
49
|
+
private params;
|
|
50
|
+
/**
|
|
51
|
+
* 构造渲染器
|
|
52
|
+
*
|
|
53
|
+
* @param context - 渲染上下文(初始参数与尺寸)
|
|
54
|
+
*/
|
|
55
|
+
constructor(context: CssBackdropRendererContext);
|
|
56
|
+
/**
|
|
57
|
+
* 挂载到 DOM 元素
|
|
58
|
+
*
|
|
59
|
+
* @param target - 宿主元素
|
|
60
|
+
*/
|
|
61
|
+
mount(target: HTMLElement): void;
|
|
62
|
+
/**
|
|
63
|
+
* 热更新参数
|
|
64
|
+
*
|
|
65
|
+
* @param params - 完整参数
|
|
66
|
+
*/
|
|
67
|
+
update(params: LiquidGlassParams): void;
|
|
68
|
+
/**
|
|
69
|
+
* 尺寸变化(降级路线无尺寸相关状态,空实现)
|
|
70
|
+
*
|
|
71
|
+
* @param _size - 新尺寸(未使用)
|
|
72
|
+
*/
|
|
73
|
+
resize(_size: LiquidGlassSize): void;
|
|
74
|
+
/**
|
|
75
|
+
* 获取能力描述
|
|
76
|
+
*
|
|
77
|
+
* @returns 能力描述
|
|
78
|
+
*/
|
|
79
|
+
getCapabilities(): RendererCapability;
|
|
80
|
+
/**
|
|
81
|
+
* 卸载并清理样式(幂等)
|
|
82
|
+
*/
|
|
83
|
+
unmount(): void;
|
|
84
|
+
/**
|
|
85
|
+
* 应用当前参数样式
|
|
86
|
+
*/
|
|
87
|
+
private apply;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/create.utils.d.ts
|
|
91
|
+
/**
|
|
92
|
+
* 命令式创建:在目标元素上应用 CSS 降级玻璃效果
|
|
93
|
+
*
|
|
94
|
+
* @param element - 宿主元素
|
|
95
|
+
* @param input - 参数输入(预设 + 覆盖)
|
|
96
|
+
* @returns 渲染器实例(调用方持有并负责 unmount)
|
|
97
|
+
*/
|
|
98
|
+
declare function createCssBackdropGlass(element: HTMLElement, input?: LiquidGlassParamsInput): CssBackdropRenderer;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/support.utils.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* CSS 降级路线支持检测
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* 支持检测结果
|
|
106
|
+
*/
|
|
107
|
+
type CssBackdropSupport = {
|
|
108
|
+
/**
|
|
109
|
+
* 是否支持降级路线(backdrop-filter 或 -webkit- 前缀)
|
|
110
|
+
*/
|
|
111
|
+
supported: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* 不支持原因(支持时为空字符串)
|
|
114
|
+
*/
|
|
115
|
+
reason: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* 检测当前环境对 backdrop-filter 的支持
|
|
119
|
+
*
|
|
120
|
+
* @returns 支持检测结果
|
|
121
|
+
*/
|
|
122
|
+
declare function detectCssBackdropSupport(): CssBackdropSupport;
|
|
123
|
+
//#endregion
|
|
124
|
+
export { CssBackdropRenderer, type CssBackdropStyles, type CssBackdropSupport, createCssBackdropGlass, createCssBackdropStyles, detectCssBackdropSupport };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolveParams as e}from"@longzai-intelligence-liquid-glass/core";function t(e,t,n,r){return`rgba(${Math.round(e*255)}, ${Math.round(t*255)}, ${Math.round(n*255)}, ${r.toFixed(3)})`}function n(e){let n=1+e.frost*1.5,r=`blur(${((e.blur+e.refraction*2)*n).toFixed(2)}px) saturate(${e.saturation}) brightness(${e.brightness})`;return{"backdrop-filter":r,"-webkit-backdrop-filter":r,background:t(e.tint.r,e.tint.g,e.tint.b,e.tint.a),"border-radius":e.shape===`circle`?`50%`:`${e.cornerRadius}px`,"box-shadow":[`inset 1.5px 1.5px 0 rgba(255, 255, 255, ${e.specular.toFixed(3)})`,`inset -1.5px -1.5px 0 rgba(255, 255, 255, ${(e.specular*.5).toFixed(3)})`,`0 8px 32px rgba(0, 0, 0, 0.12)`].join(`, `)}}var r=class{backend=`css-backdrop`;host=null;params;constructor(e){this.params=e.params}mount(e){this.host=e,this.apply()}update(e){this.params=e,this.apply()}resize(e){}getCapabilities(){return{backend:`css-backdrop`,supportsRefraction:!1,supportsDispersion:!1,supportsBlur:!0,supportsSpecular:!0,supportsDomBackdrop:!0}}unmount(){if(this.host!==null){for(let e of[`backdrop-filter`,`-webkit-backdrop-filter`,`background`,`border-radius`,`box-shadow`])this.host.style.removeProperty(e);this.host=null}}apply(){if(this.host===null)return;let e=n(this.params);for(let[t,n]of Object.entries(e))this.host.style.setProperty(t,n)}};function i(t,n){let i=new r({params:e(n),size:{width:0,height:0}});return i.mount(t),i}function a(){return typeof window>`u`||typeof CSS>`u`?{supported:!1,reason:`SSR 或非浏览器环境`}:typeof CSS.supports==`function`?CSS.supports(`backdrop-filter`,`blur(1px)`)||CSS.supports(`-webkit-backdrop-filter`,`blur(1px)`)?{supported:!0,reason:``}:{supported:!1,reason:`backdrop-filter 不受支持`}:{supported:!0,reason:``}}export{r as CssBackdropRenderer,i as createCssBackdropGlass,n as createCssBackdropStyles,a as detectCssBackdropSupport};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-liquid-glass/css-backdrop",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Liquid Glass CSS backdrop-filter 降级渲染后端",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "lzi-builder",
|
|
20
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
21
|
+
"prepublishOnly": "bun run build:prod",
|
|
22
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
23
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
24
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
25
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
26
|
+
"lint": "oxlint && oxfmt --check",
|
|
27
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
28
|
+
"test": "lzi-bun-cli test",
|
|
29
|
+
"test:watch": "lzi-bun-cli test --watch",
|
|
30
|
+
"test:coverage": "lzi-bun-cli test --coverage",
|
|
31
|
+
"clean": "lzi-dev-cli clean"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@longzai-intelligence-liquid-glass/core": "0.0.1"
|
|
35
|
+
},
|
|
36
|
+
"packageManager": "bun@1.3.14"
|
|
37
|
+
}
|