@moku-labs/web 0.5.2 → 0.5.4

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/browser.mjs CHANGED
@@ -633,18 +633,28 @@ function createLogApi(ctx) {
633
633
  }
634
634
  //#endregion
635
635
  //#region src/plugins/log/sinks.ts
636
+ /** Severity rank for threshold comparison (higher = more severe). */
637
+ const LEVEL_RANK = {
638
+ debug: 10,
639
+ info: 20,
640
+ warn: 30,
641
+ error: 40
642
+ };
636
643
  /**
637
644
  * Build the console sink: routes entries by channel — `error` → `console.error`,
638
645
  * `warn` → `console.warn`, and `debug`/`info` → `console.log`. The full entry
639
- * object is forwarded so the console serializes its `event` and `data`.
646
+ * object is forwarded so the console serializes its `event` and `data`. Entries
647
+ * below `minLevel` are dropped (the in-memory trace still records everything).
640
648
  *
649
+ * @param minLevel - Lowest severity to print. Defaults to `"debug"` (print all).
641
650
  * @returns A {@link LogSink} that writes to the matching `console` channel.
642
651
  * @example
643
652
  * ```ts
644
- * state.sinks.push(consoleSink());
653
+ * state.sinks.push(consoleSink("info")); // suppress debug spam
645
654
  * ```
646
655
  */
