UNPKG

weapp-tailwindcss

Version:

把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!

162 lines (160 loc) 4.43 kB
import "./chunk-SM5V25IN.mjs"; // src/reset/index.ts import plugin from "tailwindcss/plugin"; var DEFAULT_BUTTON_RESET_SELECTORS = ["button"]; var DEFAULT_BUTTON_DECLARATIONS = { padding: "0", backgroundColor: "transparent", fontSize: "inherit", lineHeight: "inherit", color: "inherit", borderWidth: "0" }; var BUTTON_RESET_PSEUDO_DECLARATIONS = { border: "none" }; var DEFAULT_IMAGE_RESET_SELECTORS = ["image", "img"]; var DEFAULT_IMAGE_DECLARATIONS = { display: "block", borderWidth: "0", backgroundColor: "transparent", maxWidth: "100%", height: "auto" }; function normalizeResetSelectors(option, defaults) { const resolved = option?.selectors?.length ? option.selectors : defaults; const normalized = []; for (const selector of resolved) { const trimmed = selector.trim(); if (!trimmed || normalized.includes(trimmed)) { continue; } normalized.push(trimmed); } return normalized.length ? normalized : void 0; } function convertSelectorForBase(selector) { if (selector.startsWith(".")) { const className = selector.slice(1); if (className.length > 0) { return `[class~="${className}"]`; } } if (selector.startsWith("#")) { const id = selector.slice(1); if (id.length > 0) { return `[id="${id}"]`; } } return selector; } function normalizeDeclarations(option, defaults) { const normalized = { ...defaults }; const overrides = option?.declarations; if (!overrides) { return normalized; } const entries = Object.entries(overrides); for (const [prop, value] of entries) { const resolved = normalizeDeclarationValue(value); if (resolved === void 0) { delete normalized[prop]; } else { normalized[prop] = resolved; } } return normalized; } function normalizePseudo(option, defaults) { const normalized = defaults ? { ...defaults } : {}; const overrides = option?.pseudo; if (!overrides) { return Object.keys(normalized).length ? normalized : void 0; } const entries = Object.entries(overrides); for (const [prop, value] of entries) { const resolved = normalizeDeclarationValue(value); if (resolved === void 0) { delete normalized[prop]; } else { normalized[prop] = resolved; } } return Object.keys(normalized).length ? normalized : void 0; } function normalizeDeclarationValue(value) { if (value === false || value === null || value === void 0) { return void 0; } return typeof value === "number" ? value.toString() : value; } function createResetRule(option, defaults) { if (option === false) { return void 0; } const selectors = normalizeResetSelectors(option, defaults.selectors); if (!selectors) { return void 0; } const declarations = normalizeDeclarations(option ?? {}, defaults.declarations); if (Object.keys(declarations).length === 0) { return void 0; } const pseudo = normalizePseudo(option ?? {}, defaults.pseudo); return { selectors: selectors.map(convertSelectorForBase), declarations, pseudo }; } var reset = plugin.withOptions( (options) => { const rules = []; const buttonRule = createResetRule(options?.buttonReset, { selectors: DEFAULT_BUTTON_RESET_SELECTORS, declarations: DEFAULT_BUTTON_DECLARATIONS, pseudo: BUTTON_RESET_PSEUDO_DECLARATIONS }); if (buttonRule) { rules.push(buttonRule); } const imageRule = createResetRule(options?.imageReset, { selectors: DEFAULT_IMAGE_RESET_SELECTORS, declarations: DEFAULT_IMAGE_DECLARATIONS }); if (imageRule) { rules.push(imageRule); } for (const extra of options?.extraResets ?? []) { const normalized = createResetRule(extra, { selectors: extra.selectors ?? [], declarations: {} }); if (normalized) { rules.push(normalized); } } return ({ addBase }) => { if (!rules.length) { return; } const baseRules = {}; for (const rule of rules) { baseRules[rule.selectors.join(",")] = rule.declarations; if (rule.pseudo) { const pseudoSelectors = rule.selectors.map((selector) => `${selector}::after`).join(","); baseRules[pseudoSelectors] = rule.pseudo; } } addBase(baseRules); }; }, () => { return {}; } ); var reset_default = reset; export { reset_default as default, reset };