@pyreon/unistyle 0.11.4 → 0.11.6

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.
Files changed (40) hide show
  1. package/README.md +39 -34
  2. package/lib/index.d.ts +13 -8
  3. package/lib/index.js +9 -4
  4. package/package.json +24 -24
  5. package/src/__tests__/alignContent.test.ts +57 -57
  6. package/src/__tests__/borderRadius.test.ts +40 -40
  7. package/src/__tests__/camelToKebab.test.ts +23 -23
  8. package/src/__tests__/context.test.ts +28 -28
  9. package/src/__tests__/createMediaQueries.test.ts +21 -21
  10. package/src/__tests__/edge.test.ts +76 -76
  11. package/src/__tests__/enrichTheme.test.ts +13 -13
  12. package/src/__tests__/index.test.ts +31 -31
  13. package/src/__tests__/makeItResponsive.test.ts +32 -32
  14. package/src/__tests__/processDescriptor.test.ts +107 -107
  15. package/src/__tests__/responsive.test.ts +66 -66
  16. package/src/__tests__/styles.test.ts +52 -52
  17. package/src/__tests__/units.test.ts +63 -63
  18. package/src/context.tsx +11 -6
  19. package/src/enrichTheme.ts +3 -3
  20. package/src/index.ts +11 -11
  21. package/src/responsive/createMediaQueries.ts +4 -4
  22. package/src/responsive/index.ts +14 -14
  23. package/src/responsive/makeItResponsive.ts +9 -9
  24. package/src/responsive/normalizeTheme.ts +2 -2
  25. package/src/responsive/transformTheme.ts +2 -2
  26. package/src/styles/alignContent.ts +14 -14
  27. package/src/styles/extendCss.ts +4 -4
  28. package/src/styles/index.ts +6 -6
  29. package/src/styles/shorthands/borderRadius.ts +6 -6
  30. package/src/styles/shorthands/edge.ts +29 -29
  31. package/src/styles/shorthands/index.ts +4 -4
  32. package/src/styles/styles/index.ts +6 -6
  33. package/src/styles/styles/processDescriptor.ts +31 -31
  34. package/src/styles/styles/propertyMap.ts +326 -326
  35. package/src/styles/styles/utils.ts +4 -4
  36. package/src/types.ts +155 -155
  37. package/src/units/index.ts +6 -6
  38. package/src/units/stripUnit.ts +1 -1
  39. package/src/units/value.ts +20 -20
  40. package/src/units/values.ts +18 -18
@@ -1,33 +1,33 @@
1
- import { isEmpty } from "@pyreon/ui-core"
1
+ import { isEmpty } from '@pyreon/ui-core'
2
2
 
3
3
  export type AlignContentDirectionKeys = keyof typeof ALIGN_CONTENT_DIRECTION
4
4
  export type AlignContentAlignXKeys = keyof typeof ALIGN_CONTENT_MAP_X
5
5
  export type AlignContentAlignYKeys = keyof typeof ALIGN_CONTENT_MAP_Y
6
6
 
7
7
  const ALIGN_CONTENT_MAP_SHARED = {
8
- center: "center",
9
- spaceBetween: "space-between",
10
- spaceAround: "space-around",
11
- block: "stretch",
8
+ center: 'center',
9
+ spaceBetween: 'space-between',
10
+ spaceAround: 'space-around',
11
+ block: 'stretch',
12
12
  }
13
13
 
14
14
  export const ALIGN_CONTENT_MAP_X = {
15
- left: "flex-start",
16
- right: "flex-end",
15
+ left: 'flex-start',
16
+ right: 'flex-end',
17
17
  ...ALIGN_CONTENT_MAP_SHARED,
18
18
  } as const
19
19
 
20
20
  export const ALIGN_CONTENT_MAP_Y = {
21
- top: "flex-start",
22
- bottom: "flex-end",
21
+ top: 'flex-start',
22
+ bottom: 'flex-end',
23
23
  ...ALIGN_CONTENT_MAP_SHARED,
24
24
  } as const
25
25
 
26
26
  export const ALIGN_CONTENT_DIRECTION = {
27
- inline: "row",
28
- reverseInline: "row-reverse",
29
- rows: "column",
30
- reverseRows: "column-reverse",
27
+ inline: 'row',
28
+ reverseInline: 'row-reverse',
29
+ rows: 'column',
30
+ reverseRows: 'column-reverse',
31
31
  } as const
32
32
 
