tailwindcss-injector 0.0.0 → 0.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.
package/dist/index.cjs CHANGED
@@ -1,44 +1 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- bar: () => bar,
24
- getDirname: () => getDirname,
25
- xx: () => xx
26
- });
27
- module.exports = __toCommonJS(src_exports);
28
- function bar() {
29
- return "foo";
30
- }
31
- function getDirname() {
32
- return __dirname;
33
- }
34
- var xx = /* @__PURE__ */ ((xx2) => {
35
- xx2[xx2["id"] = 0] = "id";
36
- xx2[xx2["dd"] = 1] = "dd";
37
- return xx2;
38
- })(xx || {});
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- bar,
42
- getDirname,
43
- xx
44
- });
package/dist/index.d.cts CHANGED
@@ -1,8 +1,2 @@
1
- declare function bar(): string;
2
- declare function getDirname(): string;
3
- declare enum xx {
4
- id = 0,
5
- dd = 1
6
- }
7
1
 
8
- export { bar, getDirname, xx };
2
+ export { }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,2 @@
1
- declare function bar(): string;
2
- declare function getDirname(): string;
3
- declare enum xx {
4
- id = 0,
5
- dd = 1
6
- }
7
1
 
8
- export { bar, getDirname, xx };
2
+ export { }
package/dist/index.js CHANGED
@@ -1,24 +0,0 @@
1
- // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.0_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js
2
- import { fileURLToPath } from "url";
3
- import path from "path";
4
- var getFilename = () => fileURLToPath(import.meta.url);
5
- var getDirname = () => path.dirname(getFilename());
6
- var __dirname = /* @__PURE__ */ getDirname();
7
-
8
- // src/index.ts
9
- function bar() {
10
- return "foo";
11
- }
12
- function getDirname2() {
13
- return __dirname;
14
- }
15
- var xx = /* @__PURE__ */ ((xx2) => {
16
- xx2[xx2["id"] = 0] = "id";
17
- xx2[xx2["dd"] = 1] = "dd";
18
- return xx2;
19
- })(xx || {});
20
- export {
21
- bar,
22
- getDirname2 as getDirname,
23
- xx
24
- };
package/dist/postcss.cjs CHANGED
@@ -1,4 +1,227 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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/defu@6.1.4/node_modules/defu/dist/defu.mjs
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; }var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
10
+ var __commonJS = (cb, mod) => function __require() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+
30
+ // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js
31
+ var getImportMetaUrl, importMetaUrl;
32
+ var init_cjs_shims = __esm({
33
+ "../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js"() {
34
+ "use strict";
35
+ getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
36
+ importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
37
+ }
38
+ });
39
+
40
+ // ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
41
+ var require_is_primitive = __commonJS({
42
+ "../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports, module) {
43
+ "use strict";
44
+ init_cjs_shims();
45
+ module.exports = function isPrimitive(val) {
46
+ if (typeof val === "object") {
47
+ return val === null;
48
+ }
49
+ return typeof val !== "function";
50
+ };
51
+ }
52
+ });
53
+
54
+ // ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
55
+ var require_isobject = __commonJS({
56
+ "../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
57
+ "use strict";
58
+ init_cjs_shims();
59
+ module.exports = function isObject(val) {
60
+ return val != null && typeof val === "object" && Array.isArray(val) === false;
61
+ };
62
+ }
63
+ });
64
+
65
+ // ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
66
+ var require_is_plain_object = __commonJS({
67
+ "../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports, module) {
68
+ "use strict";
69
+ init_cjs_shims();
70
+ var isObject = require_isobject();
71
+ function isObjectObject(o) {
72
+ return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
73
+ }
74
+ module.exports = function isPlainObject2(o) {
75
+ var ctor, prot;
76
+ if (isObjectObject(o) === false) return false;
77
+ ctor = o.constructor;
78
+ if (typeof ctor !== "function") return false;
79
+ prot = ctor.prototype;
80
+ if (isObjectObject(prot) === false) return false;
81
+ if (prot.hasOwnProperty("isPrototypeOf") === false) {
82
+ return false;
83
+ }
84
+ return true;
85
+ };
86
+ }
87
+ });
88
+
89
+ // ../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js
90
+ var require_set_value = __commonJS({
91
+ "../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js"(exports, module) {
92
+ "use strict";
93
+ init_cjs_shims();
94
+ var { deleteProperty } = Reflect;
95
+ var isPrimitive = require_is_primitive();
96
+ var isPlainObject2 = require_is_plain_object();
97
+ var isObject = (value) => {
98
+ return typeof value === "object" && value !== null || typeof value === "function";
99
+ };
100
+ var isUnsafeKey = (key) => {
101
+ return key === "__proto__" || key === "constructor" || key === "prototype";
102
+ };
103
+ var validateKey = (key) => {
104
+ if (!isPrimitive(key)) {
105
+ throw new TypeError("Object keys must be strings or symbols");
106
+ }
107
+ if (isUnsafeKey(key)) {
108
+ throw new Error(`Cannot set unsafe key: "${key}"`);
109
+ }
110
+ };
111
+ var toStringKey = (input) => {
112
+ return Array.isArray(input) ? input.flat().map(String).join(",") : input;
113
+ };
114
+ var createMemoKey = (input, options) => {
115
+ if (typeof input !== "string" || !options) return input;
116
+ let key = input + ";";
117
+ if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
118
+ if (options.separator !== void 0) key += `separator=${options.separator};`;
119
+ if (options.split !== void 0) key += `split=${options.split};`;
120
+ if (options.merge !== void 0) key += `merge=${options.merge};`;
121
+ if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
122
+ return key;
123
+ };
124
+ var memoize = (input, options, fn) => {
125
+ const key = toStringKey(options ? createMemoKey(input, options) : input);
126
+ validateKey(key);
127
+ const value = setValue.cache.get(key) || fn();
128
+ setValue.cache.set(key, value);
129
+ return value;
130
+ };
131
+ var splitString = (input, options = {}) => {
132
+ const sep = options.separator || ".";
133
+ const preserve = sep === "/" ? false : options.preservePaths;
134
+ if (typeof input === "string" && preserve !== false && /\//.test(input)) {
135
+ return [input];
136
+ }
137
+ const parts = [];
138
+ let part = "";
139
+ const push = (part2) => {
140
+ let number;
141
+ if (part2.trim() !== "" && Number.isInteger(number = Number(part2))) {
142
+ parts.push(number);
143
+ } else {
144
+ parts.push(part2);
145
+ }
146
+ };
147
+ for (let i = 0; i < input.length; i++) {
148
+ const value = input[i];
149
+ if (value === "\\") {
150
+ part += input[++i];
151
+ continue;
152
+ }
153
+ if (value === sep) {
154
+ push(part);
155
+ part = "";
156
+ continue;
157
+ }
158
+ part += value;
159
+ }
160
+ if (part) {
161
+ push(part);
162
+ }
163
+ return parts;
164
+ };
165
+ var split = (input, options) => {
166
+ if (options && typeof options.split === "function") return options.split(input);
167
+ if (typeof input === "symbol") return [input];
168
+ if (Array.isArray(input)) return input;
169
+ return memoize(input, options, () => splitString(input, options));
170
+ };
171
+ var assignProp = (obj, prop, value, options) => {
172
+ validateKey(prop);
173
+ if (value === void 0) {
174
+ deleteProperty(obj, prop);
175
+ } else if (options && options.merge) {
176
+ const merge = options.merge === "function" ? options.merge : Object.assign;
177
+ if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
178
+ obj[prop] = merge(obj[prop], value);
179
+ } else {
180
+ obj[prop] = value;
181
+ }
182
+ } else {
183
+ obj[prop] = value;
184
+ }
185
+ return obj;
186
+ };
187
+ var setValue = (target, path3, value, options) => {
188
+ if (!path3 || !isObject(target)) return target;
189
+ const keys = split(path3, options);
190
+ let obj = target;
191
+ for (let i = 0; i < keys.length; i++) {
192
+ const key = keys[i];
193
+ const next = keys[i + 1];
194
+ validateKey(key);
195
+ if (next === void 0) {
196
+ assignProp(obj, key, value, options);
197
+ break;
198
+ }
199
+ if (typeof next === "number" && !Array.isArray(obj[key])) {
200
+ obj = obj[key] = [];
201
+ continue;
202
+ }
203
+ if (!isObject(obj[key])) {
204
+ obj[key] = {};
205
+ }
206
+ obj = obj[key];
207
+ }
208
+ return target;
209
+ };
210
+ setValue.split = split;
211
+ setValue.cache = /* @__PURE__ */ new Map();
212
+ setValue.clear = () => {
213
+ setValue.cache = /* @__PURE__ */ new Map();
214
+ };
215
+ module.exports = setValue;
216
+ }
217
+ });
218
+
219
+ // src/postcss.ts
220
+ init_cjs_shims();
221
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
222
+
223
+ // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
224
+ init_cjs_shims();
2
225
  function isPlainObject(value) {
3
226
  if (value === null || typeof value !== "object") {
4
227
  return false;
@@ -67,24 +290,111 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
67
290
  });
