tosijs-ui 1.5.8 → 1.5.9
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.js +32 -62
- package/dist/iife.js +26 -26
- package/dist/iife.js.map +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/llms.txt +2 -2
- package/package.json +1 -1
package/dist/icons.js
CHANGED
|
@@ -7,26 +7,6 @@
|
|
|
7
7
|
<tosi-icon title="tosi-platform" icon="tosiPlatform" style="--tosi-icon-size: 128px"></tosi-icon>
|
|
8
8
|
</div>
|
|
9
9
|
|
|
10
|
-
A library that provides `ElementCreator` functions that produce SVG icons. It leverages `tosijs`'s
|
|
11
|
-
`svgElements` proxy and is intended to address all the key use-cases for SVG icons in web
|
|
12
|
-
applications along with being very easy to extend and maintain.
|
|
13
|
-
|
|
14
|
-
> ### Supported Use Cases
|
|
15
|
-
> - inline SVGs that can be styled by CSS (for buttons, etc.)
|
|
16
|
-
> - allows both stroked and filled icons (unlike font-based systems)
|
|
17
|
-
> - support for color icons (without requiring multiple glyphs perfectly aligned)
|
|
18
|
-
> - icons can be rendered as data urls, e.g. to insert into CSS… (the little `owl` logo rendered under blockquotes is an example)
|
|
19
|
-
> - icon composition: stack, transform, and style icons via naming conventions (e.g. `lock50s75o$shield`)
|
|
20
|
-
> - extensible rules system for custom prefixes and overlays (e.g. `unLock`, `checkFile`)
|
|
21
|
-
> - icon redirects eliminate redundant SVG data (e.g. `chevronDown` → `chevronRight90r`)
|
|
22
|
-
|
|
23
|
-
### Nice Features
|
|
24
|
-
> - no build process magic needed (your icons are "just javascript", no special CSS files needed, no magic glyph mappings). Adding new, or overriding existing, icons is trivial.
|
|
25
|
-
> - icons are just regular SVG, not a specialized subset.
|
|
26
|
-
> - highly optimized and compressible (the code is comparable in size to what you get with a compressed font built from the same icons, except icon fonts don't support strokes, gradients, etc.)
|
|
27
|
-
|
|
28
|
-
## icons
|
|
29
|
-
|
|
30
10
|
`icons` is a proxy that generates an `ElementCreator` for a given icon on demand,
|
|
31
11
|
e.g. `icons.chevronDown()` produces an `<svg>` element containing a downward-pointing chevron
|
|
32
12
|
icon with the class `icon-chevron-down`.
|
|
@@ -351,7 +331,7 @@ that, for example, treat all colored icons inside buttons the same way.
|
|
|
351
331
|
<tosi-icon icon="lock50s75o_10y$shield_brandColorS" size=128></tosi-icon>
|
|
352
332
|
<tosi-icon icon="unLock_brandColorS" size=128></tosi-icon>
|
|
353
333
|
<tosi-icon icon="checkFile" size=128></tosi-icon>
|
|
354
|
-
<tosi-icon icon="
|
|
334
|
+
<tosi-icon icon="spin120Loader40s_30x_brandColorS$cloud" size=128></tosi-icon>
|
|
355
335
|
|
|
356
336
|
### Why?
|
|
357
337
|
|
|
@@ -371,6 +351,12 @@ variations on every icon?
|
|
|
371
351
|
<tosi-icon icon="pin0f_brandColorS" size=64></tosi-icon>
|
|
372
352
|
<tosi-icon icon="unPin_brandColorS" size=64></tosi-icon>
|
|
373
353
|
|
|
354
|
+
And now we can just create icon languages…
|
|
355
|
+
|
|
356
|
+
<tosi-icon icon="checkUsers" size=64></tosi-icon>
|
|
357
|
+
<tosi-icon icon="searchMap" size=64></tosi-icon>
|
|
358
|
+
<tosi-icon icon="cancelHeart" size=64></tosi-icon>
|
|
359
|
+
|
|
374
360
|
### Icon modifier suffixes
|
|
375
361
|
|
|
376
362
|
The suffix system is inspired by tosijs's CSS variable math, where
|
|
@@ -473,35 +459,6 @@ with `svg2DataUrl`.
|
|
|
473
459
|
If you ask for an icon that isn't defined, the `icons` proxy will print a warning to console
|
|
474
460
|
and render a `square` (in fact, `icons.square()`) as a fallback.
|
|
475
461
|
|
|
476
|
-
## Why?
|
|
477
|
-
|
|
478
|
-
My evolution has been:
|
|
479
|
-
|
|
480
|
-
1. Using Icomoon.io, which I still think is a solid choice for managing custom icon fonts
|
|
481
|
-
2. Processing Icomoon selection.json files into icon-data and then generating SVGs dynamically
|
|
482
|
-
from the data
|
|
483
|
-
3. Ingesting SVGs directly, with a little cleanup
|
|
484
|
-
|
|
485
|
-
The goal is always to have a single source of truth for icons, no magic or convoluted tooling, and
|
|
486
|
-
be able to quickly and easily add and replace icons, distribute them with components, and
|
|
487
|
-
have no mess or fuss.
|
|
488
|
-
|
|
489
|
-
1. Works well, but…
|
|
490
|
-
- color icons are flaky,
|
|
491
|
-
- doesn't play well with others,
|
|
492
|
-
- can't really distribute the icons with your components.
|
|
493
|
-
- difficult to use icons in CSS `content`
|
|
494
|
-
- impossible to use icons in CSS backgrounds
|
|
495
|
-
2. This is `icons.ts` until just now! Solves all the above, but…
|
|
496
|
-
- no fancy SVG effects, like gradients (goodness knows I experimented with converting CSS gradients to SVG gradients) and, most
|
|
497
|
-
- **strokes** need to be converted to outlines
|
|
498
|
-
- outlined strokes can't be styled the way strokes can
|
|
499
|
-
- blocks use of popular icon libraries
|
|
500
|
-
3. This is how everyone else works, except…
|
|
501
|
-
- no build magic needed: `defineIcons({ myIcon: '<svg....>', ... })`
|
|
502
|
-
- if you want build magic, `icons.js` has no dependencies, finds icons and creates an `icon-data.ts` file.
|
|
503
|
-
- smaller icon files, even though I'm now including more icons (including *all the current* feathericons)
|
|
504
|
-
|
|
505
462
|
## Icon Sources
|
|
506
463
|
|
|
507
464
|
Many of these icons are sourced from [Feather Icons](https://github.com/feathericons/feather), but
|
|
@@ -514,6 +471,12 @@ The remaining icons I have created myself using the excellent but sometimes flaw
|
|
|
514
471
|
[Amadine](https://apps.apple.com/us/app/amadine-vector-design-art/id1339198386?mt=12)
|
|
515
472
|
and before that [Graphic](https://apps.apple.com/us/app/graphic/id404705039?mt=12).
|
|
516
473
|
|
|
474
|
+
### Building icon data
|
|
475
|
+
|
|
476
|
+
Use [make-icon-data](/?make-icon-data.js) to generate icon data from SVG files.
|
|
477
|
+
It supports directional folder conventions to auto-generate rotated and flipped
|
|
478
|
+
variants, eliminating redundant SVGs.
|
|
479
|
+
|
|
517
480
|
### Feather Icons Copyright Notice
|
|
518
481
|
|
|
519
482
|
The MIT License (MIT)
|
|
@@ -582,23 +545,21 @@ export const iconRules = [
|
|
|
582
545
|
const dps = match[1].replace('_', '-');
|
|
583
546
|
const duration = 360 / Math.abs(parseFloat(dps));
|
|
584
547
|
const direction = dps.startsWith('-') ? 'reverse' : 'normal';
|
|
585
|
-
//
|
|
586
|
-
const
|
|
587
|
-
const iconName = parsed ? parsed.baseName : baseName;
|
|
588
|
-
const icon = resolveIcon(iconName, []);
|
|
548
|
+
// Resolve baseName with suffixes intact — they apply to the icon
|
|
549
|
+
const icon = resolveIcon(baseName, []);
|
|
589
550
|
const el = icon;
|
|
590
551
|
if (el.animate) {
|
|
591
|
-
el.
|
|
552
|
+
const base = el.style.transform || '';
|
|
553
|
+
el.animate([
|
|
554
|
+
{ transform: `${base} rotate(0deg)` },
|
|
555
|
+
{ transform: `${base} rotate(360deg)` },
|
|
556
|
+
], {
|
|
592
557
|
duration: duration * 1000,
|
|
593
558
|
iterations: Infinity,
|
|
594
559
|
direction,
|
|
595
560
|
});
|
|
596
561
|
}
|
|
597
|
-
|
|
598
|
-
if (parsed) {
|
|
599
|
-
Object.assign(wrapper.style, parsed.style);
|
|
600
|
-
}
|
|
601
|
-
return wrapper;
|
|
562
|
+
return wrapIcon(baseName, parts, icon);
|
|
602
563
|
},
|
|
603
564
|
},
|
|
604
565
|
{
|
|
@@ -728,8 +689,17 @@ function parseStyleSuffixes(name) {
|
|
|
728
689
|
if (!baseName)
|
|
729
690
|
return null;
|
|
730
691
|
const data = iconData;
|
|
731
|
-
if
|
|
732
|
-
|
|
692
|
+
// Accept if baseName is in iconData, or matches a composition rule prefix
|
|
693
|
+
if (!data[baseName]) {
|
|
694
|
+
const matchesRule = iconRules.some((rule) => {
|
|
695
|
+
if (rule.prefix instanceof RegExp) {
|
|
696
|
+
return rule.prefix.test(baseName);
|
|
697
|
+
}
|
|
698
|
+
return baseName.startsWith(rule.prefix) && baseName.length > rule.prefix.length;
|
|
699
|
+
});
|
|
700
|
+
if (!matchesRule)
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
733
703
|
const style = {};
|
|
734
704
|
const suffixes = match[0].match(/_?\d+[osxyr]|[01]f|_[a-zA-Z0-9]+[FS]|\d+W/g);
|
|
735
705
|
if (!suffixes)
|