@weapp-tailwindcss/react-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/babel.cjs +112 -0
- package/dist/babel.d.ts +21 -0
- package/dist/babel.js +110 -0
- package/dist/compiler.cjs +383 -0
- package/dist/compiler.d.ts +8 -0
- package/dist/compiler.js +378 -0
- package/dist/env.cjs +1 -0
- package/dist/env.d.ts +14 -0
- package/dist/env.js +2 -0
- package/dist/index.cjs +22 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/metro-transformer.cjs +52 -0
- package/dist/metro-transformer.d.ts +5 -0
- package/dist/metro-transformer.js +49 -0
- package/dist/metro.cjs +156 -0
- package/dist/metro.d.ts +39 -0
- package/dist/metro.js +145 -0
- package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
- package/dist/runtime.cjs +187 -0
- package/dist/runtime.d.ts +17 -0
- package/dist/runtime.js +179 -0
- package/dist/tailwind.cjs +50 -0
- package/dist/tailwind.d.ts +13 -0
- package/dist/tailwind.js +49 -0
- package/dist/types-BTxnqaRV.d.ts +48 -0
- package/package.json +109 -0
package/dist/metro.cjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
|
|
3
|
+
const require_compiler = require("./compiler.cjs");
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
6
|
+
let node_os = require("node:os");
|
|
7
|
+
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
8
|
+
let node_path = require("node:path");
|
|
9
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
10
|
+
let node_process = require("node:process");
|
|
11
|
+
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
12
|
+
let node_url = require("node:url");
|
|
13
|
+
//#region src/metro.ts
|
|
14
|
+
const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
15
|
+
const registry = /* @__PURE__ */ new Map();
|
|
16
|
+
let nextId = 0;
|
|
17
|
+
function resolveInput(input, projectRoot) {
|
|
18
|
+
return input ? node_path.default.resolve(projectRoot, input) : void 0;
|
|
19
|
+
}
|
|
20
|
+
function emptyManifest() {
|
|
21
|
+
return {
|
|
22
|
+
version: 1,
|
|
23
|
+
classSet: [],
|
|
24
|
+
rules: {},
|
|
25
|
+
variables: {},
|
|
26
|
+
warnings: []
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function virtualModuleCode(manifest) {
|
|
30
|
+
return `import { setEnvironment, setManifest, setStyleSheetFactory } from ${JSON.stringify("@weapp-tailwindcss/react-native/runtime")};\nimport { Appearance, Platform, StyleSheet } from 'react-native';\nsetStyleSheetFactory(StyleSheet.create);\nconst syncEnvironment = () => setEnvironment({ platform: Platform.OS, colorScheme: Appearance.getColorScheme() ?? 'light' });\nsetManifest(${JSON.stringify(manifest)});\nsyncEnvironment();\nAppearance.addChangeListener?.(({ colorScheme }) => setEnvironment({ platform: Platform.OS, colorScheme: colorScheme ?? 'light' }));\nexport default undefined;`;
|
|
31
|
+
}
|
|
32
|
+
function writeVirtualModule(entry) {
|
|
33
|
+
node_fs.default.mkdirSync(node_path.default.dirname(entry.virtualPath), { recursive: true });
|
|
34
|
+
node_fs.default.writeFileSync(entry.virtualPath, virtualModuleCode(entry.manifest), "utf8");
|
|
35
|
+
node_fs.default.writeFileSync(entry.manifestPath, JSON.stringify(entry.manifest), "utf8");
|
|
36
|
+
}
|
|
37
|
+
async function compileOptions(options, projectRoot) {
|
|
38
|
+
if (options.manifest) return options.manifest;
|
|
39
|
+
if (options.input) {
|
|
40
|
+
const { generateNativeStylesheet } = await (require("url").pathToFileURL(__filename).href.endsWith(".ts") ? Promise.resolve().then(() => require("./tailwind.cjs")) : Promise.resolve().then(() => require("./tailwind.cjs")));
|
|
41
|
+
return generateNativeStylesheet({
|
|
42
|
+
projectRoot,
|
|
43
|
+
cssEntries: [resolveInput(options.input, projectRoot)],
|
|
44
|
+
candidates: options.classSet,
|
|
45
|
+
sourceGlobs: options.sourceGlobs
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return require_compiler.compileNativeStylesheet(options.css ?? "", { classSet: options.classSet });
|
|
49
|
+
}
|
|
50
|
+
function register(options) {
|
|
51
|
+
const id = `weapp-tailwindcss-native-${nextId++}`;
|
|
52
|
+
const projectRoot = node_path.default.resolve(options.projectRoot ?? node_process.default.cwd());
|
|
53
|
+
const entry = {
|
|
54
|
+
version: 0,
|
|
55
|
+
manifest: options.manifest ?? (options.css ? require_compiler.compileNativeStylesheet(options.css, { classSet: options.classSet }) : emptyManifest()),
|
|
56
|
+
virtualPath: node_path.default.join(node_os.default.tmpdir(), "weapp-tailwindcss-native", `${id}.js`),
|
|
57
|
+
manifestPath: node_path.default.join(node_os.default.tmpdir(), "weapp-tailwindcss-native", `${id}.manifest.json`),
|
|
58
|
+
ready: Promise.resolve(),
|
|
59
|
+
refresh: async () => {}
|
|
60
|
+
};
|
|
61
|
+
registry.set(id, entry);
|
|
62
|
+
writeVirtualModule(entry);
|
|
63
|
+
let generation = 0;
|
|
64
|
+
entry.refresh = async () => {
|
|
65
|
+
const currentGeneration = ++generation;
|
|
66
|
+
const manifest = await compileOptions(options, projectRoot);
|
|
67
|
+
if (currentGeneration === generation) {
|
|
68
|
+
entry.manifest = manifest;
|
|
69
|
+
entry.version++;
|
|
70
|
+
writeVirtualModule(entry);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
entry.ready = entry.refresh().catch((error) => {
|
|
74
|
+
entry.manifest.warnings.push({ message: `生成 React Native manifest 失败:${error instanceof Error ? error.message : String(error)}` });
|
|
75
|
+
});
|
|
76
|
+
const sourceRoots = (options.sourceGlobs ?? []).map((pattern) => pattern.split(/[*{[]/, 1)[0]?.replace(/[/\\]$/, "")).filter(Boolean);
|
|
77
|
+
[
|
|
78
|
+
...options.watchFiles ?? [],
|
|
79
|
+
...options.input ? [options.input] : [],
|
|
80
|
+
...sourceRoots
|
|
81
|
+
].map((file) => {
|
|
82
|
+
const target = node_path.default.resolve(projectRoot, file);
|
|
83
|
+
try {
|
|
84
|
+
const recursive = node_fs.default.statSync(target).isDirectory();
|
|
85
|
+
return node_fs.default.watch(target, {
|
|
86
|
+
persistent: false,
|
|
87
|
+
recursive
|
|
88
|
+
}, () => {
|
|
89
|
+
entry.refresh();
|
|
90
|
+
});
|
|
91
|
+
} catch {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
id,
|
|
97
|
+
entry
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function getRegisteredVirtualModule(filename) {
|
|
101
|
+
for (const entry of registry.values()) if (entry.virtualPath === filename) return entry;
|
|
102
|
+
}
|
|
103
|
+
async function getRegisteredManifest(id) {
|
|
104
|
+
const registered = registry.get(id);
|
|
105
|
+
if (!registered) return;
|
|
106
|
+
await registered.ready;
|
|
107
|
+
return registered.manifest;
|
|
108
|
+
}
|
|
109
|
+
function getVirtualModuleCode(filename) {
|
|
110
|
+
const registered = getRegisteredVirtualModule(filename);
|
|
111
|
+
if (!registered) return;
|
|
112
|
+
return virtualModuleCode(registered.manifest);
|
|
113
|
+
}
|
|
114
|
+
async function getVirtualModuleCodeAsync(filename) {
|
|
115
|
+
const registered = getRegisteredVirtualModule(filename);
|
|
116
|
+
if (!registered) return;
|
|
117
|
+
await registered.ready;
|
|
118
|
+
return getVirtualModuleCode(filename);
|
|
119
|
+
}
|
|
120
|
+
function withWeappTailwindcss(config, options = {}) {
|
|
121
|
+
if (typeof config === "function" || config && typeof config.then === "function") return Promise.resolve(typeof config === "function" ? config() : config).then((resolved) => withWeappTailwindcss(resolved, options));
|
|
122
|
+
const resolvedConfig = config;
|
|
123
|
+
const { id, entry } = register(options);
|
|
124
|
+
const originalResolver = resolvedConfig.resolver?.resolveRequest;
|
|
125
|
+
const sourceExts = resolvedConfig.resolver?.sourceExts ?? [];
|
|
126
|
+
const virtualResolver = (context, moduleName, platform) => {
|
|
127
|
+
if (moduleName === "@weapp-tailwindcss/react-native/virtual") return {
|
|
128
|
+
type: "sourceFile",
|
|
129
|
+
filePath: entry.virtualPath
|
|
130
|
+
};
|
|
131
|
+
return originalResolver?.(context, moduleName, platform) ?? context.resolveRequest?.(context, moduleName, platform);
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
...resolvedConfig,
|
|
135
|
+
watchFolders: [.../* @__PURE__ */ new Set([...resolvedConfig.watchFolders ?? [], node_path.default.dirname(entry.virtualPath)])],
|
|
136
|
+
transformerPath: (0, node_url.fileURLToPath)(new URL(require("url").pathToFileURL(__filename).href.includes(".ts") ? "./metro-transformer.ts" : "./metro-transformer.js", require("url").pathToFileURL(__filename).href)),
|
|
137
|
+
transformer: {
|
|
138
|
+
...resolvedConfig.transformer,
|
|
139
|
+
weappTailwindcssMetroId: id,
|
|
140
|
+
weappTailwindcssOriginalTransformerPath: resolvedConfig.transformerPath,
|
|
141
|
+
weappTailwindcssManifestPath: entry.manifestPath
|
|
142
|
+
},
|
|
143
|
+
resolver: {
|
|
144
|
+
...resolvedConfig.resolver,
|
|
145
|
+
sourceExts: sourceExts.includes("css") ? sourceExts : [...sourceExts, "css"],
|
|
146
|
+
resolveRequest: virtualResolver
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
exports.VIRTUAL_MANIFEST_MODULE = VIRTUAL_MANIFEST_MODULE;
|
|
152
|
+
exports.getRegisteredManifest = getRegisteredManifest;
|
|
153
|
+
exports.getRegisteredVirtualModule = getRegisteredVirtualModule;
|
|
154
|
+
exports.getVirtualModuleCode = getVirtualModuleCode;
|
|
155
|
+
exports.getVirtualModuleCodeAsync = getVirtualModuleCodeAsync;
|
|
156
|
+
exports.withWeappTailwindcss = withWeappTailwindcss;
|
package/dist/metro.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { o as NativeStyleManifest } from "./types-BTxnqaRV.js";
|
|
2
|
+
//#region src/metro.d.ts
|
|
3
|
+
declare const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
4
|
+
interface MetroConfigLike {
|
|
5
|
+
resolver?: {
|
|
6
|
+
sourceExts?: string[];
|
|
7
|
+
resolveRequest?: (context: unknown, moduleName: string, platform?: string) => unknown;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
transformer?: Record<string, unknown>;
|
|
11
|
+
transformerPath?: string;
|
|
12
|
+
watchFolders?: string[];
|
|
13
|
+
server?: Record<string, unknown>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
interface WeappReactNativeMetroOptions {
|
|
17
|
+
projectRoot?: string | undefined;
|
|
18
|
+
input?: string | undefined;
|
|
19
|
+
css?: string | undefined;
|
|
20
|
+
manifest?: NativeStyleManifest | undefined;
|
|
21
|
+
classSet?: Iterable<string> | undefined;
|
|
22
|
+
sourceGlobs?: string[] | undefined;
|
|
23
|
+
watchFiles?: string[] | undefined;
|
|
24
|
+
}
|
|
25
|
+
interface RegisteredManifest {
|
|
26
|
+
version: number;
|
|
27
|
+
manifest: NativeStyleManifest;
|
|
28
|
+
virtualPath: string;
|
|
29
|
+
manifestPath: string;
|
|
30
|
+
ready: Promise<void>;
|
|
31
|
+
refresh: () => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
declare function getRegisteredVirtualModule(filename: string): RegisteredManifest | undefined;
|
|
34
|
+
declare function getRegisteredManifest(id: string): Promise<NativeStyleManifest | undefined>;
|
|
35
|
+
declare function getVirtualModuleCode(filename: string): string | undefined;
|
|
36
|
+
declare function getVirtualModuleCodeAsync(filename: string): Promise<string | undefined>;
|
|
37
|
+
declare function withWeappTailwindcss<T extends MetroConfigLike>(config: T | Promise<T> | (() => T | Promise<T>), options?: WeappReactNativeMetroOptions): T | Promise<T>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { MetroConfigLike, VIRTUAL_MANIFEST_MODULE, WeappReactNativeMetroOptions, getRegisteredManifest, getRegisteredVirtualModule, getVirtualModuleCode, getVirtualModuleCodeAsync, withWeappTailwindcss };
|
package/dist/metro.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { compileNativeStylesheet } from "./compiler.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
//#region src/metro.ts
|
|
8
|
+
const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
9
|
+
const registry = /* @__PURE__ */ new Map();
|
|
10
|
+
let nextId = 0;
|
|
11
|
+
function resolveInput(input, projectRoot) {
|
|
12
|
+
return input ? path.resolve(projectRoot, input) : void 0;
|
|
13
|
+
}
|
|
14
|
+
function emptyManifest() {
|
|
15
|
+
return {
|
|
16
|
+
version: 1,
|
|
17
|
+
classSet: [],
|
|
18
|
+
rules: {},
|
|
19
|
+
variables: {},
|
|
20
|
+
warnings: []
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function virtualModuleCode(manifest) {
|
|
24
|
+
return `import { setEnvironment, setManifest, setStyleSheetFactory } from ${JSON.stringify("@weapp-tailwindcss/react-native/runtime")};\nimport { Appearance, Platform, StyleSheet } from 'react-native';\nsetStyleSheetFactory(StyleSheet.create);\nconst syncEnvironment = () => setEnvironment({ platform: Platform.OS, colorScheme: Appearance.getColorScheme() ?? 'light' });\nsetManifest(${JSON.stringify(manifest)});\nsyncEnvironment();\nAppearance.addChangeListener?.(({ colorScheme }) => setEnvironment({ platform: Platform.OS, colorScheme: colorScheme ?? 'light' }));\nexport default undefined;`;
|
|
25
|
+
}
|
|
26
|
+
function writeVirtualModule(entry) {
|
|
27
|
+
fs.mkdirSync(path.dirname(entry.virtualPath), { recursive: true });
|
|
28
|
+
fs.writeFileSync(entry.virtualPath, virtualModuleCode(entry.manifest), "utf8");
|
|
29
|
+
fs.writeFileSync(entry.manifestPath, JSON.stringify(entry.manifest), "utf8");
|
|
30
|
+
}
|
|
31
|
+
async function compileOptions(options, projectRoot) {
|
|
32
|
+
if (options.manifest) return options.manifest;
|
|
33
|
+
if (options.input) {
|
|
34
|
+
const { generateNativeStylesheet } = await (import.meta.url.endsWith(".ts") ? import("./tailwind.js") : import("./tailwind.js"));
|
|
35
|
+
return generateNativeStylesheet({
|
|
36
|
+
projectRoot,
|
|
37
|
+
cssEntries: [resolveInput(options.input, projectRoot)],
|
|
38
|
+
candidates: options.classSet,
|
|
39
|
+
sourceGlobs: options.sourceGlobs
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return compileNativeStylesheet(options.css ?? "", { classSet: options.classSet });
|
|
43
|
+
}
|
|
44
|
+
function register(options) {
|
|
45
|
+
const id = `weapp-tailwindcss-native-${nextId++}`;
|
|
46
|
+
const projectRoot = path.resolve(options.projectRoot ?? process.cwd());
|
|
47
|
+
const entry = {
|
|
48
|
+
version: 0,
|
|
49
|
+
manifest: options.manifest ?? (options.css ? compileNativeStylesheet(options.css, { classSet: options.classSet }) : emptyManifest()),
|
|
50
|
+
virtualPath: path.join(os.tmpdir(), "weapp-tailwindcss-native", `${id}.js`),
|
|
51
|
+
manifestPath: path.join(os.tmpdir(), "weapp-tailwindcss-native", `${id}.manifest.json`),
|
|
52
|
+
ready: Promise.resolve(),
|
|
53
|
+
refresh: async () => {}
|
|
54
|
+
};
|
|
55
|
+
registry.set(id, entry);
|
|
56
|
+
writeVirtualModule(entry);
|
|
57
|
+
let generation = 0;
|
|
58
|
+
entry.refresh = async () => {
|
|
59
|
+
const currentGeneration = ++generation;
|
|
60
|
+
const manifest = await compileOptions(options, projectRoot);
|
|
61
|
+
if (currentGeneration === generation) {
|
|
62
|
+
entry.manifest = manifest;
|
|
63
|
+
entry.version++;
|
|
64
|
+
writeVirtualModule(entry);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
entry.ready = entry.refresh().catch((error) => {
|
|
68
|
+
entry.manifest.warnings.push({ message: `生成 React Native manifest 失败:${error instanceof Error ? error.message : String(error)}` });
|
|
69
|
+
});
|
|
70
|
+
const sourceRoots = (options.sourceGlobs ?? []).map((pattern) => pattern.split(/[*{[]/, 1)[0]?.replace(/[/\\]$/, "")).filter(Boolean);
|
|
71
|
+
[
|
|
72
|
+
...options.watchFiles ?? [],
|
|
73
|
+
...options.input ? [options.input] : [],
|
|
74
|
+
...sourceRoots
|
|
75
|
+
].map((file) => {
|
|
76
|
+
const target = path.resolve(projectRoot, file);
|
|
77
|
+
try {
|
|
78
|
+
const recursive = fs.statSync(target).isDirectory();
|
|
79
|
+
return fs.watch(target, {
|
|
80
|
+
persistent: false,
|
|
81
|
+
recursive
|
|
82
|
+
}, () => {
|
|
83
|
+
entry.refresh();
|
|
84
|
+
});
|
|
85
|
+
} catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
id,
|
|
91
|
+
entry
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function getRegisteredVirtualModule(filename) {
|
|
95
|
+
for (const entry of registry.values()) if (entry.virtualPath === filename) return entry;
|
|
96
|
+
}
|
|
97
|
+
async function getRegisteredManifest(id) {
|
|
98
|
+
const registered = registry.get(id);
|
|
99
|
+
if (!registered) return;
|
|
100
|
+
await registered.ready;
|
|
101
|
+
return registered.manifest;
|
|
102
|
+
}
|
|
103
|
+
function getVirtualModuleCode(filename) {
|
|
104
|
+
const registered = getRegisteredVirtualModule(filename);
|
|
105
|
+
if (!registered) return;
|
|
106
|
+
return virtualModuleCode(registered.manifest);
|
|
107
|
+
}
|
|
108
|
+
async function getVirtualModuleCodeAsync(filename) {
|
|
109
|
+
const registered = getRegisteredVirtualModule(filename);
|
|
110
|
+
if (!registered) return;
|
|
111
|
+
await registered.ready;
|
|
112
|
+
return getVirtualModuleCode(filename);
|
|
113
|
+
}
|
|
114
|
+
function withWeappTailwindcss(config, options = {}) {
|
|
115
|
+
if (typeof config === "function" || config && typeof config.then === "function") return Promise.resolve(typeof config === "function" ? config() : config).then((resolved) => withWeappTailwindcss(resolved, options));
|
|
116
|
+
const resolvedConfig = config;
|
|
117
|
+
const { id, entry } = register(options);
|
|
118
|
+
const originalResolver = resolvedConfig.resolver?.resolveRequest;
|
|
119
|
+
const sourceExts = resolvedConfig.resolver?.sourceExts ?? [];
|
|
120
|
+
const virtualResolver = (context, moduleName, platform) => {
|
|
121
|
+
if (moduleName === "@weapp-tailwindcss/react-native/virtual") return {
|
|
122
|
+
type: "sourceFile",
|
|
123
|
+
filePath: entry.virtualPath
|
|
124
|
+
};
|
|
125
|
+
return originalResolver?.(context, moduleName, platform) ?? context.resolveRequest?.(context, moduleName, platform);
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
...resolvedConfig,
|
|
129
|
+
watchFolders: [.../* @__PURE__ */ new Set([...resolvedConfig.watchFolders ?? [], path.dirname(entry.virtualPath)])],
|
|
130
|
+
transformerPath: fileURLToPath(new URL(import.meta.url.includes(".ts") ? "./metro-transformer.ts" : "./metro-transformer.js", import.meta.url)),
|
|
131
|
+
transformer: {
|
|
132
|
+
...resolvedConfig.transformer,
|
|
133
|
+
weappTailwindcssMetroId: id,
|
|
134
|
+
weappTailwindcssOriginalTransformerPath: resolvedConfig.transformerPath,
|
|
135
|
+
weappTailwindcssManifestPath: entry.manifestPath
|
|
136
|
+
},
|
|
137
|
+
resolver: {
|
|
138
|
+
...resolvedConfig.resolver,
|
|
139
|
+
sourceExts: sourceExts.includes("css") ? sourceExts : [...sourceExts, "css"],
|
|
140
|
+
resolveRequest: virtualResolver
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { VIRTUAL_MANIFEST_MODULE, getRegisteredManifest, getRegisteredVirtualModule, getVirtualModuleCode, getVirtualModuleCodeAsync, withWeappTailwindcss };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
Object.defineProperty(exports, "__toESM", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return __toESM;
|
|
27
|
+
}
|
|
28
|
+
});
|
package/dist/runtime.cjs
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/runtime.ts
|
|
3
|
+
let activeManifest;
|
|
4
|
+
let activeEnvironment = {};
|
|
5
|
+
const styleMetadata = /* @__PURE__ */ new Map();
|
|
6
|
+
let styleSheetFactory;
|
|
7
|
+
let nativeStyleSheet = {};
|
|
8
|
+
function createStyleSheet(manifest) {
|
|
9
|
+
const source = manifest.styleSheet ?? Object.fromEntries(Object.entries(manifest.styleEntries ?? {}).map(([id, rule]) => [id, rule.style]));
|
|
10
|
+
nativeStyleSheet = styleSheetFactory?.(source) ?? source;
|
|
11
|
+
}
|
|
12
|
+
function flatten(value, result) {
|
|
13
|
+
if (!value) return;
|
|
14
|
+
if (typeof value === "string") {
|
|
15
|
+
result.push(...value.split(/\s+/).filter(Boolean));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
for (const item of value) flatten(item, result);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const [className, enabled] of Object.entries(value)) if (enabled) result.push(className);
|
|
23
|
+
}
|
|
24
|
+
function canonicalTokens(value) {
|
|
25
|
+
const tokens = [];
|
|
26
|
+
flatten(value, tokens);
|
|
27
|
+
return [...new Set(tokens)].sort();
|
|
28
|
+
}
|
|
29
|
+
function matches(rule, environment) {
|
|
30
|
+
if (rule.colorScheme && rule.colorScheme !== environment.colorScheme) return false;
|
|
31
|
+
if (!rule.platform) return true;
|
|
32
|
+
if (rule.platform === "native") return environment.platform !== "web";
|
|
33
|
+
return rule.platform === environment.platform;
|
|
34
|
+
}
|
|
35
|
+
function resolveRules(ids, manifest, environment) {
|
|
36
|
+
const normal = [];
|
|
37
|
+
const important = [];
|
|
38
|
+
for (const id of ids) {
|
|
39
|
+
const rule = manifest?.styleEntries?.[id];
|
|
40
|
+
if (rule) {
|
|
41
|
+
if (!matches(rule, environment)) continue;
|
|
42
|
+
(rule.important ? important : normal).push({
|
|
43
|
+
rule,
|
|
44
|
+
id
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const fallbackIds = manifest?.staticLookup?.[id] ?? [];
|
|
49
|
+
if (fallbackIds.length) for (const fallbackId of fallbackIds) {
|
|
50
|
+
const fallbackRule = manifest.styleEntries?.[fallbackId];
|
|
51
|
+
if (!fallbackRule || !matches(fallbackRule, environment)) continue;
|
|
52
|
+
(fallbackRule.important ? important : normal).push({
|
|
53
|
+
rule: fallbackRule,
|
|
54
|
+
id: fallbackId
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else for (const fallbackRule of manifest?.rules?.[id] ?? []) {
|
|
58
|
+
if (!matches(fallbackRule, environment)) continue;
|
|
59
|
+
(fallbackRule.important ? important : normal).push({
|
|
60
|
+
rule: fallbackRule,
|
|
61
|
+
id
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const order = (left, right) => (left.rule.order ?? 0) - (right.rule.order ?? 0);
|
|
66
|
+
normal.sort(order);
|
|
67
|
+
important.sort(order);
|
|
68
|
+
const style = {};
|
|
69
|
+
const importantStyle = {};
|
|
70
|
+
for (const { rule } of normal) Object.assign(style, rule.style);
|
|
71
|
+
for (const { rule } of important) {
|
|
72
|
+
Object.assign(style, rule.style);
|
|
73
|
+
Object.assign(importantStyle, rule.style);
|
|
74
|
+
}
|
|
75
|
+
const normalIds = normal.map((item) => item.id);
|
|
76
|
+
const importantIds = important.map((item) => item.id);
|
|
77
|
+
const asStyleValue = (ids, fallback) => {
|
|
78
|
+
if (!styleSheetFactory) return fallback;
|
|
79
|
+
const values = ids.map((id) => nativeStyleSheet[id]).filter((value) => value !== void 0);
|
|
80
|
+
if (values.length === 1) return values[0];
|
|
81
|
+
if (values.length > 1) return values;
|
|
82
|
+
return fallback;
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
style,
|
|
86
|
+
importantStyle,
|
|
87
|
+
styleValue: asStyleValue(normalIds, style),
|
|
88
|
+
importantValue: asStyleValue(importantIds, importantStyle)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function resolveDynamic(value, manifest, environment) {
|
|
92
|
+
const classNames = canonicalTokens(value);
|
|
93
|
+
return resolveRules(manifest?.staticLookup ? classNames.flatMap((className) => manifest.staticLookup?.[className] ?? []) : classNames, manifest, environment);
|
|
94
|
+
}
|
|
95
|
+
function rememberStyle(style, importantStyle) {
|
|
96
|
+
if (importantStyle && (typeof importantStyle !== "object" || Object.keys(importantStyle).length)) styleMetadata.set(style, { important: importantStyle });
|
|
97
|
+
return style;
|
|
98
|
+
}
|
|
99
|
+
function createNativeStyleRuntime(initialManifest) {
|
|
100
|
+
let manifest = initialManifest;
|
|
101
|
+
let environment = activeEnvironment;
|
|
102
|
+
const cache = /* @__PURE__ */ new Map();
|
|
103
|
+
const runtime = {
|
|
104
|
+
tw(value, requestedEnvironment = {}) {
|
|
105
|
+
const effectiveEnvironment = {
|
|
106
|
+
...environment,
|
|
107
|
+
...requestedEnvironment
|
|
108
|
+
};
|
|
109
|
+
const key = `${canonicalTokens(value).join("")}|${effectiveEnvironment.colorScheme ?? ""}|${effectiveEnvironment.platform ?? ""}`;
|
|
110
|
+
const cached = cache.get(key);
|
|
111
|
+
if (cached) return cached;
|
|
112
|
+
const resolved = resolveDynamic(value, manifest, effectiveEnvironment);
|
|
113
|
+
const style = rememberStyle(resolved.styleValue, resolved.importantValue);
|
|
114
|
+
cache.set(key, style);
|
|
115
|
+
return style;
|
|
116
|
+
},
|
|
117
|
+
getStaticStyle(ids, requestedEnvironment = {}) {
|
|
118
|
+
const effectiveEnvironment = {
|
|
119
|
+
...environment,
|
|
120
|
+
...requestedEnvironment
|
|
121
|
+
};
|
|
122
|
+
const resolved = resolveRules(ids, manifest, effectiveEnvironment);
|
|
123
|
+
return rememberStyle(resolved.styleValue, resolved.importantValue);
|
|
124
|
+
},
|
|
125
|
+
composeStyle(tailwindStyle, inlineStyle) {
|
|
126
|
+
const important = styleMetadata.get(tailwindStyle)?.important;
|
|
127
|
+
return important !== void 0 ? [
|
|
128
|
+
tailwindStyle,
|
|
129
|
+
inlineStyle,
|
|
130
|
+
important
|
|
131
|
+
] : [tailwindStyle, inlineStyle];
|
|
132
|
+
},
|
|
133
|
+
setManifest(nextManifest) {
|
|
134
|
+
manifest = nextManifest;
|
|
135
|
+
cache.clear();
|
|
136
|
+
styleMetadata.clear();
|
|
137
|
+
createStyleSheet(nextManifest);
|
|
138
|
+
activeManifest = nextManifest;
|
|
139
|
+
},
|
|
140
|
+
setEnvironment(nextEnvironment) {
|
|
141
|
+
environment = nextEnvironment;
|
|
142
|
+
activeEnvironment = nextEnvironment;
|
|
143
|
+
cache.clear();
|
|
144
|
+
},
|
|
145
|
+
getManifest() {
|
|
146
|
+
return manifest;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
if (initialManifest) {
|
|
150
|
+
createStyleSheet(initialManifest);
|
|
151
|
+
activeManifest = initialManifest;
|
|
152
|
+
}
|
|
153
|
+
return runtime;
|
|
154
|
+
}
|
|
155
|
+
const defaultRuntime = createNativeStyleRuntime();
|
|
156
|
+
function setManifest(manifest) {
|
|
157
|
+
defaultRuntime.setManifest(manifest);
|
|
158
|
+
}
|
|
159
|
+
/** 由 Expo virtual module 注入,避免 runtime 引入 Node-only 的 require shim。 */
|
|
160
|
+
function setStyleSheetFactory(factory) {
|
|
161
|
+
styleSheetFactory = factory;
|
|
162
|
+
if (activeManifest) createStyleSheet(activeManifest);
|
|
163
|
+
}
|
|
164
|
+
function setEnvironment(environment) {
|
|
165
|
+
defaultRuntime.setEnvironment(environment);
|
|
166
|
+
}
|
|
167
|
+
function getManifest() {
|
|
168
|
+
return activeManifest ?? defaultRuntime.getManifest();
|
|
169
|
+
}
|
|
170
|
+
function tw(value, environment) {
|
|
171
|
+
return defaultRuntime.tw(value, environment);
|
|
172
|
+
}
|
|
173
|
+
function getStaticStyle(ids, environment) {
|
|
174
|
+
return defaultRuntime.getStaticStyle(ids, environment);
|
|
175
|
+
}
|
|
176
|
+
function composeStyle(tailwindStyle, inlineStyle) {
|
|
177
|
+
return defaultRuntime.composeStyle(tailwindStyle, inlineStyle);
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
exports.composeStyle = composeStyle;
|
|
181
|
+
exports.createNativeStyleRuntime = createNativeStyleRuntime;
|
|
182
|
+
exports.getManifest = getManifest;
|
|
183
|
+
exports.getStaticStyle = getStaticStyle;
|
|
184
|
+
exports.setEnvironment = setEnvironment;
|
|
185
|
+
exports.setManifest = setManifest;
|
|
186
|
+
exports.setStyleSheetFactory = setStyleSheetFactory;
|
|
187
|
+
exports.tw = tw;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { a as NativeStyleEnvironment, c as NativeStyleRuntime, i as NativePlatform, l as NativeStyleValue, n as NativeClassValue, o as NativeStyleManifest } from "./types-BTxnqaRV.js";
|
|
2
|
+
//#region src/runtime.d.ts
|
|
3
|
+
interface StyleValue {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
type StyleSheetFactory = (value: Record<string, StyleValue>) => Record<string, unknown>;
|
|
7
|
+
declare function createNativeStyleRuntime(initialManifest?: NativeStyleManifest): NativeStyleRuntime;
|
|
8
|
+
declare function setManifest(manifest: NativeStyleManifest): void;
|
|
9
|
+
/** 由 Expo virtual module 注入,避免 runtime 引入 Node-only 的 require shim。 */
|
|
10
|
+
declare function setStyleSheetFactory(factory: StyleSheetFactory): void;
|
|
11
|
+
declare function setEnvironment(environment: NativeStyleEnvironment): void;
|
|
12
|
+
declare function getManifest(): NativeStyleManifest | undefined;
|
|
13
|
+
declare function tw(value: NativeClassValue, environment?: NativeStyleEnvironment): Record<string, unknown>;
|
|
14
|
+
declare function getStaticStyle(ids: readonly string[], environment?: NativeStyleEnvironment): NativeStyleValue;
|
|
15
|
+
declare function composeStyle(tailwindStyle: NativeStyleValue, inlineStyle: unknown): NativeStyleValue[];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type NativeClassValue, type NativePlatform, type NativeStyleEnvironment, type NativeStyleManifest, type NativeStyleValue, composeStyle, createNativeStyleRuntime, getManifest, getStaticStyle, setEnvironment, setManifest, setStyleSheetFactory, tw };
|