bestax-migrate 2.32.0 → 2.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/sources/_shared/html/parse.d.ts +10 -0
  2. package/dist/sources/_shared/html/parse.d.ts.map +1 -1
  3. package/dist/sources/_shared/html/parse.js +13 -1
  4. package/dist/sources/bulma-classes/class-map.d.ts +41 -11
  5. package/dist/sources/bulma-classes/class-map.d.ts.map +1 -1
  6. package/dist/sources/bulma-classes/class-map.js +101 -4
  7. package/dist/sources/bulma-classes/glyph.d.ts +22 -7
  8. package/dist/sources/bulma-classes/glyph.d.ts.map +1 -1
  9. package/dist/sources/bulma-classes/glyph.js +50 -20
  10. package/dist/sources/bulma-classes/html-assets.d.ts +8 -1
  11. package/dist/sources/bulma-classes/html-assets.d.ts.map +1 -1
  12. package/dist/sources/bulma-classes/html-assets.js +35 -8
  13. package/dist/sources/bulma-classes/html-extensions.d.ts +69 -0
  14. package/dist/sources/bulma-classes/html-extensions.d.ts.map +1 -0
  15. package/dist/sources/bulma-classes/html-extensions.js +146 -0
  16. package/dist/sources/bulma-classes/html-rules.d.ts +5 -0
  17. package/dist/sources/bulma-classes/html-rules.d.ts.map +1 -1
  18. package/dist/sources/bulma-classes/html-rules.js +6 -0
  19. package/dist/sources/bulma-classes/html.d.ts +3 -2
  20. package/dist/sources/bulma-classes/html.d.ts.map +1 -1
  21. package/dist/sources/bulma-classes/html.js +143 -33
  22. package/dist/sources/bulma-classes/plan.d.ts +25 -2
  23. package/dist/sources/bulma-classes/plan.d.ts.map +1 -1
  24. package/dist/sources/bulma-classes/plan.js +108 -11
  25. package/dist/sources/bulma-classes/transform.d.ts +20 -2
  26. package/dist/sources/bulma-classes/transform.d.ts.map +1 -1
  27. package/dist/sources/bulma-classes/transform.js +113 -11
  28. package/package.json +2 -2
@@ -23,8 +23,9 @@
23
23
  * file, so the CLI's manifest step reads the module the same way too.
24
24
  *
25
25
  * Nothing is ever overwritten: a module already beside the page stops it
