@weapp-tailwindcss/postcss 3.0.4 → 3.0.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.
@@ -0,0 +1,158 @@
1
+ //#region src/css-macro/constants.ts
2
+ const queryKey = "weapp-tw-platform";
3
+ const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
4
+ const WHITESPACE_RE = /\s+/g;
5
+ const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
6
+ function normalComment(text) {
7
+ if (typeof text === "string") {
8
+ const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
9
+ if (normalized.includes("\\")) return normalized;
10
+ return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
11
+ }
12
+ return text;
13
+ }
14
+ function ifdef(text) {
15
+ return {
16
+ start: `#ifdef ${normalComment(text)}`,
17
+ end: `#endif`
18
+ };
19
+ }
20
+ function ifndef(text) {
21
+ return {
22
+ start: `#ifndef ${normalComment(text)}`,
23
+ end: `#endif`
24
+ };
25
+ }
26
+ const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
27
+ function matchCustomPropertyFromValue(str, cb) {
28
+ let index = 0;
29
+ QUERY_KEY_REGEX.lastIndex = 0;
30
+ let arr = QUERY_KEY_REGEX.exec(str);
31
+ while (arr !== null) {
32
+ cb(arr, index);
33
+ index++;
34
+ arr = QUERY_KEY_REGEX.exec(str);
35
+ }
36
+ }
37
+ function parseConditionalAtRuleParam(params) {
38
+ const value = params.trim();
39
+ const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
40
+ if (!quoted) return value;
41
+ return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
42
+ }
43
+ //#endregion
44
+ //#region src/css-macro/postcss.ts
45
+ const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
46
+ const CONDITIONAL_COMMENT_SPACING = " ";
47
+ const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
48
+ const creator = () => {
49
+ return {
50
+ postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
51
+ prepare() {
52
+ function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
53
+ const hasPreviousNode = Boolean(atRule.prev());
54
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
55
+ const startComment = helper.comment({
56
+ raws: {
57
+ left: CONDITIONAL_COMMENT_SPACING,
58
+ right: CONDITIONAL_COMMENT_SPACING
59
+ },
60
+ text: comment.start
61
+ });
62
+ const endComment = helper.comment({
63
+ raws: {
64
+ left: CONDITIONAL_COMMENT_SPACING,
65
+ right: CONDITIONAL_COMMENT_SPACING
66
+ },
67
+ text: comment.end
68
+ });
69
+ const nextNodes = [
70
+ startComment,
71
+ ...clonedNodes,
72
+ endComment
73
+ ];
74
+ atRule.replaceWith(nextNodes);
75
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
76
+ startComment.raws["after"] = "\n";
77
+ if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
78
+ endComment.raws.before = "\n";
79
+ endComment.raws["after"] = "\n";
80
+ const nextNode = endComment?.next();
81
+ if (nextNode) nextNode.raws.before = "\n";
82
+ }
83
+ function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
84
+ if (atRule.parent?.type !== "rule") return false;
85
+ const parentRule = atRule.parent;
86
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
87
+ const conditionalRule = parentRule.clone();
88
+ conditionalRule.removeAll();
89
+ conditionalRule.append(...clonedNodes);
90
+ const startComment = helper.comment({
91
+ raws: {
92
+ left: CONDITIONAL_COMMENT_SPACING,
93
+ right: CONDITIONAL_COMMENT_SPACING
94
+ },
95
+ text: comment.start
96
+ });
97
+ const endComment = helper.comment({
98
+ raws: {
99
+ left: CONDITIONAL_COMMENT_SPACING,
100
+ right: CONDITIONAL_COMMENT_SPACING
101
+ },
102
+ text: comment.end
103
+ });
104
+ const nextNodes = [
105
+ startComment,
106
+ conditionalRule,
107
+ endComment
108
+ ];
109
+ const hasPreviousNode = Boolean(parentRule.prev());
110
+ atRule.remove();
111
+ if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
112
+ else parentRule.after(nextNodes);
113
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
114
+ startComment.raws["after"] = "\n";
115
+ conditionalRule.raws.before = "\n";
116
+ endComment.raws.before = "\n";
117
+ endComment.raws["after"] = "\n";
118
+ const nextNode = endComment.next();
119
+ if (nextNode) nextNode.raws.before = "\n";
120
+ return true;
121
+ }
122
+ return {
123
+ AtRule(atRule, helper) {
124
+ if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
125
+ const text = parseConditionalAtRuleParam(atRule.params);
126
+ const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
127
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
128
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
129
+ return;
130
+ }
131
+ if (atRule.name === "media") {
132
+ const values = [];
133
+ matchCustomPropertyFromValue(atRule.params, (arr) => {
134
+ const value = arr[1];
135
+ if (value) values.push(value);
136
+ });
137
+ if (values.length > 0) {
138
+ const isNegative = atRule.params.includes("not");
139
+ const text = values.join(" ");
140
+ const comment = isNegative ? ifndef(text) : ifdef(text);
141
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
142
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
143
+ }
144
+ }
145
+ },
146
+ CommentExit(comment) {
147
+ if (IFDEF_ENDIF_RE.test(comment.text)) {
148
+ comment.raws.left = CONDITIONAL_COMMENT_SPACING;
149
+ comment.raws.right = CONDITIONAL_COMMENT_SPACING;
150
+ }
151
+ }
152
+ };
153
+ }
154
+ };
155
+ };
156
+ creator.postcss = true;
157
+ //#endregion
158
+ export { creator as n, CSS_MACRO_POSTCSS_PLUGIN_NAME as t };
@@ -0,0 +1,169 @@
1
+ //#region src/css-macro/constants.ts
2
+ const queryKey = "weapp-tw-platform";
3
+ const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
4
+ const WHITESPACE_RE = /\s+/g;
5
+ const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
6
+ function normalComment(text) {
7
+ if (typeof text === "string") {
8
+ const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
9
+ if (normalized.includes("\\")) return normalized;
10
+ return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
11
+ }
12
+ return text;
13
+ }
14
+ function ifdef(text) {
15
+ return {
16
+ start: `#ifdef ${normalComment(text)}`,
17
+ end: `#endif`
18
+ };
19
+ }
20
+ function ifndef(text) {
21
+ return {
22
+ start: `#ifndef ${normalComment(text)}`,
23
+ end: `#endif`
24
+ };
25
+ }
26
+ const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
27
+ function matchCustomPropertyFromValue(str, cb) {
28
+ let index = 0;
29
+ QUERY_KEY_REGEX.lastIndex = 0;
30
+ let arr = QUERY_KEY_REGEX.exec(str);
31
+ while (arr !== null) {
32
+ cb(arr, index);
33
+ index++;
34
+ arr = QUERY_KEY_REGEX.exec(str);
35
+ }
36
+ }
37
+ function parseConditionalAtRuleParam(params) {
38
+ const value = params.trim();
39
+ const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
40
+ if (!quoted) return value;
41
+ return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
42
+ }
43
+ //#endregion
44
+ //#region src/css-macro/postcss.ts
45
+ const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
46
+ const CONDITIONAL_COMMENT_SPACING = " ";
47
+ const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
48
+ const creator = () => {
49
+ return {
50
+ postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
51
+ prepare() {
52
+ function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
53
+ const hasPreviousNode = Boolean(atRule.prev());
54
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
55
+ const startComment = helper.comment({
56
+ raws: {
57
+ left: CONDITIONAL_COMMENT_SPACING,
58
+ right: CONDITIONAL_COMMENT_SPACING
59
+ },
60
+ text: comment.start
61
+ });
62
+ const endComment = helper.comment({
63
+ raws: {
64
+ left: CONDITIONAL_COMMENT_SPACING,
65
+ right: CONDITIONAL_COMMENT_SPACING
66
+ },
67
+ text: comment.end
68
+ });
69
+ const nextNodes = [
70
+ startComment,
71
+ ...clonedNodes,
72
+ endComment
73
+ ];
74
+ atRule.replaceWith(nextNodes);
75
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
76
+ startComment.raws["after"] = "\n";
77
+ if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
78
+ endComment.raws.before = "\n";
79
+ endComment.raws["after"] = "\n";
80
+ const nextNode = endComment?.next();
81
+ if (nextNode) nextNode.raws.before = "\n";
82
+ }
83
+ function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
84
+ if (atRule.parent?.type !== "rule") return false;
85
+ const parentRule = atRule.parent;
86
+ const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
87
+ const conditionalRule = parentRule.clone();
88
+ conditionalRule.removeAll();
89
+ conditionalRule.append(...clonedNodes);
90
+ const startComment = helper.comment({
91
+ raws: {
92
+ left: CONDITIONAL_COMMENT_SPACING,
93
+ right: CONDITIONAL_COMMENT_SPACING
94
+ },
95
+ text: comment.start
96
+ });
97
+ const endComment = helper.comment({
98
+ raws: {
99
+ left: CONDITIONAL_COMMENT_SPACING,
100
+ right: CONDITIONAL_COMMENT_SPACING
101
+ },
102
+ text: comment.end
103
+ });
104
+ const nextNodes = [
105
+ startComment,
106
+ conditionalRule,
107
+ endComment
108
+ ];
109
+ const hasPreviousNode = Boolean(parentRule.prev());
110
+ atRule.remove();
111
+ if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
112
+ else parentRule.after(nextNodes);
113
+ startComment.raws.before = hasPreviousNode ? "\n" : "";
114
+ startComment.raws["after"] = "\n";
115
+ conditionalRule.raws.before = "\n";
116
+ endComment.raws.before = "\n";
117
+ endComment.raws["after"] = "\n";
118
+ const nextNode = endComment.next();
119
+ if (nextNode) nextNode.raws.before = "\n";
120
+ return true;
121
+ }
122
+ return {
123
+ AtRule(atRule, helper) {
124
+ if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
125
+ const text = parseConditionalAtRuleParam(atRule.params);
126
+ const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
127
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
128
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
129
+ return;
130
+ }
131
+ if (atRule.name === "media") {
132
+ const values = [];
133
+ matchCustomPropertyFromValue(atRule.params, (arr) => {
134
+ const value = arr[1];
135
+ if (value) values.push(value);
136
+ });
137
+ if (values.length > 0) {
138
+ const isNegative = atRule.params.includes("not");
139
+ const text = values.join(" ");
140
+ const comment = isNegative ? ifndef(text) : ifdef(text);
141
+ if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
142
+ replaceAtRuleWithConditionalComments(atRule, helper, comment);
143
+ }
144
+ }
145
+ },
146
+ CommentExit(comment) {
147
+ if (IFDEF_ENDIF_RE.test(comment.text)) {
148
+ comment.raws.left = CONDITIONAL_COMMENT_SPACING;
149
+ comment.raws.right = CONDITIONAL_COMMENT_SPACING;
150
+ }
151
+ }
152
+ };
153
+ }
154
+ };
155
+ };
156
+ creator.postcss = true;
157
+ //#endregion
158
+ Object.defineProperty(exports, "CSS_MACRO_POSTCSS_PLUGIN_NAME", {
159
+ enumerable: true,
160
+ get: function() {
161
+ return CSS_MACRO_POSTCSS_PLUGIN_NAME;
162
+ }
163
+ });
164
+ Object.defineProperty(exports, "creator", {
165
+ enumerable: true,
166
+ get: function() {
167
+ return creator;
168
+ }
169
+ });
@@ -0,0 +1,8 @@
1
+ import postcssrc from 'postcss-load-config';
2
+ export declare function getPostcssPluginName(plugin: unknown): string | undefined;
3
+ export declare function removeTailwindPostcssPlugins(plugins: unknown[]): number;
4
+ export declare function resolveFilteredPostcssConfig(root: string): Promise<{
5
+ options: import("postcss").ProcessOptions<import("postcss").Document | import("postcss").Root>;
6
+ plugins: postcssrc.ResultPlugin[];
7
+ removed: number;
8
+ } | undefined>;
@@ -0,0 +1,2 @@
1
+ export type { AcceptedPlugin, AtRule, Container, Declaration, Document, Helpers, Node, Plugin, PluginCreator, ProcessOptions, Processor, Result, Root, Rule, } from 'postcss';
2
+ export { default as postcss } from 'postcss';
@@ -0,0 +1,7 @@
1
+ import type { Root } from 'postcss';
2
+ export interface TailwindInlineSourceCandidates {
3
+ included: Set<string>;
4
+ excluded: Set<string>;
5
+ }
6
+ export declare function expandInlineSourceCandidatePattern(pattern: string): string[];
7
+ export declare function collectCssInlineSourceCandidates(root: Root): TailwindInlineSourceCandidates;
@@ -0,0 +1,31 @@
1
+ import type { Root } from 'postcss';
2
+ export interface TailwindSourceEntry {
3
+ base: string;
4
+ pattern: string;
5
+ negated: boolean;
6
+ }
7
+ export type { TailwindInlineSourceCandidates } from './source-scan/inline-source';
8
+ export { collectCssInlineSourceCandidates, expandInlineSourceCandidatePattern } from './source-scan/inline-source';
9
+ export declare const DEFAULT_SOURCE_SCAN_EXTENSIONS: string[];
10
+ export declare const FULL_SOURCE_SCAN_EXTENSIONS: string[];
11
+ export declare function createSourceScanPattern(extensions?: string[]): string;
12
+ export declare const FULL_SOURCE_SCAN_PATTERN: string;
13
+ export declare const FULL_SOURCE_SCAN_EXTENSION_RE: RegExp;
14
+ export declare function toPosixPath(value: string): string;
15
+ export declare function resolveSourceScanPath(value: string): string;
16
+ export declare function isFileExcludedByTailwindSourceEntries(file: string, entries: TailwindSourceEntry[] | undefined): boolean;
17
+ export declare function isFileMatchedByTailwindSourceEntries(file: string, entries: TailwindSourceEntry[] | undefined): boolean;
18
+ export declare function createTailwindSourceEntryMatcher(entries: TailwindSourceEntry[] | undefined): ((file: string) => boolean) | undefined;
19
+ export declare function parseConfigParam(params: string): string | undefined;
20
+ export declare function normalizeLegacyContentEntries(content: unknown, base: string, options?: {
21
+ relativeBase?: string | undefined;
22
+ }): TailwindSourceEntry[];
23
+ export declare function resolveTailwindSourceEntry(sourcePath: string, base: string, negated: boolean, defaultPattern?: string): Promise<TailwindSourceEntry>;
24
+ export declare function parseSourceFileParam(params: string): {
25
+ negated: boolean;
26
+ sourcePath: string;
27
+ } | undefined;
28
+ export declare function resolveCssSourceEntries(root: Root, base: string, defaultPattern?: string): Promise<TailwindSourceEntry[]>;
29
+ export declare function expandTailwindSourceEntries(entries: TailwindSourceEntry[], options?: {
30
+ ignore?: string[];
31
+ }): Promise<string[]>;
@@ -0,0 +1,17 @@
1
+ export declare function mergeMiniProgramPreflightRuleDeclarations(baseCss: string, css: string): {
2
+ baseCss: string;
3
+ css: string;
4
+ changed: boolean;
5
+ };
6
+ export declare function mergeMiniProgramThemeScopeRuleDeclarations(baseCss: string, css: string): {
7
+ baseCss: string;
8
+ css: string;
9
+ changed: boolean;
10
+ };
11
+ export declare function mergeCoveredCssRuleDeclarations(baseCss: string, css: string): {
12
+ baseCss: string;
13
+ css: string;
14
+ changed: boolean;
15
+ };
16
+ export declare function filterExistingCssRules(baseCss: string, css: string): string;
17
+ export declare function containsCssAfterMinify(baseCss: string, css: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "3.0.4",
3
+ "version": "3.0.7",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -30,6 +30,11 @@
30
30
  "import": "./dist/html-transform.mjs",
31
31
  "require": "./dist/html-transform.js"
32
32
  },
