@htmlplus/element 1.0.0 → 2.0.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.
Files changed (184) hide show
  1. package/README.md +616 -534
  2. package/bundlers/rollup.d.ts +2 -2
  3. package/bundlers/rollup.js +5 -5
  4. package/bundlers/vite.d.ts +2 -2
  5. package/bundlers/vite.js +5 -5
  6. package/client/decorators/bind.d.ts +4 -0
  7. package/client/decorators/bind.js +4 -0
  8. package/client/decorators/direction.d.ts +5 -0
  9. package/client/decorators/direction.js +8 -0
  10. package/client/decorators/element.d.ts +5 -0
  11. package/client/decorators/element.js +7 -2
  12. package/client/decorators/event.d.ts +21 -7
  13. package/client/decorators/event.js +7 -2
  14. package/client/decorators/host.d.ts +4 -2
  15. package/client/decorators/host.js +5 -8
  16. package/client/decorators/index.d.ts +3 -0
  17. package/client/decorators/index.js +3 -0
  18. package/client/decorators/isRTL.d.ts +4 -0
  19. package/client/decorators/isRTL.js +7 -0
  20. package/client/decorators/listen.d.ts +38 -8
  21. package/client/decorators/listen.js +9 -12
  22. package/client/decorators/method.d.ts +4 -0
  23. package/client/decorators/method.js +4 -0
  24. package/client/decorators/property.d.ts +8 -1
  25. package/client/decorators/property.js +4 -0
  26. package/client/decorators/query.d.ts +9 -2
  27. package/client/decorators/query.js +10 -9
  28. package/client/decorators/queryAll.d.ts +12 -2
  29. package/client/decorators/queryAll.js +13 -9
  30. package/client/decorators/slots.d.ts +4 -0
  31. package/client/decorators/slots.js +7 -0
  32. package/client/decorators/state.d.ts +4 -0
  33. package/client/decorators/state.js +4 -0
  34. package/client/decorators/watch.d.ts +5 -4
  35. package/client/decorators/watch.js +5 -4
  36. package/client/index.d.ts +1 -3
  37. package/client/index.js +1 -3
  38. package/client/utils/classes.d.ts +3 -0
  39. package/client/utils/classes.js +11 -28
  40. package/client/utils/config.d.ts +25 -3
  41. package/client/utils/config.js +18 -10
  42. package/client/utils/direction.d.ts +5 -2
  43. package/client/utils/direction.js +5 -1
  44. package/client/utils/event.d.ts +6 -0
  45. package/client/utils/event.js +6 -0
  46. package/client/utils/host.d.ts +3 -0
  47. package/client/utils/host.js +3 -0
  48. package/client/utils/index.d.ts +4 -1
  49. package/client/utils/index.js +4 -1
  50. package/client/utils/isCSSColor.d.ts +5 -0
  51. package/client/utils/isCSSColor.js +9 -0
  52. package/client/utils/isRTL.d.ts +3 -0
  53. package/client/utils/isRTL.js +3 -0
  54. package/client/utils/isServer.d.ts +3 -0
  55. package/client/utils/isServer.js +3 -0
  56. package/client/utils/query.d.ts +5 -0
  57. package/client/utils/query.js +8 -0
  58. package/client/utils/queryAll.d.ts +5 -0
  59. package/client/utils/queryAll.js +8 -0
  60. package/client/utils/request.d.ts +1 -1
  61. package/client/utils/request.js +1 -1
  62. package/client/utils/slots.d.ts +3 -0
  63. package/client/utils/slots.js +6 -1
  64. package/client/utils/styles.d.ts +3 -0
  65. package/client/utils/styles.js +3 -0
  66. package/client/utils/toDecorator.d.ts +2 -0
  67. package/client/utils/toDecorator.js +10 -0
  68. package/client/utils/toUnit.d.ts +4 -1
  69. package/client/utils/toUnit.js +6 -3
  70. package/constants/index.d.ts +1 -0
  71. package/constants/index.js +2 -0
  72. package/package.json +3 -3
  73. package/transformer/index.d.ts +3 -0
  74. package/transformer/index.js +3 -0
  75. package/transformer/plugins/assets.d.ts +8 -0
  76. package/transformer/plugins/assets.js +29 -0
  77. package/{compiler → transformer}/plugins/copy.d.ts +2 -2
  78. package/{compiler → transformer}/plugins/customElement.d.ts +2 -2
  79. package/{compiler → transformer}/plugins/customElement.js +13 -12
  80. package/transformer/plugins/document.d.ts +7 -0
  81. package/{compiler → transformer}/plugins/document.js +18 -18
  82. package/transformer/plugins/extract.d.ts +2 -0
  83. package/{compiler → transformer}/plugins/extract.js +1 -18
  84. package/{compiler → transformer}/plugins/index.d.ts +0 -1
  85. package/{compiler → transformer}/plugins/index.js +0 -1
  86. package/transformer/plugins/parse.d.ts +6 -0
  87. package/{compiler → transformer}/plugins/parse.js +1 -1
  88. package/transformer/plugins/read.d.ts +8 -0
  89. package/transformer/plugins/read.js +20 -0
  90. package/transformer/plugins/readme.d.ts +6 -0
  91. package/{compiler → transformer}/plugins/readme.js +3 -2
  92. package/transformer/plugins/style.d.ts +6 -0
  93. package/{compiler → transformer}/plugins/style.js +4 -2
  94. package/transformer/plugins/validate.d.ts +2 -0
  95. package/transformer/plugins/validate.js +41 -0
  96. package/transformer/plugins/visualStudioCode.d.ts +8 -0
  97. package/{compiler → transformer}/plugins/visualStudioCode.js +10 -8
  98. package/transformer/plugins/webTypes.d.ts +10 -0
  99. package/{compiler → transformer}/plugins/webTypes.js +11 -7
  100. package/transformer/transformer.d.ts +6 -0
  101. package/{compiler/compiler.js → transformer/transformer.js} +17 -17
  102. package/transformer/transformer.types.d.ts +50 -0
  103. package/{compiler → transformer}/utils/printType.js +2 -2
  104. package/{compiler → transformer}/utils/renderTemplate.js +2 -0
  105. package/types/index.d.ts +2 -4
  106. package/types/index.js +1 -4
  107. package/CHANGELOG.md +0 -7
  108. package/bundlers/index.d.ts +0 -2
  109. package/bundlers/index.js +0 -2
  110. package/client/helpers/index.d.ts +0 -1
  111. package/client/helpers/index.js +0 -1
  112. package/client/services/index.d.ts +0 -1
  113. package/client/services/index.js +0 -1
  114. package/client/services/link.d.ts +0 -4
  115. package/client/services/link.js +0 -196
  116. package/client/utils/getNamespace.d.ts +0 -2
  117. package/client/utils/getNamespace.js +0 -4
  118. package/client/vendors/uhtml.d.ts +0 -29
  119. package/client/vendors/uhtml.js +0 -700
  120. package/compiler/compiler.d.ts +0 -6
  121. package/compiler/index.d.ts +0 -2
  122. package/compiler/index.js +0 -2
  123. package/compiler/plugins/assets.d.ts +0 -8
  124. package/compiler/plugins/assets.js +0 -33
  125. package/compiler/plugins/customElementReact/customElementReact.d.ts +0 -16
  126. package/compiler/plugins/customElementReact/customElementReact.js +0 -97
  127. package/compiler/plugins/customElementReact/index.d.ts +0 -1
  128. package/compiler/plugins/customElementReact/index.js +0 -1
  129. package/compiler/plugins/customElementReact/templates/README.md.hbs +0 -1
  130. package/compiler/plugins/customElementReact/templates/_.gitignore.hbs +0 -2
  131. package/compiler/plugins/customElementReact/templates/package.json.hbs +0 -37
  132. package/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +0 -21
  133. package/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +0 -17
  134. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +0 -18
  135. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +0 -23
  136. package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +0 -1
  137. package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +0 -269
  138. package/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +0 -17
  139. package/compiler/plugins/document.d.ts +0 -7
  140. package/compiler/plugins/extract.d.ts +0 -2
  141. package/compiler/plugins/parse.d.ts +0 -5
  142. package/compiler/plugins/read.d.ts +0 -8
  143. package/compiler/plugins/read.js +0 -13
  144. package/compiler/plugins/readme.d.ts +0 -6
  145. package/compiler/plugins/style.d.ts +0 -6
  146. package/compiler/plugins/validate.d.ts +0 -2
  147. package/compiler/plugins/validate.js +0 -37
  148. package/compiler/plugins/visualStudioCode.d.ts +0 -8
  149. package/compiler/plugins/webTypes.d.ts +0 -10
  150. package/types/context.d.ts +0 -31
  151. package/types/global.d.ts +0 -4
  152. package/types/global.js +0 -1
  153. package/types/plugin.d.ts +0 -10
  154. package/types/plugin.js +0 -1
  155. package/types/plusElement.d.ts +0 -2
  156. package/types/plusElement.js +0 -1
  157. /package/{compiler → transformer}/plugins/copy.js +0 -0
  158. /package/{types/context.js → transformer/transformer.types.js} +0 -0
  159. /package/{compiler → transformer}/utils/__dirname.d.ts +0 -0
  160. /package/{compiler → transformer}/utils/__dirname.js +0 -0
  161. /package/{compiler → transformer}/utils/addDependency.d.ts +0 -0
  162. /package/{compiler → transformer}/utils/addDependency.js +0 -0
  163. /package/{compiler → transformer}/utils/getInitializer.d.ts +0 -0
  164. /package/{compiler → transformer}/utils/getInitializer.js +0 -0
  165. /package/{compiler → transformer}/utils/getType.d.ts +0 -0
  166. /package/{compiler → transformer}/utils/getType.js +0 -0
  167. /package/{compiler → transformer}/utils/getTypeReference.d.ts +0 -0
  168. /package/{compiler → transformer}/utils/getTypeReference.js +0 -0
  169. /package/{compiler → transformer}/utils/hasDecorator.d.ts +0 -0
  170. /package/{compiler → transformer}/utils/hasDecorator.js +0 -0
  171. /package/{compiler → transformer}/utils/index.d.ts +0 -0
  172. /package/{compiler → transformer}/utils/index.js +0 -0
  173. /package/{compiler → transformer}/utils/isDirectoryEmpty.d.ts +0 -0
  174. /package/{compiler → transformer}/utils/isDirectoryEmpty.js +0 -0
  175. /package/{compiler → transformer}/utils/print.d.ts +0 -0
  176. /package/{compiler → transformer}/utils/print.js +0 -0
  177. /package/{compiler → transformer}/utils/printType.d.ts +0 -0
  178. /package/{compiler → transformer}/utils/removeUnusedImport.d.ts +0 -0
  179. /package/{compiler → transformer}/utils/removeUnusedImport.js +0 -0
  180. /package/{compiler → transformer}/utils/renderTemplate.d.ts +0 -0
  181. /package/{compiler → transformer}/utils/tags.d.ts +0 -0
  182. /package/{compiler → transformer}/utils/tags.js +0 -0
  183. /package/{compiler → transformer}/utils/visitor.d.ts +0 -0
  184. /package/{compiler → transformer}/utils/visitor.js +0 -0
