@weapp-tailwindcss/postcss 2.2.0-next.0 → 2.2.1-next.0

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.
Files changed (64) hide show
  1. package/README.md +4 -5
  2. package/dist/autoprefixer.d.ts +7 -0
  3. package/dist/compat/color-mix.d.ts +5 -0
  4. package/dist/compat/tailwindcss-rpx.d.ts +4 -0
  5. package/dist/compat/tailwindcss-v4.d.ts +12 -0
  6. package/dist/compat/uni-app-x-uvue.d.ts +3 -0
  7. package/dist/compat/uni-app-x.d.ts +9 -0
  8. package/dist/constants.d.ts +1 -0
  9. package/dist/content-probe.d.ts +38 -0
  10. package/dist/cssVarsV3.d.ts +5 -0
  11. package/dist/cssVarsV4.d.ts +5 -0
  12. package/dist/defaults.d.ts +2 -0
  13. package/dist/fingerprint.d.ts +6 -0
  14. package/dist/handler.d.ts +2 -0
  15. package/dist/html-transform-DuSRw6IH.js +225 -0
  16. package/dist/html-transform.d.ts +3 -7
  17. package/dist/html-transform.js +2 -8
  18. package/dist/html-transform.mjs +190 -5
  19. package/dist/index.d.ts +8 -18
  20. package/dist/index.js +2298 -2685
  21. package/dist/index.mjs +2276 -2679
  22. package/dist/mp.d.ts +26 -0
  23. package/dist/options-resolver.d.ts +5 -0
  24. package/dist/pipeline.d.ts +44 -0
  25. package/dist/plugins/colorFunctionalFallback.d.ts +5 -0
  26. package/dist/plugins/ctx.d.ts +6 -0
  27. package/dist/plugins/getCalcDuplicateCleaner.d.ts +3 -0
  28. package/dist/plugins/getCalcPlugin.d.ts +3 -0
  29. package/dist/plugins/getCustomPropertyCleaner.d.ts +3 -0
  30. package/dist/plugins/getPxTransformPlugin.d.ts +3 -0
  31. package/dist/plugins/getRemTransformPlugin.d.ts +3 -0
  32. package/dist/plugins/getUnitsToPxPlugin.d.ts +3 -0
  33. package/dist/plugins/index.d.ts +7 -0
  34. package/dist/plugins/post/decl-dedupe.d.ts +3 -0
  35. package/dist/plugins/post/specificity-cleaner.d.ts +5 -0
  36. package/dist/plugins/post.d.ts +6 -0
  37. package/dist/plugins/pre.d.ts +5 -0
  38. package/dist/preflight.d.ts +3 -0
  39. package/dist/preset-env-options.d.ts +14 -0
  40. package/dist/processor-cache.d.ts +18 -0
  41. package/dist/selectorParser/before-after.d.ts +2 -0
  42. package/dist/selectorParser/fallback.d.ts +9 -0
  43. package/dist/selectorParser/rule-transformer.d.ts +4 -0
  44. package/dist/selectorParser/spacing.d.ts +6 -0
  45. package/dist/selectorParser/utils.d.ts +11 -0
  46. package/dist/selectorParser.d.ts +4 -0
  47. package/dist/shared.d.ts +3 -0
  48. package/dist/types.d.ts +86 -8
  49. package/dist/types.js +0 -1
  50. package/dist/types.mjs +1 -1
  51. package/dist/utils/css-vars.d.ts +9 -0
  52. package/dist/utils/decl-order.d.ts +5 -0
  53. package/dist/utils/selector-guard.d.ts +8 -0
  54. package/dist/utils/tw-vars.d.ts +5 -0
  55. package/package.json +6 -5
  56. package/dist/chunk-2DNJBRQ3.mjs +0 -64
  57. package/dist/chunk-2Y3ULRB3.js +0 -64
  58. package/dist/chunk-GGNOJ77I.js +0 -1
  59. package/dist/chunk-WAXGOBY2.mjs +0 -0
  60. package/dist/html-transform.d.mts +0 -13
  61. package/dist/index.d.mts +0 -18
  62. package/dist/types-DJDvtI8K.d.mts +0 -166
  63. package/dist/types-DJDvtI8K.d.ts +0 -166
  64. package/dist/types.d.mts +0 -8
