@weapp-tailwindcss/merge 1.3.0 → 2.0.1

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.
@@ -0,0 +1,83 @@
1
+ import { existsSync as defaultExistsSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import path from 'node:path'
4
+ import process from 'node:process'
5
+ import { fileURLToPath, pathToFileURL } from 'node:url'
6
+
7
+ const requireFn = createRequire(import.meta.url)
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
+
10
+ /**
11
+ * @param {object} [options]
12
+ * @param {(path: string) => boolean} [options.existsSync]
13
+ * @param {(path: string) => Promise<unknown>} [options.loadEsm]
14
+ * @param {(path: string) => unknown | Promise<unknown>} [options.loadCjs]
15
+ * @param {{ log: typeof console.log, error: typeof console.error }} [options.logger]
16
+ */
17
+ export async function run(options = {}) {
18
+ const {
19
+ existsSync = defaultExistsSync,
20
+ loadEsm = async filePath => import(pathToFileURL(filePath).href),
21
+ loadCjs = filePath => requireFn(filePath),
22
+ logger = console,
23
+ } = options
24
+
25
+ const esmPath = path.resolve(__dirname, '../dist/postinstall.js')
26
+ const cjsPath = path.resolve(__dirname, '../dist/postinstall.cjs')
27
+
28
+ const hasEsm = existsSync(esmPath)
29
+ const hasCjs = existsSync(cjsPath)
30
+
31
+ const loadErrors = []
32
+
33
+ if (hasEsm) {
34
+ try {
35
+ await loadEsm(esmPath)
36
+ return
37
+ }
38
+ catch (error) {
39
+ loadErrors.push(error)
40
+ }
41
+ }
42
+
43
+ if (hasCjs) {
44
+ try {
45
+ await loadCjs(cjsPath)
46
+ return
47
+ }
48
+ catch (error) {
49
+ loadErrors.push(error)
50
+ }
51
+ }
52
+
53
+ if (!hasEsm && !hasCjs) {
54
+ logger.log('postinstall bundle not found')
55
+ return
56
+ }
57
+
58
+ logger.error('Failed to load postinstall bundle.')
59
+ for (const error of loadErrors) {
60
+ logger.error(error)
61
+ }
62
+ process.exitCode = process.exitCode ?? 1
63
+ }
64
+
65
+ const entryUrl = (() => {
66
+ const candidate = process.argv[1]
67
+ if (!candidate) {
68
+ return undefined
69
+ }
70
+ try {
71
+ return pathToFileURL(candidate).href
72
+ }
73
+ catch {
74
+ return undefined
75
+ }
76
+ })()
77
+
78
+ if (entryUrl === import.meta.url) {
79
+ run().catch((error) => {
80
+ console.error('Failed to execute postinstall entry.', error)
81
+ process.exitCode = process.exitCode ?? 1
82
+ })
83
+ }
@@ -1,210 +0,0 @@
1
- // ../../node_modules/.pnpm/@weapp-core+escape@4.0.1/node_modules/@weapp-core/escape/dist/index.mjs
2
- var ComplexMappingChars2String = {
3
- "[": "_bl_",
4
- "]": "_br_",
5
- "(": "_pl_",
6
- ")": "_qr_",
7
- "#": "_h_",
8
- "!": "_i_",
9
- "/": "_s_",
10
- "\\": "_bs_",
11
- ".": "_d_",
12
- ":": "_c_",
13
- "%": "_p_",
14
- ",": "_co_",
15
- "'": "_q_",
16
- '"': "_dq_",
17
- "*": "_a_",
18
- "&": "_am_",
19
- "@": "_at_",
20
- "{": "_bal_",
21
- "}": "_bar_",
22
- // ' ': '_sp_',
23
- "+": "_plus_",
24
- // '-': '_m_',
25
- ";": "_se_",
26
- "<": "_l_",
27
- "~": "_t_",
28
- "=": "_e_",
29
- ">": "_g_",
30
- "?": "_qu_",
31
- "^": "_ca_",
32
- "`": "_bq_",
33
- "|": "_b_",
34
- "$": "_do_"
35
- // _: '_u_'
36
- };
37
- var ComplexMappingChars2StringEntries = Object.entries(ComplexMappingChars2String);
38
- var MappingChars2String = {
39
- "[": "_",
40
- "]": "_",
41
- // for tailwindcss v4
42
- "(": "y",
43
- ")": "y",
44
- "{": "z",
45
- "}": "z",
46
- "+": "a",
47
- ",": "b",
48
- ":": "c",
49
- ".": "d",
50
- "=": "e",
51
- ";": "f",
52
- ">": "g",
53
- "#": "h",
54
- "!": "i",
55
- "@": "j",
56
- "^": "k",
57
- "<": "l",
58
- "*": "m",
59
- "&": "n",
60
- "?": "o",
61
- "%": "p",
62
- "'": "q",
63
- "$": "r",
64
- "/": "s",
65
- "~": "t",
66
- "|": "u",
67
- "`": "v",
68
- "\\": "w",
69
- '"': "x"
70
- };
71
- var MappingChars2StringEntries = Object.entries(MappingChars2String);
72
- var MAX_ASCII_CHAR_CODE = 127;
73
- function isPlainObject(value) {
74
- if (value === null || typeof value !== "object") {
75
- return false;
76
- }
77
- const prototype = Object.getPrototypeOf(value);
78
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
79
- return false;
80
- }
81
- if (Symbol.iterator in value) {
82
- return false;
83
- }
84
- if (Symbol.toStringTag in value) {
85
- return Object.prototype.toString.call(value) === "[object Module]";
86
- }
87
- return true;
88
- }
89
- function _defu(baseObject, defaults, namespace = ".", merger) {
90
- if (!isPlainObject(defaults)) {
91
- return _defu(baseObject, {}, namespace, merger);
92
- }
93
- const object = Object.assign({}, defaults);
94
- for (const key in baseObject) {
95
- if (key === "__proto__" || key === "constructor") {
96
- continue;
97
- }
98
- const value = baseObject[key];
99
- if (value === null || value === void 0) {
100
- continue;
101
- }
102
- if (merger && merger(object, key, value, namespace)) {
103
- continue;
104
- }
105
- if (Array.isArray(value) && Array.isArray(object[key])) {
106
- object[key] = [...value, ...object[key]];
107
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
108
- object[key] = _defu(
109
- value,
110
- object[key],
111
- (namespace ? `${namespace}.` : "") + key.toString(),
112
- merger
113
- );
114
- } else {
115
- object[key] = value;
116
- }
117
- }
118
- return object;
119
- }
120
- function createDefu(merger) {
121
- return (...arguments_) => (
122
- // eslint-disable-next-line unicorn/no-array-reduce
123
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
124
- );
125
- }
126
- var defu = createDefu();
127
- function isAsciiNumber(code) {
128
- return code >= 48 && code <= 57;
129
- }
130
- function handleFirstCharacter(char, nextChar, ignoreHead) {
131
- if (!ignoreHead) {
132
- const code = char.codePointAt(0);
133
- if (isAsciiNumber(code)) {
134
- return `_${char}`;
135
- }
136
- if (char === "-" && nextChar && isAsciiNumber(nextChar.codePointAt(0))) {
137
- return `_${char}`;
138
- }
139
- if (char === "-" && nextChar === void 0) {
140
- return `_${char}`;
141
- }
142
- }
143
- return char;
144
- }
145
- function escape(selectors, options) {
146
- if (selectors.length === 0) {
147
- return "";
148
- }
149
- const { map, ignoreHead } = defu(options, {
150
- map: MappingChars2String,
151
- ignoreHead: false
152
- });
153
- const sb = [];
154
- for (let i = 0; i < selectors.length; i++) {
155
- const char = selectors[i];
156
- const code = char.codePointAt(0);
157
- if (code !== void 0) {
158
- if (code > MAX_ASCII_CHAR_CODE) {
159
- sb.push(`u${code.toString(16)}`);
160
- } else {
161
- const hit = map[char];
162
- if (hit) {
163
- sb.push(hit);
164
- } else if (i === 0) {
165
- sb.push(handleFirstCharacter(char, selectors[i + 1], ignoreHead));
166
- } else {
167
- sb.push(char);
168
- }
169
- }
170
- }
171
- }
172
- return sb.join("");
173
- }
174
-
175
- // ../weapp-tailwindcss/dist/chunk-Q67IXIAH.mjs
176
- function replaceWxml(original, options = {
177
- keepEOL: false,
178
- escapeMap: MappingChars2String
179
- }) {
180
- const { keepEOL, escapeMap, mangleContext, ignoreHead } = options;
181
- let res = original;
182
- if (!keepEOL) {
183
- res = res.replaceAll(/[\n\r]+/g, "");
184
- }
185
- if (mangleContext) {
186
- res = mangleContext.wxmlHandler(res);
187
- }
188
- res = escape(res, {
189
- map: escapeMap,
190
- ignoreHead
191
- });
192
- return res;
193
- }
194
-
195
- // ../weapp-tailwindcss/dist/escape.mjs
196
- var weappTwIgnore = String.raw;
197
-
198
- // src/core/escape.ts
199
- var noop = (value) => value;
200
- function resolveEscape(options) {
201
- if (options?.disableEscape) {
202
- return noop;
203
- }
204
- return options?.escapeFn ?? replaceWxml;
205
- }
206
-
207
- export {
208
- weappTwIgnore,
209
- resolveEscape
210
- };
@@ -1,210 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// ../../node_modules/.pnpm/@weapp-core+escape@4.0.1/node_modules/@weapp-core/escape/dist/index.mjs
2
- var ComplexMappingChars2String = {
3
- "[": "_bl_",
4
- "]": "_br_",
5
- "(": "_pl_",
6
- ")": "_qr_",
7
- "#": "_h_",
8
- "!": "_i_",
9
- "/": "_s_",
10
- "\\": "_bs_",
11
- ".": "_d_",
12
- ":": "_c_",
13
- "%": "_p_",
14
- ",": "_co_",
15
- "'": "_q_",
16
- '"': "_dq_",
17
- "*": "_a_",
18
- "&": "_am_",
19
- "@": "_at_",
20
- "{": "_bal_",
21
- "}": "_bar_",
22
- // ' ': '_sp_',
23
- "+": "_plus_",
24
- // '-': '_m_',
25
- ";": "_se_",
26
- "<": "_l_",
27
- "~": "_t_",
28
- "=": "_e_",
29
- ">": "_g_",
30
- "?": "_qu_",
31
- "^": "_ca_",
32
- "`": "_bq_",
33
- "|": "_b_",
34
- "$": "_do_"
35
- // _: '_u_'
36
- };
37
- var ComplexMappingChars2StringEntries = Object.entries(ComplexMappingChars2String);
38
- var MappingChars2String = {
39
- "[": "_",
40
- "]": "_",
41
- // for tailwindcss v4
42
- "(": "y",
43
- ")": "y",
44
- "{": "z",
45
- "}": "z",
46
- "+": "a",
47
- ",": "b",
48
- ":": "c",
49
- ".": "d",
50
- "=": "e",
51
- ";": "f",
52
- ">": "g",
53
- "#": "h",
54
- "!": "i",
55
- "@": "j",
56
- "^": "k",
57
- "<": "l",
58
- "*": "m",
59
- "&": "n",
60
- "?": "o",
61
- "%": "p",
62
- "'": "q",
63
- "$": "r",
64
- "/": "s",
65
- "~": "t",
66
- "|": "u",
67
- "`": "v",
68
- "\\": "w",
69
- '"': "x"
70
- };
71
- var MappingChars2StringEntries = Object.entries(MappingChars2String);
72
- var MAX_ASCII_CHAR_CODE = 127;
73
- function isPlainObject(value) {
74
- if (value === null || typeof value !== "object") {
75
- return false;
76
- }
77
- const prototype = Object.getPrototypeOf(value);
78
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
79
- return false;
80
- }
81
- if (Symbol.iterator in value) {
82
- return false;
83
- }
84
- if (Symbol.toStringTag in value) {
85
- return Object.prototype.toString.call(value) === "[object Module]";
86
- }
87
- return true;
88
- }
89
- function _defu(baseObject, defaults, namespace = ".", merger) {
90
- if (!isPlainObject(defaults)) {
91
- return _defu(baseObject, {}, namespace, merger);
92
- }
93
- const object = Object.assign({}, defaults);
94
- for (const key in baseObject) {
95
- if (key === "__proto__" || key === "constructor") {
96
- continue;
97
- }
98
- const value = baseObject[key];
99
- if (value === null || value === void 0) {
100
- continue;
101
- }
102
- if (merger && merger(object, key, value, namespace)) {
103
- continue;
104
- }
105
- if (Array.isArray(value) && Array.isArray(object[key])) {
106
- object[key] = [...value, ...object[key]];
107
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
108
- object[key] = _defu(
109
- value,
110
- object[key],
111
- (namespace ? `${namespace}.` : "") + key.toString(),
112
- merger
113
- );
114
- } else {
115
- object[key] = value;
116
- }
117
- }
118
- return object;
119
- }
120
- function createDefu(merger) {
121
- return (...arguments_) => (
122
- // eslint-disable-next-line unicorn/no-array-reduce
123
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
124
- );
125
- }
126
- var defu = createDefu();
127
- function isAsciiNumber(code) {
128
- return code >= 48 && code <= 57;
129
- }
130
- function handleFirstCharacter(char, nextChar, ignoreHead) {
131
- if (!ignoreHead) {
132
- const code = char.codePointAt(0);
133
- if (isAsciiNumber(code)) {
134
- return `_${char}`;
135
- }
136
- if (char === "-" && nextChar && isAsciiNumber(nextChar.codePointAt(0))) {
137
- return `_${char}`;
138
- }
139
- if (char === "-" && nextChar === void 0) {
140
- return `_${char}`;
141
- }
142
- }
143
- return char;
144
- }
145
- function escape(selectors, options) {
146
- if (selectors.length === 0) {
147
- return "";
148
- }
149
- const { map, ignoreHead } = defu(options, {
150
- map: MappingChars2String,
151
- ignoreHead: false
152
- });
153
- const sb = [];
154
- for (let i = 0; i < selectors.length; i++) {
155
- const char = selectors[i];
156
- const code = char.codePointAt(0);
157
- if (code !== void 0) {
158
- if (code > MAX_ASCII_CHAR_CODE) {
159
- sb.push(`u${code.toString(16)}`);
160
- } else {
161
- const hit = map[char];
162
- if (hit) {
163
- sb.push(hit);
164
- } else if (i === 0) {
165
- sb.push(handleFirstCharacter(char, selectors[i + 1], ignoreHead));
166
- } else {
167
- sb.push(char);
168
- }
169
- }
170
- }
171
- }
172
- return sb.join("");
173
- }
174
-
175
- // ../weapp-tailwindcss/dist/chunk-Q67IXIAH.mjs
176
- function replaceWxml(original, options = {
177
- keepEOL: false,
178
- escapeMap: MappingChars2String
179
- }) {
180
- const { keepEOL, escapeMap, mangleContext, ignoreHead } = options;
181
- let res = original;
182
- if (!keepEOL) {
183
- res = res.replaceAll(/[\n\r]+/g, "");
184
- }
185
- if (mangleContext) {
186
- res = mangleContext.wxmlHandler(res);
187
- }
188
- res = escape(res, {
189
- map: escapeMap,
190
- ignoreHead
191
- });
192
- return res;
193
- }
194
-
195
- // ../weapp-tailwindcss/dist/escape.mjs
196
- var weappTwIgnore = String.raw;
197
-
198
- // src/core/escape.ts
199
- var noop = (value) => value;
200
- function resolveEscape(options) {
201
- if (_optionalChain([options, 'optionalAccess', _ => _.disableEscape])) {
202
- return noop;
203
- }
204
- return _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.escapeFn]), () => ( replaceWxml));
205
- }
206
-
207
-
208
-
209
-
210
- exports.weappTwIgnore = weappTwIgnore; exports.resolveEscape = resolveEscape;
@@ -1,44 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkBWF73VRWcjs = require('./chunk-BWF73VRW.cjs');
4
-
5
- // src/core/create-runtime.ts
6
- var _clsx = require('clsx');
7
- function wrapClassAggregator(fn, escapeFn) {
8
- return (...inputs) => {
9
- return escapeFn(fn(_clsx.clsx.call(void 0, ...inputs)));
10
- };
11
- }
12
- function wrapFactory(factory, escapeFn) {
13
- return (...args) => {
14
- const runtime = factory(...args);
15
- return wrapClassAggregator(runtime, escapeFn);
16
- };
17
- }
18
- function createRuntimeFactory(options) {
19
- const {
20
- version,
21
- twMerge: _twMerge,
22
- twJoin: _twJoin,
23
- extendTailwindMerge: _extendTailwindMerge,
24
- createTailwindMerge: _createTailwindMerge
25
- } = options;
26
- return function createRuntime(createOptions) {
27
- const escapeFn = _chunkBWF73VRWcjs.resolveEscape.call(void 0, createOptions);
28
- const twMerge = wrapClassAggregator(_twMerge, escapeFn);
29
- const twJoin = wrapClassAggregator(_twJoin, escapeFn);
30
- const extendTailwindMerge = wrapFactory(_extendTailwindMerge, escapeFn);
31
- const createTailwindMerge = wrapFactory(_createTailwindMerge, escapeFn);
32
- return {
33
- version,
34
- twMerge,
35
- twJoin,
36
- extendTailwindMerge,
37
- createTailwindMerge
38
- };
39
- };
40
- }
41
-
42
-
43
-
44
- exports.createRuntimeFactory = createRuntimeFactory;
@@ -1,44 +0,0 @@
1
- import {
2
- resolveEscape
3
- } from "./chunk-4KECYPIX.js";
4
-
5
- // src/core/create-runtime.ts
6
- import { clsx } from "clsx";
7
- function wrapClassAggregator(fn, escapeFn) {
8
- return (...inputs) => {
9
- return escapeFn(fn(clsx(...inputs)));
10
- };
11
- }
12
- function wrapFactory(factory, escapeFn) {
13
- return (...args) => {
14
- const runtime = factory(...args);
15
- return wrapClassAggregator(runtime, escapeFn);
16
- };
17
- }
18
- function createRuntimeFactory(options) {
19
- const {
20
- version,
21
- twMerge: _twMerge,
22
- twJoin: _twJoin,
23
- extendTailwindMerge: _extendTailwindMerge,
24
- createTailwindMerge: _createTailwindMerge
25
- } = options;
26
- return function createRuntime(createOptions) {
27
- const escapeFn = resolveEscape(createOptions);
28
- const twMerge = wrapClassAggregator(_twMerge, escapeFn);
29
- const twJoin = wrapClassAggregator(_twJoin, escapeFn);
30
- const extendTailwindMerge = wrapFactory(_extendTailwindMerge, escapeFn);
31
- const createTailwindMerge = wrapFactory(_createTailwindMerge, escapeFn);
32
- return {
33
- version,
34
- twMerge,
35
- twJoin,
36
- extendTailwindMerge,
37
- createTailwindMerge
38
- };
39
- };
40
- }
41
-
42
- export {
43
- createRuntimeFactory
44
- };
@@ -1,13 +0,0 @@
1
- import { ClassValue } from 'clsx';
2
-
3
- type EscapeFn = (value: string) => string;
4
- interface CreateOptions {
5
- disableEscape?: boolean;
6
- escapeFn?: EscapeFn;
7
- }
8
- type TailwindMergeLibraryFn = (...inputs: any[]) => string;
9
- type TailwindMergeRuntime = (...inputs: ClassValue[]) => string;
10
- type TailwindMergeFactory<TFactory extends (...args: any[]) => TailwindMergeLibraryFn> = (...args: Parameters<TFactory>) => TailwindMergeRuntime;
11
- type TailwindMergeVersion = 2 | 3;
12
-
13
- export type { CreateOptions as C, TailwindMergeVersion as T, TailwindMergeRuntime as a, TailwindMergeFactory as b };
@@ -1,13 +0,0 @@
1
- import { ClassValue } from 'clsx';
2
-
3
- type EscapeFn = (value: string) => string;
4
- interface CreateOptions {
5
- disableEscape?: boolean;
6
- escapeFn?: EscapeFn;
7
- }
8
- type TailwindMergeLibraryFn = (...inputs: any[]) => string;
9
- type TailwindMergeRuntime = (...inputs: ClassValue[]) => string;
10
- type TailwindMergeFactory<TFactory extends (...args: any[]) => TailwindMergeLibraryFn> = (...args: Parameters<TFactory>) => TailwindMergeRuntime;
11
- type TailwindMergeVersion = 2 | 3;
12
-
13
- export type { CreateOptions as C, TailwindMergeVersion as T, TailwindMergeRuntime as a, TailwindMergeFactory as b };
@@ -1,14 +0,0 @@
1
- const fs = require('node:fs')
2
- const path = require('node:path')
3
-
4
- function main() {
5
- const targetPath = path.resolve(__dirname, '../dist/postinstall.cjs')
6
- if (fs.existsSync(targetPath)) {
7
- require(targetPath)
8
- }
9
- else {
10
- console.log('postinstall.cjs not found')
11
- }
12
- }
13
-
14
- main()