@neptune3d/dom 0.0.3 → 0.0.4

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 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.appendChild(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").append(circle);
38
+
39
+ body.appendChild(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,171 @@ 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
+ type Autocomplete<T$1 extends string> = T$1 | (string & {});
19
+ type DomElementChild = DomElement<any> | string | number;
20
+ type DomElementTagNameMap = HTMLElementTagNameMap & SvgElementTagNameMap;
21
+ type SvgElementTagNameMap = {
22
+ svgA: SVGAElement;
23
+ animate: SVGAnimateElement;
24
+ animateMotion: SVGAnimateMotionElement;
25
+ animateTransform: SVGAnimateTransformElement;
26
+ circle: SVGCircleElement;
27
+ clipPath: SVGClipPathElement;
28
+ defs: SVGDefsElement;
29
+ desc: SVGDescElement;
30
+ ellipse: SVGEllipseElement;
31
+ feBlend: SVGFEBlendElement;
32
+ feColorMatrix: SVGFEColorMatrixElement;
33
+ feComponentTransfer: SVGFEComponentTransferElement;
34
+ feComposite: SVGFECompositeElement;
35
+ feConvolveMatrix: SVGFEConvolveMatrixElement;
36
+ feDiffuseLighting: SVGFEDiffuseLightingElement;
37
+ feDisplacementMap: SVGFEDisplacementMapElement;
38
+ feDistantLight: SVGFEDistantLightElement;
39
+ feDropShadow: SVGFEDropShadowElement;
40
+ feFlood: SVGFEFloodElement;
41
+ feFuncA: SVGFEFuncAElement;
42
+ feFuncB: SVGFEFuncBElement;
43
+ feFuncG: SVGFEFuncGElement;
44
+ feFuncR: SVGFEFuncRElement;
45
+ feGaussianBlur: SVGFEGaussianBlurElement;
46
+ feImage: SVGFEImageElement;
47
+ feMerge: SVGFEMergeElement;
48
+ feMergeNode: SVGFEMergeNodeElement;
49
+ feMorphology: SVGFEMorphologyElement;
50
+ feOffset: SVGFEOffsetElement;
51
+ fePointLight: SVGFEPointLightElement;
52
+ feSpecularLighting: SVGFESpecularLightingElement;
53
+ feSpotLight: SVGFESpotLightElement;
54
+ feTile: SVGFETileElement;
55
+ feTurbulence: SVGFETurbulenceElement;
56
+ filter: SVGFilterElement;
57
+ foreignObject: SVGForeignObjectElement;
58
+ g: SVGGElement;
59
+ image: SVGImageElement;
60
+ line: SVGLineElement;
61
+ linearGradient: SVGLinearGradientElement;
62
+ marker: SVGMarkerElement;
63
+ mask: SVGMaskElement;
64
+ metadata: SVGMetadataElement;
65
+ mpath: SVGMPathElement;
66
+ path: SVGPathElement;
67
+ pattern: SVGPatternElement;
68
+ polygon: SVGPolygonElement;
69
+ polyline: SVGPolylineElement;
70
+ radialGradient: SVGRadialGradientElement;
71
+ rect: SVGRectElement;
72
+ script: SVGScriptElement;
73
+ set: SVGSetElement;
74
+ stop: SVGStopElement;
75
+ style: SVGStyleElement;
76
+ svg: SVGSVGElement;
77
+ switch: SVGSwitchElement;
78
+ symbol: SVGSymbolElement;
79
+ text: SVGTextElement;
80
+ textPath: SVGTextPathElement;
81
+ title: SVGTitleElement;
82
+ tspan: SVGTSpanElement;
83
+ use: SVGUseElement;
84
+ view: SVGViewElement;
85
+ };
86
+ type DomElementEventMap = HTMLElementEventMap & SVGElementEventMap;
87
+ //#endregion
16
88
  //#region src/StyleSheet.d.ts
89
+ /**
90
+ * Manages a dedicated `<style>` element and provides programmatic access to its CSS rules.
91
+ * Supports dynamic insertion, retrieval, and deletion of both standard and media-specific rules,
92
+ * with internal indexing for fast lookup and reuse.
93
+ *
94
+ * This class ensures a single shared stylesheet instance via `StyleSheet.getSheet()`,
95
+ * and maintains selector-to-index and media-to-rule maps on the global `window` object.
96
+ *
97
+ * Designed for use with component-level styling systems or DOM abstractions that require
98
+ * granular control over rule injection without relying on inline styles.
99
+ */
17
100
  declare class StyleSheet {
18
101
  constructor(el: HTMLStyleElement);
19
102
  protected _dom: HTMLStyleElement;
20
103
  get dom(): HTMLStyleElement;
21
104
  get sheet(): CSSStyleSheet;
22
105
  get length(): number;
106
+ /**
107
+ * Inserts or updates a global CSS rule for a given selector.
108
+ * @param selector - A global class selector (e.g., ".list-item").
109
+ * @param props - The CSS properties to apply.
110
+ */
111
+ globalCss(selector: string, props: CssProperties): void;
112
+ /**
113
+ * Inserts or updates a global CSS rule inside a media query.
114
+ * @param mediaText - The media query condition (e.g., "max-width: 600px").
115
+ * @param selector - The global class selector.
116
+ * @param props - The CSS properties to apply.
117
+ */
118
+ globalMediaCss(mediaText: string, selector: string, props: CssProperties): void;
23
119
  getCssRule(selector: string): CSSStyleRule;
24
120
  deleteCssRule(selector: string): void;
25
121
  getMediaRule(mediaText: string): MediaRule;
26
122
  deleteMediaRule(mediaText: string): void;
27
123
  static getSheet(): StyleSheet;
124
+ setRuleCss(rule: CSSStyleRule, props: CssProperties): void;
125
+ getStyleValue(name: Autocomplete<keyof CssProperties>, value: string | number): string;
28
126
  protected getCssMap(): Map<string, number>;
29
127
  protected getMediaMap(): Map<string, MediaRule>;
30
128
  static STYLE_ID: string;
31
129
  }
32
130
  //#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
131
  //#region src/DomElement.d.ts
39
- declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLElementTagNameMap> {
40
- constructor(tag: Tag, el?: HTMLElementTagNameMap[Tag]);
41
- protected _tag: Tag;
42
- protected _dom: HTMLElementTagNameMap[Tag];
132
+ /**
133
+ * A unified wrapper for HTML and SVG elements that provides a fluent, type-safe API
134
+ * for DOM manipulation, styling, and event handling.
135
+ *
136
+ * Supports both `HTMLElementTagNameMap` and `SVGElementTagNameMap` via the generic `Tag`,
137
+ * and automatically handles namespace creation for SVG elements.
138
+ *
139
+ * Provides ergonomic methods for setting styles, attributes, classes, and event listeners,
140
+ * while abstracting away platform-specific quirks (e.g., `className` vs `setAttribute("class")`).
141
+ *
142
+ * @template Tag - The tag name of the element, inferred from `DomElementTagNameMap`.
143
+ */
144
+ declare class DomElement<Tag extends keyof DomElementTagNameMap = keyof DomElementTagNameMap> {
145
+ /**
146
+ * Creates a new DomElement instance for the specified tag.
147
+ * Automatically detects whether the tag is an SVG element and uses the appropriate namespace.
148
+ * Optionally wraps an existing DOM element instead of creating a new one.
149
+ *
150
+ * @param tag - The tag name of the element (e.g., "div", "circle", "svg").
151
+ * @param el - An optional existing DOM element to wrap. If omitted, a new element is created.
152
+ */
153
+ constructor(tag: Tag, el?: DomElementTagNameMap[Tag]);
154
+ protected _tag: Tag extends "svgA" ? {
155
+ svgA: "a";
156
+ }[Tag] : Tag;
157
+ protected _isSvg: boolean;
158
+ protected _dom: DomElementTagNameMap[Tag];
43
159
  protected _sheet: StyleSheet;
44
160
  protected _cssClassName: string | undefined;
45
161
  protected _userClassName: string | undefined;
46
- get tag(): Tag;
47
- get dom(): HTMLElementTagNameMap[Tag];
162
+ /**
163
+ * Gets the tag name of the element (e.g., "div", "svg", "circle").
164
+ */
165
+ get tag(): Tag extends "svgA" ? {
166
+ svgA: "a";
167
+ }[Tag] : Tag;
168
+ /**
169
+ * Indicates whether the element is an SVG element.
170
+ * Returns `true` for tags like "svg", "circle", "path", etc.
171
+ */
172
+ get isSvg(): boolean;
173
+ /**
174
+ * Gets the underlying DOM element instance.
175
+ * This will be either an `HTMLElement` or `SVGElement` depending on the tag.
176
+ */
177
+ get dom(): DomElementTagNameMap[Tag];
48
178
  get cssClassName(): string;
49
179
  getText(): string;
50
180
  text(txt: any): this;
51
- protected resolveNode(child: DomElementChild): any;
52
181
  add(...nodes: DomElementChild[]): this;
53
182
  /**
54
183
  * Inserts one or more DomElements into a parent at the specified index.
@@ -86,20 +215,94 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
86
215
  * @returns This DomElement instance.
87
216
  */
88
217
  clear(from?: number, to?: number): this;
89
- on<T extends keyof HTMLElementEventMap>(type: T, handler: (ev: HTMLElementEventMap[T] & {
90
- currentTarget: HTMLElementTagNameMap[Tag];
218
+ /**
219
+ * Adds an event listener to the element.
220
+ * Supports both HTML and SVG elements.
221
+ * @param type - The event type (e.g., "click", "input", "mouseenter").
222
+ * @param handler - The event handler function.
223
+ * @param options - Optional event listener options.
224
+ * @return This DomElement instance for chaining.
225
+ */
226
+ on<T extends keyof DomElementEventMap>(type: T, handler: (ev: DomElementEventMap[T] & {
227
+ currentTarget: DomElementTagNameMap[Tag];
91
228
  }) => void, options?: boolean | AddEventListenerOptions): this;
92
- off<T extends keyof HTMLElementEventMap>(type: T, handler: (ev: HTMLElementEventMap[T]) => void, options?: boolean | EventListenerOptions): void;
93
- attr(obj: Record<string, any>): this;
94
- props(obj: Record<string, any>): this;
95
- prop(name: string, value: any): this;
229
+ /**
230
+ * Removes an event listener from the element.
231
+ * Supports both HTML and SVG elements.
232
+ * @param type - The event type to remove.
233
+ * @param handler - The original handler function.
234
+ * @param options - Optional event listener options.
235
+ */
236
+ off<T extends keyof DomElementEventMap>(type: T, handler: (ev: DomElementEventMap[T]) => void, options?: boolean | EventListenerOptions): void;
237
+ /**
238
+ * Retrieves the value of a single attribute.
239
+ * @param name - The attribute name to read (e.g. "aria-label", "role").
240
+ * @return The attribute value as a string, or null if not present.
241
+ */
242
+ getAttr(name: string): string | null;
243
+ /**
244
+ * Sets a single attribute on the element.
245
+ * @param name - The attribute name (e.g. "aria-label", "role", "disabled").
246
+ * @param value - The attribute value. If undefined, the attribute is removed.
247
+ * @return This DomElement instance for chaining.
248
+ */
249
+ attr(name: string, value: string | number | boolean | undefined): this;
250
+ /**
251
+ * Sets multiple attributes on the element.
252
+ * @param attributes - An object mapping attribute names to values.
253
+ * Attributes with undefined values are removed.
254
+ * @return This DomElement instance for chaining.
255
+ */
256
+ attrs(attributes: Record<string, string | number | boolean | undefined>): this;
257
+ /**
258
+ * Retrieves the value of a single property.
259
+ * @param name - The property name to read (e.g. "value", "checked", "disabled").
260
+ * @return The property value, or undefined if not present.
261
+ */
96
262
  getProp(name: string): any;
263
+ /**
264
+ * Sets a single property on the element.
265
+ * @param name - The property name (e.g. "checked", "value", "disabled").
266
+ * @param value - The property value. If undefined, the property is deleted.
267
+ * @return This DomElement instance for chaining.
268
+ */
269
+ prop(name: string, value: any): this;
270
+ /**
271
+ * Sets multiple properties on the element.
272
+ * @param properties - An object mapping property names to values.
273
+ * Properties with undefined values are deleted.
274
+ * @return This DomElement instance for chaining.
275
+ */
276
+ props(properties: Record<string, any>): this;
97
277
  style(obj: CssProperties): this;
98
278
  id(value: string): this;
279
+ /**
280
+ * Sets the user-defined class name and applies it alongside the internal CSS class.
281
+ * For SVG elements, uses `setAttribute("class", ...)`.
282
+ * @param value - The user-defined class name.
283
+ * @return This DomElement instance for chaining.
284
+ */
99
285
  className(value: string): this;
100
286
  htmlFor(value: string): this;
287
+ /**
288
+ * Sets the title of the element.
289
+ * For HTML elements, sets the `title` property.
290
+ * For SVG elements, sets the `title` attribute.
291
+ * @param value - The tooltip text to show on hover.
292
+ * @return This DomElement instance for chaining.
293
+ */
101
294
  title(value: string): this;
102
- protected setStyleProp(name: Autocomplete<keyof CssProperties>, value: string | number | undefined): this;
295
+ /**
296
+ * Sets the `disabled` attribute to disable the element.
297
+ * Applicable to form controls like <button>, <input>, <select>, etc.
298
+ * @return This DomElement instance for chaining.
299
+ */
300
+ disable(): this;
301
+ /**
302
+ * Removes the `disabled` attribute to enable the element.
303
+ * @return This DomElement instance for chaining.
304
+ */
305
+ enable(): this;
103
306
  p(value: Property.Padding | undefined): this;
104
307
  pt(value: Property.PaddingTop | undefined): this;
105
308
  pr(value: Property.PaddingRight | undefined): this;
@@ -112,10 +315,74 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
112
315
  mr(value: Property.MarginRight | undefined): this;
113
316
  mb(value: Property.MarginBottom | undefined): this;
114
317
  ml(value: Property.MarginLeft | undefined): this;
318
+ /**
319
+ * Sets the overall border radius.
320
+ * @param value - The CSS border-radius value (e.g., "8px", "50%").
321
+ * @return This DomElement instance for chaining.
322
+ */
115
323
  radius(value: Property.BorderRadius | undefined): this;
324
+ /**
325
+ * Sets the top-left corner border radius.
326
+ * @param value - The CSS border-top-left-radius value.
327
+ * @return This DomElement instance for chaining.
328
+ */
116
329
  radiusTopLeft(value: Property.BorderTopLeftRadius | undefined): this;
330
+ /**
331
+ * Sets the top-right corner border radius.
332
+ * @param value - The CSS border-top-right-radius value.
333
+ * @return This DomElement instance for chaining.
334
+ */
117
335
  radiusTopRight(value: Property.BorderTopRightRadius | undefined): this;
336
+ /**
337
+ * Sets the bottom-left corner border radius.
338
+ * @param value - The CSS border-bottom-left-radius value.
339
+ * @return This DomElement instance for chaining.
340
+ */
341
+ radiusBottomLeft(value: Property.BorderBottomLeftRadius | undefined): this;
342
+ /**
343
+ * Sets the bottom-right corner border radius.
344
+ * @param value - The CSS border-bottom-right-radius value.
345
+ * @return This DomElement instance for chaining.
346
+ */
347
+ radiusBottomRight(value: Property.BorderBottomRightRadius | undefined): this;
348
+ /**
349
+ * Sets the border radius for both top corners.
350
+ * @param value - The CSS border-radius value to apply to top-left and top-right corners.
351
+ * @return This DomElement instance for chaining.
352
+ */
118
353
  radiusTop(value: Property.BorderTopLeftRadius | undefined): this;
354
+ /**
355
+ * Sets the border radius for both bottom corners.
356
+ * @param value - The CSS border-radius value to apply to bottom-left and bottom-right corners.
357
+ * @return This DomElement instance for chaining.
358
+ */
359
+ radiusBottom(value: Property.BorderBottomLeftRadius | undefined): this;
360
+ /**
361
+ * Sets the border radius for both left corners.
362
+ * @param value - The CSS border-radius value to apply to top-left and bottom-left corners.
363
+ * @return This DomElement instance for chaining.
364
+ */
365
+ radiusLeft(value: Property.BorderTopLeftRadius | undefined): this;
366
+ /**
367
+ * Sets the border radius for both right corners.
368
+ * @param value - The CSS border-radius value to apply to top-right and bottom-right corners.
369
+ * @return This DomElement instance for chaining.
370
+ */
371
+ radiusRight(value: Property.BorderTopRightRadius | undefined): this;
372
+ /**
373
+ * Sets the border radius for both left and right sides (horizontal corners).
374
+ * Applies to top-left, top-right, bottom-left, and bottom-right corners on the X axis.
375
+ * @param value - The CSS border-radius value to apply horizontally.
376
+ * @return This DomElement instance for chaining.
377
+ */
378
+ radiusX(value: Property.BorderRadius | undefined): this;
379
+ /**
380
+ * Sets the border radius for both top and bottom sides (vertical corners).
381
+ * Applies to top-left, top-right, bottom-left, and bottom-right corners on the Y axis.
382
+ * @param value - The CSS border-radius value to apply vertically.
383
+ * @return This DomElement instance for chaining.
384
+ */
385
+ radiusY(value: Property.BorderRadius | undefined): this;
119
386
  display(value: Property.Display | undefined): this;
120
387
  flexShrink(value: Property.FlexShrink | undefined): this;
121
388
  flex(value: Property.Flex | undefined): this;
@@ -153,6 +420,42 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
153
420
  * @return This DomElement instance for chaining.
154
421
  */
155
422
  bl(value: Property.BorderLeft | undefined): this;
423
+ /**
424
+ * Sets the left and right border styles.
425
+ * @param value - The CSS border value to apply to both left and right sides.
426
+ * @return This DomElement instance for chaining.
427
+ */
428
+ bx(value: Property.BorderLeft | Property.BorderRight | undefined): this;
429
+ /**
430
+ * Sets the top and bottom border styles.
431
+ * @param value - The CSS border value to apply to both top and bottom sides.
432
+ * @return This DomElement instance for chaining.
433
+ */
434
+ by(value: Property.BorderTop | Property.BorderBottom | undefined): this;
435
+ /**
436
+ * Sets the top and left border styles.
437
+ * @param value - The CSS border value to apply to both top and left sides.
438
+ * @return This DomElement instance for chaining.
439
+ */
440
+ btl(value: Property.BorderTop | Property.BorderLeft | undefined): this;
441
+ /**
442
+ * Sets the top and right border styles.
443
+ * @param value - The CSS border value to apply to both top and right sides.
444
+ * @return This DomElement instance for chaining.
445
+ */
446
+ btr(value: Property.BorderTop | Property.BorderRight | undefined): this;
447
+ /**
448
+ * Sets the bottom and left border styles.
449
+ * @param value - The CSS border value to apply to both bottom and left sides.
450
+ * @return This DomElement instance for chaining.
451
+ */
452
+ bbl(value: Property.BorderBottom | Property.BorderLeft | undefined): this;
453
+ /**
454
+ * Sets the bottom and right border styles.
455
+ * @param value - The CSS border value to apply to both bottom and right sides.
456
+ * @return This DomElement instance for chaining.
457
+ */
458
+ bbr(value: Property.BorderBottom | Property.BorderRight | undefined): this;
156
459
  overflow(value: Property.Overflow | undefined): this;
157
460
  overflowY(value: Property.OverflowY | undefined): this;
158
461
  overflowX(value: Property.OverflowX | undefined): this;
@@ -162,10 +465,35 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
162
465
  fontStyle(value: Property.FontStyle | undefined): this;
163
466
  textAlign(value: Property.TextAlign | undefined): this;
164
467
  textDecoration(value: Property.TextDecoration | undefined): this;
468
+ /**
469
+ * Sets the CSS `position` property.
470
+ * @param value - The positioning mode (e.g., "absolute", "relative", "fixed").
471
+ * @return This DomElement instance for chaining.
472
+ */
165
473
  pos(value: Property.Position | undefined): this;
474
+ /**
475
+ * Sets the CSS `top` offset.
476
+ * @param value - The top offset value (e.g., "10px", "50%").
477
+ * @return This DomElement instance for chaining.
478
+ */
166
479
  posTop(value: Property.Top | undefined): this;
480
+ /**
481
+ * Sets the CSS `bottom` offset.
482
+ * @param value - The bottom offset value (e.g., "0", "2rem").
483
+ * @return This DomElement instance for chaining.
484
+ */
167
485
  posBottom(value: Property.Bottom | undefined): this;
486
+ /**
487
+ * Sets the CSS `left` offset.
488
+ * @param value - The left offset value (e.g., "5px", "auto").
489
+ * @return This DomElement instance for chaining.
490
+ */
168
491
  posLeft(value: Property.Left | undefined): this;
492
+ /**
493
+ * Sets the CSS `right` offset.
494
+ * @param value - The right offset value (e.g., "1em", "0").
495
+ * @return This DomElement instance for chaining.
496
+ */
169
497
  posRight(value: Property.Right | undefined): this;
170
498
  cursor(value: Property.Cursor | undefined): this;
171
499
  alignItems(value: Property.AlignItems | undefined): this;
@@ -175,23 +503,40 @@ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLEle
175
503
  templateColumns(value: Property.GridTemplateColumns | undefined): this;
176
504
  templateRows(value: Property.GridTemplateRows | undefined): this;
177
505
  appearance(value: Property.Appearance | undefined): this;
506
+ /**
507
+ * Sets the CSS `user-select` property to control text selection behavior.
508
+ * @param value - The user-select value (e.g., "none", "text", "auto", "contain", "all").
509
+ * @return This DomElement instance for chaining.
510
+ */
511
+ userSelect(value: Property.UserSelect | undefined): this;
178
512
  overflowEllipsis(): this;
179
513
  ref(refFn: (el: this) => void): this;
180
514
  rootCss(props: CssProperties): this;
181
515
  hoverCss(props: CssProperties): this;
182
516
  activeCss(props: CssProperties): this;
183
517
  focusCss(props: CssProperties): this;
184
- protected setCssClassName(): this;
185
- protected setRuleCss(rule: CSSStyleRule, props: CssProperties): void;
186
518
  css(selector: string, props: CssProperties): this;
187
519
  mediaCss(mediaText: string, selector: string, props: CssProperties): this;
188
520
  mediaRootCss(mediaText: string, props: CssProperties): this;
189
521
  minWidthCss(minWidth: number | string, props: CssProperties): this;
190
522
  maxWidthCss(maxWidth: number | string, props: CssProperties): this;
191
- protected getStyleValue(name: Autocomplete<keyof CssProperties>, value: string | number): string;
523
+ protected resolveNode(child: DomElementChild): any;
524
+ protected setStyleProp(name: Autocomplete<keyof CssProperties>, value: string | number | undefined): this;
525
+ protected setCssClassName(): this;
192
526
  }
193
- declare function $<T$1 extends keyof HTMLElementTagNameMap>(tag: T$1): DomElement<T$1>;
194
- declare function $select<T$1 extends keyof HTMLElementTagNameMap>(selector: string): DomElement<T$1>;
527
+ /**
528
+ * Creates a new DomElement instance for the given tag name.
529
+ * @param tag - The HTML tag name (e.g., "div", "button", "input").
530
+ * @return A DomElement wrapping a newly created element of the specified tag.
531
+ */
532
+ declare function $<T$1 extends keyof DomElementTagNameMap>(tag: T$1): DomElement<T$1>;
533
+ /**
534
+ * Queries the DOM for a matching element and wraps it in a DomElement.
535
+ * @param selector - A CSS selector string to locate the element.
536
+ * @return A DomElement wrapping the matched element.
537
+ * @throws If no element matches the selector, this will throw due to non-null assertion.
538
+ */
539
+ declare function $query<T$1 extends keyof DomElementTagNameMap>(selector: string): DomElement<T$1>;
195
540
  //#endregion
196
541
  //#region src/AnchorElement.d.ts
197
542
  declare class AnchorElement extends DomElement<"a"> {
@@ -236,6 +581,11 @@ declare class Canvas extends DomElement<"canvas"> {
236
581
  //#region src/constants.d.ts
237
582
  declare const UNITLESS_CSS_PROPS: Record<string, 1>;
238
583
  declare const VENDOR_CSS_PROPS: Record<string, 1>;
584
+ declare const SVG_TAGS: string[];
585
+ declare const TAG_ALIAS: {
586
+ svgA: "a";
587
+ };
588
+ type TagAlias = typeof TAG_ALIAS;
239
589
  //#endregion
240
590
  //#region src/DomBody.d.ts
241
591
  declare class DomBody {
@@ -387,7 +737,7 @@ declare class SelectElement extends DomElement<"select"> {
387
737
  }
388
738
  //#endregion
389
739
  //#region src/utils.d.ts
390
- declare function uniqueId(prefix: string): string;
740
+ declare function uniqueId(): string;
391
741
  declare function camelToKebab(prop: string): string;
392
742
  //#endregion
393
- export { $, $body, $select, AnchorElement, Autocomplete, Button, Canvas, CssProperties, type CssProperty, DomBody, DomElement, DomElementChild, IFrame, ImageElement, InputCheckbox, InputColor, InputNumber, InputRange, InputText, OptionElement, ProgressElement, SelectElement, StyleSheet, UNITLESS_CSS_PROPS, VENDOR_CSS_PROPS, camelToKebab, uniqueId };
743
+ 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`,`circle`,`rect`,`path`,`line`,`polyline`,`polygon`,`g`,`text`,`defs`,`use`,`symbol`,`clipPath`,`mask`],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.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(),n=t.get(e);if(!n){let r=this.sheet.insertRule(`@media(${e}){}`);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))}static getSheet(){let e=document.head.querySelector(`#${n.STYLE_ID}`);if(e==null){let e=document.createElement(`style`);return e.id=n.STYLE_ID,e.setAttribute(`type`,`text/css`),document.head.append(e),new n(e)}else return new n(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=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__`},l=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=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 in e)this._dom.style[t]=this._sheet.getStyleValue(t,e[t]);return this}id(e){return this._dom.id=e,this}className(e){this._userClassName=e;let t=this._cssClassName?`${e} ${this.cssClassName}`:e;return this.isSvg?this.dom.setAttribute(`class`,t):this.dom.className=t,this}htmlFor(e){return this._tag===`label`&&(this._dom.htmlFor=e),this}title(e){return this.isSvg?this.dom.setAttribute(`title`,e):this.dom.title=e,this}disable(){return this.dom.setAttribute(`disabled`,``),this}enable(){return this.dom.removeAttribute(`disabled`),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)}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)}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)}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)}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)}css(e,t){this.setCssClassName();let n=this._sheet.getCssRule(`.${this.cssClassName}${e}`);return this._sheet.setRuleCss(n,t),this}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`?String(e):e.dom}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 u(e){return new l(e)}function d(e){let t=document.querySelector(e);return new l(t.tagName.toLowerCase(),t)}var f=class extends l{constructor(){super(`a`)}href(e){return this._dom.href=e,this}},p=class extends l{constructor(){super(`button`)}type(e){return this.dom.type=e,this}},m=class extends l{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}},h=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 g(){return new h}var _=class extends l{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}},v=class extends l{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}},y=class extends l{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`)}},b=class extends l{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}},x=class extends l{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}},S=class extends l{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}},C=class extends l{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}},w=class extends l{constructor(){super(`option`)}value(e){return this.dom.value=String(e),this}getValue(){return this.dom.value}},T=class extends l{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}},E=class extends l{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{u as $,g as $body,d as $query,f as AnchorElement,p as Button,m as Canvas,h as DomBody,l as DomElement,_ as IFrame,v as ImageElement,y as InputCheckbox,b as InputColor,x as InputNumber,S as InputRange,C as InputText,i as MediaRule,w as OptionElement,T as ProgressElement,n as SVG_TAGS,E 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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neptune3d/dom",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Helper classes and functions for the DOM.",
5
5
  "type": "module",
6
6
  "license": "MIT",