@htmlplus/element 0.3.0 → 0.3.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.
Files changed (162) hide show
  1. package/README.md +4 -4
  2. package/package.json +8 -45
  3. package/dist/client/decorators/attributes.d.ts +0 -2
  4. package/dist/client/decorators/attributes.js +0 -13
  5. package/dist/client/decorators/bind.d.ts +0 -4
  6. package/dist/client/decorators/bind.js +0 -17
  7. package/dist/client/decorators/element.d.ts +0 -2
  8. package/dist/client/decorators/element.js +0 -49
  9. package/dist/client/decorators/event.d.ts +0 -21
  10. package/dist/client/decorators/event.js +0 -18
  11. package/dist/client/decorators/index.d.ts +0 -9
  12. package/dist/client/decorators/index.js +0 -9
  13. package/dist/client/decorators/listen.d.ts +0 -12
  14. package/dist/client/decorators/listen.js +0 -30
  15. package/dist/client/decorators/method.d.ts +0 -2
  16. package/dist/client/decorators/method.js +0 -12
  17. package/dist/client/decorators/property.d.ts +0 -12
  18. package/dist/client/decorators/property.js +0 -51
  19. package/dist/client/decorators/state.d.ts +0 -2
  20. package/dist/client/decorators/state.js +0 -32
  21. package/dist/client/decorators/watch.d.ts +0 -2
  22. package/dist/client/decorators/watch.js +0 -17
  23. package/dist/client/helpers/classes.d.ts +0 -1
  24. package/dist/client/helpers/classes.js +0 -62
  25. package/dist/client/helpers/direction.d.ts +0 -3
  26. package/dist/client/helpers/direction.js +0 -4
  27. package/dist/client/helpers/index.d.ts +0 -9
  28. package/dist/client/helpers/index.js +0 -9
  29. package/dist/client/helpers/is-rtl.d.ts +0 -2
  30. package/dist/client/helpers/is-rtl.js +0 -2
  31. package/dist/client/helpers/query-all.d.ts +0 -3
  32. package/dist/client/helpers/query-all.js +0 -5
  33. package/dist/client/helpers/query.d.ts +0 -3
  34. package/dist/client/helpers/query.js +0 -5
  35. package/dist/client/helpers/slots.d.ts +0 -6
  36. package/dist/client/helpers/slots.js +0 -15
  37. package/dist/client/helpers/styles.d.ts +0 -1
  38. package/dist/client/helpers/styles.js +0 -16
  39. package/dist/client/helpers/to-unit.d.ts +0 -1
  40. package/dist/client/helpers/to-unit.js +0 -7
  41. package/dist/client/index.d.ts +0 -3
  42. package/dist/client/index.js +0 -3
  43. package/dist/client/services/index.d.ts +0 -1
  44. package/dist/client/services/index.js +0 -1
  45. package/dist/client/services/link.d.ts +0 -4
  46. package/dist/client/services/link.js +0 -196
  47. package/dist/client/utils/append-to-method.d.ts +0 -2
  48. package/dist/client/utils/append-to-method.js +0 -7
  49. package/dist/client/utils/call.d.ts +0 -2
  50. package/dist/client/utils/call.js +0 -4
  51. package/dist/client/utils/define-property.d.ts +0 -1
  52. package/dist/client/utils/define-property.js +0 -1
  53. package/dist/client/utils/event.d.ts +0 -2
  54. package/dist/client/utils/event.js +0 -6
  55. package/dist/client/utils/get-members.d.ts +0 -2
  56. package/dist/client/utils/get-members.js +0 -5
  57. package/dist/client/utils/get-styles.d.ts +0 -2
  58. package/dist/client/utils/get-styles.js +0 -5
  59. package/dist/client/utils/host.d.ts +0 -2
  60. package/dist/client/utils/host.js +0 -4
  61. package/dist/client/utils/index.d.ts +0 -20
  62. package/dist/client/utils/index.js +0 -20
  63. package/dist/client/utils/is-event.d.ts +0 -1
  64. package/dist/client/utils/is-event.js +0 -3
  65. package/dist/client/utils/is-ready.d.ts +0 -2
  66. package/dist/client/utils/is-ready.js +0 -4
  67. package/dist/client/utils/is-server.d.ts +0 -1
  68. package/dist/client/utils/is-server.js +0 -3
  69. package/dist/client/utils/on-ready.d.ts +0 -2
  70. package/dist/client/utils/on-ready.js +0 -6
  71. package/dist/client/utils/parse-value.d.ts +0 -1
  72. package/dist/client/utils/parse-value.js +0 -15
  73. package/dist/client/utils/render.d.ts +0 -2
  74. package/dist/client/utils/render.js +0 -19
  75. package/dist/client/utils/request.d.ts +0 -2
  76. package/dist/client/utils/request.js +0 -28
  77. package/dist/client/utils/sync.d.ts +0 -1
  78. package/dist/client/utils/sync.js +0 -31
  79. package/dist/client/utils/task.d.ts +0 -6
  80. package/dist/client/utils/task.js +0 -37
  81. package/dist/client/utils/to-boolean.d.ts +0 -1
  82. package/dist/client/utils/to-boolean.js +0 -3
  83. package/dist/client/utils/to-event.d.ts +0 -1
  84. package/dist/client/utils/to-event.js +0 -3
  85. package/dist/client/utils/type-of.d.ts +0 -3
  86. package/dist/client/utils/type-of.js +0 -6
  87. package/dist/client/utils/update-attribute.d.ts +0 -1
  88. package/dist/client/utils/update-attribute.js +0 -7
  89. package/dist/compiler/compiler.d.ts +0 -7
  90. package/dist/compiler/compiler.js +0 -55
  91. package/dist/compiler/index.d.ts +0 -2
  92. package/dist/compiler/index.js +0 -2
  93. package/dist/compiler/plugins/componentDependencyResolver.d.ts +0 -5
  94. package/dist/compiler/plugins/componentDependencyResolver.js +0 -40
  95. package/dist/compiler/plugins/customElement.d.ts +0 -5
  96. package/dist/compiler/plugins/customElement.js +0 -138
  97. package/dist/compiler/plugins/customElementReact/customElementReact.d.ts +0 -12
  98. package/dist/compiler/plugins/customElementReact/customElementReact.js +0 -125
  99. package/dist/compiler/plugins/customElementReact/index.d.ts +0 -1
  100. package/dist/compiler/plugins/customElementReact/index.js +0 -1
  101. package/dist/compiler/plugins/customElementReact/templates/README.md.hbs +0 -1
  102. package/dist/compiler/plugins/customElementReact/templates/_.gitignore.hbs +0 -2
  103. package/dist/compiler/plugins/customElementReact/templates/package.json.hbs +0 -37
  104. package/dist/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +0 -21
  105. package/dist/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +0 -17
  106. package/dist/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +0 -18
  107. package/dist/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +0 -26
  108. package/dist/compiler/plugins/customElementReact/templates/src/index.ts.hbs +0 -1
  109. package/dist/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +0 -278
  110. package/dist/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +0 -17
  111. package/dist/compiler/plugins/docs.d.ts +0 -11
  112. package/dist/compiler/plugins/docs.js +0 -320
  113. package/dist/compiler/plugins/extract.d.ts +0 -8
  114. package/dist/compiler/plugins/extract.js +0 -70
  115. package/dist/compiler/plugins/index.d.ts +0 -7
  116. package/dist/compiler/plugins/index.js +0 -7
  117. package/dist/compiler/plugins/parse.d.ts +0 -5
  118. package/dist/compiler/plugins/parse.js +0 -16
  119. package/dist/compiler/plugins/read.d.ts +0 -5
  120. package/dist/compiler/plugins/read.js +0 -13
  121. package/dist/compiler/plugins/style.d.ts +0 -12
  122. package/dist/compiler/plugins/style.js +0 -42
  123. package/dist/compiler/plugins/validate.d.ts +0 -5
  124. package/dist/compiler/plugins/validate.js +0 -40
  125. package/dist/compiler/plugins/vscode.d.ts +0 -11
  126. package/dist/compiler/plugins/vscode.js +0 -83
  127. package/dist/compiler/utils/__dirname.d.ts +0 -1
  128. package/dist/compiler/utils/__dirname.js +0 -5
  129. package/dist/compiler/utils/get-initializer.d.ts +0 -2
  130. package/dist/compiler/utils/get-initializer.js +0 -10
  131. package/dist/compiler/utils/get-tags.d.ts +0 -6
  132. package/dist/compiler/utils/get-tags.js +0 -34
  133. package/dist/compiler/utils/get-type.d.ts +0 -2
  134. package/dist/compiler/utils/get-type.js +0 -69
  135. package/dist/compiler/utils/has-decorator.d.ts +0 -1
  136. package/dist/compiler/utils/has-decorator.js +0 -5
  137. package/dist/compiler/utils/index.d.ts +0 -10
  138. package/dist/compiler/utils/index.js +0 -10
  139. package/dist/compiler/utils/is-directory-empty.d.ts +0 -1
  140. package/dist/compiler/utils/is-directory-empty.js +0 -10
  141. package/dist/compiler/utils/print-type.d.ts +0 -1
  142. package/dist/compiler/utils/print-type.js +0 -69
  143. package/dist/compiler/utils/print.d.ts +0 -2
  144. package/dist/compiler/utils/print.js +0 -5
  145. package/dist/compiler/utils/render-template.d.ts +0 -1
  146. package/dist/compiler/utils/render-template.js +0 -25
  147. package/dist/compiler/utils/visitor.d.ts +0 -2
  148. package/dist/compiler/utils/visitor.js +0 -5
  149. package/dist/constants/index.d.ts +0 -23
  150. package/dist/constants/index.js +0 -29
  151. package/dist/runtime/index.d.ts +0 -1
  152. package/dist/runtime/index.js +0 -4
  153. package/dist/types/context.d.ts +0 -32
  154. package/dist/types/context.js +0 -1
  155. package/dist/types/global.d.ts +0 -4
  156. package/dist/types/global.js +0 -1
  157. package/dist/types/index.d.ts +0 -4
  158. package/dist/types/index.js +0 -4
  159. package/dist/types/plugin.d.ts +0 -9
  160. package/dist/types/plugin.js +0 -1
  161. package/dist/types/plus-element.d.ts +0 -2
  162. package/dist/types/plus-element.js +0 -1
