@htmlplus/element 2.13.0 → 2.13.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.
package/bundlers.d.ts CHANGED
@@ -13,7 +13,6 @@ declare const vite: (...plugins: Array<TransformerPlugin>) => {
13
13
  name: string;
14
14
  buildStart(): Promise<void>;
15
15
  load(id: any): Promise<string | undefined>;
16
- buildEnd(): Promise<void>;
17
16
  writeBundle(options: any, bundles: any): Promise<void>;
18
17
  };
19
18
 
package/bundlers.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { KEY } from './constants.js';
1
2
  import { transformer } from './transformer.js';
2
3
  import 'fs-extra';
3
4
  import '@babel/template';
@@ -9,12 +10,11 @@ import 'glob';
9
10
  import '@babel/generator';
10
11
  import path from 'node:path';
11
12
  import 'ora';
12
- import './constants.js';
13
13
 
14
14
  const rollup = (...plugins) => {
15
15
  const { start, run, finish } = transformer(...plugins);
16
16
  return {
17
- name: 'htmlplus',
17
+ name: KEY,
18
18
  async buildStart() {
19
19
  await start();
20
20
  },
@@ -35,52 +35,39 @@ const rollup = (...plugins) => {
35
35
  };
36
36
 
37
37
  const vite = (...plugins) => {
38
- const { global, start, run, finish, write } = transformer(...plugins);
38
+ const { global, start, run, finish } = transformer(...plugins);
39
39
  return {
40
- name: 'htmlplus',
40
+ name: KEY,
41
41
  async buildStart() {
42
42
  await start();
43
43
  },
44
44
  async load(id) {
45
45
  if (!id.endsWith('.tsx'))
46
46
  return;
47
- let { script, skipped, stylePath } = await run(id);
48
- if (skipped)
47
+ const context = await run(id);
48
+ if (context.skipped)
49
49
  return;
50
- if (script && stylePath) {
51
- script = script.replace(path.basename(stylePath), `${path.basename(stylePath)}?inline`);
50
+ if (context.script && context.stylePath) {
51
+ context.script = context.script.replace(path.basename(context.stylePath), `$&?inline`);
52
52
  }
53
- return script;
54
- },
55
- async buildEnd() {
56
- await finish();
53
+ return context.script;
57
54
  },
58
55
  async writeBundle(options, bundles) {
59
56
  // TODO
60
- try {
61
- for (const context of global.contexts) {
62
- for (const key in bundles) {
63
- if (!Object.hasOwnProperty.call(bundles, key))
64
- continue;
65
- const bundle = bundles[key];
66
- if (!bundle.facadeModuleId.startsWith(context.filePath))
67
- continue;
68
- const modules = bundle['modules'];
69
- for (const key in modules) {
70
- if (!Object.hasOwnProperty.call(modules, key))
71
- continue;
72
- const module = modules[key];
73
- if (!key.startsWith(context.stylePath || ''))
74
- continue;
75
- context.styleContentTransformed = module.code;
76
- break;
77
- }
78
- break;
79
- }
80
- }
81
- }
82
- catch { }
83
- await write();
57
+ global.contexts.forEach((context) => {
58
+ Object.keys(bundles).forEach((key) => {
59
+ const { facadeModuleId, modules } = bundles[key];
60
+ if (!facadeModuleId?.startsWith(context.filePath))
61
+ return;
62
+ const id = Object.keys(modules).find((key) => {
63
+ return key.startsWith(context.stylePath || '');
64
+ });
65
+ if (!id)
66
+ return;
67
+ context.styleContentTransformed = modules[id].code;
68
+ });
69
+ });
70
+ await finish();
84
71
  }
85
72
  };
86
73
  };
@@ -1,5 +1,5 @@
1
1
  import { kebabCase, camelCase, pascalCase } from 'change-case';
2
- import { API_HOST, STATIC_STYLE, STATIC_TAG, API_STACKS, API_REQUEST, API_CONNECTED, LIFECYCLE_UPDATE, API_STYLE, LIFECYCLE_UPDATED, API_RENDER_COMPLETED, METHOD_RENDER, TYPE_BOOLEAN, TYPE_NUMBER, TYPE_NULL, TYPE_DATE, TYPE_ARRAY, TYPE_OBJECT, TYPE_UNDEFINED, LIFECYCLE_CONNECTED, LIFECYCLE_DISCONNECTED, API_INSTANCE, MAPPER, LIFECYCLE_CONSTRUCTED, LIFECYCLE_ADOPTED, LIFECYCLE_LOADED } from './constants.js';
2
+ import { API_HOST, STATIC_TAG, API_STACKS, API_REQUEST, API_CONNECTED, LIFECYCLE_UPDATE, STATIC_STYLE, API_STYLE, LIFECYCLE_UPDATED, API_RENDER_COMPLETED, METHOD_RENDER, TYPE_BOOLEAN, TYPE_NUMBER, TYPE_NULL, TYPE_DATE, TYPE_ARRAY, TYPE_OBJECT, TYPE_UNDEFINED, LIFECYCLE_CONNECTED, LIFECYCLE_DISCONNECTED, KEY, API_INSTANCE, MAPPER, LIFECYCLE_CONSTRUCTED, LIFECYCLE_ADOPTED, LIFECYCLE_LOADED } from './constants.js';
3
3
 
4
4
  const appendToMethod = (target, key, handler) => {
5
5
  // Gets the previous function
@@ -264,10 +264,6 @@ const getFramework = (target) => {
264
264
  return 'angular';
265
265
  };
266
266
 
267
- const getStyles = (target) => {
268
- return target.constructor[STATIC_STYLE] ?? target[STATIC_STYLE];
269
- };
270
-
271
267
  const getTag = (target) => {
272
268
  return target.constructor[STATIC_TAG] ?? target[STATIC_TAG];
273
269
  };
@@ -1125,12 +1121,13 @@ const request = (target, name, previous, callback) => {
1125
1121
  });
1126
1122
  // TODO
1127
1123
  (() => {
1128
- const raw = getStyles(target);
1124
+ const raw = target.constructor[STATIC_STYLE];
1129
1125
  if (!raw)
1130
1126
  return;
1131
1127
  const regex1 = /this-([\w-]+)(?:-([\w-]+))?/g;
1132
1128
  const regex2 = /(\s*\w+\s*:\s*(undefined|null)\s*;?)/g;
1133
- const hasGlobal = raw.includes(':global');
1129
+ const regex3 = /global\s+[^{]+\{[^{}]*\{[^{}]*\}[^{}]*\}|global\s+[^{]+\{[^{}]*\}/g;
1130
+ const hasGlobal = raw.includes('global');
1134
1131
  const hasVariable = raw.includes('this-');
1135
1132
  let localSheet = target[API_STYLE];
1136
1133
  let globalSheet = target.constructor[API_STYLE];
@@ -1150,8 +1147,8 @@ const request = (target, name, previous, callback) => {
1150
1147
  target[API_STYLE] = localSheet;
1151
1148
  shadowRoot(target).adoptedStyleSheets.push(localSheet);
1152
1149
  }
1153
- const localStyle = parsed;
1154
- localSheet.replace(localStyle);
1150
+ const localStyle = parsed.replace(regex3, '');
1151
+ localSheet.replaceSync(localStyle);
1155
1152
  if (!hasGlobal || globalSheet)
1156
1153
  return;
1157
1154
  if (!globalSheet) {
@@ -1160,21 +1157,11 @@ const request = (target, name, previous, callback) => {
1160
1157
  document.adoptedStyleSheets.push(globalSheet);
1161
1158
  }
1162
1159
  const globalStyle = parsed
1163
- .split('}')
1164
- .map((rule) => {
1165
- let [selectors, properties] = rule.split('{');
1166
- selectors = selectors
1167
- .split(',')
1168
- .map((selector) => selector.trim())
1169
- .filter((selector) => selector.startsWith(':global'))
1170
- .map((selector) => selector.replace(':global', ''))
1171
- .map((selector) => selector.trim())
1172
- .join(',');
1173
- return selectors ? `${selectors}{${properties}}` : '';
1174
- })
1175
- .filter((selector) => !!selector)
1176
- .join('');
1177
- globalSheet.replace(globalStyle);
1160
+ ?.match(regex3)
1161
+ ?.join('')
1162
+ ?.replaceAll('global', '')
1163
+ ?.replaceAll(':host', getTag(target));
1164
+ globalSheet.replaceSync(globalStyle);
1178
1165
  })();
1179
1166
  // Calls the lifecycle's callback after the rendering phase.
1180
1167
  call(target, LIFECYCLE_UPDATED, states);
@@ -1317,7 +1304,7 @@ function Provider(namespace) {
1317
1304
  return function (target, key, descriptor) {
1318
1305
  const symbol = Symbol();
1319
1306
  const [MAIN, SUB] = namespace.split('.');
1320
- const prefix = `htmlplus:${MAIN}`;
1307
+ const prefix = `${KEY}:${MAIN}`;
1321
1308
  const cleanups = (instance) => {
1322
1309
  return (instance[symbol] ||= new Map());
1323
1310
  };
@@ -1369,7 +1356,7 @@ function Consumer(namespace) {
1369
1356
  return function (target, key) {
1370
1357
  const symbol = Symbol();
1371
1358
  const [MAIN, SUB] = namespace.split('.');
1372
- const prefix = `htmlplus:${MAIN}`;
1359
+ const prefix = `${KEY}:${MAIN}`;
1373
1360
  const cleanups = (instance) => {
1374
1361
  return (instance[symbol] ||= new Map());
1375
1362
  };
package/client.js CHANGED
@@ -1,3 +1,3 @@
1
- export { B as Bind, C as Consumer, D as Direction, E as Element, k as Event, H as Host, I as IsRTL, L as Listen, M as Method, l as Property, P as Provider, Q as Query, m as QueryAll, S as Slots, n as State, W as Watch, c as classes, d as direction, a as dispatch, g as getConfig, h as host, i as isCSSColor, b as isRTL, f as off, o as on, q as query, e as queryAll, j as setConfig, s as slots, t as toUnit } from './client-Dse96R-O.js';
1
+ export { B as Bind, C as Consumer, D as Direction, E as Element, k as Event, H as Host, I as IsRTL, L as Listen, M as Method, l as Property, P as Provider, Q as Query, m as QueryAll, S as Slots, n as State, W as Watch, c as classes, d as direction, a as dispatch, g as getConfig, h as host, i as isCSSColor, b as isRTL, f as off, o as on, q as query, e as queryAll, j as setConfig, s as slots, t as toUnit } from './client-B7RqkVf0.js';
2
2
  import 'change-case';
3
3
  import './constants.js';
package/constants.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ declare const KEY = "htmlplus";
1
2
  declare const PACKAGE_NAME = "@htmlplus/element";
2
3
  declare const MAPPER: unique symbol;
3
4
  declare const API_CONNECTED: unique symbol;
@@ -28,6 +29,7 @@ declare const STATIC_STYLE = "style";
28
29
  declare const STATIC_TAG = "tag";
29
30
  declare const STYLE_IMPORTED = "STYLE_IMPORTED";
30
31
  declare const TYPE_ARRAY: number;
32
+ declare const TYPE_BIGINT: number;
31
33
  declare const TYPE_BOOLEAN: number;
32
34
  declare const TYPE_DATE: number;
33
35
  declare const TYPE_ENUM: number;
@@ -45,4 +47,4 @@ declare const UTILS_STYLES_IMPORTED = "styles";
45
47
  declare const UTILS_STYLES_LOCAL = "UTILS_STYLES";
46
48
  declare const UTILS_PATH = "@htmlplus/element/internal.js";
47
49
 
48
- export { API_CONNECTED, API_HOST, API_INSTANCE, API_RENDER_COMPLETED, API_REQUEST, API_STACKS, API_STYLE, COMMENT_AUTO_ADDED, DECORATOR_CSS_VARIABLE, DECORATOR_ELEMENT, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_PROPERTY, DECORATOR_PROPERTY_TYPE, DECORATOR_STATE, ELEMENT_HOST_NAME, LIFECYCLE_ADOPTED, LIFECYCLE_CONNECTED, LIFECYCLE_CONSTRUCTED, LIFECYCLE_DISCONNECTED, LIFECYCLE_LOADED, LIFECYCLE_UPDATE, LIFECYCLE_UPDATED, MAPPER, METHOD_RENDER, PACKAGE_NAME, STATIC_STYLE, STATIC_TAG, STYLE_IMPORTED, TYPE_ARRAY, TYPE_BOOLEAN, TYPE_DATE, TYPE_ENUM, TYPE_FUNCTION, TYPE_NULL, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING, TYPE_UNDEFINED, UTILS_ATTRIBUTES_IMPORTED, UTILS_ATTRIBUTES_LOCAL, UTILS_HTML_IMPORTED, UTILS_HTML_LOCAL, UTILS_PATH, UTILS_STYLES_IMPORTED, UTILS_STYLES_LOCAL };
50
+ export { API_CONNECTED, API_HOST, API_INSTANCE, API_RENDER_COMPLETED, API_REQUEST, API_STACKS, API_STYLE, COMMENT_AUTO_ADDED, DECORATOR_CSS_VARIABLE, DECORATOR_ELEMENT, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_PROPERTY, DECORATOR_PROPERTY_TYPE, DECORATOR_STATE, ELEMENT_HOST_NAME, KEY, LIFECYCLE_ADOPTED, LIFECYCLE_CONNECTED, LIFECYCLE_CONSTRUCTED, LIFECYCLE_DISCONNECTED, LIFECYCLE_LOADED, LIFECYCLE_UPDATE, LIFECYCLE_UPDATED, MAPPER, METHOD_RENDER, PACKAGE_NAME, STATIC_STYLE, STATIC_TAG, STYLE_IMPORTED, TYPE_ARRAY, TYPE_BIGINT, TYPE_BOOLEAN, TYPE_DATE, TYPE_ENUM, TYPE_FUNCTION, TYPE_NULL, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING, TYPE_UNDEFINED, UTILS_ATTRIBUTES_IMPORTED, UTILS_ATTRIBUTES_LOCAL, UTILS_HTML_IMPORTED, UTILS_HTML_LOCAL, UTILS_PATH, UTILS_STYLES_IMPORTED, UTILS_STYLES_LOCAL };
package/constants.js CHANGED
@@ -1,3 +1,4 @@
1
+ const KEY = 'htmlplus';
1
2
  const PACKAGE_NAME = '@htmlplus/element';
2
3
  // TODO
3
4
  const MAPPER = Symbol();
@@ -39,15 +40,16 @@ const STATIC_TAG = 'tag';
39
40
  const STYLE_IMPORTED = 'STYLE_IMPORTED';
40
41
  // types
41
42
  const TYPE_ARRAY = 2 ** 0;
42
- const TYPE_BOOLEAN = 2 ** 1;
43
- const TYPE_DATE = 2 ** 2;
44
- const TYPE_ENUM = 2 ** 3;
45
- const TYPE_FUNCTION = 2 ** 4;
46
- const TYPE_NULL = 2 ** 5;
47
- const TYPE_NUMBER = 2 ** 6;
48
- const TYPE_OBJECT = 2 ** 7;
49
- const TYPE_STRING = 2 ** 8;
50
- const TYPE_UNDEFINED = 2 ** 9;
43
+ const TYPE_BIGINT = 2 ** 1;
44
+ const TYPE_BOOLEAN = 2 ** 2;
45
+ const TYPE_DATE = 2 ** 3;
46
+ const TYPE_ENUM = 2 ** 4;
47
+ const TYPE_FUNCTION = 2 ** 5;
48
+ const TYPE_NULL = 2 ** 6;
49
+ const TYPE_NUMBER = 2 ** 7;
50
+ const TYPE_OBJECT = 2 ** 8;
51
+ const TYPE_STRING = 2 ** 9;
52
+ const TYPE_UNDEFINED = 2 ** 10;
51
53
  // utils
52
54
  const UTILS_ATTRIBUTES_IMPORTED = 'attributes';
53
55
  const UTILS_ATTRIBUTES_LOCAL = 'UTILS_ATTRIBUTES';
@@ -57,4 +59,4 @@ const UTILS_STYLES_IMPORTED = 'styles';
57
59
  const UTILS_STYLES_LOCAL = 'UTILS_STYLES';
58
60
  const UTILS_PATH = '@htmlplus/element/internal.js';
59
61
 
60
- export { API_CONNECTED, API_HOST, API_INSTANCE, API_RENDER_COMPLETED, API_REQUEST, API_STACKS, API_STYLE, COMMENT_AUTO_ADDED, DECORATOR_CSS_VARIABLE, DECORATOR_ELEMENT, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_PROPERTY, DECORATOR_PROPERTY_TYPE, DECORATOR_STATE, ELEMENT_HOST_NAME, LIFECYCLE_ADOPTED, LIFECYCLE_CONNECTED, LIFECYCLE_CONSTRUCTED, LIFECYCLE_DISCONNECTED, LIFECYCLE_LOADED, LIFECYCLE_UPDATE, LIFECYCLE_UPDATED, MAPPER, METHOD_RENDER, PACKAGE_NAME, STATIC_STYLE, STATIC_TAG, STYLE_IMPORTED, TYPE_ARRAY, TYPE_BOOLEAN, TYPE_DATE, TYPE_ENUM, TYPE_FUNCTION, TYPE_NULL, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING, TYPE_UNDEFINED, UTILS_ATTRIBUTES_IMPORTED, UTILS_ATTRIBUTES_LOCAL, UTILS_HTML_IMPORTED, UTILS_HTML_LOCAL, UTILS_PATH, UTILS_STYLES_IMPORTED, UTILS_STYLES_LOCAL };
62
+ export { API_CONNECTED, API_HOST, API_INSTANCE, API_RENDER_COMPLETED, API_REQUEST, API_STACKS, API_STYLE, COMMENT_AUTO_ADDED, DECORATOR_CSS_VARIABLE, DECORATOR_ELEMENT, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_PROPERTY, DECORATOR_PROPERTY_TYPE, DECORATOR_STATE, ELEMENT_HOST_NAME, KEY, LIFECYCLE_ADOPTED, LIFECYCLE_CONNECTED, LIFECYCLE_CONSTRUCTED, LIFECYCLE_DISCONNECTED, LIFECYCLE_LOADED, LIFECYCLE_UPDATE, LIFECYCLE_UPDATED, MAPPER, METHOD_RENDER, PACKAGE_NAME, STATIC_STYLE, STATIC_TAG, STYLE_IMPORTED, TYPE_ARRAY, TYPE_BIGINT, TYPE_BOOLEAN, TYPE_DATE, TYPE_ENUM, TYPE_FUNCTION, TYPE_NULL, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING, TYPE_UNDEFINED, UTILS_ATTRIBUTES_IMPORTED, UTILS_ATTRIBUTES_LOCAL, UTILS_HTML_IMPORTED, UTILS_HTML_LOCAL, UTILS_PATH, UTILS_STYLES_IMPORTED, UTILS_STYLES_LOCAL };
package/internal.js CHANGED
@@ -1,3 +1,3 @@
1
- export { p as attributes, r as html, u as styles } from './client-Dse96R-O.js';
1
+ export { p as attributes, r as html, u as styles } from './client-B7RqkVf0.js';
2
2
  import 'change-case';
3
3
  import './constants.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "2.13.0",
3
+ "version": "2.13.2",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
@@ -58,6 +58,7 @@
58
58
  "prettier": "^3.3.3",
59
59
  "rimraf": "^6.0.1",
60
60
  "rollup": "^4.20.0",
61
+ "rollup-plugin-copy": "^3.5.0",
61
62
  "rollup-plugin-dts": "^6.1.1",
62
63
  "rollup-plugin-node-externals": "^7.1.2",
63
64
  "semantic-release": "^24.0.0",
package/transformer.d.ts CHANGED
@@ -49,7 +49,6 @@ interface TransformerPlugin {
49
49
  start?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
50
50
  run?: (context: TransformerPluginContext, global: TransformerPluginGlobal) => Return<TransformerPluginContext>;
51
51
  finish?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
52
- write?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
53
52
  }
54
53
 
55
54
  declare const transformer: (...plugins: TransformerPlugin[]) => {
@@ -57,7 +56,6 @@ declare const transformer: (...plugins: TransformerPlugin[]) => {
57
56
  start: () => Promise<void>;
58
57
  run: (filePath: string) => Promise<TransformerPluginContext>;
59
58
  finish: () => Promise<void>;
60
- write: () => Promise<void>;
61
59
  };
62
60
 
63
61
  declare const ASSETS_OPTIONS: Partial<AssetsOptions>;
package/transformer.js CHANGED
@@ -8,13 +8,13 @@ import template from '@babel/template';
8
8
  import { pascalCase, kebabCase, camelCase, capitalCase } from 'change-case';
9
9
  import ora from 'ora';
10
10
  import path, { join, resolve, dirname } from 'node:path';
11
- import { COMMENT_AUTO_ADDED, DECORATOR_PROPERTY, STATIC_TAG, UTILS_STYLES_LOCAL, UTILS_PATH, DECORATOR_PROPERTY_TYPE, UTILS_STYLES_IMPORTED, ELEMENT_HOST_NAME, UTILS_HTML_IMPORTED, UTILS_HTML_LOCAL, TYPE_OBJECT, TYPE_NUMBER, TYPE_DATE, TYPE_BOOLEAN, TYPE_ARRAY, TYPE_STRING, TYPE_NULL, TYPE_ENUM, UTILS_ATTRIBUTES_IMPORTED, UTILS_ATTRIBUTES_LOCAL, DECORATOR_CSS_VARIABLE, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_STATE, STATIC_STYLE, STYLE_IMPORTED, PACKAGE_NAME, DECORATOR_ELEMENT } from './constants.js';
11
+ import { KEY, COMMENT_AUTO_ADDED, DECORATOR_PROPERTY, STATIC_TAG, UTILS_STYLES_LOCAL, UTILS_PATH, DECORATOR_PROPERTY_TYPE, UTILS_STYLES_IMPORTED, ELEMENT_HOST_NAME, UTILS_HTML_IMPORTED, UTILS_HTML_LOCAL, TYPE_OBJECT, TYPE_ARRAY, TYPE_NULL, TYPE_STRING, TYPE_ENUM, TYPE_NUMBER, TYPE_DATE, TYPE_BOOLEAN, UTILS_ATTRIBUTES_IMPORTED, UTILS_ATTRIBUTES_LOCAL, DECORATOR_CSS_VARIABLE, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_STATE, STATIC_STYLE, STYLE_IMPORTED, PACKAGE_NAME, DECORATOR_ELEMENT } from './constants.js';
12
12
 
13
13
  const logger = ora({
14
14
  color: 'yellow'
15
15
  });
16
16
  const log = (message, persist) => {
17
- const content = `${new Date().toLocaleTimeString()} [HTMLPLUS] ${message}`;
17
+ const content = `${new Date().toLocaleTimeString()} [${KEY}] ${message}`;
18
18
  const log = logger.start(content);
19
19
  if (!persist)
20
20
  return;
@@ -26,7 +26,7 @@ const transformer = (...plugins) => {
26
26
  };
27
27
  const start = async () => {
28
28
  log(`Started.`, true);
29
- log(`${plugins.length} plugins found.`, true);
29
+ log(`${plugins.length} plugins detected.`, true);
30
30
  log(`Plugins are starting.`, true);
31
31
  for (const plugin of plugins) {
32
32
  if (!plugin.start)
@@ -35,7 +35,7 @@ const transformer = (...plugins) => {
35
35
  global = (await plugin.start(global)) || global;
36
36
  log(`Plugin '${plugin.name}' started successfully.`);
37
37
  }
38
- log(`Plugins started successfully.`, true);
38
+ log(`Plugins have been successfully started.`, true);
39
39
  };
40
40
  const run = async (filePath) => {
41
41
  path.join(filePath).split(path.sep).pop();
@@ -74,17 +74,10 @@ const transformer = (...plugins) => {
74
74
  global = (await plugin.finish(global)) || global;
75
75
  log(`Plugin '${plugin.name}' finished successfully.`);
76
76
  }
77
- log(`Plugins finished successfully.`, true);
77
+ log(`Plugins have been successfully finished.`, true);
78
78
  log(`Finished.`, true);
79
79
  };
80
- const write = async () => {
81
- for (const plugin of plugins) {
82
- if (!plugin.write)
83
- continue;
84
- global = (await plugin.write(global)) || global;
85
- }
86
- };
87
- return { global, start, run, finish, write };
80
+ return { global, start, run, finish };
88
81
  };
89
82
 
90
83
  const ASSETS_OPTIONS = {
@@ -591,45 +584,48 @@ const customElement = (options) => {
591
584
  expression.arguments.push(t.objectExpression([]));
592
585
  }
593
586
  const [argument] = expression.arguments;
594
- const filtered = argument.properties.filter((property) => {
595
- return property.key.name != DECORATOR_PROPERTY_TYPE;
587
+ const property = argument.properties.find((property) => {
588
+ return property.key.name == DECORATOR_PROPERTY_TYPE;
596
589
  });
597
- if (argument.properties.length != filtered.length)
590
+ if (property)
598
591
  return;
599
- argument.properties = filtered;
600
592
  let type = 0;
601
593
  const extract = (input) => {
602
594
  switch (input?.type) {
595
+ case 'bool':
596
+ case 'Boolean':
603
597
  case 'BooleanLiteral':
598
+ case 'TSBooleanKeyword':
604
599
  type |= TYPE_BOOLEAN;
605
600
  break;
601
+ case 'Date':
602
+ type |= TYPE_DATE;
603
+ break;
604
+ case 'Number':
606
605
  case 'NumericLiteral':
606
+ case 'TSNumberKeyword':
607
607
  type |= TYPE_NUMBER;
608
608
  break;
609
609
  case 'StringLiteral':
610
610
  type |= TYPE_ENUM;
611
611
  break;
612
+ case 'TSStringKeyword':
613
+ type |= TYPE_STRING;
614
+ break;
612
615
  case 'TSArrayType':
613
616
  type |= TYPE_ARRAY;
614
617
  break;
615
- case 'TSBooleanKeyword':
616
- type |= TYPE_BOOLEAN;
617
- break;
618
618
  case 'TSLiteralType':
619
619
  extract(input.literal);
620
620
  break;
621
621
  case 'TSNullKeyword':
622
622
  type |= TYPE_NULL;
623
623
  break;
624
- case 'TSNumberKeyword':
625
- type |= TYPE_NUMBER;
626
- break;
624
+ case 'Object':
627
625
  case 'TSObjectKeyword':
628
626
  type |= TYPE_OBJECT;
629
627
  break;
630
- case 'TSStringKeyword':
631
- type |= TYPE_STRING;
632
- break;
628
+ case 'Array':
633
629
  case 'TSTupleType':
634
630
  type |= TYPE_ARRAY;
635
631
  break;
@@ -637,43 +633,23 @@ const customElement = (options) => {
637
633
  type |= TYPE_OBJECT;
638
634
  break;
639
635
  case 'TSTypeReference':
640
- if (!input.typeName)
641
- break;
642
- switch (input.typeName.name) {
643
- case 'Array':
644
- type |= TYPE_ARRAY;
645
- break;
646
- case 'Boolean':
647
- type |= TYPE_BOOLEAN;
648
- break;
649
- case 'bool':
650
- type |= TYPE_BOOLEAN;
651
- break;
652
- case 'Date':
653
- type |= TYPE_DATE;
654
- break;
655
- case 'Number':
656
- type |= TYPE_NUMBER;
657
- break;
658
- case 'Object':
659
- type |= TYPE_OBJECT;
660
- break;
661
- }
636
+ extract({ type: input?.typeName?.name });
662
637
  break;
663
638
  case 'TSUnionType':
664
639
  input.types.forEach(extract);
665
640
  break;
666
- }
667
- // TODO
668
- if (input?.type == 'TSParenthesizedType' &&
669
- input?.typeAnnotation?.type == 'TSIntersectionType') {
670
- let types = input.types || input.typeAnnotation.types;
671
- if (types.length != 2)
672
- return;
673
- types = types.filter((type) => type.type != 'TSTypeLiteral');
674
- if (types.length != 1)
675
- return;
676
- extract(types[0]);
641
+ // TODO
642
+ case 'TSParenthesizedType':
643
+ if (input?.typeAnnotation?.type != 'TSIntersectionType')
644
+ break;
645
+ let types = input.types || input.typeAnnotation.types;
646
+ if (types.length != 2)
647
+ return;
648
+ types = types.filter((type) => type.type != 'TSTypeLiteral');
649
+ if (types.length != 1)
650
+ return;
651
+ extract(types[0]);
652
+ break;
677
653
  }
678
654
  };
679
655
  extract(getType(context.directoryPath, ast, path.parentPath.node.typeAnnotation?.typeAnnotation));
@@ -789,7 +765,7 @@ const DOCUMENT_OPTIONS = {
789
765
  const document = (options) => {
790
766
  const name = 'document';
791
767
  options = Object.assign({}, DOCUMENT_OPTIONS, options);
792
- const write = (global) => {
768
+ const finish = (global) => {
793
769
  const json = {
794
770
  elements: []
795
771
  };
@@ -981,7 +957,7 @@ const document = (options) => {
981
957
  fs.ensureDirSync(dirname);
982
958
  fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
983
959
  };
984
- return { name, write };
960
+ return { name, finish };
985
961
  };
986
962
 
987
963
  const extract = () => {