@memberjunction/ng-ui-components 6.2.0-edge.2 → 6.2.0-edge.3
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/lib/icon-picker/font-awesome-icons.d.ts +130 -0
- package/dist/lib/icon-picker/font-awesome-icons.d.ts.map +1 -0
- package/dist/lib/icon-picker/font-awesome-icons.js +256 -0
- package/dist/lib/icon-picker/font-awesome-icons.js.map +1 -0
- package/dist/lib/icon-picker/icon-catalogue.service.d.ts +71 -0
- package/dist/lib/icon-picker/icon-catalogue.service.d.ts.map +1 -0
- package/dist/lib/icon-picker/icon-catalogue.service.js +153 -0
- package/dist/lib/icon-picker/icon-catalogue.service.js.map +1 -0
- package/dist/lib/icon-picker/icon-picker.component.d.ts +117 -0
- package/dist/lib/icon-picker/icon-picker.component.d.ts.map +1 -0
- package/dist/lib/icon-picker/icon-picker.component.js +362 -0
- package/dist/lib/icon-picker/icon-picker.component.js.map +1 -0
- package/dist/public-api.d.ts +3 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +3 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Font Awesome icons this page can actually draw, and in which style.
|
|
3
|
+
*
|
|
4
|
+
* Read from the loaded stylesheet rather than from a list shipped here, so the catalogue
|
|
5
|
+
* is whatever the host really loaded — Free, Pro, or a pinned older version. A list in
|
|
6
|
+
* source would drift from it silently and offer icons that render as blank squares.
|
|
7
|
+
*
|
|
8
|
+
* Knowing the NAME is not enough. Font Awesome splits its icons across several fonts, and
|
|
9
|
+
* the stylesheet gives every icon the same kind of rule whichever font holds it — so a
|
|
10
|
+
* name drawn in the wrong style renders as a missing-glyph box. Which font has a given
|
|
11
|
+
* glyph is not written down anywhere in the CSS, so it is measured: a glyph the font does
|
|
12
|
+
* not have falls back and measures exactly as it does with no Font Awesome at all.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The style prefix to assume for a bare icon name.
|
|
16
|
+
*
|
|
17
|
+
* Solid, because it is the one style Font Awesome Free carries in full — `fa-regular`
|
|
18
|
+
* exists there for only a few dozen icons, so defaulting to it would silently produce
|
|
19
|
+
* blanks for most names.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_ICON_STYLE = "fa-solid";
|
|
22
|
+
/**
|
|
23
|
+
* The styles the picker offers, widest set first so a solid icon is reported as solid.
|
|
24
|
+
*
|
|
25
|
+
* Brands is deliberately absent. Those icons are company logos — Angular, Apple, Amazon
|
|
26
|
+
* Pay — and a section header or a rail label is not a place for one; offering six hundred
|
|
27
|
+
* of them buries the icons that do belong behind names nobody is searching for.
|
|
28
|
+
*
|
|
29
|
+
* Excluded from what is OFFERED, not from what renders: `fa-brands` stays a style
|
|
30
|
+
* {@link NormalizeIconClass} leaves alone, so a brands class already stored, or typed by
|
|
31
|
+
* hand, still draws.
|
|
32
|
+
*/
|
|
33
|
+
export declare const ICON_STYLES: readonly string[];
|
|
34
|
+
/** One icon the page can draw, with the style that actually draws it. */
|
|
35
|
+
export interface FontAwesomeIcon {
|
|
36
|
+
/** The bare name, e.g. `chart-column`. */
|
|
37
|
+
Name: string;
|
|
38
|
+
/** The style class that has the glyph, e.g. `fa-solid`. */
|
|
39
|
+
Style: string;
|
|
40
|
+
/** Other names the stylesheet gives the same glyph in the same style, e.g. `home` for `house`. */
|
|
41
|
+
Aliases?: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
/** An icon name and the character its stylesheet rule assigns it. */
|
|
44
|
+
export interface IconGlyphRule {
|
|
45
|
+
Name: string;
|
|
46
|
+
/** The character from the rule's `content`, which is what gets measured. */
|
|
47
|
+
Glyph: string;
|
|
48
|
+
}
|
|
49
|
+
/** How one style renders, as the browser resolves it. */
|
|
50
|
+
export interface IconStyleFont {
|
|
51
|
+
Style: string;
|
|
52
|
+
FontFamily: string;
|
|
53
|
+
FontWeight: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A small, dependable set for when the stylesheet cannot be read.
|
|
57
|
+
*
|
|
58
|
+
* Solid-only, and chosen to cover the things a form panel is usually about rather than to
|
|
59
|
+
* be exhaustive: a user who needs something else can still type its name.
|
|
60
|
+
*/
|
|
61
|
+
export declare const FALLBACK_ICONS: readonly FontAwesomeIcon[];
|
|
62
|
+
/**
|
|
63
|
+
* An icon value the browser can actually draw.
|
|
64
|
+
*
|
|
65
|
+
* Font Awesome needs a style class as well as a name: `fa-chart-column` alone matches the
|
|
66
|
+
* base `.fa-chart-column` rule, which sets a glyph but no font family, so nothing renders.
|
|
67
|
+
* A value that already names a style is returned untouched, including the older one-class
|
|
68
|
+
* `fa fa-folder` form that the generated forms still use.
|
|
69
|
+
*
|
|
70
|
+
* @param style the style to assume for a bare name. Defaults to {@link DEFAULT_ICON_STYLE}.
|
|
71
|
+
*/
|
|
72
|
+
export declare function NormalizeIconClass(value: string | null | undefined, style?: string): string;
|
|
73
|
+
/** The icon name inside a class string, without its style or `fa-` prefix. */
|
|
74
|
+
export declare function IconNameOf(value: string | null | undefined): string;
|
|
75
|
+
/**
|
|
76
|
+
* Icon names and glyphs the loaded stylesheets define.
|
|
77
|
+
*
|
|
78
|
+
* A rule qualifies when it styles `.fa-<name>` with `::before` content, which is how Font
|
|
79
|
+
* Awesome attaches a glyph — the sizing and animation helpers share the prefix but set no
|
|
80
|
+
* content, so this tells the two apart without a list to maintain.
|
|
81
|
+
*/
|
|
82
|
+
export declare function ScanLoadedIconRules(doc: Document): IconGlyphRule[];
|
|
83
|
+
/**
|
|
84
|
+
* The character a `content` value names.
|
|
85
|
+
*
|
|
86
|
+
* Font Awesome writes it as a CSS escape — `content: "\f007"` — which reaches script with
|
|
87
|
+
* the quotes and the escape intact. A value naming anything else (a keyword, a counter,
|
|
88
|
+
* a var it could not resolve) yields nothing, so it is skipped rather than measured.
|
|
89
|
+
*/
|
|
90
|
+
export declare function GlyphFromContent(content: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* How each style renders, as the browser resolves it on this page.
|
|
93
|
+
*
|
|
94
|
+
* Probed rather than assumed: the font family carries the major version in its name
|
|
95
|
+
* (`Font Awesome 6 Free`), and a host on another version, or on a kit, names it something
|
|
96
|
+
* else. A style whose family does not resolve is left out — it is not loaded.
|
|
97
|
+
*/
|
|
98
|
+
export declare function ProbeIconStyleFonts(doc: Document, styles?: readonly string[]): IconStyleFont[];
|
|
99
|
+
/**
|
|
100
|
+
* Whether a font has a glyph, decided by measuring it.
|
|
101
|
+
*
|
|
102
|
+
* Implemented by the caller so this module stays free of canvas and testable without one.
|
|
103
|
+
* Returns true when `glyph` renders from `font` rather than falling back.
|
|
104
|
+
*/
|
|
105
|
+
export type GlyphPresenceTest = (glyph: string, font: IconStyleFont) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Each icon paired with the style that actually draws it.
|
|
108
|
+
*
|
|
109
|
+
* The stylesheet says which icons exist but not which font holds each one, and drawing a
|
|
110
|
+
* brands icon as solid produces a missing-glyph box — which is what a user sees as "half
|
|
111
|
+
* the icons are broken". Styles are tried in order, so an icon present in several is
|
|
112
|
+
* reported under the first, and an icon no loaded font has is dropped rather than offered
|
|
113
|
+
* as a blank square.
|
|
114
|
+
*
|
|
115
|
+
* Names that draw the same glyph in the same style are one icon: the first name in `rules`
|
|
116
|
+
* order is kept and the rest become its {@link FontAwesomeIcon.Aliases}, so the grid shows
|
|
117
|
+
* each glyph once and a search for any of its names finds it.
|
|
118
|
+
*/
|
|
119
|
+
export declare function ResolveIconStyles(rules: readonly IconGlyphRule[], fonts: readonly IconStyleFont[], hasGlyph: GlyphPresenceTest): FontAwesomeIcon[];
|
|
120
|
+
/** How many icons the picker's grid draws at most; the rest are reached by searching. */
|
|
121
|
+
export declare const ICON_RESULT_LIMIT = 240;
|
|
122
|
+
/**
|
|
123
|
+
* Every icon matching a search, most relevant first: names that start with it, then names
|
|
124
|
+
* that contain it. An icon matches by its name or by any of its aliases. An empty search
|
|
125
|
+
* matches every icon.
|
|
126
|
+
*/
|
|
127
|
+
export declare function MatchIcons(icons: readonly FontAwesomeIcon[], search: string): FontAwesomeIcon[];
|
|
128
|
+
/** The first `limit` icons {@link MatchIcons} finds for a search. */
|
|
129
|
+
export declare function FilterIcons(icons: readonly FontAwesomeIcon[], search: string, limit?: number): FontAwesomeIcon[];
|
|
130
|
+
//# sourceMappingURL=font-awesome-icons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font-awesome-icons.d.ts","sourceRoot":"","sources":["../../../src/lib/icon-picker/font-awesome-icons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAA+B,CAAC;AAoBzE,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC5B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,kGAAkG;IAClG,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,eAAe,EAcC,CAAC;AAQvD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,GAAE,MAA2B,GAAG,MAAM,CAO/G;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAInE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,QAAQ,GAAG,aAAa,EAAE,CAgBlE;AAmBD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAE,SAAS,MAAM,EAAgB,GAAG,aAAa,EAAE,CAsB3G;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC;AAEhF;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,SAAS,aAAa,EAAE,EAC/B,KAAK,EAAE,SAAS,aAAa,EAAE,EAC/B,QAAQ,EAAE,iBAAiB,GAC5B,eAAe,EAAE,CAkBnB;AAED,yFAAyF;AACzF,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE,CAW/F;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAoB,GAAG,eAAe,EAAE,CAE3H"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Font Awesome icons this page can actually draw, and in which style.
|
|
3
|
+
*
|
|
4
|
+
* Read from the loaded stylesheet rather than from a list shipped here, so the catalogue
|
|
5
|
+
* is whatever the host really loaded — Free, Pro, or a pinned older version. A list in
|
|
6
|
+
* source would drift from it silently and offer icons that render as blank squares.
|
|
7
|
+
*
|
|
8
|
+
* Knowing the NAME is not enough. Font Awesome splits its icons across several fonts, and
|
|
9
|
+
* the stylesheet gives every icon the same kind of rule whichever font holds it — so a
|
|
10
|
+
* name drawn in the wrong style renders as a missing-glyph box. Which font has a given
|
|
11
|
+
* glyph is not written down anywhere in the CSS, so it is measured: a glyph the font does
|
|
12
|
+
* not have falls back and measures exactly as it does with no Font Awesome at all.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The style prefix to assume for a bare icon name.
|
|
16
|
+
*
|
|
17
|
+
* Solid, because it is the one style Font Awesome Free carries in full — `fa-regular`
|
|
18
|
+
* exists there for only a few dozen icons, so defaulting to it would silently produce
|
|
19
|
+
* blanks for most names.
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_ICON_STYLE = 'fa-solid';
|
|
22
|
+
/**
|
|
23
|
+
* The styles the picker offers, widest set first so a solid icon is reported as solid.
|
|
24
|
+
*
|
|
25
|
+
* Brands is deliberately absent. Those icons are company logos — Angular, Apple, Amazon
|
|
26
|
+
* Pay — and a section header or a rail label is not a place for one; offering six hundred
|
|
27
|
+
* of them buries the icons that do belong behind names nobody is searching for.
|
|
28
|
+
*
|
|
29
|
+
* Excluded from what is OFFERED, not from what renders: `fa-brands` stays a style
|
|
30
|
+
* {@link NormalizeIconClass} leaves alone, so a brands class already stored, or typed by
|
|
31
|
+
* hand, still draws.
|
|
32
|
+
*/
|
|
33
|
+
export const ICON_STYLES = ['fa-solid', 'fa-regular'];
|
|
34
|
+
/** Style prefixes an icon value may already carry, so normalization leaves it alone. */
|
|
35
|
+
const STYLE_PREFIXES = ['fa-solid', 'fa-regular', 'fa-brands', 'fa-light', 'fa-thin', 'fa-duotone', 'fas', 'far', 'fab', 'fal', 'fat', 'fad', 'fa'];
|
|
36
|
+
/**
|
|
37
|
+
* Class names that start with `fa-` but are not icons: sizing, animation and layout
|
|
38
|
+
* helpers. They carry no glyph, so offering them gives the user an empty square.
|
|
39
|
+
*/
|
|
40
|
+
const NON_ICON_CLASSES = new Set([
|
|
41
|
+
'fa-spin', 'fa-pulse', 'fa-spin-pulse', 'fa-spin-reverse', 'fa-beat', 'fa-fade',
|
|
42
|
+
'fa-beat-fade', 'fa-bounce', 'fa-flip', 'fa-shake', 'fa-fw', 'fa-border', 'fa-inverse',
|
|
43
|
+
'fa-pull-left', 'fa-pull-right', 'fa-rotate-90', 'fa-rotate-180', 'fa-rotate-270',
|
|
44
|
+
'fa-rotate-by', 'fa-flip-horizontal', 'fa-flip-vertical', 'fa-flip-both', 'fa-stack',
|
|
45
|
+
'fa-stack-1x', 'fa-stack-2x', 'fa-layers', 'fa-layers-text', 'fa-layers-counter',
|
|
46
|
+
'fa-sr-only', 'fa-sr-only-focusable', 'fa-li', 'fa-ul', 'fa-xs', 'fa-sm', 'fa-lg',
|
|
47
|
+
'fa-xl', 'fa-2xl', 'fa-1x', 'fa-2x', 'fa-3x', 'fa-4x', 'fa-5x', 'fa-6x', 'fa-7x',
|
|
48
|
+
'fa-8x', 'fa-9x', 'fa-10x', 'fa-2xs', 'fa-swap-opacity', 'fa-width-auto',
|
|
49
|
+
]);
|
|
50
|
+
/**
|
|
51
|
+
* A small, dependable set for when the stylesheet cannot be read.
|
|
52
|
+
*
|
|
53
|
+
* Solid-only, and chosen to cover the things a form panel is usually about rather than to
|
|
54
|
+
* be exhaustive: a user who needs something else can still type its name.
|
|
55
|
+
*/
|
|
56
|
+
export const FALLBACK_ICONS = [
|
|
57
|
+
'address-card', 'bell', 'bolt', 'book', 'bookmark', 'box', 'briefcase', 'building',
|
|
58
|
+
'bullseye', 'calendar', 'calendar-check', 'certificate', 'chart-bar', 'chart-column',
|
|
59
|
+
'chart-line', 'chart-pie', 'check', 'circle-check', 'circle-info', 'clipboard',
|
|
60
|
+
'clipboard-list', 'clock', 'cloud', 'code', 'comment', 'comments', 'compass',
|
|
61
|
+
'credit-card', 'database', 'diagram-project', 'dollar-sign', 'envelope', 'eye',
|
|
62
|
+
'file', 'file-lines', 'filter', 'flag', 'folder', 'gauge', 'gear', 'globe',
|
|
63
|
+
'graduation-cap', 'grip-vertical', 'heart', 'house', 'id-badge', 'id-card', 'image',
|
|
64
|
+
'inbox', 'key', 'layer-group', 'lightbulb', 'link', 'list', 'list-check', 'location-dot',
|
|
65
|
+
'lock', 'magnifying-glass', 'map', 'medal', 'message', 'money-bill', 'note-sticky',
|
|
66
|
+
'paperclip', 'pen', 'people-group', 'percent', 'phone', 'puzzle-piece', 'receipt',
|
|
67
|
+
'rocket', 'ruler', 'screwdriver-wrench', 'shield', 'sitemap', 'sliders', 'star',
|
|
68
|
+
'table', 'table-cells', 'tag', 'tags', 'thumbtack', 'ticket', 'timeline', 'trophy',
|
|
69
|
+
'truck', 'user', 'user-group', 'users', 'wand-magic-sparkles', 'warehouse', 'wrench',
|
|
70
|
+
].map((Name) => ({ Name, Style: DEFAULT_ICON_STYLE }));
|
|
71
|
+
/** Whether this value already names a Font Awesome style. */
|
|
72
|
+
function hasStylePrefix(value) {
|
|
73
|
+
const classes = value.split(/\s+/).filter((c) => c.length > 0);
|
|
74
|
+
return classes.some((c) => STYLE_PREFIXES.includes(c));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* An icon value the browser can actually draw.
|
|
78
|
+
*
|
|
79
|
+
* Font Awesome needs a style class as well as a name: `fa-chart-column` alone matches the
|
|
80
|
+
* base `.fa-chart-column` rule, which sets a glyph but no font family, so nothing renders.
|
|
81
|
+
* A value that already names a style is returned untouched, including the older one-class
|
|
82
|
+
* `fa fa-folder` form that the generated forms still use.
|
|
83
|
+
*
|
|
84
|
+
* @param style the style to assume for a bare name. Defaults to {@link DEFAULT_ICON_STYLE}.
|
|
85
|
+
*/
|
|
86
|
+
export function NormalizeIconClass(value, style = DEFAULT_ICON_STYLE) {
|
|
87
|
+
const trimmed = (value ?? '').trim().replace(/\s+/g, ' ');
|
|
88
|
+
if (trimmed.length === 0)
|
|
89
|
+
return '';
|
|
90
|
+
if (hasStylePrefix(trimmed))
|
|
91
|
+
return trimmed;
|
|
92
|
+
// A bare name without the fa- prefix is still meant as an icon name.
|
|
93
|
+
const named = trimmed.startsWith('fa-') ? trimmed : `fa-${trimmed}`;
|
|
94
|
+
return `${style} ${named}`;
|
|
95
|
+
}
|
|
96
|
+
/** The icon name inside a class string, without its style or `fa-` prefix. */
|
|
97
|
+
export function IconNameOf(value) {
|
|
98
|
+
const classes = (value ?? '').trim().split(/\s+/).filter((c) => c.length > 0);
|
|
99
|
+
const name = classes.find((c) => c.startsWith('fa-') && !STYLE_PREFIXES.includes(c) && !NON_ICON_CLASSES.has(c));
|
|
100
|
+
return name ? name.slice(3) : '';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Icon names and glyphs the loaded stylesheets define.
|
|
104
|
+
*
|
|
105
|
+
* A rule qualifies when it styles `.fa-<name>` with `::before` content, which is how Font
|
|
106
|
+
* Awesome attaches a glyph — the sizing and animation helpers share the prefix but set no
|
|
107
|
+
* content, so this tells the two apart without a list to maintain.
|
|
108
|
+
*/
|
|
109
|
+
export function ScanLoadedIconRules(doc) {
|
|
110
|
+
const found = new Map();
|
|
111
|
+
for (const sheet of Array.from(doc.styleSheets)) {
|
|
112
|
+
let rules = null;
|
|
113
|
+
try {
|
|
114
|
+
rules = sheet.cssRules;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Served without CORS headers, so its rules are not readable from script.
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (!rules)
|
|
121
|
+
continue;
|
|
122
|
+
for (const rule of Array.from(rules))
|
|
123
|
+
collectFromRule(rule, found);
|
|
124
|
+
}
|
|
125
|
+
return [...found.entries()]
|
|
126
|
+
.map(([Name, Glyph]) => ({ Name, Glyph }))
|
|
127
|
+
.sort((a, b) => a.Name.localeCompare(b.Name));
|
|
128
|
+
}
|
|
129
|
+
function collectFromRule(rule, found) {
|
|
130
|
+
const style = rule;
|
|
131
|
+
const selector = typeof style.selectorText === 'string' ? style.selectorText : '';
|
|
132
|
+
if (!selector || (!selector.includes('::before') && !selector.includes(':before')))
|
|
133
|
+
return;
|
|
134
|
+
const content = style.style?.getPropertyValue('content');
|
|
135
|
+
if (!content)
|
|
136
|
+
return;
|
|
137
|
+
const glyph = GlyphFromContent(content);
|
|
138
|
+
if (!glyph)
|
|
139
|
+
return;
|
|
140
|
+
for (const part of selector.split(',')) {
|
|
141
|
+
const match = part.trim().match(/^\.(fa-[a-z0-9-]+)::?before$/);
|
|
142
|
+
if (!match)
|
|
143
|
+
continue;
|
|
144
|
+
const cls = match[1];
|
|
145
|
+
if (NON_ICON_CLASSES.has(cls))
|
|
146
|
+
continue;
|
|
147
|
+
found.set(cls.slice(3), glyph);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The character a `content` value names.
|
|
152
|
+
*
|
|
153
|
+
* Font Awesome writes it as a CSS escape — `content: "\f007"` — which reaches script with
|
|
154
|
+
* the quotes and the escape intact. A value naming anything else (a keyword, a counter,
|
|
155
|
+
* a var it could not resolve) yields nothing, so it is skipped rather than measured.
|
|
156
|
+
*/
|
|
157
|
+
export function GlyphFromContent(content) {
|
|
158
|
+
const body = content.trim().replace(/^["']|["']$/g, '');
|
|
159
|
+
const escaped = body.match(/^\\([0-9a-fA-F]{1,6})$/);
|
|
160
|
+
if (escaped)
|
|
161
|
+
return String.fromCodePoint(parseInt(escaped[1], 16));
|
|
162
|
+
return body.length === 1 || [...body].length === 1 ? body : '';
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* How each style renders, as the browser resolves it on this page.
|
|
166
|
+
*
|
|
167
|
+
* Probed rather than assumed: the font family carries the major version in its name
|
|
168
|
+
* (`Font Awesome 6 Free`), and a host on another version, or on a kit, names it something
|
|
169
|
+
* else. A style whose family does not resolve is left out — it is not loaded.
|
|
170
|
+
*/
|
|
171
|
+
export function ProbeIconStyleFonts(doc, styles = ICON_STYLES) {
|
|
172
|
+
const out = [];
|
|
173
|
+
const host = doc.body ?? doc.documentElement;
|
|
174
|
+
if (!host)
|
|
175
|
+
return out;
|
|
176
|
+
for (const style of styles) {
|
|
177
|
+
const probe = doc.createElement('i');
|
|
178
|
+
probe.className = style;
|
|
179
|
+
probe.setAttribute('aria-hidden', 'true');
|
|
180
|
+
probe.style.position = 'absolute';
|
|
181
|
+
probe.style.left = '-99999px';
|
|
182
|
+
host.appendChild(probe);
|
|
183
|
+
try {
|
|
184
|
+
const computed = doc.defaultView?.getComputedStyle(probe);
|
|
185
|
+
const family = (computed?.fontFamily ?? '').trim();
|
|
186
|
+
if (family && /font\s*awesome/i.test(family)) {
|
|
187
|
+
out.push({ Style: style, FontFamily: family, FontWeight: (computed?.fontWeight ?? '400').trim() });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
host.removeChild(probe);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Each icon paired with the style that actually draws it.
|
|
198
|
+
*
|
|
199
|
+
* The stylesheet says which icons exist but not which font holds each one, and drawing a
|
|
200
|
+
* brands icon as solid produces a missing-glyph box — which is what a user sees as "half
|
|
201
|
+
* the icons are broken". Styles are tried in order, so an icon present in several is
|
|
202
|
+
* reported under the first, and an icon no loaded font has is dropped rather than offered
|
|
203
|
+
* as a blank square.
|
|
204
|
+
*
|
|
205
|
+
* Names that draw the same glyph in the same style are one icon: the first name in `rules`
|
|
206
|
+
* order is kept and the rest become its {@link FontAwesomeIcon.Aliases}, so the grid shows
|
|
207
|
+
* each glyph once and a search for any of its names finds it.
|
|
208
|
+
*/
|
|
209
|
+
export function ResolveIconStyles(rules, fonts, hasGlyph) {
|
|
210
|
+
if (fonts.length === 0)
|
|
211
|
+
return [];
|
|
212
|
+
const out = [];
|
|
213
|
+
const byGlyph = new Map();
|
|
214
|
+
for (const rule of rules) {
|
|
215
|
+
const font = fonts.find((f) => hasGlyph(rule.Glyph, f));
|
|
216
|
+
if (!font)
|
|
217
|
+
continue;
|
|
218
|
+
const key = `${font.Style}|${rule.Glyph}`;
|
|
219
|
+
const kept = byGlyph.get(key);
|
|
220
|
+
if (kept) {
|
|
221
|
+
kept.Aliases = [...(kept.Aliases ?? []), rule.Name];
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const icon = { Name: rule.Name, Style: font.Style };
|
|
225
|
+
byGlyph.set(key, icon);
|
|
226
|
+
out.push(icon);
|
|
227
|
+
}
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
/** How many icons the picker's grid draws at most; the rest are reached by searching. */
|
|
231
|
+
export const ICON_RESULT_LIMIT = 240;
|
|
232
|
+
/**
|
|
233
|
+
* Every icon matching a search, most relevant first: names that start with it, then names
|
|
234
|
+
* that contain it. An icon matches by its name or by any of its aliases. An empty search
|
|
235
|
+
* matches every icon.
|
|
236
|
+
*/
|
|
237
|
+
export function MatchIcons(icons, search) {
|
|
238
|
+
const needle = search.trim().toLowerCase().replace(/^fa-/, '');
|
|
239
|
+
if (needle.length === 0)
|
|
240
|
+
return [...icons];
|
|
241
|
+
const starts = [];
|
|
242
|
+
const contains = [];
|
|
243
|
+
for (const icon of icons) {
|
|
244
|
+
const names = [icon.Name, ...(icon.Aliases ?? [])];
|
|
245
|
+
if (names.some((name) => name.startsWith(needle)))
|
|
246
|
+
starts.push(icon);
|
|
247
|
+
else if (names.some((name) => name.includes(needle)))
|
|
248
|
+
contains.push(icon);
|
|
249
|
+
}
|
|
250
|
+
return [...starts, ...contains];
|
|
251
|
+
}
|
|
252
|
+
/** The first `limit` icons {@link MatchIcons} finds for a search. */
|
|
253
|
+
export function FilterIcons(icons, search, limit = ICON_RESULT_LIMIT) {
|
|
254
|
+
return MatchIcons(icons, search).slice(0, limit);
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=font-awesome-icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font-awesome-icons.js","sour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C,KAAiC,EAAE,MAAc;IACxE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC/D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;QACnD,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAChE,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,KAAiC,EAAE,MAAc,EAAE,KAAK,GAAG,iBAAiB;IACpG,OAAO,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/**\n * What Font Awesome icons this page can actually draw, and in which style.\n *\n * Read from the loaded stylesheet rather than from a list shipped here, so the catalogue\n * is whatever the host really loaded — Free, Pro, or a pinned older version. A list in\n * source would drift from it silently and offer icons that render as blank squares.\n *\n * Knowing the NAME is not enough. Font Awesome splits its icons across several fonts, and\n * the stylesheet gives every icon the same kind of rule whichever font holds it — so a\n * name drawn in the wrong style renders as a missing-glyph box. Which font has a given\n * glyph is not written down anywhere in the CSS, so it is measured: a glyph the font does\n * not have falls back and measures exactly as it does with no Font Awesome at all.\n */\n\n/**\n * The style prefix to assume for a bare icon name.\n *\n * Solid, because it is the one style Font Awesome Free carries in full — `fa-regular`\n * exists there for only a few dozen icons, so defaulting to it would silently produce\n * blanks for most names.\n */\nexport const DEFAULT_ICON_STYLE = 'fa-solid';\n\n/**\n * The styles the picker offers, widest set first so a solid icon is reported as solid.\n *\n * Brands is deliberately absent. Those icons are company logos — Angular, Apple, Amazon\n * Pay — and a section header or a rail label is not a place for one; offering six hundred\n * of them buries the icons that do belong behind names nobody is searching for.\n *\n * Excluded from what is OFFERED, not from what renders: `fa-brands` stays a style\n * {@link NormalizeIconClass} leaves alone, so a brands class already stored, or typed by\n * hand, still draws.\n */\nexport const ICON_STYLES: readonly string[] = ['fa-solid', 'fa-regular'];\n\n/** Style prefixes an icon value may already carry, so normalization leaves it alone. */\nconst STYLE_PREFIXES = ['fa-solid', 'fa-regular', 'fa-brands', 'fa-light', 'fa-thin', 'fa-duotone', 'fas', 'far', 'fab', 'fal', 'fat', 'fad', 'fa'];\n\n/**\n * Class names that start with `fa-` but are not icons: sizing, animation and layout\n * helpers. They carry no glyph, so offering them gives the user an empty square.\n */\nconst NON_ICON_CLASSES = new Set([\n 'fa-spin', 'fa-pulse', 'fa-spin-pulse', 'fa-spin-reverse', 'fa-beat', 'fa-fade',\n 'fa-beat-fade', 'fa-bounce', 'fa-flip', 'fa-shake', 'fa-fw', 'fa-border', 'fa-inverse',\n 'fa-pull-left', 'fa-pull-right', 'fa-rotate-90', 'fa-rotate-180', 'fa-rotate-270',\n 'fa-rotate-by', 'fa-flip-horizontal', 'fa-flip-vertical', 'fa-flip-both', 'fa-stack',\n 'fa-stack-1x', 'fa-stack-2x', 'fa-layers', 'fa-layers-text', 'fa-layers-counter',\n 'fa-sr-only', 'fa-sr-only-focusable', 'fa-li', 'fa-ul', 'fa-xs', 'fa-sm', 'fa-lg',\n 'fa-xl', 'fa-2xl', 'fa-1x', 'fa-2x', 'fa-3x', 'fa-4x', 'fa-5x', 'fa-6x', 'fa-7x',\n 'fa-8x', 'fa-9x', 'fa-10x', 'fa-2xs', 'fa-swap-opacity', 'fa-width-auto',\n]);\n\n/** One icon the page can draw, with the style that actually draws it. */\nexport interface FontAwesomeIcon {\n /** The bare name, e.g. `chart-column`. */\n Name: string;\n /** The style class that has the glyph, e.g. `fa-solid`. */\n Style: string;\n /** Other names the stylesheet gives the same glyph in the same style, e.g. `home` for `house`. */\n Aliases?: readonly string[];\n}\n\n/** An icon name and the character its stylesheet rule assigns it. */\nexport interface IconGlyphRule {\n Name: string;\n /** The character from the rule's `content`, which is what gets measured. */\n Glyph: string;\n}\n\n/** How one style renders, as the browser resolves it. */\nexport interface IconStyleFont {\n Style: string;\n FontFamily: string;\n FontWeight: string;\n}\n\n/**\n * A small, dependable set for when the stylesheet cannot be read.\n *\n * Solid-only, and chosen to cover the things a form panel is usually about rather than to\n * be exhaustive: a user who needs something else can still type its name.\n */\nexport const FALLBACK_ICONS: readonly FontAwesomeIcon[] = [\n 'address-card', 'bell', 'bolt', 'book', 'bookmark', 'box', 'briefcase', 'building',\n 'bullseye', 'calendar', 'calendar-check', 'certificate', 'chart-bar', 'chart-column',\n 'chart-line', 'chart-pie', 'check', 'circle-check', 'circle-info', 'clipboard',\n 'clipboard-list', 'clock', 'cloud', 'code', 'comment', 'comments', 'compass',\n 'credit-card', 'database', 'diagram-project', 'dollar-sign', 'envelope', 'eye',\n 'file', 'file-lines', 'filter', 'flag', 'folder', 'gauge', 'gear', 'globe',\n 'graduation-cap', 'grip-vertical', 'heart', 'house', 'id-badge', 'id-card', 'image',\n 'inbox', 'key', 'layer-group', 'lightbulb', 'link', 'list', 'list-check', 'location-dot',\n 'lock', 'magnifying-glass', 'map', 'medal', 'message', 'money-bill', 'note-sticky',\n 'paperclip', 'pen', 'people-group', 'percent', 'phone', 'puzzle-piece', 'receipt',\n 'rocket', 'ruler', 'screwdriver-wrench', 'shield', 'sitemap', 'sliders', 'star',\n 'table', 'table-cells', 'tag', 'tags', 'thumbtack', 'ticket', 'timeline', 'trophy',\n 'truck', 'user', 'user-group', 'users', 'wand-magic-sparkles', 'warehouse', 'wrench',\n].map((Name) => ({ Name, Style: DEFAULT_ICON_STYLE }));\n\n/** Whether this value already names a Font Awesome style. */\nfunction hasStylePrefix(value: string): boolean {\n const classes = value.split(/\\s+/).filter((c) => c.length > 0);\n return classes.some((c) => STYLE_PREFIXES.includes(c));\n}\n\n/**\n * An icon value the browser can actually draw.\n *\n * Font Awesome needs a style class as well as a name: `fa-chart-column` alone matches the\n * base `.fa-chart-column` rule, which sets a glyph but no font family, so nothing renders.\n * A value that already names a style is returned untouched, including the older one-class\n * `fa fa-folder` form that the generated forms still use.\n *\n * @param style the style to assume for a bare name. Defaults to {@link DEFAULT_ICON_STYLE}.\n */\nexport function NormalizeIconClass(value: string | null | undefined, style: string = DEFAULT_ICON_STYLE): string {\n const trimmed = (value ?? '').trim().replace(/\\s+/g, ' ');\n if (trimmed.length === 0) return '';\n if (hasStylePrefix(trimmed)) return trimmed;\n // A bare name without the fa- prefix is still meant as an icon name.\n const named = trimmed.startsWith('fa-') ? trimmed : `fa-${trimmed}`;\n return `${style} ${named}`;\n}\n\n/** The icon name inside a class string, without its style or `fa-` prefix. */\nexport function IconNameOf(value: string | null | undefined): string {\n const classes = (value ?? '').trim().split(/\\s+/).filter((c) => c.length > 0);\n const name = classes.find((c) => c.startsWith('fa-') && !STYLE_PREFIXES.includes(c) && !NON_ICON_CLASSES.has(c));\n return name ? name.slice(3) : '';\n}\n\n/**\n * Icon names and glyphs the loaded stylesheets define.\n *\n * A rule qualifies when it styles `.fa-<name>` with `::before` content, which is how Font\n * Awesome attaches a glyph — the sizing and animation helpers share the prefix but set no\n * content, so this tells the two apart without a list to maintain.\n */\nexport function ScanLoadedIconRules(doc: Document): IconGlyphRule[] {\n const found = new Map<string, string>();\n for (const sheet of Array.from(doc.styleSheets)) {\n let rules: CSSRuleList | null = null;\n try {\n rules = sheet.cssRules;\n } catch {\n // Served without CORS headers, so its rules are not readable from script.\n continue;\n }\n if (!rules) continue;\n for (const rule of Array.from(rules)) collectFromRule(rule, found);\n }\n return [...found.entries()]\n .map(([Name, Glyph]) => ({ Name, Glyph }))\n .sort((a, b) => a.Name.localeCompare(b.Name));\n}\n\nfunction collectFromRule(rule: CSSRule, found: Map<string, string>): void {\n const style = rule as CSSStyleRule;\n const selector = typeof style.selectorText === 'string' ? style.selectorText : '';\n if (!selector || (!selector.includes('::before') && !selector.includes(':before'))) return;\n const content = style.style?.getPropertyValue('content');\n if (!content) return;\n const glyph = GlyphFromContent(content);\n if (!glyph) return;\n for (const part of selector.split(',')) {\n const match = part.trim().match(/^\\.(fa-[a-z0-9-]+)::?before$/);\n if (!match) continue;\n const cls = match[1];\n if (NON_ICON_CLASSES.has(cls)) continue;\n found.set(cls.slice(3), glyph);\n }\n}\n\n/**\n * The character a `content` value names.\n *\n * Font Awesome writes it as a CSS escape — `content: \"\\f007\"` — which reaches script with\n * the quotes and the escape intact. A value naming anything else (a keyword, a counter,\n * a var it could not resolve) yields nothing, so it is skipped rather than measured.\n */\nexport function GlyphFromContent(content: string): string {\n const body = content.trim().replace(/^[\"']|[\"']$/g, '');\n const escaped = body.match(/^\\\\([0-9a-fA-F]{1,6})$/);\n if (escaped) return String.fromCodePoint(parseInt(escaped[1], 16));\n return body.length === 1 || [...body].length === 1 ? body : '';\n}\n\n/**\n * How each style renders, as the browser resolves it on this page.\n *\n * Probed rather than assumed: the font family carries the major version in its name\n * (`Font Awesome 6 Free`), and a host on another version, or on a kit, names it something\n * else. A style whose family does not resolve is left out — it is not loaded.\n */\nexport function ProbeIconStyleFonts(doc: Document, styles: readonly string[] = ICON_STYLES): IconStyleFont[] {\n const out: IconStyleFont[] = [];\n const host = doc.body ?? doc.documentElement;\n if (!host) return out;\n for (const style of styles) {\n const probe = doc.createElement('i');\n probe.className = style;\n probe.setAttribute('aria-hidden', 'true');\n probe.style.position = 'absolute';\n probe.style.left = '-99999px';\n host.appendChild(probe);\n try {\n const computed = doc.defaultView?.getComputedStyle(probe);\n const family = (computed?.fontFamily ?? '').trim();\n if (family && /font\\s*awesome/i.test(family)) {\n out.push({ Style: style, FontFamily: family, FontWeight: (computed?.fontWeight ?? '400').trim() });\n }\n } finally {\n host.removeChild(probe);\n }\n }\n return out;\n}\n\n/**\n * Whether a font has a glyph, decided by measuring it.\n *\n * Implemented by the caller so this module stays free of canvas and testable without one.\n * Returns true when `glyph` renders from `font` rather than falling back.\n */\nexport type GlyphPresenceTest = (glyph: string, font: IconStyleFont) => boolean;\n\n/**\n * Each icon paired with the style that actually draws it.\n *\n * The stylesheet says which icons exist but not which font holds each one, and drawing a\n * brands icon as solid produces a missing-glyph box — which is what a user sees as \"half\n * the icons are broken\". Styles are tried in order, so an icon present in several is\n * reported under the first, and an icon no loaded font has is dropped rather than offered\n * as a blank square.\n *\n * Names that draw the same glyph in the same style are one icon: the first name in `rules`\n * order is kept and the rest become its {@link FontAwesomeIcon.Aliases}, so the grid shows\n * each glyph once and a search for any of its names finds it.\n */\nexport function ResolveIconStyles(\n rules: readonly IconGlyphRule[],\n fonts: readonly IconStyleFont[],\n hasGlyph: GlyphPresenceTest,\n): FontAwesomeIcon[] {\n if (fonts.length === 0) return [];\n const out: FontAwesomeIcon[] = [];\n const byGlyph = new Map<string, FontAwesomeIcon>();\n for (const rule of rules) {\n const font = fonts.find((f) => hasGlyph(rule.Glyph, f));\n if (!font) continue;\n const key = `${font.Style}|${rule.Glyph}`;\n const kept = byGlyph.get(key);\n if (kept) {\n kept.Aliases = [...(kept.Aliases ?? []), rule.Name];\n continue;\n }\n const icon: FontAwesomeIcon = { Name: rule.Name, Style: font.Style };\n byGlyph.set(key, icon);\n out.push(icon);\n }\n return out;\n}\n\n/** How many icons the picker's grid draws at most; the rest are reached by searching. */\nexport const ICON_RESULT_LIMIT = 240;\n\n/**\n * Every icon matching a search, most relevant first: names that start with it, then names\n * that contain it. An icon matches by its name or by any of its aliases. An empty search\n * matches every icon.\n */\nexport function MatchIcons(icons: readonly FontAwesomeIcon[], search: string): FontAwesomeIcon[] {\n const needle = search.trim().toLowerCase().replace(/^fa-/, '');\n if (needle.length === 0) return [...icons];\n const starts: FontAwesomeIcon[] = [];\n const contains: FontAwesomeIcon[] = [];\n for (const icon of icons) {\n const names = [icon.Name, ...(icon.Aliases ?? [])];\n if (names.some((name) => name.startsWith(needle))) starts.push(icon);\n else if (names.some((name) => name.includes(needle))) contains.push(icon);\n }\n return [...starts, ...contains];\n}\n\n/** The first `limit` icons {@link MatchIcons} finds for a search. */\nexport function FilterIcons(icons: readonly FontAwesomeIcon[], search: string, limit = ICON_RESULT_LIMIT): FontAwesomeIcon[] {\n return MatchIcons(icons, search).slice(0, limit);\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type FontAwesomeIcon } from './font-awesome-icons';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* The Font Awesome icons this page can draw, worked out once and shared.
|
|
5
|
+
*
|
|
6
|
+
* Answering it means walking every CSS rule in the document and then measuring a couple of
|
|
7
|
+
* thousand glyphs, so it is done on first ask and kept. A picker that recomputed per open
|
|
8
|
+
* would stall each time it was used.
|
|
9
|
+
*/
|
|
10
|
+
export declare class IconCatalogueService {
|
|
11
|
+
private catalogue;
|
|
12
|
+
private loading;
|
|
13
|
+
private fallback;
|
|
14
|
+
/**
|
|
15
|
+
* Every icon on offer, with the style that draws it.
|
|
16
|
+
*
|
|
17
|
+
* Each style has to be FETCHED before it can be measured. A browser loads a web font
|
|
18
|
+
* only when something on the page uses it, so an app drawing solid icons has the solid
|
|
19
|
+
* font and neither of the others — and measuring then reports every brands and regular
|
|
20
|
+
* icon as missing, which is most of the catalogue.
|
|
21
|
+
*
|
|
22
|
+
* Falls back to a short built-in list when the stylesheets cannot be read — a
|
|
23
|
+
* cross-origin sheet without CORS headers throws on `cssRules` — or when reading them
|
|
24
|
+
* fails in any other way, so the picker always has something to show.
|
|
25
|
+
*/
|
|
26
|
+
Load(doc?: Document): Promise<readonly FontAwesomeIcon[]>;
|
|
27
|
+
/**
|
|
28
|
+
* What is known right now, without waiting.
|
|
29
|
+
*
|
|
30
|
+
* Empty until {@link Load} has finished, which is the honest answer: a caller that
|
|
31
|
+
* rendered this before the fonts arrived would draw the short fallback list and then
|
|
32
|
+
* replace it, which reads as the picker changing its mind.
|
|
33
|
+
*/
|
|
34
|
+
Icons(): readonly FontAwesomeIcon[];
|
|
35
|
+
/** True when the built-in list is standing in because the page could not be read. */
|
|
36
|
+
IsFallback(): boolean;
|
|
37
|
+
/** Forgets the catalogue, for a page that loads a different icon set later. */
|
|
38
|
+
Forget(): void;
|
|
39
|
+
private build;
|
|
40
|
+
/** Keeps the short built-in list as the catalogue. */
|
|
41
|
+
private useFallback;
|
|
42
|
+
/**
|
|
43
|
+
* Fetch each style's font file, returning the ones that arrived.
|
|
44
|
+
*
|
|
45
|
+
* `document.fonts.load` resolves once the face is usable by canvas. A style that fails
|
|
46
|
+
* to load is dropped rather than measured, because measuring it would report every one
|
|
47
|
+
* of its icons as missing and quietly halve the catalogue.
|
|
48
|
+
*/
|
|
49
|
+
private fetchFonts;
|
|
50
|
+
/**
|
|
51
|
+
* A test for whether a font really has a glyph, by measuring it.
|
|
52
|
+
*
|
|
53
|
+
* The family is named ALONE, with no fallback behind it, and the glyph's width is
|
|
54
|
+
* compared against a codepoint no icon font defines. A glyph the font lacks is drawn
|
|
55
|
+
* by the browser's last-resort font, exactly as the control is, so the two measure the
|
|
56
|
+
* same — while a glyph it has measures at the icon's own advance width.
|
|
57
|
+
*
|
|
58
|
+
* Comparing against the same family instead of against a second font stack is what
|
|
59
|
+
* makes this sound. Font Awesome Free ships two faces under ONE family name, solid at
|
|
60
|
+
* weight 900 and regular at 400, so a glyph missing from the requested weight is drawn
|
|
61
|
+
* from the other one before any fallback is reached — and a comparison that assumed
|
|
62
|
+
* the fallback had been reached read that as a hit.
|
|
63
|
+
*
|
|
64
|
+
* Returns null where there is no canvas to measure with, in which case the caller
|
|
65
|
+
* falls back rather than offering every icon in every style.
|
|
66
|
+
*/
|
|
67
|
+
private glyphTest;
|
|
68
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<IconCatalogueService, never>;
|
|
69
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<IconCatalogueService>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=icon-catalogue.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-catalogue.service.d.ts","sourceRoot":"","sources":["../../../src/lib/icon-picker/icon-catalogue.service.ts"],"names":[],"mappings":"AACA,OAAO,EAKH,KAAK,eAAe,EAEvB,MAAM,sBAAsB,CAAC;;AAE9B;;;;;;GAMG;AACH,qBACa,oBAAoB;IAC7B,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,OAAO,CAAoD;IACnE,OAAO,CAAC,QAAQ,CAAS;IAEzB;;;;;;;;;;;OAWG;IACU,IAAI,CAAC,GAAG,GAAE,QAAmB,GAAG,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IAWhF;;;;;;OAMG;IACI,KAAK,IAAI,SAAS,eAAe,EAAE;IAI1C,qFAAqF;IAC9E,UAAU,IAAI,OAAO;IAI5B,+EAA+E;IACxE,MAAM,IAAI,IAAI;YAMP,KAAK;IAYnB,sDAAsD;IACtD,OAAO,CAAC,WAAW;IAMnB;;;;;;OAMG;YACW,UAAU;IAexB;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,SAAS;yCA7GR,oBAAoB;6CAApB,oBAAoB;CAkIhC"}
|