@htmlplus/element 0.3.1 → 0.3.2

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 (161) hide show
  1. package/client/decorators/attributes.d.ts +2 -0
  2. package/client/decorators/attributes.js +13 -0
  3. package/client/decorators/bind.d.ts +4 -0
  4. package/client/decorators/bind.js +17 -0
  5. package/client/decorators/element.d.ts +2 -0
  6. package/client/decorators/element.js +49 -0
  7. package/client/decorators/event.d.ts +21 -0
  8. package/client/decorators/event.js +18 -0
  9. package/client/decorators/index.d.ts +9 -0
  10. package/client/decorators/index.js +9 -0
  11. package/client/decorators/listen.d.ts +12 -0
  12. package/client/decorators/listen.js +30 -0
  13. package/client/decorators/method.d.ts +2 -0
  14. package/client/decorators/method.js +12 -0
  15. package/client/decorators/property.d.ts +12 -0
  16. package/client/decorators/property.js +51 -0
  17. package/client/decorators/state.d.ts +2 -0
  18. package/client/decorators/state.js +32 -0
  19. package/client/decorators/watch.d.ts +2 -0
  20. package/client/decorators/watch.js +17 -0
  21. package/client/helpers/classes.d.ts +1 -0
  22. package/client/helpers/classes.js +62 -0
  23. package/client/helpers/direction.d.ts +3 -0
  24. package/client/helpers/direction.js +4 -0
  25. package/client/helpers/index.d.ts +9 -0
  26. package/client/helpers/index.js +9 -0
  27. package/client/helpers/is-rtl.d.ts +2 -0
  28. package/client/helpers/is-rtl.js +2 -0
  29. package/client/helpers/query-all.d.ts +3 -0
  30. package/client/helpers/query-all.js +5 -0
  31. package/client/helpers/query.d.ts +3 -0
  32. package/client/helpers/query.js +5 -0
  33. package/client/helpers/slots.d.ts +6 -0
  34. package/client/helpers/slots.js +15 -0
  35. package/client/helpers/styles.d.ts +1 -0
  36. package/client/helpers/styles.js +16 -0
  37. package/client/helpers/to-unit.d.ts +1 -0
  38. package/client/helpers/to-unit.js +7 -0
  39. package/client/index.d.ts +3 -0
  40. package/client/index.js +3 -0
  41. package/client/services/index.d.ts +1 -0
  42. package/client/services/index.js +1 -0
  43. package/client/services/link.d.ts +4 -0
  44. package/client/services/link.js +196 -0
  45. package/client/utils/append-to-method.d.ts +2 -0
  46. package/client/utils/append-to-method.js +7 -0
  47. package/client/utils/call.d.ts +2 -0
  48. package/client/utils/call.js +4 -0
  49. package/client/utils/define-property.d.ts +1 -0
  50. package/client/utils/define-property.js +1 -0
  51. package/client/utils/event.d.ts +2 -0
  52. package/client/utils/event.js +6 -0
  53. package/client/utils/get-members.d.ts +2 -0
  54. package/client/utils/get-members.js +5 -0
  55. package/client/utils/get-styles.d.ts +2 -0
  56. package/client/utils/get-styles.js +5 -0
  57. package/client/utils/host.d.ts +2 -0
  58. package/client/utils/host.js +4 -0
  59. package/client/utils/index.d.ts +20 -0
  60. package/client/utils/index.js +20 -0
  61. package/client/utils/is-event.d.ts +1 -0
  62. package/client/utils/is-event.js +3 -0
  63. package/client/utils/is-ready.d.ts +2 -0
  64. package/client/utils/is-ready.js +4 -0
  65. package/client/utils/is-server.d.ts +1 -0
  66. package/client/utils/is-server.js +3 -0
  67. package/client/utils/on-ready.d.ts +2 -0
  68. package/client/utils/on-ready.js +6 -0
  69. package/client/utils/parse-value.d.ts +1 -0
  70. package/client/utils/parse-value.js +15 -0
  71. package/client/utils/render.d.ts +2 -0
  72. package/client/utils/render.js +19 -0
  73. package/client/utils/request.d.ts +2 -0
  74. package/client/utils/request.js +28 -0
  75. package/client/utils/sync.d.ts +1 -0
  76. package/client/utils/sync.js +31 -0
  77. package/client/utils/task.d.ts +6 -0
  78. package/client/utils/task.js +37 -0
  79. package/client/utils/to-boolean.d.ts +1 -0
  80. package/client/utils/to-boolean.js +3 -0
  81. package/client/utils/to-event.d.ts +1 -0
  82. package/client/utils/to-event.js +3 -0
  83. package/client/utils/type-of.d.ts +3 -0
  84. package/client/utils/type-of.js +6 -0
  85. package/client/utils/update-attribute.d.ts +1 -0
  86. package/client/utils/update-attribute.js +7 -0
  87. package/compiler/compiler.d.ts +7 -0
  88. package/compiler/compiler.js +55 -0
  89. package/compiler/index.d.ts +2 -0
  90. package/compiler/index.js +2 -0
  91. package/compiler/plugins/componentDependencyResolver.d.ts +5 -0
  92. package/compiler/plugins/componentDependencyResolver.js +40 -0
  93. package/compiler/plugins/customElement.d.ts +5 -0
  94. package/compiler/plugins/customElement.js +138 -0
  95. package/compiler/plugins/customElementReact/customElementReact.d.ts +12 -0
  96. package/compiler/plugins/customElementReact/customElementReact.js +125 -0
  97. package/compiler/plugins/customElementReact/index.d.ts +1 -0
  98. package/compiler/plugins/customElementReact/index.js +1 -0
  99. package/compiler/plugins/customElementReact/templates/README.md.hbs +1 -0
  100. package/compiler/plugins/customElementReact/templates/_.gitignore.hbs +2 -0
  101. package/compiler/plugins/customElementReact/templates/package.json.hbs +37 -0
  102. package/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +21 -0
  103. package/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +17 -0
  104. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +18 -0
  105. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +26 -0
  106. package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +1 -0
  107. package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +278 -0
  108. package/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +17 -0
  109. package/compiler/plugins/docs.d.ts +11 -0
  110. package/compiler/plugins/docs.js +320 -0
  111. package/compiler/plugins/extract.d.ts +8 -0
  112. package/compiler/plugins/extract.js +70 -0
  113. package/compiler/plugins/index.d.ts +7 -0
  114. package/compiler/plugins/index.js +7 -0
  115. package/compiler/plugins/parse.d.ts +5 -0
  116. package/compiler/plugins/parse.js +16 -0
  117. package/compiler/plugins/read.d.ts +5 -0
  118. package/compiler/plugins/read.js +13 -0
  119. package/compiler/plugins/style.d.ts +10 -0
  120. package/compiler/plugins/style.js +36 -0
  121. package/compiler/plugins/validate.d.ts +5 -0
  122. package/compiler/plugins/validate.js +40 -0
  123. package/compiler/plugins/vscode.d.ts +11 -0
  124. package/compiler/plugins/vscode.js +83 -0
  125. package/compiler/utils/__dirname.d.ts +1 -0
  126. package/compiler/utils/__dirname.js +5 -0
  127. package/compiler/utils/get-initializer.d.ts +2 -0
  128. package/compiler/utils/get-initializer.js +10 -0
  129. package/compiler/utils/get-tags.d.ts +6 -0
  130. package/compiler/utils/get-tags.js +34 -0
  131. package/compiler/utils/get-type.d.ts +2 -0
  132. package/compiler/utils/get-type.js +69 -0
  133. package/compiler/utils/has-decorator.d.ts +1 -0
  134. package/compiler/utils/has-decorator.js +5 -0
  135. package/compiler/utils/index.d.ts +10 -0
  136. package/compiler/utils/index.js +10 -0
  137. package/compiler/utils/is-directory-empty.d.ts +1 -0
  138. package/compiler/utils/is-directory-empty.js +10 -0
  139. package/compiler/utils/print-type.d.ts +1 -0
  140. package/compiler/utils/print-type.js +69 -0
  141. package/compiler/utils/print.d.ts +2 -0
  142. package/compiler/utils/print.js +5 -0
  143. package/compiler/utils/render-template.d.ts +1 -0
  144. package/compiler/utils/render-template.js +25 -0
  145. package/compiler/utils/visitor.d.ts +2 -0
  146. package/compiler/utils/visitor.js +5 -0
  147. package/constants/index.d.ts +23 -0
  148. package/constants/index.js +29 -0
  149. package/package.json +1 -1
  150. package/runtime/index.d.ts +1 -0
  151. package/runtime/index.js +4 -0
  152. package/types/context.d.ts +32 -0
  153. package/types/context.js +1 -0
  154. package/types/global.d.ts +4 -0
  155. package/types/global.js +1 -0
  156. package/types/index.d.ts +4 -0
  157. package/types/index.js +4 -0
  158. package/types/plugin.d.ts +9 -0
  159. package/types/plugin.js +1 -0
  160. package/types/plus-element.d.ts +2 -0
  161. package/types/plus-element.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,11 @@
