@earendil-works/pi-tui 0.87.0 → 0.99.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/README.md +49 -5
- package/dist/alt-screen-search.d.ts.map +1 -1
- package/dist/alt-screen-search.js.map +1 -1
- package/dist/autocomplete.d.ts +1 -1
- package/dist/autocomplete.d.ts.map +1 -1
- package/dist/autocomplete.js +28 -8
- package/dist/autocomplete.js.map +1 -1
- package/dist/colors.d.ts +73 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/colors.js +273 -0
- package/dist/colors.js.map +1 -0
- package/dist/components/alt-screen-flash.d.ts.map +1 -1
- package/dist/components/alt-screen-flash.js.map +1 -1
- package/dist/components/box.d.ts.map +1 -1
- package/dist/components/box.js +8 -8
- package/dist/components/box.js.map +1 -1
- package/dist/components/cancellable-loader.d.ts.map +1 -1
- package/dist/components/cancellable-loader.js.map +1 -1
- package/dist/components/editor.d.ts.map +1 -1
- package/dist/components/editor.js +4 -2
- package/dist/components/editor.js.map +1 -1
- package/dist/components/h-stack.d.ts.map +1 -1
- package/dist/components/h-stack.js.map +1 -1
- package/dist/components/image.d.ts.map +1 -1
- package/dist/components/image.js.map +1 -1
- package/dist/components/input.d.ts.map +1 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/loader.d.ts.map +1 -1
- package/dist/components/loader.js.map +1 -1
- package/dist/components/markdown.d.ts +1 -0
- package/dist/components/markdown.d.ts.map +1 -1
- package/dist/components/markdown.js +8 -2
- package/dist/components/markdown.js.map +1 -1
- package/dist/components/mouse-region.d.ts.map +1 -1
- package/dist/components/mouse-region.js.map +1 -1
- package/dist/components/scroll-view.d.ts.map +1 -1
- package/dist/components/scroll-view.js.map +1 -1
- package/dist/components/select-list.d.ts.map +1 -1
- package/dist/components/select-list.js.map +1 -1
- package/dist/components/settings-list.d.ts.map +1 -1
- package/dist/components/settings-list.js.map +1 -1
- package/dist/components/spacer.d.ts.map +1 -1
- package/dist/components/spacer.js.map +1 -1
- package/dist/components/stack.d.ts.map +1 -1
- package/dist/components/stack.js.map +1 -1
- package/dist/components/text.d.ts.map +1 -1
- package/dist/components/text.js.map +1 -1
- package/dist/components/truncated-text.d.ts.map +1 -1
- package/dist/components/truncated-text.js.map +1 -1
- package/dist/components/v-stack.d.ts.map +1 -1
- package/dist/components/v-stack.js.map +1 -1
- package/dist/editor-component.d.ts.map +1 -1
- package/dist/fuzzy.d.ts.map +1 -1
- package/dist/fuzzy.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/keybindings.d.ts.map +1 -1
- package/dist/keybindings.js.map +1 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js.map +1 -1
- package/dist/kill-ring.d.ts.map +1 -1
- package/dist/kill-ring.js.map +1 -1
- package/dist/latex.d.ts.map +1 -1
- package/dist/latex.js.map +1 -1
- package/dist/layout-node.d.ts.map +1 -1
- package/dist/layout-node.js.map +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js.map +1 -1
- package/dist/native-modifiers.d.ts.map +1 -1
- package/dist/native-modifiers.js.map +1 -1
- package/dist/native-module-path.d.ts.map +1 -1
- package/dist/native-module-path.js.map +1 -1
- package/dist/native-platform.d.ts +2 -0
- package/dist/native-platform.d.ts.map +1 -1
- package/dist/native-platform.js.map +1 -1
- package/dist/oklab.d.ts +43 -0
- package/dist/oklab.d.ts.map +1 -0
- package/dist/oklab.js +210 -0
- package/dist/oklab.js.map +1 -0
- package/dist/stdin-buffer.d.ts.map +1 -1
- package/dist/stdin-buffer.js.map +1 -1
- package/dist/terminal-colors.d.ts +19 -2
- package/dist/terminal-colors.d.ts.map +1 -1
- package/dist/terminal-colors.js +12 -7
- package/dist/terminal-colors.js.map +1 -1
- package/dist/terminal-image.d.ts +3 -1
- package/dist/terminal-image.d.ts.map +1 -1
- package/dist/terminal-image.js +33 -9
- package/dist/terminal-image.js.map +1 -1
- package/dist/terminal.d.ts +3 -0
- package/dist/terminal.d.ts.map +1 -1
- package/dist/terminal.js +15 -8
- package/dist/terminal.js.map +1 -1
- package/dist/tui-alt-screen.d.ts +8 -4
- package/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/tui-alt-screen.js +13 -12
- package/dist/tui-alt-screen.js.map +1 -1
- package/dist/tui-main-screen.d.ts.map +1 -1
- package/dist/tui-main-screen.js.map +1 -1
- package/dist/tui.d.ts +23 -22
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +85 -66
- package/dist/tui.js.map +1 -1
- package/dist/undo-stack.d.ts.map +1 -1
- package/dist/undo-stack.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +99 -55
- package/dist/utils.js.map +1 -1
- package/dist/wheel-scroll.d.ts +23 -0
- package/dist/wheel-scroll.d.ts.map +1 -0
- package/dist/wheel-scroll.js +73 -0
- package/dist/wheel-scroll.js.map +1 -0
- package/dist/word-navigation.d.ts.map +1 -1
- package/dist/word-navigation.js.map +1 -1
- package/native/clipboard.h +40 -2
- package/native/darwin/README.md +1 -1
- package/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/native/darwin/src/darwin-platform.m +39 -0
- package/native/napi.h +2 -0
- package/package.json +2 -2
package/dist/layout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAkB,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA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C;AAAA,CAC/C","sourcesContent":["import type { ScrollView } from \"./components/scroll-view.ts\";\nimport { allocateStackSizes, visibleStackEntries } from \"./components/stack.ts\";\nimport { getLayoutNode } from \"./layout-node.ts\";\nimport { cropKittyImageLine, getKittyImageMetadata, isImageLine } from \"./terminal-image.ts\";\nimport { type Component, CURSOR_MARKER, compositeTuiLine } from \"./tui.ts\";\nimport {\n\textractAnsiCode,\n\tgetActiveBackgroundAnsi,\n\tgetGraphemeCellRange,\n\tsliceByColumn,\n\tvisibleWidth,\n} from \"./utils.ts\";\n\nconst OSC133_ZONE_PREFIX = /^(?:\\x1b\\]133;[ABC](?:\\x07|\\x1b\\\\))+/;\n\nexport interface LayoutRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface LayoutBox {\n\tcomponent: Component;\n\trect: LayoutRect;\n\tclip: LayoutRect;\n\tchildren: LayoutBox[];\n\tparent?: LayoutBox;\n\tlines?: readonly string[];\n\tlineOffset?: number;\n\tscrollView?: ScrollView;\n\tscrollContentLines?: readonly string[];\n\tlayer: number;\n}\n\nexport interface LayoutFrame {\n\troot: LayoutBox;\n\twidth: number;\n\theight: number;\n\tlines: string[];\n\tprimaryScrollView?: ScrollView;\n}\n\nexport interface ScrollbarGeometry {\n\tcolumn: number;\n\ttrackTop: number;\n\ttrackHeight: number;\n\tthumbTop: number;\n\tthumbHeight: number;\n\tmaxScrollTop: number;\n}\n\ninterface LayoutContext {\n\tviewport: { width: number; height: number };\n\trenderCache: Map<Component, Map<number, string[]>>;\n\trequestRender: () => void;\n\tprimaryScrollView: ScrollView | undefined;\n}\n\nfunction intersect(a: LayoutRect, b: LayoutRect): LayoutRect {\n\tconst x = Math.max(a.x, b.x);\n\tconst y = Math.max(a.y, b.y);\n\tconst right = Math.min(a.x + a.width, b.x + b.width);\n\tconst bottom = Math.min(a.y + a.height, b.y + b.height);\n\treturn { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };\n}\n\nfunction renderCached(context: LayoutContext, component: Component, width: number): string[] {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tlet widths = context.renderCache.get(component);\n\tif (!widths) {\n\t\twidths = new Map<number, string[]>();\n\t\tcontext.renderCache.set(component, widths);\n\t}\n\tlet lines = widths.get(safeWidth);\n\tif (!lines) {\n\t\tlines = component.render(safeWidth);\n\t\twidths.set(safeWidth, lines);\n\t}\n\treturn lines;\n}\n\nfunction measureHeight(context: LayoutContext, component: Component, width: number): number {\n\treturn renderCached(context, component, width).length;\n}\n\nfunction measureWidth(context: LayoutContext, component: Component, width: number): number {\n\treturn renderCached(context, component, width).reduce((max, line) => Math.max(max, visibleWidth(line)), 0);\n}\n\nfunction withParent(box: LayoutBox, parent: LayoutBox): LayoutBox {\n\tbox.parent = parent;\n\treturn box;\n}\n\nfunction translateBox(box: LayoutBox, deltaY: number): void {\n\tbox.rect.y += deltaY;\n\tfor (const child of box.children) translateBox(child, deltaY);\n}\n\nfunction updateClips(box: LayoutBox, parentClip: LayoutRect): void {\n\tbox.clip = intersect(parentClip, box.rect);\n\tfor (const child of box.children) updateClips(child, box.clip);\n}\n\nfunction layoutComponent(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst node = getLayoutNode(component);\n\tif (!node) {\n\t\tconst lines = renderCached(context, component, safeWidth);\n\t\tconst allocatedHeight = height === undefined ? lines.length : Math.max(0, Math.floor(height));\n\t\tlet lineOffset = 0;\n\t\tif (lines.length > allocatedHeight && allocatedHeight > 0) {\n\t\t\tconst cursorLine = lines.findIndex((line) => line.includes(CURSOR_MARKER));\n\t\t\tif (cursorLine >= allocatedHeight) lineOffset = cursorLine - allocatedHeight + 1;\n\t\t}\n\t\treturn {\n\t\t\tcomponent,\n\t\t\trect: { x, y, width: safeWidth, height: allocatedHeight },\n\t\t\tclip: intersect(clip, { x, y, width: safeWidth, height: allocatedHeight }),\n\t\t\tchildren: [],\n\t\t\tlines,\n\t\t\tlineOffset,\n\t\t\tlayer: 0,\n\t\t};\n\t}\n\n\tif (node.type === \"scroll\") {\n\t\tconst previousScrollTop = node.state.scrollTop;\n\t\tconst contentWidth = node.state.getContentWidth(safeWidth);\n\t\tconst childBox = layoutComponent(\n\t\t\tcontext,\n\t\t\tnode.component,\n\t\t\tx,\n\t\t\ty - previousScrollTop,\n\t\t\tcontentWidth,\n\t\t\tundefined,\n\t\t\tclip,\n\t\t);\n\t\tconst contentHeight = childBox.rect.height;\n\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\ttranslateBox(childBox, previousScrollTop - node.state.scrollTop);\n\t\tconst scrollView = node.state as ScrollView;\n\t\tif (node.state.primary || !context.primaryScrollView) context.primaryScrollView = scrollView;\n\t\tconst rect = { x, y, width: safeWidth, height: viewportHeight };\n\t\tconst childClip = intersect(clip, rect);\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: childClip,\n\t\t\tchildren: [childBox],\n\t\t\tscrollView,\n\t\t\tscrollContentLines: renderCached(context, node.component, contentWidth),\n\t\t\tlayer: 0,\n\t\t};\n\t\tchildBox.parent = box;\n\t\tupdateClips(childBox, childClip);\n\t\treturn box;\n\t}\n\n\tconst entries = visibleStackEntries(node.entries, context.viewport);\n\tconst gapTotal = Math.max(0, entries.length - 1) * node.gap;\n\tif (node.type === \"vstack\") {\n\t\tconst intrinsicHeights = entries.map((entry) =>\n\t\t\ttypeof entry.basis === \"number\" ? entry.basis : measureHeight(context, entry.component, safeWidth),\n\t\t);\n\t\tconst sizes = allocateStackSizes(entries, intrinsicHeights, height, node.gap);\n\t\tconst naturalHeight = sizes.reduce((sum, size) => sum + size, 0) + gapTotal;\n\t\tconst allocatedHeight = height === undefined ? naturalHeight : Math.max(0, Math.floor(height));\n\t\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: intersect(clip, rect),\n\t\t\tchildren: [],\n\t\t\tlayer: 0,\n\t\t};\n\t\tlet childY = y;\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, x, childY, safeWidth, sizes[index]!, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t\tchildY += sizes[index]! + node.gap;\n\t\t}\n\t\treturn box;\n\t}\n\n\tconst intrinsicWidths = entries.map((entry) =>\n\t\ttypeof entry.basis === \"number\" ? entry.basis : measureWidth(context, entry.component, safeWidth),\n\t);\n\tconst widths = allocateStackSizes(entries, intrinsicWidths, safeWidth, node.gap);\n\tconst intrinsicHeights = entries.map((entry, index) =>\n\t\tmeasureHeight(context, entry.component, Math.max(1, widths[index]!)),\n\t);\n\tconst allocatedHeight =\n\t\theight === undefined\n\t\t\t? intrinsicHeights.reduce((max, childHeight) => Math.max(max, childHeight), 0)\n\t\t\t: Math.max(0, height);\n\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tlet childX = x;\n\tfor (let index = 0; index < entries.length; index++) {\n\t\tconst naturalChildHeight = intrinsicHeights[index]!;\n\t\tconst childHeight = node.align === \"stretch\" ? allocatedHeight : Math.min(allocatedHeight, naturalChildHeight);\n\t\tlet childY = y;\n\t\tif (node.align === \"center\") childY += Math.floor((allocatedHeight - childHeight) / 2);\n\t\telse if (node.align === \"end\") childY += allocatedHeight - childHeight;\n\t\tconst childWidth = widths[index]!;\n\t\tif (childWidth === 0) {\n\t\t\tbox.children.push({\n\t\t\t\tcomponent: entries[index]!.component,\n\t\t\t\trect: { x: childX, y: childY, width: 0, height: childHeight },\n\t\t\t\tclip: { x: childX, y: childY, width: 0, height: 0 },\n\t\t\t\tchildren: [],\n\t\t\t\tparent: box,\n\t\t\t\tlayer: 0,\n\t\t\t});\n\t\t} else {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, childX, childY, childWidth, childHeight, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tchildX += childWidth + node.gap;\n\t}\n\treturn box;\n}\n\nfunction replaceScrollbarCell(\n\tline: string,\n\tcolumn: number,\n\ttotalWidth: number,\n\treplacement: string,\n\tpreserveTargetBackground: boolean,\n): string {\n\tif (isImageLine(line)) return line;\n\n\tconst graphemeRange = getGraphemeCellRange(line, column);\n\tconst start = graphemeRange?.start ?? column;\n\tconst end = graphemeRange?.end ?? column + 1;\n\tconst before = sliceByColumn(line, 0, start, true);\n\tconst target = sliceByColumn(line, start, end - start, true);\n\tconst after = sliceByColumn(line, end, Math.max(0, totalWidth - end), true);\n\n\tlet targetPrefix = \"\";\n\tlet targetIndex = 0;\n\twhile (targetIndex < target.length) {\n\t\tconst ansi = extractAnsiCode(target, targetIndex);\n\t\tif (!ansi) break;\n\t\ttargetPrefix += ansi.code;\n\t\ttargetIndex += ansi.length;\n\t}\n\tconst beforePadding = \" \".repeat(Math.max(0, start - visibleWidth(before)));\n\tconst cellPaddingBefore = \" \".repeat(Math.max(0, column - start));\n\tconst cellPaddingAfter = \" \".repeat(Math.max(0, end - column - 1));\n\tconst targetStyle = `\\x1b[0m\\x1b]8;;\\x07${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : \"\"}`;\n\treturn `${before}${beforePadding}${targetStyle}${cellPaddingBefore}${replacement}${cellPaddingAfter}${after}`;\n}\n\nexport function getScrollbarGeometry(box: LayoutBox, includeHiddenAuto = false): ScrollbarGeometry | undefined {\n\tif (!box.scrollView || box.rect.width <= 0 || box.rect.height <= 0) return undefined;\n\n\tconst contentHeight = box.children[0]?.rect.height ?? box.scrollContentLines?.length ?? 0;\n\tconst trackHeight = box.rect.height;\n\tconst canRevealHiddenAuto = includeHiddenAuto && box.scrollView.scrollbar === \"auto\" && contentHeight > trackHeight;\n\tif (!box.scrollView.isScrollbarVisible && !canRevealHiddenAuto) return undefined;\n\n\tconst minThumbHeight = Math.min(2, trackHeight);\n\tconst thumbHeight = Math.max(\n\t\tminThumbHeight,\n\t\tMath.min(trackHeight, Math.round((trackHeight * trackHeight) / contentHeight)),\n\t);\n\tconst maxScrollTop = Math.max(0, contentHeight - trackHeight);\n\tconst maxThumbTop = trackHeight - thumbHeight;\n\tconst thumbOffset = maxScrollTop === 0 ? 0 : Math.round((box.scrollView.scrollTop / maxScrollTop) * maxThumbTop);\n\tconst column = box.rect.x + box.rect.width - 1;\n\tif (column < box.clip.x || column >= box.clip.x + box.clip.width) return undefined;\n\n\treturn {\n\t\tcolumn,\n\t\ttrackTop: box.rect.y,\n\t\ttrackHeight,\n\t\tthumbTop: box.rect.y + thumbOffset,\n\t\tthumbHeight,\n\t\tmaxScrollTop,\n\t};\n}\n\nfunction paintScrollbar(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst geometry = getScrollbarGeometry(box);\n\tif (!geometry || !box.scrollView) return;\n\n\tfor (let offset = 0; offset < geometry.trackHeight; offset++) {\n\t\tconst row = geometry.trackTop + offset;\n\t\tif (row < box.clip.y || row >= box.clip.y + box.clip.height || row < 0 || row >= screen.length) continue;\n\t\tconst isThumb = row >= geometry.thumbTop && row < geometry.thumbTop + geometry.thumbHeight;\n\t\tconst replacement = isThumb\n\t\t\t? box.scrollView.scrollbarThumbStyle(box.scrollView.isScrollbarActive ? \"█\" : \"┃\")\n\t\t\t: box.scrollView.scrollbarTrackStyle(\"│\");\n\t\tscreen[row] = replaceScrollbarCell(\n\t\t\tscreen[row] ?? \"\",\n\t\t\tgeometry.column,\n\t\t\ttotalWidth,\n\t\t\treplacement,\n\t\t\tbox.scrollView.scrollbar !== \"always\",\n\t\t);\n\t}\n}\n\nfunction paintBox(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tif (box.lines) {\n\t\tconst offset = box.lineOffset ?? 0;\n\t\tconst firstRow = Math.max(box.rect.y, box.clip.y, 0);\n\t\tconst lastRow = Math.min(box.rect.y + box.rect.height, box.clip.y + box.clip.height, screen.length);\n\t\tfor (let row = firstRow; row < lastRow; row++) {\n\t\t\tconst sourceLine = box.lines[offset + row - box.rect.y];\n\t\t\tif (sourceLine === undefined) continue;\n\t\t\tlet line = sourceLine.replace(OSC133_ZONE_PREFIX, \"\");\n\t\t\tconst imageMetadata = getKittyImageMetadata(line);\n\t\t\tif (imageMetadata) {\n\t\t\t\tconst clipBottom = Math.min(screen.length, box.clip.y + box.clip.height);\n\t\t\t\tconst visibleRows = Math.min(imageMetadata.rows, clipBottom - row);\n\t\t\t\tif (visibleRows < imageMetadata.rows) line = cropKittyImageLine(line, 0, visibleRows);\n\t\t\t}\n\t\t\t// Fast path: a full-width box painting onto an untouched row can use the\n\t\t\t// source line reference directly. Compositing here would rebuild the row\n\t\t\t// string through ANSI/grapheme segmentation every frame; padding is\n\t\t\t// unnecessary because rows are written with erase-line and the final\n\t\t\t// width clamp still truncates over-wide lines.\n\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth && (isImageLine(line) || !screen[row])) {\n\t\t\t\tscreen[row] = line;\n\t\t\t} else {\n\t\t\t\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", line, box.rect.x, box.rect.width, totalWidth);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const child of box.children) paintBox(child, screen, totalWidth);\n\n\tif (box.scrollView && box.scrollContentLines && box.scrollView.scrollTop > 0 && box.rect.height > 0) {\n\t\tfor (let imageRow = box.scrollView.scrollTop - 1; imageRow >= 0; imageRow--) {\n\t\t\tconst imageLine = box.scrollContentLines[imageRow] ?? \"\";\n\t\t\tconst metadata = getKittyImageMetadata(imageLine);\n\t\t\tif (metadata) {\n\t\t\t\tconst hiddenRows = box.scrollView.scrollTop - imageRow;\n\t\t\t\tif (hiddenRows < metadata.rows) {\n\t\t\t\t\tconst visibleRows = Math.min(box.rect.height, metadata.rows - hiddenRows);\n\t\t\t\t\tconst cropped = cropKittyImageLine(imageLine, hiddenRows, visibleRows);\n\t\t\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth) screen[box.rect.y] = cropped;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (imageLine !== \"\") break;\n\t\t}\n\t}\n\n\tpaintScrollbar(box, screen, totalWidth);\n}\n\nexport function renderLayoutFrame(\n\troot: Component,\n\twidth: number,\n\theight: number,\n\trequestRender: () => void,\n): LayoutFrame {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst safeHeight = Math.max(1, Math.floor(height));\n\tconst context: LayoutContext = {\n\t\tviewport: { width: safeWidth, height: safeHeight },\n\t\trenderCache: new Map(),\n\t\trequestRender,\n\t\tprimaryScrollView: undefined,\n\t};\n\tconst rootBox = layoutComponent(context, root, 0, 0, safeWidth, safeHeight, {\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t});\n\tconst lines = Array.from({ length: safeHeight }, () => \"\");\n\tpaintBox(rootBox, lines, safeWidth);\n\treturn {\n\t\troot: rootBox,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t\tlines,\n\t\t...(context.primaryScrollView === undefined ? {} : { primaryScrollView: context.primaryScrollView }),\n\t};\n}\n\nfunction containsPoint(rect: LayoutRect, x: number, y: number): boolean {\n\treturn x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;\n}\n\n/** Return the visual hit path from the deepest component to the layout root. */\nexport function getLayoutBoxesAt(frame: LayoutFrame, x: number, y: number): LayoutBox[] {\n\tconst result: Array<{ box: LayoutBox; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tresult.push({ box, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.box.layer - a.box.layer || b.depth - a.depth);\n\treturn result.map(({ box }) => box);\n}\n\nexport function getScrollViewBox(frame: LayoutFrame, scrollView: ScrollView): LayoutBox | undefined {\n\tconst visit = (box: LayoutBox): LayoutBox | undefined => {\n\t\tif (box.scrollView === scrollView) return box;\n\t\tfor (const child of box.children) {\n\t\t\tconst match = visit(child);\n\t\t\tif (match) return match;\n\t\t}\n\t\treturn undefined;\n\t};\n\treturn visit(frame.root);\n}\n\nexport function getScrollViewsAt(frame: LayoutFrame, x: number, y: number): ScrollView[] {\n\tconst result: Array<{ scrollView: ScrollView; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tif (box.scrollView && containsPoint(box.rect, x, y)) result.push({ scrollView: box.scrollView, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.depth - a.depth);\n\treturn result.map((entry) => entry.scrollView);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAkB,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EACN,eAAe,EACf,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,YAAY,GACZ,MAAM,YAAY,CAAC;AAEpB,MAAM,kBAAkB,GAAG,sCAAsC,CAAC;AA8ClE,SAAS,S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ACD,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAkB,EAAE,CAAS,EAAE,CAAS;IACxE,MAAM,MAAM,GAAqD,EAAE,CAAC;IACpE,MAAM,KAAK,GAAG,CAAC,GAAc,EAAE,KAAa,EAAQ,EAAE;QACrD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YAAE,OAAO;QAC3C,IAAI,GAAG,CAAC,UAAU,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QACxG,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,QAAQ;YAAE,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC;IACF,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { ScrollView } from \"./components/scroll-view.ts\";\nimport { allocateStackSizes, visibleStackEntries } from \"./components/stack.ts\";\nimport { getLayoutNode } from \"./layout-node.ts\";\nimport { cropKittyImageLine, getKittyImageMetadata, isImageLine } from \"./terminal-image.ts\";\nimport { type Component, CURSOR_MARKER, compositeTuiLine } from \"./tui.ts\";\nimport {\n\textractAnsiCode,\n\tgetActiveBackgroundAnsi,\n\tgetGraphemeCellRange,\n\tsliceByColumn,\n\tvisibleWidth,\n} from \"./utils.ts\";\n\nconst OSC133_ZONE_PREFIX = /^(?:\\x1b\\]133;[ABC](?:\\x07|\\x1b\\\\))+/;\n\nexport interface LayoutRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface LayoutBox {\n\tcomponent: Component;\n\trect: LayoutRect;\n\tclip: LayoutRect;\n\tchildren: LayoutBox[];\n\tparent?: LayoutBox;\n\tlines?: readonly string[];\n\tlineOffset?: number;\n\tscrollView?: ScrollView;\n\tscrollContentLines?: readonly string[];\n\tlayer: number;\n}\n\nexport interface LayoutFrame {\n\troot: LayoutBox;\n\twidth: number;\n\theight: number;\n\tlines: string[];\n\tprimaryScrollView?: ScrollView;\n}\n\nexport interface ScrollbarGeometry {\n\tcolumn: number;\n\ttrackTop: number;\n\ttrackHeight: number;\n\tthumbTop: number;\n\tthumbHeight: number;\n\tmaxScrollTop: number;\n}\n\ninterface LayoutContext {\n\tviewport: { width: number; height: number };\n\trenderCache: Map<Component, Map<number, string[]>>;\n\trequestRender: () => void;\n\tprimaryScrollView: ScrollView | undefined;\n}\n\nfunction intersect(a: LayoutRect, b: LayoutRect): LayoutRect {\n\tconst x = Math.max(a.x, b.x);\n\tconst y = Math.max(a.y, b.y);\n\tconst right = Math.min(a.x + a.width, b.x + b.width);\n\tconst bottom = Math.min(a.y + a.height, b.y + b.height);\n\treturn { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };\n}\n\nfunction renderCached(context: LayoutContext, component: Component, width: number): string[] {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tlet widths = context.renderCache.get(component);\n\tif (!widths) {\n\t\twidths = new Map<number, string[]>();\n\t\tcontext.renderCache.set(component, widths);\n\t}\n\tlet lines = widths.get(safeWidth);\n\tif (!lines) {\n\t\tlines = component.render(safeWidth);\n\t\twidths.set(safeWidth, lines);\n\t}\n\treturn lines;\n}\n\nfunction measureHeight(context: LayoutContext, component: Component, width: number): number {\n\treturn renderCached(context, component, width).length;\n}\n\nfunction measureWidth(context: LayoutContext, component: Component, width: number): number {\n\treturn renderCached(context, component, width).reduce((max, line) => Math.max(max, visibleWidth(line)), 0);\n}\n\nfunction withParent(box: LayoutBox, parent: LayoutBox): LayoutBox {\n\tbox.parent = parent;\n\treturn box;\n}\n\nfunction translateBox(box: LayoutBox, deltaY: number): void {\n\tbox.rect.y += deltaY;\n\tfor (const child of box.children) translateBox(child, deltaY);\n}\n\nfunction updateClips(box: LayoutBox, parentClip: LayoutRect): void {\n\tbox.clip = intersect(parentClip, box.rect);\n\tfor (const child of box.children) updateClips(child, box.clip);\n}\n\nfunction layoutComponent(\n\tcontext: LayoutContext,\n\tcomponent: Component,\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number | undefined,\n\tclip: LayoutRect,\n): LayoutBox {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst node = getLayoutNode(component);\n\tif (!node) {\n\t\tconst lines = renderCached(context, component, safeWidth);\n\t\tconst allocatedHeight = height === undefined ? lines.length : Math.max(0, Math.floor(height));\n\t\tlet lineOffset = 0;\n\t\tif (lines.length > allocatedHeight && allocatedHeight > 0) {\n\t\t\tconst cursorLine = lines.findIndex((line) => line.includes(CURSOR_MARKER));\n\t\t\tif (cursorLine >= allocatedHeight) lineOffset = cursorLine - allocatedHeight + 1;\n\t\t}\n\t\treturn {\n\t\t\tcomponent,\n\t\t\trect: { x, y, width: safeWidth, height: allocatedHeight },\n\t\t\tclip: intersect(clip, { x, y, width: safeWidth, height: allocatedHeight }),\n\t\t\tchildren: [],\n\t\t\tlines,\n\t\t\tlineOffset,\n\t\t\tlayer: 0,\n\t\t};\n\t}\n\n\tif (node.type === \"scroll\") {\n\t\tconst previousScrollTop = node.state.scrollTop;\n\t\tconst contentWidth = node.state.getContentWidth(safeWidth);\n\t\tconst childBox = layoutComponent(\n\t\t\tcontext,\n\t\t\tnode.component,\n\t\t\tx,\n\t\t\ty - previousScrollTop,\n\t\t\tcontentWidth,\n\t\t\tundefined,\n\t\t\tclip,\n\t\t);\n\t\tconst contentHeight = childBox.rect.height;\n\t\tconst viewportHeight = height === undefined ? contentHeight : Math.max(0, Math.floor(height));\n\t\tnode.state.updateLayout(contentHeight, viewportHeight, context.requestRender);\n\t\ttranslateBox(childBox, previousScrollTop - node.state.scrollTop);\n\t\tconst scrollView = node.state as ScrollView;\n\t\tif (node.state.primary || !context.primaryScrollView) context.primaryScrollView = scrollView;\n\t\tconst rect = { x, y, width: safeWidth, height: viewportHeight };\n\t\tconst childClip = intersect(clip, rect);\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: childClip,\n\t\t\tchildren: [childBox],\n\t\t\tscrollView,\n\t\t\tscrollContentLines: renderCached(context, node.component, contentWidth),\n\t\t\tlayer: 0,\n\t\t};\n\t\tchildBox.parent = box;\n\t\tupdateClips(childBox, childClip);\n\t\treturn box;\n\t}\n\n\tconst entries = visibleStackEntries(node.entries, context.viewport);\n\tconst gapTotal = Math.max(0, entries.length - 1) * node.gap;\n\tif (node.type === \"vstack\") {\n\t\tconst intrinsicHeights = entries.map((entry) =>\n\t\t\ttypeof entry.basis === \"number\" ? entry.basis : measureHeight(context, entry.component, safeWidth),\n\t\t);\n\t\tconst sizes = allocateStackSizes(entries, intrinsicHeights, height, node.gap);\n\t\tconst naturalHeight = sizes.reduce((sum, size) => sum + size, 0) + gapTotal;\n\t\tconst allocatedHeight = height === undefined ? naturalHeight : Math.max(0, Math.floor(height));\n\t\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\t\tconst box: LayoutBox = {\n\t\t\tcomponent,\n\t\t\trect,\n\t\t\tclip: intersect(clip, rect),\n\t\t\tchildren: [],\n\t\t\tlayer: 0,\n\t\t};\n\t\tlet childY = y;\n\t\tfor (let index = 0; index < entries.length; index++) {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, x, childY, safeWidth, sizes[index]!, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t\tchildY += sizes[index]! + node.gap;\n\t\t}\n\t\treturn box;\n\t}\n\n\tconst intrinsicWidths = entries.map((entry) =>\n\t\ttypeof entry.basis === \"number\" ? entry.basis : measureWidth(context, entry.component, safeWidth),\n\t);\n\tconst widths = allocateStackSizes(entries, intrinsicWidths, safeWidth, node.gap);\n\tconst intrinsicHeights = entries.map((entry, index) =>\n\t\tmeasureHeight(context, entry.component, Math.max(1, widths[index]!)),\n\t);\n\tconst allocatedHeight =\n\t\theight === undefined\n\t\t\t? intrinsicHeights.reduce((max, childHeight) => Math.max(max, childHeight), 0)\n\t\t\t: Math.max(0, height);\n\tconst rect = { x, y, width: safeWidth, height: allocatedHeight };\n\tconst box: LayoutBox = {\n\t\tcomponent,\n\t\trect,\n\t\tclip: intersect(clip, rect),\n\t\tchildren: [],\n\t\tlayer: 0,\n\t};\n\tlet childX = x;\n\tfor (let index = 0; index < entries.length; index++) {\n\t\tconst naturalChildHeight = intrinsicHeights[index]!;\n\t\tconst childHeight = node.align === \"stretch\" ? allocatedHeight : Math.min(allocatedHeight, naturalChildHeight);\n\t\tlet childY = y;\n\t\tif (node.align === \"center\") childY += Math.floor((allocatedHeight - childHeight) / 2);\n\t\telse if (node.align === \"end\") childY += allocatedHeight - childHeight;\n\t\tconst childWidth = widths[index]!;\n\t\tif (childWidth === 0) {\n\t\t\tbox.children.push({\n\t\t\t\tcomponent: entries[index]!.component,\n\t\t\t\trect: { x: childX, y: childY, width: 0, height: childHeight },\n\t\t\t\tclip: { x: childX, y: childY, width: 0, height: 0 },\n\t\t\t\tchildren: [],\n\t\t\t\tparent: box,\n\t\t\t\tlayer: 0,\n\t\t\t});\n\t\t} else {\n\t\t\tbox.children.push(\n\t\t\t\twithParent(\n\t\t\t\t\tlayoutComponent(context, entries[index]!.component, childX, childY, childWidth, childHeight, box.clip),\n\t\t\t\t\tbox,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tchildX += childWidth + node.gap;\n\t}\n\treturn box;\n}\n\nfunction replaceScrollbarCell(\n\tline: string,\n\tcolumn: number,\n\ttotalWidth: number,\n\treplacement: string,\n\tpreserveTargetBackground: boolean,\n): string {\n\tif (isImageLine(line)) return line;\n\n\tconst graphemeRange = getGraphemeCellRange(line, column);\n\tconst start = graphemeRange?.start ?? column;\n\tconst end = graphemeRange?.end ?? column + 1;\n\tconst before = sliceByColumn(line, 0, start, true);\n\tconst target = sliceByColumn(line, start, end - start, true);\n\tconst after = sliceByColumn(line, end, Math.max(0, totalWidth - end), true);\n\n\tlet targetPrefix = \"\";\n\tlet targetIndex = 0;\n\twhile (targetIndex < target.length) {\n\t\tconst ansi = extractAnsiCode(target, targetIndex);\n\t\tif (!ansi) break;\n\t\ttargetPrefix += ansi.code;\n\t\ttargetIndex += ansi.length;\n\t}\n\tconst beforePadding = \" \".repeat(Math.max(0, start - visibleWidth(before)));\n\tconst cellPaddingBefore = \" \".repeat(Math.max(0, column - start));\n\tconst cellPaddingAfter = \" \".repeat(Math.max(0, end - column - 1));\n\tconst targetStyle = `\\x1b[0m\\x1b]8;;\\x07${preserveTargetBackground ? getActiveBackgroundAnsi(targetPrefix) : \"\"}`;\n\treturn `${before}${beforePadding}${targetStyle}${cellPaddingBefore}${replacement}${cellPaddingAfter}${after}`;\n}\n\nexport function getScrollbarGeometry(box: LayoutBox, includeHiddenAuto = false): ScrollbarGeometry | undefined {\n\tif (!box.scrollView || box.rect.width <= 0 || box.rect.height <= 0) return undefined;\n\n\tconst contentHeight = box.children[0]?.rect.height ?? box.scrollContentLines?.length ?? 0;\n\tconst trackHeight = box.rect.height;\n\tconst canRevealHiddenAuto = includeHiddenAuto && box.scrollView.scrollbar === \"auto\" && contentHeight > trackHeight;\n\tif (!box.scrollView.isScrollbarVisible && !canRevealHiddenAuto) return undefined;\n\n\tconst minThumbHeight = Math.min(2, trackHeight);\n\tconst thumbHeight = Math.max(\n\t\tminThumbHeight,\n\t\tMath.min(trackHeight, Math.round((trackHeight * trackHeight) / contentHeight)),\n\t);\n\tconst maxScrollTop = Math.max(0, contentHeight - trackHeight);\n\tconst maxThumbTop = trackHeight - thumbHeight;\n\tconst thumbOffset = maxScrollTop === 0 ? 0 : Math.round((box.scrollView.scrollTop / maxScrollTop) * maxThumbTop);\n\tconst column = box.rect.x + box.rect.width - 1;\n\tif (column < box.clip.x || column >= box.clip.x + box.clip.width) return undefined;\n\n\treturn {\n\t\tcolumn,\n\t\ttrackTop: box.rect.y,\n\t\ttrackHeight,\n\t\tthumbTop: box.rect.y + thumbOffset,\n\t\tthumbHeight,\n\t\tmaxScrollTop,\n\t};\n}\n\nfunction paintScrollbar(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tconst geometry = getScrollbarGeometry(box);\n\tif (!geometry || !box.scrollView) return;\n\n\tfor (let offset = 0; offset < geometry.trackHeight; offset++) {\n\t\tconst row = geometry.trackTop + offset;\n\t\tif (row < box.clip.y || row >= box.clip.y + box.clip.height || row < 0 || row >= screen.length) continue;\n\t\tconst isThumb = row >= geometry.thumbTop && row < geometry.thumbTop + geometry.thumbHeight;\n\t\tconst replacement = isThumb\n\t\t\t? box.scrollView.scrollbarThumbStyle(box.scrollView.isScrollbarActive ? \"█\" : \"┃\")\n\t\t\t: box.scrollView.scrollbarTrackStyle(\"│\");\n\t\tscreen[row] = replaceScrollbarCell(\n\t\t\tscreen[row] ?? \"\",\n\t\t\tgeometry.column,\n\t\t\ttotalWidth,\n\t\t\treplacement,\n\t\t\tbox.scrollView.scrollbar !== \"always\",\n\t\t);\n\t}\n}\n\nfunction paintBox(box: LayoutBox, screen: string[], totalWidth: number): void {\n\tif (box.lines) {\n\t\tconst offset = box.lineOffset ?? 0;\n\t\tconst firstRow = Math.max(box.rect.y, box.clip.y, 0);\n\t\tconst lastRow = Math.min(box.rect.y + box.rect.height, box.clip.y + box.clip.height, screen.length);\n\t\tfor (let row = firstRow; row < lastRow; row++) {\n\t\t\tconst sourceLine = box.lines[offset + row - box.rect.y];\n\t\t\tif (sourceLine === undefined) continue;\n\t\t\tlet line = sourceLine.replace(OSC133_ZONE_PREFIX, \"\");\n\t\t\tconst imageMetadata = getKittyImageMetadata(line);\n\t\t\tif (imageMetadata) {\n\t\t\t\tconst clipBottom = Math.min(screen.length, box.clip.y + box.clip.height);\n\t\t\t\tconst visibleRows = Math.min(imageMetadata.rows, clipBottom - row);\n\t\t\t\tif (visibleRows < imageMetadata.rows) line = cropKittyImageLine(line, 0, visibleRows);\n\t\t\t}\n\t\t\t// Fast path: a full-width box painting onto an untouched row can use the\n\t\t\t// source line reference directly. Compositing here would rebuild the row\n\t\t\t// string through ANSI/grapheme segmentation every frame; padding is\n\t\t\t// unnecessary because rows are written with erase-line and the final\n\t\t\t// width clamp still truncates over-wide lines.\n\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth && (isImageLine(line) || !screen[row])) {\n\t\t\t\tscreen[row] = line;\n\t\t\t} else {\n\t\t\t\tscreen[row] = compositeTuiLine(screen[row] ?? \"\", line, box.rect.x, box.rect.width, totalWidth);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const child of box.children) paintBox(child, screen, totalWidth);\n\n\tif (box.scrollView && box.scrollContentLines && box.scrollView.scrollTop > 0 && box.rect.height > 0) {\n\t\tfor (let imageRow = box.scrollView.scrollTop - 1; imageRow >= 0; imageRow--) {\n\t\t\tconst imageLine = box.scrollContentLines[imageRow] ?? \"\";\n\t\t\tconst metadata = getKittyImageMetadata(imageLine);\n\t\t\tif (metadata) {\n\t\t\t\tconst hiddenRows = box.scrollView.scrollTop - imageRow;\n\t\t\t\tif (hiddenRows < metadata.rows) {\n\t\t\t\t\tconst visibleRows = Math.min(box.rect.height, metadata.rows - hiddenRows);\n\t\t\t\t\tconst cropped = cropKittyImageLine(imageLine, hiddenRows, visibleRows);\n\t\t\t\t\tif (box.rect.x === 0 && box.rect.width >= totalWidth) screen[box.rect.y] = cropped;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (imageLine !== \"\") break;\n\t\t}\n\t}\n\n\tpaintScrollbar(box, screen, totalWidth);\n}\n\nexport function renderLayoutFrame(\n\troot: Component,\n\twidth: number,\n\theight: number,\n\trequestRender: () => void,\n): LayoutFrame {\n\tconst safeWidth = Math.max(1, Math.floor(width));\n\tconst safeHeight = Math.max(1, Math.floor(height));\n\tconst context: LayoutContext = {\n\t\tviewport: { width: safeWidth, height: safeHeight },\n\t\trenderCache: new Map(),\n\t\trequestRender,\n\t\tprimaryScrollView: undefined,\n\t};\n\tconst rootBox = layoutComponent(context, root, 0, 0, safeWidth, safeHeight, {\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t});\n\tconst lines = Array.from({ length: safeHeight }, () => \"\");\n\tpaintBox(rootBox, lines, safeWidth);\n\treturn {\n\t\troot: rootBox,\n\t\twidth: safeWidth,\n\t\theight: safeHeight,\n\t\tlines,\n\t\t...(context.primaryScrollView === undefined ? {} : { primaryScrollView: context.primaryScrollView }),\n\t};\n}\n\nfunction containsPoint(rect: LayoutRect, x: number, y: number): boolean {\n\treturn x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;\n}\n\n/** Return the visual hit path from the deepest component to the layout root. */\nexport function getLayoutBoxesAt(frame: LayoutFrame, x: number, y: number): LayoutBox[] {\n\tconst result: Array<{ box: LayoutBox; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tresult.push({ box, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.box.layer - a.box.layer || b.depth - a.depth);\n\treturn result.map(({ box }) => box);\n}\n\nexport function getScrollViewBox(frame: LayoutFrame, scrollView: ScrollView): LayoutBox | undefined {\n\tconst visit = (box: LayoutBox): LayoutBox | undefined => {\n\t\tif (box.scrollView === scrollView) return box;\n\t\tfor (const child of box.children) {\n\t\t\tconst match = visit(child);\n\t\t\tif (match) return match;\n\t\t}\n\t\treturn undefined;\n\t};\n\treturn visit(frame.root);\n}\n\nexport function getScrollViewsAt(frame: LayoutFrame, x: number, y: number): ScrollView[] {\n\tconst result: Array<{ scrollView: ScrollView; depth: number }> = [];\n\tconst visit = (box: LayoutBox, depth: number): void => {\n\t\tif (!containsPoint(box.clip, x, y)) return;\n\t\tif (box.scrollView && containsPoint(box.rect, x, y)) result.push({ scrollView: box.scrollView, depth });\n\t\tfor (const child of box.children) visit(child, depth + 1);\n\t};\n\tvisit(frame.root, 0);\n\tresult.sort((a, b) => b.depth - a.depth);\n\treturn result.map((entry) => entry.scrollView);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-modifiers.d.ts","sourceRoot":"","sources":["../src/native-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEjF,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAQjE"
|
|
1
|
+
{"version":3,"file":"native-modifiers.d.ts","sourceRoot":"","sources":["../src/native-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEjF,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAQjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-modifiers.js","sourceRoot":"","sources":["../src/native-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAoB,MAAM,sBAAsB,CAAC;AAIjF,MAAM,UAAU,uBAAuB,CAAC,GAAgB
|
|
1
|
+
{"version":3,"file":"native-modifiers.js","sourceRoot":"","sources":["../src/native-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAoB,MAAM,sBAAsB,CAAC;AAIjF,MAAM,UAAU,uBAAuB,CAAC,GAAgB;IACvD,MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;IACzC,IAAI,CAAC,MAAM,EAAE,iBAAiB;QAAE,OAAO,KAAK,CAAC;IAC7C,IAAI,CAAC;QACJ,OAAO,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC","sourcesContent":["import { getNativePlatformHelper, type ModifierKey } from \"./native-platform.ts\";\n\nexport type { ModifierKey } from \"./native-platform.ts\";\n\nexport function isNativeModifierPressed(key: ModifierKey): boolean {\n\tconst helper = getNativePlatformHelper();\n\tif (!helper?.isModifierPressed) return false;\n\ttry {\n\t\treturn helper.isModifierPressed(key) === true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-module-path.d.ts","sourceRoot":"","sources":["../src/native-module-path.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,4BAA4B;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/C;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,4BAAiC,GAAG,MAAM,EAAE,CAiBlH"
|
|
1
|
+
{"version":3,"file":"native-module-path.d.ts","sourceRoot":"","sources":["../src/native-module-path.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,4BAA4B;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/C;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,4BAAiC,GAAG,MAAM,EAAE,CAiBlH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-module-path.js","sourceRoot":"","sources":["../src/native-module-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AACrD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAQlD,MAAM,UAAU,yBAAyB,CAAC,UAAkB,EAAE,OAAO,GAAiC,EAAE
|
|
1
|
+
{"version":3,"file":"native-module-path.js","sourceRoot":"","sources":["../src/native-module-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AACrD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAQlD,MAAM,UAAU,yBAAyB,CAAC,UAAkB,EAAE,OAAO,GAAiC,EAAE;IACvG,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/E,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,IAAI,CAAC;QACJ,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,cAAc,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,CAAC;QACzF,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACR,4DAA4D;IAC7D,CAAC;IAED,UAAU,CAAC,IAAI,CACd,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,EACjC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,EAC3B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAC/D,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst moduleRequire = createRequire(import.meta.url);\nconst TUI_PACKAGE_NAME = \"@earendil-works/pi-tui\";\n\nexport interface NativeModuleCandidateOptions {\n\tmoduleUrl?: string;\n\texecPath?: string;\n\tresolvePackage?: (specifier: string) => string;\n}\n\nexport function getNativeModuleCandidates(nativePath: string, options: NativeModuleCandidateOptions = {}): string[] {\n\tconst moduleDir = dirname(fileURLToPath(options.moduleUrl ?? import.meta.url));\n\tconst candidates: string[] = [];\n\n\ttry {\n\t\tconst packageEntry = (options.resolvePackage ?? moduleRequire.resolve)(TUI_PACKAGE_NAME);\n\t\tcandidates.push(join(dirname(packageEntry), \"..\", nativePath));\n\t} catch {\n\t\t// Standalone binaries do not have an installed TUI package.\n\t}\n\n\tcandidates.push(\n\t\tjoin(moduleDir, \"..\", nativePath),\n\t\tjoin(moduleDir, nativePath),\n\t\tjoin(dirname(options.execPath ?? process.execPath), nativePath),\n\t);\n\treturn Array.from(new Set(candidates));\n}\n"]}
|
|
@@ -4,6 +4,8 @@ export interface NativeClipboard {
|
|
|
4
4
|
getText(): Promise<string | null | undefined>;
|
|
5
5
|
/** Undefined means unavailable, null means no image; transfer failures reject. */
|
|
6
6
|
getImage(): Promise<Uint8Array | null | undefined>;
|
|
7
|
+
/** POSIX paths of file URLs on the clipboard. Undefined means unsupported, null means no files. */
|
|
8
|
+
getFilePaths?(): Promise<string[] | null | undefined>;
|
|
7
9
|
/** Linux uses command-line tools to retain clipboard ownership instead. */
|
|
8
10
|
setText?(text: string): Promise<void>;
|
|
9
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-platform.d.ts","sourceRoot":"","sources":["../src/native-platform.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,eAAe;IAC/B,iFAAiF;IACjF,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAC9C,kFAAkF;IAClF,QAAQ,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACnD,2EAA2E;IAC3E,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED,KAAK,oBAAoB,GAAG,eAAe,GAAG;IAC7C,0BAA0B,CAAC,EAAE,MAAM,OAAO,CAAC;IAC3C,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;CACnD,CAAC;AAgCF,wBAAgB,uBAAuB,IAAI,oBAAoB,GAAG,SAAS,CAG1E;AAED,qFAAqF;AACrF,wBAAgB,kBAAkB,IAAI,eAAe,GAAG,SAAS,CAIhE"
|
|
1
|
+
{"version":3,"file":"native-platform.d.ts","sourceRoot":"","sources":["../src/native-platform.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,eAAe;IAC/B,iFAAiF;IACjF,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAC9C,kFAAkF;IAClF,QAAQ,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACnD,mGAAmG;IACnG,YAAY,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACtD,2EAA2E;IAC3E,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED,KAAK,oBAAoB,GAAG,eAAe,GAAG;IAC7C,0BAA0B,CAAC,EAAE,MAAM,OAAO,CAAC;IAC3C,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;CACnD,CAAC;AAgCF,wBAAgB,uBAAuB,IAAI,oBAAoB,GAAG,SAAS,CAG1E;AAED,qFAAqF;AACrF,wBAAgB,kBAAkB,IAAI,eAAe,GAAG,SAAS,CAIhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-platform.js","sourceRoot":"","sources":["../src/native-platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEpE,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"native-platform.js","sourceRoot":"","sources":["../src/native-platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;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OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IACpF,OAAO,wBAAwB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,kBAAkB;IACjC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,uBAAuB,EAAE,CAAC;IACnE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC3C,OAAO,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport { getNativeModuleCandidates } from \"./native-module-path.ts\";\n\nconst cjsRequire = createRequire(import.meta.url);\n\nexport type ModifierKey = \"shift\" | \"command\" | \"control\" | \"option\";\n\nexport interface NativeClipboard {\n\t/** Undefined means unavailable, null means no text; transfer failures reject. */\n\tgetText(): Promise<string | null | undefined>;\n\t/** Undefined means unavailable, null means no image; transfer failures reject. */\n\tgetImage(): Promise<Uint8Array | null | undefined>;\n\t/** POSIX paths of file URLs on the clipboard. Undefined means unsupported, null means no files. */\n\tgetFilePaths?(): Promise<string[] | null | undefined>;\n\t/** Linux uses command-line tools to retain clipboard ownership instead. */\n\tsetText?(text: string): Promise<void>;\n}\n\ntype NativePlatformHelper = NativeClipboard & {\n\tenableVirtualTerminalInput?: () => boolean;\n\tisModifierPressed?: (name: ModifierKey) => boolean;\n};\n\n// Cache module loading, not display availability: a disconnected display can recover.\nconst helpers = new Map<string, NativePlatformHelper | undefined>();\n\nfunction loadNativePlatformHelper(platform: string, suffix = \"\"): NativePlatformHelper | undefined {\n\tconst arch = process.arch;\n\tif (arch !== \"x64\" && arch !== \"arm64\") return undefined;\n\tconst nativePath = path.join(\n\t\t\"native\",\n\t\tplatform,\n\t\t\"prebuilds\",\n\t\t`${platform}-${arch}`,\n\t\t`${platform}-platform${suffix}.node`,\n\t);\n\tif (helpers.has(nativePath)) return helpers.get(nativePath);\n\n\tfor (const modulePath of getNativeModuleCandidates(nativePath)) {\n\t\ttry {\n\t\t\tconst helper = cjsRequire(modulePath) as Partial<NativePlatformHelper> | null;\n\t\t\tif (typeof helper?.getText === \"function\" && typeof helper.getImage === \"function\") {\n\t\t\t\thelpers.set(nativePath, helper as NativePlatformHelper);\n\t\t\t\treturn helper as NativePlatformHelper;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Try the next possible packaging location.\n\t\t}\n\t}\n\thelpers.set(nativePath, undefined);\n\treturn undefined;\n}\n\nexport function getNativePlatformHelper(): NativePlatformHelper | undefined {\n\tif (process.platform !== \"darwin\" && process.platform !== \"win32\") return undefined;\n\treturn loadNativePlatformHelper(process.platform);\n}\n\n/** Load a clipboard helper without opening the display until a read is requested. */\nexport function getNativeClipboard(): NativeClipboard | undefined {\n\tif (process.platform !== \"linux\") return getNativePlatformHelper();\n\tif (!process.env.DISPLAY) return undefined;\n\treturn loadNativePlatformHelper(\"linux\", \"-x11\");\n}\n"]}
|
package/dist/oklab.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Oklab and OKHSL <-> sRGB conversion. `colors.ts` builds its OKLCH, OKHSL, and color mixing on it.
|
|
3
|
+
*
|
|
4
|
+
* Oklab and OKHSL are Björn Ottosson's color spaces; OKHSL's saturation is relative to the sRGB gamut at
|
|
5
|
+
* each hue and lightness. This is a port of his reference implementation (https://bottosson.github.io/posts/colorpicker/),
|
|
6
|
+
* Copyright (c) 2021 Björn Ottosson, used under the MIT license:
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
9
|
+
* associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
12
|
+
* following conditions: The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
14
|
+
* KIND, EXPRESS OR IMPLIED.
|
|
15
|
+
*/
|
|
16
|
+
import type { RgbColor } from "./terminal-colors.ts";
|
|
17
|
+
type Vector = [number, number, number];
|
|
18
|
+
/** Oklab lightness to OKHSL lightness. */
|
|
19
|
+
export declare const oklabToOkhslLightness: (x: number) => number;
|
|
20
|
+
/** Oklab [L, a, b] to linear sRGB [r, g, b] (0-1, may leave the gamut). */
|
|
21
|
+
export declare function oklabToLinearSrgb(lab: Vector): Vector;
|
|
22
|
+
/** sRGB channels (0-255) to Oklab [L, a, b]. */
|
|
23
|
+
export declare function rgbToOklab({ r, g, b }: RgbColor): Vector;
|
|
24
|
+
/** Linear sRGB [r, g, b] to sRGB channels (0-255, rounded), clipping out-of-gamut channels. */
|
|
25
|
+
export declare function linearSrgbToRgb(linear: Vector): RgbColor;
|
|
26
|
+
/**
|
|
27
|
+
* Convert OKHSL to sRGB channels (0-255, rounded), clipping out-of-gamut channels.
|
|
28
|
+
* @param hue Hue in degrees.
|
|
29
|
+
* @param saturation Saturation, 0-1.
|
|
30
|
+
* @param lightness Lightness, 0-1.
|
|
31
|
+
*/
|
|
32
|
+
export declare function okhslToRgb(hue: number, saturation: number, lightness: number): RgbColor;
|
|
33
|
+
/**
|
|
34
|
+
* Convert sRGB channels (0-255) to OKHSL.
|
|
35
|
+
* @returns Hue `h` in degrees (0 for grays), saturation `s` and lightness `l` 0-1.
|
|
36
|
+
*/
|
|
37
|
+
export declare function rgbToOkhsl(rgb: RgbColor): {
|
|
38
|
+
h: number;
|
|
39
|
+
s: number;
|
|
40
|
+
l: number;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=oklab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oklab.d.ts","sourceRoot":"","sources":["../src/oklab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAoDvC,0CAA0C;AAC1C,eAAO,MAAM,qBAAqB,MAAO,MAAM,KAAG,MACoB,CAAC;AAUvE,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAErD;AAOD,gDAAgD;AAChD,wBAAgB,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAExD;AAED,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAGxD;AA+ED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,CAsBvF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAkB7E"}
|
package/dist/oklab.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Oklab and OKHSL <-> sRGB conversion. `colors.ts` builds its OKLCH, OKHSL, and color mixing on it.
|
|
3
|
+
*
|
|
4
|
+
* Oklab and OKHSL are Björn Ottosson's color spaces; OKHSL's saturation is relative to the sRGB gamut at
|
|
5
|
+
* each hue and lightness. This is a port of his reference implementation (https://bottosson.github.io/posts/colorpicker/),
|
|
6
|
+
* Copyright (c) 2021 Björn Ottosson, used under the MIT license:
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
9
|
+
* associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
12
|
+
* following conditions: The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
14
|
+
* KIND, EXPRESS OR IMPLIED.
|
|
15
|
+
*/
|
|
16
|
+
const multiply = (m, [x, y, z]) => m.map((row) => row[0] * x + row[1] * y + row[2] * z);
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// OKHSL <-> sRGB
|
|
19
|
+
// ============================================================================
|
|
20
|
+
const LINEAR_SRGB_TO_LMS = [
|
|
21
|
+
[0.4122214694707629, 0.5363325372617349, 0.0514459932675022],
|
|
22
|
+
[0.2119034958178251, 0.6806995506452344, 0.1073969535369405],
|
|
23
|
+
[0.0883024591900564, 0.2817188391361215, 0.6299787016738222],
|
|
24
|
+
];
|
|
25
|
+
const LMS_TO_LAB = [
|
|
26
|
+
[0.210454268309314, 0.793617774702305, -0.0040720430116193],
|
|
27
|
+
[1.9779985324311684, -2.42859224204858, 0.450593709617411],
|
|
28
|
+
[0.0259040424655478, 0.7827717124575296, -0.8086757549230774],
|
|
29
|
+
];
|
|
30
|
+
const LAB_TO_LMS = [
|
|
31
|
+
[1, 0.3963377773761749, 0.2158037573099136],
|
|
32
|
+
[1, -0.1055613458156586, -0.0638541728258133],
|
|
33
|
+
[1, -0.0894841775298119, -1.2914855480194092],
|
|
34
|
+
];
|
|
35
|
+
const LMS_TO_LINEAR_SRGB = [
|
|
36
|
+
[4.0767416360759583, -3.3077115392580629, 0.2309699031821043],
|
|
37
|
+
[-1.2684379732850315, 2.6097573492876882, -0.341319376002657],
|
|
38
|
+
[-0.0041960761386756, -0.7034186179359362, 1.7076146940746117],
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Per sRGB channel (red, green, blue): the (a, b) half-plane where that channel clips
|
|
42
|
+
* first, and the polynomial approximating the maximum saturation there.
|
|
43
|
+
*/
|
|
44
|
+
const SATURATION_FIT = [
|
|
45
|
+
[
|
|
46
|
+
[-1.8817031, -0.80936501],
|
|
47
|
+
[1.19086277, 1.76576728, 0.59662641, 0.75515197, 0.56771245],
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
[1.8144408, -1.19445267],
|
|
51
|
+
[0.73956515, -0.45954404, 0.08285427, 0.12541073, -0.14503204],
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
[0.13110758, 1.81333971],
|
|
55
|
+
[1.35733652, -0.00915799, -1.1513021, -0.50559606, 0.00692167],
|
|
56
|
+
],
|
|
57
|
+
];
|
|
58
|
+
const K1 = 0.206;
|
|
59
|
+
const K2 = 0.03;
|
|
60
|
+
const K3 = (1 + K1) / (1 + K2);
|
|
61
|
+
/** Oklab lightness to OKHSL lightness. */
|
|
62
|
+
export const oklabToOkhslLightness = (x) => 0.5 * (K3 * x - K1 + Math.sqrt((K3 * x - K1) ** 2 + 4 * K2 * K3 * x));
|
|
63
|
+
/** OKHSL lightness to Oklab lightness. */
|
|
64
|
+
const okhslToOklabLightness = (x) => (x * x + K1 * x) / (K3 * (x + K2));
|
|
65
|
+
/** sRGB transfer function: linear to encoded channel, both 0-1. */
|
|
66
|
+
const linearToSrgb = (value) => value > 0.0031308 ? 1.055 * value ** (1 / 2.4) - 0.055 : 12.92 * value;
|
|
67
|
+
/** Inverse sRGB transfer function: encoded to linear channel, both 0-1. */
|
|
68
|
+
const srgbToLinear = (value) => (value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4);
|
|
69
|
+
/** Oklab [L, a, b] to linear sRGB [r, g, b] (0-1, may leave the gamut). */
|
|
70
|
+
export function oklabToLinearSrgb(lab) {
|
|
71
|
+
return multiply(LMS_TO_LINEAR_SRGB, multiply(LAB_TO_LMS, lab).map((value) => value ** 3));
|
|
72
|
+
}
|
|
73
|
+
/** Linear sRGB [r, g, b] (0-1) to Oklab [L, a, b]. */
|
|
74
|
+
function linearSrgbToOklab(rgb) {
|
|
75
|
+
return multiply(LMS_TO_LAB, multiply(LINEAR_SRGB_TO_LMS, rgb).map(Math.cbrt));
|
|
76
|
+
}
|
|
77
|
+
/** sRGB channels (0-255) to Oklab [L, a, b]. */
|
|
78
|
+
export function rgbToOklab({ r, g, b }) {
|
|
79
|
+
return linearSrgbToOklab([r / 255, g / 255, b / 255].map(srgbToLinear));
|
|
80
|
+
}
|
|
81
|
+
/** Linear sRGB [r, g, b] to sRGB channels (0-255, rounded), clipping out-of-gamut channels. */
|
|
82
|
+
export function linearSrgbToRgb(linear) {
|
|
83
|
+
const [r, g, b] = linear.map((value) => Math.round(Math.min(1, Math.max(0, linearToSrgb(value))) * 255));
|
|
84
|
+
return { r, g, b };
|
|
85
|
+
}
|
|
86
|
+
/** Rate of change of each cube-root LMS component along a chroma direction (a, b). */
|
|
87
|
+
function lmsSlopes(a, b) {
|
|
88
|
+
return [LAB_TO_LMS[0], LAB_TO_LMS[1], LAB_TO_LMS[2]].map((row) => row[1] * a + row[2] * b);
|
|
89
|
+
}
|
|
90
|
+
/** Largest saturation (C/L) inside sRGB for hue (a, b): polynomial fit plus one Halley step. */
|
|
91
|
+
function maxSaturation(a, b) {
|
|
92
|
+
const channel = SATURATION_FIT.findIndex(([[x, y]], index) => index === 2 || x * a + y * b > 1);
|
|
93
|
+
const [k0, k1, k2, k3, k4] = SATURATION_FIT[channel][1];
|
|
94
|
+
const weights = LMS_TO_LINEAR_SRGB[channel];
|
|
95
|
+
const saturation = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
|
|
96
|
+
const slopes = lmsSlopes(a, b);
|
|
97
|
+
const base = slopes.map((k) => 1 + saturation * k);
|
|
98
|
+
const dot = (values) => values.reduce((sum, value, index) => sum + weights[index] * value, 0);
|
|
99
|
+
const f = dot(base.map((value) => value ** 3));
|
|
100
|
+
const f1 = dot(base.map((value, index) => 3 * slopes[index] * value ** 2));
|
|
101
|
+
const f2 = dot(base.map((value, index) => 6 * slopes[index] ** 2 * value));
|
|
102
|
+
return saturation - (f * f1) / (f1 * f1 - 0.5 * f * f2);
|
|
103
|
+
}
|
|
104
|
+
/** Oklab lightness and chroma of the most saturated sRGB color of hue (a, b). */
|
|
105
|
+
function cusp(a, b) {
|
|
106
|
+
const saturation = maxSaturation(a, b);
|
|
107
|
+
const lightness = Math.cbrt(1 / Math.max(...oklabToLinearSrgb([1, saturation * a, saturation * b])));
|
|
108
|
+
return [lightness, lightness * saturation];
|
|
109
|
+
}
|
|
110
|
+
/** Chroma where the constant-lightness line at `lightness` leaves the sRGB gamut. */
|
|
111
|
+
function maxChroma(a, b, lightness, [cuspL, cuspC]) {
|
|
112
|
+
if (lightness <= cuspL)
|
|
113
|
+
return (cuspC * lightness) / cuspL;
|
|
114
|
+
// Upper half: triangle edge, then one Halley step against each channel reaching 1.
|
|
115
|
+
const t = (cuspC * (lightness - 1)) / (cuspL - 1);
|
|
116
|
+
const slopes = lmsSlopes(a, b);
|
|
117
|
+
const lms = slopes.map((k) => lightness + t * k);
|
|
118
|
+
const cubes = lms.map((value) => value ** 3);
|
|
119
|
+
const first = lms.map((value, index) => 3 * slopes[index] * value ** 2);
|
|
120
|
+
const second = lms.map((value, index) => 6 * slopes[index] ** 2 * value);
|
|
121
|
+
const dot = (row, values) => row[0] * values[0] + row[1] * values[1] + row[2] * values[2];
|
|
122
|
+
const steps = LMS_TO_LINEAR_SRGB.map((row) => {
|
|
123
|
+
const f = dot(row, cubes) - 1;
|
|
124
|
+
const f1 = dot(row, first);
|
|
125
|
+
const f2 = dot(row, second);
|
|
126
|
+
const u = f1 / (f1 * f1 - 0.5 * f * f2);
|
|
127
|
+
return u >= 0 ? -f * u : Number.MAX_VALUE;
|
|
128
|
+
});
|
|
129
|
+
return t + Math.min(...steps);
|
|
130
|
+
}
|
|
131
|
+
/** OKHSL's chroma reference points at lightness L and hue (a, b): [c0, cMid, cMax]. */
|
|
132
|
+
function chromaStops(L, a, b) {
|
|
133
|
+
const peak = cusp(a, b);
|
|
134
|
+
const cMax = maxChroma(a, b, L, peak);
|
|
135
|
+
const k = cMax / Math.min(L * (peak[1] / peak[0]), (1 - L) * (peak[1] / (1 - peak[0])));
|
|
136
|
+
const midS = 0.11516993 +
|
|
137
|
+
1 /
|
|
138
|
+
(7.4477897 +
|
|
139
|
+
4.1590124 * b +
|
|
140
|
+
a *
|
|
141
|
+
(-2.19557347 +
|
|
142
|
+
1.75198401 * b +
|
|
143
|
+
a * (-2.13704948 - 10.02301043 * b + a * (-4.24894561 + 5.38770819 * b + 4.69891013 * a))));
|
|
144
|
+
const midT = 0.11239642 +
|
|
145
|
+
1 /
|
|
146
|
+
(1.6132032 -
|
|
147
|
+
0.68124379 * b +
|
|
148
|
+
a *
|
|
149
|
+
(0.40370612 +
|
|
150
|
+
0.90148123 * b +
|
|
151
|
+
a * (-0.27087943 + 0.6122399 * b + a * (0.00299215 - 0.45399568 * b - 0.14661872 * a))));
|
|
152
|
+
const cMid = 0.9 * k * Math.sqrt(Math.sqrt(1 / (1 / (L * midS) ** 4 + 1 / ((1 - L) * midT) ** 4)));
|
|
153
|
+
const c0 = Math.sqrt(1 / (1 / (L * 0.4) ** 2 + 1 / ((1 - L) * 0.8) ** 2));
|
|
154
|
+
return [c0, cMid, cMax];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Convert OKHSL to sRGB channels (0-255, rounded), clipping out-of-gamut channels.
|
|
158
|
+
* @param hue Hue in degrees.
|
|
159
|
+
* @param saturation Saturation, 0-1.
|
|
160
|
+
* @param lightness Lightness, 0-1.
|
|
161
|
+
*/
|
|
162
|
+
export function okhslToRgb(hue, saturation, lightness) {
|
|
163
|
+
const L = okhslToOklabLightness(lightness);
|
|
164
|
+
let lab = [L, 0, 0];
|
|
165
|
+
if (L > 0 && L < 1 && saturation > 0) {
|
|
166
|
+
const angle = (2 * Math.PI * (((hue % 360) + 360) % 360)) / 360;
|
|
167
|
+
const a = Math.cos(angle);
|
|
168
|
+
const b = Math.sin(angle);
|
|
169
|
+
const [c0, cMid, cMax] = chromaStops(L, a, b);
|
|
170
|
+
// Chroma rises from 0 through cMid at s = 0.8 to cMax at s = 1.
|
|
171
|
+
let chroma;
|
|
172
|
+
if (saturation < 0.8) {
|
|
173
|
+
const t = 1.25 * saturation;
|
|
174
|
+
const k1 = 0.8 * c0;
|
|
175
|
+
chroma = (t * k1) / (1 - (1 - k1 / cMid) * t);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const t = 5 * (saturation - 0.8);
|
|
179
|
+
const k1 = (0.2 * cMid ** 2 * 1.25 ** 2) / c0;
|
|
180
|
+
chroma = cMid + (t * k1) / (1 - (1 - k1 / (cMax - cMid)) * t);
|
|
181
|
+
}
|
|
182
|
+
lab = [L, chroma * a, chroma * b];
|
|
183
|
+
}
|
|
184
|
+
return linearSrgbToRgb(oklabToLinearSrgb(lab));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Convert sRGB channels (0-255) to OKHSL.
|
|
188
|
+
* @returns Hue `h` in degrees (0 for grays), saturation `s` and lightness `l` 0-1.
|
|
189
|
+
*/
|
|
190
|
+
export function rgbToOkhsl(rgb) {
|
|
191
|
+
const [L, labA, labB] = rgbToOklab(rgb);
|
|
192
|
+
const chroma = Math.hypot(labA, labB);
|
|
193
|
+
const lightness = oklabToOkhslLightness(L);
|
|
194
|
+
if (chroma < 1e-9 || lightness <= 0 || lightness >= 1)
|
|
195
|
+
return { h: 0, s: 0, l: lightness };
|
|
196
|
+
const hue = ((Math.atan2(labB, labA) * 180) / Math.PI + 360) % 360;
|
|
197
|
+
const [c0, cMid, cMax] = chromaStops(L, labA / chroma, labB / chroma);
|
|
198
|
+
let saturation;
|
|
199
|
+
if (chroma < cMid) {
|
|
200
|
+
const k1 = 0.8 * c0;
|
|
201
|
+
saturation = 0.8 * (chroma / (k1 + (1 - k1 / cMid) * chroma));
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const k1 = (0.2 * cMid ** 2 * 1.25 ** 2) / c0;
|
|
205
|
+
const offset = chroma - cMid;
|
|
206
|
+
saturation = 0.8 + 0.2 * (offset / (k1 + (1 - k1 / (cMax - cMid)) * offset));
|
|
207
|
+
}
|
|
208
|
+
return { h: hue, s: Math.min(1, Math.max(0, saturation)), l: lightness };
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=oklab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oklab.js","sourceRoot":"","sources":["../src/oklab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAS,EAAU,EAAE,CACzD,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC;AAEhE,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,kBAAkB,GAAW;IAClC,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,CAAC;IAC5D,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,CAAC;IAC5D,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,CAAC;CAC5D,CAAC;AACF,MAAM,UAAU,GAAW;IAC1B,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,CAAC,kBAAkB,CAAC;IAC3D,CAAC,kBAAkB,EAAE,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IAC1D,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,CAAC,kBAAkB,CAAC;CAC7D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AG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IACnE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC;IACtE,IAAI,UAAkB,CAAC;IACvB,IAAI,MAAM,GAAG,IAAI,EAAE,CAAC;QACnB,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;QACpB,UAAU,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACP,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;QAC7B,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * Oklab and OKHSL <-> sRGB conversion. `colors.ts` builds its OKLCH, OKHSL, and color mixing on it.\n *\n * Oklab and OKHSL are Björn Ottosson's color spaces; OKHSL's saturation is relative to the sRGB gamut at\n * each hue and lightness. This is a port of his reference implementation (https://bottosson.github.io/posts/colorpicker/),\n * Copyright (c) 2021 Björn Ottosson, used under the MIT license:\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and\n * associated documentation files (the \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the\n * following conditions: The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n * KIND, EXPRESS OR IMPLIED.\n */\n\nimport type { RgbColor } from \"./terminal-colors.ts\";\n\ntype Vector = [number, number, number];\ntype Matrix = [Vector, Vector, Vector];\n\nconst multiply = (m: Matrix, [x, y, z]: Vector): Vector =>\n\tm.map((row) => row[0] * x + row[1] * y + row[2] * z) as Vector;\n\n// ============================================================================\n// OKHSL <-> sRGB\n// ============================================================================\n\nconst LINEAR_SRGB_TO_LMS: Matrix = [\n\t[0.4122214694707629, 0.5363325372617349, 0.0514459932675022],\n\t[0.2119034958178251, 0.6806995506452344, 0.1073969535369405],\n\t[0.0883024591900564, 0.2817188391361215, 0.6299787016738222],\n];\nconst LMS_TO_LAB: Matrix = [\n\t[0.210454268309314, 0.793617774702305, -0.0040720430116193],\n\t[1.9779985324311684, -2.42859224204858, 0.450593709617411],\n\t[0.0259040424655478, 0.7827717124575296, -0.8086757549230774],\n];\nconst LAB_TO_LMS: Matrix = [\n\t[1, 0.3963377773761749, 0.2158037573099136],\n\t[1, -0.1055613458156586, -0.0638541728258133],\n\t[1, -0.0894841775298119, -1.2914855480194092],\n];\nconst LMS_TO_LINEAR_SRGB: Matrix = [\n\t[4.0767416360759583, -3.3077115392580629, 0.2309699031821043],\n\t[-1.2684379732850315, 2.6097573492876882, -0.341319376002657],\n\t[-0.0041960761386756, -0.7034186179359362, 1.7076146940746117],\n];\n/**\n * Per sRGB channel (red, green, blue): the (a, b) half-plane where that channel clips\n * first, and the polynomial approximating the maximum saturation there.\n */\nconst SATURATION_FIT: [[number, number], number[]][] = [\n\t[\n\t\t[-1.8817031, -0.80936501],\n\t\t[1.19086277, 1.76576728, 0.59662641, 0.75515197, 0.56771245],\n\t],\n\t[\n\t\t[1.8144408, -1.19445267],\n\t\t[0.73956515, -0.45954404, 0.08285427, 0.12541073, -0.14503204],\n\t],\n\t[\n\t\t[0.13110758, 1.81333971],\n\t\t[1.35733652, -0.00915799, -1.1513021, -0.50559606, 0.00692167],\n\t],\n];\nconst K1 = 0.206;\nconst K2 = 0.03;\nconst K3 = (1 + K1) / (1 + K2);\n\n/** Oklab lightness to OKHSL lightness. */\nexport const oklabToOkhslLightness = (x: number): number =>\n\t0.5 * (K3 * x - K1 + Math.sqrt((K3 * x - K1) ** 2 + 4 * K2 * K3 * x));\n/** OKHSL lightness to Oklab lightness. */\nconst okhslToOklabLightness = (x: number): number => (x * x + K1 * x) / (K3 * (x + K2));\n\n/** sRGB transfer function: linear to encoded channel, both 0-1. */\nconst linearToSrgb = (value: number): number =>\n\tvalue > 0.0031308 ? 1.055 * value ** (1 / 2.4) - 0.055 : 12.92 * value;\n/** Inverse sRGB transfer function: encoded to linear channel, both 0-1. */\nconst srgbToLinear = (value: number): number => (value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4);\n\n/** Oklab [L, a, b] to linear sRGB [r, g, b] (0-1, may leave the gamut). */\nexport function oklabToLinearSrgb(lab: Vector): Vector {\n\treturn multiply(LMS_TO_LINEAR_SRGB, multiply(LAB_TO_LMS, lab).map((value) => value ** 3) as Vector);\n}\n\n/** Linear sRGB [r, g, b] (0-1) to Oklab [L, a, b]. */\nfunction linearSrgbToOklab(rgb: Vector): Vector {\n\treturn multiply(LMS_TO_LAB, multiply(LINEAR_SRGB_TO_LMS, rgb).map(Math.cbrt) as Vector);\n}\n\n/** sRGB channels (0-255) to Oklab [L, a, b]. */\nexport function rgbToOklab({ r, g, b }: RgbColor): Vector {\n\treturn linearSrgbToOklab([r / 255, g / 255, b / 255].map(srgbToLinear) as Vector);\n}\n\n/** Linear sRGB [r, g, b] to sRGB channels (0-255, rounded), clipping out-of-gamut channels. */\nexport function linearSrgbToRgb(linear: Vector): RgbColor {\n\tconst [r, g, b] = linear.map((value) => Math.round(Math.min(1, Math.max(0, linearToSrgb(value))) * 255));\n\treturn { r, g, b };\n}\n\n/** Rate of change of each cube-root LMS component along a chroma direction (a, b). */\nfunction lmsSlopes(a: number, b: number): Vector {\n\treturn [LAB_TO_LMS[0], LAB_TO_LMS[1], LAB_TO_LMS[2]].map((row) => row[1] * a + row[2] * b) as Vector;\n}\n\n/** Largest saturation (C/L) inside sRGB for hue (a, b): polynomial fit plus one Halley step. */\nfunction maxSaturation(a: number, b: number): number {\n\tconst channel = SATURATION_FIT.findIndex(([[x, y]], index) => index === 2 || x * a + y * b > 1);\n\tconst [k0, k1, k2, k3, k4] = SATURATION_FIT[channel][1];\n\tconst weights = LMS_TO_LINEAR_SRGB[channel];\n\tconst saturation = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;\n\n\tconst slopes = lmsSlopes(a, b);\n\tconst base = slopes.map((k) => 1 + saturation * k);\n\tconst dot = (values: number[]) => values.reduce((sum, value, index) => sum + weights[index] * value, 0);\n\tconst f = dot(base.map((value) => value ** 3));\n\tconst f1 = dot(base.map((value, index) => 3 * slopes[index] * value ** 2));\n\tconst f2 = dot(base.map((value, index) => 6 * slopes[index] ** 2 * value));\n\treturn saturation - (f * f1) / (f1 * f1 - 0.5 * f * f2);\n}\n\n/** Oklab lightness and chroma of the most saturated sRGB color of hue (a, b). */\nfunction cusp(a: number, b: number): [number, number] {\n\tconst saturation = maxSaturation(a, b);\n\tconst lightness = Math.cbrt(1 / Math.max(...oklabToLinearSrgb([1, saturation * a, saturation * b])));\n\treturn [lightness, lightness * saturation];\n}\n\n/** Chroma where the constant-lightness line at `lightness` leaves the sRGB gamut. */\nfunction maxChroma(a: number, b: number, lightness: number, [cuspL, cuspC]: [number, number]): number {\n\tif (lightness <= cuspL) return (cuspC * lightness) / cuspL;\n\t// Upper half: triangle edge, then one Halley step against each channel reaching 1.\n\tconst t = (cuspC * (lightness - 1)) / (cuspL - 1);\n\tconst slopes = lmsSlopes(a, b);\n\tconst lms = slopes.map((k) => lightness + t * k);\n\tconst cubes = lms.map((value) => value ** 3);\n\tconst first = lms.map((value, index) => 3 * slopes[index] * value ** 2);\n\tconst second = lms.map((value, index) => 6 * slopes[index] ** 2 * value);\n\tconst dot = (row: Vector, values: number[]) => row[0] * values[0] + row[1] * values[1] + row[2] * values[2];\n\tconst steps = LMS_TO_LINEAR_SRGB.map((row) => {\n\t\tconst f = dot(row, cubes) - 1;\n\t\tconst f1 = dot(row, first);\n\t\tconst f2 = dot(row, second);\n\t\tconst u = f1 / (f1 * f1 - 0.5 * f * f2);\n\t\treturn u >= 0 ? -f * u : Number.MAX_VALUE;\n\t});\n\treturn t + Math.min(...steps);\n}\n\n/** OKHSL's chroma reference points at lightness L and hue (a, b): [c0, cMid, cMax]. */\nfunction chromaStops(L: number, a: number, b: number): [number, number, number] {\n\tconst peak = cusp(a, b);\n\tconst cMax = maxChroma(a, b, L, peak);\n\tconst k = cMax / Math.min(L * (peak[1] / peak[0]), (1 - L) * (peak[1] / (1 - peak[0])));\n\tconst midS =\n\t\t0.11516993 +\n\t\t1 /\n\t\t\t(7.4477897 +\n\t\t\t\t4.1590124 * b +\n\t\t\t\ta *\n\t\t\t\t\t(-2.19557347 +\n\t\t\t\t\t\t1.75198401 * b +\n\t\t\t\t\t\ta * (-2.13704948 - 10.02301043 * b + a * (-4.24894561 + 5.38770819 * b + 4.69891013 * a))));\n\tconst midT =\n\t\t0.11239642 +\n\t\t1 /\n\t\t\t(1.6132032 -\n\t\t\t\t0.68124379 * b +\n\t\t\t\ta *\n\t\t\t\t\t(0.40370612 +\n\t\t\t\t\t\t0.90148123 * b +\n\t\t\t\t\t\ta * (-0.27087943 + 0.6122399 * b + a * (0.00299215 - 0.45399568 * b - 0.14661872 * a))));\n\tconst cMid = 0.9 * k * Math.sqrt(Math.sqrt(1 / (1 / (L * midS) ** 4 + 1 / ((1 - L) * midT) ** 4)));\n\tconst c0 = Math.sqrt(1 / (1 / (L * 0.4) ** 2 + 1 / ((1 - L) * 0.8) ** 2));\n\treturn [c0, cMid, cMax];\n}\n\n/**\n * Convert OKHSL to sRGB channels (0-255, rounded), clipping out-of-gamut channels.\n * @param hue Hue in degrees.\n * @param saturation Saturation, 0-1.\n * @param lightness Lightness, 0-1.\n */\nexport function okhslToRgb(hue: number, saturation: number, lightness: number): RgbColor {\n\tconst L = okhslToOklabLightness(lightness);\n\tlet lab: Vector = [L, 0, 0];\n\tif (L > 0 && L < 1 && saturation > 0) {\n\t\tconst angle = (2 * Math.PI * (((hue % 360) + 360) % 360)) / 360;\n\t\tconst a = Math.cos(angle);\n\t\tconst b = Math.sin(angle);\n\t\tconst [c0, cMid, cMax] = chromaStops(L, a, b);\n\t\t// Chroma rises from 0 through cMid at s = 0.8 to cMax at s = 1.\n\t\tlet chroma: number;\n\t\tif (saturation < 0.8) {\n\t\t\tconst t = 1.25 * saturation;\n\t\t\tconst k1 = 0.8 * c0;\n\t\t\tchroma = (t * k1) / (1 - (1 - k1 / cMid) * t);\n\t\t} else {\n\t\t\tconst t = 5 * (saturation - 0.8);\n\t\t\tconst k1 = (0.2 * cMid ** 2 * 1.25 ** 2) / c0;\n\t\t\tchroma = cMid + (t * k1) / (1 - (1 - k1 / (cMax - cMid)) * t);\n\t\t}\n\t\tlab = [L, chroma * a, chroma * b];\n\t}\n\treturn linearSrgbToRgb(oklabToLinearSrgb(lab));\n}\n\n/**\n * Convert sRGB channels (0-255) to OKHSL.\n * @returns Hue `h` in degrees (0 for grays), saturation `s` and lightness `l` 0-1.\n */\nexport function rgbToOkhsl(rgb: RgbColor): { h: number; s: number; l: number } {\n\tconst [L, labA, labB] = rgbToOklab(rgb);\n\tconst chroma = Math.hypot(labA, labB);\n\tconst lightness = oklabToOkhslLightness(L);\n\tif (chroma < 1e-9 || lightness <= 0 || lightness >= 1) return { h: 0, s: 0, l: lightness };\n\n\tconst hue = ((Math.atan2(labB, labA) * 180) / Math.PI + 360) % 360;\n\tconst [c0, cMid, cMax] = chromaStops(L, labA / chroma, labB / chroma);\n\tlet saturation: number;\n\tif (chroma < cMid) {\n\t\tconst k1 = 0.8 * c0;\n\t\tsaturation = 0.8 * (chroma / (k1 + (1 - k1 / cMid) * chroma));\n\t} else {\n\t\tconst k1 = (0.2 * cMid ** 2 * 1.25 ** 2) / c0;\n\t\tconst offset = chroma - cMid;\n\t\tsaturation = 0.8 + 0.2 * (offset / (k1 + (1 - k1 / (cMax - cMid)) * offset));\n\t}\n\treturn { h: hue, s: Math.min(1, Math.max(0, saturation)), l: lightness };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdin-buffer.d.ts","sourceRoot":"","sources":["../src/stdin-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA+OtC,MAAM,MAAM,kBAAkB,GAAG;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACf,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,qBAAa,WAAY,SAAQ,YAAY,CAAC,mBAAmB,CAAC;IACjE,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,8BAA8B,CAAqB;IAE3D,YAAY,OAAO,GAAE,kBAAuB,EAI3C;IAEM,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAqG1C;IAED,OAAO,CAAC,gBAAgB;IAWxB,KAAK,IAAI,MAAM,EAAE,CAchB;IAED,KAAK,IAAI,IAAI,CASZ;IAED,SAAS,IAAI,MAAM,CAElB;IAED,OAAO,IAAI,IAAI,CAEd;CACD","sourcesContent":["/**\n * StdinBuffer buffers input and emits complete sequences.\n *\n * This is necessary because stdin data events can arrive in partial chunks,\n * especially for escape sequences like mouse events. Without buffering,\n * partial sequences can be misinterpreted as regular keypresses.\n *\n * For example, the mouse SGR sequence `\\x1b[<35;20;5m` might arrive as:\n * - Event 1: `\\x1b`\n * - Event 2: `[<35`\n * - Event 3: `;20;5m`\n *\n * The buffer accumulates these until a complete sequence is detected.\n * Call the `process()` method to feed input data.\n *\n * Based on code from OpenTUI (https://github.com/anomalyco/opentui)\n * MIT License - Copyright (c) 2025 opentui\n */\n\nimport { EventEmitter } from \"events\";\n\nconst ESC = \"\\x1b\";\nconst DEFAULT_SEQUENCE_TIMEOUT_MS = 50;\nconst DEFAULT_ESCAPE_TIMEOUT_MS = 10;\nconst BRACKETED_PASTE_START = \"\\x1b[200~\";\nconst BRACKETED_PASTE_END = \"\\x1b[201~\";\n\n/**\n * Check if a string is a complete escape sequence or needs more data\n */\nfunction isCompleteSequence(data: string): \"complete\" | \"incomplete\" | \"not-escape\" {\n\tif (!data.startsWith(ESC)) {\n\t\treturn \"not-escape\";\n\t}\n\n\tif (data.length === 1) {\n\t\treturn \"incomplete\";\n\t}\n\n\tconst afterEsc = data.slice(1);\n\n\t// CSI sequences: ESC [\n\tif (afterEsc.startsWith(\"[\")) {\n\t\t// Check for old-style mouse sequence: ESC[M + 3 bytes\n\t\tif (afterEsc.startsWith(\"[M\")) {\n\t\t\t// Old-style mouse needs ESC[M + 3 bytes = 6 total\n\t\t\treturn data.length >= 6 ? \"complete\" : \"incomplete\";\n\t\t}\n\t\treturn isCompleteCsiSequence(data);\n\t}\n\n\t// OSC sequences: ESC ]\n\tif (afterEsc.startsWith(\"]\")) {\n\t\treturn isCompleteOscSequence(data);\n\t}\n\n\t// DCS sequences: ESC P ... ESC \\ (includes XTVersion responses)\n\tif (afterEsc.startsWith(\"P\")) {\n\t\treturn isCompleteDcsSequence(data);\n\t}\n\n\t// APC sequences: ESC _ ... ESC \\ (includes Kitty graphics responses)\n\tif (afterEsc.startsWith(\"_\")) {\n\t\treturn isCompleteApcSequence(data);\n\t}\n\n\t// SS3 sequences: ESC O\n\tif (afterEsc.startsWith(\"O\")) {\n\t\t// ESC O followed by a single character\n\t\treturn afterEsc.length >= 2 ? \"complete\" : \"incomplete\";\n\t}\n\n\t// Meta key sequences: ESC followed by a single character\n\tif (afterEsc.length === 1) {\n\t\treturn \"complete\";\n\t}\n\n\t// Unknown escape sequence - treat as complete\n\treturn \"complete\";\n}\n\n/**\n * Check if CSI sequence is complete\n * CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)\n */\nfunction isCompleteCsiSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}[`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// Need at least ESC [ and one more character\n\tif (data.length < 3) {\n\t\treturn \"incomplete\";\n\t}\n\n\tconst payload = data.slice(2);\n\n\t// CSI sequences end with a byte in the range 0x40-0x7E (@-~)\n\t// This includes all letters and several special characters\n\tconst lastChar = payload[payload.length - 1];\n\tconst lastCharCode = lastChar.charCodeAt(0);\n\n\tif (lastCharCode >= 0x40 && lastCharCode <= 0x7e) {\n\t\t// Special handling for SGR mouse sequences\n\t\t// Format: ESC[<B;X;Ym or ESC[<B;X;YM\n\t\tif (payload.startsWith(\"<\")) {\n\t\t\t// Must have format: <digits;digits;digits[Mm]\n\t\t\tconst mouseMatch = /^<\\d+;\\d+;\\d+[Mm]$/.test(payload);\n\t\t\tif (mouseMatch) {\n\t\t\t\treturn \"complete\";\n\t\t\t}\n\t\t\t// If it ends with M or m but doesn't match the pattern, still incomplete\n\t\t\tif (lastChar === \"M\" || lastChar === \"m\") {\n\t\t\t\t// Check if we have the right structure\n\t\t\t\tconst parts = payload.slice(1, -1).split(\";\");\n\t\t\t\tif (parts.length === 3 && parts.every((p) => /^\\d+$/.test(p))) {\n\t\t\t\t\treturn \"complete\";\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn \"incomplete\";\n\t\t}\n\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if OSC sequence is complete\n * OSC sequences: ESC ] ... ST (where ST is ESC \\ or BEL)\n */\nfunction isCompleteOscSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}]`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// OSC sequences end with ST (ESC \\) or BEL (\\x07)\n\tif (data.endsWith(`${ESC}\\\\`) || data.endsWith(\"\\x07\")) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if DCS (Device Control String) sequence is complete\n * DCS sequences: ESC P ... ST (where ST is ESC \\)\n * Used for XTVersion responses like ESC P >| ... ESC \\\n */\nfunction isCompleteDcsSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}P`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// DCS sequences end with ST (ESC \\)\n\tif (data.endsWith(`${ESC}\\\\`)) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Check if APC (Application Program Command) sequence is complete\n * APC sequences: ESC _ ... ST (where ST is ESC \\)\n * Used for Kitty graphics responses like ESC _ G ... ESC \\\n */\nfunction isCompleteApcSequence(data: string): \"complete\" | \"incomplete\" {\n\tif (!data.startsWith(`${ESC}_`)) {\n\t\treturn \"complete\";\n\t}\n\n\t// APC sequences end with ST (ESC \\)\n\tif (data.endsWith(`${ESC}\\\\`)) {\n\t\treturn \"complete\";\n\t}\n\n\treturn \"incomplete\";\n}\n\n/**\n * Split accumulated buffer into complete sequences\n */\nfunction parseUnmodifiedKittyPrintableCodepoint(sequence: string): number | undefined {\n\tconst match = sequence.match(/^\\x1b\\[(\\d+)(?::\\d*)?(?::\\d+)?u$/);\n\tif (!match) return undefined;\n\n\tconst codepoint = parseInt(match[1]!, 10);\n\treturn codepoint >= 32 ? codepoint : undefined;\n}\n\nfunction extractCompleteSequences(buffer: string): { sequences: string[]; remainder: string } {\n\tconst sequences: string[] = [];\n\tlet pos = 0;\n\n\twhile (pos < buffer.length) {\n\t\tconst remaining = buffer.slice(pos);\n\n\t\t// Try to extract a sequence starting at this position\n\t\tif (remaining.startsWith(ESC)) {\n\t\t\t// Find the end of this escape sequence\n\t\t\tlet seqEnd = 1;\n\t\t\twhile (seqEnd <= remaining.length) {\n\t\t\t\tconst candidate = remaining.slice(0, seqEnd);\n\t\t\t\tconst status = isCompleteSequence(candidate);\n\n\t\t\t\tif (status === \"complete\") {\n\t\t\t\t\t// WezTerm with enable_kitty_keyboard sends the Escape key press as a\n\t\t\t\t\t// raw '\\x1b' byte (simple text path in encode_kitty, ignoring\n\t\t\t\t\t// DISAMBIGUATE_ESCAPE_CODES) and the release as a full Kitty CSI-u\n\t\t\t\t\t// sequence. These arrive concatenated as '\\x1b\\x1b[27;...u'.\n\t\t\t\t\t// The buffer would normally treat '\\x1b\\x1b' as a complete meta-key\n\t\t\t\t\t// sequence (ESC + single char), leaving '[27;...u' to be typed as\n\t\t\t\t\t// plain text. If the character immediately following '\\x1b\\x1b'\n\t\t\t\t\t// would begin a new escape sequence, emit only the first ESC and\n\t\t\t\t\t// restart from the second.\n\t\t\t\t\tif (candidate === \"\\x1b\\x1b\") {\n\t\t\t\t\t\tconst nextChar = remaining[seqEnd];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnextChar === \"[\" || // CSI\n\t\t\t\t\t\t\tnextChar === \"]\" || // OSC\n\t\t\t\t\t\t\tnextChar === \"O\" || // SS3\n\t\t\t\t\t\t\tnextChar === \"P\" || // DCS\n\t\t\t\t\t\t\tnextChar === \"_\" // APC\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tsequences.push(ESC);\n\t\t\t\t\t\t\tpos += 1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsequences.push(candidate);\n\t\t\t\t\tpos += seqEnd;\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (status === \"incomplete\") {\n\t\t\t\t\tseqEnd++;\n\t\t\t\t} else {\n\t\t\t\t\t// Should not happen when starting with ESC\n\t\t\t\t\tsequences.push(candidate);\n\t\t\t\t\tpos += seqEnd;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (seqEnd > remaining.length) {\n\t\t\t\treturn { sequences, remainder: remaining };\n\t\t\t}\n\t\t} else {\n\t\t\t// Not an escape sequence - take a single character\n\t\t\tsequences.push(remaining[0]!);\n\t\t\tpos++;\n\t\t}\n\t}\n\n\treturn { sequences, remainder: \"\" };\n}\n\nexport type StdinBufferOptions = {\n\t/**\n\t * Maximum time to wait for an incomplete sequence such as CSI or mouse\n\t * (default: 50ms).\n\t */\n\ttimeout?: number;\n\t/**\n\t * Maximum time to wait after a lone ESC before treating it as Escape\n\t * (default: 10ms). Increase for high-latency Alt+key input (SSH).\n\t */\n\tescapeTimeout?: number;\n};\n\nexport type StdinBufferEventMap = {\n\tdata: [string];\n\tpaste: [string];\n};\n\n/**\n * Buffers stdin input and emits complete sequences via the 'data' event.\n * Handles partial escape sequences that arrive across multiple chunks.\n */\nexport class StdinBuffer extends EventEmitter<StdinBufferEventMap> {\n\tprivate buffer: string = \"\";\n\tprivate timeout: ReturnType<typeof setTimeout> | null = null;\n\tprivate readonly timeoutMs: number;\n\tprivate readonly escapeTimeoutMs: number;\n\tprivate pasteMode: boolean = false;\n\tprivate pasteBuffer: string = \"\";\n\tprivate pendingKittyPrintableCodepoint: number | undefined;\n\n\tconstructor(options: StdinBufferOptions = {}) {\n\t\tsuper();\n\t\tthis.timeoutMs = options.timeout ?? DEFAULT_SEQUENCE_TIMEOUT_MS;\n\t\tthis.escapeTimeoutMs = options.escapeTimeout ?? DEFAULT_ESCAPE_TIMEOUT_MS;\n\t}\n\n\tpublic process(data: string | Buffer): void {\n\t\t// Clear any pending timeout\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\n\t\t// Handle high-byte conversion (for compatibility with parseKeypress)\n\t\t// If buffer has single byte > 127, convert to ESC + (byte - 128)\n\t\tlet str: string;\n\t\tif (Buffer.isBuffer(data)) {\n\t\t\tif (data.length === 1 && data[0]! > 127) {\n\t\t\t\tconst byte = data[0]! - 128;\n\t\t\t\tstr = `\\x1b${String.fromCharCode(byte)}`;\n\t\t\t} else {\n\t\t\t\tstr = data.toString();\n\t\t\t}\n\t\t} else {\n\t\t\tstr = data;\n\t\t}\n\n\t\tif (str.length === 0 && this.buffer.length === 0) {\n\t\t\tthis.emitDataSequence(\"\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.buffer += str;\n\n\t\tif (this.pasteMode) {\n\t\t\tthis.pasteBuffer += this.buffer;\n\t\t\tthis.buffer = \"\";\n\n\t\t\tconst endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n\t\t\tif (endIndex !== -1) {\n\t\t\t\tconst pastedContent = this.pasteBuffer.slice(0, endIndex);\n\t\t\t\tconst remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n\t\t\t\tthis.pasteMode = false;\n\t\t\t\tthis.pasteBuffer = \"\";\n\t\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\n\t\t\t\tthis.emit(\"paste\", pastedContent);\n\n\t\t\t\tif (remaining.length > 0) {\n\t\t\t\t\tthis.process(remaining);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);\n\t\tif (startIndex !== -1) {\n\t\t\tif (startIndex > 0) {\n\t\t\t\tconst beforePaste = this.buffer.slice(0, startIndex);\n\t\t\t\tconst result = extractCompleteSequences(beforePaste);\n\t\t\t\tfor (const sequence of result.sequences) {\n\t\t\t\t\tthis.emitDataSequence(sequence);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\t\tthis.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);\n\t\t\tthis.pasteMode = true;\n\t\t\tthis.pasteBuffer = this.buffer;\n\t\t\tthis.buffer = \"\";\n\n\t\t\tconst endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);\n\t\t\tif (endIndex !== -1) {\n\t\t\t\tconst pastedContent = this.pasteBuffer.slice(0, endIndex);\n\t\t\t\tconst remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);\n\n\t\t\t\tthis.pasteMode = false;\n\t\t\t\tthis.pasteBuffer = \"\";\n\t\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\n\t\t\t\tthis.emit(\"paste\", pastedContent);\n\n\t\t\t\tif (remaining.length > 0) {\n\t\t\t\t\tthis.process(remaining);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst result = extractCompleteSequences(this.buffer);\n\t\tthis.buffer = result.remainder;\n\n\t\tfor (const sequence of result.sequences) {\n\t\t\tthis.emitDataSequence(sequence);\n\t\t}\n\n\t\tif (this.buffer.length > 0) {\n\t\t\tconst timeoutMs = this.buffer === ESC ? this.escapeTimeoutMs : this.timeoutMs;\n\t\t\tthis.timeout = setTimeout(() => {\n\t\t\t\tconst flushed = this.flush();\n\n\t\t\t\tfor (const sequence of flushed) {\n\t\t\t\t\tthis.emitDataSequence(sequence);\n\t\t\t\t}\n\t\t\t}, timeoutMs);\n\t\t}\n\t}\n\n\tprivate emitDataSequence(sequence: string): void {\n\t\tconst rawCodepoint = sequence.length === 1 ? sequence.codePointAt(0) : undefined;\n\t\tif (rawCodepoint !== undefined && rawCodepoint === this.pendingKittyPrintableCodepoint) {\n\t\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.pendingKittyPrintableCodepoint = parseUnmodifiedKittyPrintableCodepoint(sequence);\n\t\tthis.emit(\"data\", sequence);\n\t}\n\n\tflush(): string[] {\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\n\t\tif (this.buffer.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst sequences = [this.buffer];\n\t\tthis.buffer = \"\";\n\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t\treturn sequences;\n\t}\n\n\tclear(): void {\n\t\tif (this.timeout) {\n\t\t\tclearTimeout(this.timeout);\n\t\t\tthis.timeout = null;\n\t\t}\n\t\tthis.buffer = \"\";\n\t\tthis.pasteMode = false;\n\t\tthis.pasteBuffer = \"\";\n\t\tthis.pendingKittyPrintableCodepoint = undefined;\n\t}\n\n\tgetBuffer(): string {\n\t\treturn this.buffer;\n\t}\n\n\tdestroy(): void {\n\t\tthis.clear();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stdin-buffer.d.ts","sourceRoot":"","sources":["../src/stdin-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA+OtC,MAAM,MAAM,kBAAkB,GAAG;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACf,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,qBAAa,WAAY,SAAQ,YAAY,CAAC,mBAAmB,CAAC;IACjE,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,8BAA8B,CAAqB;IAE3D,YAAY,OAAO,GAAE,kBAAuB,EAI3C;IAEM,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAqG1C;IAED,OAAO,CAAC,gBAAgB;IAWxB,KAAK,IAAI,MAAM,EAAE,CAchB;IAED,KAAK,IAAI,IAAI,CASZ;IAED,SAAS,IAAI,MAAM,CAElB;IAED,OAAO,IAAI,IAAI,CAEd;CACD"}
|