ikoneme-lib 0.3.0 → 0.5.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/README.md +36 -4
- package/dist/ikonCanvas.d.ts +13 -0
- package/dist/ikonDb.d.ts +8 -0
- package/dist/ikonLayout.d.ts +69 -0
- package/dist/ikonSchema.d.ts +21 -1
- package/dist/ikoneme-lib.cjs +9 -9
- package/dist/ikoneme-lib.cjs.map +1 -1
- package/dist/ikoneme-lib.js +788 -565
- package/dist/ikoneme-lib.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/package.json +53 -53
package/README.md
CHANGED
|
@@ -125,12 +125,30 @@ import {
|
|
|
125
125
|
- `normalizeIkoneme(ikons)` — upgrades any legacy/URL-only stored payloads to
|
|
126
126
|
the `{ name, url }` shape. Run this on data loaded from storage/an API
|
|
127
127
|
before rendering.
|
|
128
|
-
- `generateIkonemeFromText(text)` — deterministic placeholder
|
|
129
|
-
(hash-based), useful for demos/tests until real NLP output is wired
|
|
128
|
+
- `generateIkonemeFromText(text, { search })` — deterministic placeholder
|
|
129
|
+
generator (hash-based), useful for demos/tests until real NLP output is wired
|
|
130
|
+
in. The root of each word is looked up with `search(word, { limit })`, which
|
|
131
|
+
defaults to `searchIkons`; pass one built on `searchIkonsV2` to match words in
|
|
132
|
+
any language.
|
|
130
133
|
- `BORDER_CONFIG` — the 12 border types (`{ id, label, color, plural, image }`);
|
|
131
134
|
`image` is the artwork as a data URI, `color` its main colour.
|
|
132
135
|
- `getBorderImageStyle(border, size)` — inline style that draws a border's
|
|
133
136
|
artwork around a square box of `size` px (what `<Ikon>` uses).
|
|
137
|
+
- `createEmptyIkon()` — an ikon with every zone empty and no border.
|
|
138
|
+
|
|
139
|
+
### Image export
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
import { renderIkonemeToPng, renderIkonemeToCanvas, drawIkon } from 'ikoneme-lib'
|
|
143
|
+
|
|
144
|
+
const blob = await renderIkonemeToPng(ikons, { size: 120, perRow: 8, title: 'hello' })
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Draws ikons on a canvas with the same layout, tints and border artwork as
|
|
148
|
+
`<Ikon>`. Options: `size`, `gap`, `padding`, `perRow`, `background`, `title`,
|
|
149
|
+
`titleColor`, `titleFont`, `pixelRatio`. Remote icons are loaded with CORS, so
|
|
150
|
+
an image host without `Access-Control-Allow-Origin` is skipped (the browser
|
|
151
|
+
won't let it into an exportable canvas).
|
|
134
152
|
|
|
135
153
|
### IkonDB helpers
|
|
136
154
|
|
|
@@ -138,11 +156,25 @@ The public [IkonDB](https://ikondb.iigap.com/api/docs) client backing the
|
|
|
138
156
|
default root search, exported for reuse:
|
|
139
157
|
|
|
140
158
|
```js
|
|
141
|
-
import { searchIkons, getIkonDetails, getIkonList, IKONDB_BASE_URL } from 'ikoneme-lib'
|
|
159
|
+
import { searchIkons, searchIkonsV2, getIkonDetails, getIkonList, IKONDB_BASE_URL } from 'ikoneme-lib'
|
|
142
160
|
```
|
|
143
161
|
|
|
144
162
|
- `searchIkons(query, { limit })` — `{ id, name, url }[]`, matched by name
|
|
145
|
-
against the full list (fetched once, cached for an hour).
|
|
163
|
+
against the full list (fetched once, cached for an hour). Public, but it only
|
|
164
|
+
knows each icon's base name (mostly Esperanto), so "perro" or "dog" find
|
|
165
|
+
nothing.
|
|
166
|
+
- `searchIkonsV2(query, { token, lang, limit })` — same result shape, from
|
|
167
|
+
`/api/v2/icons/search`: also matches translated titles and tags in 16
|
|
168
|
+
languages, with exact matches first. Needs a logged-in user's access token
|
|
169
|
+
(`POST /api/v2/auth/login`); on failure it throws an `Error` whose `status`
|
|
170
|
+
is the HTTP status, so a host can renew the token on `401` and retry. `lang`
|
|
171
|
+
(e.g. `"it"`) limits matches to that language and picks the name shown.
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
const searchRoot = (query, opts) => searchIkonsV2(query, { token, ...opts })
|
|
175
|
+
<IkonEditor ikon={ikon} searchRoot={searchRoot} onSave={save} onClose={close} />
|
|
176
|
+
const ikons = await generateIkonemeFromText(text, { search: searchRoot })
|
|
177
|
+
```
|
|
146
178
|
- `getIkonDetails(id)` — `{ id, name, url, origin, preview, thumb, svg }` for one
|
|
147
179
|
icon (cached per id), or `null` if it does not exist.
|
|
148
180
|
- `getIkonList()` — the whole cached list.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function drawIkon(ctx: any, ikon: any, x: any, y: any, size: any): Promise<void>;
|
|
2
|
+
export function renderIkonemeToCanvas(ikons: any, { size, gap, padding, perRow, background, title, titleColor, titleFont, pixelRatio }?: {
|
|
3
|
+
size?: number;
|
|
4
|
+
gap?: number;
|
|
5
|
+
padding?: number;
|
|
6
|
+
perRow?: number;
|
|
7
|
+
background?: string;
|
|
8
|
+
title?: any;
|
|
9
|
+
titleColor?: string;
|
|
10
|
+
titleFont?: string;
|
|
11
|
+
pixelRatio?: number;
|
|
12
|
+
}): Promise<HTMLCanvasElement>;
|
|
13
|
+
export function renderIkonemeToPng(ikons: any, options: any): Promise<any>;
|
package/dist/ikonDb.d.ts
CHANGED
|
@@ -5,6 +5,14 @@ export function searchIkons(query: any, { baseUrl, limit }?: {
|
|
|
5
5
|
baseUrl?: string;
|
|
6
6
|
limit?: number;
|
|
7
7
|
}): Promise<any[]>;
|
|
8
|
+
export function searchIkonsV2(query: any, { token, lang, baseUrl, limit }?: {
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
id: any;
|
|
13
|
+
name: any;
|
|
14
|
+
url: any;
|
|
15
|
+
}[]>;
|
|
8
16
|
export function getIkonDetails(id: any, { baseUrl }?: {
|
|
9
17
|
baseUrl?: string;
|
|
10
18
|
}): Promise<any>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export function getIkonPaddings(size: any): {
|
|
2
|
+
framePad: number;
|
|
3
|
+
zonePad: number;
|
|
4
|
+
rootPad: number;
|
|
5
|
+
};
|
|
6
|
+
export function trackOffsets(length: any, weights: any): number[];
|
|
7
|
+
export const EDGE_FR: 1.18;
|
|
8
|
+
export const MID_FR: 0.95;
|
|
9
|
+
export const TRACK_WEIGHTS: number[];
|
|
10
|
+
export const REF_WEIGHTS: number[];
|
|
11
|
+
export namespace ZONE_BACKGROUNDS {
|
|
12
|
+
let context: string;
|
|
13
|
+
let reference: string;
|
|
14
|
+
let role: string;
|
|
15
|
+
let modes: string;
|
|
16
|
+
let root: string;
|
|
17
|
+
let east: string;
|
|
18
|
+
let tenses: string;
|
|
19
|
+
}
|
|
20
|
+
export const ZONE_DIVIDER: "rgba(0, 0, 0, 0.14)";
|
|
21
|
+
export namespace ZONE_GRID {
|
|
22
|
+
export namespace context_1 {
|
|
23
|
+
let cols: number[];
|
|
24
|
+
let rows: number[];
|
|
25
|
+
}
|
|
26
|
+
export { context_1 as context };
|
|
27
|
+
export namespace reference_1 {
|
|
28
|
+
let cols_1: number[];
|
|
29
|
+
export { cols_1 as cols };
|
|
30
|
+
let rows_1: number[];
|
|
31
|
+
export { rows_1 as rows };
|
|
32
|
+
}
|
|
33
|
+
export { reference_1 as reference };
|
|
34
|
+
export namespace role_1 {
|
|
35
|
+
let cols_2: number[];
|
|
36
|
+
export { cols_2 as cols };
|
|
37
|
+
let rows_2: number[];
|
|
38
|
+
export { rows_2 as rows };
|
|
39
|
+
}
|
|
40
|
+
export { role_1 as role };
|
|
41
|
+
export namespace modes_1 {
|
|
42
|
+
let cols_3: number[];
|
|
43
|
+
export { cols_3 as cols };
|
|
44
|
+
let rows_3: number[];
|
|
45
|
+
export { rows_3 as rows };
|
|
46
|
+
}
|
|
47
|
+
export { modes_1 as modes };
|
|
48
|
+
export namespace root_1 {
|
|
49
|
+
let cols_4: number[];
|
|
50
|
+
export { cols_4 as cols };
|
|
51
|
+
let rows_4: number[];
|
|
52
|
+
export { rows_4 as rows };
|
|
53
|
+
}
|
|
54
|
+
export { root_1 as root };
|
|
55
|
+
export namespace east_1 {
|
|
56
|
+
let cols_5: number[];
|
|
57
|
+
export { cols_5 as cols };
|
|
58
|
+
let rows_5: number[];
|
|
59
|
+
export { rows_5 as rows };
|
|
60
|
+
}
|
|
61
|
+
export { east_1 as east };
|
|
62
|
+
export namespace tenses_1 {
|
|
63
|
+
let cols_6: number[];
|
|
64
|
+
export { cols_6 as cols };
|
|
65
|
+
let rows_6: number[];
|
|
66
|
+
export { rows_6 as rows };
|
|
67
|
+
}
|
|
68
|
+
export { tenses_1 as tenses };
|
|
69
|
+
}
|
package/dist/ikonSchema.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { searchIkons } from './ikonDb';
|
|
1
2
|
export function getBorderConfig(borderId: any): {
|
|
2
3
|
id: string;
|
|
3
4
|
label: string;
|
|
@@ -5,6 +6,10 @@ export function getBorderConfig(borderId: any): {
|
|
|
5
6
|
plural: boolean;
|
|
6
7
|
image: any;
|
|
7
8
|
};
|
|
9
|
+
export function getBorderMetrics(size: any): {
|
|
10
|
+
frame: number;
|
|
11
|
+
corner: number;
|
|
12
|
+
};
|
|
8
13
|
export function getBorderImageStyle(border: any, size: any): {
|
|
9
14
|
borderStyle?: undefined;
|
|
10
15
|
borderColor?: undefined;
|
|
@@ -58,9 +63,24 @@ export function createDefaultIkon(): {
|
|
|
58
63
|
};
|
|
59
64
|
border: any;
|
|
60
65
|
};
|
|
66
|
+
export function createEmptyIkon(): {
|
|
67
|
+
context: any;
|
|
68
|
+
reference: {
|
|
69
|
+
left: any;
|
|
70
|
+
right: any;
|
|
71
|
+
};
|
|
72
|
+
role: any;
|
|
73
|
+
modes: any;
|
|
74
|
+
root: any;
|
|
75
|
+
rootName: any;
|
|
76
|
+
tenses: any;
|
|
77
|
+
border: any;
|
|
78
|
+
};
|
|
61
79
|
export function normalizeIkon(icon: any): any;
|
|
62
80
|
export function normalizeIkoneme(ikons: any): any;
|
|
63
|
-
export function generateIkonemeFromText(text: any
|
|
81
|
+
export function generateIkonemeFromText(text: any, { search }?: {
|
|
82
|
+
search?: typeof searchIkons;
|
|
83
|
+
}): Promise<any[]>;
|
|
64
84
|
export namespace ZONE_CONFIG {
|
|
65
85
|
let context: {
|
|
66
86
|
tooltip: string;
|