package/dist/mp.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { IStyleHandlerOptions } from './types';
2
+ import { Rule } from 'postcss';
3
+ /**
4
+ * 带有子选择器的
5
+ * 参考:https://tailwindcss.com/docs/space
6
+ * .space-x-4>:not([hidden])~:not([hidden])
7
+ *
8
+ * 参考:https://tailwindcss.com/docs/divide-width
9
+ * .divide-x>:not([hidden])~:not([hidden])
10
+ *
11
+ * 参考:https://tailwindcss.com/docs/divide-color
12
+ * .divide-blue-200>:not([hidden])~:not([hidden])
13
+ * :is(.dark .dark\:divide-slate-700)>:not([hidden])~:not([hidden])
14
+ *
15
+ * 参考:https://tailwindcss.com/docs/divide-style
16
+ * .divide-dashed>:not([hidden])~:not([hidden])
17
+ *
18
+ * 其中小程序里直接写
19
+ * .divide-y-4>:not(hidden) + :not(hidden)
20
+ * 会语法错误
21
+ */
22
+ export declare function testIfVariablesScope(node: Rule, count?: number): boolean;
23
+ export declare function testIfTwBackdrop(node: Rule, count?: number): boolean;
24
+ export declare function makePseudoVarRule(): Rule;
25
+ export declare function remakeCssVarSelector(selectors: string[], options: IStyleHandlerOptions): string[];
26
+ export declare function commonChunkPreflight(node: Rule, options: IStyleHandlerOptions): void;
@@ -0,0 +1,5 @@
1
+ import type { IStyleHandlerOptions } from './types';
2
+ export interface OptionsResolver {
3
+ resolve: (overrides?: Partial<IStyleHandlerOptions>) => IStyleHandlerOptions;
4
+ }
5
+ export declare function createOptionsResolver(baseOptions: IStyleHandlerOptions): OptionsResolver;
@@ -0,0 +1,44 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { FeatureSignal } from './content-probe';
3
+ import type { IStyleHandlerOptions } from './types';
4
+ export type PipelineStage = 'pre' | 'normal' | 'post';
5
+ export interface PipelineNodeCursor {
6
+ id: string;
7
+ stage: PipelineStage;
8
+ }
9
+ export interface PipelineNodeContext {
10
+ stage: PipelineStage;
11
+ /**
12
+ * 整个流水线内的顺序索引(从 0 开始)
13
+ */
14
+ index: number;
15
+ /**
16
+ * 当前流水线包含的节点总数
17
+ */
18
+ size: number;
19
+ /**
20
+ * 所在阶段内的顺序索引(从 0 开始)
21
+ */
22
+ stageIndex: number;
23
+ /**
24
+ * 所在阶段的节点数量
25
+ */
26
+ stageSize: number;
27
+ /**
28
+ * 指向前一个节点的游标(若存在)
29
+ */
30
+ previous?: PipelineNodeCursor;
31
+ /**
32
+ * 指向后一个节点的游标(若存在)
33
+ */
34
+ next?: PipelineNodeCursor;
35
+ }
36
+ export interface ResolvedPipelineNode extends PipelineNodeCursor {
37
+ plugin: AcceptedPlugin;
38
+ context: PipelineNodeContext;
39
+ }
40
+ export interface StyleProcessingPipeline {
41
+ nodes: ResolvedPipelineNode[];
42
+ plugins: AcceptedPlugin[];
43
+ }
44
+ export declare function createStylePipeline(options: IStyleHandlerOptions, signal?: FeatureSignal): StyleProcessingPipeline;
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from 'postcss';
2
+ export declare function createColorFunctionalFallback(): Plugin;
3
+ export declare namespace createColorFunctionalFallback {
4
+ var postcss: boolean;
5
+ }
@@ -0,0 +1,6 @@
1
+ export declare function createContext(): {
2
+ variablesScopeWeakMap: WeakMap<WeakKey, any>;
3
+ isVariablesScope: (rule: WeakKey) => boolean;
4
+ markVariablesScope: (rule: WeakKey) => void;
5
+ };
6
+ export type IContext = ReturnType<typeof createContext>;
@@ -0,0 +1,3 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export declare function getCalcDuplicateCleaner(options: IStyleHandlerOptions): AcceptedPlugin | null;
@@ -0,0 +1,3 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export declare function getCalcPlugin(options: IStyleHandlerOptions): AcceptedPlugin | null;
@@ -0,0 +1,3 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export declare function getCustomPropertyCleaner(options: IStyleHandlerOptions): AcceptedPlugin | null;
@@ -0,0 +1,3 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export declare function getPxTransformPlugin(options: IStyleHandlerOptions): AcceptedPlugin | null;
@@ -0,0 +1,3 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export declare function getRemTransformPlugin(options: IStyleHandlerOptions): AcceptedPlugin | null;
@@ -0,0 +1,3 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export declare function getUnitsToPxPlugin(options: IStyleHandlerOptions): AcceptedPlugin | null;
@@ -0,0 +1,7 @@
1
+ import type { AcceptedPlugin } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export { createStylePipeline } from '../pipeline';
4
+ export { postcssWeappTailwindcssPostPlugin } from './post';
5
+ export { postcssWeappTailwindcssPrePlugin } from './pre';
6
+ export { default as postcssRem2rpx } from 'postcss-rem-to-responsive-pixel';
7
+ export declare function getPlugins(options: IStyleHandlerOptions): AcceptedPlugin[];
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'postcss';
2
+ export declare function reorderVariableDeclarations(rule: Rule): void;
3
+ export declare function dedupeDeclarations(rule: Rule): void;
@@ -0,0 +1,5 @@
1
+ import type { Rule } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../../types';
3
+ export declare function createFallbackPlaceholderReplacer(): (code: string) => string;
4
+ export declare function createFallbackPlaceholderCleaner(): (rule: Rule) => void;
5
+ export declare function createRootSpecificityCleaner(options: IStyleHandlerOptions): ((rule: Rule) => void) | undefined;
@@ -0,0 +1,6 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export type PostcssWeappTailwindcssRenamePlugin = PluginCreator<IStyleHandlerOptions>;
4
+ export { reorderVariableDeclarations } from './post/decl-dedupe';
5
+ declare const postcssWeappTailwindcssPostPlugin: PostcssWeappTailwindcssRenamePlugin;
6
+ export { postcssWeappTailwindcssPostPlugin };
@@ -0,0 +1,5 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export type PostcssWeappTailwindcssRenamePlugin = PluginCreator<IStyleHandlerOptions>;
4
+ declare const postcssWeappTailwindcssPrePlugin: PostcssWeappTailwindcssRenamePlugin;
5
+ export { postcssWeappTailwindcssPrePlugin };
@@ -0,0 +1,3 @@
1
+ import type { CssPreflightOptions, IPropValue } from './types';
2
+ export type InjectPreflight = () => IPropValue[];
3
+ export declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
@@ -0,0 +1,14 @@
1
+ export interface PresetEnvOptions {
2
+ stage?: false | 0 | 1 | 2 | 3 | 4;
3
+ minimumVendorImplementations?: number;
4
+ browsers?: string | string[];
5
+ features?: Record<string, boolean | Record<string, unknown>>;
6
+ insertBefore?: Record<string, unknown>;
7
+ insertAfter?: Record<string, unknown>;
8
+ debug?: boolean;
9
+ logical?: {
10
+ inlineDirection?: 'top-to-bottom' | 'bottom-to-top' | 'right-to-left' | 'left-to-right';
11
+ blockDirection?: 'top-to-bottom' | 'bottom-to-top' | 'right-to-left' | 'left-to-right';
12
+ };
13
+ [key: string]: unknown;
14
+ }
@@ -0,0 +1,18 @@
1
+ import type { ProcessOptions, Processor } from 'postcss';
2
+ import type { FeatureSignal } from './content-probe';
3
+ import type { StyleProcessingPipeline } from './pipeline';
4
+ import type { IStyleHandlerOptions } from './types';
5
+ export declare class StyleProcessorCache {
6
+ private readonly pipelineCacheByKey;
7
+ private readonly processOptionsCache;
8
+ private readonly processorCacheByKey;
9
+ private readonly processorKeyCache;
10
+ private createProcessorCacheKey;
11
+ /**
12
+ * 构建包含信号的复合缓存键
13
+ */
14
+ private createCompositeCacheKey;
15
+ getPipeline(options: IStyleHandlerOptions, signal?: FeatureSignal): StyleProcessingPipeline;
16
+ getProcessOptions(options: IStyleHandlerOptions): ProcessOptions;
17
+ getProcessor(options: IStyleHandlerOptions, signal?: FeatureSignal): Processor;
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { Rule } from 'postcss';
2
+ export declare function isOnlyBeforeAndAfterPseudoElement(node: Rule): boolean;
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ import psp from 'postcss-selector-parser';
4
+ /**
5
+ * 获取用于小程序兼容性处理的解析器,内部会缓存实例并移除不支持的选择器。
6
+ * 增加了选择器字符串级缓存,避免对相同选择器重复 parse。
7
+ * @returns 带清理规则的解析器实例。
8
+ */
9
+ export declare function getFallbackRemove(_rule?: Rule, options?: IStyleHandlerOptions): psp.Processor<unknown, psp.Selectors>;
@@ -0,0 +1,4 @@
1
+ import type { Rule } from 'postcss';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ export type RuleTransformer = (rule: Rule) => void;
4
+ export declare function ruleTransformSync(rule: Rule, options: IStyleHandlerOptions): void;
@@ -0,0 +1,6 @@
1
+ import type { Rule } from 'postcss';
2
+ import type { Node, Pseudo } from 'postcss-selector-parser';
3
+ import type { IStyleHandlerOptions } from '../types';
4
+ export declare function isNotLastChildPseudo(node?: Node | null): node is Pseudo;
5
+ export declare function transformSpacingSelector(nodes: Node[] | undefined, options: IStyleHandlerOptions): boolean;
6
+ export declare function normalizeSpacingDeclarations(rule: Rule): void;
@@ -0,0 +1,11 @@
1
+ import type { Node } from 'postcss-selector-parser';
2
+ import type { IStyleHandlerOptions } from '../types';
3
+ import psp from 'postcss-selector-parser';
4
+ export type ParserTransformOptions = Partial<{
5
+ lossless: boolean;
6
+ updateSelector: boolean;
7
+ }>;
8
+ export declare function normalizeTransformOptions(options?: ParserTransformOptions): ParserTransformOptions;
9
+ export declare function mklist(node: Node): Node[];
10
+ export declare function composeIsPseudoAst(strs: string | string[]): Node[];
11
+ export declare function getCombinatorSelectorAst(options: IStyleHandlerOptions): (psp.Pseudo | psp.Selector | psp.String | psp.Tag | psp.Root | psp.Nesting | psp.Identifier | psp.Comment | psp.Combinator | psp.ClassName | psp.Attribute | psp.Universal)[];
@@ -0,0 +1,4 @@
1
+ export { isOnlyBeforeAndAfterPseudoElement } from './selectorParser/before-after';
2
+ export { getFallbackRemove } from './selectorParser/fallback';
3
+ export { ruleTransformSync } from './selectorParser/rule-transformer';
4
+ export { composeIsPseudoAst, getCombinatorSelectorAst, mklist, } from './selectorParser/utils';
@@ -0,0 +1,3 @@
1
+ import type { InternalCssSelectorReplacerOptions } from './types';
2
+ export declare function internalCssSelectorReplacer(selectors: string, options?: InternalCssSelectorReplacerOptions): string;
3
+ export declare function composeIsPseudo(strs: string | string[]): string;
package/dist/types.d.ts CHANGED
@@ -1,8 +1,86 @@
1
- import '@weapp-tailwindcss/postcss-calc';
2
- import 'postcss';
3
- import 'postcss-load-config';
4
- export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
5
- export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
- export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
7
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UniAppXCssTarget, i as UniAppXUnsupportedMode, j as UserDefinedPostcssOptions, W as WeappAutoprefixerOptions } from './types-DJDvtI8K.js';
8
- import 'autoprefixer';
1
+ import type { PostCssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
2
+ import type { Result as PostcssResult } from 'postcss';
3
+ import type { Result } from 'postcss-load-config';
4
+ import type { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
5
+ import type { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
+ import type { GlobalUnitTransform, UserDefinedOptions as UnitConverterOptions, UnitMap } from 'postcss-rule-unit-converter';
7
+ import type { WeappAutoprefixerOptions } from './autoprefixer';
8
+ import type { StyleProcessingPipeline } from './pipeline';
9
+ import type { IContext as PostcssContext } from './plugins/ctx';
10
+ import type { InjectPreflight } from './preflight';
11
+ import type { PresetEnvOptions } from './preset-env-options';
12
+ export type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
13
+ export interface IPropValue {
14
+ prop: string;
15
+ value: string;
16
+ }
17
+ export type UniAppXCssTarget = 'uvue';
18
+ export type UniAppXUnsupportedMode = 'error' | 'warn' | 'silent';
19
+ export type CssPreflightOptions = {
20
+ [key: string]: string | number | boolean;
21
+ } | false;
22
+ export type RequiredStyleHandlerOptions = {
23
+ /**
24
+ * @description 默认为 true,此时会对样式主文件,进行猜测
25
+ */
26
+ isMainChunk?: boolean;
27
+ cssPreflight?: CssPreflightOptions;
28
+ cssInjectPreflight?: InjectPreflight;
29
+ escapeMap?: Record<string, string>;
30
+ } & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx' | 'px2rpx' | 'unitsToPx'>;
31
+ export interface InternalCssSelectorReplacerOptions {
32
+ escapeMap?: Record<string, string>;
33
+ }
34
+ interface CssCalcOptions extends PostCssCalcOptions {
35
+ includeCustomProperties?: (string | RegExp)[];
36
+ }
37
+ export interface UnitsToPxOptions extends Pick<UnitConverterOptions, 'disabled' | 'exclude' | 'mediaQuery' | 'propList' | 'replace' | 'selectorBlackList' | 'unitPrecision'> {
38
+ minValue?: number;
39
+ to?: string;
40
+ unitMap?: UnitMap;
41
+ transform?: GlobalUnitTransform | false;
42
+ }
43
+ export type IStyleHandlerOptions = {
44
+ ctx?: PostcssContext;
45
+ postcssOptions?: LoadedPostcssOptions;
46
+ cssRemoveProperty?: boolean;
47
+ cssRemoveHoverPseudoClass?: boolean;
48
+ cssPresetEnv?: PresetEnvOptions;
49
+ autoprefixer?: WeappAutoprefixerOptions;
50
+ cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
51
+ atRules?: {
52
+ property?: boolean;
53
+ supports?: boolean;
54
+ media?: boolean;
55
+ };
56
+ uniAppX?: boolean;
57
+ uniAppXCssTarget?: UniAppXCssTarget;
58
+ uniAppXUnsupported?: UniAppXUnsupportedMode;
59
+ majorVersion?: number;
60
+ } & RequiredStyleHandlerOptions;
61
+ export interface UserDefinedPostcssOptions {
62
+ cssPreflight?: CssPreflightOptions;
63
+ cssPreflightRange?: 'all';
64
+ cssChildCombinatorReplaceValue?: string | string[];
65
+ cssPresetEnv?: PresetEnvOptions;
66
+ autoprefixer?: WeappAutoprefixerOptions;
67
+ injectAdditionalCssVarScope?: boolean;
68
+ cssSelectorReplacement?: {
69
+ root?: string | string[] | false;
70
+ universal?: string | string[] | false;
71
+ };
72
+ rem2rpx?: boolean | Rem2rpxOptions;
73
+ px2rpx?: boolean | Px2rpxOptions;
74
+ unitsToPx?: boolean | UnitsToPxOptions;
75
+ postcssOptions?: LoadedPostcssOptions;
76
+ cssRemoveHoverPseudoClass?: boolean;
77
+ cssRemoveProperty?: boolean;
78
+ uniAppX?: boolean;
79
+ uniAppXCssTarget?: UniAppXCssTarget;
80
+ uniAppXUnsupported?: UniAppXUnsupportedMode;
81
+ }
82
+ export type { CssCalcOptions, PresetEnvOptions, Px2rpxOptions, Rem2rpxOptions, WeappAutoprefixerOptions, };
83
+ export interface StyleHandler {
84
+ (rawSource: string, opt?: Partial<IStyleHandlerOptions>): Promise<PostcssResult>;
85
+ getPipeline: (opt?: Partial<IStyleHandlerOptions>) => StyleProcessingPipeline;
86
+ }
package/dist/types.js CHANGED
@@ -1 +0,0 @@
1
- "use strict";require('./chunk-GGNOJ77I.js');
package/dist/types.mjs CHANGED
@@ -1 +1 @@
1
- import "./chunk-WAXGOBY2.mjs";
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Declaration } from 'postcss';
2
+ export interface CssVarDefinition {
3
+ prop: string;
4
+ value: string;
5
+ }
6
+ /**
7
+ * 将 CSS 变量定义转换为可直接插入的 Declaration 节点列表。
8
+ */
9
+ export declare function createCssVarNodes(definitions: CssVarDefinition[]): Declaration[];
@@ -0,0 +1,5 @@
1
+ import type { Declaration, Rule } from 'postcss';
2
+ /**
3
+ * 将同一规则内的声明重排,使字面量优先,带变量的声明靠后,保持各自相对顺序。
4
+ */
5
+ export declare function reorderLiteralFirst(rule: Rule, declarations: Declaration[], isVariable: (decl: Declaration) => boolean): void;
@@ -0,0 +1,8 @@
1
+ import type { Rule } from 'postcss';
2
+ interface SelectorMutationMeta {
3
+ phase: string;
4
+ reason: string;
5
+ }
6
+ export declare function assignRuleSelectors(rule: Rule, selectors: string[], meta: SelectorMutationMeta): boolean;
7
+ export declare function appendRuleSelector(rule: Rule, selector: string, meta: SelectorMutationMeta): boolean;
8
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Rule } from 'postcss';
2
+ /**
3
+ * 判断规则内是否包含一定数量的 Tailwind CSS 变量声明。
4
+ */
5
+ export declare function hasTwVars(rule: Rule, count?: number): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "2.2.0-next.0",
3
+ "version": "2.2.1-next.0",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -60,12 +60,12 @@
60
60
  "@weapp-tailwindcss/postcss-calc": "^1.0.0",
61
61
  "autoprefixer": "^10.5.0",
62
62
  "lru-cache": "10.4.3",
63
- "postcss": "^8.5.12",
63
+ "postcss": "^8.5.14",
64
64
  "postcss-preset-env": "^10.6.1",
65
65
  "postcss-pxtrans": "^1.0.4",
66
66
  "postcss-rem-to-responsive-pixel": "^7.0.4",
67
+ "postcss-rule-unit-converter": "^0.2.2",
67
68
  "postcss-selector-parser": "~7.1.1",
68
- "postcss-units-to-px": "^0.2.2",
69
69
  "postcss-value-parser": "^4.2.0",
70
70
  "@weapp-tailwindcss/shared": "1.1.3"
71
71
  },
