tosijs-ui 1.5.9 → 1.5.10

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/dist/icons.d.ts CHANGED
@@ -8,8 +8,6 @@ export interface IconRule {
8
8
  prefix: string | RegExp;
9
9
  apply: (baseName: string, match: RegExpMatchArray | string, parts: ElementPart[]) => Element | string | null;
10
10
  }
11
- /** Returns icon name safe for suffix concatenation (appends _ if name ends in digit) */
12
- export declare const safeIconSuffix: (name: string) => string;
13
11
  export declare const iconRules: IconRule[];
14
12
  export declare const icons: SVGIconMap;
15
13
  export declare class SvgIcon extends WebComponent {
package/dist/icons.js CHANGED
@@ -446,6 +446,33 @@ through the full pipeline), an **Element** (used directly), or **null**
446
446
  },
447
447
  })
448
448
 
449
+ ### Building an icon vocabulary
450
+
451
+ You don't need to spell out the DSL every time. The real power is in
452
+ defining named patterns that become your application's icon language.
453
+ For example, a `remove` prefix that overlays a trash icon:
454
+
455
+ iconRules.push({
456
+ prefix: 'remove',
457
+ apply: (baseName) =>
458
+ `trash75o_actionColorS$${baseName}50o`,
459
+ })
460
+
461
+ Now `removeUser`, `removeFile`, `removeProject` all just work — and
462
+ they're consistent. If you redesign the trash icon or change
463
+ `--action-color`, every "remove" icon updates automatically.
464
+
465
+ You can also use `defineIcons` for one-off named compositions:
466
+
467
+ defineIcons({
468
+ cloudSync: 'spin120Loader40s_30x$cloud',
469
+ secureShield: 'lock50s75o_10y$shield',
470
+ newFile: 'plus75o60s25x25y$file',
471
+ })
472
+
473
+ Then just use `icons.cloudSync()` or `<tosi-icon icon="cloudSync">` —
474
+ the composition is invisible to consumers of the icon.
475
+
449
476
  ### Composites and `svg2DataUrl`
450
477
 
451
478
  Composed icons (stacked, overlay rules) are wrapped in a `<span>`, not
@@ -536,8 +563,8 @@ export const svg2DataUrl = (icon, fill, stroke, strokeWidth) => {
536
563
  const text = encodeURIComponent(svg.outerHTML);
537
564
  return `url(data:image/svg+xml;charset=UTF-8,${text})`;
538
565
  };
539
- /** Returns icon name safe for suffix concatenation (appends _ if name ends in digit) */
540
- export const safeIconSuffix = (name) => /\d$/.test(name) ? name + '_' : name;
566
+ // Appends _ to names ending in digits to prevent suffix ambiguity
567
+ const safeIconSuffix = (name) => /\d$/.test(name) ? name + '_' : name;
541
568
  export const iconRules = [
542
569
  {
543
570
  prefix: /^spin(_?\d+)/,
@@ -564,19 +591,19 @@ export const iconRules = [
564
591
  },
565
592
  {
566
593
  prefix: 'un',
567
- apply: (baseName) => `slash25o$${safeIconSuffix(baseName)}75s75o`,
594
+ apply: (baseName) => `slash25o$${baseName}75s75o`,
568
595
  },
569
596
  {
570
597
  prefix: 'check',
571
- apply: (baseName) => `check75o_00aa00S$${safeIconSuffix(baseName)}75s50o`,
598
+ apply: (baseName) => `check75o_00aa00S$${baseName}75s50o`,
572
599
  },
573
600
  {
574
601
  prefix: 'cancel',
575
- apply: (baseName) => `x75o_cc0000S$${safeIconSuffix(baseName)}75s50o`,
602
+ apply: (baseName) => `x75o_cc0000S$${baseName}75s50o`,
576
603
  },
577
604
  {
578
605
  prefix: 'search',
579
- apply: (baseName) => `search80s30x30y$${safeIconSuffix(baseName)}50o`,
606
+ apply: (baseName) => `search80s30x30y$${baseName}50o`,
580
607
  },
581
608
  ];
582
609
  function makeIcon(spec, parts) {
@@ -660,7 +687,7 @@ function composeIcon(prop, parts) {
660
687
  // Only apply if baseName can actually resolve to an icon
661
688
  if (!canResolve(baseName))
662
689
  continue;
663
- const result = rule.apply(baseName, match, parts);
690
+ const result = rule.apply(safeIconSuffix(baseName), match, parts);
664
691
  if (typeof result === 'string')
665
692
  return resolveIcon(result, parts);
666
693
  if (result)
@@ -757,6 +784,8 @@ function parseStyleSuffixes(name) {
757
784
  return { baseName, style };
758
785
  }
759
786
  function resolveIcon(prop, parts) {
787
+ if (prop.endsWith('_'))
788
+ prop = prop.slice(0, -1);
760
789
  const data = iconData;
761
790
  // Direct match or redirect chain
762
791
  let name = prop;