update
This commit is contained in:
@@ -0,0 +1,273 @@
|
||||
import { U as UserConfig, P as Plugin } from './types-B254mqw1.mjs';
|
||||
import { V as Variant, C as Candidate } from './resolve-config-QUZ9b-Gn.mjs';
|
||||
import './colors.mjs';
|
||||
|
||||
declare const enum ThemeOptions {
|
||||
NONE = 0,
|
||||
INLINE = 1,
|
||||
REFERENCE = 2,
|
||||
DEFAULT = 4,
|
||||
STATIC = 8,
|
||||
USED = 16
|
||||
}
|
||||
declare class Theme {
|
||||
#private;
|
||||
private values;
|
||||
private keyframes;
|
||||
prefix: string | null;
|
||||
constructor(values?: Map<string, {
|
||||
value: string;
|
||||
options: ThemeOptions;
|
||||
}>, keyframes?: Set<AtRule>);
|
||||
add(key: string, value: string, options?: ThemeOptions): void;
|
||||
keysInNamespaces(themeKeys: Iterable<ThemeKey>): string[];
|
||||
get(themeKeys: ThemeKey[]): string | null;
|
||||
hasDefault(key: string): boolean;
|
||||
getOptions(key: string): ThemeOptions;
|
||||
entries(): IterableIterator<[string, {
|
||||
value: string;
|
||||
options: ThemeOptions;
|
||||
}]> | [string, {
|
||||
value: string;
|
||||
options: ThemeOptions;
|
||||
}][];
|
||||
prefixKey(key: string): string;
|
||||
clearNamespace(namespace: string, clearOptions: ThemeOptions): void;
|
||||
markUsedVariable(themeKey: string): boolean;
|
||||
resolve(candidateValue: string | null, themeKeys: ThemeKey[], options?: ThemeOptions): string | null;
|
||||
resolveValue(candidateValue: string | null, themeKeys: ThemeKey[]): string | null;
|
||||
resolveWith(candidateValue: string, themeKeys: ThemeKey[], nestedKeys?: `--${string}`[]): [string, Record<string, string>] | null;
|
||||
namespace(namespace: string): Map<string | null, string>;
|
||||
addKeyframes(value: AtRule): void;
|
||||
getKeyframes(): AtRule[];
|
||||
}
|
||||
type ThemeKey = `--${string}`;
|
||||
|
||||
type VariantFn<T extends Variant['kind']> = (rule: Rule, variant: Extract<Variant, {
|
||||
kind: T;
|
||||
}>) => null | void;
|
||||
type CompareFn = (a: Variant, z: Variant) => number;
|
||||
declare const enum Compounds {
|
||||
Never = 0,
|
||||
AtRules = 1,
|
||||
StyleRules = 2
|
||||
}
|
||||
declare class Variants {
|
||||
compareFns: Map<number, CompareFn>;
|
||||
variants: Map<string, {
|
||||
kind: Variant["kind"];
|
||||
order: number;
|
||||
applyFn: VariantFn<any>;
|
||||
compoundsWith: Compounds;
|
||||
compounds: Compounds;
|
||||
}>;
|
||||
private completions;
|
||||
/**
|
||||
* Registering a group of variants should result in the same sort number for
|
||||
* all the variants. This is to ensure that the variants are applied in the
|
||||
* correct order.
|
||||
*/
|
||||
private groupOrder;
|
||||
/**
|
||||
* Keep track of the last sort order instead of using the size of the map to
|
||||
* avoid unnecessarily skipping order numbers.
|
||||
*/
|
||||
private lastOrder;
|
||||
static(name: string, applyFn: VariantFn<'static'>, { compounds, order }?: {
|
||||
compounds?: Compounds;
|
||||
order?: number;
|
||||
}): void;
|
||||
fromAst(name: string, ast: AstNode[]): void;
|
||||
functional(name: string, applyFn: VariantFn<'functional'>, { compounds, order }?: {
|
||||
compounds?: Compounds;
|
||||
order?: number;
|
||||
}): void;
|
||||
compound(name: string, compoundsWith: Compounds, applyFn: VariantFn<'compound'>, { compounds, order }?: {
|
||||
compounds?: Compounds;
|
||||
order?: number;
|
||||
}): void;
|
||||
group(fn: () => void, compareFn?: CompareFn): void;
|
||||
has(name: string): boolean;
|
||||
get(name: string): {
|
||||
kind: Variant["kind"];
|
||||
order: number;
|
||||
applyFn: VariantFn<any>;
|
||||
compoundsWith: Compounds;
|
||||
compounds: Compounds;
|
||||
} | undefined;
|
||||
kind(name: string): "static" | "arbitrary" | "functional" | "compound";
|
||||
compoundsWith(parent: string, child: string | Variant): boolean;
|
||||
suggest(name: string, suggestions: () => string[]): void;
|
||||
getCompletions(name: string): string[];
|
||||
compare(a: Variant | null, z: Variant | null): number;
|
||||
keys(): IterableIterator<string>;
|
||||
entries(): IterableIterator<[string, {
|
||||
kind: Variant["kind"];
|
||||
order: number;
|
||||
applyFn: VariantFn<any>;
|
||||
compoundsWith: Compounds;
|
||||
compounds: Compounds;
|
||||
}]>;
|
||||
private set;
|
||||
private nextOrder;
|
||||
}
|
||||
|
||||
declare function compileAstNodes(candidate: Candidate, designSystem: DesignSystem): {
|
||||
node: AstNode;
|
||||
propertySort: {
|
||||
order: number[];
|
||||
count: number;
|
||||
};
|
||||
}[];
|
||||
|
||||
interface ClassMetadata {
|
||||
modifiers: string[];
|
||||
}
|
||||
type ClassEntry = [string, ClassMetadata];
|
||||
interface SelectorOptions {
|
||||
modifier?: string;
|
||||
value?: string;
|
||||
}
|
||||
interface VariantEntry {
|
||||
name: string;
|
||||
isArbitrary: boolean;
|
||||
values: string[];
|
||||
hasDash: boolean;
|
||||
selectors: (options: SelectorOptions) => string[];
|
||||
}
|
||||
|
||||
type CompileFn<T extends Candidate['kind']> = (value: Extract<Candidate, {
|
||||
kind: T;
|
||||
}>) => AstNode[] | undefined | null;
|
||||
interface SuggestionGroup {
|
||||
supportsNegative?: boolean;
|
||||
values: (string | null)[];
|
||||
modifiers: string[];
|
||||
}
|
||||
type UtilityOptions = {
|
||||
types: string[];
|
||||
};
|
||||
type Utility = {
|
||||
kind: 'static' | 'functional';
|
||||
compileFn: CompileFn<any>;
|
||||
options?: UtilityOptions;
|
||||
};
|
||||
declare class Utilities {
|
||||
private utilities;
|
||||
private completions;
|
||||
static(name: string, compileFn: CompileFn<'static'>): void;
|
||||
functional(name: string, compileFn: CompileFn<'functional'>, options?: UtilityOptions): void;
|
||||
has(name: string, kind: 'static' | 'functional'): boolean;
|
||||
get(name: string): Utility[];
|
||||
getCompletions(name: string): SuggestionGroup[];
|
||||
suggest(name: string, groups: () => SuggestionGroup[]): void;
|
||||
keys(kind: 'static' | 'functional'): string[];
|
||||
}
|
||||
|
||||
type DesignSystem = {
|
||||
theme: Theme;
|
||||
utilities: Utilities;
|
||||
variants: Variants;
|
||||
invalidCandidates: Set<string>;
|
||||
important: boolean;
|
||||
getClassOrder(classes: string[]): [string, bigint | null][];
|
||||
getClassList(): ClassEntry[];
|
||||
getVariants(): VariantEntry[];
|
||||
parseCandidate(candidate: string): Readonly<Candidate>[];
|
||||
parseVariant(variant: string): Readonly<Variant> | null;
|
||||
compileAstNodes(candidate: Candidate): ReturnType<typeof compileAstNodes>;
|
||||
getVariantOrder(): Map<Variant, number>;
|
||||
resolveThemeValue(path: string, forceInline?: boolean): string | undefined;
|
||||
trackUsedVariables(raw: string): void;
|
||||
candidatesToCss(classes: string[]): (string | null)[];
|
||||
};
|
||||
|
||||
type StyleRule = {
|
||||
kind: 'rule';
|
||||
selector: string;
|
||||
nodes: AstNode[];
|
||||
};
|
||||
type AtRule = {
|
||||
kind: 'at-rule';
|
||||
name: string;
|
||||
params: string;
|
||||
nodes: AstNode[];
|
||||
};
|
||||
type Declaration = {
|
||||
kind: 'declaration';
|
||||
property: string;
|
||||
value: string | undefined;
|
||||
important: boolean;
|
||||
};
|
||||
type Comment = {
|
||||
kind: 'comment';
|
||||
value: string;
|
||||
};
|
||||
type Context = {
|
||||
kind: 'context';
|
||||
context: Record<string, string | boolean>;
|
||||
nodes: AstNode[];
|
||||
};
|
||||
type AtRoot = {
|
||||
kind: 'at-root';
|
||||
nodes: AstNode[];
|
||||
};
|
||||
type Rule = StyleRule | AtRule;
|
||||
type AstNode = StyleRule | AtRule | Declaration | Comment | Context | AtRoot;
|
||||
|
||||
type Config = UserConfig;
|
||||
declare const enum Polyfills {
|
||||
None = 0,
|
||||
AtProperty = 1,
|
||||
ColorMix = 2,
|
||||
All = 3
|
||||
}
|
||||
type CompileOptions = {
|
||||
base?: string;
|
||||
polyfills?: Polyfills;
|
||||
loadModule?: (id: string, base: string, resourceHint: 'plugin' | 'config') => Promise<{
|
||||
module: Plugin | Config;
|
||||
base: string;
|
||||
}>;
|
||||
loadStylesheet?: (id: string, base: string) => Promise<{
|
||||
content: string;
|
||||
base: string;
|
||||
}>;
|
||||
};
|
||||
type Root = null | 'none' | {
|
||||
base: string;
|
||||
pattern: string;
|
||||
};
|
||||
declare const enum Features {
|
||||
None = 0,
|
||||
AtApply = 1,
|
||||
AtImport = 2,
|
||||
JsPluginCompat = 4,
|
||||
ThemeFunction = 8,
|
||||
Utilities = 16,
|
||||
Variants = 32
|
||||
}
|
||||
declare function compileAst(input: AstNode[], opts?: CompileOptions): Promise<{
|
||||
sources: {
|
||||
base: string;
|
||||
pattern: string;
|
||||
negated: boolean;
|
||||
}[];
|
||||
root: Root;
|
||||
features: Features;
|
||||
build(candidates: string[]): AstNode[];
|
||||
}>;
|
||||
declare function compile(css: string, opts?: CompileOptions): Promise<{
|
||||
sources: {
|
||||
base: string;
|
||||
pattern: string;
|
||||
negated: boolean;
|
||||
}[];
|
||||
root: Root;
|
||||
features: Features;
|
||||
build(candidates: string[]): string;
|
||||
}>;
|
||||
declare function __unstable__loadDesignSystem(css: string, opts?: CompileOptions): Promise<DesignSystem>;
|
||||
declare function postcssPluginWarning(): void;
|
||||
|
||||
export { type Config, Features, Polyfills, __unstable__loadDesignSystem, compile, compileAst, postcssPluginWarning as default };
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,IAAkB;IAC1C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE;YAC5B,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC/B;QACD,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACrB;SAAM;QACN,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;KACf;AACF,CAAC;AAED,MAAM,iBAAiB,GAAU;IAChC,OAAO,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;AAC1B,CAAC;AAED,MAAM,iBAAiB,CAAK;IAC3B,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACpJ,CAAC;AAED,MAAM,sBAAsB,GAAU;IACrC,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,kBAAkB,GAAO;IAC9B,OAAO,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvM,CAAC;AAGD,MAAM,iBAAiB,MAAc,EAAE,MAAW;IACjD,MAAM,GAAG,GAAG,MAAa,CAAC;IAC1B,IAAI,MAAM,EAAE;QACX,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;YACzB,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;SACvB;KACD;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"45":0.00362,"115":0.05423,"118":0.02169,"119":0.00362,"128":0.01085,"134":0.00362,"135":0.1193,"136":0.18075,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 116 117 120 121 122 123 124 125 126 127 129 130 131 132 133 137 138 139 140 3.5 3.6"},D:{"11":0.01085,"52":0.00723,"66":0.02169,"68":0.00723,"72":0.00723,"75":0.00362,"79":0.02169,"83":0.01085,"86":0.00362,"87":0.00362,"88":0.00362,"90":0.00362,"109":1.39901,"111":0.00723,"114":0.01808,"119":0.06869,"124":0.00362,"125":0.00362,"126":0.00723,"128":0.00362,"129":0.00362,"130":0.00362,"131":0.02169,"132":0.02531,"133":2.02079,"134":3.62946,_:"4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 53 54 55 56 57 58 59 60 61 62 63 64 65 67 69 70 71 73 74 76 77 78 80 81 84 85 89 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 110 112 113 115 116 117 118 120 121 122 123 127 135 136 137 138"},F:{"87":0.00362,"115":0.00362,"116":0.00723,"117":0.03977,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"12":0.00362,"16":0.00362,"17":0.01085,"18":0.00362,"90":0.00362,"91":0.01085,"92":0.07592,"100":0.00362,"109":0.01446,"119":0.55671,"120":0.00362,"124":0.02169,"127":0.54225,"128":0.29643,"129":0.00723,"130":0.15545,"131":0.57479,"132":0.54225,"133":6.76005,"134":15.56258,_:"13 14 15 79 80 81 83 84 85 86 87 88 89 93 94 95 96 97 98 99 101 102 103 104 105 106 107 108 110 111 112 113 114 115 116 117 118 121 122 123 125 126"},E:{_:"0 4 5 6 7 8 9 10 11 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 14.1 15.1 15.2-15.3 15.4 15.5 16.0 16.1 16.2 16.3 16.4 16.5 17.1 17.2 17.3 18.4","11.1":0.00362,"12.1":0.01446,"13.1":0.00723,"15.6":0.00362,"16.6":0.01446,"17.0":0.00362,"17.4":0.01808,"17.5":0.00723,"17.6":0.01085,"18.0":0.00362,"18.1":0.00362,"18.2":0.00362,"18.3":0.01808},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00221,"5.0-5.1":0,"6.0-6.1":0.00663,"7.0-7.1":0.00442,"8.1-8.4":0,"9.0-9.2":0.00332,"9.3":0.01547,"10.0-10.2":0.00111,"10.3":0.02542,"11.0-11.2":0.11716,"11.3-11.4":0.00774,"12.0-12.1":0.00442,"12.2-12.5":0.10942,"13.0-13.1":0.00221,"13.2":0.00332,"13.3":0.00442,"13.4-13.7":0.01547,"14.0-14.4":0.03868,"14.5-14.8":0.04642,"15.0-15.1":0.02542,"15.2-15.3":0.02542,"15.4":0.03095,"15.5":0.03537,"15.6-15.8":0.43547,"16.0":0.06189,"16.1":0.1271,"16.2":0.06631,"16.3":0.11495,"16.4":0.02542,"16.5":0.04753,"16.6-16.7":0.51615,"17.0":0.03095,"17.1":0.05526,"17.2":0.042,"17.3":0.05858,"17.4":0.11716,"17.5":0.26084,"17.6-17.7":0.75709,"18.0":0.21221,"18.1":0.69409,"18.2":0.31057,"18.3":6.4911,"18.4":0.09616},P:{"4":0.03058,"21":0.1631,"22":0.01019,"23":0.01019,"24":0.01019,"25":0.08155,"26":0.02039,"27":0.23445,_:"20 6.2-6.4 7.2-7.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0","5.0-5.4":0.02039},I:{"0":0.08283,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00002,"4.4":0,"4.4.3-4.4.4":0.00009},K:{"0":0.2554,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{"2.5":0.66404,_:"3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.01277},Q:{_:"14.9"},O:{"0":0.03831},H:{"0":0},L:{"0":53.44505}};
|
||||
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env node
|
||||
// Standalone semver comparison program.
|
||||
// Exits successfully and prints matching version(s) if
|
||||
// any supplied version is valid and passes all tests.
|
||||
|
||||
var argv = process.argv.slice(2)
|
||||
|
||||
var versions = []
|
||||
|
||||
var range = []
|
||||
|
||||
var inc = null
|
||||
|
||||
var version = require('../package.json').version
|
||||
|
||||
var loose = false
|
||||
|
||||
var includePrerelease = false
|
||||
|
||||
var coerce = false
|
||||
|
||||
var rtl = false
|
||||
|
||||
var identifier
|
||||
|
||||
var semver = require('../semver')
|
||||
|
||||
var reverse = false
|
||||
|
||||
var options = {}
|
||||
|
||||
main()
|
||||
|
||||
function main () {
|
||||
if (!argv.length) return help()
|
||||
while (argv.length) {
|
||||
var a = argv.shift()
|
||||
var indexOfEqualSign = a.indexOf('=')
|
||||
if (indexOfEqualSign !== -1) {
|
||||
a = a.slice(0, indexOfEqualSign)
|
||||
argv.unshift(a.slice(indexOfEqualSign + 1))
|
||||
}
|
||||
switch (a) {
|
||||
case '-rv': case '-rev': case '--rev': case '--reverse':
|
||||
reverse = true
|
||||
break
|
||||
case '-l': case '--loose':
|
||||
loose = true
|
||||
break
|
||||
case '-p': case '--include-prerelease':
|
||||
includePrerelease = true
|
||||
break
|
||||
case '-v': case '--version':
|
||||
versions.push(argv.shift())
|
||||
break
|
||||
case '-i': case '--inc': case '--increment':
|
||||
switch (argv[0]) {
|
||||
case 'major': case 'minor': case 'patch': case 'prerelease':
|
||||
case 'premajor': case 'preminor': case 'prepatch':
|
||||
inc = argv.shift()
|
||||
break
|
||||
default:
|
||||
inc = 'patch'
|
||||
break
|
||||
}
|
||||
break
|
||||
case '--preid':
|
||||
identifier = argv.shift()
|
||||
break
|
||||
case '-r': case '--range':
|
||||
range.push(argv.shift())
|
||||
break
|
||||
case '-c': case '--coerce':
|
||||
coerce = true
|
||||
break
|
||||
case '--rtl':
|
||||
rtl = true
|
||||
break
|
||||
case '--ltr':
|
||||
rtl = false
|
||||
break
|
||||
case '-h': case '--help': case '-?':
|
||||
return help()
|
||||
default:
|
||||
versions.push(a)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
|
||||
|
||||
versions = versions.map(function (v) {
|
||||
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
|
||||
}).filter(function (v) {
|
||||
return semver.valid(v)
|
||||
})
|
||||
if (!versions.length) return fail()
|
||||
if (inc && (versions.length !== 1 || range.length)) { return failInc() }
|
||||
|
||||
for (var i = 0, l = range.length; i < l; i++) {
|
||||
versions = versions.filter(function (v) {
|
||||
return semver.satisfies(v, range[i], options)
|
||||
})
|
||||
if (!versions.length) return fail()
|
||||
}
|
||||
return success(versions)
|
||||
}
|
||||
|
||||
function failInc () {
|
||||
console.error('--inc can only be used on a single version with no range')
|
||||
fail()
|
||||
}
|
||||
|
||||
function fail () { process.exit(1) }
|
||||
|
||||
function success () {
|
||||
var compare = reverse ? 'rcompare' : 'compare'
|
||||
versions.sort(function (a, b) {
|
||||
return semver[compare](a, b, options)
|
||||
}).map(function (v) {
|
||||
return semver.clean(v, options)
|
||||
}).map(function (v) {
|
||||
return inc ? semver.inc(v, inc, options, identifier) : v
|
||||
}).forEach(function (v, i, _) { console.log(v) })
|
||||
}
|
||||
|
||||
function help () {
|
||||
console.log(['SemVer ' + version,
|
||||
'',
|
||||
'A JavaScript implementation of the https://semver.org/ specification',
|
||||
'Copyright Isaac Z. Schlueter',
|
||||
'',
|
||||
'Usage: semver [options] <version> [<version> [...]]',
|
||||
'Prints valid versions sorted by SemVer precedence',
|
||||
'',
|
||||
'Options:',
|
||||
'-r --range <range>',
|
||||
' Print versions that match the specified range.',
|
||||
'',
|
||||
'-i --increment [<level>]',
|
||||
' Increment a version by the specified level. Level can',
|
||||
' be one of: major, minor, patch, premajor, preminor,',
|
||||
" prepatch, or prerelease. Default level is 'patch'.",
|
||||
' Only one version may be specified.',
|
||||
'',
|
||||
'--preid <identifier>',
|
||||
' Identifier to be used to prefix premajor, preminor,',
|
||||
' prepatch or prerelease version increments.',
|
||||
'',
|
||||
'-l --loose',
|
||||
' Interpret versions and ranges loosely',
|
||||
'',
|
||||
'-p --include-prerelease',
|
||||
' Always include prerelease versions in range matching',
|
||||
'',
|
||||
'-c --coerce',
|
||||
' Coerce a string into SemVer if possible',
|
||||
' (does not imply --loose)',
|
||||
'',
|
||||
'--rtl',
|
||||
' Coerce version strings right to left',
|
||||
'',
|
||||
'--ltr',
|
||||
' Coerce version strings left to right (default)',
|
||||
'',
|
||||
'Program exits successfully if any valid version satisfies',
|
||||
'all supplied ranges, and prints all satisfying versions.',
|
||||
'',
|
||||
'If no satisfying versions are found, then exits failure.',
|
||||
'',
|
||||
'Versions are printed in ascending order, so supplying',
|
||||
'multiple versions to the utility will just sort them.'
|
||||
].join('\n'))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F mC","6308":"A","6436":"B"},B:{"1":"0 9 Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","6436":"C L M G N O P"},C:{"1":"0 9 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","2":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB qC rC","2052":"cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B"},D:{"1":"0 9 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","2":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B","8258":"1B 2B 3B"},E:{"1":"B C L M G FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","2":"J PB K D E sC SC tC uC vC","3108":"F A wC TC"},F:{"1":"0 zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","2":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB 4C 5C 6C 7C FC kC 8C GC","8258":"rB sB tB uB vB wB xB yB"},G:{"1":"ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","2":"E SC 9C lC AD BD CD DD","3108":"ED FD GD HD"},H:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"2":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 TC iD jD kD lD mD IC JC KC nD","2":"J dD eD fD gD hD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"rD","2052":"qD"}},B:4,C:"CSS Scroll Snap",D:true};
|
||||
@@ -0,0 +1,38 @@
|
||||
import { MatchLocation } from './RouterProvider.cjs';
|
||||
import { AnyPathParams } from './route.cjs';
|
||||
export interface Segment {
|
||||
type: 'pathname' | 'param' | 'wildcard';
|
||||
value: string;
|
||||
}
|
||||
export declare function joinPaths(paths: Array<string | undefined>): string;
|
||||
export declare function cleanPath(path: string): string;
|
||||
export declare function trimPathLeft(path: string): string;
|
||||
export declare function trimPathRight(path: string): string;
|
||||
export declare function trimPath(path: string): string;
|
||||
export declare function removeTrailingSlash(value: string, basepath: string): string;
|
||||
export declare function exactPathTest(pathName1: string, pathName2: string, basepath: string): boolean;
|
||||
interface ResolvePathOptions {
|
||||
basepath: string;
|
||||
base: string;
|
||||
to: string;
|
||||
trailingSlash?: 'always' | 'never' | 'preserve';
|
||||
caseSensitive?: boolean;
|
||||
}
|
||||
export declare function resolvePath({ basepath, base, to, trailingSlash, caseSensitive, }: ResolvePathOptions): string;
|
||||
export declare function parsePathname(pathname?: string): Array<Segment>;
|
||||
interface InterpolatePathOptions {
|
||||
path?: string;
|
||||
params: Record<string, unknown>;
|
||||
leaveWildcards?: boolean;
|
||||
leaveParams?: boolean;
|
||||
decodeCharMap?: Map<string, string>;
|
||||
}
|
||||
type InterPolatePathResult = {
|
||||
interpolatedPath: string;
|
||||
usedParams: Record<string, unknown>;
|
||||
};
|
||||
export declare function interpolatePath({ path, params, leaveWildcards, leaveParams, decodeCharMap, }: InterpolatePathOptions): InterPolatePathResult;
|
||||
export declare function matchPathname(basepath: string, currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
|
||||
export declare function removeBasepath(basepath: string, pathname: string, caseSensitive?: boolean): string;
|
||||
export declare function matchByPath(basepath: string, from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
|
||||
export {};
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* These are types for things that are present in the `experimental` builds of React but not yet
|
||||
* on a stable build.
|
||||
*
|
||||
* Once they are promoted to stable they can just be moved to the main index file.
|
||||
*
|
||||
* To load the types declared here in an actual project, there are three ways. The easiest one,
|
||||
* if your `tsconfig.json` already has a `"types"` array in the `"compilerOptions"` section,
|
||||
* is to add `"react-dom/experimental"` to the `"types"` array.
|
||||
*
|
||||
* Alternatively, a specific import syntax can to be used from a typescript file.
|
||||
* This module does not exist in reality, which is why the {} is important:
|
||||
*
|
||||
* ```ts
|
||||
* import {} from 'react-dom/experimental'
|
||||
* ```
|
||||
*
|
||||
* It is also possible to include it through a triple-slash reference:
|
||||
*
|
||||
* ```ts
|
||||
* /// <reference types="react-dom/experimental" />
|
||||
* ```
|
||||
*
|
||||
* Either the import or the reference only needs to appear once, anywhere in the project.
|
||||
*/
|
||||
|
||||
// See https://github.com/facebook/react/blob/main/packages/react-dom/index.experimental.js to see how the exports are declared,
|
||||
// but confirm with published source code (e.g. https://unpkg.com/react-dom@experimental) that these exports end up in the published code
|
||||
|
||||
import React = require("react");
|
||||
import ReactDOM = require("./canary");
|
||||
|
||||
export {};
|
||||
|
||||
declare module "." {
|
||||
}
|
||||
|
||||
declare module "react" {
|
||||
interface ViewTransitionPseudoElement extends Animatable {
|
||||
getComputedStyle: () => CSSStyleDeclaration;
|
||||
}
|
||||
|
||||
interface ViewTransitionInstance {
|
||||
group: ViewTransitionPseudoElement;
|
||||
imagePair: ViewTransitionPseudoElement;
|
||||
old: ViewTransitionPseudoElement;
|
||||
new: ViewTransitionPseudoElement;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface GestureProvider extends AnimationTimeline {}
|
||||
|
||||
// @enableFragmentRefs
|
||||
interface FragmentInstance {
|
||||
blur: () => void;
|
||||
focus: (focusOptions?: FocusOptions | undefined) => void;
|
||||
focusLast: (focusOptions?: FocusOptions | undefined) => void;
|
||||
observeUsing(observer: IntersectionObserver | ResizeObserver): void;
|
||||
unobserveUsing(observer: IntersectionObserver | ResizeObserver): void;
|
||||
getClientRects(): Array<DOMRect>;
|
||||
getRootNode(getRootNodeOptions?: GetRootNodeOptions | undefined): Document | ShadowRoot | FragmentInstance;
|
||||
addEventListener(
|
||||
type: string,
|
||||
listener: EventListener,
|
||||
optionsOrUseCapture?: Parameters<Element["addEventListener"]>[2],
|
||||
): void;
|
||||
removeEventListener(
|
||||
type: string,
|
||||
listener: EventListener,
|
||||
optionsOrUseCapture?: Parameters<Element["removeEventListener"]>[2],
|
||||
): void;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { AnyRouter, RegisteredRouter, UseRouteContextBaseOptions, UseRouteContextOptions, UseRouteContextResult } from '@tanstack/router-core';
|
||||
export type UseRouteContextRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown>(opts?: UseRouteContextBaseOptions<TRouter, TFrom, true, TSelected>) => UseRouteContextResult<TRouter, TFrom, true, TSelected>;
|
||||
export declare function useRouteContext<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TSelected = unknown>(opts: UseRouteContextOptions<TRouter, TFrom, TStrict, TSelected>): UseRouteContextResult<TRouter, TFrom, TStrict, TSelected>;
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = isScope;
|
||||
var _index = require("./generated/index.js");
|
||||
function isScope(node, parent) {
|
||||
if ((0, _index.isBlockStatement)(node) && ((0, _index.isFunction)(parent) || (0, _index.isCatchClause)(parent))) {
|
||||
return false;
|
||||
}
|
||||
if ((0, _index.isPattern)(node) && ((0, _index.isFunction)(parent) || (0, _index.isCatchClause)(parent))) {
|
||||
return true;
|
||||
}
|
||||
return (0, _index.isScopable)(node);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=isScope.js.map
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getInclusionReasons = getInclusionReasons;
|
||||
var _semver = require("semver");
|
||||
var _pretty = require("./pretty.js");
|
||||
var _utils = require("./utils.js");
|
||||
function getInclusionReasons(item, targetVersions, list) {
|
||||
const minVersions = list[item] || {};
|
||||
return Object.keys(targetVersions).reduce((result, env) => {
|
||||
const minVersion = (0, _utils.getLowestImplementedVersion)(minVersions, env);
|
||||
const targetVersion = targetVersions[env];
|
||||
if (!minVersion) {
|
||||
result[env] = (0, _pretty.prettifyVersion)(targetVersion);
|
||||
} else {
|
||||
const minIsUnreleased = (0, _utils.isUnreleasedVersion)(minVersion, env);
|
||||
const targetIsUnreleased = (0, _utils.isUnreleasedVersion)(targetVersion, env);
|
||||
if (!targetIsUnreleased && (minIsUnreleased || _semver.lt(targetVersion.toString(), (0, _utils.semverify)(minVersion)))) {
|
||||
result[env] = (0, _pretty.prettifyVersion)(targetVersion);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=debug.js.map
|
||||
@@ -0,0 +1,662 @@
|
||||
/**
|
||||
* @fileoverview Main CLI object.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
* NOTE: The CLI object should *not* call process.exit() directly. It should only return
|
||||
* exit codes. This allows other programs to use the CLI object and still control
|
||||
* when the program exits.
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const fs = require("node:fs"),
|
||||
path = require("node:path"),
|
||||
{ promisify } = require("node:util"),
|
||||
{ LegacyESLint } = require("./eslint"),
|
||||
{
|
||||
ESLint,
|
||||
shouldUseFlatConfig,
|
||||
locateConfigFileToUse,
|
||||
} = require("./eslint/eslint"),
|
||||
createCLIOptions = require("./options"),
|
||||
log = require("./shared/logging"),
|
||||
RuntimeInfo = require("./shared/runtime-info"),
|
||||
{ normalizeSeverityToString } = require("./shared/severity");
|
||||
const {
|
||||
Legacy: { naming },
|
||||
} = require("@eslint/eslintrc");
|
||||
const { ModuleImporter } = require("@humanwhocodes/module-importer");
|
||||
const debug = require("debug")("eslint:cli");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("./eslint/eslint").ESLintOptions} ESLintOptions */
|
||||
/** @typedef {import("./eslint/eslint").LintMessage} LintMessage */
|
||||
/** @typedef {import("./eslint/eslint").LintResult} LintResult */
|
||||
/** @typedef {import("./options").ParsedCLIOptions} ParsedCLIOptions */
|
||||
/** @typedef {import("./shared/types").Plugin} Plugin */
|
||||
/** @typedef {import("./shared/types").ResultsMeta} ResultsMeta */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const mkdir = promisify(fs.mkdir);
|
||||
const stat = promisify(fs.stat);
|
||||
const writeFile = promisify(fs.writeFile);
|
||||
|
||||
/**
|
||||
* Loads plugins with the specified names.
|
||||
* @param {{ "import": (name: string) => Promise<any> }} importer An object with an `import` method called once for each plugin.
|
||||
* @param {string[]} pluginNames The names of the plugins to be loaded, with or without the "eslint-plugin-" prefix.
|
||||
* @returns {Promise<Record<string, Plugin>>} A mapping of plugin short names to implementations.
|
||||
*/
|
||||
async function loadPlugins(importer, pluginNames) {
|
||||
const plugins = {};
|
||||
|
||||
await Promise.all(
|
||||
pluginNames.map(async pluginName => {
|
||||
const longName = naming.normalizePackageName(
|
||||
pluginName,
|
||||
"eslint-plugin",
|
||||
);
|
||||
const module = await importer.import(longName);
|
||||
|
||||
if (!("default" in module)) {
|
||||
throw new Error(
|
||||
`"${longName}" cannot be used with the \`--plugin\` option because its default module does not provide a \`default\` export`,
|
||||
);
|
||||
}
|
||||
|
||||
const shortName = naming.getShorthandName(
|
||||
pluginName,
|
||||
"eslint-plugin",
|
||||
);
|
||||
|
||||
plugins[shortName] = module.default;
|
||||
}),
|
||||
);
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Predicate function for whether or not to apply fixes in quiet mode.
|
||||
* If a message is a warning, do not apply a fix.
|
||||
* @param {LintMessage} message The lint result.
|
||||
* @returns {boolean} True if the lint message is an error (and thus should be
|
||||
* autofixed), false otherwise.
|
||||
*/
|
||||
function quietFixPredicate(message) {
|
||||
return message.severity === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Predicate function for whether or not to run a rule in quiet mode.
|
||||
* If a rule is set to warning, do not run it.
|
||||
* @param {{ ruleId: string; severity: number; }} rule The rule id and severity.
|
||||
* @returns {boolean} True if the lint rule should run, false otherwise.
|
||||
*/
|
||||
function quietRuleFilter(rule) {
|
||||
return rule.severity === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the CLI options into the options expected by the ESLint constructor.
|
||||
* @param {ParsedCLIOptions} cliOptions The CLI options to translate.
|
||||
* @param {"flat"|"eslintrc"} [configType="eslintrc"] The format of the
|
||||
* config to generate.
|
||||
* @returns {Promise<ESLintOptions>} The options object for the ESLint constructor.
|
||||
* @private
|
||||
*/
|
||||
async function translateOptions(
|
||||
{
|
||||
cache,
|
||||
cacheFile,
|
||||
cacheLocation,
|
||||
cacheStrategy,
|
||||
config,
|
||||
configLookup,
|
||||
env,
|
||||
errorOnUnmatchedPattern,
|
||||
eslintrc,
|
||||
ext,
|
||||
fix,
|
||||
fixDryRun,
|
||||
fixType,
|
||||
flag,
|
||||
global,
|
||||
ignore,
|
||||
ignorePath,
|
||||
ignorePattern,
|
||||
inlineConfig,
|
||||
parser,
|
||||
parserOptions,
|
||||
plugin,
|
||||
quiet,
|
||||
reportUnusedDisableDirectives,
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
reportUnusedInlineConfigs,
|
||||
resolvePluginsRelativeTo,
|
||||
rule,
|
||||
rulesdir,
|
||||
stats,
|
||||
warnIgnored,
|
||||
passOnNoPatterns,
|
||||
maxWarnings,
|
||||
},
|
||||
configType,
|
||||
) {
|
||||
let overrideConfig, overrideConfigFile;
|
||||
const importer = new ModuleImporter();
|
||||
|
||||
if (configType === "flat") {
|
||||
overrideConfigFile =
|
||||
typeof config === "string" ? config : !configLookup;
|
||||
if (overrideConfigFile === false) {
|
||||
overrideConfigFile = void 0;
|
||||
}
|
||||
|
||||
const languageOptions = {};
|
||||
|
||||
if (global) {
|
||||
languageOptions.globals = global.reduce((obj, name) => {
|
||||
if (name.endsWith(":true")) {
|
||||
obj[name.slice(0, -5)] = "writable";
|
||||
} else {
|
||||
obj[name] = "readonly";
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (parserOptions) {
|
||||
languageOptions.parserOptions = parserOptions;
|
||||
}
|
||||
|
||||
if (parser) {
|
||||
languageOptions.parser = await importer.import(parser);
|
||||
}
|
||||
|
||||
overrideConfig = [
|
||||
{
|
||||
...(Object.keys(languageOptions).length > 0
|
||||
? { languageOptions }
|
||||
: {}),
|
||||
rules: rule ? rule : {},
|
||||
},
|
||||
];
|
||||
|
||||
if (
|
||||
reportUnusedDisableDirectives ||
|
||||
reportUnusedDisableDirectivesSeverity !== void 0
|
||||
) {
|
||||
overrideConfig[0].linterOptions = {
|
||||
reportUnusedDisableDirectives: reportUnusedDisableDirectives
|
||||
? "error"
|
||||
: normalizeSeverityToString(
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (reportUnusedInlineConfigs !== void 0) {
|
||||
overrideConfig[0].linterOptions = {
|
||||
...overrideConfig[0].linterOptions,
|
||||
reportUnusedInlineConfigs: normalizeSeverityToString(
|
||||
reportUnusedInlineConfigs,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (plugin) {
|
||||
overrideConfig[0].plugins = await loadPlugins(importer, plugin);
|
||||
}
|
||||
|
||||
if (ext) {
|
||||
overrideConfig.push({
|
||||
files: ext.map(
|
||||
extension =>
|
||||
`**/*${extension.startsWith(".") ? "" : "."}${extension}`,
|
||||
),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
overrideConfigFile = config;
|
||||
|
||||
overrideConfig = {
|
||||
env:
|
||||
env &&
|
||||
env.reduce((obj, name) => {
|
||||
obj[name] = true;
|
||||
return obj;
|
||||
}, {}),
|
||||
globals:
|
||||
global &&
|
||||
global.reduce((obj, name) => {
|
||||
if (name.endsWith(":true")) {
|
||||
obj[name.slice(0, -5)] = "writable";
|
||||
} else {
|
||||
obj[name] = "readonly";
|
||||
}
|
||||
return obj;
|
||||
}, {}),
|
||||
ignorePatterns: ignorePattern,
|
||||
parser,
|
||||
parserOptions,
|
||||
plugins: plugin,
|
||||
rules: rule,
|
||||
};
|
||||
}
|
||||
|
||||
const options = {
|
||||
allowInlineConfig: inlineConfig,
|
||||
cache,
|
||||
cacheLocation: cacheLocation || cacheFile,
|
||||
cacheStrategy,
|
||||
errorOnUnmatchedPattern,
|
||||
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
|
||||
fixTypes: fixType,
|
||||
ignore,
|
||||
overrideConfig,
|
||||
overrideConfigFile,
|
||||
passOnNoPatterns,
|
||||
};
|
||||
|
||||
if (configType === "flat") {
|
||||
options.ignorePatterns = ignorePattern;
|
||||
options.stats = stats;
|
||||
options.warnIgnored = warnIgnored;
|
||||
options.flags = flag;
|
||||
|
||||
/*
|
||||
* For performance reasons rules not marked as 'error' are filtered out in quiet mode. As maxWarnings
|
||||
* requires rules set to 'warn' to be run, we only filter out 'warn' rules if maxWarnings is not specified.
|
||||
*/
|
||||
options.ruleFilter =
|
||||
quiet && maxWarnings === -1 ? quietRuleFilter : () => true;
|
||||
} else {
|
||||
options.resolvePluginsRelativeTo = resolvePluginsRelativeTo;
|
||||
options.rulePaths = rulesdir;
|
||||
options.useEslintrc = eslintrc;
|
||||
options.extensions = ext;
|
||||
options.ignorePath = ignorePath;
|
||||
if (
|
||||
reportUnusedDisableDirectives ||
|
||||
reportUnusedDisableDirectivesSeverity !== void 0
|
||||
) {
|
||||
options.reportUnusedDisableDirectives =
|
||||
reportUnusedDisableDirectives
|
||||
? "error"
|
||||
: normalizeSeverityToString(
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count error messages.
|
||||
* @param {LintResult[]} results The lint results.
|
||||
* @returns {{errorCount:number;fatalErrorCount:number,warningCount:number}} The number of error messages.
|
||||
*/
|
||||
function countErrors(results) {
|
||||
let errorCount = 0;
|
||||
let fatalErrorCount = 0;
|
||||
let warningCount = 0;
|
||||
|
||||
for (const result of results) {
|
||||
errorCount += result.errorCount;
|
||||
fatalErrorCount += result.fatalErrorCount;
|
||||
warningCount += result.warningCount;
|
||||
}
|
||||
|
||||
return { errorCount, fatalErrorCount, warningCount };
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given file path is a directory or not.
|
||||
* @param {string} filePath The path to a file to check.
|
||||
* @returns {Promise<boolean>} `true` if the given path is a directory.
|
||||
*/
|
||||
async function isDirectory(filePath) {
|
||||
try {
|
||||
return (await stat(filePath)).isDirectory();
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the results of the linting.
|
||||
* @param {ESLint} engine The ESLint instance to use.
|
||||
* @param {LintResult[]} results The results to print.
|
||||
* @param {string} format The name of the formatter to use or the path to the formatter.
|
||||
* @param {string} outputFile The path for the output file.
|
||||
* @param {ResultsMeta} resultsMeta Warning count and max threshold.
|
||||
* @returns {Promise<boolean>} True if the printing succeeds, false if not.
|
||||
* @private
|
||||
*/
|
||||
async function printResults(engine, results, format, outputFile, resultsMeta) {
|
||||
let formatter;
|
||||
|
||||
try {
|
||||
formatter = await engine.loadFormatter(format);
|
||||
} catch (e) {
|
||||
log.error(e.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
const output = await formatter.format(results, resultsMeta);
|
||||
|
||||
if (outputFile) {
|
||||
const filePath = path.resolve(process.cwd(), outputFile);
|
||||
|
||||
if (await isDirectory(filePath)) {
|
||||
log.error(
|
||||
"Cannot write to output file path, it is a directory: %s",
|
||||
outputFile,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await mkdir(path.dirname(filePath), { recursive: true });
|
||||
await writeFile(filePath, output);
|
||||
} catch (ex) {
|
||||
log.error("There was a problem writing the output file:\n%s", ex);
|
||||
return false;
|
||||
}
|
||||
} else if (output) {
|
||||
log.info(output);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Encapsulates all CLI behavior for eslint. Makes it easier to test as well as
|
||||
* for other Node.js programs to effectively run the CLI.
|
||||
*/
|
||||
const cli = {
|
||||
/**
|
||||
* Calculates the command string for the --inspect-config operation.
|
||||
* @param {string} configFile The path to the config file to inspect.
|
||||
* @returns {Promise<string>} The command string to execute.
|
||||
*/
|
||||
async calculateInspectConfigFlags(configFile) {
|
||||
// find the config file
|
||||
const { configFilePath, basePath } = await locateConfigFileToUse({
|
||||
cwd: process.cwd(),
|
||||
configFile,
|
||||
});
|
||||
|
||||
return ["--config", configFilePath, "--basePath", basePath];
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes the CLI based on an array of arguments that is passed in.
|
||||
* @param {string|Array|Object} args The arguments to process.
|
||||
* @param {string} [text] The text to lint (used for TTY).
|
||||
* @param {boolean} [allowFlatConfig=true] Whether or not to allow flat config.
|
||||
* @returns {Promise<number>} The exit code for the operation.
|
||||
*/
|
||||
async execute(args, text, allowFlatConfig = true) {
|
||||
if (Array.isArray(args)) {
|
||||
debug("CLI args: %o", args.slice(2));
|
||||
}
|
||||
|
||||
/*
|
||||
* Before doing anything, we need to see if we are using a
|
||||
* flat config file. If so, then we need to change the way command
|
||||
* line args are parsed. This is temporary, and when we fully
|
||||
* switch to flat config we can remove this logic.
|
||||
*/
|
||||
|
||||
const usingFlatConfig =
|
||||
allowFlatConfig && (await shouldUseFlatConfig());
|
||||
|
||||
debug("Using flat config?", usingFlatConfig);
|
||||
|
||||
if (allowFlatConfig && !usingFlatConfig) {
|
||||
process.emitWarning(
|
||||
"You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https://eslint.org/docs/latest/use/configure/migration-guide for details. An eslintrc configuration file is used because you have the ESLINT_USE_FLAT_CONFIG environment variable set to false. If you want to use an eslint.config.js file, remove the environment variable. If you want to find the location of the eslintrc configuration file, use the --debug flag.",
|
||||
"ESLintRCWarning",
|
||||
);
|
||||
}
|
||||
|
||||
const CLIOptions = createCLIOptions(usingFlatConfig);
|
||||
|
||||
/** @type {ParsedCLIOptions} */
|
||||
let options;
|
||||
|
||||
try {
|
||||
options = CLIOptions.parse(args);
|
||||
} catch (error) {
|
||||
debug("Error parsing CLI options:", error.message);
|
||||
|
||||
let errorMessage = error.message;
|
||||
|
||||
if (usingFlatConfig) {
|
||||
errorMessage +=
|
||||
"\nYou're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.";
|
||||
}
|
||||
|
||||
log.error(errorMessage);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const files = options._;
|
||||
const useStdin = typeof text === "string";
|
||||
|
||||
if (options.help) {
|
||||
log.info(CLIOptions.generateHelp());
|
||||
return 0;
|
||||
}
|
||||
if (options.version) {
|
||||
log.info(RuntimeInfo.version());
|
||||
return 0;
|
||||
}
|
||||
if (options.envInfo) {
|
||||
try {
|
||||
log.info(RuntimeInfo.environment());
|
||||
return 0;
|
||||
} catch (err) {
|
||||
debug("Error retrieving environment info");
|
||||
log.error(err.message);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.printConfig) {
|
||||
if (files.length) {
|
||||
log.error(
|
||||
"The --print-config option must be used with exactly one file name.",
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
if (useStdin) {
|
||||
log.error(
|
||||
"The --print-config option is not available for piped-in code.",
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const engine = usingFlatConfig
|
||||
? new ESLint(await translateOptions(options, "flat"))
|
||||
: new LegacyESLint(await translateOptions(options));
|
||||
const fileConfig = await engine.calculateConfigForFile(
|
||||
options.printConfig,
|
||||
);
|
||||
|
||||
log.info(JSON.stringify(fileConfig, null, " "));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (options.inspectConfig) {
|
||||
log.info(
|
||||
"You can also run this command directly using 'npx @eslint/config-inspector@latest' in the same directory as your configuration file.",
|
||||
);
|
||||
|
||||
try {
|
||||
const flatOptions = await translateOptions(options, "flat");
|
||||
const spawn = require("cross-spawn");
|
||||
const flags = await cli.calculateInspectConfigFlags(
|
||||
flatOptions.overrideConfigFile,
|
||||
);
|
||||
|
||||
spawn.sync(
|
||||
"npx",
|
||||
["@eslint/config-inspector@latest", ...flags],
|
||||
{ encoding: "utf8", stdio: "inherit" },
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug(`Running on ${useStdin ? "text" : "files"}`);
|
||||
|
||||
if (options.fix && options.fixDryRun) {
|
||||
log.error(
|
||||
"The --fix option and the --fix-dry-run option cannot be used together.",
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
if (useStdin && options.fix) {
|
||||
log.error(
|
||||
"The --fix option is not available for piped-in code; use --fix-dry-run instead.",
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
if (options.fixType && !options.fix && !options.fixDryRun) {
|
||||
log.error(
|
||||
"The --fix-type option requires either --fix or --fix-dry-run.",
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (
|
||||
options.reportUnusedDisableDirectives &&
|
||||
options.reportUnusedDisableDirectivesSeverity !== void 0
|
||||
) {
|
||||
log.error(
|
||||
"The --report-unused-disable-directives option and the --report-unused-disable-directives-severity option cannot be used together.",
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (usingFlatConfig && options.ext) {
|
||||
// Passing `--ext ""` results in `options.ext` being an empty array.
|
||||
if (options.ext.length === 0) {
|
||||
log.error("The --ext option value cannot be empty.");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Passing `--ext ,ts` results in an empty string at index 0. Passing `--ext ts,,tsx` results in an empty string at index 1.
|
||||
const emptyStringIndex = options.ext.indexOf("");
|
||||
|
||||
if (emptyStringIndex >= 0) {
|
||||
log.error(
|
||||
`The --ext option arguments cannot be empty strings. Found an empty string at index ${emptyStringIndex}.`,
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
const ActiveESLint = usingFlatConfig ? ESLint : LegacyESLint;
|
||||
const eslintOptions = await translateOptions(
|
||||
options,
|
||||
usingFlatConfig ? "flat" : "eslintrc",
|
||||
);
|
||||
const engine = new ActiveESLint(eslintOptions);
|
||||
let results;
|
||||
|
||||
if (useStdin) {
|
||||
results = await engine.lintText(text, {
|
||||
filePath: options.stdinFilename,
|
||||
|
||||
// flatConfig respects CLI flag and constructor warnIgnored, eslintrc forces true for backwards compatibility
|
||||
warnIgnored: usingFlatConfig ? void 0 : true,
|
||||
});
|
||||
} else {
|
||||
results = await engine.lintFiles(files);
|
||||
}
|
||||
|
||||
if (options.fix) {
|
||||
debug("Fix mode enabled - applying fixes");
|
||||
await ActiveESLint.outputFixes(results);
|
||||
}
|
||||
|
||||
let resultsToPrint = results;
|
||||
|
||||
if (options.quiet) {
|
||||
debug("Quiet mode enabled - filtering out warnings");
|
||||
resultsToPrint = ActiveESLint.getErrorResults(resultsToPrint);
|
||||
}
|
||||
|
||||
const resultCounts = countErrors(results);
|
||||
const tooManyWarnings =
|
||||
options.maxWarnings >= 0 &&
|
||||
resultCounts.warningCount > options.maxWarnings;
|
||||
const resultsMeta = tooManyWarnings
|
||||
? {
|
||||
maxWarningsExceeded: {
|
||||
maxWarnings: options.maxWarnings,
|
||||
foundWarnings: resultCounts.warningCount,
|
||||
},
|
||||
}
|
||||
: {};
|
||||
|
||||
if (
|
||||
await printResults(
|
||||
engine,
|
||||
resultsToPrint,
|
||||
options.format,
|
||||
options.outputFile,
|
||||
resultsMeta,
|
||||
)
|
||||
) {
|
||||
// Errors and warnings from the original unfiltered results should determine the exit code
|
||||
const shouldExitForFatalErrors =
|
||||
options.exitOnFatalError && resultCounts.fatalErrorCount > 0;
|
||||
|
||||
if (!resultCounts.errorCount && tooManyWarnings) {
|
||||
log.error(
|
||||
"ESLint found too many warnings (maximum: %s).",
|
||||
options.maxWarnings,
|
||||
);
|
||||
}
|
||||
|
||||
if (shouldExitForFatalErrors) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return resultCounts.errorCount || tooManyWarnings ? 1 : 0;
|
||||
}
|
||||
|
||||
return 2;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = cli;
|
||||
@@ -0,0 +1,117 @@
|
||||
{
|
||||
"name": "react-dom",
|
||||
"version": "19.1.0",
|
||||
"description": "React package for working with the DOM.",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/facebook/react.git",
|
||||
"directory": "packages/react-dom"
|
||||
},
|
||||
"keywords": [
|
||||
"react"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/facebook/react/issues"
|
||||
},
|
||||
"homepage": "https://react.dev/",
|
||||
"dependencies": {
|
||||
"scheduler": "^0.26.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.1.0"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"client.js",
|
||||
"client.react-server.js",
|
||||
"index.js",
|
||||
"profiling.js",
|
||||
"profiling.react-server.js",
|
||||
"react-dom.react-server.js",
|
||||
"server.browser.js",
|
||||
"server.bun.js",
|
||||
"server.edge.js",
|
||||
"server.js",
|
||||
"server.node.js",
|
||||
"server.react-server.js",
|
||||
"static.browser.js",
|
||||
"static.edge.js",
|
||||
"static.js",
|
||||
"static.node.js",
|
||||
"static.react-server.js",
|
||||
"test-utils.js",
|
||||
"cjs/"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"react-server": "./react-dom.react-server.js",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./client": {
|
||||
"react-server": "./client.react-server.js",
|
||||
"default": "./client.js"
|
||||
},
|
||||
"./server": {
|
||||
"react-server": "./server.react-server.js",
|
||||
"workerd": "./server.edge.js",
|
||||
"bun": "./server.bun.js",
|
||||
"deno": "./server.browser.js",
|
||||
"worker": "./server.browser.js",
|
||||
"node": "./server.node.js",
|
||||
"edge-light": "./server.edge.js",
|
||||
"browser": "./server.browser.js",
|
||||
"default": "./server.node.js"
|
||||
},
|
||||
"./server.browser": {
|
||||
"react-server": "./server.react-server.js",
|
||||
"default": "./server.browser.js"
|
||||
},
|
||||
"./server.bun": {
|
||||
"react-server": "./server.react-server.js",
|
||||
"default": "./server.bun.js"
|
||||
},
|
||||
"./server.edge": {
|
||||
"react-server": "./server.react-server.js",
|
||||
"default": "./server.edge.js"
|
||||
},
|
||||
"./server.node": {
|
||||
"react-server": "./server.react-server.js",
|
||||
"default": "./server.node.js"
|
||||
},
|
||||
"./static": {
|
||||
"react-server": "./static.react-server.js",
|
||||
"workerd": "./static.edge.js",
|
||||
"deno": "./static.browser.js",
|
||||
"worker": "./static.browser.js",
|
||||
"node": "./static.node.js",
|
||||
"edge-light": "./static.edge.js",
|
||||
"browser": "./static.browser.js",
|
||||
"default": "./static.node.js"
|
||||
},
|
||||
"./static.browser": {
|
||||
"react-server": "./static.react-server.js",
|
||||
"default": "./static.browser.js"
|
||||
},
|
||||
"./static.edge": {
|
||||
"react-server": "./static.react-server.js",
|
||||
"default": "./static.edge.js"
|
||||
},
|
||||
"./static.node": {
|
||||
"react-server": "./static.react-server.js",
|
||||
"default": "./static.node.js"
|
||||
},
|
||||
"./profiling": {
|
||||
"react-server": "./profiling.react-server.js",
|
||||
"default": "./profiling.js"
|
||||
},
|
||||
"./test-utils": "./test-utils.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"browser": {
|
||||
"./server.js": "./server.browser.js",
|
||||
"./static.js": "./static.browser.js"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_superPropBase","require","_defineProperty","set","target","property","value","receiver","Reflect","base","superPropBase","desc","Object","getOwnPropertyDescriptor","call","writable","defineProperty","_set","isStrict","s","TypeError"],"sources":["../../src/helpers/set.ts"],"sourcesContent":["/* @minVersion 7.0.0-beta.0 */\n\nimport superPropBase from \"./superPropBase.ts\";\nimport defineProperty from \"./defineProperty.ts\";\n\nfunction set(\n target: object,\n property: PropertyKey,\n value: any,\n receiver?: any,\n): boolean {\n if (typeof Reflect !== \"undefined\" && Reflect.set) {\n // @ts-expect-error explicit function reassign\n set = Reflect.set;\n } else {\n // @ts-expect-error explicit function reassign\n set = function set(target, property, value, receiver) {\n var base = superPropBase(target, property);\n var desc;\n\n if (base) {\n desc = Object.getOwnPropertyDescriptor(base, property)!;\n if (desc.set) {\n desc.set.call(receiver, value);\n return true;\n // so getOwnPropertyDescriptor should always be defined\n } else if (!desc.writable) {\n // Both getter and non-writable fall into this.\n return false;\n }\n }\n\n // Without a super that defines the property, spec boils down to\n // \"define on receiver\" for some reason.\n desc = Object.getOwnPropertyDescriptor(receiver, property);\n if (desc) {\n if (!desc.writable) {\n // Setter, getter, and non-writable fall into this.\n return false;\n }\n\n desc.value = value;\n Object.defineProperty(receiver, property, desc);\n } else {\n // Avoid setters that may be defined on Sub's prototype, but not on\n // the instance.\n defineProperty(receiver, property, value);\n }\n\n return true;\n };\n }\n\n return set(target, property, value, receiver);\n}\n\nexport default function _set(\n target: object,\n property: PropertyKey,\n value: any,\n receiver?: any,\n isStrict?: boolean,\n) {\n var s = set(target, property, value, receiver || target);\n if (!s && isStrict) {\n throw new TypeError(\"failed to set property\");\n }\n\n return value;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,SAASE,GAAGA,CACVC,MAAc,EACdC,QAAqB,EACrBC,KAAU,EACVC,QAAc,EACL;EACT,IAAI,OAAOC,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACL,GAAG,EAAE;IAEjDA,GAAG,GAAGK,OAAO,CAACL,GAAG;EACnB,CAAC,MAAM;IAELA,GAAG,GAAG,SAASA,GAAGA,CAACC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAE;MACpD,IAAIE,IAAI,GAAG,IAAAC,sBAAa,EAACN,MAAM,EAAEC,QAAQ,CAAC;MAC1C,IAAIM,IAAI;MAER,IAAIF,IAAI,EAAE;QACRE,IAAI,GAAGC,MAAM,CAACC,wBAAwB,CAACJ,IAAI,EAAEJ,QAAQ,CAAE;QACvD,IAAIM,IAAI,CAACR,GAAG,EAAE;UACZQ,IAAI,CAACR,GAAG,CAACW,IAAI,CAACP,QAAQ,EAAED,KAAK,CAAC;UAC9B,OAAO,IAAI;QAEb,CAAC,MAAM,IAAI,CAACK,IAAI,CAACI,QAAQ,EAAE;UAEzB,OAAO,KAAK;QACd;MACF;MAIAJ,IAAI,GAAGC,MAAM,CAACC,wBAAwB,CAACN,QAAQ,EAAEF,QAAQ,CAAC;MAC1D,IAAIM,IAAI,EAAE;QACR,IAAI,CAACA,IAAI,CAACI,QAAQ,EAAE;UAElB,OAAO,KAAK;QACd;QAEAJ,IAAI,CAACL,KAAK,GAAGA,KAAK;QAClBM,MAAM,CAACI,cAAc,CAACT,QAAQ,EAAEF,QAAQ,EAAEM,IAAI,CAAC;MACjD,CAAC,MAAM;QAGL,IAAAK,uBAAc,EAACT,QAAQ,EAAEF,QAAQ,EAAEC,KAAK,CAAC;MAC3C;MAEA,OAAO,IAAI;IACb,CAAC;EACH;EAEA,OAAOH,GAAG,CAACC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,CAAC;AAC/C;AAEe,SAASU,IAAIA,CAC1Bb,MAAc,EACdC,QAAqB,EACrBC,KAAU,EACVC,QAAc,EACdW,QAAkB,EAClB;EACA,IAAIC,CAAC,GAAGhB,GAAG,CAACC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,IAAIH,MAAM,CAAC;EACxD,IAAI,CAACe,CAAC,IAAID,QAAQ,EAAE;IAClB,MAAM,IAAIE,SAAS,CAAC,wBAAwB,CAAC;EAC/C;EAEA,OAAOd,KAAK;AACd","ignoreList":[]}
|
||||
@@ -0,0 +1 @@
|
||||
exports.download = require('./download')
|
||||
@@ -0,0 +1,168 @@
|
||||
'use client';
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
|
||||
import makeCancellable from 'make-cancellable-promise';
|
||||
import clsx from 'clsx';
|
||||
import invariant from 'tiny-invariant';
|
||||
import warning from 'warning';
|
||||
import * as pdfjs from 'pdfjs-dist';
|
||||
import usePageContext from '../shared/hooks/usePageContext.js';
|
||||
import useResolver from '../shared/hooks/useResolver.js';
|
||||
import { cancelRunningTask } from '../shared/utils.js';
|
||||
function isTextItem(item) {
|
||||
return 'str' in item;
|
||||
}
|
||||
export default function TextLayer() {
|
||||
const pageContext = usePageContext();
|
||||
invariant(pageContext, 'Unable to find Page context.');
|
||||
const { customTextRenderer, onGetTextError, onGetTextSuccess, onRenderTextLayerError, onRenderTextLayerSuccess, page, pageIndex, pageNumber, rotate, scale, } = pageContext;
|
||||
invariant(page, 'Attempted to load page text content, but no page was specified.');
|
||||
const [textContentState, textContentDispatch] = useResolver();
|
||||
const { value: textContent, error: textContentError } = textContentState;
|
||||
const layerElement = useRef(null);
|
||||
warning(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue('--react-pdf-text-layer'), 10) === 1, 'TextLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-text-layer');
|
||||
/**
|
||||
* Called when a page text content is read successfully
|
||||
*/
|
||||
function onLoadSuccess() {
|
||||
if (!textContent) {
|
||||
// Impossible, but TypeScript doesn't know that
|
||||
return;
|
||||
}
|
||||
if (onGetTextSuccess) {
|
||||
onGetTextSuccess(textContent);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Called when a page text content failed to read successfully
|
||||
*/
|
||||
function onLoadError() {
|
||||
if (!textContentError) {
|
||||
// Impossible, but TypeScript doesn't know that
|
||||
return;
|
||||
}
|
||||
warning(false, textContentError.toString());
|
||||
if (onGetTextError) {
|
||||
onGetTextError(textContentError);
|
||||
}
|
||||
}
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: useEffect intentionally triggered on page change
|
||||
useEffect(function resetTextContent() {
|
||||
textContentDispatch({ type: 'RESET' });
|
||||
}, [page, textContentDispatch]);
|
||||
useEffect(function loadTextContent() {
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
const cancellable = makeCancellable(page.getTextContent());
|
||||
const runningTask = cancellable;
|
||||
cancellable.promise
|
||||
.then((nextTextContent) => {
|
||||
textContentDispatch({ type: 'RESOLVE', value: nextTextContent });
|
||||
})
|
||||
.catch((error) => {
|
||||
textContentDispatch({ type: 'REJECT', error });
|
||||
});
|
||||
return () => cancelRunningTask(runningTask);
|
||||
}, [page, textContentDispatch]);
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: Ommitted callbacks so they are not called every time they change
|
||||
useEffect(() => {
|
||||
if (textContent === undefined) {
|
||||
return;
|
||||
}
|
||||
if (textContent === false) {
|
||||
onLoadError();
|
||||
return;
|
||||
}
|
||||
onLoadSuccess();
|
||||
}, [textContent]);
|
||||
/**
|
||||
* Called when a text layer is rendered successfully
|
||||
*/
|
||||
const onRenderSuccess = useCallback(() => {
|
||||
if (onRenderTextLayerSuccess) {
|
||||
onRenderTextLayerSuccess();
|
||||
}
|
||||
}, [onRenderTextLayerSuccess]);
|
||||
/**
|
||||
* Called when a text layer failed to render successfully
|
||||
*/
|
||||
const onRenderError = useCallback((error) => {
|
||||
warning(false, error.toString());
|
||||
if (onRenderTextLayerError) {
|
||||
onRenderTextLayerError(error);
|
||||
}
|
||||
}, [onRenderTextLayerError]);
|
||||
function onMouseDown() {
|
||||
const layer = layerElement.current;
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
layer.classList.add('selecting');
|
||||
}
|
||||
function onMouseUp() {
|
||||
const layer = layerElement.current;
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
layer.classList.remove('selecting');
|
||||
}
|
||||
const viewport = useMemo(() => page.getViewport({ scale, rotation: rotate }), [page, rotate, scale]);
|
||||
useLayoutEffect(function renderTextLayer() {
|
||||
if (!page || !textContent) {
|
||||
return;
|
||||
}
|
||||
const { current: layer } = layerElement;
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
layer.innerHTML = '';
|
||||
const textContentSource = page.streamTextContent({ includeMarkedContent: true });
|
||||
const parameters = {
|
||||
container: layer,
|
||||
textContentSource,
|
||||
viewport,
|
||||
};
|
||||
const cancellable = new pdfjs.TextLayer(parameters);
|
||||
const runningTask = cancellable;
|
||||
cancellable
|
||||
.render()
|
||||
.then(() => {
|
||||
const end = document.createElement('div');
|
||||
end.className = 'endOfContent';
|
||||
layer.append(end);
|
||||
const layerChildren = layer.querySelectorAll('[role="presentation"]');
|
||||
if (customTextRenderer) {
|
||||
let index = 0;
|
||||
textContent.items.forEach((item, itemIndex) => {
|
||||
if (!isTextItem(item)) {
|
||||
return;
|
||||
}
|
||||
const child = layerChildren[index];
|
||||
if (!child) {
|
||||
return;
|
||||
}
|
||||
const content = customTextRenderer(Object.assign({ pageIndex,
|
||||
pageNumber,
|
||||
itemIndex }, item));
|
||||
child.innerHTML = content;
|
||||
index += item.str && item.hasEOL ? 2 : 1;
|
||||
});
|
||||
}
|
||||
// Intentional immediate callback
|
||||
onRenderSuccess();
|
||||
})
|
||||
.catch(onRenderError);
|
||||
return () => cancelRunningTask(runningTask);
|
||||
}, [
|
||||
customTextRenderer,
|
||||
onRenderError,
|
||||
onRenderSuccess,
|
||||
page,
|
||||
pageIndex,
|
||||
pageNumber,
|
||||
textContent,
|
||||
viewport,
|
||||
]);
|
||||
return (_jsx("div", { className: clsx('react-pdf__Page__textContent', 'textLayer'), onMouseUp: onMouseUp, onMouseDown: onMouseDown, ref: layerElement }));
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,63 @@
|
||||
|
||||
var test = require('tape')
|
||||
var _JSON = require('../')
|
||||
|
||||
function clone (o) {
|
||||
return JSON.parse(JSON.stringify(o))
|
||||
}
|
||||
|
||||
var examples = {
|
||||
simple: { foo: [], bar: {}, baz: Buffer.from('some binary data') },
|
||||
just_buffer: Buffer.from('JUST A BUFFER'),
|
||||
all_types: {
|
||||
string:'hello',
|
||||
number: 3145,
|
||||
null: null,
|
||||
object: {},
|
||||
array: [],
|
||||
boolean: true,
|
||||
boolean2: false
|
||||
},
|
||||
foo: Buffer.from('foo'),
|
||||
foo2: Buffer.from('foo2'),
|
||||
escape: {
|
||||
buffer: Buffer.from('x'),
|
||||
string: _JSON.stringify(Buffer.from('x'))
|
||||
},
|
||||
escape2: {
|
||||
buffer: Buffer.from('x'),
|
||||
string: ':base64:'+ Buffer.from('x').toString('base64')
|
||||
},
|
||||
undefined: {
|
||||
empty: undefined, test: true
|
||||
},
|
||||
undefined2: {
|
||||
first: 1, empty: undefined, test: true
|
||||
},
|
||||
undefinedArray: {
|
||||
array: [undefined, 1, 'two']
|
||||
},
|
||||
fn: {
|
||||
fn: function () {}
|
||||
},
|
||||
undefined: undefined
|
||||
}
|
||||
|
||||
for(k in examples)
|
||||
(function (value, k) {
|
||||
test(k, function (t) {
|
||||
var s = _JSON.stringify(value)
|
||||
console.log('parse', s)
|
||||
if(JSON.stringify(value) !== undefined) {
|
||||
console.log(s)
|
||||
var _value = _JSON.parse(s)
|
||||
t.deepEqual(clone(_value), clone(value))
|
||||
}
|
||||
else
|
||||
t.equal(s, undefined)
|
||||
t.end()
|
||||
})
|
||||
})(examples[k], k)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// This alphabet uses `A-Za-z0-9_-` symbols.
|
||||
// The order of characters is optimized for better gzip and brotli compression.
|
||||
// Same as in non-secure/index.js
|
||||
let urlAlphabet =
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||
|
||||
module.exports = { urlAlphabet }
|
||||
@@ -0,0 +1,567 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @fileoverview defineConfig helper
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Type Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("eslint").Linter.Config} Config */
|
||||
/** @typedef {import("eslint").Linter.LegacyConfig} LegacyConfig */
|
||||
/** @typedef {import("eslint").ESLint.Plugin} Plugin */
|
||||
/** @typedef {import("eslint").Linter.RuleEntry} RuleEntry */
|
||||
/** @typedef {import("./types.ts").ExtendsElement} ExtendsElement */
|
||||
/** @typedef {import("./types.ts").SimpleExtendsElement} SimpleExtendsElement */
|
||||
/** @typedef {import("./types.ts").ConfigWithExtends} ConfigWithExtends */
|
||||
/** @typedef {import("./types.ts").InfiniteArray<Config>} InfiniteConfigArray */
|
||||
/** @typedef {import("./types.ts").ConfigWithExtendsArray} ConfigWithExtendsArray */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const eslintrcKeys = [
|
||||
"env",
|
||||
"extends",
|
||||
"globals",
|
||||
"ignorePatterns",
|
||||
"noInlineConfig",
|
||||
"overrides",
|
||||
"parser",
|
||||
"parserOptions",
|
||||
"reportUnusedDisableDirectives",
|
||||
"root",
|
||||
];
|
||||
|
||||
const allowedGlobalIgnoreKeys = new Set(["ignores", "name"]);
|
||||
|
||||
/**
|
||||
* Gets the name of a config object.
|
||||
* @param {Config} config The config object.
|
||||
* @param {string} indexPath The index path of the config object.
|
||||
* @return {string} The name of the config object.
|
||||
*/
|
||||
function getConfigName(config, indexPath) {
|
||||
if (config.name) {
|
||||
return config.name;
|
||||
}
|
||||
|
||||
return `UserConfig${indexPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of an extension.
|
||||
* @param {SimpleExtendsElement} extension The extension.
|
||||
* @param {string} indexPath The index of the extension.
|
||||
* @return {string} The name of the extension.
|
||||
*/
|
||||
function getExtensionName(extension, indexPath) {
|
||||
if (typeof extension === "string") {
|
||||
return extension;
|
||||
}
|
||||
|
||||
if (extension.name) {
|
||||
return extension.name;
|
||||
}
|
||||
|
||||
return `ExtendedConfig${indexPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a config object is a legacy config.
|
||||
* @param {Config|LegacyConfig} config The config object to check.
|
||||
* @return {config is LegacyConfig} `true` if the config object is a legacy config.
|
||||
*/
|
||||
function isLegacyConfig(config) {
|
||||
for (const key of eslintrcKeys) {
|
||||
if (key in config) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a config object is a global ignores config.
|
||||
* @param {Config} config The config object to check.
|
||||
* @return {boolean} `true` if the config object is a global ignores config.
|
||||
*/
|
||||
function isGlobalIgnores(config) {
|
||||
return Object.keys(config).every(key => allowedGlobalIgnoreKeys.has(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a plugin member ID (rule, processor, etc.) and returns
|
||||
* the namespace and member name.
|
||||
* @param {string} id The ID to parse.
|
||||
* @returns {{namespace:string, name:string}} The namespace and member name.
|
||||
*/
|
||||
function getPluginMember(id) {
|
||||
const firstSlashIndex = id.indexOf("/");
|
||||
|
||||
if (firstSlashIndex === -1) {
|
||||
return { namespace: "", name: id };
|
||||
}
|
||||
|
||||
let namespace = id.slice(0, firstSlashIndex);
|
||||
|
||||
/*
|
||||
* Special cases:
|
||||
* 1. The namespace is `@`, that means it's referring to the
|
||||
* core plugin so `@` is the full namespace.
|
||||
* 2. The namespace starts with `@`, that means it's referring to
|
||||
* an npm scoped package. That means the namespace is the scope
|
||||
* and the package name (i.e., `@eslint/core`).
|
||||
*/
|
||||
if (namespace[0] === "@" && namespace !== "@") {
|
||||
const secondSlashIndex = id.indexOf("/", firstSlashIndex + 1);
|
||||
if (secondSlashIndex !== -1) {
|
||||
namespace = id.slice(0, secondSlashIndex);
|
||||
return { namespace, name: id.slice(secondSlashIndex + 1) };
|
||||
}
|
||||
}
|
||||
|
||||
const name = id.slice(firstSlashIndex + 1);
|
||||
|
||||
return { namespace, name };
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the plugin config by replacing the namespace with the plugin namespace.
|
||||
* @param {string} userNamespace The namespace of the plugin.
|
||||
* @param {Plugin} plugin The plugin config object.
|
||||
* @param {Config} config The config object to normalize.
|
||||
* @return {Config} The normalized config object.
|
||||
*/
|
||||
function normalizePluginConfig(userNamespace, plugin, config) {
|
||||
// @ts-ignore -- ESLint types aren't updated yet
|
||||
const pluginNamespace = plugin.meta?.namespace;
|
||||
|
||||
// don't do anything if the plugin doesn't have a namespace or rules
|
||||
if (
|
||||
!pluginNamespace ||
|
||||
pluginNamespace === userNamespace ||
|
||||
(!config.rules && !config.processor && !config.language)
|
||||
) {
|
||||
return config;
|
||||
}
|
||||
|
||||
const result = { ...config };
|
||||
|
||||
// update the rules
|
||||
if (result.rules) {
|
||||
const ruleIds = Object.keys(result.rules);
|
||||
|
||||
/** @type {Record<string,RuleEntry|undefined>} */
|
||||
const newRules = {};
|
||||
|
||||
for (let i = 0; i < ruleIds.length; i++) {
|
||||
const ruleId = ruleIds[i];
|
||||
const { namespace: ruleNamespace, name: ruleName } =
|
||||
getPluginMember(ruleId);
|
||||
|
||||
if (ruleNamespace === pluginNamespace) {
|
||||
newRules[`${userNamespace}/${ruleName}`] = result.rules[ruleId];
|
||||
} else {
|
||||
newRules[ruleId] = result.rules[ruleId];
|
||||
}
|
||||
}
|
||||
|
||||
result.rules = newRules;
|
||||
}
|
||||
|
||||
// update the processor
|
||||
|
||||
if (typeof result.processor === "string") {
|
||||
const { namespace: processorNamespace, name: processorName } =
|
||||
getPluginMember(result.processor);
|
||||
|
||||
if (processorNamespace) {
|
||||
if (processorNamespace === pluginNamespace) {
|
||||
result.processor = `${userNamespace}/${processorName}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the language
|
||||
if (typeof result.language === "string") {
|
||||
const { namespace: languageNamespace, name: languageName } =
|
||||
getPluginMember(result.language);
|
||||
|
||||
if (languageNamespace === pluginNamespace) {
|
||||
result.language = `${userNamespace}/${languageName}`;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deeply normalizes a plugin config, traversing recursively into an arrays.
|
||||
* @param {string} userPluginNamespace The namespace of the plugin.
|
||||
* @param {Plugin} plugin The plugin object.
|
||||
* @param {Config|LegacyConfig|(Config|LegacyConfig)[]} pluginConfig The plugin config to normalize.
|
||||
* @param {string} pluginConfigName The name of the plugin config.
|
||||
* @return {InfiniteConfigArray} The normalized plugin config.
|
||||
*/
|
||||
function deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
pluginConfig,
|
||||
pluginConfigName,
|
||||
) {
|
||||
// if it's an array then it's definitely a new config
|
||||
if (Array.isArray(pluginConfig)) {
|
||||
return pluginConfig.map(pluginSubConfig =>
|
||||
deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
pluginSubConfig,
|
||||
pluginConfigName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// if it's a legacy config, throw an error
|
||||
if (isLegacyConfig(pluginConfig)) {
|
||||
throw new TypeError(
|
||||
`Plugin config "${pluginConfigName}" is an eslintrc config and cannot be used in this context.`,
|
||||
);
|
||||
}
|
||||
|
||||
return normalizePluginConfig(userPluginNamespace, plugin, pluginConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a plugin config by name in the given config.
|
||||
* @param {Config} config The config object.
|
||||
* @param {string} pluginConfigName The name of the plugin config.
|
||||
* @return {InfiniteConfigArray} The plugin config.
|
||||
*/
|
||||
function findPluginConfig(config, pluginConfigName) {
|
||||
const { namespace: userPluginNamespace, name: configName } =
|
||||
getPluginMember(pluginConfigName);
|
||||
const plugin = config.plugins?.[userPluginNamespace];
|
||||
|
||||
if (!plugin) {
|
||||
throw new TypeError(`Plugin "${userPluginNamespace}" not found.`);
|
||||
}
|
||||
|
||||
const directConfig = plugin.configs?.[configName];
|
||||
if (directConfig) {
|
||||
// Arrays are always flat configs, and non-legacy configs can be used directly
|
||||
if (Array.isArray(directConfig) || !isLegacyConfig(directConfig)) {
|
||||
return deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
directConfig,
|
||||
pluginConfigName,
|
||||
);
|
||||
}
|
||||
|
||||
// If it's a legacy config, look for the flat version
|
||||
const flatConfig = plugin.configs?.[`flat/${configName}`];
|
||||
|
||||
if (
|
||||
flatConfig &&
|
||||
(Array.isArray(flatConfig) || !isLegacyConfig(flatConfig))
|
||||
) {
|
||||
return deepNormalizePluginConfig(
|
||||
userPluginNamespace,
|
||||
plugin,
|
||||
flatConfig,
|
||||
pluginConfigName,
|
||||
);
|
||||
}
|
||||
|
||||
throw new TypeError(
|
||||
`Plugin config "${configName}" in plugin "${userPluginNamespace}" is an eslintrc config and cannot be used in this context.`,
|
||||
);
|
||||
}
|
||||
|
||||
throw new TypeError(
|
||||
`Plugin config "${configName}" not found in plugin "${userPluginNamespace}".`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens an array while keeping track of the index path.
|
||||
* @param {any[]} configList The array to traverse.
|
||||
* @param {string} indexPath The index path of the value in a multidimensional array.
|
||||
* @return {IterableIterator<{indexPath:string, value:any}>} The flattened list of values.
|
||||
*/
|
||||
function* flatTraverse(configList, indexPath = "") {
|
||||
for (let i = 0; i < configList.length; i++) {
|
||||
const newIndexPath = indexPath ? `${indexPath}[${i}]` : `[${i}]`;
|
||||
|
||||
// if it's an array then traverse it as well
|
||||
if (Array.isArray(configList[i])) {
|
||||
yield* flatTraverse(configList[i], newIndexPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
yield { indexPath: newIndexPath, value: configList[i] };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends a list of config files by creating every combination of base and extension files.
|
||||
* @param {(string|string[])[]} [baseFiles] The base files.
|
||||
* @param {(string|string[])[]} [extensionFiles] The extension files.
|
||||
* @return {(string|string[])[]} The extended files.
|
||||
*/
|
||||
function extendConfigFiles(baseFiles = [], extensionFiles = []) {
|
||||
if (!extensionFiles.length) {
|
||||
return baseFiles.concat();
|
||||
}
|
||||
|
||||
if (!baseFiles.length) {
|
||||
return extensionFiles.concat();
|
||||
}
|
||||
|
||||
/** @type {(string|string[])[]} */
|
||||
const result = [];
|
||||
|
||||
for (const baseFile of baseFiles) {
|
||||
for (const extensionFile of extensionFiles) {
|
||||
/*
|
||||
* Each entry can be a string or array of strings. The end result
|
||||
* needs to be an array of strings, so we need to be sure to include
|
||||
* all of the items when there's an array.
|
||||
*/
|
||||
|
||||
const entry = [];
|
||||
|
||||
if (Array.isArray(baseFile)) {
|
||||
entry.push(...baseFile);
|
||||
} else {
|
||||
entry.push(baseFile);
|
||||
}
|
||||
|
||||
if (Array.isArray(extensionFile)) {
|
||||
entry.push(...extensionFile);
|
||||
} else {
|
||||
entry.push(extensionFile);
|
||||
}
|
||||
|
||||
result.push(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends a config object with another config object.
|
||||
* @param {Config} baseConfig The base config object.
|
||||
* @param {string} baseConfigName The name of the base config object.
|
||||
* @param {Config} extension The extension config object.
|
||||
* @param {string} extensionName The index of the extension config object.
|
||||
* @return {Config} The extended config object.
|
||||
*/
|
||||
function extendConfig(baseConfig, baseConfigName, extension, extensionName) {
|
||||
const result = { ...extension };
|
||||
|
||||
// for global ignores there is no further work to be done, we just keep everything
|
||||
if (!isGlobalIgnores(extension)) {
|
||||
// for files we need to create every combination of base and extension files
|
||||
if (baseConfig.files) {
|
||||
result.files = extendConfigFiles(baseConfig.files, extension.files);
|
||||
}
|
||||
|
||||
// for ignores we just concatenation the extension ignores onto the base ignores
|
||||
if (baseConfig.ignores) {
|
||||
result.ignores = baseConfig.ignores.concat(extension.ignores ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
result.name = `${baseConfigName} > ${extensionName}`;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a list of extends elements.
|
||||
* @param {ConfigWithExtends} config The config object.
|
||||
* @param {WeakMap<Config, string>} configNames The map of config objects to their names.
|
||||
* @return {Config[]} The flattened list of config objects.
|
||||
*/
|
||||
function processExtends(config, configNames) {
|
||||
if (!config.extends) {
|
||||
return [config];
|
||||
}
|
||||
|
||||
if (!Array.isArray(config.extends)) {
|
||||
throw new TypeError("The `extends` property must be an array.");
|
||||
}
|
||||
|
||||
const {
|
||||
/** @type {Config[]} */
|
||||
extends: extendsList,
|
||||
|
||||
/** @type {Config} */
|
||||
...configObject
|
||||
} = config;
|
||||
|
||||
const extensionNames = new WeakMap();
|
||||
|
||||
// replace strings with the actual configs
|
||||
const objectExtends = extendsList.map(extendsElement => {
|
||||
if (typeof extendsElement === "string") {
|
||||
const pluginConfig = findPluginConfig(config, extendsElement);
|
||||
|
||||
// assign names
|
||||
if (Array.isArray(pluginConfig)) {
|
||||
pluginConfig.forEach((pluginConfigElement, index) => {
|
||||
extensionNames.set(
|
||||
pluginConfigElement,
|
||||
`${extendsElement}[${index}]`,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
extensionNames.set(pluginConfig, extendsElement);
|
||||
}
|
||||
|
||||
return pluginConfig;
|
||||
}
|
||||
|
||||
return /** @type {Config} */ (extendsElement);
|
||||
});
|
||||
|
||||
const result = [];
|
||||
|
||||
for (const { indexPath, value: extendsElement } of flatTraverse(
|
||||
objectExtends,
|
||||
)) {
|
||||
const extension = /** @type {Config} */ (extendsElement);
|
||||
|
||||
if ("extends" in extension) {
|
||||
throw new TypeError("Nested 'extends' is not allowed.");
|
||||
}
|
||||
|
||||
const baseConfigName = /** @type {string} */ (configNames.get(config));
|
||||
const extensionName =
|
||||
extensionNames.get(extendsElement) ??
|
||||
getExtensionName(extendsElement, indexPath);
|
||||
|
||||
result.push(
|
||||
extendConfig(
|
||||
configObject,
|
||||
baseConfigName,
|
||||
extension,
|
||||
extensionName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the base config object has only `ignores` and `extends`, then
|
||||
* removing `extends` turns it into a global ignores, which is not what
|
||||
* we want. So we need to check if the base config object is a global ignores
|
||||
* and if so, we don't add it to the array.
|
||||
*
|
||||
* (The other option would be to add a `files` entry, but that would result
|
||||
* in a config that didn't actually do anything because there are no
|
||||
* other keys in the config.)
|
||||
*/
|
||||
if (!isGlobalIgnores(configObject)) {
|
||||
result.push(configObject);
|
||||
}
|
||||
|
||||
return result.flat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a list of config objects and arrays.
|
||||
* @param {ConfigWithExtends[]} configList The list of config objects and arrays.
|
||||
* @param {WeakMap<Config, string>} configNames The map of config objects to their names.
|
||||
* @return {Config[]} The flattened list of config objects.
|
||||
*/
|
||||
function processConfigList(configList, configNames) {
|
||||
return configList.flatMap(config => processExtends(config, configNames));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Helper function to define a config array.
|
||||
* @param {ConfigWithExtendsArray} args The arguments to the function.
|
||||
* @returns {Config[]} The config array.
|
||||
*/
|
||||
function defineConfig(...args) {
|
||||
const configNames = new WeakMap();
|
||||
const configs = [];
|
||||
|
||||
if (args.length === 0) {
|
||||
throw new TypeError("Expected one or more arguments.");
|
||||
}
|
||||
|
||||
// first flatten the list of configs and get the names
|
||||
for (const { indexPath, value } of flatTraverse(args)) {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new TypeError(
|
||||
`Expected an object but received ${String(value)}.`,
|
||||
);
|
||||
}
|
||||
|
||||
const config = /** @type {ConfigWithExtends} */ (value);
|
||||
|
||||
// save config name for easy reference later
|
||||
configNames.set(config, getConfigName(config, indexPath));
|
||||
configs.push(config);
|
||||
}
|
||||
|
||||
return processConfigList(configs, configNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @fileoverview Global ignores helper function.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Type Definitions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
let globalIgnoreCount = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a global ignores config with the given patterns.
|
||||
* @param {string[]} ignorePatterns The ignore patterns.
|
||||
* @param {string} [name] The name of the global ignores config.
|
||||
* @returns {Config} The global ignores config.
|
||||
*/
|
||||
function globalIgnores(ignorePatterns, name) {
|
||||
if (!Array.isArray(ignorePatterns)) {
|
||||
throw new TypeError("ignorePatterns must be an array");
|
||||
}
|
||||
|
||||
if (ignorePatterns.length === 0) {
|
||||
throw new TypeError("ignorePatterns must contain at least one pattern");
|
||||
}
|
||||
|
||||
const id = globalIgnoreCount++;
|
||||
|
||||
return {
|
||||
name: name || `globalIgnores ${id}`,
|
||||
ignores: ignorePatterns,
|
||||
};
|
||||
}
|
||||
|
||||
exports.defineConfig = defineConfig;
|
||||
exports.globalIgnores = globalIgnores;
|
||||
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.findSuggestion = findSuggestion;
|
||||
const {
|
||||
min
|
||||
} = Math;
|
||||
function levenshtein(a, b) {
|
||||
let t = [],
|
||||
u = [],
|
||||
i,
|
||||
j;
|
||||
const m = a.length,
|
||||
n = b.length;
|
||||
if (!m) {
|
||||
return n;
|
||||
}
|
||||
if (!n) {
|
||||
return m;
|
||||
}
|
||||
for (j = 0; j <= n; j++) {
|
||||
t[j] = j;
|
||||
}
|
||||
for (i = 1; i <= m; i++) {
|
||||
for (u = [i], j = 1; j <= n; j++) {
|
||||
u[j] = a[i - 1] === b[j - 1] ? t[j - 1] : min(t[j - 1], t[j], u[j - 1]) + 1;
|
||||
}
|
||||
t = u;
|
||||
}
|
||||
return u[n];
|
||||
}
|
||||
function findSuggestion(str, arr) {
|
||||
const distances = arr.map(el => levenshtein(el, str));
|
||||
return arr[distances.indexOf(min(...distances))];
|
||||
}
|
||||
|
||||
//# sourceMappingURL=find-suggestion.js.map
|
||||
Reference in New Issue
Block a user