styimat 1.6.3 → 1.7.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
@@ -1,12 +1,9 @@
1
1
  # styimat
2
-
3
2
  [![Stars](https://img.shields.io/badge/dynamic/json?label=Stars&query=%24.stargazers_count&url=https%3A%2F%2Fgitee.com%2Fapi%2Fv5%2Frepos%2Fwxy6987%2Fstyimat&color=FFD700&style=yellow)](https://gitee.com/wxy6987/styimat/stargazers)
4
3
  [![Forks](https://img.shields.io/badge/dynamic/json?label=Forks&query=%24.forks_count&url=https%3A%2F%2Fgitee.com%2Fapi%2Fv5%2Frepos%2Fwxy6987%2Fstyimat&color=red)](https://gitee.com/wxy6987/styimat/members)
5
4
  [![version](https://img.shields.io/npm/v/styimat.svg?color=brightgreen)](https://www.npmjs.com/package/styimat)
6
5
  [![license](https://img.shields.io/npm/l/styimat.svg?color=lightgrey)](LICENSE)
7
- [![size](https://img.shields.io/bundlephobia/minzip/styimat?label=size&color=blue)](https://bundlephobia.com/package/styimat)
8
-
9
-
6
+ ![size](https://img.shields.io/bundlephobia/minzip/styimat?label=size&color=blue)
10
7
 
11
8
  一个功能强大的 CSS 变量预处理库,支持嵌套规则、Lab/LCH 颜色空间转换、Display P3 广色域和增强的数学计算功能。
12
9
 
@@ -273,6 +270,10 @@ $font-family: 'Inter', sans-serif;
273
270
  .container {
274
271
  $local-var: 20px;
275
272
  margin: $local-var;
273
+
274
+ &::before {
275
+ content: $$ctx; //获取元素属性ctx
276
+ }
276
277
  }
277
278
  ```
278
279
 
@@ -326,7 +327,7 @@ $font-family: 'Inter', sans-serif;
326
327
 
327
328
  ## 十六进制颜色语法详解
328
329
 
329
- ### Lab 十六进制格式:`lab#L16A16B16`
330
+ ### Lab 十六进制格式:`lab#LLAABB`
330
331
  Lab 颜色使用 `lab#` 前缀,后跟 6 个十六进制字符:
331
332
  - 前 2 位:L(明度),范围 00-FF,映射到 0-100
332
333
  - 中间 2 位:A(红绿轴),范围 00-FF,映射到 -192 到 192
@@ -337,11 +338,11 @@ Lab 颜色使用 `lab#` 前缀,后跟 6 个十六进制字符:
337
338
  - A = 0xFF = 255 → (255-128) × 1.5 ≈ 190.5
338
339
  - B = 0x80 = 128 → (128-128) × 1.5 = 0
339
340
 
340
- ### LCH 十六进制格式:`lch#L16C16H`
341
+ ### LCH 十六进制格式:`lch#LLCCHHH`
341
342
  LCH 颜色使用 `lch#` 前缀,后跟 6 个字符(最后1-3位是十进制色相值):
342
343
  - 前 2 位:L(明度),范围 00-FF,映射到 0-100
343
344
  - 中间 2 位:C(色度),范围 00-FF,映射到 0-150
344
- - 后 1-3 位:H(色相),范围 0-999,映射到 0-360度
345
+ - 后 1-3 位:H(色相),范围 0-100,映射到 0-360度
345
346
 
346
347
  示例:`lch#8CFF090` 表示:
347
348
  - L = 0x8C = 140 → 140/255 × 100 ≈ 55
@@ -362,8 +363,10 @@ LCH 颜色使用 `lch#` 前缀,后跟 6 个字符(最后1-3位是十进制
362
363
  color: lab(20 40 60);
363
364
  }
364
365
  }
366
+ }
365
367
 
366
- @media (min-width: 768px) {
368
+ @media (min-width: 768px) {
369
+ .container {
367
370
  padding: 2rem;
368
371
 
369
372
  .header {
@@ -493,12 +496,12 @@ $border-radius: 0.5rem;
493
496
  ```css
494
497
  /* 使用十六进制语法创建调色板 */
495
498
  $primary: lab#8CFF80;
496
- $secondary: lch#8CFF180;
497
- $accent: lch#6CFF270;
499
+ $secondary: lch#8CFF18;
500
+ $accent: lch#6CFF27;
498
501
 
499
502
  /* 创建变体 */
500
- $primary-light: lab#B4FFA0;
501
- $primary-dark: lab#64FF60;
503
+ $primary-light: lab#B4FF0A;
504
+ $primary-dark: lab#64FF06;
502
505
  $primary-transparent: lab(55 190 0 / 0.8);
503
506
 
504
507
  .theme {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styimat",
3
- "version": "1.6.3",
3
+ "version": "1.7.0",
4
4
  "description": "一个高效的CSS变量预处理库,支持Lab/LCH颜色空间自动转换、嵌套选择器和Display P3广色域,让现代CSS开发更简洁强大。",
5
5
  "keywords": [
6
6
  "css",
@@ -44,7 +44,7 @@
44
44
  "build:min": "npx terser styimat.js -o styimat.min.js --comments '/^!'",
45
45
  "prepare": "npm run build:min",
46
46
  "prepublishOnly": "npm run build:min",
47
- "postpublish": "git:auto-commit && npm run git:auto-tag",
47
+ "postpublish": "npm run git:auto-commit && npm run git:auto-tag",
48
48
  "release": "npm publish",
49
49
  "publish:patch": "npm version patch --no-git-tag-version && npm publish",
50
50
  "publish:minor": "npm version minor --no-git-tag-version && npm publish",
package/styimat.js CHANGED
@@ -1123,15 +1123,9 @@
1123
1123
  function replaceVariableUses(cssText, globalVariables, selectorVariables, config) {
1124
1124
  let result = cssText;
1125
1125
 
1126
- // 先替换全局变量
1127
- for (const [varName, varValue] of Object.entries(globalVariables)) {
1128
- const varRegex = new RegExp(`\\$${varName}(?![a-zA-Z0-9_-])`, 'g');
1129
- result = result.replace(varRegex, `var(--${varName})`);
1130
- }
1131
-
1132
- // 然后处理选择器特定的变量
1133
- result = result.replace(/\$([a-zA-Z0-9_-]+)/g, (match, varName) => {
1134
- return `var(--${varName})`;
1126
+ // 处理变量
1127
+ result = result.replace(/(?:\$\$|\$)([a-zA-Z0-9_-]+)/g, (match, varName) => {
1128
+ return match.startsWith('$$') ? `attr(${varName})` : `var(--${varName})`;
1135
1129
  });
1136
1130
 
1137
1131
  // 最后处理所有的LAB、LCH颜色和math()函数
@@ -1511,7 +1505,7 @@
1511
1505
 
1512
1506
  // 将API的所有方法复制到主函数上
1513
1507
  Object.assign(styimat, api);
1514
- Object.setPrototypeOf(styimat, Function.prototype);
1508
+ Object.setPrototypeOf(styimat, Function.prototype);
1515
1509
 
1516
1510
  // 自动初始化
1517
1511
  if (typeof window !== 'undefined') {
package/styimat.min.js CHANGED
@@ -392,10 +392,8 @@ if(rule.children&&rule.children.length>0){result+=convertRulesToCSS(rule.childre
392
392
  function replaceVariableUsesInValue(value,variables){return value.replace(/\$([a-zA-Z0-9_-]+)/g,(match,varName)=>{if(variables[varName]){return`var(--${varName})`}return match})}
393
393
  // 替换变量使用
394
394
  function replaceVariableUses(cssText,globalVariables,selectorVariables,config){let result=cssText;
395
- // 先替换全局变量
396
- for(const[varName,varValue]of Object.entries(globalVariables)){const varRegex=new RegExp(`\\$${varName}(?![a-zA-Z0-9_-])`,"g");result=result.replace(varRegex,`var(--${varName})`)}
397
- // 然后处理选择器特定的变量
398
- result=result.replace(/\$([a-zA-Z0-9_-]+)/g,(match,varName)=>`var(--${varName})`);
395
+ // 处理变量
396
+ result=result.replace(/(?:\$\$|\$)([a-zA-Z0-9_-]+)/g,(match,varName)=>match.startsWith("$$")?`attr(${varName})`:`var(--${varName})`);
399
397
  // 最后处理所有的LAB、LCH颜色和math()函数
400
398
  result=processCSSValue(result,config);return result}
401
399
  // 生成根规则