@hamur/icon 0.0.0-stage → 0.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.
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 +29 -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 +114 -4
  50. package/src/adapters/Icon.svelte +60 -0
  51. package/src/adapters/angular-icon.ts +112 -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
@@ -0,0 +1,46 @@
1
+ // @bun
2
+ import {
3
+ NAME_PATTERN,
4
+ addServerCollection
5
+ } from "../chunks/bun-react-nygte91t.js";
6
+
7
+ // packages/icon/src/testing.ts
8
+ import { readFileSync } from "fs";
9
+
10
+ // packages/icon/src/locate.ts
11
+ import { existsSync } from "fs";
12
+ import { dirname, join } from "path";
13
+ var collectionCandidates = (prefix, full) => [
14
+ `@iconify-json/${prefix}/icons.json`,
15
+ ...full ? [`@iconify/json/json/${prefix}.json`] : []
16
+ ];
17
+ function locateCollection(rootDir, prefix, full) {
18
+ const candidates = collectionCandidates(prefix, full);
19
+ for (let dir = rootDir;; dir = dirname(dir)) {
20
+ for (const candidate of candidates) {
21
+ const file = join(dir, "node_modules", candidate);
22
+ if (existsSync(file))
23
+ return file;
24
+ }
25
+ if (dirname(dir) === dir)
26
+ return;
27
+ }
28
+ }
29
+
30
+ // packages/icon/src/testing.ts
31
+ function loadIconCollections(prefixes) {
32
+ const rootDir = process.cwd();
33
+ for (const prefix of prefixes) {
34
+ if (!NAME_PATTERN.test(prefix))
35
+ throw new Error(`loadIconCollections: "${prefix}" is not a collection prefix`);
36
+ const file = locateCollection(rootDir, prefix, true);
37
+ if (!file) {
38
+ const looked = collectionCandidates(prefix, true).map((candidate) => `node_modules/${candidate}`).join(" or ");
39
+ throw new Error(`loadIconCollections: collection "${prefix}" is not installed; looked for ${looked} from ${rootDir} up. Add @iconify-json/${prefix} to the app's devDependencies`);
40
+ }
41
+ addServerCollection(prefix, JSON.parse(readFileSync(file, "utf8")));
42
+ }
43
+ }
44
+ export {
45
+ loadIconCollections
46
+ };
@@ -0,0 +1,29 @@
1
+ import { type OnInit } from "@angular/core";
2
+ import type { IconCustomize, IconMode } from "../types.ts";
3
+ /**
4
+ * `<hamur-icon name="mdi:home" mode="svg" />`, an icon of a collection by name, drawn as `<svg>` from the sanitised
5
+ * body, or as a `<span>` and one CSS rule, inside the `<hamur-icon>` element. The nodes are written with the renderer, as no template
6
+ * can name an element the body decides; the props are taken off the host, and `aria-label` and `aria-labelledby` are
7
+ * also written on the drawn element.
8
+ */
9
+ export declare class Icon implements OnInit {
10
+ readonly name: import("@angular/core/types/core.js").InputSignal<string>;
11
+ readonly size: import("@angular/core/types/core.js").InputSignal<string | number | undefined>;
12
+ readonly mode: import("@angular/core/types/core.js").InputSignal<IconMode | undefined>;
13
+ readonly title: import("@angular/core/types/core.js").InputSignal<string | undefined>;
14
+ readonly customize: import("@angular/core/types/core.js").InputSignal<IconCustomize | undefined>;
15
+ private readonly injector;
16
+ private readonly app;
17
+ private readonly config;
18
+ private readonly host;
19
+ private readonly renderer;
20
+ private readonly label;
21
+ private readonly labelledby;
22
+ private readonly uid;
23
+ private readonly answers;
24
+ private readonly view;
25
+ constructor();
26
+ ngOnInit(): void;
27
+ private draw;
28
+ private element;
29
+ }
@@ -0,0 +1,2 @@
1
+ export { Icon } from "./angular-icon.ts";
2
+ export type { IconProps } from "../types.ts";
@@ -0,0 +1,8 @@
1
+ import type { IconProps } from "../types.ts";
2
+ export type { IconProps };
3
+ export type HtmlIconProps = IconProps & {
4
+ class?: string;
5
+ [attribute: string]: unknown;
6
+ };
7
+ /** An icon of a collection by name as markup, `<svg>` from the sanitised body or a `<span>` and one CSS rule; other props are attributes. */
8
+ export declare function Icon(props: HtmlIconProps): string;
@@ -0,0 +1,6 @@
1
+ import { type ComponentChildren, type SVGAttributes } from "preact";
2
+ import type { IconProps } from "../types.ts";
3
+ export type { IconProps };
4
+ export type PreactIconProps = IconProps & Omit<SVGAttributes<SVGSVGElement>, keyof IconProps | "ref" | "children">;
5
+ /** An icon of a collection by name, drawn as `<svg>` from the sanitised body, or as a `<span>` and one CSS rule. */
6
+ export declare function Icon({ name, size, mode, title, customize, class: className, className: alias, ...rest }: PreactIconProps): ComponentChildren;
@@ -0,0 +1,6 @@
1
+ import { type ReactNode, type SVGProps } from "react";
2
+ import type { IconProps } from "../types.ts";
3
+ export type { IconProps };
4
+ export type ReactIconProps = IconProps & Omit<SVGProps<SVGSVGElement>, keyof IconProps | "ref" | "children">;
5
+ /** An icon of a collection by name, drawn as `<svg>` from the sanitised body, or as a `<span>` and one CSS rule. */
6
+ export declare function Icon({ name, size, mode, title, customize, className, ...rest }: ReactIconProps): ReactNode;
@@ -0,0 +1,6 @@
1
+ import { type JSX } from "@solidjs/web";
2
+ import { type Icons } from "../runtime/icons.ts";
3
+ import type { IconProps } from "../types.ts";
4
+ export type SolidIconProps = IconProps & Omit<JSX.SvgSVGAttributes<SVGSVGElement>, keyof IconProps | "ref" | "children">;
5
+ /** `Icon` over `icons`, so a test renders it without the build's options module. */
6
+ export declare const createIcon: (icons: Icons) => (props: SolidIconProps) => JSX.Element;
@@ -0,0 +1,4 @@
1
+ export type { IconProps } from "../types.ts";
2
+ export type { SolidIconProps } from "./solid-icon.ts";
3
+ /** An icon of a collection by name, drawn as `<svg>` from the sanitised body, or as a `<span>` and one CSS rule. */
4
+ export declare const Icon: (props: import("./solid-icon.ts").SolidIconProps) => import("@solidjs/web").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export type { IconProps } from "../types.ts";
2
+ export { default as Icon } from "./Icon.svelte";
@@ -0,0 +1,41 @@
1
+ import { type PropType } from "vue";
2
+ import type { IconCustomize, IconMode, IconProps } from "../types.ts";
3
+ export type { IconProps };
4
+ /** An icon of a collection by name, drawn as `<svg>` from the sanitised body, or as a `<span>` and one CSS rule; other attributes fall through to it. */
5
+ export declare const Icon: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
6
+ name: {
7
+ type: StringConstructor;
8
+ required: true;
9
+ };
10
+ size: {
11
+ type: PropType<string | number>;
12
+ };
13
+ mode: {
14
+ type: PropType<IconMode>;
15
+ };
16
+ title: {
17
+ type: StringConstructor;
18
+ };
19
+ customize: {
20
+ type: PropType<IconCustomize>;
21
+ };
22
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
23
+ [key: string]: any;
24
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
25
+ name: {
26
+ type: StringConstructor;
27
+ required: true;
28
+ };
29
+ size: {
30
+ type: PropType<string | number>;
31
+ };
32
+ mode: {
33
+ type: PropType<IconMode>;
34
+ };
35
+ title: {
36
+ type: StringConstructor;
37
+ };
38
+ customize: {
39
+ type: PropType<IconCustomize>;
40
+ };
41
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -0,0 +1,21 @@
1
+ import { type HamurContext } from "hamur/kit";
2
+ import type { ResolvedIconOptions } from "../options.ts";
3
+ import type { IconifyJSON, IconPayload } from "../types.ts";
4
+ import { type ScanRoot } from "./scan.ts";
5
+ export interface ClientBundle {
6
+ payload: IconPayload;
7
+ /** The warnings, one per name that is in no installed collection. */
8
+ warnings: string[];
9
+ }
10
+ /** Each name of `names` (name to the place that wrote it) the collections hold, resolved, by prefix. */
11
+ export declare function createClientBundle(names: Map<string, string>, collections: Record<string, IconifyJSON>): ClientBundle;
12
+ /** The bytes of the module's data, in KB rounded up, so a bundle over the limit never reads as the limit. */
13
+ export declare function bundleSizeError(payload: IconPayload, sizeLimitKb: number): string | undefined;
14
+ /** Logs each message once; the client bundle and the class utility share one, so a name both find warns once. */
15
+ export declare function createWarner(): (message: string) => void;
16
+ export declare function scanRoots(hamur: HamurContext): ScanRoot[];
17
+ /**
18
+ * `#hamur/icon/client`, the icons of `clientBundle.icons` and the names the scan finds, read from `collections`
19
+ * (filled in `modules:done`) once the hook ran. A bundle over `sizeLimitKb` fails the build.
20
+ */
21
+ export declare function setupClient(options: ResolvedIconOptions, hamur: HamurContext, collections: Record<string, IconifyJSON>, warn?: (message: string) => void): void;
@@ -0,0 +1,13 @@
1
+ import { type HamurContext } from "hamur/kit";
2
+ import type { ResolvedIconOptions } from "../options.ts";
3
+ import type { IconifyJSON } from "../types.ts";
4
+ /** The prefixes of the `@iconify-json/<prefix>` packages in the app's `dependencies` and `devDependencies`. */
5
+ export declare function listedCollections(rootDir: string): string[];
6
+ /** `[icon] server bundle: mdi 4.1 MB, lucide 0.9 MB`; undefined when no collection is bundled. */
7
+ export declare function bundleLine(sizes: Record<string, number>): string | undefined;
8
+ /**
9
+ * The installed collections and those of `icon:collections` are written as
10
+ * `<buildDir>/icons/<prefix>.json` and mounted as `assets:icons`, data in the server bundle on every preset. `prefixes` is filled
11
+ * once the hook ran, before any template is read; `known` gets the collections themselves, for the client bundle.
12
+ */
13
+ export declare function setupCollections(options: ResolvedIconOptions, hamur: HamurContext, prefixes: string[], known?: Record<string, IconifyJSON>): void;
@@ -0,0 +1,10 @@
1
+ import { type HamurContext } from "hamur/kit";
2
+ import type { ResolvedIconOptions } from "../options.ts";
3
+ import type { IconifyJSON } from "../types.ts";
4
+ /** The rule of each class the collections know; a class that names no icon is `warn`ed and has none. */
5
+ export declare function createClassesCss(classes: Map<string, {
6
+ name: string;
7
+ file: string;
8
+ }>, collections: Record<string, IconifyJSON>, options: Pick<ResolvedIconOptions, "cssLayer" | "cssWherePseudo">, warn: (message: string) => void): string;
9
+ /** `#hamur/icon/classes.css`, one rule per class the scan finds, imported by an app plugin so it is global CSS. */
10
+ export declare function setupCss(options: ResolvedIconOptions, hamur: HamurContext, collections: Record<string, IconifyJSON>, warn: (message: string) => void): void;
@@ -0,0 +1,10 @@
1
+ import type { ResolvedIconOptions } from "../options.ts";
2
+ import type { IconifyIcon, IconifyJSON } from "../types.ts";
3
+ type CustomCollection = ResolvedIconOptions["customCollections"][number];
4
+ /** One SVG file as an Iconify icon; `shown` is the file's path in an error. */
5
+ export declare function readSvgIcon(source: string, shown: string): IconifyIcon;
6
+ /** The `.svg` files of `entry.dir` as one collection, each read once; an icon is named by its path segments joined with `-`. */
7
+ export declare function readCustomCollection(rootDir: string, entry: CustomCollection): IconifyJSON;
8
+ /** The custom collections whose `dir` holds `file`, when it is an `.svg`. */
9
+ export declare const isCustomFile: (entries: CustomCollection[], file: string) => CustomCollection[];
10
+ export {};
@@ -0,0 +1,4 @@
1
+ import { type HamurContext } from "hamur/kit";
2
+ import { type ResolvedIconOptions } from "../options.ts";
3
+ /** The door with `/_hamur/icons/**`, on every preset that has a server and a provider. */
4
+ export declare function setupEndpoint(options: ResolvedIconOptions, hamur: HamurContext): void;
@@ -0,0 +1,3 @@
1
+ import type { ResolvedIconOptions } from "../options.ts";
2
+ /** `#hamur/icon/options` and the server app plugin that reads the icon server bundle. */
3
+ export declare function setupRuntime(options: ResolvedIconOptions, prefixes: string[]): void;
@@ -0,0 +1,37 @@
1
+ /** The files the scan reads, the ones that hold string literals of the app. */
2
+ export declare const SCAN_EXTENSIONS: RegExp;
3
+ export interface ScanRoot {
4
+ /** The app's or a layer's directory; `include` and `exclude` are globs from here. */
5
+ rootDir: string;
6
+ /** The folders below it to read. */
7
+ dirs: string[];
8
+ /** Folders inside `dirs` that are not read. */
9
+ skip: string[];
10
+ }
11
+ export interface ScanRules {
12
+ include: string[];
13
+ exclude: string[];
14
+ }
15
+ export interface ScanSource {
16
+ file: string;
17
+ /** From the app's `rootDir`. */
18
+ relative: string;
19
+ }
20
+ /** The icon names (`prefix:name`) that are string literals of `text` with a known prefix, in the order found. */
21
+ export declare function scanText(text: string, prefixes: readonly string[], selectorPrefix: string): string[];
22
+ /** An icon class of the app: the class as written (`i-mdi-home`, `i-mdi:home`) and the icon it names (`mdi:home`). */
23
+ export interface IconClass {
24
+ class: string;
25
+ name: string;
26
+ }
27
+ /** The class tokens of the literals of `text` and, in a stylesheet, the `.i-…` selectors (`\:` for the colon), that name an icon of a known prefix. */
28
+ export declare function scanClassText(text: string, prefixes: readonly string[], selectorPrefix: string, stylesheet?: boolean): IconClass[];
29
+ /** The files below the `dirs` of each root, each once, narrowed by `include` and `exclude`. */
30
+ export declare function findSources(roots: ScanRoot[], appRoot: string, rules: ScanRules): ScanSource[];
31
+ /** Each icon name the sources write, with the first file that does. */
32
+ export declare function scanSources(sources: ScanSource[], prefixes: readonly string[], selectorPrefix: string): Map<string, string>;
33
+ /** Each icon class the sources write, with the icon it names and the first file that writes it. */
34
+ export declare function scanClassSources(sources: ScanSource[], prefixes: readonly string[], selectorPrefix: string): Map<string, {
35
+ name: string;
36
+ file: string;
37
+ }>;
@@ -0,0 +1,3 @@
1
+ import type { IconifyJSON } from "./types.ts";
2
+ /** The upstream answer reduced to what `resolveIcon` reads: known keys, right types, aliases with a known parent. */
3
+ export declare function cleanCollection(prefix: string, body: Record<string, unknown>): IconifyJSON;
@@ -0,0 +1,8 @@
1
+ import type { IconOptions } from "./types.ts";
2
+ export { default } from "./module.ts";
3
+ export type { IconifyIcon, IconifyJSON, IconOptions, IconProps } from "./types.ts";
4
+ declare module "hamur" {
5
+ interface HamurModuleOptions {
6
+ icon?: IconOptions;
7
+ }
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { HamurContext } from "hamur/kit";
2
+ import type { IconifyJSON } from "./types.ts";
3
+ declare module "hamur" {
4
+ interface HamurHooks {
5
+ /** Once in `modules:done`, with every installed collection by prefix; add a collection or replace one by assigning its prefix. */
6
+ "icon:collections": (collections: Record<string, IconifyJSON>) => void | Promise<void>;
7
+ }
8
+ }
9
+ /** The collections after `icon:collections`; a value that is not Iconify JSON fails the build naming its prefix. */
10
+ export declare function callCollectionsHook(hamur: HamurContext, collections: Record<string, IconifyJSON>): Promise<Record<string, IconifyJSON>>;
@@ -0,0 +1,4 @@
1
+ /** Where a collection's file is looked for, in `node_modules` of each directory. */
2
+ export declare const collectionCandidates: (prefix: string, full: boolean) => string[];
3
+ /** The file of a collection, looked for in `node_modules` from `rootDir` up, so a hoisted workspace install is found. */
4
+ export declare function locateCollection(rootDir: string, prefix: string, full: boolean): string | undefined;
@@ -0,0 +1,3 @@
1
+ import type { IconOptions } from "./types.ts";
2
+ declare const _default: import("hamur/kit").HamurModule<IconOptions>;
3
+ export default _default;
@@ -0,0 +1,13 @@
1
+ /** A prefix and a name of an icon. */
2
+ export declare const NAME_PATTERN: RegExp;
3
+ export interface IconName {
4
+ prefix: string;
5
+ name: string;
6
+ }
7
+ /**
8
+ * `prefix:name`, or the class form `<selectorPrefix>prefix:name` and `<selectorPrefix>prefix-name`; the last is read against
9
+ * the prefixes the build knows, the longest that leaves a name winning. Shared by the server, the browser and the scanner.
10
+ */
11
+ export declare function normalizeName(input: string, prefixes: readonly string[], selectorPrefix?: string): IconName | undefined;
12
+ /** The most icons one request may ask for. */
13
+ export declare const MAX_ICONS = 100;
@@ -0,0 +1,46 @@
1
+ import type { IconDefaults, IconOptions } from "./types.ts";
2
+ /** Presets that serve files only, with no endpoint to ask. */
3
+ export declare const FILE_PRESETS: Set<string>;
4
+ export interface ResolvedIconOptions {
5
+ provider: "server" | "iconify" | "none";
6
+ iconifyApiEndpoint: string;
7
+ fallbackToApi: boolean;
8
+ fetchTimeout: number;
9
+ /** The Iconify JSON file of each collection of the icon server bundle, by prefix. */
10
+ installed: Record<string, string>;
11
+ clientBundle: {
12
+ icons: string[];
13
+ scan: boolean | {
14
+ include: string[];
15
+ exclude: string[];
16
+ };
17
+ sizeLimitKb: number;
18
+ };
19
+ /** `dir` absolute. */
20
+ customCollections: Array<{
21
+ prefix: string;
22
+ dir: string;
23
+ recursive: boolean;
24
+ }>;
25
+ cssLayer?: string;
26
+ cssSelectorPrefix: string;
27
+ cssWherePseudo: boolean;
28
+ cssClasses: boolean;
29
+ }
30
+ export interface OptionsContext {
31
+ rootDir: string;
32
+ /** The roots of the app's layers, in priority order. */
33
+ layerRoots?: string[];
34
+ preset: string;
35
+ exists(path: string): boolean;
36
+ /** The prefixes of the `@iconify-json/<prefix>` packages the app's `package.json` lists. */
37
+ listed: string[];
38
+ /** The Iconify JSON file of `prefix`: `@iconify-json/<prefix>/icons.json`, or with `full` also `@iconify/json/json/<prefix>.json`. */
39
+ locate(prefix: string, full: boolean): string | undefined;
40
+ }
41
+ /** The keys of `icon` that `Icon` reads at render, checked; only the ones set. */
42
+ export declare function iconDefaults(input: IconOptions | undefined): IconDefaults;
43
+ /** The part of `defaults` the app's own `runtimeConfig.public.icon` does not set, per key and per alias, so the app wins. */
44
+ export declare function iconDefaultsUnder(defaults: IconDefaults, app: unknown): IconDefaults;
45
+ /** `icon` of `hamur.config.ts` checked and merged over the defaults; every load error names its key. */
46
+ export declare function resolveOptions(input: IconOptions | undefined, ctx: OptionsContext): ResolvedIconOptions;
@@ -0,0 +1,68 @@
1
+ import { type SvgNode, type SvgStyle, type SvgValue } from "hamur/adapter";
2
+ import type { IconName } from "./name.ts";
3
+ import type { IconCustomize, IconifyIcon, IconifyJSON, IconMode, IconRuntimeOptions } from "./types.ts";
4
+ export declare const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
5
+ /** An icon with its aliases resolved and its rotation and flips written into the body. */
6
+ export interface IconData {
7
+ body: string;
8
+ left: number;
9
+ top: number;
10
+ width: number;
11
+ height: number;
12
+ }
13
+ /** Iconify's alias rules: size and offsets of the nearer alias win, quarter turns add up and flips cancel in pairs. */
14
+ export declare function resolveIcon(collection: IconifyJSON, name: string): IconData | undefined;
15
+ /** The Iconify JSON entry of a resolved icon, as the payload and the client bundle hold it. */
16
+ export declare const payloadIcon: (data: IconData) => IconifyIcon;
17
+ /** The body read once by the shared sanitiser; a body it cannot parse draws nothing. */
18
+ export declare function iconNodes(body: string): SvgNode[];
19
+ /** A value with each `{ id }` part written `<uid>-<id>`, so two icons on a page never share an id. */
20
+ export declare function svgValue(value: SvgValue, uid: string): string;
21
+ /** An element's attributes as strings, its `style` list written in as one `name:value;…` value. */
22
+ export declare function svgAttributes(node: {
23
+ attrs: Record<string, SvgValue>;
24
+ style?: SvgStyle;
25
+ }, uid: string): Record<string, string>;
26
+ export declare const escapeHtml: (text: string) => string;
27
+ /** Attributes as markup; a name HTML cannot hold as one attribute name is left out. */
28
+ export declare const attributesMarkup: (attrs: Record<string, string>) => string;
29
+ /** The nodes as markup, for html and for the data URL of a CSS rule; never a parser's input in the page. */
30
+ export declare function svgMarkup(nodes: SvgNode[], uid: string): string;
31
+ /** A `size` an icon can use: a finite number of pixels or a CSS length; anything else would write into `style`. */
32
+ export declare const validSize: (size: string | number) => boolean;
33
+ /** `size` as an attribute and as a CSS length: a number is CSS pixels, an invalid size `1em`. */
34
+ export declare function iconSize(size: string | number | undefined): {
35
+ attribute: string;
36
+ css: string;
37
+ };
38
+ /** The CSS-mode class: `<cssSelectorPrefix><prefix>:<name>`. */
39
+ export declare const iconClass: (name: IconName, selectorPrefix: string) => string;
40
+ /** One rule, a mask painted in `currentColor` for a body that uses it, else the icon's own colours as a background. */
41
+ export declare function iconRule(className: string, data: IconData, nodes: SvgNode[], where: boolean): string;
42
+ /** The text of `<style>` for every rule recorded, in `@layer <cssLayer>` when set. */
43
+ export declare function iconStyle(rules: Iterable<string>, layer: string | undefined): string;
44
+ export interface IconViewInput {
45
+ name: string;
46
+ size?: string | number;
47
+ mode?: IconMode;
48
+ title?: string;
49
+ customize?: IconCustomize;
50
+ class?: string;
51
+ /** The props give `aria-label` or `aria-labelledby`. */
52
+ labelled?: boolean;
53
+ }
54
+ export type IconView = {
55
+ mode: "svg";
56
+ attrs: Record<string, string>;
57
+ title?: string;
58
+ nodes: SvgNode[];
59
+ } | {
60
+ mode: "css";
61
+ attrs: Record<string, string>;
62
+ rule?: {
63
+ className: string;
64
+ text: string;
65
+ };
66
+ };
67
+ /** What one `Icon` draws, for every library alike; `found` is undefined for a name no source has. */
68
+ export declare function iconView(input: IconViewInput, name: IconName | undefined, found: IconData | undefined, options: IconRuntimeOptions): IconView;
@@ -0,0 +1,2 @@
1
+ /** Each collection of the icon server bundle is parsed once per process; the app plugin and the endpoint share the one read. */
2
+ export declare function loadServerCollections(): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import "#hamur/icon/classes.css";
2
+ declare const _default: import("hamur/app").AppPlugin<{}>;
3
+ export default _default;
@@ -0,0 +1,27 @@
1
+ import type { AppContext, HeadInput } from "hamur/app";
2
+ import { type IconView, type IconViewInput } from "../render.ts";
3
+ import type { IconDefaults, IconifyJSON, IconPayload, IconRuntimeOptions } from "../types.ts";
4
+ import type { Remote } from "./remote.ts";
5
+ export declare function addServerCollection(prefix: string, collection: IconifyJSON): void;
6
+ export declare const getServerCollection: (prefix: string) => IconifyJSON | undefined;
7
+ /** `head` is the whole `<style>` text of the app's CSS-mode icons once this one is recorded. */
8
+ export type IconRenderView = IconView & {
9
+ head?: string;
10
+ /** Set while the icon is being fetched; settles when the answer is cached. */ pending?: Promise<void>;
11
+ };
12
+ export interface Icons {
13
+ /** `config` is `runtimeConfig.public.icon`: its `aliases` rename `input.name`, its `size`, `class` and `mode` fill what `input` leaves out. */
14
+ view(app: AppContext, input: IconViewInput, config?: IconDefaults): IconRenderView;
15
+ /** Calls `listener` after a fetch answered; the returned function stops it. Nothing is fetched on the server. */
16
+ subscribe(listener: () => void): () => void;
17
+ /** Changes with every answer, so a subscriber that started after a render can tell it missed one. */
18
+ version(): number;
19
+ }
20
+ /**
21
+ * The server render reads the icon server bundle and puts each icon it drew into `app.modulePayload.icon`, which the
22
+ * browser reads back, so the hydration draws the same markup with no request. An icon the client bundle holds is left out
23
+ * of it, since the browser has it already. CSS-mode rules are recorded per app by class.
24
+ */
25
+ export declare function createIcons(options: IconRuntimeOptions, warn?: ((message: string) => void) | undefined, collections?: Map<string, IconifyJSON>, client?: IconPayload, remote?: Remote): Icons;
26
+ /** The app's CSS-mode rules as one `<style>`; a later push under the key holds a superset of an earlier one and replaces it. */
27
+ export declare function iconHead(view: IconRenderView): HeadInput;
@@ -0,0 +1,2 @@
1
+ export declare const icons: import("./icons.ts").Icons;
2
+ export { iconHead, type IconRenderView } from "./icons.ts";
@@ -0,0 +1,22 @@
1
+ import type { IconifyIcon } from "../types.ts";
2
+ export interface RemoteOptions {
3
+ provider: "server" | "iconify";
4
+ iconifyApiEndpoint: string;
5
+ fetchTimeout: number;
6
+ fetch?: typeof fetch;
7
+ /** Read inside a `try` on every access, since the accessor can throw; default `sessionStorage`. */
8
+ storage?: () => Storage | undefined;
9
+ }
10
+ /** The icons the browser asked for, by prefix and name; `null` is an icon known to be missing. */
11
+ export interface Remote {
12
+ lookup(prefix: string, name: string): IconifyIcon | null | undefined;
13
+ /** The promise of the batch that will answer, or `undefined` when the icon is already answered. */
14
+ request(prefix: string, name: string, baseURL: string): Promise<void> | undefined;
15
+ subscribe(listener: () => void): () => void;
16
+ version(): number;
17
+ }
18
+ /**
19
+ * Names asked within one microtask are one request per prefix (at most `MAX_ICONS` names each). The answers are kept in memory
20
+ * and in `sessionStorage`, misses too, so a missing icon is not asked again; a failed request is remembered in memory only.
21
+ */
22
+ export declare function createRemote(options: RemoteOptions): Remote;
@@ -0,0 +1,3 @@
1
+ /** The server app plugin reads the icon server bundle once per process, before the first render needs it. */
2
+ declare const _default: import("hamur/app").AppPlugin<{}>;
3
+ export default _default;
@@ -0,0 +1 @@
1
+ export { iconEndpoint } from "./handler.ts";
@@ -0,0 +1,28 @@
1
+ import { MAX_ICONS } from "../name.ts";
2
+ import type { IconifyJSON } from "../types.ts";
3
+ export { MAX_ICONS };
4
+ export interface IconEndpointFallback {
5
+ iconifyApiEndpoint: string;
6
+ fetchTimeout: number;
7
+ fetch?: typeof fetch;
8
+ warn?: (message: string) => void;
9
+ /** Icons kept from upstream answers, hits and misses; default 1000. */
10
+ cacheSize?: number;
11
+ /** Milliseconds an upstream answer is kept; default one hour. */
12
+ cacheTtl?: number;
13
+ /** Outgoing requests at once; above it the bundle's icons are answered alone. Default 4. */
14
+ maxConcurrent?: number;
15
+ now?: () => number;
16
+ }
17
+ export interface IconEndpointEnvironment {
18
+ /** `hamur dev` answers `cache-control: no-cache`. */
19
+ dev: boolean;
20
+ collection(prefix: string): IconifyJSON | undefined;
21
+ /** Set when `icon.fallbackToApi` is on. */
22
+ fallback?: IconEndpointFallback;
23
+ }
24
+ /**
25
+ * `GET /_hamur/icons/<prefix>.json?icons=a,b` in the Iconify API's shape. The prefix and every name are checked against
26
+ * `NAME_PATTERN` before they are looked up or put in an outgoing URL; the endpoint reads no file the request names.
27
+ */
28
+ export declare function createIconEndpoint(env: IconEndpointEnvironment): (request: Request) => Promise<Response>;
@@ -0,0 +1 @@
1
+ export declare const iconEndpoint: import("hamur/adapter").Handler<unknown, Response, unknown, Response, {}>;
@@ -0,0 +1,2 @@
1
+ /** Reads the installed collections into the registry a server render reads, as the server plugin does at start. */
2
+ export declare function loadIconCollections(prefixes: string[]): void;