ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/icons/checks/i02_budget.ts

checks/i02_budget.ts

35 líneas, 2.1 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // ICN-R02: the icon budget. A page carries only what its tier allows; a picture drawn for a page (bespoke) needs the tier
  2. // `bespoke`, and a collection holds at most `icons.max` bespoke files. Tiers: none < kind < pick < bespoke.
  3. import { Icons, finish, isGlyph, isSvgPath, norm, ownIcons, SETTINGS_PAGE } from '../lib/iconlib.ts';
  4. const ic = new Icons();
  5. const n = norm(ic.root, 'ICN-R02');
  6. const out: string[] = [];
  7. const bespoke = new Map<string, Set<string>>(); // group -> distinct bespoke files
  8. if (n.active) {
  9. for (const p of ic.pages()) {
  10. const { icon, art } = ownIcons(p);
  11. const at = `${p.id} (tier ${p.tier}: ${p.why})`;
  12. const files: string[] = [];
  13. if (icon && isSvgPath(icon)) files.push(ic.resolve(p.id, icon));
  14. if (art && isSvgPath(art)) files.push(ic.resolve(p.id, art));
  15. const own = files.filter((f) => !ic.inSet(f));
  16. if (p.tier === 'none' && (icon || art)) out.push(`${at}: the page carries an icon, the tier shows none → remove icon and art`);
  17. else if (p.tier === 'kind' && (icon || art)) out.push(`${at}: the page carries its own icon, the collection gives one icon to all → remove icon and art (set icons.item on the collection)`);
  18. else if (p.tier === 'pick') {
  19. if (art) out.push(`${at}: art is a bespoke picture → remove art, or raise the tier to bespoke in the collection`);
  20. if (icon && !isGlyph(icon) && own.length) out.push(`${at}: icon ${own[0]} is drawn for the page, the tier allows an emoji or an icon from ${ic.s.set}/ → pick one`);
  21. }
  22. if (p.tier === 'bespoke' && own.length) {
  23. const g = p.coll ?? (ic.s.heroes.includes(p.id) ? '' : '(pages outside collections)');
  24. if (g) for (const f of own) (bespoke.get(g) ?? bespoke.set(g, new Set()).get(g)!).add(f);
  25. }
  26. }
  27. const colls = ic.collections();
  28. for (const [g, files] of bespoke) {
  29. const max = colls[g]?.max ?? ic.s.max;
  30. if (files.size > max) out.push(`${g}${colls[g] ? '.md' : ''}: ${files.size} bespoke icon files, the budget is ${max} → reuse files, move pages to the shared set, or raise icons.max (${colls[g] ? 'the collection' : SETTINGS_PAGE}) with the owner`);
  31. }
  32. }
  33. finish(n, out);