@dava96/osrs-icons 1.0.15 → 1.0.17

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 (47) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +170 -5
  3. package/dist/cjs/animateCursor.d.ts +72 -0
  4. package/dist/cjs/animateCursor.d.ts.map +1 -0
  5. package/dist/cjs/animateCursor.js +94 -0
  6. package/dist/cjs/applyCursors.d.ts +64 -0
  7. package/dist/cjs/applyCursors.d.ts.map +1 -0
  8. package/dist/cjs/applyCursors.js +82 -0
  9. package/dist/cjs/flip.d.ts +55 -0
  10. package/dist/cjs/flip.d.ts.map +1 -0
  11. package/dist/cjs/flip.js +117 -0
  12. package/dist/cjs/generated/icons.d.ts +1 -0
  13. package/dist/cjs/generated/icons.d.ts.map +1 -0
  14. package/dist/cjs/generated/meta.d.ts +15 -0
  15. package/dist/cjs/generated/meta.d.ts.map +1 -0
  16. package/dist/cjs/generated/meta.js +14 -0
  17. package/dist/cjs/index.d.ts +16 -0
  18. package/dist/cjs/index.d.ts.map +1 -0
  19. package/dist/cjs/index.js +20 -1
  20. package/dist/cjs/packs.d.ts +142 -0
  21. package/dist/cjs/packs.d.ts.map +1 -0
  22. package/dist/cjs/packs.js +192 -0
  23. package/dist/esm/animateCursor.d.ts +72 -0
  24. package/dist/esm/animateCursor.d.ts.map +1 -0
  25. package/dist/esm/animateCursor.js +91 -0
  26. package/dist/esm/applyCursors.d.ts +64 -0
  27. package/dist/esm/applyCursors.d.ts.map +1 -0
  28. package/dist/esm/applyCursors.js +79 -0
  29. package/dist/esm/flip.d.ts +55 -0
  30. package/dist/esm/flip.d.ts.map +1 -0
  31. package/dist/esm/flip.js +114 -0
  32. package/dist/esm/generated/icons.d.ts +1 -0
  33. package/dist/esm/generated/icons.d.ts.map +1 -0
  34. package/dist/esm/generated/meta.d.ts +15 -0
  35. package/dist/esm/generated/meta.d.ts.map +1 -0
  36. package/dist/esm/generated/meta.js +14 -0
  37. package/dist/esm/index.d.ts +16 -0
  38. package/dist/esm/index.d.ts.map +1 -0
  39. package/dist/esm/index.js +18 -1
  40. package/dist/esm/packs.d.ts +142 -0
  41. package/dist/esm/packs.d.ts.map +1 -0
  42. package/dist/esm/packs.js +189 -0
  43. package/package.json +2 -2
  44. package/dist/cjs/index_test.d.ts +0 -1
  45. package/dist/cjs/index_test.js +0 -110
  46. package/dist/esm/index_test.d.ts +0 -1
  47. package/dist/esm/index_test.js +0 -105
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Standard CSS cursor states that can be mapped to OSRS icons.
3
+ *
4
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
5
+ */
6
+ export type CursorState = 'default' | 'pointer' | 'wait' | 'text' | 'move' | 'crosshair' | 'grab' | 'grabbing' | 'not-allowed' | 'help' | 'progress' | 'cell' | 'copy' | 'alias' | 'no-drop' | 'col-resize' | 'row-resize' | 'n-resize' | 'e-resize' | 's-resize' | 'w-resize' | 'zoom-in' | 'zoom-out';
7
+ /**
8
+ * A mapping of CSS cursor states to OSRS icon cursor strings.
9
+ *
10
+ * Only include the states you want to override — unlisted states
11
+ * keep their default browser cursor.
12
+ */
13
+ export type CursorMapping = Partial<Record<CursorState, string>>;
14
+ /**
15
+ * Applies OSRS cursor icons to CSS cursor states on a target element
16
+ * or globally across the entire page.
17
+ *
18
+ * Injects a `<style>` tag with CSS rules that map each specified cursor
19
+ * state to the given OSRS icon. Returns a cleanup function that removes
20
+ * the injected styles and restores the previous cursors.
21
+ *
22
+ * **Browser-only** — in non-browser environments this is a no-op that
23
+ * returns an empty cleanup function.
24
+ *
25
+ * @param mapping - An object mapping CSS cursor states to OSRS cursor strings.
26
+ * @param target - Optional element to scope the cursors to. Defaults to the
27
+ * entire document (global).
28
+ * @returns A cleanup function that reverts all applied cursors.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { abyssalWhip, dragonScimitar, applyCursors } from '@dava96/osrs-icons';
33
+ *
34
+ * // Apply globally
35
+ * const remove = applyCursors({
36
+ * default: abyssalWhip,
37
+ * pointer: dragonScimitar,
38
+ * });
39
+ *
40
+ * // Later, revert to browser defaults
41
+ * remove();
42
+ * ```
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { bucketPack, applyCursors } from '@dava96/osrs-icons';
47
+ *
48
+ * // Scope to a specific element
49
+ * const cleanup = applyCursors(
50
+ * { wait: bucketPack.full },
51
+ * document.getElementById('loading-area')!,
52
+ * );
53
+ * ```
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { herringPack, applyCursors } from '@dava96/osrs-icons';
58
+ *
59
+ * // Use the red herring for error states!
60
+ * applyCursors({ not-allowed: herringPack.error });
61
+ * ```
62
+ */
63
+ export declare function applyCursors(mapping: CursorMapping, target?: HTMLElement): () => void;
64
+ //# sourceMappingURL=applyCursors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyCursors.d.ts","sourceRoot":"","sources":["../../src/applyCursors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,SAAS,GACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,WAAW,GACX,MAAM,GACN,UAAU,GACV,aAAa,GACb,MAAM,GACN,UAAU,GACV,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,SAAS,GACT,UAAU,CAAC;AAEf;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,IAAI,CA6BrF"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Applies OSRS cursor icons to CSS cursor states on a target element
3
+ * or globally across the entire page.
4
+ *
5
+ * Injects a `<style>` tag with CSS rules that map each specified cursor
6
+ * state to the given OSRS icon. Returns a cleanup function that removes
7
+ * the injected styles and restores the previous cursors.
8
+ *
9
+ * **Browser-only** — in non-browser environments this is a no-op that
10
+ * returns an empty cleanup function.
11
+ *
12
+ * @param mapping - An object mapping CSS cursor states to OSRS cursor strings.
13
+ * @param target - Optional element to scope the cursors to. Defaults to the
14
+ * entire document (global).
15
+ * @returns A cleanup function that reverts all applied cursors.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { abyssalWhip, dragonScimitar, applyCursors } from '@dava96/osrs-icons';
20
+ *
21
+ * // Apply globally
22
+ * const remove = applyCursors({
23
+ * default: abyssalWhip,
24
+ * pointer: dragonScimitar,
25
+ * });
26
+ *
27
+ * // Later, revert to browser defaults
28
+ * remove();
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { bucketPack, applyCursors } from '@dava96/osrs-icons';
34
+ *
35
+ * // Scope to a specific element
36
+ * const cleanup = applyCursors(
37
+ * { wait: bucketPack.full },
38
+ * document.getElementById('loading-area')!,
39
+ * );
40
+ * ```
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { herringPack, applyCursors } from '@dava96/osrs-icons';
45
+ *
46
+ * // Use the red herring for error states!
47
+ * applyCursors({ not-allowed: herringPack.error });
48
+ * ```
49
+ */
50
+ export function applyCursors(mapping, target) {
51
+ if (typeof document === 'undefined') {
52
+ return () => { };
53
+ }
54
+ const styleElement = document.createElement('style');
55
+ const selector = target ? `[data-osrs-cursor-id="${generateId()}"]` : '*';
56
+ if (target) {
57
+ target.setAttribute('data-osrs-cursor-id', selector.slice(22, -2));
58
+ }
59
+ const rules = Object.entries(mapping)
60
+ .map(([state, cursorValue]) => {
61
+ const fallback = state === 'default' ? 'auto' : state;
62
+ return `${selector} { cursor: ${cursorValue.replace(', auto', `, ${fallback}`)}; }`;
63
+ })
64
+ .join('\n');
65
+ styleElement.textContent = rules;
66
+ styleElement.setAttribute('data-osrs-cursors', 'true');
67
+ document.head.appendChild(styleElement);
68
+ return () => {
69
+ styleElement.remove();
70
+ if (target) {
71
+ target.removeAttribute('data-osrs-cursor-id');
72
+ }
73
+ };
74
+ }
75
+ /** Generates a short unique ID for scoping cursor styles to elements. */
76
+ let idCounter = 0;
77
+ function generateId() {
78
+ return `osrs-${++idCounter}-${Date.now().toString(36)}`;
79
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Horizontally flips CSS cursor icons so they point in the opposite direction.
3
+ *
4
+ * Many OSRS inventory icons face right, but cursor conventions typically
5
+ * expect left-facing images. This helper mirrors the embedded base64 PNG
6
+ * using the Canvas API and returns new, ready-to-use CSS cursor strings.
7
+ *
8
+ * Results are cached internally — flipping the same icon twice returns
9
+ * the cached value instantly.
10
+ *
11
+ * **Browser-only** — requires the Canvas API. In non-browser environments
12
+ * (Node.js, SSR) the original cursor strings are returned unchanged.
13
+ *
14
+ * Supports three input shapes:
15
+ * - **Single string** → returns a single flipped string.
16
+ * - **Array of strings** → returns an array of flipped strings (same order).
17
+ * - **Record of strings** → returns a record with the same keys, values flipped.
18
+ * Perfect for flipping an entire pack in one call.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { abyssalWhip, flipCursor } from '@dava96/osrs-icons';
23
+ *
24
+ * // Single icon
25
+ * const flipped = await flipCursor(abyssalWhip);
26
+ * document.body.style.cursor = flipped;
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { coinsPack, flipCursor } from '@dava96/osrs-icons';
32
+ *
33
+ * // Flip an entire pack
34
+ * const flippedPack = await flipCursor(coinsPack);
35
+ * // flippedPack._1, flippedPack._2, ... are all flipped
36
+ * // flippedPack.stages is a flipped array
37
+ * ```
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { airRune, fireRune, flipCursor } from '@dava96/osrs-icons';
42
+ *
43
+ * // Flip an array of cursors
44
+ * const [flippedAir, flippedFire] = await flipCursor([airRune, fireRune]);
45
+ * ```
46
+ */
47
+ /** Flip a single CSS cursor string. */
48
+ export declare function flipCursor(cursorValue: string): Promise<string>;
49
+ /** Flip an array of CSS cursor strings, preserving order. */
50
+ export declare function flipCursor(cursorValues: readonly string[]): Promise<string[]>;
51
+ /** Flip every string value in a record (e.g. a pack object), preserving keys. */
52
+ export declare function flipCursor<T extends Record<string, unknown>>(pack: T): Promise<{
53
+ [K in keyof T]: T[K] extends string ? string : T[K] extends readonly string[] ? string[] : T[K];
54
+ }>;
55
+ //# sourceMappingURL=flip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/flip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAUH,uCAAuC;AACvC,wBAAsB,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAEvE,6DAA6D;AAC7D,wBAAsB,UAAU,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAErF,iFAAiF;AACjF,wBAAsB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,IAAI,EAAE,CAAC,GACN,OAAO,CAAC;KACR,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;CAChG,CAAC,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Horizontally flips CSS cursor icons so they point in the opposite direction.
3
+ *
4
+ * Many OSRS inventory icons face right, but cursor conventions typically
5
+ * expect left-facing images. This helper mirrors the embedded base64 PNG
6
+ * using the Canvas API and returns new, ready-to-use CSS cursor strings.
7
+ *
8
+ * Results are cached internally — flipping the same icon twice returns
9
+ * the cached value instantly.
10
+ *
11
+ * **Browser-only** — requires the Canvas API. In non-browser environments
12
+ * (Node.js, SSR) the original cursor strings are returned unchanged.
13
+ *
14
+ * Supports three input shapes:
15
+ * - **Single string** → returns a single flipped string.
16
+ * - **Array of strings** → returns an array of flipped strings (same order).
17
+ * - **Record of strings** → returns a record with the same keys, values flipped.
18
+ * Perfect for flipping an entire pack in one call.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { abyssalWhip, flipCursor } from '@dava96/osrs-icons';
23
+ *
24
+ * // Single icon
25
+ * const flipped = await flipCursor(abyssalWhip);
26
+ * document.body.style.cursor = flipped;
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { coinsPack, flipCursor } from '@dava96/osrs-icons';
32
+ *
33
+ * // Flip an entire pack
34
+ * const flippedPack = await flipCursor(coinsPack);
35
+ * // flippedPack._1, flippedPack._2, ... are all flipped
36
+ * // flippedPack.stages is a flipped array
37
+ * ```
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { airRune, fireRune, flipCursor } from '@dava96/osrs-icons';
42
+ *
43
+ * // Flip an array of cursors
44
+ * const [flippedAir, flippedFire] = await flipCursor([airRune, fireRune]);
45
+ * ```
46
+ */
47
+ /** Matches `url('...')` in a CSS cursor value. Precompiled to avoid re-creation per call. */
48
+ const FLIP_URL_REGEX = /url\('(.*?)'\)/;
49
+ /** Internal cache to avoid re-processing the same icon. */
50
+ const flipCache = new Map();
51
+ // ── Implementation ─────────────────────────────────────────────────
52
+ export async function flipCursor(input) {
53
+ if (typeof input === 'string') {
54
+ return flipSingleCursor(input);
55
+ }
56
+ if (Array.isArray(input)) {
57
+ return Promise.all(input.map(flipSingleCursor));
58
+ }
59
+ const entries = Object.entries(input);
60
+ const flippedEntries = await Promise.all(entries.map(async ([key, value]) => {
61
+ if (typeof value === 'string') {
62
+ return [key, await flipSingleCursor(value)];
63
+ }
64
+ if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
65
+ return [key, await Promise.all(value.map(flipSingleCursor))];
66
+ }
67
+ return [key, value];
68
+ }));
69
+ return Object.fromEntries(flippedEntries);
70
+ }
71
+ // ── Internal helpers ───────────────────────────────────────────────
72
+ /** Flips a single CSS cursor string, using the cache. */
73
+ async function flipSingleCursor(cursorValue) {
74
+ if (flipCache.has(cursorValue)) {
75
+ return flipCache.get(cursorValue);
76
+ }
77
+ if (typeof document === 'undefined') {
78
+ return cursorValue;
79
+ }
80
+ const dataUrlMatch = cursorValue.match(FLIP_URL_REGEX);
81
+ if (!dataUrlMatch) {
82
+ return cursorValue;
83
+ }
84
+ const originalDataUrl = dataUrlMatch[1];
85
+ const flippedDataUrl = await mirrorImage(originalDataUrl);
86
+ const flippedCursor = cursorValue.replace(originalDataUrl, flippedDataUrl);
87
+ flipCache.set(cursorValue, flippedCursor);
88
+ return flippedCursor;
89
+ }
90
+ /**
91
+ * Loads a data URL into an off-screen canvas, mirrors it horizontally,
92
+ * and returns the flipped image as a new data URL.
93
+ */
94
+ function mirrorImage(dataUrl) {
95
+ return new Promise((resolve, reject) => {
96
+ const img = new Image();
97
+ img.onload = () => {
98
+ const canvas = document.createElement('canvas');
99
+ canvas.width = img.width;
100
+ canvas.height = img.height;
101
+ const ctx = canvas.getContext('2d');
102
+ if (!ctx) {
103
+ resolve(dataUrl);
104
+ return;
105
+ }
106
+ ctx.translate(canvas.width, 0);
107
+ ctx.scale(-1, 1);
108
+ ctx.drawImage(img, 0, 0);
109
+ resolve(canvas.toDataURL('image/png'));
110
+ };
111
+ img.onerror = () => reject(new Error('Failed to load cursor image for flipping'));
112
+ img.src = dataUrl;
113
+ });
114
+ }
@@ -17413,3 +17413,4 @@ export declare const zurielsStaff = "url('data:image/png;base64,iVBORw0KGgoAAAAN
17413
17413
  export declare const zurielsStaffLastManStanding = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAeCAMAAADn2eWTAAAAulBMVEVMaXFsZGRdV1dYUlJnYGBza2tOSUgAAAFIQ0NMRkZbVVV5cXCEenpqYmI8NzdWUFBjXFs5NDSJYF1dNzWkcm9UMC50Q0KFTkqKUU6JgH8/OjpwaWlFQEBQLiyHUExUTU2PVVGTZWNnPTpxQj99V1VkOjl/SkhmMi5hOTeMUlB5SEVXNDB2OjdzOTVcPz1CPT1MJCI1MDBmbmZye3JITkh2RkOU2sS75thboIx807mK1sBwxaxrvaWP2MLZgia+AAAAAXRSTlMAQObYZgAAAAlwSFlzAAALEwAACxMBAJqcGAAAAKxJREFUeNp902cCgyAMBWCU6lPr1qrde++973+t9gBJ+PsRHgRQih2AEvD15BgK9++HUWQ4394P0IEoytOFzkWaZpV2jqRi2AByNymqK8FYAeVh959C1k6Rx3tgQcfOJts1MKKPg56eb5aDLqNGNAbAoc03GJbLNx91CeFIlRJaEgYS1niEiIaEcdQSlvXckHti8Jt2wmHbt0w2FGbgCTvSdodHs++E0r3w3+kHfw4LUj07+AMAAAAASUVORK5CYII='), auto";