647
- function consoleSink() {
656
+ function consoleSink(minLevel = "debug") {
657
+ const threshold = LEVEL_RANK[minLevel];
648
658
  return {
649
659
  /**
650
660
  * Route a single entry to the console channel matching its level.
@@ -656,6 +666,7 @@ function consoleSink() {
656
666
  * ```
657
667
  */
658
668
  write(entry) {
669
+ if (LEVEL_RANK[entry.level] < threshold) return;
659
670
  if (entry.level === "error") console.error(entry);
660
671
  else if (entry.level === "warn") console.warn(entry);
661
672
  else console.log(entry);
@@ -663,18 +674,22 @@ write(entry) {
663
674
  }
664
675
  /**
665
676
  * Install mode-selected default sinks at onInit. The in-memory trace is always
666
- * on (`state.entries`); the console sink is added only in dev/production.
677
+ * on (`state.entries`); the console sink is added only in dev/production. `dev`
678
+ * prints everything (debug+); `production` prints `info`+ only, so the per-phase
679
+ * `debug` events (build:bundle, build:pages, …) don't spam a prod build. Both
680
+ * modes still record all levels in the in-memory trace.
667
681
  *
668
682
  * @param ctx - Core plugin context (`{ config, state }`).
669
683
  * @param ctx.config - Resolved log config (`{ mode }`).
670
684
  * @param ctx.state - Mutable log state (`{ entries, sinks }`).
671
685
  * @example
672
686
  * ```ts
673
- * // mode "dev" -> state.sinks === [consoleSink()]; mode "test" -> state.sinks === []
687
+ * // "dev" -> [consoleSink("debug")]; "production" -> [consoleSink("info")]; "test"/"silent" -> []
674
688
  * ```
675
689
  */
676
690
  function installDefaultSinks(ctx) {
677
- if (ctx.config.mode === "dev" || ctx.config.mode === "production") ctx.state.sinks.push(consoleSink());
691
+ if (ctx.config.mode === "dev") ctx.state.sinks.push(consoleSink("debug"));
692
+ else if (ctx.config.mode === "production") ctx.state.sinks.push(consoleSink("info"));
678
693
  }
679
694
  //#endregion
680
695
  //#region src/plugins/log/state.ts
package/dist/index.cjs CHANGED
@@ -667,18 +667,28 @@ function createLogApi(ctx) {
667
667
  }
668
668
  //#endregion
669
669
  //#region src/plugins/log/sinks.ts
670
+ /** Severity rank for threshold comparison (higher = more severe). */
671
+ const LEVEL_RANK = {
672
+ debug: 10,
673
+ info: 20,
674
+ warn: 30,
675
+ error: 40
676
+ };
670
677
  /**
671
678
  * Build the console sink: routes entries by channel — `error` → `console.error`,
672
679
  * `warn` → `console.warn`, and `debug`/`info` → `console.log`. The full entry
673
- * object is forwarded so the console serializes its `event` and `data`.
680
+ * object is forwarded so the console serializes its `event` and `data`. Entries
681
+ * below `minLevel` are dropped (the in-memory trace still records everything).
674
682
  *
683
+ * @param minLevel - Lowest severity to print. Defaults to `"debug"` (print all).
675
684
  * @returns A {@link LogSink} that writes to the matching `console` channel.
676
685
  * @example
677
686
  * ```ts
678
- * state.sinks.push(consoleSink());
687
+ * state.sinks.push(consoleSink("info")); // suppress debug spam
679
688
  * ```
680
689
  */
681
- function consoleSink() {
690
+ function consoleSink(minLevel = "debug") {
691
+ const threshold = LEVEL_RANK[minLevel];
682
692
  return {
683
693
  /**
684
694
  * Route a single entry to the console channel matching its level.
@@ -690,6 +700,7 @@ function consoleSink() {
690
700
  * ```
691
701
  */
692
702
  write(entry) {
703
+ if (LEVEL_RANK[entry.level] < threshold) return;
693
704
  if (entry.level === "error") console.error(entry);
694
705
  else if (entry.level === "warn") console.warn(entry);
695
706
  else console.log(entry);
@@ -697,18 +708,22 @@ write(entry) {
697
708
  }
698
709
  /**
699
710
  * Install mode-selected default sinks at onInit. The in-memory trace is always
700
- * on (`state.entries`); the console sink is added only in dev/production.
711
+ * on (`state.entries`); the console sink is added only in dev/production. `dev`
712
+ * prints everything (debug+); `production` prints `info`+ only, so the per-phase
713
+ * `debug` events (build:bundle, build:pages, …) don't spam a prod build. Both
714
+ * modes still record all levels in the in-memory trace.
701
715
  *
702
716
  * @param ctx - Core plugin context (`{ config, state }`).
703
717
  * @param ctx.config - Resolved log config (`{ mode }`).
704
718
  * @param ctx.state - Mutable log state (`{ entries, sinks }`).
705
719
  * @example
706
720
  * ```ts
707
- * // mode "dev" -> state.sinks === [consoleSink()]; mode "test" -> state.sinks === []
721
+ * // "dev" -> [consoleSink("debug")]; "production" -> [consoleSink("info")]; "test"/"silent" -> []
708
722
  * ```
709
723
  */
710
724
  function installDefaultSinks(ctx) {
711
- if (ctx.config.mode === "dev" || ctx.config.mode === "production") ctx.state.sinks.push(consoleSink());
725
+ if (ctx.config.mode === "dev") ctx.state.sinks.push(consoleSink("debug"));
726
+ else if (ctx.config.mode === "production") ctx.state.sinks.push(consoleSink("info"));
712
727
  }
713
728
  //#endregion
714
729
  //#region src/plugins/log/state.ts
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ComponentChildren, VNode } from "preact";
2
2
  import { EmitFn } from "@moku-labs/core";
3
+ import { BundledTheme, ThemeRegistrationAny } from "shiki";
3
4
  import { Pluggable, Processor } from "unified";
4
5
 
5
6
  //#region \0rolldown/runtime.js
@@ -1680,8 +1681,15 @@ type Config$1 = {
1680
1681
  */
1681
1682
  trustedContent: boolean; /** Additional remark plugins, concatenated AFTER framework defaults. Defaults to []. */
1682
1683
  extraRemarkPlugins?: readonly Pluggable[]; /** Additional rehype plugins, concatenated after custom transforms, before Shiki + sanitize. Defaults to []. */
1683
- extraRehypePlugins?: readonly Pluggable[]; /** Shiki theme name for syntax highlighting. Defaults to "github-dark". */
1684
- shikiTheme?: string; /** Author applied to articles whose frontmatter omits author. Defaults to undefined. */
1684
+ extraRehypePlugins?: readonly Pluggable[];
1685
+ /**
1686
+ * Shiki theme for syntax highlighting: a bundled theme NAME — typed as Shiki's
1687
+ * `BundledTheme` union so editors autocomplete the ~60 built-ins (default
1688
+ * "github-dark") — or a custom `ThemeRegistration` object. Passed straight through
1689
+ * to `@shikijs/rehype`'s `theme`. (Like Shiki's own theme type, an arbitrary string
1690
+ * still compiles via the object arm, so this is autocomplete, not typo-rejection.)
1691
+ */
1692
+ shikiTheme?: BundledTheme | ThemeRegistrationAny; /** Author applied to articles whose frontmatter omits author. Defaults to undefined. */
1685
1693
  defaultAuthor?: string;
1686
1694
  };
1687
1695
  /**
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { EmitFn } from "@moku-labs/core";
2
2
  import { Pluggable, Processor } from "unified";
3
3
  import { ComponentChildren, VNode } from "preact";
4
+ import { BundledTheme, ThemeRegistrationAny } from "shiki";
4
5
 
5
6
  //#region src/plugins/log/types.d.ts
6
7
  declare namespace types_d_exports$6 {
@@ -1680,8 +1681,15 @@ type Config$1 = {
1680
1681
  */
1681
1682
  trustedContent: boolean; /** Additional remark plugins, concatenated AFTER framework defaults. Defaults to []. */
1682
1683
  extraRemarkPlugins?: readonly Pluggable[]; /** Additional rehype plugins, concatenated after custom transforms, before Shiki + sanitize. Defaults to []. */
1683
- extraRehypePlugins?: readonly Pluggable[]; /** Shiki theme name for syntax highlighting. Defaults to "github-dark". */
1684
- shikiTheme?: string; /** Author applied to articles whose frontmatter omits author. Defaults to undefined. */
1684
+ extraRehypePlugins?: readonly Pluggable[];
1685
+ /**
1686
+ * Shiki theme for syntax highlighting: a bundled theme NAME — typed as Shiki's
1687
+ * `BundledTheme` union so editors autocomplete the ~60 built-ins (default
1688
+ * "github-dark") — or a custom `ThemeRegistration` object. Passed straight through
1689
+ * to `@shikijs/rehype`'s `theme`. (Like Shiki's own theme type, an arbitrary string
1690
+ * still compiles via the object arm, so this is autocomplete, not typo-rejection.)
1691
+ */
1692
+ shikiTheme?: BundledTheme | ThemeRegistrationAny; /** Author applied to articles whose frontmatter omits author. Defaults to undefined. */
1685
1693
  defaultAuthor?: string;
1686
1694
  };
1687
1695
  /**
package/dist/index.mjs CHANGED
@@ -654,18 +654,28 @@ function createLogApi(ctx) {
654
654
  }
655
655
  //#endregion
656
656
  //#region src/plugins/log/sinks.ts
657
+ /** Severity rank for threshold comparison (higher = more severe). */
658
+ const LEVEL_RANK = {
659
+ debug: 10,
660
+ info: 20,
661
+ warn: 30,
662
+ error: 40
663
+ };
657
664
  /**
658
665
  * Build the console sink: routes entries by channel — `error` → `console.error`,
659
666
  * `warn` → `console.warn`, and `debug`/`info` → `console.log`. The full entry
660
- * object is forwarded so the console serializes its `event` and `data`.
667
+ * object is forwarded so the console serializes its `event` and `data`. Entries
668
+ * below `minLevel` are dropped (the in-memory trace still records everything).
661
669
  *
670
+ * @param minLevel - Lowest severity to print. Defaults to `"debug"` (print all).
662
671
  * @returns A {@link LogSink} that writes to the matching `console` channel.
663
672
  * @example
664
673
  * ```ts
665
- * state.sinks.push(consoleSink());
674
+ * state.sinks.push(consoleSink("info")); // suppress debug spam
666
675
  * ```
667
676
  */
668
- function consoleSink() {
677
+ function consoleSink(minLevel = "debug") {
678
+ const threshold = LEVEL_RANK[minLevel];
669
679
  return {
670
680
  /**
671
681
  * Route a single entry to the console channel matching its level.
@@ -677,6 +687,7 @@ function consoleSink() {
677
687
  * ```
678
688
  */
679
689
  write(entry) {
690
+ if (LEVEL_RANK[entry.level] < threshold) return;
680
691
  if (entry.level === "error") console.error(entry);
681
692
  else if (entry.level === "warn") console.warn(entry);
682
693
  else console.log(entry);
@@ -684,18 +695,22 @@ write(entry) {
684
695
  }
685
696
  /**
686
697
  * Install mode-selected default sinks at onInit. The in-memory trace is always
687
- * on (`state.entries`); the console sink is added only in dev/production.
698
+ * on (`state.entries`); the console sink is added only in dev/production. `dev`
699
+ * prints everything (debug+); `production` prints `info`+ only, so the per-phase
700
+ * `debug` events (build:bundle, build:pages, …) don't spam a prod build. Both
701
+ * modes still record all levels in the in-memory trace.
688
702
  *
689
703
  * @param ctx - Core plugin context (`{ config, state }`).
690
704
  * @param ctx.config - Resolved log config (`{ mode }`).
691
705
  * @param ctx.state - Mutable log state (`{ entries, sinks }`).
692
706
  * @example
693
707
  * ```ts
694
- * // mode "dev" -> state.sinks === [consoleSink()]; mode "test" -> state.sinks === []
708
+ * // "dev" -> [consoleSink("debug")]; "production" -> [consoleSink("info")]; "test"/"silent" -> []
695
709
  * ```
696
710
  */
697
711
  function installDefaultSinks(ctx) {
698
- if (ctx.config.mode === "dev" || ctx.config.mode === "production") ctx.state.sinks.push(consoleSink());
712
+ if (ctx.config.mode === "dev") ctx.state.sinks.push(consoleSink("debug"));
713
+ else if (ctx.config.mode === "production") ctx.state.sinks.push(consoleSink("info"));
699
714
  }
700
715
  //#endregion
701
716
  //#region src/plugins/log/state.ts
package/package.json CHANGED
@@ -112,5 +112,5 @@
112
112
  "test:integration": "vitest run --project integration",
113
113
  "test:coverage": "vitest run --project unit --project integration --coverage"
114
114
  },
115
- "version": "0.5.2"
115
+ "version": "0.5.4"
116
116
  }