redgin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 josnin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # RedGin
2
+ # Simplified library for building [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components)
3
+
4
+ * Javascript [Template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) for Template syntax
5
+ * Introduced Reactive Tags, Directives (watch, div, span, ...)
6
+ * Getters/Setters is handled by RedGin
7
+ * Inline Events
8
+ * Vanilla JS, Works on all JS framework
9
+
10
+
11
+ ## Use directly in browser
12
+
13
+ ```html
14
+
15
+ <!DOCTYPE html>
16
+ <html lang="en">
17
+ <head>
18
+ <script src="https://josnin.sgp1.digitaloceanspaces.com/redgin/dist/redgin.js"></script>
19
+ </head>
20
+ <body>
21
+ <app-root></app-root>
22
+
23
+ <script type="module">
24
+ class AppRoot extends RedGin {
25
+ render() {
26
+ return ` This is app root! `
27
+ }
28
+ }
29
+ customElements.define('app-root', AppRoot);
30
+ </script>
31
+
32
+ </body>
33
+ </html>
34
+
35
+ ```
36
+
37
+
38
+ ## How to?
39
+ ### Inline Events
40
+ it uses events tag ( click ) to create event listener behind the scene and automatically clear once the component is remove from DOM
41
+ ```js
42
+ import { RedGin, click } from 'red-gin.js';
43
+
44
+ class Event extends RedGin {
45
+ render() {
46
+ return `<button ${ click( () => alert('Click Me') )} >Submit</button>`
47
+ }
48
+
49
+ }
50
+
51
+ customElements.define('sample-event', Event);
52
+
53
+ ```
54
+
55
+ ### List Render (Reactive)
56
+ * dynamically create reactive props define in observedAttributes()
57
+ * its uses watch directives to rerender inside html when value change
58
+ ```js
59
+ import { RedGin, watch } from 'red-gin.js';
60
+
61
+ class Loop extends RedGin {
62
+
63
+ static get observedAttributes() { return ['arr'] } // dynamically create reactive props this.arr
64
+
65
+ render() {
66
+ return `<ul> ${ watch(['arr'], () =>
67
+ this.arr.map( e => `Number: ${e}`)
68
+ ).join('')
69
+ }
70
+ </ul>`
71
+ }
72
+ }
73
+
74
+ customElements.define('sample-loop', Loop);
75
+
76
+ ```
77
+ #### results
78
+ ```html
79
+
80
+ <ul>
81
+ <li>Number: 1</li>
82
+ <li>Number: 2</li>
83
+ <li>Number: 3</li>
84
+ </ul>
85
+
86
+ ```
87
+
88
+
89
+
90
+ ### IF condition (Static)
91
+ ```js
92
+ import { RedGin } from 'red-gin.js';
93
+
94
+ class If extends RedGin {
95
+ isDisabled = true
96
+
97
+ render() {
98
+ return `<button
99
+ ${ this.isDisabled ? `disabled` : ``}
100
+ > Submit
101
+ </button>
102
+ }
103
+ }
104
+
105
+ customElements.define('sample-if', If);
106
+
107
+ ```
108
+
109
+ ### IF condition (Reactive)
110
+ * dynamically create reactive props define in observedAttributes()
111
+ * its uses directive watch to rerender inside html when value change
112
+ ```js
113
+ import { RedGin, watch } from "./red-gin.js";
114
+
115
+ class If extends RedGin {
116
+
117
+ static get observedAttributes() { return ['is-disable']; }
118
+ // dynamically create camelCase props. ie. this.isDisable
119
+
120
+ render() {
121
+ return `
122
+ ${ watch(['isDisable'], () =>
123
+ <button
124
+ ${ this.isDisable ? `disable`: ``}
125
+ > Submit
126
+ </button>
127
+ )
128
+ }
129
+ `
130
+ }
131
+
132
+ }
133
+
134
+ customElements.define('sample-if', If);
135
+ ```
136
+
137
+ ### Render Obj (Reactive)
138
+ * recommend to use watch directive when rendering obj
139
+ ```js
140
+
141
+ obj = setget({
142
+ id:1,
143
+ name:'John Doe'
144
+ }, { forWatch: false } ) // forWatch default is true, for complex just define a setter/getter manually?
145
+
146
+
147
+ render() {
148
+ return `${ watch(['obj'], () =>
149
+ `<div>${ this.obj.id }</div>
150
+ <div>${ this.obj.name }</div>`
151
+ ) }`
152
+ }
153
+ ```
154
+
155
+ ### Render List of Obj (Reactive)
156
+ ```js
157
+ onInit(): void {
158
+ this.obj = [{id:1, name:'John Doe'}]
159
+ }
160
+
161
+ render() {
162
+ return `${ watch(['obj'], () => this.obj.map( (e: any) =>
163
+ `<span>ID:${e.id} Name:${e.name}</span>`)
164
+ ) }`
165
+ }
166
+ ```
167
+
168
+ ### Render with Simplified tag (Reactive)
169
+ * recommend to use div (span, etc.) directives for simple display of value
170
+ ```js
171
+ onInit(): void {
172
+ this.id = 1;
173
+ this.name = 'Joh Doe'
174
+ }
175
+
176
+ render() {
177
+ return `
178
+ ${ div('id') }
179
+ ${ div('name') }`
180
+ }
181
+ ```
182
+
183
+ ### PropReflect Custom
184
+ Can only define single variable to each attr
185
+ IF define , auto creation of attr props is ignored
186
+ ```js
187
+ msg = propReflect('Hello?', { type: String } )
188
+ ```
189
+
190
+ ## Reference
191
+ https://web.dev/custom-elements-best-practices/
192
+
193
+ https://web.dev/shadowdom-v1/
194
+
195
+ ## Installation
196
+ ```
197
+ npm install
198
+ ```
199
+
200
+ ## How to run development server?
201
+ ```
202
+ cd ~/Documents/redgin/
203
+ npm run build
204
+ npm start
205
+ ```
206
+
207
+ ## Help
208
+
209
+ Need help? Open an issue in: [ISSUES](https://github.com/josnin/redgin/issues)
210
+
211
+
212
+ ## Contributing
213
+ Want to improve and add feature? Fork the repo, add your changes and send a pull request.
214
+
@@ -0,0 +1,347 @@
1
+ declare var C: {
2
+ new (): {
3
+ connectedCallback(): void;
4
+ attributeChangedCallback(t: any, e: any, o: any): void;
5
+ disconnectedCallback(): void;
6
+ updateContents(t: any): any;
7
+ setEventListeners(): void;
8
+ setPropsBehavior(): void;
9
+ getStyles(t: any): string;
10
+ _onInit(): void;
11
+ _onDoUpdate(): void;
12
+ _onUpdated(): void;
13
+ onInit(): void;
14
+ onDoUpdate(): void;
15
+ onUpdated(): void;
16
+ styles: any[];
17
+ render(): string;
18
+ accessKey: string;
19
+ readonly accessKeyLabel: string;
20
+ autocapitalize: string;
21
+ dir: string;
22
+ draggable: boolean;
23
+ hidden: boolean;
24
+ inert: boolean;
25
+ innerText: string;
26
+ lang: string;
27
+ readonly offsetHeight: number;
28
+ readonly offsetLeft: number;
29
+ readonly offsetParent: Element;
30
+ readonly offsetTop: number;
31
+ readonly offsetWidth: number;
32
+ outerText: string;
33
+ spellcheck: boolean;
34
+ title: string;
35
+ translate: boolean;
36
+ attachInternals(): ElementInternals;
37
+ click(): void;
38
+ addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
39
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
40
+ removeEventListener<K_1 extends keyof HTMLElementEventMap>(type: K_1, listener: (this: HTMLElement, ev: HTMLElementEventMap[K_1]) => any, options?: boolean | EventListenerOptions): void;
41
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
42
+ readonly attributes: NamedNodeMap;
43
+ readonly classList: DOMTokenList;
44
+ className: string;
45
+ readonly clientHeight: number;
46
+ readonly clientLeft: number;
47
+ readonly clientTop: number;
48
+ readonly clientWidth: number;
49
+ id: string;
50
+ readonly localName: string;
51
+ readonly namespaceURI: string;
52
+ onfullscreenchange: (this: Element, ev: Event) => any;
53
+ onfullscreenerror: (this: Element, ev: Event) => any;
54
+ outerHTML: string;
55
+ readonly ownerDocument: Document;
56
+ readonly part: DOMTokenList;
57
+ readonly prefix: string;
58
+ readonly scrollHeight: number;
59
+ scrollLeft: number;
60
+ scrollTop: number;
61
+ readonly scrollWidth: number;
62
+ readonly shadowRoot: ShadowRoot;
63
+ slot: string;
64
+ readonly tagName: string;
65
+ attachShadow(init: ShadowRootInit): ShadowRoot;
66
+ closest<K_2 extends keyof HTMLElementTagNameMap>(selector: K_2): HTMLElementTagNameMap[K_2];
67
+ closest<K_3 extends keyof SVGElementTagNameMap>(selector: K_3): SVGElementTagNameMap[K_3];
68
+ closest<E extends Element = Element>(selectors: string): E;
69
+ getAttribute(qualifiedName: string): string;
70
+ getAttributeNS(namespace: string, localName: string): string;
71
+ getAttributeNames(): string[];
72
+ getAttributeNode(qualifiedName: string): Attr;
73
+ getAttributeNodeNS(namespace: string, localName: string): Attr;
74
+ getBoundingClientRect(): DOMRect;
75
+ getClientRects(): DOMRectList;
76
+ getElementsByClassName(classNames: string): HTMLCollectionOf<Element>;
77
+ getElementsByTagName<K_4 extends keyof HTMLElementTagNameMap>(qualifiedName: K_4): HTMLCollectionOf<HTMLElementTagNameMap[K_4]>;
78
+ getElementsByTagName<K_5 extends keyof SVGElementTagNameMap>(qualifiedName: K_5): HTMLCollectionOf<SVGElementTagNameMap[K_5]>;
79
+ getElementsByTagName(qualifiedName: string): HTMLCollectionOf<Element>;
80
+ getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>;
81
+ getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
82
+ getElementsByTagNameNS(namespace: string, localName: string): HTMLCollectionOf<Element>;
83
+ hasAttribute(qualifiedName: string): boolean;
84
+ hasAttributeNS(namespace: string, localName: string): boolean;
85
+ hasAttributes(): boolean;
86
+ hasPointerCapture(pointerId: number): boolean;
87
+ insertAdjacentElement(where: InsertPosition, element: Element): Element;
88
+ insertAdjacentHTML(position: InsertPosition, text: string): void;
89
+ insertAdjacentText(where: InsertPosition, data: string): void;
90
+ matches(selectors: string): boolean;
91
+ releasePointerCapture(pointerId: number): void;
92
+ removeAttribute(qualifiedName: string): void;
93
+ removeAttributeNS(namespace: string, localName: string): void;
94
+ removeAttributeNode(attr: Attr): Attr;
95
+ requestFullscreen(options?: FullscreenOptions): Promise<void>;
96
+ requestPointerLock(): void;
97
+ scroll(options?: ScrollToOptions): void;
98
+ scroll(x: number, y: number): void;
99
+ scrollBy(options?: ScrollToOptions): void;
100
+ scrollBy(x: number, y: number): void;
101
+ scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
102
+ scrollTo(options?: ScrollToOptions): void;
103
+ scrollTo(x: number, y: number): void;
104
+ setAttribute(qualifiedName: string, value: string): void;
105
+ setAttributeNS(namespace: string, qualifiedName: string, value: string): void;
106
+ setAttributeNode(attr: Attr): Attr;
107
+ setAttributeNodeNS(attr: Attr): Attr;
108
+ setPointerCapture(pointerId: number): void;
109
+ toggleAttribute(qualifiedName: string, force?: boolean): boolean;
110
+ webkitMatchesSelector(selectors: string): boolean;
111
+ readonly baseURI: string;
112
+ readonly childNodes: NodeListOf<ChildNode>;
113
+ readonly firstChild: ChildNode;
114
+ readonly isConnected: boolean;
115
+ readonly lastChild: ChildNode;
116
+ readonly nextSibling: ChildNode;
117
+ readonly nodeName: string;
118
+ readonly nodeType: number;
119
+ nodeValue: string;
120
+ readonly parentElement: HTMLElement;
121
+ readonly parentNode: ParentNode;
122
+ readonly previousSibling: ChildNode;
123
+ textContent: string;
124
+ appendChild<T extends Node>(node: T): T;
125
+ cloneNode(deep?: boolean): Node;
126
+ compareDocumentPosition(other: Node): number;
127
+ contains(other: Node): boolean;
128
+ getRootNode(options?: GetRootNodeOptions): Node;
129
+ hasChildNodes(): boolean;
130
+ insertBefore<T_1 extends Node>(node: T_1, child: Node): T_1;
131
+ isDefaultNamespace(namespace: string): boolean;
132
+ isEqualNode(otherNode: Node): boolean;
133
+ isSameNode(otherNode: Node): boolean;
134
+ lookupNamespaceURI(prefix: string): string;
135
+ lookupPrefix(namespace: string): string;
136
+ normalize(): void;
137
+ removeChild<T_2 extends Node>(child: T_2): T_2;
138
+ replaceChild<T_3 extends Node>(node: Node, child: T_3): T_3;
139
+ readonly ATTRIBUTE_NODE: number;
140
+ readonly CDATA_SECTION_NODE: number;
141
+ readonly COMMENT_NODE: number;
142
+ readonly DOCUMENT_FRAGMENT_NODE: number;
143
+ readonly DOCUMENT_NODE: number;
144
+ readonly DOCUMENT_POSITION_CONTAINED_BY: number;
145
+ readonly DOCUMENT_POSITION_CONTAINS: number;
146
+ readonly DOCUMENT_POSITION_DISCONNECTED: number;
147
+ readonly DOCUMENT_POSITION_FOLLOWING: number;
148
+ readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number;
149
+ readonly DOCUMENT_POSITION_PRECEDING: number;
150
+ readonly DOCUMENT_TYPE_NODE: number;
151
+ readonly ELEMENT_NODE: number;
152
+ readonly ENTITY_NODE: number;
153
+ readonly ENTITY_REFERENCE_NODE: number;
154
+ readonly NOTATION_NODE: number;
155
+ readonly PROCESSING_INSTRUCTION_NODE: number;
156
+ readonly TEXT_NODE: number;
157
+ dispatchEvent(event: Event): boolean;
158
+ ariaAtomic: string;
159
+ ariaAutoComplete: string;
160
+ ariaBusy: string;
161
+ ariaChecked: string;
162
+ ariaColCount: string;
163
+ ariaColIndex: string;
164
+ ariaColIndexText: string;
165
+ ariaColSpan: string;
166
+ ariaCurrent: string;
167
+ ariaDisabled: string;
168
+ ariaExpanded: string;
169
+ ariaHasPopup: string;
170
+ ariaHidden: string;
171
+ ariaInvalid: string;
172
+ ariaKeyShortcuts: string;
173
+ ariaLabel: string;
174
+ ariaLevel: string;
175
+ ariaLive: string;
176
+ ariaModal: string;
177
+ ariaMultiLine: string;
178
+ ariaMultiSelectable: string;
179
+ ariaOrientation: string;
180
+ ariaPlaceholder: string;
181
+ ariaPosInSet: string;
182
+ ariaPressed: string;
183
+ ariaReadOnly: string;
184
+ ariaRequired: string;
185
+ ariaRoleDescription: string;
186
+ ariaRowCount: string;
187
+ ariaRowIndex: string;
188
+ ariaRowIndexText: string;
189
+ ariaRowSpan: string;
190
+ ariaSelected: string;
191
+ ariaSetSize: string;
192
+ ariaSort: string;
193
+ ariaValueMax: string;
194
+ ariaValueMin: string;
195
+ ariaValueNow: string;
196
+ ariaValueText: string;
197
+ role: string;
198
+ animate(keyframes: PropertyIndexedKeyframes | Keyframe[], options?: number | KeyframeAnimationOptions): Animation;
199
+ getAnimations(options?: GetAnimationsOptions): Animation[];
200
+ after(...nodes: (string | Node)[]): void;
201
+ before(...nodes: (string | Node)[]): void;
202
+ remove(): void;
203
+ replaceWith(...nodes: (string | Node)[]): void;
204
+ innerHTML: string;
205
+ readonly nextElementSibling: Element;
206
+ readonly previousElementSibling: Element;
207
+ readonly childElementCount: number;
208
+ readonly children: HTMLCollection;
209
+ readonly firstElementChild: Element;
210
+ readonly lastElementChild: Element;
211
+ append(...nodes: (string | Node)[]): void;
212
+ prepend(...nodes: (string | Node)[]): void;
213
+ querySelector<K_6 extends keyof HTMLElementTagNameMap>(selectors: K_6): HTMLElementTagNameMap[K_6];
214
+ querySelector<K_7 extends keyof SVGElementTagNameMap>(selectors: K_7): SVGElementTagNameMap[K_7];
215
+ querySelector<E_1 extends Element = Element>(selectors: string): E_1;
216
+ querySelectorAll<K_8 extends keyof HTMLElementTagNameMap>(selectors: K_8): NodeListOf<HTMLElementTagNameMap[K_8]>;
217
+ querySelectorAll<K_9 extends keyof SVGElementTagNameMap>(selectors: K_9): NodeListOf<SVGElementTagNameMap[K_9]>;
218
+ querySelectorAll<E_2 extends Element = Element>(selectors: string): NodeListOf<E_2>;
219
+ replaceChildren(...nodes: (string | Node)[]): void;
220
+ readonly assignedSlot: HTMLSlotElement;
221
+ oncopy: (this: DocumentAndElementEventHandlers, ev: ClipboardEvent) => any;
222
+ oncut: (this: DocumentAndElementEventHandlers, ev: ClipboardEvent) => any;
223
+ onpaste: (this: DocumentAndElementEventHandlers, ev: ClipboardEvent) => any;
224
+ readonly style: CSSStyleDeclaration;
225
+ contentEditable: string;
226
+ enterKeyHint: string;
227
+ inputMode: string;
228
+ readonly isContentEditable: boolean;
229
+ onabort: (this: GlobalEventHandlers, ev: UIEvent) => any;
230
+ onanimationcancel: (this: GlobalEventHandlers, ev: AnimationEvent) => any;
231
+ onanimationend: (this: GlobalEventHandlers, ev: AnimationEvent) => any;
232
+ onanimationiteration: (this: GlobalEventHandlers, ev: AnimationEvent) => any;
233
+ onanimationstart: (this: GlobalEventHandlers, ev: AnimationEvent) => any;
234
+ onauxclick: (this: GlobalEventHandlers, ev: MouseEvent) => any;
235
+ onbeforeinput: (this: GlobalEventHandlers, ev: InputEvent) => any;
236
+ onblur: (this: GlobalEventHandlers, ev: FocusEvent) => any;
237
+ oncancel: (this: GlobalEventHandlers, ev: Event) => any;
238
+ oncanplay: (this: GlobalEventHandlers, ev: Event) => any;
239
+ oncanplaythrough: (this: GlobalEventHandlers, ev: Event) => any;
240
+ onchange: (this: GlobalEventHandlers, ev: Event) => any;
241
+ onclick: (this: GlobalEventHandlers, ev: MouseEvent) => any;
242
+ onclose: (this: GlobalEventHandlers, ev: Event) => any;
243
+ oncontextmenu: (this: GlobalEventHandlers, ev: MouseEvent) => any;
244
+ oncuechange: (this: GlobalEventHandlers, ev: Event) => any;
245
+ ondblclick: (this: GlobalEventHandlers, ev: MouseEvent) => any;
246
+ ondrag: (this: GlobalEventHandlers, ev: DragEvent) => any;
247
+ ondragend: (this: GlobalEventHandlers, ev: DragEvent) => any;
248
+ ondragenter: (this: GlobalEventHandlers, ev: DragEvent) => any;
249
+ ondragleave: (this: GlobalEventHandlers, ev: DragEvent) => any;
250
+ ondragover: (this: GlobalEventHandlers, ev: DragEvent) => any;
251
+ ondragstart: (this: GlobalEventHandlers, ev: DragEvent) => any;
252
+ ondrop: (this: GlobalEventHandlers, ev: DragEvent) => any;
253
+ ondurationchange: (this: GlobalEventHandlers, ev: Event) => any;
254
+ onemptied: (this: GlobalEventHandlers, ev: Event) => any;
255
+ onended: (this: GlobalEventHandlers, ev: Event) => any;
256
+ onerror: OnErrorEventHandlerNonNull;
257
+ onfocus: (this: GlobalEventHandlers, ev: FocusEvent) => any;
258
+ onformdata: (this: GlobalEventHandlers, ev: FormDataEvent) => any;
259
+ ongotpointercapture: (this: GlobalEventHandlers, ev: PointerEvent) => any;
260
+ oninput: (this: GlobalEventHandlers, ev: Event) => any;
261
+ oninvalid: (this: GlobalEventHandlers, ev: Event) => any;
262
+ onkeydown: (this: GlobalEventHandlers, ev: KeyboardEvent) => any;
263
+ onkeypress: (this: GlobalEventHandlers, ev: KeyboardEvent) => any;
264
+ onkeyup: (this: GlobalEventHandlers, ev: KeyboardEvent) => any;
265
+ onload: (this: GlobalEventHandlers, ev: Event) => any;
266
+ onloadeddata: (this: GlobalEventHandlers, ev: Event) => any;
267
+ onloadedmetadata: (this: GlobalEventHandlers, ev: Event) => any;
268
+ onloadstart: (this: GlobalEventHandlers, ev: Event) => any;
269
+ onlostpointercapture: (this: GlobalEventHandlers, ev: PointerEvent) => any;
270
+ onmousedown: (this: GlobalEventHandlers, ev: MouseEvent) => any;
271
+ onmouseenter: (this: GlobalEventHandlers, ev: MouseEvent) => any;
272
+ onmouseleave: (this: GlobalEventHandlers, ev: MouseEvent) => any;
273
+ onmousemove: (this: GlobalEventHandlers, ev: MouseEvent) => any;
274
+ onmouseout: (this: GlobalEventHandlers, ev: MouseEvent) => any;
275
+ onmouseover: (this: GlobalEventHandlers, ev: MouseEvent) => any;
276
+ onmouseup: (this: GlobalEventHandlers, ev: MouseEvent) => any;
277
+ onpause: (this: GlobalEventHandlers, ev: Event) => any;
278
+ onplay: (this: GlobalEventHandlers, ev: Event) => any;
279
+ onplaying: (this: GlobalEventHandlers, ev: Event) => any;
280
+ onpointercancel: (this: GlobalEventHandlers, ev: PointerEvent) => any;
281
+ onpointerdown: (this: GlobalEventHandlers, ev: PointerEvent) => any;
282
+ onpointerenter: (this: GlobalEventHandlers, ev: PointerEvent) => any;
283
+ onpointerleave: (this: GlobalEventHandlers, ev: PointerEvent) => any;
284
+ onpointermove: (this: GlobalEventHandlers, ev: PointerEvent) => any;
285
+ onpointerout: (this: GlobalEventHandlers, ev: PointerEvent) => any;
286
+ onpointerover: (this: GlobalEventHandlers, ev: PointerEvent) => any;
287
+ onpointerup: (this: GlobalEventHandlers, ev: PointerEvent) => any;
288
+ onprogress: (this: GlobalEventHandlers, ev: ProgressEvent<EventTarget>) => any;
289
+ onratechange: (this: GlobalEventHandlers, ev: Event) => any;
290
+ onreset: (this: GlobalEventHandlers, ev: Event) => any;
291
+ onresize: (this: GlobalEventHandlers, ev: UIEvent) => any;
292
+ onscroll: (this: GlobalEventHandlers, ev: Event) => any;
293
+ onsecuritypolicyviolation: (this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any;
294
+ onseeked: (this: GlobalEventHandlers, ev: Event) => any;
295
+ onseeking: (this: GlobalEventHandlers, ev: Event) => any;
296
+ onselect: (this: GlobalEventHandlers, ev: Event) => any;
297
+ onselectionchange: (this: GlobalEventHandlers, ev: Event) => any;
298
+ onselectstart: (this: GlobalEventHandlers, ev: Event) => any;
299
+ onslotchange: (this: GlobalEventHandlers, ev: Event) => any;
300
+ onstalled: (this: GlobalEventHandlers, ev: Event) => any;
301
+ onsubmit: (this: GlobalEventHandlers, ev: SubmitEvent) => any;
302
+ onsuspend: (this: GlobalEventHandlers, ev: Event) => any;
303
+ ontimeupdate: (this: GlobalEventHandlers, ev: Event) => any;
304
+ ontoggle: (this: GlobalEventHandlers, ev: Event) => any;
305
+ ontouchcancel?: (this: GlobalEventHandlers, ev: TouchEvent) => any;
306
+ ontouchend?: (this: GlobalEventHandlers, ev: TouchEvent) => any;
307
+ ontouchmove?: (this: GlobalEventHandlers, ev: TouchEvent) => any;
308
+ ontouchstart?: (this: GlobalEventHandlers, ev: TouchEvent) => any;
309
+ ontransitioncancel: (this: GlobalEventHandlers, ev: TransitionEvent) => any;
310
+ ontransitionend: (this: GlobalEventHandlers, ev: TransitionEvent) => any;
311
+ ontransitionrun: (this: GlobalEventHandlers, ev: TransitionEvent) => any;
312
+ ontransitionstart: (this: GlobalEventHandlers, ev: TransitionEvent) => any;
313
+ onvolumechange: (this: GlobalEventHandlers, ev: Event) => any;
314
+ onwaiting: (this: GlobalEventHandlers, ev: Event) => any;
315
+ onwebkitanimationend: (this: GlobalEventHandlers, ev: Event) => any;
316
+ onwebkitanimationiteration: (this: GlobalEventHandlers, ev: Event) => any;
317
+ onwebkitanimationstart: (this: GlobalEventHandlers, ev: Event) => any;
318
+ onwebkittransitionend: (this: GlobalEventHandlers, ev: Event) => any;
319
+ onwheel: (this: GlobalEventHandlers, ev: WheelEvent) => any;
320
+ autofocus: boolean;
321
+ readonly dataset: DOMStringMap;
322
+ nonce?: string;
323
+ tabIndex: number;
324
+ blur(): void;
325
+ focus(options?: FocusOptions): void;
326
+ };
327
+ };
328
+ declare namespace F {
329
+ const mode: string;
330
+ const delegatesFocus: boolean;
331
+ }
332
+ declare var p: {
333
+ new (): {};
334
+ define(t: any): void;
335
+ };
336
+ declare var c: {
337
+ new (): {};
338
+ define(t: any): void;
339
+ };
340
+ declare var K: string[];
341
+ declare function I(s: any, t: any, e: any): void;
342
+ declare function j(s: any, t: any): string;
343
+ declare function q(s: any, t: any): any;
344
+ declare var H: any[];
345
+ declare function M(s: any, t: any): any;
346
+ declare function _(s: any, t: any): string;
347
+ export { C as RedGin, F as attachShadow, p as customDirectives, c as customPropsBehavior, K as defaultStyles, I as emit, j as event, q as getset, H as injectStyles, M as propReflect, _ as watch };
@@ -0,0 +1,13 @@
1
+ var D=Object.defineProperty;var L=(s,t,e)=>t in s?D(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var d=(s,t,e)=>(L(s,typeof t!="symbol"?t+"":t,e),e);var x=()=>crypto.randomUUID().split("-")[0],v=s=>s.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),u=s=>s.replace(/-./g,t=>t[1].toUpperCase());function A(s){let t=!1;for(let e of p.reg)t=e.call(this,s);return!0}var m=class{static define(t){m.reg.push(t)}},p=m;d(p,"reg",[]);var h={},b=class extends HTMLElement{};customElements.get("in-watch")||customElements.define("in-watch",b);var _=(s,t)=>{let e=document.createElement("in-watch"),o=x();for(let n of s)Object.hasOwn(h,n)||(h[n]={}),h[n][o]=t;return e.dataset.watch__=o,e.outerHTML};function T(s){let t=u(s),e=!1;if(Object.hasOwn(h,t)){for(let o of Object.keys(h[t]))if(this.shadowRoot){let n=this.shadowRoot.querySelector(`[data-watch__="${o}"]`);n&&(n.innerHTML=h[t][o]?h[t][o].call(this):this[t],e=!0)}}return e}p.define(T);var S=()=>crypto.randomUUID().split("-")[0];var U=[],f;(function(s){s[s.ADD=0]="ADD",s[s.REMOVE=1]="REMOVE"})(f||(f={}));var j=(s,t)=>{let e=S();return U.push([s,t,e]),`data-evt__=${e}`};function I(s,t,e){let o={detail:t,composed:!0},n=new CustomEvent(s,{...o,...e});this.shadowRoot&&this.shadowRoot.dispatchEvent(n)}function E(s){for(let t of U){let[e,o,n]=t;if(this.shadowRoot){let i=this.shadowRoot.querySelector(`[data-evt__="${n}"]`);i&&(s===f.ADD?i.addEventListener(e,o):i.removeEventListener(e,o))}}}function R(){E.call(this,f.ADD)}function O(){E.call(this,f.REMOVE)}function $(s,t){for(let e of c.reg)e.call(this,s,t)}var g=class{static define(t){g.reg.push(t)}},c=g;d(c,"reg",[]);var P=["^class$","^style$","^className$","^classList$","^id$","^dataset$","^data-","^aria-"],y=["disabled"],k=s=>{let t=!0;for(let e of P){let o=new RegExp(e,"g");if(s.match(o)){t=!1,console.error(`Please remove attribute '${s}' in the observedAttributes,
2
+ DOM already provided built-in props reflection for this attribute.`);break}}return t};function B(s,t){if(t===void 0||t.name!="propReflect")return;let{type:e,value:o,serializerFn:n,deserializerFn:i}=t,l=this.constructor.observedAttributes,w=u(s),r=v(s);if(l===void 0||!l.includes(r)){console.error(`Unable to apply propReflect '${w}' for attribute '${r}',
3
+ Please add '${r}' in the observedAttributes of ${this.constructor.name} component`);return}!k(r)||Object.defineProperty(this,w,{configurable:!0,set(a){if(i)return i.call(this,r,e,o,a);(e===Boolean||typeof a=="boolean"||y.includes(r))&&a===!0?this.setAttribute(r,""):(e===Boolean||y.includes(r))&&a===!1?this.removeAttribute(r):([Object,Array].includes(e)||["object","array"].includes(typeof a))&&a?this.setAttribute(r,JSON.stringify(a)):([String,Number].includes(e)||["string","number"].includes(typeof a))&&a?this.setAttribute(r,a):this.removeAttribute(r)},get(){if(n)return n.call(this,r,e,o);if(r in y||e===Boolean||typeof o=="boolean")return this.hasAttribute(r);if(([String,Array,Object].includes(e)||["string","array","object"].includes(typeof o))&&!this.hasAttribute(r))return o;if((e===String||typeof o=="string")&&this.hasAttribute(r))return this.getAttribute(r);if((e===Number||typeof o=="number")&&this.hasAttribute(r))return Number(this.getAttribute(r));if(([Array,Object].includes(e)||["array","object"].includes(typeof o))&&this.hasAttribute(r))return JSON.parse(this.getAttribute(r))}})}function M(s,t){return{value:s,...t,name:"propReflect"}}c.define(B);function N(s,t){if(t===void 0||t.name!="getset")return;let{value:e,forWatch:o}=t;this[`#${s}`]=e,Object.defineProperty(this,s,{configurable:!0,set(n){this[`#${s}`]=n,o&&this.updateContents(s)},get(){return this[`#${s}`]}})}function q(s,t){return{value:s,...{forWatch:!0},...t,name:"getset"}}c.define(N);var F={mode:"open",delegatesFocus:!0},H=[],K=[` /* Custom elements are display: inline by default,
4
+ * so setting their width or height will have no effect
5
+ */
6
+ :host { display: block; }
7
+ `],C=class extends HTMLElement{constructor(){super(),this.attachShadow(F)}connectedCallback(){this._onInit(),this._onDoUpdate()}attributeChangedCallback(t,e,o){if(e===o)return;this.updateContents(t)&&this._onUpdated()}disconnectedCallback(){O.call(this)}updateContents(t){return A.call(this,t)}setEventListeners(){R.call(this)}setPropsBehavior(){let t=Object.getOwnPropertyNames(this);for(let e of t){let o=this[e];$.call(this,e,o)}}getStyles(t){let e=[],o=[],n=this.shadowRoot?.adoptedStyleSheets;for(let i of t)if(i.startsWith("<link"))e.push(i);else if(i.startsWith("@import")||!n){let l=document.createElement("style");l.innerHTML=i,e.push(l.outerHTML)}else{let l=new CSSStyleSheet;l.replaceSync(i),o.push(l)}return this.shadowRoot&&o.length>0&&(this.shadowRoot.adoptedStyleSheets=o),e.join("")}_onInit(){this.setPropsBehavior(),this.shadowRoot&&(this.shadowRoot.innerHTML=`
8
+ ${this.getStyles(H)}
9
+ ${this.getStyles(K)}
10
+ ${this.getStyles(this.styles)}
11
+ ${this.render()}
12
+ `),this.onInit()}_onDoUpdate(){let t=Object.getOwnPropertyNames(this);for(let e of t)this.updateContents(e)&&this._onUpdated();this.onDoUpdate()}_onUpdated(){this.setEventListeners(),this.onUpdated()}onInit(){}onDoUpdate(){}onUpdated(){}styles=[];render(){return""}};export{C as RedGin,F as attachShadow,p as customDirectives,c as customPropsBehavior,K as defaultStyles,I as emit,j as event,q as getset,H as injectStyles,M as propReflect,_ as watch};
13
+ //# sourceMappingURL=redgin.min.js.map
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "redgin",
3
+ "version": "0.1.0",
4
+ "description": "Simplified library for building web components",
5
+ "main": "dist/redgin.min.js",
6
+ "types": "dist/redgin.min.d.ts",
7
+ "engines": {
8
+ "node": ">=16"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "build": "tsc -w",
13
+ "start": "node server.js"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/josnin/redgin.git"
18
+ },
19
+ "author": "josnin",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/josnin/redgin/issues"
23
+ },
24
+ "homepage": "https://github.com/josnin/redgin#readme",
25
+ "devDependencies": {
26
+ "@fastify/static": "^5.0.0",
27
+ "@types/node": "^18.11.14",
28
+ "codelyzer": "^6.0.2",
29
+ "esbuild": "^0.16.4",
30
+ "fastify": "^3.21.0",
31
+ "typescript": "^4.9.4"
32
+ }
33
+ }
package/server.js ADDED
@@ -0,0 +1,25 @@
1
+ const fastify = require('fastify')({ logger: true })
2
+ const path = require('path');
3
+
4
+ fastify.register(require('@fastify/static'), {
5
+ root: path.join(__dirname, 'src'),
6
+ wildcard: false
7
+ })
8
+
9
+ // Declare route
10
+ fastify.get('/*', async (request, reply) => {
11
+ return await reply.sendFile("index.html");
12
+ })
13
+
14
+ // run server
15
+ const start = async () => {
16
+ try {
17
+ await fastify.listen( { port: 5068 })
18
+ } catch (err) {
19
+ fastify.log.error(err)
20
+ process.exit(1)
21
+ }
22
+ }
23
+
24
+ start()
25
+
package/tsconfig.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "es2022", /* Specify what module code is generated. */
29
+ // "rootDir": "./", /* Specify the root folder within your source files. */
30
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ "paths": {
34
+ "https://josnin.sgp1.cdn.digitaloceanspaces.com/redgin/redgin.min.js": [
35
+ "./src/redgin.d.ts"
36
+ ],
37
+ },
38
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
39
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
40
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
41
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
42
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
43
+ // "resolveJsonModule": true, /* Enable importing .json files. */
44
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
+
46
+ /* JavaScript Support */
47
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
+
51
+ /* Emit */
52
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
53
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
57
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
58
+ // "removeComments": true, /* Disable emitting comments. */
59
+ // "noEmit": true, /* Disable emitting files from a compilation. */
60
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
61
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
62
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
63
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
64
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
65
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
66
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
69
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75
+
76
+ /* Interop Constraints */
77
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
79
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
80
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
81
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
82
+
83
+ /* Type Checking */
84
+ "strict": true, /* Enable all strict type-checking options. */
85
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
86
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
87
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
88
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
89
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
90
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
91
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
92
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
93
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
94
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
95
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
96
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
97
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
98
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
99
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
100
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
101
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
102
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
103
+
104
+ /* Completeness */
105
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
106
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
107
+ },
108
+ "exclude": ["node_modules", "**/node_modules/*"],
109
+ "include": ["src", "dist"]
110
+ }