UNPKG

weapp-tailwindcss

Version:

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

162 lines (157 loc) 5.68 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-MB4BR57E.js'); // src/reset/index.ts var _plugin = require('tailwindcss/plugin'); var _plugin2 = _interopRequireDefault(_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 = _optionalChain([option, 'optionalAccess', _ => _.selectors, 'optionalAccess', _2 => _2.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 = _optionalChain([option, 'optionalAccess', _3 => _3.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 = _optionalChain([option, 'optionalAccess', _4 => _4.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(_nullishCoalesce(option, () => ( {})), defaults.declarations); if (Object.keys(declarations).length === 0) { return void 0; } const pseudo = normalizePseudo(_nullishCoalesce(option, () => ( {})), defaults.pseudo); return { selectors: selectors.map(convertSelectorForBase), declarations, pseudo }; } var reset = _plugin2.default.withOptions( (options) => { const rules = []; const buttonRule = createResetRule(_optionalChain([options, 'optionalAccess', _5 => _5.buttonReset]), { selectors: DEFAULT_BUTTON_RESET_SELECTORS, declarations: DEFAULT_BUTTON_DECLARATIONS, pseudo: BUTTON_RESET_PSEUDO_DECLARATIONS }); if (buttonRule) { rules.push(buttonRule); } const imageRule = createResetRule(_optionalChain([options, 'optionalAccess', _6 => _6.imageReset]), { selectors: DEFAULT_IMAGE_RESET_SELECTORS, declarations: DEFAULT_IMAGE_DECLARATIONS }); if (imageRule) { rules.push(imageRule); } for (const extra of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _7 => _7.extraResets]), () => ( []))) { const normalized = createResetRule(extra, { selectors: _nullishCoalesce(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; exports.default = reset_default; exports.reset = reset;