styimat 1.0.1 → 1.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/README.md +18 -0
- package/package.json +22 -10
- package/styimat.js +13 -9
- package/styimat.min.js +8 -4
package/README.md
CHANGED
|
@@ -69,6 +69,24 @@ const result = styimat.convert(css);
|
|
|
69
69
|
console.log(result);
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
### AMD中使用
|
|
73
|
+
```javascript
|
|
74
|
+
// scripts/main.js
|
|
75
|
+
require.config({
|
|
76
|
+
paths: {
|
|
77
|
+
'styimat': 'https://cdn.jsdelivr.net/npm/styimat/styimat.min'
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
require(['styimat'], function(styimat) {
|
|
82
|
+
// 主应用代码
|
|
83
|
+
styimat.apply(`
|
|
84
|
+
$primary: lab(50 20 -10);
|
|
85
|
+
body { color: $primary; }
|
|
86
|
+
`);
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
72
90
|
### 命令行使用
|
|
73
91
|
|
|
74
92
|
```bash
|
package/package.json
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "styimat",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A powerful CSS variable preprocessor with nested selectors, Lab/LCH color spaces conversion and modern color features.",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "https://gitee.com/wxy6987/styimat.git"
|
|
8
|
-
},
|
|
9
|
-
"bugs": {
|
|
10
|
-
"url": "https://gitee.com/wxy6987/styimat/issues"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://gitee.com/wxy6987/styimat#readme",
|
|
13
5
|
"keywords": [
|
|
14
6
|
"css",
|
|
15
7
|
"preprocessor",
|
|
@@ -39,10 +31,30 @@
|
|
|
39
31
|
"bin": {
|
|
40
32
|
"styimat": "convert-styimat.js"
|
|
41
33
|
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://gitee.com/wxy6987/styimat.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://gitee.com/wxy6987/styimat/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://gitee.com/wxy6987/styimat#readme",
|
|
42
42
|
"scripts": {
|
|
43
43
|
"test": "echo \"No tests yet\" && exit 0",
|
|
44
44
|
"build:min": "npx terser styimat.js -o styimat.min.js --comments '/^!'",
|
|
45
45
|
"prepare": "npm run build:min",
|
|
46
|
-
"prepublishOnly": "npm run build:min && echo 'Built successfully!'"
|
|
46
|
+
"prepublishOnly": "npm run build:min && echo 'Built successfully!'",
|
|
47
|
+
"preversion": "git add . && echo 'All files added to Git'",
|
|
48
|
+
"version": "git add . && git add -u",
|
|
49
|
+
"postversion": "git push && git push --tags",
|
|
50
|
+
"postpublish": "git add . && git commit -m 'chore: publish v$(node -p \"require('./package.json').version\")' && git push",
|
|
51
|
+
"release": "npm run release:patch",
|
|
52
|
+
"release:patch": "npm version patch && npm publish",
|
|
53
|
+
"release:minor": "npm version minor && npm publish",
|
|
54
|
+
"release:major": "npm version major && npm publish",
|
|
55
|
+
"git:add": "git add .",
|
|
56
|
+
"git:commit": "git commit -m",
|
|
57
|
+
"git:push": "git push",
|
|
58
|
+
"git:auto": "git add . && git commit -m 'Auto commit' && git push"
|
|
47
59
|
}
|
|
48
60
|
}
|
package/styimat.js
CHANGED
|
@@ -5,7 +5,18 @@
|
|
|
5
5
|
* 支持 lab# 和 lch# 十六进制语法
|
|
6
6
|
* 支持 Display P3 广色域显示器
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
(function(root, factory) {
|
|
9
|
+
if (typeof define === 'function' && define.amd) {
|
|
10
|
+
// AMD 支持 (RequireJS)
|
|
11
|
+
define([], factory);
|
|
12
|
+
} else if (typeof module === 'object' && module.exports) {
|
|
13
|
+
// CommonJS 支持 (Node.js, Browserify, Webpack)
|
|
14
|
+
module.exports = factory();
|
|
15
|
+
} else {
|
|
16
|
+
// 浏览器全局变量
|
|
17
|
+
root.styimat = factory();
|
|
18
|
+
}
|
|
19
|
+
}(typeof self !== 'undefined' ? self : this, function() {
|
|
9
20
|
// 默认配置
|
|
10
21
|
let defaultConfig = {
|
|
11
22
|
rootSelector: ':root',
|
|
@@ -1156,11 +1167,4 @@ const styimat = (function() {
|
|
|
1156
1167
|
}
|
|
1157
1168
|
|
|
1158
1169
|
return api;
|
|
1159
|
-
})
|
|
1160
|
-
|
|
1161
|
-
// 导出
|
|
1162
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
1163
|
-
module.exports = styimat;
|
|
1164
|
-
} else {
|
|
1165
|
-
window.styimat = styimat;
|
|
1166
|
-
}
|
|
1170
|
+
}));
|
package/styimat.min.js
CHANGED
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
* 支持 lab# 和 lch# 十六进制语法
|
|
6
6
|
* 支持 Display P3 广色域显示器
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
(function(root,factory){if(typeof define==="function"&&define.amd){
|
|
9
|
+
// AMD 支持 (RequireJS)
|
|
10
|
+
define([],factory)}else if(typeof module==="object"&&module.exports){
|
|
11
|
+
// CommonJS 支持 (Node.js, Browserify, Webpack)
|
|
12
|
+
module.exports=factory()}else{
|
|
13
|
+
// 浏览器全局变量
|
|
14
|
+
root.styimat=factory()}})(typeof self!=="undefined"?self:this,function(){
|
|
9
15
|
// 默认配置
|
|
10
16
|
let defaultConfig={rootSelector:":root",variablePrefix:"--",preserveOriginal:false,indentSize:2,enableNesting:true,autoProcessStyleTags:true,styleTagAttribute:"e",convertLabToRGB:true,// 是否将lab颜色转换为rgb
|
|
11
17
|
convertLchToRGB:true,// 是否将lch颜色转换为rgb
|
|
@@ -346,6 +352,4 @@ const labMatch=colorString.match(/lab\(\s*([\d.]+)(%?)\s+([\d.-]+)\s+([\d.-]+)(?
|
|
|
346
352
|
// 尝试解析lch()函数格式
|
|
347
353
|
const lchMatch=colorString.match(/lch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.%]+))?\s*\)/i);if(lchMatch){let L=parseFloat(lchMatch[1]);const C=parseFloat(lchMatch[3]);let H=parseFloat(lchMatch[4]);const alpha=lchMatch[6]?lchMatch[6].includes("%")?parseFloat(lchMatch[6])/100:parseFloat(lchMatch[6]):null;const lab=lchToLab(L,C,H);const colorStr=generateColorString(lab.L,lab.a,lab.b,defaultConfig,alpha);return{L:L,C:C,H:H,alpha:alpha,lab:lab,rgb:preciseLabToRGB(lab.L,lab.a,lab.b),p3:labToP3(lab.L,lab.a,lab.b),colorString:colorStr}}return null}catch(error){console.warn("无法解析颜色:",colorString,error);return null}}}};
|
|
348
354
|
// 自动初始化
|
|
349
|
-
if(typeof window!=="undefined"){apply();Object.defineProperty(window.HTMLElement.prototype,"cssVar",{get(){const element=this;return new Proxy({},{get(target,prop){const varName=prop.startsWith("--")?prop:`--${prop}`;return element.style.getPropertyValue(varName)},set(target,prop,value){const varName=prop.startsWith("--")?prop:`--${prop}`;element.style.setProperty(varName,value);return true}})}})}return api}
|
|
350
|
-
// 导出
|
|
351
|
-
if(typeof module!=="undefined"&&module.exports){module.exports=styimat}else{window.styimat=styimat}
|
|
355
|
+
if(typeof window!=="undefined"){apply();Object.defineProperty(window.HTMLElement.prototype,"cssVar",{get(){const element=this;return new Proxy({},{get(target,prop){const varName=prop.startsWith("--")?prop:`--${prop}`;return element.style.getPropertyValue(varName)},set(target,prop,value){const varName=prop.startsWith("--")?prop:`--${prop}`;element.style.setProperty(varName,value);return true}})}})}return api});
|