@iyulab/components 2.26.1 → 2.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.27.1] - 2026-10-15
4
+
5
+ ### Fixed
6
+
7
+ - `plugins/dts-globals`: a class the declaration bundler inlined into an entry as a private copy (declared there, exported
8
+ only by another entry) is now pointed at the public export as well. The copy is a second nominal type for the same tag,
9
+ so a program that loaded both entries failed with `TS2717`.
10
+
11
+ ## [2.27.0] - 2026-10-15
12
+
13
+ ### Added
14
+
15
+ - `plugins/dts-globals` — `fixPublishedDtsGlobals(packageRoot)`, a build step for packages that bundle their
16
+ declarations (`vite-plugin-dts` with `bundleTypes`). The bundler copies every `declare global` merge of the source
17
+ tree into each entry `.d.ts` but drops the classes those merges name when the entry does not reach them, so a
18
+ consumer that checks library types (`skipLibCheck: false`) fails with `TS2304` just for importing the package. The
19
+ step points each such name at the public entry that exports it (`import('<package>/<subpath>').Name`), types a tag
20
+ whose class no entry exports as `HTMLElement`, and leaves built-in types alone. Call it from the plugin's
21
+ `afterBuild` hook (`import { fixPublishedDtsGlobals } from '@iyulab/components/plugins/dts-globals.js'`).
22
+
3
23
  ## [2.26.1] - 2026-10-14
4
24
 
5
25
  ### Fixed
package/README.md CHANGED
@@ -171,6 +171,7 @@ Theme.set('system');
171
171
  | SC 2.5.8 타깃 크기(최소) | 등록된 모든 컴포넌트의 포인터 타깃이 24×24 CSS px 이상이거나 간격 예외(중심 간 24px)를 충족하고, 그 좌표에서 실제로 눌린다 | `tests/browser/target-size.browser.test.ts`(실제 크로미움) |
172
172
  | SC 2.1.1 키보드(포인터 커서 검사) | 픽스처가 그리는 어떤 요소도 포인터 커서를 보이면서 상호작용 요소가 아닌 채로 있지 않다 — 클릭만 받는 `div` 가 들어오지 못한다(키 처리 자체는 컴포넌트 테스트가 잰다) | 같은 파일 |
173
173
  | SC 1.3.1 정보와 관계 · SC 4.1.2 이름·역할·값 | `u-field` 의 `label`/`description` 이 슬롯된 컨트롤의 접근성 이름·설명으로 실제로 도달한다(네이티브 엘리먼트 · `u-*` 폼 컨트롤 양쪽) | `tests/browser/field-label-association.browser.test.ts` |
174
+ | SC 2.4.7 포커스 표시 · SC 1.4.11 비텍스트 대비(강제 색 모드) | Windows 대비 테마(`forced-colors: active`)에서도 포커스 링이 보이고, `u-switch` 켬/끔과 입력류의 무효 표시가 구분된다 — 색을 시스템 색으로 덮는 그 모드를 에뮬레이션해 Tab·상태 전환 전후의 픽셀로 잰다 | `tests/browser/forced-colors-focus.browser.test.ts` · `tests/browser/forced-colors-state.browser.test.ts` |
174
175
 
175
176
  🔴**폼 컨트롤의 접근성 이름은 «한 곳에서만» 준다.** `u-field` 는 자기 `label` 을 슬롯된 컨트롤에
