@htmlplus/element 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +2 -2
  2. package/client/decorators/attributes.d.ts +2 -0
  3. package/client/decorators/attributes.js +13 -0
  4. package/client/decorators/bind.d.ts +4 -0
  5. package/client/decorators/bind.js +17 -0
  6. package/client/decorators/element.d.ts +2 -0
  7. package/client/decorators/element.js +53 -0
  8. package/client/decorators/event.d.ts +21 -0
  9. package/client/decorators/event.js +17 -0
  10. package/client/decorators/index.d.ts +9 -0
  11. package/client/decorators/index.js +9 -0
  12. package/client/decorators/listen.d.ts +12 -0
  13. package/client/decorators/listen.js +31 -0
  14. package/client/decorators/method.d.ts +2 -0
  15. package/client/decorators/method.js +11 -0
  16. package/client/decorators/property.d.ts +8 -0
  17. package/client/decorators/property.js +45 -0
  18. package/client/decorators/state.d.ts +2 -0
  19. package/client/decorators/state.js +23 -0
  20. package/client/decorators/watch.d.ts +8 -0
  21. package/client/decorators/watch.js +34 -0
  22. package/client/helpers/classes.d.ts +1 -0
  23. package/client/helpers/classes.js +62 -0
  24. package/client/helpers/direction.d.ts +3 -0
  25. package/client/helpers/direction.js +4 -0
  26. package/client/helpers/index.d.ts +9 -0
  27. package/client/helpers/index.js +9 -0
  28. package/client/helpers/isRTL.d.ts +2 -0
  29. package/client/helpers/isRTL.js +2 -0
  30. package/client/helpers/query.d.ts +3 -0
  31. package/client/helpers/query.js +5 -0
  32. package/client/helpers/queryAll.d.ts +3 -0
  33. package/client/helpers/queryAll.js +5 -0
  34. package/client/helpers/slots.d.ts +6 -0
  35. package/client/helpers/slots.js +15 -0
  36. package/client/helpers/styles.d.ts +1 -0
  37. package/client/helpers/styles.js +17 -0
  38. package/client/helpers/toUnit.d.ts +1 -0
  39. package/client/helpers/toUnit.js +7 -0
  40. package/client/index.d.ts +3 -0
  41. package/client/index.js +3 -0
  42. package/client/services/index.d.ts +1 -0
  43. package/client/services/index.js +1 -0
  44. package/client/services/link.d.ts +4 -0
  45. package/client/services/link.js +196 -0
  46. package/client/utils/appendToMethod.d.ts +2 -0
  47. package/client/utils/appendToMethod.js +7 -0
  48. package/client/utils/call.d.ts +2 -0
  49. package/client/utils/call.js +4 -0
  50. package/client/utils/defineProperty.d.ts +1 -0
  51. package/client/utils/defineProperty.js +1 -0
  52. package/client/utils/event.d.ts +5 -0
  53. package/client/utils/event.js +9 -0
  54. package/client/utils/getMembers.d.ts +2 -0
  55. package/client/utils/getMembers.js +5 -0
  56. package/client/utils/getStyles.d.ts +2 -0
  57. package/client/utils/getStyles.js +5 -0
  58. package/client/utils/host.d.ts +2 -0
  59. package/client/utils/host.js +4 -0
  60. package/client/utils/index.d.ts +17 -0
  61. package/client/utils/index.js +17 -0
  62. package/client/utils/isEvent.d.ts +1 -0
  63. package/client/utils/isEvent.js +3 -0
  64. package/client/utils/isServer.d.ts +1 -0
  65. package/client/utils/isServer.js +3 -0
  66. package/client/utils/parseValue.d.ts +1 -0
  67. package/client/utils/parseValue.js +15 -0
  68. package/client/utils/request.d.ts +4 -0
  69. package/client/utils/request.js +38 -0
  70. package/client/utils/sync.d.ts +1 -0
  71. package/client/utils/sync.js +31 -0
  72. package/client/utils/task.d.ts +6 -0
  73. package/client/utils/task.js +37 -0
  74. package/client/utils/toBoolean.d.ts +1 -0
  75. package/client/utils/toBoolean.js +3 -0
  76. package/client/utils/toEvent.d.ts +1 -0
  77. package/client/utils/toEvent.js +3 -0
  78. package/client/utils/typeOf.d.ts +3 -0
  79. package/client/utils/typeOf.js +6 -0
  80. package/client/utils/updateAttribute.d.ts +1 -0
  81. package/client/utils/updateAttribute.js +7 -0
  82. package/client/vendor/uhtml.d.ts +22 -0
  83. package/client/vendor/uhtml.js +700 -0
  84. package/compiler/compiler.d.ts +7 -0
  85. package/compiler/compiler.js +72 -0
  86. package/compiler/index.d.ts +2 -0
  87. package/compiler/index.js +2 -0
  88. package/compiler/plugins/customElement.d.ts +8 -0
  89. package/compiler/plugins/customElement.js +157 -0
  90. package/compiler/plugins/customElementReact/customElementReact.d.ts +12 -0
  91. package/compiler/plugins/customElementReact/customElementReact.js +129 -0
  92. package/compiler/plugins/customElementReact/index.d.ts +1 -0
  93. package/compiler/plugins/customElementReact/index.js +1 -0
  94. package/compiler/plugins/customElementReact/templates/README.md.hbs +1 -0
  95. package/compiler/plugins/customElementReact/templates/_.gitignore.hbs +2 -0
  96. package/compiler/plugins/customElementReact/templates/package.json.hbs +37 -0
  97. package/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +21 -0
  98. package/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +17 -0
  99. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +18 -0
  100. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +26 -0
  101. package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +1 -0
  102. package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +278 -0
  103. package/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +17 -0
  104. package/compiler/plugins/document.d.ts +10 -0
  105. package/compiler/plugins/document.js +254 -0
  106. package/compiler/plugins/external.d.ts +9 -0
  107. package/compiler/plugins/external.js +25 -0
  108. package/compiler/plugins/extract.d.ts +8 -0
  109. package/compiler/plugins/extract.js +62 -0
  110. package/compiler/plugins/index.d.ts +9 -0
  111. package/compiler/plugins/index.js +9 -0
  112. package/compiler/plugins/parse.d.ts +5 -0
  113. package/compiler/plugins/parse.js +16 -0
  114. package/compiler/plugins/read.d.ts +5 -0
  115. package/compiler/plugins/read.js +13 -0
  116. package/compiler/plugins/style.d.ts +10 -0
  117. package/compiler/plugins/style.js +36 -0
  118. package/compiler/plugins/validate.d.ts +5 -0
  119. package/compiler/plugins/validate.js +40 -0
  120. package/compiler/plugins/vscode.d.ts +11 -0
  121. package/compiler/plugins/vscode.js +83 -0
  122. package/compiler/utils/__dirname.d.ts +1 -0
  123. package/compiler/utils/__dirname.js +5 -0
  124. package/compiler/utils/getInitializer.d.ts +2 -0
  125. package/compiler/utils/getInitializer.js +10 -0
  126. package/compiler/utils/getType.d.ts +2 -0
  127. package/compiler/utils/getType.js +69 -0
  128. package/compiler/utils/getTypeReference.d.ts +2 -0
  129. package/compiler/utils/getTypeReference.js +33 -0
  130. package/compiler/utils/hasDecorator.d.ts +1 -0
  131. package/compiler/utils/hasDecorator.js +5 -0
  132. package/compiler/utils/index.d.ts +11 -0
  133. package/compiler/utils/index.js +11 -0
  134. package/compiler/utils/isDirectoryEmpty.d.ts +1 -0
  135. package/compiler/utils/isDirectoryEmpty.js +10 -0
  136. package/compiler/utils/print.d.ts +2 -0
  137. package/compiler/utils/print.js +5 -0
  138. package/compiler/utils/printType.d.ts +1 -0
  139. package/compiler/utils/printType.js +69 -0
  140. package/compiler/utils/renderTemplate.d.ts +1 -0
  141. package/compiler/utils/renderTemplate.js +25 -0
  142. package/compiler/utils/tags.d.ts +13 -0
  143. package/compiler/utils/tags.js +53 -0
  144. package/compiler/utils/visitor.d.ts +2 -0
  145. package/compiler/utils/visitor.js +5 -0
  146. package/constants/index.d.ts +22 -0
  147. package/constants/index.js +28 -0
  148. package/package.json +14 -17
  149. package/types/context.d.ts +38 -0
  150. package/types/context.js +1 -0
  151. package/types/global.d.ts +4 -0
  152. package/types/global.js +1 -0
  153. package/types/index.d.ts +4 -0
  154. package/types/index.js +4 -0
  155. package/types/plugin.d.ts +10 -0
  156. package/types/plugin.js +1 -0
  157. package/types/plusElement.d.ts +2 -0
  158. package/types/plusElement.js +1 -0
