@htmlplus/element 2.1.0 → 2.1.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/client/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './decorators/index.js';
2
- export { classes, direction, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, styles, toUnit, setConfig, type Config, type ConfigOptions } from './utils/index.js';
2
+ export { classes, direction, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, toUnit, setConfig, type Config, type ConfigOptions } from './utils/index.js';
package/client/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './decorators/index.js';
2
- export { classes, direction, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, styles, toUnit, setConfig } from './utils/index.js';
2
+ export { classes, direction, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, toUnit, setConfig } from './utils/index.js';
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Converts a JavaScript object containing CSS styles to a CSS string.
3
3
  */
4
- export declare const styles: (input: any) => string;
4
+ export declare const styles: (input: object) => string;
@@ -1,20 +1,10 @@
1
1
  import { kebabCase } from 'change-case';
2
- import { typeOf } from './typeOf.js';
3
2
  /**
4
3
  * Converts a JavaScript object containing CSS styles to a CSS string.
5
4
  */
6
5
  export const styles = (input) => {
7
- switch (typeOf(input)) {
8
- case 'array':
9
- return input.join('; ');
10
- case 'object':
11
- return Object.keys(input)
12
- .filter((key) => input[key] !== undefined && input[key] !== null)
13
- .map((key) => `${key.startsWith('--') ? '--' : ''}${kebabCase(key)}: ${input[key]}`)
14
- .join('; ');
15
- case 'string':
16
- return input;
17
- default:
18
- return '';
19
- }
6
+ return Object.keys(input)
7
+ .filter((key) => input[key] !== undefined && input[key] !== null)
8
+ .map((key) => `${key.startsWith('--') ? '--' : ''}${kebabCase(key)}: ${input[key]}`)
9
+ .join('; ');
20
10
  };
@@ -6,14 +6,14 @@ export declare const API_LOCKED: unique symbol;
6
6
  export declare const API_REQUEST: unique symbol;
7
7
  export declare const API_RENDER_COMPLETED: unique symbol;
8
8
  export declare const API_STACKS: unique symbol;
9
- export declare const COMMENT_AUTO_ADDED_DEPENDENCY = " THIS DEPENDENCY IS AUTO-ADDED, DO NOT EDIT MANUALY";
10
- export declare const COMMENT_AUTO_ADDED_PROPERTY = " THIS PROPERTY IS AUTO-ADDED, DO NOT EDIT MANUALY";
11
- export declare const CSS_DECORATOR_PROPERTY = "@Property()";
9
+ export declare const COMMENT_AUTO_ADDED = " THIS IS AUTO-ADDED, DO NOT EDIT MANUALY";
10
+ export declare const DECORATOR_CSS_VARIABLE = "@Property()";
12
11
  export declare const DECORATOR_ELEMENT = "Element";
13
12
  export declare const DECORATOR_EVENT = "Event";
14
13
  export declare const DECORATOR_PROPERTY = "Property";
15
14
  export declare const DECORATOR_STATE = "State";
16
15
  export declare const DECORATOR_METHOD = "Method";
16
+ export declare const ELEMENT_HOST_NAME = "host";
17
17
  export declare const LIFECYCLE_ADOPTED = "adoptedCallback";
18
18
  export declare const LIFECYCLE_CONNECT = "connectCallback";
19
19
  export declare const LIFECYCLE_CONNECTED = "connectedCallback";
@@ -1,5 +1,5 @@
1
1
  export const PACKAGE_NAME = '@htmlplus/element';
2
- // apis
2
+ // APIs
3
3
  export const API_CONNECTED = Symbol();
4
4
  export const API_HOST = Symbol();
5
5
  export const API_INSTANCE = Symbol();
@@ -8,16 +8,17 @@ export const API_REQUEST = Symbol();
8
8
  export const API_RENDER_COMPLETED = Symbol();
9
9
  export const API_STACKS = Symbol();
10
10
  // comments