176
177
  `aria-label` 로 얹고(섀도우 경계를 넘지 못하는 `aria-labelledby` 대신 문자열 복사다), 폼 컨트롤은
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Makes every published entry `.d.ts` self-contained with respect to its `declare global` blocks.
3
+ *
4
+ * Why this exists: a declaration bundler (`vite-plugin-dts` with `bundleTypes`, i.e. api-extractor)
5
+ * copies the global augmentations of the whole source tree into **every** entry it rolls up — a
6
+ * component module's `declare global { interface HTMLElementTagNameMap { 'u-x': UX } }` lands in
7
+ * the main entry too — but it only keeps the declarations that entry itself reaches. The merge
8
+ * body survives while the class it names does not, so a consumer that type-checks libraries
9
+ * (`skipLibCheck: false`) fails with `TS2304: Cannot find name 'UX'` just for importing the
10
+ * package. The same happens when the entry has the name only as a value (a React wrapper `const`),
11
+ * which surfaces as `TS2749`.
12
+ *
13
+ * The fix keeps the augmentation (so `document.querySelector('u-x')` stays typed from any entry)
14
+ * and points each dangling name at the public entry that exports it:
15
+ * `'u-x': UX` becomes `'u-x': import('<package>/<subpath>').UX`. A tag whose class no entry
16
+ * exports is a composed-only internal, so its map value becomes `HTMLElement` — the most specific
17
+ * public type there is. Any other dangling name is left as it is: guessing would hide a real
18
+ * export gap, and the published-declaration compile check is what reports it.
19
+ *
20
+ * Call it from the declaration plugin's `afterBuild` hook, after the bundled `.d.ts` files exist.
21
+ */
22
+ export declare function fixPublishedDtsGlobals(packageRoot: string): void;
23
+ interface DeclarationEntry {
24
+ /** Export key, `.` or `./sub`. */
25
+ key: string;
26
+ /** Built declaration file, relative to the package root. */
27
+ file: string;
28
+ }
29
+ /**
30
+ * Entry declaration files from the manifest's `exports`. A local manifest may point at `./src/…`
31
+ * because the publish workflow rewrites `src/` to `dist/`; the built file is always under `dist/`.
32
+ */
33
+ export declare function declarationEntries(exportsMap: Record<string, unknown>): DeclarationEntry[];
34
+ /**
35
+ * `name → specifier` for every type-capable name an entry exports publicly. The main entry wins
36
+ * when several entries export the same name.
37
+ */
38
+ export declare function indexExportedTypes(packageName: string, entries: {
39
+ key: string;
40
+ source: string;
41
+ }[]): Map<string, string>;
42
+ /** Type-capable names a declaration file exports (`export declare class X` · `export { X }` of a declared `X`). */
43
+ export declare function exportedTypeNames(source: string): Set<string>;
44
+ /** Names a declaration file can use as types: its own type declarations and its imports. */
45
+ export declare function localTypeNames(source: string): Set<string>;
46
+ /**
47
+ * Global type names from the TypeScript `lib.*.d.ts` the package builds with (`HTMLElement`,
48
+ * `CustomEvent`, `HTMLDivElement` …). These are never dangling, so they are never rewritten —
49
+ * a tag mapped to a built-in element type keeps that type.
50
+ */
51
+ export declare function libGlobalNames(packageRoot: string): Set<string>;
52
+ /**
53
+ * Rewrites the dangling names inside each top-level `declare global { … }` block of one
54
+ * declaration file (see `fixPublishedDtsGlobals`). Everything outside those blocks is untouched.
55
+ */
56
+ export declare function resolveDanglingGlobals(source: string, exportedFrom: Map<string, string>, globals?: Set<string>): string;
57
+ export {};
@@ -0,0 +1,239 @@
1
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
2
+ import { createRequire } from 'module';
3
+ import { dirname, join, resolve } from 'path';
4
+ /**
5
+ * Makes every published entry `.d.ts` self-contained with respect to its `declare global` blocks.
6
+ *
7
+ * Why this exists: a declaration bundler (`vite-plugin-dts` with `bundleTypes`, i.e. api-extractor)
8
+ * copies the global augmentations of the whole source tree into **every** entry it rolls up — a
9
+ * component module's `declare global { interface HTMLElementTagNameMap { 'u-x': UX } }` lands in
10
+ * the main entry too — but it only keeps the declarations that entry itself reaches. The merge
11
+ * body survives while the class it names does not, so a consumer that type-checks libraries
12
+ * (`skipLibCheck: false`) fails with `TS2304: Cannot find name 'UX'` just for importing the
13
+ * package. The same happens when the entry has the name only as a value (a React wrapper `const`),
14
+ * which surfaces as `TS2749`.
15
+ *
16
+ * The fix keeps the augmentation (so `document.querySelector('u-x')` stays typed from any entry)
17
+ * and points each dangling name at the public entry that exports it:
18
+ * `'u-x': UX` becomes `'u-x': import('<package>/<subpath>').UX`. A tag whose class no entry
19
+ * exports is a composed-only internal, so its map value becomes `HTMLElement` — the most specific
20
+ * public type there is. Any other dangling name is left as it is: guessing would hide a real
21
+ * export gap, and the published-declaration compile check is what reports it.
22
+ *
23
+ * Call it from the declaration plugin's `afterBuild` hook, after the bundled `.d.ts` files exist.
24
+ */
25
+ export function fixPublishedDtsGlobals(packageRoot) {
26
+ const manifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8'));
27
+ const entries = declarationEntries(manifest.exports ?? {})
28
+ .map((entry) => ({ ...entry, path: resolve(packageRoot, entry.file) }))
29
+ .filter((entry) => existsSync(entry.path));
30
+ const sources = entries.map((entry) => ({ ...entry, source: readFileSync(entry.path, 'utf8') }));
31
+ const exportedFrom = indexExportedTypes(manifest.name, sources);
32
+ const globals = libGlobalNames(packageRoot);
33
+ for (const entry of sources) {
34
+ const fixed = resolveDanglingGlobals(entry.source, exportedFrom, globals);
35
+ if (fixed !== entry.source)
36
+ writeFileSync(entry.path, fixed);
37
+ }
38
+ }
39
+ /**
40
+ * Entry declaration files from the manifest's `exports`. A local manifest may point at `./src/…`
41
+ * because the publish workflow rewrites `src/` to `dist/`; the built file is always under `dist/`.
42
+ */
43
+ export function declarationEntries(exportsMap) {
44
+ const out = [];
45
+ for (const [key, target] of Object.entries(exportsMap)) {
46
+ if (!target || typeof target !== 'object')
47
+ continue;
48
+ const types = target.types;
49
+ if (typeof types !== 'string' || key.includes('*'))
50
+ continue;
51
+ out.push({ key, file: types.replace(/^\.\/src\//, './dist/') });
52
+ }
53
+ return out;
54
+ }
55
+ /**
56
+ * `name → specifier` for every type-capable name an entry exports publicly. The main entry wins
57
+ * when several entries export the same name.
58
+ */
59
+ export function indexExportedTypes(packageName, entries) {
60
+ const index = new Map();
61
+ const ordered = [...entries].sort((a, b) => (a.key === '.' ? -1 : b.key === '.' ? 1 : 0));
62
+ for (const { key, source } of ordered) {
63
+ const specifier = key === '.' ? packageName : `${packageName}/${key.replace(/^\.\//, '')}`;
64
+ for (const name of exportedTypeNames(source))
65
+ if (!index.has(name))
66
+ index.set(name, specifier);
67
+ }
68
+ return index;
69
+ }
70
+ /** Type-capable names a declaration file exports (`export declare class X` · `export { X }` of a declared `X`). */
71
+ export function exportedTypeNames(source) {
72
+ const declared = localTypeNames(source);
73
+ const exported = new Set();
74
+ for (const m of source.matchAll(/^export\s+declare\s+(?:abstract\s+)?(?:class|interface|type|enum)\s+([A-Za-z_$][\w$]*)/gm)) {
75
+ exported.add(m[1]);
76
+ }
77
+ for (const m of source.matchAll(/^export\s*\{([^}]*)\}\s*;?\s*$/gm)) {
78
+ for (const part of m[1].split(',')) {
79
+ const [local, alias] = part.trim().replace(/^type\s+/, '').split(/\s+as\s+/);
80
+ if (local && declared.has(local))
81
+ exported.add((alias ?? local).trim());
82
+ }
83
+ }
84
+ return exported;
85
+ }
86
+ /** Names a declaration file can use as types: its own type declarations and its imports. */
87
+ export function localTypeNames(source) {
88
+ const names = new Set();
89
+ for (const m of source.matchAll(/^\s*(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:class|interface|type|enum)\s+([A-Za-z_$][\w$]*)/gm)) {
90
+ names.add(m[1]);
91
+ }
92
+ for (const m of source.matchAll(/^\s*import\s+(?:type\s+)?([^;]*?)\s+from\s+['"][^'"]+['"]/gm)) {
93
+ const clause = m[1];
94
+ const named = clause.match(/\{([^}]*)\}/);
95
+ if (named) {
96
+ for (const part of named[1].split(',')) {
97
+ const bits = part.trim().replace(/^type\s+/, '').split(/\s+as\s+/);
98
+ const local = (bits[1] ?? bits[0]).trim();
99
+ if (local)
100
+ names.add(local);
101
+ }
102
+ }
103
+ const rest = clause.replace(/\{[^}]*\}/, '').replace(/\*\s+as\s+/, '').split(',');
104
+ for (const part of rest) {
105
+ const local = part.trim();
106
+ if (/^[A-Za-z_$][\w$]*$/.test(local))
107
+ names.add(local);
108
+ }
109
+ }
110
+ return names;
111
+ }
112
+ /**
113
+ * Global type names from the TypeScript `lib.*.d.ts` the package builds with (`HTMLElement`,
114
+ * `CustomEvent`, `HTMLDivElement` …). These are never dangling, so they are never rewritten —
115
+ * a tag mapped to a built-in element type keeps that type.
116
+ */
117
+ export function libGlobalNames(packageRoot) {
118
+ const names = new Set();
119
+ let libDir;
120
+ try {
121
+ libDir = dirname(createRequire(join(packageRoot, 'package.json')).resolve('typescript/package.json'));
122
+ }
123
+ catch {
124
+ return names;
125
+ }
126
+ const dir = join(libDir, 'lib');
127
+ for (const file of readdirSync(dir)) {
128
+ if (!/^lib\..*\.d\.ts$/.test(file))
129
+ continue;
130
+ const text = readFileSync(join(dir, file), 'utf8');
131
+ for (const m of text.matchAll(/^(?:declare\s+)?(?:interface|type|var|class)\s+([A-Za-z_$][\w$]*)/gm))
132
+ names.add(m[1]);
133
+ }
134
+ return names;
135
+ }
136
+ /**
137
+ * Rewrites the dangling names inside each top-level `declare global { … }` block of one
138
+ * declaration file (see `fixPublishedDtsGlobals`). Everything outside those blocks is untouched.
139
+ */
140
+ export function resolveDanglingGlobals(source, exportedFrom, globals = new Set()) {
141
+ const local = localTypeNames(source);
142
+ // A class the bundler inlined as a private copy (declared here, exported only by another entry) is a second nominal
143
+ // type for the same tag — merging both copies into one global map fails with TS2717. Point at the public one.
144
+ const exportedHere = exportedTypeNames(source);
145
+ for (const name of [...local]) {
146
+ if (exportedHere.has(name) || !exportedFrom.has(name))
147
+ continue;
148
+ const declared = new RegExp(`^\\s*(?:export\\s+)?(?:declare\\s+)?(?:abstract\\s+)?(?:class|interface|type|enum)\\s+${name}\\b`, 'm');
149
+ if (declared.test(source))
150
+ local.delete(name); // an import is an explicit binding — kept
151
+ }
152
+ for (const name of globals)
153
+ if (!exportedFrom.has(name))
154
+ local.add(name);
155
+ let out = '';
156
+ let cursor = 0;
157
+ const marker = /declare\s+global\s*\{/g;
158
+ for (let m = marker.exec(source); m; m = marker.exec(source)) {
159
+ const open = m.index + m[0].length - 1;
160
+ const close = matchingBrace(source, open);
161
+ if (close === -1)
162
+ break;
163
+ out += source.slice(cursor, open) + rewriteBlock(source.slice(open, close + 1), local, exportedFrom);
164
+ cursor = close + 1;
165
+ marker.lastIndex = cursor;
166
+ }
167
+ return out + source.slice(cursor);
168
+ }
169
+ function matchingBrace(text, open) {
170
+ let depth = 0;
171
+ for (let i = open; i < text.length; i++) {
172
+ if (text[i] === '{')
173
+ depth++;
174
+ else if (text[i] === '}' && --depth === 0)
175
+ return i;
176
+ }
177
+ return -1;
178
+ }
179
+ /**
180
+ * Walks one block, tracking which interface each position sits in, and rewrites type references.
181
+ * Skipped: quoted text, names right after `interface`/`namespace`/`extends` targets that are being
182
+ * declared, and qualified tails (`A.B` — only `A` is a reference).
183
+ */
184
+ function rewriteBlock(block, local, exportedFrom) {
185
+ const interfaces = [];
186
+ let pendingInterface = null;
187
+ let out = '';
188
+ let i = 0;
189
+ while (i < block.length) {
190
+ const ch = block[i];
191
+ if (ch === "'" || ch === '"' || ch === '`') {
192
+ const end = block.indexOf(ch, i + 1);
193
+ const stop = end === -1 ? block.length : end + 1;
194
+ out += block.slice(i, stop);
195
+ i = stop;
196
+ continue;
197
+ }
198
+ if (ch === '{') {
199
+ interfaces.push(pendingInterface);
200
+ pendingInterface = null;
201
+ out += ch;
202
+ i++;
203
+ continue;
204
+ }
205
+ if (ch === '}') {
206
+ interfaces.pop();
207
+ out += ch;
208
+ i++;
209
+ continue;
210
+ }
211
+ const word = /^[A-Za-z_$][\w$]*/.exec(block.slice(i));
212
+ if (!word) {
213
+ out += ch;
214
+ i++;
215
+ continue;
216
+ }
217
+ const name = word[0];
218
+ const before = out.trimEnd();
219
+ const declaresName = /\b(?:interface|namespace|class|type|enum)$/.test(before);
220
+ const qualifiedTail = before.endsWith('.');
221
+ if (declaresName && /\binterface$/.test(before))
222
+ pendingInterface = name;
223
+ if (!declaresName && !qualifiedTail && /^[A-Z]/.test(name) && !local.has(name)) {
224
+ const specifier = exportedFrom.get(name);
225
+ const inTagMap = interfaces[interfaces.length - 1] === 'HTMLElementTagNameMap';
226
+ if (specifier)
227
+ out += `import('${specifier}').${name}`;
228
+ else if (inTagMap && /:\s*$/.test(out))
229
+ out += 'HTMLElement';
230
+ else
231
+ out += name;
232
+ }
233
+ else {
234
+ out += name;
235
+ }
236
+ i += name.length;
237
+ }
238
+ return out;
239
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/components",
3
3
  "description": "web-components library based on lit-element made by iyulab",
4
- "version": "2.26.1",
4
+ "version": "2.27.1",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",