styimat 4.2.1 → 5.0.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
@@ -62,7 +62,7 @@ const css = `
62
62
  .button { background-color: $primary; }
63
63
  `;
64
64
 
65
- const result = styimat.convert(css);
65
+ const result = await styimat.convert(css);
66
66
  console.log(result);
67
67
  ```
68
68
 
@@ -97,7 +97,7 @@ apply();
97
97
 
98
98
  ## 使用方法
99
99
 
100
- ### 一、JavaScript调用
100
+ ### JavaScript调用
101
101
 
102
102
  #### 1. 作为函数调用
103
103
  ```javascript
@@ -110,8 +110,7 @@ const css = await styimat(`
110
110
  // 方式2:传入配置对象(返回函数本身)
111
111
  styimat({
112
112
  enableP3: true,
113
- enableMath: true,
114
- mathPrecision: 8
113
+ enableMath: true
115
114
  });
116
115
 
117
116
  // 方式3:无参数调用(自动处理页面中所有标记的<style>标签)
@@ -162,7 +161,7 @@ styimat.config({
162
161
  });
163
162
 
164
163
  // 4. 使用工具方法
165
- const mathResult = styimat.math.evaluate('100px / 2'); // "50px"
164
+ const mathResult = styimat.math.evaluate('100px/2'); // "calc(100px / 2)"
166
165
  const rgbColor = styimat.colorUtils.labToRGB(54.7, 77.9, 80.1);
167
166
  ```
168
167
 
@@ -202,7 +201,7 @@ const designSystem = await styimat`
202
201
  styimat.apply(designSystem);
203
202
  ```
204
203
 
205
- ### 二、命令行使用
204
+ ### 命令行使用
206
205
 
207
206
  ```bash
208
207
  # 基本用法
@@ -225,9 +224,9 @@ styimat input.css output.css
225
224
 
226
225
  **更多使用方法请 `npx styimat -h`**
227
226
 
228
- ### 三、Styimat语法
227
+ ## Styimat语法
229
228
 
230
- #### 1. 变量定义
229
+ ### 1. 变量定义
231
230
  ```css
232
231
  /* 全局变量 */
233
232
  $primary-color: lab(54.7 77.9 80.1);
@@ -245,7 +244,7 @@ $font-family: 'Inter', sans-serif;
245
244
  }
246
245
  ```
247
246
 
248
- #### 2. 配置头语法
247
+ ### 2. 配置头语法
249
248
  ```css
250
249
  #indent-size 4
251
250
  #auto-process-style-tags true
@@ -254,43 +253,42 @@ $font-family: 'Inter', sans-serif;
254
253
  #root-selector :root
255
254
  #enable-nesting true
256
255
  #enable-math true
257
- #math-precision 8
258
256
 
259
257
  /* 然后写您的CSS代码 */
260
258
  $primary-color: lab#32a852;
261
- $spacing: math(16px * 2 + 4px);
259
+ $spacing: math(16px*2+4px);
262
260
 
263
261
  body {
264
262
  color: $primary-color;
265
263
  padding: $spacing;
266
264
 
267
265
  .container {
268
- margin: math($spacing / 2);
266
+ margin: math($spacing/2);
269
267
  }
270
268
  }
271
269
  ```
272
270
 
273
271
  **注意**:配置头既支持驼峰命名也支持连字符命名,例如 `indent-size` 和 `indentSize` 效果相同。
274
272
 
275
- #### 3. 导入语法
273
+ ### 3. 导入语法
276
274
  ```css
277
275
  @import yourcss.css;
278
276
 
279
277
  /* 然后写您的CSS代码 */
280
278
  $primary-color: lab#32a852;
281
- $spacing: math(16px * 2 + 4px);
279
+ $spacing: math(16px*2+4px);
282
280
 
283
281
  body {
284
282
  color: $primary-color;
285
283
  padding: $spacing;
286
284
 
287
285
  .container {
288
- margin: math($spacing / 2);
286
+ margin: math($spacing/2);
289
287
  }
290
288
  }
291
289
  ```
292
290
 
293
- #### 4. 别名语法
291
+ ### 4. 别名语法
294
292
  ```css
295
293
  @alias bg background-color;
296
294
 
@@ -302,7 +300,7 @@ body {
302
300
  }
303
301
  ```
304
302
 
305
- #### 5. 宏语法
303
+ ### 5. 宏语法
306
304
  ```css