33
33
  export type AlignContent = ({
@@ -47,7 +47,7 @@ const alignContent: AlignContent = (attrs) => {
47
47
  return null
48
48
  }
49
49
 
50
- const isReverted = ["inline", "reverseInline"].includes(direction)
50
+ const isReverted = ['inline', 'reverseInline'].includes(direction)
51
51
  const dir = ALIGN_CONTENT_DIRECTION[direction]
52
52
  const x = ALIGN_CONTENT_MAP_X[alignX]
53
53
  const y = ALIGN_CONTENT_MAP_Y[alignY]
@@ -7,17 +7,17 @@ export type ExtendCss = (
7
7
  ) => string
8
8
 
9
9
  const simpleCss = (strings: TemplateStringsArray, ...values: any[]): string => {
10
- let result = ""
10
+ let result = ''
11
11
  for (let i = 0; i < strings.length; i++) {
12
12
  result += strings[i]
13
- if (i < values.length) result += String(values[i] ?? "")
13
+ if (i < values.length) result += String(values[i] ?? '')
14
14
  }
15
15
  return result
16
16
  }
17
17
 
18
18
  const extendCss: ExtendCss = (styles) => {
19
- if (!styles) return ""
20
- if (typeof styles === "function") {
19
+ if (!styles) return ''
20
+ if (typeof styles === 'function') {
21
21
  return styles(simpleCss)
22
22
  }
23
23
  return styles
@@ -3,14 +3,14 @@ export type {
3
3
  AlignContentAlignXKeys,
4
4
  AlignContentAlignYKeys,
5
5
  AlignContentDirectionKeys,
6
- } from "./alignContent"
6
+ } from './alignContent'
7
7
  export {
8
8
  ALIGN_CONTENT_DIRECTION,
9
9
  ALIGN_CONTENT_MAP_X,
10
10
  ALIGN_CONTENT_MAP_Y,
11
11
  default as alignContent,
12
- } from "./alignContent"
13
- export type { ExtendCss } from "./extendCss"
14
- export { default as extendCss } from "./extendCss"
15
- export type { Styles, StylesTheme } from "./styles"
16
- export { default as styles } from "./styles"
12
+ } from './alignContent'
13
+ export type { ExtendCss } from './extendCss'
14
+ export { default as extendCss } from './extendCss'
15
+ export type { Styles, StylesTheme } from './styles'
16
+ export { default as styles } from './styles'
@@ -1,4 +1,4 @@
1
- import { value } from "../../units"
1
+ import { value } from '../../units'
2
2
 
3
3
  type PropertyValue = string | number | null | undefined
4
4
  type PV = PropertyValue
@@ -62,14 +62,14 @@ const formatShorthand = (corners: PV[], calc: (p: PV) => any) => {
62
62
  }
63
63
 
64
64
  const CORNER_CSS = [
65
- "border-top-left-radius",
66
- "border-top-right-radius",
67
- "border-bottom-right-radius",
68
- "border-bottom-left-radius",
65
+ 'border-top-left-radius',
66
+ 'border-top-right-radius',
67
+ 'border-bottom-right-radius',
68
+ 'border-bottom-left-radius',
69
69
  ] as const
70
70
 
71
71
  const formatIndividual = (corners: PV[], calc: (p: PV) => any) => {
72
- let output = ""
72
+ let output = ''
73
73
  for (let i = 0; i < corners.length; i++) {
74
74
  if (isValidValue(corners[i])) output += `${CORNER_CSS[i]}: ${calc(corners[i])};`
75
75
  }
@@ -1,27 +1,27 @@
1
- import { value } from "../../units"
1
+ import { value } from '../../units'
2
2
 
3
3
  type CssUnits =
4
- | "px"
5
- | "rem"
6
- | "%"
7
- | "em"
8
- | "ex"
9
- | "cm"
10
- | "mm"
11
- | "in"
12
- | "pt"
13
- | "pc"
14
- | "ch"
15
- | "vh"
16
- | "vw"
17
- | "vmin"
18
- | "vmax"
4
+ | 'px'
5
+ | 'rem'
6
+ | '%'
7
+ | 'em'
8
+ | 'ex'
9
+ | 'cm'
10
+ | 'mm'
11
+ | 'in'
12
+ | 'pt'
13
+ | 'pc'
14
+ | 'ch'
15
+ | 'vh'
16
+ | 'vw'
17
+ | 'vmin'
18
+ | 'vmax'
19
19
 
20
20
  const isValidValue = (v: unknown) => !!v || v === 0
21
21
 
22
- type Property = "inset" | "margin" | "padding" | "border-width" | "border-style" | "border-color"
22
+ type Property = 'inset' | 'margin' | 'padding' | 'border-width' | 'border-style' | 'border-color'
23
23
  type Value = string | number | null | undefined
24
- type Side = "top" | "bottom" | "left" | "right"
24
+ type Side = 'top' | 'bottom' | 'left' | 'right'
25
25
 
26
26
  type EdgeValues = {
27
27
  full: Value
@@ -36,12 +36,12 @@ type EdgeValues = {
36
36
  type Definitions = Record<Property, { unit?: CssUnits; edgeCss: (side: Side) => string }>
37
37
 
38
38
  const definitions: Definitions = {
39
- inset: { unit: "rem", edgeCss: (side) => side },
40
- margin: { unit: "rem", edgeCss: (side) => `margin-${side}` },
41
- padding: { unit: "rem", edgeCss: (side) => `padding-${side}` },
42
- "border-width": { unit: "px", edgeCss: (side) => `border-${side}-width` },
43
- "border-style": { edgeCss: (side) => `border-${side}-style` },
44
- "border-color": { edgeCss: (side) => `border-${side}-color` },
39
+ inset: { unit: 'rem', edgeCss: (side) => side },
40
+ margin: { unit: 'rem', edgeCss: (side) => `margin-${side}` },
41
+ padding: { unit: 'rem', edgeCss: (side) => `padding-${side}` },
42
+ 'border-width': { unit: 'px', edgeCss: (side) => `border-${side}-width` },
43
+ 'border-style': { edgeCss: (side) => `border-${side}-style` },
44
+ 'border-color': { edgeCss: (side) => `border-${side}-color` },
45
45
  }
46
46
 
47
47
  const hasAnyValue = (vals: EdgeValues) =>
@@ -84,11 +84,11 @@ const formatIndividual = (
84
84
  calc: (v: Value) => Value,
85
85
  ) => {
86
86
  const [t, r, b, l] = sides
87
- let output = ""
88
- if (isValidValue(t)) output += `${edgeCss("top")}: ${calc(t)};`
89
- if (isValidValue(b)) output += `${edgeCss("bottom")}: ${calc(b)};`
90
- if (isValidValue(l)) output += `${edgeCss("left")}: ${calc(l)};`
91
- if (isValidValue(r)) output += `${edgeCss("right")}: ${calc(r)};`
87
+ let output = ''
88
+ if (isValidValue(t)) output += `${edgeCss('top')}: ${calc(t)};`
89
+ if (isValidValue(b)) output += `${edgeCss('bottom')}: ${calc(b)};`
90
+ if (isValidValue(l)) output += `${edgeCss('left')}: ${calc(l)};`
91
+ if (isValidValue(r)) output += `${edgeCss('right')}: ${calc(r)};`
92
92
  return output
93
93
  }
94
94
 
@@ -1,4 +1,4 @@
1
- export type { BorderRadius } from "./borderRadius"
2
- export { default as borderRadius } from "./borderRadius"
3
- export type { Edge } from "./edge"
4
- export { default as edge } from "./edge"
1
+ export type { BorderRadius } from './borderRadius'
2
+ export { default as borderRadius } from './borderRadius'
3
+ export type { Edge } from './edge'
4
+ export { default as edge } from './edge'
@@ -1,8 +1,8 @@
1
- import { values } from "../../units"
2
- import { borderRadius, edge } from "../shorthands"
3
- import processDescriptor from "./processDescriptor"
4
- import propertyMap from "./propertyMap"
5
- import type { InnerTheme, Theme } from "./types"
1
+ import { values } from '../../units'
2
+ import { borderRadius, edge } from '../shorthands'
3
+ import processDescriptor from './processDescriptor'
4
+ import propertyMap from './propertyMap'
5
+ import type { InnerTheme, Theme } from './types'
6
6
 
7
7
  export type { Theme as StylesTheme }
8
8
 
@@ -27,7 +27,7 @@ const styles: Styles = ({ theme: t, css, rootSize }) => {
27
27
  processDescriptor(d, t, css, calc, shorthand, borderRadiusFn),
28
28
  )
29
29
 
30
- return fragments.filter(Boolean).join(" ")
30
+ return fragments.filter(Boolean).join(' ')
31
31
  }
32
32
 
33
33
  export default styles
@@ -1,8 +1,8 @@
1
- import type { Values } from "../../units/values"
2
- import type { BorderRadius } from "../shorthands/borderRadius"
3
- import type { Edge } from "../shorthands/edge"
4
- import type { PropertyDescriptor } from "./propertyMap"
5
- import type { InnerTheme } from "./types"
1
+ import type { Values } from '../../units/values'
2
+ import type { BorderRadius } from '../shorthands/borderRadius'
3
+ import type { Edge } from '../shorthands/edge'
4
+ import type { PropertyDescriptor } from './propertyMap'
5
+ import type { InnerTheme } from './types'
6
6
 
7
7
  type Css = (strings: TemplateStringsArray, ...values: any[]) => string
8
8
  type Calc = (...params: any[]) => ReturnType<Values>
@@ -10,39 +10,39 @@ type Calc = (...params: any[]) => ReturnType<Values>
10
10
  /** Mirrors the Value / PropertyValue types used by edge and borderRadius shorthands. */
11
11
  type Value = string | number | null | undefined
12
12
 
13
- const toCssDecl = (css: string, v: unknown) => (v == null ? "" : `${css}: ${v};`)
13
+ const toCssDecl = (css: string, v: unknown) => (v == null ? '' : `${css}: ${v};`)
14
14
 
15
15
  const processSpecial = (
16
- d: Extract<PropertyDescriptor, { kind: "special" }>,
16
+ d: Extract<PropertyDescriptor, { kind: 'special' }>,
17
17
  t: InnerTheme,
18
18
  ): string => {
19
19
  switch (d.id) {
20
- case "fullScreen":
21
- if (!t.fullScreen) return ""
22
- return "position: fixed; top: 0; left: 0; right: 0; bottom: 0;"
20
+ case 'fullScreen':
21
+ if (!t.fullScreen) return ''
22
+ return 'position: fixed; top: 0; left: 0; right: 0; bottom: 0;'
23
23
 
24
- case "backgroundImage":
25
- if (!t.backgroundImage) return ""
24
+ case 'backgroundImage':
25
+ if (!t.backgroundImage) return ''
26
26
  return `background-image: url(${t.backgroundImage});`
27
27
 
28
- case "animation": {
29
- const parts = [t.keyframe, t.animation].filter(Boolean).join(" ")
30
- return parts ? `animation: ${parts};` : ""
28
+ case 'animation': {
29
+ const parts = [t.keyframe, t.animation].filter(Boolean).join(' ')
30
+ return parts ? `animation: ${parts};` : ''
31
31
  }
32
32
 
33
- case "hideEmpty":
34
- if (!t.hideEmpty) return ""
35
- return "&:empty { display: none; }"
33
+ case 'hideEmpty':
34
+ if (!t.hideEmpty) return ''
35
+ return '&:empty { display: none; }'
36
36
 
37
- case "clearFix":
38
- if (!t.clearFix) return ""
37
+ case 'clearFix':
38
+ if (!t.clearFix) return ''
39
39
  return '&::after { clear: both; content: ""; display: table; }'
40
40
 
41
- case "extendCss":
42
- return (t.extendCss as string) ?? ""
41
+ case 'extendCss':
42
+ return (t.extendCss as string) ?? ''
43
43
 
44
44
  default:
45
- return ""
45
+ return ''
46
46
  }
47
47
  }
48
48
 
@@ -55,16 +55,16 @@ const processDescriptor = (
55
55
  borderRadiusFn: ReturnType<BorderRadius>,
56
56
  ): string => {
57
57
  switch (d.kind) {
58
- case "simple":
58
+ case 'simple':
59
59
  return toCssDecl(d.css, t[d.key])
60
60
 
61
- case "convert":
61
+ case 'convert':
62
62
  return toCssDecl(d.css, calc(t[d.key]))
63
63
 
64
- case "convert_fallback":
64
+ case 'convert_fallback':
65
65
  return toCssDecl(d.css, calc(...d.keys.map((k) => t[k])))
66
66
 
67
- case "edge":
67
+ case 'edge':
68
68
  return (
69
69
  shorthand(d.property, {
70
70
  full: t[d.keys.full] as Value,
@@ -74,10 +74,10 @@ const processDescriptor = (
74
74
  left: t[d.keys.left] as Value,
75
75
  bottom: t[d.keys.bottom] as Value,
76
76
  right: t[d.keys.right] as Value,
77
- }) ?? ""
77
+ }) ?? ''
78
78
  )
79
79
 
80
- case "border_radius":
80
+ case 'border_radius':
81
81
  return (
82
82
  borderRadiusFn({
83
83
  full: t[d.keys.full] as Value,
@@ -89,10 +89,10 @@ const processDescriptor = (
89
89
  topRight: t[d.keys.topRight] as Value,
90
90
  bottomLeft: t[d.keys.bottomLeft] as Value,
91
91
  bottomRight: t[d.keys.bottomRight] as Value,
92
- }) ?? ""
92
+ }) ?? ''
93
93
  )
94
94
 
95
- case "special":
95
+ case 'special':
96
96
  return processSpecial(d, t)
97
97
  }
98
98
  }