@at-flux/dom 0.0.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.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.cjs +56 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +28 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Taylor Siviter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @at-flux/dom
|
|
2
|
+
|
|
3
|
+
Type-safe DOM helpers for Astro / browser code. **Separate** from `@at-flux/astroflare` — add it as its own dependency and import from `@at-flux/dom`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @at-flux/dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { getElementById, getElementByQueryOrThrow } from '@at-flux/dom';
|
|
15
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
getElementById: () => getElementById,
|
|
24
|
+
getElementByIdOrThrow: () => getElementByIdOrThrow,
|
|
25
|
+
getElementByQuery: () => getElementByQuery,
|
|
26
|
+
getElementByQueryOrThrow: () => getElementByQueryOrThrow
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var getElementById = (id, ctor) => {
|
|
30
|
+
const element = document.getElementById(id);
|
|
31
|
+
return element instanceof ctor ? element : null;
|
|
32
|
+
};
|
|
33
|
+
var getElementByIdOrThrow = (id, ctor) => {
|
|
34
|
+
const element = getElementById(id, ctor);
|
|
35
|
+
if (!element) {
|
|
36
|
+
throw new Error(`Element with id "${id}" not found or not the expected type`);
|
|
37
|
+
}
|
|
38
|
+
return element;
|
|
39
|
+
};
|
|
40
|
+
var getElementByQuery = (selector, root = document) => {
|
|
41
|
+
return root.querySelector(selector);
|
|
42
|
+
};
|
|
43
|
+
var getElementByQueryOrThrow = (selector, root = document) => {
|
|
44
|
+
const element = getElementByQuery(selector, root);
|
|
45
|
+
if (!element) {
|
|
46
|
+
throw new Error(`Element not found with selector "${selector}"`);
|
|
47
|
+
}
|
|
48
|
+
return element;
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
getElementById,
|
|
53
|
+
getElementByIdOrThrow,
|
|
54
|
+
getElementByQuery,
|
|
55
|
+
getElementByQueryOrThrow
|
|
56
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe DOM helpers shared across Astroflare projects.
|
|
3
|
+
*/
|
|
4
|
+
declare const getElementById: <T extends HTMLElement>(id: string, ctor: {
|
|
5
|
+
new (...args: unknown[]): T;
|
|
6
|
+
} | (Function & {
|
|
7
|
+
prototype: T;
|
|
8
|
+
})) => T | null;
|
|
9
|
+
declare const getElementByIdOrThrow: <T extends HTMLElement>(id: string, ctor: {
|
|
10
|
+
new (...args: unknown[]): T;
|
|
11
|
+
} | (Function & {
|
|
12
|
+
prototype: T;
|
|
13
|
+
})) => T;
|
|
14
|
+
declare const getElementByQuery: <T extends Element>(selector: string, root?: Document | Element) => T | null;
|
|
15
|
+
declare const getElementByQueryOrThrow: <T extends Element>(selector: string, root?: Document | Element) => T;
|
|
16
|
+
|
|
17
|
+
export { getElementById, getElementByIdOrThrow, getElementByQuery, getElementByQueryOrThrow };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe DOM helpers shared across Astroflare projects.
|
|
3
|
+
*/
|
|
4
|
+
declare const getElementById: <T extends HTMLElement>(id: string, ctor: {
|
|
5
|
+
new (...args: unknown[]): T;
|
|
6
|
+
} | (Function & {
|
|
7
|
+
prototype: T;
|
|
8
|
+
})) => T | null;
|
|
9
|
+
declare const getElementByIdOrThrow: <T extends HTMLElement>(id: string, ctor: {
|
|
10
|
+
new (...args: unknown[]): T;
|
|
11
|
+
} | (Function & {
|
|
12
|
+
prototype: T;
|
|
13
|
+
})) => T;
|
|
14
|
+
declare const getElementByQuery: <T extends Element>(selector: string, root?: Document | Element) => T | null;
|
|
15
|
+
declare const getElementByQueryOrThrow: <T extends Element>(selector: string, root?: Document | Element) => T;
|
|
16
|
+
|
|
17
|
+
export { getElementById, getElementByIdOrThrow, getElementByQuery, getElementByQueryOrThrow };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var getElementById = (id, ctor) => {
|
|
3
|
+
const element = document.getElementById(id);
|
|
4
|
+
return element instanceof ctor ? element : null;
|
|
5
|
+
};
|
|
6
|
+
var getElementByIdOrThrow = (id, ctor) => {
|
|
7
|
+
const element = getElementById(id, ctor);
|
|
8
|
+
if (!element) {
|
|
9
|
+
throw new Error(`Element with id "${id}" not found or not the expected type`);
|
|
10
|
+
}
|
|
11
|
+
return element;
|
|
12
|
+
};
|
|
13
|
+
var getElementByQuery = (selector, root = document) => {
|
|
14
|
+
return root.querySelector(selector);
|
|
15
|
+
};
|
|
16
|
+
var getElementByQueryOrThrow = (selector, root = document) => {
|
|
17
|
+
const element = getElementByQuery(selector, root);
|
|
18
|
+
if (!element) {
|
|
19
|
+
throw new Error(`Element not found with selector "${selector}"`);
|
|
20
|
+
}
|
|
21
|
+
return element;
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
getElementById,
|
|
25
|
+
getElementByIdOrThrow,
|
|
26
|
+
getElementByQuery,
|
|
27
|
+
getElementByQueryOrThrow
|
|
28
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@at-flux/dom",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Type-safe DOM helpers for Astroflare projects",
|
|
6
|
+
"author": "Taylor Siviter <taylor@siviter.xyz>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"astro",
|
|
10
|
+
"dom",
|
|
11
|
+
"utilities",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"default": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"jsdom": "^25.0.1",
|
|
35
|
+
"tsup": "^8.0.0",
|
|
36
|
+
"typescript": "^5.0.0",
|
|
37
|
+
"vitest": "^3.2.4"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/at-flux/astroflare.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/at-flux/astroflare/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/at-flux/astroflare#readme",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"test:watch": "vitest",
|
|
57
|
+
"typecheck": "tsc --noEmit"
|
|
58
|
+
}
|
|
59
|
+
}
|