33
+ "./css-macro/postcss": {
34
+ "types": "./dist/css-macro/postcss.d.ts",
35
+ "import": "./dist/css-macro/postcss.mjs",
36
+ "require": "./dist/css-macro/postcss.js"
37
+ },
33
38
  "./package.json": "./package.json"
34
39
  },
35
40
  "main": "./dist/index.js",
@@ -40,6 +45,9 @@
40
45
  "html-transform": [
41
46
  "./dist/html-transform.d.ts"
42
47
  ],
48
+ "css-macro/postcss": [
49
+ "./dist/css-macro/postcss.d.ts"
50
+ ],
43
51
  "types": [
44
52
  "./dist/types.d.ts"
45
53
  ],
@@ -59,14 +67,18 @@
59
67
  "@weapp-core/escape": "~8.0.0",
60
68
  "autoprefixer": "^10.5.0",
61
69
  "lru-cache": "11.5.1",
70
+ "micromatch": "^4.0.8",
62
71
  "postcss": "^8.5.15",
72
+ "postcss-load-config": "^6.0.1",
63
73
  "postcss-pxtrans": "^1.0.4",
64
74
  "postcss-rem-to-responsive-pixel": "^7.0.4",
65
75
  "postcss-rule-unit-converter": "^0.2.2",
66
76
  "postcss-selector-parser": "~7.1.2",
67
77
  "postcss-value-parser": "^4.2.0",
78
+ "tailwindcss-patch": "9.4.3",
68
79
  "@weapp-tailwindcss/postcss-calc": "^1.0.2",
69
- "@weapp-tailwindcss/shared": "2.0.0"
80
+ "@weapp-tailwindcss/shared": "2.0.0",
81
+ "tailwindcss-config": "2.0.0"
70
82
  },
71
83
  "devDependencies": {
72
84
  "@csstools/css-color-parser": "^4.1.1",
@@ -21,9 +21,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
- let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
25
24
  let node_process = require("node:process");
26
25
  node_process = __toESM(node_process);
26
+ let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
27
27
  //#region src/html-transform.ts
28
28
  const htmlTags = [
29
29
  "html",