Skip to content

Commit

Permalink
fix: text-shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Sep 27, 2023
1 parent 2c72ccc commit aaf6c0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/builder/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const SCALE = 1.1

export function buildDropShadow(
{ id, width, height }: { id: string; width: number; height: number },
style: Record<string, any>
style: {
shadowColor: string[]
shadowOffset: {
width: number
height: number
}[]
shadowRadius: number[]
}
) {
if (
!style.shadowColor ||
Expand Down
21 changes: 18 additions & 3 deletions src/handler/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ function handleSpecialCase(
if (name === 'textShadow') {
// Handle multiple text shadows if provided.
value = value.toString().trim()
const result = {}
if (value.includes(',')) {
const shadows = splitEffects(value)
const result = {}
for (const shadow of shadows) {
const styles = getStylesForProperty('textShadow', shadow, true)
for (const k in styles) {
Expand All @@ -186,8 +186,14 @@ function handleSpecialCase(
}
}
}
return result
} else {
const styles = getStylesForProperty('textShadow', value, true)
for (const k in styles) {
result[k] = [styles[k]]
}
}

return result
}

return
Expand Down Expand Up @@ -255,6 +261,13 @@ type MainStyle = {
gap: number
rowGap: number
columnGap: number

textShadowOffset: {
width: number
height: number
}[]
textShadowColor: string[]
textShadowRadius: number[]
}

type OtherStyle = Exclude<Record<PropertyKey, string | number>, keyof MainStyle>
Expand Down Expand Up @@ -288,7 +301,7 @@ export default function expand(

const name = getPropertyName(prop)
const value = preprocess(style[prop], currentColor)

console.log('::;name', name)
try {
const resolvedStyle =
handleSpecialCase(name, value, currentColor) ||
Expand All @@ -300,6 +313,8 @@ export default function expand(
)

Object.assign(serializedStyle, resolvedStyle)

console.log(':::resolvedStyle', resolvedStyle)
} catch (err) {
throw new Error(
err.message +
Expand Down
10 changes: 3 additions & 7 deletions src/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,9 @@ export default async function* buildTextNodes(

let filter = ''
if (parentStyle.textShadowOffset) {
let { textShadowColor, textShadowOffset, textShadowRadius } =
parentStyle as any
if (!Array.isArray(parentStyle.textShadowOffset)) {
textShadowColor = [textShadowColor]
textShadowOffset = [textShadowOffset]
textShadowRadius = [textShadowRadius]
}
const { textShadowColor, textShadowOffset, textShadowRadius } = parentStyle

console.log(':::parentStyle', parentStyle)

filter = buildDropShadow(
{
Expand Down

0 comments on commit aaf6c0c

Please sign in to comment.