@@ -76,8 +76,9 @@
76
76
  "postcss-custom-properties": "^14.0.6"
77
77
  },
78
78
  "scripts": {
79
- "dev": "tsup --watch --sourcemap",
80
- "build": "tsup",
79
+ "dev": "tsdown --watch --sourcemap",
80
+ "build": "tsdown && pnpm run build:types",
81
+ "build:types": "tsc -p tsconfig.build.json",
81
82
  "test": "vitest run",
82
83
  "bench": "vitest bench",
83
84
  "test:dev": "vitest",
@@ -1,64 +0,0 @@
1
- // src/html-transform.ts
2
- import process from "process";
3
- import { defu } from "@weapp-tailwindcss/shared";
4
- var htmlTags = ["html", "body", "a", "audio", "button", "canvas", "form", "iframe", "img", "input", "label", "progress", "select", "slot", "textarea", "video", "abbr", "area", "b", "bdi", "big", "br", "cite", "code", "data", "datalist", "del", "dfn", "em", "i", "ins", "kbd", "map", "mark", "meter", "output", "picture", "q", "s", "samp", "small", "span", "strong", "sub", "sup", "td", "template", "th", "time", "tt", "u", "var", "wbr", "address", "article", "aside", "blockquote", "caption", "dd", "details", "dialog", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "legend", "li", "main", "nav", "ol", "p", "pre", "section", "summary", "table", "tbody", "tfoot", "thead", "tr", "ul", "svg"];
5
- var miniAppTags = ["cover-image", "cover-view", "match-media", "movable-area", "movable-view", "page-container", "scroll-view", "share-element", "swiper", "swiper-item", "view", "icon", "progress", "rich-text", "text", "button", "checkbox", "checkbox-group", "editor", "form", "input", "keyboard-accessory", "label", "picker", "picker-view", "picker-view-column", "radio", "radio-group", "slider", "switch", "textarea", "functional-page-navigator", "navigator", "audio", "camera", "image", "live-player", "live-pusher", "video", "voip-room", "map", "canvas", "web-view", "ad", "ad-custom", "official-account", "open-data", "navigation-bar", "page-meta"];
6
- var tags2Rgx = (tags = []) => new RegExp(`(^| |\\+|,|~|>|\\n)(${tags.join("|")})\\b(?=$| |\\.|\\+|,|~|:|\\[)`, "g");
7
- var UNIVERSAL_SELECTOR_RE = /(?:^| )\*(?![=/*])/;
8
- var postcssHtmlTransform = (opts = {}) => {
9
- const options = defu(opts, {
10
- platform: process.env.TARO_ENV
11
- });
12
- let selectorFilter;
13
- let walkRules;
14
- switch (options.platform) {
15
- case "h5": {
16
- selectorFilter = tags2Rgx(miniAppTags);
17
- walkRules = (rule) => {
18
- rule.selector = rule.selector.replace(selectorFilter, "$1taro-$2-core");
19
- };
20
- break;
21
- }
22
- case "rn": {
23
- break;
24
- }
25
- case "quickapp": {
26
- break;
27
- }
28
- default: {
29
- const selector = tags2Rgx(htmlTags);
30
- walkRules = (rule) => {
31
- if (options.removeUniversal && UNIVERSAL_SELECTOR_RE.test(rule.selector)) {
32
- rule.remove();
33
- return;
34
- }
35
- rule.selector = rule.selector.replace(selector, "$1.h5-$2");
36
- };
37
- }
38
- }
39
- return {
40
- postcssPlugin: "postcss-html-transform",
41
- Rule(rule) {
42
- if (typeof walkRules === "function") {
43
- if (selectorFilter && selectorFilter.test(rule.selector)) {
44
- walkRules(rule);
45
- } else {
46
- walkRules(rule);
47
- }
48
- }
49
- },
50
- Declaration(decl) {
51
- if (options?.removeCursorStyle) {
52
- if (decl.prop === "cursor") {
53
- decl.remove();
54
- }
55
- }
56
- }
57
- };
58
- };
59
- postcssHtmlTransform.postcss = true;
60
- var html_transform_default = postcssHtmlTransform;
61
-
62
- export {
63
- html_transform_default
64
- };
@@ -1,64 +0,0 @@
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; }// src/html-transform.ts
2
- var _process = require('process'); var _process2 = _interopRequireDefault(_process);
3
- var _shared = require('@weapp-tailwindcss/shared');
4
- var htmlTags = ["html", "body", "a", "audio", "button", "canvas", "form", "iframe", "img", "input", "label", "progress", "select", "slot", "textarea", "video", "abbr", "area", "b", "bdi", "big", "br", "cite", "code", "data", "datalist", "del", "dfn", "em", "i", "ins", "kbd", "map", "mark", "meter", "output", "picture", "q", "s", "samp", "small", "span", "strong", "sub", "sup", "td", "template", "th", "time", "tt", "u", "var", "wbr", "address", "article", "aside", "blockquote", "caption", "dd", "details", "dialog", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "legend", "li", "main", "nav", "ol", "p", "pre", "section", "summary", "table", "tbody", "tfoot", "thead", "tr", "ul", "svg"];
5
- var miniAppTags = ["cover-image", "cover-view", "match-media", "movable-area", "movable-view", "page-container", "scroll-view", "share-element", "swiper", "swiper-item", "view", "icon", "progress", "rich-text", "text", "button", "checkbox", "checkbox-group", "editor", "form", "input", "keyboard-accessory", "label", "picker", "picker-view", "picker-view-column", "radio", "radio-group", "slider", "switch", "textarea", "functional-page-navigator", "navigator", "audio", "camera", "image", "live-player", "live-pusher", "video", "voip-room", "map", "canvas", "web-view", "ad", "ad-custom", "official-account", "open-data", "navigation-bar", "page-meta"];
6
- var tags2Rgx = (tags = []) => new RegExp(`(^| |\\+|,|~|>|\\n)(${tags.join("|")})\\b(?=$| |\\.|\\+|,|~|:|\\[)`, "g");
7
- var UNIVERSAL_SELECTOR_RE = /(?:^| )\*(?![=/*])/;
8
- var postcssHtmlTransform = (opts = {}) => {
9
- const options = _shared.defu.call(void 0, opts, {
10
- platform: _process2.default.env.TARO_ENV
11
- });
12
- let selectorFilter;
13
- let walkRules;
14
- switch (options.platform) {
15
- case "h5": {
16
- selectorFilter = tags2Rgx(miniAppTags);
17
- walkRules = (rule) => {
18
- rule.selector = rule.selector.replace(selectorFilter, "$1taro-$2-core");
19
- };
20
- break;
21
- }
22
- case "rn": {
23
- break;
24
- }
25
- case "quickapp": {
26
- break;
27
- }
28
- default: {
29
- const selector = tags2Rgx(htmlTags);
30
- walkRules = (rule) => {
31
- if (options.removeUniversal && UNIVERSAL_SELECTOR_RE.test(rule.selector)) {
32
- rule.remove();
33
- return;
34
- }
35
- rule.selector = rule.selector.replace(selector, "$1.h5-$2");
36
- };
37
- }
38
- }
39
- return {
40
- postcssPlugin: "postcss-html-transform",
41
- Rule(rule) {
42
- if (typeof walkRules === "function") {
43
- if (selectorFilter && selectorFilter.test(rule.selector)) {
44
- walkRules(rule);
45
- } else {
46
- walkRules(rule);
47
- }
48
- }
49
- },
50
- Declaration(decl) {
51
- if (_optionalChain([options, 'optionalAccess', _ => _.removeCursorStyle])) {
52
- if (decl.prop === "cursor") {
53
- decl.remove();
54
- }
55
- }
56
- }
57
- };
58
- };
59
- postcssHtmlTransform.postcss = true;
60
- var html_transform_default = postcssHtmlTransform;
61
-
62
-
63
-
64
- exports.html_transform_default = html_transform_default;
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1,13 +0,0 @@
1
- import { PluginCreator } from 'postcss';
2
-
3
- interface IOptions {
4
- /** 当前编译平台 */
5
- platform?: string;
6
- /** 设置是否去除 cursor 相关样式 (h5默认值:true) */
7
- removeCursorStyle?: boolean;
8
- /** 是否移除 * 相关样式 */
9
- removeUniversal?: boolean;
10
- }
11
- declare const postcssHtmlTransform: PluginCreator<IOptions>;
12
-
13
- export { type IOptions, postcssHtmlTransform as default };
package/dist/index.d.mts DELETED
@@ -1,18 +0,0 @@
1
- import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-DJDvtI8K.mjs';
2
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, L as LoadedPostcssOptions, P as PipelineNodeContext, d as PipelineNodeCursor, e as PipelineStage, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, g as ResolvedPipelineNode, h as StyleProcessingPipeline, U as UniAppXCssTarget, i as UniAppXUnsupportedMode, j as UserDefinedPostcssOptions, W as WeappAutoprefixerOptions, k as createInjectPreflight, l as createStylePipeline } from './types-DJDvtI8K.mjs';
3
- export { IOptions as PostcssHtmlTransformOptions, default as postcssHtmlTransform } from './html-transform.mjs';
4
- export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
5
- export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
- export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
7
- import '@weapp-tailwindcss/postcss-calc';
8
- import 'postcss';
9
- import 'postcss-load-config';
10
- import 'autoprefixer';
11
-
12
- declare function createStyleHandler(options?: Partial<IStyleHandlerOptions>): StyleHandler;
13
-
14
- declare function createFallbackPlaceholderReplacer(): (code: string) => string;
15
-
16
- declare function internalCssSelectorReplacer(selectors: string, options?: InternalCssSelectorReplacerOptions): string;
17
-
18
- export { IStyleHandlerOptions, InternalCssSelectorReplacerOptions, StyleHandler, createFallbackPlaceholderReplacer, createStyleHandler, internalCssSelectorReplacer };