68
291
 
69
292
  // src/postcss.ts
293
+ var import_set_value = __toESM(require_set_value(), 1);
70
294
  var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
71
295
  var _tailwindcss = require('tailwindcss'); var _tailwindcss2 = _interopRequireDefault(_tailwindcss);
296
+
297
+ // src/config.ts
298
+ init_cjs_shims();
299
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
300
+
301
+ var _jiti = require('jiti');
302
+ var _lilconfig = require('lilconfig');
303
+ var jiti = _jiti.createJiti.call(void 0, importMetaUrl);
304
+ var moduleName = "tailwind";
305
+ async function loadConfig(options) {
306
+ const { config, cwd } = defu(options, {
307
+ cwd: _process2.default.cwd()
308
+ });
309
+ const searcher = _lilconfig.lilconfig.call(void 0, "tailwindcss", {
310
+ searchPlaces: [
311
+ `${moduleName}.config.js`,
312
+ `${moduleName}.config.cjs`,
313
+ `${moduleName}.config.mjs`,
314
+ `${moduleName}.config.ts`,
315
+ `${moduleName}.config.cts`,
316
+ `${moduleName}.config.mts`
317
+ ],
318
+ loaders: {
319
+ ".js": jiti,
320
+ ".cjs": jiti,
321
+ ".mjs": jiti,
322
+ ".ts": jiti,
323
+ ".cts": jiti,
324
+ ".mts": jiti
325
+ }
326
+ });
327
+ if (typeof config === "string" && config) {
328
+ const configPath = _path2.default.isAbsolute(config) ? config : _path2.default.resolve(cwd, config);
329
+ const result = await searcher.load(configPath);
330
+ return _optionalChain([result, 'optionalAccess', _ => _.config]);
331
+ } else {
332
+ const result = await searcher.search(cwd);
333
+ return _optionalChain([result, 'optionalAccess', _2 => _2.config]);
334
+ }
335
+ }
336
+
337
+ // src/utils.ts
338
+ init_cjs_shims();
339
+
340
+ function removeFileExtension(filePath) {
341
+ let baseName = _path2.default.basename(filePath, _path2.default.extname(filePath));
342
+ while (baseName.includes(".")) {
343
+ baseName = _path2.default.basename(baseName, _path2.default.extname(baseName));
344
+ }
345
+ const dir = _path2.default.dirname(filePath);
346
+ return _path2.default.join(dir, baseName);
347
+ }
348
+
349
+ // src/postcss.ts
72
350
  var creator = (options) => {
73
- const { config, filter } = defu(options, {
351
+ const { config, filter, directiveParams, cwd, extensions } = defu(options, {
74
352
  filter: () => true,
75
- config: void 0
353
+ config: void 0,
354
+ directiveParams: ["utilities"],
355
+ cwd: _process2.default.cwd(),
356
+ extensions: ["wxml", "js", "ts"]
76
357
  });
358
+ const extensionsGlob = `{${extensions.join(",")}}`;
77
359
  return {
78
360
  postcssPlugin: "postcss-tailwindcss-injector",
79
- async Once(root) {
80
- if (filter(_optionalChain([root, 'access', _ => _.source, 'optionalAccess', _2 => _2.input]))) {
81
- const cfg = typeof config === "function" ? config(_optionalChain([root, 'access', _3 => _3.source, 'optionalAccess', _4 => _4.input])) : config;
82
- const { root: newRoot } = await _postcss2.default.call(void 0, [
83
- _tailwindcss2.default.call(void 0, cfg)
84
- ]).process(root);
85
- root.replaceWith(newRoot);
361
+ plugins: [
362
+ {
363
+ postcssPlugin: "post",
364
+ async Once(root, helpers) {
365
+ if (filter(_optionalChain([root, 'access', _3 => _3.source, 'optionalAccess', _4 => _4.input]))) {
366
+ let _root = root;
367
+ for (const params of directiveParams) {
368
+ const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
369
+ if (!node) {
370
+ _root = _root.prepend(helpers.atRule({ name: "tailwind", params }));
371
+ }
372
+ }
373
+ const cfg = typeof config === "function" ? config(_optionalChain([root, 'access', _5 => _5.source, 'optionalAccess', _6 => _6.input])) : config;
374
+ let tailwindcssConfig;
375
+ if (typeof cfg === "string") {
376
+ tailwindcssConfig = await loadConfig({
377
+ cwd,
378
+ config: cfg
379
+ });
380
+ } else {
381
+ tailwindcssConfig = _nullishCoalesce(cfg, () => ( {
382
+ content: []
383
+ }));
384
+ }
385
+ if (tailwindcssConfig && _optionalChain([root, 'access', _7 => _7.source, 'optionalAccess', _8 => _8.input]) && root.source.input.file) {
386
+ (0, import_set_value.default)(tailwindcssConfig, "content", [
387
+ `${removeFileExtension(root.source.input.file)}.${extensionsGlob}`
388
+ ]);
389
+ }
390
+ const { root: newRoot } = await _postcss2.default.call(void 0, [
391
+ _tailwindcss2.default.call(void 0, tailwindcssConfig)
392
+ ]).process(_root);
393
+ root.replaceWith(newRoot);
394
+ }
395
+ }
86
396
  }
87
- }
397
+ ]
88
398
  };
89
399
  };
90
400
  creator.postcss = true;
@@ -92,5 +402,39 @@ var postcss_default = creator;
92
402
 
93
403
 
94
404
  exports.default = postcss_default;
405
+ /*! Bundled license information:
406
+
407
+ is-primitive/index.js:
408
+ (*!
409
+ * is-primitive <https://github.com/jonschlinkert/is-primitive>
410
+ *
411
+ * Copyright (c) 2014-present, Jon Schlinkert.
412
+ * Released under the MIT License.
413
+ *)
414
+
415
+ isobject/index.js:
416
+ (*!
417
+ * isobject <https://github.com/jonschlinkert/isobject>
418
+ *
419
+ * Copyright (c) 2014-2017, Jon Schlinkert.
420
+ * Released under the MIT License.
421
+ *)
422
+
423
+ is-plain-object/index.js:
424
+ (*!
425
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
426
+ *
427
+ * Copyright (c) 2014-2017, Jon Schlinkert.
428
+ * Released under the MIT License.
429
+ *)
430
+
431
+ set-value/index.js:
432
+ (*!
433
+ * set-value <https://github.com/jonschlinkert/set-value>
434
+ *
435
+ * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
436
+ * Released under the MIT License.
437
+ *)
438
+ */
95
439
 
96
440
  module.exports = exports.default;
@@ -1,13 +1,15 @@
1
1
  import postcss, { PluginCreator } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
3
 
4
- type InlineTailwindcssOptions = string | Config | {
5
- config: string | Config;
6
- } | undefined;
4
+ type InlineTailwindcssOptions = string | Config | undefined;
7
5
  interface Options {
6
+ cwd: string;
8
7
  filter: (input?: postcss.Input) => boolean;
9
8
  config: InlineTailwindcssOptions | ((input?: postcss.Input) => InlineTailwindcssOptions);
9
+ directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
10
+ extensions: string[];
10
11
  }
12
+
11
13
  declare const creator: PluginCreator<Partial<Options>>;
12
14
 
13
15
  export { type Options, creator as default };
package/dist/postcss.d.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  import postcss, { PluginCreator } from 'postcss';
2
2
  import { Config } from 'tailwindcss';
3
3
 
4
- type InlineTailwindcssOptions = string | Config | {
5
- config: string | Config;
6
- } | undefined;
4
+ type InlineTailwindcssOptions = string | Config | undefined;
7
5
  interface Options {
6
+ cwd: string;
8
7
  filter: (input?: postcss.Input) => boolean;
9
8
  config: InlineTailwindcssOptions | ((input?: postcss.Input) => InlineTailwindcssOptions);
9
+ directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
10
+ extensions: string[];
10
11
  }
12
+
11
13
  declare const creator: PluginCreator<Partial<Options>>;
12
14
 
13
15
  export { type Options, creator as default };
package/dist/postcss.js CHANGED
@@ -1,4 +1,224 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
10
+ var __commonJS = (cb, mod) => function __require() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+
30
+ // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js
31
+ var init_esm_shims = __esm({
32
+ "../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js"() {
33
+ "use strict";
34
+ }
35
+ });
36
+
37
+ // ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
38
+ var require_is_primitive = __commonJS({
39
+ "../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports, module) {
40
+ "use strict";
41
+ init_esm_shims();
42
+ module.exports = function isPrimitive(val) {
43
+ if (typeof val === "object") {
44
+ return val === null;
45
+ }
46
+ return typeof val !== "function";
47
+ };
48
+ }
49
+ });
50
+
51
+ // ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
52
+ var require_isobject = __commonJS({
53
+ "../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
54
+ "use strict";
55
+ init_esm_shims();
56
+ module.exports = function isObject(val) {
57
+ return val != null && typeof val === "object" && Array.isArray(val) === false;
58
+ };
59
+ }
60
+ });
61
+
62
+ // ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
63
+ var require_is_plain_object = __commonJS({
64
+ "../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports, module) {
65
+ "use strict";
66
+ init_esm_shims();
67
+ var isObject = require_isobject();
68
+ function isObjectObject(o) {
69
+ return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
70
+ }
71
+ module.exports = function isPlainObject2(o) {
72
+ var ctor, prot;
73
+ if (isObjectObject(o) === false) return false;
74
+ ctor = o.constructor;
75
+ if (typeof ctor !== "function") return false;
76
+ prot = ctor.prototype;
77
+ if (isObjectObject(prot) === false) return false;
78
+ if (prot.hasOwnProperty("isPrototypeOf") === false) {
79
+ return false;
80
+ }
81
+ return true;
82
+ };
83
+ }
84
+ });
85
+
86
+ // ../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js
87
+ var require_set_value = __commonJS({
88
+ "../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js"(exports, module) {
89
+ "use strict";
90
+ init_esm_shims();
91
+ var { deleteProperty } = Reflect;
92
+ var isPrimitive = require_is_primitive();
93
+ var isPlainObject2 = require_is_plain_object();
94
+ var isObject = (value) => {
95
+ return typeof value === "object" && value !== null || typeof value === "function";
96
+ };
97
+ var isUnsafeKey = (key) => {
98
+ return key === "__proto__" || key === "constructor" || key === "prototype";
99
+ };
100
+ var validateKey = (key) => {
101
+ if (!isPrimitive(key)) {
102
+ throw new TypeError("Object keys must be strings or symbols");
103
+ }
104
+ if (isUnsafeKey(key)) {
105
+ throw new Error(`Cannot set unsafe key: "${key}"`);
106
+ }
107
+ };
108
+ var toStringKey = (input) => {
109
+ return Array.isArray(input) ? input.flat().map(String).join(",") : input;
110
+ };
111
+ var createMemoKey = (input, options) => {
112
+ if (typeof input !== "string" || !options) return input;
113
+ let key = input + ";";
114
+ if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
115
+ if (options.separator !== void 0) key += `separator=${options.separator};`;
116
+ if (options.split !== void 0) key += `split=${options.split};`;
117
+ if (options.merge !== void 0) key += `merge=${options.merge};`;
118
+ if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
119
+ return key;
120
+ };
121
+ var memoize = (input, options, fn) => {
122
+ const key = toStringKey(options ? createMemoKey(input, options) : input);
123
+ validateKey(key);
124
+ const value = setValue.cache.get(key) || fn();
125
+ setValue.cache.set(key, value);
126
+ return value;
127
+ };
128
+ var splitString = (input, options = {}) => {
129
+ const sep = options.separator || ".";
130
+ const preserve = sep === "/" ? false : options.preservePaths;
131
+ if (typeof input === "string" && preserve !== false && /\//.test(input)) {
132
+ return [input];
133
+ }
134
+ const parts = [];
135
+ let part = "";
136
+ const push = (part2) => {
137
+ let number;
138
+ if (part2.trim() !== "" && Number.isInteger(number = Number(part2))) {
139
+ parts.push(number);
140
+ } else {
141
+ parts.push(part2);
142
+ }
143
+ };
144
+ for (let i = 0; i < input.length; i++) {
145
+ const value = input[i];
146
+ if (value === "\\") {
147
+ part += input[++i];
148
+ continue;
149
+ }
150
+ if (value === sep) {
151
+ push(part);
152
+ part = "";
153
+ continue;
154
+ }
155
+ part += value;
156
+ }
157
+ if (part) {
158
+ push(part);
159
+ }
160
+ return parts;
161
+ };
162
+ var split = (input, options) => {
163
+ if (options && typeof options.split === "function") return options.split(input);
164
+ if (typeof input === "symbol") return [input];
165
+ if (Array.isArray(input)) return input;
166
+ return memoize(input, options, () => splitString(input, options));
167
+ };
168
+ var assignProp = (obj, prop, value, options) => {
169
+ validateKey(prop);
170
+ if (value === void 0) {
171
+ deleteProperty(obj, prop);
172
+ } else if (options && options.merge) {
173
+ const merge = options.merge === "function" ? options.merge : Object.assign;
174
+ if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
175
+ obj[prop] = merge(obj[prop], value);
176
+ } else {
177
+ obj[prop] = value;
178
+ }
179
+ } else {
180
+ obj[prop] = value;
181
+ }
182
+ return obj;
183
+ };
184
+ var setValue = (target, path3, value, options) => {
185
+ if (!path3 || !isObject(target)) return target;
186
+ const keys = split(path3, options);
187
+ let obj = target;
188
+ for (let i = 0; i < keys.length; i++) {
189
+ const key = keys[i];
190
+ const next = keys[i + 1];
191
+ validateKey(key);
192
+ if (next === void 0) {
193
+ assignProp(obj, key, value, options);
194
+ break;
195
+ }
196
+ if (typeof next === "number" && !Array.isArray(obj[key])) {
197
+ obj = obj[key] = [];
198
+ continue;
199
+ }
200
+ if (!isObject(obj[key])) {
201
+ obj[key] = {};
202
+ }
203
+ obj = obj[key];
204
+ }
205
+ return target;
206
+ };
207
+ setValue.split = split;
208
+ setValue.cache = /* @__PURE__ */ new Map();
209
+ setValue.clear = () => {
210
+ setValue.cache = /* @__PURE__ */ new Map();
211
+ };
212
+ module.exports = setValue;
213
+ }
214
+ });
215
+
216
+ // src/postcss.ts
217
+ init_esm_shims();
218
+ import process2 from "node:process";
219
+
1
220
  // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
