@hamur/icon 0.0.0-stage → 0.0.2

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.
Files changed (88) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +14 -2
  3. package/dist/chunks/bun-react-fhd05zxm.js +206 -0
  4. package/dist/chunks/bun-react-nygte91t.js +305 -0
  5. package/dist/src/adapters/angular.js +104 -0
  6. package/dist/src/adapters/html.js +47 -0
  7. package/dist/src/adapters/preact.js +56 -0
  8. package/dist/src/adapters/react.js +66 -0
  9. package/dist/src/adapters/solid.js +97 -0
  10. package/dist/src/adapters/svelte.js +6 -0
  11. package/dist/src/adapters/vue.js +63 -0
  12. package/dist/src/index.js +897 -0
  13. package/dist/src/testing.js +46 -0
  14. package/dist/types/src/adapters/angular-icon.d.ts +32 -0
  15. package/dist/types/src/adapters/angular.d.ts +2 -0
  16. package/dist/types/src/adapters/html.d.ts +8 -0
  17. package/dist/types/src/adapters/preact.d.ts +6 -0
  18. package/dist/types/src/adapters/react.d.ts +6 -0
  19. package/dist/types/src/adapters/solid-icon.d.ts +6 -0
  20. package/dist/types/src/adapters/solid.d.ts +4 -0
  21. package/dist/types/src/adapters/svelte.d.ts +2 -0
  22. package/dist/types/src/adapters/vue.d.ts +41 -0
  23. package/dist/types/src/build/client.d.ts +21 -0
  24. package/dist/types/src/build/collections.d.ts +13 -0
  25. package/dist/types/src/build/css.d.ts +10 -0
  26. package/dist/types/src/build/custom.d.ts +10 -0
  27. package/dist/types/src/build/endpoint.d.ts +4 -0
  28. package/dist/types/src/build/runtime.d.ts +3 -0
  29. package/dist/types/src/build/scan.d.ts +37 -0
  30. package/dist/types/src/clean.d.ts +3 -0
  31. package/dist/types/src/index.d.ts +8 -0
  32. package/dist/types/src/kit.d.ts +10 -0
  33. package/dist/types/src/locate.d.ts +4 -0
  34. package/dist/types/src/module.d.ts +3 -0
  35. package/dist/types/src/name.d.ts +13 -0
  36. package/dist/types/src/options.d.ts +46 -0
  37. package/dist/types/src/render.d.ts +68 -0
  38. package/dist/types/src/runtime/bundle.d.ts +2 -0
  39. package/dist/types/src/runtime/classes.d.ts +3 -0
  40. package/dist/types/src/runtime/icons.d.ts +27 -0
  41. package/dist/types/src/runtime/index.d.ts +2 -0
  42. package/dist/types/src/runtime/remote.d.ts +22 -0
  43. package/dist/types/src/runtime/server.d.ts +3 -0
  44. package/dist/types/src/server/door.d.ts +1 -0
  45. package/dist/types/src/server/endpoint.d.ts +28 -0
  46. package/dist/types/src/server/handler.d.ts +1 -0
  47. package/dist/types/src/testing.d.ts +2 -0
  48. package/dist/types/src/types.d.ts +102 -0
  49. package/package.json +141 -4
  50. package/src/adapters/Icon.svelte +60 -0
  51. package/src/adapters/angular-icon.ts +104 -0
  52. package/src/adapters/angular.ts +2 -0
  53. package/src/adapters/html.ts +44 -0
  54. package/src/adapters/preact.ts +63 -0
  55. package/src/adapters/react.ts +80 -0
  56. package/src/adapters/solid-icon.ts +99 -0
  57. package/src/adapters/solid.ts +8 -0
  58. package/src/adapters/svelte.ts +2 -0
  59. package/src/adapters/test/IconPage.svelte +5 -0
  60. package/src/adapters/test/support.ts +78 -0
  61. package/src/adapters/vue.ts +64 -0
  62. package/src/build/client.ts +113 -0
  63. package/src/build/collections.ts +86 -0
  64. package/src/build/css.ts +67 -0
  65. package/src/build/custom.ts +120 -0
  66. package/src/build/endpoint.ts +16 -0
  67. package/src/build/runtime.ts +24 -0
  68. package/src/build/scan.ts +148 -0
  69. package/src/clean.ts +66 -0
  70. package/src/env.d.ts +22 -0
  71. package/src/index.ts +10 -0
  72. package/src/kit.ts +29 -0
  73. package/src/locate.ts +20 -0
  74. package/src/module.ts +35 -0
  75. package/src/name.ts +38 -0
  76. package/src/options.ts +275 -0
  77. package/src/render.ts +247 -0
  78. package/src/runtime/bundle.ts +26 -0
  79. package/src/runtime/classes.ts +5 -0
  80. package/src/runtime/icons.ts +146 -0
  81. package/src/runtime/index.ts +17 -0
  82. package/src/runtime/remote.ts +147 -0
  83. package/src/runtime/server.ts +7 -0
  84. package/src/server/door.ts +1 -0
  85. package/src/server/endpoint.ts +251 -0
  86. package/src/server/handler.ts +30 -0
  87. package/src/testing.ts +23 -0
  88. package/src/types.ts +97 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 productdevbook
