@slimr/css 2.1.74 → 2.1.76

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.
@@ -1,7 +1,7 @@
1
- import {T2SProps, t2s} from '@slimr/util'
1
+ import { type T2SProps, t2s } from "@slimr/util"
2
2
 
3
- import {addCss} from './addCss.js'
4
- import {expandShorthands} from './shorthandProps.js'
3
+ import { addCss } from "./addCss.js"
4
+ import { expandShorthands } from "./shorthandProps.js"
5
5
 
6
6
  /**
7
7
  * Joins class names and omits falsey props
@@ -18,7 +18,7 @@ import {expandShorthands} from './shorthandProps.js'
18
18
  * ```
19
19
  */
20
20
  export function classJoin(...classes: (string | 0 | null | undefined)[]) {
21
- return classes.filter(c => c && typeof c === 'string').join(' ')
21
+ return classes.filter((c) => c && typeof c === "string").join(" ")
22
22
  }
23
23
 
24
24
  /**
@@ -43,50 +43,50 @@ export function classJoin(...classes: (string | 0 | null | undefined)[]) {
43
43
  * ...and the queue will be executed next javascript tick
44
44
  */
45
45
  export function createClass(...p: T2SProps) {
46
- let css = t2s(...p)
47
- if (!css) return ''
48
- let className = createClass.history.get(css)
49
- if (!className) {
50
- className = 's' + createClass.count++
51
- createClass.history.set(css, className)
46
+ let css = t2s(...p)
47
+ if (!css) return ""
48
+ let className = createClass.history.get(css)
49
+ if (!className) {
50
+ className = `s${createClass.count++}`
51
+ createClass.history.set(css, className)
52
52
 
53
- css = deleteComments(css)
54
- css = expandShorthands(css)
55
- css = expandArrayValues(css)
56
- const qs = findQueries(css)
53
+ css = deleteComments(css)
54
+ css = expandShorthands(css)
55
+ css = expandArrayValues(css)
56
+ const qs = findQueries(css)
57
57
 
58
- for (const q of qs.reverse()) {
59
- css = css.slice(0, q.start) + css.slice(q.end)
60
- }
61
- qs.reverse()
58
+ for (const q of qs.reverse()) {
59
+ css = css.slice(0, q.start) + css.slice(q.end)
60
+ }
61
+ qs.reverse()
62
62
 
63
- css = `.${className}{\n${css}\n}\n`
64
- css += qs
65
- .map(q => {
66
- if (q.query.startsWith('&')) {
67
- return `.${className}${q.query.slice(1)}{\n${q.innerBody}\n}`
68
- }
69
- if (q.query.startsWith('@keyframes')) {
70
- return q.outerBody
71
- }
72
- return `${q.query}{\n.${className}{${q.innerBody}\n}\n}`
73
- })
74
- .join('\n')
63
+ css = `.${className}{\n${css}\n}\n`
64
+ css += qs
65
+ .map((q) => {
66
+ if (q.query.startsWith("&")) {
67
+ return `.${className}${q.query.slice(1)}{\n${q.innerBody}\n}`
68
+ }
69
+ if (q.query.startsWith("@keyframes")) {
70
+ return q.outerBody
71
+ }
72
+ return `${q.query}{\n.${className}{${q.innerBody}\n}\n}`
73
+ })
74
+ .join("\n")
75
75
 
76
- css = trimByLine(css) + '\n\n'
76
+ css = `${trimByLine(css)}\n\n`
77
77
 
78
- addCss(css)
79
- }
80
- return className
78
+ addCss(css)
79
+ }
80
+ return className
81
81
  }
82
82
  /** Breakpoints like chakra */
83
- createClass.breakPoints = ['30em', '48em', '62em', '80em', '96em']
83
+ createClass.breakPoints = ["30em", "48em", "62em", "80em", "96em"]
84
84
  createClass.count = 0
85
85
  createClass.history = new Map<string, string>()
86
86
 
87
87
  /** delete css comments **/
88
88
  function deleteComments(css: string) {
89
- return css.replace(/{\/\*[\s\S]*?(?=\*\/})\*\/}/gm, '')
89
+ return css.replace(/{\/\*[\s\S]*?(?=\*\/})\*\/}/gm, "")
90
90
  }
