Skip to content

Commit

Permalink
feat: autoUno build v0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryZhu-dev committed Nov 14, 2024
1 parent cbc4491 commit 6f7e3e3
Showing 1 changed file with 90 additions and 110 deletions.
200 changes: 90 additions & 110 deletions autouno/src/index.js
Original file line number Diff line number Diff line change
@@ -1,114 +1,95 @@
const propertyWithUnit = [
"animation-delay$ms",
"animation-duration$ms",
"border-width$px",
"bottom$px",
"box-shadow$px",
"clip$px",
"column-gap$px",
"column-rule-width$px",
"column-span$px",
"column-width$px",
"columns$px",
"height$px",
"left$px",
"letter-spacing$px",
"line-height$px",
"margin$px",
"margin-bottom$px",
"margin-left$px",
"margin-right$px",
"margin-top$px",
"max-height$px",
"max-width$px",
"min-height$px",
"min-width$px",
"padding$px",
"padding-bottom$px",
"padding-left$px",
"padding-right$px",
"padding-top$px",
"right$px",
"text-indent$px",
"top$px",
"transform$px",
"transform-origin$px",
"transition-delay$ms",
"transition-duration$ms",
"transition-timing-function$px",
"width$px",
"word-spacing$px",
"z-index$px",
"color",
"background-color",
"border-color",
"font-size$px",
"font-weight$",
const propertyWithCustomValue = [
'animation-delay$ms',
'animation-duration$ms',
'border-width$px',
'bottom$px',
'box-shadow$px',
'color',
'height$px',
'left$px',
'letter-spacing$px',
'line-height$px',
'margin$px',
'margin-bottom$px',
'margin-left$px',
'margin-right$px',
'margin-top$px',
'max-height$px',
'max-width$px',
'min-height$px',
'min-width$px',
'padding$px',
'padding-bottom$px',
'padding-left$px',
'padding-right$px',
'padding-top$px',
'right$px',
'top$px',
'transform$px',
'transform-origin$px',
'transition-delay$ms',
'transition-duration$ms',
'transition-timing-function$px',
'width$px',
'word-spacing$px',
'z-index$px',
'background-color',
'border-color',
'font-size$px',
'font-weight$'
]

const propertyCommon = [
"display: flex",
"display: block",
"display: inline",
"display: inline-block",
"display: grid",
"display: none",
"position: relative",
"position: absolute",
"position: fixed",
"position: sticky",
"float: left",
"float: right",
"clear: both",
"outline: none",
"overflow: hidden",
"overflow: scroll",
"overflow: auto",
"visibility: visible",
"visibility: hidden",
"text-align: left",
"text-align: center",
"text-align: right",
"font-weight: bold",
"font-style: italic",
"line-height: normal",
"letter-spacing: normal",
"text-transform: uppercase",
"background-position: center",
"background-repeat: no-repeat",
"box-sizing: border-box",
"cursor: pointer",
"cursor: not-allowed",
"cursor: move",
"text-decoration: none",
"text-decoration: underline",
"word-wrap: break-word",
"white-space: nowrap",
"visibility: visible",
"transform-origin: center",
"justify-content: center",
"justify-content: space-between",
"align-items: center",
"align-self: flex-start",
"grid-template-rows: auto",
"list-style-type: none",
"list-style-position: inside",
"resize: both",
"user-select: none",
"pointer-events: none",
"transform-style: preserve-3d",
"backface-visibility: hidden",
"scroll-behavior: smooth",
"text-align-last: center",
"table-layout: fixed",
"word-break: break-all",
"box-decoration-break: clone",
"vertical-align: middle",
"white-space: normal",
"writing-mode: vertical-rl",
"pointer-events: auto"
'display: flex',
'display: block',
'display: inline',
'display: inline-block',
'display: grid',
'display: none',
'position: relative',
'position: absolute',
'position: fixed',
'position: sticky',
'float: left',
'float: right',
'clear: both',
'outline: none',
'overflow: hidden',
'overflow: scroll',
'overflow: auto',
'visibility: visible',
'visibility: hidden',
'text-align: left',
'text-align: center',
'text-align: right',
'font-weight: bold',
'background-position: center',
'background-repeat: no-repeat',
'box-sizing: border-box',
'cursor: pointer',
'cursor: not-allowed',
'cursor: move',
'text-decoration: none',
'text-decoration: underline',
'white-space: nowrap',
'visibility: visible',
'transform-origin: center',
'justify-content: center',
'justify-content: space-between',
'align-items: center',
'align-self: flex-start',
'resize: both',
'user-select: none',
'pointer-events: none',
'backface-visibility: hidden',
'scroll-behavior: smooth',
'text-align-last: center',
'table-layout: fixed',
'word-break: break-all',
'white-space: normal',
'pointer-events: auto'
]
const randomKeyWord = ['padd10px', 'marg10px', 'borde10px', 'd:fl', 'd:in', 'd:gr', 'hei100vh', 'wid100vh', 'left10%']
const randomKeyWord = ['padd10px', 'm10px', 'mrr10', 'borde10px', 'd:fl', 'd:in', 'dg', 'h100vh', 'w100vh', 'left10%', 'df', 'w100', 'h100%']
function findBestMatch(input, customproperty = []) {
// 将输入字符串转换为字符数组
const inputChars = input.split('')
Expand All @@ -117,7 +98,7 @@ function findBestMatch(input, customproperty = []) {
let maxMatches = 0

// 遍历所有目标字符串
for (let keywordOrigin of customproperty.concat(propertyWithUnit.concat(propertyCommon))) {
for (let keywordOrigin of customproperty.concat(propertyWithCustomValue.concat(propertyCommon))) {
const keyword = keywordOrigin.split('$')[0]
// 用来记录目标字符串的字符序列是否匹配
let matchCount = 0
Expand All @@ -133,8 +114,7 @@ function findBestMatch(input, customproperty = []) {
inputIndex++
}
}
// 如果找到的匹配字符数大于等于 2,且比当前最大匹配数多
if (matchCount >= 2 && matchCount > maxMatches) {
if (matchCount >= 1 && matchCount > maxMatches) {
maxMatches = matchCount
bestMatch = keywordOrigin
}
Expand Down

0 comments on commit 6f7e3e3

Please sign in to comment.