@hamur/icon 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ <script lang="ts">
2
+ import { untrack } from "svelte"
3
+ import type { SvgNode } from "hamur/adapter"
4
+ import { useApp, useRuntimeConfig, useHead } from "@hamur/adapter-svelte"
5
+ import { svgAttributes, svgValue } from "../render.ts"
6
+ import { iconHead, icons } from "../runtime/index.ts"
7
+ import type { IconDefaults, IconCustomize, IconMode } from "../types.ts"
8
+
9
+ type Props = {
10
+ name: string
11
+ size?: string | number
12
+ mode?: IconMode
13
+ title?: string
14
+ customize?: IconCustomize
15
+ class?: string
16
+ [attribute: string]: unknown
17
+ }
18
+
19
+ let { name, size, mode, title, customize, class: className, ...rest }: Props = $props()
20
+ const id = $props.id()
21
+ const uid = id.replace(/[^\w-]/g, "_")
22
+ const app = useApp()
23
+ const config = useRuntimeConfig().public as { icon?: IconDefaults }
24
+ const seen = icons.version()
25
+ let answers = $state(0)
26
+ $effect(() => {
27
+ if (icons.version() !== seen) untrack(() => answers++)
28
+ return icons.subscribe(() => answers++)
29
+ })
30
+ const view = $derived(
31
+ (answers,
32
+ icons.view(
33
+ app,
34
+ {
35
+ name,
36
+ size,
37
+ mode,
38
+ title,
39
+ customize,
40
+ class: className,
41
+ labelled: rest["aria-label"] != null || rest["aria-labelledby"] != null,
42
+ },
43
+ config.icon,
44
+ )),
45
+ )
46
+ useHead(() => iconHead(view))
47
+ </script>
48
+
49
+ {#snippet draw(node: SvgNode)}{#if typeof node === "string" || Array.isArray(node)}{svgValue(
50
+ node,
51
+ uid,
52
+ )}{:else}<svelte:element this={node.tag} xmlns="http://www.w3.org/2000/svg" {...svgAttributes(node, uid)}
53
+ >{#each node.children as child}{@render draw(child)}{/each}</svelte:element
54
+ >{/if}{/snippet}
55
+
56
+ {#if view.mode === "css"}<span {...view.attrs} {...rest}></span>{:else}<svg {...view.attrs} {...rest}
57
+ >{#if view.title !== undefined}<title>{view.title}</title>{/if}{#each view.nodes as node}{@render draw(
58
+ node,
59
+ )}{/each}</svg
60
+ >{/if}
@@ -1,5 +1,6 @@
1
1
  import { type OnInit } from "@angular/core";
2
2
  import type { IconCustomize, IconMode } from "../types.ts";
3
+ import * as i0 from "@angular/core";
3
4
  /**
4
5
  * `<hamur-icon name="mdi:home" mode="svg" />`, an icon of a collection by name, drawn as `<svg>` from the sanitised
5
6
  * body, or as a `<span>` and one CSS rule, inside the `<hamur-icon>` element. The nodes are written with the renderer, as no template
@@ -7,11 +8,11 @@ import type { IconCustomize, IconMode } from "../types.ts";
7
8
  * also written on the drawn element.
8
9
  */
9
10
  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>;
11
+ readonly name: import("@angular/core").InputSignal<string>;
12
+ readonly size: import("@angular/core").InputSignal<string | number | undefined>;
13
+ readonly mode: import("@angular/core").InputSignal<IconMode | undefined>;
14
+ readonly title: import("@angular/core").InputSignal<string | undefined>;
15
+ readonly customize: import("@angular/core").InputSignal<IconCustomize | undefined>;
15
16
  private readonly injector;
16
17
  private readonly app;
17
18
  private readonly config;
@@ -26,4 +27,6 @@ export declare class Icon implements OnInit {
26
27
  ngOnInit(): void;
27
28
  private draw;
28
29
  private element;
30
+ static ɵfac: i0.ɵɵFactoryDeclaration<Icon, never>;
31
+ static ɵcmp: i0.ɵɵComponentDeclaration<Icon, "hamur-icon", never, { "name": { "alias": "name"; "required": true; "isSignal": true; }; "size": { "alias": "size"; "required": false; "isSignal": true; }; "mode": { "alias": "mode"; "required": false; "isSignal": true; }; "title": { "alias": "title"; "required": false; "isSignal": true; }; "customize": { "alias": "customize"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
29
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamur/icon",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,39 +11,66 @@
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./dist/types/src/index.d.ts",
14
- "default": "./dist/src/index.js"
14
+ "bun": "./src/index.ts",
15
+ "hamur-source": "./src/index.ts",
16
+ "node": "./dist/src/index.js",
17
+ "default": "./src/index.ts"
15
18
  },
16
19
  "./react": {
17
20
  "types": "./dist/types/src/adapters/react.d.ts",
18
- "default": "./dist/src/adapters/react.js"
21
+ "bun": "./src/adapters/react.ts",
22
+ "hamur-source": "./src/adapters/react.ts",
23
+ "node": "./dist/src/adapters/react.js",
24
+ "default": "./src/adapters/react.ts"
19
25
  },
20
26
  "./vue": {
21
27
  "types": "./dist/types/src/adapters/vue.d.ts",
22
- "default": "./dist/src/adapters/vue.js"
28
+ "bun": "./src/adapters/vue.ts",
29
+ "hamur-source": "./src/adapters/vue.ts",
30
+ "node": "./dist/src/adapters/vue.js",
31
+ "default": "./src/adapters/vue.ts"
23
32
  },
24
33
  "./preact": {
25
34
  "types": "./dist/types/src/adapters/preact.d.ts",
26
- "default": "./dist/src/adapters/preact.js"
35
+ "bun": "./src/adapters/preact.ts",
36
+ "hamur-source": "./src/adapters/preact.ts",
37
+ "node": "./dist/src/adapters/preact.js",
38
+ "default": "./src/adapters/preact.ts"
27
39
  },
28
40
  "./svelte": {
29
41
  "types": "./dist/types/src/adapters/svelte.d.ts",
30
- "default": "./dist/src/adapters/svelte.js"
42
+ "bun": "./src/adapters/svelte.ts",
43
+ "hamur-source": "./src/adapters/svelte.ts",
44
+ "node": "./dist/src/adapters/svelte.js",
45
+ "default": "./src/adapters/svelte.ts"
31
46
  },
32
47
  "./solid": {
33
48
  "types": "./dist/types/src/adapters/solid.d.ts",
34
- "default": "./dist/src/adapters/solid.js"
49
+ "bun": "./src/adapters/solid.ts",
50
+ "hamur-source": "./src/adapters/solid.ts",
51
+ "node": "./dist/src/adapters/solid.js",
52
+ "default": "./src/adapters/solid.ts"
35
53
  },
36
54
  "./html": {
37
55
  "types": "./dist/types/src/adapters/html.d.ts",
38
- "default": "./dist/src/adapters/html.js"
56
+ "bun": "./src/adapters/html.ts",
57
+ "hamur-source": "./src/adapters/html.ts",
58
+ "node": "./dist/src/adapters/html.js",
59
+ "default": "./src/adapters/html.ts"
39
60
  },
40
61
  "./angular": {
41
62
  "types": "./dist/types/src/adapters/angular.d.ts",
42
- "default": "./dist/src/adapters/angular.js"
63
+ "bun": "./src/adapters/angular.ts",
64
+ "hamur-source": "./src/adapters/angular.ts",
65
+ "node": "./dist/src/adapters/angular.js",
66
+ "default": "./src/adapters/angular.ts"
43
67
  },
44
68
  "./testing": {
45
69
  "types": "./dist/types/src/testing.d.ts",
46
- "default": "./dist/src/testing.js"
70
+ "bun": "./src/testing.ts",
71
+ "hamur-source": "./src/testing.ts",
72
+ "node": "./dist/src/testing.js",
73
+ "default": "./src/testing.ts"
47
74
  },
48
75
  "./package.json": "./package.json"
49
76
  },
@@ -53,14 +80,14 @@
53
80
  ],
54
81
  "dependencies": {},
55
82
  "peerDependencies": {
56
- "hamur": "^0.0.1",
57
- "@hamur/adapter-react": "^0.0.1",
58
- "@hamur/adapter-vue": "^0.0.1",
59
- "@hamur/adapter-preact": "^0.0.1",
60
- "@hamur/adapter-svelte": "^0.0.1",
61
- "@hamur/adapter-solid": "^0.0.1",
62
- "@hamur/adapter-html": "^0.0.1",
63
- "@hamur/adapter-angular": "^0.0.1",
83
+ "hamur": "^0.0.3",
84
+ "@hamur/adapter-react": "^0.0.3",
85
+ "@hamur/adapter-vue": "^0.0.3",
86
+ "@hamur/adapter-preact": "^0.0.3",
87
+ "@hamur/adapter-svelte": "^0.0.3",
88
+ "@hamur/adapter-solid": "^0.0.3",
89
+ "@hamur/adapter-html": "^0.0.3",
90
+ "@hamur/adapter-angular": "^0.0.3",
64
91
  "react": "^19.3.1",
65
92
  "preact": "^11.0.2",
66
93
  "vue": "^3.5.44",
@@ -1,112 +1,104 @@
1
- import {
2
- Component,
3
- DestroyRef,
4
- ElementRef,
5
- HostAttributeToken,
6
- Injector,
7
- Renderer2,
8
- computed,
9
- effect,
10
- inject,
11
- input,
12
- runInInjectionContext,
13
- signal,
14
- untracked,
15
- type OnInit,
16
- } from "@angular/core"
17
- import { injectApp, injectHead, injectId, injectRuntimeConfig } from "@hamur/adapter-angular"
18
- import type { SvgNode } from "hamur/adapter"
19
- import { svgAttributes, svgValue } from "../render.ts"
20
- import { iconHead, icons, type IconRenderView } from "../runtime/index.ts"
21
- import type { IconDefaults, IconCustomize, IconMode } from "../types.ts"
22
-
1
+ import { Component, DestroyRef, ElementRef, HostAttributeToken, Injector, Renderer2, computed, effect, inject, input, runInInjectionContext, signal, untracked, } from "@angular/core";
2
+ import { injectApp, injectHead, injectId, injectRuntimeConfig } from "@hamur/adapter-angular";
3
+ import { svgAttributes, svgValue } from "../render.ts";
4
+ import { iconHead, icons } from "../runtime/index.ts";
5
+ import * as i0 from "@angular/core";
23
6
  /**
24
7
  * `<hamur-icon name="mdi:home" mode="svg" />`, an icon of a collection by name, drawn as `<svg>` from the sanitised
25
8
  * body, or as a `<span>` and one CSS rule, inside the `<hamur-icon>` element. The nodes are written with the renderer, as no template
26
9
  * can name an element the body decides; the props are taken off the host, and `aria-label` and `aria-labelledby` are
27
10
  * also written on the drawn element.
28
11
  */
29
- @Component({
30
- selector: "hamur-icon",
31
- template: "",
32
- host: {
33
- "[attr.name]": "null",
34
- "[attr.size]": "null",
35
- "[attr.mode]": "null",
36
- "[attr.title]": "null",
37
- "[attr.customize]": "null",
38
- },
39
- })
40
- export class Icon implements OnInit {
41
- readonly name = input.required<string>()
42
- readonly size = input<string | number>()
43
- readonly mode = input<IconMode>()
44
- readonly title = input<string>()
45
- readonly customize = input<IconCustomize>()
46
-
47
- private readonly injector = inject(Injector)
48
- private readonly app = injectApp()
49
- private readonly config = injectRuntimeConfig().public as { icon?: IconDefaults }
50
- private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement
51
- private readonly renderer = inject(Renderer2)
52
- private readonly label = inject(new HostAttributeToken("aria-label"), { optional: true })
53
- private readonly labelledby = inject(new HostAttributeToken("aria-labelledby"), { optional: true })
54
- private readonly uid = injectId().replace(/[^\w-]/g, "_")
55
- private readonly answers = signal(icons.version())
56
-
57
- private readonly view = computed(() => {
58
- void this.answers()
59
- return icons.view(
60
- this.app,
61
- {
62
- name: this.name(),
63
- size: this.size(),
64
- mode: this.mode(),
65
- title: this.title(),
66
- customize: this.customize(),
67
- labelled: this.label !== null || this.labelledby !== null,
68
- },
69
- this.config.icon,
70
- )
71
- })
72
-
73
- constructor() {
74
- inject(DestroyRef).onDestroy(icons.subscribe(() => this.answers.set(icons.version())))
75
- effect(() => {
76
- const view = this.view()
77
- untracked(() => this.draw(view))
78
- })
79
- }
80
-
81
- ngOnInit(): void {
82
- runInInjectionContext(this.injector, () => injectHead(() => iconHead(this.view())))
83
- }
84
-
85
- private draw(view: IconRenderView): void {
86
- const { renderer, host } = this
87
- while (host.firstChild) renderer.removeChild(host, host.firstChild)
88
- const root = view.mode === "css" ? renderer.createElement("span") : renderer.createElement("svg", "svg")
89
- const attrs = { ...view.attrs }
90
- if (this.label !== null) attrs["aria-label"] = this.label
91
- if (this.labelledby !== null) attrs["aria-labelledby"] = this.labelledby
92
- for (const [name, value] of Object.entries(attrs)) renderer.setAttribute(root, name, value)
93
- if (view.mode === "svg") {
94
- if (view.title !== undefined) {
95
- const title = renderer.createElement("title", "svg")
96
- renderer.appendChild(title, renderer.createText(view.title))
97
- renderer.appendChild(root, title)
98
- }
99
- for (const node of view.nodes) renderer.appendChild(root, this.element(node))
12
+ export class Icon {
13
+ name = input.required(/* @ts-ignore */
14
+ ...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
15
+ size = input(/* @ts-ignore */
16
+ ...(ngDevMode ? [undefined, { debugName: "size" }] : /* istanbul ignore next */ []));
17
+ mode = input(/* @ts-ignore */
18
+ ...(ngDevMode ? [undefined, { debugName: "mode" }] : /* istanbul ignore next */ []));
19
+ title = input(/* @ts-ignore */
20
+ ...(ngDevMode ? [undefined, { debugName: "title" }] : /* istanbul ignore next */ []));
21
+ customize = input(/* @ts-ignore */
22
+ ...(ngDevMode ? [undefined, { debugName: "customize" }] : /* istanbul ignore next */ []));
23
+ injector = inject(Injector);
24
+ app = injectApp();
25
+ config = injectRuntimeConfig().public;
26
+ host = inject(ElementRef).nativeElement;
27
+ renderer = inject(Renderer2);
28
+ label = inject(new HostAttributeToken("aria-label"), { optional: true });
29
+ labelledby = inject(new HostAttributeToken("aria-labelledby"), { optional: true });
30
+ uid = injectId().replace(/[^\w-]/g, "_");
31
+ answers = signal(icons.version(), /* @ts-ignore */
32
+ ...(ngDevMode ? [{ debugName: "answers" }] : /* istanbul ignore next */ []));
33
+ view = computed(() => {
34
+ void this.answers();
35
+ return icons.view(this.app, {
36
+ name: this.name(),
37
+ size: this.size(),
38
+ mode: this.mode(),
39
+ title: this.title(),
40
+ customize: this.customize(),
41
+ labelled: this.label !== null || this.labelledby !== null,
42
+ }, this.config.icon);
43
+ }, /* @ts-ignore */
44
+ ...(ngDevMode ? [{ debugName: "view" }] : /* istanbul ignore next */ []));
45
+ constructor() {
46
+ inject(DestroyRef).onDestroy(icons.subscribe(() => this.answers.set(icons.version())));
47
+ effect(() => {
48
+ const view = this.view();
49
+ untracked(() => this.draw(view));
50
+ });
100
51
  }
101
- renderer.appendChild(host, root)
102
- }
103
-
104
- private element(node: SvgNode): Node {
105
- if (typeof node === "string" || Array.isArray(node)) return this.renderer.createText(svgValue(node, this.uid))
106
- const element = this.renderer.createElement(node.tag, "svg")
107
- for (const [name, value] of Object.entries(svgAttributes(node, this.uid)))
108
- this.renderer.setAttribute(element, name, value)
109
- for (const child of node.children) this.renderer.appendChild(element, this.element(child))
110
- return element
111
- }
52
+ ngOnInit() {
53
+ runInInjectionContext(this.injector, () => injectHead(() => iconHead(this.view())));
54
+ }
55
+ draw(view) {
56
+ const { renderer, host } = this;
57
+ while (host.firstChild)
58
+ renderer.removeChild(host, host.firstChild);
59
+ const root = view.mode === "css" ? renderer.createElement("span") : renderer.createElement("svg", "svg");
60
+ const attrs = { ...view.attrs };
61
+ if (this.label !== null)
62
+ attrs["aria-label"] = this.label;
63
+ if (this.labelledby !== null)
64
+ attrs["aria-labelledby"] = this.labelledby;
65
+ for (const [name, value] of Object.entries(attrs))
66
+ renderer.setAttribute(root, name, value);
67
+ if (view.mode === "svg") {
68
+ if (view.title !== undefined) {
69
+ const title = renderer.createElement("title", "svg");
70
+ renderer.appendChild(title, renderer.createText(view.title));
71
+ renderer.appendChild(root, title);
72
+ }
73
+ for (const node of view.nodes)
74
+ renderer.appendChild(root, this.element(node));
75
+ }
76
+ renderer.appendChild(host, root);
77
+ }
78
+ element(node) {
79
+ if (typeof node === "string" || Array.isArray(node))
80
+ return this.renderer.createText(svgValue(node, this.uid));
81
+ const element = this.renderer.createElement(node.tag, "svg");
82
+ for (const [name, value] of Object.entries(svgAttributes(node, this.uid)))
83
+ this.renderer.setAttribute(element, name, value);
84
+ for (const child of node.children)
85
+ this.renderer.appendChild(element, this.element(child));
86
+ return element;
87
+ }
88
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Icon, deps: [], target: i0.ɵɵFactoryTarget.Component });
89
+ static ɵcmp = i0.ɵɵ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 });
112
90
  }
91
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Icon, decorators: [{
92
+ type: Component,
93
+ args: [{
94
+ selector: "hamur-icon",
95
+ template: "",
96
+ host: {
97
+ "[attr.name]": "null",
98
+ "[attr.size]": "null",
99
+ "[attr.mode]": "null",
100
+ "[attr.title]": "null",
101
+ "[attr.customize]": "null",
102
+ },
103
+ }]
104
+ }], 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 }] }] } });
package/src/env.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  interface ImportMeta {
2
2
  readonly dev?: boolean
3
3
  readonly server?: boolean
4
- readonly hot?: unknown
5
4
  }
6
5
 
7
6
  declare module "#hamur/icon/options" {