11
- export const COMMENT_AUTO_ADDED_DEPENDENCY = ' THIS DEPENDENCY IS AUTO-ADDED, DO NOT EDIT MANUALY';
12
- export const COMMENT_AUTO_ADDED_PROPERTY = ' THIS PROPERTY IS AUTO-ADDED, DO NOT EDIT MANUALY';
11
+ export const COMMENT_AUTO_ADDED = ' THIS IS AUTO-ADDED, DO NOT EDIT MANUALY';
13
12
  // CSS decorators
14
- export const CSS_DECORATOR_PROPERTY = '@Property()';
13
+ export const DECORATOR_CSS_VARIABLE = '@Property()';
15
14
  // decorators
16
15
  export const DECORATOR_ELEMENT = 'Element';
17
16
  export const DECORATOR_EVENT = 'Event';
18
17
  export const DECORATOR_PROPERTY = 'Property';
19
18
  export const DECORATOR_STATE = 'State';
20
19
  export const DECORATOR_METHOD = 'Method';
20
+ // element
21
+ export const ELEMENT_HOST_NAME = 'host';
21
22
  // lifecycle
22
23
  export const LIFECYCLE_ADOPTED = 'adoptedCallback';
23
24
  export const LIFECYCLE_CONNECT = 'connectCallback';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
@@ -32,32 +32,32 @@
32
32
  },
33
33
  "homepage": "https://github.com/htmlplus/element#readme",
34
34
  "dependencies": {
35
- "@babel/generator": "^7.20.4",
36
- "@babel/parser": "^7.20.3",
37
- "@babel/template": "^7.22.15",
38
- "@babel/traverse": "^7.20.1",
39
- "@babel/types": "^7.20.2",
40
- "@types/node": "^18.11.9",
41
- "change-case": "^5.1.2",
42
- "fast-glob": "^3.2.12",
43
- "fs-extra": "^10.1.0",
44
- "handlebars": "^4.7.7",
45
- "ora": "^6.1.2",
46
- "typescript": "^4.9.3"
35
+ "@babel/generator": "^7.23.6",
36
+ "@babel/parser": "^7.23.9",
37
+ "@babel/template": "^7.23.9",
38
+ "@babel/traverse": "^7.23.9",
39
+ "@babel/types": "^7.23.9",
40
+ "@types/node": "^20.11.19",
41
+ "change-case": "^5.4.3",
42
+ "fs-extra": "^11.2.0",
43
+ "glob": "^10.3.10",
44
+ "handlebars": "^4.7.8",
45
+ "ora": "^8.0.1",
46
+ "typescript": "^4.9.5"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@semantic-release/changelog": "^6.0.3",
50
50
  "@semantic-release/commit-analyzer": "^11.1.0",
51
51
  "@semantic-release/git": "^10.0.1",
52
- "@semantic-release/github": "^9.2.4",
53
- "@semantic-release/npm": "^11.0.1",
52
+ "@semantic-release/github": "^9.2.6",
53
+ "@semantic-release/npm": "^11.0.2",
54
54
  "@semantic-release/release-notes-generator": "^12.1.0",
55
- "@trivago/prettier-plugin-sort-imports": "^4.0.0",
56
- "cpy": "^9.0.1",
57
- "prettier": "^2.8.0",
58
- "rimraf": "^3.0.2",
59
- "semantic-release": "^22.0.8",
60
- "tsx": "^4.6.2",
61
- "vite": "^3.2.4"
55
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
56
+ "cpy": "^11.0.0",
57
+ "prettier": "^3.2.5",
58
+ "rimraf": "^5.0.5",
59
+ "semantic-release": "^23.0.2",
60
+ "tsx": "^4.7.1",
61
+ "vite": "^5.1.3"
62
62
  }
63
63
  }
@@ -1,7 +1,6 @@
1
1
  import { TransformerPlugin, TransformerPluginContext } from '../transformer.types';
