@htmlplus/element 2.1.1 → 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 +1 -1
- package/client/index.js +1 -1
- package/client/utils/styles.d.ts +1 -1
- package/client/utils/styles.js +4 -14
- package/constants/index.d.ts +3 -3
- package/constants/index.js +5 -4
- package/package.json +1 -1
- package/transformer/plugins/assets.d.ts +0 -1
- package/transformer/plugins/assets.js +11 -14
- package/transformer/plugins/customElement.js +9 -10
- package/transformer/plugins/document.js +1 -1
- package/transformer/plugins/style.js +1 -1
- package/transformer/utils/addDependency.js +1 -1
- package/transformer/utils/index.d.ts +0 -4
- package/transformer/utils/index.js +0 -4
- package/transformer/utils/__dirname.d.ts +0 -1
- package/transformer/utils/__dirname.js +0 -5
- package/transformer/utils/isDirectoryEmpty.d.ts +0 -1
- package/transformer/utils/isDirectoryEmpty.js +0 -10
- package/transformer/utils/removeUnusedImport.d.ts +0 -1
- package/transformer/utils/removeUnusedImport.js +0 -49
- package/transformer/utils/renderTemplate.d.ts +0 -1
- package/transformer/utils/renderTemplate.js +0 -25
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,
|
|
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,
|
|
2
|
+
export { classes, direction, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, toUnit, setConfig } from './utils/index.js';
|
package/client/utils/styles.d.ts
CHANGED
package/client/utils/styles.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
};
|
package/constants/index.d.ts
CHANGED
|
@@ -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
|
|
10
|
-
export declare const
|
|
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";
|
package/constants/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const PACKAGE_NAME = '@htmlplus/element';
|
|
2
|
-
//
|
|
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
|
|
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
|
|
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,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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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,
|
|
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
|
-
//
|
|
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.
|
|
25
|
+
t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
|
|
28
26
|
body.body.unshift(node);
|
|
29
27
|
}
|
|
30
28
|
});
|
|
31
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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 ==
|
|
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
|
-
//
|
|
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
|
-
//
|
|
275
|
+
// attach typings
|
|
277
276
|
if (options.typings) {
|
|
278
277
|
visitor(ast, {
|
|
279
278
|
Program(path) {
|
|
@@ -181,7 +181,7 @@ export const document = (options) => {
|
|
|
181
181
|
return [];
|
|
182
182
|
return fs
|
|
183
183
|
.readFileSync(context.stylePath, 'utf8')
|
|
184
|
-
.split(CONSTANTS.
|
|
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.
|
|
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.
|
|
58
|
+
t.addComment(declaration, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
return {
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
export declare const isDirectoryEmpty: (directory: string) => boolean;
|
|
@@ -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 '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
|
-
};
|