26
- * (`html-file:exists`), so a second run changes nothing, and the page itself
27
- * stays as it was. A page with no Bulma component class writes nothing (a
26
+ * (`html-file:exists`), so a second run on the page changes nothing, and the
27
+ * page itself stays as it was. A re-run a TODO asks for is one on the module,
28
+ * which is what each says. A page with no Bulma component class writes nothing (a
28
29
  * Vite `index.html` is a page like any other), and a server template
29
30
  * (`{{`, `{%`, `<?php`, `<%`) is refused rather than read as HTML.
30
31
  */
@@ -33,23 +34,16 @@ import path from 'node:path';
33
34
  import { makeApi, runTransform } from '../../runner.js';
34
35
  import { isNumberProp, numberLiteral } from '../_shared/html/attributes.js';
35
36
  import { emitJsx } from '../_shared/html/emit.js';
36
- import { childrenOf, isElement, isText, parseHtml, } from '../_shared/html/parse.js';
37
+ import { attributeOf, childrenOf, classesOf, isElement, isText, parseHtml, } from '../_shared/html/parse.js';
37
38
  import { boxOfDisplay, uaDisplay, validInlineDisplay, } from '../_shared/html/whitespace.js';
38
39
  import { flaggableRoot } from './class-map.js';
39
40
  import { bulmaDisplay, bulmaOutOfFlow, HELPER_DISPLAY } from './display.js';
40
- import { bulmaBuildMessage, bulmaMediaMessage, bulmaStylesheetMessage, classifyAsset, extensionMessage, fontAwesomeMessage, jqueryMessage, PRIMARY_CLASS, scriptMessage, stylesheetMessage, webfontMessage, } from './html-assets.js';
41
+ import { bulmaBuildMessage, bulmaMediaMessage, bulmaStylesheetMessage, classifyAsset, extensionMessage, extensionPackage, fontAwesomeMessage, jqueryMessage, PRIMARY_CLASS, scriptMessage, stylesheetMessage, webfontMessage, } from './html-assets.js';
42
+ import { CAROUSEL_CLASS, carouselClassMessage, carouselSelectors, COVERED_SELECTOR, coveredMessage, drivenMessage, selectAll, } from './html-extensions.js';
41
43
  import { htmlRuleId, NAVBAR_FIXED_CLASSES, THEME_CLASSES, } from './html-rules.js';
42
44
  import { inNextApp, writesTypeScript } from './project.js';
43
45
  import transform, { FILE_RULES } from './transform.js';
44
46
  const HTML_NS = 'http://www.w3.org/1999/xhtml';
45
- function attributeOf(element, name) {
46
- return element.attrs.find(attr => attr.name === name && !attr.prefix)?.value;
47
- }
48
- function classesOf(element) {
49
- return (attributeOf(element, 'class') ?? '')
50
- .split(/[ \t\n\f\r]+/)
51
- .filter(Boolean);
52
- }
53
47
  function textContent(node) {
54
48
  return childrenOf(node)
55
49
  .map(child => isText(child) ? child.value : isElement(child) ? textContent(child) : '')
@@ -268,7 +262,7 @@ const SCRIPT_PATTERNS = [
268
262
  [
269
263
  'modal',
270
264
  /modal/,
271
- "opens or closes a modal: bestax's `Modal` shows while `active` is true and calls `onClose` from its background, its close button and Escape, so keep the open state in `useState`",
265
+ "opens or closes a modal: bestax's `Modal` shows while `active` is true and calls `onClose` on Escape and from a `Modal.Close` with no `onClick` of its own, while `Modal.Background` closes it only with `onClick={onClose}`, so keep the open state in `useState`",
272
266
  ],
273
267
  [
274
268
  'dismiss',
@@ -333,6 +327,14 @@ function scriptNotes(script, page) {
333
327
  ];
334
328
  }
335
329
  const code = textContent(script);
330
+ for (const selector of carouselSelectors(code)) {
331
+ page.carousels.push({
332
+ selector,
333
+ script: line === null
334
+ ? 'an inline script'
335
+ : `the inline script at line ${line}`,
336
+ });
337
+ }
336
338
  const found = SCRIPT_PATTERNS.filter(([, pattern]) => pattern.test(code));
337
339
  if (found.length === 0) {
338
340
  return [
@@ -402,10 +404,10 @@ function placeOf(url, dir) {
402
404
  * the patterns that name what they drive. Null when it can't be read, is too
403
405
  * large to be the page's own, or shows none of them.
404
406
  */
405
- function localScriptNotes(quoted, target, dir, line) {
407
+ function localScriptNotes(quoted, target, page, line) {
406
408
  let code;
407
409
  try {
408
- const file = path.resolve(dir, target);
410
+ const file = path.resolve(page.dir, target);
409
411
  if (fs.statSync(file).size > LOCAL_SCRIPT_LIMIT)
410
412
  return null;
411
413
  code = fs.readFileSync(file, 'utf8');
@@ -413,6 +415,12 @@ function localScriptNotes(quoted, target, dir, line) {
413
415
  catch {
414
416
  return null;
415
417
  }
418
+ for (const selector of carouselSelectors(code)) {
419
+ page.carousels.push({
420
+ selector,
421
+ script: `the page's script \`${quoted}\``,
422
+ });
423
+ }
416
424
  const found = LOCAL_SCRIPT_PATTERNS.filter(([, pattern]) => pattern.test(code));
417
425
  if (found.length === 0)
418
426
  return null;
@@ -543,7 +551,7 @@ function assetNotes(page, root) {
543
551
  case 'script': {
544
552
  const { place, target } = placeOf(load.url, page.dir);
545
553
  const local = place === 'beside'
546
- ? localScriptNotes(quoted, target, page.dir, load.line)
554
+ ? localScriptNotes(quoted, target, page, load.line)
547
555
  : null;
548
556
  if (local)
549
557
  notes.push(...local);
@@ -575,7 +583,10 @@ function assetNotes(page, root) {
575
583
  }
576
584
  else {
577
585
  rule = htmlRuleId('html-asset', 'bulma-extension');
578
- message = extensionMessage(asset.name, quoted, new Set(loads.map(load => load.loads)), page.css);
586
+ const kinds = new Set(loads.map(load => load.loads));
587
+ message = extensionMessage(asset.name, quoted, kinds, page.css,
588
+ // Its stylesheet is what crops them (`extensionNotes`).
589
+ kinds.has('stylesheet') && page.covered.length > 0);
579
590
  }
580
591
  if (message === null)
581
592
  continue;
@@ -588,6 +599,83 @@ function assetNotes(page, root) {
588
599
  }
589
600
  return { notes, importsBulma };
590
601
  }
602
+ /** Where a note about several elements goes: the first, and every line. */
603
+ function atElements(elements) {
604
+ const lines = [
605
+ ...new Set(elements.flatMap(element => {
606
+ const line = element.sourceCodeLocation?.startLine;
607
+ return line === undefined ? [] : [line];
608
+ })),
609
+ ];
610
+ return {
611
+ line: elements[0].sourceCodeLocation?.startLine ?? null,
612
+ ...(lines.length > 1 ? { lines } : {}),
613
+ };
614
+ }
615
+ /**
616
+ * bulma-carousel's own markup, which no component converts: each selector
617
+ * the page's scripts attach it to, at the elements it matches; the
618
+ * `carousel` class anywhere else, on a page that uses bulma-carousel; and
619
+ * `is-covered` on an `.image`, on a page that loads its stylesheet, the one
620
+ * thing that styles it. A selector the codemod can't read, or that matches
621
+ * nothing, has no note of its own: the script's note still stands.
622
+ */
623
+ function extensionNotes(root, page) {
624
+ const notes = [];
625
+ const extensions = page.loads.flatMap(load => {
626
+ const asset = classifyAsset(load.url, load.loads);
627
+ return asset.kind === 'bulma-extension'
628
+ ? [{ name: extensionPackage(asset.name), loads: load.loads }]
629
+ : [];
630
+ });
631
+ const driven = new Set();
632
+ const read = new Set();
633
+ for (const { selector, script } of page.carousels) {
634
+ if (read.has(selector))
635
+ continue;
636
+ read.add(selector);
637
+ const elements = selectAll(root, selector, page.quirks) ?? [];
638
+ if (elements.length === 0)
639
+ continue;
640
+ for (const element of elements)
641
+ driven.add(element);
642
+ const ids = new Set(elements.map(element => attributeOf(element, 'id')));
643
+ notes.push({
644
+ rule: htmlRuleId('html-extension', 'carousel'),
645
+ message: drivenMessage({
646
+ selector: quote(selector, 40),
647
+ script,
648
+ count: elements.length,
649
+ sharedId: elements.length > 1 && ids.size === 1 ? [...ids][0] : undefined,
650
+ carouselClass: elements.some(element => classesOf(element).includes(CAROUSEL_CLASS)),
651
+ }),
652
+ ...atElements(elements),
653
+ });
654
+ }
655
+ const usesCarousel = page.carousels.length > 0 ||
656
+ extensions.some(({ name }) => ['bulma-carousel', 'bulma-extensions'].includes(name));
657
+ // A class's TODO is about the app's stylesheets, which read it in its own
658
+ // case: only what a script selects follows the page's quirks.
659
+ const classed = usesCarousel
660
+ ? selectAll(root, `.${CAROUSEL_CLASS}`, false).filter(element => !driven.has(element))
661
+ : [];
662
+ if (classed.length > 0) {
663
+ notes.push({
664
+ rule: htmlRuleId('html-extension', 'carousel'),
665
+ message: carouselClassMessage(),
666
+ ...atElements(classed),
667
+ });
668
+ }
669
+ const cropped = extensions.some(({ name, loads }) => name === 'bulma-carousel' && loads === 'stylesheet');
670
+ if (cropped && page.covered.length > 0) {
671
+ notes.push({
672
+ rule: htmlRuleId('html-extension', 'is-covered'),
673
+ message: coveredMessage(),
674
+ ...atElements(page.covered),
675
+ });
676
+ }
677
+ return notes;
678
+ }
591
679
  /** A `<meta http-equiv>` that sets the page's Content Security Policy. */
592
680
  function isCsp(meta) {
593
681
  return ((attributeOf(meta, 'http-equiv') ?? '').trim().toLowerCase() ===
@@ -1192,7 +1280,7 @@ export function convertPage(file, source, collector, options = {}) {
1192
1280
  file,
1193
1281
  line: null,
1194
1282
  rule: htmlRuleId('html-file', 'exists'),
1195
- message: `\`${path.basename(outputPath)}\` is already beside the page, and the codemod never overwrites a file: move or delete it to convert the page again`,
1283
+ message: `\`${path.basename(outputPath)}\` is already beside the page, and the codemod never overwrites a file: to carry on from the TODOs it holds, run the codemod on \`${path.basename(outputPath)}\` itself, and to convert the page again, move or delete it`,
1196
1284
  }, outputPath);
1197
1285
  }
1198
1286
  const template = TEMPLATE_SYNTAX.exec(source);
@@ -1209,7 +1297,11 @@ export function convertPage(file, source, collector, options = {}) {
1209
1297
  dir: path.dirname(file),
1210
1298
  css: options.cssMode ?? 'keep',
1211
1299
  nextjs: inNextApp(file, options.packageLanguages),
1300
+ quirks: parsed.quirks,
1212
1301
  loads: [],
1302
+ carousels: [],
1303
+ // In its own case, as the rule the TODO gives the app reads it.
1304
+ covered: selectAll(parsed.root, COVERED_SELECTOR, false),
1213
1305
  };
1214
1306
  parseNotes(parsed, notes.document);
1215
1307
  headNotes(parsed.head, notes.document, context);
@@ -1221,6 +1313,7 @@ export function convertPage(file, source, collector, options = {}) {
1221
1313
  dropScripts(parsed.root, notes.document, context);
1222
1314
  const assets = assetNotes(context, parsed.root);
1223
1315
  notes.document.push(...assets.notes);
1316
+ notes.content.push(...extensionNotes(parsed.root, context));
1224
1317
  const emitted = emitJsx(parsed.root, {
1225
1318
  displayOf: pageDisplayOf,
1226
1319
  indent: 2,
@@ -1255,6 +1348,9 @@ export function convertPage(file, source, collector, options = {}) {
1255
1348
  }
1256
1349
  // The transform reads the module's path, so the gates for a server
1257
1350
  // component or another JSX runtime apply to it; its report names the page.
1351
+ // A re-run its TODOs ask for is one on the module, since the page converts
1352
+ // only once (`html-file:exists`), so they say so.
1353
+ const moduleName = path.basename(outputPath);
1258
1354
  const planned = new Map();
1259
1355
  const onPage = {
1260
1356
  add: entry => {
@@ -1264,11 +1360,15 @@ export function convertPage(file, source, collector, options = {}) {
1264
1360
  // A file-level gate's TODO is about the whole page, so it gets no
1265
1361
  // page line of the element it sits on.
1266
1362
  const forFile = FILE_RULES.includes(entry.rule);
1267
- if (line !== null && !forFile) {
1268
- const text = todoText(entry.message);
1269
- planned.set(text, [...(planned.get(text) ?? []), line]);
1270
- }
1271
- collector?.add({ ...entry, file, line });
1363
+ const text = todoText(entry.message);
1364
+ const lines = planned.get(text) ?? [];
1365
+ planned.set(text, line !== null && !forFile ? [...lines, line] : lines);
1366
+ collector?.add({
1367
+ ...entry,
1368
+ message: rerunOn(entry.message, moduleName),
1369
+ file,
1370
+ line,
1371
+ });
1272
1372
  },
1273
1373
  };
1274
1374
  const { output } = runTransform(transform, outputPath, intermediate, onPage, {
@@ -1277,34 +1377,44 @@ export function convertPage(file, source, collector, options = {}) {
1277
1377
  });
1278
1378
  return {
1279
1379
  outputPath,
1280
- output: finishModule(withPageLines(output ?? intermediate, planned, page)),
1380
+ output: finishModule(withPageLines(output ?? intermediate, planned, page, moduleName)),
1281
1381
  intermediate,
1282
1382
  };
1283
1383
  }
1384
+ /**
1385
+ * A TODO from a page's run with each re-run it asks for named as one on its
1386
+ * module: run again on the page, the codemod writes nothing.
1387
+ */
1388
+ function rerunOn(message, moduleName) {
1389
+ return message.replace(/\bre-run\b/g, `re-run on \`${moduleName}\``);
1390
+ }
1284
1391
  /** A TODO's message as its comment writes it, on one line. */
1285
1392
  function todoText(message) {
1286
1393
  return message.replace(/[\r\n\u2028\u2029]+/g, ' ').trim();
1287
1394
  }
1288
1395
  /**
1289
- * The planner's TODO lines, each with the page's lines it is about. The
1290
- * transform writes one line for each message, however many elements share
1291
- * it (five `.icon`s missing the same attribute), above the `return`, so the
1292
- * lines go on after, the way the page's own notes carry theirs. Nothing from
1293
- * the `return` on is read, since the page's text is there.
1396
+ * The transform's TODO lines, each with its re-runs named as ones on the
1397
+ * module and the page's lines it is about, if any. The transform writes one
1398
+ * line for each message, however many elements share it (five `.icon`s
1399
+ * missing the same attribute), above the `return`, so the lines go on after,
1400
+ * the way the page's own notes carry theirs. Nothing from the `return` on is
1401
+ * read, since the page's text is there.
1294
1402
  */
1295
- function withPageLines(code, planned, page) {
1403
+ function withPageLines(code, planned, page, moduleName) {
1296
1404
  if (planned.size === 0)
1297
1405
  return code;
1298
1406
  const lines = code.split('\n');
1299
1407
  for (let i = 0; i < lines.length; i++) {
1300
1408
  if (/^\s*return\b/.test(lines[i]))
1301
1409
  break;
1302
- const todo = /^\s*\/\/ TODO\(bestax-migrate\): (.*)$/.exec(lines[i]);
1303
- const on = todo ? planned.get(todo[1]) : undefined;
1410
+ const todo = /^(\s*\/\/ TODO\(bestax-migrate\): )(.*)$/.exec(lines[i]);
1411
+ const on = todo ? planned.get(todo[2]) : undefined;
1304
1412
  if (!on)
1305
1413
  continue;
1306
1414
  const at = [...new Set(on)].sort((a, b) => a - b).join(', ');
1307
- lines[i] = `${lines[i]} (${page}:${at})`;
1415
+ lines[i] =
1416
+ `${todo[1]}${rerunOn(todo[2], moduleName)}` +
1417
+ (at === '' ? '' : ` (${page}:${at})`);
1308
1418
  }
1309
1419
  return lines.join('\n');
1310
1420
  }
@@ -11,8 +11,14 @@
11
11
  * `<i aria-hidden="true">` alone in a `.icon` that carries nothing assistive
12
12
  * tech reads (the table's `hiddenMovesBeside`) converts to `Icon`, which writes that attribute
13
13
  * on the `.icon` instead (`movesHidden`), since the glyph is hidden either
14
- * way. And a Bulma 0.9 helper v1 removed (`REPLACED_IN_V1`), which styles
15
- * nothing under v1, converts as the v1 helper that does its job.
14
+ * way. A `.icon` like it around a bare glyph, in a link or button its own
15
+ * `aria-label` or `aria-labelledby` names, converts too, and `Icon` writes
16
+ * the attribute it doesn't carry (`addsHidden`), since that label is what
17
+ * assistive tech reads for the control. Font Awesome 6's long name for a
18
+ * style is written as the bestax-icons skill's `variant`, which `Icon`
19
+ * renders as the short name, the same style (`glyph.ts`, `longStyle`). And a
20
+ * Bulma 0.9 helper v1 removed (`REPLACED_IN_V1`), which styles nothing under
21
+ * v1, converts as the v1 helper that does its job.
16
22
  */
17
23
  import { type Glyph } from './glyph.js';
18
24
  export interface ElementFacts {
@@ -140,6 +146,14 @@ export interface ElementFacts {
140
146
  clickableAround?: {
141
147
  tag: string;
142
148
  label?: 'aria-label' | 'aria-labelledby' | 'text' | 'none';
149
+ /**
150
+ * For an <a>: true when it has an `href` written out as a string, so it
151
+ * is a link, and false when it has neither an `href` nor a `role`, so it
152
+ * has no role at all and ARIA lets nothing name it. Left out when that
153
+ * can't be told from here (an `href` written as an expression, or a
154
+ * `role` of its own).
155
+ */
156
+ link?: boolean;
143
157
  };
144
158
  }
145
159
  export interface ChildFacts {
@@ -231,6 +245,15 @@ export interface Conversion {
231
245
  * attribute moved up, and nothing else.
232
246
  */
233
247
  movesHidden?: true;
248
+ /**
249
+ * The element carried no `aria-hidden`, and sits in a link or a <button>
250
+ * its own `aria-label` or `aria-labelledby` names, which assistive tech
251
+ * reads in place of what the control holds: the target writes the
252
+ * attribute on it, a way a conversion's markup differs on purpose, since
253
+ * nothing assistive tech reads changes. The render tests compare it with
254
+ * the attribute restated, and nothing else.
255
+ */
256
+ addsHidden?: true;
234
257
  /**
235
258
  * The target renders the bare element around this one too: the component
236
259
  * takes that element's place, with its `key`.
@@ -1 +1 @@
1
- {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAwBH,OAAO,EAKL,KAAK,KAAK,EACX,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC,SA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GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IACvE,0EAA0E;IAC1E,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,yDAAyD;IACzD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,2DAA2D;IAC3D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B;;;OAGG;IACH,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;QACnD,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IACF,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAuLD,wBAAgB,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CA+B9C"}
@@ -11,8 +11,14 @@
11
11
  * `<i aria-hidden="true">` alone in a `.icon` that carries nothing assistive
12
12
  * tech reads (the table's `hiddenMovesBeside`) converts to `Icon`, which writes that attribute
13
13
  * on the `.icon` instead (`movesHidden`), since the glyph is hidden either
14
- * way. And a Bulma 0.9 helper v1 removed (`REPLACED_IN_V1`), which styles
15
- * nothing under v1, converts as the v1 helper that does its job.
14
+ * way. A `.icon` like it around a bare glyph, in a link or button its own
15
+ * `aria-label` or `aria-labelledby` names, converts too, and `Icon` writes
16
+ * the attribute it doesn't carry (`addsHidden`), since that label is what
17
+ * assistive tech reads for the control. Font Awesome 6's long name for a
18
+ * style is written as the bestax-icons skill's `variant`, which `Icon`
19
+ * renders as the short name, the same style (`glyph.ts`, `longStyle`). And a
20
+ * Bulma 0.9 helper v1 removed (`REPLACED_IN_V1`), which styles nothing under
21
+ * v1, converts as the v1 helper that does its job.
16
22
  */
17
23
  import { FORWARDS_REF, HELPER_PROPS, HELPER_TOKENS, inTagSet, legacyHint, modifierFor, modifiesRoot, numberAttrsOf, placedFor, PRECEDENCE, reachesTag, replacedBy, rootFor, rootItNeeds, tagFit, WRAPPER_OWN_PROPS, wrapperFor, } from './class-map.js';
18
24
  import { glyphProps, readDrawnGlyph, readGlyph, readHiddenGlyph, } from './glyph.js';
@@ -176,8 +182,23 @@ function offTagSizes(entry, root, target, tag, tokens, converted, writes) {
176
182
  function carriedBy(facts) {
177
183
  return [...new Set([...facts.tokens, ...(facts.conditional ?? []).flat()])];
178
184
  }
185
+ /**
186
+ * What a TODO that promises a re-run says instead once its element converts:
187
+ * the next run plans no component, so the re-run would do nothing, and the
188
+ * fix is by hand.
189
+ */
190
+ const BY_HAND = new WeakMap();
179
191
  export function plan(facts) {
180
- const result = planElement(facts);
192
+ const planned = planElement(facts);
193
+ const result = planned.conversion
194
+ ? {
195
+ ...planned,
196
+ todos: planned.todos.map(todo => {
197
+ const byHand = BY_HAND.get(todo);
198
+ return byHand === undefined ? todo : { ...todo, message: byHand };
199
+ }),
200
+ }
201
+ : planned;
181
202
  // A Bulma 0.9 helper v1 removed converts as the v1 helper that replaced
182
203
  // it, and only one that stays a class gets the TODO naming that helper:
183
204
  // where it converted, nothing is left to do.
@@ -221,13 +242,17 @@ function planElement(facts) {
221
242
  })) {
222
243
  const needed = rootFor(root);
223
244
  const article = /^[aeiou]/.test(root) ? 'an' : 'a';
224
- const fix = reachesTag(needed, tag)
245
+ const rerun = reachesTag(needed, tag);
246
+ const fix = rerun
225
247
  ? `add \`${root}\`, which bestax \`${needed.target}\` renders, then re-run`
226
248
  : `add \`${root}\` for Bulma to style it, though bestax \`${needed.target}\` renders ${tagsItReaches(needed)}, not ${aTag(tag)}, so the element stays markup`;
227
- todos.push({
228
- rule: ruleId('modifier', root),
229
- message: `\`${token}\` is ${article} \`.${root}\` modifier, and Bulma styles it only on the element that carries \`.${root}\`, so on this one it styles nothing unless the project's own CSS gives it a rule; if this element is the ${root}, ${fix}, and otherwise drop the class`,
230
- });
249
+ const says = (remedy) => `\`${token}\` is ${article} \`.${root}\` modifier, and Bulma styles it only on the element that carries \`.${root}\`, so on this one it styles nothing unless the project's own CSS gives it a rule; if this element is the ${root}, ${remedy}, and otherwise drop the class`;
250
+ const todo = { rule: ruleId('modifier', root), message: says(fix) };
251
+ // On an element that converts anyway, a re-run finds a component.
252
+ if (rerun) {
253
+ BY_HAND.set(todo, says(`convert it to bestax \`${needed.target}\` by hand`));
254
+ }
255
+ todos.push(todo);
231
256
  }
232
257
  }
233
258
  // A family this source leaves as markup keeps its element as markup, even
@@ -425,8 +450,39 @@ function planElement(facts) {
425
450
  [...attributes.keys()].every(name => movesBeside(entry, name))
426
451
  ? readHiddenGlyph(facts.soleChild)
427
452
  : undefined;
428
- const missing = [...Object.entries(defaults), ...written].filter(([name]) => !attributes.has(name) && !(moved && name === 'aria-hidden'));
453
+ // An icon in a link or <button> its own label names is decoration there:
454
+ // that label is what assistive tech reads for the control, in place of
455
+ // what it holds, so the `aria-hidden` the target writes changes nothing it
456
+ // reads. Another difference in markup a conversion makes on purpose, held
457
+ // to the same shape: a bare glyph the target renders from props, in an
458
+ // element that carries nothing else assistive tech reads. The render tests
459
+ // compare it with the attribute restated.
460
+ const decorates = !moved &&
461
+ entry.readsGlyph &&
462
+ naming === 'unnamed' &&
463
+ defaults['aria-hidden'] === 'true' &&
464
+ !attributes.has('aria-hidden') &&
465
+ [...attributes.keys()].every(name => movesBeside(entry, name)) &&
466
+ namesItsContent(facts.clickableAround)
467
+ ? readGlyph(facts.soleChild)
468
+ : undefined;
469
+ const missing = [...Object.entries(defaults), ...written].filter(([name]) => !attributes.has(name) && !((moved || decorates) && name === 'aria-hidden'));
429
470
  const drop = [];
471
+ // A target that renders a glyph from props is written the way the
472
+ // bestax-icons skill writes it, with no attribute it renders by itself
473
+ // with the same value (`aria-hidden="true"` with no name, `role="img"`
474
+ // beside one): the markup is the same without it.
475
+ // A `role` or `tabIndex` written as an expression may stop those
476
+ // defaults at run time, so the element keeps what it wrote.
477
+ const mayStop = entry.defaultsUnless?.some(name => attributes.has(name) && attributes.get(name) === null);
478
+ if (entry.readsGlyph && naming !== 'unsure' && !mayStop) {
479
+ for (const [name, value] of Object.entries(defaults)) {
480
+ const given = attributes.get(name);
481
+ if (given === value || (given === true && value === 'true')) {
482
+ drop.push(name);
483
+ }
484
+ }
485
+ }
430
486
  for (const name of entry.untypedAttrs ?? []) {
431
487
  if (!attributes.has(name))
432
488
  continue;
@@ -630,7 +686,9 @@ function planElement(facts) {
630
686
  todos.push(...secondColors(entry, root, target, tokens, converted, writes));
631
687
  todos.push(...offTagSizes(entry, root, target, tag, tokens, converted, writes));
632
688
  // A glyph the target renders from props takes the place of the only child.
633
- const glyph = moved ?? (entry.readsGlyph ? readGlyph(facts.soleChild) : undefined);
689
+ const glyph = moved ??
690
+ decorates ??
691
+ (entry.readsGlyph ? readGlyph(facts.soleChild) : undefined);
634
692
  return {
635
693
  conversion: {
636
694
  target,
@@ -644,6 +702,7 @@ function planElement(facts) {
644
702
  : {}),
645
703
  ...(glyph ? { glyph } : {}),
646
704
  ...(moved ? { movesHidden: true } : {}),
705
+ ...(decorates ? { addsHidden: true } : {}),
647
706
  ...(parent ? { replacesParent: true } : {}),
648
707
  ...(conditional.length > 0 ? { conditional } : {}),
649
708
  ...(icons ? { icons } : {}),
@@ -757,6 +816,16 @@ function movesBeside(entry, name) {
757
816
  ? name.startsWith(allowed.slice(0, -1))
758
817
  : name === allowed);
759
818
  }
819
+ /**
820
+ * Whether the link or <button> around an element names itself with its own
821
+ * `aria-label` or `aria-labelledby`, which assistive tech reads for it in
822
+ * place of what it holds. An <a> counts only as a link: one with no `href`
823
+ * has no role, and ARIA lets nothing name it.
824
+ */
825
+ function namesItsContent(around) {
826
+ return ((around?.label === 'aria-label' || around?.label === 'aria-labelledby') &&
827
+ (around.tag === 'button' || around.link === true));
828
+ }
760
829
  /**
761
830
  * What to do about an unnamed element whose target hides it with an
762
831
  * `aria-hidden` it doesn't carry, and that renders a glyph from props
@@ -813,12 +882,40 @@ function hiddenAdvice(facts, entry, usual) {
813
882
  const around = facts.clickableAround;
814
883
  const label = around?.label;
815
884
  const tag = around && aTag(around.tag);
885
+ // An <a> with no `href` and no `role` is no link, and has no role at all,
886
+ // so ARIA lets nothing name it: it needs an `href`, or to be a <button>,
887
+ // before a label does anything.
888
+ const unlinked = around?.tag === 'a' && around.link === false;
889
+ const hide = `add \`aria-hidden="true"\` here, which bestax \`${target}\` writes on an icon with no name of its own`;
890
+ // What a re-run converts this to once the control around it names itself
891
+ // and is a link, where an icon converts as it is (`namesItsContent`). Only
892
+ // from a control that isn't both yet, so the planner asks once.
893
+ const labelled = label === 'aria-label' || label === 'aria-labelledby';
894
+ const fixed = around && (unlinked || label === 'none')
895
+ ? plan({
896
+ ...facts,
897
+ clickableAround: {
898
+ ...around,
899
+ ...(!labelled && { label: 'aria-label' }),
900
+ ...(unlinked && { link: true }),
901
+ },
902
+ }).conversion
903
+ : undefined;
904
+ const once = fixed?.glyph
905
+ ? `re-run, and this converts to \`${target}\` with ${jsxProps(glyphProps(fixed.glyph))}, which hides the icon with \`aria-hidden="true"\`${hint}`
906
+ : undefined;
907
+ if (unlinked && labelled) {
908
+ return `this \`.icon\` sits in an <a> with no \`href\`, which is no link and has no role, so ARIA lets nothing name it and its \`${label}\` names nothing; give the <a> an \`href\`, or make it a <button>, then ${once ?? `${hide}, and re-run${outcome}${hint}`}`;
909
+ }
816
910
  if (label && label !== 'none') {
817
911
  const by = label === 'text' ? 'its own text' : `its \`${label}\``;
818
912
  return `this \`.icon\` sits in ${tag} that ${by} names, so the icon is decoration there, and bestax \`${target}\` writes \`aria-hidden="true"\` on an icon with no name of its own, which this one doesn't carry; add it, then re-run${outcome}${hint}`;
819
913
  }
820
914
  if (label === 'none' && readGlyph(sole)) {
821
- return `nothing names the <${around.tag}> around this \`.icon\`: it has no \`aria-label\` and no text outside its icons, and a font icon's glyph is no name a screen reader can read; give the <${around.tag}> an \`aria-label\` that says what it does, then add \`aria-hidden="true"\` here, which bestax \`${target}\` writes on an icon with no name of its own, and re-run${outcome}${hint}`;
915
+ const name = unlinked
916
+ ? 'an `href`, or make it a <button>, and give it an `aria-label` that says what it does'
917
+ : 'an `aria-label` that says what it does';
918
+ return `nothing names the <${around.tag}> around this \`.icon\`: it has no \`aria-label\` and no text outside its icons, and a font icon's glyph is no name a screen reader can read; give the <${around.tag}> ${name}, then ${once ?? `${hide}, and re-run${outcome}${hint}`}`;
822
919
  }
823
920
  return `${usual}${outcome}${hint}`;
824
921
  }
@@ -5,8 +5,9 @@
5
5
  * scope when a lowercase JSX element carries a `className` with a Bulma class
6
6
  * `class-map.ts` knows. Each such element goes through `plan()`, which
7
7
  * converts it only when the component renders exactly the same markup, but
8
- * for the exceptions it states (Font Awesome's hidden `<i>`, and a Bulma 0.9
9
- * helper v1 removed).
8
+ * for the exceptions it states (Font Awesome's hidden `<i>`, an icon in a
9
+ * link or button its own label names, Font Awesome 6's long name for a
10
+ * style, and a Bulma 0.9 helper v1 removed).
10
11
  *
11
12
  * Passes, in order:
12
13
  * 1. the shared stylesheet-import pass (a no-op under the default `keep`)
@@ -17,6 +18,9 @@
17
18
  * Next.js server component (bestax's components are client components)
18
19
  * 4. TODOs in reading order; conversions innermost first
19
20
  * 5. write the bestax import, after the file's last import
21
+ * 6. settle the TODOs an earlier run wrote: one this run writes again keeps
22
+ * its earlier copy, and one that asked for a re-run it no longer writes
23
+ * goes (`settleTodos`)
20
24
  */
21
25
  import type { API, FileInfo } from 'jscodeshift';
22
26
  import type { TransformOptions } from '../../types.js';
@@ -25,6 +29,20 @@ import type { TransformOptions } from '../../types.js';
25
29
  * the file, though it sits on the first element that would convert, so no
26
30
  * line of the file is where it came from.
27
31
  */
32
+ /**
33
+ * A `TODO(bestax-migrate)` line comment's message as a run compares it: the
34
+ * page's lines an HTML page's module adds after it left out, and a re-run it
35
+ * asks for on a named file read as any re-run. So a re-run on that module
36
+ * finds the TODOs it writes again in the ones the page's run wrote.
37
+ */
38
+ export declare function todoKey(text: string): string;
39
+ /**
40
+ * The packages the library sources migrate from. A file that still imports
41
+ * one may hold that source's TODOs, which ask for a re-run of it, not of
42
+ * this one, so this one leaves every TODO there as it is. A new library
43
+ * source joins this list.
44
+ */
45
+ export declare const LIBRARY_SOURCES: RegExp;
28
46
  export declare const FILE_RULES: readonly ["jsx-runtime", "imports", "styled-jsx", "rsc"];
29
47
  export default function transform(fileInfo: FileInfo, api: API, options?: TransformOptions): string | undefined;
30
48
  //# sourceMappingURL=transform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AA+iCvD;;;;GAIG;AACH,eAAO,MAAM,UAAU,0DAKb,CAAC;AAGX,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,SAAS,CA89BpB"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/sources/bulma-classes/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAmkCvD;;;;GAIG;AACH;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM5C;AASD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QACuB,CAAC;AAEpD,eAAO,MAAM,UAAU,0DAKb,CAAC;AAGX,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,SAAS,CAwhCpB"}