91
91
 
92
92
  /**
@@ -95,82 +95,82 @@ function deleteComments(css: string) {
95
95
  * Inspired by https://chakra-ui.com/docs/styled-system/responsive-styles
96
96
  */
97
97
  function expandArrayValues(css: string) {
98
- if (!css.includes('[')) return css
99
- return css
100
- .split('\n')
101
- .map(l => {
102
- // eslint-disable-next-line no-useless-escape
103
- const [, prop, valArrayStr] = [...l.matchAll(/([A-Za-z\-]*):[ ]*\[([^\]]+)\]/g)]?.[0] ?? []
104
- if (valArrayStr) {
105
- return (
106
- valArrayStr
107
- // Replace commas inside css functions with a magic char (§) to prevent
108
- // erroneous splitting
109
- .replace(/\([^),]*,/g, m => m.replace(/,/g, '§'))
110
- .replace(/\([^),]*,/g, m => m.replace(/,/g, '§'))
111
- .replace(/\([^),]*,/g, m => m.replace(/,/g, '§'))
112
- .split(',')
113
- .map((val, i) => {
114
- val = val.trim()
115
- if (!val || val === 'null' || val === 'undefined') return ''
116
- val = val.replace(/§/g, ',')
117
- if (i === 0) {
118
- return `${prop}: ${val};`
119
- }
120
- return `@media (min-width: ${createClass.breakPoints[i - 1]}) { ${prop}: ${val}; }`
121
- })
122
- .join('\n')
123
- )
124
- }
125
- return l
126
- })
127
- .join('\n')
98
+ if (!css.includes("[")) return css
99
+ return css
100
+ .split("\n")
101
+ .map((l) => {
102
+ // eslint-disable-next-line no-useless-escape
103
+ const [, prop, valArrayStr] = [...l.matchAll(/([A-Za-z-]*):[ ]*\[([^\]]+)\]/g)]?.[0] ?? []
104
+ if (valArrayStr) {
105
+ return (
106
+ valArrayStr
107
+ // Replace commas inside css functions with a magic char (§) to prevent
108
+ // erroneous splitting
109
+ .replace(/\([^),]*,/g, (m) => m.replace(/,/g, "§"))
110
+ .replace(/\([^),]*,/g, (m) => m.replace(/,/g, "§"))
111
+ .replace(/\([^),]*,/g, (m) => m.replace(/,/g, "§"))
112
+ .split(",")
113
+ .map((val, i) => {
114
+ val = val.trim()
115
+ if (!val || val === "null" || val === "undefined") return ""
116
+ val = val.replace(/§/g, ",")
117
+ if (i === 0) {
118
+ return `${prop}: ${val};`
119
+ }
120
+ return `@media (min-width: ${createClass.breakPoints[i - 1]}) { ${prop}: ${val}; }`
121
+ })
122
+ .join("\n")
123
+ )
124
+ }
125
+ return l
126
+ })
127
+ .join("\n")
128
128
  }
129
129
 
130
130
  /** Find @keyframes, @media, @container queries in css **/
131
131
  function findQueries(css: string) {
132
- const queries: {
133
- start: number
134
- end: number
135
- query: string
136
- outerBody: string
137
- innerBody: string
138
- }[] = []
139
- for (const m of css.matchAll(/[@&]/gm)) {
140
- let query = ''
141
- let bodyStart = 0
142
- let openCount = 0
143
- for (let i = m.index!; i < css.length; i++) {
144
- if (css[i] === '{') {
145
- if (openCount === 0) {
146
- query = css.slice(m.index, i).trim()
147
- bodyStart = i + 1
148
- }
149
- openCount++
150
- } else if (css[i] === '}') {
151
- openCount--
152
- if (openCount === 0) {
153
- queries.push({
154
- start: m.index!,
155
- end: i + 1,
156
- query,
157
- outerBody: css.slice(m.index, i + 1),
158
- innerBody: css.slice(bodyStart, i),
159
- })
160
- break
161
- }
162
- }
163
- }
164
- if (openCount !== 0) console.error(`${query} not closed: "${css}"`)
165
- }
166
- return queries
132
+ const queries: {
133
+ start: number
134
+ end: number
135
+ query: string
136
+ outerBody: string
137
+ innerBody: string
138
+ }[] = []
139
+ for (const m of css.matchAll(/[@&]/gm)) {
140
+ let query = ""
141
+ let bodyStart = 0
142
+ let openCount = 0
143
+ for (let i = m.index!; i < css.length; i++) {
144
+ if (css[i] === "{") {
145
+ if (openCount === 0) {
146
+ query = css.slice(m.index, i).trim()
147
+ bodyStart = i + 1
148
+ }
149
+ openCount++
150
+ } else if (css[i] === "}") {
151
+ openCount--
152
+ if (openCount === 0) {
153
+ queries.push({
154
+ start: m.index!,
155
+ end: i + 1,
156
+ query,
157
+ outerBody: css.slice(m.index, i + 1),
158
+ innerBody: css.slice(bodyStart, i),
159
+ })
160
+ break
161
+ }
162
+ }
163
+ }
164
+ if (openCount !== 0) console.error(`${query} not closed: "${css}"`)
165
+ }
166
+ return queries
167
167
  }
