@htmlplus/element 0.8.6 → 1.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.
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 +11 -4
  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/{compiler → transformer}/plugins/customElementReact/customElementReact.d.ts +4 -4
  81. package/{compiler → transformer}/plugins/customElementReact/customElementReact.js +18 -18
  82. package/{compiler → transformer}/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +1 -1
  83. package/{compiler → transformer}/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +3 -3
  84. package/transformer/plugins/customElementReact/templates/src/index.ts.hbs +1 -0
  85. package/transformer/plugins/document.d.ts +7 -0
  86. package/{compiler → transformer}/plugins/document.js +18 -18
  87. package/transformer/plugins/extract.d.ts +2 -0
  88. package/{compiler → transformer}/plugins/extract.js +1 -18
  89. package/transformer/plugins/parse.d.ts +6 -0
  90. package/{compiler → transformer}/plugins/parse.js +1 -1
  91. package/transformer/plugins/read.d.ts +8 -0
  92. package/transformer/plugins/read.js +20 -0
  93. package/transformer/plugins/readme.d.ts +6 -0
  94. package/{compiler → transformer}/plugins/readme.js +3 -2
  95. package/transformer/plugins/style.d.ts +6 -0
  96. package/{compiler → transformer}/plugins/style.js +4 -2
  97. package/transformer/plugins/validate.d.ts +2 -0
  98. package/transformer/plugins/validate.js +41 -0
  99. package/transformer/plugins/visualStudioCode.d.ts +8 -0
  100. package/{compiler → transformer}/plugins/visualStudioCode.js +10 -8
  101. package/transformer/plugins/webTypes.d.ts +10 -0
  102. package/{compiler → transformer}/plugins/webTypes.js +11 -7
  103. package/transformer/transformer.d.ts +6 -0
  104. package/{compiler/compiler.js → transformer/transformer.js} +17 -17
  105. package/transformer/transformer.types.d.ts +50 -0
  106. package/{compiler → transformer}/utils/printType.js +2 -2
  107. package/{compiler → transformer}/utils/renderTemplate.js +2 -0
  108. package/types/index.d.ts +2 -4
  109. package/types/index.js +1 -4
  110. package/bundlers/index.d.ts +0 -2
  111. package/bundlers/index.js +0 -2
  112. package/client/helpers/index.d.ts +0 -1
  113. package/client/helpers/index.js +0 -1
  114. package/client/services/index.d.ts +0 -1
  115. package/client/services/index.js +0 -1
  116. package/client/services/link.d.ts +0 -4
  117. package/client/services/link.js +0 -196
  118. package/client/utils/getNamespace.d.ts +0 -2
  119. package/client/utils/getNamespace.js +0 -4
  120. package/client/vendors/uhtml.d.ts +0 -29
  121. package/client/vendors/uhtml.js +0 -700
  122. package/compiler/compiler.d.ts +0 -6
  123. package/compiler/index.d.ts +0 -2
  124. package/compiler/index.js +0 -2
  125. package/compiler/plugins/assets.d.ts +0 -8
  126. package/compiler/plugins/assets.js +0 -33
  127. package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +0 -1
  128. package/compiler/plugins/document.d.ts +0 -7
  129. package/compiler/plugins/extract.d.ts +0 -2
  130. package/compiler/plugins/parse.d.ts +0 -5
  131. package/compiler/plugins/read.d.ts +0 -8
  132. package/compiler/plugins/read.js +0 -13
  133. package/compiler/plugins/readme.d.ts +0 -6
  134. package/compiler/plugins/style.d.ts +0 -6
  135. package/compiler/plugins/validate.d.ts +0 -2
  136. package/compiler/plugins/validate.js +0 -37
  137. package/compiler/plugins/visualStudioCode.d.ts +0 -8
  138. package/compiler/plugins/webTypes.d.ts +0 -10
  139. package/types/context.d.ts +0 -31
  140. package/types/global.d.ts +0 -4
  141. package/types/global.js +0 -1
  142. package/types/plugin.d.ts +0 -10
  143. package/types/plugin.js +0 -1
  144. package/types/plusElement.d.ts +0 -2
  145. package/types/plusElement.js +0 -1
  146. /package/{compiler → transformer}/plugins/copy.js +0 -0
  147. /package/{compiler → transformer}/plugins/customElementReact/index.d.ts +0 -0
  148. /package/{compiler → transformer}/plugins/customElementReact/index.js +0 -0
  149. /package/{compiler → transformer}/plugins/customElementReact/templates/README.md.hbs +0 -0
  150. /package/{compiler → transformer}/plugins/customElementReact/templates/_.gitignore.hbs +0 -0
  151. /package/{compiler → transformer}/plugins/customElementReact/templates/package.json.hbs +0 -0
  152. /package/{compiler → transformer}/plugins/customElementReact/templates/rollup.config.js.hbs +0 -0
  153. /package/{compiler → transformer}/plugins/customElementReact/templates/src/components/index.ts.hbs +0 -0
  154. /package/{compiler → transformer}/plugins/customElementReact/templates/src/proxy.ts.hbs +0 -0
  155. /package/{compiler → transformer}/plugins/customElementReact/templates/tsconfig.json.hbs +0 -0
  156. /package/{compiler → transformer}/plugins/index.d.ts +0 -0
  157. /package/{compiler → transformer}/plugins/index.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
