@htmlplus/element 2.12.0 → 2.13.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 (175) hide show
  1. package/README.md +2 -2
  2. package/bundlers.d.ts +20 -0
  3. package/{bundlers/vite.js → bundlers.js} +39 -3
  4. package/client-5FqNUiuz.d.ts +309 -0
  5. package/client-Dse96R-O.js +1805 -0
  6. package/client.d.ts +1 -0
  7. package/client.js +3 -0
  8. package/constants.d.ts +48 -0
  9. package/constants.js +60 -0
  10. package/internal.d.ts +1 -0
  11. package/internal.js +3 -0
  12. package/package.json +8 -4
  13. package/transformer.d.ts +139 -0
  14. package/transformer.js +1277 -0
  15. package/bundlers/rollup.d.ts +0 -7
  16. package/bundlers/rollup.js +0 -23
  17. package/bundlers/vite.d.ts +0 -8
  18. package/client/decorators/bind.d.ts +0 -8
  19. package/client/decorators/bind.js +0 -21
  20. package/client/decorators/context.d.ts +0 -3
  21. package/client/decorators/context.js +0 -121
  22. package/client/decorators/direction.d.ts +0 -5
  23. package/client/decorators/direction.js +0 -8
  24. package/client/decorators/element.d.ts +0 -7
  25. package/client/decorators/element.js +0 -65
  26. package/client/decorators/event.d.ts +0 -35
  27. package/client/decorators/event.js +0 -53
  28. package/client/decorators/host.d.ts +0 -4
  29. package/client/decorators/host.js +0 -7
  30. package/client/decorators/index.d.ts +0 -15
  31. package/client/decorators/index.js +0 -15
  32. package/client/decorators/isRTL.d.ts +0 -4
  33. package/client/decorators/isRTL.js +0 -7
  34. package/client/decorators/listen.d.ts +0 -52
  35. package/client/decorators/listen.js +0 -37
  36. package/client/decorators/method.d.ts +0 -6
  37. package/client/decorators/method.js +0 -15
  38. package/client/decorators/property.d.ts +0 -25
  39. package/client/decorators/property.js +0 -94
  40. package/client/decorators/query.d.ts +0 -9
  41. package/client/decorators/query.js +0 -12
  42. package/client/decorators/queryAll.d.ts +0 -12
  43. package/client/decorators/queryAll.js +0 -15
  44. package/client/decorators/slots.d.ts +0 -4
  45. package/client/decorators/slots.js +0 -7
  46. package/client/decorators/state.d.ts +0 -6
  47. package/client/decorators/state.js +0 -23
  48. package/client/decorators/watch.d.ts +0 -11
  49. package/client/decorators/watch.js +0 -31
  50. package/client/index.d.ts +0 -2
  51. package/client/index.js +0 -2
  52. package/client/utils/appendToMethod.d.ts +0 -1
  53. package/client/utils/appendToMethod.js +0 -15
  54. package/client/utils/attributes.d.ts +0 -2
  55. package/client/utils/attributes.js +0 -33
  56. package/client/utils/call.d.ts +0 -1
  57. package/client/utils/call.js +0 -3
  58. package/client/utils/classes.d.ts +0 -4
  59. package/client/utils/classes.js +0 -45
  60. package/client/utils/config.d.ts +0 -39
  61. package/client/utils/config.js +0 -28
  62. package/client/utils/defineProperty.d.ts +0 -1
  63. package/client/utils/defineProperty.js +0 -1
  64. package/client/utils/direction.d.ts +0 -6
  65. package/client/utils/direction.js +0 -8
  66. package/client/utils/event.d.ts +0 -13
  67. package/client/utils/event.js +0 -48
  68. package/client/utils/getFramework.d.ts +0 -2
  69. package/client/utils/getFramework.js +0 -20
  70. package/client/utils/getStyles.d.ts +0 -2
  71. package/client/utils/getStyles.js +0 -4
  72. package/client/utils/getTag.d.ts +0 -2
  73. package/client/utils/getTag.js +0 -4
  74. package/client/utils/host.d.ts +0 -5
  75. package/client/utils/host.js +0 -12
  76. package/client/utils/index.d.ts +0 -32
  77. package/client/utils/index.js +0 -32
  78. package/client/utils/isCSSColor.d.ts +0 -5
  79. package/client/utils/isCSSColor.js +0 -9
  80. package/client/utils/isEvent.d.ts +0 -1
  81. package/client/utils/isEvent.js +0 -3
  82. package/client/utils/isRTL.d.ts +0 -5
  83. package/client/utils/isRTL.js +0 -5
  84. package/client/utils/isServer.d.ts +0 -4
  85. package/client/utils/isServer.js +0 -6
  86. package/client/utils/merge.d.ts +0 -1
  87. package/client/utils/merge.js +0 -22
  88. package/client/utils/query.d.ts +0 -5
  89. package/client/utils/query.js +0 -7
  90. package/client/utils/queryAll.d.ts +0 -5
  91. package/client/utils/queryAll.js +0 -7
  92. package/client/utils/request.d.ts +0 -9
  93. package/client/utils/request.js +0 -106
  94. package/client/utils/shadowRoot.d.ts +0 -2
  95. package/client/utils/shadowRoot.js +0 -4
  96. package/client/utils/slots.d.ts +0 -9
  97. package/client/utils/slots.js +0 -18
  98. package/client/utils/styles.d.ts +0 -4
  99. package/client/utils/styles.js +0 -10
  100. package/client/utils/task.d.ts +0 -6
  101. package/client/utils/task.js +0 -34
  102. package/client/utils/toBoolean.d.ts +0 -1
  103. package/client/utils/toBoolean.js +0 -3
  104. package/client/utils/toDecorator.d.ts +0 -2
  105. package/client/utils/toDecorator.js +0 -10
  106. package/client/utils/toEvent.d.ts +0 -1
  107. package/client/utils/toEvent.js +0 -3
  108. package/client/utils/toProperty.d.ts +0 -1
  109. package/client/utils/toProperty.js +0 -55
  110. package/client/utils/toUnit.d.ts +0 -4
  111. package/client/utils/toUnit.js +0 -10
  112. package/client/utils/typeOf.d.ts +0 -3
  113. package/client/utils/typeOf.js +0 -6
  114. package/client/utils/uhtml.d.ts +0 -22
  115. package/client/utils/uhtml.js +0 -703
  116. package/client/utils/updateAttribute.d.ts +0 -2
  117. package/client/utils/updateAttribute.js +0 -10
  118. package/constants/index.d.ts +0 -48
  119. package/constants/index.js +0 -60
  120. package/transformer/index.d.ts +0 -3
  121. package/transformer/index.js +0 -3
  122. package/transformer/plugins/assets.d.ts +0 -7
  123. package/transformer/plugins/assets.js +0 -26
  124. package/transformer/plugins/copy.d.ts +0 -9
  125. package/transformer/plugins/copy.js +0 -29
  126. package/transformer/plugins/customElement.d.ts +0 -7
  127. package/transformer/plugins/customElement.js +0 -392
  128. package/transformer/plugins/document.d.ts +0 -7
  129. package/transformer/plugins/document.js +0 -206
  130. package/transformer/plugins/extract.d.ts +0 -2
  131. package/transformer/plugins/extract.js +0 -22
  132. package/transformer/plugins/index.d.ts +0 -12
  133. package/transformer/plugins/index.js +0 -12
  134. package/transformer/plugins/parse.d.ts +0 -6
  135. package/transformer/plugins/parse.js +0 -13
  136. package/transformer/plugins/read.d.ts +0 -7
  137. package/transformer/plugins/read.js +0 -19
  138. package/transformer/plugins/readme.d.ts +0 -6
  139. package/transformer/plugins/readme.js +0 -24
  140. package/transformer/plugins/style.d.ts +0 -6
  141. package/transformer/plugins/style.js +0 -42
  142. package/transformer/plugins/validate.d.ts +0 -2
  143. package/transformer/plugins/validate.js +0 -40
  144. package/transformer/plugins/visualStudioCode.d.ts +0 -8
  145. package/transformer/plugins/visualStudioCode.js +0 -73
  146. package/transformer/plugins/webTypes.d.ts +0 -10
  147. package/transformer/plugins/webTypes.js +0 -74
  148. package/transformer/transformer.d.ts +0 -8
  149. package/transformer/transformer.js +0 -78
  150. package/transformer/transformer.types.d.ts +0 -52
  151. package/transformer/transformer.types.js +0 -1
  152. package/transformer/utils/addDependency.d.ts +0 -7
  153. package/transformer/utils/addDependency.js +0 -64
  154. package/transformer/utils/extractAttribute.d.ts +0 -2
  155. package/transformer/utils/extractAttribute.js +0 -10
  156. package/transformer/utils/extractFromComment.d.ts +0 -4
  157. package/transformer/utils/extractFromComment.js +0 -51
  158. package/transformer/utils/getInitializer.d.ts +0 -2
  159. package/transformer/utils/getInitializer.js +0 -3
  160. package/transformer/utils/getType.d.ts +0 -2
  161. package/transformer/utils/getType.js +0 -89
  162. package/transformer/utils/getTypeReference.d.ts +0 -2
  163. package/transformer/utils/getTypeReference.js +0 -33
  164. package/transformer/utils/hasDecorator.d.ts +0 -1
  165. package/transformer/utils/hasDecorator.js +0 -5
  166. package/transformer/utils/index.d.ts +0 -10
  167. package/transformer/utils/index.js +0 -10
  168. package/transformer/utils/print.d.ts +0 -2
  169. package/transformer/utils/print.js +0 -5
  170. package/transformer/utils/printType.d.ts +0 -1
  171. package/transformer/utils/printType.js +0 -69
  172. package/transformer/utils/visitor.d.ts +0 -2
  173. package/transformer/utils/visitor.js +0 -5
  174. package/types/index.d.ts +0 -2
  175. package/types/index.js +0 -1