221
+ init_esm_shims();
2
222
  function isPlainObject(value) {
3
223
  if (value === null || typeof value !== "object") {
4
224
  return false;
@@ -67,24 +287,111 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
67
287
  });
68
288
 
69
289
  // src/postcss.ts
290
+ var import_set_value = __toESM(require_set_value(), 1);
70
291
  import postcss from "postcss";
71
292
  import tailwindcss from "tailwindcss";
293
+
294
+ // src/config.ts
295
+ init_esm_shims();
296
+ import path from "node:path";
297
+ import process from "node:process";
298
+ import { createJiti } from "jiti";
299
+ import { lilconfig } from "lilconfig";
300
+ var jiti = createJiti(import.meta.url);
301
+ var moduleName = "tailwind";
302
+ async function loadConfig(options) {
303
+ const { config, cwd } = defu(options, {
304
+ cwd: process.cwd()
305
+ });
306
+ const searcher = lilconfig("tailwindcss", {
307
+ searchPlaces: [
308
+ `${moduleName}.config.js`,
309
+ `${moduleName}.config.cjs`,
310
+ `${moduleName}.config.mjs`,
311
+ `${moduleName}.config.ts`,
312
+ `${moduleName}.config.cts`,
313
+ `${moduleName}.config.mts`
314
+ ],
315
+ loaders: {
316
+ ".js": jiti,
317
+ ".cjs": jiti,
318
+ ".mjs": jiti,
319
+ ".ts": jiti,
320
+ ".cts": jiti,
321
+ ".mts": jiti
322
+ }
323
+ });
324
+ if (typeof config === "string" && config) {
325
+ const configPath = path.isAbsolute(config) ? config : path.resolve(cwd, config);
326
+ const result = await searcher.load(configPath);
327
+ return result?.config;
328
+ } else {
329
+ const result = await searcher.search(cwd);
330
+ return result?.config;
331
+ }
332
+ }
333
+
334
+ // src/utils.ts
335
+ init_esm_shims();
336
+ import path2 from "node:path";
337
+ function removeFileExtension(filePath) {
338
+ let baseName = path2.basename(filePath, path2.extname(filePath));
339
+ while (baseName.includes(".")) {
340
+ baseName = path2.basename(baseName, path2.extname(baseName));
341
+ }
342
+ const dir = path2.dirname(filePath);
343
+ return path2.join(dir, baseName);
344
+ }
345
+
346
+ // src/postcss.ts
72
347
  var creator = (options) => {
73
- const { config, filter } = defu(options, {
348
+ const { config, filter, directiveParams, cwd, extensions } = defu(options, {
74
349
  filter: () => true,
75
- config: void 0
350
+ config: void 0,
351
+ directiveParams: ["utilities"],
352
+ cwd: process2.cwd(),
353
+ extensions: ["wxml", "js", "ts"]
76
354
  });
355
+ const extensionsGlob = `{${extensions.join(",")}}`;
77
356
  return {
78
357
  postcssPlugin: "postcss-tailwindcss-injector",
79
- async Once(root) {
80
- if (filter(root.source?.input)) {
81
- const cfg = typeof config === "function" ? config(root.source?.input) : config;
82
- const { root: newRoot } = await postcss([
83
- tailwindcss(cfg)
84
- ]).process(root);
85
- root.replaceWith(newRoot);
358
+ plugins: [
359
+ {
360
+ postcssPlugin: "post",
361
+ async Once(root, helpers) {
362
+ if (filter(root.source?.input)) {
363
+ let _root = root;
364
+ for (const params of directiveParams) {
365
+ const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
366
+ if (!node) {
367
+ _root = _root.prepend(helpers.atRule({ name: "tailwind", params }));
368
+ }
369
+ }
370
+ const cfg = typeof config === "function" ? config(root.source?.input) : config;
371
+ let tailwindcssConfig;
372
+ if (typeof cfg === "string") {
373
+ tailwindcssConfig = await loadConfig({
374
+ cwd,
375
+ config: cfg
376
+ });
377
+ } else {
378
+ tailwindcssConfig = cfg ?? {
379
+ content: []
380
+ };
381
+ }
382
+ if (tailwindcssConfig && root.source?.input && root.source.input.file) {
383
+ (0, import_set_value.default)(tailwindcssConfig, "content", [
384
+ `${removeFileExtension(root.source.input.file)}.${extensionsGlob}`
385
+ ]);
386
+ }
387
+ const { root: newRoot } = await postcss([
388
+ tailwindcss(tailwindcssConfig)
389
+ ]).process(_root);
390
+ root.replaceWith(newRoot);
391
+ }
392
+ }
86
393
  }
87
- }
394
+ ]
88
395
  };
89
396
  };
90
397
  creator.postcss = true;
@@ -92,3 +399,37 @@ var postcss_default = creator;
92
399
  export {
93
400
  postcss_default as default
94
401
  };
402
+ /*! Bundled license information:
403
+
404
+ is-primitive/index.js:
405
+ (*!
406
+ * is-primitive <https://github.com/jonschlinkert/is-primitive>
407
+ *
408
+ * Copyright (c) 2014-present, Jon Schlinkert.
409
+ * Released under the MIT License.
410
+ *)
411
+
412
+ isobject/index.js:
413
+ (*!
414
+ * isobject <https://github.com/jonschlinkert/isobject>
415
+ *
416
+ * Copyright (c) 2014-2017, Jon Schlinkert.
417
+ * Released under the MIT License.
418
+ *)
419
+
420
+ is-plain-object/index.js:
421
+ (*!
422
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
423
+ *
424
+ * Copyright (c) 2014-2017, Jon Schlinkert.
425
+ * Released under the MIT License.
426
+ *)
427
+
428
+ set-value/index.js:
429
+ (*!
430
+ * set-value <https://github.com/jonschlinkert/set-value>
431
+ *
432
+ * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
433
+ * Released under the MIT License.
434
+ *)
435
+ */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tailwindcss-injector",
3
3
  "type": "module",
4
- "version": "0.0.0",
4
+ "version": "0.0.1",
5
5
  "description": "tsup(esbuild) build package template",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -31,6 +31,8 @@
31
31
  "dist"
32
32
  ],
33
33
  "dependencies": {
34
+ "jiti": "^2.4.1",
35
+ "lilconfig": "^3.1.2",
34
36
  "postcss": "^8.4.49",
35
37
  "tailwindcss": "^3.4.15"
36
38
  },