@fictjs/ssr 0.18.0 → 0.20.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.
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/stream-runtime.ts
21
+ var stream_runtime_exports = {};
22
+ __export(stream_runtime_exports, {
23
+ FICT_STREAM_RUNTIME_CODE: () => FICT_STREAM_RUNTIME_CODE,
24
+ createStreamRuntimeCode: () => createStreamRuntimeCode
25
+ });
26
+ module.exports = __toCommonJS(stream_runtime_exports);
27
+ function createStreamRuntimeCode(options = {}) {
28
+ const observerMode = options.observerMode ?? true;
29
+ return `(function(){if(window.__FICT_STREAM)return;var cache=new Map();function find(id){var hit=cache.get(id);if(hit)return hit;var start=null,end=null;var w=document.createTreeWalker(document,NodeFilter.SHOW_COMMENT);while(w.nextNode()){var n=w.currentNode;var d=n.data;if(d==="fict:suspense-start:"+id)start=n;else if(d==="fict:suspense-end:"+id)end=n;if(start&&end)break;}if(start&&end){hit={start:start,end:end};cache.set(id,hit);}return hit;}function apply(id){var tpl=document.querySelector('template[data-fict-suspense="' + id + '"]');if(!tpl)return;var b=find(id);if(!b)return;var node=b.start.nextSibling;while(node&&node!==b.end){var next=node.nextSibling;node.parentNode&&node.parentNode.removeChild(node);node=next;}b.end.parentNode&&b.end.parentNode.insertBefore(tpl.content,b.end);tpl.parentNode&&tpl.parentNode.removeChild(tpl);}window.__FICT_STREAM={apply:apply};` + (observerMode ? 'function scan(root){var list=(root&&root.querySelectorAll?root:document).querySelectorAll("template[data-fict-suspense]");for(var i=0;i<list.length;i++){apply(list[i].getAttribute("data-fict-suspense"));}}if(typeof MutationObserver==="function"){new MutationObserver(function(muts){for(var i=0;i<muts.length;i++){for(var j=0;j<muts[i].addedNodes.length;j++){var n=muts[i].addedNodes[j];if(n.nodeType===1){if(n.matches&&n.matches("template[data-fict-suspense]"))apply(n.getAttribute("data-fict-suspense"));scan(n);}}}}).observe(document.documentElement||document,{childList:true,subtree:true});}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){scan(document);},{once:true});}else{scan(document);}' : "") + "})();";
30
+ }
31
+ var FICT_STREAM_RUNTIME_CODE = createStreamRuntimeCode({ observerMode: true });
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ FICT_STREAM_RUNTIME_CODE,
35
+ createStreamRuntimeCode
36
+ });
@@ -0,0 +1,16 @@
1
+ interface StreamRuntimeCodeOptions {
2
+ /**
3
+ * Enable observer mode so patch templates are applied without per-chunk inline scripts.
4
+ */
5
+ observerMode?: boolean;
6
+ }
7
+ /**
8
+ * Create the browser-side streaming patch runtime as classic-script JavaScript.
9
+ *
10
+ * The generated package asset `@fictjs/ssr/fict-stream-runtime.js` is built from
11
+ * this helper with `observerMode: true`.
12
+ */
13
+ declare function createStreamRuntimeCode(options?: StreamRuntimeCodeOptions): string;
14
+ declare const FICT_STREAM_RUNTIME_CODE: string;
15
+
16
+ export { FICT_STREAM_RUNTIME_CODE, type StreamRuntimeCodeOptions, createStreamRuntimeCode };
@@ -0,0 +1,16 @@
1
+ interface StreamRuntimeCodeOptions {
2
+ /**
3
+ * Enable observer mode so patch templates are applied without per-chunk inline scripts.
4
+ */
5
+ observerMode?: boolean;
6
+ }
7
+ /**
8
+ * Create the browser-side streaming patch runtime as classic-script JavaScript.
9
+ *
10
+ * The generated package asset `@fictjs/ssr/fict-stream-runtime.js` is built from
11
+ * this helper with `observerMode: true`.
12
+ */
13
+ declare function createStreamRuntimeCode(options?: StreamRuntimeCodeOptions): string;
14
+ declare const FICT_STREAM_RUNTIME_CODE: string;
15
+
16
+ export { FICT_STREAM_RUNTIME_CODE, type StreamRuntimeCodeOptions, createStreamRuntimeCode };
@@ -0,0 +1,8 @@
1
+ import {
2
+ FICT_STREAM_RUNTIME_CODE,
3
+ createStreamRuntimeCode
4
+ } from "./chunk-DI4PFT6R.js";
5
+ export {
6
+ FICT_STREAM_RUNTIME_CODE,
7
+ createStreamRuntimeCode
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fictjs/ssr",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "Fict server-side rendering",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -20,18 +20,24 @@
20
20
  "types": "./dist/index.d.ts",
21
21
  "import": "./dist/index.js",
22
22
  "require": "./dist/index.cjs"
23
- }
23
+ },
24
+ "./stream-runtime": {
25
+ "types": "./dist/stream-runtime.d.ts",
26
+ "import": "./dist/stream-runtime.js",
27
+ "require": "./dist/stream-runtime.cjs"
28
+ },
29
+ "./fict-stream-runtime.js": "./dist/fict-stream-runtime.js"
24
30
  },
25
31
  "files": [
26
32
  "dist"
27
33
  ],
28
34
  "dependencies": {
29
35
  "linkedom": "^0.18.12",
30
- "@fictjs/runtime": "0.18.0"
36
+ "@fictjs/runtime": "0.20.0"
31
37
  },
32
38
  "devDependencies": {
33
39
  "tsup": "^8.5.1",
34
- "fict": "0.18.0"
40
+ "fict": "0.20.0"
35
41
  },
36
42
  "keywords": [
37
43
  "fict",
@@ -43,10 +49,12 @@
43
49
  "author": "unadlib",
44
50
  "license": "MIT",
45
51
  "scripts": {
46
- "build": "tsup src/index.ts --format cjs,esm --dts",
47
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
52
+ "build": "tsup src/index.ts src/stream-runtime.ts --format cjs,esm --dts && pnpm run build:stream-runtime",
53
+ "build:stream-runtime": "node scripts/write-stream-runtime-asset.mjs",
54
+ "dev": "tsup src/index.ts src/stream-runtime.ts --format cjs,esm --dts --watch --onSuccess \"pnpm run build:stream-runtime\"",
48
55
  "test": "vitest run",
49
56
  "test:edge": "node test/edge-runtime.smoke.mjs",
57
+ "test:matrix": "pnpm run test && pnpm run test:edge",
50
58
  "test:coverage": "vitest run --coverage",
51
59
  "lint": "eslint src",
52
60
  "typecheck": "tsc --noEmit",