@@ -1,15 +1,15 @@
1
1
  import { kebabCase } from 'change-case';
2
2
  import { typeOf } from './typeOf.js';
3
+ /**
4
+ * TODO
5
+ */
3
6
  export const classes = (input, smart) => {
4
7
  const result = [];
5
8
  switch (typeOf(input)) {
6
9
  case 'array': {
7
- input.forEach((item) => {
8
- const value = classes(item, smart);
9
- if (!value)
10
- return;
11
- result.push(value);
12
- });
10
+ for (const item of input) {
11
+ result.push(classes(item, smart));
12
+ }
13
13
  break;
14
14
  }
15
15
  case 'object': {
@@ -19,34 +19,17 @@ export const classes = (input, smart) => {
19
19
  const name = kebabCase(key);
20
20
  const type = typeOf(value);
21
21
  if (!smart) {
22
- if (!value)
23
- continue;
24
- result.push(name);
22
+ value && result.push(name);
25
23
  continue;
26
24
  }
27
25
  switch (type) {
28
26
  case 'boolean': {
29
- if (!value)
30
- continue;
31
- result.push(`${name}`);
32
- break;
33
- }
34
- case 'number': {
35
- result.push(`${name}-${value}`);
27
+ value && result.push(`${name}`);
36
28
  break;
37
29
  }
30
+ case 'number':
38
31
  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
- }
32
+ result.push(`${name}-${value}`);
50
33
  break;
51
34
  }
52
35
  }
@@ -58,5 +41,5 @@ export const classes = (input, smart) => {
58
41
  break;
59
42
  }
60
43
  }
61
- return result.join(' ');
44
+ return result.filter((item) => item).join(' ');
62
45
  };
