weapp-tailwindcss
Version:
把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!
75 lines (73 loc) • 2.51 kB
JavaScript
import {
setupPatchRecorder
} from "./chunk-GIUNRP65.mjs";
import {
collectRuntimeClassSet,
getCompilerContext,
refreshTailwindRuntimeState
} from "./chunk-4Z6MHSEO.mjs";
import "./chunk-SZOXLSNK.mjs";
import "./chunk-TFOTUR4L.mjs";
import "./chunk-RR5HCKVQ.mjs";
import "./chunk-SM5V25IN.mjs";
// src/core.ts
import process from "process";
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
function createContext(options = {}) {
const opts = getCompilerContext(options);
const { templateHandler, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
const patchRecorderState = setupPatchRecorder(initialTwPatcher, opts.tailwindcssBasedir, {
source: "runtime",
cwd: opts.tailwindcssBasedir ?? process.cwd()
});
let runtimeSet = /* @__PURE__ */ new Set();
const runtimeState = {
twPatcher: initialTwPatcher,
patchPromise: patchRecorderState.patchPromise,
refreshTailwindcssPatcher,
onPatchCompleted: patchRecorderState.onPatchCompleted
};
async function refreshRuntimeState(force) {
await refreshTailwindRuntimeState(runtimeState, force);
}
async function transformWxss(rawCss, options2) {
await runtimeState.patchPromise;
const result = await styleHandler(rawCss, defuOverrideArray(options2, {
isMainChunk: true
}));
await refreshRuntimeState(true);
await runtimeState.patchPromise;
runtimeSet = await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
return result;
}
async function transformJs(rawJs, options2 = {}) {
await runtimeState.patchPromise;
if (options2?.runtimeSet) {
runtimeSet = options2.runtimeSet;
} else {
await refreshRuntimeState(true);
await runtimeState.patchPromise;
runtimeSet = await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
}
return await jsHandler(rawJs, runtimeSet, options2);
}
async function transformWxml(rawWxml, options2) {
await runtimeState.patchPromise;
if (!options2?.runtimeSet && runtimeSet.size === 0) {
await refreshRuntimeState(true);
await runtimeState.patchPromise;
runtimeSet = await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
}
return templateHandler(rawWxml, defuOverrideArray(options2, {
runtimeSet
}));
}
return {
transformWxss,
transformWxml,
transformJs
};
}
export {
createContext
};