@@ -1,206 +0,0 @@
1
- import { capitalCase, kebabCase } from 'change-case';
2
- import fs from 'fs-extra';
3
- import { glob } from 'glob';
4
- import path from 'path';
5
- import * as CONSTANTS from '../../constants/index.js';
6
- import { extractAttribute, extractFromComment, getInitializer, getTypeReference, print } from '../utils/index.js';
7
- export const DOCUMENT_OPTIONS = {
8
- destination: path.join('dist', 'document.json')
9
- };
10
- export const document = (options) => {
11
- const name = 'document';
12
- options = Object.assign({}, DOCUMENT_OPTIONS, options);
13
- const write = (global) => {
14
- const json = {
15
- elements: []
16
- };
17
- for (const context of global.contexts) {
18
- const events = context.classEvents.map((event) => {
19
- const cancelable = (() => {
20
- if (!event.decorators)
21
- return false;
22
- try {
23
- for (const decorator of event.decorators) {
24
- for (const argument of decorator.expression['arguments']) {
25
- for (const property of argument.properties) {
26
- if (property.key.name != 'cancelable')
27
- continue;
28
- if (property.value.type != 'BooleanLiteral')
29
- continue;
30
- if (!property.value.value)
31
- continue;
32
- return true;
33
- }
34
- }
35
- }
36
- }
37
- catch { }
38
- return false;
39
- })();
40
- const detail = print(event.typeAnnotation?.['typeAnnotation']);
41
- const detailReference = getTypeReference(context.fileAST, event.typeAnnotation?.['typeAnnotation'].typeParameters.params[0]);
42
- const name = event.key['name'];
43
- return Object.assign({
44
- cancelable,
45
- detail,
46
- detailReference,
47
- name
48
- }, extractFromComment(event));
49
- });
50
- const lastModified = glob
51
- .sync('**/*.*', { cwd: context.directoryPath })
52
- .map((file) => fs.statSync(path.join(context.directoryPath, file)).mtime)
53
- .sort((a, b) => (a > b ? 1 : -1))
54
- .pop();
55
- const methods = context.classMethods.map((method) => {
56
- const async = method.async;
57
- const name = method.key['name'];
58
- const comments = extractFromComment(method);
59
- // TODO
60
- const parameters = method.params.map((param) => ({
61
- description: comments.params?.find((item) => item.name == param['name'])?.description,
62
- required: !param['optional'],
63
- name: param['name'],
64
- type: print(param?.['typeAnnotation']?.typeAnnotation) || undefined,
65
- typeReference: getTypeReference(context.fileAST, param?.['typeAnnotation']?.typeAnnotation)
66
- }));
67
- // TODO
68
- delete comments.params;
69
- const returns = print(method.returnType?.['typeAnnotation']) || 'void';
70
- const returnsReference = getTypeReference(context.fileAST, method.returnType?.['typeAnnotation']);
71
- const signature = [
72
- method.key['name'],
73
- '(',
74
- parameters
75
- .map((parameter) => {
76
- let string = '';
77
- string += parameter.name;
78
- string += parameter.required ? '' : '?';
79
- string += parameter.type ? ': ' : '';
80
- string += parameter.type ?? '';
81
- return string;
82
- })
83
- .join(', '),
84
- ')',
85
- ' => ',
86
- returns
87
- ].join('');
88
- return Object.assign({
89
- async,
90
- name,
91
- parameters,
92
- returns,
93
- returnsReference,
94
- signature
95
- }, comments,
96
- // TODO
97
- {
98
- returns
99
- },
100
- // TODO
101
- returns != 'void' &&
102
- comments.returns && {
103
- tags: [
104
- {
105
- key: 'returns',
106
- value: `${comments.returns}`
107
- }
108
- ]
109
- });
110
- });
111
- const properties = context.classProperties.map((property) => {
112
- const attribute = extractAttribute(property) || kebabCase(property.key['name']);
113
- // TODO
114
- const initializer = getInitializer(property.value);
115
- const name = property.key['name'];
116
- const readonly = property['kind'] == 'get';
117
- // TODO
118
- const reflects = (() => {
119
- if (!property.decorators)
120
- return false;
121
- try {
122
- for (const decorator of property.decorators) {
123
- for (const argument of decorator.expression['arguments']) {
124
- for (const property of argument.properties) {
125
- if (property.key.name != 'reflect')
126
- continue;
127
- if (property.value.type != 'BooleanLiteral')
128
- continue;
129
- if (!property.value.value)
130
- continue;
131
- return true;
132
- }
133
- }
134
- }
135
- }
136
- catch { }
137
- return false;
138
- })();
139
- const required = 'optional' in property && !property.optional;
140
- // TODO
141
- const type = property['returnType']
142
- ? print(property['returnType']?.['typeAnnotation'])
143
- : print(property.typeAnnotation?.['typeAnnotation']);
144
- const typeReference = getTypeReference(context.fileAST, property.typeAnnotation?.['typeAnnotation']);
145
- return Object.assign({
146
- attribute,
147
- initializer,
148
- name,
149
- readonly,
150
- reflects,
151
- required,
152
- type,
153
- typeReference
154
- }, extractFromComment(property));
155
- });
156
- // TODO
157
- const styles = (() => {
158
- if (!context.styleContent)
159
- return [];
160
- return context.styleContent
161
- .split(CONSTANTS.DECORATOR_CSS_VARIABLE)
162
- .slice(1)
163
- .map((section) => {
164
- const [first, second] = section.split(/\n/);
165
- const description = first.replace('*/', '').trim();
166
- const name = second.split(':')[0].trim();
167
- const initializerDefault = second.split(':').slice(1).join(':').replace(';', '').trim();
168
- // TODO
169
- const initializerTransformed = context.styleContentTransformed
170
- ?.split(name)
171
- ?.at(1)
172
- ?.split(':')
173
- ?.filter((section) => !!section)
174
- ?.at(0)
175
- ?.split(/;|}/)
176
- ?.at(0)
177
- ?.trim();
178
- const initializer = initializerTransformed || initializerDefault;
179
- return {
180
- description,
181
- initializer,
182
- name
183
- };
184
- });
185
- })();
186
- const title = capitalCase(context.elementKey);
187
- const element = Object.assign({
188
- events,
189
- key: context.elementKey,
190
- lastModified,
191
- methods,
192
- properties,
193
- readmeContent: context.readmeContent,
194
- styles,
195
- title
196
- }, extractFromComment(context.class));
197
- const transformed = options.transformer?.(context, element) || element;
198
- json.elements.push(transformed);
199
- }
200
- json.elements = json.elements.sort((a, b) => (a.title > b.title ? 1 : -1));
201
- const dirname = path.dirname(options.destination);
202
- fs.ensureDirSync(dirname);
203
- fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
204
- };
205
- return { name, write };
206
- };
@@ -1,2 +0,0 @@
1
- import { TransformerPlugin } from '../transformer.types.js';
2
- export declare const extract: () => TransformerPlugin;
@@ -1,22 +0,0 @@
1
- import t from '@babel/types';
2
- import { kebabCase } from 'change-case';
3
- import * as CONSTANTS from '../../constants/index.js';
4
- import { hasDecorator } from '../utils/index.js';
5
- export const extract = () => {
6
- const name = 'extract';
7
- const run = (context) => {
8
- const { declaration, leadingComments } = context.fileAST?.program.body.find((child) => {
9
- return t.isExportNamedDeclaration(child);
10
- });
11
- context.class = declaration;
12
- context.class.leadingComments = leadingComments; // TODO
13
- context.classMembers = context.class?.body?.body || [];
14
- context.className = context.class?.id?.name;
15
- context.elementKey = kebabCase(context.className || '');
16
- context.classEvents = context.classMembers.filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_EVENT));
17
- context.classMethods = context.classMembers.filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_METHOD));
18
- context.classProperties = context.classMembers.filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_PROPERTY));
19
- context.classStates = context.classMembers.filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_STATE));
20
- };
21
- return { name, run };
22
- };
@@ -1,12 +0,0 @@
1
- export * from './assets.js';
2
- export * from './copy.js';
3
- export * from './customElement.js';
4
- export * from './document.js';
5
- export * from './extract.js';
6
- export * from './parse.js';
7
- export * from './read.js';
8
- export * from './readme.js';
9
- export * from './style.js';
10
- export * from './validate.js';
11
- export * from './visualStudioCode.js';
12
- export * from './webTypes.js';
@@ -1,12 +0,0 @@
1
- export * from './assets.js';
2
- export * from './copy.js';
3
- export * from './customElement.js';
4
- export * from './document.js';
5
- export * from './extract.js';
6
- export * from './parse.js';
7
- export * from './read.js';
8
- export * from './readme.js';
9
- export * from './style.js';
10
- export * from './validate.js';
11
- export * from './visualStudioCode.js';
12
- export * from './webTypes.js';
@@ -1,6 +0,0 @@
1
- import { ParserOptions } from '@babel/parser';
2
- import { TransformerPlugin } from '../transformer.types.js';
3
- export declare const PARSE_OPTIONS: Partial<ParseOptions>;
4
- export interface ParseOptions extends ParserOptions {
5
- }
6
- export declare const parse: (options?: ParseOptions) => TransformerPlugin;
@@ -1,13 +0,0 @@
1
- import { parse as parser } from '@babel/parser';
2
- export const PARSE_OPTIONS = {
3
- sourceType: 'module',
4
- plugins: [['decorators', { decoratorsBeforeExport: true }], 'jsx', 'typescript']
5
- };
6
- export const parse = (options) => {
7
- const name = 'parse';
8
- options = Object.assign({}, PARSE_OPTIONS, options);
9
- const run = (context) => {
10
- context.fileAST = parser(context.fileContent, options);
11
- };
12
- return { name, run };
13
- };
@@ -1,7 +0,0 @@
1
- import { TransformerPlugin } from '../transformer.types.js';
2
- export declare const READ_OPTIONS: Partial<ReadOptions>;
3
- export interface ReadOptions {
4
- encoding: 'utf8' | 'ascii' | 'utf-8' | 'utf16le' | 'utf-16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
5
- flag?: string | undefined;
6
- }
7
- export declare const read: (options?: ReadOptions) => TransformerPlugin;
@@ -1,19 +0,0 @@
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
- if (!context.filePath)
11
- return;
12
- context.fileContent = fs.readFileSync(context.filePath, options);
13
- context.fileExtension = path.extname(context.filePath);
14
- context.fileName = path.basename(context.filePath, context.fileExtension);
15
- context.directoryPath = path.dirname(context.filePath);
16
- context.directoryName = path.basename(context.directoryPath);
17
- };
18
- return { name, run };
19
- };
@@ -1,6 +0,0 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
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;
@@ -1,24 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- export const README_OPTIONS = {
4
- source(context) {
5
- return path.join(context.directoryPath, `${context.fileName}.md`);
6
- }
7
- };
8
- export const readme = (options) => {
9
- const name = 'readme';
10
- options = Object.assign({}, README_OPTIONS, options);
11
- const finish = (global) => {
12
- for (const context of global.contexts) {
13
- context.readmePath = options.source(context);
14
- if (!context.readmePath)
15
- continue;
16
- if (!fs.existsSync(context.readmePath))
17
- continue;
18
- context.readmeContent = fs.readFileSync(context.readmePath, 'utf8');
19
- context.readmeExtension = path.extname(context.readmePath);
20
- context.readmeName = path.basename(context.readmePath, context.readmeExtension);
21
- }
22
- };
23
- return { name, finish };
24
- };
@@ -1,6 +0,0 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
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;
@@ -1,42 +0,0 @@
1
- import t from '@babel/types';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import * as CONSTANTS from '../../constants/index.js';
5
- import { addDependency } from '../utils/index.js';
6
- export const STYLE_OPTIONS = {
7
- source(context) {
8
- return [
9
- path.join(context.directoryPath, `${context.fileName}.css`),
10
- path.join(context.directoryPath, `${context.fileName}.less`),
11
- path.join(context.directoryPath, `${context.fileName}.sass`),
12
- path.join(context.directoryPath, `${context.fileName}.scss`),
13
- path.join(context.directoryPath, `${context.fileName}.styl`)
14
- ];
15
- }
16
- };
17
- export const style = (options) => {
18
- const name = 'style';
19
- options = Object.assign({}, STYLE_OPTIONS, options);
20
- const run = (context) => {
21
- const sources = [options.source(context)].flat();
22
- for (const source of sources) {
23
- if (!source)
24
- continue;
25
- if (!fs.existsSync(source))
26
- continue;
27
- context.stylePath = source;
28
- break;
29
- }
30
- if (!context.stylePath)
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);
35
- const { local } = addDependency(context.fileAST, context.stylePath, CONSTANTS.STYLE_IMPORTED, undefined, true);
36
- // TODO: remove 'local!'
37
- const property = t.classProperty(t.identifier(CONSTANTS.STATIC_STYLE), t.identifier(local), undefined, null, undefined, true);
38
- t.addComment(property, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
39
- context.class.body.body.unshift(property);
40
- };
41
- return { name, run };
42
- };
@@ -1,2 +0,0 @@
1
- import { TransformerPlugin } from '../transformer.types.js';
2
- export declare const validate: () => TransformerPlugin;
@@ -1,40 +0,0 @@
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
- if (path.node.source?.value !== CONSTANTS.PACKAGE_NAME)
11
- return;
12
- for (const specifier of path.node.specifiers) {
13
- if (specifier.imported.name !== CONSTANTS.DECORATOR_ELEMENT)
14
- continue;
15
- const binding = path.scope.getBinding(specifier.imported.name);
16
- if (binding.references == 0)
17
- break;
18
- const referencePaths = binding.referencePaths.filter((referencePath) => {
19
- if (t.isCallExpression(referencePath.parent) &&
20
- t.isDecorator(referencePath.parentPath.parent) &&
21
- t.isClassDeclaration(referencePath.parentPath.parentPath.parent) &&
22
- t.isExportNamedDeclaration(referencePath.parentPath.parentPath.parentPath.parent))
23
- return true;
24
- });
25
- if (referencePaths.length > 1) {
26
- throw new Error('In each file, only one custom element can be defined. \n' +
27
- 'If more than one @Element() decorator is used in the file, it will result in an error.\n');
28
- }
29
- context.skipped = false;
30
- if (referencePaths.length == 1)
31
- break;
32
- throw new Error('It appears that the class annotated with the @Element() decorator is not being exported correctly.');
33
- }
34
- path.stop();
35
- }
36
- });
37
- context.skipped;
38
- };
39
- return { name, run };
40
- };
@@ -1,8 +0,0 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
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;
@@ -1,73 +0,0 @@
1
- import { kebabCase } from 'change-case';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { extractAttribute, extractFromComment, getType, print } from '../utils/index.js';
5
- export const VISUAL_STUDIO_CODE_OPTIONS = {
6
- destination: path.join('dist', 'visual-studio-code.json')
7
- };
8
- export const visualStudioCode = (options) => {
9
- const name = 'visualStudioCode';
10
- options = Object.assign({}, VISUAL_STUDIO_CODE_OPTIONS, options);
11
- const finish = (global) => {
12
- const contexts = global.contexts.sort((a, b) => {
13
- return a.elementKey.toUpperCase() > b.elementKey.toUpperCase() ? +1 : -1;
14
- });
15
- const json = {
16
- $schema: 'TODO',
17
- version: 1.1,
18
- tags: []
19
- };
20
- for (const context of contexts) {
21
- const tag = Object.assign({
22
- name: context.elementKey,
23
- attributes: [],
24
- references: [
25
- {
26
- name: 'Source code',
27
- url: options.reference?.(context)
28
- }
29
- ]
30
- }, extractFromComment(context.class, ['description']));
31
- for (const property of context.classProperties || []) {
32
- const attribute = Object.assign({
33
- name: extractAttribute(property) || kebabCase(property.key['name']),
34
- values: []
35
- }, extractFromComment(property, ['description']));
36
- const type = print(getType(context.directoryPath, context.fileAST, property.typeAnnotation?.['typeAnnotation']));
37
- const sections = type.split('|');
38
- for (const section of sections) {
39
- const trimmed = section.trim();
40
- if (!trimmed)
41
- continue;
42
- const isBoolean = /bool|boolean|Boolean/.test(trimmed);
43
- const isNumber = !isNaN(trimmed);
44
- const isString = /^("|'|`)/.test(trimmed);
45
- if (isBoolean) {
46
- attribute.values.push({
47
- name: 'false'
48
- }, {
49
- name: 'true'
50
- });
51
- }
52
- else if (isNumber) {
53
- attribute.values.push({
54
- name: trimmed
55
- });
56
- }
57
- else if (isString) {
58
- attribute.values.push({
59
- name: trimmed.slice(1, -1)
60
- });
61
- }
62
- }
63
- tag.attributes.push(attribute);
64
- }
65
- const transformed = options.transformer?.(context, tag) || tag;
66
- json.tags.push(transformed);
67
- }
68
- const dirname = path.dirname(options.destination);
69
- fs.ensureDirSync(dirname);
70
- fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
71
- };
72
- return { name, finish };
73
- };
@@ -1,10 +0,0 @@
1
- import { TransformerPlugin, TransformerPluginContext } from '../transformer.types.js';
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;
@@ -1,74 +0,0 @@
1
- import { kebabCase } from 'change-case';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { extractAttribute, extractFromComment, getInitializer, getType, print } from '../utils/index.js';
5
- export const WEB_TYPES_OPTIONS = {
6
- destination: path.join('dist', 'web-types.json'),
7
- packageName: '',
8
- packageVersion: ''
9
- };
10
- export const webTypes = (options) => {
11
- const name = 'webTypes';
12
- options = Object.assign({}, WEB_TYPES_OPTIONS, options);
13
- const finish = (global) => {
14
- const contexts = global.contexts.sort((a, b) => {
15
- return a.elementKey.toUpperCase() > b.elementKey.toUpperCase() ? +1 : -1;
16
- });
17
- const json = {
18
- '$schema': 'http://json.schemastore.org/web-types',
19
- 'name': options.packageName,
20
- 'version': options.packageVersion,
21
- 'description-markup': 'markdown',
22
- 'framework-config': {
23
- 'enable-when': {
24
- 'node-packages': [options.packageName]
25
- }
26
- },
27
- 'contributions': {
28
- html: {
29
- elements: []
30
- }
31
- }
32
- };
33
- for (const context of contexts) {
34
- const attributes = context.classProperties?.map((property) => Object.assign({
35
- name: extractAttribute(property) || kebabCase(property.key['name']),
36
- value: {
37
- // kind: TODO
38
- type: print(getType(context.directoryPath, context.fileAST, property.typeAnnotation?.['typeAnnotation']))
39
- // required: TODO
40
- // default: TODO
41
- },
42
- default: getInitializer(property.value)
43
- }, extractFromComment(property, ['description', 'deprecated', 'experimental'])));
44
- const events = context.classEvents?.map((event) => Object.assign({
45
- name: kebabCase(event.key['name']) // TODO
46
- // 'value': TODO
47
- }, extractFromComment(event, ['description', 'deprecated', 'experimental'])));
48
- const methods = context.classMethods?.map((method) => Object.assign({
49
- name: method.key['name']
50
- // 'value': TODO
51
- }, extractFromComment(method, ['description', 'deprecated', 'experimental'])));
52
- const properties = context.classProperties?.map((property) => Object.assign({
53
- name: property.key['name'],
54
- // 'value': TODO
55
- default: getInitializer(property.value)
56
- }, extractFromComment(property, ['description', 'deprecated', 'experimental'])));
57
- const element = Object.assign({
58
- 'name': context.elementKey,
59
- 'doc-url': options.reference?.(context),
60
- 'js': {
61
- events,
62
- properties: [].concat(properties, methods)
63
- },
64
- attributes
65
- }, extractFromComment(context.class, ['description', 'deprecated', 'experimental', 'slots']));
66
- const transformed = options.transformer?.(context, element) || element;
67
- json.contributions.html.elements.push(transformed);
68
- }
69
- const dirname = path.dirname(options.destination);
70
- fs.ensureDirSync(dirname);
71
- fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
72
- };
73
- return { name, finish };
74
- };
@@ -1,8 +0,0 @@
1
- import { TransformerPlugin, TransformerPluginContext, TransformerPluginGlobal } from './transformer.types.js';
2
- export declare const transformer: (...plugins: TransformerPlugin[]) => {
3
- global: TransformerPluginGlobal;
4
- start: () => Promise<void>;
5
- run: (filePath: string) => Promise<TransformerPluginContext>;
6
- finish: () => Promise<void>;
7
- write: () => Promise<void>;
8
- };