@camox/api-contract 0.43.0 → 0.44.0
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.
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +72 -0
- package/dist/index.d.ts +513 -118
- package/dist/index.js +102 -0
- package/dist/query-keys.d.ts +4 -0
- package/dist/query-keys.js +4 -0
- package/package.json +6 -1
- package/src/comments.ts +33 -0
- package/src/icons.ts +84 -0
- package/src/index.ts +2 -0
- package/src/query-keys.ts +4 -0
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IconifyJSON } from "@iconify/types";
|
|
2
|
+
export declare const ICON_CATALOG_VERSION = "2.2.532";
|
|
3
|
+
export type IconSvgData = {
|
|
4
|
+
body: string;
|
|
5
|
+
attributes: Record<string, string>;
|
|
6
|
+
attribution?: {
|
|
7
|
+
collection: string;
|
|
8
|
+
author: string;
|
|
9
|
+
license: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare function loadIconCollection(prefix: string): Promise<IconifyJSON>;
|
|
14
|
+
export declare function iconCollectionIds(data: IconifyJSON): string[];
|
|
15
|
+
export declare function resolveIconSvg(data: IconifyJSON, id: string): IconSvgData;
|
|
16
|
+
export declare function scopeIconSvgIds(body: string, prefix: string): string;
|
|
17
|
+
export declare function validateIconValue(value: unknown, schema: {
|
|
18
|
+
fieldType?: string;
|
|
19
|
+
enum?: unknown;
|
|
20
|
+
}): void;
|
package/dist/icons.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getIconData, iconToSVG } from "@iconify/utils";
|
|
2
|
+
// One immutable snapshot for declarations, schemas, picker and SVG resolution.
|
|
3
|
+
export const ICON_CATALOG_VERSION = "2.2.532";
|
|
4
|
+
const collections = new Map();
|
|
5
|
+
export async function loadIconCollection(prefix) {
|
|
6
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(prefix))
|
|
7
|
+
throw new Error("Invalid icon collection");
|
|
8
|
+
const existing = collections.get(prefix);
|
|
9
|
+
if (existing)
|
|
10
|
+
return existing;
|
|
11
|
+
const pending = (async () => {
|
|
12
|
+
const response = await fetch(`https://unpkg.com/@iconify/json@${ICON_CATALOG_VERSION}/json/${prefix}.json`, { signal: AbortSignal.timeout(30_000) });
|
|
13
|
+
if (!response.ok)
|
|
14
|
+
throw new Error(`Unable to load icon collection ${prefix}`);
|
|
15
|
+
const data = (await response.json());
|
|
16
|
+
if (data.prefix !== prefix || !data.icons || !data.info?.license)
|
|
17
|
+
throw new Error("Invalid icon catalog or missing license");
|
|
18
|
+
return data;
|
|
19
|
+
})();
|
|
20
|
+
collections.set(prefix, pending);
|
|
21
|
+
// Bound worker memory; failed fetches must be retryable.
|
|
22
|
+
if (collections.size > 8)
|
|
23
|
+
collections.delete(collections.keys().next().value);
|
|
24
|
+
try {
|
|
25
|
+
return await pending;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
collections.delete(prefix);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function iconCollectionIds(data) {
|
|
33
|
+
return [...Object.keys(data.icons), ...Object.keys(data.aliases ?? {})]
|
|
34
|
+
.filter((name) => getIconData(data, name) !== null)
|
|
35
|
+
.sort()
|
|
36
|
+
.map((name) => `${data.prefix}:${name}`);
|
|
37
|
+
}
|
|
38
|
+
export function resolveIconSvg(data, id) {
|
|
39
|
+
const [prefix, name, extra] = id.split(":");
|
|
40
|
+
if (prefix !== data.prefix || !name || extra !== undefined)
|
|
41
|
+
throw new Error("Invalid icon ID");
|
|
42
|
+
const icon = getIconData(data, name);
|
|
43
|
+
if (!icon)
|
|
44
|
+
throw new Error(`Unknown icon: ${id}`);
|
|
45
|
+
const svg = iconToSVG(icon);
|
|
46
|
+
return {
|
|
47
|
+
body: svg.body,
|
|
48
|
+
attributes: svg.attributes,
|
|
49
|
+
attribution: data.info
|
|
50
|
+
? {
|
|
51
|
+
collection: data.info.name,
|
|
52
|
+
author: data.info.author.name,
|
|
53
|
+
license: data.info.license.title,
|
|
54
|
+
url: data.info.license.url,
|
|
55
|
+
}
|
|
56
|
+
: undefined,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function scopeIconSvgIds(body, prefix) {
|
|
60
|
+
const ids = [...body.matchAll(/\sid="([^\s"]+)"/g)].map((match) => match[1]);
|
|
61
|
+
if (!ids.length)
|
|
62
|
+
return body;
|
|
63
|
+
const pattern = ids.map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
64
|
+
return body.replace(new RegExp(`([#;"])(${pattern})([")]|\\.[a-z])`, "g"), (_match, before, id, after) => `${before}${prefix}${id}${after}`);
|
|
65
|
+
}
|
|
66
|
+
export function validateIconValue(value, schema) {
|
|
67
|
+
if (schema.fieldType !== "Icon")
|
|
68
|
+
return;
|
|
69
|
+
if (typeof value !== "string" || !Array.isArray(schema.enum) || !schema.enum.includes(value)) {
|
|
70
|
+
throw new Error(`Invalid icon ID: ${String(value)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|