@weapp-tailwindcss/runtime 0.1.7 → 0.1.9
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/dist/index.cjs +24 -6
- package/dist/index.d.cts +11 -6
- package/dist/index.d.mts +11 -6
- package/dist/index.mjs +24 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,4 +6,4 @@ This package is the foundation for runtime packages, providing escape/unescape,
|
|
|
6
6
|
|
|
7
7
|
## Website
|
|
8
8
|
|
|
9
|
-
For setup guides, configuration references, and framework examples, see the [official weapp-tailwindcss documentation](https://tw.
|
|
9
|
+
For setup guides, configuration references, and framework examples, see the [official weapp-tailwindcss documentation](https://tw.weapp.dev).
|
package/README.zh-CN.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -51,10 +51,27 @@ function resolveTransformers(options) {
|
|
|
51
51
|
//#region src/create-runtime.ts
|
|
52
52
|
const CACHE_LIMIT = 256;
|
|
53
53
|
const UNESCAPE_RE = /u[0-9a-f]{3,}/i;
|
|
54
|
+
const ESCAPE_NEEDLES = Object.keys(_weapp_core_escape.MappingChars2String).filter(Boolean);
|
|
55
|
+
function hasWhitespace(value) {
|
|
56
|
+
return value.includes(" ") || value.includes(" ") || value.includes("\n") || value.includes("\r") || value.includes("\f") || value.includes("\v");
|
|
57
|
+
}
|
|
54
58
|
function shouldUnescape(value) {
|
|
55
59
|
return value.includes("_") || UNESCAPE_RE.test(value);
|
|
56
60
|
}
|
|
57
|
-
function
|
|
61
|
+
function shouldEscape(value) {
|
|
62
|
+
for (const needle of ESCAPE_NEEDLES) if (value.includes(needle)) return true;
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
function transformTokens(value, transformFn) {
|
|
66
|
+
if (!value) return value;
|
|
67
|
+
if (!hasWhitespace(value)) return transformFn(value);
|
|
68
|
+
return value.split(/\s+/).filter(Boolean).map(transformFn).join(" ");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 为任意 class 聚合函数套上 unescape / 可选 prepare-restore / escape 与有界 LRU。
|
|
72
|
+
* 命中缓存时直接返回已转义结果,避免重复跑引擎。
|
|
73
|
+
*/
|
|
74
|
+
function wrapRuntimeAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
58
75
|
const cache = /* @__PURE__ */ new Map();
|
|
59
76
|
return (...inputs) => {
|
|
60
77
|
let rawInput;
|
|
@@ -63,7 +80,7 @@ function wrapClassAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
63
80
|
if (!rawInput) return rawInput;
|
|
64
81
|
const cached = cache.get(rawInput);
|
|
65
82
|
if (cached !== void 0) return cached;
|
|
66
|
-
const normalized = shouldUnescape(rawInput) ? transformers.unescape
|
|
83
|
+
const normalized = shouldUnescape(rawInput) ? transformTokens(rawInput, transformers.unescape) : rawInput;
|
|
67
84
|
let metadata;
|
|
68
85
|
let preparedValue = normalized;
|
|
69
86
|
if (prepareValue) {
|
|
@@ -76,7 +93,7 @@ function wrapClassAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
76
93
|
}
|
|
77
94
|
const merged = fn(preparedValue);
|
|
78
95
|
const restored = restoreValue ? restoreValue(merged, metadata) : merged;
|
|
79
|
-
const escaped = transformers.escape
|
|
96
|
+
const escaped = shouldEscape(restored) ? transformTokens(restored, transformers.escape) : restored;
|
|
80
97
|
if (cache.size >= CACHE_LIMIT) {
|
|
81
98
|
const firstEntry = cache.keys().next();
|
|
82
99
|
if (!firstEntry.done) cache.delete(firstEntry.value);
|
|
@@ -87,15 +104,15 @@ function wrapClassAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
87
104
|
}
|
|
88
105
|
function wrapFactory(factory, transformers, prepareValue, restoreValue) {
|
|
89
106
|
return (...args) => {
|
|
90
|
-
return
|
|
107
|
+
return wrapRuntimeAggregator(factory(...args), transformers, prepareValue, restoreValue);
|
|
91
108
|
};
|
|
92
109
|
}
|
|
93
110
|
function createRuntimeFactory(options) {
|
|
94
111
|
const { version, twMerge: twMergeImpl, twJoin: twJoinImpl, extendTailwindMerge: extendFactory, createTailwindMerge: createFactory, prepareValue, restoreValue } = options;
|
|
95
112
|
return function createRuntime(createOptions) {
|
|
96
113
|
const transformers = resolveTransformers(createOptions);
|
|
97
|
-
const twMerge =
|
|
98
|
-
const twJoin =
|
|
114
|
+
const twMerge = wrapRuntimeAggregator(twMergeImpl, transformers, prepareValue, restoreValue);
|
|
115
|
+
const twJoin = wrapRuntimeAggregator(twJoinImpl, transformers, prepareValue, restoreValue);
|
|
99
116
|
const extendTailwindMerge = wrapFactory(extendFactory, transformers, prepareValue, restoreValue);
|
|
100
117
|
const createTailwindMerge = wrapFactory(createFactory, transformers, prepareValue, restoreValue);
|
|
101
118
|
return {
|
|
@@ -171,3 +188,4 @@ exports.createRuntimeFactory = createRuntimeFactory;
|
|
|
171
188
|
exports.identity = identity;
|
|
172
189
|
exports.resolveTransformers = resolveTransformers;
|
|
173
190
|
exports.weappTwIgnore = weappTwIgnore;
|
|
191
|
+
exports.wrapRuntimeAggregator = wrapRuntimeAggregator;
|
package/dist/index.d.cts
CHANGED
|
@@ -37,7 +37,12 @@ interface CreateRuntimeFactoryOptions<TTwMerge extends TailwindMergeLibraryFn, T
|
|
|
37
37
|
*/
|
|
38
38
|
restoreValue?: (value: string, metadata?: unknown) => string;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 为任意 class 聚合函数套上 unescape / 可选 prepare-restore / escape 与有界 LRU。
|
|
42
|
+
* 命中缓存时直接返回已转义结果,避免重复跑引擎。
|
|
43
|
+
*/
|
|
44
|
+
export declare function wrapRuntimeAggregator(fn: TailwindMergeLibraryFn, transformers: Transformers, prepareValue?: (value: string) => string | TransformResult, restoreValue?: (value: string, metadata?: unknown) => string): TailwindMergeRuntime;
|
|
45
|
+
export declare function createRuntimeFactory<TTwMerge extends TailwindMergeLibraryFn, TTwJoin extends TailwindMergeLibraryFn, TExtendFactory extends TailwindMergeFactoryFn, TCreateFactory extends TailwindMergeFactoryFn>(options: CreateRuntimeFactoryOptions<TTwMerge, TTwJoin, TExtendFactory, TCreateFactory>): (createOptions?: CreateOptions) => {
|
|
41
46
|
version: TailwindMergeVersion;
|
|
42
47
|
twMerge: TailwindMergeRuntime;
|
|
43
48
|
twJoin: TailwindMergeRuntime;
|
|
@@ -47,7 +52,7 @@ declare function createRuntimeFactory<TTwMerge extends TailwindMergeLibraryFn, T
|
|
|
47
52
|
//#endregion
|
|
48
53
|
//#region src/rpx-length.d.ts
|
|
49
54
|
type ReplacementCounters = Record<string, number>;
|
|
50
|
-
declare function createRpxLengthTransform(prefixes?: readonly ["text", "border", "bg", "outline", "ring"]): {
|
|
55
|
+
export declare function createRpxLengthTransform(prefixes?: readonly ["text", "border", "bg", "outline", "ring"]): {
|
|
51
56
|
prepareValue: (value: string) => string | {
|
|
52
57
|
value: string;
|
|
53
58
|
metadata: {
|
|
@@ -59,12 +64,12 @@ declare function createRpxLengthTransform(prefixes?: readonly ["text", "border",
|
|
|
59
64
|
//#endregion
|
|
60
65
|
//#region src/transformers.d.ts
|
|
61
66
|
declare const identity: (value: string) => string;
|
|
62
|
-
declare function resolveTransformers(options?: CreateOptions): Transformers;
|
|
67
|
+
export declare function resolveTransformers(options?: CreateOptions): Transformers;
|
|
63
68
|
//#endregion
|
|
64
69
|
//#region src/index.d.ts
|
|
65
|
-
declare const weappTwIgnore: (template: {
|
|
70
|
+
export declare const weappTwIgnore: (template: {
|
|
66
71
|
raw: readonly string[] | ArrayLike<string>;
|
|
67
72
|
}, ...substitutions: any[]) => string;
|
|
68
|
-
type ClsxFn = typeof clsxFn;
|
|
73
|
+
export type ClsxFn = typeof clsxFn;
|
|
69
74
|
//#endregion
|
|
70
|
-
export { type ClassValue,
|
|
75
|
+
export { type ClassValue, type CreateOptions, type EscapeConfig, type TailwindMergeFactory, type TailwindMergeLibraryFn, type TailwindMergeRuntime, type TailwindMergeVersion, type Transformers, type UnescapeConfig, clsxFn as clsx, identity };
|
package/dist/index.d.mts
CHANGED
|
@@ -37,7 +37,12 @@ interface CreateRuntimeFactoryOptions<TTwMerge extends TailwindMergeLibraryFn, T
|
|
|
37
37
|
*/
|
|
38
38
|
restoreValue?: (value: string, metadata?: unknown) => string;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 为任意 class 聚合函数套上 unescape / 可选 prepare-restore / escape 与有界 LRU。
|
|
42
|
+
* 命中缓存时直接返回已转义结果,避免重复跑引擎。
|
|
43
|
+
*/
|
|
44
|
+
export declare function wrapRuntimeAggregator(fn: TailwindMergeLibraryFn, transformers: Transformers, prepareValue?: (value: string) => string | TransformResult, restoreValue?: (value: string, metadata?: unknown) => string): TailwindMergeRuntime;
|
|
45
|
+
export declare function createRuntimeFactory<TTwMerge extends TailwindMergeLibraryFn, TTwJoin extends TailwindMergeLibraryFn, TExtendFactory extends TailwindMergeFactoryFn, TCreateFactory extends TailwindMergeFactoryFn>(options: CreateRuntimeFactoryOptions<TTwMerge, TTwJoin, TExtendFactory, TCreateFactory>): (createOptions?: CreateOptions) => {
|
|
41
46
|
version: TailwindMergeVersion;
|
|
42
47
|
twMerge: TailwindMergeRuntime;
|
|
43
48
|
twJoin: TailwindMergeRuntime;
|
|
@@ -47,7 +52,7 @@ declare function createRuntimeFactory<TTwMerge extends TailwindMergeLibraryFn, T
|
|
|
47
52
|
//#endregion
|
|
48
53
|
//#region src/rpx-length.d.ts
|
|
49
54
|
type ReplacementCounters = Record<string, number>;
|
|
50
|
-
declare function createRpxLengthTransform(prefixes?: readonly ["text", "border", "bg", "outline", "ring"]): {
|
|
55
|
+
export declare function createRpxLengthTransform(prefixes?: readonly ["text", "border", "bg", "outline", "ring"]): {
|
|
51
56
|
prepareValue: (value: string) => string | {
|
|
52
57
|
value: string;
|
|
53
58
|
metadata: {
|
|
@@ -59,12 +64,12 @@ declare function createRpxLengthTransform(prefixes?: readonly ["text", "border",
|
|
|
59
64
|
//#endregion
|
|
60
65
|
//#region src/transformers.d.ts
|
|
61
66
|
declare const identity: (value: string) => string;
|
|
62
|
-
declare function resolveTransformers(options?: CreateOptions): Transformers;
|
|
67
|
+
export declare function resolveTransformers(options?: CreateOptions): Transformers;
|
|
63
68
|
//#endregion
|
|
64
69
|
//#region src/index.d.ts
|
|
65
|
-
declare const weappTwIgnore: (template: {
|
|
70
|
+
export declare const weappTwIgnore: (template: {
|
|
66
71
|
raw: readonly string[] | ArrayLike<string>;
|
|
67
72
|
}, ...substitutions: any[]) => string;
|
|
68
|
-
type ClsxFn = typeof clsxFn;
|
|
73
|
+
export type ClsxFn = typeof clsxFn;
|
|
69
74
|
//#endregion
|
|
70
|
-
export { type ClassValue,
|
|
75
|
+
export { type ClassValue, type CreateOptions, type EscapeConfig, type TailwindMergeFactory, type TailwindMergeLibraryFn, type TailwindMergeRuntime, type TailwindMergeVersion, type Transformers, type UnescapeConfig, clsxFn as clsx, identity };
|
package/dist/index.mjs
CHANGED
|
@@ -50,10 +50,27 @@ function resolveTransformers(options) {
|
|
|
50
50
|
//#region src/create-runtime.ts
|
|
51
51
|
const CACHE_LIMIT = 256;
|
|
52
52
|
const UNESCAPE_RE = /u[0-9a-f]{3,}/i;
|
|
53
|
+
const ESCAPE_NEEDLES = Object.keys(MappingChars2String).filter(Boolean);
|
|
54
|
+
function hasWhitespace(value) {
|
|
55
|
+
return value.includes(" ") || value.includes(" ") || value.includes("\n") || value.includes("\r") || value.includes("\f") || value.includes("\v");
|
|
56
|
+
}
|
|
53
57
|
function shouldUnescape(value) {
|
|
54
58
|
return value.includes("_") || UNESCAPE_RE.test(value);
|
|
55
59
|
}
|
|
56
|
-
function
|
|
60
|
+
function shouldEscape(value) {
|
|
61
|
+
for (const needle of ESCAPE_NEEDLES) if (value.includes(needle)) return true;
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
function transformTokens(value, transformFn) {
|
|
65
|
+
if (!value) return value;
|
|
66
|
+
if (!hasWhitespace(value)) return transformFn(value);
|
|
67
|
+
return value.split(/\s+/).filter(Boolean).map(transformFn).join(" ");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 为任意 class 聚合函数套上 unescape / 可选 prepare-restore / escape 与有界 LRU。
|
|
71
|
+
* 命中缓存时直接返回已转义结果,避免重复跑引擎。
|
|
72
|
+
*/
|
|
73
|
+
function wrapRuntimeAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
57
74
|
const cache = /* @__PURE__ */ new Map();
|
|
58
75
|
return (...inputs) => {
|
|
59
76
|
let rawInput;
|
|
@@ -62,7 +79,7 @@ function wrapClassAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
62
79
|
if (!rawInput) return rawInput;
|
|
63
80
|
const cached = cache.get(rawInput);
|
|
64
81
|
if (cached !== void 0) return cached;
|
|
65
|
-
const normalized = shouldUnescape(rawInput) ? transformers.unescape
|
|
82
|
+
const normalized = shouldUnescape(rawInput) ? transformTokens(rawInput, transformers.unescape) : rawInput;
|
|
66
83
|
let metadata;
|
|
67
84
|
let preparedValue = normalized;
|
|
68
85
|
if (prepareValue) {
|
|
@@ -75,7 +92,7 @@ function wrapClassAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
75
92
|
}
|
|
76
93
|
const merged = fn(preparedValue);
|
|
77
94
|
const restored = restoreValue ? restoreValue(merged, metadata) : merged;
|
|
78
|
-
const escaped = transformers.escape
|
|
95
|
+
const escaped = shouldEscape(restored) ? transformTokens(restored, transformers.escape) : restored;
|
|
79
96
|
if (cache.size >= CACHE_LIMIT) {
|
|
80
97
|
const firstEntry = cache.keys().next();
|
|
81
98
|
if (!firstEntry.done) cache.delete(firstEntry.value);
|
|
@@ -86,15 +103,15 @@ function wrapClassAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
86
103
|
}
|
|
87
104
|
function wrapFactory(factory, transformers, prepareValue, restoreValue) {
|
|
88
105
|
return (...args) => {
|
|
89
|
-
return
|
|
106
|
+
return wrapRuntimeAggregator(factory(...args), transformers, prepareValue, restoreValue);
|
|
90
107
|
};
|
|
91
108
|
}
|
|
92
109
|
function createRuntimeFactory(options) {
|
|
93
110
|
const { version, twMerge: twMergeImpl, twJoin: twJoinImpl, extendTailwindMerge: extendFactory, createTailwindMerge: createFactory, prepareValue, restoreValue } = options;
|
|
94
111
|
return function createRuntime(createOptions) {
|
|
95
112
|
const transformers = resolveTransformers(createOptions);
|
|
96
|
-
const twMerge =
|
|
97
|
-
const twJoin =
|
|
113
|
+
const twMerge = wrapRuntimeAggregator(twMergeImpl, transformers, prepareValue, restoreValue);
|
|
114
|
+
const twJoin = wrapRuntimeAggregator(twJoinImpl, transformers, prepareValue, restoreValue);
|
|
98
115
|
const extendTailwindMerge = wrapFactory(extendFactory, transformers, prepareValue, restoreValue);
|
|
99
116
|
const createTailwindMerge = wrapFactory(createFactory, transformers, prepareValue, restoreValue);
|
|
100
117
|
return {
|
|
@@ -164,4 +181,4 @@ function createRpxLengthTransform(prefixes = DEFAULT_PREFIXES) {
|
|
|
164
181
|
}
|
|
165
182
|
const weappTwIgnore = String.raw;
|
|
166
183
|
//#endregion
|
|
167
|
-
export { clsxFn as clsx, createRpxLengthTransform, createRuntimeFactory, identity, resolveTransformers, weappTwIgnore };
|
|
184
|
+
export { clsxFn as clsx, createRpxLengthTransform, createRuntimeFactory, identity, resolveTransformers, weappTwIgnore, wrapRuntimeAggregator };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.9",
|
|
5
5
|
"description": "Shared runtime adapters for cross-platform Tailwind CSS class utilities. 跨端 Tailwind CSS 类名工具的共享运行时适配层。",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://tw.
|
|
8
|
+
"homepage": "https://tw.weapp.dev/docs/community/merge/runtime-api",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/sonofmagic/weapp-tailwindcss.git",
|