168
168
 
169
169
  /** Trims whitespace for every line */
170
170
  function trimByLine(css: string) {
171
- return css
172
- .split('\n')
173
- .map(l => l.trim())
174
- .filter(l => l)
175
- .join('\n')
171
+ return css
172
+ .split("\n")
173
+ .map((l) => l.trim())
174
+ .filter((l) => l)
175
+ .join("\n")
176
176
  }
package/esm/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './addCss.js';
2
- export * from './createClass.js';
3
- export * from './shorthandProps.js';
4
- export { createClass as css } from './createClass.js';
1
+ export * from "./addCss.js";
2
+ export * from "./createClass.js";
3
+ export { createClass as css } from "./createClass.js";
4
+ export * from "./shorthandProps.js";
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from './addCss.js';
2
- export * from './createClass.js';
3
- export * from './shorthandProps.js';
4
- export { createClass as css } from './createClass.js';
1
+ export * from "./addCss.js";
2
+ export * from "./createClass.js";
3
+ export { createClass as css } from "./createClass.js";
4
+ export * from "./shorthandProps.js";
5
5
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAC,WAAW,IAAI,GAAG,EAAC,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACrD,cAAc,qBAAqB,CAAA"}
package/esm/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './addCss.js'
2
- export * from './createClass.js'
3
- export * from './shorthandProps.js'
4
- export {createClass as css} from './createClass.js'
1
+ export * from "./addCss.js"
2
+ export * from "./createClass.js"
3
+ export { createClass as css } from "./createClass.js"
4
+ export * from "./shorthandProps.js"
@@ -72,4 +72,4 @@ export declare function expandShorthands(css: string): string;
72
72
  /**
73
73
  * Map shorthand props to their full css prop
74
74
  */
75
- export declare const shorthandPropsMap: Record<keyof Omit<ShorthandProps, 'mx' | 'my' | 'px' | 'py'>, string>;
75
+ export declare const shorthandPropsMap: Record<keyof Omit<ShorthandProps, "mx" | "my" | "px" | "py">, string>;
@@ -2,13 +2,13 @@
2
2
  * Expand short-hand css props to full
3
3
  */
4
4
  export function expandShorthands(css) {
5
- css = '\n' + css; // inject a newline to make the regex easier
5
+ css = `\n${css}`; // inject a newline to make the regex easier
6
6
  // Handle 'mx', 'my', 'px', 'py'
7
7
  css = css
8
- .replace(/([mp])x:([^;]*)/g, '$1l:$2;\n$1r:$2')
9
- .replace(/([mp])y:([^;]*);/g, '$1t:$2;\n$1b:$2');
8
+ .replace(/([mp])x:([^;]*)/g, "$1l:$2;\n$1r:$2")
9
+ .replace(/([mp])y:([^;]*);/g, "$1t:$2;\n$1b:$2");
10
10
  Object.entries(shorthandPropsMap).forEach(([k, v]) => {
11
- css = css.replace(new RegExp(`([ \n\t;])${k}:`, 'g'), `$1${v}:`);
11
+ css = css.replace(new RegExp(`([ \n\t;])${k}:`, "g"), `$1${v}:`);
12
12
  });
13
13
  return css.trim();
14
14
  }
