@axiom-core/dom-injector 0.1.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.
@@ -0,0 +1 @@
1
+ export declare function setThemeAttributes(attributes: Record<string, string>): void;
@@ -0,0 +1,32 @@
1
+ const TRACK_KEY = 'axiomInjectorKeys';
2
+ export function setThemeAttributes(attributes) {
3
+ if (typeof document === 'undefined')
4
+ return;
5
+ const root = document.documentElement;
6
+ // retrieve previously set keys from dataset
7
+ let prevKeys = [];
8
+ try {
9
+ const raw = root.dataset[TRACK_KEY];
10
+ if (raw)
11
+ prevKeys = JSON.parse(raw);
12
+ }
13
+ catch {
14
+ prevKeys = [];
15
+ }
16
+ // remove previous data-* keys that we set
17
+ for (const key of prevKeys) {
18
+ root.removeAttribute('data-' + key);
19
+ delete root.dataset[key];
20
+ }
21
+ // apply new attributes deterministically (sorted keys)
22
+ const keys = Object.keys(attributes).sort();
23
+ for (const key of keys) {
24
+ const value = attributes[key];
25
+ root.setAttribute('data-' + key, value);
26
+ // reflect in dataset for convenience
27
+ root.dataset[key] = value;
28
+ }
29
+ // store the list of keys we manage
30
+ root.dataset[TRACK_KEY] = JSON.stringify(keys);
31
+ }
32
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC,MAAM,UAAU,kBAAkB,CAAC,UAAkC;IACnE,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO;IAE5C,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC;IAEtC,4CAA4C;IAC5C,IAAI,QAAQ,GAAa,EAAE,CAAC;IAC5B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,GAAG;YAAE,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAa,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,QAAQ,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,0CAA0C;IAC1C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,IAAI,CAAC,eAAe,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,uDAAuD;IACvD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,YAAY,CAAC,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;QACxC,qCAAqC;QACpC,IAAI,CAAC,OAAkC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACxD,CAAC;IAED,mCAAmC;IACnC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { type InjectOptions } from './types.js';
2
+ export { injectCss, removeInjectedCss } from './inject.js';
3
+ export { setThemeAttributes } from './attributes.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { injectCss, removeInjectedCss } from './inject.js';
2
+ export { setThemeAttributes } from './attributes.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { InjectOptions } from './types.js';
2
+ export declare function injectCss(cssText: string, options?: InjectOptions): void;
3
+ export declare function removeInjectedCss(id?: string): void;
package/dist/inject.js ADDED
@@ -0,0 +1,43 @@
1
+ const DEFAULT_ID = 'axiom-theme';
2
+ function getHead() {
3
+ return typeof document === 'undefined' ? null : (document.head ?? document.getElementsByTagName('head')[0] ?? null);
4
+ }
5
+ export function injectCss(cssText, options) {
6
+ if (typeof document === 'undefined')
7
+ return;
8
+ const id = options?.id ?? DEFAULT_ID;
9
+ const head = getHead();
10
+ if (!head)
11
+ return;
12
+ const existing = document.getElementById(id);
13
+ if (existing) {
14
+ // idempotent: update content only
15
+ if (existing.textContent !== cssText)
16
+ existing.textContent = cssText;
17
+ return;
18
+ }
19
+ const style = document.createElement('style');
20
+ style.type = 'text/css';
21
+ style.id = id;
22
+ style.textContent = cssText;
23
+ if (options?.prepend) {
24
+ if (head.firstChild)
25
+ head.insertBefore(style, head.firstChild);
26
+ else
27
+ head.appendChild(style);
28
+ }
29
+ else {
30
+ head.appendChild(style);
31
+ }
32
+ }
33
+ export function removeInjectedCss(id) {
34
+ if (typeof document === 'undefined')
35
+ return;
36
+ const sel = id ?? DEFAULT_ID;
37
+ const el = document.getElementById(sel);
38
+ if (!el)
39
+ return;
40
+ if (el.parentNode)
41
+ el.parentNode.removeChild(el);
42
+ }
43
+ //# sourceMappingURL=inject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,SAAS,OAAO;IACd,OAAO,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;AACtH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAe,EAA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,CAAC;AACnD,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface InjectOptions {
2
+ id?: string;
3
+ prepend?: boolean;
4
+ }
5
+ export interface InjectedStyle extends HTMLStyleElement {
6
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@axiom-core/dom-injector",
3
+ "version": "0.1.0",
4
+ "description": "Axiom Core — idempotent DOM style injection",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "sideEffects": false,
13
+ "exports": {
14
+ "./package.json": "./package.json",
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/Haneefe/Axiom-Core.git"
24
+ },
25
+ "homepage": "https://github.com/Haneefe/Axiom-Core",
26
+ "bugs": {
27
+ "url": "https://github.com/Haneefe/Axiom-Core/issues"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
32
+ }