307
305
  @macro grid($columns, $gap: 10px) {
308
306
  display: grid;
@@ -312,10 +310,12 @@ body {
312
310
 
313
311
  .container {
314
312
  @grid(3, 20px);
313
+ // 也可以
314
+ @grid: 3 20px;
315
315
  }
316
316
  ```
317
317
 
318
- #### 6. Math计算语法
318
+ ### 6. Math计算语法
319
319
  ```css
320
320
  /* math() 函数 */
321
321
  .element {
@@ -332,7 +332,7 @@ body {
332
332
  }
333
333
  ```
334
334
 
335
- #### 7. Lab颜色语法
335
+ ### 7. Lab颜色语法
336
336
  ```css
337
337
  /* 标准 lab() 函数 */
338
338
  .element {
@@ -346,7 +346,7 @@ body {
346
346
  }
347
347
  ```
348
348
 
349
- #### 8. LCH颜色语法
349
+ ### 8. LCH颜色语法
350
350
  ```css
351
351
  /* 标准 lch() 函数 */
352
352
  .element {
@@ -360,7 +360,7 @@ body {
360
360
  }
361
361
  ```
362
362
 
363
- #### 9. 嵌套规则
363
+ ### 9. 嵌套规则
364
364
  ```css
365
365
  /* Sass 风格的嵌套 */
366
366
  .container {
@@ -386,7 +386,7 @@ body {
386
386
  }
387
387
  ```
388
388
 
389
- #### 10. 嵌套变量
389
+ ### 10. 嵌套变量
390
390
  ```css
391
391
  /* 变量可以引用其他变量 */
392
392
  $base-color: lab(54.7 77.9 80.1);
@@ -411,7 +411,7 @@ $padding-large: math(2rem * 1.5);
411
411
  const styimat = require('styimat');
412
412
 
413
413
  // 转换 CSS
414
- const css = styimat.convert(cssString, config);
414
+ const cssPromise = styimat.convert(cssString, config);
415
415
 
416
416
  // 应用到页面
417
417
  styimat.apply(cssString, config);
@@ -424,7 +424,6 @@ styimat.config({
424
424
  convertLchToRGB: true,
425
425
  enableP3: true,
426
426
  enableMath: true,
427
- mathPrecision: 6,
428
427
  indentSize: 4,
429
428
  enableNesting: true,
430
429
  importBaseUrl: '', // 导入基础URL
@@ -436,8 +435,8 @@ styimat.config({
436
435
  });
437
436
 
438
437
  // 数学工具
439
- styimat.math.evaluate('100px / 2'); // "50px"
440
- styimat.math.evaluate('(16px * 1.5) + 4px'); // "28px"
438
+ styimat.math.evaluate('100px/2'); // "calc(100px / 2)"
439
+ styimat.math.evaluate('(16px*1.5)+4px'); // "calc((16px * 1.5) + 4px)"
441
440
 
442
441
  // 颜色工具
443
442
  const rgb = styimat.colorUtils.labToRGB(54.7, 77.9, 80.1);
@@ -452,6 +451,26 @@ styimat.imports.clearCache(); // 清除导入缓存
452
451
  styimat.imports.setBaseUrl('/css/'); // 设置导入基础URL
453
452
  styimat.imports.setCacheEnabled(false); // 禁用导入缓存
454
453
  styimat.imports.setTimeout(10000); // 设置导入超时时间
454
+
455
+ // 设置插件
456
+ styimat.plugins.compress = {
457
+ enable: true,
458
+ convert: function(css, config) {
459
+ return css.replace(/[\n\b]/g, "");
460
+ },
461
+ created() {
462
+ // 创建时调用
463
+ },
464
+ deleted() {
465
+ // 删除时调用
466
+ }
467
+ };
468
+
469
+ delete styimat.plugins.compress; // 删除插件
470
+
471
+ for(const name in styimat.plugins) {
472
+ console.log(name);
473
+ }
455
474
  ```
456
475
 
457
476
  ### 配置选项
@@ -469,7 +488,6 @@ styimat.imports.setTimeout(10000); // 设置导入超时时间
469
488
  | `convertLchToRGB` | boolean | `true` | 是否转换 LCH 颜色为 RGB |
470
489
  | `enableP3` | boolean | `true` | 是否启用 Display P3 广色域支持 |
471
490
  | `enableMath` | boolean | `true` | 是否启用 `math()` 函数增强 |
472
- | `mathPrecision` | number | `6` | 数学计算的精度 |
473
491
  | `importBaseUrl` | string | ` | 导入的基础URL |
474
492
  | `importCache` | boolean | `true` | 是否缓存导入的文件 |
475
493
  | `importTimeout` | number | `5000` | 导入超时时间(毫秒) |
package/bin/cli.js CHANGED
@@ -163,7 +163,7 @@ async function convertAndOutput(inputContent, outputFile) {
163
163
  if (outputFile) {
164
164
  fs.writeFileSync(outputFile, outputContent, 'utf8');
165
165
  } else {
166
- process.stdout.write(outputContent + '\n');
166
+ process.stdout.write(outputContent);
167
167
  }
168
168
  } catch (error) {
169
169
  console.error('转换错误:', error.message);