bun-plugin-stx 0.1.12 → 0.1.16
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/dist/chunk-h0s48z3v.js +3 -0
- package/dist/chunk-mjj2b826.js +678 -0
- package/dist/client.js +1 -143
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -9712
- package/dist/preload.d.ts +0 -0
- package/dist/preload.js +2 -0
- package/dist/serve.d.ts +0 -0
- package/dist/serve.js +41 -0
- package/package.json +12 -2
package/dist/client.js
CHANGED
|
@@ -1,144 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __export = (target, all) => {
|
|
19
|
-
for (var name in all)
|
|
20
|
-
__defProp(target, name, {
|
|
21
|
-
get: all[name],
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
set: (newValue) => all[name] = () => newValue
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
28
|
-
var __promiseAll = (args) => Promise.all(args);
|
|
29
|
-
var __require = import.meta.require;
|
|
30
|
-
|
|
31
|
-
// src/client.ts
|
|
32
|
-
var version = "1.0.0";
|
|
33
|
-
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
34
|
-
async function hydrateIsland(element, name, handler) {
|
|
35
|
-
if (!isBrowser)
|
|
36
|
-
return;
|
|
37
|
-
try {
|
|
38
|
-
const id = element.getAttribute("data-island-id");
|
|
39
|
-
const propsScript = document.querySelector(`script[data-island-props="${id}"]`);
|
|
40
|
-
const props = propsScript ? JSON.parse(propsScript.textContent || "{}") : {};
|
|
41
|
-
const module = await handler();
|
|
42
|
-
const hydrateFn = module.default || module.hydrate;
|
|
43
|
-
if (typeof hydrateFn !== "function") {
|
|
44
|
-
console.error(`Island handler for "${name}" does not export a valid hydration function`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
await hydrateFn(element, props);
|
|
48
|
-
element.setAttribute("data-hydrated", "true");
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error(`Failed to hydrate island "${name}":`, error);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function hydrateIslands(handlers) {
|
|
54
|
-
if (!isBrowser)
|
|
55
|
-
return;
|
|
56
|
-
const islands = document.querySelectorAll("[data-island]");
|
|
57
|
-
const lazyIslands = [];
|
|
58
|
-
islands.forEach((island) => {
|
|
59
|
-
const name = island.getAttribute("data-island");
|
|
60
|
-
const priority = island.getAttribute("data-priority") || "lazy";
|
|
61
|
-
if (!name || !handlers[name] || island.getAttribute("data-hydrated") === "true") {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (priority === "eager") {
|
|
65
|
-
hydrateIsland(island, name, handlers[name]);
|
|
66
|
-
} else {
|
|
67
|
-
lazyIslands.push([island, name]);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
if (lazyIslands.length > 0 && "IntersectionObserver" in window) {
|
|
71
|
-
const observer = new IntersectionObserver((entries) => {
|
|
72
|
-
entries.forEach((entry) => {
|
|
73
|
-
if (entry.isIntersecting) {
|
|
74
|
-
const element = entry.target;
|
|
75
|
-
const name = element.getAttribute("data-island");
|
|
76
|
-
if (name && handlers[name] && element.getAttribute("data-hydrated") !== "true") {
|
|
77
|
-
hydrateIsland(element, name, handlers[name]);
|
|
78
|
-
observer.unobserve(element);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}, {
|
|
83
|
-
rootMargin: "200px",
|
|
84
|
-
threshold: 0
|
|
85
|
-
});
|
|
86
|
-
lazyIslands.forEach(([element]) => {
|
|
87
|
-
observer.observe(element);
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
setTimeout(() => {
|
|
91
|
-
lazyIslands.forEach(([element, name]) => {
|
|
92
|
-
if (element.getAttribute("data-hydrated") !== "true") {
|
|
93
|
-
hydrateIsland(element, name, handlers[name]);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}, 1000);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function preloadIslandHandlers(handlers) {
|
|
100
|
-
if (!isBrowser)
|
|
101
|
-
return;
|
|
102
|
-
Object.entries(handlers).forEach(([name, getHandler]) => {
|
|
103
|
-
try {
|
|
104
|
-
const handlerString = getHandler.toString();
|
|
105
|
-
const moduleMatch = handlerString.match(/import\(['"](.+)['"]\)/);
|
|
106
|
-
if (moduleMatch && moduleMatch[1]) {
|
|
107
|
-
const link = document.createElement("link");
|
|
108
|
-
link.rel = "modulepreload";
|
|
109
|
-
link.href = moduleMatch[1];
|
|
110
|
-
link.setAttribute("data-island-module", name);
|
|
111
|
-
document.head.appendChild(link);
|
|
112
|
-
}
|
|
113
|
-
} catch (error) {
|
|
114
|
-
console.warn(`Failed to preload island handler for "${name}":`, error);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
function initIslands(handlers, config = {}) {
|
|
119
|
-
if (!isBrowser)
|
|
120
|
-
return;
|
|
121
|
-
const defaultConfig = {
|
|
122
|
-
autoStart: true,
|
|
123
|
-
preload: "lazy"
|
|
124
|
-
};
|
|
125
|
-
const options = { ...defaultConfig, ...config };
|
|
126
|
-
if (options.preload !== "none") {
|
|
127
|
-
preloadIslandHandlers(handlers);
|
|
128
|
-
}
|
|
129
|
-
if (options.autoStart) {
|
|
130
|
-
if (document.readyState === "loading") {
|
|
131
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
132
|
-
hydrateIslands(handlers);
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
hydrateIslands(handlers);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
export {
|
|
140
|
-
version,
|
|
141
|
-
preloadIslandHandlers,
|
|
142
|
-
initIslands,
|
|
143
|
-
hydrateIslands
|
|
144
|
-
};
|
|
2
|
+
import"./chunk-h0s48z3v.js";var R="1.0.0",L=typeof window<"u"&&typeof document<"u";async function N(x,E,G){if(!L)return;try{let j=x.getAttribute("data-island-id"),q=document.querySelector(`script[data-island-props="${j}"]`),C=q?JSON.parse(q.textContent||"{}"):{},J=await G(),K=J.default||J.hydrate;if(typeof K!=="function"){console.error(`Island handler for "${E}" does not export a valid hydration function`);return}await K(x,C),x.setAttribute("data-hydrated","true")}catch(j){console.error(`Failed to hydrate island "${E}":`,j)}}function P(x){if(!L)return;let E=document.querySelectorAll("[data-island]"),G=[];if(E.forEach((j)=>{let q=j.getAttribute("data-island"),C=j.getAttribute("data-priority")||"lazy";if(!q||!x[q]||j.getAttribute("data-hydrated")==="true")return;if(C==="eager")N(j,q,x[q]);else G.push([j,q])}),G.length>0&&"IntersectionObserver"in window){let j=new IntersectionObserver((q)=>{q.forEach((C)=>{if(C.isIntersecting){let J=C.target,K=J.getAttribute("data-island");if(K&&x[K]&&J.getAttribute("data-hydrated")!=="true")N(J,K,x[K]),j.unobserve(J)}})},{rootMargin:"200px",threshold:0});G.forEach(([q])=>{j.observe(q)})}else setTimeout(()=>{G.forEach(([j,q])=>{if(j.getAttribute("data-hydrated")!=="true")N(j,q,x[q])})},1000)}function Q(x){if(!L)return;Object.entries(x).forEach(([E,G])=>{try{let q=G.toString().match(/import\(['"](.+)['"]\)/);if(q&&q[1]){let C=document.createElement("link");C.rel="modulepreload",C.href=q[1],C.setAttribute("data-island-module",E),document.head.appendChild(C)}}catch(j){console.warn(`Failed to preload island handler for "${E}":`,j)}})}function T(x,E={}){if(!L)return;let j={...{autoStart:!0,preload:"lazy"},...E};if(j.preload!=="none")Q(x);if(j.autoStart)if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>{P(x)});else P(x)}export{R as version,Q as preloadIslandHandlers,T as initIslands,P as hydrateIslands};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { BunPlugin } from 'bun';
|
|
2
|
+
import { readMarkdownFile } from '@stacksjs/stx';
|
|
2
3
|
import type { StxOptions } from '@stacksjs/stx';
|
|
4
|
+
export type { ServeOptions, ServeResult, StxOptions } from '@stacksjs/stx';
|
|
3
5
|
export declare function stxPlugin(userOptions?: StxOptions): BunPlugin;
|
|
6
|
+
export { createMiddleware, createRoute, readMarkdownFile, serve } from '@stacksjs/stx';
|
|
4
7
|
export default stxPlugin;
|