@primate/webc 0.4.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.
@@ -1,4 +1,4 @@
1
- import type Dict from "@rcompat/type/Dict";
1
+ import type { Dict } from "@rcompat/type";
2
2
  export default class Component extends HTMLElement {
3
3
  #private;
4
4
  static tag: string;
@@ -0,0 +1,9 @@
1
+ import type { Dict } from "@rcompat/type";
2
+ type Props = {
3
+ props: Dict;
4
+ };
5
+ export default class WebComponentsApp {
6
+ static mount(view: string, props: Props): void;
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=app.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import * as views from "webc:views";
2
- export default class WebComponentsClient {
2
+ export default class WebComponentsApp {
3
3
  static mount(view, props) {
4
4
  globalThis.document.body.appendChild(new views[view](props.props));
5
5
  }
6
6
  }
7
- //# sourceMappingURL=index.js.map
7
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1,7 @@
1
+ declare const _default: (input?: {
2
+ extensions?: string[] | undefined;
3
+ spa?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } | undefined) => import("@primate/core/frontend").Module;
6
+ export default _default;
7
+ //# sourceMappingURL=default.d.ts.map
@@ -1,29 +1,43 @@
1
- import Runtime from "#Runtime";
2
- import fail from "@primate/core/fail";
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
- export default class Default extends Runtime {
6
- compile = {
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 fail("view at {0} has no class name", view);
14
- const tag = (await this.normalize(view
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=Default.js.map
41
+ },
42
+ });
43
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1,4 @@
1
+ import type { Init } from "@primate/core/frontend";
2
+ declare const module: Init;
3
+ export default module;
4
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1,11 @@
1
+ const module = {
2
+ name: "webc",
3
+ extensions: [".webc"],
4
+ layouts: false,
5
+ client: true,
6
+ render(_view, _props) {
7
+ return { body: "", head: "" };
8
+ },
9
+ };
10
+ export default module;
11
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1,7 @@
1
+ declare const _default: (input?: {
2
+ extensions?: string[] | undefined;
3
+ spa?: boolean | undefined;
4
+ ssr?: boolean | undefined;
5
+ } | undefined) => import("@primate/core/frontend").Module;
6
+ export default _default;
7
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,4 @@
1
+ import init from "#init";
2
+ import frontend from "@primate/core/frontend";
3
+ export default frontend(init);
4
+ //# sourceMappingURL=runtime.js.map
@@ -1,4 +1,4 @@
1
- import type Dict from "@rcompat/type/Dict";
1
+ import type { Dict } from "@rcompat/type";
2
2
  export default class Component {
3
3
  render(_props: Dict): string;
4
4
  mounted(_: ShadowRoot): void;
@@ -1,2 +1,2 @@
1
- export { default } from "#client/index";
1
+ export { default } from "#client/app";
2
2
  //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,2 @@
1
- export { default } from "#client/index";
1
+ export { default } from "#client/app";
2
2
  //# sourceMappingURL=browser.js.map
@@ -1,4 +1,2 @@
1
- import Default from "#Default";
2
- declare const _default: (options?: typeof Default.input) => Default;
3
- export default _default;
1
+ export { default } from "#default";
4
2
  //# sourceMappingURL=default.d.ts.map
@@ -1,3 +1,2 @@
1
- import Default from "#Default";
2
- export default (options) => new Default(options);
1
+ export { default } from "#default";
3
2
  //# sourceMappingURL=default.js.map
@@ -1,4 +1,2 @@
1
- import Runtime from "#Runtime";
2
- declare const _default: (options?: typeof Runtime.input) => Runtime;
3
- export default _default;
1
+ export { default } from "#runtime";
4
2
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,3 +1,2 @@
1
- import Runtime from "#Runtime";
2
- export default (options) => new Runtime(options);
1
+ export { default } from "#runtime";
3
2
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,47 +1,53 @@
1
1
  {
2
2
  "name": "@primate/webc",
3
- "version": "0.4.0",
4
- "description": "Primate web components frontend",
3
+ "version": "0.6.0",
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",
7
+ "type": "module",
7
8
  "license": "MIT",
8
- "files": [
9
- "/lib/**/*.js",
10
- "/lib/**/*.d.ts",
11
- "!/**/*.spec.*"
12
- ],
13
9
  "repository": {
14
10
  "type": "git",
15
11
  "url": "https://github.com/primate-run/primate",
16
12
  "directory": "packages/webc"
17
13
  },
14
+ "files": [
15
+ "/lib/**/*.js",
16
+ "/lib/**/*.d.ts",
17
+ "!/**/*.spec.*"
18
+ ],
18
19
  "dependencies": {
19
- "@rcompat/fs": "^0.22.3",
20
- "@primate/core": "^0.4.0"
20
+ "@rcompat/crypto": "^0.16.1",
21
+ "@rcompat/error": "^0.3.1",
22
+ "@rcompat/fs": "^0.28.1",
23
+ "@primate/core": "^0.6.0"
24
+ },
25
+ "devDependencies": {
26
+ "@rcompat/type": "^0.11.1"
21
27
  },
22
28
  "peerDependencies": {
23
- "primate": "^0.35.0"
29
+ "primate": "^0.37.0"
24
30
  },
25
- "type": "module",
26
31
  "imports": {
27
32
  "#*": {
28
- "apekit": "./src/private/*.ts",
33
+ "@primate/source": "./src/private/*.ts",
29
34
  "default": "./lib/private/*.js"
30
35
  },
31
36
  "#Component": {
32
- "apekit": "./src/private/client/Component.ts",
37
+ "@primate/source": "./src/private/client/Component.ts",
33
38
  "browser": "./lib/private/client/Component.js",
34
39
  "default": "./lib/private/server/Component.js"
35
40
  }
36
41
  },
37
42
  "exports": {
38
43
  ".": {
44
+ "@primate/source": "./src/public/default.ts",
39
45
  "browser": "./lib/public/browser.js",
40
46
  "runtime": "./lib/public/runtime.js",
41
47
  "default": "./lib/public/default.js"
42
48
  },
43
49
  "./*": {
44
- "apekit": "./src/public/*.ts",
50
+ "@primate/source": "./src/public/*.ts",
45
51
  "default": "./lib/public/*.js"
46
52
  }
47
53
  },
@@ -1,12 +0,0 @@
1
- import Runtime from "#Runtime";
2
- import type FileRef from "@rcompat/fs/FileRef";
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
@@ -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/FileRef";
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").default<T>;
15
- }
16
- //# sourceMappingURL=Runtime.d.ts.map
@@ -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
@@ -1,9 +0,0 @@
1
- import type Dict from "@rcompat/type/Dict";
2
- type Props = {
3
- props: Dict;
4
- };
5
- export default class WebComponentsClient {
6
- static mount(view: string, props: Props): void;
7
- }
8
- export {};
9
- //# sourceMappingURL=index.d.ts.map