Skip to content

Commit d42b2ad

Browse files
committed
convert more easy values
1 parent 1b20904 commit d42b2ad

File tree

1 file changed

+36
-81
lines changed

1 file changed

+36
-81
lines changed

src/index.ts

Lines changed: 36 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -552,20 +552,49 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
552552
resets.p(property, valueLoc)
553553
}
554554
} else if (isProperty('z-index', property)) {
555-
zindex.p(value.text, valueLoc)
555+
zindex.p(text, valueLoc)
556556
return SKIP
557557
} else if (isProperty('font', property)) {
558558
// TODO: implement
559559
} else if (isProperty('font-size', property)) {
560-
if (!SYSTEM_FONTS.has(value.text)) {
561-
fontSizes.p(value.text, valueLoc)
560+
if (!SYSTEM_FONTS.has(text)) {
561+
fontSizes.p(text, valueLoc)
562562
}
563563
} else if (isProperty('font-family', property)) {
564-
if (!SYSTEM_FONTS.has(value.text)) {
565-
fontFamilies.p(value.text, valueLoc)
564+
if (!SYSTEM_FONTS.has(text)) {
565+
fontFamilies.p(text, valueLoc)
566566
}
567+
return SKIP // to prevent finding color false positives (Black as font family name is not a color)
567568
} else if (isProperty('line-height', property)) {
568-
lineHeights.p(value.text, valueLoc)
569+
lineHeights.p(text, valueLoc)
570+
} else if (isProperty('transition', property) || isProperty('animation', property)) {
571+
// TODO: iplement
572+
} else if (isProperty('animation-duration', property) || isProperty('transition-duration', property)) {
573+
for (let child of value.children) {
574+
if (child.type_name !== 'Operator') {
575+
durations.p(child.text, valueLoc)
576+
}
577+
}
578+
} else if (isProperty('transition-timing-function', property) || isProperty('animation-timing-function', property)) {
579+
for (let child of value.children) {
580+
if (child.type_name !== 'Operator') {
581+
timingFunctions.p(child.text, valueLoc)
582+
}
583+
}
584+
} else if (isProperty('container-name', property)) {
585+
containerNames.p(text, valueLoc)
586+
} else if (isProperty('container', property)) {
587+
// The first identifier is the container name
588+
// Example: container: my-layout / inline-size;
589+
if (value.first_child?.type_name === 'Identifier') {
590+
containerNames.p(value.first_child.text, valueLoc)
591+
}
592+
} else if (border_radius_properties.has(basename(property))) {
593+
borderRadiuses.push(text, property, valueLoc)
594+
} else if (isProperty('text-shadow', property)) {
595+
textShadows.p(text, valueLoc)
596+
} else if (isProperty('box-shadow', property)) {
597+
boxShadows.p(text, valueLoc)
569598
}
570599

571600
wallaceWalk2(value, (valueNode) => {
@@ -662,29 +691,7 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
662691

663692
// Process properties first that don't have colors,
664693
// so we can avoid further walking them;
665-
if (
666-
isProperty('margin', property) ||
667-
isProperty('margin-block', property) ||
668-
isProperty('margin-inline', property) ||
669-
isProperty('margin-top', property) ||
670-
isProperty('margin-right', property) ||
671-
isProperty('margin-bottom', property) ||
672-
isProperty('margin-left', property) ||
673-
isProperty('padding', property) ||
674-
isProperty('padding-block', property) ||
675-
isProperty('padding-inline', property) ||
676-
isProperty('padding-top', property) ||
677-
isProperty('padding-right', property) ||
678-
isProperty('padding-bottom', property) ||
679-
isProperty('padding-left', property)
680-
) {
681-
// if (isValueReset(node)) {
682-
// resets.p(property, declaration.loc!)
683-
// }
684-
} else if (isProperty('z-index', property)) {
685-
// zindex.p(stringifyNode(node), loc)
686-
// return this.skip
687-
} else if (isProperty('font', property)) {
694+
if (isProperty('font', property)) {
688695
if (isSystemFont(node)) return
689696

690697
let result = destructure(node, stringifyNode, function (item) {
@@ -710,19 +717,12 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
710717
lineHeights.p(line_height, loc)
711718
}
712719

713-
break
714-
} else if (isProperty('font-size', property)) {
715-
// if (!isSystemFont(node)) {
716-
// fontSizes.p(stringifyNode(node), loc)
717-
// }
718720
break
719721
} else if (isProperty('font-family', property)) {
720722
// if (!isSystemFont(node)) {
721723
// fontFamilies.p(stringifyNode(node), loc)
722724
// }
723725
break
724-
} else if (isProperty('line-height', property)) {
725-
// lineHeights.p(stringifyNode(node), loc)
726726
} else if (isProperty('transition', property) || isProperty('animation', property)) {
727727
analyzeAnimation(children, function (item: { type: string; value: CssNode }) {
728728
if (item.type === 'fn') {
@@ -734,51 +734,6 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
734734
}
735735
})
736736
break
737-
} else if (isProperty('animation-duration', property) || isProperty('transition-duration', property)) {
738-
if (children && children.size > 1) {
739-
children.forEach((child) => {
740-
if (child.type !== Operator) {
741-
durations.p(stringifyNode(child), loc)
742-
}
743-
})
744-
} else {
745-
durations.p(stringifyNode(node), loc)
746-
}
747-
break
748-
} else if (isProperty('transition-timing-function', property) || isProperty('animation-timing-function', property)) {
749-
if (children && children.size > 1) {
750-
children.forEach((child) => {
751-
if (child.type !== Operator) {
752-
timingFunctions.p(stringifyNode(child), loc)
753-
}
754-
})
755-
} else {
756-
timingFunctions.p(stringifyNode(node), loc)
757-
}
758-
break
759-
} else if (isProperty('container-name', property)) {
760-
containerNames.p(stringifyNode(node), loc)
761-
} else if (isProperty('container', property)) {
762-
// The first identifier is the container name
763-
// Example: container: my-layout / inline-size;
764-
if (children.first?.type === 'Identifier') {
765-
containerNames.p(children.first.name, loc)
766-
}
767-
} else if (border_radius_properties.has(basename(property))) {
768-
if (!isValueKeyword(node)) {
769-
borderRadiuses.push(stringifyNode(node), property, loc)
770-
}
771-
break
772-
} else if (isProperty('text-shadow', property)) {
773-
if (!isValueKeyword(node)) {
774-
textShadows.p(stringifyNode(node), loc)
775-
}
776-
// no break here: potentially contains colors
777-
} else if (isProperty('box-shadow', property)) {
778-
if (!isValueKeyword(node)) {
779-
boxShadows.p(stringifyNode(node), loc)
780-
}
781-
// no break here: potentially contains colors
782737
}
783738

784739
walk(node, function (valueNode: CssNode) {

0 commit comments

Comments
 (0)