@@ -1 +0,0 @@
1
- export * from './link.js';
@@ -1,4 +0,0 @@
1
- export declare type LinkConfig = {
2
- scope?: Function;
3
- };
4
- export declare const createLink: (namespace: string) => any;
@@ -1,196 +0,0 @@
1
- import { defineProperty, host } from '../utils/index.js';
2
- const links = new Map();
3
- // TODO: return type
4
- export const createLink = (namespace) => {
5
- if (links.has(namespace))
6
- return links.get(namespace);
7
- const config = {
8
- scope: (i) => i.connector
9
- };
10
- let disconnecting = false;
11
- const children = new Map();
12
- const parents = new Map();
13
- const properties = [];
14
- const find = (source) => {
15
- return properties.find((destination) => destination.instance === source.instance && destination.name === source.name);
16
- };
17
- const register = (source) => {
18
- properties.push(source);
19
- if (!children.has(source.instance))
20
- children.set(source.instance, new Set());
21
- // TODO: any
22
- const siblings = children.get(source.instance);
23
- siblings.add(source);
24
- };
25
- const unregister = (source) => {
26
- // TODO: any
27
- source = find(source);
28
- const index = properties.findIndex((property) => property === source);
29
- if (index === -1)
30
- return;
31
- properties.splice(index, 1);
32
- // TODO: any
33
- const siblings = children.get(source.instance);
34
- siblings.delete(source);
35
- if (siblings.size)
36
- return;
37
- children.delete(source.instance);
38
- parents.delete(source.instance);
39
- };
40
- const get = (source) => {
41
- // TODO: any
42
- return source.instance[source.name];
43
- };
44
- const set = (source, value) => {
45
- // TODO: any
46
- source.instance[source.name] = value;
47
- };
48
- const reset = (source) => {
49
- if (source.type === 'action')
50
- return;
51
- if (source.type === 'inject')
52
- return set(source, source.value /* TODO */);
53
- // TODO: any
54
- defineProperty(source.instance, source.name, {
55
- value: get(source) /* TODO */,
56
- enumerable: true,
57
- configurable: true
58
- });
59
- };
60
- const map = (source, destination) => {
61
- let value = get(source);
62
- if (typeof value === 'function')
63
- value = value.bind(source.instance);
64
- set(destination, value);
65
- };
66
- const proxy = (source) => {
67
- let value = get(source);
68
- // TODO: any
69
- defineProperty(source.instance, source.name, {
70
- enumerable: true,
71
- configurable: true,
72
- get() {
73
- return value;
74
- },
75
- set(input) {
76
- if (input === value)
77
- return;
78
- value = input;
79
- siblings(source, ['inject']).map((destination) => set(destination, value));
80
- }
81
- });
82
- };
83
- const parent = (source) => {
84
- var _a;
85
- const cache = parents.get(source.instance);
86
- if (cache)
87
- return cache;
88
- // TODO: element? and any
89
- let parent = (_a = source.element) === null || _a === void 0 ? void 0 : _a.parentElement;
90
- while (parent) {
91
- if (parent.shadowRoot) {
92
- const item = properties.find((property) => property.element === parent && property.name === source.name);
93
- if (item) {
94
- parents.set(source.instance, item);
95
- return item;
96
- }
97
- }
98
- parent = parent.parentElement;
99
- }
100
- };
101
- const scope = (source) => {
102
- var _a, _b;
103
- if (!source)
104
- return;
105
- // TODO
106
- if (disconnecting)
107
- return source.instance['$scope-prev'];
108
- // TODO: &&
109
- let input = config.scope && config.scope(source.instance);
110
- if (typeof input !== 'undefined')
111
- return input;
112
- // TODO: any
113
- return ((_b = (_a = scope(parent(source))) !== null && _a !== void 0 ? _a : source.instance['$scope-auto']) !== null && _b !== void 0 ? _b : (source.instance['$scope-auto'] = Math.random()));
114
- };
115
- const siblings = (source, types) => {
116
- return properties.filter((destination) => {
117
- // TODO: any
118
- if (!types.includes(destination.type))
119
- return false;
120
- if (source === destination)
121
- return false;
122
- if (source.name !== destination.name)
123
- return false;
124
- if (scope(source) !== scope(destination))
125
- return false;
126
- return true;
127
- });
128
- };
129
- const connect = (source) => {
130
- // TODO
131
- source.instance['$scope-prev'] = scope(source);
132
- register(source);
133
- switch (source.type) {
134
- case 'action':
135
- siblings(source, ['inject']).forEach((destination) => map(source, destination));
136
- break;
137
- case 'observable':
138
- proxy(source);
139
- siblings(source, ['inject']).forEach((destination) => map(source, destination));
140
- break;
141
- case 'inject':
142
- siblings(source, ['action', 'observable']).forEach((destination) => map(destination, source));
143
- break;
144
- }
145
- };
146
- const disconnect = (source) => {
147
- reset(source);
148
- if (source.type === 'inject')
149
- return unregister(source);
150
- siblings(source, ['inject']).forEach(reset);
151
- unregister(source);
152
- };
153
- const reconnect = (instance) => {
154
- const p = properties.filter((property) => property.instance === instance);
155
- disconnecting = true;
156
- p.forEach(disconnect);
157
- disconnecting = false;
158
- p.forEach(connect);
159
- };
160
- const decorator = (type) => () => (target, name) => {
161
- const connected = target.connectedCallback;
162
- target.connectedCallback = function () {
163
- connected && connected.bind(this)();
164
- const property = {
165
- element: host(this),
166
- instance: this,
167
- name,
168
- type,
169
- value: this[name]
170
- };
171
- if (find(property))
172
- console.error('TODO: Error log');
173
- connect(property);
174
- };
175
- const disconnected = target.disconnectedCallback;
176
- target.disconnectedCallback = function () {
177
- disconnected && disconnected.bind(this)();
178
- const property = find({ instance: this, name });
179
- if (!property)
180
- console.error('TODO: Error log');
181
- // TODO: any
182
- disconnect(property);
183
- };
184
- };
185
- const Action = decorator('action');
186
- const Inject = decorator('inject');
187
- const Observable = decorator('observable');
188
- const result = {
189
- Action,
190
- Inject,
191
- Observable,
192
- reconnect
193
- };
194
- links.set(namespace, result);
195
- return result;
196
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const appendToMethod: (target: PlusElement, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
@@ -1,7 +0,0 @@
1
- export const appendToMethod = (target, propertyKey, handler) => {
2
- const callback = target[propertyKey];
3
- target[propertyKey] = function () {
4
- handler.bind(this)(Array.from(arguments));
5
- return callback === null || callback === void 0 ? void 0 : callback.bind(this)(arguments);
6
- };
7
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const call: (target: PlusElement, key: string, ...args: Array<any>) => any;
@@ -1,4 +0,0 @@
1
- export const call = (target, key, ...args) => {
2
- var _a;
3
- return (_a = target[key]) === null || _a === void 0 ? void 0 : _a.call(target, ...args);
4
- };
@@ -1 +0,0 @@
1
- export declare const defineProperty: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
@@ -1 +0,0 @@
1
- export const defineProperty = Object.defineProperty;
@@ -1,2 +0,0 @@
1
- export declare const on: (target: Window | Document | Element, event: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined) => void;
2
- export declare const off: (target: Window | Document | Element, event: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined) => void;
@@ -1,6 +0,0 @@
1
- export const on = (target, event, handler, options) => {
2
- target.addEventListener(event, handler, options);
3
- };
4
- export const off = (target, event, handler, options) => {
5
- target.removeEventListener(event, handler, options);
6
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const getMembers: (target: PlusElement) => any;
@@ -1,5 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- export const getMembers = (target) => {
3
- var _a;
4
- return (_a = target.constructor[CONSTANTS.STATIC_MEMBERS]) !== null && _a !== void 0 ? _a : target[CONSTANTS.STATIC_MEMBERS];
5
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const getStyles: (target: PlusElement) => string | undefined;
@@ -1,5 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- export const getStyles = (target) => {
3
- var _a;
4
- return (_a = target.constructor[CONSTANTS.STATIC_STYLES]) !== null && _a !== void 0 ? _a : target[CONSTANTS.STATIC_STYLES];
5
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const host: (target: PlusElement) => HTMLElement;
@@ -1,4 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- export const host = (target) => {
3
- return target[CONSTANTS.API_HOST]();
4
- };
@@ -1,20 +0,0 @@
1
- export * from './append-to-method.js';
2
- export * from './call.js';
3
- export * from './define-property.js';
4
- export * from './event.js';
5
- export * from './get-members.js';
6
- export * from './get-styles.js';
7
- export * from './host.js';
8
- export * from './is-event.js';
9
- export * from './is-ready.js';
10
- export * from './is-server.js';
11
- export * from './on-ready.js';
12
- export * from './parse-value.js';
13
- export * from './render.js';
14
- export * from './request.js';
15
- export * from './sync.js';
16
- export * from './task.js';
17
- export * from './to-boolean.js';
18
- export * from './to-event.js';
19
- export * from './type-of.js';
20
- export * from './update-attribute.js';
@@ -1,20 +0,0 @@
1
- export * from './append-to-method.js';
2
- export * from './call.js';
3
- export * from './define-property.js';
4
- export * from './event.js';
5
- export * from './get-members.js';
6
- export * from './get-styles.js';
7
- export * from './host.js';
8
- export * from './is-event.js';
9
- export * from './is-ready.js';
10
- export * from './is-server.js';
11
- export * from './on-ready.js';
12
- export * from './parse-value.js';
13
- export * from './render.js';
14
- export * from './request.js';
15
- export * from './sync.js';
16
- export * from './task.js';
17
- export * from './to-boolean.js';
18
- export * from './to-event.js';
19
- export * from './type-of.js';
20
- export * from './update-attribute.js';
@@ -1 +0,0 @@
1
- export declare const isEvent: (input: string) => boolean;
@@ -1,3 +0,0 @@
1
- export const isEvent = (input) => {
2
- return !!(input === null || input === void 0 ? void 0 : input.match(/on[A-Z]\w+/g));
3
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const isReady: (target: PlusElement) => boolean;
@@ -1,4 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- export const isReady = (target) => {
3
- return target[CONSTANTS.API_READY];
4
- };
@@ -1 +0,0 @@
1
- export declare const isServer: () => boolean;
@@ -1,3 +0,0 @@
1
- export const isServer = () => {
2
- return !(typeof window != 'undefined' && window.document);
3
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare function onReady(target: PlusElement, callback: (this: any) => void): void;
@@ -1,6 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- export function onReady(target, callback) {
3
- var _a;
4
- var _b;
5
- ((_a = target[_b = CONSTANTS.API_SETUP]) !== null && _a !== void 0 ? _a : (target[_b] = [])).push(callback);
6
- }
@@ -1 +0,0 @@
1
- export declare const parseValue: (value: any, type: any) => any;
@@ -1,15 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- import { toBoolean } from './to-boolean.js';
3
- // TODO: input type & validate date
4
- export const parseValue = (value, type) => {
5
- switch (type) {
6
- case CONSTANTS.TYPE_BOOLEAN:
7
- return toBoolean(value);
8
- case CONSTANTS.TYPE_DATE:
9
- return new Date(value);
10
- case CONSTANTS.TYPE_NUMBER:
11
- return parseFloat(value);
12
- default:
13
- return value;
14
- }
15
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const render: (target: PlusElement) => void;
@@ -1,19 +0,0 @@
1
- import { html, render as renderer } from 'uhtml';
2
- import * as CONSTANTS from '../../constants/index.js';
3
- import { call } from './call.js';
4
- import { getStyles } from './get-styles.js';
5
- import { host } from './host.js';
6
- export const render = (target) => {
7
- const element = host(target);
8
- renderer(element.shadowRoot, () => {
9
- const markup = call(target, CONSTANTS.METHOD_RENDER);
10
- const styles = getStyles(target);
11
- if (!styles && !markup)
12
- return html ``;
13
- if (!styles)
14
- return markup;
15
- if (!markup)
16
- return html `<style>${styles}</style>`;
17
- return html `<style>${styles}</style>${markup}`;
18
- });
19
- };
@@ -1,2 +0,0 @@
1
- import { PlusElement } from '../../types/index.js';
2
- export declare const request: (target: PlusElement, state?: any) => Promise<boolean>;
@@ -1,28 +0,0 @@
1
- import * as CONSTANTS from '../../constants/index.js';
2
- import { call } from '../utils/call';
3
- import { isReady } from '../utils/is-ready';
4
- import { render } from '../utils/render';
5
- import { task } from '../utils/task';
6
- const targets = new Map();
7
- export const request = (target, state) => {
8
- if (!isReady(target))
9
- return Promise.resolve(false);
10
- let run = targets.get(target);
11
- if (run)
12
- return run(state);
13
- run = task({
14
- canStart: (states, state) => {
15
- return /* hasChange */ true;
16
- },
17
- canRun: (states) => {
18
- return /* shouldUpdate */ true;
19
- },
20
- run: (states) => {
21
- call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
22
- render(target);
23
- call(target, CONSTANTS.LIFECYCLE_UPDATED, states);
24
- }
25
- });
26
- targets.set(target, run);
27
- return run(state);
28
- };
@@ -1 +0,0 @@
1
- export declare const sync: (node: HTMLElement) => (next?: any) => void;
@@ -1,31 +0,0 @@
1
- import { on, off } from './event.js';
2
- import { isEvent } from './is-event.js';
3
- import { toEvent } from './to-event.js';
4
- import { updateAttribute } from './update-attribute.js';
5
- export const sync = (node) => {
6
- let prev = {};
7
- return (next = {}) => {
8
- const prevClass = (prev.class || '').split(' ');
9
- const nextClass = (next.class || '').split(' ');
10
- const newClass = node.className
11
- .split(' ')
12
- .filter((key) => !prevClass.includes(key) && !nextClass.includes(key))
13
- .concat(nextClass)
14
- .filter((key) => key)
15
- .join(' ');
16
- updateAttribute(node, 'class', newClass || undefined);
17
- if (prev.style || next.style)
18
- node.setAttribute('style', next.style || '');
19
- for (const key in prev)
20
- isEvent(key) && off(node, toEvent(key), prev[key]);
21
- for (const key in next) {
22
- if (['class', 'style'].includes(key))
23
- continue;
24
- if (isEvent(key))
25
- on(node, toEvent(key), next[key]);
26
- else
27
- updateAttribute(node, key, next[key]);
28
- }
29
- prev = Object.assign({}, next);
30
- };
31
- };
@@ -1,6 +0,0 @@
1
- export interface QueueOptions {
2
- canStart?: (states: any, state: any) => boolean;
3
- canRun?: (states: any) => boolean;
4
- run: (states: any) => void;
5
- }
6
- export declare const task: (options: QueueOptions) => (state?: any) => Promise<boolean>;
@@ -1,37 +0,0 @@
1
- export const task = (options) => {
2
- let states, isPending, updatePromise;
3
- const run = (state) => {
4
- const newStates = Object.assign({}, states, state);
5
- if (options.canStart && !options.canStart(newStates, state))
6
- return Promise.resolve(false);
7
- states = newStates;
8
- if (!isPending)
9
- updatePromise = enqueue();
10
- return updatePromise;
11
- };
12
- const enqueue = async () => {
13
- isPending = true;
14
- try {
15
- await updatePromise;
16
- }
17
- catch (error) {
18
- Promise.reject(error);
19
- }
20
- // TODO: maybe is optional
21
- if (!isPending)
22
- return updatePromise;
23
- try {
24
- if (options.canRun && !options.canRun(states))
25
- return (isPending = false);
26
- options.run(states);
27
- states = undefined;
28
- isPending = false;
29
- return true;
30
- }
31
- catch (error) {
32
- isPending = false;
33
- throw error;
34
- }
35
- };
36
- return run;
37
- };
@@ -1 +0,0 @@
1
- export declare const toBoolean: (input: any) => boolean;
@@ -1,3 +0,0 @@
1
- export const toBoolean = (input) => {
2
- return ![undefined, null, false, 'false'].includes(input);
3
- };
@@ -1 +0,0 @@
1
- export declare const toEvent: (input: string) => string;
@@ -1,3 +0,0 @@
1
- export const toEvent = (input) => {
2
- return input === null || input === void 0 ? void 0 : input.slice(2).toLowerCase();
3
- };
@@ -1,3 +0,0 @@
1
- declare type Types = 'array' | 'boolean' | 'function' | 'number' | 'object' | 'string';
2
- export declare const typeOf: (input: any) => Types;
3
- export {};
@@ -1,6 +0,0 @@
1
- export const typeOf = (input) => {
2
- return Object.prototype.toString
3
- .call(input)
4
- .replace(/\[|\]|object| /g, '')
5
- .toLowerCase();
6
- };
@@ -1 +0,0 @@
1
- export declare const updateAttribute: (node: Element, key: string, value: any) => void;
@@ -1,7 +0,0 @@
1
- import { paramCase } from 'change-case';
2
- export const updateAttribute = (node, key, value) => {
3
- const name = paramCase(key);
4
- if ([undefined, null, false].includes(value))
5
- return node.removeAttribute(name);
6
- node.setAttribute(name, value === true ? '' : value);
7
- };
@@ -1,7 +0,0 @@
1
- import { Context, Plugin } from '../types/index.js';
2
- declare const _default: (...plugins: Array<Plugin>) => {
3
- start: () => Promise<void>;
4
- next: (filePath: string) => Promise<Context>;
5
- finish: () => Promise<void>;
6
- };
7
- export default _default;
@@ -1,55 +0,0 @@
1
- import logUpdate from 'log-update';
2
- const log = (namespace, message, persist) => {
3
- logUpdate(`${new Date().toLocaleTimeString()} [@htmlplus/element]${namespace ? `[${namespace}]` : ''} ${message}`);
4
- persist && logUpdate.done();
5
- };
6
- export default (...plugins) => {
7
- let global = {
8
- contexts: []
9
- };
10
- const start = async () => {
11
- log(undefined, 'Starting...', true);
12
- for (const plugin of plugins) {
13
- if (plugin.start) {
14
- global = (await plugin.start(global)) || global;
15
- }
16
- log(plugin.name, 'Started successfully.');
17
- }
18
- log(undefined, `${plugins.length} Plugins started successfully.`, true);
19
- };
20
- const next = async (filePath) => {
21
- const key = filePath.split(/[\/|\\]/g).pop();
22
- let context = {
23
- filePath
24
- };
25
- log(`${key}`, 'Executing...');
26
- for (const plugin of plugins) {
27
- if (!plugin.next)
28
- continue;
29
- context = (await plugin.next(context, global)) || context;
30
- global.contexts = global.contexts.filter((current) => current.filePath != context.filePath).concat(context);
31
- if (context.isInvalid)
32
- break;
33
- }
34
- if (context.isInvalid)
35
- log(key, 'Break executing because file is invalid.');
36
- else
37
- log(key, 'Executed successfully.');
38
- return context;
39
- };
40
- const finish = async () => {
41
- log(undefined, 'Finishing...', true);
42
- for (const plugin of plugins) {
43
- if (plugin.finish) {
44
- global = (await plugin.finish(global)) || global;
45
- }
46
- log(plugin.name, 'Finished successfully.');
47
- }
48
- log(undefined, `${plugins.length} Plugins finished successfully.`, true);
49
- };
50
- return {
51
- start,
52
- next,
53
- finish
54
- };
55
- };
@@ -1,2 +0,0 @@
1
- export { default as default } from './compiler.js';
2
- export * from './plugins/index.js';
@@ -1,2 +0,0 @@
1
- export { default as default } from './compiler.js';
2
- export * from './plugins/index.js';
@@ -1,5 +0,0 @@
1
- import { Context, Global } from '../../types/index.js';
2
- export declare const componentDependencyResolver: () => {
3
- name: string;
4
- next: (context: Context, global: Global) => void;
5
- };