@corenel/ui-kit 0.4.1 → 0.4.2

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.
@@ -1,6 +1,29 @@
1
1
  /** Resolve a fence tag to a supported Monaco language id, or null if unsupported. */
2
2
  export declare function monacoLangId(lang: string): string | null;
3
+ /**
4
+ * Did Monaco actually TOKENIZE, or just hand back undifferentiated text?
5
+ *
6
+ * `colorize()` succeeds even when no tokens provider is registered for the
7
+ * language: every character comes back as `mtk1`, the theme's default
8
+ * foreground. That is indistinguishable from success at the call site and
9
+ * strictly WORSE than the caller's own synchronous highlighter, which it would
10
+ * otherwise replace.
11
+ *
12
+ * It is not hypothetical. `json` is registered by the pack with `grammar: null`
13
+ * because its tokens come from the full JSON language service the HOST loads
14
+ * (src/lib/monaco.ts) — and this module deliberately never imports that. So on
15
+ * any surface where no editor has mounted (corenel's /app is entirely
16
+ * editor-free), every JSON block in the transcript colorized to a single
17
+ * `mtk1` blob a few seconds after render, visibly discarding a correct
18
+ * highlight.
19
+ *
20
+ * More than one distinct `mtk` class means real tokens. Exactly one (or none)
21
+ * means the tokenizer was absent, and the honest answer is the module's own
22
+ * documented contract: return null and let the fallback stand.
23
+ */
24
+ export declare function hasRealTokens(html: string): boolean;
3
25
  /** Highlight `code` as `lang` via Monaco, returning themed HTML (with `.mtkN`
4
- * token spans), or null when the language is unsupported or tokenization fails. */
26
+ * token spans), or null when the language is unsupported, has no tokenizer
27
+ * registered on this surface, or tokenization fails. */
5
28
  export declare function colorizeToHtml(code: string, lang: string): Promise<string | null>;
6
29
  //# sourceMappingURL=monacoColorize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"monacoColorize.d.ts","sourceRoot":"","sources":["../monacoColorize.ts"],"names":[],"mappings":"AAoCA,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGxD;AA6BD;mFACmF;AACnF,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWvF"}
1
+ {"version":3,"file":"monacoColorize.d.ts","sourceRoot":"","sources":["../monacoColorize.ts"],"names":[],"mappings":"AAoCA,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGxD;AA6BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGnD;AAED;;wDAEwD;AACxD,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYvF"}
@@ -63,8 +63,34 @@ function syncTheme(monaco) {
63
63
  appliedTheme = id;
64
64
  }
65
65
  }
66
+ /**
67
+ * Did Monaco actually TOKENIZE, or just hand back undifferentiated text?
68
+ *
69
+ * `colorize()` succeeds even when no tokens provider is registered for the
70
+ * language: every character comes back as `mtk1`, the theme's default
71
+ * foreground. That is indistinguishable from success at the call site and
72
+ * strictly WORSE than the caller's own synchronous highlighter, which it would
73
+ * otherwise replace.
74
+ *
75
+ * It is not hypothetical. `json` is registered by the pack with `grammar: null`
76
+ * because its tokens come from the full JSON language service the HOST loads
77
+ * (src/lib/monaco.ts) — and this module deliberately never imports that. So on
78
+ * any surface where no editor has mounted (corenel's /app is entirely
79
+ * editor-free), every JSON block in the transcript colorized to a single
80
+ * `mtk1` blob a few seconds after render, visibly discarding a correct
81
+ * highlight.
82
+ *
83
+ * More than one distinct `mtk` class means real tokens. Exactly one (or none)
84
+ * means the tokenizer was absent, and the honest answer is the module's own
85
+ * documented contract: return null and let the fallback stand.
86
+ */
87
+ export function hasRealTokens(html) {
88
+ const classes = new Set(html.match(/mtk\d+/g) ?? []);
89
+ return classes.size > 1;
90
+ }
66
91
  /** Highlight `code` as `lang` via Monaco, returning themed HTML (with `.mtkN`
67
- * token spans), or null when the language is unsupported or tokenization fails. */
92
+ * token spans), or null when the language is unsupported, has no tokenizer
93
+ * registered on this surface, or tokenization fails. */
68
94
  export async function colorizeToHtml(code, lang) {
69
95
  const id = monacoLangId(lang);
70
96
  if (!id)
@@ -73,7 +99,8 @@ export async function colorizeToHtml(code, lang) {
73
99
  syncTheme(monaco);
74
100
  try {
75
101
  const html = await monaco.editor.colorize(code, id, { tabSize: 2 });
76
- return html || null;
102
+ // A token-less result is a failure wearing success's clothes — see hasRealTokens.
103
+ return html && hasRealTokens(html) ? html : null;
77
104
  }
78
105
  catch {
79
106
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"monacoColorize.js","sourceRoot":"","sources":["../monacoColorize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAIxD,mFAAmF;AACnF,mFAAmF;AACnF,8EAA8E;AAC9E,mFAAmF;AACnF,8BAA8B;AAE9B,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACvC,CAAC;AAED,IAAI,OAAO,GAA8B,IAAI,CAAC;AAC9C,KAAK,UAAU,YAAY;IACzB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,MAAM,CAAC,wCAAwC,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;IAC7B,4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CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAAC,YAAY,GAAG,EAAE,CAAC;IAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IACrD,OAAO,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED;;wDAEwD;AACxD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY;IAC7D,MAAM,EAAE,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;IACpC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QACpE,kFAAkF;QAClF,OAAO,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corenel/ui-kit",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "description": "Corenel shared UI primitives — icons, theme, token-usage helpers, small UI helpers, monaco colorizer. Consumed by @corenel/web-ui and the prompd app alike.",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "gpt-tokenizer": "^3.4.0",
27
- "@corenel/protocol": "0.6.0"
27
+ "@corenel/protocol": "0.6.1"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "monaco-editor": "*",