@cmodjs/core 8.8.4 → 8.9.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.
package/ui/elements.js CHANGED
@@ -1,3 +1,8 @@
1
+ const tableFacts = new WeakMap();
2
+ const plainTerminal = { hasNerdFont: false };
3
+ export function drawnIn() {
4
+ return drawing?.drawnIn ?? plainTerminal;
5
+ }
1
6
  const unbuilt = Symbol('an element built outside a render');
2
7
  let drawing;
3
8
  const lowerings = new Map();
@@ -10,7 +15,7 @@ function elementNamed(name, props) {
10
15
  }
11
16
  export function drawWith(table, draw, markdown) {
12
17
  const outer = drawing;
13
- const current = { table: table, markdown };
18
+ const current = { table: table, markdown, drawnIn: tableFacts.get(table) ?? plainTerminal };
14
19
  drawing = current;
15
20
  try {
16
21
  return built(current, draw());
@@ -108,7 +113,7 @@ export function drawsFocusable(data, key) {
108
113
  return true;
109
114
  return Object.values(fields).some((each) => drawsFocusable(each, key));
110
115
  }
111
- export function forClaudeCode(table, surface, open) {
116
+ export function forClaudeCode(table, surface, open, { hasNerdFont } = plainTerminal) {
112
117
  const { Button: button, Link: link, Image: image, Svg: svg, Raster: raster } = table;
113
118
  const opening = (props) => {
114
119
  const { href, ...rest } = props;
@@ -121,7 +126,9 @@ export function forClaudeCode(table, surface, open) {
121
126
  return button({ ...rest, onPress: (press) => open(href, press) });
122
127
  };
123
128
  const named = (draw) => ({ label, ...rest }) => draw({ alt: label, ...rest });
124
- return { ...table, Button: opening, Image: named(image), Svg: named(svg), Raster: ({ label, ...rest }) => raster(rest) };
129
+ const resolved = { ...table, Button: opening, Image: named(image), Svg: named(svg), Raster: ({ label, ...rest }) => raster(rest) };
130
+ tableFacts.set(resolved, { hasNerdFont: hasNerdFont && surface === 'terminal' });
131
+ return resolved;
125
132
  }
126
133
  export const Box = element('Box');
127
134
  export const Text = element('Text');