bestax-migrate 2.32.1 → 2.34.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.
@@ -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
  */
@@ -37,7 +38,7 @@ import { attributeOf, childrenOf, classesOf, isElement, isText, parseHtml, } fro
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, extensionPackage, fontAwesomeMessage, jqueryMessage, PRIMARY_CLASS, scriptMessage, stylesheetMessage, webfontMessage, } from './html-assets.js';
41
+ import { bulmaBuildMessage, bulmaMediaMessage, bulmaStylesheetMessage, classifyAsset, extensionMessage, extensionPackage, fontAwesomeMessage, jqueryMessage, PRIMARY_CLASS, scriptMessage, socialBrand, stylesheetMessage, webfontMessage, } from './html-assets.js';
41
42
  import { CAROUSEL_CLASS, carouselClassMessage, carouselSelectors, COVERED_SELECTOR, coveredMessage, drivenMessage, selectAll, } from './html-extensions.js';
42
43
  import { htmlRuleId, NAVBAR_FIXED_CLASSES, THEME_CLASSES, } from './html-rules.js';
43
44
  import { inNextApp, writesTypeScript } from './project.js';
@@ -261,7 +262,7 @@ const SCRIPT_PATTERNS = [
261
262
  [
262
263
  'modal',
263
264
  /modal/,
264
- "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`",
265
266
  ],
266
267
  [
267
268
  'dismiss',
@@ -492,6 +493,27 @@ function usesPrimary(root) {
492
493
  (classesOf(child).some(token => PRIMARY_CLASS.test(token)) ||
493
494
  usesPrimary(child)));
494
495
  }
496
+ /**
497
+ * The bulma-social brands the page's markup shows (`socialBrand`), each once,
498
+ * in the order the page first shows it.
499
+ */
500
+ function socialBrands(root) {
501
+ const found = new Set();
502
+ const visit = (parent) => {
503
+ for (const child of childrenOf(parent)) {
504
+ if (!isElement(child))
505
+ continue;
506
+ for (const token of classesOf(child)) {
507
+ const brand = socialBrand(token);
508
+ if (brand !== null)
509
+ found.add(brand);
510
+ }
511
+ visit(child);
512
+ }
513
+ };
514
+ visit(root);
515
+ return [...found];
516
+ }
495
517
  /**
496
518
  * The stylesheets and scripts the page loads, as notes: one for each, but
497
519
  * one for an extension's stylesheet and script together, since they are one
@@ -583,9 +605,12 @@ function assetNotes(page, root) {
583
605
  else {
584
606
  rule = htmlRuleId('html-asset', 'bulma-extension');
585
607
  const kinds = new Set(loads.map(load => load.loads));
586
- message = extensionMessage(asset.name, quoted, kinds, page.css,
587
- // Its stylesheet is what crops them (`extensionNotes`).
588
- kinds.has('stylesheet') && page.covered.length > 0);
608
+ const { name } = asset;
609
+ message = extensionMessage(name, quoted, kinds, page.css, {
610
+ // Its stylesheet is what crops them (`extensionNotes`).
611
+ covered: kinds.has('stylesheet') && page.covered.length > 0,
612
+ brands: extensionPackage(name) === 'bulma-social' ? socialBrands(root) : [],
613
+ });
589
614
  }
590
615
  if (message === null)
591
616
  continue;
@@ -1279,7 +1304,7 @@ export function convertPage(file, source, collector, options = {}) {
1279
1304
  file,
1280
1305
  line: null,
1281
1306
  rule: htmlRuleId('html-file', 'exists'),
1282
- 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`,
1307
+ 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`,
1283
1308
  }, outputPath);
1284
1309
  }
1285
1310
  const template = TEMPLATE_SYNTAX.exec(source);
@@ -1347,6 +1372,9 @@ export function convertPage(file, source, collector, options = {}) {
1347
1372
  }
1348
1373
  // The transform reads the module's path, so the gates for a server
1349
1374
  // component or another JSX runtime apply to it; its report names the page.
1375
+ // A re-run its TODOs ask for is one on the module, since the page converts
1376
+ // only once (`html-file:exists`), so they say so.
1377
+ const moduleName = path.basename(outputPath);
1350
1378
  const planned = new Map();
1351
1379
  const onPage = {
1352
1380
  add: entry => {
@@ -1356,11 +1384,15 @@ export function convertPage(file, source, collector, options = {}) {
1356
1384
  // A file-level gate's TODO is about the whole page, so it gets no
1357
1385
  // page line of the element it sits on.
1358
1386
  const forFile = FILE_RULES.includes(entry.rule);
1359
- if (line !== null && !forFile) {
1360
- const text = todoText(entry.message);
1361
- planned.set(text, [...(planned.get(text) ?? []), line]);
1362
- }
1363
- collector?.add({ ...entry, file, line });
1387
+ const text = todoText(entry.message);
1388
+ const lines = planned.get(text) ?? [];
1389
+ planned.set(text, line !== null && !forFile ? [...lines, line] : lines);
1390
+ collector?.add({
1391
+ ...entry,
1392
+ message: rerunOn(entry.message, moduleName),
1393
+ file,
1394
+ line,
1395
+ });
1364
1396
  },
1365
1397
  };
1366
1398
  const { output } = runTransform(transform, outputPath, intermediate, onPage, {
@@ -1369,34 +1401,44 @@ export function convertPage(file, source, collector, options = {}) {
1369
1401
  });
1370
1402
  return {
1371
1403
  outputPath,
1372
- output: finishModule(withPageLines(output ?? intermediate, planned, page)),
1404
+ output: finishModule(withPageLines(output ?? intermediate, planned, page, moduleName)),
1373
1405
  intermediate,
1374
1406
  };
1375
1407
  }
1408
+ /**
1409
+ * A TODO from a page's run with each re-run it asks for named as one on its
1410
+ * module: run again on the page, the codemod writes nothing.
1411
+ */
1412
+ function rerunOn(message, moduleName) {
1413
+ return message.replace(/\bre-run\b/g, `re-run on \`${moduleName}\``);
1414
+ }
1376
1415
  /** A TODO's message as its comment writes it, on one line. */
1377
1416
  function todoText(message) {
1378
1417
  return message.replace(/[\r\n\u2028\u2029]+/g, ' ').trim();
1379
1418
  }
1380
1419
  /**
1381
- * The planner's TODO lines, each with the page's lines it is about. The
1382
- * transform writes one line for each message, however many elements share
1383
- * it (five `.icon`s missing the same attribute), above the `return`, so the
1384
- * lines go on after, the way the page's own notes carry theirs. Nothing from
1385
- * the `return` on is read, since the page's text is there.
1420
+ * The transform's TODO lines, each with its re-runs named as ones on the
1421
+ * module and the page's lines it is about, if any. The transform writes one
1422
+ * line for each message, however many elements share it (five `.icon`s
1423
+ * missing the same attribute), above the `return`, so the lines go on after,
1424
+ * the way the page's own notes carry theirs. Nothing from the `return` on is
1425
+ * read, since the page's text is there.
1386
1426
  */
1387
- function withPageLines(code, planned, page) {
1427
+ function withPageLines(code, planned, page, moduleName) {
1388
1428
  if (planned.size === 0)
1389
1429
  return code;
1390
1430
  const lines = code.split('\n');
1391
1431
  for (let i = 0; i < lines.length; i++) {
1392
1432
  if (/^\s*return\b/.test(lines[i]))
1393
1433
  break;
1394
- const todo = /^\s*\/\/ TODO\(bestax-migrate\): (.*)$/.exec(lines[i]);
1395
- const on = todo ? planned.get(todo[1]) : undefined;
1434
+ const todo = /^(\s*\/\/ TODO\(bestax-migrate\): )(.*)$/.exec(lines[i]);
1435
+ const on = todo ? planned.get(todo[2]) : undefined;
1396
1436
  if (!on)
1397
1437
  continue;
1398
1438
  const at = [...new Set(on)].sort((a, b) => a - b).join(', ');
1399
- lines[i] = `${lines[i]} (${page}:${at})`;
1439
+ lines[i] =
1440
+ `${todo[1]}${rerunOn(todo[2], moduleName)}` +
1441
+ (at === '' ? '' : ` (${page}:${at})`);
1400
1442
  }
1401
1443
  return lines.join('\n');
1402
1444
  }
@@ -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,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;IAC7C;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,4EAA4E;IAC5E,WAAW,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC,qEAAqE;IACrE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,qEAAqE;IACrE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;I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
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"}