-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
476 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { border } from './border' | ||
import { colors } from './color' | ||
import { margin } from './margin' | ||
import { positions } from './position' | ||
import { sizes } from './size' | ||
import { spacing } from './spacing' | ||
|
||
export const maps = [ | ||
border, | ||
positions, | ||
margin, | ||
spacing, | ||
colors, | ||
sizes | ||
].flat(1) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { StaticPropAtomicMap } from '../types' | ||
|
||
export const sizes: StaticPropAtomicMap[] = [ | ||
['width', 'w'], | ||
['height', 'h'], | ||
['min-width', 'min-w'], | ||
['min-height', 'min-h'], | ||
['max-width', 'max-w'], | ||
['max-height', 'max-h'], | ||
['font-size', 'text'], | ||
['line-height', ['leading', 'lh']], | ||
['border-radius', ['rounded', 'rd']], | ||
['border-top-left-radius', ['rounded-tl', 'rd-tl']], | ||
['border-top-right-radius', ['rounded-tr', 'rd-tr']], | ||
['border-bottom-right-radius', ['rounded-br', 'rd-br']], | ||
['border-bottom-left-radius', ['rounded-bl', 'rd-bl']], | ||
['border-width', ['border', 'b']], | ||
|
||
['border-top-width', 'btw'], | ||
['border-right-width', 'brw'], | ||
['border-bottom-width', 'bbw'], | ||
['border-left-width', 'blw'], | ||
['border-style', 'bs'], | ||
['border-top-style', 'bts'], | ||
['border-right-style', 'brs'], | ||
['border-bottom-style', 'bbs'], | ||
['border-left-style', 'bls'], | ||
['border-color', 'bc'], | ||
['border-top-color', 'btc'], | ||
['border-right-color', 'brc'], | ||
['border-bottom-color', 'bbc'], | ||
['border-left-color', 'blc'], | ||
['border', 'b'], | ||
['outline', 'o'], | ||
['outline-width', 'ow'], | ||
['outline-style', 'os'], | ||
['outline-color', 'oc'], | ||
['box-shadow', 'shadow'], | ||
['text-shadow', 'tshadow'], | ||
['letter-spacing', 'ls'], | ||
['word-spacing', 'ws'], | ||
['background-size', 'bg-size'], | ||
['background-position', 'bg-pos'], | ||
['background-repeat', 'bg-repeat'], | ||
['background-attachment', 'bg-attach'], | ||
['background-origin', 'bg-origin'], | ||
['background-clip', 'bg-clip'], | ||
['background-color', 'bgc'], | ||
['background-image', 'bgi'], | ||
['background-blend-mode', 'bg-blend'], | ||
['background-attachment', 'bg-attach'], | ||
['background-origin', 'bg-origin'], | ||
['background-clip', 'bg-clip'], | ||
['background-color', 'bgc'], | ||
['background-image', 'bgi'], | ||
['background-blend-mode', 'bg-blend'], | ||
['background-attachment', 'bg-attach'], | ||
['background-origin', ' bg-origin'], | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createPos4Props } from './position' | ||
import type { PropsAtomicMap } from '../types' | ||
|
||
export const spacing: PropsAtomicMap[] = [ | ||
['margin', 'm'], | ||
['padding', 'p'], | ||
createPos4Props('margin', 'm'), | ||
createPos4Props('padding', 'p'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Magicolor } from '@magic-color/core' | ||
import { guessType as guessColorType, Magicolor } from '@magic-color/core' | ||
import type { UnoGenerator } from '@unocss/core' | ||
import { maps } from '../maps' | ||
import { toArray } from '../utils' | ||
|
@@ -10,6 +10,8 @@ const nonTransfromPxProps = [ | |
'border', | ||
] | ||
|
||
const HexUnoColorMap = new WeakMap<UnoGenerator, Colors>() | ||
|
||
/** | ||
Check warning on line 15 in src/transfromer/index.ts GitHub Actions / lint
|
||
* 将 CssValueParsedMeta[] 转换为 atomic css | ||
* @param meta CssValueParsedMeta[] | ||
Check warning on line 17 in src/transfromer/index.ts GitHub Actions / lint
|
||
|
@@ -79,8 +81,17 @@ function analyzeMeta(bundle: { | |
const atomics: string[] = [] | ||
|
||
for (const m of meta) { | ||
if (Array.isArray(m)) { | ||
|
||
if (Array.isArray(m.value)) { | ||
if (m.type === 'Function') { | ||
if (m.fname === 'var') { | ||
const token = m.value.map(v => (v.value as string).trim()).join('').replace(/^--/, '$') | ||
atomics.push(`${key}-${token}`) | ||
} | ||
else { | ||
const token = m.raw.replace(/\s/g, '_') | ||
atomics.push(`${key}-[${token}]`) | ||
} | ||
} | ||
} | ||
else { | ||
if (m.unit === 'px' && /^\d+$/.test(m.value as string)) { | ||
|
@@ -91,15 +102,24 @@ function analyzeMeta(bundle: { | |
atomics.push(`${key}-${Number(m.value) / 4}`) | ||
} | ||
} | ||
else if (isColorProp(prop)) { | ||
const colorKey = analyzeColor(m.value as string, uno) | ||
if (colorKey) { | ||
atomics.push(`${key}-${colorKey}`) | ||
|
||
else if (isColorProp(prop) || m.type === 'Hash' || guessColorType(m.raw) != null) { | ||
const themeKey = analyzeColor(m.value as string, uno) | ||
if (themeKey) { | ||
atomics.push(`${key}-${themeKey}`) | ||
} | ||
else { | ||
atomics.push(`${key}-[${m.value}]`) | ||
atomics.push(`${key}-${m.value}`) | ||
} | ||
} | ||
|
||
else if (m.type === 'Identifier') { | ||
atomics.push(`${key}-${m.value}`) | ||
} | ||
|
||
else { | ||
atomics.push(`${key}-${m.raw}`) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -129,14 +149,24 @@ function analyzeColor(color: string, uno: UnoGenerator): string | undefined { | |
} | ||
|
||
if ((uno.config.theme as any).colors) { | ||
const colors = hexable((uno.config.theme as any).colors) | ||
let colors: Colors | ||
let hexColor | ||
|
||
if (HexUnoColorMap.has(uno)) { | ||
colors = HexUnoColorMap.get(uno)! | ||
} | ||
else { | ||
colors = hexable((uno.config.theme as any).colors) | ||
HexUnoColorMap.set(uno, colors) | ||
} | ||
|
||
try { | ||
hexColor = new Magicolor(color).hex() | ||
} | ||
catch { | ||
return | ||
} | ||
|
||
const paths = findColorPath(colors, hexColor) | ||
|
||
if (paths && paths.length > 0) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.