id-dom 0.0.4 → 0.0.6

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,152 @@
1
+ /**
2
+ * Typed lookup by ID.
3
+ *
4
+ * @template {Element} T
5
+ * @param {string} id
6
+ * @param {{ new (...args: any[]): T }} Type
7
+ * @param {DomConfig} [config]
8
+ * @returns {T | null}
9
+ */
10
+ export function byId<T extends Element>(id: string, Type: {
11
+ new (...args: any[]): T;
12
+ }, config?: DomConfig): T | null;
13
+ export namespace byId {
14
+ /**
15
+ * Optional typed lookup: always returns T | null.
16
+ *
17
+ * @template {Element} T
18
+ * @param {string} id
19
+ * @param {{ new (...args: any[]): T }} Type
20
+ * @param {DomConfig} [config]
21
+ * @returns {T | null}
22
+ */
23
+ export function optional<T extends Element>(id: string, Type: {
24
+ new (...args: any[]): T;
25
+ }, config?: DomConfig): T | null;
26
+ import opt = optional;
27
+ export { opt };
28
+ }
29
+ /**
30
+ * Tag-name lookup by element tag.
31
+ * Useful when constructor checks are not the right fit.
32
+ *
33
+ * @param {string} id
34
+ * @param {string} tagName
35
+ * @param {DomConfig} [config]
36
+ * @returns {Element | null}
37
+ */
38
+ export function tag(id: string, tagName: string, config?: DomConfig): Element | null;
39
+ export namespace tag {
40
+ /**
41
+ * Optional tag lookup: always returns Element | null.
42
+ *
43
+ * @param {string} id
44
+ * @param {string} tagName
45
+ * @param {DomConfig} [config]
46
+ * @returns {Element | null}
47
+ */
48
+ export function optional(id: string, tagName: string, config?: DomConfig): Element | null;
49
+ import opt_1 = optional;
50
+ export { opt_1 as opt };
51
+ }
52
+ /**
53
+ * Factory: scope getters to a specific root + default policy.
54
+ *
55
+ * @param {any} root
56
+ * @param {Omit<DomConfig, 'root'>} [config]
57
+ * @returns {DomApi}
58
+ */
59
+ export function createDom(root: any, config?: Omit<DomConfig, "root">): DomApi;
60
+ /** @type {TypedHelper<HTMLElement>} */
61
+ export const el: TypedHelper<HTMLElement>;
62
+ /** @type {TypedHelper<HTMLInputElement>} */
63
+ export const input: TypedHelper<HTMLInputElement>;
64
+ /** @type {TypedHelper<HTMLButtonElement>} */
65
+ export const button: TypedHelper<HTMLButtonElement>;
66
+ /** @type {TypedHelper<HTMLTextAreaElement>} */
67
+ export const textarea: TypedHelper<HTMLTextAreaElement>;
68
+ /** @type {TypedHelper<HTMLSelectElement>} */
69
+ export const select: TypedHelper<HTMLSelectElement>;
70
+ /** @type {TypedHelper<HTMLFormElement>} */
71
+ export const form: TypedHelper<HTMLFormElement>;
72
+ /** @type {TypedHelper<HTMLDivElement>} */
73
+ export const div: TypedHelper<HTMLDivElement>;
74
+ /** @type {TypedHelper<HTMLSpanElement>} */
75
+ export const span: TypedHelper<HTMLSpanElement>;
76
+ /** @type {TypedHelper<HTMLLabelElement>} */
77
+ export const label: TypedHelper<HTMLLabelElement>;
78
+ /** @type {TypedHelper<HTMLCanvasElement>} */
79
+ export const canvas: TypedHelper<HTMLCanvasElement>;
80
+ /** @type {TypedHelper<HTMLTemplateElement>} */
81
+ export const template: TypedHelper<HTMLTemplateElement>;
82
+ /** @type {TypedHelper<SVGSVGElement>} */
83
+ export const svg: TypedHelper<SVGSVGElement>;
84
+ /** @type {TypedHelper<HTMLBodyElement>} */
85
+ export const body: TypedHelper<HTMLBodyElement>;
86
+ /** @type {TypedHelper<HTMLElement>} */
87
+ export const main: TypedHelper<HTMLElement>;
88
+ /** @type {TypedHelper<HTMLElement>} */
89
+ export const section: TypedHelper<HTMLElement>;
90
+ /** @type {TypedHelper<HTMLElement>} */
91
+ export const small: TypedHelper<HTMLElement>;
92
+ export default dom;
93
+ export type DomMode = "throw" | "null";
94
+ export type DomConfig = {
95
+ mode?: DomMode;
96
+ warn?: boolean;
97
+ onError?: (error: Error, ctx: any) => void;
98
+ root?: any;
99
+ };
100
+ /**
101
+ * The callable shape exposed by every typed helper (`input`, `button`, …)
102
+ * and tag helper (`main`, `section`, …). The base call follows the helper's
103
+ * default `mode` (typically `'throw'`); `.optional`/`.opt` always return `T | null`.
104
+ */
105
+ export type TypedHelper<T> = ((id: string) => T) & {
106
+ optional: (id: string) => T | null;
107
+ opt: (id: string) => T | null;
108
+ };
109
+ /**
110
+ * Aggregate API returned by {@link createDom}. Mirrors the named exports
111
+ * but is scoped to the configured root.
112
+ *
113
+ * SSR behavior (0.0.6+): typed-element helpers are *always callable*.
114
+ * In a non-DOM environment where the corresponding global constructor
115
+ * is undefined (Node without jsdom, edge runtimes), the base call
116
+ * throws a clear "DOM required" error and `.optional` / `.opt` return
117
+ * `null`. This matches the throw / null semantics consumers already
118
+ * expect from the browser path.
119
+ */
120
+ export type DomApi = {
121
+ byId: (<T extends Element>(id: string, Type: {
122
+ new (...args: any[]): T;
123
+ }) => T) & {
124
+ optional: <T extends Element>(id: string, Type: {
125
+ new (...args: any[]): T;
126
+ }) => T | null;
127
+ opt: <T extends Element>(id: string, Type: {
128
+ new (...args: any[]): T;
129
+ }) => T | null;
130
+ };
131
+ tag: ((id: string, tagName: string) => Element) & {
132
+ optional: (id: string, tagName: string) => Element | null;
133
+ opt: (id: string, tagName: string) => Element | null;
134
+ };
135
+ el: TypedHelper<HTMLElement>;
136
+ input: TypedHelper<HTMLInputElement>;
137
+ button: TypedHelper<HTMLButtonElement>;
138
+ textarea: TypedHelper<HTMLTextAreaElement>;
139
+ select: TypedHelper<HTMLSelectElement>;
140
+ form: TypedHelper<HTMLFormElement>;
141
+ div: TypedHelper<HTMLDivElement>;
142
+ span: TypedHelper<HTMLSpanElement>;
143
+ label: TypedHelper<HTMLLabelElement>;
144
+ canvas: TypedHelper<HTMLCanvasElement>;
145
+ template: TypedHelper<HTMLTemplateElement>;
146
+ svg: TypedHelper<SVGSVGElement>;
147
+ body: TypedHelper<HTMLBodyElement>;
148
+ main: TypedHelper<HTMLElement>;
149
+ section: TypedHelper<HTMLElement>;
150
+ small: TypedHelper<HTMLElement>;
151
+ };
152
+ declare const dom: DomApi;
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "id-dom",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Deterministic DOM element getters by ID (typed, tiny, modern).",
5
- "author": "DR.WATT",
5
+ "author": "WATT3D <WATT3D@protonmail.com>",
6
6
  "license": "SEE LICENSE IN LICENSE",
