Skip to content

Commit

Permalink
line the style
Browse files Browse the repository at this point in the history
  • Loading branch information
Shirtiny committed Dec 14, 2021
1 parent ff674a1 commit ce1937f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ import { Shape, Slider } from "./shape";
/*
* @Author: Shirtiny
* @Date: 2021-06-23 16:31:16
* @LastEditTime: 2021-06-24 22:57:31
* @LastEditTime: 2021-12-14 15:21:11
* @Description:
*/

export const css = (
literals: TemplateStringsArray,
...values: Array<string | number>
) => {
type Text = string | number;

const line = (str?: string) => {
return str ? str.replace(/\s*(;|\{|\})+\s*[\n\r]*/g, "$1") : "";
};

export const css = (literals: TemplateStringsArray, ...values: Text[]) => {
// 模板字符串无变量时 values为空数组 literals数组只有一个值 是模版字符串本身
if (values.length === 0) {
return literals[0];
if (!values.length) {
return line(literals[0]);
}

let cssStr: string = "";

values.forEach((value, index) => {
cssStr += literals[index] + value;
});
// literals总比values多一个 遍历values完毕后 还剩一个literal没有加上
cssStr += literals[literals.length - 1];
return cssStr;
return line(cssStr);
};

type cssParam = {
Expand Down

0 comments on commit ce1937f

Please sign in to comment.