ngwr 12.2.0 → 13.0.1
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/README.md +11 -1
- package/border-glow/border-glow.scss +1 -1
- package/border-glow/styles/_index.scss +15 -233
- package/border-glow/styles/_rules.scss +228 -0
- package/breadcrumbs/breadcrumbs.scss +1 -1
- package/breadcrumbs/styles/_index.scss +15 -78
- package/breadcrumbs/styles/_rules.scss +84 -0
- package/card/card.scss +1 -1
- package/card/styles/_index.scss +15 -96
- package/card/styles/_rules.scss +96 -0
- package/cascader/cascader.scss +1 -1
- package/cascader/styles/_index.scss +15 -244
- package/cascader/styles/_rules.scss +261 -0
- package/checkbox/styles/_index.scss +7 -0
- package/circular-text/circular-text.scss +1 -1
- package/circular-text/styles/_index.scss +15 -63
- package/circular-text/styles/_rules.scss +58 -0
- package/color-picker/styles/_index.scss +8 -0
- package/drag-drop/sortable-list.scss +1 -1
- package/drag-drop/styles/_index.scss +14 -143
- package/drag-drop/styles/_rules.scss +151 -0
- package/falling-text/falling-text.scss +1 -1
- package/falling-text/styles/_index.scss +15 -36
- package/falling-text/styles/_rules.scss +31 -0
- package/fesm2022/ngwr-border-glow.mjs +14 -5
- package/fesm2022/ngwr-border-glow.mjs.map +1 -1
- package/fesm2022/ngwr-breadcrumbs.mjs +15 -4
- package/fesm2022/ngwr-breadcrumbs.mjs.map +1 -1
- package/fesm2022/ngwr-card.mjs +2 -2
- package/fesm2022/ngwr-card.mjs.map +1 -1
- package/fesm2022/ngwr-cascader.mjs +27 -9
- package/fesm2022/ngwr-cascader.mjs.map +1 -1
- package/fesm2022/ngwr-checkbox.mjs +86 -8
- package/fesm2022/ngwr-checkbox.mjs.map +1 -1
- package/fesm2022/ngwr-circular-text.mjs +2 -2
- package/fesm2022/ngwr-circular-text.mjs.map +1 -1
- package/fesm2022/ngwr-color-picker.mjs +57 -7
- package/fesm2022/ngwr-color-picker.mjs.map +1 -1
- package/fesm2022/ngwr-context-menu.mjs +6 -2
- package/fesm2022/ngwr-context-menu.mjs.map +1 -1
- package/fesm2022/ngwr-date-picker.mjs +8 -0
- package/fesm2022/ngwr-date-picker.mjs.map +1 -1
- package/fesm2022/ngwr-dialog.mjs +22 -16
- package/fesm2022/ngwr-dialog.mjs.map +1 -1
- package/fesm2022/ngwr-directives.mjs +5 -2
- package/fesm2022/ngwr-directives.mjs.map +1 -1
- package/fesm2022/ngwr-drag-drop.mjs +2 -2
- package/fesm2022/ngwr-drag-drop.mjs.map +1 -1
- package/fesm2022/ngwr-drawer.mjs +24 -18
- package/fesm2022/ngwr-drawer.mjs.map +1 -1
- package/fesm2022/ngwr-dropdown.mjs +6 -2
- package/fesm2022/ngwr-dropdown.mjs.map +1 -1
- package/fesm2022/ngwr-falling-text.mjs +2 -2
- package/fesm2022/ngwr-falling-text.mjs.map +1 -1
- package/fesm2022/ngwr-file-upload.mjs +29 -8
- package/fesm2022/ngwr-file-upload.mjs.map +1 -1
- package/fesm2022/ngwr-form.mjs +48 -1
- package/fesm2022/ngwr-form.mjs.map +1 -1
- package/fesm2022/ngwr-fuzzy-text.mjs +21 -4
- package/fesm2022/ngwr-fuzzy-text.mjs.map +1 -1
- package/fesm2022/ngwr-glitch-text.mjs +2 -2
- package/fesm2022/ngwr-glitch-text.mjs.map +1 -1
- package/fesm2022/ngwr-gradient-text.mjs +11 -4
- package/fesm2022/ngwr-gradient-text.mjs.map +1 -1
- package/fesm2022/ngwr-icon-adapters-feather.mjs +11 -0
- package/fesm2022/ngwr-icon-adapters-feather.mjs.map +1 -1
- package/fesm2022/ngwr-icon-adapters-lucide.mjs +22 -2
- package/fesm2022/ngwr-icon-adapters-lucide.mjs.map +1 -1
- package/fesm2022/ngwr-icon.mjs +474 -37
- package/fesm2022/ngwr-icon.mjs.map +1 -1
- package/fesm2022/ngwr-input-otp.mjs +41 -3
- package/fesm2022/ngwr-input-otp.mjs.map +1 -1
- package/fesm2022/ngwr-knob.mjs +17 -2
- package/fesm2022/ngwr-knob.mjs.map +1 -1
- package/fesm2022/ngwr-lightbox.mjs +2 -2
- package/fesm2022/ngwr-lightbox.mjs.map +1 -1
- package/fesm2022/ngwr-list.mjs +2 -2
- package/fesm2022/ngwr-list.mjs.map +1 -1
- package/fesm2022/ngwr-loading-bar.mjs +2 -2
- package/fesm2022/ngwr-loading-bar.mjs.map +1 -1
- package/fesm2022/ngwr-markdown.mjs +63 -11
- package/fesm2022/ngwr-markdown.mjs.map +1 -1
- package/fesm2022/ngwr-marquee.mjs +2 -2
- package/fesm2022/ngwr-marquee.mjs.map +1 -1
- package/fesm2022/ngwr-overlay.mjs +36 -7
- package/fesm2022/ngwr-overlay.mjs.map +1 -1
- package/fesm2022/ngwr-pagination.mjs +1 -1
- package/fesm2022/ngwr-pagination.mjs.map +1 -1
- package/fesm2022/ngwr-qr.mjs +38 -1
- package/fesm2022/ngwr-qr.mjs.map +1 -1
- package/fesm2022/ngwr-radio.mjs +63 -8
- package/fesm2022/ngwr-radio.mjs.map +1 -1
- package/fesm2022/ngwr-rating.mjs +17 -2
- package/fesm2022/ngwr-rating.mjs.map +1 -1
- package/fesm2022/ngwr-segmented.mjs +22 -3
- package/fesm2022/ngwr-segmented.mjs.map +1 -1
- package/fesm2022/ngwr-select.mjs +46 -12
- package/fesm2022/ngwr-select.mjs.map +1 -1
- package/fesm2022/ngwr-shiny-text.mjs +12 -5
- package/fesm2022/ngwr-shiny-text.mjs.map +1 -1
- package/fesm2022/ngwr-slider.mjs +21 -6
- package/fesm2022/ngwr-slider.mjs.map +1 -1
- package/fesm2022/ngwr-spotlight-card.mjs +2 -2
- package/fesm2022/ngwr-spotlight-card.mjs.map +1 -1
- package/fesm2022/ngwr-star-border.mjs +2 -2
- package/fesm2022/ngwr-star-border.mjs.map +1 -1
- package/fesm2022/ngwr-switch.mjs +44 -4
- package/fesm2022/ngwr-switch.mjs.map +1 -1
- package/fesm2022/ngwr-table.mjs +1 -1
- package/fesm2022/ngwr-table.mjs.map +1 -1
- package/fesm2022/ngwr-tabs.mjs +6 -2
- package/fesm2022/ngwr-tabs.mjs.map +1 -1
- package/fesm2022/ngwr-textarea.mjs +5 -2
- package/fesm2022/ngwr-textarea.mjs.map +1 -1
- package/fesm2022/ngwr-theme.mjs +41 -1
- package/fesm2022/ngwr-theme.mjs.map +1 -1
- package/fesm2022/ngwr-tilt-card.mjs +2 -2
- package/fesm2022/ngwr-tilt-card.mjs.map +1 -1
- package/fesm2022/ngwr-transfer.mjs +38 -6
- package/fesm2022/ngwr-transfer.mjs.map +1 -1
- package/fesm2022/ngwr-tree.mjs +33 -7
- package/fesm2022/ngwr-tree.mjs.map +1 -1
- package/fesm2022/ngwr-typewriter.mjs +2 -2
- package/fesm2022/ngwr-typewriter.mjs.map +1 -1
- package/fesm2022/ngwr-utils.mjs +107 -1
- package/fesm2022/ngwr-utils.mjs.map +1 -1
- package/fesm2022/ngwr-version.mjs +1 -1
- package/fesm2022/ngwr-version.mjs.map +1 -1
- package/fesm2022/ngwr-virtual-scroll.mjs +2 -2
- package/fesm2022/ngwr-virtual-scroll.mjs.map +1 -1
- package/fesm2022/ngwr-waves.mjs +2 -2
- package/fesm2022/ngwr-waves.mjs.map +1 -1
- package/file-upload/styles/_index.scss +6 -0
- package/glitch-text/glitch-text.scss +1 -1
- package/glitch-text/styles/_index.scss +14 -164
- package/glitch-text/styles/_rules.scss +160 -0
- package/gradient-text/gradient-text.scss +1 -1
- package/gradient-text/styles/_index.scss +15 -118
- package/gradient-text/styles/_rules.scss +113 -0
- package/input/styles/_index.scss +13 -0
- package/input-otp/styles/_index.scss +8 -0
- package/lightbox/lightbox.scss +1 -1
- package/lightbox/styles/_index.scss +15 -191
- package/lightbox/styles/_rules.scss +198 -0
- package/list/list.scss +1 -1
- package/list/styles/_index.scss +15 -101
- package/list/styles/_rules.scss +108 -0
- package/llms-full.txt +4 -4
- package/loading-bar/loading-bar.scss +1 -1
- package/loading-bar/styles/_index.scss +15 -33
- package/loading-bar/styles/_rules.scss +28 -0
- package/marquee/marquee.scss +1 -1
- package/marquee/styles/_index.scss +15 -155
- package/marquee/styles/_rules.scss +150 -0
- package/package.json +3 -3
- package/segmented/styles/_index.scss +8 -0
- package/select/styles/_index.scss +17 -1
- package/shiny-text/shiny-text.scss +1 -1
- package/shiny-text/styles/_index.scss +14 -105
- package/shiny-text/styles/_rules.scss +101 -0
- package/slider/styles/_index.scss +8 -0
- package/spotlight-card/spotlight-card.scss +1 -1
- package/spotlight-card/styles/_index.scss +15 -52
- package/spotlight-card/styles/_rules.scss +47 -0
- package/star-border/star-border.scss +1 -1
- package/star-border/styles/_index.scss +15 -125
- package/star-border/styles/_rules.scss +120 -0
- package/switch/styles/_index.scss +7 -0
- package/theme/styles/_dark.scss +81 -4
- package/theme/styles/_index.scss +1 -0
- package/theme/styles/_motion.scss +94 -0
- package/tilt-card/styles/_index.scss +15 -45
- package/tilt-card/styles/_rules.scss +40 -0
- package/tilt-card/tilt-card.scss +1 -1
- package/tree/styles/_index.scss +15 -1
- package/types/ngwr-breadcrumbs.d.ts +1 -0
- package/types/ngwr-cascader.d.ts +17 -1
- package/types/ngwr-checkbox.d.ts +51 -3
- package/types/ngwr-color-picker.d.ts +19 -1
- package/types/ngwr-file-upload.d.ts +18 -1
- package/types/ngwr-form.d.ts +51 -2
- package/types/ngwr-fuzzy-text.d.ts +5 -0
- package/types/ngwr-icon-adapters-feather.d.ts +11 -0
- package/types/ngwr-icon.d.ts +42 -1
- package/types/ngwr-input-otp.d.ts +23 -1
- package/types/ngwr-knob.d.ts +14 -0
- package/types/ngwr-radio.d.ts +37 -2
- package/types/ngwr-rating.d.ts +14 -0
- package/types/ngwr-segmented.d.ts +18 -1
- package/types/ngwr-select.d.ts +17 -1
- package/types/ngwr-shiny-text.d.ts +1 -0
- package/types/ngwr-slider.d.ts +14 -1
- package/types/ngwr-switch.d.ts +26 -2
- package/types/ngwr-textarea.d.ts +3 -0
- package/types/ngwr-theme.d.ts +24 -0
- package/types/ngwr-transfer.d.ts +17 -1
- package/types/ngwr-tree.d.ts +21 -1
- package/types/ngwr-utils.d.ts +47 -1
- package/types/ngwr-version.d.ts +1 -1
- package/typewriter/styles/_index.scss +15 -38
- package/typewriter/styles/_rules.scss +33 -0
- package/typewriter/typewriter.scss +1 -1
- package/virtual-scroll/styles/_index.scss +15 -32
- package/virtual-scroll/styles/_rules.scss +27 -0
- package/virtual-scroll/virtual-scroll.scss +1 -1
- package/waves/styles/_index.scss +15 -50
- package/waves/styles/_rules.scss +45 -0
- package/waves/waves.scss +1 -1
package/fesm2022/ngwr-icon.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DOCUMENT } from '@angular/common';
|
|
1
2
|
import * as i0 from '@angular/core';
|
|
2
3
|
import { InjectionToken, inject, Injectable, input, ElementRef, computed, effect, isDevMode, ViewEncapsulation, Component } from '@angular/core';
|
|
3
4
|
|
|
@@ -60,6 +61,402 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
60
61
|
type: Injectable
|
|
61
62
|
}] });
|
|
62
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @license
|
|
66
|
+
*
|
|
67
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
68
|
+
* found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE
|
|
69
|
+
*/
|
|
70
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
71
|
+
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
72
|
+
/**
|
|
73
|
+
* SVG elements an icon may be built from.
|
|
74
|
+
*
|
|
75
|
+
* Derived from the real sets rather than guessed: across the 12 459 SVG files
|
|
76
|
+
* under `icon/_svg` (Lucide, Phosphor, Tabler, Heroicons), the whole of
|
|
77
|
+
* `feather-icons`' `icons.json` and every `lucide` IconNode, only eight
|
|
78
|
+
* elements ever appear — `svg`, `path`, `circle`, `line`, `rect`, `polyline`,
|
|
79
|
+
* `polygon`, `ellipse`. The rest of this list is headroom for the icons a
|
|
80
|
+
* consumer draws themselves: grouping, `<defs>` with gradients, a clip path, a
|
|
81
|
+
* mask, a `<title>`, real `<text>`.
|
|
82
|
+
*
|
|
83
|
+
* What is deliberately absent is the entire scripting surface:
|
|
84
|
+
*
|
|
85
|
+
* - `<script>` — obvious, and the one vector `innerHTML` already refused;
|
|
86
|
+
* - `<foreignObject>` — an XHTML escape hatch, so `<img onerror>` inside an
|
|
87
|
+
* otherwise well-formed icon;
|
|
88
|
+
* - `<image>` — its `onerror` fires on any unreachable `href`, which is the
|
|
89
|
+
* cheapest handler to land, and no real icon set uses it;
|
|
90
|
+
* - `<a>` — a `javascript:` href inside a glyph the user is invited to click;
|
|
91
|
+
* - `<animate>` / `<set>` / `<animateTransform>` / `<animateMotion>` — SMIL can
|
|
92
|
+
* retarget another element's `href` at a `javascript:` URL;
|
|
93
|
+
* - `<style>` — arbitrary CSS in the app's origin, including `url()` requests;
|
|
94
|
+
* - `<filter>` and the `fe*` primitives — `<feImage href>` is another external
|
|
95
|
+
* fetch, and no icon set in the corpus filters.
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
const ELEMENTS = new Set([
|
|
100
|
+
'svg',
|
|
101
|
+
'g',
|
|
102
|
+
'defs',
|
|
103
|
+
'symbol',
|
|
104
|
+
'use',
|
|
105
|
+
'title',
|
|
106
|
+
'desc',
|
|
107
|
+
'path',
|
|
108
|
+
'circle',
|
|
109
|
+
'ellipse',
|
|
110
|
+
'line',
|
|
111
|
+
'polyline',
|
|
112
|
+
'polygon',
|
|
113
|
+
'rect',
|
|
114
|
+
'text',
|
|
115
|
+
'tspan',
|
|
116
|
+
'textPath',
|
|
117
|
+
'linearGradient',
|
|
118
|
+
'radialGradient',
|
|
119
|
+
'stop',
|
|
120
|
+
'clipPath',
|
|
121
|
+
'mask',
|
|
122
|
+
'pattern',
|
|
123
|
+
]);
|
|
124
|
+
/**
|
|
125
|
+
* Attributes an icon may carry, allowed on every element it is allowed on.
|
|
126
|
+
*
|
|
127
|
+
* An allowlist rather than a blocklist, so `onload`, `onerror`, `onclick` and
|
|
128
|
+
* every other handler — including ones no browser has shipped yet — are gone by
|
|
129
|
+
* construction rather than by enumeration.
|
|
130
|
+
*
|
|
131
|
+
* `style` is NOT here, and that is a decision rather than an oversight: not one
|
|
132
|
+
* icon in the corpus uses it, and a `style` attribute is arbitrary CSS in the
|
|
133
|
+
* app's origin. Anything a `style` would have done, a presentation attribute
|
|
134
|
+
* does.
|
|
135
|
+
*
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
const ATTRIBUTES = new Set([
|
|
139
|
+
// geometry
|
|
140
|
+
'viewBox',
|
|
141
|
+
'preserveAspectRatio',
|
|
142
|
+
'transform',
|
|
143
|
+
'transform-origin',
|
|
144
|
+
'd',
|
|
145
|
+
'pathLength',
|
|
146
|
+
'cx',
|
|
147
|
+
'cy',
|
|
148
|
+
'r',
|
|
149
|
+
'rx',
|
|
150
|
+
'ry',
|
|
151
|
+
'x',
|
|
152
|
+
'y',
|
|
153
|
+
'x1',
|
|
154
|
+
'y1',
|
|
155
|
+
'x2',
|
|
156
|
+
'y2',
|
|
157
|
+
'dx',
|
|
158
|
+
'dy',
|
|
159
|
+
'width',
|
|
160
|
+
'height',
|
|
161
|
+
'points',
|
|
162
|
+
// paint servers, clips and masks
|
|
163
|
+
'gradientUnits',
|
|
164
|
+
'gradientTransform',
|
|
165
|
+
'spreadMethod',
|
|
166
|
+
'offset',
|
|
167
|
+
'fx',
|
|
168
|
+
'fy',
|
|
169
|
+
'fr',
|
|
170
|
+
'patternUnits',
|
|
171
|
+
'patternContentUnits',
|
|
172
|
+
'patternTransform',
|
|
173
|
+
'maskUnits',
|
|
174
|
+
'maskContentUnits',
|
|
175
|
+
'clipPathUnits',
|
|
176
|
+
// presentation
|
|
177
|
+
'fill',
|
|
178
|
+
'fill-opacity',
|
|
179
|
+
'fill-rule',
|
|
180
|
+
'stroke',
|
|
181
|
+
'stroke-width',
|
|
182
|
+
'stroke-linecap',
|
|
183
|
+
'stroke-linejoin',
|
|
184
|
+
'stroke-miterlimit',
|
|
185
|
+
'stroke-dasharray',
|
|
186
|
+
'stroke-dashoffset',
|
|
187
|
+
'stroke-opacity',
|
|
188
|
+
'opacity',
|
|
189
|
+
'color',
|
|
190
|
+
'clip-path',
|
|
191
|
+
'clip-rule',
|
|
192
|
+
'mask',
|
|
193
|
+
'paint-order',
|
|
194
|
+
'vector-effect',
|
|
195
|
+
'shape-rendering',
|
|
196
|
+
'stop-color',
|
|
197
|
+
'stop-opacity',
|
|
198
|
+
'display',
|
|
199
|
+
'visibility',
|
|
200
|
+
'overflow',
|
|
201
|
+
'isolation',
|
|
202
|
+
'mix-blend-mode',
|
|
203
|
+
// text
|
|
204
|
+
'startOffset',
|
|
205
|
+
'textLength',
|
|
206
|
+
'lengthAdjust',
|
|
207
|
+
'text-anchor',
|
|
208
|
+
'dominant-baseline',
|
|
209
|
+
'alignment-baseline',
|
|
210
|
+
'baseline-shift',
|
|
211
|
+
'font-family',
|
|
212
|
+
'font-size',
|
|
213
|
+
'font-stretch',
|
|
214
|
+
'font-style',
|
|
215
|
+
'font-variant',
|
|
216
|
+
'font-weight',
|
|
217
|
+
'letter-spacing',
|
|
218
|
+
'word-spacing',
|
|
219
|
+
'writing-mode',
|
|
220
|
+
'direction',
|
|
221
|
+
// identity, accessibility and document plumbing
|
|
222
|
+
'id',
|
|
223
|
+
'class',
|
|
224
|
+
'role',
|
|
225
|
+
'aria-hidden',
|
|
226
|
+
'aria-label',
|
|
227
|
+
'aria-labelledby',
|
|
228
|
+
'aria-describedby',
|
|
229
|
+
'aria-roledescription',
|
|
230
|
+
'focusable',
|
|
231
|
+
'lang',
|
|
232
|
+
'version',
|
|
233
|
+
'baseProfile',
|
|
234
|
+
'xmlns',
|
|
235
|
+
'xmlns:xlink',
|
|
236
|
+
'xml:space',
|
|
237
|
+
'xml:lang',
|
|
238
|
+
// resolved against ONLY_FRAGMENT below, never free-form
|
|
239
|
+
'href',
|
|
240
|
+
'xlink:href',
|
|
241
|
+
]);
|
|
242
|
+
/**
|
|
243
|
+
* `href` may point at a fragment in the same document and nowhere else — that
|
|
244
|
+
* is the whole legitimate use inside an icon (`<use href="#glyph">`), and it
|
|
245
|
+
* excludes `javascript:`, `data:` and every remote fetch in one rule.
|
|
246
|
+
*/
|
|
247
|
+
const FRAGMENT_ONLY = new Set(['href', 'xlink:href']);
|
|
248
|
+
/** A same-document fragment reference: `#id`, and nothing that is not one. */
|
|
249
|
+
const FRAGMENT_RE = /^#[^\s]+$/;
|
|
250
|
+
/**
|
|
251
|
+
* `url(` inside a presentation attribute is a reference to a paint server, a
|
|
252
|
+
* clip path or a mask. Those are fragment references too; a remote one is at
|
|
253
|
+
* best a request the page did not ask for.
|
|
254
|
+
*/
|
|
255
|
+
const URL_FN_RE = /url\(/i;
|
|
256
|
+
const URL_FRAGMENT_RE = /^url\(\s*(['"]?)#[^\s'")]+\1\s*\)$/i;
|
|
257
|
+
/**
|
|
258
|
+
* Icons are shallow — the deepest in the corpus nests three levels. The cap is
|
|
259
|
+
* there so a hostile registration cannot recurse this function into a stack
|
|
260
|
+
* overflow; content below it is dropped, not truncated silently, because
|
|
261
|
+
* {@link WrIconStripReport} names what went.
|
|
262
|
+
*/
|
|
263
|
+
const MAX_DEPTH = 16;
|
|
264
|
+
/**
|
|
265
|
+
* Build a live `<svg>` element out of a registered icon's markup, keeping only
|
|
266
|
+
* what an icon legitimately needs.
|
|
267
|
+
*
|
|
268
|
+
* `<wr-icon>` used to assign `icon.data` to `innerHTML`, which executes an
|
|
269
|
+
* `onload` on the root, an `<image onerror>`, an `<img>` smuggled in after a
|
|
270
|
+
* closed `</svg>`, and anything inside a `<foreignObject>` — with the app's own
|
|
271
|
+
* origin, in a production build. The library already refuses exactly this next
|
|
272
|
+
* door: `<wr-markdown>` escapes raw HTML because its input is untrusted by
|
|
273
|
+
* construction and one `<img onerror>` is the whole cost of being wrong. Icon
|
|
274
|
+
* data arrives from `provideWrIcons()`, which a multi-tenant app or a fetched
|
|
275
|
+
* icon pack fills at runtime, so it is untrusted the same way.
|
|
276
|
+
*
|
|
277
|
+
* Three properties do the work, and none of them is a filter over known-bad
|
|
278
|
+
* strings:
|
|
279
|
+
*
|
|
280
|
+
* 1. **Parsed inert, never inserted.** The markup is parsed into a document
|
|
281
|
+
* with no browsing context, so nothing loads and nothing runs even before it
|
|
282
|
+
* is inspected.
|
|
283
|
+
* 2. **Only the first `<svg>` survives.** An icon IS an SVG element, so
|
|
284
|
+
* everything beside the root is dropped — which is what makes
|
|
285
|
+
* `</svg><img src=x onerror=…>` inert regardless of what the payload says,
|
|
286
|
+
* and it is the same shape as the `feather()` shell escape.
|
|
287
|
+
* 3. **Rebuilt, not filtered.** Every element and attribute that lands in the
|
|
288
|
+
* document is one this file created from an allowlist. Nothing is
|
|
289
|
+
* transferred from the parsed tree, so there is no attribute an unfamiliar
|
|
290
|
+
* payload can smuggle past a matcher.
|
|
291
|
+
*
|
|
292
|
+
* A refused element takes its subtree with it rather than having its children
|
|
293
|
+
* hoisted into its parent. Hoisting would preserve more of a hand-drawn icon
|
|
294
|
+
* wrapped in something unsupported, and it is exactly the kind of cleverness
|
|
295
|
+
* that makes "what does the output contain" depend on what the parser saw. The
|
|
296
|
+
* blunt rule is the reviewable one, and the dev-mode warning names what went.
|
|
297
|
+
*
|
|
298
|
+
* `DomSanitizer.sanitize(SecurityContext.HTML, …)` is not an option here, which
|
|
299
|
+
* is worth recording so it is not re-proposed: Angular's HTML allowlist
|
|
300
|
+
* (`VOID_ELEMENTS`, `BLOCK_ELEMENTS`, `INLINE_ELEMENTS`) contains no SVG
|
|
301
|
+
* element at all. Run against real Lucide, Feather and Heroicons icons it does
|
|
302
|
+
* not merely drop presentation attributes — it returns the empty string.
|
|
303
|
+
*
|
|
304
|
+
* @returns the rebuilt element, or `null` when the data holds no `<svg>` root.
|
|
305
|
+
* @internal
|
|
306
|
+
*/
|
|
307
|
+
function sanitizeIcon(doc, data, report) {
|
|
308
|
+
const source = parseInert(doc, data);
|
|
309
|
+
return source ? copy(doc, source, report, 0) : null;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Parse into a document that cannot run anything.
|
|
313
|
+
*
|
|
314
|
+
* `DOMParser` is the path every browser and the unit-test DOM take: it takes a
|
|
315
|
+
* plain string, so it is not a Trusted Types sink, and its result has no
|
|
316
|
+
* browsing context. It does not exist under SSR — `@angular/platform-server`
|
|
317
|
+
* renders into domino — so the server falls back to a detached `<template>`,
|
|
318
|
+
* whose content is a separate inert document for the same reason. That branch
|
|
319
|
+
* is unreachable in a browser, which is what keeps the innerHTML write out of
|
|
320
|
+
* the only place Trusted Types is enforced.
|
|
321
|
+
*
|
|
322
|
+
* Both parsers were checked to agree on the part that matters: the HTML
|
|
323
|
+
* parser's foreign-content adjustment restores the camel case of `viewBox`,
|
|
324
|
+
* `clipPath`, `linearGradient`, `gradientTransform`, `textPath` and puts
|
|
325
|
+
* `xlink:href` in the xlink namespace.
|
|
326
|
+
*/
|
|
327
|
+
function parseInert(doc, data) {
|
|
328
|
+
const parser = doc.defaultView?.DOMParser;
|
|
329
|
+
if (parser)
|
|
330
|
+
return firstSvg(new parser().parseFromString(data, 'text/html').body);
|
|
331
|
+
const template = doc.createElement('template');
|
|
332
|
+
template.innerHTML = data;
|
|
333
|
+
return firstSvg(template.content);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The first `<svg>` in document order, found by walking rather than by
|
|
337
|
+
* `querySelector`.
|
|
338
|
+
*
|
|
339
|
+
* Two reasons, and the second is the one that matters. A control that decides
|
|
340
|
+
* what may execute should not route that decision through a selector engine —
|
|
341
|
+
* `localName === 'svg'` is a comparison anyone can check, and CSS parsing is a
|
|
342
|
+
* layer with its own history. The first reason is merely that it is faster:
|
|
343
|
+
* jsdom's engine costs 4 ms on a document this size, which the unit suite pays
|
|
344
|
+
* on every rendered icon.
|
|
345
|
+
*/
|
|
346
|
+
function firstSvg(root) {
|
|
347
|
+
const children = root.childNodes;
|
|
348
|
+
for (let i = 0, n = children.length; i < n; i++) {
|
|
349
|
+
const child = children[i];
|
|
350
|
+
if (child.nodeType !== 1)
|
|
351
|
+
continue;
|
|
352
|
+
const element = child;
|
|
353
|
+
if (element.localName === 'svg')
|
|
354
|
+
return element;
|
|
355
|
+
const nested = firstSvg(element);
|
|
356
|
+
if (nested)
|
|
357
|
+
return nested;
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
/** Recreate one element, then its allowed children, in the live document. */
|
|
362
|
+
function copy(doc, source, report, depth) {
|
|
363
|
+
const el = doc.createElementNS(SVG_NS, source.localName);
|
|
364
|
+
const attributes = source.attributes;
|
|
365
|
+
for (let i = 0, n = attributes.length; i < n; i++) {
|
|
366
|
+
const { name, value } = attributes[i];
|
|
367
|
+
if (!isAllowedAttribute(name, value)) {
|
|
368
|
+
report?.attributes.add(name);
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (name === 'xlink:href')
|
|
372
|
+
el.setAttributeNS(XLINK_NS, name, value);
|
|
373
|
+
else
|
|
374
|
+
el.setAttribute(name, value);
|
|
375
|
+
}
|
|
376
|
+
if (depth >= MAX_DEPTH) {
|
|
377
|
+
// Named, not silent — the cap is the one rule here that can bite an icon
|
|
378
|
+
// nobody meant as an attack, and a truncated glyph should say so.
|
|
379
|
+
if (source.childNodes.length > 0)
|
|
380
|
+
report?.elements.add(`… deeper than ${MAX_DEPTH} levels`);
|
|
381
|
+
return el;
|
|
382
|
+
}
|
|
383
|
+
const children = source.childNodes;
|
|
384
|
+
for (let i = 0, n = children.length; i < n; i++) {
|
|
385
|
+
const child = children[i];
|
|
386
|
+
// Text, so `<title>`, `<desc>` and `<text>` keep saying what they said.
|
|
387
|
+
// Comments, CDATA and processing instructions are dropped: an icon has no
|
|
388
|
+
// use for them and a comment is a place to hide a payload from a reader.
|
|
389
|
+
if (child.nodeType === 3) {
|
|
390
|
+
el.appendChild(doc.createTextNode(child.nodeValue ?? ''));
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (child.nodeType !== 1)
|
|
394
|
+
continue;
|
|
395
|
+
const element = child;
|
|
396
|
+
if (!ELEMENTS.has(element.localName)) {
|
|
397
|
+
report?.elements.add(element.localName);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
el.appendChild(copy(doc, element, report, depth + 1));
|
|
401
|
+
}
|
|
402
|
+
return el;
|
|
403
|
+
}
|
|
404
|
+
function isAllowedAttribute(name, value) {
|
|
405
|
+
// `data-*` is a styling and testing hook that can never be behavioural.
|
|
406
|
+
if (name.startsWith('data-'))
|
|
407
|
+
return true;
|
|
408
|
+
if (!ATTRIBUTES.has(name))
|
|
409
|
+
return false;
|
|
410
|
+
if (FRAGMENT_ONLY.has(name))
|
|
411
|
+
return FRAGMENT_RE.test(value.trim());
|
|
412
|
+
if (URL_FN_RE.test(value))
|
|
413
|
+
return URL_FRAGMENT_RE.test(value.trim());
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* @license
|
|
419
|
+
*
|
|
420
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
421
|
+
* found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE
|
|
422
|
+
*/
|
|
423
|
+
const VIEW_BOX_RE = /<svg\b[^>]*\bviewBox\s*=/i;
|
|
424
|
+
const SVG_ROOT_RE = /<svg\b/i;
|
|
425
|
+
/**
|
|
426
|
+
* Dev-mode sanity check for a registered icon — a **rendering** check, and
|
|
427
|
+
* explicitly not a security control.
|
|
428
|
+
*
|
|
429
|
+
* It warns about the two things that make an icon come out wrong: no `<svg>`
|
|
430
|
+
* root, and no `viewBox`, which stops the glyph scaling to the host. It reads
|
|
431
|
+
* the string with two regexes and cannot tell a shape from a script — every
|
|
432
|
+
* payload in the icon corpus passes it, because each one does carry an `<svg>`
|
|
433
|
+
* root with a `viewBox`. It also runs only under `isDevMode()`, so it is absent
|
|
434
|
+
* from the build an attacker would meet.
|
|
435
|
+
*
|
|
436
|
+
* What actually keeps hostile markup out of the DOM is {@link sanitizeIcon},
|
|
437
|
+
* which runs on every render in every build: `<wr-icon>` rebuilds the glyph
|
|
438
|
+
* from an allowlist instead of assigning to `innerHTML`. Anything this function
|
|
439
|
+
* would have to reject is already gone by then, and the component says so in
|
|
440
|
+
* dev mode when it drops something.
|
|
441
|
+
*
|
|
442
|
+
* Production builds drop the call entirely via `isDevMode()` tree-shaking.
|
|
443
|
+
*
|
|
444
|
+
* @internal
|
|
445
|
+
*/
|
|
446
|
+
function validateIcon(icon) {
|
|
447
|
+
if (!SVG_ROOT_RE.test(icon.data)) {
|
|
448
|
+
// eslint-disable-next-line no-console -- dev-mode validation
|
|
449
|
+
console.warn(`[NGWR] Icon "${icon.name}" data does not contain an <svg> root element. ` +
|
|
450
|
+
`Custom icons must be valid SVG markup.`);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (!VIEW_BOX_RE.test(icon.data)) {
|
|
454
|
+
// eslint-disable-next-line no-console -- dev-mode validation
|
|
455
|
+
console.warn(`[NGWR] Icon "${icon.name}" has no viewBox attribute — it won't scale ` +
|
|
456
|
+
`to the host size. Add viewBox="0 0 W H" to the <svg> root.`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
63
460
|
/**
|
|
64
461
|
* @license
|
|
65
462
|
*
|
|
@@ -83,6 +480,7 @@ class WrIcon {
|
|
|
83
480
|
name = input.required(/* @ts-ignore */
|
|
84
481
|
...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
|
|
85
482
|
host = inject(ElementRef);
|
|
483
|
+
doc = inject(DOCUMENT);
|
|
86
484
|
/**
|
|
87
485
|
* Every icon visible from this position, walked up the whole chain of
|
|
88
486
|
* registering injector levels.
|
|
@@ -118,17 +516,74 @@ class WrIcon {
|
|
|
118
516
|
`If the name IS registered, check the injector level: a component-level provideWrIcons() ` +
|
|
119
517
|
`shadows icons registered on an ancestor component.`);
|
|
120
518
|
}
|
|
121
|
-
this.
|
|
519
|
+
this.clear();
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
// Rebuilt from an allowlist rather than assigned to `innerHTML`, which
|
|
523
|
+
// ran an `onload` on the root, an `<image onerror>`, an `<img>` smuggled
|
|
524
|
+
// in after a closed `</svg>` and anything inside a `<foreignObject>` —
|
|
525
|
+
// in production builds, with the app's own origin. `provideWrIcons()`
|
|
526
|
+
// data is untrusted the same way `<wr-markdown>`'s input is: a tenant
|
|
527
|
+
// logo or a fetched icon pack is a normal way to fill it. Building nodes
|
|
528
|
+
// also keeps `<wr-icon>` clear of Trusted Types, which refuses the
|
|
529
|
+
// `innerHTML` write outright.
|
|
530
|
+
const report = isDevMode() ? { elements: new Set(), attributes: new Set() } : undefined;
|
|
531
|
+
const svg = sanitizeIcon(this.doc, icon.data, report);
|
|
532
|
+
if (!svg) {
|
|
533
|
+
if (isDevMode()) {
|
|
534
|
+
// eslint-disable-next-line no-console -- misconfiguration must be visible, but must not throw
|
|
535
|
+
console.error(`[NGWR] Icon "${name}" has no <svg> root element and cannot be rendered. ` +
|
|
536
|
+
`Custom icons must be valid SVG markup.`);
|
|
537
|
+
}
|
|
538
|
+
this.clear();
|
|
122
539
|
return;
|
|
123
540
|
}
|
|
124
|
-
this.host.nativeElement.innerHTML = icon.data;
|
|
125
541
|
// Every hand-written inline SVG in the library carries aria-hidden;
|
|
126
542
|
// registered icons went in without it, so a decorative glyph could be
|
|
127
543
|
// announced — usually as a bare "graphic" beside the label it decorates.
|
|
128
544
|
// Consumers that need a name put it on the interactive host instead.
|
|
129
|
-
|
|
545
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
546
|
+
this.clear();
|
|
547
|
+
this.host.nativeElement.appendChild(svg);
|
|
548
|
+
if (report)
|
|
549
|
+
this.reportStripped(name, icon, report);
|
|
130
550
|
});
|
|
131
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* `replaceChildren()` would say this in one call, but domino — the DOM
|
|
554
|
+
* `@angular/platform-server` renders into — does not implement it, and
|
|
555
|
+
* `innerHTML = ''` is the write Trusted Types refuses.
|
|
556
|
+
*/
|
|
557
|
+
clear() {
|
|
558
|
+
const el = this.host.nativeElement;
|
|
559
|
+
while (el.firstChild)
|
|
560
|
+
el.removeChild(el.firstChild);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Say what the allowlist removed, once per registered icon.
|
|
564
|
+
*
|
|
565
|
+
* A silently stripped icon is the failure mode this rebuild could introduce:
|
|
566
|
+
* a consumer's own glyph renders blank or wrong and nothing anywhere says
|
|
567
|
+
* why. Keyed on the definition object, so a page with fifty instances of the
|
|
568
|
+
* same icon warns once and an icon nobody renders never warns at all.
|
|
569
|
+
*/
|
|
570
|
+
reportStripped(name, icon, report) {
|
|
571
|
+
if (WrIcon.reported.has(icon))
|
|
572
|
+
return;
|
|
573
|
+
if (report.elements.size === 0 && report.attributes.size === 0)
|
|
574
|
+
return;
|
|
575
|
+
WrIcon.reported.add(icon);
|
|
576
|
+
const removed = [
|
|
577
|
+
report.elements.size ? `elements: ${[...report.elements].join(', ')}` : '',
|
|
578
|
+
report.attributes.size ? `attributes: ${[...report.attributes].join(', ')}` : '',
|
|
579
|
+
].filter(Boolean);
|
|
580
|
+
// eslint-disable-next-line no-console -- a stripped icon must not be silent
|
|
581
|
+
console.warn(`[NGWR] Icon "${name}" was rendered without part of its markup — ${removed.join('; ')}. ` +
|
|
582
|
+
`Registered icon data is treated as untrusted and rebuilt from an allowlist of SVG ` +
|
|
583
|
+
`shape, paint and text elements, so event handlers, <script>, <style>, <image>, ` +
|
|
584
|
+
`<foreignObject>, <a>, SMIL animation and non-fragment hrefs never reach the DOM.`);
|
|
585
|
+
}
|
|
586
|
+
static reported = new WeakSet();
|
|
132
587
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.4", ngImport: i0, type: WrIcon, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
133
588
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.1.4", type: WrIcon, isStandalone: true, selector: "wr-icon", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "attr.data-icon": "name()" }, classAttribute: "wr-icon" }, ngImport: i0, template: '', isInline: true, encapsulation: i0.ViewEncapsulation.None });
|
|
134
589
|
}
|
|
@@ -145,39 +600,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
145
600
|
}]
|
|
146
601
|
}], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }] } });
|
|
147
602
|
|
|
148
|
-
/**
|
|
149
|
-
* @license
|
|
150
|
-
*
|
|
151
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
152
|
-
* found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE
|
|
153
|
-
*/
|
|
154
|
-
const VIEW_BOX_RE = /<svg\b[^>]*\bviewBox\s*=/i;
|
|
155
|
-
const SVG_ROOT_RE = /<svg\b/i;
|
|
156
|
-
/**
|
|
157
|
-
* Dev-mode sanity check for a registered icon.
|
|
158
|
-
*
|
|
159
|
-
* Warns about issues that prevent correct rendering — most importantly,
|
|
160
|
-
* a missing `viewBox`, which causes the SVG not to scale to the icon
|
|
161
|
-
* host's size.
|
|
162
|
-
*
|
|
163
|
-
* Production builds drop the call entirely via `isDevMode()` tree-shaking.
|
|
164
|
-
*
|
|
165
|
-
* @internal
|
|
166
|
-
*/
|
|
167
|
-
function validateIcon(icon) {
|
|
168
|
-
if (!SVG_ROOT_RE.test(icon.data)) {
|
|
169
|
-
// eslint-disable-next-line no-console -- dev-mode validation
|
|
170
|
-
console.warn(`[NGWR] Icon "${icon.name}" data does not contain an <svg> root element. ` +
|
|
171
|
-
`Custom icons must be valid SVG markup.`);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (!VIEW_BOX_RE.test(icon.data)) {
|
|
175
|
-
// eslint-disable-next-line no-console -- dev-mode validation
|
|
176
|
-
console.warn(`[NGWR] Icon "${icon.name}" has no viewBox attribute — it won't scale ` +
|
|
177
|
-
`to the host size. Add viewBox="0 0 W H" to the <svg> root.`);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
603
|
/**
|
|
182
604
|
* @license
|
|
183
605
|
*
|
|
@@ -194,7 +616,13 @@ function validateIcon(icon) {
|
|
|
194
616
|
*
|
|
195
617
|
* In dev mode, each icon is validated for common issues (missing
|
|
196
618
|
* `viewBox`, malformed root). Validation is dropped from production
|
|
197
|
-
* builds via `isDevMode()` tree-shaking
|
|
619
|
+
* builds via `isDevMode()` tree-shaking, and it is a rendering check rather
|
|
620
|
+
* than a security one — see {@link validateIcon}.
|
|
621
|
+
*
|
|
622
|
+
* Icon `data` is treated as **untrusted** at render: `<wr-icon>` rebuilds the
|
|
623
|
+
* glyph from an allowlist instead of writing the string to `innerHTML`, so a
|
|
624
|
+
* set fetched at runtime or supplied by a tenant cannot execute in the app's
|
|
625
|
+
* origin. Dev mode names anything the allowlist removed.
|
|
198
626
|
*
|
|
199
627
|
* @example
|
|
200
628
|
* ```ts
|
|
@@ -272,6 +700,15 @@ function provideWrIcons(icons) {
|
|
|
272
700
|
* ],
|
|
273
701
|
* });
|
|
274
702
|
* ```
|
|
703
|
+
*
|
|
704
|
+
* **`svg` is treated as untrusted.** It is a string, so it is a natural place
|
|
705
|
+
* for a tenant's uploaded logo or an icon pack fetched from an API to end up,
|
|
706
|
+
* and `<wr-icon>` used to write it to `innerHTML`. It no longer does: the glyph
|
|
707
|
+
* is rebuilt from an allowlist of SVG shape, paint and text elements, so
|
|
708
|
+
* `<script>`, `<style>`, `<image>`, `<foreignObject>`, `<a>`, SMIL animation,
|
|
709
|
+
* every `on*` handler, `style` attributes and non-fragment `href`s are dropped
|
|
710
|
+
* before anything reaches the DOM. In dev mode the component names what it
|
|
711
|
+
* removed, so a legitimate icon that loses something says so out loud.
|
|
275
712
|
*/
|
|
276
713
|
function svgIcon(name, svg) {
|
|
277
714
|
return { name, data: svg };
|