7
7
  "type": "module",
8
8
  "main": "./dist/index.cjs",
9
9
  "module": "./dist/index.js",
10
+ "types": "./dist/types/id-dom.d.ts",
10
11
  "exports": {
11
12
  ".": {
13
+ "types": "./dist/types/id-dom.d.ts",
12
14
  "import": "./dist/index.js",
13
15
  "require": "./dist/index.cjs",
14
16
  "default": "./dist/index.js"
15
17
  },
16
18
  "./min": {
19
+ "types": "./dist/types/id-dom.d.ts",
17
20
  "import": "./dist/index.min.js",
18
21
  "default": "./dist/index.min.js"
19
22
  }
@@ -22,7 +25,9 @@
22
25
  "files": [
23
26
  "dist",
24
27
  "README.md",
25
- "LICENSE"
28
+ "LICENSE",
29
+ "ADDITIONAL_TERMS.md",
30
+ "robots.txt"
26
31
  ],
27
32
  "repository": {
28
33
  "type": "git",
@@ -44,13 +49,15 @@
44
49
  ],
45
50
  "scripts": {
46
51
  "build": "node build.js",
47
- "prepublishOnly": "npm run build",
52
+ "build:types": "tsc -p tsconfig.types.json",
53
+ "prepublishOnly": "npm run build && npm run build:types",
48
54
  "test": "vitest run --environment jsdom",
49
55
  "test:watch": "vitest --environment jsdom"
50
56
  },
51
57
  "devDependencies": {
52
58
  "esbuild": "^0.27.3",
53
59
  "jsdom": "^24.0.0",
60
+ "typescript": "^5.9.3",
54
61
  "vitest": "^3.1.2"
55
62
  },
56
63
  "engines": {
package/robots.txt ADDED
@@ -0,0 +1,79 @@
1
+ # WATT3D — AI scraping policy
2
+ #
3
+ # This file enumerates known AI / LLM training and inference crawlers
4
+ # that the WATT3D AI Training Rider does not consent to. See
5
+ # ./ADDITIONAL_TERMS.md for the legal scope and definitions.
6
+ #
7
+ # Honoring robots.txt is voluntary. The rider applies whether or not
8
+ # a bot respects this file. The enumeration is non-exhaustive — bots
9
+ # not listed here are still bound by the rider if they perform
10
+ # Training Use as defined in ADDITIONAL_TERMS.md §1.
11
+
12
+ User-agent: GPTBot
13
+ Disallow: /
14
+
15
+ User-agent: ChatGPT-User
16
+ Disallow: /
17
+
18
+ User-agent: OAI-SearchBot
19
+ Disallow: /
20
+
21
+ User-agent: anthropic-ai
22
+ Disallow: /
23
+
24
+ User-agent: ClaudeBot
25
+ Disallow: /
26
+
27
+ User-agent: Claude-Web
28
+ Disallow: /
29
+
30
+ User-agent: Claude-SearchBot
31
+ Disallow: /
32
+
33
+ User-agent: Google-Extended
34
+ Disallow: /
35
+
36
+ User-agent: Applebot-Extended
37
+ Disallow: /
38
+
39
+ User-agent: Meta-ExternalAgent
40
+ Disallow: /
41
+
42
+ User-agent: Meta-ExternalFetcher
43
+ Disallow: /
44
+
45
+ User-agent: FacebookBot
46
+ Disallow: /
47
+
48
+ User-agent: CCBot
49
+ Disallow: /
50
+
51
+ User-agent: PerplexityBot
52
+ Disallow: /
53
+
54
+ User-agent: Perplexity-User
55
+ Disallow: /
56
+
57
+ User-agent: cohere-ai
58
+ Disallow: /
59
+
60
+ User-agent: Bytespider
61
+ Disallow: /
62
+
63
+ User-agent: Amazonbot
64
+ Disallow: /
65
+
66
+ User-agent: Omgilibot
67
+ Disallow: /
68
+
69
+ User-agent: AI2Bot
70
+ Disallow: /
71
+
72
+ User-agent: Diffbot
73
+ Disallow: /
74
+
75
+ # Everyone else: full access. Search engines and human-driven crawlers
76
+ # remain welcome.
77
+
78
+ User-agent: *
79
+ Allow: /