@weapp-tailwindcss/runtime 0.1.9 → 0.1.11
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/dist/index.cjs +33 -18
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +30 -15
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let clsx = require("clsx");
|
|
3
|
-
let
|
|
3
|
+
let _weapp_tailwindcss_escape = require("@weapp-tailwindcss/escape");
|
|
4
|
+
//#region src/transformer-probes.ts
|
|
5
|
+
const probes = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
const unescapePattern = /u[0-9a-f]{3,}/i;
|
|
7
|
+
const escapeNeedles = Object.keys(_weapp_tailwindcss_escape.MappingChars2String).filter(Boolean);
|
|
8
|
+
/** 仅为已知默认转换器登记可证明安全的跳过条件,不改变公开类型。 */
|
|
9
|
+
function registerTransformProbe(transform, direction) {
|
|
10
|
+
probes.set(transform, direction === "identity" ? () => false : direction === "unescape" ? (value) => value.includes("_") || unescapePattern.test(value) : (value) => escapeNeedles.some((needle) => value.includes(needle)));
|
|
11
|
+
}
|
|
12
|
+
/** 自定义转换器没有探针时必须执行,不能用默认映射推断其行为。 */
|
|
13
|
+
function needsTransform(transform, value) {
|
|
14
|
+
return probes.get(transform)?.(value) ?? true;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
4
17
|
//#region src/transformers.ts
|
|
5
18
|
const identity = (value) => value;
|
|
19
|
+
registerTransformProbe(identity, "identity");
|
|
6
20
|
function isConfig(value) {
|
|
7
21
|
return typeof value === "object" && value !== null;
|
|
8
22
|
}
|
|
9
23
|
function mergeWithDefaultMap(map) {
|
|
10
24
|
if (!map) return;
|
|
11
|
-
if (map ===
|
|
25
|
+
if (map === _weapp_tailwindcss_escape.MappingChars2String) return _weapp_tailwindcss_escape.MappingChars2String;
|
|
12
26
|
return {
|
|
13
|
-
...
|
|
27
|
+
..._weapp_tailwindcss_escape.MappingChars2String,
|
|
14
28
|
...map
|
|
15
29
|
};
|
|
16
30
|
}
|
|
@@ -18,7 +32,7 @@ function resolveSharedMap(options) {
|
|
|
18
32
|
const { escape, unescape } = options ?? {};
|
|
19
33
|
if (isConfig(escape) && escape.map) return mergeWithDefaultMap(escape.map);
|
|
20
34
|
if (isConfig(unescape) && unescape.map) return mergeWithDefaultMap(unescape.map);
|
|
21
|
-
return
|
|
35
|
+
return _weapp_tailwindcss_escape.MappingChars2String;
|
|
22
36
|
}
|
|
23
37
|
function resolveTransformers(options) {
|
|
24
38
|
const sharedMap = resolveSharedMap(options);
|
|
@@ -42,26 +56,23 @@ function resolveTransformers(options) {
|
|
|
42
56
|
};
|
|
43
57
|
else unescapeOptions = { map: sharedMap };
|
|
44
58
|
}
|
|
59
|
+
const escapeFn = escapeEnabled ? (value) => (0, _weapp_tailwindcss_escape.escape)(value, escapeOptions) : identity;
|
|
60
|
+
const unescapeFn = unescapeEnabled ? (value) => (0, _weapp_tailwindcss_escape.unescape)(value, unescapeOptions) : identity;
|
|
61
|
+
if (sharedMap === _weapp_tailwindcss_escape.MappingChars2String) {
|
|
62
|
+
if (escapeEnabled && !isConfig(escapeConfig)) registerTransformProbe(escapeFn, "escape");
|
|
63
|
+
if (unescapeEnabled && !isConfig(unescapeConfig)) registerTransformProbe(unescapeFn, "unescape");
|
|
64
|
+
}
|
|
45
65
|
return {
|
|
46
|
-
escape:
|
|
47
|
-
unescape:
|
|
66
|
+
escape: escapeFn,
|
|
67
|
+
unescape: unescapeFn
|
|
48
68
|
};
|
|
49
69
|
}
|
|
50
70
|
//#endregion
|
|
51
71
|
//#region src/create-runtime.ts
|
|
52
72
|
const CACHE_LIMIT = 256;
|
|
53
|
-
const UNESCAPE_RE = /u[0-9a-f]{3,}/i;
|
|
54
|
-
const ESCAPE_NEEDLES = Object.keys(_weapp_core_escape.MappingChars2String).filter(Boolean);
|
|
55
73
|
function hasWhitespace(value) {
|
|
56
74
|
return value.includes(" ") || value.includes(" ") || value.includes("\n") || value.includes("\r") || value.includes("\f") || value.includes("\v");
|
|
57
75
|
}
|
|
58
|
-
function shouldUnescape(value) {
|
|
59
|
-
return value.includes("_") || UNESCAPE_RE.test(value);
|
|
60
|
-
}
|
|
61
|
-
function shouldEscape(value) {
|
|
62
|
-
for (const needle of ESCAPE_NEEDLES) if (value.includes(needle)) return true;
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
76
|
function transformTokens(value, transformFn) {
|
|
66
77
|
if (!value) return value;
|
|
67
78
|
if (!hasWhitespace(value)) return transformFn(value);
|
|
@@ -79,8 +90,12 @@ function wrapRuntimeAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
79
90
|
else rawInput = (0, clsx.clsx)(...inputs);
|
|
80
91
|
if (!rawInput) return rawInput;
|
|
81
92
|
const cached = cache.get(rawInput);
|
|
82
|
-
if (cached !== void 0)
|
|
83
|
-
|
|
93
|
+
if (cached !== void 0) {
|
|
94
|
+
cache.delete(rawInput);
|
|
95
|
+
cache.set(rawInput, cached);
|
|
96
|
+
return cached;
|
|
97
|
+
}
|
|
98
|
+
const normalized = needsTransform(transformers.unescape, rawInput) ? transformTokens(rawInput, transformers.unescape) : rawInput;
|
|
84
99
|
let metadata;
|
|
85
100
|
let preparedValue = normalized;
|
|
86
101
|
if (prepareValue) {
|
|
@@ -93,7 +108,7 @@ function wrapRuntimeAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
93
108
|
}
|
|
94
109
|
const merged = fn(preparedValue);
|
|
95
110
|
const restored = restoreValue ? restoreValue(merged, metadata) : merged;
|
|
96
|
-
const escaped =
|
|
111
|
+
const escaped = needsTransform(transformers.escape, restored) ? transformTokens(restored, transformers.escape) : restored;
|
|
97
112
|
if (cache.size >= CACHE_LIMIT) {
|
|
98
113
|
const firstEntry = cache.keys().next();
|
|
99
114
|
if (!firstEntry.done) cache.delete(firstEntry.value);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClassValue, ClassValue as ClassValue$1, clsx as clsxFn } from "clsx";
|
|
2
|
-
import { EscapeOptions, UnescapeOptions } from "@weapp-
|
|
2
|
+
import { EscapeOptions, UnescapeOptions } from "@weapp-tailwindcss/escape";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
type EscapeConfig = boolean | EscapeOptions;
|
|
5
5
|
type UnescapeConfig = boolean | UnescapeOptions;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClassValue, ClassValue as ClassValue$1, clsx as clsxFn } from "clsx";
|
|
2
|
-
import { EscapeOptions, UnescapeOptions } from "@weapp-
|
|
2
|
+
import { EscapeOptions, UnescapeOptions } from "@weapp-tailwindcss/escape";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
type EscapeConfig = boolean | EscapeOptions;
|
|
5
5
|
type UnescapeConfig = boolean | UnescapeOptions;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { clsx, clsx as clsxFn } from "clsx";
|
|
2
|
-
import { MappingChars2String, escape, unescape } from "@weapp-
|
|
2
|
+
import { MappingChars2String, escape, unescape } from "@weapp-tailwindcss/escape";
|
|
3
|
+
//#region src/transformer-probes.ts
|
|
4
|
+
const probes = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
const unescapePattern = /u[0-9a-f]{3,}/i;
|
|
6
|
+
const escapeNeedles = Object.keys(MappingChars2String).filter(Boolean);
|
|
7
|
+
/** 仅为已知默认转换器登记可证明安全的跳过条件,不改变公开类型。 */
|
|
8
|
+
function registerTransformProbe(transform, direction) {
|
|
9
|
+
probes.set(transform, direction === "identity" ? () => false : direction === "unescape" ? (value) => value.includes("_") || unescapePattern.test(value) : (value) => escapeNeedles.some((needle) => value.includes(needle)));
|
|
10
|
+
}
|
|
11
|
+
/** 自定义转换器没有探针时必须执行,不能用默认映射推断其行为。 */
|
|
12
|
+
function needsTransform(transform, value) {
|
|
13
|
+
return probes.get(transform)?.(value) ?? true;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
3
16
|
//#region src/transformers.ts
|
|
4
17
|
const identity = (value) => value;
|
|
18
|
+
registerTransformProbe(identity, "identity");
|
|
5
19
|
function isConfig(value) {
|
|
6
20
|
return typeof value === "object" && value !== null;
|
|
7
21
|
}
|
|
@@ -41,26 +55,23 @@ function resolveTransformers(options) {
|
|
|
41
55
|
};
|
|
42
56
|
else unescapeOptions = { map: sharedMap };
|
|
43
57
|
}
|
|
58
|
+
const escapeFn = escapeEnabled ? (value) => escape(value, escapeOptions) : identity;
|
|
59
|
+
const unescapeFn = unescapeEnabled ? (value) => unescape(value, unescapeOptions) : identity;
|
|
60
|
+
if (sharedMap === MappingChars2String) {
|
|
61
|
+
if (escapeEnabled && !isConfig(escapeConfig)) registerTransformProbe(escapeFn, "escape");
|
|
62
|
+
if (unescapeEnabled && !isConfig(unescapeConfig)) registerTransformProbe(unescapeFn, "unescape");
|
|
63
|
+
}
|
|
44
64
|
return {
|
|
45
|
-
escape:
|
|
46
|
-
unescape:
|
|
65
|
+
escape: escapeFn,
|
|
66
|
+
unescape: unescapeFn
|
|
47
67
|
};
|
|
48
68
|
}
|
|
49
69
|
//#endregion
|
|
50
70
|
//#region src/create-runtime.ts
|
|
51
71
|
const CACHE_LIMIT = 256;
|
|
52
|
-
const UNESCAPE_RE = /u[0-9a-f]{3,}/i;
|
|
53
|
-
const ESCAPE_NEEDLES = Object.keys(MappingChars2String).filter(Boolean);
|
|
54
72
|
function hasWhitespace(value) {
|
|
55
73
|
return value.includes(" ") || value.includes(" ") || value.includes("\n") || value.includes("\r") || value.includes("\f") || value.includes("\v");
|
|
56
74
|
}
|
|
57
|
-
function shouldUnescape(value) {
|
|
58
|
-
return value.includes("_") || UNESCAPE_RE.test(value);
|
|
59
|
-
}
|
|
60
|
-
function shouldEscape(value) {
|
|
61
|
-
for (const needle of ESCAPE_NEEDLES) if (value.includes(needle)) return true;
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
75
|
function transformTokens(value, transformFn) {
|
|
65
76
|
if (!value) return value;
|
|
66
77
|
if (!hasWhitespace(value)) return transformFn(value);
|
|
@@ -78,8 +89,12 @@ function wrapRuntimeAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
78
89
|
else rawInput = clsx(...inputs);
|
|
79
90
|
if (!rawInput) return rawInput;
|
|
80
91
|
const cached = cache.get(rawInput);
|
|
81
|
-
if (cached !== void 0)
|
|
82
|
-
|
|
92
|
+
if (cached !== void 0) {
|
|
93
|
+
cache.delete(rawInput);
|
|
94
|
+
cache.set(rawInput, cached);
|
|
95
|
+
return cached;
|
|
96
|
+
}
|
|
97
|
+
const normalized = needsTransform(transformers.unescape, rawInput) ? transformTokens(rawInput, transformers.unescape) : rawInput;
|
|
83
98
|
let metadata;
|
|
84
99
|
let preparedValue = normalized;
|
|
85
100
|
if (prepareValue) {
|
|
@@ -92,7 +107,7 @@ function wrapRuntimeAggregator(fn, transformers, prepareValue, restoreValue) {
|
|
|
92
107
|
}
|
|
93
108
|
const merged = fn(preparedValue);
|
|
94
109
|
const restored = restoreValue ? restoreValue(merged, metadata) : merged;
|
|
95
|
-
const escaped =
|
|
110
|
+
const escaped = needsTransform(transformers.escape, restored) ? transformTokens(restored, transformers.escape) : restored;
|
|
96
111
|
if (cache.size >= CACHE_LIMIT) {
|
|
97
112
|
const firstEntry = cache.keys().next();
|
|
98
113
|
if (!firstEntry.done) cache.delete(firstEntry.value);
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.11",
|
|
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
8
|
"homepage": "https://tw.weapp.dev/docs/community/merge/runtime-api",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/weapp-tailwindcss/weapp-tailwindcss.git",
|
|
12
12
|
"directory": "packages-runtime/runtime"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/weapp-tailwindcss/weapp-tailwindcss/issues"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
18
18
|
"tailwindcss",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@weapp-
|
|
49
|
+
"@weapp-tailwindcss/escape": "0.0.2",
|
|
50
50
|
"clsx": "^2.1.1"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|