@unocss/core
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -11,5 +11,5 @@ declare type Awaitable<T> = T | Promise<T>; | ||
declare type Extractor = (code: string, id?: string) => Awaitable<Set<string> | undefined>; | ||
declare type DynamicRule = [RegExp, ((match: string[], theme: Theme) => Awaitable<CSSObject | CSSEntries | undefined>)]; | ||
declare type DynamicRule<Theme extends {} = {}> = [RegExp, ((match: string[], theme: Theme) => Awaitable<CSSObject | CSSEntries | undefined>)]; | ||
declare type StaticRule = [string, CSSObject | CSSEntries]; | ||
declare type Rule = DynamicRule | StaticRule; | ||
declare type Rule<Theme extends {} = {}> = DynamicRule<Theme> | StaticRule; | ||
declare type DynamicShortcut = [RegExp, ((match: string[]) => (string | string[] | undefined))]; | ||
@@ -21,3 +21,3 @@ declare type StaticShortcut = [string, string | string[]]; | ||
declare type ExcludeRule = string | RegExp; | ||
declare type Variant = { | ||
declare type Variant<Theme extends {} = {}> = { | ||
/** | ||
@@ -46,12 +46,3 @@ * The entry function to match and rewrite the selector for futher processing. | ||
}; | ||
interface Theme { | ||
borderRadius?: Record<string, string>; | ||
breakpoints?: Record<string, string>; | ||
colors?: Record<string, string | Record<string, string>>; | ||
fontFamily?: Record<string, string>; | ||
fontSize?: Record<string, [string, string]>; | ||
lineHeight?: Record<string, string>; | ||
letterSpacing?: Record<string, string>; | ||
} | ||
interface ConfigBase { | ||
interface ConfigBase<Theme extends {} = {}> { | ||
/** | ||
@@ -103,7 +94,7 @@ * Rules to generate CSS utilities | ||
} | ||
interface UserConfig extends ConfigBase, GeneratorOptions { | ||
interface UserConfig<Theme extends {} = {}> extends ConfigBase<Theme>, GeneratorOptions { | ||
theme?: Theme; | ||
presets?: Preset[]; | ||
} | ||
interface UserConfigDefaults extends ConfigBase { | ||
interface UserConfigDefaults<Theme extends {} = {}> extends ConfigBase<Theme> { | ||
theme?: Theme; | ||
@@ -139,3 +130,3 @@ presets?: Preset[]; | ||
]; | ||
declare function defineConfig(config: UserConfig): UserConfig; | ||
declare function defineConfig(config: UserConfig): UserConfig<{}>; | ||
@@ -161,42 +152,4 @@ declare function escapeRegExp(string: string): string; | ||
declare function size(str: string): string | undefined; | ||
declare function border(str: string): string | undefined; | ||
declare function number(str: string): number | undefined; | ||
declare function percent(str: string): string | undefined; | ||
declare function fraction(str: string): string | undefined; | ||
declare function bracket(str: string): string | undefined; | ||
declare const handlers_size: typeof size; | ||
declare const handlers_border: typeof border; | ||
declare const handlers_number: typeof number; | ||
declare const handlers_percent: typeof percent; | ||
declare const handlers_fraction: typeof fraction; | ||
declare const handlers_bracket: typeof bracket; | ||
declare namespace handlers { | ||
export { | ||
handlers_size as size, | ||
handlers_border as border, | ||
handlers_number as number, | ||
handlers_percent as percent, | ||
handlers_fraction as fraction, | ||
handlers_bracket as bracket, | ||
}; | ||
} | ||
declare type HandlerName = keyof typeof handlers; | ||
declare const handlersNames: ("number" | "size" | "border" | "percent" | "fraction" | "bracket")[]; | ||
declare type Handler = { | ||
[K in HandlerName]: Handler; | ||
} & { | ||
(str: string): string | undefined; | ||
__options: { | ||
sequence: HandlerName[]; | ||
}; | ||
}; | ||
declare const handler: Handler; | ||
declare function hex2rgba(hex: string): [number, number, number, number] | [number, number, number] | undefined; | ||
declare function getMatchedPositions(code: string, matched: Set<string>): [number, number][]; | ||
declare const attributifyRE: RegExp; | ||
@@ -234,3 +187,3 @@ declare const validateFilterRE: RegExp; | ||
matchVariants(raw: string): VariantMatchedResult; | ||
applyVariants(parsed: ParsedUtil, variants?: Variant[], raw?: string): readonly [string, CSSEntries, string | undefined]; | ||
applyVariants(parsed: ParsedUtil, variants?: Variant<{}>[], raw?: string): readonly [string, CSSEntries, string | undefined]; | ||
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | undefined>; | ||
@@ -243,3 +196,4 @@ stringifyUtil(parsed?: ParsedUtil): StringifiedUtil | undefined; | ||
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator; | ||
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null; | ||
export { ArgumentType, Awaitable, BetterMap, CSSEntries, CSSObject, ConfigBase, DeepPartial, DynamicRule, DynamicShortcut, ExcludeRule, Extractor, GenerateResult, GeneratorOptions, Handler, HandlerName, ParsedUtil, Preset, ResolvedConfig, RestArgs, Rule, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, Theme, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserShortcuts, Variant, VariantMatchedResult, attributifyRE, border, bracket, createGenerator, defineConfig, e, entriesToCss, escapeRegExp, escapeSelector, extractorSplit, fraction, getMatchedPositions, handler, handlersNames, hex2rgba, isAttributifySelector, isObject, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, number, percent, size, toArray, uniq, validateFilterRE, variantMatcher }; | ||
export { ArgumentType, Awaitable, BetterMap, CSSEntries, CSSObject, ConfigBase, DeepPartial, DynamicRule, DynamicShortcut, ExcludeRule, Extractor, GenerateResult, GeneratorOptions, ParsedUtil, Preset, ResolvedConfig, RestArgs, Rule, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserShortcuts, Variant, VariantMatchedResult, attributifyRE, createGenerator, defineConfig, e, entriesToCss, escapeRegExp, escapeSelector, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, toArray, uniq, validateFilterRE, variantMatcher }; |
@@ -15,4 +15,2 @@ var __defProp = Object.defineProperty; | ||
attributifyRE: () => attributifyRE, | ||
border: () => border, | ||
bracket: () => bracket, | ||
createGenerator: () => createGenerator, | ||
@@ -25,6 +23,3 @@ defineConfig: () => defineConfig, | ||
extractorSplit: () => extractorSplit, | ||
fraction: () => fraction, | ||
getMatchedPositions: () => getMatchedPositions, | ||
handler: () => handler, | ||
handlersNames: () => handlersNames, | ||
hasScopePlaceholder: () => hasScopePlaceholder, | ||
hex2rgba: () => hex2rgba, | ||
@@ -38,5 +33,2 @@ isAttributifySelector: () => isAttributifySelector, | ||
mergeSet: () => mergeSet, | ||
number: () => number, | ||
percent: () => percent, | ||
size: () => size, | ||
toArray: () => toArray, | ||
@@ -148,94 +140,2 @@ uniq: () => uniq, | ||
// src/utils/handlers/handlers.ts | ||
var handlers_exports = {}; | ||
__export(handlers_exports, { | ||
border: () => border, | ||
bracket: () => bracket, | ||
fraction: () => fraction, | ||
number: () => number, | ||
percent: () => percent, | ||
size: () => size | ||
}); | ||
var numberWithUnitRE = /^(-?[0-9.]+)([a-z]*)$/i; | ||
var numberRE = /^(-?[0-9.]+)$/i; | ||
function size(str) { | ||
if (str === "auto" || str === "a") | ||
return "auto"; | ||
const match = str.match(numberWithUnitRE); | ||
if (!match) | ||
return; | ||
const [, n, unit] = match; | ||
if (unit) | ||
return str; | ||
const num = parseFloat(n); | ||
if (!Number.isNaN(num)) | ||
return `${num / 4}rem`; | ||
} | ||
function border(str) { | ||
const match = str.match(numberWithUnitRE); | ||
if (!match) | ||
return; | ||
const [, n, unit] = match; | ||
if (unit) | ||
return str; | ||
const num = parseFloat(n); | ||
if (!Number.isNaN(num)) | ||
return `${num}px`; | ||
} | ||
function number(str) { | ||
if (!numberRE.test(str)) | ||
return; | ||
const num = parseFloat(str); | ||
if (!Number.isNaN(num)) | ||
return num; | ||
} | ||
function percent(str) { | ||
if (str.endsWith("%")) | ||
str = str.slice(0, -1); | ||
const num = parseFloat(str); | ||
if (!Number.isNaN(num)) | ||
return `${num / 100}`; | ||
} | ||
function fraction(str) { | ||
const [left, right] = str.split("/"); | ||
const num = parseFloat(left) / parseFloat(right); | ||
if (!Number.isNaN(num)) | ||
return `${num * 100}%`; | ||
} | ||
function bracket(str) { | ||
if (str[0] === "[" && str[str.length - 1] === "]") | ||
return str.slice(1, -1); | ||
} | ||
// src/utils/handlers/shorthand.ts | ||
var handlersNames = Object.keys(handlers_exports); | ||
var handler = function(str) { | ||
var _a; | ||
const s = ((_a = this.__options) == null ? void 0 : _a.sequence) || []; | ||
this.__options.sequence = []; | ||
for (const n of s) { | ||
const res = handlers_exports[n](str); | ||
if (res) | ||
return res; | ||
} | ||
return void 0; | ||
}; | ||
function addProcessor(that, name) { | ||
if (!that.__options) { | ||
that.__options = { | ||
sequence: [] | ||
}; | ||
} | ||
that.__options.sequence.push(name); | ||
return that; | ||
} | ||
handlersNames.forEach((i) => { | ||
Object.defineProperty(handler, i, { | ||
enumerable: true, | ||
get() { | ||
return addProcessor(this, i); | ||
} | ||
}); | ||
}); | ||
// src/utils/colors.ts | ||
@@ -264,34 +164,2 @@ var hexRE = /^#?([\da-f]+)$/i; | ||
// src/utils/playground.ts | ||
function getMatchedPositions(code, matched) { | ||
const result = []; | ||
const attributify = []; | ||
const plain = new Set(); | ||
Array.from(matched).forEach((v) => { | ||
const match = isAttributifySelector(v); | ||
if (!match) | ||
plain.add(v); | ||
else if (!match[2]) | ||
plain.add(match[1]); | ||
else | ||
attributify.push(match); | ||
}); | ||
let start = 0; | ||
code.split(/[\s"';<>]/g).forEach((i) => { | ||
const end = start + i.length; | ||
if (plain.has(i)) | ||
result.push([start, end]); | ||
start = end + 1; | ||
}); | ||
attributify.forEach(([, name, value]) => { | ||
const regex = new RegExp(`${escapeRegExp(name)}=(['"])[^\\1]*?${escapeRegExp(value)}[^\\1]*?\\1`, "g"); | ||
Array.from(code.matchAll(regex)).forEach((match) => { | ||
const start2 = match.index + match[0].indexOf(value); | ||
const end = start2 + value.length; | ||
result.push([start2, end]); | ||
}); | ||
}); | ||
return result; | ||
} | ||
// src/utils/regex.ts | ||
@@ -419,21 +287,2 @@ var attributifyRE = /^\[(.+?)~?="(.*)"\]$/; | ||
// src/generator/utils.ts | ||
var reScopePlaceholder = / \$\$ /; | ||
var hasScopePlaceholder = (css) => css.match(reScopePlaceholder); | ||
function applyScope(css, scope) { | ||
if (hasScopePlaceholder(css)) | ||
return css.replace(reScopePlaceholder, scope ? ` ${scope} ` : " "); | ||
else | ||
return scope ? `${scope} ${css}` : css; | ||
} | ||
function toEscapedSelector(raw) { | ||
if (raw.startsWith("[")) | ||
return raw.replace(/^\[(.+?)(~?=)"(.*)"\]$/, (_, n, s, i) => `[${escapeSelector(n)}${s}"${escapeSelector(i)}"]`); | ||
else | ||
return `.${escapeSelector(raw)}`; | ||
} | ||
function normalizeEntries(obj) { | ||
return !Array.isArray(obj) ? Object.entries(obj) : obj; | ||
} | ||
// src/generator/index.ts | ||
@@ -516,7 +365,7 @@ var UnoGenerator = class { | ||
const css = Array.from(sheet).map(([query, items]) => { | ||
const size2 = items.length; | ||
const size = items.length; | ||
const sorted = items.sort((a, b) => a[0] - b[0] || a[1].localeCompare(b[1])).map((a) => [applyScope(a[1], scope), a[2]]); | ||
const rules = sorted.map(([selector, body], idx) => { | ||
if (this.config.mergeSelectors) { | ||
for (let i = size2 - 1; i > idx; i--) { | ||
for (let i = size - 1; i > idx; i--) { | ||
const current = sorted[i]; | ||
@@ -592,7 +441,7 @@ if (current[1] === body) { | ||
continue; | ||
const [matcher, handler2] = rule; | ||
const [matcher, handler] = rule; | ||
const match = processed.match(matcher); | ||
if (!match) | ||
continue; | ||
const obj = await handler2(match, theme); | ||
const obj = await handler(match, theme); | ||
if (obj) | ||
@@ -656,2 +505,19 @@ return [i, raw, normalizeEntries(obj), variants]; | ||
} | ||
var reScopePlaceholder = / \$\$ /; | ||
var hasScopePlaceholder = (css) => css.match(reScopePlaceholder); | ||
function applyScope(css, scope) { | ||
if (hasScopePlaceholder(css)) | ||
return css.replace(reScopePlaceholder, scope ? ` ${scope} ` : " "); | ||
else | ||
return scope ? `${scope} ${css}` : css; | ||
} | ||
function toEscapedSelector(raw) { | ||
if (raw.startsWith("[")) | ||
return raw.replace(/^\[(.+?)(~?=)"(.*)"\]$/, (_, n, s, i) => `[${e(n)}${s}"${e(i)}"]`); | ||
else | ||
return `.${e(raw)}`; | ||
} | ||
function normalizeEntries(obj) { | ||
return !Array.isArray(obj) ? Object.entries(obj) : obj; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -663,4 +529,2 @@ 0 && (module.exports = { | ||
attributifyRE, | ||
border, | ||
bracket, | ||
createGenerator, | ||
@@ -673,6 +537,3 @@ defineConfig, | ||
extractorSplit, | ||
fraction, | ||
getMatchedPositions, | ||
handler, | ||
handlersNames, | ||
hasScopePlaceholder, | ||
hex2rgba, | ||
@@ -686,5 +547,2 @@ isAttributifySelector, | ||
mergeSet, | ||
number, | ||
percent, | ||
size, | ||
toArray, | ||
@@ -691,0 +549,0 @@ uniq, |
{ | ||
"name": "@unocss/core", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40043
1204