@stephansama/astro-iconify-svgmap
Version:
Astro integration for generating iconify svgmaps for ssg sites
87 lines (85 loc) • 3.35 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __esm = (fn, res) => function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/const.ts
var const_exports = {};
__export(const_exports, {
CONFIG_FILENAME: () => CONFIG_FILENAME,
LOADED_ICONS_FILENAME: () => LOADED_ICONS_FILENAME,
defaultConfig: () => defaultConfig
});
var FILE_PREFIX, CONFIG_FILENAME, LOADED_ICONS_FILENAME, defaultConfig;
var init_const = __esm({
"src/const.ts"() {
"use strict";
FILE_PREFIX = "node_modules/";
CONFIG_FILENAME = FILE_PREFIX + "iconifysvgmap.config.json";
LOADED_ICONS_FILENAME = FILE_PREFIX + "iconifysvgmap.json";
defaultConfig = {
outDir: "public"
};
}
});
// src/get.ts
var get_exports = {};
__export(get_exports, {
getIcon: () => getIcon
});
module.exports = __toCommonJS(get_exports);
async function getIcon(pack, name) {
const onServer = typeof document === "undefined";
const selectedPack = pack === "noto-emoji" ? "noto" : pack;
if (!onServer) return `/${selectedPack}.svg#${name}`;
const fs = await import("fs");
const { LOADED_ICONS_FILENAME: LOADED_ICONS_FILENAME2 } = await Promise.resolve().then(() => (init_const(), const_exports));
const current = fs.readFileSync(LOADED_ICONS_FILENAME2, {
encoding: "utf-8",
flag: "as+"
});
const currentRepresentation = JSON.parse(current || "{}");
const newPack = currentRepresentation[selectedPack]?.includes(name) ? currentRepresentation[selectedPack] : [
.../* @__PURE__ */ new Set([
name,
...currentRepresentation[selectedPack] ? currentRepresentation[selectedPack] : []
])
];
const newRepresentation = {
...currentRepresentation,
[selectedPack]: newPack
};
fs.writeFileSync(LOADED_ICONS_FILENAME2, JSON.stringify(newRepresentation));
return `/${selectedPack}.svg#${name}`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getIcon
});
//# sourceMappingURL=get.cjs.map