@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
@@ -0,0 +1,47 @@
1
+ // @bun
2
+ import {
3
+ escapeHtml,
4
+ attributesMarkup,
5
+ svgMarkup,
6
+ iconHead
7
+ } from "../../chunks/bun-react-nygte91t.js";
8
+ import {
9
+ icons
10
+ } from "../../chunks/bun-react-fhd05zxm.js";
11
+
12
+ // packages/icon/src/adapters/html.ts
13
+ import { Await, useApp, useRuntimeConfig, useHead, useId } from "@hamur/adapter-html";
14
+ function attributes(values) {
15
+ const out = {};
16
+ for (const [name, value] of Object.entries(values)) {
17
+ if (value === undefined || value === null || value === false)
18
+ continue;
19
+ out[name] = value === true ? "" : String(value);
20
+ }
21
+ return out;
22
+ }
23
+ function Icon(props) {
24
+ const { name, size, mode, title, customize, class: className, ...rest } = props;
25
+ const view = icons.view(useApp(), {
26
+ name,
27
+ size,
28
+ mode,
29
+ title,
30
+ customize,
31
+ class: className,
32
+ labelled: rest["aria-label"] != null || rest["aria-labelledby"] != null
33
+ }, useRuntimeConfig().public.icon);
34
+ let markup;
35
+ if (view.mode === "css") {
36
+ if (view.head !== undefined)
37
+ useHead(iconHead(view));
38
+ markup = `<span${attributesMarkup({ ...view.attrs, ...attributes(rest) })}></span>`;
39
+ } else {
40
+ const uid = useId().replace(/[^\w-]/g, "_");
41
+ markup = `<svg${attributesMarkup({ ...view.attrs, ...attributes(rest) })}>${view.title === undefined ? "" : `<title>${escapeHtml(view.title)}</title>`}${svgMarkup(view.nodes, uid)}</svg>`;
42
+ }
43
+ return view.pending ? Await(view.pending, { fallback: markup, then: () => Icon(props) }) : markup;
44
+ }
45
+ export {
46
+ Icon
47
+ };
@@ -0,0 +1,56 @@
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/preact.ts
12
+ import { h } from "preact";
13
+ import { useEffect, useState } from "preact/hooks";
14
+ import { useApp, useRuntimeConfig, useHead, useId } from "@hamur/adapter-preact";
15
+ function element(node, uid) {
16
+ if (typeof node === "string" || Array.isArray(node))
17
+ return svgValue(node, uid);
18
+ return h(node.tag, svgAttributes(node, uid), ...node.children.map((child) => element(child, uid)));
19
+ }
20
+ function Icon({
21
+ name,
22
+ size,
23
+ mode,
24
+ title,
25
+ customize,
26
+ class: className,
27
+ className: alias,
28
+ ...rest
29
+ }) {
30
+ const uid = useId().replace(/[^\w-]/g, "_");
31
+ const seen = icons.version();
32
+ const [, update] = useState(0);
33
+ useEffect(() => {
34
+ if (icons.version() !== seen)
35
+ update((count) => count + 1);
36
+ return icons.subscribe(() => update((count) => count + 1));
37
+ }, []);
38
+ const config = useRuntimeConfig().public.icon;
39
+ const view = icons.view(useApp(), {
40
+ name,
41
+ size,
42
+ mode,
43
+ title,
44
+ customize,
45
+ class: [className, alias].filter((value) => typeof value === "string" && value !== "").join(" ") || undefined,
46
+ labelled: rest["aria-label"] != null || rest["aria-labelledby"] != null
47
+ }, config);
48
+ useHead(iconHead(view));
49
+ const props = { ...view.attrs, ...rest };
50
+ if (view.mode === "css")
51
+ return h("span", props);
52
+ return h("svg", props, view.title === undefined ? null : h("title", null, view.title), ...view.nodes.map((node) => element(node, uid)));
53
+ }
54
+ export {
55
+ Icon
56
+ };
@@ -0,0 +1,66 @@
1
+ // @bun
2
+ import {
3
+ svgValue,
4
+ iconHead
5
+ } from "../../chunks/bun-react-nygte91t.js";
6
+ import {
7
+ icons
8
+ } from "../../chunks/bun-react-fhd05zxm.js";
9
+
10
+ // packages/icon/src/adapters/react.ts
11
+ import { createElement, useSyncExternalStore } from "react";
12
+ import { useApp, useRuntimeConfig, useHead, useId } from "@hamur/adapter-react";
13
+ function propName(name) {
14
+ if (name === "class")
15
+ return "className";
16
+ if (name === "tabindex")
17
+ return "tabIndex";
18
+ if (name.startsWith("aria-") || name.startsWith("data-"))
19
+ return name;
20
+ return name.replace(/[-:]([a-z])/g, (_, letter) => letter.toUpperCase());
21
+ }
22
+ var styleKey = (name) => name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
23
+ var h = (tag, props, ...children) => createElement(tag, props, ...children);
24
+ function styleObject(text) {
25
+ return Object.fromEntries(text.split(";").filter(Boolean).map((declaration) => [
26
+ styleKey(declaration.slice(0, declaration.indexOf(":"))),
27
+ declaration.slice(declaration.indexOf(":") + 1)
28
+ ]));
29
+ }
30
+ function rootProps(attrs) {
31
+ const props = {};
32
+ for (const [name, value] of Object.entries(attrs))
33
+ props[name === "style" ? "style" : propName(name)] = name === "style" ? styleObject(value) : value;
34
+ return props;
35
+ }
36
+ function element(node, uid) {
37
+ if (typeof node === "string" || Array.isArray(node))
38
+ return svgValue(node, uid);
39
+ const props = {};
40
+ for (const [name, value] of Object.entries(node.attrs))
41
+ props[propName(name)] = svgValue(value, uid);
42
+ if (node.style)
43
+ props.style = Object.fromEntries(node.style.map((declaration) => [styleKey(declaration.name), svgValue(declaration.value, uid)]));
44
+ return h(node.tag, props, ...node.children.map((child) => element(child, uid)));
45
+ }
46
+ function Icon({ name, size, mode, title, customize, className, ...rest }) {
47
+ const uid = useId().replace(/[^\w-]/g, "_");
48
+ useSyncExternalStore(icons.subscribe, icons.version, icons.version);
49
+ const view = icons.view(useApp(), {
50
+ name,
51
+ size,
52
+ mode,
53
+ title,
54
+ customize,
55
+ class: className,
56
+ labelled: rest["aria-label"] != null || rest["aria-labelledby"] != null
57
+ }, useRuntimeConfig().public.icon);
58
+ useHead(iconHead(view));
59
+ const props = { ...rootProps(view.attrs), ...rest };
60
+ if (view.mode === "css")
61
+ return h("span", props);
62
+ return h("svg", props, view.title === undefined ? null : h("title", null, view.title), ...view.nodes.map((node) => element(node, uid)));
63
+ }
64
+ export {
65
+ Icon
66
+ };
@@ -0,0 +1,97 @@
1
+ // @bun
2
+ import {
3
+ SVG_NAMESPACE,
4
+ svgValue,
5
+ svgAttributes,
6
+ iconHead
7
+ } from "../../chunks/bun-react-nygte91t.js";
8
+ import {
9
+ icons
10
+ } from "../../chunks/bun-react-fhd05zxm.js";
11
+
12
+ // packages/icon/src/adapters/solid-icon.ts
13
+ import {
14
+ createComponent,
15
+ createMemo,
16
+ createSignal,
17
+ isHydrating,
18
+ merge,
19
+ omit,
20
+ onCleanup
21
+ } from "solid-js";
22
+ import { dynamic, isServer, spread } from "@solidjs/web";
23
+ import { useApp, useRuntimeConfig, useHead, useId } from "@hamur/adapter-solid";
24
+ var OWN = ["name", "size", "mode", "title", "customize", "class"];
25
+ var tags = new Map;
26
+ function tagged(tag) {
27
+ let made = tags.get(tag);
28
+ if (!made)
29
+ tags.set(tag, made = dynamic(() => tag, { static: true }));
30
+ return made;
31
+ }
32
+ function svgElement(tag, props) {
33
+ if (isServer || isHydrating())
34
+ return createComponent(tagged(tag), props);
35
+ const element = document.createElementNS(SVG_NAMESPACE, tag);
36
+ spread(element, props);
37
+ return element;
38
+ }
39
+ function withStyle(attrs) {
40
+ const { style, ...rest } = attrs;
41
+ const out = { ...rest };
42
+ if (style === undefined)
43
+ return out;
44
+ return isServer ? { ...out, style } : { ...out, ref: (element) => element.setAttribute("style", style) };
45
+ }
46
+ function element(node, uid) {
47
+ if (typeof node === "string" || Array.isArray(node))
48
+ return svgValue(node, uid);
49
+ return svgElement(node.tag, {
50
+ ...withStyle(svgAttributes(node, uid)),
51
+ get children() {
52
+ return node.children.map((child) => element(child, uid));
53
+ }
54
+ });
55
+ }
56
+ var createIcon = (icons) => function Icon(props) {
57
+ const own = props;
58
+ const rest = omit(props, ...OWN);
59
+ const app = useApp();
60
+ const config = useRuntimeConfig().public;
61
+ const uid = useId().replace(/[^\w-]/g, "_");
62
+ const [answers, answered] = createSignal(icons.version());
63
+ onCleanup(icons.subscribe(() => answered(icons.version())));
64
+ const view = createMemo(() => {
65
+ answers();
66
+ return icons.view(app, {
67
+ name: own.name,
68
+ size: own.size,
69
+ mode: own.mode,
70
+ title: own.title,
71
+ customize: own.customize,
72
+ class: typeof own.class === "string" && own.class !== "" ? own.class : undefined,
73
+ labelled: rest["aria-label"] != null || rest["aria-labelledby"] != null
74
+ }, config.icon);
75
+ });
76
+ useHead(() => iconHead(view()));
77
+ return () => {
78
+ const current = view();
79
+ if (current.mode === "css")
80
+ return createComponent(tagged("span"), merge(withStyle(current.attrs), rest));
81
+ const children = () => [
82
+ ...current.title === undefined ? [] : [svgElement("title", { children: current.title })],
83
+ ...current.nodes.map((node) => element(node, uid))
84
+ ];
85
+ return svgElement("svg", merge(withStyle(current.attrs), rest, {
86
+ get children() {
87
+ return children();
88
+ }
89
+ }));
90
+ };
91
+ };
92
+
93
+ // packages/icon/src/adapters/solid.ts
94
+ var Icon = createIcon(icons);
95
+ export {
96
+ Icon
97
+ };
@@ -0,0 +1,6 @@
1
+ // @bun
2
+ // packages/icon/src/adapters/svelte.ts
3
+ import { default as default2 } from "../../../src/adapters/Icon.svelte";
4
+ export {
5
+ default2 as Icon
6
+ };
@@ -0,0 +1,63 @@
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/vue.ts
12
+ import { defineComponent, h, onScopeDispose, shallowRef } from "vue";
13
+ import { useApp, useRuntimeConfig, useHead, useId } from "@hamur/adapter-vue";
14
+ function element(node, uid) {
15
+ if (typeof node === "string" || Array.isArray(node))
16
+ return svgValue(node, uid);
17
+ return h(node.tag, svgAttributes(node, uid), node.children.map((child) => element(child, uid)));
18
+ }
19
+ var Icon = defineComponent({
20
+ name: "Icon",
21
+ inheritAttrs: false,
22
+ props: {
23
+ name: { type: String, required: true },
24
+ size: { type: [String, Number] },
25
+ mode: { type: String },
26
+ title: { type: String },
27
+ customize: { type: Function }
28
+ },
29
+ setup(props, { attrs }) {
30
+ const app = useApp();
31
+ const config = useRuntimeConfig().public;
32
+ const uid = useId().replace(/[^\w-]/g, "_");
33
+ const answers = shallowRef(icons.version());
34
+ onScopeDispose(icons.subscribe(() => answers.value = icons.version()));
35
+ const read = () => {
36
+ answers.value;
37
+ return icons.view(app, {
38
+ name: props.name,
39
+ size: props.size,
40
+ mode: props.mode,
41
+ title: props.title,
42
+ customize: props.customize,
43
+ class: typeof attrs.class === "string" && attrs.class !== "" ? attrs.class : undefined,
44
+ labelled: attrs["aria-label"] != null || attrs["aria-labelledby"] != null
45
+ }, config.icon);
46
+ };
47
+ useHead(() => iconHead(read()));
48
+ return () => {
49
+ const view = read();
50
+ const { class: _class, ...rest } = attrs;
51
+ const own = { ...view.attrs, ...rest };
52
+ if (view.mode === "css")
53
+ return h("span", own);
54
+ return h("svg", own, [
55
+ ...view.title === undefined ? [] : [h("title", view.title)],
56
+ ...view.nodes.map((node) => element(node, uid))
57
+ ]);
58
+ };
59
+ }
60
+ });
61
+ export {
62
+ Icon
63
+ };