This commit is contained in:
2026-07-27 00:56:18 +03:30
commit 1c75afe0fd
244 changed files with 27710 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
{
"name": "@ohmycv/dynamic-css",
"version": "0.1.1",
"description": "Dynamically injects global CSS.",
"homepage": "https://github.com/Renovamen/oh-my-cv/tree/main/packages/dynamic-css",
"bugs": {
"url": "https://github.com/Renovamen/oh-my-cv"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Renovamen/oh-my-cv.git",
"directory": "packages/dynamic-css"
},
"license": "MIT",
"author": "Renovamen <renovamenzxh@gmail.com>",
"files": [
"dist"
],
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"build-fast:pkg": "tsup src/index.ts --format cjs,esm",
"build:pkg": "pnpm run build-fast:pkg --dts"
},
"publishConfig": {
"access": "public"
}
}
+43
View File
@@ -0,0 +1,43 @@
const sheetsMap = new Map<string, HTMLStyleElement>();
/**
* Dynamically injects CSS into the document. Borrowed from Vite:
* https://github.com/vitejs/vite/blob/main/packages/vite/src/client/client.ts
*
* This used to be implemented using constructable stylesheets, but that was abandoned
* due to low performance, see https://github.com/vitejs/vite/pull/11818.
*
* @param id To make sure the CSS won't override each other.
* @param content A string of CSS to inject.
*/
export const injectCss = (id: string, content: string) => {
let style = sheetsMap.get(id);
if (!style) {
style = document.createElement("style");
style.setAttribute("type", "text/css");
style.setAttribute("data-dynamic-css-id", id);
style.textContent = content;
document.head.appendChild(style);
} else {
style.textContent = content;
}
sheetsMap.set(id, style);
};
/**
* Remove the CSS from the document.
*
* @param id The ID of the CSS to remove.
*/
export const removeCss = (id: string) => {
const style = sheetsMap.get(id);
if (style) {
document.head.removeChild(style);
sheetsMap.delete(id);
}
};
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src"]
}