@hirobius/design-system 0.19.1 → 0.20.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.
- package/CONSUMING.md +9 -6
- package/DESIGN.md +7 -5
- package/README.md +14 -11
- package/codemods/hds-prefix.mjs +231 -0
- package/codemods/jsx-fold.mjs +515 -0
- package/codemods/not-found-pattern.mjs +71 -0
- package/codemods/patterns-subpath.mjs +242 -81
- package/codemods/patterns-subpath.names.json +41 -15
- package/codemods/removed-0.20.json +194 -0
- package/codemods/tile-grid.mjs +283 -0
- package/codemods/unrewritable.mjs +291 -0
- package/dist/chunks/DemoStateContext-Cz5TmrYu.js +32 -0
- package/dist/chunks/empty-state-BBqhCx0S.js +1217 -0
- package/dist/contexts.js +157 -78
- package/dist/hirobius-ui.js +1517 -5270
- package/dist/manifest.js +12 -13
- package/dist/patterns.js +780 -513
- package/dist/styles.css +1 -1
- package/dist/tokens.css +1 -1
- package/dist/tokens.js +29 -8
- package/dist/types/src/app/components/avatar-group.d.ts +1 -2
- package/dist/types/src/app/components/badge.d.ts +8 -3
- package/dist/types/src/app/components/blockquote.d.ts +1 -2
- package/dist/types/src/app/components/box-sx.d.ts +110 -13
- package/dist/types/src/app/components/box.d.ts +6 -3
- package/dist/types/src/app/components/breadcrumb.d.ts +0 -5
- package/dist/types/src/app/components/button.d.ts +33 -4
- package/dist/types/src/app/components/card.d.ts +7 -8
- package/dist/types/src/app/components/combobox.d.ts +47 -11
- package/dist/types/src/app/components/container.d.ts +2 -2
- package/dist/types/src/app/components/data-table-section.d.ts +1 -1
- package/dist/types/src/app/components/dialog.d.ts +7 -1
- package/dist/types/src/app/components/disclosure.d.ts +1 -5
- package/dist/types/src/app/components/field.d.ts +1 -2
- package/dist/types/src/app/components/grid.d.ts +10 -6
- package/dist/types/src/app/components/hds-tooltip.d.ts +12 -2
- package/dist/types/src/app/components/inline-code.d.ts +1 -2
- package/dist/types/src/app/components/input.d.ts +8 -5
- package/dist/types/src/app/components/kbd.d.ts +1 -2
- package/dist/types/src/app/components/metadata-list.d.ts +1 -2
- package/dist/types/src/app/components/page-header.d.ts +0 -2
- package/dist/types/src/app/components/popover.d.ts +8 -0
- package/dist/types/src/app/components/progress.d.ts +33 -6
- package/dist/types/src/app/components/segmented-control.d.ts +2 -26
- package/dist/types/src/app/components/select.d.ts +10 -1
- package/dist/types/src/app/components/skeleton.d.ts +2 -3
- package/dist/types/src/app/components/spinner.d.ts +1 -2
- package/dist/types/src/app/components/stack.d.ts +4 -1
- package/dist/types/src/app/components/stat.d.ts +1 -2
- package/dist/types/src/app/components/status-dot.d.ts +18 -4
- package/dist/types/src/app/components/status-list-item.d.ts +1 -2
- package/dist/types/src/app/components/surface.d.ts +2 -3
- package/dist/types/src/app/components/switcher.d.ts +1 -1
- package/dist/types/src/app/components/table.d.ts +1 -15
- package/dist/types/src/app/components/tag.d.ts +0 -6
- package/dist/types/src/app/components/text.d.ts +1 -2
- package/dist/types/src/app/components/textarea.d.ts +1 -2
- package/dist/types/src/app/components/toast.d.ts +1 -2
- package/dist/types/src/app/components/tooltip.d.ts +1 -1
- package/dist/types/src/app/context/DemoStateContext.d.ts +1 -1
- package/dist/types/src/app/context/RouterContext.d.ts +5 -5
- package/dist/types/src/app/data/manifest-types.d.ts +6 -5
- package/dist/types/src/app/design-system/generated-token-refs.d.ts +8 -0
- package/dist/types/src/app/design-system/generated-token-values.d.ts +1 -0
- package/dist/types/src/app/design-system/tokens.d.ts +22 -3
- package/dist/types/src/icons.d.ts +1 -1
- package/dist/types/src/index.d.ts +33 -124
- package/dist/types/src/patterns.d.ts +20 -25
- package/dist/variables.css +6 -0
- package/docs/CONSUMING.md +21 -13
- package/hirobius.tokens.json +48 -15
- package/llms.txt +19 -20
- package/package.json +17 -22
- package/public/hds-manifest.json +2405 -6537
- package/public/llms/components.txt +41 -423
- package/public/llms/layout.txt +4 -4
- package/public/llms-full.txt +67 -448
- package/public/llms.txt +19 -20
- package/src/app/data/component-api.json +1379 -3271
- package/dist/chunks/LanguageContext-BxdCwiFg.js +0 -95
- package/dist/chunks/TokenDisplayContext-DKYJMVWk.js +0 -26
- package/dist/chunks/activity-feed-BGQ6v3wc.js +0 -22040
- package/dist/types/src/app/components/activity-feed.d.ts +0 -73
- package/dist/types/src/app/components/app-shell.d.ts +0 -40
- package/dist/types/src/app/components/aspect-ratio.d.ts +0 -25
- package/dist/types/src/app/components/bleed.d.ts +0 -39
- package/dist/types/src/app/components/button-group.d.ts +0 -22
- package/dist/types/src/app/components/calendar.d.ts +0 -22
- package/dist/types/src/app/components/carousel.d.ts +0 -26
- package/dist/types/src/app/components/center.d.ts +0 -36
- package/dist/types/src/app/components/cinematic-link.d.ts +0 -18
- package/dist/types/src/app/components/circular-progress.d.ts +0 -28
- package/dist/types/src/app/components/cluster.d.ts +0 -39
- package/dist/types/src/app/components/command-palette.d.ts +0 -46
- package/dist/types/src/app/components/component-instance-matrix.d.ts +0 -27
- package/dist/types/src/app/components/context-menu.d.ts +0 -78
- package/dist/types/src/app/components/cover.d.ts +0 -43
- package/dist/types/src/app/components/date-input.d.ts +0 -31
- package/dist/types/src/app/components/date-range-input.d.ts +0 -34
- package/dist/types/src/app/components/date-time-input.d.ts +0 -30
- package/dist/types/src/app/components/doc-link-card.d.ts +0 -32
- package/dist/types/src/app/components/error-boundary.d.ts +0 -25
- package/dist/types/src/app/components/file-input.d.ts +0 -30
- package/dist/types/src/app/components/foundation-swatch.d.ts +0 -45
- package/dist/types/src/app/components/frame.d.ts +0 -38
- package/dist/types/src/app/components/heading-stack.d.ts +0 -52
- package/dist/types/src/app/components/history-card.d.ts +0 -12
- package/dist/types/src/app/components/hover-card.d.ts +0 -46
- package/dist/types/src/app/components/icon-button.d.ts +0 -22
- package/dist/types/src/app/components/image-lightbox.d.ts +0 -14
- package/dist/types/src/app/components/input-group.d.ts +0 -23
- package/dist/types/src/app/components/multi-selector.d.ts +0 -40
- package/dist/types/src/app/components/nav-group.d.ts +0 -29
- package/dist/types/src/app/components/nav-item.d.ts +0 -33
- package/dist/types/src/app/components/not-found-pattern.d.ts +0 -1
- package/dist/types/src/app/components/overflow-list.d.ts +0 -21
- package/dist/types/src/app/components/selectable-card.d.ts +0 -29
- package/dist/types/src/app/components/side-nav.d.ts +0 -23
- package/dist/types/src/app/components/sketch.d.ts +0 -19
- package/dist/types/src/app/components/stacked-card-rail.d.ts +0 -32
- package/dist/types/src/app/components/stepper-field.d.ts +0 -12
- package/dist/types/src/app/components/stepper.d.ts +0 -33
- package/dist/types/src/app/components/text-lockup.d.ts +0 -38
- package/dist/types/src/app/components/tile-grid.d.ts +0 -17
- package/dist/types/src/app/components/time-input.d.ts +0 -24
- package/dist/types/src/app/components/toggle-button.d.ts +0 -32
- package/dist/types/src/app/components/token.d.ts +0 -90
- package/dist/types/src/app/components/tokenUtils.d.ts +0 -38
- package/dist/types/src/app/components/tokenizer.d.ts +0 -24
- package/dist/types/src/app/components/toolbar.d.ts +0 -36
- package/dist/types/src/app/components/top-nav.d.ts +0 -23
- package/dist/types/src/app/components/tree-list.d.ts +0 -30
- package/dist/types/src/app/data/nav-model.d.ts +0 -39
- package/dist/types/src/app/hooks/useFocusVisible.d.ts +0 -9
- package/dist/types/src/app/layouts/CaseStudyLayout.d.ts +0 -20
- package/dist/types/src/app/layouts/DocLayout.d.ts +0 -14
- package/dist/types/src/app/layouts/EmbeddedDocLayoutContext.d.ts +0 -6
- package/dist/types/src/app/layouts/HdsDocsShell.d.ts +0 -72
- package/dist/types/src/app/layouts/HdsSystemDocLayout.d.ts +0 -14
- package/dist/types/src/app/lib/hds-search.d.ts +0 -45
- package/dist/types/src/app/lib/nav-active.d.ts +0 -16
- package/dist/types/src/app/lib/navLevels.d.ts +0 -4
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the codemods in this directory cannot rewrite (hds#389 R1a), shared by
|
|
3
|
+
* hds-prefix.mjs and patterns-subpath.mjs. Both ship as package bins and run
|
|
4
|
+
* under `npx`, so this has no dependencies.
|
|
5
|
+
*
|
|
6
|
+
* A codemod rewrites the named imports and re-exports of the package root. It
|
|
7
|
+
* cannot see which names a file reads through:
|
|
8
|
+
* - `export * from '<pkg>'` or `export type * from '<pkg>'`: its importers are
|
|
9
|
+
* in other files, so it is always listed;
|
|
10
|
+
* - a namespace import (`import * as X from '<pkg>'`, `import type * as X`), or
|
|
11
|
+
* a call that loads the package by name (`import()`, `require()`, `vi.mock`,
|
|
12
|
+
* `jest.mock`, `jest.requireMock`, `jest.unstable_mockModule`,
|
|
13
|
+
* `requireActual`, `importActual` and the like, with type arguments such as
|
|
14
|
+
* `vi.importActual<T>(…)` and comments allowed before the specifier): listed
|
|
15
|
+
* only when the file reads a removed name off something, as a member
|
|
16
|
+
* (`m.Page`, `m?.Page`), a string key (`m['Page']`) or a destructuring
|
|
17
|
+
* pattern (`const { Page } =`, `({ Page: P }) =>`). A bare identifier (a
|
|
18
|
+
* local binding, a type, the alias a codemod wrote) is not a read, so a
|
|
19
|
+
* migrated file reaches `--check` exit 0.
|
|
20
|
+
*
|
|
21
|
+
* `maskSource` tells code from text in one linear pass with one regular
|
|
22
|
+
* expression: no recursion and no JSX parsing, so the cost does not grow with
|
|
23
|
+
* `<T>` casts or nesting. It is a tokenizer, not a parser, so JSX text can
|
|
24
|
+
* mislead it (hds#434):
|
|
25
|
+
* - a lone quote, or `//` other than in a URL, blanks at most the rest of its
|
|
26
|
+
* line;
|
|
27
|
+
* - a lone backtick opens a template, and `/*` (as in `src/*.ts`) opens a
|
|
28
|
+
* block comment. Either one blanks everything up to the next backtick or
|
|
29
|
+
* comment close, which can be the end of the file.
|
|
30
|
+
* A regex literal read as a division (a `/` after `)`, `]` or a name) can do
|
|
31
|
+
* the same through a quote or backtick in its body. A `/` that starts a line
|
|
32
|
+
* right after a comment is read as a regex, so a commented list of patterns
|
|
33
|
+
* reads correctly. Valid code cannot end inside a block comment or template, so
|
|
34
|
+
* when the masking does, `findUnrewritable` lists the file as unreadable
|
|
35
|
+
* instead of passing it.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const ID = String.raw`[A-Za-z_$][\w$]*`;
|
|
39
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
40
|
+
|
|
41
|
+
// The body and flags of a regex literal, after its opening `/`.
|
|
42
|
+
const REGEX_BODY = String.raw`[^/\\\n[]*(?:(?:\\.|\[[^\]\\\n]*(?:\\.[^\]\\\n]*)*\])[^/\\\n[]*)*\/[A-Za-z]*`;
|
|
43
|
+
// A regex literal: a `/` where an expression can start, so it does not divide.
|
|
44
|
+
// The lookbehind runs only at a `/`, which keeps the pass linear.
|
|
45
|
+
const REGEX_LITERAL =
|
|
46
|
+
String.raw`\/(?![*/])(?<=(?:^|[(,=:[!&|?;{+\-*%~^>]|(?<![\w$])(?:return|typeof|case|do|else|in|of|new|delete|void|throw|yield|await))\s*\/)` +
|
|
47
|
+
REGEX_BODY;
|
|
48
|
+
// A `/` that starts a line, shaped like a regex literal. `maskSource` reads it as
|
|
49
|
+
// one only when a comment ends right before it (hds#434): the comment hides the
|
|
50
|
+
// token that decides, and a line that starts with a division is rare.
|
|
51
|
+
const LINE_START_REGEX = String.raw`(?<lineStart>\/(?![*/])(?<=(?:^|\n)[ \t]*\/)${REGEX_BODY})`;
|
|
52
|
+
const TOKEN = new RegExp(
|
|
53
|
+
[
|
|
54
|
+
// A line comment; `https://` in JSX text is not one.
|
|
55
|
+
String.raw`\/\/(?<!(?<![\w$])(?:https?|wss?|ftp|file|git|ssh):\/\/)[^\n]*`,
|
|
56
|
+
String.raw`\/\*[\s\S]*?(?:\*\/|$)`,
|
|
57
|
+
String.raw`'[^'\\\n]*(?:\\[\s\S][^'\\\n]*)*'`,
|
|
58
|
+
String.raw`"[^"\\\n]*(?:\\[\s\S][^"\\\n]*)*"`,
|
|
59
|
+
'`',
|
|
60
|
+
'[{}]',
|
|
61
|
+
REGEX_LITERAL,
|
|
62
|
+
LINE_START_REGEX,
|
|
63
|
+
].join('|'),
|
|
64
|
+
'g',
|
|
65
|
+
);
|
|
66
|
+
const BOM = '\uFEFF';
|
|
67
|
+
// Template text up to the closing backtick or the next `${`.
|
|
68
|
+
const TEMPLATE_TEXT = /[^`\\$]*(?:(?:\\[\s\S]|\$(?!\{))[^`\\$]*)*/y;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The source with every comment, the text of every string and template, and
|
|
72
|
+
* every regex literal body blanked to spaces. Same length, newlines kept, so an
|
|
73
|
+
* index into `code` is an index into `source`. Quotes and backticks stay, and so
|
|
74
|
+
* does the code inside `${}`. A byte order mark at the start is blanked too.
|
|
75
|
+
* @param {string} source
|
|
76
|
+
* @returns {{ code: string, strings: { start: number, end: number, value: string }[],
|
|
77
|
+
* unterminated: { kind: 'comment' | 'template', at: number, line: number } | null }}
|
|
78
|
+
* `strings`: each quoted string and each template without `${}`, `start` at the
|
|
79
|
+
* opening quote and `end` after the closing one. `unterminated`: the block
|
|
80
|
+
* comment or template the source ends inside (the outermost one), which valid
|
|
81
|
+
* code cannot do, or null.
|
|
82
|
+
*/
|
|
83
|
+
export function maskSource(source) {
|
|
84
|
+
const n = source.length;
|
|
85
|
+
const blanks = source.startsWith(BOM) ? [[0, 1]] : [];
|
|
86
|
+
const strings = [];
|
|
87
|
+
const resume = []; // brace depth outside each open `${`
|
|
88
|
+
const open = []; // where each template still open starts
|
|
89
|
+
let depth = 0;
|
|
90
|
+
let commentEnd = -1; // the end of the last token, while that token is a comment
|
|
91
|
+
let openComment = -1; // a block comment the source ends inside
|
|
92
|
+
let i = 0;
|
|
93
|
+
|
|
94
|
+
/** Template text from `from`; returns where code resumes. */
|
|
95
|
+
const templateText = (from) => {
|
|
96
|
+
TEMPLATE_TEXT.lastIndex = from;
|
|
97
|
+
TEMPLATE_TEXT.exec(source);
|
|
98
|
+
const j = TEMPLATE_TEXT.lastIndex;
|
|
99
|
+
blanks.push([from, j]);
|
|
100
|
+
if (j >= n) return n;
|
|
101
|
+
if (source[j] === '`') {
|
|
102
|
+
const opened = open.pop();
|
|
103
|
+
// A template with no `${}` is a plain string; one resumed after a `}` is not.
|
|
104
|
+
if (opened === from - 1)
|
|
105
|
+
strings.push({ start: opened, end: j + 1, value: source.slice(opened + 1, j) });
|
|
106
|
+
return j + 1;
|
|
107
|
+
}
|
|
108
|
+
resume.push(depth);
|
|
109
|
+
depth = 0;
|
|
110
|
+
return j + 2;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
while (i < n) {
|
|
114
|
+
TOKEN.lastIndex = i;
|
|
115
|
+
const m = TOKEN.exec(source);
|
|
116
|
+
if (!m) break;
|
|
117
|
+
const at = m.index;
|
|
118
|
+
const t = m[0];
|
|
119
|
+
if (m.groups.lineStart !== undefined) {
|
|
120
|
+
// Only whitespace since a comment: the comment hid the token before the `/`.
|
|
121
|
+
const afterComment = commentEnd >= 0 && /^\s*$/.test(source.slice(commentEnd, at));
|
|
122
|
+
commentEnd = -1;
|
|
123
|
+
if (!afterComment) {
|
|
124
|
+
i = at + 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
i = at + t.length;
|
|
129
|
+
const c = t[0];
|
|
130
|
+
commentEnd = c === '/' && (t[1] === '/' || t[1] === '*') ? i : -1;
|
|
131
|
+
if (t === '{') depth++;
|
|
132
|
+
else if (t === '}') {
|
|
133
|
+
if (depth > 0) depth--;
|
|
134
|
+
else if (resume.length > 0) {
|
|
135
|
+
depth = resume.pop();
|
|
136
|
+
i = templateText(i);
|
|
137
|
+
}
|
|
138
|
+
} else if (t === '`') {
|
|
139
|
+
open.push(at);
|
|
140
|
+
i = templateText(i);
|
|
141
|
+
} else if (c === "'" || c === '"') {
|
|
142
|
+
blanks.push([at + 1, i - 1]);
|
|
143
|
+
strings.push({ start: at, end: i, value: t.slice(1, -1) });
|
|
144
|
+
} else if (t[1] === '/') blanks.push([at, i]);
|
|
145
|
+
else if (t[1] === '*') {
|
|
146
|
+
blanks.push([at, i]);
|
|
147
|
+
if (t.length < 4 || !t.endsWith('*/')) openComment = at;
|
|
148
|
+
} else blanks.push([at + 1, i]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let code = '';
|
|
152
|
+
let last = 0;
|
|
153
|
+
for (const [start, end] of blanks) {
|
|
154
|
+
if (end <= start) continue;
|
|
155
|
+
code += source.slice(last, start) + source.slice(start, end).replace(/[^\n]/g, ' ');
|
|
156
|
+
last = end;
|
|
157
|
+
}
|
|
158
|
+
code += source.slice(last);
|
|
159
|
+
|
|
160
|
+
let unterminated = null;
|
|
161
|
+
const at = open.length > 0 ? open[0] : openComment;
|
|
162
|
+
if (at >= 0)
|
|
163
|
+
unterminated = {
|
|
164
|
+
kind: open.length > 0 ? 'template' : 'comment',
|
|
165
|
+
at,
|
|
166
|
+
line: source.slice(0, at).split('\n').length,
|
|
167
|
+
};
|
|
168
|
+
return { code, strings, unterminated };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Calls that load a module by name: `import()`, `require()` and the test-runner forms.
|
|
172
|
+
const LOADERS = [
|
|
173
|
+
'import',
|
|
174
|
+
'require',
|
|
175
|
+
'requireActual',
|
|
176
|
+
'importActual',
|
|
177
|
+
'requireMock',
|
|
178
|
+
'importMock',
|
|
179
|
+
'mock',
|
|
180
|
+
'doMock',
|
|
181
|
+
'unstable_mockModule',
|
|
182
|
+
'createMockFromModule',
|
|
183
|
+
];
|
|
184
|
+
const KEYWORDS = new Set(['return', 'typeof', 'case', 'in', 'of', 'void', 'yield', 'await']);
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The names in `names` that the code reads off something: `.Name`, `['Name']`,
|
|
188
|
+
* or a key or shorthand in a destructuring pattern.
|
|
189
|
+
*/
|
|
190
|
+
function readNames(code, strings, names) {
|
|
191
|
+
const read = new Set();
|
|
192
|
+
for (const m of code.matchAll(new RegExp(String.raw`(?<!\.)\.\s*(${ID})`, 'g')))
|
|
193
|
+
if (names.has(m[1])) read.add(m[1]);
|
|
194
|
+
|
|
195
|
+
for (const s of strings) {
|
|
196
|
+
if (!names.has(s.value)) continue;
|
|
197
|
+
const before = /(\?\.|[)\]]|[\w$]+)\s*\[\s*$/.exec(
|
|
198
|
+
code.slice(Math.max(0, s.start - 80), s.start),
|
|
199
|
+
);
|
|
200
|
+
if (before && !KEYWORDS.has(before[1]) && /^\s*\]/.test(code.slice(s.end, s.end + 80)))
|
|
201
|
+
read.add(s.value);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const open = [];
|
|
205
|
+
for (const m of code.matchAll(/[{}]/g)) {
|
|
206
|
+
if (m[0] === '{') {
|
|
207
|
+
open.push(m.index);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const start = open.pop();
|
|
211
|
+
if (start === undefined) continue;
|
|
212
|
+
const end = m.index;
|
|
213
|
+
const before = code.slice(Math.max(0, start - 16), start);
|
|
214
|
+
const after = code.slice(end + 1, end + 201);
|
|
215
|
+
const pattern =
|
|
216
|
+
/(?:(?<![\w$])(?:const|let|var)|[(,])\s*$/.test(before) &&
|
|
217
|
+
/^\s*(?:=(?![=>])|of\b|(?::[^;{}()=]*)?\)\s*(?::[^;{}()=]*)?(?:=>|\{))/.test(after);
|
|
218
|
+
if (!pattern) continue;
|
|
219
|
+
for (const k of code
|
|
220
|
+
.slice(start, end)
|
|
221
|
+
.matchAll(new RegExp(String.raw`[{,]\s*(${ID})\s*(?=[,}:=]|$)`, 'g')))
|
|
222
|
+
if (names.has(k[1])) read.add(k[1]);
|
|
223
|
+
}
|
|
224
|
+
return [...read].sort();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Type arguments between a loader and its `(`: `vi.importActual<typeof import('…')>(…)`.
|
|
228
|
+
// Bounded and lazy, so a stray `<` costs at most this many characters.
|
|
229
|
+
const TYPE_ARGS = String.raw`(?:<[\s\S]{0,400}?>\s*)?`;
|
|
230
|
+
|
|
231
|
+
const UNREADABLE = {
|
|
232
|
+
comment: "a block comment never closes (in JSX text, write /* as {'/*'})",
|
|
233
|
+
template: "a template literal never closes (in JSX text, write a backtick as {'`'})",
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Statements that hide which names a file takes from `pkg`, each as one line for
|
|
238
|
+
* a `--check` report: `export * from '<pkg>'` always; a namespace import or a
|
|
239
|
+
* module-loading call of `pkg` with `(uses A, B)` when the file reads one of
|
|
240
|
+
* `names` off something; and, for a file that names `pkg` but ends inside a
|
|
241
|
+
* block comment or template, `unreadable from line N: …`, since its imports
|
|
242
|
+
* after that line cannot be read.
|
|
243
|
+
* @param {string} source
|
|
244
|
+
* @param {string} pkg the package root specifier, matched exactly
|
|
245
|
+
* @param {Iterable<string>} names the names the root no longer exports
|
|
246
|
+
* @returns {string[]}
|
|
247
|
+
*/
|
|
248
|
+
export function findUnrewritable(source, pkg, names) {
|
|
249
|
+
const { code, strings, unterminated } = maskSource(source);
|
|
250
|
+
// `code` keeps quotes but blanks the specifier, so compare it in `source`.
|
|
251
|
+
const isPkg = (quoteAt) =>
|
|
252
|
+
source.startsWith(pkg, quoteAt + 1) && source[quoteAt + 1 + pkg.length] === source[quoteAt];
|
|
253
|
+
const blank = `(['"\`]) {${pkg.length}}`;
|
|
254
|
+
const found = [];
|
|
255
|
+
for (const m of code.matchAll(
|
|
256
|
+
new RegExp(
|
|
257
|
+
String.raw`(?:^|(?<=;))[ \t]*export\s+(?:type\s+)?\*(?:\s*as\s+${ID})?\s*from\s*${blank}\1`,
|
|
258
|
+
'gm',
|
|
259
|
+
),
|
|
260
|
+
)) {
|
|
261
|
+
const quoteAt = m.index + m[0].length - pkg.length - 2;
|
|
262
|
+
if (isPkg(quoteAt)) found.push(source.slice(m.index, m.index + m[0].length).trim());
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const hidden = new Set();
|
|
266
|
+
for (const m of code.matchAll(
|
|
267
|
+
new RegExp(
|
|
268
|
+
String.raw`(?:^|(?<=;))[ \t]*import\s+(?:type\s+)?(?:${ID}\s*,\s*)?\*\s*as\s+${ID}\s*from\s*${blank}\1`,
|
|
269
|
+
'gm',
|
|
270
|
+
),
|
|
271
|
+
)) {
|
|
272
|
+
const quoteAt = m.index + m[0].length - pkg.length - 2;
|
|
273
|
+
if (isPkg(quoteAt)) hidden.add(source.slice(m.index, m.index + m[0].length).trim());
|
|
274
|
+
}
|
|
275
|
+
for (const m of code.matchAll(
|
|
276
|
+
new RegExp(
|
|
277
|
+
String.raw`(?<![\w$])(${LOADERS.map(esc).join('|')})\s*${TYPE_ARGS}\(\s*${blank}\2`,
|
|
278
|
+
'g',
|
|
279
|
+
),
|
|
280
|
+
)) {
|
|
281
|
+
const quoteAt = m.index + m[0].length - pkg.length - 2;
|
|
282
|
+
if (isPkg(quoteAt)) hidden.add(`${m[1]}('${pkg}')`);
|
|
283
|
+
}
|
|
284
|
+
if (hidden.size > 0) {
|
|
285
|
+
const read = readNames(code, strings, new Set(names));
|
|
286
|
+
if (read.length > 0) for (const h of hidden) found.push(`${h} (uses ${read.join(', ')})`);
|
|
287
|
+
}
|
|
288
|
+
if (unterminated && source.includes(pkg))
|
|
289
|
+
found.push(`unreadable from line ${unterminated.line}: ${UNREADABLE[unterminated.kind]}`);
|
|
290
|
+
return found;
|
|
291
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
3
|
+
import { useContext as o, createContext as r, forwardRef as d } from "react";
|
|
4
|
+
const c = /* @__PURE__ */ d(function({ to: t, children: a, ...s }, f) {
|
|
5
|
+
return /* @__PURE__ */ e("a", { ref: f, href: t, ...s, children: a });
|
|
6
|
+
}), u = /* @__PURE__ */ r(null);
|
|
7
|
+
function m({ adapter: n, children: t }) {
|
|
8
|
+
return /* @__PURE__ */ e(u.Provider, { value: n, children: t });
|
|
9
|
+
}
|
|
10
|
+
function p() {
|
|
11
|
+
const n = o(u);
|
|
12
|
+
return n || {
|
|
13
|
+
navigate: (t) => {
|
|
14
|
+
typeof window < "u" && window.location.assign(t);
|
|
15
|
+
},
|
|
16
|
+
currentPath: typeof window < "u" ? window.location.pathname : "/",
|
|
17
|
+
LinkComponent: c
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const i = /* @__PURE__ */ r(null);
|
|
21
|
+
function x({ state: n, children: t }) {
|
|
22
|
+
return /* @__PURE__ */ e(i.Provider, { value: n, children: t });
|
|
23
|
+
}
|
|
24
|
+
function v() {
|
|
25
|
+
return o(i);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
x as F,
|
|
29
|
+
m as H,
|
|
30
|
+
p as a,
|
|
31
|
+
v as u
|
|
32
|
+
};
|