17414
17414
  export declare const zurielsStaffBh = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAeCAMAAADn2eWTAAAAulBMVEVMaXFsZGRdV1dYUlJnYGBza2tOSUgAAAFIQ0NMRkZbVVV5cXCEenpqYmI8NzdWUFBjXFs5NDSJYF1dNzWkcm9UMC50Q0KFTkqKUU6JgH8/OjpwaWlFQEBQLiyHUExUTU2PVVGTZWNnPTpxQj99V1VkOjl/SkhmMi5hOTeMUlB5SEVXNDB2OjdzOTVcPz1CPT1MJCI1MDBmbmZye3JITkh2RkOU2sS75thboIx807mK1sBwxaxrvaWP2MLZgia+AAAAAXRSTlMAQObYZgAAAAlwSFlzAAALEwAACxMBAJqcGAAAAKxJREFUeNp902cCgyAMBWCU6lPr1qrde++973+t9gBJ+PsRHgRQih2AEvD15BgK9++HUWQ4394P0IEoytOFzkWaZpV2jqRi2AByNymqK8FYAeVh959C1k6Rx3tgQcfOJts1MKKPg56eb5aDLqNGNAbAoc03GJbLNx91CeFIlRJaEgYS1niEiIaEcdQSlvXckHti8Jt2wmHbt0w2FGbgCTvSdodHs++E0r3w3+kHfw4LUj07+AMAAAAASUVORK5CYII='), auto";
