@revojs/client 0.2.7 → 0.2.9

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.
@@ -0,0 +1,8 @@
1
+ export declare function createClientScope(variables?: object, states?: Record<string, unknown>): Promise<{
2
+ hooks?: {
3
+ [x: string]: ArrayLike<import("revojs").Hook> | undefined;
4
+ } | undefined;
5
+ context?: {
6
+ [x: string]: {} | undefined;
7
+ } | undefined;
8
+ } & import("revojs").Scope>;
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import { STATE_CONTEXT, VARIABLE_CONTEXT, createScope } from "revojs";
2
+ //#region src/index.ts
3
+ function createClientScope(variables = {}, states) {
4
+ if (states === void 0) {
5
+ const content = globalThis.document?.getElementById("states")?.textContent?.trim();
6
+ const value = content ? JSON.parse(content) : {};
7
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("Client hydration state must be an object");
8
+ states = value;
9
+ }
10
+ return createScope({ context: {
11
+ [VARIABLE_CONTEXT]: variables,
12
+ [STATE_CONTEXT]: states
13
+ } });
14
+ }
15
+ //#endregion
16
+ export { createClientScope };
@@ -9,6 +9,7 @@ export interface ClientConfig {
9
9
  html: Record<HtmlTags, HtmlTag>;
10
10
  }
11
11
  export declare function toHtmlTagDescriptor(htmlTag: HtmlTag, injectTo: HtmlTagDescriptor["injectTo"]): HtmlTagDescriptor;
12
+ export declare function cssImportSpecifiers(children: Array<string>): Array<string> | undefined;
12
13
  declare const _default: import("revojs/module").Module<"client", ClientConfig, []>;
13
14
  export default _default;
14
15
  export declare const CLIENT = "client";
@@ -21,6 +21,16 @@ function toHtmlTagDescriptor(htmlTag, injectTo) {
21
21
  injectTo
22
22
  };
23
23
  }
24
+ function cssImportSpecifiers(children) {
25
+ const specifiers = new Array();
26
+ for (const statement of children.join("").split(";")) {
27
+ if (statement.trim() === "") continue;
28
+ const specifier = /^import\s*["']([^"']+)["']$/.exec(statement.trim())?.[1];
29
+ if (specifier === void 0 || !specifier.endsWith(".css")) return;
30
+ specifiers.push(specifier);
31
+ }
32
+ return specifiers.length > 0 ? specifiers : void 0;
33
+ }
24
34
  var module_default = defineModule({
25
35
  name: "client",
26
36
  config: () => ({ html: {
@@ -65,6 +75,19 @@ var module_default = defineModule({
65
75
  if (typeof entry === "string" || entry.tagName !== "script" || entry.attributes.type !== "module") return entry;
66
76
  const children = entry.children.filter((child) => typeof child === "string");
67
77
  if (children.length === 0 || children.length !== entry.children.length) return entry;
78
+ const specifiers = cssImportSpecifiers(children);
79
+ if (specifiers) {
80
+ const name = `client-entry/${index++}.css`;
81
+ addVirtual(config, name, () => specifiers.map((specifier) => `@import ${JSON.stringify(specifier)};`).join("\n"));
82
+ return {
83
+ tagName: "link",
84
+ attributes: {
85
+ rel: "stylesheet",
86
+ href: `/@id/__x00__${name}`
87
+ },
88
+ children: []
89
+ };
90
+ }
68
91
  const name = `client-entry/${index++}.js`;
69
92
  addVirtual(config, name, () => children.join(""));
70
93
  return {
@@ -124,4 +147,4 @@ var module_default = defineModule({
124
147
  var CLIENT = "client";
125
148
  var CLIENT_SUFFIX = "?client";
126
149
  //#endregion
127
- export { CLIENT, CLIENT_SUFFIX, module_default as default, toHtmlTagDescriptor };
150
+ export { CLIENT, CLIENT_SUFFIX, cssImportSpecifiers, module_default as default, toHtmlTagDescriptor };
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@revojs/client";
3
- var version = "0.2.7";
3
+ var version = "0.2.9";
4
4
  var repository = {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/tellua/revojs.git"
@@ -22,6 +22,7 @@ var exports = {
22
22
  };
23
23
  var scripts = {
24
24
  "build": "vite build",
25
+ "typecheck": "tsc --noEmit -p tsconfig.json",
25
26
  "watch": "vite build --watch"
26
27
  };
27
28
  var dependencies = { "revojs": "*" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/client",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,6 +25,7 @@
25
25
  },
26
26
  "scripts": {
27
27
  "build": "vite build",
28
+ "typecheck": "tsc --noEmit -p tsconfig.json",
28
29
  "watch": "vite build --watch"
29
30
  },
30
31
  "dependencies": {