4
+ Copyright (c) 2019 Material-UI SAS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # @hamur/icon
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The first-party icon module for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. It has no dependency.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add @hamur/icon
9
+ ```
10
+
11
+ Add it to `modules` in `hamur.config.ts` and set the `icon` key.
12
+
13
+ ## Docs
14
+
15
+ [Documentation](https://docs.productdevbook.com/) and the [API reference](https://docs.productdevbook.com/api-reference/icon). MIT license.
@@ -0,0 +1,206 @@
1
+ // @bun
2
+ import {
3
+ resolveIcon,
4
+ payloadIcon,
5
+ NAME_PATTERN,
6
+ MAX_ICONS,
7
+ createIcons
8
+ } from "./bun-react-nygte91t.js";
9
+
10
+ // packages/icon/src/runtime/index.ts
11
+ import client from "#hamur/icon/client";
12
+ import options from "#hamur/icon/options";
13
+
14
+ // packages/icon/src/clean.ts
15
+ var MAX_BODY_LENGTH = 64 * 1024;
16
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
17
+ var ICON_NUMBERS = ["width", "height", "left", "top", "rotate"];
18
+ var finite = (value) => typeof value === "number" && Number.isFinite(value);
19
+ function cleanEntry(value, alias) {
20
+ if (!isObject(value))
21
+ return;
22
+ const out = {};
23
+ if (alias) {
24
+ if (typeof value.parent !== "string")
25
+ return;
26
+ out.parent = value.parent;
27
+ } else {
28
+ if (typeof value.body !== "string" || value.body.length > MAX_BODY_LENGTH)
29
+ return;
30
+ out.body = value.body;
31
+ }
32
+ for (const key of ICON_NUMBERS) {
33
+ if (value[key] === undefined)
34
+ continue;
35
+ if (!finite(value[key]))
36
+ return;
37
+ out[key] = value[key];
38
+ }
39
+ for (const key of ["hFlip", "vFlip"]) {
40
+ if (value[key] === undefined)
41
+ continue;
42
+ if (typeof value[key] !== "boolean")
43
+ return;
44
+ out[key] = value[key];
45
+ }
46
+ return out;
47
+ }
48
+ function cleanCollection(prefix, body) {
49
+ const clean = { prefix, icons: {} };
50
+ for (const key of ["width", "height", "left", "top"])
51
+ if (finite(body[key]))
52
+ clean[key] = body[key];
53
+ const icons = clean.icons;
54
+ for (const [name, value] of Object.entries(body.icons)) {
55
+ const entry = NAME_PATTERN.test(name) ? cleanEntry(value, false) : undefined;
56
+ if (entry)
57
+ icons[name] = entry;
58
+ }
59
+ if (isObject(body.aliases)) {
60
+ const aliases = {};
61
+ const candidates = Object.entries(body.aliases).filter(([name]) => NAME_PATTERN.test(name)).flatMap(([name, value]) => {
62
+ const entry = cleanEntry(value, true);
63
+ return entry ? [[name, entry]] : [];
64
+ });
65
+ for (let changed = true;changed; ) {
66
+ changed = false;
67
+ for (const [name, entry] of candidates) {
68
+ if (Object.hasOwn(aliases, name))
69
+ continue;
70
+ const parent = entry.parent;
71
+ if (Object.hasOwn(icons, parent) || Object.hasOwn(aliases, parent)) {
72
+ aliases[name] = entry;
73
+ changed = true;
74
+ }
75
+ }
76
+ }
77
+ clean.aliases = aliases;
78
+ }
79
+ return clean;
80
+ }
81
+
82
+ // packages/icon/src/runtime/remote.ts
83
+ var KEY = "hamur:icon:";
84
+ var sessionStore = () => globalThis.sessionStorage;
85
+ function createRemote(options) {
86
+ const cache = new Map;
87
+ const listeners = new Set;
88
+ let changes = 0;
89
+ let batch;
90
+ const queued = new Map;
91
+ const keyOf = (prefix, name) => `${prefix}:${name}`;
92
+ const storage = options.storage ?? sessionStore;
93
+ const storageKey = (prefix, name) => `${KEY}${options.provider}:${keyOf(prefix, name)}`;
94
+ function stored(prefix, name) {
95
+ try {
96
+ const text = storage()?.getItem(storageKey(prefix, name));
97
+ if (text == null)
98
+ return;
99
+ if (text === "0")
100
+ return null;
101
+ const collection = cleanCollection(prefix, { icons: { [name]: JSON.parse(text) } });
102
+ const data = resolveIcon(collection, name);
103
+ return data ? payloadIcon(data) : undefined;
104
+ } catch {
105
+ return;
106
+ }
107
+ }
108
+ function keep(prefix, name, icon, persist) {
109
+ cache.set(keyOf(prefix, name), icon);
110
+ if (!persist)
111
+ return;
112
+ try {
113
+ storage()?.setItem(storageKey(prefix, name), icon === null ? "0" : JSON.stringify(icon));
114
+ } catch {}
115
+ }
116
+ async function ask(prefix, names, baseURL) {
117
+ const origin = options.provider === "server" ? `${baseURL}_hamur/icons` : options.iconifyApiEndpoint;
118
+ const controller = new AbortController;
119
+ const timer = setTimeout(() => controller.abort(), options.fetchTimeout);
120
+ try {
121
+ const response = await (options.fetch ?? fetch)(`${origin}/${prefix}.json?icons=${names.join(",")}`, {
122
+ signal: controller.signal,
123
+ headers: { accept: "application/json" }
124
+ });
125
+ if (response.status === 404) {
126
+ for (const name of names)
127
+ keep(prefix, name, null, true);
128
+ return;
129
+ }
130
+ if (!response.ok)
131
+ throw new Error(`status ${response.status}`);
132
+ const body = await response.json();
133
+ if (typeof body !== "object" || body === null || typeof body.icons !== "object" || body.icons === null)
134
+ throw new Error("not an icon set");
135
+ const collection = cleanCollection(prefix, body);
136
+ for (const name of names) {
137
+ const data = resolveIcon(collection, name);
138
+ keep(prefix, name, data ? payloadIcon(data) : null, true);
139
+ }
140
+ } catch {
141
+ for (const name of names)
142
+ keep(prefix, name, null, false);
143
+ } finally {
144
+ clearTimeout(timer);
145
+ }
146
+ }
147
+ async function flush(current) {
148
+ batch = undefined;
149
+ const requests = [];
150
+ for (const [prefix, set] of current.names) {
151
+ const rest = [];
152
+ for (const name of set) {
153
+ const found = stored(prefix, name);
154
+ if (found === undefined)
155
+ rest.push(name);
156
+ else
157
+ cache.set(keyOf(prefix, name), found);
158
+ }
159
+ for (let at = 0;at < rest.length; at += MAX_ICONS)
160
+ requests.push(ask(prefix, rest.slice(at, at + MAX_ICONS), current.baseURL));
161
+ }
162
+ await Promise.all(requests);
163
+ for (const [prefix, set] of current.names)
164
+ for (const name of set)
165
+ queued.delete(keyOf(prefix, name));
166
+ changes++;
167
+ for (const listener of [...listeners])
168
+ listener();
169
+ }
170
+ return {
171
+ lookup: (prefix, name) => cache.get(keyOf(prefix, name)),
172
+ request(prefix, name, baseURL) {
173
+ const key = keyOf(prefix, name);
174
+ if (cache.has(key) || !NAME_PATTERN.test(prefix) || !NAME_PATTERN.test(name))
175
+ return;
176
+ const waiting = queued.get(key);
177
+ if (waiting)
178
+ return waiting;
179
+ if (!batch) {
180
+ const created = { baseURL, names: new Map, done: undefined };
181
+ created.done = new Promise((resolve) => queueMicrotask(() => void flush(created).then(resolve, resolve)));
182
+ batch = created;
183
+ }
184
+ const set = batch.names.get(prefix) ?? new Set;
185
+ set.add(name);
186
+ batch.names.set(prefix, set);
187
+ queued.set(key, batch.done);
188
+ return batch.done;
189
+ },
190
+ subscribe(listener) {
191
+ listeners.add(listener);
192
+ return () => void listeners.delete(listener);
193
+ },
194
+ version: () => changes
195
+ };
196
+ }
197
+
198
+ // packages/icon/src/runtime/index.ts
199
+ var remote = import.meta.server || options.provider === "none" ? undefined : createRemote({
200
+ provider: options.provider,
201
+ iconifyApiEndpoint: options.iconifyApiEndpoint,
202
+ fetchTimeout: options.fetchTimeout
203
+ });
204
+ var icons = createIcons(options, undefined, undefined, client, remote);
205
+
206
+ export { icons };
@@ -0,0 +1,305 @@
1
+ // @bun
2
+ // packages/icon/src/render.ts
3
+ import { sanitizeSvg } from "hamur/adapter";
4
+ var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
5
+ function resolveIcon(collection, name) {
6
+ const chain = [];
7
+ const seen = new Set;
8
+ let current = name;
9
+ while (!Object.hasOwn(collection.icons, current)) {
10
+ const alias = collection.aliases && Object.hasOwn(collection.aliases, current) ? collection.aliases[current] : undefined;
11
+ if (!alias || seen.has(current))
12
+ return;
13
+ seen.add(current);
14
+ chain.push(alias);
15
+ current = alias.parent;
16
+ }
17
+ const icon = collection.icons[current];
18
+ if (typeof icon.body !== "string")
19
+ return;
20
+ const box = {
21
+ left: icon.left ?? collection.left ?? 0,
22
+ top: icon.top ?? collection.top ?? 0,
23
+ width: icon.width ?? collection.width ?? 16,
24
+ height: icon.height ?? collection.height ?? 16
25
+ };
26
+ let rotate = icon.rotate ?? 0;
27
+ let hFlip = icon.hFlip === true;
28
+ let vFlip = icon.vFlip === true;
29
+ for (const alias of chain.reverse()) {
30
+ if (alias.left !== undefined)
31
+ box.left = alias.left;
32
+ if (alias.top !== undefined)
33
+ box.top = alias.top;
34
+ if (alias.width !== undefined)
35
+ box.width = alias.width;
36
+ if (alias.height !== undefined)
37
+ box.height = alias.height;
38
+ rotate += alias.rotate ?? 0;
39
+ if (alias.hFlip)
40
+ hFlip = !hFlip;
41
+ if (alias.vFlip)
42
+ vFlip = !vFlip;
43
+ }
44
+ return transform(icon.body, box, rotate, hFlip, vFlip);
45
+ }
46
+ var payloadIcon = (data) => ({
47
+ body: data.body,
48
+ width: data.width,
49
+ height: data.height,
50
+ ...data.left ? { left: data.left } : {},
51
+ ...data.top ? { top: data.top } : {}
52
+ });
53
+ function transform(body, box, rotate, hFlip, vFlip) {
54
+ const steps = [];
55
+ let turns = rotate;
56
+ if (hFlip && vFlip)
57
+ turns += 2;
58
+ else if (hFlip || vFlip) {
59
+ steps.push(hFlip ? `translate(${box.width + box.left} ${-box.top || 0})` : `translate(${-box.left || 0} ${box.height + box.top})`, hFlip ? "scale(-1 1)" : "scale(1 -1)");
60
+ box.left = 0;
61
+ box.top = 0;
62
+ }
63
+ turns = (turns % 4 + 4) % 4;
64
+ if (turns === 1) {
65
+ const center = box.height / 2 + box.top;
66
+ steps.unshift(`rotate(90 ${center} ${center})`);
67
+ } else if (turns === 2) {
68
+ steps.unshift(`rotate(180 ${box.width / 2 + box.left} ${box.height / 2 + box.top})`);
69
+ } else if (turns === 3) {
70
+ const center = box.width / 2 + box.left;
71
+ steps.unshift(`rotate(-90 ${center} ${center})`);
72
+ }
73
+ if (turns % 2 === 1) {
74
+ [box.left, box.top] = [box.top, box.left];
75
+ [box.width, box.height] = [box.height, box.width];
76
+ }
77
+ return { body: steps.length ? `<g transform="${steps.join(" ")}">${body}</g>` : body, ...box };
78
+ }
79
+ var SANITIZED_LIMIT = 500;
80
+ var sanitized = new Map;
81
+ function iconNodes(body) {
82
+ let nodes = sanitized.get(body);
83
+ if (nodes === undefined) {
84
+ try {
85
+ nodes = sanitizeSvg(body, "icon");
86
+ } catch {
87
+ nodes = [];
88
+ }
89
+ if (sanitized.size >= SANITIZED_LIMIT)
90
+ sanitized.delete(sanitized.keys().next().value);
91
+ } else
92
+ sanitized.delete(body);
93
+ sanitized.set(body, nodes);
94
+ return nodes;
95
+ }
96
+ function svgValue(value, uid) {
97
+ return typeof value === "string" ? value : value.map((part) => typeof part === "string" ? part : `${uid}-${part.id}`).join("");
98
+ }
99
+ function svgAttributes(node, uid) {
100
+ const attrs = {};
101
+ for (const [name, value] of Object.entries(node.attrs))
102
+ attrs[name] = svgValue(value, uid);
103
+ if (node.style)
104
+ attrs.style = node.style.map((declaration) => `${declaration.name}:${svgValue(declaration.value, uid)}`).join(";");
105
+ return attrs;
106
+ }
107
+ var ESCAPES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" };
108
+ var escapeHtml = (text) => text.replace(/[&<>"]/g, (char) => ESCAPES[char]);
109
+ var ATTRIBUTE_NAME = /^[^\s"'<>/=]+$/;
110
+ var attributesMarkup = (attrs) => Object.entries(attrs).filter(([name]) => ATTRIBUTE_NAME.test(name)).map(([name, value]) => ` ${name}="${escapeHtml(value)}"`).join("");
111
+ function svgMarkup(nodes, uid) {
112
+ let out = "";
113
+ for (const node of nodes) {
114
+ if (typeof node === "string" || Array.isArray(node))
115
+ out += escapeHtml(svgValue(node, uid));
116
+ else
117
+ out += `<${node.tag}${attributesMarkup(svgAttributes(node, uid))}>${svgMarkup(node.children, uid)}</${node.tag}>`;
118
+ }
119
+ return out;
120
+ }
121
+ var CSS_LENGTH = /^\d*\.?\d+(px|em|rem|ex|ch|vw|vh|vmin|vmax|%|pt|cm|mm|in|pc|q)?$/i;
122
+ var validSize = (size) => typeof size === "number" ? Number.isFinite(size) && size >= 0 : CSS_LENGTH.test(size);
123
+ function iconSize(size) {
124
+ if (size === undefined || !validSize(size))
125
+ return { attribute: "1em", css: "1em" };
126
+ return typeof size === "number" ? { attribute: String(size), css: `${size}px` } : { attribute: size, css: size };
127
+ }
128
+ var iconClass = (name, selectorPrefix) => `${selectorPrefix}${name.prefix}:${name.name}`;
129
+ function iconRule(className, data, nodes, where) {
130
+ const markup = svgMarkup(nodes, "i");
131
+ const svg = `<svg xmlns="${SVG_NAMESPACE}" viewBox="${data.left} ${data.top} ${data.width} ${data.height}" width="${data.width}" height="${data.height}">${markup}</svg>`;
132
+ const selector = `.${className.replaceAll(":", "\\:")}`;
133
+ const paint = /currentcolor/i.test(markup) ? "background-color: currentColor; -webkit-mask: var(--svg) no-repeat center / 100% 100%; mask: var(--svg) no-repeat center / 100% 100%;" : "background: var(--svg) no-repeat center / 100% 100%;";
134
+ return `${where ? `:where(${selector})` : selector} { display: inline-block; width: 1em; height: 1em; ${paint} --svg: url("data:image/svg+xml,${encodeURIComponent(svg)}"); }`;
135
+ }
136
+ function iconStyle(rules, layer) {
137
+ const text = [...rules].join(`
138
+ `);
139
+ return layer === undefined ? text : `@layer ${layer} {
140
+ ${text}
141
+ }`;
142
+ }
143
+ function iconView(input, name, found, options) {
144
+ const size = iconSize(input.size);
145
+ const extra = input.class || undefined;
146
+ const title = input.title;
147
+ if ((input.mode ?? "svg") === "css") {
148
+ const className = name ? iconClass(name, options.cssSelectorPrefix) : undefined;
149
+ const attrs = {};
150
+ if (className || extra)
151
+ attrs.class = [className, extra].filter(Boolean).join(" ");
152
+ attrs.role = "img";
153
+ if (title !== undefined)
154
+ attrs["aria-label"] = title;
155
+ else if (!input.labelled)
156
+ attrs["aria-hidden"] = "true";
157
+ if (!found || !name || !className)
158
+ return { mode: "css", attrs: { ...attrs, style: `display:inline-block;width:${size.css};height:${size.css}` } };
159
+ if (size.css !== "1em")
160
+ attrs.style = `width:${size.css};height:${size.css}`;
161
+ const body = input.customize ? input.customize(found.body, name.name, name.prefix) : found.body;
162
+ return {
163
+ mode: "css",
164
+ attrs,
165
+ rule: { className, text: iconRule(className, found, iconNodes(body), options.cssWherePseudo) }
166
+ };
167
+ }
168
+ const attrs = { xmlns: SVG_NAMESPACE };
169
+ if (found)
170
+ attrs.viewBox = `${found.left} ${found.top} ${found.width} ${found.height}`;
171
+ attrs.width = size.attribute;
172
+ attrs.height = size.attribute;
173
+ if (title !== undefined || input.labelled)
174
+ attrs.role = "img";
175
+ else
176
+ attrs["aria-hidden"] = "true";
177
+ attrs.focusable = "false";
178
+ attrs["data-hamur-icon"] = name ? `${name.prefix}:${name.name}` : input.name;
179
+ if (extra)
180
+ attrs.class = extra;
181
+ if (!found || !name)
182
+ return { mode: "svg", attrs, nodes: [] };
183
+ const body = input.customize ? input.customize(found.body, name.name, name.prefix) : found.body;
184
+ return { mode: "svg", attrs, ...title === undefined ? {} : { title }, nodes: iconNodes(body) };
185
+ }
186
+
187
+ // packages/icon/src/runtime/icons.ts
188
+ import { runtimeConfigOf } from "hamur/adapter";
189
+
190
+ // packages/icon/src/name.ts
191
+ var NAME_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
192
+ function pair(text) {
193
+ const at = text.indexOf(":");
194
+ if (at === -1)
195
+ return;
196
+ const prefix = text.slice(0, at);
197
+ const name = text.slice(at + 1);
198
+ return NAME_PATTERN.test(prefix) && NAME_PATTERN.test(name) ? { prefix, name } : undefined;
199
+ }
200
+ function normalizeName(input, prefixes, selectorPrefix = "i-") {
201
+ if (selectorPrefix !== "" && input.startsWith(selectorPrefix)) {
202
+ const rest = input.slice(selectorPrefix.length);
203
+ if (rest.includes(":")) {
204
+ const found = pair(rest);
205
+ if (found)
206
+ return found;
207
+ } else {
208
+ for (const prefix of [...prefixes].sort((a, b) => b.length - a.length)) {
209
+ const name = rest.slice(prefix.length + 1);
210
+ if (rest.startsWith(`${prefix}-`) && NAME_PATTERN.test(name))
211
+ return { prefix, name };
212
+ }
213
+ }
214
+ }
215
+ return pair(input);
216
+ }
217
+ var MAX_ICONS = 100;
218
+
219
+ // packages/icon/src/runtime/icons.ts
220
+ var serverCollections = new Map;
221
+ function addServerCollection(prefix, collection) {
222
+ serverCollections.set(prefix, collection);
223
+ }
224
+ function createIcons(options, warn = import.meta.dev ? (message) => console.warn(message) : undefined, collections = serverCollections, client = {}, remote) {
225
+ const warned = new Set;
226
+ const once = (message) => {
227
+ if (!warn || warned.has(message))
228
+ return;
229
+ warned.add(message);
230
+ warn(message);
231
+ };
232
+ const recorders = new WeakMap;
233
+ const sent = (app) => app.modulePayload.icon;
234
+ const bundled = (prefix, name) => client[prefix] !== undefined && Object.hasOwn(client[prefix].icons, name);
235
+ function find(app, prefix, name) {
236
+ const collection = collections.get(prefix);
237
+ const data = collection && resolveIcon(collection, name);
238
+ if (data) {
239
+ if (!bundled(prefix, name)) {
240
+ const payload = app.modulePayload.icon ??= {};
241
+ (payload[prefix] ??= { icons: {} }).icons[name] = payloadIcon(data);
242
+ }
243
+ return data;
244
+ }
245
+ const fetched = remote?.lookup(prefix, name);
246
+ for (const icons of [
247
+ sent(app)?.[prefix]?.icons,
248
+ client[prefix]?.icons,
249
+ fetched ? { [name]: fetched } : undefined
250
+ ]) {
251
+ const found = icons && resolveIcon({ prefix, icons }, name);
252
+ if (found)
253
+ return found;
254
+ }
255
+ return;
256
+ }
257
+ return {
258
+ view(app, given, config) {
259
+ const aliased = config?.aliases && Object.hasOwn(config.aliases, given.name) && typeof config.aliases[given.name] === "string" ? config.aliases[given.name] : given.name;
260
+ const input = {
261
+ ...given,
262
+ name: aliased,
263
+ size: given.size ?? config?.size,
264
+ mode: given.mode ?? config?.mode,
265
+ class: given.class || config?.class || undefined,
266
+ customize: given.customize
267
+ };
268
+ const name = normalizeName(input.name, options.prefixes, options.cssSelectorPrefix);
269
+ const data = name && find(app, name.prefix, name.name);
270
+ const pending = name && !data ? remote?.request(name.prefix, name.name, runtimeConfigOf(app).app.baseURL) : undefined;
271
+ if (!name)
272
+ once(`[icon] Icon name ${JSON.stringify(input.name)} is not "prefix:name" or "i-prefix-name"; import a component, or put the SVG in a custom collection`);
273
+ else if (!data && !pending) {
274
+ const known = options.prefixes.includes(name.prefix) || collections.has(name.prefix) || sent(app)?.[name.prefix] !== undefined || client[name.prefix] !== undefined;
275
+ if (options.provider === "none" && !collections.has(name.prefix))
276
+ once(`[icon] icon.provider is "none": "${name.prefix}:${name.name}" is not in the payload or the client bundle`);
277
+ else if (known)
278
+ once(`[icon] icon "${name.prefix}:${name.name}" not found`);
279
+ else if (options.provider !== "iconify")
280
+ once(`[icon] collection "${name.prefix}" is not installed; add @iconify-json/${name.prefix}, or set icon.provider "iconify"`);
281
+ else if (remote)
282
+ once(`[icon] icon "${name.prefix}:${name.name}" not found`);
283
+ }
284
+ if (input.size !== undefined && !validSize(input.size))
285
+ once(`[icon] Icon size ${JSON.stringify(input.size)} is not a number or a CSS length; 1em is used`);
286
+ const drawn = iconView(input, name, data || undefined, options);
287
+ const view = pending ? { ...drawn, pending } : drawn;
288
+ if (view.mode !== "css" || !view.rule)
289
+ return view;
290
+ let rules = recorders.get(app);
291
+ if (!rules)
292
+ recorders.set(app, rules = new Map);
293
+ if (!rules.has(view.rule.className))
294
+ rules.set(view.rule.className, view.rule.text);
295
+ return { ...view, head: iconStyle(rules.values(), options.cssLayer) };
296
+ },
297
+ subscribe: (listener) => remote?.subscribe(listener) ?? (() => {}),
298
+ version: () => remote?.version() ?? 0
299
+ };
300
+ }
301
+ function iconHead(view) {
302
+ return view.head === undefined ? {} : { style: [{ key: "hamur-icons", innerHTML: view.head }] };
303
+ }
304
+
305
+ export { SVG_NAMESPACE, resolveIcon, payloadIcon, svgValue, svgAttributes, escapeHtml, attributesMarkup, svgMarkup, NAME_PATTERN, MAX_ICONS, addServerCollection, createIcons, iconHead };
@@ -0,0 +1,104 @@
1
+ // @bun
2
+ import {
3
+ svgValue,
4
+ svgAttributes,
5
+ iconHead
6
+ } from "../../chunks/bun-react-nygte91t.js";
7
+ import {
8
+ icons
9
+ } from "../../chunks/bun-react-fhd05zxm.js";
10
+
11
+ // packages/icon/src/adapters/angular-icon.ts
12
+ import { Component, DestroyRef, ElementRef, HostAttributeToken, Injector, Renderer2, computed, effect, inject, input, runInInjectionContext, signal, untracked } from "@angular/core";
13
+ import { injectApp, injectHead, injectId, injectRuntimeConfig } from "@hamur/adapter-angular";
14
+ import * as i0 from "@angular/core";
15
+
16
+ class Icon {
17
+ name = input.required(...ngDevMode ? [{ debugName: "name" }] : []);
18
+ size = input(...ngDevMode ? [undefined, { debugName: "size" }] : []);
19
+ mode = input(...ngDevMode ? [undefined, { debugName: "mode" }] : []);
20
+ title = input(...ngDevMode ? [undefined, { debugName: "title" }] : []);
21
+ customize = input(...ngDevMode ? [undefined, { debugName: "customize" }] : []);
22
+ injector = inject(Injector);
23
+ app = injectApp();
24
+ config = injectRuntimeConfig().public;
25
+ host = inject(ElementRef).nativeElement;
26
+ renderer = inject(Renderer2);
27
+ label = inject(new HostAttributeToken("aria-label"), { optional: true });
28
+ labelledby = inject(new HostAttributeToken("aria-labelledby"), { optional: true });
29
+ uid = injectId().replace(/[^\w-]/g, "_");
30
+ answers = signal(icons.version(), ...ngDevMode ? [{ debugName: "answers" }] : []);
31
+ view = computed(() => {
32
+ this.answers();
33
+ return icons.view(this.app, {
34
+ name: this.name(),
35
+ size: this.size(),
36
+ mode: this.mode(),
37
+ title: this.title(),
38
+ customize: this.customize(),
39
+ labelled: this.label !== null || this.labelledby !== null
40
+ }, this.config.icon);
41
+ }, ...ngDevMode ? [{ debugName: "view" }] : []);
42
+ constructor() {
43
+ inject(DestroyRef).onDestroy(icons.subscribe(() => this.answers.set(icons.version())));
44
+ effect(() => {
45
+ const view = this.view();
46
+ untracked(() => this.draw(view));
47
+ });
48
+ }
49
+ ngOnInit() {
50
+ runInInjectionContext(this.injector, () => injectHead(() => iconHead(this.view())));
51
+ }
52
+ draw(view) {
53
+ const { renderer, host } = this;
54
+ while (host.firstChild)
55
+ renderer.removeChild(host, host.firstChild);
56
+ const root = view.mode === "css" ? renderer.createElement("span") : renderer.createElement("svg", "svg");
57
+ const attrs = { ...view.attrs };
58
+ if (this.label !== null)
59
+ attrs["aria-label"] = this.label;
60
+ if (this.labelledby !== null)
61
+ attrs["aria-labelledby"] = this.labelledby;
62
+ for (const [name, value] of Object.entries(attrs))
63
+ renderer.setAttribute(root, name, value);
64
+ if (view.mode === "svg") {
65
+ if (view.title !== undefined) {
66
+ const title = renderer.createElement("title", "svg");
67
+ renderer.appendChild(title, renderer.createText(view.title));
68
+ renderer.appendChild(root, title);
69
+ }
70
+ for (const node of view.nodes)
71
+ renderer.appendChild(root, this.element(node));
72
+ }
73
+ renderer.appendChild(host, root);
74
+ }
75
+ element(node) {
76
+ if (typeof node === "string" || Array.isArray(node))
77
+ return this.renderer.createText(svgValue(node, this.uid));
78
+ const element = this.renderer.createElement(node.tag, "svg");
79
+ for (const [name, value] of Object.entries(svgAttributes(node, this.uid)))
80
+ this.renderer.setAttribute(element, name, value);
81
+ for (const child of node.children)
82
+ this.renderer.appendChild(element, this.element(child));
83
+ return element;
84
+ }
85
+ static \u{275}fac = i0.\u{275}\u{275}ngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Icon, deps: [], target: i0.\u{275}\u{275}FactoryTarget.Component });
86
+ static \u{275}cmp = i0.\u{275}\u{275}ngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: Icon, isStandalone: true, selector: "hamur-icon", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: true, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, customize: { classPropertyName: "customize", publicName: "customize", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.name": "null", "attr.size": "null", "attr.mode": "null", "attr.title": "null", "attr.customize": "null" } }, ngImport: i0, template: "", isInline: true });
87
+ }
88
+ i0.\u{275}\u{275}ngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Icon, decorators: [{
89
+ type: Component,
90
+ args: [{
91
+ selector: "hamur-icon",
92
+ template: "",
93
+ host: {
94
+ "[attr.name]": "null",
95
+ "[attr.size]": "null",
96
+ "[attr.mode]": "null",
97
+ "[attr.title]": "null",
98
+ "[attr.customize]": "null"
99
+ }
100
+ }]
101
+ }], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], customize: [{ type: i0.Input, args: [{ isSignal: true, alias: "customize", required: false }] }] } });
102
+ export {
103
+ Icon
104
+ };