2
2
  export declare const ASSETS_OPTIONS: Partial<AssetsOptions>;
3
3
  export interface AssetsOptions {
4
- once?: boolean;
5
4
  destination?: (context: TransformerPluginContext) => string;
6
5
  source?: (context: TransformerPluginContext) => string;
7
6
  }
@@ -1,7 +1,6 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  export const ASSETS_OPTIONS = {
4
- once: true,
5
4
  destination(context) {
6
5
  return path.join('dist', 'assets', context.fileName);
7
6
  },
@@ -12,18 +11,16 @@ export const ASSETS_OPTIONS = {
12
11
  export const assets = (options) => {
13
12
  const name = 'assets';
14
13
  options = Object.assign({}, ASSETS_OPTIONS, options);
15
- const sources = new Set();
16
- const run = (context) => {
17
- context.assetsDestination = options.destination(context);
18
- context.assetsSource = options.source(context);
19
- if (!context.assetsSource)
20
- return;
21
- if (!fs.existsSync(context.assetsSource))
22
- return;
23
- if (options.once && sources.has(context.assetsSource))
24
- return;
25
- sources.add(context.assetsSource);
26
- fs.copySync(context.assetsSource, context.assetsDestination);
14
+ const finish = (global) => {
15
+ for (const context of global.contexts) {
16
+ context.assetsDestination = options.destination(context);
17
+ context.assetsSource = options.source(context);
18
+ if (!context.assetsSource)
19
+ return;
20
+ if (!fs.existsSync(context.assetsSource))
21
+ return;
22
+ fs.copySync(context.assetsSource, context.assetsDestination);
23
+ }
27
24
  };
28
- return { name, run };
25
+ return { name, finish };
29
26
  };
@@ -13,22 +13,20 @@ export const customElement = (options) => {
13
13
  options = Object.assign({}, CUSTOM_ELEMENT_OPTIONS, options);
14
14
  const run = (context) => {
15
15
  const ast = t.cloneNode(context.fileAST, true);
16
- // TODO
17
16
  context.elementTagName = `${options.prefix || ''}${context.elementKey}`;
18
- // TODO
19
17
  context.elementInterfaceName = `HTML${pascalCase(context.elementTagName)}Element`;
20
- // attaches name
18
+ // attach tag name
21
19
  visitor(ast, {
22
20
  ClassDeclaration(path) {
23
21
  const { body, id } = path.node;
24
22
  if (id.name != context.className)
25
23
  return;
26
24
  const node = t.classProperty(t.identifier(CONSTANTS.STATIC_TAG), t.stringLiteral(context.elementTagName), undefined, undefined, undefined, true);
27
- t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_PROPERTY, true);
25
+ t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
28
26
  body.body.unshift(node);
29
27
  }
30
28
  });
31
- // attaches style mapper for 'style' attribute
29
+ // attach style mapper for 'style' attribute
32
30
  visitor(ast, {
33
31
  JSXAttribute(path) {
34
32
  const { name, value } = path.node;
@@ -44,7 +42,7 @@ export const customElement = (options) => {
44
42
  path.skip();
45
43
  }
46
44
  });
47
- // replaces 'className' attribute with 'class'
45
+ // replace 'className' attribute with 'class'
48
46
  visitor(ast, {
49
47
  JSXAttribute(path) {
50
48
  const { name, value } = path.node;
@@ -66,7 +64,8 @@ export const customElement = (options) => {
66
64
  path.replaceWith(t.jsxAttribute(t.jsxIdentifier(name.name.toLowerCase()), value));
67
65
  }
68
66
  });
69
- // converts 'jsx' to 'uhtml' syntax
67
+ // TODO
68
+ // convert 'jsx' to 'uhtml' syntax
70
69
  visitor(ast, {
71
70
  enter(path) {
72
71
  const { type } = path.node;
@@ -95,7 +94,7 @@ export const customElement = (options) => {
95
94
  switch (node.type) {
96
95
  case 'JSXElement':
97
96
  const attributes = node.openingElement.attributes;
98
- const isHost = node.openingElement.name.name == 'host';
97
+ const isHost = node.openingElement.name.name == CONSTANTS.ELEMENT_HOST_NAME;
99
98
  // TODO
100
99
  if (isHost) {
101
100
  const children = node.children.map(render).flat();
@@ -176,7 +175,7 @@ export const customElement = (options) => {
176
175
  path.replaceWith(transform(render(path.node)));
177
176
  }
178
177
  });
179
- // adds type to properties
178
+ // add type to properties
180
179
  visitor(ast, {
181
180
  Decorator(path) {
182
181
  var _a, _b;
@@ -273,7 +272,7 @@ export const customElement = (options) => {
273
272
  argument.properties.push(t.objectProperty(t.identifier(CONSTANTS.STATIC_MEMBERS_TYPE), t.numericLiteral(type)));
274
273
  }
275
274
  });
276
- // attaches typings
275
+ // attach typings
277
276
  if (options.typings) {
278
277
  visitor(ast, {
279
278
  Program(path) {
@@ -1,6 +1,6 @@
1
1
  import { capitalCase, kebabCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
- import glob from 'glob';
3
+ import { glob } from 'glob';
4
4
  import path from 'path';
5
5
  import * as CONSTANTS from '../../constants/index.js';
6
6
  import { getInitializer, getTag, getTags, getTypeReference, hasTag, parseTag, print } from '../utils/index.js';
@@ -181,7 +181,7 @@ export const document = (options) => {
181
181
  return [];
182
182
  return fs
183
183
  .readFileSync(context.stylePath, 'utf8')
184
- .split(CONSTANTS.CSS_DECORATOR_PROPERTY)
184
+ .split(CONSTANTS.DECORATOR_CSS_VARIABLE)
185
185
  .slice(1)
186
186
  .map((section) => {
187
187
  const [first, second] = section.split(/\n/);
@@ -35,7 +35,7 @@ export const style = (options) => {
35
35
  const { local } = addDependency(context.fileAST, context.stylePath, CONSTANTS.STYLE_IMPORTED, undefined, true);
36
36
  // TODO: remove 'local!'
37
37
  const property = t.classProperty(t.identifier(CONSTANTS.STATIC_STYLES), t.identifier(local), undefined, null, undefined, true);
38
- t.addComment(property, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_PROPERTY, true);
38
+ t.addComment(property, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
39
39
  context.class.body.body.unshift(property);
40
40
  };
41
41
  return { name, run };
@@ -55,7 +55,7 @@ export function addDependency(path, source, local, imported, comment) {
55
55
  (file.program || file).body.unshift(declaration);
56
56
  // TODO
57
57
  if (comment) {
58
- t.addComment(declaration, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_DEPENDENCY, true);
58
+ t.addComment(declaration, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
59
59
  }
60
60
  }
61
61
  return {
@@ -1,5 +1,5 @@
1
1
  import { parse } from '@babel/parser';
2
- import glob from 'fast-glob';
2
+ import { glob } from 'glob';
3
3
  import fs from 'fs-extra';
4
4
  import { dirname, resolve } from 'path';
5
5
  import { join } from 'path';
@@ -1,13 +1,9 @@
1
- export * from './__dirname.js';
2
1
  export * from './addDependency.js';
3
2
  export * from './getInitializer.js';
4
3
  export * from './getType.js';
5
4
  export * from './getTypeReference.js';
6
5
  export * from './hasDecorator.js';
7
- export * from './isDirectoryEmpty.js';
8
6
  export * from './printType.js';
9
7
  export * from './print.js';
10
- export * from './removeUnusedImport.js';
11
- export * from './renderTemplate.js';
12
8
  export * from './tags.js';
13
9
  export * from './visitor.js';
@@ -1,13 +1,9 @@
1
- export * from './__dirname.js';
2
1
  export * from './addDependency.js';
3
2
  export * from './getInitializer.js';
4
3
  export * from './getType.js';
5
4
  export * from './getTypeReference.js';
6
5
  export * from './hasDecorator.js';
7
- export * from './isDirectoryEmpty.js';
8
6
  export * from './printType.js';
9
7
  export * from './print.js';
10
- export * from './removeUnusedImport.js';
11
- export * from './renderTemplate.js';
12
8
  export * from './tags.js';
13
9
  export * from './visitor.js';
@@ -1 +0,0 @@
1
- export declare const __dirname: (url: string | URL) => string;
@@ -1,5 +0,0 @@
1
- import { dirname } from 'path';
2
- import { fileURLToPath } from 'url';
3
- export const __dirname = (url) => {
4
- return dirname(fileURLToPath(url));
5
- };
@@ -1 +0,0 @@
1
- export declare const isDirectoryEmpty: (directory: string) => boolean;
@@ -1,10 +0,0 @@
1
- import fs from 'fs-extra';
2
- export const isDirectoryEmpty = (directory) => {
3
- try {
4
- const files = fs.readdirSync(directory);
5
- return !files.length;
6
- }
7
- catch (_a) {
8
- return true;
9
- }
10
- };
@@ -1 +0,0 @@
1
- export declare const removeUnusedImport: (ast: any) => void;
@@ -1,49 +0,0 @@
1
- import t from '@babel/types';
2
- import { visitor } from './visitor.js';
3
- // TODO
4
- export const removeUnusedImport = (ast) => {
5
- visitor(ast, {
6
- Program: {
7
- exit(path) {
8
- for (const entry of Object.entries(path.scope.bindings)) {
9
- let { kind, path, referenced, referencePaths } = entry[1];
10
- if (kind !== 'module')
11
- continue;
12
- if (referenced) {
13
- referenced = false;
14
- for (const referencePath of referencePaths) {
15
- let find = true;
16
- let parent = referencePath;
17
- while (parent) {
18
- if (!parent.node) {
19
- find = false;
20
- break;
21
- }
22
- parent = parent.parentPath;
23
- }
24
- if (!find)
25
- continue;
26
- referenced = true;
27
- break;
28
- }
29
- }
30
- if (referenced)
31
- continue;
32
- const source = path.parentPath.get('source');
33
- if (!t.isStringLiteral(source))
34
- continue;
35
- if (path.isImportSpecifier()) {
36
- path.remove();
37
- if (path.parentPath.node.specifiers.length)
38
- continue;
39
- path.parentPath.remove();
40
- continue;
41
- }
42
- if (!path.parentPath)
43
- continue;
44
- path.parentPath.remove();
45
- }
46
- }
47
- }
48
- });
49
- };
@@ -1 +0,0 @@
1
- export declare const renderTemplate: (source: string | Array<string>, destination: string, options?: any) => (context: any) => void;
@@ -1,25 +0,0 @@
1
- import glob from 'fast-glob';
2
- import fs from 'fs-extra';
3
- import handlebars from 'handlebars';
4
- import path from 'path';
5
- export const renderTemplate = (source, destination, options) => (context) => {
6
- const files = glob.sync(source, options);
7
- for (const file of files) {
8
- // TODO
9
- const from = path.resolve((options === null || options === void 0 ? void 0 : options.cwd) || '', file);
10
- // TODO
11
- const to = path.join(destination, path
12
- .normalize(file)
13
- .split(path.sep)
14
- .slice(1)
15
- .map((section) => handlebars.compile(section)(context))
16
- .join(path.sep)
17
- .replace('_.', '.')
18
- .replace('.hbs', ''));
19
- const directory = path.dirname(to);
20
- const raw = fs.readFileSync(from, 'utf8');
21
- const template = handlebars.compile(raw)(context);
22
- fs.ensureDirSync(directory);
23
- fs.writeFileSync(to, template, 'utf8');
24
- }
25
- };