UNPKG

weapp-tailwindcss

Version:

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

75 lines (66 loc) 3.64 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; } var _chunkIGTIMGCPjs = require('./chunk-IGTIMGCP.js'); var _chunkA2OSQ5CVjs = require('./chunk-A2OSQ5CV.js'); require('./chunk-PT4IJT3Q.js'); require('./chunk-6R4BK6D6.js'); require('./chunk-FMBPNII7.js'); require('./chunk-MB4BR57E.js'); // src/core.ts var _process = require('process'); var _process2 = _interopRequireDefault(_process); var _shared = require('@weapp-tailwindcss/shared'); function createContext(options = {}) { const opts = _chunkA2OSQ5CVjs.getCompilerContext.call(void 0, options); const { templateHandler, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts; const patchRecorderState = _chunkIGTIMGCPjs.setupPatchRecorder.call(void 0, initialTwPatcher, opts.tailwindcssBasedir, { source: "runtime", cwd: _nullishCoalesce(opts.tailwindcssBasedir, () => ( _process2.default.cwd())) }); let runtimeSet = /* @__PURE__ */ new Set(); const runtimeState = { twPatcher: initialTwPatcher, patchPromise: patchRecorderState.patchPromise, refreshTailwindcssPatcher, onPatchCompleted: patchRecorderState.onPatchCompleted }; async function refreshRuntimeState(force) { await _chunkA2OSQ5CVjs.refreshTailwindRuntimeState.call(void 0, runtimeState, force); } async function transformWxss(rawCss, options2) { await runtimeState.patchPromise; const result = await styleHandler(rawCss, _shared.defuOverrideArray.call(void 0, options2, { isMainChunk: true })); await refreshRuntimeState(true); await runtimeState.patchPromise; runtimeSet = await _chunkA2OSQ5CVjs.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true }); return result; } async function transformJs(rawJs, options2 = {}) { await runtimeState.patchPromise; if (_optionalChain([options2, 'optionalAccess', _ => _.runtimeSet])) { runtimeSet = options2.runtimeSet; } else { await refreshRuntimeState(true); await runtimeState.patchPromise; runtimeSet = await _chunkA2OSQ5CVjs.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true }); } return await jsHandler(rawJs, runtimeSet, options2); } async function transformWxml(rawWxml, options2) { await runtimeState.patchPromise; if (!_optionalChain([options2, 'optionalAccess', _2 => _2.runtimeSet]) && runtimeSet.size === 0) { await refreshRuntimeState(true); await runtimeState.patchPromise; runtimeSet = await _chunkA2OSQ5CVjs.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, { force: true, skipRefresh: true }); } return templateHandler(rawWxml, _shared.defuOverrideArray.call(void 0, options2, { runtimeSet })); } return { transformWxss, transformWxml, transformJs }; } exports.createContext = createContext;