@htmlplus/element 0.3.1 → 0.4.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/README.md +2 -2
- package/client/decorators/attributes.d.ts +2 -0
- package/client/decorators/attributes.js +13 -0
- package/client/decorators/bind.d.ts +4 -0
- package/client/decorators/bind.js +17 -0
- package/client/decorators/element.d.ts +2 -0
- package/client/decorators/element.js +53 -0
- package/client/decorators/event.d.ts +21 -0
- package/client/decorators/event.js +17 -0
- package/client/decorators/index.d.ts +9 -0
- package/client/decorators/index.js +9 -0
- package/client/decorators/listen.d.ts +12 -0
- package/client/decorators/listen.js +31 -0
- package/client/decorators/method.d.ts +2 -0
- package/client/decorators/method.js +11 -0
- package/client/decorators/property.d.ts +8 -0
- package/client/decorators/property.js +45 -0
- package/client/decorators/state.d.ts +2 -0
- package/client/decorators/state.js +23 -0
- package/client/decorators/watch.d.ts +8 -0
- package/client/decorators/watch.js +34 -0
- package/client/helpers/classes.d.ts +1 -0
- package/client/helpers/classes.js +62 -0
- package/client/helpers/direction.d.ts +3 -0
- package/client/helpers/direction.js +4 -0
- package/client/helpers/index.d.ts +9 -0
- package/client/helpers/index.js +9 -0
- package/client/helpers/isRTL.d.ts +2 -0
- package/client/helpers/isRTL.js +2 -0
- package/client/helpers/query.d.ts +3 -0
- package/client/helpers/query.js +5 -0
- package/client/helpers/queryAll.d.ts +3 -0
- package/client/helpers/queryAll.js +5 -0
- package/client/helpers/slots.d.ts +6 -0
- package/client/helpers/slots.js +15 -0
- package/client/helpers/styles.d.ts +1 -0
- package/client/helpers/styles.js +17 -0
- package/client/helpers/toUnit.d.ts +1 -0
- package/client/helpers/toUnit.js +7 -0
- package/client/index.d.ts +3 -0
- package/client/index.js +3 -0
- package/client/services/index.d.ts +1 -0
- package/client/services/index.js +1 -0
- package/client/services/link.d.ts +4 -0
- package/client/services/link.js +196 -0
- package/client/utils/appendToMethod.d.ts +2 -0
- package/client/utils/appendToMethod.js +7 -0
- package/client/utils/call.d.ts +2 -0
- package/client/utils/call.js +4 -0
- package/client/utils/defineProperty.d.ts +1 -0
- package/client/utils/defineProperty.js +1 -0
- package/client/utils/event.d.ts +5 -0
- package/client/utils/event.js +9 -0
- package/client/utils/getMembers.d.ts +2 -0
- package/client/utils/getMembers.js +5 -0
- package/client/utils/getStyles.d.ts +2 -0
- package/client/utils/getStyles.js +5 -0
- package/client/utils/host.d.ts +2 -0
- package/client/utils/host.js +4 -0
- package/client/utils/index.d.ts +17 -0
- package/client/utils/index.js +17 -0
- package/client/utils/isEvent.d.ts +1 -0
- package/client/utils/isEvent.js +3 -0
- package/client/utils/isServer.d.ts +1 -0
- package/client/utils/isServer.js +3 -0
- package/client/utils/parseValue.d.ts +1 -0
- package/client/utils/parseValue.js +15 -0
- package/client/utils/request.d.ts +4 -0
- package/client/utils/request.js +38 -0
- package/client/utils/sync.d.ts +1 -0
- package/client/utils/sync.js +31 -0
- package/client/utils/task.d.ts +6 -0
- package/client/utils/task.js +37 -0
- package/client/utils/toBoolean.d.ts +1 -0
- package/client/utils/toBoolean.js +3 -0
- package/client/utils/toEvent.d.ts +1 -0
- package/client/utils/toEvent.js +3 -0
- package/client/utils/typeOf.d.ts +3 -0
- package/client/utils/typeOf.js +6 -0
- package/client/utils/updateAttribute.d.ts +1 -0
- package/client/utils/updateAttribute.js +7 -0
- package/client/vendor/uhtml.d.ts +22 -0
- package/client/vendor/uhtml.js +700 -0
- package/compiler/compiler.d.ts +7 -0
- package/compiler/compiler.js +72 -0
- package/compiler/index.d.ts +2 -0
- package/compiler/index.js +2 -0
- package/compiler/plugins/customElement.d.ts +8 -0
- package/compiler/plugins/customElement.js +157 -0
- package/compiler/plugins/customElementReact/customElementReact.d.ts +12 -0
- package/compiler/plugins/customElementReact/customElementReact.js +129 -0
- package/compiler/plugins/customElementReact/index.d.ts +1 -0
- package/compiler/plugins/customElementReact/index.js +1 -0
- package/compiler/plugins/customElementReact/templates/README.md.hbs +1 -0
- package/compiler/plugins/customElementReact/templates/_.gitignore.hbs +2 -0
- package/compiler/plugins/customElementReact/templates/package.json.hbs +37 -0
- package/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +21 -0
- package/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +17 -0
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +18 -0
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +26 -0
- package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +1 -0
- package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +278 -0
- package/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +17 -0
- package/compiler/plugins/document.d.ts +10 -0
- package/compiler/plugins/document.js +254 -0
- package/compiler/plugins/external.d.ts +9 -0
- package/compiler/plugins/external.js +25 -0
- package/compiler/plugins/extract.d.ts +8 -0
- package/compiler/plugins/extract.js +62 -0
- package/compiler/plugins/index.d.ts +9 -0
- package/compiler/plugins/index.js +9 -0
- package/compiler/plugins/parse.d.ts +5 -0
- package/compiler/plugins/parse.js +16 -0
- package/compiler/plugins/read.d.ts +5 -0
- package/compiler/plugins/read.js +13 -0
- package/compiler/plugins/style.d.ts +10 -0
- package/compiler/plugins/style.js +36 -0
- package/compiler/plugins/validate.d.ts +5 -0
- package/compiler/plugins/validate.js +40 -0
- package/compiler/plugins/vscode.d.ts +11 -0
- package/compiler/plugins/vscode.js +83 -0
- package/compiler/utils/__dirname.d.ts +1 -0
- package/compiler/utils/__dirname.js +5 -0
- package/compiler/utils/getInitializer.d.ts +2 -0
- package/compiler/utils/getInitializer.js +10 -0
- package/compiler/utils/getType.d.ts +2 -0
- package/compiler/utils/getType.js +69 -0
- package/compiler/utils/getTypeReference.d.ts +2 -0
- package/compiler/utils/getTypeReference.js +33 -0
- package/compiler/utils/hasDecorator.d.ts +1 -0
- package/compiler/utils/hasDecorator.js +5 -0
- package/compiler/utils/index.d.ts +11 -0
- package/compiler/utils/index.js +11 -0
- package/compiler/utils/isDirectoryEmpty.d.ts +1 -0
- package/compiler/utils/isDirectoryEmpty.js +10 -0
- package/compiler/utils/print.d.ts +2 -0
- package/compiler/utils/print.js +5 -0
- package/compiler/utils/printType.d.ts +1 -0
- package/compiler/utils/printType.js +69 -0
- package/compiler/utils/renderTemplate.d.ts +1 -0
- package/compiler/utils/renderTemplate.js +25 -0
- package/compiler/utils/tags.d.ts +13 -0
- package/compiler/utils/tags.js +53 -0
- package/compiler/utils/visitor.d.ts +2 -0
- package/compiler/utils/visitor.js +5 -0
- package/constants/index.d.ts +22 -0
- package/constants/index.js +28 -0
- package/package.json +14 -17
- package/types/context.d.ts +38 -0
- package/types/context.js +1 -0
- package/types/global.d.ts +4 -0
- package/types/global.js +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +4 -0
- package/types/plugin.d.ts +10 -0
- package/types/plugin.js +1 -0
- package/types/plusElement.d.ts +2 -0
- package/types/plusElement.js +1 -0
package/README.md
CHANGED
|
@@ -941,8 +941,8 @@ const { start, next, finish } = compiler(...plugins);
|
|
|
941
941
|
TODO
|
|
942
942
|
|
|
943
943
|
```js
|
|
944
|
-
import compiler from '@htmlplus/element/compiler';
|
|
945
|
-
import { customElement, extract, parse, read, style, validate } from '@htmlplus/element/compiler';
|
|
944
|
+
import compiler from '@htmlplus/element/compiler/index.js';
|
|
945
|
+
import { customElement, extract, parse, read, style, validate } from '@htmlplus/element/compiler/index.js';
|
|
946
946
|
|
|
947
947
|
const { start, next, finish } = compiler(
|
|
948
948
|
read(),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { appendToMethod, host, sync } from '../utils/index.js';
|
|
3
|
+
export function Attributes() {
|
|
4
|
+
return function (target, propertyKey) {
|
|
5
|
+
const updates = new Map();
|
|
6
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
7
|
+
updates.set(this, sync(host(this)));
|
|
8
|
+
});
|
|
9
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function () {
|
|
10
|
+
updates.get(this)(this[propertyKey]);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineProperty } from '../utils/index.js';
|
|
2
|
+
export function Bind() {
|
|
3
|
+
return function (target, propertyKey, descriptor) {
|
|
4
|
+
return {
|
|
5
|
+
configurable: true,
|
|
6
|
+
get() {
|
|
7
|
+
const value = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value.bind(this);
|
|
8
|
+
defineProperty(this, propertyKey, {
|
|
9
|
+
value,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true
|
|
12
|
+
});
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { camelCase, paramCase } from 'change-case';
|
|
2
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
+
import { call, getMembers, isServer, parseValue, request } from '../utils/index.js';
|
|
4
|
+
import * as uhtml from '../vendor/uhtml.js';
|
|
5
|
+
export function Element(tag) {
|
|
6
|
+
return function (constructor) {
|
|
7
|
+
if (isServer())
|
|
8
|
+
return;
|
|
9
|
+
const members = getMembers(constructor);
|
|
10
|
+
class Plus extends HTMLElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.attachShadow({ mode: 'open' });
|
|
14
|
+
// TODO
|
|
15
|
+
this.plus = new constructor();
|
|
16
|
+
this.plus[CONSTANTS.API_HOST] = () => this;
|
|
17
|
+
this.plus['uhtml'] = uhtml;
|
|
18
|
+
this.plus[CONSTANTS.API_READY] = true;
|
|
19
|
+
}
|
|
20
|
+
static get observedAttributes() {
|
|
21
|
+
return Object.keys(members)
|
|
22
|
+
.filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION)
|
|
23
|
+
.map((key) => paramCase(key));
|
|
24
|
+
}
|
|
25
|
+
adoptedCallback() {
|
|
26
|
+
call(this.plus, CONSTANTS.LIFECYCLE_ADOPTED);
|
|
27
|
+
}
|
|
28
|
+
// TODO
|
|
29
|
+
attributeChangedCallback(name, prev, next) {
|
|
30
|
+
const key = camelCase(name);
|
|
31
|
+
const [type] = members[key];
|
|
32
|
+
const parsed = parseValue(next, type);
|
|
33
|
+
this.plus[key] = parsed;
|
|
34
|
+
}
|
|
35
|
+
connectedCallback() {
|
|
36
|
+
call(this.plus, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
37
|
+
request(this.plus)
|
|
38
|
+
.then(() => {
|
|
39
|
+
call(this.plus, CONSTANTS.LIFECYCLE_LOADED);
|
|
40
|
+
})
|
|
41
|
+
.catch((error) => {
|
|
42
|
+
throw error;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
disconnectedCallback() {
|
|
46
|
+
call(this.plus, CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (customElements.get(tag))
|
|
50
|
+
return;
|
|
51
|
+
customElements.define(tag, Plus);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
export declare type EventEmitter<T = any> = (data?: T) => CustomEvent<T>;
|
|
3
|
+
export interface EventOptions {
|
|
4
|
+
/**
|
|
5
|
+
* A string custom event name to override the default.
|
|
6
|
+
*/
|
|
7
|
+
name?: string;
|
|
8
|
+
/**
|
|
9
|
+
* A Boolean indicating whether the event bubbles up through the DOM or not. default is `false`.
|
|
10
|
+
*/
|
|
11
|
+
bubbles?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* A Boolean indicating whether the event is cancelable. default is `false`.
|
|
14
|
+
*/
|
|
15
|
+
cancelable?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* A Boolean value indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM. The default is false.
|
|
18
|
+
*/
|
|
19
|
+
composed?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function Event<T = any>(options?: EventOptions): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineProperty, dispatch, host } from '../utils/index.js';
|
|
2
|
+
export function Event(options = {}) {
|
|
3
|
+
return function (target, propertyKey) {
|
|
4
|
+
defineProperty(target, propertyKey, {
|
|
5
|
+
get() {
|
|
6
|
+
return (detail) => {
|
|
7
|
+
var _a;
|
|
8
|
+
(_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
|
|
9
|
+
const name = options.name || String(propertyKey);
|
|
10
|
+
const event = new CustomEvent(name, Object.assign(Object.assign({}, options), { detail }));
|
|
11
|
+
dispatch(host(this), event);
|
|
12
|
+
return event;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './attributes.js';
|
|
2
|
+
export * from './bind.js';
|
|
3
|
+
export * from './element.js';
|
|
4
|
+
export * from './event.js';
|
|
5
|
+
export * from './listen.js';
|
|
6
|
+
export * from './method.js';
|
|
7
|
+
export * from './property.js';
|
|
8
|
+
export * from './state.js';
|
|
9
|
+
export * from './watch.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './attributes.js';
|
|
2
|
+
export * from './bind.js';
|
|
3
|
+
export * from './element.js';
|
|
4
|
+
export * from './event.js';
|
|
5
|
+
export * from './listen.js';
|
|
6
|
+
export * from './method.js';
|
|
7
|
+
export * from './property.js';
|
|
8
|
+
export * from './state.js';
|
|
9
|
+
export * from './watch.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
export interface ListenOptions {
|
|
3
|
+
target?: 'host' | 'body' | 'document' | 'window';
|
|
4
|
+
once?: boolean;
|
|
5
|
+
passive?: boolean;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
capture?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function Listen(name: string, options?: ListenOptions): (target: PlusElement, propertyKey: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
10
|
+
configurable: boolean;
|
|
11
|
+
get(): any;
|
|
12
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { appendToMethod, host, on, off } from '../utils/index.js';
|
|
3
|
+
import { Bind } from './bind.js';
|
|
4
|
+
const defaults = {
|
|
5
|
+
target: 'host'
|
|
6
|
+
};
|
|
7
|
+
export function Listen(name, options = defaults) {
|
|
8
|
+
return function (target, propertyKey, descriptor) {
|
|
9
|
+
const element = (instance) => {
|
|
10
|
+
switch (options.target) {
|
|
11
|
+
case 'body':
|
|
12
|
+
return window.document.body;
|
|
13
|
+
case 'document':
|
|
14
|
+
return window.document;
|
|
15
|
+
case 'window':
|
|
16
|
+
return window;
|
|
17
|
+
case 'host':
|
|
18
|
+
return host(instance);
|
|
19
|
+
default:
|
|
20
|
+
return host(instance);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
24
|
+
on(element(this), name, this[propertyKey], options);
|
|
25
|
+
});
|
|
26
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_DISCONNECTED, function () {
|
|
27
|
+
off(element(this), name, this[propertyKey], options);
|
|
28
|
+
});
|
|
29
|
+
return Bind()(target, propertyKey, descriptor);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { appendToMethod, defineProperty, host } from '../utils/index.js';
|
|
3
|
+
export function Method() {
|
|
4
|
+
return function (target, propertyKey) {
|
|
5
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
6
|
+
defineProperty(host(this), propertyKey, {
|
|
7
|
+
get: () => this[propertyKey].bind(this)
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
export interface PropertyOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Whether property value is reflected back to the associated attribute. default is `false`.
|
|
5
|
+
*/
|
|
6
|
+
reflect?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function Property(options?: PropertyOptions): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { paramCase } from 'change-case';
|
|
2
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
+
import { defineProperty, getMembers, host, parseValue, request, updateAttribute, appendToMethod } from '../utils/index.js';
|
|
4
|
+
export function Property(options) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const name = String(propertyKey);
|
|
7
|
+
const attribute = paramCase(name);
|
|
8
|
+
const type = getMembers(target)[name].at(0);
|
|
9
|
+
const values = new Map();
|
|
10
|
+
function get() {
|
|
11
|
+
return values.get(this);
|
|
12
|
+
}
|
|
13
|
+
function set(input) {
|
|
14
|
+
const value = values.get(this);
|
|
15
|
+
if (input === value)
|
|
16
|
+
return;
|
|
17
|
+
values.set(this, input);
|
|
18
|
+
const isReady = !!this[CONSTANTS.API_READY];
|
|
19
|
+
request(this, { [name]: [input, value, !this[CONSTANTS.API_READY]] }).then(() => {
|
|
20
|
+
const element = host(this);
|
|
21
|
+
const has = element.hasAttribute(attribute);
|
|
22
|
+
if (!isReady && has)
|
|
23
|
+
return;
|
|
24
|
+
if (!(options === null || options === void 0 ? void 0 : options.reflect))
|
|
25
|
+
return;
|
|
26
|
+
const raw = element.getAttribute(attribute);
|
|
27
|
+
const parsed = parseValue(raw, type);
|
|
28
|
+
if (input === parsed)
|
|
29
|
+
return;
|
|
30
|
+
updateAttribute(element, attribute, input);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
defineProperty(target, propertyKey, { get, set });
|
|
34
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
35
|
+
const element = host(this);
|
|
36
|
+
const get = () => {
|
|
37
|
+
return this[propertyKey];
|
|
38
|
+
};
|
|
39
|
+
const set = (input) => {
|
|
40
|
+
this[propertyKey] = input;
|
|
41
|
+
};
|
|
42
|
+
defineProperty(element, propertyKey, { get, set });
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { defineProperty, request } from '../utils/index.js';
|
|
3
|
+
export function State() {
|
|
4
|
+
return function (target, propertyKey) {
|
|
5
|
+
const name = String(propertyKey);
|
|
6
|
+
const values = new Map();
|
|
7
|
+
function get() {
|
|
8
|
+
return values.get(this);
|
|
9
|
+
}
|
|
10
|
+
function set(input) {
|
|
11
|
+
const value = values.get(this);
|
|
12
|
+
if (input === value)
|
|
13
|
+
return;
|
|
14
|
+
values.set(this, input);
|
|
15
|
+
request(this, { [name]: [input, value, !this[CONSTANTS.API_READY]] })
|
|
16
|
+
.then(() => undefined)
|
|
17
|
+
.catch((error) => {
|
|
18
|
+
throw error;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
defineProperty(target, propertyKey, { get, set });
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Monitors properties and states to catch changes.
|
|
4
|
+
* The decorated method will be invoked after any
|
|
5
|
+
* changes with the key, newValue, and oldValue as parameters.
|
|
6
|
+
* If the arguments aren't defined, all of the properties and states are considered.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Watch(keys?: Array<string>, immediate?: boolean): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { appendToMethod } from '../utils/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Monitors properties and states to catch changes.
|
|
5
|
+
* The decorated method will be invoked after any
|
|
6
|
+
* changes with the key, newValue, and oldValue as parameters.
|
|
7
|
+
* If the arguments aren't defined, all of the properties and states are considered.
|
|
8
|
+
*/
|
|
9
|
+
export function Watch(keys, immediate) {
|
|
10
|
+
return function (target, propertyKey) {
|
|
11
|
+
// Registers a lifecycle to detect changes.
|
|
12
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function ([states]) {
|
|
13
|
+
// Gets all keys
|
|
14
|
+
const keys = Object.keys(states);
|
|
15
|
+
// Loops the keys
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
// Finds current key in keys
|
|
18
|
+
const has = keys === null || keys === void 0 ? void 0 : keys.some((x) => x == key);
|
|
19
|
+
// Checks the existence of key
|
|
20
|
+
if (!has && !!(keys === null || keys === void 0 ? void 0 : keys.length))
|
|
21
|
+
continue;
|
|
22
|
+
// Gets the current state
|
|
23
|
+
const state = states === null || states === void 0 ? void 0 : states[key];
|
|
24
|
+
// Destructs the state
|
|
25
|
+
const [next, prev, isInitial] = state;
|
|
26
|
+
// TODO
|
|
27
|
+
if (!immediate && isInitial)
|
|
28
|
+
continue;
|
|
29
|
+
// Invokes the method with parameters.
|
|
30
|
+
this[propertyKey](next, prev, key);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const classes: (input: any, smart?: boolean | undefined) => string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { paramCase } from 'change-case';
|
|
2
|
+
import { typeOf } from '../utils/index.js';
|
|
3
|
+
export const classes = (input, smart) => {
|
|
4
|
+
const result = [];
|
|
5
|
+
switch (typeOf(input)) {
|
|
6
|
+
case 'array': {
|
|
7
|
+
input.forEach((item) => {
|
|
8
|
+
const value = classes(item, smart);
|
|
9
|
+
if (!value)
|
|
10
|
+
return;
|
|
11
|
+
result.push(value);
|
|
12
|
+
});
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
case 'object': {
|
|
16
|
+
const keys = Object.keys(input);
|
|
17
|
+
for (const key of keys) {
|
|
18
|
+
const value = input[key];
|
|
19
|
+
const name = paramCase(key);
|
|
20
|
+
const type = typeOf(value);
|
|
21
|
+
if (!smart) {
|
|
22
|
+
if (!value)
|
|
23
|
+
continue;
|
|
24
|
+
result.push(name);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
switch (type) {
|
|
28
|
+
case 'boolean': {
|
|
29
|
+
if (!value)
|
|
30
|
+
continue;
|
|
31
|
+
result.push(`${name}`);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case 'number': {
|
|
35
|
+
result.push(`${name}-${value}`);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case 'string': {
|
|
39
|
+
switch (value) {
|
|
40
|
+
case '':
|
|
41
|
+
case 'true':
|
|
42
|
+
result.push(`${name}`);
|
|
43
|
+
break;
|
|
44
|
+
case 'false':
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
result.push(`${name}-${value}`);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'string': {
|
|
57
|
+
result.push(input);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result.join(' ');
|
|
62
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './classes.js';
|
|
2
|
+
export * from './direction.js';
|
|
3
|
+
export * from './isRTL.js';
|
|
4
|
+
export * from './query.js';
|
|
5
|
+
export * from './queryAll.js';
|
|
6
|
+
export * from './slots.js';
|
|
7
|
+
export * from './styles.js';
|
|
8
|
+
export * from './toUnit.js';
|
|
9
|
+
export { host, isServer, on, off } from '../utils/index.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './classes.js';
|
|
2
|
+
export * from './direction.js';
|
|
3
|
+
export * from './isRTL.js';
|
|
4
|
+
export * from './query.js';
|
|
5
|
+
export * from './queryAll.js';
|
|
6
|
+
export * from './slots.js';
|
|
7
|
+
export * from './styles.js';
|
|
8
|
+
export * from './toUnit.js';
|
|
9
|
+
export { host, isServer, on, off } from '../utils/index.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function query<K extends keyof HTMLElementTagNameMap>(target: any, selectors: K): HTMLElementTagNameMap[K] | null;
|
|
2
|
+
export declare function query<K extends keyof SVGElementTagNameMap>(target: any, selectors: K): SVGElementTagNameMap[K] | null;
|
|
3
|
+
export declare function query<E extends Element = Element>(target: any, selectors: string): E | null;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function queryAll<K extends keyof HTMLElementTagNameMap>(target: any, selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
|
|
2
|
+
export declare function queryAll<K extends keyof SVGElementTagNameMap>(target: any, selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
|
|
3
|
+
export declare function queryAll<E extends Element = Element>(target: any, selectors: string): NodeListOf<E>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineProperty } from '../utils/index.js';
|
|
2
|
+
import { queryAll } from './queryAll.js';
|
|
3
|
+
export const slots = (target) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const result = {};
|
|
6
|
+
(_a = queryAll(target, 'slot')) === null || _a === void 0 ? void 0 : _a.forEach((slot) => {
|
|
7
|
+
const name = slot.name || 'default';
|
|
8
|
+
defineProperty(result, name, {
|
|
9
|
+
get() {
|
|
10
|
+
return !!slot.assignedNodes().filter((node) => { var _a; return node.nodeName != '#text' || ((_a = node.nodeValue) === null || _a === void 0 ? void 0 : _a.trim()); }).length;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: (input: any) => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { paramCase } from 'change-case';
|
|
2
|
+
import { typeOf } from '../utils/index.js';
|
|
3
|
+
export const styles = (input) => {
|
|
4
|
+
switch (typeOf(input)) {
|
|
5
|
+
case 'array':
|
|
6
|
+
return input.join('; ');
|
|
7
|
+
case 'object':
|
|
8
|
+
return Object.keys(input)
|
|
9
|
+
.filter((key) => input[key] !== undefined && input[key] !== null)
|
|
10
|
+
.map((key) => `${key.startsWith('--') ? '--' : ''}${paramCase(key)}: ${input[key]}`)
|
|
11
|
+
.join('; ');
|
|
12
|
+
case 'string':
|
|
13
|
+
return input;
|
|
14
|
+
default:
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toUnit: (input: string | number, unit?: string) => string | undefined;
|
package/client/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './link.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './link.js';
|