Files
order-notification-automation/web/modules/assistant/dsh-native.js
T

82 lines
3.2 KiB
JavaScript

/* Adapted from DeepSeek Harness 0.2.1-rc.2, Copyright (c) 2026 DeepSeek.
* MIT; see licenses/DeepSeek-Harness-MIT.txt and DSH-native-NOTICES.md.
* Geometry/grouping bodies are upstream; wrapper and fixed-catalog resolution
* remove React/Cordis and native host command aliases. */
(function (root) {
'use strict';
const SIDEBAR_AUTO_COLLAPSE = 1024;
/** Maximum normal right panel width as a fraction of the frame. */
const RIGHTBAR_MAX_RATIO = 0.7;
/** First-open right panel preference as a fraction of the frame. */
const RIGHTBAR_DEFAULT_RATIO = 0.45;
/**
* Clamp a panel width into its contract range.
* @param px - requested width.
* @param min - range lower bound.
* @param max - range upper bound.
* @returns the clamped width.
*/
function clampWidth(px, min, max) {
return Math.min(max, Math.max(min, Math.round(px)));
}
/**
* Solve the three column widths for one viewport frame.
* @param viewport - available frame width in px.
* @param sidebar - sidebar width preference in px (0 = closed).
* @param rightbar - requested right panel width in px (0 = no track).
* @param collapsedWidth - track width of the closed sidebar; the default keeps
* the icon rail, 0 hides the column entirely (macOS desktop).
* @returns actual widths after shrinking or removing the right track; only
* without that track may the center fall below its minimum, down to zero.
*/
function computeColumns(viewport, sidebar, rightbar, collapsedWidth = 56) {
const s = sidebar === 0 ? collapsedWidth : clampWidth(sidebar, 264, 420);
const available = viewport - s - 400;
const r =
rightbar === 0 || available < 300
? 0
: Math.min(available, clampWidth(rightbar, 300, viewport * RIGHTBAR_MAX_RATIO));
return {
sidebar: s,
center: Math.max(0, viewport - s - r),
rightbar: r,
};
}
function groupOptions(options) {
const groups = /* @__PURE__ */ new Map();
for (const option of options) {
const name = option.group?.name;
const existing = groups.get(name);
if (existing !== void 0) existing.rows.push(option);
else
groups.set(name, {
group: option.group,
rows: [option],
});
}
return [...groups.values()];
}
function resolveCommand(token, descriptors) {
return descriptors.find((descriptor) => descriptor.name === token);
}
// Native popup substring policy; fuzzy mode and its React primitives omitted.
function filterOptions(options, search) {
const query = search.trim().toLowerCase(),
groups = groupOptions(options);
const ordered = groups.some((group) => group.group !== undefined)
? groups.flatMap((group) => group.rows)
: options;
return query === ''
? ordered
: ordered.filter(
(o) =>
o.label.toLowerCase().includes(query) ||
(o.detail?.toLowerCase().includes(query) ?? false),
);
}
const api = { clampWidth, computeColumns, resolveCommand, filterOptions, groupOptions };
if (typeof module === 'object' && module.exports) module.exports = api;
else root.AssistantNative = api;
})(typeof window === 'object' ? window : globalThis);