@htmlplus/element 0.4.5 → 0.4.7
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/bundler/index.d.ts +2 -0
- package/bundler/index.js +2 -0
- package/bundler/rollup.d.ts +7 -0
- package/bundler/rollup.js +21 -0
- package/bundler/vite.d.ts +7 -0
- package/bundler/vite.js +25 -0
- package/client/decorators/attributes.d.ts +1 -1
- package/client/decorators/element.d.ts +1 -1
- package/client/decorators/event.d.ts +1 -1
- package/client/decorators/listen.d.ts +1 -1
- package/client/decorators/method.d.ts +1 -1
- package/client/decorators/property.d.ts +1 -1
- package/client/decorators/state.d.ts +1 -1
- package/client/decorators/watch.d.ts +1 -1
- package/client/helpers/direction.d.ts +1 -1
- package/client/helpers/isRTL.d.ts +1 -1
- package/client/helpers/slots.d.ts +1 -1
- package/client/utils/getMemberType.d.ts +1 -1
- package/client/utils/getMembersKey.d.ts +1 -1
- package/client/utils/getStyles.d.ts +1 -1
- package/client/utils/host.d.ts +1 -1
- package/client/utils/request.d.ts +1 -1
- package/client/utils/request.js +2 -2
- package/compiler/compiler.d.ts +1 -1
- package/compiler/plugins/assets.d.ts +1 -1
- package/compiler/plugins/customElement.d.ts +1 -1
- package/compiler/plugins/customElement.js +1 -1
- package/compiler/plugins/customElementReact/customElementReact.d.ts +1 -1
- package/compiler/plugins/document.d.ts +1 -1
- package/compiler/plugins/extract.d.ts +1 -1
- package/compiler/plugins/finish.d.ts +4 -0
- package/compiler/plugins/finish.js +7 -0
- package/compiler/plugins/index.d.ts +2 -0
- package/compiler/plugins/index.js +2 -0
- package/compiler/plugins/parse.d.ts +1 -1
- package/compiler/plugins/read.d.ts +1 -1
- package/compiler/plugins/start.d.ts +4 -0
- package/compiler/plugins/start.js +7 -0
- package/compiler/plugins/style.d.ts +1 -1
- package/compiler/plugins/style.js +1 -1
- package/compiler/plugins/validate.d.ts +1 -1
- package/compiler/plugins/visualStudioCode.d.ts +1 -1
- package/compiler/plugins/webTypes.d.ts +1 -1
- package/compiler/utils/addDependency.d.ts +3 -1
- package/compiler/utils/addDependency.js +25 -15
- package/compiler/utils/index.d.ts +1 -0
- package/compiler/utils/index.js +1 -0
- package/compiler/utils/removeUnusedImport.d.ts +1 -0
- package/compiler/utils/removeUnusedImport.js +49 -0
- package/package.json +5 -11
- package/types/global.d.ts +1 -1
- package/types/index.d.ts +4 -4
- package/types/index.js +4 -4
- package/types/plugin.d.ts +1 -1
package/bundler/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import compiler from '../compiler/index.js';
|
|
2
|
+
export const rollup = (...plugins) => {
|
|
3
|
+
const { start, next, finish } = compiler(...plugins);
|
|
4
|
+
return {
|
|
5
|
+
name: 'htmlplus',
|
|
6
|
+
async buildStart() {
|
|
7
|
+
await start();
|
|
8
|
+
},
|
|
9
|
+
async load(id) {
|
|
10
|
+
if (!id.endsWith('.tsx'))
|
|
11
|
+
return;
|
|
12
|
+
const { isInvalid, script } = await next(id);
|
|
13
|
+
if (isInvalid)
|
|
14
|
+
return;
|
|
15
|
+
return script;
|
|
16
|
+
},
|
|
17
|
+
async buildEnd() {
|
|
18
|
+
await finish();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
package/bundler/vite.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import compiler from '../compiler/index.js';
|
|
3
|
+
export const vite = (...plugins) => {
|
|
4
|
+
const { start, next, finish } = compiler(...plugins);
|
|
5
|
+
return {
|
|
6
|
+
name: 'htmlplus',
|
|
7
|
+
async buildStart() {
|
|
8
|
+
await start();
|
|
9
|
+
},
|
|
10
|
+
async load(id) {
|
|
11
|
+
if (!id.endsWith('.tsx'))
|
|
12
|
+
return;
|
|
13
|
+
let { isInvalid, script, stylePath } = await next(id);
|
|
14
|
+
if (isInvalid)
|
|
15
|
+
return;
|
|
16
|
+
if (script && stylePath) {
|
|
17
|
+
script = script.replace(path.basename(stylePath), `${path.basename(stylePath)}?inline`);
|
|
18
|
+
}
|
|
19
|
+
return script;
|
|
20
|
+
},
|
|
21
|
+
async buildEnd() {
|
|
22
|
+
await finish();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function Attributes(): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function Element(tag?: string): (constructor: PlusElement) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function Method(): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function State(): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const isRTL: (target: PlusElement) => boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const getMemberType: (target: PlusElement, key: string) => string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const getMembersKey: (target: PlusElement) => string[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const getStyles: (target: PlusElement) => string | undefined;
|
package/client/utils/host.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const host: (target: PlusElement) => HTMLElement;
|
package/client/utils/request.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { call } from '../utils/call';
|
|
3
|
-
import { task } from '../utils/task';
|
|
2
|
+
import { call } from '../utils/call.js';
|
|
3
|
+
import { task } from '../utils/task.js';
|
|
4
4
|
import { html, render } from '../vendor/uhtml.js';
|
|
5
5
|
import { getStyles } from './getStyles.js';
|
|
6
6
|
import { host } from './host.js';
|
package/compiler/compiler.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export const customElement = (options) => {
|
|
|
21
21
|
return;
|
|
22
22
|
if (value.type != 'JSXExpressionContainer')
|
|
23
23
|
return;
|
|
24
|
-
const local = addDependency(
|
|
24
|
+
const local = addDependency(path, CONSTANTS.PACKAGE_NAME, CONSTANTS.UTILS_STYLE_MAP, CONSTANTS.UTILS_STYLE_MAP);
|
|
25
25
|
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('style'), t.jsxExpressionContainer(t.callExpression(t.identifier(local), [value.expression]))));
|
|
26
26
|
path.skip();
|
|
27
27
|
}
|
|
@@ -3,8 +3,10 @@ export * from './customElementReact/index.js';
|
|
|
3
3
|
export * from './customElement.js';
|
|
4
4
|
export * from './document.js';
|
|
5
5
|
export * from './extract.js';
|
|
6
|
+
export * from './finish.js';
|
|
6
7
|
export * from './parse.js';
|
|
7
8
|
export * from './read.js';
|
|
9
|
+
export * from './start.js';
|
|
8
10
|
export * from './style.js';
|
|
9
11
|
export * from './validate.js';
|
|
10
12
|
export * from './webTypes.js';
|
|
@@ -3,8 +3,10 @@ export * from './customElementReact/index.js';
|
|
|
3
3
|
export * from './customElement.js';
|
|
4
4
|
export * from './document.js';
|
|
5
5
|
export * from './extract.js';
|
|
6
|
+
export * from './finish.js';
|
|
6
7
|
export * from './parse.js';
|
|
7
8
|
export * from './read.js';
|
|
9
|
+
export * from './start.js';
|
|
8
10
|
export * from './style.js';
|
|
9
11
|
export * from './validate.js';
|
|
10
12
|
export * from './webTypes.js';
|
|
@@ -26,7 +26,7 @@ export const style = (options) => {
|
|
|
26
26
|
}
|
|
27
27
|
if (!context.stylePath)
|
|
28
28
|
return;
|
|
29
|
-
const local = addDependency(context.fileAST, context.stylePath, 'AUTO_IMPORT_STYLE'
|
|
29
|
+
const local = addDependency(context.fileAST, context.stylePath, 'AUTO_IMPORT_STYLE');
|
|
30
30
|
const property = t.classProperty(t.identifier(CONSTANTS.STATIC_STYLES), t.identifier(local), undefined, null, undefined, true);
|
|
31
31
|
context.class.body.body.unshift(property);
|
|
32
32
|
};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { File } from '@babel/types';
|
|
2
|
-
export declare
|
|
2
|
+
export declare function addDependency(path: File | any, source: string): void;
|
|
3
|
+
export declare function addDependency(path: File | any, source: string, local: string): string;
|
|
4
|
+
export declare function addDependency(path: File | any, source: string, local: string, imported: string): string;
|
|
@@ -1,41 +1,51 @@
|
|
|
1
1
|
import t from '@babel/types';
|
|
2
2
|
import { visitor } from './visitor.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export function addDependency(path, source, local, imported) {
|
|
4
|
+
const isDefault = local && !imported;
|
|
5
|
+
const isImport = local && imported;
|
|
6
|
+
const isNormal = !local && !imported;
|
|
7
|
+
let declaration;
|
|
8
|
+
let file = path;
|
|
9
|
+
while (file.parentPath)
|
|
10
|
+
file = file.parentPath;
|
|
11
|
+
file = file.node || file;
|
|
5
12
|
visitor(file, {
|
|
6
13
|
ImportDeclaration(path) {
|
|
7
14
|
if (path.node.source.value != source)
|
|
8
15
|
return;
|
|
9
|
-
|
|
16
|
+
declaration = path.node;
|
|
10
17
|
}
|
|
11
18
|
});
|
|
12
|
-
|
|
19
|
+
if (isNormal && declaration)
|
|
20
|
+
return;
|
|
21
|
+
let specifier = declaration === null || declaration === void 0 ? void 0 : declaration.specifiers.find((specifier) => {
|
|
13
22
|
var _a;
|
|
14
23
|
if (isDefault) {
|
|
15
24
|
return specifier.type == 'ImportDefaultSpecifier';
|
|
16
25
|
}
|
|
17
|
-
else {
|
|
26
|
+
else if (isImport) {
|
|
18
27
|
return ((_a = specifier.imported) === null || _a === void 0 ? void 0 : _a.name) == imported;
|
|
19
28
|
}
|
|
20
29
|
});
|
|
21
30
|
if (specifier)
|
|
22
31
|
return specifier.local.name;
|
|
23
32
|
if (isDefault) {
|
|
24
|
-
specifier = t.importDefaultSpecifier(t.identifier(
|
|
33
|
+
specifier = t.importDefaultSpecifier(t.identifier(local));
|
|
25
34
|
}
|
|
26
|
-
else {
|
|
27
|
-
specifier = t.importSpecifier(t.identifier(local
|
|
35
|
+
else if (isImport) {
|
|
36
|
+
specifier = t.importSpecifier(t.identifier(local), t.identifier(imported));
|
|
28
37
|
}
|
|
29
|
-
if (
|
|
38
|
+
if (declaration) {
|
|
30
39
|
if (isDefault) {
|
|
31
|
-
|
|
40
|
+
declaration.specifiers.unshift(specifier);
|
|
32
41
|
}
|
|
33
|
-
else {
|
|
34
|
-
|
|
42
|
+
else if (isImport) {
|
|
43
|
+
declaration.specifiers.push(specifier);
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
46
|
else {
|
|
38
|
-
|
|
47
|
+
// TODO
|
|
48
|
+
(file.program || file).body.unshift(t.importDeclaration(specifier ? [specifier] : [], t.stringLiteral(source)));
|
|
39
49
|
}
|
|
40
|
-
return
|
|
41
|
-
}
|
|
50
|
+
return local;
|
|
51
|
+
}
|
|
@@ -7,6 +7,7 @@ export * from './hasDecorator.js';
|
|
|
7
7
|
export * from './isDirectoryEmpty.js';
|
|
8
8
|
export * from './printType.js';
|
|
9
9
|
export * from './print.js';
|
|
10
|
+
export * from './removeUnusedImport.js';
|
|
10
11
|
export * from './renderTemplate.js';
|
|
11
12
|
export * from './tags.js';
|
|
12
13
|
export * from './visitor.js';
|
package/compiler/utils/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from './hasDecorator.js';
|
|
|
7
7
|
export * from './isDirectoryEmpty.js';
|
|
8
8
|
export * from './printType.js';
|
|
9
9
|
export * from './print.js';
|
|
10
|
+
export * from './removeUnusedImport.js';
|
|
10
11
|
export * from './renderTemplate.js';
|
|
11
12
|
export * from './tags.js';
|
|
12
13
|
export * from './visitor.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const removeUnusedImport: (ast: any) => void;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
6
6
|
"description": "Compiler of HTMLPlus",
|
|
@@ -8,13 +8,7 @@
|
|
|
8
8
|
"main": "client/index.js",
|
|
9
9
|
"types": "client/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
|
-
"
|
|
12
|
-
"compiler",
|
|
13
|
-
"constants",
|
|
14
|
-
"runtime",
|
|
15
|
-
"types",
|
|
16
|
-
"package.json",
|
|
17
|
-
"README.md"
|
|
11
|
+
"**/*.*"
|
|
18
12
|
],
|
|
19
13
|
"publishConfig": {
|
|
20
14
|
"directory": "dist"
|
|
@@ -25,12 +19,12 @@
|
|
|
25
19
|
"keywords": [],
|
|
26
20
|
"repository": {
|
|
27
21
|
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/htmlplus/
|
|
22
|
+
"url": "git+https://github.com/htmlplus/htmlplus.git"
|
|
29
23
|
},
|
|
30
24
|
"bugs": {
|
|
31
|
-
"url": "https://github.com/htmlplus/
|
|
25
|
+
"url": "https://github.com/htmlplus/htmlplus/issues"
|
|
32
26
|
},
|
|
33
|
-
"homepage": "https://github.com/htmlplus/
|
|
27
|
+
"homepage": "https://github.com/htmlplus/htmlplus#readme",
|
|
34
28
|
"dependencies": {
|
|
35
29
|
"@babel/generator": "^7.18.9",
|
|
36
30
|
"@babel/parser": "^7.18.9",
|
package/types/global.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './context
|
|
2
|
-
export * from './global
|
|
3
|
-
export * from './plugin
|
|
4
|
-
export * from './plusElement
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './global';
|
|
3
|
+
export * from './plugin';
|
|
4
|
+
export * from './plusElement';
|
package/types/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './context
|
|
2
|
-
export * from './global
|
|
3
|
-
export * from './plugin
|
|
4
|
-
export * from './plusElement
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './global';
|
|
3
|
+
export * from './plugin';
|
|
4
|
+
export * from './plusElement';
|
package/types/plugin.d.ts
CHANGED