@neptune3d/dom 0.0.3 → 0.0.5
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/README.md +56 -1
- package/dist/index.d.ts +721 -36
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
1
|
# neptune3d/dom
|
|
2
2
|
|
|
3
|
-
Helper classes and functions for the DOM.
|
|
3
|
+
Helper classes and functions for the DOM.
|
|
4
|
+
|
|
5
|
+
## 🚀 Getting Started
|
|
6
|
+
|
|
7
|
+
Install the package:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install neptune3d/dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Import and create elements:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { $, $body } from "neptune3d/dom";
|
|
17
|
+
|
|
18
|
+
const div = $("div")
|
|
19
|
+
.text("Hello world")
|
|
20
|
+
.css("", { padding: "1rem", background: "#eee" })
|
|
21
|
+
.on("click", () => console.log("Clicked!"));
|
|
22
|
+
|
|
23
|
+
const body = $body();
|
|
24
|
+
|
|
25
|
+
body.append(div.dom);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use SVG elements:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
const circle = $("circle")
|
|
32
|
+
.attr("cx", "50")
|
|
33
|
+
.attr("cy", "50")
|
|
34
|
+
.attr("r", "40")
|
|
35
|
+
.attr("fill", "red");
|
|
36
|
+
|
|
37
|
+
const svg = $("svg").attr("width", "100").attr("height", "100").add(circle);
|
|
38
|
+
|
|
39
|
+
body.append(svg.dom);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Define global styles:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { StyleSheet } from "neptune3d/dom";
|
|
46
|
+
|
|
47
|
+
StyleSheet.getSheet().globalCss(".list-item", {
|
|
48
|
+
padding: "0.5rem",
|
|
49
|
+
borderBottom: "1px solid #ccc",
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 📦 Features
|
|
54
|
+
|
|
55
|
+
- Chainable DOM manipulation
|
|
56
|
+
- Scoped and global CSS rule injection
|
|
57
|
+
- Media query support
|
|
58
|
+
- Event listener helpers
|
package/dist/index.d.ts
CHANGED
|
@@ -13,42 +13,223 @@ declare class MediaRule {
|
|
|
13
13
|
delete(index: number): void;
|
|
14
14
|
}
|
|
15
15
|
//#endregion
|
|
16
|
+
//#region src/types.d.ts
|
|
17
|
+
type CssProperties = PropertiesFallback<string | number> & {
|
|
18
|
+
[key: `--${string}`]: string | number | undefined;
|
|
19
|
+
};
|
|
20
|
+
type Autocomplete<T$1 extends string> = T$1 | (string & {});
|
|
21
|
+
type DomElementChild = DomElement<any> | Node | string | number;
|
|
22
|
+
type DomElementTagNameMap = HTMLElementTagNameMap & SvgElementTagNameMap;
|
|
23
|
+
type SvgElementTagNameMap = {
|
|
24
|
+
svgA: SVGAElement;
|
|
25
|
+
animate: SVGAnimateElement;
|
|
26
|
+
animateMotion: SVGAnimateMotionElement;
|
|
27
|
+
animateTransform: SVGAnimateTransformElement;
|
|
28
|
+
circle: SVGCircleElement;
|
|
29
|
+
clipPath: SVGClipPathElement;
|
|
30
|
+
defs: SVGDefsElement;
|
|
31
|
+
desc: SVGDescElement;
|
|
32
|
+
ellipse: SVGEllipseElement;
|
|
33
|
+
feBlend: SVGFEBlendElement;
|
|
34
|
+
feColorMatrix: SVGFEColorMatrixElement;
|
|
35
|
+
feComponentTransfer: SVGFEComponentTransferElement;
|
|
36
|
+
feComposite: SVGFECompositeElement;
|
|
37
|
+
feConvolveMatrix: SVGFEConvolveMatrixElement;
|
|
38
|
+
feDiffuseLighting: SVGFEDiffuseLightingElement;
|
|
39
|
+
feDisplacementMap: SVGFEDisplacementMapElement;
|
|
40
|
+
feDistantLight: SVGFEDistantLightElement;
|
|
41
|
+
feDropShadow: SVGFEDropShadowElement;
|
|
42
|
+
feFlood: SVGFEFloodElement;
|
|
43
|
+
feFuncA: SVGFEFuncAElement;
|
|
44
|
+
feFuncB: SVGFEFuncBElement;
|
|
45
|
+
feFuncG: SVGFEFuncGElement;
|
|
46
|
+
feFuncR: SVGFEFuncRElement;
|
|
47
|
+
feGaussianBlur: SVGFEGaussianBlurElement;
|
|
48
|
+
feImage: SVGFEImageElement;
|
|
49
|
+
feMerge: SVGFEMergeElement;
|
|
50
|
+
feMergeNode: SVGFEMergeNodeElement;
|
|
51
|
+
feMorphology: SVGFEMorphologyElement;
|
|
52
|
+
feOffset: SVGFEOffsetElement;
|
|
53
|
+
fePointLight: SVGFEPointLightElement;
|
|
54
|
+
feSpecularLighting: SVGFESpecularLightingElement;
|
|
55
|
+
feSpotLight: SVGFESpotLightElement;
|
|
56
|
+
feTile: SVGFETileElement;
|
|
57
|
+
feTurbulence: SVGFETurbulenceElement;
|
|
58
|
+
filter: SVGFilterElement;
|
|
59
|
+
foreignObject: SVGForeignObjectElement;
|
|
60
|
+
g: SVGGElement;
|
|
61
|
+
image: SVGImageElement;
|
|
62
|
+
line: SVGLineElement;
|
|
63
|
+
linearGradient: SVGLinearGradientElement;
|
|
64
|
+
marker: SVGMarkerElement;
|
|
65
|
+
mask: SVGMaskElement;
|
|
66
|
+
metadata: SVGMetadataElement;
|
|
67
|
+
mpath: SVGMPathElement;
|
|
68
|
+
path: SVGPathElement;
|
|
69
|
+
pattern: SVGPatternElement;
|
|
70
|
+
polygon: SVGPolygonElement;
|
|
71
|
+
polyline: SVGPolylineElement;
|
|
72
|
+
radialGradient: SVGRadialGradientElement;
|
|
73
|
+
rect: SVGRectElement;
|
|
74
|
+
script: SVGScriptElement;
|
|
75
|
+
set: SVGSetElement;
|
|
76
|
+
stop: SVGStopElement;
|
|
77
|
+
style: SVGStyleElement;
|
|
78
|
+
svg: SVGSVGElement;
|
|
79
|
+
switch: SVGSwitchElement;
|
|
80
|
+
symbol: SVGSymbolElement;
|
|
81
|
+
text: SVGTextElement;
|
|
82
|
+
textPath: SVGTextPathElement;
|
|
83
|
+
title: SVGTitleElement;
|
|
84
|
+
tspan: SVGTSpanElement;
|
|
85
|
+
use: SVGUseElement;
|
|
86
|
+
view: SVGViewElement;
|
|
87
|
+
};
|
|
88
|
+
type DomElementEventMap = HTMLElementEventMap & SVGElementEventMap;
|
|
89
|
+
//#endregion
|
|
16
90
|
//#region src/StyleSheet.d.ts
|
|
91
|
+
/**
|
|
92
|
+
* Manages a dedicated `<style>` element and provides programmatic access to its CSS rules.
|
|
93
|
+
* Supports dynamic insertion, retrieval, and deletion of both standard and media-specific rules,
|
|
94
|
+
* with internal indexing for fast lookup and reuse.
|
|
95
|
+
*
|
|
96
|
+
* This class ensures a single shared stylesheet instance via `StyleSheet.getSheet()`,
|
|
97
|
+
* and maintains selector-to-index and media-to-rule maps on the global `window` object.
|
|
98
|
+
*
|
|
99
|
+
* Designed for use with component-level styling systems or DOM abstractions that require
|
|
100
|
+
* granular control over rule injection without relying on inline styles.
|
|
101
|
+
*/
|
|
17
102
|
declare class StyleSheet {
|
|
18
103
|
constructor(el: HTMLStyleElement);
|
|
19
104
|
protected _dom: HTMLStyleElement;
|
|
20
105
|
get dom(): HTMLStyleElement;
|
|
21
106
|
get sheet(): CSSStyleSheet;
|
|
22
107
|
get length(): number;
|
|
108
|
+
/**
|
|
109
|
+
* Inserts or updates a global CSS rule for a given selector.
|
|
110
|
+
* @param selector - A global class selector (e.g., ".list-item").
|
|
111
|
+
* @param props - The CSS properties to apply.
|
|
112
|
+
*/
|
|
113
|
+
globalCss(selector: string, props: CssProperties): void;
|
|
114
|
+
/**
|
|
115
|
+
* Inserts or updates a global CSS rule inside a media query.
|
|
116
|
+
* @param mediaText - The media query condition (e.g., "max-width: 600px").
|
|
117
|
+
* @param selector - The global class selector.
|
|
118
|
+
* @param props - The CSS properties to apply.
|
|
119
|
+
*/
|
|
120
|
+
globalMediaCss(mediaText: string, selector: string, props: CssProperties): void;
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves or creates a CSSStyleRule for the given selector.
|
|
123
|
+
* If the rule doesn't exist, it is inserted at the end of the stylesheet and cached.
|
|
124
|
+
*
|
|
125
|
+
* This ensures stable indexing and avoids rule override issues caused by shifting positions.
|
|
126
|
+
* The returned rule can be used to modify style declarations programmatically.
|
|
127
|
+
*
|
|
128
|
+
* @param selector - The CSS selector string (e.g., ".button", "#header", "div > span").
|
|
129
|
+
* @return The corresponding CSSStyleRule instance.
|
|
130
|
+
*/
|
|
23
131
|
getCssRule(selector: string): CSSStyleRule;
|
|
24
132
|
deleteCssRule(selector: string): void;
|
|
133
|
+
/**
|
|
134
|
+
* Retrieves or creates a CSSMediaRule for the given media query.
|
|
135
|
+
* If the rule doesn't exist, it is inserted at the end of the stylesheet and cached.
|
|
136
|
+
*
|
|
137
|
+
* This ensures consistent indexing and avoids rule override issues caused by shifting positions.
|
|
138
|
+
*
|
|
139
|
+
* @param mediaText - The media query string (e.g., "screen and (max-width: 600px)").
|
|
140
|
+
* @return A MediaRule wrapper containing the index and CSSMediaRule reference.
|
|
141
|
+
*/
|
|
25
142
|
getMediaRule(mediaText: string): MediaRule;
|
|
26
143
|
deleteMediaRule(mediaText: string): void;
|
|
27
|
-
|
|
144
|
+
setRuleCss(rule: CSSStyleRule, props: CssProperties): void;
|
|
145
|
+
getStyleValue(name: Autocomplete<keyof CssProperties>, value: string | number): string;
|
|
28
146
|
protected getCssMap(): Map<string, number>;
|
|
29
147
|
protected getMediaMap(): Map<string, MediaRule>;
|
|
30
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves or creates a <style> element with the given ID and wraps it in a StyleSheet instance.
|
|
150
|
+
* If no element with the specified ID exists, a new <style> tag is created, appended to <head>,
|
|
151
|
+
* and assigned the ID. This allows multiple independently managed stylesheets via custom IDs.
|
|
152
|
+
*
|
|
153
|
+
* @param id - Optional ID of the <style> element to target. Defaults to DEFAULT_STYLE_ID.
|
|
154
|
+
* @return A StyleSheet instance bound to the specified <style> element.
|
|
155
|
+
*/
|
|
156
|
+
static getSheet(id?: string): StyleSheet;
|
|
157
|
+
/**
|
|
158
|
+
* The default ID used for the primary stylesheet managed by the StyleSheet class.
|
|
159
|
+
* This ensures consistent lookup and avoids collisions with other style elements in the document.
|
|
160
|
+
*/
|
|
161
|
+
static DEFAULT_STYLE_ID: string;
|
|
31
162
|
}
|
|
32
163
|
//#endregion
|
|
33
|
-
//#region src/types.d.ts
|
|
34
|
-
type CssProperties = PropertiesFallback<string | number>;
|
|
35
|
-
type Autocomplete<T$1 extends string> = T$1 | (string & {});
|
|
36
|
-
type DomElementChild = DomElement<any> | string | number;
|
|
37
|
-
//#endregion
|
|
38
164
|
//#region src/DomElement.d.ts
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
165
|
+
/**
|
|
166
|
+
* A unified wrapper for HTML and SVG elements that provides a fluent, type-safe API
|
|
167
|
+
* for DOM manipulation, styling, and event handling.
|
|
168
|
+
*
|
|
169
|
+
* Supports both `HTMLElementTagNameMap` and `SVGElementTagNameMap` via the generic `Tag`,
|
|
170
|
+
* and automatically handles namespace creation for SVG elements.
|
|
171
|
+
*
|
|
172
|
+
* Provides ergonomic methods for setting styles, attributes, classes, and event listeners,
|
|
173
|
+
* while abstracting away platform-specific quirks (e.g., `className` vs `setAttribute("class")`).
|
|
174
|
+
*
|
|
175
|
+
* @template Tag - The tag name of the element, inferred from `DomElementTagNameMap`.
|
|
176
|
+
*/
|
|
177
|
+
declare class DomElement<Tag extends keyof DomElementTagNameMap = keyof DomElementTagNameMap> {
|
|
178
|
+
/**
|
|
179
|
+
* Creates a new DomElement instance for the specified tag.
|
|
180
|
+
* Automatically detects whether the tag is an SVG element and uses the appropriate namespace.
|
|
181
|
+
* Optionally wraps an existing DOM element instead of creating a new one.
|
|
182
|
+
*
|
|
183
|
+
* @param tag - The tag name of the element (e.g., "div", "circle", "svg").
|
|
184
|
+
* @param el - An optional existing DOM element to wrap. If omitted, a new element is created.
|
|
185
|
+
*/
|
|
186
|
+
constructor(tag: Tag, el?: DomElementTagNameMap[Tag]);
|
|
187
|
+
protected _tag: Tag extends "svgA" ? {
|
|
188
|
+
svgA: "a";
|
|
189
|
+
}[Tag] : Tag;
|
|
190
|
+
protected _isSvg: boolean;
|
|
191
|
+
protected _dom: DomElementTagNameMap[Tag];
|
|
43
192
|
protected _sheet: StyleSheet;
|
|
44
193
|
protected _cssClassName: string | undefined;
|
|
45
194
|
protected _userClassName: string | undefined;
|
|
46
|
-
|
|
47
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Gets the tag name of the element (e.g., "div", "svg", "circle").
|
|
197
|
+
*/
|
|
198
|
+
get tag(): Tag extends "svgA" ? {
|
|
199
|
+
svgA: "a";
|
|
200
|
+
}[Tag] : Tag;
|
|
201
|
+
/**
|
|
202
|
+
* Indicates whether the element is an SVG element.
|
|
203
|
+
* Returns `true` for tags like "svg", "circle", "path", etc.
|
|
204
|
+
*/
|
|
205
|
+
get isSvg(): boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Gets the underlying DOM element instance.
|
|
208
|
+
* This will be either an `HTMLElement` or `SVGElement` depending on the tag.
|
|
209
|
+
*/
|
|
210
|
+
get dom(): DomElementTagNameMap[Tag];
|
|
48
211
|
get cssClassName(): string;
|
|
49
212
|
getText(): string;
|
|
50
|
-
|
|
51
|
-
|
|
213
|
+
/**
|
|
214
|
+
* Sets or clears the text content of the element.
|
|
215
|
+
* Converts any value to a string before assignment.
|
|
216
|
+
* Passing `undefined` or `null` removes the text by setting it to an empty string.
|
|
217
|
+
*
|
|
218
|
+
* @param value - The text content to set, or `undefined`/`null` to clear it.
|
|
219
|
+
* @return This DomElement instance for chaining.
|
|
220
|
+
*/
|
|
221
|
+
text(value: any): this;
|
|
222
|
+
/**
|
|
223
|
+
* Appends one or more child nodes to the element.
|
|
224
|
+
* Accepts DomElement instances, regular DOM Nodes, strings, or numbers.
|
|
225
|
+
*
|
|
226
|
+
* - Strings and numbers are coerced to text nodes.
|
|
227
|
+
* - DomElement instances are unwrapped to their native DOM nodes.
|
|
228
|
+
* - DOM Nodes are appended directly.
|
|
229
|
+
*
|
|
230
|
+
* @param nodes - One or more child elements or text values to append.
|
|
231
|
+
* @return This DomElement instance for chaining.
|
|
232
|
+
*/
|
|
52
233
|
add(...nodes: DomElementChild[]): this;
|
|
53
234
|
/**
|
|
54
235
|
* Inserts one or more DomElements into a parent at the specified index.
|
|
@@ -76,6 +257,14 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
|
|
|
76
257
|
* @return This DomElement instance.
|
|
77
258
|
*/
|
|
78
259
|
setChildrenFromIndex(index: number, ...nodes: DomElementChild[]): this;
|
|
260
|
+
/**
|
|
261
|
+
* Removes the element from the DOM tree.
|
|
262
|
+
* Equivalent to calling `element.remove()` on the native DOM node.
|
|
263
|
+
*
|
|
264
|
+
* This does not dispose internal state or event listeners — use `dispose()` if cleanup is needed.
|
|
265
|
+
*
|
|
266
|
+
* @return This DomElement instance for chaining.
|
|
267
|
+
*/
|
|
79
268
|
remove(): void;
|
|
80
269
|
/**
|
|
81
270
|
* Removes child elements within the specified index range.
|
|
@@ -86,43 +275,332 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
|
|
|
86
275
|
* @returns This DomElement instance.
|
|
87
276
|
*/
|
|
88
277
|
clear(from?: number, to?: number): this;
|
|
89
|
-
|
|
90
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Adds an event listener to the element.
|
|
280
|
+
* Supports both HTML and SVG elements.
|
|
281
|
+
* @param type - The event type (e.g., "click", "input", "mouseenter").
|
|
282
|
+
* @param handler - The event handler function.
|
|
283
|
+
* @param options - Optional event listener options.
|
|
284
|
+
* @return This DomElement instance for chaining.
|
|
285
|
+
*/
|
|
286
|
+
on<T extends keyof DomElementEventMap>(type: T, handler: (ev: DomElementEventMap[T] & {
|
|
287
|
+
currentTarget: DomElementTagNameMap[Tag];
|
|
91
288
|
}) => void, options?: boolean | AddEventListenerOptions): this;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Removes an event listener from the element.
|
|
291
|
+
* Supports both HTML and SVG elements.
|
|
292
|
+
* @param type - The event type to remove.
|
|
293
|
+
* @param handler - The original handler function.
|
|
294
|
+
* @param options - Optional event listener options.
|
|
295
|
+
*/
|
|
296
|
+
off<T extends keyof DomElementEventMap>(type: T, handler: (ev: DomElementEventMap[T]) => void, options?: boolean | EventListenerOptions): void;
|
|
297
|
+
/**
|
|
298
|
+
* Retrieves the value of a single attribute.
|
|
299
|
+
* @param name - The attribute name to read (e.g. "aria-label", "role").
|
|
300
|
+
* @return The attribute value as a string, or null if not present.
|
|
301
|
+
*/
|
|
302
|
+
getAttr(name: string): string | null;
|
|
303
|
+
/**
|
|
304
|
+
* Sets a single attribute on the element.
|
|
305
|
+
* @param name - The attribute name (e.g. "aria-label", "role", "disabled").
|
|
306
|
+
* @param value - The attribute value. If undefined, the attribute is removed.
|
|
307
|
+
* @return This DomElement instance for chaining.
|
|
308
|
+
*/
|
|
309
|
+
attr(name: string, value: string | number | boolean | undefined): this;
|
|
310
|
+
/**
|
|
311
|
+
* Sets multiple attributes on the element.
|
|
312
|
+
* @param attributes - An object mapping attribute names to values.
|
|
313
|
+
* Attributes with undefined values are removed.
|
|
314
|
+
* @return This DomElement instance for chaining.
|
|
315
|
+
*/
|
|
316
|
+
attrs(attributes: Record<string, string | number | boolean | undefined>): this;
|
|
317
|
+
/**
|
|
318
|
+
* Retrieves the value of a single property.
|
|
319
|
+
* @param name - The property name to read (e.g. "value", "checked", "disabled").
|
|
320
|
+
* @return The property value, or undefined if not present.
|
|
321
|
+
*/
|
|
96
322
|
getProp(name: string): any;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
323
|
+
/**
|
|
324
|
+
* Sets a single property on the element.
|
|
325
|
+
* @param name - The property name (e.g. "checked", "value", "disabled").
|
|
326
|
+
* @param value - The property value. If undefined, the property is deleted.
|
|
327
|
+
* @return This DomElement instance for chaining.
|
|
328
|
+
*/
|
|
329
|
+
prop(name: string, value: any): this;
|
|
330
|
+
/**
|
|
331
|
+
* Sets multiple properties on the element.
|
|
332
|
+
* @param props - An object mapping property names to values.
|
|
333
|
+
* Properties with undefined values are deleted.
|
|
334
|
+
* @return This DomElement instance for chaining.
|
|
335
|
+
*/
|
|
336
|
+
props(props: Record<string, any>): this;
|
|
337
|
+
/**
|
|
338
|
+
* Applies a batch of CSS style properties to the element.
|
|
339
|
+
* Delegates each property to `setStyleProp`, which handles value normalization and kebab-case conversion.
|
|
340
|
+
*
|
|
341
|
+
* - Properties with `undefined` values are removed from the inline style.
|
|
342
|
+
* - Numeric values are passed through the style sheet for unit resolution.
|
|
343
|
+
* - Supports chainable usage for fluent DOM composition.
|
|
344
|
+
*
|
|
345
|
+
* @param props - A partial map of CSS properties and their values.
|
|
346
|
+
* @returns This DomElement instance for chaining.
|
|
347
|
+
*/
|
|
348
|
+
style(props: CssProperties): this;
|
|
349
|
+
/**
|
|
350
|
+
* Sets or removes the `id` of the element.
|
|
351
|
+
* Passing `undefined` clears the ID by setting it to an empty string.
|
|
352
|
+
*
|
|
353
|
+
* @param value - The element's ID, or `undefined` to remove it.
|
|
354
|
+
* @return This DomElement instance for chaining.
|
|
355
|
+
*/
|
|
356
|
+
id(value: string | undefined): this;
|
|
357
|
+
/**
|
|
358
|
+
* Sets or removes the user-defined class name and applies it alongside the internal CSS class.
|
|
359
|
+
* Uses `setAttribute("class", ...)` for both HTML and SVG elements.
|
|
360
|
+
*
|
|
361
|
+
* Passing `undefined` removes the user-defined class name entirely.
|
|
362
|
+
*
|
|
363
|
+
* @param value - The user-defined class name, or `undefined` to remove it.
|
|
364
|
+
* @return This DomElement instance for chaining.
|
|
365
|
+
*/
|
|
366
|
+
className(value: string | undefined): this;
|
|
367
|
+
/**
|
|
368
|
+
* Sets or removes the `htmlFor` property on a <label> element.
|
|
369
|
+
* This links the label to a form control by its ID.
|
|
370
|
+
*
|
|
371
|
+
* Passing `undefined` removes the association.
|
|
372
|
+
* Has no effect if the element is not a <label>.
|
|
373
|
+
*
|
|
374
|
+
* @param value - The ID of the target form control, or `undefined` to remove it.
|
|
375
|
+
* @return This DomElement instance for chaining.
|
|
376
|
+
*/
|
|
377
|
+
htmlFor(value: string | undefined): this;
|
|
378
|
+
/**
|
|
379
|
+
* Sets or removes the `title` attribute on the element.
|
|
380
|
+
* Applies to both HTML and SVG elements. Passing `undefined` removes the attribute.
|
|
381
|
+
*
|
|
382
|
+
* @param value - The tooltip text to show on hover, or `undefined` to remove it.
|
|
383
|
+
* @return This DomElement instance for chaining.
|
|
384
|
+
*/
|
|
385
|
+
title(value: string | undefined): this;
|
|
386
|
+
/**
|
|
387
|
+
* Sets or removes the `disabled` attribute on the element.
|
|
388
|
+
* Applicable to form controls like <button>, <input>, <select>, etc.
|
|
389
|
+
*
|
|
390
|
+
* @param value - If true, sets the `disabled` attribute; if false, removes it.
|
|
391
|
+
* @return This DomElement instance for chaining.
|
|
392
|
+
*/
|
|
393
|
+
disabled(value: boolean): this;
|
|
394
|
+
/**
|
|
395
|
+
* Sets the `disabled` attribute to disable the element.
|
|
396
|
+
* Applicable to form controls like <button>, <input>, <select>, etc.
|
|
397
|
+
* @return This DomElement instance for chaining.
|
|
398
|
+
*/
|
|
399
|
+
disable(): this;
|
|
400
|
+
/**
|
|
401
|
+
* Removes the `disabled` attribute to enable the element.
|
|
402
|
+
* @return This DomElement instance for chaining.
|
|
403
|
+
*/
|
|
404
|
+
enable(): this;
|
|
405
|
+
/**
|
|
406
|
+
* Sets or clears the `padding` style of the element.
|
|
407
|
+
* Accepts any valid CSS padding shorthand (e.g., "10px", "1em 2em").
|
|
408
|
+
* Passing `undefined` removes the padding style.
|
|
409
|
+
*
|
|
410
|
+
* @param value - The padding value to apply, or `undefined` to remove it.
|
|
411
|
+
* @return This DomElement instance for chaining.
|
|
412
|
+
*/
|
|
103
413
|
p(value: Property.Padding | undefined): this;
|
|
414
|
+
/**
|
|
415
|
+
* Sets or clears the `padding-top` style of the element.
|
|
416
|
+
* Accepts any valid CSS value (e.g., "10px", "1em").
|
|
417
|
+
* Passing `undefined` removes the top padding.
|
|
418
|
+
*
|
|
419
|
+
* @param value - The top padding value to apply, or `undefined` to remove it.
|
|
420
|
+
* @return This DomElement instance for chaining.
|
|
421
|
+
*/
|
|
104
422
|
pt(value: Property.PaddingTop | undefined): this;
|
|
423
|
+
/**
|
|
424
|
+
* Sets or clears the `padding-right` style of the element.
|
|
425
|
+
* Accepts any valid CSS value (e.g., "10px", "1em").
|
|
426
|
+
* Passing `undefined` removes the right padding.
|
|
427
|
+
*
|
|
428
|
+
* @param value - The right padding value to apply, or `undefined` to remove it.
|
|
429
|
+
* @return This DomElement instance for chaining.
|
|
430
|
+
*/
|
|
105
431
|
pr(value: Property.PaddingRight | undefined): this;
|
|
432
|
+
/**
|
|
433
|
+
* Sets or clears the `padding-bottom` style of the element.
|
|
434
|
+
* Accepts any valid CSS value (e.g., "10px", "1em").
|
|
435
|
+
* Passing `undefined` removes the bottom padding.
|
|
436
|
+
*
|
|
437
|
+
* @param value - The bottom padding value to apply, or `undefined` to remove it.
|
|
438
|
+
* @return This DomElement instance for chaining.
|
|
439
|
+
*/
|
|
106
440
|
pb(value: Property.PaddingBottom | undefined): this;
|
|
441
|
+
/**
|
|
442
|
+
* Sets or clears the `padding-left` style of the element.
|
|
443
|
+
* Accepts any valid CSS value (e.g., "10px", "1em").
|
|
444
|
+
* Passing `undefined` removes the left padding.
|
|
445
|
+
*
|
|
446
|
+
* @param value - The left padding value to apply, or `undefined` to remove it.
|
|
447
|
+
* @return This DomElement instance for chaining.
|
|
448
|
+
*/
|
|
107
449
|
pl(value: Property.PaddingLeft | undefined): this;
|
|
450
|
+
/**
|
|
451
|
+
* Sets or clears horizontal padding (`padding-left` and `padding-right`) simultaneously.
|
|
452
|
+
* Accepts any valid CSS value (e.g., "10px", "1em").
|
|
453
|
+
* Passing `undefined` removes both left and right padding.
|
|
454
|
+
*
|
|
455
|
+
* @param value - The horizontal padding value to apply, or `undefined` to remove it.
|
|
456
|
+
* @return This DomElement instance for chaining.
|
|
457
|
+
*/
|
|
108
458
|
px(value: Property.PaddingLeft | undefined): this;
|
|
459
|
+
/**
|
|
460
|
+
* Sets or clears vertical padding (`padding-top` and `padding-bottom`) simultaneously.
|
|
461
|
+
* Accepts any valid CSS value (e.g., "10px", "1em").
|
|
462
|
+
* Passing `undefined` removes both top and bottom padding.
|
|
463
|
+
*
|
|
464
|
+
* @param value - The vertical padding value to apply, or `undefined` to remove it.
|
|
465
|
+
* @return This DomElement instance for chaining.
|
|
466
|
+
*/
|
|
109
467
|
py(value: Property.PaddingTop | undefined): this;
|
|
468
|
+
/**
|
|
469
|
+
* Sets or clears the `margin` style of the element.
|
|
470
|
+
* Accepts any valid CSS margin shorthand (e.g., "10px", "1em 2em").
|
|
471
|
+
* Passing `undefined` removes the margin style.
|
|
472
|
+
*
|
|
473
|
+
* @param value - The margin value to apply, or `undefined` to remove it.
|
|
474
|
+
* @return This DomElement instance for chaining.
|
|
475
|
+
*/
|
|
110
476
|
m(value: Property.Margin | undefined): this;
|
|
477
|
+
/**
|
|
478
|
+
* Sets or clears the `margin-top` style of the element.
|
|
479
|
+
* Accepts any valid CSS value (e.g., "10px", "auto").
|
|
480
|
+
* Passing `undefined` removes the top margin.
|
|
481
|
+
*
|
|
482
|
+
* @param value - The top margin value to apply, or `undefined` to remove it.
|
|
483
|
+
* @return This DomElement instance for chaining.
|
|
484
|
+
*/
|
|
111
485
|
mt(value: Property.MarginTop | undefined): this;
|
|
486
|
+
/**
|
|
487
|
+
* Sets or clears the `margin-right` style of the element.
|
|
488
|
+
* Accepts any valid CSS value (e.g., "10px", "auto").
|
|
489
|
+
* Passing `undefined` removes the right margin.
|
|
490
|
+
*
|
|
491
|
+
* @param value - The right margin value to apply, or `undefined` to remove it.
|
|
492
|
+
* @return This DomElement instance for chaining.
|
|
493
|
+
*/
|
|
112
494
|
mr(value: Property.MarginRight | undefined): this;
|
|
495
|
+
/**
|
|
496
|
+
* Sets or clears the `margin-bottom` style of the element.
|
|
497
|
+
* Accepts any valid CSS value (e.g., "10px", "auto").
|
|
498
|
+
* Passing `undefined` removes the bottom margin.
|
|
499
|
+
*
|
|
500
|
+
* @param value - The bottom margin value to apply, or `undefined` to remove it.
|
|
501
|
+
* @return This DomElement instance for chaining.
|
|
502
|
+
*/
|
|
113
503
|
mb(value: Property.MarginBottom | undefined): this;
|
|
504
|
+
/**
|
|
505
|
+
* Sets or clears the `margin-left` style of the element.
|
|
506
|
+
* Accepts any valid CSS value (e.g., "10px", "auto").
|
|
507
|
+
* Passing `undefined` removes the left margin.
|
|
508
|
+
*
|
|
509
|
+
* @param value - The left margin value to apply, or `undefined` to remove it.
|
|
510
|
+
* @return This DomElement instance for chaining.
|
|
511
|
+
*/
|
|
114
512
|
ml(value: Property.MarginLeft | undefined): this;
|
|
513
|
+
/**
|
|
514
|
+
* Sets the overall border radius.
|
|
515
|
+
* @param value - The CSS border-radius value (e.g., "8px", "50%").
|
|
516
|
+
* @return This DomElement instance for chaining.
|
|
517
|
+
*/
|
|
115
518
|
radius(value: Property.BorderRadius | undefined): this;
|
|
519
|
+
/**
|
|
520
|
+
* Sets the top-left corner border radius.
|
|
521
|
+
* @param value - The CSS border-top-left-radius value.
|
|
522
|
+
* @return This DomElement instance for chaining.
|
|
523
|
+
*/
|
|
116
524
|
radiusTopLeft(value: Property.BorderTopLeftRadius | undefined): this;
|
|
525
|
+
/**
|
|
526
|
+
* Sets the top-right corner border radius.
|
|
527
|
+
* @param value - The CSS border-top-right-radius value.
|
|
528
|
+
* @return This DomElement instance for chaining.
|
|
529
|
+
*/
|
|
117
530
|
radiusTopRight(value: Property.BorderTopRightRadius | undefined): this;
|
|
531
|
+
/**
|
|
532
|
+
* Sets the bottom-left corner border radius.
|
|
533
|
+
* @param value - The CSS border-bottom-left-radius value.
|
|
534
|
+
* @return This DomElement instance for chaining.
|
|
535
|
+
*/
|
|
536
|
+
radiusBottomLeft(value: Property.BorderBottomLeftRadius | undefined): this;
|
|
537
|
+
/**
|
|
538
|
+
* Sets the bottom-right corner border radius.
|
|
539
|
+
* @param value - The CSS border-bottom-right-radius value.
|
|
540
|
+
* @return This DomElement instance for chaining.
|
|
541
|
+
*/
|
|
542
|
+
radiusBottomRight(value: Property.BorderBottomRightRadius | undefined): this;
|
|
543
|
+
/**
|
|
544
|
+
* Sets the border radius for both top corners.
|
|
545
|
+
* @param value - The CSS border-radius value to apply to top-left and top-right corners.
|
|
546
|
+
* @return This DomElement instance for chaining.
|
|
547
|
+
*/
|
|
118
548
|
radiusTop(value: Property.BorderTopLeftRadius | undefined): this;
|
|
549
|
+
/**
|
|
550
|
+
* Sets the border radius for both bottom corners.
|
|
551
|
+
* @param value - The CSS border-radius value to apply to bottom-left and bottom-right corners.
|
|
552
|
+
* @return This DomElement instance for chaining.
|
|
553
|
+
*/
|
|
554
|
+
radiusBottom(value: Property.BorderBottomLeftRadius | undefined): this;
|
|
555
|
+
/**
|
|
556
|
+
* Sets the border radius for both left corners.
|
|
557
|
+
* @param value - The CSS border-radius value to apply to top-left and bottom-left corners.
|
|
558
|
+
* @return This DomElement instance for chaining.
|
|
559
|
+
*/
|
|
560
|
+
radiusLeft(value: Property.BorderTopLeftRadius | undefined): this;
|
|
561
|
+
/**
|
|
562
|
+
* Sets the border radius for both right corners.
|
|
563
|
+
* @param value - The CSS border-radius value to apply to top-right and bottom-right corners.
|
|
564
|
+
* @return This DomElement instance for chaining.
|
|
565
|
+
*/
|
|
566
|
+
radiusRight(value: Property.BorderTopRightRadius | undefined): this;
|
|
567
|
+
/**
|
|
568
|
+
* Sets the border radius for both left and right sides (horizontal corners).
|
|
569
|
+
* Applies to top-left, top-right, bottom-left, and bottom-right corners on the X axis.
|
|
570
|
+
* @param value - The CSS border-radius value to apply horizontally.
|
|
571
|
+
* @return This DomElement instance for chaining.
|
|
572
|
+
*/
|
|
573
|
+
radiusX(value: Property.BorderRadius | undefined): this;
|
|
574
|
+
/**
|
|
575
|
+
* Sets the border radius for both top and bottom sides (vertical corners).
|
|
576
|
+
* Applies to top-left, top-right, bottom-left, and bottom-right corners on the Y axis.
|
|
577
|
+
* @param value - The CSS border-radius value to apply vertically.
|
|
578
|
+
* @return This DomElement instance for chaining.
|
|
579
|
+
*/
|
|
580
|
+
radiusY(value: Property.BorderRadius | undefined): this;
|
|
119
581
|
display(value: Property.Display | undefined): this;
|
|
120
582
|
flexShrink(value: Property.FlexShrink | undefined): this;
|
|
121
583
|
flex(value: Property.Flex | undefined): this;
|
|
122
584
|
bgColor(value: Property.BackgroundColor | undefined): this;
|
|
123
585
|
color(value: Property.Color | undefined): this;
|
|
124
|
-
|
|
586
|
+
/**
|
|
587
|
+
* Sets or clears the `width` style of the element.
|
|
588
|
+
* Accepts CSS width values (e.g., "100px", "50%") or numeric pixel values.
|
|
589
|
+
* Passing `undefined` removes the width style.
|
|
590
|
+
*
|
|
591
|
+
* @param value - The width value to apply, or `undefined` to remove it.
|
|
592
|
+
* @return This DomElement instance for chaining.
|
|
593
|
+
*/
|
|
125
594
|
w(value: Property.Width | number | undefined): this;
|
|
595
|
+
/**
|
|
596
|
+
* Sets or clears the `height` style of the element.
|
|
597
|
+
* Accepts CSS height values (e.g., "100px", "auto") or numeric pixel values.
|
|
598
|
+
* Passing `undefined` removes the height style.
|
|
599
|
+
*
|
|
600
|
+
* @param value - The height value to apply, or `undefined` to remove it.
|
|
601
|
+
* @return This DomElement instance for chaining.
|
|
602
|
+
*/
|
|
603
|
+
h(value: Property.Height | number | undefined): this;
|
|
126
604
|
/**
|
|
127
605
|
* Sets the full border style.
|
|
128
606
|
* @param value - The CSS border value (e.g., "1px solid #ccc").
|
|
@@ -153,6 +631,42 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
|
|
|
153
631
|
* @return This DomElement instance for chaining.
|
|
154
632
|
*/
|
|
155
633
|
bl(value: Property.BorderLeft | undefined): this;
|
|
634
|
+
/**
|
|
635
|
+
* Sets the left and right border styles.
|
|
636
|
+
* @param value - The CSS border value to apply to both left and right sides.
|
|
637
|
+
* @return This DomElement instance for chaining.
|
|
638
|
+
*/
|
|
639
|
+
bx(value: Property.BorderLeft | Property.BorderRight | undefined): this;
|
|
640
|
+
/**
|
|
641
|
+
* Sets the top and bottom border styles.
|
|
642
|
+
* @param value - The CSS border value to apply to both top and bottom sides.
|
|
643
|
+
* @return This DomElement instance for chaining.
|
|
644
|
+
*/
|
|
645
|
+
by(value: Property.BorderTop | Property.BorderBottom | undefined): this;
|
|
646
|
+
/**
|
|
647
|
+
* Sets the top and left border styles.
|
|
648
|
+
* @param value - The CSS border value to apply to both top and left sides.
|
|
649
|
+
* @return This DomElement instance for chaining.
|
|
650
|
+
*/
|
|
651
|
+
btl(value: Property.BorderTop | Property.BorderLeft | undefined): this;
|
|
652
|
+
/**
|
|
653
|
+
* Sets the top and right border styles.
|
|
654
|
+
* @param value - The CSS border value to apply to both top and right sides.
|
|
655
|
+
* @return This DomElement instance for chaining.
|
|
656
|
+
*/
|
|
657
|
+
btr(value: Property.BorderTop | Property.BorderRight | undefined): this;
|
|
658
|
+
/**
|
|
659
|
+
* Sets the bottom and left border styles.
|
|
660
|
+
* @param value - The CSS border value to apply to both bottom and left sides.
|
|
661
|
+
* @return This DomElement instance for chaining.
|
|
662
|
+
*/
|
|
663
|
+
bbl(value: Property.BorderBottom | Property.BorderLeft | undefined): this;
|
|
664
|
+
/**
|
|
665
|
+
* Sets the bottom and right border styles.
|
|
666
|
+
* @param value - The CSS border value to apply to both bottom and right sides.
|
|
667
|
+
* @return This DomElement instance for chaining.
|
|
668
|
+
*/
|
|
669
|
+
bbr(value: Property.BorderBottom | Property.BorderRight | undefined): this;
|
|
156
670
|
overflow(value: Property.Overflow | undefined): this;
|
|
157
671
|
overflowY(value: Property.OverflowY | undefined): this;
|
|
158
672
|
overflowX(value: Property.OverflowX | undefined): this;
|
|
@@ -162,10 +676,35 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
|
|
|
162
676
|
fontStyle(value: Property.FontStyle | undefined): this;
|
|
163
677
|
textAlign(value: Property.TextAlign | undefined): this;
|
|
164
678
|
textDecoration(value: Property.TextDecoration | undefined): this;
|
|
679
|
+
/**
|
|
680
|
+
* Sets the CSS `position` property.
|
|
681
|
+
* @param value - The positioning mode (e.g., "absolute", "relative", "fixed").
|
|
682
|
+
* @return This DomElement instance for chaining.
|
|
683
|
+
*/
|
|
165
684
|
pos(value: Property.Position | undefined): this;
|
|
685
|
+
/**
|
|
686
|
+
* Sets the CSS `top` offset.
|
|
687
|
+
* @param value - The top offset value (e.g., "10px", "50%").
|
|
688
|
+
* @return This DomElement instance for chaining.
|
|
689
|
+
*/
|
|
166
690
|
posTop(value: Property.Top | undefined): this;
|
|
691
|
+
/**
|
|
692
|
+
* Sets the CSS `bottom` offset.
|
|
693
|
+
* @param value - The bottom offset value (e.g., "0", "2rem").
|
|
694
|
+
* @return This DomElement instance for chaining.
|
|
695
|
+
*/
|
|
167
696
|
posBottom(value: Property.Bottom | undefined): this;
|
|
697
|
+
/**
|
|
698
|
+
* Sets the CSS `left` offset.
|
|
699
|
+
* @param value - The left offset value (e.g., "5px", "auto").
|
|
700
|
+
* @return This DomElement instance for chaining.
|
|
701
|
+
*/
|
|
168
702
|
posLeft(value: Property.Left | undefined): this;
|
|
703
|
+
/**
|
|
704
|
+
* Sets the CSS `right` offset.
|
|
705
|
+
* @param value - The right offset value (e.g., "1em", "0").
|
|
706
|
+
* @return This DomElement instance for chaining.
|
|
707
|
+
*/
|
|
169
708
|
posRight(value: Property.Right | undefined): this;
|
|
170
709
|
cursor(value: Property.Cursor | undefined): this;
|
|
171
710
|
alignItems(value: Property.AlignItems | undefined): this;
|
|
@@ -175,23 +714,158 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
|
|
|
175
714
|
templateColumns(value: Property.GridTemplateColumns | undefined): this;
|
|
176
715
|
templateRows(value: Property.GridTemplateRows | undefined): this;
|
|
177
716
|
appearance(value: Property.Appearance | undefined): this;
|
|
717
|
+
/**
|
|
718
|
+
* Sets the CSS `user-select` property to control text selection behavior.
|
|
719
|
+
* @param value - The user-select value (e.g., "none", "text", "auto", "contain", "all").
|
|
720
|
+
* @return This DomElement instance for chaining.
|
|
721
|
+
*/
|
|
722
|
+
userSelect(value: Property.UserSelect | undefined): this;
|
|
723
|
+
/**
|
|
724
|
+
* Sets the vertical alignment of the element.
|
|
725
|
+
* Common values include "middle", "top", "bottom", "baseline", or pixel/em units.
|
|
726
|
+
*
|
|
727
|
+
* @param value - The CSS vertical-align value (e.g., "middle", "top", "10px").
|
|
728
|
+
* @return This DomElement instance for chaining.
|
|
729
|
+
*/
|
|
730
|
+
verticalAlign(value: Property.VerticalAlign | undefined): this;
|
|
731
|
+
/**
|
|
732
|
+
* Applies CSS styles to truncate overflowing text with an ellipsis.
|
|
733
|
+
* Ensures the text stays on a single line and hides overflow.
|
|
734
|
+
*
|
|
735
|
+
* Equivalent to:
|
|
736
|
+
* ```css
|
|
737
|
+
* overflow: hidden;
|
|
738
|
+
* white-space: nowrap;
|
|
739
|
+
* text-overflow: ellipsis;
|
|
740
|
+
* ```
|
|
741
|
+
*
|
|
742
|
+
* @return This DomElement instance for chaining.
|
|
743
|
+
*/
|
|
178
744
|
overflowEllipsis(): this;
|
|
179
745
|
ref(refFn: (el: this) => void): this;
|
|
746
|
+
/**
|
|
747
|
+
* Applies scoped CSS styles to the element using a class-based selector.
|
|
748
|
+
* Ensures the element has a unique internal class name, then targets it with the given selector.
|
|
749
|
+
*
|
|
750
|
+
* For example, calling `css(":hover", { color: "red" })` will generate:
|
|
751
|
+
* ```css
|
|
752
|
+
* .<internalClassName>:hover { color: red; }
|
|
753
|
+
* ```
|
|
754
|
+
*
|
|
755
|
+
* This enables dynamic styling of pseudo-classes, child selectors, or media queries without inline styles.
|
|
756
|
+
*
|
|
757
|
+
* @param selector - A CSS selector suffix (e.g., ":hover", " > span") scoped to the internal class.
|
|
758
|
+
* @param props - A map of CSS properties to apply to the generated rule.
|
|
759
|
+
* @return This DomElement instance for chaining.
|
|
760
|
+
*/
|
|
761
|
+
css(selector: string, props: CssProperties): this;
|
|
762
|
+
/**
|
|
763
|
+
* Applies scoped CSS styles directly to the root selector of the element.
|
|
764
|
+
* Equivalent to styling `.className` without any pseudo-classes or combinators.
|
|
765
|
+
*
|
|
766
|
+
* @param props - A map of CSS properties to apply to the root selector.
|
|
767
|
+
* @return This DomElement instance for chaining.
|
|
768
|
+
*/
|
|
180
769
|
rootCss(props: CssProperties): this;
|
|
770
|
+
/**
|
|
771
|
+
* Applies scoped CSS styles to the `:hover` state of the element.
|
|
772
|
+
* Useful for styling hover interactions without inline styles.
|
|
773
|
+
*
|
|
774
|
+
* @param props - A map of CSS properties to apply when the element is hovered.
|
|
775
|
+
* @return This DomElement instance for chaining.
|
|
776
|
+
*/
|
|
181
777
|
hoverCss(props: CssProperties): this;
|
|
778
|
+
/**
|
|
779
|
+
* Applies scoped CSS styles to the `:active` state of the element.
|
|
780
|
+
* Useful for styling active interactions (e.g., mouse down).
|
|
781
|
+
*
|
|
782
|
+
* @param props - A map of CSS properties to apply when the element is active.
|
|
783
|
+
* @return This DomElement instance for chaining.
|
|
784
|
+
*/
|
|
182
785
|
activeCss(props: CssProperties): this;
|
|
786
|
+
/**
|
|
787
|
+
* Applies scoped CSS styles to the `:focus` state of the element.
|
|
788
|
+
* Useful for styling keyboard or programmatic focus.
|
|
789
|
+
*
|
|
790
|
+
* @param props - A map of CSS properties to apply when the element is focused.
|
|
791
|
+
* @return This DomElement instance for chaining.
|
|
792
|
+
*/
|
|
183
793
|
focusCss(props: CssProperties): this;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
794
|
+
/**
|
|
795
|
+
* Applies scoped CSS styles to the `:focus-within` state of the element.
|
|
796
|
+
* Useful for styling when any child element has focus.
|
|
797
|
+
*
|
|
798
|
+
* @param props - A map of CSS properties to apply when the element or its descendants are focused.
|
|
799
|
+
* @return This DomElement instance for chaining.
|
|
800
|
+
*/
|
|
801
|
+
focusWithinCss(props: CssProperties): this;
|
|
802
|
+
/**
|
|
803
|
+
* Applies scoped CSS styles to the element within a media query block.
|
|
804
|
+
* Ensures the element has a unique internal class name, then targets it with the given selector inside the specified media query.
|
|
805
|
+
*
|
|
806
|
+
* For example, calling `mediaCss("screen and (max-width: 600px)", ":hover", { color: "red" })` will generate:
|
|
807
|
+
* ```css
|
|
808
|
+
* \@media screen and (max-width: 600px) {
|
|
809
|
+
* .<internalClassName>:hover { color: red; }
|
|
810
|
+
* }
|
|
811
|
+
* ```
|
|
812
|
+
*
|
|
813
|
+
* This enables responsive styling and conditional behavior based on viewport or device characteristics.
|
|
814
|
+
*
|
|
815
|
+
* @param mediaText - The media query string (e.g., "screen and (max-width: 600px)").
|
|
816
|
+
* @param selector - A CSS selector suffix (e.g., ":hover", " > span") scoped to the internal class.
|
|
817
|
+
* @param props - A map of CSS properties to apply within the media rule.
|
|
818
|
+
* @return This DomElement instance for chaining.
|
|
819
|
+
*/
|
|
187
820
|
mediaCss(mediaText: string, selector: string, props: CssProperties): this;
|
|
821
|
+
/**
|
|
822
|
+
* Applies scoped CSS styles to the root selector of the element within a media query block.
|
|
823
|
+
* Useful for conditionally styling the element based on viewport or device characteristics.
|
|
824
|
+
*
|
|
825
|
+
* @param mediaText - The media query string (e.g., "screen and (max-width: 600px)").
|
|
826
|
+
* @param props - A map of CSS properties to apply within the media rule.
|
|
827
|
+
* @return This DomElement instance for chaining.
|
|
828
|
+
*/
|
|
188
829
|
mediaRootCss(mediaText: string, props: CssProperties): this;
|
|
830
|
+
/**
|
|
831
|
+
* Applies scoped CSS styles to the root selector of the element when the viewport width
|
|
832
|
+
* meets or exceeds the specified minimum.
|
|
833
|
+
*
|
|
834
|
+
* Automatically converts numeric values to pixel-based CSS width values.
|
|
835
|
+
*
|
|
836
|
+
* @param minWidth - The minimum width threshold (e.g., 600 or "40em").
|
|
837
|
+
* @param props - A map of CSS properties to apply when the condition is met.
|
|
838
|
+
* @return This DomElement instance for chaining.
|
|
839
|
+
*/
|
|
189
840
|
minWidthCss(minWidth: number | string, props: CssProperties): this;
|
|
841
|
+
/**
|
|
842
|
+
* Applies scoped CSS styles to the root selector of the element when the viewport width
|
|
843
|
+
* is less than or equal to the specified maximum.
|
|
844
|
+
*
|
|
845
|
+
* Automatically converts numeric values to pixel-based CSS width values.
|
|
846
|
+
*
|
|
847
|
+
* @param maxWidth - The maximum width threshold (e.g., 600 or "40em").
|
|
848
|
+
* @param props - A map of CSS properties to apply when the condition is met.
|
|
849
|
+
* @return This DomElement instance for chaining.
|
|
850
|
+
*/
|
|
190
851
|
maxWidthCss(maxWidth: number | string, props: CssProperties): this;
|
|
191
|
-
protected
|
|
852
|
+
protected resolveNode(child: DomElementChild): Node;
|
|
853
|
+
protected setStyleProp(name: Autocomplete<keyof CssProperties>, value: string | number | undefined): this;
|
|
854
|
+
protected setCssClassName(): this;
|
|
192
855
|
}
|
|
193
|
-
|
|
194
|
-
|
|
856
|
+
/**
|
|
857
|
+
* Creates a new DomElement instance for the given tag name.
|
|
858
|
+
* @param tag - The HTML tag name (e.g., "div", "button", "input").
|
|
859
|
+
* @return A DomElement wrapping a newly created element of the specified tag.
|
|
860
|
+
*/
|
|
861
|
+
declare function $<T$1 extends keyof DomElementTagNameMap>(tag: T$1): DomElement<T$1>;
|
|
862
|
+
/**
|
|
863
|
+
* Queries the DOM for a matching element and wraps it in a DomElement.
|
|
864
|
+
* @param selector - A CSS selector string to locate the element.
|
|
865
|
+
* @return A DomElement wrapping the matched element.
|
|
866
|
+
* @throws If no element matches the selector, this will throw due to non-null assertion.
|
|
867
|
+
*/
|
|
868
|
+
declare function $query<T$1 extends keyof DomElementTagNameMap>(selector: string): DomElement<T$1>;
|
|
195
869
|
//#endregion
|
|
196
870
|
//#region src/AnchorElement.d.ts
|
|
197
871
|
declare class AnchorElement extends DomElement<"a"> {
|
|
@@ -203,6 +877,7 @@ declare class AnchorElement extends DomElement<"a"> {
|
|
|
203
877
|
declare class Button extends DomElement<"button"> {
|
|
204
878
|
constructor();
|
|
205
879
|
type(value: "button" | "submit" | "reset"): this;
|
|
880
|
+
disabledCss(props: CssProperties): this;
|
|
206
881
|
}
|
|
207
882
|
//#endregion
|
|
208
883
|
//#region src/Canvas.d.ts
|
|
@@ -236,6 +911,11 @@ declare class Canvas extends DomElement<"canvas"> {
|
|
|
236
911
|
//#region src/constants.d.ts
|
|
237
912
|
declare const UNITLESS_CSS_PROPS: Record<string, 1>;
|
|
238
913
|
declare const VENDOR_CSS_PROPS: Record<string, 1>;
|
|
914
|
+
declare const SVG_TAGS: string[];
|
|
915
|
+
declare const TAG_ALIAS: {
|
|
916
|
+
svgA: "a";
|
|
917
|
+
};
|
|
918
|
+
type TagAlias = typeof TAG_ALIAS;
|
|
239
919
|
//#endregion
|
|
240
920
|
//#region src/DomBody.d.ts
|
|
241
921
|
declare class DomBody {
|
|
@@ -274,6 +954,7 @@ declare class InputCheckbox extends DomElement<"input"> {
|
|
|
274
954
|
name(value: string): this;
|
|
275
955
|
checked(value: boolean): this;
|
|
276
956
|
isChecked(): boolean;
|
|
957
|
+
disabledCss(props: CssProperties): this;
|
|
277
958
|
}
|
|
278
959
|
//#endregion
|
|
279
960
|
//#region src/InputColor.d.ts
|
|
@@ -297,6 +978,7 @@ declare class InputColor extends DomElement<"input"> {
|
|
|
297
978
|
g: number;
|
|
298
979
|
b: number;
|
|
299
980
|
};
|
|
981
|
+
disabledCss(props: CssProperties): this;
|
|
300
982
|
}
|
|
301
983
|
//#endregion
|
|
302
984
|
//#region src/InputNumber.d.ts
|
|
@@ -309,6 +991,7 @@ declare class InputNumber extends DomElement<"input"> {
|
|
|
309
991
|
max(value: number): this;
|
|
310
992
|
step(value: number): this;
|
|
311
993
|
placeholder(value: string): this;
|
|
994
|
+
disabledCss(props: CssProperties): this;
|
|
312
995
|
}
|
|
313
996
|
//#endregion
|
|
314
997
|
//#region src/InputRange.d.ts
|
|
@@ -320,6 +1003,7 @@ declare class InputRange extends DomElement<"input"> {
|
|
|
320
1003
|
min(value: number): this;
|
|
321
1004
|
max(value: number): this;
|
|
322
1005
|
step(value: number): this;
|
|
1006
|
+
disabledCss(props: CssProperties): this;
|
|
323
1007
|
}
|
|
324
1008
|
//#endregion
|
|
325
1009
|
//#region src/InputText.d.ts
|
|
@@ -329,6 +1013,7 @@ declare class InputText extends DomElement<"input"> {
|
|
|
329
1013
|
value(value: string): this;
|
|
330
1014
|
getValue(): string;
|
|
331
1015
|
placeholder(value: string): this;
|
|
1016
|
+
disabledCss(props: CssProperties): this;
|
|
332
1017
|
}
|
|
333
1018
|
//#endregion
|
|
334
1019
|
//#region src/OptionElement.d.ts
|
|
@@ -387,7 +1072,7 @@ declare class SelectElement extends DomElement<"select"> {
|
|
|
387
1072
|
}
|
|
388
1073
|
//#endregion
|
|
389
1074
|
//#region src/utils.d.ts
|
|
390
|
-
declare function uniqueId(
|
|
1075
|
+
declare function uniqueId(): string;
|
|
391
1076
|
declare function camelToKebab(prop: string): string;
|
|
392
1077
|
//#endregion
|
|
393
|
-
export { $, $body, $
|
|
1078
|
+
export { $, $body, $query, AnchorElement, Autocomplete, Button, Canvas, CssProperties, type CssProperty, DomBody, DomElement, DomElementChild, DomElementEventMap, DomElementTagNameMap, IFrame, ImageElement, InputCheckbox, InputColor, InputNumber, InputRange, InputText, MediaRule, OptionElement, ProgressElement, SVG_TAGS, SelectElement, StyleSheet, TAG_ALIAS, TagAlias, UNITLESS_CSS_PROPS, VENDOR_CSS_PROPS, camelToKebab, uniqueId };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e={opacity:1,zIndex:1,fontWeight:1,lineHeight:1,flexGrow:1,flexShrink:1,order:1,zoom:1,scale:1,counterIncrement:1,counterReset:1,tabSize:1,orphans:1,widows:1,columns:1,columnCount:1,gridRow:1,gridColumn:1},t={WebkitAppearance:1};var n=class{constructor(e,t){this._index=e,this._rule=t,this.cssMap=new Map}_index;_rule;cssMap;get index(){return this._index}get rule(){return this._rule}get length(){return this._rule.cssRules.length}getCssRule(e){let t=this.cssMap.get(e);return t??=this._rule.insertRule(`${e}{}`,this.length),this._rule.cssRules.item(t)}delete(e){this._rule.deleteRule(e)}},r=class e{constructor(e){this._dom=e}_dom;get dom(){return this._dom}get sheet(){return this.dom.sheet}get length(){return this.sheet.cssRules.length}getCssRule(e){let t=this.getCssMap(),n=t.get(e);return n??(n=this.sheet.insertRule(`${e}{}`),t.set(e,n)),this.sheet.cssRules.item(n)}deleteCssRule(e){let t=this.getCssMap(),n=t.get(e);n!=null&&(this.sheet.deleteRule(n),t.delete(e))}getMediaRule(e){let t=this.getMediaMap(),r=t.get(e);if(!r){let i=this.sheet.insertRule(`@media(${e}){}`);r=new n(i,this.sheet.cssRules.item(i)),t.set(e,r)}return r}deleteMediaRule(e){let t=this.getMediaMap(),n=t.get(e);n!=null&&(this.sheet.deleteRule(n.index),t.delete(e))}static getSheet(){let t=document.head.querySelector(`#${e.STYLE_ID}`);if(t==null){let t=document.createElement(`style`);return t.id=e.STYLE_ID,t.setAttribute(`type`,`text/css`),document.head.append(t),new e(t)}else return new e(t)}getCssMap(){let e=window.__neptuneCssMap__;return e||(e=new Map,window.__neptuneCssMap__=e),e}getMediaMap(){let e=window.__neptuneMediaMap__;return e||(e=new Map,window.__neptuneMediaMap__=e),e}static STYLE_ID=`__neptune-style__`};function i(e){return`${e}-${Date.now().toString(36)}-${(a++).toString(36)}`}let a=0;function o(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).toLowerCase()}var s=class{constructor(e,t){this._tag=e,this._dom=t??document.createElement(e),this._sheet=r.getSheet()}_tag;_dom;_sheet;_cssClassName;_userClassName;get tag(){return this._tag}get dom(){return this._dom}get cssClassName(){return this._cssClassName||=i(this.tag),this._cssClassName}getText(){return this._dom.textContent}text(e){return this._dom.textContent=String(e),this}resolveNode(e){return typeof e==`string`||typeof e==`number`?String(e):e.dom}add(...e){return this._dom.append(...e.map(e=>this.resolveNode(e))),this}insertAtIndex(e,...t){let n=Array.from(this.dom.children),r=Math.max(0,Math.min(e,n.length));for(let e of t){let t=n[r]??null;this.dom.insertBefore(this.resolveNode(e),t),r++}return this}setChildren(...e){return this.clear().add(...e)}setChildrenFromIndex(e,...t){let n=Array.from(this._dom.children),r=n.length,i=Math.max(0,Math.min(e,r));for(let e=i;e<r;e++)this._dom.removeChild(n[e]);let a=this._dom.children[i]??null;for(let e of t)this._dom.insertBefore(this.resolveNode(e),a);return this}remove(){this.dom.remove()}clear(e,t){let n=Array.from(this._dom.children),r=Math.max(0,e??0),i=Math.min(n.length,t??n.length);for(let e=r;e<i;e++)this._dom.removeChild(n[e]);return this}on(e,t,n){return this._dom.addEventListener(e,t,n),this}off(e,t,n){return this._dom.removeEventListener(e,t,n)}attr(e){for(let t in e)this._dom.setAttribute(t,e[t]);return this}props(e){for(let t in e){let n=e[t];this._dom[t]=n}return this}prop(e,t){return this._dom[e]=t,this}getProp(e){return this._dom[e]}style(e){for(let t in e)this._dom.style[t]=this.getStyleValue(t,e[t]);return this}id(e){return this._dom.id=e,this}className(e){return this._userClassName=e,this._dom.className=this._cssClassName?`${e} ${this.cssClassName}`:e,this}htmlFor(e){return this._tag===`label`&&(this._dom.htmlFor=e),this}title(e){return this.dom.title=e,this}setStyleProp(e,t){return t===void 0?(this.dom.style.removeProperty(o(e)),this):(this.dom.style.setProperty(o(e),this.getStyleValue(e,t)),this)}p(e){return this.setStyleProp(`padding`,e)}pt(e){return this.setStyleProp(`paddingTop`,e)}pr(e){return this.setStyleProp(`paddingRight`,e)}pb(e){return this.setStyleProp(`paddingBottom`,e)}pl(e){return this.setStyleProp(`paddingLeft`,e)}px(e){return this.pl(e).pr(e)}py(e){return this.pt(e).pb(e)}m(e){return this.setStyleProp(`margin`,e)}mt(e){return this.setStyleProp(`marginTop`,e)}mr(e){return this.setStyleProp(`marginRight`,e)}mb(e){return this.setStyleProp(`marginBottom`,e)}ml(e){return this.setStyleProp(`marginLeft`,e)}radius(e){return this.setStyleProp(`borderRadius`,e)}radiusTopLeft(e){return this.setStyleProp(`borderTopLeftRadius`,e)}radiusTopRight(e){return this.setStyleProp(`borderTopRightRadius`,e)}radiusTop(e){return this.radiusTopLeft(e).radiusTopRight(e)}display(e){return this.setStyleProp(`display`,e)}flexShrink(e){return this.setStyleProp(`flexShrink`,e)}flex(e){return this.setStyleProp(`flex`,e)}bgColor(e){return this.setStyleProp(`backgroundColor`,e)}color(e){return this.setStyleProp(`color`,e)}h(e){return this.setStyleProp(`height`,e)}w(e){return this.setStyleProp(`width`,e)}b(e){return this.setStyleProp(`border`,e)}bt(e){return this.setStyleProp(`borderTop`,e)}br(e){return this.setStyleProp(`borderRight`,e)}bb(e){return this.setStyleProp(`borderBottom`,e)}bl(e){return this.setStyleProp(`borderLeft`,e)}overflow(e){return this.setStyleProp(`overflow`,e)}overflowY(e){return this.setStyleProp(`overflowY`,e)}overflowX(e){return this.setStyleProp(`overflowX`,e)}fontSize(e){return this.setStyleProp(`fontSize`,e)}fontWeight(e){return this.setStyleProp(`fontWeight`,e)}fontFamily(e){return this.setStyleProp(`fontFamily`,e)}fontStyle(e){return this.setStyleProp(`fontStyle`,e)}textAlign(e){return this.setStyleProp(`textAlign`,e)}textDecoration(e){return this.setStyleProp(`textDecoration`,e)}pos(e){return this.setStyleProp(`position`,e)}posTop(e){return this.setStyleProp(`top`,e)}posBottom(e){return this.setStyleProp(`bottom`,e)}posLeft(e){return this.setStyleProp(`left`,e)}posRight(e){return this.setStyleProp(`right`,e)}cursor(e){return this.setStyleProp(`cursor`,e)}alignItems(e){return this.setStyleProp(`alignItems`,e)}justifyContent(e){return this.setStyleProp(`justifyContent`,e)}gap(e){return this.setStyleProp(`gap`,e)}flexDirection(e){return this.setStyleProp(`flexDirection`,e)}templateColumns(e){return this.setStyleProp(`gridTemplateColumns`,e)}templateRows(e){return this.setStyleProp(`gridTemplateRows`,e)}appearance(e){return this.setStyleProp(`appearance`,e)}overflowEllipsis(){return this.style({overflow:`hidden`,whiteSpace:`nowrap`,textOverflow:`ellipsis`})}ref(e){return e(this),this}rootCss(e){return this.css(``,e)}hoverCss(e){return this.css(`:hover`,e)}activeCss(e){return this.css(`:active`,e)}focusCss(e){return this.css(`:focus`,e)}setCssClassName(){return this.dom.className=this._userClassName?`${this._userClassName} ${this.cssClassName}`:this.cssClassName,this}setRuleCss(e,n){for(let r in n){let i=!!t[r],a=o(r);e.style.setProperty(i?`-${a}`:a,this.getStyleValue(r,n[r]))}}css(e,t){this.setCssClassName();let n=this._sheet.getCssRule(`.${this.cssClassName}${e}`);return this.setRuleCss(n,t),this}mediaCss(e,t,n){this.setCssClassName();let r=this._sheet.getMediaRule(e).getCssRule(`.${this.cssClassName}${t}`);return this.setRuleCss(r,n),this}mediaRootCss(e,t){return this.mediaCss(e,``,t)}minWidthCss(e,t){return this.mediaCss(`min-width:${this.getStyleValue(`width`,e)}`,``,t)}maxWidthCss(e,t){return this.mediaCss(`max-width:${this.getStyleValue(`width`,e)}`,``,t)}getStyleValue(t,n){return typeof n==`number`?e[t]?String(n):`${n}px`:n}};function c(e){return new s(e)}function l(e){let t=document.querySelector(e);return new s(t.tagName.toLowerCase(),t)}var u=class extends s{constructor(){super(`a`)}href(e){return this._dom.href=e,this}},d=class extends s{constructor(){super(`button`)}type(e){return this.dom.type=e,this}},f=class extends s{constructor(e){super(`canvas`,e)}_size={width:this._dom.width,height:this._dom.height};getWidth(){return this._dom.width}getHeight(){return this._dom.height}width(e){return this._dom.width=e,this}height(e){return this._dom.height=e,this}setSize(e,t){return this._dom.width=e,this._dom.height=t,this}getSize(){return this._size.width=this._dom.width,this._size.height=this._dom.height,this._size}getAspect(){return this._dom.width/this._dom.height}getAspectScale(e){let t=this._dom.width/this._dom.height,n,r,i;return t>=1?(n=1/t,r=1,i=1):(n=1,r=t,i=1),e.x=n,e.y=r,e.z=i,e}},p=class{get dom(){return document.body}style(e){for(let t in e)this.dom.style[t]=this.getStyleValue(t,e[t]);return this}getStyleValue(t,n){return typeof n==`number`?e[t]?String(n):`${n}px`:n}add(...e){return this.dom.append(...e.map(e=>e.dom)),this}clear(){return this.dom.innerHTML=``,this}};function m(){return new p}var h=class extends s{constructor(){super(`iframe`)}src(e){return this._dom.src=e,this}allowFullscreen(e=!0){return this._dom.allowFullscreen=e,this}width(e){return this._dom.width=this.getStyleValue(`width`,e),this}height(e){return this._dom.height=this.getStyleValue(`height`,e),this}setSize(e,t){return this._dom.width=this.getStyleValue(`width`,e),this._dom.height=this.getStyleValue(`height`,t),this}reload(){this.dom.src=this.dom.src}},g=class extends s{constructor(){super(`img`)}src(e){return this._dom.src=e,this}width(e){return this._dom.width=e,this}height(e){return this._dom.height=e,this}setSize(e,t){return this._dom.width=e,this._dom.height=t,this}alt(e){return this.dom.alt=e,this}},_=class extends s{constructor(){super(`input`),this._dom.type=`checkbox`}name(e){return this._dom.name=e,this}checked(e){return this.prop(`checked`,e),this}isChecked(){return this.getProp(`checked`)}},v=class extends s{constructor(){super(`input`),this._dom.type=`color`}_rgb={r:1,g:1,b:1};name(e){return this._dom.name=e,this}value(e){return this._dom.value=e,this}getValue(){return this._dom.value}getRGB(){let e=this._dom.value,t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16);return this._rgb.r=t,this._rgb.g=n,this._rgb.b=r,this._rgb}getNormalizedRGB(){let e=this._dom.value,t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16);return this._rgb.r=t/255,this._rgb.g=n/255,this._rgb.b=r/255,this._rgb}},y=class extends s{constructor(){super(`input`),this._dom.type=`number`}name(e){return this._dom.name=e,this}value(e){return this._dom.value=String(e),this}getValue(){return Number(this._dom.value)}min(e){return this._dom.min=String(e),this}max(e){return this._dom.max=String(e),this}step(e){return this._dom.step=String(e),this}placeholder(e){return this.dom.placeholder=e,this}},b=class extends s{constructor(){super(`input`),this._dom.type=`range`}name(e){return this._dom.name=e,this}value(e){return this._dom.value=String(e),this}getValue(){return Number(this._dom.value)}min(e){return this._dom.min=String(e),this}max(e){return this._dom.max=String(e),this}step(e){return this._dom.step=String(e),this}},x=class extends s{constructor(){super(`input`),this._dom.type=`text`}name(e){return this._dom.name=e,this}value(e){return this._dom.value=e,this}getValue(){return this._dom.value}placeholder(e){return this.dom.placeholder=e,this}},S=class extends s{constructor(){super(`option`)}value(e){return this.dom.value=String(e),this}getValue(){return this.dom.value}},C=class extends s{constructor(){super(`progress`)}value(e){return this.dom.value=e,this}getValue(){return this.dom.value}max(e){return this.dom.max=e,this}getMax(){return this.dom.max}indeterminate(){return this.dom.removeAttribute(`value`),this}},w=class extends s{constructor(){super(`select`)}name(e){return this.dom.name=e,this}value(e){return this.dom.value=String(e),this}getValue(){return this.dom.value}};export{c as $,m as $body,l as $select,u as AnchorElement,d as Button,f as Canvas,p as DomBody,s as DomElement,h as IFrame,g as ImageElement,_ as InputCheckbox,v as InputColor,y as InputNumber,b as InputRange,x as InputText,S as OptionElement,C as ProgressElement,w as SelectElement,r as StyleSheet,e as UNITLESS_CSS_PROPS,t as VENDOR_CSS_PROPS,o as camelToKebab,i as uniqueId};
|
|
1
|
+
const e={opacity:1,zIndex:1,fontWeight:1,lineHeight:1,flexGrow:1,flexShrink:1,order:1,zoom:1,scale:1,counterIncrement:1,counterReset:1,tabSize:1,orphans:1,widows:1,columns:1,columnCount:1,gridRow:1,gridColumn:1},t={WebkitAppearance:1},n=`svg.svgA.animate.animateMotion.animateTransform.circle.clipPath.defs.desc.ellipse.feBlend.feColorMatrix.feComponentTransfer.feComposite.feConvolveMatrix.feDiffuseLighting.feDisplacementMap.feDistantLight.feDropShadow.feFlood.feFuncA.feFuncB.feFuncG.feFuncR.feGaussianBlur.feImage.feMerge.feMergeNode.feMorphology.feOffset.fePointLight.feSpecularLighting.feSpotLight.feTile.feTurbulence.filter.foreignObject.g.image.line.linearGradient.marker.mask.metadata.mpath.path.pattern.polygon.polyline.radialGradient.rect.script.set.stop.style.switch.symbol.text.textPath.title.tspan.use.view`.split(`.`),r={svgA:`a`};var i=class{constructor(e,t){this._index=e,this._rule=t,this.cssMap=new Map}_index;_rule;cssMap;get index(){return this._index}get rule(){return this._rule}get length(){return this._rule.cssRules.length}getCssRule(e){let t=this.cssMap.get(e);return t??=this._rule.insertRule(`${e}{}`,this.length),this._rule.cssRules.item(t)}delete(e){this._rule.deleteRule(e)}};function a(){return`${Date.now().toString(36)}-${(o++).toString(36)}`}let o=0;function s(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).toLowerCase()}var c=class n{constructor(e){this._dom=e}_dom;get dom(){return this._dom}get sheet(){return this.dom.sheet}get length(){return this.sheet.cssRules.length}globalCss(e,t){let n=this.getCssRule(e);this.setRuleCss(n,t)}globalMediaCss(e,t,n){let r=this.getMediaRule(e).getCssRule(t);this.setRuleCss(r,n)}getCssRule(e){let t=this.getCssMap(),n=t.get(e);return n??(n=this.sheet.cssRules.length,this.sheet.insertRule(`${e}{}`,n),t.set(e,n)),this.sheet.cssRules.item(n)}deleteCssRule(e){let t=this.getCssMap(),n=t.get(e);n!=null&&(this.sheet.deleteRule(n),t.delete(e))}getMediaRule(e){let t=this.getMediaMap(),n=t.get(e);if(!n){let r=this.sheet.cssRules.length;this.sheet.insertRule(`@media(${e}){}`,r),n=new i(r,this.sheet.cssRules.item(r)),t.set(e,n)}return n}deleteMediaRule(e){let t=this.getMediaMap(),n=t.get(e);n!=null&&(this.sheet.deleteRule(n.index),t.delete(e))}setRuleCss(e,n){for(let r in n){let i=!!t[r],a=s(r);e.style.setProperty(i?`-${a}`:a,this.getStyleValue(r,n[r]))}}getStyleValue(t,n){return typeof n==`number`?e[t]?String(n):`${n}px`:n}getCssMap(){let e=l.get(this.sheet);return e||(e=new Map,l.set(this.sheet,e)),e}getMediaMap(){let e=u.get(this.sheet);return e||(e=new Map,u.set(this.sheet,e)),e}static getSheet(e=n.DEFAULT_STYLE_ID){let t=document.head.querySelector(`#${e}`);if(t==null){let t=document.createElement(`style`);return t.id=e,t.setAttribute(`type`,`text/css`),document.head.append(t),new n(t)}else return new n(t)}static DEFAULT_STYLE_ID=`__neptune-style__`};const l=new WeakMap,u=new WeakMap;var d=class{constructor(e,t){this._tag=r[e]??e,this._isSvg=n.includes(this._tag),this._dom=t??(this._isSvg?document.createElementNS(`http://www.w3.org/2000/svg`,this._tag):document.createElement(this._tag)),this._sheet=c.getSheet()}_tag;_isSvg;_dom;_sheet;_cssClassName;_userClassName;get tag(){return this._tag}get isSvg(){return this._isSvg}get dom(){return this._dom}get cssClassName(){return this._cssClassName||=a(),this._cssClassName}getText(){return this._dom.textContent}text(e){return this._dom.textContent=e==null?``:String(e),this}add(...e){return this._dom.append(...e.map(e=>this.resolveNode(e))),this}insertAtIndex(e,...t){let n=Array.from(this.dom.children),r=Math.max(0,Math.min(e,n.length));for(let e of t){let t=n[r]??null;this.dom.insertBefore(this.resolveNode(e),t),r++}return this}setChildren(...e){return this.clear().add(...e)}setChildrenFromIndex(e,...t){let n=Array.from(this._dom.children),r=n.length,i=Math.max(0,Math.min(e,r));for(let e=i;e<r;e++)this._dom.removeChild(n[e]);let a=this._dom.children[i]??null;for(let e of t)this._dom.insertBefore(this.resolveNode(e),a);return this}remove(){this.dom.remove()}clear(e,t){let n=Array.from(this._dom.children),r=Math.max(0,e??0),i=Math.min(n.length,t??n.length);for(let e=r;e<i;e++)this._dom.removeChild(n[e]);return this}on(e,t,n){return this._dom.addEventListener(e,t,n),this}off(e,t,n){this._dom.removeEventListener(e,t,n)}getAttr(e){return this.dom.getAttribute(e)}attr(e,t){return t===void 0?this.dom.removeAttribute(e):this.dom.setAttribute(e,String(t)),this}attrs(e){for(let[t,n]of Object.entries(e))this.attr(t,n);return this}getProp(e){return this.dom[e]}prop(e,t){return this.dom[e]=t,this}props(e){for(let[t,n]of Object.entries(e))this.prop(t,n);return this}style(e){for(let t of Object.keys(e))this.setStyleProp(t,e[t]);return this}id(e){return this._dom.id=e??``,this}className(e){this._userClassName=e??``;let t=this._cssClassName?`${this._userClassName} ${this.cssClassName}`.trim():this._userClassName;return this.dom.setAttribute(`class`,t),this}htmlFor(e){return this.tag===`label`&&(this.dom.htmlFor=e??``),this}title(e){return e===void 0?this.dom.removeAttribute(`title`):this.dom.setAttribute(`title`,e),this}disabled(e){return e?this.dom.setAttribute(`disabled`,``):this.dom.removeAttribute(`disabled`),this}disable(){return this.disabled(!0)}enable(){return this.disabled(!1)}p(e){return this.setStyleProp(`padding`,e)}pt(e){return this.setStyleProp(`paddingTop`,e)}pr(e){return this.setStyleProp(`paddingRight`,e)}pb(e){return this.setStyleProp(`paddingBottom`,e)}pl(e){return this.setStyleProp(`paddingLeft`,e)}px(e){return this.pl(e).pr(e)}py(e){return this.pt(e).pb(e)}m(e){return this.setStyleProp(`margin`,e)}mt(e){return this.setStyleProp(`marginTop`,e)}mr(e){return this.setStyleProp(`marginRight`,e)}mb(e){return this.setStyleProp(`marginBottom`,e)}ml(e){return this.setStyleProp(`marginLeft`,e)}radius(e){return this.setStyleProp(`borderRadius`,e)}radiusTopLeft(e){return this.setStyleProp(`borderTopLeftRadius`,e)}radiusTopRight(e){return this.setStyleProp(`borderTopRightRadius`,e)}radiusBottomLeft(e){return this.setStyleProp(`borderBottomLeftRadius`,e)}radiusBottomRight(e){return this.setStyleProp(`borderBottomRightRadius`,e)}radiusTop(e){return this.radiusTopLeft(e).radiusTopRight(e)}radiusBottom(e){return this.radiusBottomLeft(e).radiusBottomRight(e)}radiusLeft(e){return this.radiusTopLeft(e).radiusBottomLeft(e)}radiusRight(e){return this.radiusTopRight(e).radiusBottomRight(e)}radiusX(e){return this.radiusLeft(e).radiusRight(e)}radiusY(e){return this.radiusTop(e).radiusBottom(e)}display(e){return this.setStyleProp(`display`,e)}flexShrink(e){return this.setStyleProp(`flexShrink`,e)}flex(e){return this.setStyleProp(`flex`,e)}bgColor(e){return this.setStyleProp(`backgroundColor`,e)}color(e){return this.setStyleProp(`color`,e)}w(e){return this.setStyleProp(`width`,e)}h(e){return this.setStyleProp(`height`,e)}b(e){return this.setStyleProp(`border`,e)}bt(e){return this.setStyleProp(`borderTop`,e)}br(e){return this.setStyleProp(`borderRight`,e)}bb(e){return this.setStyleProp(`borderBottom`,e)}bl(e){return this.setStyleProp(`borderLeft`,e)}bx(e){return this.setStyleProp(`borderLeft`,e),this.setStyleProp(`borderRight`,e),this}by(e){return this.setStyleProp(`borderTop`,e),this.setStyleProp(`borderBottom`,e),this}btl(e){return this.setStyleProp(`borderTop`,e),this.setStyleProp(`borderLeft`,e),this}btr(e){return this.setStyleProp(`borderTop`,e),this.setStyleProp(`borderRight`,e),this}bbl(e){return this.setStyleProp(`borderBottom`,e),this.setStyleProp(`borderLeft`,e),this}bbr(e){return this.setStyleProp(`borderBottom`,e),this.setStyleProp(`borderRight`,e),this}overflow(e){return this.setStyleProp(`overflow`,e)}overflowY(e){return this.setStyleProp(`overflowY`,e)}overflowX(e){return this.setStyleProp(`overflowX`,e)}fontSize(e){return this.setStyleProp(`fontSize`,e)}fontWeight(e){return this.setStyleProp(`fontWeight`,e)}fontFamily(e){return this.setStyleProp(`fontFamily`,e)}fontStyle(e){return this.setStyleProp(`fontStyle`,e)}textAlign(e){return this.setStyleProp(`textAlign`,e)}textDecoration(e){return this.setStyleProp(`textDecoration`,e)}pos(e){return this.setStyleProp(`position`,e)}posTop(e){return this.setStyleProp(`top`,e)}posBottom(e){return this.setStyleProp(`bottom`,e)}posLeft(e){return this.setStyleProp(`left`,e)}posRight(e){return this.setStyleProp(`right`,e)}cursor(e){return this.setStyleProp(`cursor`,e)}alignItems(e){return this.setStyleProp(`alignItems`,e)}justifyContent(e){return this.setStyleProp(`justifyContent`,e)}gap(e){return this.setStyleProp(`gap`,e)}flexDirection(e){return this.setStyleProp(`flexDirection`,e)}templateColumns(e){return this.setStyleProp(`gridTemplateColumns`,e)}templateRows(e){return this.setStyleProp(`gridTemplateRows`,e)}appearance(e){return this.setStyleProp(`appearance`,e)}userSelect(e){return this.setStyleProp(`userSelect`,e)}verticalAlign(e){return this.setStyleProp(`verticalAlign`,e)}overflowEllipsis(){return this.style({overflow:`hidden`,whiteSpace:`nowrap`,textOverflow:`ellipsis`})}ref(e){return e(this),this}css(e,t){this.setCssClassName();let n=this._sheet.getCssRule(`.${this.cssClassName}${e}`);return this._sheet.setRuleCss(n,t),this}rootCss(e){return this.css(``,e)}hoverCss(e){return this.css(`:hover`,e)}activeCss(e){return this.css(`:active`,e)}focusCss(e){return this.css(`:focus`,e)}focusWithinCss(e){return this.css(`:focus-within`,e)}mediaCss(e,t,n){this.setCssClassName();let r=this._sheet.getMediaRule(e).getCssRule(`.${this.cssClassName}${t}`);return this._sheet.setRuleCss(r,n),this}mediaRootCss(e,t){return this.mediaCss(e,``,t)}minWidthCss(e,t){return this.mediaCss(`min-width:${this._sheet.getStyleValue(`width`,e)}`,``,t)}maxWidthCss(e,t){return this.mediaCss(`max-width:${this._sheet.getStyleValue(`width`,e)}`,``,t)}resolveNode(e){return typeof e==`string`||typeof e==`number`?document.createTextNode(String(e)):`dom`in e?e.dom:e}setStyleProp(e,t){return t===void 0?(this.dom.style.removeProperty(s(e)),this):(this.dom.style.setProperty(s(e),this._sheet.getStyleValue(e,t)),this)}setCssClassName(){let e=this._userClassName?`${this._userClassName} ${this.cssClassName}`:this.cssClassName;return this.isSvg?this.dom.setAttribute(`class`,e):this.dom.className=e,this}};function f(e){return new d(e)}function p(e){let t=document.querySelector(e);return new d(t.tagName.toLowerCase(),t)}var m=class extends d{constructor(){super(`a`)}href(e){return this._dom.href=e,this}},h=class extends d{constructor(){super(`button`)}type(e){return this.dom.type=e,this}disabledCss(e){return this.css(`:disabled`,e)}},g=class extends d{constructor(e){super(`canvas`,e)}_size={width:this._dom.width,height:this._dom.height};getWidth(){return this._dom.width}getHeight(){return this._dom.height}width(e){return this._dom.width=e,this}height(e){return this._dom.height=e,this}setSize(e,t){return this._dom.width=e,this._dom.height=t,this}getSize(){return this._size.width=this._dom.width,this._size.height=this._dom.height,this._size}getAspect(){return this._dom.width/this._dom.height}getAspectScale(e){let t=this._dom.width/this._dom.height,n,r,i;return t>=1?(n=1/t,r=1,i=1):(n=1,r=t,i=1),e.x=n,e.y=r,e.z=i,e}},_=class{get dom(){return document.body}style(e){for(let t in e)this.dom.style[t]=this.getStyleValue(t,e[t]);return this}getStyleValue(t,n){return typeof n==`number`?e[t]?String(n):`${n}px`:n}add(...e){return this.dom.append(...e.map(e=>e.dom)),this}clear(){return this.dom.innerHTML=``,this}};function v(){return new _}var y=class extends d{constructor(){super(`iframe`)}src(e){return this._dom.src=e,this}allowFullscreen(e=!0){return this._dom.allowFullscreen=e,this}width(e){return this._dom.width=this._sheet.getStyleValue(`width`,e),this}height(e){return this._dom.height=this._sheet.getStyleValue(`height`,e),this}setSize(e,t){return this._dom.width=this._sheet.getStyleValue(`width`,e),this._dom.height=this._sheet.getStyleValue(`height`,t),this}reload(){this.dom.src=this.dom.src}},b=class extends d{constructor(){super(`img`)}src(e){return this._dom.src=e,this}width(e){return this._dom.width=e,this}height(e){return this._dom.height=e,this}setSize(e,t){return this._dom.width=e,this._dom.height=t,this}alt(e){return this.dom.alt=e,this}},x=class extends d{constructor(){super(`input`),this._dom.type=`checkbox`}name(e){return this._dom.name=e,this}checked(e){return this.prop(`checked`,e),this}isChecked(){return this.getProp(`checked`)}disabledCss(e){return this.css(`:disabled`,e)}},S=class extends d{constructor(){super(`input`),this._dom.type=`color`}_rgb={r:1,g:1,b:1};name(e){return this._dom.name=e,this}value(e){return this._dom.value=e,this}getValue(){return this._dom.value}getRGB(){let e=this._dom.value,t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16);return this._rgb.r=t,this._rgb.g=n,this._rgb.b=r,this._rgb}getNormalizedRGB(){let e=this._dom.value,t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16);return this._rgb.r=t/255,this._rgb.g=n/255,this._rgb.b=r/255,this._rgb}disabledCss(e){return this.css(`:disabled`,e)}},C=class extends d{constructor(){super(`input`),this._dom.type=`number`}name(e){return this._dom.name=e,this}value(e){return this._dom.value=String(e),this}getValue(){return Number(this._dom.value)}min(e){return this._dom.min=String(e),this}max(e){return this._dom.max=String(e),this}step(e){return this._dom.step=String(e),this}placeholder(e){return this.dom.placeholder=e,this}disabledCss(e){return this.css(`:disabled`,e)}},w=class extends d{constructor(){super(`input`),this._dom.type=`range`}name(e){return this._dom.name=e,this}value(e){return this._dom.value=String(e),this}getValue(){return Number(this._dom.value)}min(e){return this._dom.min=String(e),this}max(e){return this._dom.max=String(e),this}step(e){return this._dom.step=String(e),this}disabledCss(e){return this.css(`:disabled`,e)}},T=class extends d{constructor(){super(`input`),this._dom.type=`text`}name(e){return this._dom.name=e,this}value(e){return this._dom.value=e,this}getValue(){return this._dom.value}placeholder(e){return this.dom.placeholder=e,this}disabledCss(e){return this.css(`:disabled`,e)}},E=class extends d{constructor(){super(`option`)}value(e){return this.dom.value=String(e),this}getValue(){return this.dom.value}},D=class extends d{constructor(){super(`progress`)}value(e){return this.dom.value=e,this}getValue(){return this.dom.value}max(e){return this.dom.max=e,this}getMax(){return this.dom.max}indeterminate(){return this.dom.removeAttribute(`value`),this}},O=class extends d{constructor(){super(`select`)}name(e){return this.dom.name=e,this}value(e){return this.dom.value=String(e),this}getValue(){return this.dom.value}};export{f as $,v as $body,p as $query,m as AnchorElement,h as Button,g as Canvas,_ as DomBody,d as DomElement,y as IFrame,b as ImageElement,x as InputCheckbox,S as InputColor,C as InputNumber,w as InputRange,T as InputText,i as MediaRule,E as OptionElement,D as ProgressElement,n as SVG_TAGS,O as SelectElement,c as StyleSheet,r as TAG_ALIAS,e as UNITLESS_CSS_PROPS,t as VENDOR_CSS_PROPS,s as camelToKebab,a as uniqueId};
|