UNPKG

weapp-tailwindcss

Version:

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

1,087 lines (1,053 loc) 32.1 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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; } var _chunkPLMJW644js = require('./chunk-PLMJW644.js'); var _chunkIS2CB3USjs = require('./chunk-IS2CB3US.js'); var _chunkO335YLYHjs = require('./chunk-O335YLYH.js'); var _chunkBZ6OV5EPjs = require('./chunk-BZ6OV5EP.js'); // src/cache/index.ts var _lrucache = require('lru-cache'); // src/cache/md5.ts var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto); function md5Hash(data) { return _crypto2.default.createHash("md5").update(data).digest("hex"); } // src/cache/index.ts function createCache(options) { const disabled = options === false; const hashMap = /* @__PURE__ */ new Map(); const instance = new (0, _lrucache.LRUCache)({ // 可能会添加和删除一些页面和组件, 先设定 1024 吧 max: 1024, ttl: 0, ttlAutopurge: false }); return { hashMap, instance, hasHashKey(key) { return hashMap.has(key); }, getHashValue(key) { return hashMap.get(key); }, setHashValue(key, value) { return hashMap.set(key, value); }, get(key) { return instance.get(key); }, set(key, value) { return instance.set(key, value); }, computeHash(message) { return md5Hash(message); }, calcHashValueChanged(key, hash) { const hit = this.getHashValue(key); if (hit) { this.setHashValue(key, { // new file should be changed changed: hash !== hit.hash, // new hash hash }); } else { this.setHashValue(key, { // new file should be changed changed: true, hash }); } return this; }, has(key) { return instance.has(key); }, async process(key, callback, fallback) { if (disabled) { const res = await fallback(); if (res) { this.set(res.key, res.source); } } else { const hit = this.getHashValue(key); if (hit && !hit.changed) { const returnFlag = await callback(); if (returnFlag !== false) { return; } } const res = await fallback(); if (res) { this.set(res.key, res.source); } } } }; } function initializeCache(cacheConfig) { if (typeof cacheConfig === "boolean" || cacheConfig === void 0) { return createCache(cacheConfig); } return cacheConfig; } // src/babel/index.ts var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse); var _parser = require('@babel/parser'); function _interopDefaultCompat(e) { return e && typeof e === "object" && "default" in e ? e.default : e; } var traverse = _interopDefaultCompat(_traverse2.default); // src/js/babel.ts var _escape = require('@ast-core/escape'); var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring); // src/js/handlers.ts var _regex = require('@weapp-core/regex'); var _extractors = require('@weapp-tailwindcss/shared/extractors'); // src/utils/decode.ts function decodeUnicode2(input) { try { return JSON.parse(`"${input}"`); } catch (_error) { return input; } } // src/js/handlers.ts function replaceHandleValue(path2, options) { const { classNameSet, escapeMap, mangleContext: ctx, needEscaped = false, jsPreserveClass, arbitraryValues, alwaysEscape, unescapeUnicode } = options; const allowDoubleQuotes = _optionalChain([arbitraryValues, 'optionalAccess', _2 => _2.allowDoubleQuotes]); const offset = path2.isStringLiteral() ? 1 : 0; const str = path2.isStringLiteral() ? path2.node.value : path2.isTemplateElement() ? path2.node.value.raw : ""; let rawStr = str; let needUpdate = false; if (unescapeUnicode && rawStr.includes("\\u")) { rawStr = decodeUnicode2(rawStr); } const node = path2.node; const arr = _extractors.splitCode.call(void 0, rawStr, allowDoubleQuotes); for (const v of arr) { if (alwaysEscape || classNameSet && classNameSet.has(v) && !_optionalChain([jsPreserveClass, 'optionalCall', _3 => _3(v)])) { let ignoreFlag = false; if (Array.isArray(node.leadingComments)) { ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes("weapp-tw") && x.value.includes("ignore")) > -1; } if (!ignoreFlag) { if (ctx) { rawStr = ctx.jsHandler(rawStr); } rawStr = rawStr.replace( new RegExp(_regex.escapeStringRegexp.call(void 0, v)), _chunkPLMJW644js.replaceWxml.call(void 0, v, { escapeMap }) ); needUpdate = true; } } } if (needUpdate && typeof node.start === "number" && typeof node.end === "number") { const start = node.start + offset; const end = node.end - offset; if (start < end && str !== rawStr) { const value = needEscaped ? _escape.jsStringEscape.call(void 0, rawStr) : rawStr; return { start, end, value, path: path2 }; } } } // src/js/JsTokenUpdater.ts var JsTokenUpdater = class { constructor({ value } = {}) { this.value = _nullishCoalesce(value, () => ( [])); } addToken(token) { if (token) { this.value.push(token); } } push(...args) { this.value.push(...args); return this; } map(callbackfn) { this.value = this.value.map(callbackfn); return this; } filter(callbackfn) { this.value = this.value.filter(callbackfn); return this; } updateMagicString(ms) { for (const { start, end, value } of this.value) { ms.update(start, end, value); } return ms; } }; // src/js/NodePathWalker.ts var walkedBindingWeakMap = /* @__PURE__ */ new WeakMap(); var NodePathWalker = class { constructor({ ignoreCallExpressionIdentifiers, callback } = {}) { this.ignoreCallExpressionIdentifiers = _nullishCoalesce(ignoreCallExpressionIdentifiers, () => ( [])); this.callback = _nullishCoalesce(callback, () => ( (() => { }))); this.imports = /* @__PURE__ */ new Set(); } walkVariableDeclarator(path2) { const init = path2.get("init"); this.walkNode(init); } walkTemplateLiteral(path2) { for (const exp of path2.get("expressions")) { this.walkNode(exp); } for (const quasis of path2.get("quasis")) { this.callback(quasis); } } walkStringLiteral(path2) { this.callback(path2); } walkBinaryExpression(path2) { const left = path2.get("left"); this.walkNode(left); const right = path2.get("right"); this.walkNode(right); } walkLogicalExpression(path2) { const left = path2.get("left"); this.walkNode(left); const right = path2.get("right"); this.walkNode(right); } walkObjectExpression(path2) { const props = path2.get("properties"); for (const prop of props) { if (prop.isObjectProperty()) { const key = prop.get("key"); this.walkNode(key); const value = prop.get("value"); this.walkNode(value); } } } walkArrayExpression(path2) { const elements = path2.get("elements"); for (const element of elements) { this.walkNode(element); } } walkNode(arg) { if (walkedBindingWeakMap.get(arg)) { return; } walkedBindingWeakMap.set(arg, true); if (arg.isIdentifier()) { const binding = arg.scope.getBinding(arg.node.name); if (binding) { this.walkNode(binding.path); } } else if (arg.isMemberExpression()) { const objectPath = arg.get("object"); if (objectPath.isIdentifier()) { const binding = arg.scope.getBinding(objectPath.node.name); if (binding) { if (binding.path.isVariableDeclarator()) { this.walkVariableDeclarator(binding.path); } } } } else if (arg.isTemplateLiteral()) { this.walkTemplateLiteral(arg); } else if (arg.isStringLiteral()) { this.walkStringLiteral(arg); } else if (arg.isBinaryExpression()) { this.walkBinaryExpression(arg); } else if (arg.isLogicalExpression()) { this.walkLogicalExpression(arg); } else if (arg.isObjectExpression()) { this.walkObjectExpression(arg); } else if (arg.isArrayExpression()) { this.walkArrayExpression(arg); } else if (arg.isVariableDeclarator()) { this.walkVariableDeclarator(arg); } else if (arg.isImportSpecifier() && arg.node.importKind !== "type" || arg.isImportDefaultSpecifier()) { const importDeclaration = arg.parentPath; if (importDeclaration.isImportDeclaration() && importDeclaration.node.importKind !== "type") { if (arg.isImportSpecifier()) { const imported = arg.get("imported"); if (imported.isIdentifier()) { this.imports.add( { declaration: importDeclaration, specifier: arg, imported: imported.node.name, source: importDeclaration.node.source.value, type: "ImportSpecifier" } ); } } else if (arg.isImportDefaultSpecifier()) { this.imports.add( { declaration: importDeclaration, specifier: arg, source: importDeclaration.node.source.value, type: "ImportDefaultSpecifier" } ); } } } } /** * @description main 方法 * @param path */ walkCallExpression(path2) { const calleePath = path2.get("callee"); if (calleePath.isIdentifier() && _chunkO335YLYHjs.regExpTest.call(void 0, this.ignoreCallExpressionIdentifiers, calleePath.node.name, { exact: true })) { for (const arg of path2.get("arguments")) { this.walkNode(arg); } } } walkExportDeclaration(path2) { if (path2.isExportDeclaration()) { if (path2.isExportNamedDeclaration()) { this.walkExportNamedDeclaration(path2); } else if (path2.isExportDefaultDeclaration()) { this.walkExportDefaultDeclaration(path2); } else if (path2.isExportAllDeclaration()) { this.walkExportAllDeclaration(path2); } } } walkExportNamedDeclaration(path2) { const declaration = path2.get("declaration"); if (declaration.isVariableDeclaration()) { for (const decl of declaration.get("declarations")) { this.walkNode(decl); } } const specifiers = path2.get("specifiers"); for (const spec of specifiers) { if (spec.isExportSpecifier()) { const local = spec.get("local"); if (local.isIdentifier()) { this.walkNode(local); } } } } walkExportDefaultDeclaration(path2) { const decl = path2.get("declaration"); if (decl.isIdentifier()) { this.walkNode(decl); } } walkExportAllDeclaration(path2) { const source = path2.get("source"); if (source.isStringLiteral()) { this.imports.add( { declaration: path2, source: source.node.value, type: "ExportAllDeclaration" } ); } } }; // src/js/babel.ts var parseCache = new (0, _lrucache.LRUCache)( { max: 512 } ); function genCacheKey(source, options) { return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val); } function babelParse(code, { cache, ...options } = {}) { const cacheKey = genCacheKey(code, options); let result; if (cache) { result = parseCache.get(cacheKey); } if (!result) { result = _parser.parse.call(void 0, code, options); if (cache) { parseCache.set(cacheKey, result); } } return result; } function isEvalPath(p) { if (p.isCallExpression()) { const calleePath = p.get("callee"); return calleePath.isIdentifier( { name: "eval" } ); } return false; } var ignoreFlagMap = /* @__PURE__ */ new WeakMap(); function analyzeSource(ast, options) { const jsTokenUpdater = new JsTokenUpdater(); const walker = new NodePathWalker( { ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers, callback(path2) { if (path2.isStringLiteral() || path2.isTemplateElement()) { ignoreFlagMap.set(path2, true); } } } ); const targetPaths = []; const importDeclarations = /* @__PURE__ */ new Set(); const exportDeclarations = /* @__PURE__ */ new Set(); const traverseOptions = { StringLiteral: { enter(p) { if (isEvalPath(p.parentPath)) { return; } targetPaths.push(p); } }, TemplateElement: { enter(p) { const pp = p.parentPath; if (pp.isTemplateLiteral()) { const ppp = pp.parentPath; if (isEvalPath(ppp)) { return; } if (ppp.isTaggedTemplateExpression()) { const tagPath = ppp.get("tag"); if (tagPath.isIdentifier() && _chunkO335YLYHjs.regExpTest.call(void 0, _nullishCoalesce(options.ignoreTaggedTemplateExpressionIdentifiers, () => ( [])), tagPath.node.name, { exact: true })) { return; } } } targetPaths.push(p); } }, CallExpression: { enter(p) { if (isEvalPath(p)) { p.traverse({ StringLiteral: { enter(path2) { const { code } = jsHandler(path2.node.value, { ...options, needEscaped: false, generateMap: false }); if (code) { const node = path2.node; if (typeof node.start === "number" && typeof node.end === "number") { const start = node.start + 1; const end = node.end - 1; if (start < end && path2.node.value !== code) { jsTokenUpdater.addToken( { start, end, value: _escape.jsStringEscape.call(void 0, code), path: path2 } ); } } } } }, TemplateElement: { enter(path2) { const { code } = jsHandler(path2.node.value.raw, { ...options, generateMap: false }); if (code) { const node = path2.node; if (typeof node.start === "number" && typeof node.end === "number") { const start = node.start; const end = node.end; if (start < end && path2.node.value.raw !== code) { jsTokenUpdater.addToken( { start, end, value: code, path: path2 } ); } } } } } }); return; } walker.walkCallExpression(p); } }, ImportDeclaration: { enter(p) { importDeclarations.add(p); } }, ExportDeclaration: { enter(p) { exportDeclarations.add(p); } } }; traverse(ast, traverseOptions); return { walker, jsTokenUpdater, ast, targetPaths, importDeclarations, exportDeclarations // jsTokens, }; } function processUpdatedSource(rawSource, options, analysis) { const ms = new (0, _magicstring2.default)(rawSource); const { targetPaths, jsTokenUpdater } = analysis; const tokens = targetPaths.filter( (x) => { return !ignoreFlagMap.get(x); } ).map( (p) => { if (p.isStringLiteral()) { return replaceHandleValue( p, { ...options, needEscaped: _nullishCoalesce(options.needEscaped, () => ( true)) } ); } else if (p.isTemplateElement()) { return replaceHandleValue( p, { ...options, needEscaped: false } ); } return void 0; } ).filter(Boolean); jsTokenUpdater.push( ...tokens ).filter( (x) => { return !ignoreFlagMap.get(x.path); } ).updateMagicString(ms); return ms; } function jsHandler(rawSource, options) { let ast; try { ast = babelParse(rawSource, options.babelParserOptions); } catch (error) { return { code: rawSource, error }; } const analysis = analyzeSource(ast, options); const ms = processUpdatedSource(rawSource, options, analysis); return { code: ms.toString(), get map() { return ms.generateMap(); } }; } // src/js/index.ts function createJsHandler(options) { const { mangleContext, arbitraryValues, escapeMap, jsPreserveClass, generateMap, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers } = options; function handler(rawSource, classNameSet, options2) { const opts = _chunkO335YLYHjs.defuOverrideArray.call(void 0, options2, { classNameSet, escapeMap, arbitraryValues, mangleContext, jsPreserveClass, generateMap, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers }); return jsHandler(rawSource, opts); } return handler; } // src/tailwindcss/index.ts var _localpkg = require('local-pkg'); // src/tailwindcss/patcher.ts var _path = require('path'); var _path2 = _interopRequireDefault(_path); var _process = require('process'); var _process2 = _interopRequireDefault(_process); var _shared = require('@weapp-tailwindcss/shared'); var _tailwindcsspatch = require('tailwindcss-patch'); function createTailwindcssPatcher(options) { const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {}; const cache = {}; if (cacheDir) { if (_path2.default.isAbsolute(cacheDir)) { cache.dir = cacheDir; } else if (basedir) { cache.dir = _path2.default.resolve(basedir, cacheDir); } else { cache.dir = _path2.default.resolve(_process2.default.cwd(), cacheDir); } } return new (0, _tailwindcsspatch.TailwindcssPatcher)(_shared.defuOverrideArray.call(void 0, tailwindcssPatcherOptions, { cache, patch: { basedir, applyPatches: { exportContext: true, extendLengthUnits: supportCustomLengthUnitsPatch }, tailwindcss, resolve: { paths: [ _chunkBZ6OV5EPjs.importMetaUrl ] } } } )); } // src/wxml/utils.ts var _types = require('@babel/types'); var t = _interopRequireWildcard(_types); var _htmlparser2 = require('htmlparser2'); // src/wxml/Tokenizer.ts var Tokenizer = class { constructor() { this.reset(); } processChar(char, index) { switch (this.state) { case 0 /* START */: if (char === " ") { } else if (char === "{") { this.state = 2 /* OPEN_BRACE */; this.bufferStartIndex = index; this.buffer += char; this.expressionBuffer = char; this.expressionStartIndex = index; } else { this.state = 1 /* TEXT */; this.bufferStartIndex = index; this.buffer += char; } break; case 1 /* TEXT */: if (char === " ") { this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions }); this.buffer = ""; this.expressions = []; this.state = 0 /* START */; } else if (char === "{") { this.buffer += char; this.expressionBuffer = char; this.expressionStartIndex = index; this.state = 2 /* OPEN_BRACE */; } else { this.buffer += char; } break; case 2 /* OPEN_BRACE */: if (char === "}") { this.buffer += char; this.expressionBuffer += char; this.state = 3 /* POTENTIAL_CLOSE */; } else { this.buffer += char; this.expressionBuffer += char; } break; case 3 /* POTENTIAL_CLOSE */: if (char === "}") { this.buffer += char; this.expressionBuffer += char; this.expressions.push({ start: this.expressionStartIndex, end: index + 1, value: this.expressionBuffer }); this.expressionBuffer = ""; this.state = 4 /* BRACES_COMPLETE */; } else { this.buffer += char; this.expressionBuffer += char; this.state = 2 /* OPEN_BRACE */; } break; case 4 /* BRACES_COMPLETE */: if (char === " ") { this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions }); this.buffer = ""; this.expressions = []; this.state = 0 /* START */; } else if (char === "{") { this.expressionStartIndex = index; this.expressionBuffer = char; this.buffer += char; this.state = 2 /* OPEN_BRACE */; } else { this.buffer += char; this.state = 1 /* TEXT */; } break; default: throw new Error("Unexpected state"); } } run(input) { for (let i = 0; i < input.length; i++) { const char = input[i]; this.processChar(char, i); } if (this.buffer.length > 0) { this.tokens.push({ start: this.bufferStartIndex, end: input.length, value: this.buffer, expressions: this.expressions }); } return this.tokens; } reset() { this.state = 0 /* START */; this.buffer = ""; this.tokens = []; this.bufferStartIndex = 0; this.expressionBuffer = ""; this.expressionStartIndex = 0; this.expressions = []; } }; // src/wxml/utils.ts function generateCode(match, options = {}) { try { const { jsHandler: jsHandler2, runtimeSet } = options; if (jsHandler2 && runtimeSet) { const { code } = jsHandler2(match, runtimeSet); return code; } else { const ms = new (0, _magicstring2.default)(match); const ast = _parser.parseExpression.call(void 0, match); const jsTokenUpdater = new JsTokenUpdater(); traverse(ast, { StringLiteral(path2) { if (t.isMemberExpression(path2.parent)) { return; } if (t.isBinaryExpression(path2.parent) && (t.isConditionalExpression(_optionalChain([path2, 'access', _4 => _4.parentPath, 'optionalAccess', _5 => _5.parent])) || t.isLogicalExpression(_optionalChain([path2, 'access', _6 => _6.parentPath, 'optionalAccess', _7 => _7.parent])))) { return; } jsTokenUpdater.addToken( replaceHandleValue( path2, { mangleContext: options.mangleContext, escapeMap: options.escapeMap, classNameSet: options.runtimeSet, needEscaped: true, alwaysEscape: true } ) ); }, noScope: true }); jsTokenUpdater.updateMagicString(ms); return ms.toString(); } } catch (e2) { return match; } } function handleEachClassFragment(ms, tokens, options = {}) { for (const token of tokens) { let p = token.start; if (token.expressions.length > 0) { for (const exp of token.expressions) { if (exp.start > token.start && p < exp.start) { ms.update(p, exp.start, _chunkPLMJW644js.replaceWxml.call(void 0, ms.slice(p, exp.start), { keepEOL: true, escapeMap: options.escapeMap, mangleContext: options.mangleContext, // 首的str才会被转译 // example: 2xl:xx 2x{{y}} ignoreHead: p > 0 })); } const code = `{{${generateCode(exp.value.slice(2, -2), options)}}}`; ms.update(exp.start, exp.end, code); p = exp.end; } if (token.end > p) { ms.update(p, token.end, _chunkPLMJW644js.replaceWxml.call(void 0, ms.slice(p, token.end), { keepEOL: false, escapeMap: options.escapeMap, mangleContext: options.mangleContext, ignoreHead: true })); } } else { ms.update(token.start, token.end, _chunkPLMJW644js.replaceWxml.call(void 0, token.value, { keepEOL: false, escapeMap: options.escapeMap, mangleContext: options.mangleContext, ignoreHead: false })); } } } function templateReplacer(original, options = {}) { const ms = new (0, _magicstring2.default)(original); const tokenizer = new Tokenizer(); const tokens = tokenizer.run(ms.original); handleEachClassFragment(ms, tokens, options); return ms.toString(); } function regTest(reg, str) { reg.lastIndex = 0; return reg.test(str); } function isPropsMatch(props, attr) { if (Array.isArray(props)) { for (const prop of props) { const res = typeof prop === "string" ? prop.toLowerCase() === attr.toLowerCase() : regTest(prop, attr); if (res) { return res; } } return false; } else if (typeof props === "string") { return props === attr; } else { return regTest(props, attr); } } async function customTemplateHandler(rawSource, options) { const { customAttributesEntities = [], disabledDefaultTemplateHandler, inlineWxs, runtimeSet, jsHandler: jsHandler2 } = _nullishCoalesce(options, () => ( {})); const s = new (0, _magicstring2.default)(rawSource); let tag = ""; const wxsArray = []; const parser = new (0, _htmlparser2.Parser)( { onopentagname(name) { tag = name; }, onattribute(name, value, quote) { if (value) { let update2 = function() { s.update( parser.startIndex + name.length + 2, // !important // htmlparser2 9.0.0: parser.endIndex // htmlparser2 9.1.0: parser.endIndex - 1 // https://github.com/sonofmagic/weapp-tailwindcss/issues/269 parser.endIndex - 1, templateReplacer(value, { ...options, quote }) ); }; var update = update2; if (!disabledDefaultTemplateHandler && ["class", "hover-class", "virtualhostclass"].includes(name.toLocaleLowerCase())) { update2(); } for (const [t2, props] of customAttributesEntities) { if (t2 === "*") { if (isPropsMatch(props, name)) { update2(); } } else if (typeof t2 === "string") { if (t2 === tag && isPropsMatch(props, name)) { update2(); } } else if (regTest(t2, tag) && isPropsMatch(props, name)) { update2(); } } } }, ontext(data) { if (inlineWxs && tag === "wxs") { wxsArray.push({ data, endIndex: parser.endIndex + 1, startIndex: parser.startIndex }); } }, onclosetag() { tag = ""; } }, { xmlMode: true } ); parser.write(s.original); parser.end(); for (const { data, endIndex, startIndex } of wxsArray) { const { code } = await jsHandler2(data, runtimeSet); s.update(startIndex, endIndex, code); } return s.toString(); } function createTemplateHandler(options = {}) { return (rawSource, opt = {}) => { return customTemplateHandler(rawSource, _chunkO335YLYHjs.defuOverrideArray.call(void 0, opt, options)); }; } // src/context/index.ts var _mangle = require('@weapp-tailwindcss/mangle'); var _postcss = require('@weapp-tailwindcss/postcss'); function getCompilerContext(opts) { const ctx = _chunkO335YLYHjs.defuOverrideArray.call(void 0, opts, _chunkIS2CB3USjs.getDefaultOptions.call(void 0, ), {} ); ctx.escapeMap = ctx.customReplaceDictionary; const { cssPreflight, customRuleCallback, cssPreflightRange, customAttributes, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass, disabledDefaultTemplateHandler, cssSelectorReplacement, rem2rpx, cache, babelParserOptions, postcssOptions, cssRemoveProperty, cssRemoveHoverPseudoClass, escapeMap, mangle, tailwindcssBasedir, appType, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, cssPresetEnv, tailwindcss, tailwindcssPatcherOptions } = ctx; const customAttributesEntities = _chunkO335YLYHjs.isMap.call(void 0, customAttributes) ? [...customAttributes.entries()] : Object.entries(customAttributes); const { initMangle, mangleContext, setMangleRuntimeSet } = _mangle.useMangleStore.call(void 0, ); initMangle(mangle); const styleHandler = _postcss.createStyleHandler.call(void 0, { cssPreflight, customRuleCallback, cssPreflightRange, escapeMap, mangleContext, cssChildCombinatorReplaceValue, injectAdditionalCssVarScope, cssSelectorReplacement, rem2rpx, postcssOptions, cssRemoveProperty, cssRemoveHoverPseudoClass, cssPresetEnv }); const jsHandler2 = createJsHandler({ escapeMap, mangleContext, arbitraryValues, jsPreserveClass, generateMap: true, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers }); const templateHandler = createTemplateHandler({ customAttributesEntities, escapeMap, mangleContext, inlineWxs, jsHandler: jsHandler2, disabledDefaultTemplateHandler }); ctx.styleHandler = styleHandler; ctx.jsHandler = jsHandler2; ctx.templateHandler = templateHandler; const twPatcher = createTailwindcssPatcher( { basedir: tailwindcssBasedir, cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0, supportCustomLengthUnitsPatch: _nullishCoalesce(supportCustomLengthUnitsPatch, () => ( true)), tailwindcss, tailwindcssPatcherOptions } ); ctx.setMangleRuntimeSet = setMangleRuntimeSet; ctx.cache = initializeCache(cache); ctx.twPatcher = twPatcher; return ctx; } exports.getCompilerContext = getCompilerContext;