@@ -16,32 +16,32 @@ export function expandShorthands(css) {
16
16
  * Map shorthand props to their full css prop
17
17
  */
18
18
  export const shorthandPropsMap = {
19
- ai: 'align-items',
20
- b: 'border',
21
- br: 'border-radius',
22
- bg: 'background',
23
- c: 'color',
24
- d: 'display',
25
- f: 'flex',
26
- fd: 'flex-direction',
27
- i: 'inset',
28
- h: 'height',
29
- jc: 'justify-content',
30
- m: 'margin',
31
- ml: 'margin-left',
32
- mr: 'margin-right',
33
- mt: 'margin-top',
34
- mb: 'margin-bottom',
35
- maxW: 'max-width',
36
- minW: 'min-width',
37
- p: 'padding',
38
- pl: 'padding-left',
39
- pr: 'padding-right',
40
- pt: 'padding-top',
41
- pb: 'padding-bottom',
42
- pos: 'position',
43
- ta: 'text-align',
44
- w: 'width',
45
- z: 'z-index',
19
+ ai: "align-items",
20
+ b: "border",
21
+ br: "border-radius",
22
+ bg: "background",
23
+ c: "color",
24
+ d: "display",
25
+ f: "flex",
26
+ fd: "flex-direction",
27
+ i: "inset",
28
+ h: "height",
29
+ jc: "justify-content",
30
+ m: "margin",
31
+ ml: "margin-left",
32
+ mr: "margin-right",
33
+ mt: "margin-top",
34
+ mb: "margin-bottom",
35
+ maxW: "max-width",
36
+ minW: "min-width",
37
+ p: "padding",
38
+ pl: "padding-left",
39
+ pr: "padding-right",
40
+ pt: "padding-top",
41
+ pb: "padding-bottom",
42
+ pos: "position",
43
+ ta: "text-align",
44
+ w: "width",
45
+ z: "z-index",
46
46
  };
47
47
  //# sourceMappingURL=shorthandProps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shorthandProps.js","sourceRoot":"","sources":["../src/shorthandProps.ts"],"names":[],"mappings":"AAoEA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,GAAG,GAAG,IAAI,GAAG,GAAG,CAAA,CAAC,4CAA4C;IAC7D,gCAAgC;IAChC,GAAG,GAAG,GAAG;SACN,OAAO,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;SAC9C,OAAO,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAAA;IAClD,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QACnD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IAClE,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAG1B;IACF,EAAE,EAAE,aAAa;IACjB,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,YAAY;IAChB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,MAAM;IACT,EAAE,EAAE,gBAAgB;IACpB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,iBAAiB;IACrB,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,eAAe;IACnB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,WAAW;IACjB,CAAC,EAAE,SAAS;IACZ,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,gBAAgB;IACpB,GAAG,EAAE,UAAU;IACf,EAAE,EAAE,YAAY;IAChB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,SAAS;CACb,CAAA"}
1
+ {"version":3,"file":"shorthandProps.js","sourceRoot":"","sources":["../src/shorthandProps.ts"],"names":[],"mappings":"AAoEA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,GAAG,GAAG,KAAK,GAAG,EAAE,CAAA,CAAC,4CAA4C;IAC7D,gCAAgC;IAChC,GAAG,GAAG,GAAG;SACP,OAAO,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;SAC9C,OAAO,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAAA;IACjD,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QACpD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAG1B;IACH,EAAE,EAAE,aAAa;IACjB,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,YAAY;IAChB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,MAAM;IACT,EAAE,EAAE,gBAAgB;IACpB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,iBAAiB;IACrB,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,eAAe;IACnB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,WAAW;IACjB,CAAC,EAAE,SAAS;IACZ,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,gBAAgB;IACpB,GAAG,EAAE,UAAU;IACf,EAAE,EAAE,YAAY;IAChB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,SAAS;CACZ,CAAA"}
@@ -2,117 +2,117 @@
2
2
  * All the shorthand props that can be used in the css prop
3
3
  */
4
4
  export interface ShorthandProps {
5
- /** shorthand for css:align-items */
6
- ai?: string
7
- /** shorthand for css:border */
8
- b?: string | number
9
- /** shorthand for css:border-radius */
10
- br?: string | number
11
- /** shorthand for css:background */
12
- bg?: string
13
- /** shorthand for css:color */
14
- c?: string
15
- /** shorthand for css:display */
16
- d?: string
17
- /** shorthand for css:flex */
18
- f?: string
19
- /** shorthand for css:flex-direction */
20
- fd?: string
21
- /** shorthand for css:height */
22
- h?: number | string
23
- /** shorthand for css:inset */
24
- i?: number | string
25
- /** shorthand for css:justify-content */
26
- jc?: string
27
- /** shorthand for css:margin */
28
- m?: number | string
29
- /** shorthand for css:margin-left */
30
- ml?: number | string
31
- /** shorthand for css:margin-right */
32
- mr?: number | string
33
- /** shorthand for css:margin-top */
34
- mt?: number | string
35
- /** shorthand for css:margin-bottom */
36
- mb?: number | string
37
- /** shorthand for css:margin-top & margin-bottom */
38
- my?: number | string
39
- /** shorthand for css:margin-left & margin-right */
40
- mx?: number | string
41
- /** shorthand for css:max-width */
42
- maxW?: number | string
43
- /** shorthand for css:min-width */
44
- minW?: number | string
45
- /** shorthand for css:padding */
46
- p?: number | string
47
- /** shorthand for css:padding-left */
48
- pl?: number | string
49
- /** shorthand for css:padding-right */
50
- pr?: number | string
51
- /** shorthand for css:padding-top */
52
- pt?: number | string
53
- /** shorthand for css:padding-bottom */
54
- pb?: number | string
55
- /** shorthand for css:padding-top & padding-bottom */
56
- py?: number | string
57
- /** shorthand for css:padding-left & padding-right */
58
- px?: number | string
59
- /** shorthand for css:position */
60
- pos?: number | string
61
- /** shorthand for css:text-align */
62
- ta?: string
63
- /** shorthand for css:width */
64
- w?: number | string
65
- /** shorthand for css:z-index */
66
- z?: number | string
5
+ /** shorthand for css:align-items */
6
+ ai?: string
7
+ /** shorthand for css:border */
8
+ b?: string | number
9
+ /** shorthand for css:border-radius */
10
+ br?: string | number
11
+ /** shorthand for css:background */
12
+ bg?: string
13
+ /** shorthand for css:color */
14
+ c?: string
15
+ /** shorthand for css:display */
16
+ d?: string
17
+ /** shorthand for css:flex */
18
+ f?: string
19
+ /** shorthand for css:flex-direction */
20
+ fd?: string
21
+ /** shorthand for css:height */
22
+ h?: number | string
23
+ /** shorthand for css:inset */
24
+ i?: number | string
25
+ /** shorthand for css:justify-content */
26
+ jc?: string
27
+ /** shorthand for css:margin */
28
+ m?: number | string
29
+ /** shorthand for css:margin-left */
30
+ ml?: number | string
31
+ /** shorthand for css:margin-right */
32
+ mr?: number | string
33
+ /** shorthand for css:margin-top */
34
+ mt?: number | string
35
+ /** shorthand for css:margin-bottom */
36
+ mb?: number | string
37
+ /** shorthand for css:margin-top & margin-bottom */
38
+ my?: number | string
39
+ /** shorthand for css:margin-left & margin-right */
40
+ mx?: number | string
41
+ /** shorthand for css:max-width */
42
+ maxW?: number | string
43
+ /** shorthand for css:min-width */
44
+ minW?: number | string
45
+ /** shorthand for css:padding */
46
+ p?: number | string
47
+ /** shorthand for css:padding-left */
48
+ pl?: number | string
49
+ /** shorthand for css:padding-right */
50
+ pr?: number | string
51
+ /** shorthand for css:padding-top */
52
+ pt?: number | string
53
+ /** shorthand for css:padding-bottom */
54
+ pb?: number | string
55
+ /** shorthand for css:padding-top & padding-bottom */
56
+ py?: number | string
57
+ /** shorthand for css:padding-left & padding-right */
58
+ px?: number | string
59
+ /** shorthand for css:position */
60
+ pos?: number | string
61
+ /** shorthand for css:text-align */
62
+ ta?: string
63
+ /** shorthand for css:width */
64
+ w?: number | string
65
+ /** shorthand for css:z-index */
66
+ z?: number | string
67
67
  }
68
68
 
69
69
  /**
70
70
  * Expand short-hand css props to full
71
71
  */
72
72
  export function expandShorthands(css: string) {
73
- css = '\n' + css // inject a newline to make the regex easier
74
- // Handle 'mx', 'my', 'px', 'py'
75
- css = css
76
- .replace(/([mp])x:([^;]*)/g, '$1l:$2;\n$1r:$2')
77
- .replace(/([mp])y:([^;]*);/g, '$1t:$2;\n$1b:$2')
78
- Object.entries(shorthandPropsMap).forEach(([k, v]) => {
79
- css = css.replace(new RegExp(`([ \n\t;])${k}:`, 'g'), `$1${v}:`)
80
- })
81
- return css.trim()
73
+ css = `\n${css}` // inject a newline to make the regex easier
74
+ // Handle 'mx', 'my', 'px', 'py'
75
+ css = css
76
+ .replace(/([mp])x:([^;]*)/g, "$1l:$2;\n$1r:$2")
77
+ .replace(/([mp])y:([^;]*);/g, "$1t:$2;\n$1b:$2")
78
+ Object.entries(shorthandPropsMap).forEach(([k, v]) => {
79
+ css = css.replace(new RegExp(`([ \n\t;])${k}:`, "g"), `$1${v}:`)
80
+ })
81
+ return css.trim()
82
82
  }
83
83
 
84
84
  /**
85
85
  * Map shorthand props to their full css prop
86
86
  */
87
87
  export const shorthandPropsMap: Record<
88
- keyof Omit<ShorthandProps, 'mx' | 'my' | 'px' | 'py'>,
89
- string
88
+ keyof Omit<ShorthandProps, "mx" | "my" | "px" | "py">,
89
+ string
90
90
  > = {
91
- ai: 'align-items',
92
- b: 'border',
93
- br: 'border-radius',
94
- bg: 'background',
95
- c: 'color',
96
- d: 'display',
97
- f: 'flex',
98
- fd: 'flex-direction',
99
- i: 'inset',
100
- h: 'height',
101
- jc: 'justify-content',
102
- m: 'margin',
103
- ml: 'margin-left',
104
- mr: 'margin-right',
105
- mt: 'margin-top',
106
- mb: 'margin-bottom',
107
- maxW: 'max-width',
108
- minW: 'min-width',
109
- p: 'padding',
110
- pl: 'padding-left',
111
- pr: 'padding-right',
112
- pt: 'padding-top',
113
- pb: 'padding-bottom',
114
- pos: 'position',
115
- ta: 'text-align',
116
- w: 'width',
117
- z: 'z-index',
91
+ ai: "align-items",
92
+ b: "border",
93
+ br: "border-radius",
94
+ bg: "background",
95
+ c: "color",
96
+ d: "display",
97
+ f: "flex",
98
+ fd: "flex-direction",
99
+ i: "inset",
100
+ h: "height",
101
+ jc: "justify-content",
102
+ m: "margin",
103
+ ml: "margin-left",
104
+ mr: "margin-right",
105
+ mt: "margin-top",
106
+ mb: "margin-bottom",
107
+ maxW: "max-width",
108
+ minW: "min-width",
109
+ p: "padding",
110
+ pl: "padding-left",
111
+ pr: "padding-right",
112
+ pt: "padding-top",
113
+ pb: "padding-bottom",
114
+ pos: "position",
115
+ ta: "text-align",
116
+ w: "width",
117
+ z: "z-index",
118
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slimr/css",
3
- "version": "2.1.74",
3
+ "version": "2.1.76",
4
4
  "author": "Brian Dombrowski",
5
5
  "license": "ISC",
6
6
  "private": false,
@@ -34,6 +34,6 @@
34
34
  "start": "nodemon -w src -e '*' -x 'npm run build && cd ../demo && npm start'"
35
35
  },
36
36
  "dependencies": {
37
- "@slimr/util": "^3.2.67"
37
+ "@slimr/util": "^3.2.69"
38
38
  }
39
39
  }