@@ -0,0 +1,278 @@
1
+ /**************************************************
2
+ * THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
3
+ **************************************************/
4
+
5
+ import { camelCase, paramCase, pascalCase } from 'change-case';
6
+ import React from 'react';
7
+
8
+ type EventHandlerType = (event: Event) => any;
9
+
10
+ type FinalPropsType<ElementType> = Omit<PropsType<ElementType>, 'forwardedRef'>;
11
+
12
+ type Mutable<T> = { -readonly [P in keyof T]-?: T[P] };
13
+
14
+ interface ExtraType {
15
+ props?: Array<string>;
16
+ events?: Array<string>;
17
+ }
18
+
19
+ interface PropsType<ElementType> extends React.HTMLAttributes<ElementType> {
20
+ forwardedRef: React.RefObject<ElementType>;
21
+ ref?: React.Ref<any>;
22
+ }
23
+
24
+ export interface StyleReactProps {
25
+ class?: string;
26
+ className?: string;
27
+ style?: {
28
+ [key: string]: any;
29
+ };
30
+ }
31
+
32
+ const arrayToMap = (array: string[] | DOMTokenList) => {
33
+ const map = new Map<string, string>();
34
+
35
+ (array as string[]).forEach((s: string) => map.set(s, s));
36
+
37
+ return map;
38
+ };
39
+
40
+ const getCustomEvent = (name: string, events: Array<string>) => {
41
+ // TODO
42
+ name = camelCase(name.slice(3));
43
+
44
+ const event = events.find((event) => event.endsWith(name));
45
+
46
+ if (!event) return;
47
+
48
+ return event;
49
+ };
50
+
51
+ const forwardRef = <ElementType, PropType>(ReactComponent: any) => {
52
+ const forwardRef = (
53
+ props: PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & StyleReactProps,
54
+ ref: React.Ref<ElementType>
55
+ ) => {
56
+ const { children, ...remainedProps } = props;
57
+
58
+ const newProps = {
59
+ ...remainedProps,
60
+ forwardedRef: ref
61
+ };
62
+
63
+ return React.createElement(ReactComponent, newProps, children);
64
+ };
65
+
66
+ forwardRef.displayName = ReactComponent.displayName;
67
+
68
+ return React.forwardRef(forwardRef);
69
+ };
70
+
71
+ const isEvent = (name: string) => {
72
+ return name.indexOf('on') === 0 && name[2] === name[2].toUpperCase();
73
+ };
74
+
75
+ const isPrimitive = (value: any) => {
76
+ const type = typeof value;
77
+
78
+ const match = type.match(/boolean|string|number/);
79
+
80
+ return match;
81
+ };
82
+
83
+ const getProps = <ElementType>(ref: React.Ref<ElementType>, props: PropsType<ElementType>, extra: ExtraType) => {
84
+ const { forwardedRef } = props;
85
+
86
+ const result: FinalPropsType<ElementType> = {
87
+ ref: mergeRefs(forwardedRef, ref)
88
+ };
89
+
90
+ Object.keys(props).forEach((name) => {
91
+ if (name === 'children' || name === 'className' || name === 'forwardedRef' || name === 'ref') return;
92
+
93
+ const value = props[name];
94
+
95
+ if (isEvent(name)) {
96
+ if (typeof document === 'undefined') return;
97
+
98
+ const event = getCustomEvent(name, extra.events);
99
+
100
+ if (event) return;
101
+
102
+ result[name] = value;
103
+ } else if (extra.props.includes(name)) {
104
+ if (!isPrimitive(value)) return;
105
+
106
+ result[paramCase(name)] = value;
107
+ } else {
108
+ result[name] = value;
109
+ }
110
+ });
111
+
112
+ return result;
113
+ };
114
+
115
+ const mergeRefs =
116
+ <ElementType>(...refs: React.Ref<ElementType>[]) =>
117
+ (value: ElementType) => {
118
+ return refs.forEach((ref) => {
119
+ if (typeof ref === 'function') return ref(value);
120
+
121
+ if (ref == null) return;
122
+
123
+ (ref as Mutable<React.RefObject<ElementType>>).current = value;
124
+ });
125
+ };
126
+
127
+ const setClass = <ElementType>(element: ElementType, props: PropsType<ElementType>) => {
128
+ const classes: string[] = [];
129
+
130
+ const current = arrayToMap((element as any).classList);
131
+
132
+ const prev: string = element['$class'];
133
+ const next: string = props.className || (props as any).class;
134
+
135
+ const prevClass = arrayToMap(prev ? prev.split(' ') : []);
136
+ const nextClass = arrayToMap(next ? next.split(' ') : []);
137
+
138
+ current.forEach((key) => {
139
+ if (nextClass.has(key)) {
140
+ classes.push(key);
141
+
142
+ nextClass.delete(key);
143
+ } else if (!prevClass.has(key)) {
144
+ classes.push(key);
145
+ }
146
+ });
147
+
148
+ nextClass.forEach((key) => classes.push(key));
149
+
150
+ const className = classes.join(' ');
151
+
152
+ (element as any).className = className;
153
+
154
+ element['$class'] = className;
155
+ };
156
+
157
+ const setEvent = (element: Element, name: string, handler: EventHandlerType) => {
158
+ const events = element['$events'] || (element['$events'] = {});
159
+
160
+ const previous = events[name];
161
+
162
+ previous && element.removeEventListener(name, previous);
163
+
164
+ function callback(event: Event) {
165
+ handler && handler.call(this, event);
166
+ }
167
+
168
+ element.addEventListener(name, (events[name] = callback));
169
+ };
170
+
171
+ const setProps = <ElementType>(element: ElementType, props: PropsType<ElementType>, extra: ExtraType) => {
172
+ if (!(element instanceof Element)) return;
173
+
174
+ setClass<ElementType>(element, props);
175
+
176
+ Object.keys(props).forEach((name) => {
177
+ if (
178
+ name === 'children' ||
179
+ name === 'class' ||
180
+ name === 'className' ||
181
+ name === 'forwardedRef' ||
182
+ name === 'ref' ||
183
+ name === 'style'
184
+ )
185
+ return;
186
+
187
+ const value = props[name];
188
+
189
+ if (isEvent(name)) {
190
+ if (typeof document === 'undefined') return;
191
+
192
+ const event = getCustomEvent(name, extra.events);
193
+
194
+ if (!event) return;
195
+
196
+ setEvent(element, event, value);
197
+ } else if (extra.props.includes(name)) {
198
+ if (isPrimitive(value)) {
199
+ element.setAttribute(paramCase(name), value);
200
+ } else {
201
+ element[name] = value;
202
+ }
203
+ } else {
204
+ element[name] = value;
205
+ }
206
+ });
207
+ };
208
+
209
+ export const proxy = <ElementType, PropType>(
210
+ tagName: string,
211
+ props: Array<string> = [],
212
+ events: Array<string> = []
213
+ ) => {
214
+ const extra: ExtraType = {
215
+ props,
216
+ events
217
+ };
218
+
219
+ const ReactComponent = class extends React.Component<PropsType<ElementType>> {
220
+ element!: ElementType;
221
+
222
+ setElement = (element: ElementType) => {
223
+ this.element = element;
224
+ };
225
+
226
+ constructor(props: PropsType<ElementType>) {
227
+ super(props);
228
+ }
229
+
230
+ componentDidMount() {
231
+ this.componentDidUpdate(/*this.props*/);
232
+ }
233
+
234
+ componentDidUpdate(/*prevProps: InternalProps<ElementType>*/) {
235
+ setProps<ElementType>(this.element as any, this.props, extra);
236
+ }
237
+
238
+ componentWillUnmount() {
239
+ if (!this.element) return;
240
+
241
+ const events = this.element['$events'] || {};
242
+
243
+ Object.keys(events).forEach((name) => {
244
+ const handler = events[name];
245
+
246
+ (this.element as any).removeEventListener(name, handler);
247
+ });
248
+
249
+ delete this.element['$events'];
250
+ }
251
+
252
+ render() {
253
+ const { children } = this.props;
254
+
255
+ const props = getProps<ElementType>(this.setElement, this.props, extra);
256
+
257
+ return React.createElement(tagName, props, children);
258
+ }
259
+ };
260
+
261
+ // TODO
262
+ // const ReactComponentNew = (props: InternalPropsType<ElementType>) => {
263
+
264
+ // const { children } = props;
265
+
266
+ // const ref = useRef(null);
267
+
268
+ // const newProps: FinalPropsType<ElementType> = getProps(ref, props, events);
269
+
270
+ // useEffect(() => setProps(ref.current, props, events));
271
+
272
+ // return React.createElement(tagName, newProps, children);
273
+ // }
274
+
275
+ ReactComponent['displayName'] = pascalCase(tagName);
276
+
277
+ return forwardRef<ElementType, PropType>(ReactComponent);
278
+ };
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "experimentalDecorators": true,
4
+ "declaration": true,
5
+ "declarationDir": "dist",
6
+ "module": "esnext",
7
+ "target": "es5",
8
+ "lib": ["es6", "dom", "es2016", "es2017"],
9
+ "sourceMap": true,
10
+ "jsx": "react",
11
+ "moduleResolution": "node",
12
+ "allowSyntheticDefaultImports": true,
13
+ "esModuleInterop": true
14
+ },
15
+ "include": ["src"],
16
+ "exclude": ["dist", "node_modules"]
17
+ }
@@ -0,0 +1,10 @@
1
+ import { Context } from '../../types/index.js';
2
+ export interface DocumentOptions {
3
+ destination: string;
4
+ }
5
+ export declare const document: (options: DocumentOptions) => {
6
+ name: string;
7
+ start: (global: any) => void;
8
+ next: (context: Context, global: any) => void;
9
+ finish: (global: any) => void;
10
+ };
@@ -0,0 +1,254 @@
1
+ import { capitalCase, paramCase } from 'change-case';
2
+ import fs from 'fs';
3
+ import glob from 'glob';
4
+ import path from 'path';
5
+ import { getInitializer, getTag, getTags, getTypeReference, hasTag, parseTag, print } from '../utils/index.js';
6
+ export const document = (options) => {
7
+ const name = 'document';
8
+ const start = (global) => {
9
+ global.document = {
10
+ components: []
11
+ };
12
+ };
13
+ const next = (context, global) => {
14
+ var _a;
15
+ const events = context.classEvents.map((event) => {
16
+ var _a, _b, _c;
17
+ const isCancelable = (() => {
18
+ if (!event.decorators)
19
+ return false;
20
+ try {
21
+ for (const decorator of event.decorators) {
22
+ for (const argument of decorator.expression['arguments']) {
23
+ for (const property of argument.properties) {
24
+ if (property.key.name != 'cancelable')
25
+ continue;
26
+ if (property.value.type != 'BooleanLiteral')
27
+ continue;
28
+ if (!property.value.value)
29
+ continue;
30
+ return true;
31
+ }
32
+ }
33
+ }
34
+ }
35
+ catch (_a) { }
36
+ return false;
37
+ })();
38
+ const description = (_a = getTags(event).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
39
+ const detail = print((_b = event.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation']);
40
+ const detailReference = getTypeReference(context.fileAST, (_c = event.typeAnnotation) === null || _c === void 0 ? void 0 : _c['typeAnnotation'].typeParameters.params[0]);
41
+ const isExperimental = hasTag(event, 'experimental');
42
+ const isModel = hasTag(event, 'model');
43
+ const name = event.key['name'];
44
+ const tags = getTags(event);
45
+ return {
46
+ description,
47
+ detail,
48
+ detailReference,
49
+ isCancelable,
50
+ isExperimental,
51
+ isModel,
52
+ name,
53
+ tags
54
+ };
55
+ });
56
+ const group = (_a = getTag(context.class, 'group')) === null || _a === void 0 ? void 0 : _a.value;
57
+ const isDeprecated = hasTag(context.class, 'deprecated');
58
+ const isExperimental = hasTag(context.class, 'experimental');
59
+ const lastModified = glob
60
+ .sync(path.join(context.directoryPath, '**/*.*'))
61
+ .map((file) => fs.statSync(file).mtime)
62
+ .sort((a, b) => (a > b ? 1 : -1))
63
+ .pop();
64
+ const methods = context.classMethods.map((method) => {
65
+ var _a, _b, _c;
66
+ const description = (_a = getTags(method).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
67
+ const isAsync = method.async;
68
+ const isDeprecated = hasTag(method, 'deprecated');
69
+ const isExperimental = hasTag(method, 'experimental');
70
+ const name = method.key['name'];
71
+ const returns = print((_b = method.returnType) === null || _b === void 0 ? void 0 : _b['typeAnnotation']) || 'void';
72
+ const returnsReference = getTypeReference(context.fileAST, (_c = method.returnType) === null || _c === void 0 ? void 0 : _c['typeAnnotation']);
73
+ const tags = getTags(method);
74
+ // TODO
75
+ const parameters = method.params.map((param) => {
76
+ var _a, _b, _c;
77
+ return ({
78
+ description: (_a = getTags(method, 'param')
79
+ .map((tag) => parseTag(tag, ' '))
80
+ .find((tag) => tag.name == param['name'])) === null || _a === void 0 ? void 0 : _a.description,
81
+ isOptional: !!param['optional'],
82
+ name: param['name'],
83
+ type: print((_b = param === null || param === void 0 ? void 0 : param['typeAnnotation']) === null || _b === void 0 ? void 0 : _b.typeAnnotation) || undefined,
84
+ typeReference: getTypeReference(context.fileAST, (_c = param === null || param === void 0 ? void 0 : param['typeAnnotation']) === null || _c === void 0 ? void 0 : _c.typeAnnotation)
85
+ });
86
+ });
87
+ const signature = [
88
+ method.key['name'],
89
+ '(',
90
+ parameters
91
+ .map((parameter) => {
92
+ var _a;
93
+ let string = '';
94
+ string += parameter.name;
95
+ string += parameter.isOptional ? '?' : '';
96
+ string += parameter.type ? ': ' : '';
97
+ string += (_a = parameter.type) !== null && _a !== void 0 ? _a : '';
98
+ return string;
99
+ })
100
+ .join(', '),
101
+ ')',
102
+ ' => ',
103
+ returns
104
+ ].join('');
105
+ return {
106
+ description,
107
+ isAsync,
108
+ isDeprecated,
109
+ isExperimental,
110
+ name,
111
+ returns,
112
+ returnsReference,
113
+ tags,
114
+ parameters,
115
+ signature
116
+ };
117
+ });
118
+ const parts = getTags(context.class, 'part').map((tag) => parseTag(tag));
119
+ const properties = context.classProperties.map((property) => {
120
+ var _a, _b, _c;
121
+ const attribute = paramCase(property.key['name']);
122
+ const description = (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
123
+ // TODO
124
+ const hasReflect = (() => {
125
+ if (!property.decorators)
126
+ return false;
127
+ try {
128
+ for (const decorator of property.decorators) {
129
+ for (const argument of decorator.expression['arguments']) {
130
+ for (const property of argument.properties) {
131
+ if (property.key.name != 'reflect')
132
+ continue;
133
+ if (property.value.type != 'BooleanLiteral')
134
+ continue;
135
+ if (!property.value.value)
136
+ continue;
137
+ return true;
138
+ }
139
+ }
140
+ }
141
+ }
142
+ catch (_a) { }
143
+ return false;
144
+ })();
145
+ // TODO
146
+ const initializer = getInitializer(property.value);
147
+ const isDeprecated = hasTag(property, 'deprecated');
148
+ const isExperimental = hasTag(property, 'experimental');
149
+ const isModel = hasTag(property, 'model');
150
+ const isRequired = !property.optional;
151
+ const name = property.key['name'];
152
+ const tags = getTags(property);
153
+ const type = print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation']);
154
+ const typeReference = getTypeReference(context.fileAST, (_c = property.typeAnnotation) === null || _c === void 0 ? void 0 : _c['typeAnnotation']);
155
+ return {
156
+ attribute,
157
+ description,
158
+ hasReflect,
159
+ initializer,
160
+ isDeprecated,
161
+ isExperimental,
162
+ isModel,
163
+ isRequired,
164
+ name,
165
+ tags,
166
+ type,
167
+ typeReference
168
+ };
169
+ });
170
+ const readme = (() => {
171
+ try {
172
+ const source = path.join(context.directoryPath, `${context.fileName}.md`);
173
+ return fs.readFileSync(source, 'utf8');
174
+ }
175
+ catch (_a) { }
176
+ })();
177
+ const readmeDescription = (() => {
178
+ const content = readme || '';
179
+ if (!content.startsWith('# '))
180
+ return '';
181
+ const sections = content.split('\n');
182
+ for (let i = 1; i < sections.length; i++) {
183
+ const section = sections[i].trim();
184
+ if (!section)
185
+ continue;
186
+ return section;
187
+ }
188
+ return '';
189
+ })();
190
+ const slots = getTags(context.class, 'slot').map((tag) => parseTag(tag));
191
+ // TODO
192
+ const styles = (() => {
193
+ if (!context.stylePath)
194
+ return [];
195
+ return fs
196
+ .readFileSync(context.stylePath, 'utf8')
197
+ .split('@prop')
198
+ .slice(1)
199
+ .map((section) => {
200
+ var _a;
201
+ let [description, name] = section.split(/\n/);
202
+ name = name.split(':').slice(0, -1).join(':').trim();
203
+ description = description.trim();
204
+ let [initializer] = ((_a = context.styleParsed) === null || _a === void 0 ? void 0 : _a.split(name).slice(1, 2)) || [];
205
+ if (initializer)
206
+ initializer = initializer.split(/;|}/)[0].replace(':', '').trim();
207
+ return {
208
+ description,
209
+ initializer,
210
+ name
211
+ };
212
+ });
213
+ })();
214
+ const tag = context.componentTag;
215
+ const tags = getTags(context.class);
216
+ const title = capitalCase(context.componentKey);
217
+ global.document.components.push({
218
+ // TODO
219
+ // main
220
+ // development
221
+ // source
222
+ events,
223
+ group,
224
+ isDeprecated,
225
+ isExperimental,
226
+ key: context.componentKey,
227
+ lastModified,
228
+ methods,
229
+ parts,
230
+ properties,
231
+ readme,
232
+ readmeDescription,
233
+ slots,
234
+ styles,
235
+ tag,
236
+ tags,
237
+ title
238
+ });
239
+ };
240
+ const finish = (global) => {
241
+ const dirname = path.dirname(options.destination);
242
+ global.document.components = global.document.components.sort((a, b) => (a.title > b.title ? 1 : -1));
243
+ if (!fs.existsSync(dirname))
244
+ fs.mkdirSync(dirname, { recursive: true });
245
+ JSON.stringify(global.document, null, 2);
246
+ fs.writeFileSync(options.destination, JSON.stringify(global.document, null, 2), 'utf8');
247
+ };
248
+ return {
249
+ name,
250
+ start,
251
+ next,
252
+ finish
253
+ };
254
+ };
@@ -0,0 +1,9 @@
1
+ import { Context } from '../../types/index.js';
2
+ export declare type ExternalOptions = {
3
+ source?: (context: Context) => string;
4
+ destination: (context: Context) => string;
5
+ };
6
+ export declare const external: (options: ExternalOptions) => {
7
+ name: string;
8
+ next: (context: Context) => void;
9
+ };
@@ -0,0 +1,25 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ const defaults = {
4
+ source(context) {
5
+ return path.join(context.directoryPath, 'external');
6
+ },
7
+ destination(context) {
8
+ return '';
9
+ }
10
+ };
11
+ export const external = (options) => {
12
+ const name = 'external';
13
+ options = Object.assign(Object.assign({}, defaults), options);
14
+ const next = (context) => {
15
+ var _a;
16
+ const source = (_a = options.source) === null || _a === void 0 ? void 0 : _a.call(options, context);
17
+ if (!source || !fs.existsSync(source))
18
+ return;
19
+ fs.copySync(source, options.destination(context));
20
+ };
21
+ return {
22
+ name,
23
+ next
24
+ };
25
+ };
@@ -0,0 +1,8 @@
1
+ import { Context } from '../../types/index.js';
2
+ export interface ExtractOptions {
3
+ prefix?: string;
4
+ }
5
+ export declare const extract: (options?: ExtractOptions | undefined) => {
6
+ name: string;
7
+ next: (context: Context) => void;
8
+ };
@@ -0,0 +1,62 @@
1
+ import * as t from '@babel/types';
2
+ import { pascalCase, paramCase } from 'change-case';
3
+ import path from 'path';
4
+ import * as CONSTANTS from '../../constants/index.js';
5
+ import { hasDecorator, visitor } from '../utils/index.js';
6
+ export const extract = (options) => {
7
+ const name = 'extract';
8
+ const next = (context) => {
9
+ var _a, _b;
10
+ visitor(context.fileAST, {
11
+ ClassDeclaration: {
12
+ exit(path) {
13
+ var _a, _b;
14
+ context.class = path.node;
15
+ context.classMembers = ((_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.body) || [];
16
+ path.skip();
17
+ }
18
+ },
19
+ Decorator(path) {
20
+ var _a;
21
+ const name = (_a = path.node.expression.callee) === null || _a === void 0 ? void 0 : _a.name;
22
+ // TODO
23
+ if (CONSTANTS.DECORATOR_ELEMENT == name) {
24
+ const [argument] = path.node.expression.arguments;
25
+ if (argument) {
26
+ context.componentTag = argument === null || argument === void 0 ? void 0 : argument.value;
27
+ return;
28
+ }
29
+ context.componentTag = paramCase(path.parent.id.name);
30
+ if (options === null || options === void 0 ? void 0 : options.prefix)
31
+ context.componentTag = options.prefix + '-' + context.componentTag;
32
+ path.replaceWith(t.decorator(t.callExpression(t.identifier(name), [
33
+ t.stringLiteral(context.componentTag),
34
+ ...path.node.expression.arguments.slice(1)
35
+ ])));
36
+ return;
37
+ }
38
+ }
39
+ });
40
+ context.directoryPath = path.dirname(context.filePath);
41
+ context.directoryName = path.basename(context.directoryPath);
42
+ context.fileExtension = path.extname(context.filePath);
43
+ context.fileName = path.basename(context.filePath, context.fileExtension);
44
+ context.className = (_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.name;
45
+ // TODO
46
+ context.componentClassName = pascalCase(context.componentTag);
47
+ context.componentClassNamePrune = pascalCase(context.componentTag.split('-').slice(1).join('-'));
48
+ context.componentInterfaceName = `HTML${context.componentClassName}Element`;
49
+ context.componentKey = paramCase(context.componentClassNamePrune);
50
+ context.classEvents = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_EVENT));
51
+ context.classMethods = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_METHOD));
52
+ context.classProperties = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_PROPERTY));
53
+ context.classStates = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_STATE));
54
+ context.classHasMount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.LIFECYCLE_CONNECTED);
55
+ context.classHasUnmount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.LIFECYCLE_DISCONNECTED);
56
+ context.classRender = (context.classMembers || []).find((member) => member['key'].name == CONSTANTS.METHOD_RENDER);
57
+ };
58
+ return {
59
+ name,
60
+ next
61
+ };
62
+ };
@@ -0,0 +1,9 @@
1
+ export * from './customElementReact/index.js';
2
+ export * from './customElement.js';
3
+ export * from './document.js';
4
+ export * from './external.js';
5
+ export * from './extract.js';
6
+ export * from './parse.js';
7
+ export * from './read.js';
8
+ export * from './style.js';
9
+ export * from './validate.js';
@@ -0,0 +1,9 @@
1
+ export * from './customElementReact/index.js';
2
+ export * from './customElement.js';
3
+ export * from './document.js';
4
+ export * from './external.js';
5
+ export * from './extract.js';
6
+ export * from './parse.js';
7
+ export * from './read.js';
8
+ export * from './style.js';
9
+ export * from './validate.js';