@@ -1,8 +1,11 @@
1
+ /**
2
+ * TODO
3
+ */
1
4
  export interface Config {
2
5
  asset?: {
3
6
  [key: string]: any;
4
7
  };
5
- component?: {
8
+ element?: {
6
9
  [key: string]: {
7
10
  property?: {
8
11
  [key: string]: any;
@@ -10,5 +13,24 @@ export interface Config {
10
13
  };
11
14
  };
12
15
  }
13
- export declare const getConfig: (namespace: string, ...parameters: string[]) => any;
14
- export declare const setConfig: (namespace: string, config: Config, override?: boolean) => void;
16
+ /**
17
+ * TODO
18
+ */
19
+ export interface ConfigOptions {
20
+ /**
21
+ * TODO
22
+ */
23
+ force?: boolean;
24
+ /**
25
+ * TODO
26
+ */
27
+ override?: boolean;
28
+ }
29
+ /**
30
+ * TODO
31
+ */
32
+ export declare const getConfig: (...keys: string[]) => any;
33
+ /**
34
+ * TODO
35
+ */
36
+ export declare const setConfig: (config: Config, options?: ConfigOptions) => void;
@@ -1,20 +1,28 @@
1
+ import { isServer } from './isServer.js';
1
2
  import { merge } from './merge.js';
2
- let defaults = {
3
- component: {}
3
+ const DEFAULTS = {
4
+ element: {}
4
5
  };
5
- export const getConfig = (namespace, ...parameters) => {
6
- if (typeof window == 'undefined')
6
+ /**
7
+ * TODO
8
+ */
9
+ export const getConfig = (...keys) => {
10
+ if (isServer())
7
11
  return;
8
- let config = window[namespace];
9
- for (const parameter of parameters) {
12
+ let config = window[`$htmlplus$`];
13
+ for (const key of keys) {
10
14
  if (!config)
11
15
  break;
12
- config = config[parameter];
16
+ config = config[key];
13
17
  }
14
18
  return config;
15
19
  };
16
- export const setConfig = (namespace, config, override) => {
17
- if (typeof window == 'undefined')
20
+ /**
21
+ * TODO
22
+ */
23
+ export const setConfig = (config, options) => {
24
+ if (isServer())
18
25
  return;
19
- window[namespace] = merge({}, defaults, override ? {} : window[namespace], config);
26
+ const previous = (options === null || options === void 0 ? void 0 : options.override) ? {} : window[`$htmlplus$`];
27
+ window[`$htmlplus$`] = merge({}, DEFAULTS, previous, config);
20
28
  };
@@ -1,3 +1,6 @@
1
1
  import { PlusElement } from '../../types';
2
- export type Direction = 'ltr' | 'rtl';
3
- export declare const direction: (target: PlusElement) => Direction;
2
+ /**
3
+ * Indicates whether the [Direction](https://mdn.io/css-direction)
4
+ * of the element is `Right-To-Left` or `Left-To-Right`.
5
+ */
6
+ export declare const direction: (target: PlusElement) => 'ltr' | 'rtl';
@@ -1,4 +1,8 @@
1
1
  import { host } from './host.js';
2
+ /**
3
+ * Indicates whether the [Direction](https://mdn.io/css-direction)
4
+ * of the element is `Right-To-Left` or `Left-To-Right`.
5
+ */
2
6
  export const direction = (target) => {
3
- return getComputedStyle(host(target)).getPropertyValue('direction').toLowerCase();
7
+ return getComputedStyle(host(target)).getPropertyValue('direction');
4
8
  };
@@ -3,6 +3,12 @@ type EventType = 'outside' | (string & {});
3
3
  type EventHandler = EventListenerOrEventListenerObject;
4
4
  type EventOptions = boolean | AddEventListenerOptions;
5
5
  type EventListener = (target: EventTarget, type: EventType, handler: EventHandler, options?: EventOptions) => void;
6
+ /**
7
+ * TODO
8
+ */
6
9
  export declare const off: EventListener;
10
+ /**
11
+ * TODO
12
+ */
7
13
  export declare const on: EventListener;
8
14
  export {};
@@ -1,4 +1,7 @@
1
1
  const outsides = [];
2
+ /**
3
+ * TODO
4
+ */
2
5
  export const off = (target, type, handler, options) => {
3
6
  if (type != 'outside')
4
7
  return target.removeEventListener(type, handler, options);
@@ -9,6 +12,9 @@ export const off = (target, type, handler, options) => {
9
12
  off(document, outside.type, outside.callback, outside.options);
10
13
  outsides.splice(index, 1);
11
14
  };
15
+ /**
16
+ * TODO
17
+ */
12
18
  export const on = (target, type, handler, options) => {
13
19
  if (type != 'outside')
14
20
  return target.addEventListener(type, handler, options);
@@ -1,2 +1,5 @@
1
1
  import { PlusElement } from '../../types';
2
+ /**
3
+ * Indicates the host of the element.
4
+ */
2
5
  export declare const host: (target: PlusElement) => HTMLElement;
@@ -1,4 +1,7 @@
1
1
  import * as CONSTANTS from '../../constants/index.js';
2
+ /**
3
+ * Indicates the host of the element.
4
+ */
2
5
  export const host = (target) => {
3
6
  return target[CONSTANTS.API_HOST]();
4
7
  };
@@ -9,20 +9,23 @@ export * from './direction.js';
9
9
  export * from './event.js';
10
10
  export * from './getFramework.js';
11
11
  export * from './getMembers.js';
12
- export * from './getNamespace.js';
13
12
  export * from './getStyles.js';
14
13
  export * from './getTag.js';
15
14
  export * from './host.js';
15
+ export * from './isCSSColor.js';
16
16
  export * from './isEvent.js';
17
17
  export * from './isRTL.js';
18
18
  export * from './isServer.js';
19
19
  export * from './merge.js';
20
+ export * from './query.js';
21
+ export * from './queryAll.js';
20
22
  export * from './request.js';
21
23
  export * from './shadowRoot.js';
22
24
  export * from './slots.js';
23
25
  export * from './styles.js';
24
26
  export * from './task.js';
25
27
  export * from './toBoolean.js';
28
+ export * from './toDecorator.js';
26
29
  export * from './toEvent.js';
27
30
  export * from './toProperty.js';
28
31
  export * from './toUnit.js';
@@ -9,20 +9,23 @@ export * from './direction.js';
9
9
  export * from './event.js';
10
10
  export * from './getFramework.js';
11
11
  export * from './getMembers.js';
12
- export * from './getNamespace.js';
13
12
  export * from './getStyles.js';
14
13
  export * from './getTag.js';
15
14
  export * from './host.js';
15
+ export * from './isCSSColor.js';
16
16
  export * from './isEvent.js';
17
17
  export * from './isRTL.js';
18
18
  export * from './isServer.js';
19
19
  export * from './merge.js';
20
+ export * from './query.js';
21
+ export * from './queryAll.js';
20
22
  export * from './request.js';
21
23
  export * from './shadowRoot.js';
22
24
  export * from './slots.js';
23
25
  export * from './styles.js';
24
26
  export * from './task.js';
25
27
  export * from './toBoolean.js';
28
+ export * from './toDecorator.js';
26
29
  export * from './toEvent.js';
27
30
  export * from './toProperty.js';
28
31
  export * from './toUnit.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Determines whether the given input string is a valid
3
+ * [CSS Color](https://mdn.io/color-value) or not.
4
+ */
5
+ export declare const isCSSColor: (input: string) => boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Determines whether the given input string is a valid
3
+ * [CSS Color](https://mdn.io/color-value) or not.
4
+ */
5
+ export const isCSSColor = (input) => {
6
+ const option = new Option();
7
+ option.style.color = input;
8
+ return option.style.color !== '';
9
+ };
@@ -1,2 +1,5 @@
1
1
  import { PlusElement } from '../../types';
2
+ /**
3
+ * Indicates whether the direction of the element is `Right-To-Left` or not.
4
+ */
2
5
  export declare const isRTL: (target: PlusElement) => boolean;
@@ -1,2 +1,5 @@
1
1
  import { direction } from './direction.js';
2
+ /**
3
+ * Indicates whether the direction of the element is `Right-To-Left` or not.
4
+ */
2
5
  export const isRTL = (target) => direction(target) == 'rtl';
@@ -1 +1,4 @@
1
+ /**
2
+ * Indicates whether the current code is running on a server.
3
+ */
1
4
  export declare const isServer: () => boolean;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Indicates whether the current code is running on a server.
3
+ */
1
4
  export const isServer = () => {
2
5
  return !(typeof window != 'undefined' && window.document);
3
6
  };
@@ -0,0 +1,5 @@
1
+ import { PlusElement } from '../../types/index.js';
2
+ /**
3
+ * Selects the first element in the shadow dom that matches a specified CSS selector.
4
+ */
5
+ export declare function query(target: PlusElement, selectors: string): Element | null | undefined;
@@ -0,0 +1,8 @@
1
+ import { shadowRoot } from './shadowRoot.js';
2
+ /**
3
+ * Selects the first element in the shadow dom that matches a specified CSS selector.
4
+ */
5
+ export function query(target, selectors) {
6
+ var _a;
7
+ return (_a = shadowRoot(target)) === null || _a === void 0 ? void 0 : _a.querySelector(selectors);
8
+ }
@@ -0,0 +1,5 @@
1
+ import { PlusElement } from '../../types/index.js';
2
+ /**
3
+ * Selects all elements in the shadow dom that match a specified CSS selector.
4
+ */
5
+ export declare function queryAll(target: PlusElement, selectors: string): NodeListOf<Element> | undefined;
@@ -0,0 +1,8 @@
1
+ import { shadowRoot } from './shadowRoot.js';
2
+ /**
3
+ * Selects all elements in the shadow dom that match a specified CSS selector.
4
+ */
5
+ export function queryAll(target, selectors) {
6
+ var _a;
7
+ return (_a = shadowRoot(target)) === null || _a === void 0 ? void 0 : _a.querySelectorAll(selectors);
8
+ }
@@ -1,7 +1,7 @@
1
1
  import { PlusElement } from '../../types';
2
2
  /**
3
3
  * Updates the DOM with a scheduled task.
4
- * @param target The component instance.
4
+ * @param target The element instance.
5
5
  * @param name Property/State name.
6
6
  * @param previous The previous value of Property/State.
7
7
  * @param callback Invoked when the rendering phase is completed.
@@ -6,7 +6,7 @@ import { task } from './task.js';
6
6
  import { html, render } from './uhtml.js';
7
7
  /**
8
8
  * Updates the DOM with a scheduled task.
9
- * @param target The component instance.
9
+ * @param target The element instance.
10
10
  * @param name Property/State name.
11
11
  * @param previous The previous value of Property/State.
12
12
  * @param callback Invoked when the rendering phase is completed.
@@ -2,5 +2,8 @@ import { PlusElement } from '../../types';
2
2
  type Slots = {
3
3
  [key: string]: boolean;
4
4
  };
5
+ /**
6
+ * Returns the slots name.
7
+ */
5
8
  export declare const slots: (target: PlusElement) => Slots;
6
9
  export {};
@@ -1,10 +1,15 @@
1
1
  import { host } from './host.js';
2
+ /**
3
+ * Returns the slots name.
4
+ */
2
5
  export const slots = (target) => {
3
6
  var _a;
4
7
  const slots = {};
5
8
  const children = Array.from(host(target).childNodes);
6
9
  for (const child of children) {
7
- const name = child['slot'] || (((_a = child.nodeValue) === null || _a === void 0 ? void 0 : _a.trim()) && 'default');
10
+ if (child.nodeName == '#comment')
11
+ continue;
12
+ const name = child['slot'] || (((_a = child.nodeValue) === null || _a === void 0 ? void 0 : _a.trim()) && 'default') || ('slot' in child && 'default');
8
13
  if (!name)
9
14
  continue;
10
15
  slots[name] = true;
@@ -1 +1,4 @@
1
+ /**
2
+ * Converts a JavaScript object containing CSS styles to a CSS string.
3
+ */
1
4
  export declare const styles: (input: any) => string;
@@ -1,5 +1,8 @@
1
1
  import { kebabCase } from 'change-case';
2
2
  import { typeOf } from './typeOf.js';
3
+ /**
4
+ * Converts a JavaScript object containing CSS styles to a CSS string.
5
+ */
3
6
  export const styles = (input) => {
4
7
  switch (typeOf(input)) {
5
8
  case 'array':
@@ -0,0 +1,2 @@
1
+ import { PlusElement } from '../../types/index.js';
2
+ export declare function toDecorator(util: Function, ...parameters: any[]): (target: PlusElement, propertyKey: PropertyKey) => void;
@@ -0,0 +1,10 @@
1
+ import { defineProperty } from './defineProperty.js';
2
+ export function toDecorator(util, ...parameters) {
3
+ return function (target, propertyKey) {
4
+ defineProperty(target, propertyKey, {
5
+ get() {
6
+ return util(this, ...parameters);
7
+ }
8
+ });
9
+ };
10
+ }
@@ -1 +1,4 @@
1
- export declare const toUnit: (input: string | number, unit?: string) => string | undefined;
1
+ /**
2
+ * Converts a value to a unit.
3
+ */
4
+ export declare const toUnit: (input: string | number, unit?: string) => string;
@@ -1,7 +1,10 @@
1
+ /**
2
+ * Converts a value to a unit.
3
+ */
1
4
  export const toUnit = (input, unit = 'px') => {
2
- if (input == null || input === '')
3
- return undefined;
5
+ if (input === null || input === undefined || input === '')
6
+ return input;
4
7
  if (isNaN(+input))
5
8
  return String(input);
6
- return `${Number(input)}${unit}`;
9
+ return Number(input) + unit;
7
10
  };
@@ -8,6 +8,7 @@ export declare const API_RENDER_COMPLETED: unique symbol;
8
8
  export declare const API_STACKS: unique symbol;
9
9
  export declare const COMMENT_AUTO_ADDED_DEPENDENCY = " THIS DEPENDENCY IS AUTO-ADDED, DO NOT EDIT MANUALY";
10
10
  export declare const COMMENT_AUTO_ADDED_PROPERTY = " THIS PROPERTY IS AUTO-ADDED, DO NOT EDIT MANUALY";
11
+ export declare const CSS_DECORATOR_PROPERTY = "@Property()";
11
12
  export declare const DECORATOR_ELEMENT = "Element";
12
13
  export declare const DECORATOR_EVENT = "Event";
13
14
  export declare const DECORATOR_PROPERTY = "Property";
@@ -10,6 +10,8 @@ export const API_STACKS = Symbol();
10
10
  // comments
11
11
  export const COMMENT_AUTO_ADDED_DEPENDENCY = ' THIS DEPENDENCY IS AUTO-ADDED, DO NOT EDIT MANUALY';
12
12
  export const COMMENT_AUTO_ADDED_PROPERTY = ' THIS PROPERTY IS AUTO-ADDED, DO NOT EDIT MANUALY';
13
+ // CSS decorators
14
+ export const CSS_DECORATOR_PROPERTY = '@Property()';
13
15
  // decorators
14
16
  export const DECORATOR_ELEMENT = 'Element';
15
17
  export const DECORATOR_EVENT = 'Event';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
@@ -15,7 +15,7 @@
15
15
  "directory": "dist"
16
16
  },
17
17
  "engines": {
18
- "node": ">= 12.7.0"
18
+ "node": ">= 20.10.0"
19
19
  },
20
20
  "keywords": [
21
21
  "components",
@@ -57,7 +57,7 @@
57
57
  "prettier": "^2.8.0",
58
58
  "rimraf": "^3.0.2",
59
59
  "semantic-release": "^22.0.8",
60
- "ts-node": "^10.9.1",
60
+ "tsx": "^4.6.2",
61
61
  "vite": "^3.2.4"
62
62
  }
63
63
  }
@@ -0,0 +1,3 @@
1
+ export * from './transformer.js';
2
+ export * from './transformer.types.js';
3
+ export * from './plugins/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './transformer.js';
2
+ export * from './transformer.types.js';
3
+ export * from './plugins/index.js';
@@ -0,0 +1,8 @@
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
2
+ export declare const ASSETS_OPTIONS: Partial<AssetsOptions>;
3
+ export interface AssetsOptions {
4
+ once?: boolean;
5
+ destination?: (context: TransformerPluginContext) => string;
6
+ source?: (context: TransformerPluginContext) => string;
7
+ }
8
+ export declare const assets: (options?: AssetsOptions) => TransformerPlugin;
@@ -0,0 +1,29 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ export const ASSETS_OPTIONS = {
4
+ once: true,
5
+ destination(context) {
6
+ return path.join('dist', 'assets', context.fileName);
7
+ },
8
+ source(context) {
9
+ return path.join(context.directoryPath, 'assets');
10
+ }
11
+ };
12
+ export const assets = (options) => {
13
+ const name = 'assets';
14
+ options = Object.assign({}, ASSETS_OPTIONS, options);
15
+ const sources = new Set();
16
+ const run = (context) => {
17
+ context.assetsDestination = options.destination(context);
18
+ context.assetsSource = options.source(context);
19
+ if (!context.assetsSource)
20
+ return;
21
+ if (!fs.existsSync(context.assetsSource))
22
+ return;
23
+ if (options.once && sources.has(context.assetsSource))
24
+ return;
25
+ sources.add(context.assetsSource);
26
+ fs.copySync(context.assetsSource, context.assetsDestination);
27
+ };
28
+ return { name, run };
29
+ };
@@ -1,4 +1,4 @@
1
- import { Plugin } from '../../types';
1
+ import { TransformerPlugin } from '../transformer.types';
2
2
  export declare const COPY_OPTIONS: Partial<CopyOptions>;
3
3
  export interface CopyOptions {
4
4
  at?: 'start' | 'run' | 'finish';
@@ -6,4 +6,4 @@ export interface CopyOptions {
6
6
  source: string;
7
7
  transformer?: (content: string) => string;
8
8
  }
9
- export declare const copy: (options: CopyOptions) => Plugin;
9
+ export declare const copy: (options: CopyOptions) => TransformerPlugin;
@@ -1,7 +1,7 @@
1
- import { Plugin } from '../../types';
1
+ import { TransformerPlugin } from '../transformer.types';
2
2
  export declare const CUSTOM_ELEMENT_OPTIONS: Partial<CustomElementOptions>;
3
3
  export interface CustomElementOptions {
4
4
  prefix?: string;
5
5
  typings?: boolean;
6
6
  }
7
- export declare const customElement: (options?: CustomElementOptions) => Plugin;
7
+ export declare const customElement: (options?: CustomElementOptions) => TransformerPlugin;