@hamur/icon 0.0.1 → 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.
|
@@ -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
|
|
11
|
-
readonly size: import("@angular/core
|
|
12
|
-
readonly mode: import("@angular/core
|
|
13
|
-
readonly title: import("@angular/core
|
|
14
|
-
readonly customize: import("@angular/core
|
|
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.
|
|
3
|
+
"version": "0.0.2",
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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.
|
|
57
|
-
"@hamur/adapter-react": "^0.0.
|
|
58
|
-
"@hamur/adapter-vue": "^0.0.
|
|
59
|
-
"@hamur/adapter-preact": "^0.0.
|
|
60
|
-
"@hamur/adapter-svelte": "^0.0.
|
|
61
|
-
"@hamur/adapter-solid": "^0.0.
|
|
62
|
-
"@hamur/adapter-html": "^0.0.
|
|
63
|
-
"@hamur/adapter-angular": "^0.0.
|
|
83
|
+
"hamur": "^0.0.2",
|
|
84
|
+
"@hamur/adapter-react": "^0.0.2",
|
|
85
|
+
"@hamur/adapter-vue": "^0.0.2",
|
|
86
|
+
"@hamur/adapter-preact": "^0.0.2",
|
|
87
|
+
"@hamur/adapter-svelte": "^0.0.2",
|
|
88
|
+
"@hamur/adapter-solid": "^0.0.2",
|
|
89
|
+
"@hamur/adapter-html": "^0.0.2",
|
|
90
|
+
"@hamur/adapter-angular": "^0.0.2",
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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 }] }] } });
|