@neptune3d/dom 0.0.1

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 ADDED
@@ -0,0 +1,3 @@
1
+ # neptune3d/dom
2
+
3
+ Helper classes and functions for the DOM.
@@ -0,0 +1,341 @@
1
+ import { PropertiesFallback, Property, Property as CssProperty } from "csstype";
2
+
3
+ //#region src/MediaRule.d.ts
4
+ declare class MediaRule {
5
+ constructor(index: number, rule: CSSMediaRule);
6
+ protected _index: number;
7
+ protected _rule: CSSMediaRule;
8
+ protected cssMap: Map<string, number>;
9
+ get index(): number;
10
+ get rule(): CSSMediaRule;
11
+ get length(): number;
12
+ getCssRule(selector: string): CSSStyleRule;
13
+ delete(index: number): void;
14
+ }
15
+ //#endregion
16
+ //#region src/StyleSheet.d.ts
17
+ declare class StyleSheet {
18
+ constructor(el: HTMLStyleElement);
19
+ protected _dom: HTMLStyleElement;
20
+ get dom(): HTMLStyleElement;
21
+ get sheet(): CSSStyleSheet;
22
+ get length(): number;
23
+ getCssRule(selector: string): CSSStyleRule;
24
+ deleteCssRule(selector: string): void;
25
+ getMediaRule(mediaText: string): MediaRule;
26
+ deleteMediaRule(mediaText: string): void;
27
+ static getSheet(): StyleSheet;
28
+ protected getCssMap(): Map<string, number>;
29
+ protected getMediaMap(): Map<string, MediaRule>;
30
+ static STYLE_ID: string;
31
+ }
32
+ //#endregion
33
+ //#region src/types.d.ts
34
+ type CssProperties = PropertiesFallback<string | number>;
35
+ type Autocomplete<T$1 extends string> = T$1 | (string & {});
36
+ //#endregion
37
+ //#region src/DomElement.d.ts
38
+ declare class DomElement<Tag extends keyof HTMLElementTagNameMap = keyof HTMLElementTagNameMap> {
39
+ constructor(tag: Tag, el?: HTMLElementTagNameMap[Tag]);
40
+ protected _tag: Tag;
41
+ protected _dom: HTMLElementTagNameMap[Tag];
42
+ protected _sheet: StyleSheet;
43
+ protected _cssClassName: string | undefined;
44
+ protected _userClassName: string | undefined;
45
+ get tag(): Tag;
46
+ get dom(): HTMLElementTagNameMap[Tag];
47
+ get cssClassName(): string;
48
+ getText(): string;
49
+ text(txt: any): this;
50
+ add(...nodes: DomElement<any>[]): this;
51
+ /**
52
+ * Inserts one or more DomElements into a parent at the specified index.
53
+ * Each node is inserted sequentially starting from the given index.
54
+ *
55
+ * @param index - The zero-based index at which to start inserting.
56
+ * @param nodes - One or more DomElements to insert.
57
+ * @return This DomElement instance.
58
+ */
59
+ insertAtIndex(index: number, ...nodes: DomElement<any>[]): this;
60
+ /**
61
+ * Replaces all existing child elements of this DOM node with the provided ones.
62
+ * Internally clears the current children and appends the new nodes in order.
63
+ *
64
+ * @param nodes - One or more DomElement instances to set as children.
65
+ * @return This DomElement instance.
66
+ */
67
+ setChildren(...nodes: DomElement<any>[]): this;
68
+ /**
69
+ * Replaces child elements starting from the specified index with the provided nodes.
70
+ * All children before the index are preserved.
71
+ *
72
+ * @param index - The zero-based index at which replacement begins.
73
+ * @param nodes - One or more DomElement instances to insert.
74
+ * @return This DomElement instance.
75
+ */
76
+ setChildrenFromIndex(index: number, ...nodes: DomElement<any>[]): this;
77
+ remove(): void;
78
+ /**
79
+ * Removes child elements within the specified index range.
80
+ * If no range is provided, removes all children.
81
+ *
82
+ * @param from - The starting index (inclusive). Defaults to 0.
83
+ * @param to - The ending index (exclusive). Defaults to all children.
84
+ * @returns This DomElement instance.
85
+ */
86
+ clear(from?: number, to?: number): this;
87
+ on<T extends keyof HTMLElementEventMap>(type: T, handler: (ev: HTMLElementEventMap[T] & {
88
+ currentTarget: HTMLElementTagNameMap[Tag];
89
+ }) => void, options?: boolean | AddEventListenerOptions): this;
90
+ off<T extends keyof HTMLElementEventMap>(type: T, handler: (ev: HTMLElementEventMap[T]) => void, options?: boolean | EventListenerOptions): void;
91
+ attr(obj: Record<string, any>): this;
92
+ props(obj: Record<string, any>): this;
93
+ prop(name: string, value: any): this;
94
+ getProp(name: string): any;
95
+ style(obj: CssProperties): this;
96
+ id(value: string): this;
97
+ className(value: string): this;
98
+ htmlFor(value: string): this;
99
+ title(value: string): this;
100
+ protected setStyleProp(name: Autocomplete<keyof CssProperties>, value: string | number | undefined): this;
101
+ p(value: Property.Padding | undefined): this;
102
+ pt(value: Property.PaddingTop | undefined): this;
103
+ pr(value: Property.PaddingRight | undefined): this;
104
+ pb(value: Property.PaddingBottom | undefined): this;
105
+ pl(value: Property.PaddingLeft | undefined): this;
106
+ px(value: Property.PaddingLeft | undefined): this;
107
+ py(value: Property.PaddingTop | undefined): this;
108
+ m(value: Property.Margin | undefined): this;
109
+ mt(value: Property.MarginTop | undefined): this;
110
+ mr(value: Property.MarginRight | undefined): this;
111
+ mb(value: Property.MarginBottom | undefined): this;
112
+ ml(value: Property.MarginLeft | undefined): this;
113
+ radius(value: Property.BorderRadius | undefined): this;
114
+ radiusTopLeft(value: Property.BorderTopLeftRadius | undefined): this;
115
+ radiusTopRight(value: Property.BorderTopRightRadius | undefined): this;
116
+ radiusTop(value: Property.BorderTopLeftRadius | undefined): this;
117
+ display(value: Property.Display | undefined): this;
118
+ flexShrink(value: Property.FlexShrink | undefined): this;
119
+ flex(value: Property.Flex | undefined): this;
120
+ bgColor(value: Property.BackgroundColor | undefined): this;
121
+ color(value: Property.Color | undefined): this;
122
+ h(value: Property.Height | number | undefined): this;
123
+ w(value: Property.Width | number | undefined): this;
124
+ b(value: Property.Border | undefined): this;
125
+ br(value: Property.BorderRight | undefined): this;
126
+ overflow(value: Property.Overflow | undefined): this;
127
+ overflowY(value: Property.OverflowY | undefined): this;
128
+ overflowX(value: Property.OverflowX | undefined): this;
129
+ fontSize(value: Property.FontSize | undefined): this;
130
+ fontWeight(value: Property.FontWeight | undefined): this;
131
+ fontFamily(value: Property.FontFamily | undefined): this;
132
+ fontStyle(value: Property.FontStyle | undefined): this;
133
+ textAlign(value: Property.TextAlign | undefined): this;
134
+ textDecoration(value: Property.TextDecoration | undefined): this;
135
+ pos(value: Property.Position | undefined): this;
136
+ posTop(value: Property.Top | undefined): this;
137
+ posBottom(value: Property.Bottom | undefined): this;
138
+ posLeft(value: Property.Left | undefined): this;
139
+ posRight(value: Property.Right | undefined): this;
140
+ cursor(value: Property.Cursor | undefined): this;
141
+ alignItems(value: Property.AlignItems | undefined): this;
142
+ justifyContent(value: Property.JustifyContent | undefined): this;
143
+ gap(value: Property.Gap | undefined): this;
144
+ flexDirection(value: Property.FlexDirection | undefined): this;
145
+ templateColumns(value: Property.GridTemplateColumns | undefined): this;
146
+ templateRows(value: Property.GridTemplateRows | undefined): this;
147
+ appearance(value: Property.Appearance | undefined): this;
148
+ overflowEllipsis(): this;
149
+ ref(refFn: (el: this) => void): this;
150
+ rootCss(props: CssProperties): this;
151
+ hoverCss(props: CssProperties): this;
152
+ activeCss(props: CssProperties): this;
153
+ focusCss(props: CssProperties): this;
154
+ protected setCssClassName(): this;
155
+ protected setRuleCss(rule: CSSStyleRule, props: CssProperties): void;
156
+ css(selector: string, props: CssProperties): this;
157
+ mediaCss(mediaText: string, selector: string, props: CssProperties): this;
158
+ mediaRootCss(mediaText: string, props: CssProperties): this;
159
+ minWidthCss(minWidth: number | string, props: CssProperties): this;
160
+ maxWidthCss(maxWidth: number | string, props: CssProperties): this;
161
+ protected getStyleValue(name: Autocomplete<keyof CssProperties>, value: string | number): string;
162
+ }
163
+ declare function $<T$1 extends keyof HTMLElementTagNameMap>(tag: T$1): DomElement<T$1>;
164
+ declare function $select<T$1 extends keyof HTMLElementTagNameMap>(selector: string): DomElement<T$1>;
165
+ declare function $wrap<T$1 extends keyof HTMLElementTagNameMap = "div">(tag: T$1, ...nodes: DomElement[]): DomElement<T$1>;
166
+ //#endregion
167
+ //#region src/AnchorElement.d.ts
168
+ declare class AnchorElement extends DomElement<"a"> {
169
+ constructor();
170
+ href(value: string): this;
171
+ }
172
+ //#endregion
173
+ //#region src/Button.d.ts
174
+ declare class Button extends DomElement<"button"> {
175
+ constructor();
176
+ type(value: "button" | "submit" | "reset"): this;
177
+ }
178
+ //#endregion
179
+ //#region src/Canvas.d.ts
180
+ declare class Canvas extends DomElement<"canvas"> {
181
+ constructor(el?: HTMLCanvasElement);
182
+ protected _size: {
183
+ width: number;
184
+ height: number;
185
+ };
186
+ getWidth(): number;
187
+ getHeight(): number;
188
+ width(value: number): this;
189
+ height(value: number): this;
190
+ setSize(width: number, height: number): this;
191
+ getSize(): {
192
+ width: number;
193
+ height: number;
194
+ };
195
+ getAspect(): number;
196
+ getAspectScale(target: {
197
+ x: number;
198
+ y: number;
199
+ z: number;
200
+ }): {
201
+ x: number;
202
+ y: number;
203
+ z: number;
204
+ };
205
+ }
206
+ //#endregion
207
+ //#region src/constants.d.ts
208
+ declare const UNITLESS_CSS_PROPS: Record<string, 1>;
209
+ declare const VENDOR_CSS_PROPS: Record<string, 1>;
210
+ //#endregion
211
+ //#region src/DomBody.d.ts
212
+ declare class DomBody {
213
+ get dom(): HTMLBodyElement;
214
+ style(obj: CssProperties): this;
215
+ protected getStyleValue(name: string, value: string | number): string;
216
+ add(...nodes: DomElement<any>[]): this;
217
+ clear(): this;
218
+ }
219
+ //#endregion
220
+ //#region src/Flex.d.ts
221
+ declare class Flex<T$1 extends keyof HTMLElementTagNameMap = "div"> extends DomElement<T$1> {
222
+ constructor(tag?: T$1);
223
+ alignItems(value?: Property.AlignItems): this;
224
+ justifyContent(value?: Property.JustifyContent): this;
225
+ gap(value: Property.Gap): this;
226
+ direction(value: Property.FlexDirection): this;
227
+ }
228
+ //#endregion
229
+ //#region src/Grid.d.ts
230
+ declare class Grid<T$1 extends keyof HTMLElementTagNameMap = "div"> extends DomElement<T$1> {
231
+ constructor(tag?: T$1);
232
+ templateColumns(value: Property.GridTemplateColumns): this;
233
+ templateRows(value: Property.GridTemplateRows): this;
234
+ gap(value: Property.Gap): this;
235
+ alignItems(value?: Property.AlignItems): this;
236
+ }
237
+ //#endregion
238
+ //#region src/IFrame.d.ts
239
+ declare class IFrame extends DomElement<"iframe"> {
240
+ constructor();
241
+ src(value: string): this;
242
+ allowFullscreen(value?: boolean): this;
243
+ width(value: number): this;
244
+ height(value: number): this;
245
+ setSize(width: number, height: number): this;
246
+ reload(): void;
247
+ }
248
+ //#endregion
249
+ //#region src/ImageElement.d.ts
250
+ declare class ImageElement extends DomElement<"img"> {
251
+ constructor();
252
+ src(value: string): this;
253
+ width(value: number): this;
254
+ height(value: number): this;
255
+ setSize(width: number, height: number): this;
256
+ alt(value: string): this;
257
+ }
258
+ //#endregion
259
+ //#region src/InputCheckbox.d.ts
260
+ declare class InputCheckbox extends DomElement<"input"> {
261
+ constructor();
262
+ name(value: string): this;
263
+ checked(value: boolean): this;
264
+ isChecked(): boolean;
265
+ }
266
+ //#endregion
267
+ //#region src/InputColor.d.ts
268
+ declare class InputColor extends DomElement<"input"> {
269
+ constructor();
270
+ protected _rgb: {
271
+ r: number;
272
+ g: number;
273
+ b: number;
274
+ };
275
+ name(value: string): this;
276
+ value(value: string): this;
277
+ getValue(): string;
278
+ getRGB(): {
279
+ r: number;
280
+ g: number;
281
+ b: number;
282
+ };
283
+ getNormalizedRGB(): {
284
+ r: number;
285
+ g: number;
286
+ b: number;
287
+ };
288
+ }
289
+ //#endregion
290
+ //#region src/InputNumber.d.ts
291
+ declare class InputNumber extends DomElement<"input"> {
292
+ constructor();
293
+ name(value: string): this;
294
+ value(value: number): this;
295
+ getValue(): number;
296
+ min(value: number): this;
297
+ max(value: number): this;
298
+ step(value: number): this;
299
+ placeholder(value: string): this;
300
+ }
301
+ //#endregion
302
+ //#region src/InputRange.d.ts
303
+ declare class InputRange extends DomElement<"input"> {
304
+ constructor();
305
+ name(value: string): this;
306
+ value(value: number): this;
307
+ getValue(): number;
308
+ min(value: number): this;
309
+ max(value: number): this;
310
+ step(value: number): this;
311
+ }
312
+ //#endregion
313
+ //#region src/InputText.d.ts
314
+ declare class InputText extends DomElement<"input"> {
315
+ constructor();
316
+ name(value: string): this;
317
+ value(value: string): this;
318
+ getValue(): string;
319
+ placeholder(value: string): this;
320
+ }
321
+ //#endregion
322
+ //#region src/OptionElement.d.ts
323
+ declare class OptionElement extends DomElement<"option"> {
324
+ constructor();
325
+ value(value: string | number): this;
326
+ getValue(): string;
327
+ }
328
+ //#endregion
329
+ //#region src/SelectElement.d.ts
330
+ declare class SelectElement extends DomElement<"select"> {
331
+ constructor();
332
+ name(value: string): this;
333
+ value(value: string | number): this;
334
+ getValue(): string;
335
+ }
336
+ //#endregion
337
+ //#region src/utils.d.ts
338
+ declare function uniqueId(prefix: string): string;
339
+ declare function camelToKebab(prop: string): string;
340
+ //#endregion
341
+ export { $, $select, $wrap, AnchorElement, Autocomplete, Button, Canvas, CssProperties, type CssProperty, DomBody, DomElement, Flex, Grid, IFrame, ImageElement, InputCheckbox, InputColor, InputNumber, InputRange, InputText, OptionElement, SelectElement, StyleSheet, UNITLESS_CSS_PROPS, VENDOR_CSS_PROPS, camelToKebab, uniqueId };
package/dist/index.js ADDED
@@ -0,0 +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}add(...e){return this._dom.append(...e.map(e=>e._dom)),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(e.dom,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(e._dom,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(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)}br(e){return this.setStyleProp(`borderRight`,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)}function u(e,...t){return c(e).add(...t)}var d=class extends s{constructor(){super(`a`)}href(e){return this._dom.href=e,this}},f=class extends s{constructor(){super(`button`)}type(e){return this.dom.type=e,this}},p=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}},m=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}},h=class extends s{constructor(e){super(e??`div`),this.style({display:`flex`,alignItems:`center`})}alignItems(e=`center`){return this._dom.style.alignItems=e,this}justifyContent(e=`center`){return this._dom.style.justifyContent=e,this}gap(e){return this._dom.style.gap=this.getStyleValue(`gap`,e),this}direction(e){return this.dom.style.flexDirection=e,this}},g=class extends s{constructor(e){super(e??`div`),this.style({display:`grid`,alignItems:`center`})}templateColumns(e){return this._dom.style.gridTemplateColumns=String(e),this}templateRows(e){return this._dom.style.gridTemplateRows=String(e),this}gap(e){return this._dom.style.gap=this.getStyleValue(`gap`,e),this}alignItems(e=`center`){return this._dom.style.alignItems=e,this}},_=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}},v=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}},y=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`)}},b=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}},x=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}},S=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}},C=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}},w=class extends s{constructor(){super(`option`)}value(e){return this.dom.value=String(e),this}getValue(){return this.dom.value}},T=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 $,l as $select,u as $wrap,d as AnchorElement,f as Button,p as Canvas,m as DomBody,s as DomElement,h as Flex,g as Grid,_ as IFrame,v as ImageElement,y as InputCheckbox,b as InputColor,x as InputNumber,S as InputRange,C as InputText,w as OptionElement,T as SelectElement,r as StyleSheet,e as UNITLESS_CSS_PROPS,t as VENDOR_CSS_PROPS,o as camelToKebab,i as uniqueId};
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@neptune3d/dom",
3
+ "version": "0.0.1",
4
+ "description": "Helper classes and functions for the DOM.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/neptune-3d/dom#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/neptune-3d/dom/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/neptune-3d/dom.git"
14
+ },
15
+ "author": "Dusan Jovanov <jovanovdusan1@gmail.com>",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "main": "./dist/index.js",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": "./dist/index.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "scripts": {
27
+ "build": "tsdown",
28
+ "dev": "tsdown --watch",
29
+ "test": "vitest",
30
+ "typecheck": "tsc --noEmit"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^24.7.2",
34
+ "bumpp": "^10.3.1",
35
+ "prettier": "2.8",
36
+ "tsdown": "^0.15.6",
37
+ "typescript": "^5.9.3",
38
+ "vitest": "^3.2.4"
39
+ },
40
+ "dependencies": {
41
+ "csstype": "^3.1.3"
42
+ }
43
+ }