@primate/webc 0.5.0 → 0.6.0
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/lib/private/default.d.ts +7 -0
- package/lib/private/{Default.js → default.js} +24 -10
- package/lib/private/init.d.ts +4 -0
- package/lib/private/init.js +11 -0
- package/lib/private/runtime.d.ts +7 -0
- package/lib/private/runtime.js +4 -0
- package/lib/public/default.d.ts +1 -3
- package/lib/public/default.js +1 -2
- package/lib/public/runtime.d.ts +1 -3
- package/lib/public/runtime.js +1 -2
- package/package.json +11 -8
- package/lib/private/Default.d.ts +0 -12
- package/lib/private/Runtime.d.ts +0 -16
- package/lib/private/Runtime.js +0 -19
|
@@ -1,29 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import init from "#init";
|
|
2
|
+
import frontend from "@primate/core/frontend";
|
|
3
|
+
import hash from "@rcompat/crypto/hash";
|
|
4
|
+
import error from "@rcompat/error";
|
|
5
|
+
import fs from "@rcompat/fs";
|
|
3
6
|
const script_re = /(?<=<script)>(?<code>.*?)(?=<\/script>)/gus;
|
|
4
7
|
const webc_class_name_re = /export default class (?<name>.*?) extends/u;
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
function no_class_name(view) {
|
|
9
|
+
return error.template `view at ${view} has no class name`;
|
|
10
|
+
}
|
|
11
|
+
const errors = error.coded({
|
|
12
|
+
no_class_name,
|
|
13
|
+
});
|
|
14
|
+
async function normalize(path) {
|
|
15
|
+
const file = fs.ref(path);
|
|
16
|
+
const basename = path.slice(0, -file.fullExtension.length);
|
|
17
|
+
return `p_${await hash(`${basename}.webc`)}`;
|
|
18
|
+
}
|
|
19
|
+
export default frontend({
|
|
20
|
+
...init,
|
|
21
|
+
compile: {
|
|
7
22
|
client: async (text, view) => {
|
|
8
23
|
const [script] = [...text.matchAll(script_re)]
|
|
9
24
|
.map(({ groups }) => groups.code);
|
|
10
25
|
const { name } = script.match(webc_class_name_re)?.groups
|
|
11
26
|
?? { name: undefined };
|
|
12
27
|
if (name === undefined)
|
|
13
|
-
throw
|
|
14
|
-
const tag = (await
|
|
28
|
+
throw errors.no_class_name(view);
|
|
29
|
+
const tag = (await normalize(view
|
|
15
30
|
.debase(view.directory, "/").path)).replace("_", "-");
|
|
16
31
|
const js = `${script}
|
|
17
32
|
globalThis.customElements.define("${tag}", ${name});
|
|
18
33
|
`;
|
|
19
34
|
return { js };
|
|
20
35
|
},
|
|
21
|
-
normalize: this.normalize,
|
|
22
36
|
server: (text) => {
|
|
23
37
|
const [code] = [...text.matchAll(script_re)]
|
|
24
38
|
.map(({ groups }) => groups.code);
|
|
25
39
|
return code;
|
|
26
40
|
},
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=default.js.map
|
package/lib/public/default.d.ts
CHANGED
package/lib/public/default.js
CHANGED
package/lib/public/runtime.d.ts
CHANGED
package/lib/public/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/webc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Web Components for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/web-components",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -17,34 +17,37 @@
|
|
|
17
17
|
"!/**/*.spec.*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@rcompat/
|
|
21
|
-
"@
|
|
20
|
+
"@rcompat/crypto": "^0.16.1",
|
|
21
|
+
"@rcompat/error": "^0.3.1",
|
|
22
|
+
"@rcompat/fs": "^0.28.1",
|
|
23
|
+
"@primate/core": "^0.6.0"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
|
-
"@rcompat/type": "^0.
|
|
26
|
+
"@rcompat/type": "^0.11.1"
|
|
25
27
|
},
|
|
26
28
|
"peerDependencies": {
|
|
27
|
-
"primate": "^0.
|
|
29
|
+
"primate": "^0.37.0"
|
|
28
30
|
},
|
|
29
31
|
"imports": {
|
|
30
32
|
"#*": {
|
|
31
|
-
"
|
|
33
|
+
"@primate/source": "./src/private/*.ts",
|
|
32
34
|
"default": "./lib/private/*.js"
|
|
33
35
|
},
|
|
34
36
|
"#Component": {
|
|
35
|
-
"
|
|
37
|
+
"@primate/source": "./src/private/client/Component.ts",
|
|
36
38
|
"browser": "./lib/private/client/Component.js",
|
|
37
39
|
"default": "./lib/private/server/Component.js"
|
|
38
40
|
}
|
|
39
41
|
},
|
|
40
42
|
"exports": {
|
|
41
43
|
".": {
|
|
44
|
+
"@primate/source": "./src/public/default.ts",
|
|
42
45
|
"browser": "./lib/public/browser.js",
|
|
43
46
|
"runtime": "./lib/public/runtime.js",
|
|
44
47
|
"default": "./lib/public/default.js"
|
|
45
48
|
},
|
|
46
49
|
"./*": {
|
|
47
|
-
"
|
|
50
|
+
"@primate/source": "./src/public/*.ts",
|
|
48
51
|
"default": "./lib/public/*.js"
|
|
49
52
|
}
|
|
50
53
|
},
|
package/lib/private/Default.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Runtime from "#Runtime";
|
|
2
|
-
import type { FileRef } from "@rcompat/fs";
|
|
3
|
-
export default class Default extends Runtime {
|
|
4
|
-
compile: {
|
|
5
|
-
client: (text: string, view: FileRef) => Promise<{
|
|
6
|
-
js: string;
|
|
7
|
-
}>;
|
|
8
|
-
normalize: (name: string) => Promise<string>;
|
|
9
|
-
server: (text: string) => string;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=Default.d.ts.map
|
package/lib/private/Runtime.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type App from "@primate/core/App";
|
|
2
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
3
|
-
import type Render from "@primate/core/frontend/Render";
|
|
4
|
-
import type Next from "@primate/core/Next";
|
|
5
|
-
import type { FileRef } from "@rcompat/fs";
|
|
6
|
-
export default class Runtime extends FrontendModule {
|
|
7
|
-
#private;
|
|
8
|
-
name: string;
|
|
9
|
-
defaultExtensions: string[];
|
|
10
|
-
layouts: boolean;
|
|
11
|
-
client: boolean;
|
|
12
|
-
render: Render;
|
|
13
|
-
get views(): FileRef | undefined;
|
|
14
|
-
init<T extends App>(app: T, next: Next<T>): import("@rcompat/type").MaybePromise<T>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=Runtime.d.ts.map
|
package/lib/private/Runtime.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
|
-
export default class Runtime extends FrontendModule {
|
|
3
|
-
#views;
|
|
4
|
-
name = "webc";
|
|
5
|
-
defaultExtensions = [".webc"];
|
|
6
|
-
layouts = false;
|
|
7
|
-
client = true;
|
|
8
|
-
render = (_view, _props) => {
|
|
9
|
-
return { body: "", head: "" };
|
|
10
|
-
};
|
|
11
|
-
get views() {
|
|
12
|
-
return this.#views;
|
|
13
|
-
}
|
|
14
|
-
init(app, next) {
|
|
15
|
-
this.#views = app.path.views;
|
|
16
|
-
return super.init(app, next);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=Runtime.js.map
|