thermalkit 0.2.0 → 0.2.1
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,16 +1,8 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import {
|
|
3
|
-
import path from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
4
3
|
|
|
5
4
|
//#region src/icons.ts
|
|
6
5
|
const require_ = createRequire(import.meta.url);
|
|
7
|
-
let phosphorAssetsDir = null;
|
|
8
|
-
try {
|
|
9
|
-
const pkgPath = require_.resolve("@phosphor-icons/core/package.json");
|
|
10
|
-
phosphorAssetsDir = path.join(path.dirname(pkgPath), "assets");
|
|
11
|
-
} catch {
|
|
12
|
-
phosphorAssetsDir = null;
|
|
13
|
-
}
|
|
14
6
|
const cache = new Map();
|
|
15
7
|
function readInner(filePath) {
|
|
16
8
|
const raw = readFileSync(filePath, "utf8");
|
|
@@ -26,12 +18,10 @@ function loadIcon(name, weight = "regular") {
|
|
|
26
18
|
const cached = cache.get(key);
|
|
27
19
|
if (cached !== void 0) return cached;
|
|
28
20
|
let content = "";
|
|
29
|
-
|
|
30
|
-
const file =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} catch {}
|
|
34
|
-
}
|
|
21
|
+
try {
|
|
22
|
+
const file = require_.resolve(`@phosphor-icons/core/assets/${weight}/${name}.svg`);
|
|
23
|
+
content = readInner(file);
|
|
24
|
+
} catch {}
|
|
35
25
|
cache.set(key, content);
|
|
36
26
|
return content;
|
|
37
27
|
}
|
|
@@ -46,4 +36,4 @@ function loadIcons(names, weight = "regular") {
|
|
|
46
36
|
|
|
47
37
|
//#endregion
|
|
48
38
|
export { loadIcon, loadIcons };
|
|
49
|
-
//# sourceMappingURL=icons-
|
|
39
|
+
//# sourceMappingURL=icons-DLPLwYIQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons-DLPLwYIQ.js","names":["filePath: string","name: string","weight: PhosphorWeight","names: string[]","out: Record<string, string>"],"sources":["../../src/icons.ts"],"sourcesContent":["/**\n * Thin loader for Phosphor icons (`@phosphor-icons/core`).\n *\n * The package ships per-icon `.svg` files at:\n * assets/<weight>/<name>.svg\n *\n * We read each file once, extract the inner SVG content (everything between\n * `<svg …>` and `</svg>`), and cache it so subsequent loads are free.\n *\n * The Page builder embeds this content via:\n * <g transform=\"translate(x, y) scale(s)\" fill=\"#000\">{content}</g>\n *\n * Resolution note: phosphor's package.json restricts `exports` so that\n * `require.resolve('@phosphor-icons/core/package.json')` fails on modern\n * Node. The only thing the package exports besides `.` is the assets\n * themselves, so we resolve each SVG by its public subpath\n * (`./assets/<weight>/<name>.svg`) and let Node's resolver locate the\n * package wherever it lives in the dependency tree.\n */\nimport { readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\n\nconst require_ = createRequire(import.meta.url);\n\nexport type PhosphorWeight =\n | 'thin' | 'light' | 'regular' | 'bold' | 'fill' | 'duotone';\n\nconst cache = new Map<string, string>();\n\nfunction readInner(filePath: string): string {\n const raw = readFileSync(filePath, 'utf8');\n const m = raw.match(/<svg[^>]*>([\\s\\S]*?)<\\/svg>/);\n return m ? m[1].trim() : '';\n}\n\n/**\n * Load a single Phosphor icon's inner SVG.\n * Returns `''` if the icon (or Phosphor itself) is unavailable.\n */\nexport function loadIcon(name: string, weight: PhosphorWeight = 'regular'): string {\n const key = `${weight}/${name}`;\n const cached = cache.get(key);\n if (cached !== undefined) return cached;\n let content = '';\n try {\n // Resolve via the public exports map. Throws if Phosphor isn't\n // installed or the requested icon doesn't exist.\n const file = require_.resolve(`@phosphor-icons/core/assets/${weight}/${name}.svg`);\n content = readInner(file);\n } catch {\n // swallow — caller sees an empty string (page just skips the icon)\n }\n cache.set(key, content);\n return content;\n}\n\n/**\n * Load multiple icons into a `name → content` map suitable for `new Page({ icons })`.\n */\nexport function loadIcons(\n names: string[],\n weight: PhosphorWeight = 'regular',\n): Record<string, string> {\n const out: Record<string, string> = {};\n for (const n of names) out[n] = loadIcon(n, weight);\n return out;\n}\n"],"mappings":";;;;AAsBA,MAAM,WAAW,cAAc,OAAO,KAAK,IAAI;AAK/C,MAAM,QAAQ,IAAI;AAElB,SAAS,UAAUA,UAA0B;CAC3C,MAAM,MAAM,aAAa,UAAU,OAAO;CAC1C,MAAM,IAAI,IAAI,MAAM,8BAA8B;AAClD,QAAO,IAAI,EAAE,GAAG,MAAM,GAAG;AAC1B;;;;;AAMD,SAAgB,SAASC,MAAcC,SAAyB,WAAmB;CACjF,MAAM,OAAO,EAAE,OAAO,GAAG,KAAK;CAC9B,MAAM,SAAS,MAAM,IAAI,IAAI;AAC7B,KAAI,kBAAsB,QAAO;CACjC,IAAI,UAAU;AACd,KAAI;EAGF,MAAM,OAAO,SAAS,SAAS,8BAA8B,OAAO,GAAG,KAAK,MAAM;AAClF,YAAU,UAAU,KAAK;CAC1B,QAAO,CAEP;AACD,OAAM,IAAI,KAAK,QAAQ;AACvB,QAAO;AACR;;;;AAKD,SAAgB,UACdC,OACAD,SAAyB,WACD;CACxB,MAAME,MAA8B,CAAE;AACtC,MAAK,MAAM,KAAK,MAAO,KAAI,KAAK,SAAS,GAAG,OAAO;AACnD,QAAO;AACR"}
|
package/dist/icons.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../src/icons.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../src/icons.ts"],"names":[],"mappings":"AAwBA,MAAM,MAAM,cAAc,GACtB,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAU/D;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,cAA0B,GAAG,MAAM,CAejF;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,GAAE,cAA0B,GACjC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIxB"}
|
package/dist/icons.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"icons-C1OFHE6u.js","names":["phosphorAssetsDir: string | null","filePath: string","name: string","weight: PhosphorWeight","names: string[]","out: Record<string, string>"],"sources":["../../src/icons.ts"],"sourcesContent":["/**\n * Thin loader for Phosphor icons (`@phosphor-icons/core`).\n *\n * The package ships per-icon `.svg` files at:\n * assets/<weight>/<name>.svg\n *\n * We read each file once, extract the inner SVG content (everything between\n * `<svg …>` and `</svg>`), and cache it so subsequent loads are free.\n *\n * The Page builder embeds this content via:\n * <g transform=\"translate(x, y) scale(s)\" fill=\"#000\">{content}</g>\n */\nimport { readFileSync, existsSync } from 'node:fs';\nimport path from 'node:path';\nimport { createRequire } from 'node:module';\n\nconst require_ = createRequire(import.meta.url);\n\nexport type PhosphorWeight =\n | 'thin' | 'light' | 'regular' | 'bold' | 'fill' | 'duotone';\n\n// Resolve the package once. Fall back gracefully if Phosphor isn't installed.\nlet phosphorAssetsDir: string | null = null;\ntry {\n const pkgPath = require_.resolve('@phosphor-icons/core/package.json');\n phosphorAssetsDir = path.join(path.dirname(pkgPath), 'assets');\n} catch {\n phosphorAssetsDir = null;\n}\n\nconst cache = new Map<string, string>();\n\nfunction readInner(filePath: string): string {\n const raw = readFileSync(filePath, 'utf8');\n const m = raw.match(/<svg[^>]*>([\\s\\S]*?)<\\/svg>/);\n return m ? m[1].trim() : '';\n}\n\n/**\n * Load a single Phosphor icon's inner SVG.\n * Returns `''` if the icon (or Phosphor itself) is unavailable.\n */\nexport function loadIcon(name: string, weight: PhosphorWeight = 'regular'): string {\n const key = `${weight}/${name}`;\n const cached = cache.get(key);\n if (cached !== undefined) return cached;\n let content = '';\n if (phosphorAssetsDir) {\n const file = path.join(phosphorAssetsDir, weight, `${name}.svg`);\n if (existsSync(file)) {\n try { content = readInner(file); } catch { /* swallow */ }\n }\n }\n cache.set(key, content);\n return content;\n}\n\n/**\n * Load multiple icons into a `name → content` map suitable for `new Page({ icons })`.\n */\nexport function loadIcons(\n names: string[],\n weight: PhosphorWeight = 'regular',\n): Record<string, string> {\n const out: Record<string, string> = {};\n for (const n of names) out[n] = loadIcon(n, weight);\n return out;\n}\n"],"mappings":";;;;;AAgBA,MAAM,WAAW,cAAc,OAAO,KAAK,IAAI;AAM/C,IAAIA,oBAAmC;AACvC,IAAI;CACF,MAAM,UAAU,SAAS,QAAQ,oCAAoC;AACrE,qBAAoB,KAAK,KAAK,KAAK,QAAQ,QAAQ,EAAE,SAAS;AAC/D,QAAO;AACN,qBAAoB;AACrB;AAED,MAAM,QAAQ,IAAI;AAElB,SAAS,UAAUC,UAA0B;CAC3C,MAAM,MAAM,aAAa,UAAU,OAAO;CAC1C,MAAM,IAAI,IAAI,MAAM,8BAA8B;AAClD,QAAO,IAAI,EAAE,GAAG,MAAM,GAAG;AAC1B;;;;;AAMD,SAAgB,SAASC,MAAcC,SAAyB,WAAmB;CACjF,MAAM,OAAO,EAAE,OAAO,GAAG,KAAK;CAC9B,MAAM,SAAS,MAAM,IAAI,IAAI;AAC7B,KAAI,kBAAsB,QAAO;CACjC,IAAI,UAAU;AACd,KAAI,mBAAmB;EACrB,MAAM,OAAO,KAAK,KAAK,mBAAmB,SAAS,EAAE,KAAK,MAAM;AAChE,MAAI,WAAW,KAAK,CAClB,KAAI;AAAE,aAAU,UAAU,KAAK;EAAG,QAAO,CAAiB;CAE7D;AACD,OAAM,IAAI,KAAK,QAAQ;AACvB,QAAO;AACR;;;;AAKD,SAAgB,UACdC,OACAD,SAAyB,WACD;CACxB,MAAME,MAA8B,CAAE;AACtC,MAAK,MAAM,KAAK,MAAO,KAAI,KAAK,SAAS,GAAG,OAAO;AACnD,QAAO;AACR"}
|