1
+ import { Context } from '../../types/index.js';
2
+ export interface DocsOptions {
3
+ dist: string;
4
+ prefix: string;
5
+ }
6
+ export declare const docs: (options: DocsOptions) => {
7
+ name: string;
8
+ start: (global: any) => void;
9
+ next: (context: Context, global: any) => void;
10
+ finish: (global: any) => void;
11
+ };
@@ -0,0 +1,320 @@
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, getTags, getType, printType } from '../utils/index.js';
6
+ export const docs = (options) => {
7
+ const name = 'docs';
8
+ const start = (global) => {
9
+ global.docs = {
10
+ prefix: options.prefix,
11
+ components: []
12
+ };
13
+ };
14
+ const next = (context, global) => {
15
+ var _a;
16
+ const tags = getTags(context.class);
17
+ const development = tags.some((tag) => tag.key == 'development');
18
+ const experimental = tags.some((tag) => tag.key == 'experimental');
19
+ const externals = fs.existsSync(path.resolve(context.directoryPath || '', 'externals'));
20
+ const examples = (() => {
21
+ const items = [];
22
+ const source = path.join(context.directoryPath || '', 'examples');
23
+ if (!fs.existsSync(source))
24
+ return items;
25
+ return fs
26
+ .readdirSync(source)
27
+ .filter((file) => file.endsWith('.md'))
28
+ .map((file) => {
29
+ const item = {};
30
+ const regex = /```\w+\s\[\w+(:\w+)?\]\s[\S\s]*?```/g;
31
+ const filePath = path.join(source, file);
32
+ const content = fs.readFileSync(filePath, 'utf8');
33
+ item.key = path.basename(filePath).replace('.md', '');
34
+ item.title = capitalCase(item.key);
35
+ item.readme = content.replace(regex, '').trim();
36
+ item.codes = (content.match(regex) || []).map((section) => {
37
+ try {
38
+ const lines = section.split('\n');
39
+ const key = ((lines[0].match(/\[\w+(:\w+)?\]/) || []).shift() || '').replace('[', '').replace(']', '');
40
+ const type = ((lines[0].match(/```\w+/) || []).pop() || '').replace('```', '');
41
+ const value = lines.slice(1, -1).join('\n');
42
+ return {
43
+ key,
44
+ type,
45
+ value
46
+ };
47
+ }
48
+ catch (_a) { }
49
+ });
50
+ return item;
51
+ });
52
+ })();
53
+ const readme = (() => {
54
+ try {
55
+ const source = path.resolve(context.directoryPath || '', `${context.fileName}.md`);
56
+ return fs.readFileSync(source, 'utf8');
57
+ }
58
+ catch (_a) { }
59
+ })();
60
+ const description = (() => {
61
+ const content = readme || '';
62
+ if (!content.startsWith('# '))
63
+ return '';
64
+ const sections = content.split('\n');
65
+ for (let i = 1; i < sections.length; i++) {
66
+ const section = sections[i].trim();
67
+ if (!section)
68
+ continue;
69
+ return section;
70
+ }
71
+ return '';
72
+ })();
73
+ const properties = (context.classProperties || []).map((property) => {
74
+ var _a;
75
+ const tags = getTags(property);
76
+ const name = property.key['name'];
77
+ const attribute = paramCase(name);
78
+ // TODO
79
+ const initializer = getInitializer(property.value);
80
+ // TODO
81
+ const reflect = (() => {
82
+ if (!property.decorators)
83
+ return false;
84
+ try {
85
+ for (const decorator of property.decorators) {
86
+ for (const argument of decorator.expression['arguments']) {
87
+ for (const property of argument.properties) {
88
+ if (property.key.name != 'reflect')
89
+ continue;
90
+ if (property.value.type != 'BooleanLiteral')
91
+ continue;
92
+ if (!property.value.value)
93
+ continue;
94
+ return true;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ catch (_a) { }
100
+ return false;
101
+ })();
102
+ const required = !property.optional;
103
+ // TODO
104
+ const { type, members } = (() => {
105
+ const ast = getType(context.fileAST, (property.typeAnnotation || {})['typeAnnotation'], {
106
+ directory: context.directoryPath
107
+ });
108
+ return printType(ast);
109
+ })();
110
+ const experimental = tags.some((tag) => tag.key == 'experimental');
111
+ const description = (_a = tags.find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
112
+ const model = tags.some((tag) => tag.key == 'model');
113
+ return {
114
+ name,
115
+ attribute,
116
+ initializer,
117
+ reflect,
118
+ required,
119
+ type,
120
+ experimental,
121
+ description,
122
+ members,
123
+ model
124
+ };
125
+ });
126
+ const parts = tags
127
+ .filter((tag) => tag.key == 'part')
128
+ .map((tag) => {
129
+ var _a;
130
+ const sections = ((_a = tag.value) === null || _a === void 0 ? void 0 : _a.split('-')) || [];
131
+ const name = sections[0].trim();
132
+ const description = sections.slice(1).join('-').trim();
133
+ return {
134
+ name,
135
+ description
136
+ };
137
+ });
138
+ const methods = (context.classMethods || []).map((method) => {
139
+ var _a;
140
+ const tags = getTags(method);
141
+ const name = method.key['name'];
142
+ const experimental = tags.some((tag) => tag.key == 'experimental');
143
+ // TODO
144
+ // const params = printType(getType(
145
+ // context.ast,
146
+ // method.params,
147
+ // {
148
+ // directory: context.directory,
149
+ // }
150
+ // ));
151
+ // console.log(111, params)
152
+ // TODO: returnType
153
+ const type = (() => {
154
+ try {
155
+ return printType(getType(context.fileAST, (method.returnType || {})['typeAnnotation'], {
156
+ directory: context.directoryPath
157
+ }));
158
+ }
159
+ catch (_a) { }
160
+ })();
161
+ // TODO
162
+ const signature = `${method.key['name']}(${''}) => ${type}`;
163
+ const description = (_a = tags.find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
164
+ // TODO
165
+ const parameters = [
166
+ // {
167
+ // "name": "offsetX",
168
+ // "description": "Moving size (px) in the `horizontal` direction. Use `null` to ignore this."
169
+ // },
170
+ // {
171
+ // "name": "offsetY",
172
+ // "description": "Moving size (px) in the `vertical` direction. Use `null` to ignore this."
173
+ // }
174
+ ];
175
+ return {
176
+ name,
177
+ experimental,
178
+ type,
179
+ signature,
180
+ description,
181
+ parameters
182
+ };
183
+ });
184
+ const slots = tags
185
+ .filter((tag) => tag.key == 'slot')
186
+ .map((tag) => {
187
+ var _a;
188
+ const sections = ((_a = tag.value) === null || _a === void 0 ? void 0 : _a.split('-')) || [];
189
+ const name = sections[0].trim();
190
+ const description = sections.slice(1).join('-').trim();
191
+ return {
192
+ name,
193
+ description
194
+ };
195
+ });
196
+ const events = (context.classEvents || []).map((event) => {
197
+ var _a;
198
+ const tags = getTags(event);
199
+ const name = event.key['name'];
200
+ const cancelable = (() => {
201
+ if (!event.decorators)
202
+ return false;
203
+ try {
204
+ for (const decorator of event.decorators) {
205
+ for (const argument of decorator.expression['arguments']) {
206
+ for (const property of argument.properties) {
207
+ if (property.key.name != 'cancelable')
208
+ continue;
209
+ if (property.value.type != 'BooleanLiteral')
210
+ continue;
211
+ if (!property.value.value)
212
+ continue;
213
+ return true;
214
+ }
215
+ }
216
+ }
217
+ }
218
+ catch (_a) { }
219
+ return false;
220
+ })();
221
+ // TODO
222
+ const detail = (() => {
223
+ try {
224
+ return printType(getType(context.fileAST, (event.typeAnnotation || {})['typeAnnotation'].typeParameters.params[0], {
225
+ directory: context.directoryPath
226
+ }));
227
+ }
228
+ catch (_a) { }
229
+ })();
230
+ const experimental = tags.some((tag) => tag.key == 'experimental');
231
+ const description = (_a = tags.find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
232
+ const model = tags.some((tag) => tag.key == 'model');
233
+ return {
234
+ name,
235
+ cancelable,
236
+ detail,
237
+ experimental,
238
+ description,
239
+ model
240
+ };
241
+ });
242
+ const styles = (() => {
243
+ const styles = [];
244
+ try {
245
+ fs.readFileSync(context.stylePath || '', 'utf8')
246
+ .split('@prop')
247
+ .slice(1)
248
+ .map((section) => {
249
+ var _a;
250
+ let [description, name] = section.split(/\n/);
251
+ name = name.split(':').slice(0, -1).join(':').trim();
252
+ description = description.trim();
253
+ let [initializer] = ((_a = context.styleParsed) === null || _a === void 0 ? void 0 : _a.split(name).slice(1, 2)) || [];
254
+ if (initializer)
255
+ initializer = initializer.split(/;|}/)[0].replace(':', '').trim();
256
+ styles.push({
257
+ name,
258
+ initializer,
259
+ description
260
+ });
261
+ });
262
+ }
263
+ catch (_a) { }
264
+ return styles;
265
+ })();
266
+ // TODO
267
+ const lastModified = 0;
268
+ // glob
269
+ // .sync(path.join(context.directory, '**/*.*'))
270
+ // .reduce((result, file) => {
271
+ // const state = fs.statSync(file);
272
+ // return result > state.mtime ? result : state.mtime
273
+ // }, 0);
274
+ const group = ((_a = tags.find((tag) => tag.key == 'group')) === null || _a === void 0 ? void 0 : _a.value) || null;
275
+ const main = (group && context.componentKey == group) || !group;
276
+ // TODO
277
+ // context.types = (() => {
278
+ // return [];
279
+ // })();
280
+ global.docs.components.push({
281
+ key: context.componentKey,
282
+ tag: context.componentTag,
283
+ title: capitalCase(context.componentKey || ''),
284
+ main,
285
+ group,
286
+ development,
287
+ experimental,
288
+ // TODO
289
+ deprecated: false,
290
+ externals,
291
+ lastModified,
292
+ // TODO
293
+ tags: [],
294
+ // TODO
295
+ source: context.componentKey,
296
+ description,
297
+ readme,
298
+ properties,
299
+ slots,
300
+ events,
301
+ styles,
302
+ parts,
303
+ methods,
304
+ examples
305
+ });
306
+ };
307
+ const finish = (global) => {
308
+ global.docs.components = global.docs.components.sort((a, b) => (a.key > b.key ? 1 : -1));
309
+ // TODO
310
+ // fs.ensureDirSync(path.dirname(options.dist));
311
+ // TODO
312
+ // fs.writeJSONSync(options.dist, global.docs, { replacer: null, spaces: 2 });
313
+ };
314
+ return {
315
+ name,
316
+ start,
317
+ next,
318
+ finish
319
+ };
320
+ };
@@ -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
+ };