17415
17415
  export declare const zurielsStaffBhinactive = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAeCAMAAADn2eWTAAAAsVBMVEVMaXFFQEA5NDQ3IB0oJiZjXFtMRkYAAAEyLi5UTU15SEVhOTdhWlpqYmI1MDBza2ssKipYUlJCPT1bVVU/OjpRSkpMLCpIKihmMi6VZ2V4VFE8NzdWUFBIQ0MkIiJOSUh5cXB/Skh2RkNUMC5dNzVuQD1xQj9nSEZALCqAWFZnPTo/JCRUKCY0GBh0Q0JVW1UgHR1kbGQ0OTRxx65uwahDdmdWmYWW2sZvw6tcoo5mtJ6pW+hyAAAAAXRSTlMAQObYZgAAAAlwSFlzAAALEwAACxMBAJqcGAAAAK9JREFUeNp901cCgyAMBmBU9K9oa7VaR4fde+/2/gerB0jCCw8fISGAUuwAlICPH8dQeH9ejCLH9f59gk6I4HS+0XlRVbnx7Aup2DpAmerABARjB6yOm2YJGdtHmWk0E5l2uS72wJw+DmbWoTBTh9FesgDAoc03GG6Hbz7aEqIlRUoYShhL6PMIEUMJh6OusG090NwTQzRJxhy6keuxSZHFllCRlwoV+ZatpXvhv9Mfx6IK2oVBcCAAAAAASUVORK5CYII='), auto";
17416
+ //# sourceMappingURL=icons.d.ts.map