flexily 0.5.2 → 0.6.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/dist/chunk-CBBoxR_p.mjs +26 -0
- package/dist/constants-BNURa6H7.mjs +65 -0
- package/dist/constants-BNURa6H7.mjs.map +1 -0
- package/dist/constants-D7ythAJC.d.mts +64 -0
- package/dist/constants-D7ythAJC.d.mts.map +1 -0
- package/{src/classic/node.ts → dist/index-classic.d.mts} +118 -619
- package/dist/index-classic.d.mts.map +1 -0
- package/dist/index-classic.mjs +1909 -0
- package/dist/index-classic.mjs.map +1 -0
- package/dist/index.d.mts +195 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3279 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node-zero-75maLs2s.d.mts +762 -0
- package/dist/node-zero-75maLs2s.d.mts.map +1 -0
- package/dist/src-BWyhokNZ.mjs +692 -0
- package/dist/src-BWyhokNZ.mjs.map +1 -0
- package/dist/src-DdSLylRA.mjs +816 -0
- package/dist/src-DdSLylRA.mjs.map +1 -0
- package/dist/testing.d.mts +55 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +154 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types--IozHd4V.mjs +283 -0
- package/dist/types--IozHd4V.mjs.map +1 -0
- package/dist/types-DG1H4DVR.d.mts +157 -0
- package/dist/types-DG1H4DVR.d.mts.map +1 -0
- package/package.json +33 -24
- package/src/CLAUDE.md +0 -527
- package/src/classic/layout.ts +0 -1843
- package/src/constants.ts +0 -82
- package/src/create-flexily.ts +0 -153
- package/src/index-classic.ts +0 -110
- package/src/index.ts +0 -133
- package/src/layout-flex-lines.ts +0 -413
- package/src/layout-helpers.ts +0 -160
- package/src/layout-measure.ts +0 -259
- package/src/layout-stats.ts +0 -41
- package/src/layout-traversal.ts +0 -70
- package/src/layout-zero.ts +0 -2219
- package/src/logger.ts +0 -68
- package/src/monospace-measurer.ts +0 -68
- package/src/node-zero.ts +0 -1508
- package/src/pretext-measurer.ts +0 -86
- package/src/test-measurer.ts +0 -219
- package/src/testing.ts +0 -215
- package/src/text-layout.ts +0 -75
- package/src/trace.ts +0 -252
- package/src/types.ts +0 -236
- package/src/utils.ts +0 -243
package/src/logger.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger with auto-detection
|
|
3
|
-
*
|
|
4
|
-
* Uses @beorn/logger if available (when used in km), falls back to debug library.
|
|
5
|
-
* Supports the conditional `?.` pattern for zero-cost when disabled.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// Debug library style: (msg, ...args) - printf-style formatting
|
|
9
|
-
type DebugFn = (msg: string, ...args: unknown[]) => void
|
|
10
|
-
|
|
11
|
-
interface ConditionalLogger {
|
|
12
|
-
debug?: DebugFn
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let _logger: ConditionalLogger | null = null
|
|
16
|
-
|
|
17
|
-
async function createFallbackLogger(namespace: string): Promise<ConditionalLogger> {
|
|
18
|
-
// Dynamic import to avoid bundling debug if not needed
|
|
19
|
-
try {
|
|
20
|
-
const { default: createDebug } = (await import("debug")) as {
|
|
21
|
-
default: (ns: string) => DebugFn & { enabled: boolean }
|
|
22
|
-
}
|
|
23
|
-
const debug = createDebug(namespace)
|
|
24
|
-
return { debug: debug.enabled ? debug : undefined }
|
|
25
|
-
} catch {
|
|
26
|
-
// debug not installed either
|
|
27
|
-
return { debug: undefined }
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function detectLogger(namespace: string): Promise<ConditionalLogger> {
|
|
32
|
-
try {
|
|
33
|
-
const { createLogger } = await import("loggily")
|
|
34
|
-
const logger = createLogger(namespace)
|
|
35
|
-
// Wrap @beorn/logger to accept printf-style args
|
|
36
|
-
if (logger.debug) {
|
|
37
|
-
const originalDebug = logger.debug
|
|
38
|
-
return {
|
|
39
|
-
debug: (msg: string, ...args: unknown[]) => {
|
|
40
|
-
// Format printf-style placeholders
|
|
41
|
-
let i = 0
|
|
42
|
-
const formatted = msg.replace(/%[sdOo]/g, () => {
|
|
43
|
-
const arg = args[i++]
|
|
44
|
-
if (arg === undefined) return ""
|
|
45
|
-
if (arg === null) return "null"
|
|
46
|
-
if (typeof arg === "object") return JSON.stringify(arg)
|
|
47
|
-
return String(arg)
|
|
48
|
-
})
|
|
49
|
-
originalDebug(formatted)
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return { debug: undefined }
|
|
54
|
-
} catch {
|
|
55
|
-
return createFallbackLogger(namespace)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Eagerly initialize (top-level await)
|
|
60
|
-
// This runs once at module load time
|
|
61
|
-
_logger = await detectLogger("flexily:layout")
|
|
62
|
-
|
|
63
|
-
/** Logger instance - use with optional chaining: `log.debug?.('message')` */
|
|
64
|
-
export const log: ConditionalLogger = {
|
|
65
|
-
get debug() {
|
|
66
|
-
return _logger?.debug
|
|
67
|
-
},
|
|
68
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Monospace text measurement.
|
|
3
|
-
*
|
|
4
|
-
* Terminal text: graphemeCount * charWidth, always 1 line (no wrapping).
|
|
5
|
-
* This is the default for terminal UIs where 1 char = 1 cell.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { FlexilyPlugin } from "./create-flexily.js"
|
|
9
|
-
import type { TextLayoutService, PreparedText, TextLayout, IntrinsicSizes } from "./text-layout.js"
|
|
10
|
-
|
|
11
|
-
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Create a monospace text measurement service.
|
|
15
|
-
*
|
|
16
|
-
* @param charWidth - Width of each character cell (default: 1 for terminal grids)
|
|
17
|
-
* @param charHeight - Height of each character cell (default: 1 for terminal grids)
|
|
18
|
-
*/
|
|
19
|
-
export function createMonospaceMeasurer(charWidth = 1, charHeight = 1): TextLayoutService {
|
|
20
|
-
return {
|
|
21
|
-
prepare(input) {
|
|
22
|
-
const { text } = input
|
|
23
|
-
|
|
24
|
-
// Count grapheme clusters for proper emoji/CJK support
|
|
25
|
-
let graphemeCount = 0
|
|
26
|
-
for (const _ of segmenter.segment(text)) graphemeCount++
|
|
27
|
-
|
|
28
|
-
const totalWidth = graphemeCount * charWidth
|
|
29
|
-
|
|
30
|
-
const prepared: PreparedText = {
|
|
31
|
-
intrinsicSizes(): IntrinsicSizes {
|
|
32
|
-
return {
|
|
33
|
-
minContentWidth: totalWidth, // monospace: entire text is one unbreakable segment
|
|
34
|
-
maxContentWidth: totalWidth,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
layout(constraints): TextLayout {
|
|
39
|
-
const width = constraints.maxWidth !== undefined ? Math.min(totalWidth, constraints.maxWidth) : totalWidth
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
width,
|
|
43
|
-
height: charHeight,
|
|
44
|
-
lineCount: 1,
|
|
45
|
-
firstBaseline: charHeight,
|
|
46
|
-
lastBaseline: charHeight,
|
|
47
|
-
truncated: width < totalWidth,
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return prepared
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Plugin: add monospace text measurement to the engine.
|
|
59
|
-
*
|
|
60
|
-
* @param charWidth - Width per character cell (default: 1)
|
|
61
|
-
* @param charHeight - Height per character cell (default: 1)
|
|
62
|
-
*/
|
|
63
|
-
export function withMonospace(charWidth = 1, charHeight = 1): FlexilyPlugin {
|
|
64
|
-
return (engine) => {
|
|
65
|
-
engine.textLayout = createMonospaceMeasurer(charWidth, charHeight)
|
|
66
|
-
return engine
|
|
67
|
-
}
|
|
68
|
-
}
|