@moku-labs/web 0.3.0 → 0.3.1
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/index.cjs +224 -2
- package/dist/index.d.cts +303 -108
- package/dist/index.d.mts +303 -108
- package/dist/index.mjs +224 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -806,7 +806,27 @@ const coreConfig = createCoreConfig("web", {
|
|
|
806
806
|
env: { providers: [dotenv(), processEnv()] }
|
|
807
807
|
}
|
|
808
808
|
});
|
|
809
|
-
|
|
809
|
+
/**
|
|
810
|
+
* Create a custom plugin bound to this framework's `Config`/`Events` and the core
|
|
811
|
+
* plugin APIs (`log`, `env`). Plugin types are fully inferred from the spec
|
|
812
|
+
* object — never write them explicitly. This is the binding every built-in
|
|
813
|
+
* plugin is wired with, and the one consumer plugins should use too.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```ts
|
|
817
|
+
* const analytics = createPlugin("analytics", {
|
|
818
|
+
* config: { writeKey: "" },
|
|
819
|
+
* api: (ctx) => ({ track: (event: string) => ctx.log.info("analytics:track", { event }) })
|
|
820
|
+
* });
|
|
821
|
+
* ```
|
|
822
|
+
*/
|
|
823
|
+
const createPlugin$1 = coreConfig.createPlugin;
|
|
824
|
+
/**
|
|
825
|
+
* Step 2 of the factory chain — captures the framework's default plugin set and
|
|
826
|
+
* returns the consumer entry points ({@link createApp} + a re-exported
|
|
827
|
+
* `createPlugin`). Wired once in `src/index.ts`; consumers don't call it directly.
|
|
828
|
+
*/
|
|
829
|
+
const createCore = coreConfig.createCore;
|
|
810
830
|
//#endregion
|
|
811
831
|
//#region src/plugins/i18n/api.ts
|
|
812
832
|
/** Error prefix for all i18n lifecycle failures. */
|
|
@@ -934,6 +954,25 @@ function createI18nApi(ctx) {
|
|
|
934
954
|
}
|
|
935
955
|
};
|
|
936
956
|
}
|
|
957
|
+
/**
|
|
958
|
+
* Internationalization plugin — locale registry plus a flat translation helper
|
|
959
|
+
* with default-locale fallback. Pure config-as-data (no state or events);
|
|
960
|
+
* consumed read-only by content, router, head, and build.
|
|
961
|
+
*
|
|
962
|
+
* @example Register locales and translations
|
|
963
|
+
* ```ts
|
|
964
|
+
* const app = createApp({
|
|
965
|
+
* pluginConfigs: {
|
|
966
|
+
* i18n: {
|
|
967
|
+
* locales: ["en", "uk"],
|
|
968
|
+
* defaultLocale: "en",
|
|
969
|
+
* localeNames: { en: "English", uk: "Українська" },
|
|
970
|
+
* translations: { uk: { "nav.home": "Головна" } }
|
|
971
|
+
* }
|
|
972
|
+
* }
|
|
973
|
+
* });
|
|
974
|
+
* ```
|
|
975
|
+
*/
|
|
937
976
|
const i18nPlugin = createPlugin$1("i18n", {
|
|
938
977
|
config: {
|
|
939
978
|
locales: ["en"],
|
|
@@ -1729,6 +1768,26 @@ function validateContentConfig(config) {
|
|
|
1729
1768
|
* and `content:invalidated`.
|
|
1730
1769
|
* @see README.md
|
|
1731
1770
|
*/
|
|
1771
|
+
/**
|
|
1772
|
+
* Content plugin — Markdown pipeline: discovers files, parses frontmatter, renders
|
|
1773
|
+
* to sanitized HTML (rehype-sanitize unless `trustedContent`), and exposes a
|
|
1774
|
+
* locale-keyed Article model. Depends on i18n; emits `content:ready` and
|
|
1775
|
+
* `content:invalidated`.
|
|
1776
|
+
*
|
|
1777
|
+
* @example Point at a content directory and pick a Shiki theme
|
|
1778
|
+
* ```ts
|
|
1779
|
+
* const app = createApp({
|
|
1780
|
+
* pluginConfigs: {
|
|
1781
|
+
* content: {
|
|
1782
|
+
* contentDir: "./content",
|
|
1783
|
+
* shikiTheme: "github-dark",
|
|
1784
|
+
* defaultAuthor: "Ada Lovelace"
|
|
1785
|
+
* // trustedContent: true // ONLY for fully author-controlled Markdown — disables sanitize
|
|
1786
|
+
* }
|
|
1787
|
+
* }
|
|
1788
|
+
* });
|
|
1789
|
+
* ```
|
|
1790
|
+
*/
|
|
1732
1791
|
const contentPlugin = createPlugin$1("content", {
|
|
1733
1792
|
depends: [i18nPlugin],
|
|
1734
1793
|
events: contentEvents,
|
|
@@ -1892,6 +1951,25 @@ function createSiteApi(ctx) {
|
|
|
1892
1951
|
}
|
|
1893
1952
|
};
|
|
1894
1953
|
}
|
|
1954
|
+
/**
|
|
1955
|
+
* Site plugin — holds global, frozen site metadata (name, url, author,
|
|
1956
|
+
* description) and builds canonical URLs. Consumed by router, head, and build.
|
|
1957
|
+
* `name` and `url` must be non-empty (validated at `onInit`).
|
|
1958
|
+
*
|
|
1959
|
+
* @example Set your site identity
|
|
1960
|
+
* ```ts
|
|
1961
|
+
* const app = createApp({
|
|
1962
|
+
* pluginConfigs: {
|
|
1963
|
+
* site: {
|
|
1964
|
+
* name: "My Blog",
|
|
1965
|
+
* url: "https://blog.dev",
|
|
1966
|
+
* author: "Ada Lovelace",
|
|
1967
|
+
* description: "Notes on computing"
|
|
1968
|
+
* }
|
|
1969
|
+
* }
|
|
1970
|
+
* });
|
|
1971
|
+
* ```
|
|
1972
|
+
*/
|
|
1895
1973
|
const sitePlugin = createPlugin$1("site", {
|
|
1896
1974
|
config: {
|
|
1897
1975
|
name: "",
|
|
@@ -2521,6 +2599,26 @@ function defineRoutes(routes) {
|
|
|
2521
2599
|
function createState$4(_ctx) {
|
|
2522
2600
|
return { table: null };
|
|
2523
2601
|
}
|
|
2602
|
+
/**
|
|
2603
|
+
* Router plugin — typed, named route definitions with locale-aware URL generation
|
|
2604
|
+
* and matching. Author routes with {@link route} + {@link defineRoutes}. Depends
|
|
2605
|
+
* on site (base URL) and i18n (locales).
|
|
2606
|
+
*
|
|
2607
|
+
* @example Define routes and choose a render mode
|
|
2608
|
+
* ```ts
|
|
2609
|
+
* const app = createApp({
|
|
2610
|
+
* pluginConfigs: {
|
|
2611
|
+
* router: {
|
|
2612
|
+
* routes: defineRoutes({
|
|
2613
|
+
* home: route("/"),
|
|
2614
|
+
* article: route("/blog/{slug}/")
|
|
2615
|
+
* }),
|
|
2616
|
+
* mode: "hybrid" // "ssg" | "spa" | "hybrid" (default)
|
|
2617
|
+
* }
|
|
2618
|
+
* }
|
|
2619
|
+
* });
|
|
2620
|
+
* ```
|
|
2621
|
+
*/
|
|
2524
2622
|
const routerPlugin = createPlugin$1("router", {
|
|
2525
2623
|
depends: [sitePlugin, i18nPlugin],
|
|
2526
2624
|
helpers: {
|
|
@@ -3034,6 +3132,25 @@ function createState$3(_ctx) {
|
|
|
3034
3132
|
* @file head — Standard Plugin wiring harness (logic in primitives/compose/api/config).
|
|
3035
3133
|
* @see README.md
|
|
3036
3134
|
*/
|
|
3135
|
+
/**
|
|
3136
|
+
* Head plugin — composes per-route `<head>` metadata (title template, Open Graph,
|
|
3137
|
+
* Twitter cards, canonical, hreflang). Use the re-exported SEO primitives
|
|
3138
|
+
* ({@link meta}, {@link og}, {@link twitter}, …) inside a route's `.head()`.
|
|
3139
|
+
* Depends on site, i18n, and router.
|
|
3140
|
+
*
|
|
3141
|
+
* @example Set global head defaults
|
|
3142
|
+
* ```ts
|
|
3143
|
+
* const app = createApp({
|
|
3144
|
+
* pluginConfigs: {
|
|
3145
|
+
* head: {
|
|
3146
|
+
* titleTemplate: "%s — My Blog",
|
|
3147
|
+
* twitterCard: "summary_large_image",
|
|
3148
|
+
* twitterHandle: "@moku_labs"
|
|
3149
|
+
* }
|
|
3150
|
+
* }
|
|
3151
|
+
* });
|
|
3152
|
+
* ```
|
|
3153
|
+
*/
|
|
3037
3154
|
const headPlugin = createPlugin$1("head", {
|
|
3038
3155
|
depends: [
|
|
3039
3156
|
sitePlugin,
|
|
@@ -4041,6 +4158,27 @@ function createState$2(ctx) {
|
|
|
4041
4158
|
* @file build — Complex plugin: SSG orchestrator (wiring harness only).
|
|
4042
4159
|
* @see README.md
|
|
4043
4160
|
*/
|
|
4161
|
+
/**
|
|
4162
|
+
* Build plugin — the static-site-generation orchestrator. Renders every route to
|
|
4163
|
+
* `outDir`, and optionally emits feeds, a sitemap, optimized images, and OG
|
|
4164
|
+
* images. Depends on site, i18n, content, router, and head; emits `build:phase`.
|
|
4165
|
+
*
|
|
4166
|
+
* @example Configure the production build
|
|
4167
|
+
* ```ts
|
|
4168
|
+
* const app = createApp({
|
|
4169
|
+
* pluginConfigs: {
|
|
4170
|
+
* build: {
|
|
4171
|
+
* outDir: "dist",
|
|
4172
|
+
* minify: true,
|
|
4173
|
+
* feeds: true,
|
|
4174
|
+
* sitemap: true,
|
|
4175
|
+
* images: true,
|
|
4176
|
+
* ogImage: false // or an object to enable + configure OG-image generation
|
|
4177
|
+
* }
|
|
4178
|
+
* }
|
|
4179
|
+
* });
|
|
4180
|
+
* ```
|
|
4181
|
+
*/
|
|
4044
4182
|
const buildPlugin = createPlugin$1("build", {
|
|
4045
4183
|
depends: [
|
|
4046
4184
|
sitePlugin,
|
|
@@ -4840,6 +4978,24 @@ function createState$1(_ctx) {
|
|
|
4840
4978
|
* Depends: site. Emits: deploy:complete.
|
|
4841
4979
|
* @see README.md
|
|
4842
4980
|
*/
|
|
4981
|
+
/**
|
|
4982
|
+
* Deploy plugin — ships the built `outDir` to Cloudflare Pages via the injectable
|
|
4983
|
+
* wrangler subprocess, with entropy-gated secret scrubbing of logged output.
|
|
4984
|
+
* Depends on site; emits `deploy:complete`.
|
|
4985
|
+
*
|
|
4986
|
+
* @example Configure the deploy target
|
|
4987
|
+
* ```ts
|
|
4988
|
+
* const app = createApp({
|
|
4989
|
+
* pluginConfigs: {
|
|
4990
|
+
* deploy: {
|
|
4991
|
+
* target: "cloudflare-pages",
|
|
4992
|
+
* outDir: "dist",
|
|
4993
|
+
* productionBranch: "main"
|
|
4994
|
+
* }
|
|
4995
|
+
* }
|
|
4996
|
+
* });
|
|
4997
|
+
* ```
|
|
4998
|
+
*/
|
|
4843
4999
|
const deployPlugin = createPlugin$1("deploy", {
|
|
4844
5000
|
config: defaultConfig,
|
|
4845
5001
|
depends: [sitePlugin],
|
|
@@ -5812,6 +5968,26 @@ function disposeSpa() {
|
|
|
5812
5968
|
* Emits: spa:navigate, spa:navigated, spa:component-mount, spa:component-unmount.
|
|
5813
5969
|
* @see README.md
|
|
5814
5970
|
*/
|
|
5971
|
+
/**
|
|
5972
|
+
* SPA plugin — progressive client-side navigation layered over the static site:
|
|
5973
|
+
* swaps a page region on navigation, with an optional progress bar and View
|
|
5974
|
+
* Transitions. Register interactive islands with {@link createComponent}. Depends
|
|
5975
|
+
* on router and head; emits `spa:navigate`, `spa:navigated`, `spa:component-mount`,
|
|
5976
|
+
* and `spa:component-unmount`.
|
|
5977
|
+
*
|
|
5978
|
+
* @example Enable view transitions and a custom swap region
|
|
5979
|
+
* ```ts
|
|
5980
|
+
* const app = createApp({
|
|
5981
|
+
* pluginConfigs: {
|
|
5982
|
+
* spa: {
|
|
5983
|
+
* swapSelector: "main > section",
|
|
5984
|
+
* viewTransitions: true,
|
|
5985
|
+
* progressBar: true
|
|
5986
|
+
* }
|
|
5987
|
+
* }
|
|
5988
|
+
* });
|
|
5989
|
+
* ```
|
|
5990
|
+
*/
|
|
5815
5991
|
const spaPlugin = createPlugin$1("spa", {
|
|
5816
5992
|
depends: [routerPlugin, headPlugin],
|
|
5817
5993
|
config: defaultSpaConfig,
|
|
@@ -5846,7 +6022,13 @@ var types_exports$5 = /* @__PURE__ */ __exportAll({});
|
|
|
5846
6022
|
//#endregion
|
|
5847
6023
|
//#region src/plugins/router/types.ts
|
|
5848
6024
|
var types_exports$6 = /* @__PURE__ */ __exportAll({});
|
|
5849
|
-
|
|
6025
|
+
//#endregion
|
|
6026
|
+
//#region src/index.ts
|
|
6027
|
+
/**
|
|
6028
|
+
* @file `@moku-labs/web` — a Moku Layer-2 content static-site + SPA framework.
|
|
6029
|
+
* @see README.md
|
|
6030
|
+
*/
|
|
6031
|
+
const framework = createCore(coreConfig, {
|
|
5850
6032
|
plugins: [
|
|
5851
6033
|
sitePlugin,
|
|
5852
6034
|
i18nPlugin,
|
|
@@ -5859,5 +6041,45 @@ const { createApp, createPlugin } = createCore(coreConfig, {
|
|
|
5859
6041
|
],
|
|
5860
6042
|
pluginConfigs: {}
|
|
5861
6043
|
});
|
|
6044
|
+
/**
|
|
6045
|
+
* Create and initialize a `@moku-labs/web` application — the Layer-3 entry point.
|
|
6046
|
+
* Your overrides are merged over the framework defaults through the 4-level config
|
|
6047
|
+
* cascade, every plugin's lifecycle runs, and a fully-typed, frozen app is returned.
|
|
6048
|
+
*
|
|
6049
|
+
* @param options - Optional configuration:
|
|
6050
|
+
* - `pluginConfigs` — per-plugin overrides, keyed by plugin name
|
|
6051
|
+
* (`site`, `i18n`, `router`, `content`, `head`, `build`, `spa`, `deploy`, `env`).
|
|
6052
|
+
* - `config` — global framework config (e.g. `{ mode: "development" }`).
|
|
6053
|
+
* - `plugins` — extra consumer plugins, merged into the app and its return type.
|
|
6054
|
+
* - `onReady` / `onError` / `onStart` / `onStop` — lifecycle callbacks.
|
|
6055
|
+
* @returns The initialized app: `start()`, `stop()`, every plugin's API, and `log`.
|
|
6056
|
+
* @example
|
|
6057
|
+
* ```ts
|
|
6058
|
+
* const app = createApp({
|
|
6059
|
+
* pluginConfigs: {
|
|
6060
|
+
* site: { name: "My Blog", url: "https://blog.dev", author: "Ada", description: "Notes" },
|
|
6061
|
+
* router: { routes: defineRoutes({ home: route("/"), post: route("/blog/{slug}/") }) }
|
|
6062
|
+
* }
|
|
6063
|
+
* });
|
|
6064
|
+
* await app.start();
|
|
6065
|
+
* ```
|
|
6066
|
+
*/
|
|
6067
|
+
const createApp = framework.createApp;
|
|
6068
|
+
/**
|
|
6069
|
+
* Create a custom plugin bound to this framework's `Config`/`Events` and core
|
|
6070
|
+
* APIs. Plugin types are inferred from the spec object — never written explicitly.
|
|
6071
|
+
* Pass the result to {@link createApp} via `plugins`.
|
|
6072
|
+
*
|
|
6073
|
+
* @example
|
|
6074
|
+
* ```ts
|
|
6075
|
+
* const analytics = createPlugin("analytics", {
|
|
6076
|
+
* config: { writeKey: "" },
|
|
6077
|
+
* api: (ctx) => ({ track: (event: string) => ctx.log.info("analytics:track", { event }) })
|
|
6078
|
+
* });
|
|
6079
|
+
*
|
|
6080
|
+
* const app = createApp({ plugins: [analytics] });
|
|
6081
|
+
* ```
|
|
6082
|
+
*/
|
|
6083
|
+
const createPlugin = framework.createPlugin;
|
|
5862
6084
|
//#endregion
|
|
5863
6085
|
export { types_exports as Build, types_exports$1 as Content, types_exports$2 as Deploy, types_exports$3 as Env, types_exports$4 as Head, types_exports$5 as Log, types_exports$6 as Router, types_exports$7 as Spa, buildArticleHead, buildPlugin, canonical, contentPlugin, createApp, createPlugin, defineRoutes, deployPlugin, envPlugin, feedLink, headPlugin, hreflang, i18nPlugin, jsonLd, logPlugin, meta, og, route, routerPlugin, sitePlugin, spaPlugin, twitter };
|
package/package.json
CHANGED