@@ -14,15 +14,16 @@ export const customElement = (options) => {
14
14
  const run = (context) => {
15
15
  const ast = t.cloneNode(context.fileAST, true);
16
16
  // TODO
17
- const tag = ((options === null || options === void 0 ? void 0 : options.prefix) || '') + context.componentKey;
18
- const componentInterfaceName = `HTML${pascalCase(tag)}Element`;
17
+ context.elementTagName = `${options.prefix || ''}${context.elementKey}`;
18
+ // TODO
19
+ context.elementInterfaceName = `HTML${pascalCase(context.elementTagName)}Element`;
19
20
  // attaches name
20
21
  visitor(ast, {
21
22
  ClassDeclaration(path) {
22
23
  const { body, id } = path.node;
23
24
  if (id.name != context.className)
24
25
  return;
25
- const node = t.classProperty(t.identifier(CONSTANTS.STATIC_TAG), t.stringLiteral(tag), undefined, undefined, undefined, true);
26
+ const node = t.classProperty(t.identifier(CONSTANTS.STATIC_TAG), t.stringLiteral(context.elementTagName), undefined, undefined, undefined, true);
26
27
  t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_PROPERTY, true);
27
28
  body.body.unshift(node);
28
29
  }
@@ -273,7 +274,7 @@ export const customElement = (options) => {
273
274
  }
274
275
  });
275
276
  // attaches typings
276
- if (options === null || options === void 0 ? void 0 : options.typings) {
277
+ if (options.typings) {
277
278
  visitor(ast, {
278
279
  Program(path) {
279
280
  const attributes = context.classProperties.map((property) => {
@@ -312,6 +313,7 @@ export const customElement = (options) => {
312
313
  leadingComments: t.cloneNode(property, true).leadingComments
313
314
  });
314
315
  });
316
+ // prettier-ignore
315
317
  const ast = template.default.ast(`
316
318
  export interface ${context.className}Attributes {
317
319
  ${attributes.map(print).join('')}
@@ -332,27 +334,27 @@ export const customElement = (options) => {
332
334
  export interface ${context.className}JSX extends ${context.className}Events, ${context.className}Properties { }
333
335
 
334
336
  declare global {
335
- interface ${componentInterfaceName} extends HTMLElement, ${context.className}Methods, ${context.className}Properties { }
337
+ interface ${context.elementInterfaceName} extends HTMLElement, ${context.className}Methods, ${context.className}Properties { }
336
338
 
337
- var ${componentInterfaceName}: {
338
- prototype: ${componentInterfaceName};
339
- new (): ${componentInterfaceName};
339
+ var ${context.elementInterfaceName}: {
340
+ prototype: ${context.elementInterfaceName};
341
+ new (): ${context.elementInterfaceName};
340
342
  };
341
343
 
342
344
  interface HTMLElementTagNameMap {
343
- "${tag}": ${componentInterfaceName};
345
+ "${context.elementTagName}": ${context.elementInterfaceName};
344
346
  }
345
347
 
346
348
  namespace JSX {
347
349
  interface IntrinsicElements {
348
- "${tag}": ${context.className}Events & ${context.className}Attributes & {
350
+ "${context.elementTagName}": ${context.className}Events & ${context.className}Attributes & {
349
351
  [key: string]: any;
350
352
  };
351
353
  }
352
354
  }
353
355
  }
354
356
 
355
- export type ${context.className}Element = globalThis.${componentInterfaceName}
357
+ export type ${context.className}Element = globalThis.${context.elementInterfaceName}
356
358
  `, {
357
359
  plugins: ['typescript'],
358
360
  preserveComments: true
@@ -361,7 +363,6 @@ export const customElement = (options) => {
361
363
  }
362
364
  });
363
365
  }
364
- // TODO
365
366
  context.script = print(ast);
366
367
  };
367
368
  return { name, run };
@@ -1,16 +1,16 @@
1
- import { Context, Plugin } from '../../../types';
1
+ import { TransformerPlugin, TransformerPluginContext } from '../../transformer.types';
2
2
  export declare const CUSTOM_ELEMENT_REACT_OPTIONS: Partial<CustomElementReactOptions>;
3
3
  export interface CustomElementReactOptions {
4
4
  compact?: boolean;
5
5
  destination: string;
6
6
  eventName?: (eventName: string) => string;
7
- importerComponent: (context: Context) => {
7
+ importerElement: (context: TransformerPluginContext) => {
8
8
  source: string;
9
9
  };
10
- importerComponentType: (context: Context) => {
10
+ importerElementType: (context: TransformerPluginContext) => {
11
11
  source: string;
12
12
  imported: string;
13
13
  local: string;
14
14
  };
15
15
  }
16
- export declare const customElementReact: (options: CustomElementReactOptions) => Plugin;
16
+ export declare const customElementReact: (options: CustomElementReactOptions) => TransformerPlugin;
@@ -13,7 +13,7 @@ export const customElementReact = (options) => {
13
13
  const config = { cwd: __dirname(import.meta.url) };
14
14
  const isEmpty = isDirectoryEmpty(options.destination);
15
15
  const skip = [];
16
- const getKey = (component) => component.className;
16
+ const getKey = (element) => element.className;
17
17
  for (const key in globalNew.contexts) {
18
18
  const context = globalNew.contexts[key];
19
19
  const classEvents = context.classEvents.map((classEvent) => {
@@ -24,12 +24,12 @@ export const customElementReact = (options) => {
24
24
  to });
25
25
  });
26
26
  const fileName = context.fileName;
27
- const importerComponent = options.importerComponent(context);
28
- const importerComponentType = options.importerComponentType(context);
27
+ const importerElement = options.importerElement(context);
28
+ const importerElementType = options.importerElementType(context);
29
29
  const state = Object.assign(Object.assign({}, context), { classEvents,
30
30
  fileName,
31
- importerComponent,
32
- importerComponentType,
31
+ importerElement,
32
+ importerElementType,
33
33
  options });
34
34
  const patterns = [
35
35
  'templates/src/components/*fileName*.ts.hbs',
@@ -40,27 +40,27 @@ export const customElementReact = (options) => {
40
40
  if (options.compact) {
41
41
  globalNew.groups = Object.values(globalNew.contexts)
42
42
  .sort((a, b) => getKey(b).length - getKey(a).length)
43
- .map((component, index, components) => ({
44
- key: getKey(component),
45
- components: components.filter((current) => getKey(current).startsWith(getKey(component)))
43
+ .map((element, index, elements) => ({
44
+ key: getKey(element),
45
+ elements: elements.filter((current) => getKey(current).startsWith(getKey(element)))
46
46
  }))
47
- .sort((a, b) => b.components.length - a.components.length)
47
+ .sort((a, b) => b.elements.length - a.elements.length)
48
48
  .filter((group) => {
49
49
  if (skip.includes(group.key))
50
50
  return;
51
- group.components.forEach((component) => skip.push(getKey(component)));
51
+ group.elements.forEach((element) => skip.push(getKey(element)));
52
52
  return true;
53
53
  })
54
54
  .map((group) => {
55
- const all = group.components
55
+ const all = group.elements
56
56
  .reverse()
57
- .map((component, index) => {
58
- const componentClassNameInCategory = getKey(component).replace(group.key, '');
59
- const importerComponent = options.importerComponent(component);
60
- const importerComponentType = options.importerComponentType(component);
61
- return Object.assign(Object.assign({}, component), { componentClassNameInCategory,
62
- importerComponent,
63
- importerComponentType });
57
+ .map((element, index) => {
58
+ const elementClassNameInCategory = getKey(element).replace(group.key, '');
59
+ const importerElement = options.importerElement(element);
60
+ const importerElementType = options.importerElementType(element);
61
+ return Object.assign(Object.assign({}, element), { elementClassNameInCategory,
62
+ importerElement,
63
+ importerElementType });
64
64
  })
65
65
  // TODO: experimental
66
66
  .sort((a, b) => (getKey(b) < getKey(a) ? 0 : -1));
@@ -10,7 +10,7 @@ const All = Object.assign(
10
10
  {{root.className}},
11
11
  {
12
12
  {{#each filterd}}
13
- {{componentClassNameInCategory}}: {{className}},
13
+ {{elementClassNameInCategory}}: {{className}},
14
14
  {{/each}}
15
15
  }
16
16
  );
@@ -1,14 +1,14 @@
1
1
  /**************************************************
2
2
  * THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
3
3
  **************************************************/
4
- import { {{className}} as {{className}}Core } from '{{importerComponent.source}}';
5
- import type { {{className}}Element, {{importerComponentType.imported}} as {{importerComponentType.local}} } from '{{importerComponentType.source}}';
4
+ import { {{className}} as {{className}}Core } from '{{importerElement.source}}';
5
+ import type { {{className}}Element, {{importerElementType.imported}} as {{importerElementType.local}} } from '{{importerElementType.source}}';
6
6
 
7
7
  import { proxy } from '../proxy';
8
8
  import type { Rename } from '../proxy';
9
9
 
10
10
  type Renamed = Rename<
11
- {{importerComponentType.local}},
11
+ {{importerElementType.local}},
12
12
  {
13
13
  {{#each classEvents}}
14
14
  {{from}}: '{{to}}';
@@ -0,0 +1 @@
1
+ export * from './elements';
@@ -0,0 +1,7 @@
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
2
+ export declare const DOCUMENT_OPTIONS: Partial<DocumentOptions>;
3
+ export interface DocumentOptions {
4
+ destination: string;
5
+ transformer?: (context: TransformerPluginContext, element: any) => any;
6
+ }
7
+ export declare const document: (options?: DocumentOptions) => TransformerPlugin;
@@ -2,15 +2,18 @@ import { capitalCase, kebabCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
3
  import glob from 'glob';
4
4
  import path from 'path';
5
+ import * as CONSTANTS from '../../constants/index.js';
5
6
  import { getInitializer, getTag, getTags, getTypeReference, hasTag, parseTag, print } from '../utils/index.js';
6
- export const DOCUMENT_OPTIONS = {};
7
+ export const DOCUMENT_OPTIONS = {
8
+ destination: path.join('dist', 'document.json')
9
+ };
7
10
  export const document = (options) => {
8
11
  const name = 'document';
9
12
  options = Object.assign({}, DOCUMENT_OPTIONS, options);
10
13
  const finish = (global) => {
11
- var _a, _b, _c;
14
+ var _a, _b, _c, _d;
12
15
  const json = {
13
- components: []
16
+ elements: []
14
17
  };
15
18
  for (const context of global.contexts) {
16
19
  const deprecated = hasTag(context.class, 'deprecated');
@@ -62,7 +65,7 @@ export const document = (options) => {
62
65
  const group = (_b = getTag(context.class, 'group')) === null || _b === void 0 ? void 0 : _b.value;
63
66
  const lastModified = glob
64
67
  .sync('**/*.*', { cwd: context.directoryPath })
65
- .map((file) => fs.statSync(path.resolve(context.directoryPath, file)).mtime)
68
+ .map((file) => fs.statSync(path.join(context.directoryPath, file)).mtime)
66
69
  .sort((a, b) => (a > b ? 1 : -1))
67
70
  .pop();
68
71
  const methods = context.classMethods.map((method) => {
@@ -178,16 +181,13 @@ export const document = (options) => {
178
181
  return [];
179
182
  return fs
180
183
  .readFileSync(context.stylePath, 'utf8')
181
- .split('@prop')
184
+ .split(CONSTANTS.CSS_DECORATOR_PROPERTY)
182
185
  .slice(1)
183
186
  .map((section) => {
184
- var _a;
185
- let [description, name] = section.split(/\n/);
186
- name = name.split(':').slice(0, -1).join(':').trim();
187
- description = description.trim();
188
- let [initializer] = ((_a = context.styleParsed) === null || _a === void 0 ? void 0 : _a.split(name).slice(1, 2)) || [];
189
- if (initializer)
190
- initializer = initializer.split(/;|}/)[0].replace(':', '').trim();
187
+ const [first, second] = section.split(/\n/);
188
+ const description = first.replace('*/', '').trim();
189
+ const name = second.split(':')[0].trim();
190
+ const initializer = second.split(':').slice(1).join(':').replace(';', '').trim();
191
191
  return {
192
192
  description,
193
193
  initializer,
@@ -196,14 +196,14 @@ export const document = (options) => {
196
196
  });
197
197
  })();
198
198
  const tags = getTags(context.class).filter((tag) => !['part', 'slot'].includes(tag.key));
199
- const title = capitalCase(context.componentKey);
200
- const component = {
199
+ const title = capitalCase(context.elementKey);
200
+ const element = {
201
201
  events,
202
202
  group,
203
203
  deprecated,
204
204
  description,
205
205
  experimental,
206
- key: context.componentKey,
206
+ key: context.elementKey,
207
207
  lastModified,
208
208
  methods,
209
209
  parts,
@@ -214,10 +214,10 @@ export const document = (options) => {
214
214
  tags,
215
215
  title
216
216
  };
217
- const transformed = ((_c = options.transformer) === null || _c === void 0 ? void 0 : _c.call(options, context, component)) || component;
218
- json.components.push(transformed);
217
+ const transformed = ((_d = (_c = options).transformer) === null || _d === void 0 ? void 0 : _d.call(_c, context, element)) || element;
218
+ json.elements.push(transformed);
219
219
  }
220
- json.components = json.components.sort((a, b) => (a.title > b.title ? 1 : -1));
220
+ json.elements = json.elements.sort((a, b) => (a.title > b.title ? 1 : -1));
221
221
  const dirname = path.dirname(options.destination);
222
222
  fs.ensureDirSync(dirname);
223
223
  fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
@@ -0,0 +1,2 @@
1
+ import { TransformerPlugin } from '../transformer.types';
2
+ export declare const extract: () => TransformerPlugin;
@@ -1,6 +1,5 @@
1
1
  import t from '@babel/types';
2
2
  import { kebabCase } from 'change-case';
3
- import path from 'path';
4
3
  import * as CONSTANTS from '../../constants/index.js';
5
4
  import { hasDecorator, visitor } from '../utils/index.js';
6
5
  export const extract = () => {
@@ -19,26 +18,10 @@ export const extract = () => {
19
18
  }
20
19
  path.skip();
21
20
  }
22
- },
23
- JSXElement(path) {
24
- var _a;
25
- const { openingElement } = path.node;
26
- const name = openingElement.name.name;
27
- if (!/-/g.test(name))
28
- return;
29
- (_a = context.customElementNames) !== null && _a !== void 0 ? _a : (context.customElementNames = []);
30
- context.customElementNames.push(name);
31
- context.customElementNames = context.customElementNames
32
- .filter((item, index, items) => items.indexOf(item) === index)
33
- .sort();
34
21
  }
35
22
  });
36
- context.directoryPath = path.dirname(context.filePath);
37
- context.directoryName = path.basename(context.directoryPath);
38
- context.fileExtension = path.extname(context.filePath);
39
- context.fileName = path.basename(context.filePath, context.fileExtension);
40
23
  context.className = (_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.name;
41
- context.componentKey = kebabCase(context.className);
24
+ context.elementKey = kebabCase(context.className || '');
42
25
  context.classEvents = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_EVENT));
43
26
  context.classMethods = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_METHOD));
44
27
  context.classProperties = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_PROPERTY));
@@ -0,0 +1,6 @@
1
+ import { ParserOptions } from '@babel/parser';
2
+ import { TransformerPlugin } from '../transformer.types';
3
+ export declare const PARSE_OPTIONS: Partial<ParseOptions>;
4
+ export interface ParseOptions extends ParserOptions {
5
+ }
6
+ export declare const parse: (options?: ParseOptions) => TransformerPlugin;
@@ -8,7 +8,7 @@ export const parse = (options) => {
8
8
  options = Object.assign({}, PARSE_OPTIONS, options);
9
9
  const run = (context) => {
10
10
  var _a;
11
- context.fileAST = (_a = context.fileAST) !== null && _a !== void 0 ? _a : parser(context.fileContent, options);
11
+ (_a = context.fileAST) !== null && _a !== void 0 ? _a : (context.fileAST = parser(context.fileContent, options));
12
12
  };
13
13
  return { name, run };
14
14
  };
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { TransformerPlugin } from '../transformer.types';
3
+ export declare const READ_OPTIONS: Partial<ReadOptions>;
4
+ export interface ReadOptions {
5
+ encoding: BufferEncoding;
6
+ flag?: string | undefined;
7
+ }
8
+ export declare const read: (options?: ReadOptions) => TransformerPlugin;
@@ -0,0 +1,20 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ export const READ_OPTIONS = {
4
+ encoding: 'utf8'
5
+ };
6
+ export const read = (options) => {
7
+ const name = 'read';
8
+ options = Object.assign({}, READ_OPTIONS, options);
9
+ const run = (context) => {
10
+ var _a;
11
+ if (!context.filePath)
12
+ return;
13
+ (_a = context.fileContent) !== null && _a !== void 0 ? _a : (context.fileContent = fs.readFileSync(context.filePath, options));
14
+ context.fileExtension = path.extname(context.filePath);
15
+ context.fileName = path.basename(context.filePath, context.fileExtension);
16
+ context.directoryPath = path.dirname(context.filePath);
17
+ context.directoryName = path.basename(context.directoryPath);
18
+ };
19
+ return { name, run };
20
+ };
@@ -0,0 +1,6 @@
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
2
+ export declare const README_OPTIONS: Partial<ReadmeOptions>;
3
+ export interface ReadmeOptions {
4
+ source?: (context: TransformerPluginContext) => string;
5
+ }
6
+ export declare const readme: (options?: ReadmeOptions) => TransformerPlugin;
@@ -9,14 +9,15 @@ export const readme = (options) => {
9
9
  const name = 'readme';
10
10
  options = Object.assign({}, README_OPTIONS, options);
11
11
  const finish = (global) => {
12
- var _a;
13
12
  for (const context of global.contexts) {
14
- context.readmePath = (_a = options.source) === null || _a === void 0 ? void 0 : _a.call(options, context);
13
+ context.readmePath = options.source(context);
15
14
  if (!context.readmePath)
16
15
  continue;
17
16
  if (!fs.existsSync(context.readmePath))
18
17
  continue;
19
18
  context.readmeContent = fs.readFileSync(context.readmePath, 'utf8');
19
+ context.readmeExtension = path.extname(context.readmePath);
20
+ context.readmeName = path.basename(context.readmePath, context.readmeExtension);
20
21
  }
21
22
  };
22
23
  return { name, finish };
@@ -0,0 +1,6 @@
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
2
+ export declare const STYLE_OPTIONS: Partial<StyleOptions>;
3
+ export interface StyleOptions {
4
+ source?: (context: TransformerPluginContext) => string | string[];
5
+ }
6
+ export declare const style: (options?: StyleOptions) => TransformerPlugin;
@@ -18,8 +18,7 @@ export const style = (options) => {
18
18
  const name = 'style';
19
19
  options = Object.assign({}, STYLE_OPTIONS, options);
20
20
  const run = (context) => {
21
- var _a;
22
- const sources = [(_a = options === null || options === void 0 ? void 0 : options.source) === null || _a === void 0 ? void 0 : _a.call(options, context)].flat();
21
+ const sources = [options.source(context)].flat();
23
22
  for (const source of sources) {
24
23
  if (!source)
25
24
  continue;
@@ -30,6 +29,9 @@ export const style = (options) => {
30
29
  }
31
30
  if (!context.stylePath)
32
31
  return;
32
+ context.styleContent = fs.readFileSync(context.stylePath, 'utf8');
33
+ context.styleExtension = path.extname(context.stylePath);
34
+ context.styleName = path.basename(context.stylePath, context.styleExtension);
33
35
  const { local } = addDependency(context.fileAST, context.stylePath, CONSTANTS.STYLE_IMPORTED, undefined, true);
34
36
  // TODO: remove 'local!'
35
37
  const property = t.classProperty(t.identifier(CONSTANTS.STATIC_STYLES), t.identifier(local), undefined, null, undefined, true);
@@ -0,0 +1,2 @@
1
+ import { TransformerPlugin } from '../transformer.types';
2
+ export declare const validate: () => TransformerPlugin;
@@ -0,0 +1,41 @@
1
+ import t from '@babel/types';
2
+ import * as CONSTANTS from '../../constants/index.js';
3
+ import { visitor } from '../utils/index.js';
4
+ export const validate = () => {
5
+ const name = 'validate';
6
+ const run = (context) => {
7
+ context.skipped = true;
8
+ visitor(context.fileAST, {
9
+ ImportDeclaration(path) {
10
+ var _a;
11
+ if (((_a = path.node.source) === null || _a === void 0 ? void 0 : _a.value) !== CONSTANTS.PACKAGE_NAME)
12
+ return;
13
+ for (const specifier of path.node.specifiers) {
14
+ if (specifier.imported.name !== CONSTANTS.DECORATOR_ELEMENT)
15
+ continue;
16
+ const binding = path.scope.getBinding(specifier.imported.name);
17
+ if (binding.references == 0)
18
+ break;
19
+ const referencePaths = binding.referencePaths.filter((referencePath) => {
20
+ if (t.isCallExpression(referencePath.parent) &&
21
+ t.isDecorator(referencePath.parentPath.parent) &&
22
+ t.isClassDeclaration(referencePath.parentPath.parentPath.parent) &&
23
+ t.isExportNamedDeclaration(referencePath.parentPath.parentPath.parentPath.parent))
24
+ return true;
25
+ });
26
+ if (referencePaths.length > 1) {
27
+ throw new Error('In each file, only one custom element can be defined. \n' +
28
+ 'If more than one @Element() decorator is used in the file, it will result in an error.\n');
29
+ }
30
+ context.skipped = false;
31
+ if (referencePaths.length == 1)
32
+ break;
33
+ throw new Error('It appears that the class annotated with the @Element() decorator is not being exported correctly.');
34
+ }
35
+ path.stop();
36
+ }
37
+ });
38
+ context.skipped;
39
+ };
40
+ return { name, run };
41
+ };
@@ -0,0 +1,8 @@
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
2
+ export declare const VISUAL_STUDIO_CODE_OPTIONS: Partial<VisualStudioCodeOptions>;
3
+ export interface VisualStudioCodeOptions {
4
+ destination?: string;
5
+ reference?: (context: TransformerPluginContext) => string;
6
+ transformer?: (context: TransformerPluginContext, element: any) => any;
7
+ }
8
+ export declare const visualStudioCode: (options?: VisualStudioCodeOptions) => TransformerPlugin;
@@ -2,14 +2,16 @@ import { kebabCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import { getTags, getType, print } from '../utils/index.js';
5
- export const VISUAL_STUDIO_CODE_OPTIONS = {};
5
+ export const VISUAL_STUDIO_CODE_OPTIONS = {
6
+ destination: path.join('dist', 'visual-studio-code.json')
7
+ };
6
8
  export const visualStudioCode = (options) => {
7
9
  const name = 'visualStudioCode';
8
10
  options = Object.assign({}, VISUAL_STUDIO_CODE_OPTIONS, options);
9
11
  const finish = (global) => {
10
- var _a, _b, _c, _d, _e;
12
+ var _a, _b, _c, _d, _e, _f, _g;
11
13
  const contexts = global.contexts.sort((a, b) => {
12
- return a.componentKey.toUpperCase() > b.componentKey.toUpperCase() ? +1 : -1;
14
+ return a.elementKey.toUpperCase() > b.elementKey.toUpperCase() ? +1 : -1;
13
15
  });
14
16
  const json = {
15
17
  $schema: 'TODO',
@@ -19,23 +21,23 @@ export const visualStudioCode = (options) => {
19
21
  for (const context of contexts) {
20
22
  const description = (_a = getTags(context.class).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
21
23
  const tag = {
22
- name: context.componentKey,
24
+ name: context.elementKey,
23
25
  description: description,
24
26
  attributes: [],
25
27
  references: [
26
28
  {
27
29
  name: 'Source code',
28
- url: (_b = options.reference) === null || _b === void 0 ? void 0 : _b.call(options, context)
30
+ url: (_c = (_b = options).reference) === null || _c === void 0 ? void 0 : _c.call(_b, context)
29
31
  }
30
32
  ]
31
33
  };
32
34
  for (const property of context.classProperties || []) {
33
35
  const attribute = {
34
36
  name: kebabCase(property.key['name']),
35
- description: (_c = getTags(property).find((tag) => !tag.key)) === null || _c === void 0 ? void 0 : _c.value,
37
+ description: (_d = getTags(property).find((tag) => !tag.key)) === null || _d === void 0 ? void 0 : _d.value,
36
38
  values: []
37
39
  };
38
- const type = print(getType(context.directoryPath, context.fileAST, (_d = property.typeAnnotation) === null || _d === void 0 ? void 0 : _d['typeAnnotation']));
40
+ const type = print(getType(context.directoryPath, context.fileAST, (_e = property.typeAnnotation) === null || _e === void 0 ? void 0 : _e['typeAnnotation']));
39
41
  const sections = type.split('|');
40
42
  for (const section of sections) {
41
43
  const trimmed = section.trim();
@@ -64,7 +66,7 @@ export const visualStudioCode = (options) => {
64
66
  }
65
67
  tag.attributes.push(attribute);
66
68
  }
67
- const transformed = ((_e = options.transformer) === null || _e === void 0 ? void 0 : _e.call(options, context, tag)) || tag;
69
+ const transformed = ((_g = (_f = options).transformer) === null || _g === void 0 ? void 0 : _g.call(_f, context, tag)) || tag;
68
70
  json.tags.push(transformed);
69
71
  }
70
72
  const dirname = path.dirname(options.destination);
@@ -0,0 +1,10 @@
1
+ import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
2
+ export declare const WEB_TYPES_OPTIONS: Partial<WebTypesOptions>;
3
+ export interface WebTypesOptions {
4
+ destination?: string;
5
+ packageName?: string;
6
+ packageVersion?: string;
7
+ reference?: (context: TransformerPluginContext) => string;
8
+ transformer?: (context: TransformerPluginContext, element: any) => any;
9
+ }
10
+ export declare const webTypes: (options?: WebTypesOptions) => TransformerPlugin;
@@ -2,14 +2,18 @@ import { kebabCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import { getInitializer, getTags, getType, hasTag, parseTag, print } from '../utils/index.js';
5
- export const WEB_TYPES_OPTIONS = {};
5
+ export const WEB_TYPES_OPTIONS = {
6
+ destination: path.join('dist', 'web-types.json'),
7
+ packageName: '',
8
+ packageVersion: ''
9
+ };
6
10
  export const webTypes = (options) => {
7
11
  const name = 'webTypes';
8
12
  options = Object.assign({}, WEB_TYPES_OPTIONS, options);
9
13
  const finish = (global) => {
10
- var _a, _b, _c, _d, _e, _f, _g;
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
11
15
  const contexts = global.contexts.sort((a, b) => {
12
- return a.componentKey.toUpperCase() > b.componentKey.toUpperCase() ? +1 : -1;
16
+ return a.elementKey.toUpperCase() > b.elementKey.toUpperCase() ? +1 : -1;
13
17
  });
14
18
  const json = {
15
19
  '$schema': 'http://json.schemastore.org/web-types',
@@ -69,10 +73,10 @@ export const webTypes = (options) => {
69
73
  description
70
74
  };
71
75
  });
72
- const component = {
73
- 'name': context.componentKey,
76
+ const element = {
77
+ 'name': context.elementKey,
74
78
  'description': description,
75
- 'doc-url': (_f = options.reference) === null || _f === void 0 ? void 0 : _f.call(options, context),
79
+ 'doc-url': (_g = (_f = options).reference) === null || _g === void 0 ? void 0 : _g.call(_f, context),
76
80
  'deprecated': hasTag(context.class, 'deprecated'),
77
81
  'experimental': hasTag(context.class, 'experimental'),
78
82
  'js': {
@@ -82,7 +86,7 @@ export const webTypes = (options) => {
82
86
  attributes,
83
87
  slots
84
88
  };
85
- const transformed = ((_g = options.transformer) === null || _g === void 0 ? void 0 : _g.call(options, context, component)) || component;
89
+ const transformed = ((_j = (_h = options).transformer) === null || _j === void 0 ? void 0 : _j.call(_h, context, element)) || element;
86
90
  json.contributions.html.elements.push(transformed);
87
91
  }
88
92
  const dirname = path.dirname(options.destination);
@@ -0,0 +1,6 @@
1
+ import { TransformerPlugin, TransformerPluginContext } from './transformer.types';
2
+ export declare const transformer: (...plugins: TransformerPlugin[]) => {
3
+ start: () => Promise<void>;
4
+ run: (filePath: string) => Promise<TransformerPluginContext>;
5
+ finish: () => Promise<void>;
6
+ };