@weapp-tailwindcss/runtime 0.1.6 → 0.1.7

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 CHANGED
@@ -1,60 +1,9 @@
1
1
  # @weapp-tailwindcss/runtime
2
2
 
3
- `@weapp-tailwindcss/runtime` 提供了一套在小程序环境中运行 Tailwind 相关工具时所需的“公共层”——包含统一的 `escape/unescape` 转换器、`clsx` 封装、`weappTwIgnore`、以及帮助将这些能力注入第三方库的 `createRuntimeFactory`。
3
+ > English | [简体中文](./README.zh-CN.md)
4
4
 
5
- - 📦 面向 `tailwind-merge`/`tailwind-variants`/`cva` 等运行时库的公共依赖
6
- - 🔁 自动共享 escape 映射,避免多处维护
7
- - 🧩 暴露 `weappTwIgnore`(`String.raw` 包装),供第三方消费
5
+ This package is the foundation for runtime packages, providing escape/unescape, runtime wrapping, caching, and rpx length transformation primitives.
8
6
 
9
- ## 安装
7
+ ## Website
10
8
 
11
- ```bash
12
- pnpm add @weapp-tailwindcss/runtime
13
- ```
14
-
15
- ## 快速上手
16
-
17
- ```ts
18
- import { createRuntimeFactory } from '@weapp-tailwindcss/runtime'
19
- import { createTailwindMerge, extendTailwindMerge, twJoin, twMerge } from 'tailwind-merge'
20
-
21
- const create = createRuntimeFactory({
22
- createTailwindMerge,
23
- extendTailwindMerge,
24
- twJoin,
25
- twMerge,
26
- })
27
-
28
- const runtime = create()
29
-
30
- runtime.twMerge('text-[#ececec]', 'text-[#ECECEC]') // => 自动 escape 的结果
31
- ```
32
-
33
- ## 自定义 escape/unescape
34
-
35
- ```ts
36
- import { createRuntimeFactory } from '@weapp-tailwindcss/runtime'
37
- import { createTailwindMerge } from 'tailwind-merge'
38
-
39
- const create = createRuntimeFactory({
40
- createTailwindMerge,
41
- extendTailwindMerge,
42
- twJoin,
43
- twMerge,
44
- })
45
-
46
- const custom = create({
47
- escape: false, // 关闭最终 escape,适合 Web SSR
48
- unescape: {
49
- map: { '#': '__hash__' },
50
- },
51
- })
52
- ```
53
-
54
- ## 其他导出
55
-
56
- - `resolveTransformers`:仅想复用 escape/unescape 时可以直接调用
57
- - `clsx` / `ClsxFn` / `ClassValue`:再导出一次,避免子包重复安装 `clsx`
58
- - `weappTwIgnore`:模板字符串标签,是 `String.raw` 的别名,方便外部包跳过 weapp 转义
59
-
60
- 更多细节见官方文档:<https://tw.icebreaker.top/docs/community/merge/runtime-api>
9
+ For setup guides, configuration references, and framework examples, see the [official weapp-tailwindcss documentation](https://tw.icebreaker.top).
@@ -0,0 +1,9 @@
1
+ # @weapp-tailwindcss/runtime
2
+
3
+ > [English](./README.md) | 简体中文
4
+
5
+ 这个包是 runtime 系列包的基础层,提供 escape/unescape、运行时包装、缓存和 rpx 长度转换等公共能力。
6
+
7
+ ## 官网
8
+
9
+ 更多接入方式、配置说明和框架示例见 [weapp-tailwindcss 官方文档](https://tw.icebreaker.top)。
package/dist/index.cjs CHANGED
@@ -27,17 +27,21 @@ function resolveTransformers(options) {
27
27
  const escapeEnabled = escapeConfig !== false;
28
28
  const unescapeEnabled = unescapeConfig !== false;
29
29
  let escapeOptions;
30
- if (escapeEnabled) if (isConfig(escapeConfig)) escapeOptions = {
31
- ...escapeConfig,
32
- map: mergeWithDefaultMap(escapeConfig.map) ?? sharedMap
33
- };
34
- else escapeOptions = { map: sharedMap };
30
+ if (escapeEnabled) {
31
+ if (isConfig(escapeConfig)) escapeOptions = {
32
+ ...escapeConfig,
33
+ map: mergeWithDefaultMap(escapeConfig.map) ?? sharedMap
34
+ };
35
+ else escapeOptions = { map: sharedMap };
36
+ }
35
37
  let unescapeOptions;
36
- if (unescapeEnabled) if (isConfig(unescapeConfig)) unescapeOptions = {
37
- ...unescapeConfig,
38
- map: mergeWithDefaultMap(unescapeConfig.map) ?? sharedMap
39
- };
40
- else unescapeOptions = { map: sharedMap };
38
+ if (unescapeEnabled) {
39
+ if (isConfig(unescapeConfig)) unescapeOptions = {
40
+ ...unescapeConfig,
41
+ map: mergeWithDefaultMap(unescapeConfig.map) ?? sharedMap
42
+ };
43
+ else unescapeOptions = { map: sharedMap };
44
+ }
41
45
  return {
42
46
  escape: escapeEnabled ? (value) => (0, _weapp_core_escape.escape)(value, escapeOptions) : identity,
43
47
  unescape: unescapeEnabled ? (value) => (0, _weapp_core_escape.unescape)(value, unescapeOptions) : identity
@@ -90,12 +94,16 @@ function createRuntimeFactory(options) {
90
94
  const { version, twMerge: twMergeImpl, twJoin: twJoinImpl, extendTailwindMerge: extendFactory, createTailwindMerge: createFactory, prepareValue, restoreValue } = options;
91
95
  return function createRuntime(createOptions) {
92
96
  const transformers = resolveTransformers(createOptions);
97
+ const twMerge = wrapClassAggregator(twMergeImpl, transformers, prepareValue, restoreValue);
98
+ const twJoin = wrapClassAggregator(twJoinImpl, transformers, prepareValue, restoreValue);
99
+ const extendTailwindMerge = wrapFactory(extendFactory, transformers, prepareValue, restoreValue);
100
+ const createTailwindMerge = wrapFactory(createFactory, transformers, prepareValue, restoreValue);
93
101
  return {
94
102
  version,
95
- twMerge: wrapClassAggregator(twMergeImpl, transformers, prepareValue, restoreValue),
96
- twJoin: wrapClassAggregator(twJoinImpl, transformers, prepareValue, restoreValue),
97
- extendTailwindMerge: wrapFactory(extendFactory, transformers, prepareValue, restoreValue),
98
- createTailwindMerge: wrapFactory(createFactory, transformers, prepareValue, restoreValue)
103
+ twMerge,
104
+ twJoin,
105
+ extendTailwindMerge,
106
+ createTailwindMerge
99
107
  };
100
108
  };
101
109
  }
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ClassValue, ClassValue as ClassValue$1, clsx as clsxFn } from "clsx";
2
2
  import { EscapeOptions, UnescapeOptions } from "@weapp-core/escape";
3
-
4
3
  //#region src/types.d.ts
5
4
  type EscapeConfig = boolean | EscapeOptions;
6
5
  type UnescapeConfig = boolean | UnescapeOptions;
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ClassValue, ClassValue as ClassValue$1, clsx as clsxFn } from "clsx";
2
2
  import { EscapeOptions, UnescapeOptions } from "@weapp-core/escape";
3
-
4
3
  //#region src/types.d.ts
5
4
  type EscapeConfig = boolean | EscapeOptions;
6
5
  type UnescapeConfig = boolean | UnescapeOptions;
package/dist/index.mjs CHANGED
@@ -26,17 +26,21 @@ function resolveTransformers(options) {
26
26
  const escapeEnabled = escapeConfig !== false;
27
27
  const unescapeEnabled = unescapeConfig !== false;
28
28
  let escapeOptions;
29
- if (escapeEnabled) if (isConfig(escapeConfig)) escapeOptions = {
30
- ...escapeConfig,
31
- map: mergeWithDefaultMap(escapeConfig.map) ?? sharedMap
32
- };
33
- else escapeOptions = { map: sharedMap };
29
+ if (escapeEnabled) {
30
+ if (isConfig(escapeConfig)) escapeOptions = {
31
+ ...escapeConfig,
32
+ map: mergeWithDefaultMap(escapeConfig.map) ?? sharedMap
33
+ };
34
+ else escapeOptions = { map: sharedMap };
35
+ }
34
36
  let unescapeOptions;
35
- if (unescapeEnabled) if (isConfig(unescapeConfig)) unescapeOptions = {
36
- ...unescapeConfig,
37
- map: mergeWithDefaultMap(unescapeConfig.map) ?? sharedMap
38
- };
39
- else unescapeOptions = { map: sharedMap };
37
+ if (unescapeEnabled) {
38
+ if (isConfig(unescapeConfig)) unescapeOptions = {
39
+ ...unescapeConfig,
40
+ map: mergeWithDefaultMap(unescapeConfig.map) ?? sharedMap
41
+ };
42
+ else unescapeOptions = { map: sharedMap };
43
+ }
40
44
  return {
41
45
  escape: escapeEnabled ? (value) => escape(value, escapeOptions) : identity,
42
46
  unescape: unescapeEnabled ? (value) => unescape(value, unescapeOptions) : identity
@@ -89,12 +93,16 @@ function createRuntimeFactory(options) {
89
93
  const { version, twMerge: twMergeImpl, twJoin: twJoinImpl, extendTailwindMerge: extendFactory, createTailwindMerge: createFactory, prepareValue, restoreValue } = options;
90
94
  return function createRuntime(createOptions) {
91
95
  const transformers = resolveTransformers(createOptions);
96
+ const twMerge = wrapClassAggregator(twMergeImpl, transformers, prepareValue, restoreValue);
97
+ const twJoin = wrapClassAggregator(twJoinImpl, transformers, prepareValue, restoreValue);
98
+ const extendTailwindMerge = wrapFactory(extendFactory, transformers, prepareValue, restoreValue);
99
+ const createTailwindMerge = wrapFactory(createFactory, transformers, prepareValue, restoreValue);
92
100
  return {
93
101
  version,
94
- twMerge: wrapClassAggregator(twMergeImpl, transformers, prepareValue, restoreValue),
95
- twJoin: wrapClassAggregator(twJoinImpl, transformers, prepareValue, restoreValue),
96
- extendTailwindMerge: wrapFactory(extendFactory, transformers, prepareValue, restoreValue),
97
- createTailwindMerge: wrapFactory(createFactory, transformers, prepareValue, restoreValue)
102
+ twMerge,
103
+ twJoin,
104
+ extendTailwindMerge,
105
+ createTailwindMerge
98
106
  };
99
107
  };
100
108
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/runtime",
3
3
  "type": "module",
4
- "version": "0.1.6",
5
- "description": "Shared runtime helpers (transformers, clsx wrappers, metadata) for weapp-tailwindcss 在小程序运行时的适配层。",
4
+ "version": "0.1.7",
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.icebreaker.top/docs/community/merge/runtime-api",