styimat 1.0.2 → 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 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,6 +1,6 @@
1
1
  {
2
2
  "name": "styimat",
3
- "version": "1.0.2",
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
5
  "keywords": [
6
6
  "css",
package/styimat.js CHANGED
@@ -5,7 +5,18 @@
5
5
  * 支持 lab# 和 lch# 十六进制语法
6
6
  * 支持 Display P3 广色域显示器
7
7
  */
8
- const styimat = (function() {
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
- const styimat=function(){
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});