@gitkraken/core-gitlens 0.47.0 → 0.48.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/dist/git-cli/providers/branches.js +8 -4
  3. package/dist/git-cli/providers/branches.js.map +1 -1
  4. package/dist/git-cli/providers/config.js +2 -2
  5. package/dist/git-cli/providers/pausedOperations.js +2 -2
  6. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  7. package/dist/git-cli/providers/staging.js +1 -1
  8. package/dist/ipc/discovery.js +1 -1
  9. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  10. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  11. package/dist/plus/ai/providers/anthropicProvider.js +0 -20
  12. package/dist/plus/ai/providers/anthropicProvider.js.map +1 -1
  13. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  14. package/dist/plus/integrations/models/publicIntegration.d.ts +0 -1
  15. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  16. package/dist/plus/integrations/providers/issueSorts.d.ts +0 -1
  17. package/dist/plus/integrations/reads/drains.d.ts +0 -1
  18. package/dist/utils/date.d.ts +1 -0
  19. package/dist/utils/date.js +10 -1
  20. package/dist/utils/date.js.map +1 -1
  21. package/dist/utils/env/node/exec.js +2 -2
  22. package/dist/utils/keys/keymapDispatcher.d.ts +12 -0
  23. package/dist/utils/keys/keymapDispatcher.js +33 -1
  24. package/dist/utils/keys/keymapDispatcher.js.map +1 -1
  25. package/dist/utils/pausedOperation.js +48 -16
  26. package/dist/utils/pausedOperation.js.map +1 -1
  27. package/dist/utils/plural.d.ts +1 -0
  28. package/dist/utils/plural.js +7 -2
  29. package/dist/utils/plural.js.map +1 -1
  30. package/dist/utils/wheel.d.ts +8 -0
  31. package/dist/utils/wheel.js +12 -0
  32. package/dist/utils/wheel.js.map +1 -0
  33. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"anthropicProvider.js","names":["provider"],"sources":["../../../../../plus/ai/src/providers/anthropicProvider.ts"],"sourcesContent":["import { anthropicProviderDescriptor as provider } from '../constants.js';\nimport { AIError, AIErrorReason } from '../errors.js';\nimport type { AIActionType, AIModel } from '../models/model.js';\nimport type { AIChatMessage, AIChatMessageRole, AIResponseFormat, AIToolDefinition } from '../models/provider.js';\nimport { getReducedMaxInputTokens } from '../utils/ai.utils.js';\nimport type { ChatCompletionRequest } from './openAICompatibleProviderBase.js';\nimport { OpenAICompatibleProviderBase } from './openAICompatibleProviderBase.js';\n\ntype AnthropicModel = AIModel<typeof provider.id>;\nconst models: AnthropicModel[] = [\n\t{\n\t\tid: 'claude-fable-5-2',\n\t\tname: 'Claude Fable 5.2',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5-5',\n\t\tname: 'Claude Opus 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5-5',\n\t\tname: 'Claude Sonnet 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-haiku-5-5',\n\t\tname: 'Claude Haiku 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\tdefault: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5-1',\n\t\tname: 'Claude Fable 5.1',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5',\n\t\tname: 'Claude Opus 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5',\n\t\tname: 'Claude Fable 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5',\n\t\tname: 'Claude Sonnet 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-8',\n\t\tname: 'Claude Opus 4.8',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-7',\n\t\tname: 'Claude Opus 4.7',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-4-6',\n\t\tname: 'Claude Sonnet 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-6',\n\t\tname: 'Claude Opus 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5-20251001',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t// Anthropic retires Sonnet 4.5 on 2026-11-30 — remove both entries after that date (#6164)\n\t{\n\t\tid: 'claude-sonnet-4-5',\n\t\tname: 'Claude Sonnet 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-sonnet-4-5-20250929',\n\t\tname: 'Claude Sonnet 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5-20251101',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n];\n\nexport class AnthropicProvider extends OpenAICompatibleProviderBase<typeof provider.id> {\n\treadonly id = provider.id;\n\treadonly name = provider.name;\n\treadonly supportsTools = true;\n\tprotected readonly descriptor = provider;\n\tprotected readonly config = {\n\t\tkeyUrl: 'https://console.anthropic.com/account/keys',\n\t\tkeyValidator: /(?:sk-)?[a-zA-Z0-9-_]{32,}/,\n\t};\n\n\tgetModels(): Promise<readonly AIModel<typeof provider.id>[]> {\n\t\treturn Promise.resolve(models);\n\t}\n\n\tprotected getUrl(_model: AIModel<typeof provider.id>): string {\n\t\treturn 'https://api.anthropic.com/v1/messages';\n\t}\n\n\t// Anthropic uses `output_config.format` (no name/strict — enforcement is unconditional) and\n\t// rejects unknown fields, so this must fully replace the base's `response_format` translation\n\tprotected override applyResponseFormat(\n\t\trequest: ChatCompletionRequest,\n\t\t_model: AIModel<typeof provider.id>,\n\t\tresponseFormat: AIResponseFormat,\n\t): void {\n\t\trequest.output_config = { format: { type: 'json_schema', schema: responseFormat.schema } };\n\t}\n\n\tprotected override getHeaders<TAction extends AIActionType>(\n\t\t_action: TAction,\n\t\tapiKey: string,\n\t\t_model: AIModel<typeof provider.id>,\n\t\t_url: string,\n\t): Record<string, string> {\n\t\treturn {\n\t\t\tAccept: 'application/json',\n\t\t\t'Content-Type': 'application/json',\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t'x-api-key': apiKey,\n\t\t\t'anthropic-version': '2023-06-01',\n\t\t};\n\t}\n\n\tprotected override fetchCore<TAction extends AIActionType>(\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tapiKey: string,\n\t\trequest: object,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<Response> {\n\t\tif ('max_completion_tokens' in request) {\n\t\t\tconst { max_completion_tokens: max, ...rest } = request;\n\t\t\trequest = max ? { max_tokens: max, ...rest } : rest;\n\t\t}\n\t\treturn super.fetchCore(action, model, apiKey, request, signal);\n\t}\n\n\tprotected override extractSystemPrompt(messages: AIChatMessage<AIChatMessageRole>[]): {\n\t\tmessages: AIChatMessage<AIChatMessageRole>[];\n\t\tsystem?: string;\n\t} {\n\t\t// Anthropic's Messages API rejects `system`-role entries in `messages` and requires the initial\n\t\t// system prompt in the top-level `system` field, so pull any such messages out.\n\t\tconst systemMessages = messages.filter(m => m.role === 'system');\n\t\tif (!systemMessages.length) return { messages: messages };\n\n\t\treturn {\n\t\t\tsystem: systemMessages.map(m => m.content).join('\\n\\n'),\n\t\t\tmessages: messages.filter(m => m.role !== 'system'),\n\t\t};\n\t}\n\n\tprotected override async handleFetchFailure<TAction extends AIActionType>(\n\t\trsp: Response,\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tretries: number,\n\t\tmaxInputTokens: number,\n\t\tbody?: string,\n\t\tsentTools?: boolean,\n\t): Promise<{ retry: true; maxInputTokens: number; withoutTools?: boolean }> {\n\t\tif (rsp.status !== 404 && rsp.status !== 429) {\n\t\t\t// Read into `body` (not the response) so `super.handleFetchFailure` below can still\n\t\t\t// use it; consuming the response here would lose Anthropic's error for the fallback.\n\t\t\tbody ??= await rsp\n\t\t\t\t.clone()\n\t\t\t\t.text()\n\t\t\t\t.catch(() => undefined);\n\t\t\tlet json;\n\t\t\ttry {\n\t\t\t\tjson = (body != null ? JSON.parse(body) : undefined) as AnthropicError | undefined;\n\t\t\t} catch {}\n\n\t\t\tdebugger;\n\n\t\t\tif (json?.error?.type === 'invalid_request_error') {\n\t\t\t\tif (json?.error?.message?.includes('prompt is too long')) {\n\t\t\t\t\tif (retries < 3) {\n\t\t\t\t\t\t// Extract actual token count from error to calculate smarter reduction\n\t\t\t\t\t\tconst match = /prompt is too long: (\\d+) tokens/.exec(json?.error?.message);\n\t\t\t\t\t\tconst estimatedTokens = match?.[1] != null ? parseInt(match[1], 10) : undefined;\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tretry: true,\n\t\t\t\t\t\t\tmaxInputTokens: getReducedMaxInputTokens(maxInputTokens, retries + 1, estimatedTokens),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RequestTooLarge,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (json?.error?.message?.includes('balance is too low')) {\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RateLimitOrFundsExceeded,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn super.handleFetchFailure(rsp, action, model, retries, maxInputTokens, body, sentTools);\n\t}\n\n\tprotected override serializeTools(tools: readonly AIToolDefinition[]): { tools: unknown[] } {\n\t\t// Anthropic names the schema field `input_schema` and has no `function` envelope.\n\t\treturn {\n\t\t\ttools: tools.map(t => ({ name: t.name, description: t.description, input_schema: t.parameters })),\n\t\t};\n\t}\n\n\tprotected override serializeMessages(messages: AIChatMessage<AIChatMessageRole>[]): unknown[] {\n\t\tconst out: unknown[] = [];\n\n\t\tfor (const m of messages) {\n\t\t\t// Anthropic carries tool results as `tool_result` blocks on a *user* message, not a\n\t\t\t// `tool`-role message. Consecutive results are batched into one user turn, matching how the\n\t\t\t// API expects a multi-tool-call round to be answered.\n\t\t\tif (m.role === 'tool') {\n\t\t\t\t// See the base provider: a result with no call id can't be addressed, so it goes as plain\n\t\t\t\t// text instead of a `tool_use_id: undefined` block the API rejects.\n\t\t\t\tif (m.toolCallId == null) {\n\t\t\t\t\tout.push({ role: 'user', content: m.content });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst block = { type: 'tool_result', tool_use_id: m.toolCallId, content: m.content };\n\t\t\t\tconst last = out.at(-1) as { role?: string; content?: unknown[] } | undefined;\n\t\t\t\tif (last?.role === 'user' && Array.isArray(last.content) && isToolResultBlocks(last.content)) {\n\t\t\t\t\tlast.content.push(block);\n\t\t\t\t} else {\n\t\t\t\t\tout.push({ role: 'user', content: [block] });\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (m.role === 'assistant' && m.toolCalls?.length) {\n\t\t\t\tout.push({\n\t\t\t\t\trole: 'assistant',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t...(m.content ? [{ type: 'text', text: m.content }] : []),\n\t\t\t\t\t\t...m.toolCalls.map(c => ({ type: 'tool_use', id: c.id, name: c.name, input: c.args })),\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tout.push({ role: m.role, content: m.content });\n\t\t}\n\n\t\treturn out;\n\t}\n}\n\n/** Whether an assembled user message's content is a batch of `tool_result` blocks we can append to. */\nfunction isToolResultBlocks(content: unknown[]): content is { type: string }[] {\n\treturn content.every(b => (b as { type?: string })?.type === 'tool_result');\n}\n\ninterface AnthropicError {\n\ttype: 'error';\n\terror: {\n\t\ttype:\n\t\t\t| 'invalid_request_error'\n\t\t\t| 'authentication_error'\n\t\t\t| 'permission_error'\n\t\t\t| 'not_found_error'\n\t\t\t| 'rate_limit_error'\n\t\t\t| 'api_error'\n\t\t\t| 'overloaded_error';\n\t\tmessage: string;\n\t};\n}\n"],"mappings":";;;;;AASA,MAAM,SAA2B;CAChC;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EAEV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,SAAS;EACT,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EAEV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EAEV,aAAa;CACd;CACA;EACC,IAAI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AK;KAAE,MAAM;KAAQ,SAAS,CAAC,KAAK;IAAE,CAAC;IAE5C;GACD;GAEA,IAAI,EAAE,SAAS,eAAe,EAAE,WAAW,QAAQ;IAClD,IAAI,KAAK;KACR,MAAM;KACN,SAAS,CACR,GAAI,EAAE,UAAU,CAAC;MAAE,MAAM;MAAQ,MAAM,EAAE;KAAQ,CAAC,IAAI,CAAC,GACvD,GAAG,EAAE,UAAU,KAAI,OAAM;MAAE,MAAM;MAAY,IAAI,EAAE;MAAI,MAAM,EAAE;MAAM,OAAO,EAAE;KAAK,EAAE,CACtF;IACD,CAAC;IACD;GACD;GAEA,IAAI,KAAK;IAAE,MAAM,EAAE;IAAM,SAAS,EAAE;GAAQ,CAAC;EAC9C;EAEA,OAAO;CACR;AACD;;AAGA,SAAS,mBAAmB,SAAmD;CAC9E,OAAO,QAAQ,OAAM,MAAM,GAAyB,SAAS,aAAa;AAC3E"}
1
+ {"version":3,"file":"anthropicProvider.js","names":["provider"],"sources":["../../../../../plus/ai/src/providers/anthropicProvider.ts"],"sourcesContent":["import { anthropicProviderDescriptor as provider } from '../constants.js';\nimport { AIError, AIErrorReason } from '../errors.js';\nimport type { AIActionType, AIModel } from '../models/model.js';\nimport type { AIChatMessage, AIChatMessageRole, AIResponseFormat, AIToolDefinition } from '../models/provider.js';\nimport { getReducedMaxInputTokens } from '../utils/ai.utils.js';\nimport type { ChatCompletionRequest } from './openAICompatibleProviderBase.js';\nimport { OpenAICompatibleProviderBase } from './openAICompatibleProviderBase.js';\n\ntype AnthropicModel = AIModel<typeof provider.id>;\nconst models: AnthropicModel[] = [\n\t{\n\t\tid: 'claude-fable-5-2',\n\t\tname: 'Claude Fable 5.2',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5-5',\n\t\tname: 'Claude Opus 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5-5',\n\t\tname: 'Claude Sonnet 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-haiku-5-5',\n\t\tname: 'Claude Haiku 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\tdefault: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5-1',\n\t\tname: 'Claude Fable 5.1',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5',\n\t\tname: 'Claude Opus 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5',\n\t\tname: 'Claude Fable 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5',\n\t\tname: 'Claude Sonnet 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-8',\n\t\tname: 'Claude Opus 4.8',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-7',\n\t\tname: 'Claude Opus 4.7',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-4-6',\n\t\tname: 'Claude Sonnet 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-6',\n\t\tname: 'Claude Opus 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5-20251001',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5-20251101',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n];\n\nexport class AnthropicProvider extends OpenAICompatibleProviderBase<typeof provider.id> {\n\treadonly id = provider.id;\n\treadonly name = provider.name;\n\treadonly supportsTools = true;\n\tprotected readonly descriptor = provider;\n\tprotected readonly config = {\n\t\tkeyUrl: 'https://console.anthropic.com/account/keys',\n\t\tkeyValidator: /(?:sk-)?[a-zA-Z0-9-_]{32,}/,\n\t};\n\n\tgetModels(): Promise<readonly AIModel<typeof provider.id>[]> {\n\t\treturn Promise.resolve(models);\n\t}\n\n\tprotected getUrl(_model: AIModel<typeof provider.id>): string {\n\t\treturn 'https://api.anthropic.com/v1/messages';\n\t}\n\n\t// Anthropic uses `output_config.format` (no name/strict — enforcement is unconditional) and\n\t// rejects unknown fields, so this must fully replace the base's `response_format` translation\n\tprotected override applyResponseFormat(\n\t\trequest: ChatCompletionRequest,\n\t\t_model: AIModel<typeof provider.id>,\n\t\tresponseFormat: AIResponseFormat,\n\t): void {\n\t\trequest.output_config = { format: { type: 'json_schema', schema: responseFormat.schema } };\n\t}\n\n\tprotected override getHeaders<TAction extends AIActionType>(\n\t\t_action: TAction,\n\t\tapiKey: string,\n\t\t_model: AIModel<typeof provider.id>,\n\t\t_url: string,\n\t): Record<string, string> {\n\t\treturn {\n\t\t\tAccept: 'application/json',\n\t\t\t'Content-Type': 'application/json',\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t'x-api-key': apiKey,\n\t\t\t'anthropic-version': '2023-06-01',\n\t\t};\n\t}\n\n\tprotected override fetchCore<TAction extends AIActionType>(\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tapiKey: string,\n\t\trequest: object,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<Response> {\n\t\tif ('max_completion_tokens' in request) {\n\t\t\tconst { max_completion_tokens: max, ...rest } = request;\n\t\t\trequest = max ? { max_tokens: max, ...rest } : rest;\n\t\t}\n\t\treturn super.fetchCore(action, model, apiKey, request, signal);\n\t}\n\n\tprotected override extractSystemPrompt(messages: AIChatMessage<AIChatMessageRole>[]): {\n\t\tmessages: AIChatMessage<AIChatMessageRole>[];\n\t\tsystem?: string;\n\t} {\n\t\t// Anthropic's Messages API rejects `system`-role entries in `messages` and requires the initial\n\t\t// system prompt in the top-level `system` field, so pull any such messages out.\n\t\tconst systemMessages = messages.filter(m => m.role === 'system');\n\t\tif (!systemMessages.length) return { messages: messages };\n\n\t\treturn {\n\t\t\tsystem: systemMessages.map(m => m.content).join('\\n\\n'),\n\t\t\tmessages: messages.filter(m => m.role !== 'system'),\n\t\t};\n\t}\n\n\tprotected override async handleFetchFailure<TAction extends AIActionType>(\n\t\trsp: Response,\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tretries: number,\n\t\tmaxInputTokens: number,\n\t\tbody?: string,\n\t\tsentTools?: boolean,\n\t): Promise<{ retry: true; maxInputTokens: number; withoutTools?: boolean }> {\n\t\tif (rsp.status !== 404 && rsp.status !== 429) {\n\t\t\t// Read into `body` (not the response) so `super.handleFetchFailure` below can still\n\t\t\t// use it; consuming the response here would lose Anthropic's error for the fallback.\n\t\t\tbody ??= await rsp\n\t\t\t\t.clone()\n\t\t\t\t.text()\n\t\t\t\t.catch(() => undefined);\n\t\t\tlet json;\n\t\t\ttry {\n\t\t\t\tjson = (body != null ? JSON.parse(body) : undefined) as AnthropicError | undefined;\n\t\t\t} catch {}\n\n\t\t\tdebugger;\n\n\t\t\tif (json?.error?.type === 'invalid_request_error') {\n\t\t\t\tif (json?.error?.message?.includes('prompt is too long')) {\n\t\t\t\t\tif (retries < 3) {\n\t\t\t\t\t\t// Extract actual token count from error to calculate smarter reduction\n\t\t\t\t\t\tconst match = /prompt is too long: (\\d+) tokens/.exec(json?.error?.message);\n\t\t\t\t\t\tconst estimatedTokens = match?.[1] != null ? parseInt(match[1], 10) : undefined;\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tretry: true,\n\t\t\t\t\t\t\tmaxInputTokens: getReducedMaxInputTokens(maxInputTokens, retries + 1, estimatedTokens),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RequestTooLarge,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (json?.error?.message?.includes('balance is too low')) {\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RateLimitOrFundsExceeded,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn super.handleFetchFailure(rsp, action, model, retries, maxInputTokens, body, sentTools);\n\t}\n\n\tprotected override serializeTools(tools: readonly AIToolDefinition[]): { tools: unknown[] } {\n\t\t// Anthropic names the schema field `input_schema` and has no `function` envelope.\n\t\treturn {\n\t\t\ttools: tools.map(t => ({ name: t.name, description: t.description, input_schema: t.parameters })),\n\t\t};\n\t}\n\n\tprotected override serializeMessages(messages: AIChatMessage<AIChatMessageRole>[]): unknown[] {\n\t\tconst out: unknown[] = [];\n\n\t\tfor (const m of messages) {\n\t\t\t// Anthropic carries tool results as `tool_result` blocks on a *user* message, not a\n\t\t\t// `tool`-role message. Consecutive results are batched into one user turn, matching how the\n\t\t\t// API expects a multi-tool-call round to be answered.\n\t\t\tif (m.role === 'tool') {\n\t\t\t\t// See the base provider: a result with no call id can't be addressed, so it goes as plain\n\t\t\t\t// text instead of a `tool_use_id: undefined` block the API rejects.\n\t\t\t\tif (m.toolCallId == null) {\n\t\t\t\t\tout.push({ role: 'user', content: m.content });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst block = { type: 'tool_result', tool_use_id: m.toolCallId, content: m.content };\n\t\t\t\tconst last = out.at(-1) as { role?: string; content?: unknown[] } | undefined;\n\t\t\t\tif (last?.role === 'user' && Array.isArray(last.content) && isToolResultBlocks(last.content)) {\n\t\t\t\t\tlast.content.push(block);\n\t\t\t\t} else {\n\t\t\t\t\tout.push({ role: 'user', content: [block] });\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (m.role === 'assistant' && m.toolCalls?.length) {\n\t\t\t\tout.push({\n\t\t\t\t\trole: 'assistant',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t...(m.content ? [{ type: 'text', text: m.content }] : []),\n\t\t\t\t\t\t...m.toolCalls.map(c => ({ type: 'tool_use', id: c.id, name: c.name, input: c.args })),\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tout.push({ role: m.role, content: m.content });\n\t\t}\n\n\t\treturn out;\n\t}\n}\n\n/** Whether an assembled user message's content is a batch of `tool_result` blocks we can append to. */\nfunction isToolResultBlocks(content: unknown[]): content is { type: string }[] {\n\treturn content.every(b => (b as { type?: string })?.type === 'tool_result');\n}\n\ninterface AnthropicError {\n\ttype: 'error';\n\terror: {\n\t\ttype:\n\t\t\t| 'invalid_request_error'\n\t\t\t| 'authentication_error'\n\t\t\t| 'permission_error'\n\t\t\t| 'not_found_error'\n\t\t\t| 'rate_limit_error'\n\t\t\t| 'api_error'\n\t\t\t| 'overloaded_error';\n\t\tmessage: string;\n\t};\n}\n"],"mappings":";;;;;AASA,MAAM,SAA2B;CAChC;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EAEV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,SAAS;EACT,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;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AC1F,KAAK,QAAQ,KAAK,KAAK;SAEvB,IAAI,KAAK;KAAE,MAAM;KAAQ,SAAS,CAAC,KAAK;IAAE,CAAC;IAE5C;GACD;GAEA,IAAI,EAAE,SAAS,eAAe,EAAE,WAAW,QAAQ;IAClD,IAAI,KAAK;KACR,MAAM;KACN,SAAS,CACR,GAAI,EAAE,UAAU,CAAC;MAAE,MAAM;MAAQ,MAAM,EAAE;KAAQ,CAAC,IAAI,CAAC,GACvD,GAAG,EAAE,UAAU,KAAI,OAAM;MAAE,MAAM;MAAY,IAAI,EAAE;MAAI,MAAM,EAAE;MAAM,OAAO,EAAE;KAAK,EAAE,CACtF;IACD,CAAC;IACD;GACD;GAEA,IAAI,KAAK;IAAE,MAAM,EAAE;IAAM,SAAS,EAAE;GAAQ,CAAC;EAC9C;EAEA,OAAO;CACR;AACD;;AAGA,SAAS,mBAAmB,SAAmD;CAC9E,OAAO,QAAQ,OAAM,MAAM,GAAyB,SAAS,aAAa;AAC3E"}
@@ -1,8 +1,8 @@
1
1
  import { CancellationError, isCancellationError } from "../../../utils/cancellation.js";
2
2
  import { Logger as _logger, getLoggableName } from "../../../utils/logger.js";
3
3
  import { maybeStartScopedLogger } from "../../../utils/logger.scoped.js";
4
- import { uuid } from "../../../utils/crypto.js";
5
4
  import _usingCtx from "../../../_virtual/@oxc-project+runtime/helpers/esm/usingCtx.js";
5
+ import { uuid } from "../../../utils/crypto.js";
6
6
  import { AIError } from "../errors.js";
7
7
  import { getActionName, getReducedMaxInputTokens, getValidatedTemperature } from "../utils/ai.utils.js";
8
8
  import { isResponseFormatRejected, rememberResponseFormatRejection } from "./responseFormatCache.js";
@@ -10,7 +10,6 @@ import { RepositoryMetadata } from "../../../git/models/repositoryMetadata.js";
10
10
  import { PullRequestUrlIdentity } from "../../../git/utils/pullRequest.utils.js";
11
11
  import { GitCloudHostIntegrationId, IntegrationIds, IssuesCloudHostIntegrationId, IssuesHostIntegrationIds } from "../constants.js";
12
12
  import { Sources } from "../telemetry.js";
13
- import "../providerFilters.js";
14
13
  import { ProviderRepositoryShape } from "../results.js";
15
14
  import { ProviderRepositoriesInput } from "../manager.js";
16
15
  //#region ../plus/integrations/src/models/publicIntegration.d.ts
@@ -7,9 +7,9 @@ import { trace } from "../../../../utils/decorators/log.js";
7
7
  import { PromiseCache } from "../../../../utils/promiseCache.js";
8
8
  import __decorate from "../../../../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
9
9
  import { AuthenticationError, RequestClientError, RequestNotFoundError, RequestRateLimitError, getDeferredRequestFailure, reportRequestFailure } from "../../../../git/errors.js";
10
- import { sha256, uuid } from "../../../../utils/crypto.js";
11
10
  import { maybeStopWatch } from "../../../../utils/stopwatch.js";
12
11
  import { base64 } from "../../../../utils/base64.js";
12
+ import { sha256, uuid } from "../../../../utils/crypto.js";
13
13
  import { effectiveIssueSort } from "../../../../git/utils/issue.utils.js";
14
14
  import { ProviderFetchError, isRateLimitResponse, toRateLimitError } from "../../errors.js";
15
15
  import { CommitReadRefusedError, isCommitReadRefusal, isNotFoundResponse, throwProviderError } from "../providerErrors.js";
@@ -1,5 +1,4 @@
1
1
  import { IssueSorting } from "../../../git/models/issue.js";
2
- import "../providerFilters.js";
3
2
  //#region ../plus/integrations/src/providers/issueSorts.d.ts
4
3
  /** GitHub and GHE: one `search` channel serves all three issue reads, so all three order the same way. */
5
4
  export declare const githubIssueSorts: IssueSorting[];
@@ -1,7 +1,6 @@
1
1
  import { ResourceDescriptor } from "../../../git/models/resourceDescriptor.js";
2
2
  import { PullRequest, PullRequestFilter, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
3
3
  import { IntegrationIds } from "../constants.js";
4
- import "../providerFilters.js";
5
4
  import { ProviderWarning } from "../results.js";
6
5
  import { ProviderSweepTarget, PullRequestSweepOptions } from "../manager.js";
7
6
  import { IntegrationResult } from "../models/publicIntegration.js";
@@ -35,6 +35,7 @@ export declare function unitDivisorMs(unit: Intl.RelativeTimeFormatUnit): number
35
35
  * window to where the NEXT unit actually takes over (not just `n+1` steps of the same divisor) can read
36
36
  * the real cutover point instead of re-deriving the thresholds table itself. */
37
37
  export declare function unitThresholdMs(unit: Intl.RelativeTimeFormatUnit): number;
38
+ export declare function msUntilFromNowChanges(date: number, now: number): number | undefined;
38
39
  export declare function fromNow(date: Date | number, short?: boolean, now?: Date | number): string;
39
40
  export declare function formatDate(date: Date | number, format: 'full' | 'long' | 'medium' | 'short' | string | null | undefined, locale?: string, cache?: boolean): string;
40
41
  export declare function getDateDifference(first: Date | number, second: Date | number, unit?: 'days' | 'hours' | 'minutes' | 'seconds', roundFn?: (value: number) => number): number;
@@ -135,6 +135,15 @@ function unitDivisorMs(unit) {
135
135
  function unitThresholdMs(unit) {
136
136
  return unitThresholds[unit] ?? 0;
137
137
  }
138
+ function msUntilFromNowChanges(date, now) {
139
+ const elapsed = now - date;
140
+ if (!Number.isFinite(elapsed) || elapsed < 0) return void 0;
141
+ let largerUnitThreshold = Infinity;
142
+ for (const [, threshold, divisor] of relativeUnitThresholds) {
143
+ if (elapsed >= threshold || threshold === 1e3) return Math.min((Math.floor(elapsed / divisor) + 1) * divisor, largerUnitThreshold) - elapsed;
144
+ largerUnitThreshold = threshold;
145
+ }
146
+ }
138
147
  function fromNow(date, short, now = Date.now()) {
139
148
  const elapsed = (typeof date === "number" ? date : date.getTime()) - (typeof now === "number" ? now : now.getTime());
140
149
  if (!Number.isFinite(elapsed)) return "";
@@ -340,6 +349,6 @@ function getNumericFormat(style, locale) {
340
349
  return formatter.format;
341
350
  }
342
351
  //#endregion
343
- export { createFromDateDelta, formatDate, formatNumeric, fromNow, fromNowUnit, fromNowUnitKey, getDateDifference, getNumericFormat, getTimeRemaining, setDefaultDateLocales, unitDivisorMs, unitThresholdMs };
352
+ export { createFromDateDelta, formatDate, formatNumeric, fromNow, fromNowUnit, fromNowUnitKey, getDateDifference, getNumericFormat, getTimeRemaining, msUntilFromNowChanges, setDefaultDateLocales, unitDivisorMs, unitThresholdMs };
344
353
 
345
354
  //# sourceMappingURL=date.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","names":[],"sources":["../../../utils/src/date.ts"],"sourcesContent":["// NOTE@eamodio If this changes we need to update the replacement function too (since its parameter number/order relies on the matching)\nconst customDateTimeFormatParserRegex =\n\t/(?<literal>\\[.*?\\])|(?<year>YYYY|YY)|(?<month>M{1,4})|(?<day>Do|DD?)|(?<weekday>d{2,4})|(?<hour>HH?|hh?)|(?<minute>mm?)|(?<second>ss?)|(?<fractionalSecond>SSS)|(?<dayPeriod>A|a)|(?<timeZoneName>ZZ?)/g;\nconst dateTimeFormatRegex = /(?<dateStyle>full|long|medium|short)(?:\\+(?<timeStyle>full|long|medium|short))?/;\nconst relativeUnitThresholds: [Intl.RelativeTimeFormatUnit, number, number, string][] = [\n\t['year', 24 * 60 * 60 * 1000 * (365 * 2 - 1), 24 * 60 * 60 * 1000 * 365, 'yr'],\n\t['month', (24 * 60 * 60 * 1000 * 365) / 12, (24 * 60 * 60 * 1000 * 365) / 12, 'mo'],\n\t['week', 24 * 60 * 60 * 1000 * 7, 24 * 60 * 60 * 1000 * 7, 'wk'],\n\t['day', 24 * 60 * 60 * 1000, 24 * 60 * 60 * 1000, 'd'],\n\t['hour', 60 * 60 * 1000, 60 * 60 * 1000, 'h'],\n\t['minute', 60 * 1000, 60 * 1000, 'm'],\n\t['second', 1000, 1000, 's'],\n];\n// Built ONCE from the table above (not per-call `.find()` scans, and not a Map — plain object property\n// reads are monomorphic/faster than Map.get for this) — backs unitDivisorMs/unitThresholdMs below. Never\n// touched on fromNow's own hot path (see the loop in fromNow itself).\nconst unitDivisors: Partial<Record<Intl.RelativeTimeFormatUnit, number>> = {};\nconst unitThresholds: Partial<Record<Intl.RelativeTimeFormatUnit, number>> = {};\nfor (const [unit, threshold, divisor] of relativeUnitThresholds) {\n\tunitDivisors[unit] = divisor;\n\tunitThresholds[unit] = threshold;\n}\n\ntype DateStyle = 'full' | 'long' | 'medium' | 'short';\ntype TimeStyle = 'full' | 'long' | 'medium' | 'short';\nexport type DateTimeFormat = DateStyle | `${DateStyle}+${TimeStyle}`;\n\nlet locale: string | undefined;\nconst dateTimeFormatCache = new Map<string | undefined, Intl.DateTimeFormat>();\nlet defaultLocales: string[] | undefined;\nlet defaultRelativeTimeFormat: InstanceType<typeof Intl.RelativeTimeFormat> | undefined;\nlet defaultShortRelativeTimeFormat: InstanceType<typeof Intl.RelativeTimeFormat> | undefined;\n\nconst numberFormatCache = new Map<string | undefined, Intl.NumberFormat>();\n\nexport function setDefaultDateLocales(locales: string | string[] | null | undefined): void {\n\tif (typeof locales === 'string') {\n\t\tif (locales === 'system' || locales.trim().length === 0) {\n\t\t\tdefaultLocales = undefined;\n\t\t} else {\n\t\t\tdefaultLocales = [locales];\n\t\t}\n\t} else {\n\t\tdefaultLocales = locales ?? undefined;\n\t}\n\n\tdefaultRelativeTimeFormat = undefined;\n\tdefaultShortRelativeTimeFormat = undefined;\n\tdateTimeFormatCache.clear();\n\n\tnumberFormatCache.clear();\n\n\tlocale = undefined;\n}\n\nexport function createFromDateDelta(\n\tdate: Date,\n\tdelta: { years?: number; months?: number; days?: number; hours?: number; minutes?: number; seconds?: number },\n): Date {\n\tconst d = new Date(date.getTime());\n\n\tfor (const [key, value] of Object.entries(delta)) {\n\t\tif (!value) continue;\n\n\t\tswitch (key) {\n\t\t\tcase 'years':\n\t\t\t\td.setFullYear(d.getFullYear() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'months':\n\t\t\t\td.setMonth(d.getMonth() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'days':\n\t\t\t\td.setDate(d.getDate() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'hours':\n\t\t\t\td.setHours(d.getHours() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'minutes':\n\t\t\t\td.setMinutes(d.getMinutes() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'seconds':\n\t\t\t\td.setSeconds(d.getSeconds() + value);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn d;\n}\n\n/** The unit + truncated magnitude `fromNow` would pick for `date` relative to `now` — same threshold\n * table + truncation `fromNow` formats with, factored out so a caller that needs to CLASSIFY a date\n * (not just format it) can't drift from what the column actually displays. Allocation-free (no `Date`\n * construction — both `date` and `now` are read as epoch ms when passed as numbers). `now` defaults to\n * `Date.now()`; a caller classifying many rows against the SAME instant should pass it explicitly. */\nexport function fromNowUnit(\n\tdate: Date | number,\n\tnow: Date | number = Date.now(),\n): { unit: Intl.RelativeTimeFormatUnit; value: number } | undefined {\n\tconst elapsed =\n\t\t(typeof date === 'number' ? date : date.getTime()) - (typeof now === 'number' ? now : now.getTime());\n\t// Guard against invalid dates (e.g. `new Date(<unparseable>)`) — mirrors fromNow's own guard.\n\tif (!Number.isFinite(elapsed)) return undefined;\n\n\tconst elapsedABS = Math.abs(elapsed);\n\tfor (const [unit, threshold, divisor] of relativeUnitThresholds) {\n\t\tif (elapsedABS >= threshold || threshold === 1000 /* second */) {\n\t\t\treturn { unit: unit, value: Math.trunc(elapsed / divisor) };\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** Allocation-free sibling of `fromNowUnit` for a caller that only needs to CLASSIFY (compare two dates'\n * groups) rather than build the `{unit,value}` object — same loop over the same table, so it can't\n * drift from `fromNowUnit`/`fromNow`. Encodes the result as `unitOrdinal*100000 + truncValue` (ordinal\n * 0 = 'year' … 6 = 'second', matching `relativeUnitThresholds`' order; `truncValue` keeps its sign, so\n * a positive result means `date` is in the FUTURE relative to `now`). */\nexport function fromNowUnitKey(date: Date | number, now: Date | number = Date.now()): number | undefined {\n\tconst elapsed =\n\t\t(typeof date === 'number' ? date : date.getTime()) - (typeof now === 'number' ? now : now.getTime());\n\tif (!Number.isFinite(elapsed)) return undefined;\n\n\tconst elapsedABS = Math.abs(elapsed);\n\tlet ordinal = 0;\n\tfor (const [, threshold, divisor] of relativeUnitThresholds) {\n\t\tif (elapsedABS >= threshold || threshold === 1000 /* second */) {\n\t\t\treturn ordinal * 100_000 + Math.trunc(elapsed / divisor);\n\t\t}\n\n\t\tordinal++;\n\t}\n\treturn undefined;\n}\n\n/** The divisor (ms) `fromNowUnit` divides elapsed time by for `unit` — i.e. the elapsed-ms width one\n * step of `value` represents. Exported so a caller reconstructing a `fromNowUnit` result's elapsed\n * WINDOW (its start/end bounds) doesn't have to re-derive the thresholds table itself. */\nexport function unitDivisorMs(unit: Intl.RelativeTimeFormatUnit): number {\n\treturn unitDivisors[unit] ?? 0;\n}\n\n/** The elapsed-ms THRESHOLD `fromNowUnit` requires to classify into `unit` at all (only differs from\n * `unitDivisorMs` for 'year' — see the table above). Exported so a caller clamping a group's elapsed\n * window to where the NEXT unit actually takes over (not just `n+1` steps of the same divisor) can read\n * the real cutover point instead of re-deriving the thresholds table itself. */\nexport function unitThresholdMs(unit: Intl.RelativeTimeFormatUnit): number {\n\treturn unitThresholds[unit] ?? 0;\n}\n\n// fromNow keeps its OWN single-pass loop (not routed through fromNowUnit) — one iteration, no\n// intermediate {unit,value} object allocation on this hot formatting path; fromNowUnit below iterates\n// the SAME `relativeUnitThresholds` array, so the two classifications can't drift apart. `now` defaults\n// to `Date.now()`, like fromNowUnit's — pass it to pin the instant (a caller comparing against its own\n// clock read otherwise sits one unpredictable tick away from the bucket it expects).\nexport function fromNow(date: Date | number, short?: boolean, now: Date | number = Date.now()): string {\n\tconst elapsed =\n\t\t(typeof date === 'number' ? date : date.getTime()) - (typeof now === 'number' ? now : now.getTime());\n\t// Guard against invalid dates (e.g. `new Date(<unparseable>)`), since a non-finite value would throw in `Intl.RelativeTimeFormat.format`\n\tif (!Number.isFinite(elapsed)) return '';\n\n\tfor (const [unit, threshold, divisor, shortUnit] of relativeUnitThresholds) {\n\t\tconst elapsedABS = Math.abs(elapsed);\n\t\tif (elapsedABS >= threshold || threshold === 1000 /* second */) {\n\t\t\tif (short) {\n\t\t\t\tif (locale == null) {\n\t\t\t\t\tif (defaultShortRelativeTimeFormat != null) {\n\t\t\t\t\t\tlocale = defaultShortRelativeTimeFormat.resolvedOptions().locale;\n\t\t\t\t\t} else if (defaultRelativeTimeFormat != null) {\n\t\t\t\t\t\tlocale = defaultRelativeTimeFormat.resolvedOptions().locale;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdefaultShortRelativeTimeFormat = new Intl.RelativeTimeFormat(defaultLocales, {\n\t\t\t\t\t\t\tlocaleMatcher: 'best fit',\n\t\t\t\t\t\t\tnumeric: 'always',\n\t\t\t\t\t\t\tstyle: 'narrow',\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlocale = defaultShortRelativeTimeFormat.resolvedOptions().locale;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (locale === 'en' || locale?.startsWith('en-')) {\n\t\t\t\t\tconst value = Math.floor(elapsedABS / divisor);\n\t\t\t\t\treturn `${value}${shortUnit}`;\n\t\t\t\t}\n\n\t\t\t\tdefaultShortRelativeTimeFormat ??= new Intl.RelativeTimeFormat(defaultLocales, {\n\t\t\t\t\tlocaleMatcher: 'best fit',\n\t\t\t\t\tnumeric: 'always',\n\t\t\t\t\tstyle: 'narrow',\n\t\t\t\t});\n\n\t\t\t\treturn defaultShortRelativeTimeFormat.format(Math.trunc(elapsed / divisor), unit);\n\t\t\t}\n\n\t\t\tdefaultRelativeTimeFormat ??= new Intl.RelativeTimeFormat(defaultLocales, {\n\t\t\t\tlocaleMatcher: 'best fit',\n\t\t\t\tnumeric: 'auto',\n\t\t\t\tstyle: 'long',\n\t\t\t});\n\t\t\treturn defaultRelativeTimeFormat.format(Math.trunc(elapsed / divisor), unit);\n\t\t}\n\t}\n\n\treturn '';\n}\n\nexport function formatDate(\n\tdate: Date | number,\n\tformat: 'full' | 'long' | 'medium' | 'short' | string | null | undefined,\n\tlocale?: string,\n\tcache: boolean = true,\n): string {\n\tformat = format ?? undefined;\n\n\t// Guard against invalid dates (e.g. `new Date(<unparseable>)`), since they would throw in `Intl.DateTimeFormat.format`\n\tif (Number.isNaN(typeof date === 'number' ? date : date.getTime())) return '';\n\n\tconst key = `${locale ?? ''}:${format}`;\n\n\tlet formatter = dateTimeFormatCache.get(key);\n\tif (formatter == null) {\n\t\tconst options = getDateTimeFormatOptionsFromFormatString(format);\n\n\t\tlet locales;\n\t\tif (locale == null) {\n\t\t\tlocales = defaultLocales;\n\t\t} else if (locale === 'system') {\n\t\t\tlocales = undefined;\n\t\t} else {\n\t\t\tlocales = [locale];\n\t\t}\n\n\t\tformatter = new Intl.DateTimeFormat(locales, options);\n\t\tif (cache) {\n\t\t\tdateTimeFormatCache.set(key, formatter);\n\t\t}\n\t}\n\n\tif (format == null || dateTimeFormatRegex.test(format)) {\n\t\treturn formatter.format(date);\n\t}\n\n\tfunction getTimeFormatter(format: TimeStyle) {\n\t\tconst key = `${locale ?? ''}:time:${format}`;\n\n\t\tlet formatter = dateTimeFormatCache.get(key);\n\t\tif (formatter == null) {\n\t\t\tconst options: Intl.DateTimeFormatOptions = { localeMatcher: 'best fit', timeStyle: format };\n\n\t\t\tlet locales;\n\t\t\tif (locale == null) {\n\t\t\t\tlocales = defaultLocales;\n\t\t\t} else if (locale === 'system') {\n\t\t\t\tlocales = undefined;\n\t\t\t} else {\n\t\t\t\tlocales = [locale];\n\t\t\t}\n\n\t\t\tformatter = new Intl.DateTimeFormat(locales, options);\n\t\t\tif (cache) {\n\t\t\t\tdateTimeFormatCache.set(key, formatter);\n\t\t\t}\n\t\t}\n\n\t\treturn formatter;\n\t}\n\n\tconst parts = formatter.formatToParts(date);\n\treturn format.replace(\n\t\tcustomDateTimeFormatParserRegex,\n\t\t(\n\t\t\t_match,\n\t\t\tliteral,\n\t\t\t_year,\n\t\t\t_month,\n\t\t\t_day,\n\t\t\t_weekday,\n\t\t\t_hour,\n\t\t\t_minute,\n\t\t\t_second,\n\t\t\t_fractionalSecond,\n\t\t\t_dayPeriod,\n\t\t\t_timeZoneName,\n\t\t\t_offset,\n\t\t\t_s,\n\t\t\tgroups,\n\t\t) => {\n\t\t\tif (literal != null) return (literal as string).substring(1, literal.length - 1);\n\n\t\t\tfor (const [key, value] of Object.entries(groups)) {\n\t\t\t\tif (value == null) continue;\n\n\t\t\t\tconst part = parts.find(p => p.type === key);\n\n\t\t\t\tif (value === 'Do' && part?.type === 'day') {\n\t\t\t\t\treturn formatWithOrdinal(Number(part.value));\n\t\t\t\t} else if (value === 'a' && part?.type === 'dayPeriod') {\n\t\t\t\t\t// For some reason the Intl.DateTimeFormat doesn't honor the `dayPeriod` value and always returns the long version, so use the \"short\" timeStyle instead\n\t\t\t\t\tconst dayPeriod = getTimeFormatter('short')\n\t\t\t\t\t\t.formatToParts(date)\n\t\t\t\t\t\t.find(p => p.type === 'dayPeriod');\n\t\t\t\t\treturn ` ${(dayPeriod ?? part)?.value ?? ''}`;\n\t\t\t\t}\n\t\t\t\treturn part?.value ?? '';\n\t\t\t}\n\n\t\t\treturn '';\n\t\t},\n\t);\n}\n\nexport function getDateDifference(\n\tfirst: Date | number,\n\tsecond: Date | number,\n\tunit?: 'days' | 'hours' | 'minutes' | 'seconds',\n\troundFn?: (value: number) => number,\n): number {\n\tconst diff =\n\t\t(typeof second === 'number' ? second : second.getTime()) -\n\t\t(typeof first === 'number' ? first : first.getTime());\n\tconst round = roundFn ?? Math.floor;\n\tswitch (unit) {\n\t\tcase 'days':\n\t\t\treturn round(diff / (1000 * 60 * 60 * 24));\n\t\tcase 'hours':\n\t\t\treturn round(diff / (1000 * 60 * 60));\n\t\tcase 'minutes':\n\t\t\treturn round(diff / (1000 * 60));\n\t\tcase 'seconds':\n\t\t\treturn round(diff / 1000);\n\t\tdefault:\n\t\t\treturn diff;\n\t}\n}\n\nfunction getDateTimeFormatOptionsFromFormatString(\n\tformat: DateTimeFormat | string | undefined,\n): Intl.DateTimeFormatOptions {\n\tif (format == null) return { localeMatcher: 'best fit', dateStyle: 'full', timeStyle: 'short' };\n\n\tconst match = dateTimeFormatRegex.exec(format);\n\tif (match?.groups != null) {\n\t\tconst { dateStyle, timeStyle } = match.groups;\n\t\treturn {\n\t\t\tlocaleMatcher: 'best fit',\n\t\t\tdateStyle: (dateStyle as Intl.DateTimeFormatOptions['dateStyle']) || 'full',\n\t\t\ttimeStyle: (timeStyle as Intl.DateTimeFormatOptions['timeStyle']) || undefined,\n\t\t};\n\t}\n\n\tconst options: Intl.DateTimeFormatOptions = { localeMatcher: 'best fit' };\n\n\tfor (const { groups } of format.matchAll(customDateTimeFormatParserRegex)) {\n\t\tif (groups == null) continue;\n\n\t\tfor (const [key, value] of Object.entries(groups)) {\n\t\t\tif (value == null) continue;\n\n\t\t\tswitch (key) {\n\t\t\t\tcase 'year':\n\t\t\t\t\toptions.year = value.length === 4 ? 'numeric' : '2-digit';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'month':\n\t\t\t\t\tswitch (value.length) {\n\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\toptions.month = 'long';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\toptions.month = 'short';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\toptions.month = '2-digit';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\toptions.month = 'numeric';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'day':\n\t\t\t\t\tif (value === 'DD') {\n\t\t\t\t\t\toptions.day = '2-digit';\n\t\t\t\t\t} else {\n\t\t\t\t\t\toptions.day = 'numeric';\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'weekday':\n\t\t\t\t\tswitch (value.length) {\n\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\toptions.weekday = 'long';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\toptions.weekday = 'short';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\toptions.weekday = 'narrow';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'hour':\n\t\t\t\t\toptions.hour = value.length === 2 ? '2-digit' : 'numeric';\n\t\t\t\t\toptions.hour12 = value === 'hh' || value === 'h';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'minute':\n\t\t\t\t\toptions.minute = value.length === 2 ? '2-digit' : 'numeric';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'second':\n\t\t\t\t\toptions.second = value.length === 2 ? '2-digit' : 'numeric';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'fractionalSecond':\n\t\t\t\t\t(options as unknown as { fractionalSecondDigits?: number }).fractionalSecondDigits = 3;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'dayPeriod':\n\t\t\t\t\toptions.dayPeriod = 'narrow';\n\t\t\t\t\toptions.hour12 = true;\n\t\t\t\t\toptions.hourCycle = 'h12';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'timeZoneName':\n\t\t\t\t\toptions.timeZoneName = value.length === 2 ? 'long' : 'short';\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn options;\n}\n\nexport function getTimeRemaining(\n\texpiresOn: string | undefined,\n\tunit?: 'days' | 'hours' | 'minutes' | 'seconds',\n): number | undefined {\n\treturn expiresOn != null ? getDateDifference(Date.now(), new Date(expiresOn), unit, Math.round) : undefined;\n}\n\nconst ordinals = ['th', 'st', 'nd', 'rd'];\nfunction formatWithOrdinal(n: number): string {\n\tconst v = n % 100;\n\treturn `${n}${ordinals[(v - 20) % 10] ?? ordinals[v] ?? ordinals[0]}`;\n}\n\nexport function formatNumeric(\n\tvalue: number,\n\tstyle?: 'decimal' | 'currency' | 'percent' | 'unit' | null | undefined,\n\tlocale?: string,\n): string {\n\tconst format = getNumericFormat(style, locale);\n\treturn format(value);\n}\n\nexport function getNumericFormat(\n\tstyle?: 'decimal' | 'currency' | 'percent' | 'unit' | null | undefined,\n\tlocale?: string,\n): Intl.NumberFormat['format'] {\n\tstyle ??= 'decimal';\n\n\tconst key = `${locale ?? ''}:${style}`;\n\n\tlet formatter = numberFormatCache.get(key);\n\tif (formatter == null) {\n\t\tconst options: Intl.NumberFormatOptions = { localeMatcher: 'best fit', style: style };\n\n\t\tlet locales;\n\t\tif (locale == null) {\n\t\t\tlocales = defaultLocales;\n\t\t} else if (locale === 'system') {\n\t\t\tlocales = undefined;\n\t\t} else {\n\t\t\tlocales = [locale];\n\t\t}\n\n\t\tformatter = new Intl.NumberFormat(locales, options);\n\t\tnumberFormatCache.set(key, formatter);\n\t}\n\n\treturn formatter.format;\n}\n"],"mappings":";AACA,MAAM,kCACL;AACD,MAAM,sBAAsB;AAC5B,MAAM,yBAAkF;CACvF;EAAC;EAAQ;EAAqC;EAA2B;CAAI;CAC7E;EAAC;EAAS;EAAkC;EAAkC;CAAI;CAClF;EAAC;EAAQ;EAAyB;EAAyB;CAAI;CAC/D;EAAC;EAAO;EAAqB;EAAqB;CAAG;CACrD;EAAC;EAAQ;EAAgB;EAAgB;CAAG;CAC5C;EAAC;EAAU;EAAW;EAAW;CAAG;CACpC;EAAC;EAAU;EAAM;EAAM;CAAG;AAC3B;AAIA,MAAM,eAAqE,CAAC;AAC5E,MAAM,iBAAuE,CAAC;AAC9E,KAAK,MAAM,CAAC,MAAM,WAAW,YAAY,wBAAwB;CAChE,aAAa,QAAQ;CACrB,eAAe,QAAQ;AACxB;AAMA,IAAI;AACJ,MAAM,sCAAsB,IAAI,IAA6C;AAC7E,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,MAAM,oCAAoB,IAAI,IAA2C;AAEzE,SAAgB,sBAAsB,SAAqD;CAC1F,IAAI,OAAO,YAAY,UAAU;EAChC,IAAI,YAAY,YAAY,QAAQ,KAAK,CAAC,CAAC,WAAW,GACrD,iBAAiB,KAAA;OAEjB,iBAAiB,CAAC,OAAO;CAE3B,OACC,iBAAiB,WAAW,KAAA;CAG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,GAAG,IAAI,KAAK,SAAS,GAAG,MAAM,KAAK,KAAK,IAAI,KAAA;AACnG;AAEA,MAAM,WAAW;CAAC;CAAM;CAAM;CAAM;AAAI;AACxC,SAAS,kBAAkB,GAAmB;CAC7C,MAAM,IAAI,IAAI;CACd,OAAO,GAAG,IAAI,UAAU,IAAI,MAAM,OAAO,SAAS,MAAM,SAAS;AAClE;AAEA,SAAgB,cACf,OACA,OACA,QACS;CAET,OADe,iBAAiB,OAAO,MAC3B,CAAC,CAAC,KAAK;AACpB;AAEA,SAAgB,iBACf,OACA,QAC8B;CAC9B,UAAU;CAEV,MAAM,MAAM,GAAG,UAAU,GAAG,GAAG;CAE/B,IAAI,YAAY,kBAAkB,IAAI,GAAG;CACzC,IAAI,aAAa,MAAM;EACtB,MAAM,UAAoC;GAAE,eAAe;GAAmB;EAAM;EAEpF,IAAI;EACJ,IAAI,UAAU,MACb,UAAU;OACJ,IAAI,WAAW,UACrB,UAAU,KAAA;OAEV,UAAU,CAAC,MAAM;EAGlB,YAAY,IAAI,KAAK,aAAa,SAAS,OAAO;EAClD,kBAAkB,IAAI,KAAK,SAAS;CACrC;CAEA,OAAO,UAAU;AAClB"}
1
+ {"version":3,"file":"date.js","names":[],"sources":["../../../utils/src/date.ts"],"sourcesContent":["// NOTE@eamodio If this changes we need to update the replacement function too (since its parameter number/order relies on the matching)\nconst customDateTimeFormatParserRegex =\n\t/(?<literal>\\[.*?\\])|(?<year>YYYY|YY)|(?<month>M{1,4})|(?<day>Do|DD?)|(?<weekday>d{2,4})|(?<hour>HH?|hh?)|(?<minute>mm?)|(?<second>ss?)|(?<fractionalSecond>SSS)|(?<dayPeriod>A|a)|(?<timeZoneName>ZZ?)/g;\nconst dateTimeFormatRegex = /(?<dateStyle>full|long|medium|short)(?:\\+(?<timeStyle>full|long|medium|short))?/;\nconst relativeUnitThresholds: [Intl.RelativeTimeFormatUnit, number, number, string][] = [\n\t['year', 24 * 60 * 60 * 1000 * (365 * 2 - 1), 24 * 60 * 60 * 1000 * 365, 'yr'],\n\t['month', (24 * 60 * 60 * 1000 * 365) / 12, (24 * 60 * 60 * 1000 * 365) / 12, 'mo'],\n\t['week', 24 * 60 * 60 * 1000 * 7, 24 * 60 * 60 * 1000 * 7, 'wk'],\n\t['day', 24 * 60 * 60 * 1000, 24 * 60 * 60 * 1000, 'd'],\n\t['hour', 60 * 60 * 1000, 60 * 60 * 1000, 'h'],\n\t['minute', 60 * 1000, 60 * 1000, 'm'],\n\t['second', 1000, 1000, 's'],\n];\n// Built ONCE from the table above (not per-call `.find()` scans, and not a Map — plain object property\n// reads are monomorphic/faster than Map.get for this) — backs unitDivisorMs/unitThresholdMs below. Never\n// touched on fromNow's own hot path (see the loop in fromNow itself).\nconst unitDivisors: Partial<Record<Intl.RelativeTimeFormatUnit, number>> = {};\nconst unitThresholds: Partial<Record<Intl.RelativeTimeFormatUnit, number>> = {};\nfor (const [unit, threshold, divisor] of relativeUnitThresholds) {\n\tunitDivisors[unit] = divisor;\n\tunitThresholds[unit] = threshold;\n}\n\ntype DateStyle = 'full' | 'long' | 'medium' | 'short';\ntype TimeStyle = 'full' | 'long' | 'medium' | 'short';\nexport type DateTimeFormat = DateStyle | `${DateStyle}+${TimeStyle}`;\n\nlet locale: string | undefined;\nconst dateTimeFormatCache = new Map<string | undefined, Intl.DateTimeFormat>();\nlet defaultLocales: string[] | undefined;\nlet defaultRelativeTimeFormat: InstanceType<typeof Intl.RelativeTimeFormat> | undefined;\nlet defaultShortRelativeTimeFormat: InstanceType<typeof Intl.RelativeTimeFormat> | undefined;\n\nconst numberFormatCache = new Map<string | undefined, Intl.NumberFormat>();\n\nexport function setDefaultDateLocales(locales: string | string[] | null | undefined): void {\n\tif (typeof locales === 'string') {\n\t\tif (locales === 'system' || locales.trim().length === 0) {\n\t\t\tdefaultLocales = undefined;\n\t\t} else {\n\t\t\tdefaultLocales = [locales];\n\t\t}\n\t} else {\n\t\tdefaultLocales = locales ?? undefined;\n\t}\n\n\tdefaultRelativeTimeFormat = undefined;\n\tdefaultShortRelativeTimeFormat = undefined;\n\tdateTimeFormatCache.clear();\n\n\tnumberFormatCache.clear();\n\n\tlocale = undefined;\n}\n\nexport function createFromDateDelta(\n\tdate: Date,\n\tdelta: { years?: number; months?: number; days?: number; hours?: number; minutes?: number; seconds?: number },\n): Date {\n\tconst d = new Date(date.getTime());\n\n\tfor (const [key, value] of Object.entries(delta)) {\n\t\tif (!value) continue;\n\n\t\tswitch (key) {\n\t\t\tcase 'years':\n\t\t\t\td.setFullYear(d.getFullYear() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'months':\n\t\t\t\td.setMonth(d.getMonth() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'days':\n\t\t\t\td.setDate(d.getDate() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'hours':\n\t\t\t\td.setHours(d.getHours() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'minutes':\n\t\t\t\td.setMinutes(d.getMinutes() + value);\n\t\t\t\tbreak;\n\t\t\tcase 'seconds':\n\t\t\t\td.setSeconds(d.getSeconds() + value);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn d;\n}\n\n/** The unit + truncated magnitude `fromNow` would pick for `date` relative to `now` — same threshold\n * table + truncation `fromNow` formats with, factored out so a caller that needs to CLASSIFY a date\n * (not just format it) can't drift from what the column actually displays. Allocation-free (no `Date`\n * construction — both `date` and `now` are read as epoch ms when passed as numbers). `now` defaults to\n * `Date.now()`; a caller classifying many rows against the SAME instant should pass it explicitly. */\nexport function fromNowUnit(\n\tdate: Date | number,\n\tnow: Date | number = Date.now(),\n): { unit: Intl.RelativeTimeFormatUnit; value: number } | undefined {\n\tconst elapsed =\n\t\t(typeof date === 'number' ? date : date.getTime()) - (typeof now === 'number' ? now : now.getTime());\n\t// Guard against invalid dates (e.g. `new Date(<unparseable>)`) — mirrors fromNow's own guard.\n\tif (!Number.isFinite(elapsed)) return undefined;\n\n\tconst elapsedABS = Math.abs(elapsed);\n\tfor (const [unit, threshold, divisor] of relativeUnitThresholds) {\n\t\tif (elapsedABS >= threshold || threshold === 1000 /* second */) {\n\t\t\treturn { unit: unit, value: Math.trunc(elapsed / divisor) };\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** Allocation-free sibling of `fromNowUnit` for a caller that only needs to CLASSIFY (compare two dates'\n * groups) rather than build the `{unit,value}` object — same loop over the same table, so it can't\n * drift from `fromNowUnit`/`fromNow`. Encodes the result as `unitOrdinal*100000 + truncValue` (ordinal\n * 0 = 'year' … 6 = 'second', matching `relativeUnitThresholds`' order; `truncValue` keeps its sign, so\n * a positive result means `date` is in the FUTURE relative to `now`). */\nexport function fromNowUnitKey(date: Date | number, now: Date | number = Date.now()): number | undefined {\n\tconst elapsed =\n\t\t(typeof date === 'number' ? date : date.getTime()) - (typeof now === 'number' ? now : now.getTime());\n\tif (!Number.isFinite(elapsed)) return undefined;\n\n\tconst elapsedABS = Math.abs(elapsed);\n\tlet ordinal = 0;\n\tfor (const [, threshold, divisor] of relativeUnitThresholds) {\n\t\tif (elapsedABS >= threshold || threshold === 1000 /* second */) {\n\t\t\treturn ordinal * 100_000 + Math.trunc(elapsed / divisor);\n\t\t}\n\n\t\tordinal++;\n\t}\n\treturn undefined;\n}\n\n/** The divisor (ms) `fromNowUnit` divides elapsed time by for `unit` — i.e. the elapsed-ms width one\n * step of `value` represents. Exported so a caller reconstructing a `fromNowUnit` result's elapsed\n * WINDOW (its start/end bounds) doesn't have to re-derive the thresholds table itself. */\nexport function unitDivisorMs(unit: Intl.RelativeTimeFormatUnit): number {\n\treturn unitDivisors[unit] ?? 0;\n}\n\n/** The elapsed-ms THRESHOLD `fromNowUnit` requires to classify into `unit` at all (only differs from\n * `unitDivisorMs` for 'year' — see the table above). Exported so a caller clamping a group's elapsed\n * window to where the NEXT unit actually takes over (not just `n+1` steps of the same divisor) can read\n * the real cutover point instead of re-deriving the thresholds table itself. */\nexport function unitThresholdMs(unit: Intl.RelativeTimeFormatUnit): number {\n\treturn unitThresholds[unit] ?? 0;\n}\n\nexport function msUntilFromNowChanges(date: number, now: number): number | undefined {\n\tconst elapsed = now - date;\n\tif (!Number.isFinite(elapsed) || elapsed < 0) return undefined;\n\n\tlet largerUnitThreshold = Infinity;\n\tfor (const [, threshold, divisor] of relativeUnitThresholds) {\n\t\tif (elapsed >= threshold || threshold === 1000) {\n\t\t\treturn Math.min((Math.floor(elapsed / divisor) + 1) * divisor, largerUnitThreshold) - elapsed;\n\t\t}\n\n\t\tlargerUnitThreshold = threshold;\n\t}\n\treturn undefined;\n}\n\n// fromNow keeps its OWN single-pass loop (not routed through fromNowUnit) — one iteration, no\n// intermediate {unit,value} object allocation on this hot formatting path; fromNowUnit below iterates\n// the SAME `relativeUnitThresholds` array, so the two classifications can't drift apart. `now` defaults\n// to `Date.now()`, like fromNowUnit's — pass it to pin the instant (a caller comparing against its own\n// clock read otherwise sits one unpredictable tick away from the bucket it expects).\nexport function fromNow(date: Date | number, short?: boolean, now: Date | number = Date.now()): string {\n\tconst elapsed =\n\t\t(typeof date === 'number' ? date : date.getTime()) - (typeof now === 'number' ? now : now.getTime());\n\t// Guard against invalid dates (e.g. `new Date(<unparseable>)`), since a non-finite value would throw in `Intl.RelativeTimeFormat.format`\n\tif (!Number.isFinite(elapsed)) return '';\n\n\tfor (const [unit, threshold, divisor, shortUnit] of relativeUnitThresholds) {\n\t\tconst elapsedABS = Math.abs(elapsed);\n\t\tif (elapsedABS >= threshold || threshold === 1000 /* second */) {\n\t\t\tif (short) {\n\t\t\t\tif (locale == null) {\n\t\t\t\t\tif (defaultShortRelativeTimeFormat != null) {\n\t\t\t\t\t\tlocale = defaultShortRelativeTimeFormat.resolvedOptions().locale;\n\t\t\t\t\t} else if (defaultRelativeTimeFormat != null) {\n\t\t\t\t\t\tlocale = defaultRelativeTimeFormat.resolvedOptions().locale;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdefaultShortRelativeTimeFormat = new Intl.RelativeTimeFormat(defaultLocales, {\n\t\t\t\t\t\t\tlocaleMatcher: 'best fit',\n\t\t\t\t\t\t\tnumeric: 'always',\n\t\t\t\t\t\t\tstyle: 'narrow',\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlocale = defaultShortRelativeTimeFormat.resolvedOptions().locale;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (locale === 'en' || locale?.startsWith('en-')) {\n\t\t\t\t\tconst value = Math.floor(elapsedABS / divisor);\n\t\t\t\t\treturn `${value}${shortUnit}`;\n\t\t\t\t}\n\n\t\t\t\tdefaultShortRelativeTimeFormat ??= new Intl.RelativeTimeFormat(defaultLocales, {\n\t\t\t\t\tlocaleMatcher: 'best fit',\n\t\t\t\t\tnumeric: 'always',\n\t\t\t\t\tstyle: 'narrow',\n\t\t\t\t});\n\n\t\t\t\treturn defaultShortRelativeTimeFormat.format(Math.trunc(elapsed / divisor), unit);\n\t\t\t}\n\n\t\t\tdefaultRelativeTimeFormat ??= new Intl.RelativeTimeFormat(defaultLocales, {\n\t\t\t\tlocaleMatcher: 'best fit',\n\t\t\t\tnumeric: 'auto',\n\t\t\t\tstyle: 'long',\n\t\t\t});\n\t\t\treturn defaultRelativeTimeFormat.format(Math.trunc(elapsed / divisor), unit);\n\t\t}\n\t}\n\n\treturn '';\n}\n\nexport function formatDate(\n\tdate: Date | number,\n\tformat: 'full' | 'long' | 'medium' | 'short' | string | null | undefined,\n\tlocale?: string,\n\tcache: boolean = true,\n): string {\n\tformat = format ?? undefined;\n\n\t// Guard against invalid dates (e.g. `new Date(<unparseable>)`), since they would throw in `Intl.DateTimeFormat.format`\n\tif (Number.isNaN(typeof date === 'number' ? date : date.getTime())) return '';\n\n\tconst key = `${locale ?? ''}:${format}`;\n\n\tlet formatter = dateTimeFormatCache.get(key);\n\tif (formatter == null) {\n\t\tconst options = getDateTimeFormatOptionsFromFormatString(format);\n\n\t\tlet locales;\n\t\tif (locale == null) {\n\t\t\tlocales = defaultLocales;\n\t\t} else if (locale === 'system') {\n\t\t\tlocales = undefined;\n\t\t} else {\n\t\t\tlocales = [locale];\n\t\t}\n\n\t\tformatter = new Intl.DateTimeFormat(locales, options);\n\t\tif (cache) {\n\t\t\tdateTimeFormatCache.set(key, formatter);\n\t\t}\n\t}\n\n\tif (format == null || dateTimeFormatRegex.test(format)) {\n\t\treturn formatter.format(date);\n\t}\n\n\tfunction getTimeFormatter(format: TimeStyle) {\n\t\tconst key = `${locale ?? ''}:time:${format}`;\n\n\t\tlet formatter = dateTimeFormatCache.get(key);\n\t\tif (formatter == null) {\n\t\t\tconst options: Intl.DateTimeFormatOptions = { localeMatcher: 'best fit', timeStyle: format };\n\n\t\t\tlet locales;\n\t\t\tif (locale == null) {\n\t\t\t\tlocales = defaultLocales;\n\t\t\t} else if (locale === 'system') {\n\t\t\t\tlocales = undefined;\n\t\t\t} else {\n\t\t\t\tlocales = [locale];\n\t\t\t}\n\n\t\t\tformatter = new Intl.DateTimeFormat(locales, options);\n\t\t\tif (cache) {\n\t\t\t\tdateTimeFormatCache.set(key, formatter);\n\t\t\t}\n\t\t}\n\n\t\treturn formatter;\n\t}\n\n\tconst parts = formatter.formatToParts(date);\n\treturn format.replace(\n\t\tcustomDateTimeFormatParserRegex,\n\t\t(\n\t\t\t_match,\n\t\t\tliteral,\n\t\t\t_year,\n\t\t\t_month,\n\t\t\t_day,\n\t\t\t_weekday,\n\t\t\t_hour,\n\t\t\t_minute,\n\t\t\t_second,\n\t\t\t_fractionalSecond,\n\t\t\t_dayPeriod,\n\t\t\t_timeZoneName,\n\t\t\t_offset,\n\t\t\t_s,\n\t\t\tgroups,\n\t\t) => {\n\t\t\tif (literal != null) return (literal as string).substring(1, literal.length - 1);\n\n\t\t\tfor (const [key, value] of Object.entries(groups)) {\n\t\t\t\tif (value == null) continue;\n\n\t\t\t\tconst part = parts.find(p => p.type === key);\n\n\t\t\t\tif (value === 'Do' && part?.type === 'day') {\n\t\t\t\t\treturn formatWithOrdinal(Number(part.value));\n\t\t\t\t} else if (value === 'a' && part?.type === 'dayPeriod') {\n\t\t\t\t\t// For some reason the Intl.DateTimeFormat doesn't honor the `dayPeriod` value and always returns the long version, so use the \"short\" timeStyle instead\n\t\t\t\t\tconst dayPeriod = getTimeFormatter('short')\n\t\t\t\t\t\t.formatToParts(date)\n\t\t\t\t\t\t.find(p => p.type === 'dayPeriod');\n\t\t\t\t\treturn ` ${(dayPeriod ?? part)?.value ?? ''}`;\n\t\t\t\t}\n\t\t\t\treturn part?.value ?? '';\n\t\t\t}\n\n\t\t\treturn '';\n\t\t},\n\t);\n}\n\nexport function getDateDifference(\n\tfirst: Date | number,\n\tsecond: Date | number,\n\tunit?: 'days' | 'hours' | 'minutes' | 'seconds',\n\troundFn?: (value: number) => number,\n): number {\n\tconst diff =\n\t\t(typeof second === 'number' ? second : second.getTime()) -\n\t\t(typeof first === 'number' ? first : first.getTime());\n\tconst round = roundFn ?? Math.floor;\n\tswitch (unit) {\n\t\tcase 'days':\n\t\t\treturn round(diff / (1000 * 60 * 60 * 24));\n\t\tcase 'hours':\n\t\t\treturn round(diff / (1000 * 60 * 60));\n\t\tcase 'minutes':\n\t\t\treturn round(diff / (1000 * 60));\n\t\tcase 'seconds':\n\t\t\treturn round(diff / 1000);\n\t\tdefault:\n\t\t\treturn diff;\n\t}\n}\n\nfunction getDateTimeFormatOptionsFromFormatString(\n\tformat: DateTimeFormat | string | undefined,\n): Intl.DateTimeFormatOptions {\n\tif (format == null) return { localeMatcher: 'best fit', dateStyle: 'full', timeStyle: 'short' };\n\n\tconst match = dateTimeFormatRegex.exec(format);\n\tif (match?.groups != null) {\n\t\tconst { dateStyle, timeStyle } = match.groups;\n\t\treturn {\n\t\t\tlocaleMatcher: 'best fit',\n\t\t\tdateStyle: (dateStyle as Intl.DateTimeFormatOptions['dateStyle']) || 'full',\n\t\t\ttimeStyle: (timeStyle as Intl.DateTimeFormatOptions['timeStyle']) || undefined,\n\t\t};\n\t}\n\n\tconst options: Intl.DateTimeFormatOptions = { localeMatcher: 'best fit' };\n\n\tfor (const { groups } of format.matchAll(customDateTimeFormatParserRegex)) {\n\t\tif (groups == null) continue;\n\n\t\tfor (const [key, value] of Object.entries(groups)) {\n\t\t\tif (value == null) continue;\n\n\t\t\tswitch (key) {\n\t\t\t\tcase 'year':\n\t\t\t\t\toptions.year = value.length === 4 ? 'numeric' : '2-digit';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'month':\n\t\t\t\t\tswitch (value.length) {\n\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\toptions.month = 'long';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\toptions.month = 'short';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\toptions.month = '2-digit';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\toptions.month = 'numeric';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'day':\n\t\t\t\t\tif (value === 'DD') {\n\t\t\t\t\t\toptions.day = '2-digit';\n\t\t\t\t\t} else {\n\t\t\t\t\t\toptions.day = 'numeric';\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'weekday':\n\t\t\t\t\tswitch (value.length) {\n\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\toptions.weekday = 'long';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\toptions.weekday = 'short';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\toptions.weekday = 'narrow';\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'hour':\n\t\t\t\t\toptions.hour = value.length === 2 ? '2-digit' : 'numeric';\n\t\t\t\t\toptions.hour12 = value === 'hh' || value === 'h';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'minute':\n\t\t\t\t\toptions.minute = value.length === 2 ? '2-digit' : 'numeric';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'second':\n\t\t\t\t\toptions.second = value.length === 2 ? '2-digit' : 'numeric';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'fractionalSecond':\n\t\t\t\t\t(options as unknown as { fractionalSecondDigits?: number }).fractionalSecondDigits = 3;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'dayPeriod':\n\t\t\t\t\toptions.dayPeriod = 'narrow';\n\t\t\t\t\toptions.hour12 = true;\n\t\t\t\t\toptions.hourCycle = 'h12';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'timeZoneName':\n\t\t\t\t\toptions.timeZoneName = value.length === 2 ? 'long' : 'short';\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn options;\n}\n\nexport function getTimeRemaining(\n\texpiresOn: string | undefined,\n\tunit?: 'days' | 'hours' | 'minutes' | 'seconds',\n): number | undefined {\n\treturn expiresOn != null ? getDateDifference(Date.now(), new Date(expiresOn), unit, Math.round) : undefined;\n}\n\nconst ordinals = ['th', 'st', 'nd', 'rd'];\nfunction formatWithOrdinal(n: number): string {\n\tconst v = n % 100;\n\treturn `${n}${ordinals[(v - 20) % 10] ?? ordinals[v] ?? ordinals[0]}`;\n}\n\nexport function formatNumeric(\n\tvalue: number,\n\tstyle?: 'decimal' | 'currency' | 'percent' | 'unit' | null | undefined,\n\tlocale?: string,\n): string {\n\tconst format = getNumericFormat(style, locale);\n\treturn format(value);\n}\n\nexport function getNumericFormat(\n\tstyle?: 'decimal' | 'currency' | 'percent' | 'unit' | null | undefined,\n\tlocale?: string,\n): Intl.NumberFormat['format'] {\n\tstyle ??= 'decimal';\n\n\tconst key = `${locale ?? ''}:${style}`;\n\n\tlet formatter = numberFormatCache.get(key);\n\tif (formatter == null) {\n\t\tconst options: Intl.NumberFormatOptions = { localeMatcher: 'best fit', style: style };\n\n\t\tlet locales;\n\t\tif (locale == null) {\n\t\t\tlocales = defaultLocales;\n\t\t} else if (locale === 'system') {\n\t\t\tlocales = undefined;\n\t\t} else {\n\t\t\tlocales = [locale];\n\t\t}\n\n\t\tformatter = new Intl.NumberFormat(locales, options);\n\t\tnumberFormatCache.set(key, formatter);\n\t}\n\n\treturn formatter.format;\n}\n"],"mappings":";AACA,MAAM,kCACL;AACD,MAAM,sBAAsB;AAC5B,MAAM,yBAAkF;CACvF;EAAC;EAAQ;EAAqC;EAA2B;CAAI;CAC7E;EAAC;EAAS;EAAkC;EAAkC;CAAI;CAClF;EAAC;EAAQ;EAAyB;EAAyB;CAAI;CAC/D;EAAC;EAAO;EAAqB;EAAqB;CAAG;CACrD;EAAC;EAAQ;EAAgB;EAAgB;CAAG;CAC5C;EAAC;EAAU;EAAW;EAAW;CAAG;CACpC;EAAC;EAAU;EAAM;EAAM;CAAG;AAC3B;AAIA,MAAM,eAAqE,CAAC;AAC5E,MAAM,iBAAuE,CAAC;AAC9E,KAAK,MAAM,CAAC,MAAM,WAAW,YAAY,wBAAwB;CAChE,aAAa,QAAQ;CACrB,eAAe,QAAQ;AACxB;AAMA,IAAI;AACJ,MAAM,sCAAsB,IAAI,IAA6C;AAC7E,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,MAAM,oCAAoB,IAAI,IAA2C;AAEzE,SAAgB,sBAAsB,SAAqD;CAC1F,IAAI,OAAO,YAAY,UAAU;EAChC,IAAI,YAAY,YAAY,QAAQ,KAAK,CAAC,CAAC,WAAW,GACrD,iBAAiB,KAAA;OAEjB,iBAAiB,CAAC,OAAO;CAE3B,OACC,iBAAiB,WAAW,KAAA;CAG7B,4BAA4B,KAAA;CAC5B,iCAAiC,KAAA;CACjC,oBAAoB,MAAM;CAE1B,kBAAkB,MAAM;CAExB,SAAS,KAAA;AACV;AAEA,SAAgB,oBACf,MACA,OACO;CACP,MAAM,IAAI,IAAI,KAAK,KAAK,QAAQ,CAAC;CAEjC,KAAK,MAAM,CAAC,KAAK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AAI,SAAS;GAEvD;EACD;CACD;CAEA,OAAO;AACR;AAEA,SAAgB,iBACf,WACA,MACqB;CACrB,OAAO,aAAa,OAAO,kBAAkB,KAAK,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,MAAM,KAAK,KAAK,IAAI,KAAA;AACnG;AAEA,MAAM,WAAW;CAAC;CAAM;CAAM;CAAM;AAAI;AACxC,SAAS,kBAAkB,GAAmB;CAC7C,MAAM,IAAI,IAAI;CACd,OAAO,GAAG,IAAI,UAAU,IAAI,MAAM,OAAO,SAAS,MAAM,SAAS;AAClE;AAEA,SAAgB,cACf,OACA,OACA,QACS;CAET,OADe,iBAAiB,OAAO,MAC3B,CAAC,CAAC,KAAK;AACpB;AAEA,SAAgB,iBACf,OACA,QAC8B;CAC9B,UAAU;CAEV,MAAM,MAAM,GAAG,UAAU,GAAG,GAAG;CAE/B,IAAI,YAAY,kBAAkB,IAAI,GAAG;CACzC,IAAI,aAAa,MAAM;EACtB,MAAM,UAAoC;GAAE,eAAe;GAAmB;EAAM;EAEpF,IAAI;EACJ,IAAI,UAAU,MACb,UAAU;OACJ,IAAI,WAAW,UACrB,UAAU,KAAA;OAEV,UAAU,CAAC,MAAM;EAGlB,YAAY,IAAI,KAAK,aAAa,SAAS,OAAO;EAClD,kBAAkB,IAAI,KAAK,SAAS;CACrC;CAEA,OAAO,UAAU;AAClB"}
@@ -1,10 +1,10 @@
1
1
  import { getScopedLogger, maybeStartScopedLogger } from "../../logger.scoped.js";
2
2
  import { isWindows } from "./platform.js";
3
3
  import { join } from "path";
4
- import { stat } from "fs/promises";
5
- import * as process from "process";
6
4
  import { execFile, spawn } from "child_process";
7
5
  import { access, constants } from "fs";
6
+ import { stat } from "fs/promises";
7
+ import * as process from "process";
8
8
  //#region ../utils/src/env/node/exec.ts
9
9
  var RunError = class extends Error {
10
10
  cmd;
@@ -21,6 +21,12 @@ export type KeymapSheetRow = {
21
21
  * Absent (rather than empty) when the row has no ids at all — a fixed/residual row. */
22
22
  ids?: readonly string[];
23
23
  };
24
+ export type KeymapRegistrar<TScope extends string> = {
25
+ registerScope(id: TScope, registration: ScopeRegistration | 'always', guards?: readonly ((e: KeyboardEvent) => boolean)[]): Disposable;
26
+ registerBindings(descriptors: readonly KeyBindingDescriptor<TScope, KeyboardEvent>[]): Disposable;
27
+ pushOverlay(entry: OverlayEntry): Disposable;
28
+ dispose(): void;
29
+ };
24
30
  /** Owns a document-level keydown listener and dispatches it to registered bindings by scope, honoring
25
31
  * an overlay-close stack (Escape) ahead of any binding match. Framework-agnostic — consumers register
26
32
  * scopes/bindings/overlays and call {@link KeymapDispatcher.attach} once. */
@@ -39,13 +45,19 @@ export declare class KeymapDispatcher<TScope extends string> {
39
45
  * disabled owner's row can still surface via a registered `with` partner. */
40
46
  private bindingByDescriptor;
41
47
  private overlayStack;
48
+ private registrarCount;
42
49
  private attached;
50
+ private readonly root;
43
51
  constructor(options: {
44
52
  isMac: boolean;
45
53
  onWarn?: (message: string) => void;
54
+ root?: Element;
46
55
  });
47
56
  registerScope(id: TScope, registration: ScopeRegistration | 'always', guards?: readonly ((e: KeyboardEvent) => boolean)[]): Disposable;
48
57
  registerBindings(descriptors: readonly KeyBindingDescriptor<TScope, KeyboardEvent>[]): Disposable;
58
+ createRegistrar(): KeymapRegistrar<TScope>;
59
+ private addScope;
60
+ private addBindings;
49
61
  /** Replaces the active override map and rebuilds the effective binding list. Cheap enough to call
50
62
  * on every config push. */
51
63
  setOverrides(overrides: KeyBindingOverrides | undefined): void;
@@ -20,12 +20,43 @@ var KeymapDispatcher = class {
20
20
  * disabled owner's row can still surface via a registered `with` partner. */
21
21
  bindingByDescriptor = /* @__PURE__ */ new Map();
22
22
  overlayStack = [];
23
+ registrarCount = 0;
23
24
  attached = false;
25
+ root;
24
26
  constructor(options) {
25
27
  this.isMac = options.isMac;
26
28
  this.onWarn = options.onWarn;
29
+ this.root = options.root;
27
30
  }
28
31
  registerScope(id, registration, guards = []) {
32
+ return this.addScope(id, registration, guards);
33
+ }
34
+ registerBindings(descriptors) {
35
+ return this.addBindings(descriptors);
36
+ }
37
+ createRegistrar() {
38
+ const suffix = `#${++this.registrarCount}`;
39
+ const owned = /* @__PURE__ */ new Set();
40
+ const own = (disposable) => {
41
+ owned.add(disposable);
42
+ return createDisposable(() => {
43
+ if (owned.delete(disposable)) disposable.dispose();
44
+ });
45
+ };
46
+ return {
47
+ registerScope: (id, registration, guards = []) => own(this.addScope(`${id}${suffix}`, registration, guards)),
48
+ registerBindings: (descriptors) => own(this.addBindings(descriptors.map((d) => ({
49
+ ...d,
50
+ scope: `${d.scope}${suffix}`
51
+ })))),
52
+ pushOverlay: (entry) => own(this.pushOverlay(entry)),
53
+ dispose: () => {
54
+ for (const disposable of owned) disposable.dispose();
55
+ owned.clear();
56
+ }
57
+ };
58
+ }
59
+ addScope(id, registration, guards) {
29
60
  const entry = {
30
61
  registration,
31
62
  guards
@@ -37,7 +68,7 @@ var KeymapDispatcher = class {
37
68
  this.alwaysOrder = this.alwaysOrder.filter((scopeId) => scopeId !== id);
38
69
  });
39
70
  }
40
- registerBindings(descriptors) {
71
+ addBindings(descriptors) {
41
72
  this.registrationGroups.push(descriptors);
42
73
  this.rebuildBindings();
43
74
  return createDisposable(() => {
@@ -156,6 +187,7 @@ var KeymapDispatcher = class {
156
187
  }
157
188
  _onKeydown = (e) => {
158
189
  if (e.defaultPrevented) return;
190
+ if (this.root != null && !e.composedPath().includes(this.root)) return;
159
191
  if (e.key === "Escape" && this.overlayStack.length > 0 && this.closeTopOverlay()) {
160
192
  e.preventDefault();
161
193
  e.stopPropagation();
@@ -1 +1 @@
1
- {"version":3,"file":"keymapDispatcher.js","names":[],"sources":["../../../../utils/src/keys/keymapDispatcher.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n\nimport type { Disposable } from '../disposable.js';\nimport { createDisposable } from '../disposable.js';\nimport { matchesChord } from './chord.js';\nimport type {\n\tKeyBinding,\n\tKeyBindingDescriptor,\n\tKeyBindingOverrides,\n\tOverlayEntry,\n\tSheetDisplayEntry,\n\tSheetDisplayText,\n} from './keybinding.js';\nimport { registerBinding, resolveKeydown, resolveOverlayClose } from './keybinding.js';\n\n/** Where a scope is \"active\": rooted at a specific element, or matched by a CSS selector against the\n * keydown's composed path. */\nexport type ScopeRegistration = { root: Element } | { selector: string };\n\n/** A row for a rendered shortcut sheet — one binding's group/label/keys, in display form. */\nexport type KeymapSheetRow = {\n\tgroup: string;\n\tlabel: string;\n\torder?: number;\n\tkeys: readonly SheetDisplayEntry[];\n\tsubline?: readonly SheetDisplayEntry[];\n\t/** Whole localized subline; takes precedence over legacy display entries. */\n\tsublineText?: SheetDisplayText;\n\t/** The row's own id (if any) followed by each contributing partner's id — for the row tooltip.\n\t * Absent (rather than empty) when the row has no ids at all — a fixed/residual row. */\n\tids?: readonly string[];\n};\n\ntype ScopeEntry = {\n\tregistration: ScopeRegistration | 'always';\n\tguards: readonly ((e: KeyboardEvent) => boolean)[];\n};\n\n/** Owns a document-level keydown listener and dispatches it to registered bindings by scope, honoring\n * an overlay-close stack (Escape) ahead of any binding match. Framework-agnostic — consumers register\n * scopes/bindings/overlays and call {@link KeymapDispatcher.attach} once. */\nexport class KeymapDispatcher<TScope extends string> {\n\tprivate readonly isMac: boolean;\n\tprivate readonly onWarn: ((message: string) => void) | undefined;\n\tprivate readonly scopes = new Map<TScope, ScopeEntry>();\n\tprivate alwaysOrder: TScope[] = [];\n\t/** Registered descriptor groups, in registration order — kept so bindings can be rebuilt whenever\n\t * a group is added/removed or the overrides change. */\n\tprivate registrationGroups: (readonly KeyBindingDescriptor<TScope, KeyboardEvent>[])[] = [];\n\tprivate overrides: KeyBindingOverrides | undefined;\n\tprivate bindings: KeyBinding<TScope, KeyboardEvent>[] = [];\n\t/** Every registered descriptor's outcome, `undefined` when disabled by an override — lets\n\t * {@link sheetEntries} walk descriptors in registration order (not just the survivors) so a\n\t * disabled owner's row can still surface via a registered `with` partner. */\n\tprivate bindingByDescriptor = new Map<\n\t\tKeyBindingDescriptor<TScope, KeyboardEvent>,\n\t\tKeyBinding<TScope, KeyboardEvent> | undefined\n\t>();\n\tprivate overlayStack: OverlayEntry[] = [];\n\tprivate attached = false;\n\n\tconstructor(options: { isMac: boolean; onWarn?: (message: string) => void }) {\n\t\tthis.isMac = options.isMac;\n\t\tthis.onWarn = options.onWarn;\n\t}\n\n\tregisterScope(\n\t\tid: TScope,\n\t\tregistration: ScopeRegistration | 'always',\n\t\tguards: readonly ((e: KeyboardEvent) => boolean)[] = [],\n\t): Disposable {\n\t\tconst entry: ScopeEntry = { registration: registration, guards: guards };\n\t\tthis.scopes.set(id, entry);\n\t\tif (registration === 'always') {\n\t\t\tthis.alwaysOrder.push(id);\n\t\t}\n\n\t\treturn createDisposable(() => {\n\t\t\tif (this.scopes.get(id) === entry) {\n\t\t\t\tthis.scopes.delete(id);\n\t\t\t}\n\n\t\t\tthis.alwaysOrder = this.alwaysOrder.filter(scopeId => scopeId !== id);\n\t\t});\n\t}\n\n\tregisterBindings(descriptors: readonly KeyBindingDescriptor<TScope, KeyboardEvent>[]): Disposable {\n\t\tthis.registrationGroups.push(descriptors);\n\t\tthis.rebuildBindings();\n\n\t\treturn createDisposable(() => {\n\t\t\tconst index = this.registrationGroups.indexOf(descriptors);\n\t\t\tif (index === -1) return;\n\n\t\t\tthis.registrationGroups.splice(index, 1);\n\t\t\tthis.rebuildBindings();\n\t\t});\n\t}\n\n\t/** Replaces the active override map and rebuilds the effective binding list. Cheap enough to call\n\t * on every config push. */\n\tsetOverrides(overrides: KeyBindingOverrides | undefined): void {\n\t\tthis.overrides = overrides;\n\t\tthis.warnIgnoredWildcards(overrides);\n\t\tthis.rebuildBindings();\n\t}\n\n\t/** Wildcards can only disable (see `resolveOverride`) — warns once per offending wildcard key so\n\t * a user who tried to rebind via `'panels.*'`/`'*'` learns why it didn't take. */\n\tprivate warnIgnoredWildcards(overrides: KeyBindingOverrides | undefined): void {\n\t\tif (!overrides || this.onWarn == null) return;\n\n\t\tfor (const key of Object.keys(overrides)) {\n\t\t\tif (key !== '*' && !key.endsWith('.*')) continue;\n\n\t\t\tconst value = overrides[key];\n\t\t\tif (value === false || value.length === 0) continue;\n\n\t\t\tthis.onWarn(`Ignoring shortcut override '${key}': a wildcard can only disable (false), not rebind`);\n\t\t}\n\t}\n\n\tprivate rebuildBindings(): void {\n\t\tconst bindings: KeyBinding<TScope, KeyboardEvent>[] = [];\n\t\tconst byDescriptor = new Map<\n\t\t\tKeyBindingDescriptor<TScope, KeyboardEvent>,\n\t\t\tKeyBinding<TScope, KeyboardEvent> | undefined\n\t\t>();\n\n\t\tfor (const group of this.registrationGroups) {\n\t\t\tfor (const descriptor of group) {\n\t\t\t\tconst binding = registerBinding(descriptor, this.isMac, this.overrides, this.onWarn);\n\t\t\t\tbyDescriptor.set(descriptor, binding);\n\t\t\t\tif (binding == null) continue;\n\n\t\t\t\tbindings.push(binding);\n\t\t\t}\n\t\t}\n\n\t\tthis.bindings = bindings;\n\t\tthis.bindingByDescriptor = byDescriptor;\n\t}\n\n\t/** Closes the topmost overlay willing to close, exactly as an Escape keydown would — for hosts whose\n\t * widgets consume Esc locally but still want the stack to outrank their own fallback action. */\n\tcloseTopOverlay(): boolean {\n\t\tconst candidates = resolveOverlayClose(this.overlayStack);\n\t\tfor (const entry of candidates) {\n\t\t\tif (!entry.onClose()) continue;\n\n\t\t\tconst index = this.overlayStack.indexOf(entry);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.overlayStack.splice(index, 1);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tpushOverlay(entry: OverlayEntry): Disposable {\n\t\tthis.overlayStack.push(entry);\n\n\t\treturn createDisposable(() => {\n\t\t\tconst index = this.overlayStack.indexOf(entry);\n\t\t\tif (index === -1) return;\n\n\t\t\tthis.overlayStack.splice(index, 1);\n\t\t});\n\t}\n\n\tattach(): void {\n\t\tif (this.attached) return;\n\n\t\tdocument.addEventListener('keydown', this._onKeydown, false);\n\t\tthis.attached = true;\n\t}\n\n\tdispose(): void {\n\t\tif (this.attached) {\n\t\t\tdocument.removeEventListener('keydown', this._onKeydown, false);\n\t\t\tthis.attached = false;\n\t\t}\n\n\t\tthis.scopes.clear();\n\t\tthis.alwaysOrder = [];\n\t\tthis.registrationGroups = [];\n\t\tthis.overrides = undefined;\n\t\tthis.bindings = [];\n\t\tthis.bindingByDescriptor = new Map();\n\t\tthis.overlayStack = [];\n\t}\n\n\tsheetEntries(): readonly KeymapSheetRow[] {\n\t\tconst byId = new Map<string, KeyBinding<TScope, KeyboardEvent>>();\n\t\tfor (const binding of this.bindings) {\n\t\t\tif (binding.id == null) continue;\n\n\t\t\tbyId.set(binding.id, binding);\n\t\t}\n\n\t\t// A partner's display segment — its live effective keys once overridden, otherwise the\n\t\t// `with` entry's own default display (falling back to the partner's own keys).\n\t\tconst partnerSegment = (\n\t\t\tpartnerBinding: KeyBinding<TScope, KeyboardEvent>,\n\t\t\tpartner: { keys?: readonly SheetDisplayEntry[] },\n\t\t): readonly SheetDisplayEntry[] =>\n\t\t\tpartnerBinding.overridden ? partnerBinding.keys : (partner.keys ?? partnerBinding.keys);\n\n\t\tconst rows: KeymapSheetRow[] = [];\n\t\t// Walk descriptors (not just `this.bindings`) so a visible descriptor disabled by an override\n\t\t// can still surface a row when one of its `with` partners is still registered.\n\t\tfor (const group of this.registrationGroups) {\n\t\t\tfor (const descriptor of group) {\n\t\t\t\tif (descriptor.sheet === 'hidden') continue;\n\n\t\t\t\tconst sheet = descriptor.sheet;\n\t\t\t\tconst binding = this.bindingByDescriptor.get(descriptor);\n\n\t\t\t\tconst keys: SheetDisplayEntry[] = [];\n\t\t\t\tconst ids: string[] = [];\n\n\t\t\t\tif (binding != null) {\n\t\t\t\t\tconst self = binding.overridden ? binding.keys : (sheet.keysOverride ?? binding.keys);\n\t\t\t\t\tkeys.push(...self);\n\t\t\t\t\tif (binding.id != null) {\n\t\t\t\t\t\tids.push(binding.id);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const partner of sheet.with ?? []) {\n\t\t\t\t\tconst partnerBinding = byId.get(partner.id);\n\t\t\t\t\tif (partnerBinding == null) continue; // disabled (or unregistered) partner contributes nothing\n\n\t\t\t\t\tif (keys.length > 0) {\n\t\t\t\t\t\tkeys.push('sep:/');\n\t\t\t\t\t}\n\t\t\t\t\tkeys.push(...partnerSegment(partnerBinding, partner));\n\t\t\t\t\tids.push(partner.id);\n\t\t\t\t}\n\n\t\t\t\t// The owner is disabled AND no `with` partner survived — nothing left to show.\n\t\t\t\tif (binding == null && ids.length === 0) continue;\n\n\t\t\t\trows.push({\n\t\t\t\t\tgroup: sheet.group,\n\t\t\t\t\tlabel: sheet.label,\n\t\t\t\t\torder: sheet.order,\n\t\t\t\t\tkeys: keys,\n\t\t\t\t\tsubline: sheet.subline,\n\t\t\t\t\tsublineText: sheet.sublineText,\n\t\t\t\t\tids: ids.length > 0 ? ids : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn rows;\n\t}\n\n\tprivate readonly _onKeydown = (e: KeyboardEvent): void => {\n\t\tif (e.defaultPrevented) return;\n\n\t\tif (e.key === 'Escape' && this.overlayStack.length > 0 && this.closeTopOverlay()) {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\treturn;\n\t\t}\n\n\t\tconst chain: TScope[] = [];\n\t\tfor (const element of e.composedPath()) {\n\t\t\tfor (const [id, entry] of this.scopes) {\n\t\t\t\tif (entry.registration === 'always') continue;\n\t\t\t\tif (chain.includes(id)) continue;\n\n\t\t\t\tconst registration = entry.registration;\n\t\t\t\tconst matches =\n\t\t\t\t\t('root' in registration && registration.root === element) ||\n\t\t\t\t\t('selector' in registration &&\n\t\t\t\t\t\telement instanceof Element &&\n\t\t\t\t\t\telement.matches(registration.selector));\n\t\t\t\tif (matches) {\n\t\t\t\t\tchain.push(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const id of this.alwaysOrder) {\n\t\t\tif (!chain.includes(id)) {\n\t\t\t\tchain.push(id);\n\t\t\t}\n\t\t}\n\n\t\tconst candidates = resolveKeydown(this.bindings, chain, e);\n\t\tfor (const candidate of candidates) {\n\t\t\tconst guards = this.scopes.get(candidate.scope)?.guards ?? [];\n\t\t\tif (guards.some(guard => !guard(e))) continue;\n\n\t\t\tif (candidate.when?.some(when => !when(e))) continue;\n\n\t\t\tconst chordIndex = candidate.chords.findIndex(chord => matchesChord(chord, e));\n\t\t\tif (!candidate.run(e, chordIndex)) continue;\n\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\treturn;\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;AAyCA,IAAa,mBAAb,MAAqD;CACpD;CACA;CACA,yBAA0B,IAAI,IAAwB;CACtD,cAAgC,CAAC;;;CAGjC,qBAAyF,CAAC;CAC1F;CACA,WAAwD,CAAC;;;;CAIzD,sCAA8B,IAAI,IAGhC;CACF,eAAuC,CAAC;CACxC,WAAmB;CAEnB,YAAY,SAAiE;EAC5E,KAAK,QAAQ,QAAQ;EACrB,KAAK,SAAS,QAAQ;CACvB;CAEA,cACC,IACA,cACA,SAAqD,CAAC,GACzC;EACb,MAAM,QAAoB;GAAgB;GAAsB;EAAO;EACvE,KAAK,OAAO,IAAI,IAAI,KAAK;EACzB,IAAI,iBAAiB,UACpB,KAAK,YAAY,KAAK,EAAE;EAGzB,OAAO,uBAAuB;GAC7B,IAAI,KAAK,OAAO,IAAI,EAAE,MAAM,OAC3B,KAAK,OAAO,OAAO,EAAE;GAGtB,KAAK,cAAc,KAAK,YAAY,QAAO,YAAW,YAAY,EAAE;EACrE,CAAC;CACF;CAEA,iBAAiB,aAAiF;EACjG,KAAK,mBAAmB,KAAK,WAAW;EACxC,KAAK,gBAAgB;EAErB,OAAO,uBAAuB;GAC7B,MAAM,QAAQ,KAAK,mBAAmB,QAAQ,WAAW;GACzD,IAAI,UAAU,IAAI;GAElB,KAAK,mBAAmB,OAAO,OAAO,CAA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AC7E,IAAI,CAAC,UAAU,IAAI,GAAG,UAAU,GAAG;GAEnC,EAAE,eAAe;GACjB,EAAE,gBAAgB;GAClB;EACD;CACD;AACD"}
1
+ {"version":3,"file":"keymapDispatcher.js","names":[],"sources":["../../../../utils/src/keys/keymapDispatcher.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n\nimport type { Disposable } from '../disposable.js';\nimport { createDisposable } from '../disposable.js';\nimport { matchesChord } from './chord.js';\nimport type {\n\tKeyBinding,\n\tKeyBindingDescriptor,\n\tKeyBindingOverrides,\n\tOverlayEntry,\n\tSheetDisplayEntry,\n\tSheetDisplayText,\n} from './keybinding.js';\nimport { registerBinding, resolveKeydown, resolveOverlayClose } from './keybinding.js';\n\n/** Where a scope is \"active\": rooted at a specific element, or matched by a CSS selector against the\n * keydown's composed path. */\nexport type ScopeRegistration = { root: Element } | { selector: string };\n\n/** A row for a rendered shortcut sheet — one binding's group/label/keys, in display form. */\nexport type KeymapSheetRow = {\n\tgroup: string;\n\tlabel: string;\n\torder?: number;\n\tkeys: readonly SheetDisplayEntry[];\n\tsubline?: readonly SheetDisplayEntry[];\n\t/** Whole localized subline; takes precedence over legacy display entries. */\n\tsublineText?: SheetDisplayText;\n\t/** The row's own id (if any) followed by each contributing partner's id — for the row tooltip.\n\t * Absent (rather than empty) when the row has no ids at all — a fixed/residual row. */\n\tids?: readonly string[];\n};\n\ntype ScopeEntry = {\n\tregistration: ScopeRegistration | 'always';\n\tguards: readonly ((e: KeyboardEvent) => boolean)[];\n};\n\nexport type KeymapRegistrar<TScope extends string> = {\n\tregisterScope(\n\t\tid: TScope,\n\t\tregistration: ScopeRegistration | 'always',\n\t\tguards?: readonly ((e: KeyboardEvent) => boolean)[],\n\t): Disposable;\n\tregisterBindings(descriptors: readonly KeyBindingDescriptor<TScope, KeyboardEvent>[]): Disposable;\n\tpushOverlay(entry: OverlayEntry): Disposable;\n\tdispose(): void;\n};\n\n/** Owns a document-level keydown listener and dispatches it to registered bindings by scope, honoring\n * an overlay-close stack (Escape) ahead of any binding match. Framework-agnostic — consumers register\n * scopes/bindings/overlays and call {@link KeymapDispatcher.attach} once. */\nexport class KeymapDispatcher<TScope extends string> {\n\tprivate readonly isMac: boolean;\n\tprivate readonly onWarn: ((message: string) => void) | undefined;\n\tprivate readonly scopes = new Map<string, ScopeEntry>();\n\tprivate alwaysOrder: string[] = [];\n\t/** Registered descriptor groups, in registration order — kept so bindings can be rebuilt whenever\n\t * a group is added/removed or the overrides change. */\n\tprivate registrationGroups: (readonly KeyBindingDescriptor<string, KeyboardEvent>[])[] = [];\n\tprivate overrides: KeyBindingOverrides | undefined;\n\tprivate bindings: KeyBinding<string, KeyboardEvent>[] = [];\n\t/** Every registered descriptor's outcome, `undefined` when disabled by an override — lets\n\t * {@link sheetEntries} walk descriptors in registration order (not just the survivors) so a\n\t * disabled owner's row can still surface via a registered `with` partner. */\n\tprivate bindingByDescriptor = new Map<\n\t\tKeyBindingDescriptor<string, KeyboardEvent>,\n\t\tKeyBinding<string, KeyboardEvent> | undefined\n\t>();\n\tprivate overlayStack: OverlayEntry[] = [];\n\tprivate registrarCount = 0;\n\tprivate attached = false;\n\tprivate readonly root: Element | undefined;\n\n\tconstructor(options: { isMac: boolean; onWarn?: (message: string) => void; root?: Element }) {\n\t\tthis.isMac = options.isMac;\n\t\tthis.onWarn = options.onWarn;\n\t\tthis.root = options.root;\n\t}\n\n\tregisterScope(\n\t\tid: TScope,\n\t\tregistration: ScopeRegistration | 'always',\n\t\tguards: readonly ((e: KeyboardEvent) => boolean)[] = [],\n\t): Disposable {\n\t\treturn this.addScope(id, registration, guards);\n\t}\n\n\tregisterBindings(descriptors: readonly KeyBindingDescriptor<TScope, KeyboardEvent>[]): Disposable {\n\t\treturn this.addBindings(descriptors);\n\t}\n\n\tcreateRegistrar(): KeymapRegistrar<TScope> {\n\t\tconst suffix = `#${++this.registrarCount}`;\n\t\tconst owned = new Set<Disposable>();\n\t\tconst own = (disposable: Disposable): Disposable => {\n\t\t\towned.add(disposable);\n\t\t\treturn createDisposable(() => {\n\t\t\t\tif (owned.delete(disposable)) {\n\t\t\t\t\tdisposable.dispose();\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\n\t\treturn {\n\t\t\tregisterScope: (id, registration, guards = []) =>\n\t\t\t\town(this.addScope(`${id}${suffix}`, registration, guards)),\n\t\t\tregisterBindings: descriptors =>\n\t\t\t\town(this.addBindings(descriptors.map(d => ({ ...d, scope: `${d.scope}${suffix}` })))),\n\t\t\tpushOverlay: entry => own(this.pushOverlay(entry)),\n\t\t\tdispose: () => {\n\t\t\t\tfor (const disposable of owned) {\n\t\t\t\t\tdisposable.dispose();\n\t\t\t\t}\n\t\t\t\towned.clear();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate addScope(\n\t\tid: string,\n\t\tregistration: ScopeRegistration | 'always',\n\t\tguards: readonly ((e: KeyboardEvent) => boolean)[],\n\t): Disposable {\n\t\tconst entry: ScopeEntry = { registration: registration, guards: guards };\n\t\tthis.scopes.set(id, entry);\n\t\tif (registration === 'always') {\n\t\t\tthis.alwaysOrder.push(id);\n\t\t}\n\n\t\treturn createDisposable(() => {\n\t\t\tif (this.scopes.get(id) === entry) {\n\t\t\t\tthis.scopes.delete(id);\n\t\t\t}\n\n\t\t\tthis.alwaysOrder = this.alwaysOrder.filter(scopeId => scopeId !== id);\n\t\t});\n\t}\n\n\tprivate addBindings(descriptors: readonly KeyBindingDescriptor<string, KeyboardEvent>[]): Disposable {\n\t\tthis.registrationGroups.push(descriptors);\n\t\tthis.rebuildBindings();\n\n\t\treturn createDisposable(() => {\n\t\t\tconst index = this.registrationGroups.indexOf(descriptors);\n\t\t\tif (index === -1) return;\n\n\t\t\tthis.registrationGroups.splice(index, 1);\n\t\t\tthis.rebuildBindings();\n\t\t});\n\t}\n\n\t/** Replaces the active override map and rebuilds the effective binding list. Cheap enough to call\n\t * on every config push. */\n\tsetOverrides(overrides: KeyBindingOverrides | undefined): void {\n\t\tthis.overrides = overrides;\n\t\tthis.warnIgnoredWildcards(overrides);\n\t\tthis.rebuildBindings();\n\t}\n\n\t/** Wildcards can only disable (see `resolveOverride`) — warns once per offending wildcard key so\n\t * a user who tried to rebind via `'panels.*'`/`'*'` learns why it didn't take. */\n\tprivate warnIgnoredWildcards(overrides: KeyBindingOverrides | undefined): void {\n\t\tif (!overrides || this.onWarn == null) return;\n\n\t\tfor (const key of Object.keys(overrides)) {\n\t\t\tif (key !== '*' && !key.endsWith('.*')) continue;\n\n\t\t\tconst value = overrides[key];\n\t\t\tif (value === false || value.length === 0) continue;\n\n\t\t\tthis.onWarn(`Ignoring shortcut override '${key}': a wildcard can only disable (false), not rebind`);\n\t\t}\n\t}\n\n\tprivate rebuildBindings(): void {\n\t\tconst bindings: KeyBinding<string, KeyboardEvent>[] = [];\n\t\tconst byDescriptor = new Map<\n\t\t\tKeyBindingDescriptor<string, KeyboardEvent>,\n\t\t\tKeyBinding<string, KeyboardEvent> | undefined\n\t\t>();\n\n\t\tfor (const group of this.registrationGroups) {\n\t\t\tfor (const descriptor of group) {\n\t\t\t\tconst binding = registerBinding(descriptor, this.isMac, this.overrides, this.onWarn);\n\t\t\t\tbyDescriptor.set(descriptor, binding);\n\t\t\t\tif (binding == null) continue;\n\n\t\t\t\tbindings.push(binding);\n\t\t\t}\n\t\t}\n\n\t\tthis.bindings = bindings;\n\t\tthis.bindingByDescriptor = byDescriptor;\n\t}\n\n\t/** Closes the topmost overlay willing to close, exactly as an Escape keydown would — for hosts whose\n\t * widgets consume Esc locally but still want the stack to outrank their own fallback action. */\n\tcloseTopOverlay(): boolean {\n\t\tconst candidates = resolveOverlayClose(this.overlayStack);\n\t\tfor (const entry of candidates) {\n\t\t\tif (!entry.onClose()) continue;\n\n\t\t\tconst index = this.overlayStack.indexOf(entry);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.overlayStack.splice(index, 1);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tpushOverlay(entry: OverlayEntry): Disposable {\n\t\tthis.overlayStack.push(entry);\n\n\t\treturn createDisposable(() => {\n\t\t\tconst index = this.overlayStack.indexOf(entry);\n\t\t\tif (index === -1) return;\n\n\t\t\tthis.overlayStack.splice(index, 1);\n\t\t});\n\t}\n\n\tattach(): void {\n\t\tif (this.attached) return;\n\n\t\tdocument.addEventListener('keydown', this._onKeydown, false);\n\t\tthis.attached = true;\n\t}\n\n\tdispose(): void {\n\t\tif (this.attached) {\n\t\t\tdocument.removeEventListener('keydown', this._onKeydown, false);\n\t\t\tthis.attached = false;\n\t\t}\n\n\t\tthis.scopes.clear();\n\t\tthis.alwaysOrder = [];\n\t\tthis.registrationGroups = [];\n\t\tthis.overrides = undefined;\n\t\tthis.bindings = [];\n\t\tthis.bindingByDescriptor = new Map();\n\t\tthis.overlayStack = [];\n\t}\n\n\tsheetEntries(): readonly KeymapSheetRow[] {\n\t\tconst byId = new Map<string, KeyBinding<string, KeyboardEvent>>();\n\t\tfor (const binding of this.bindings) {\n\t\t\tif (binding.id == null) continue;\n\n\t\t\tbyId.set(binding.id, binding);\n\t\t}\n\n\t\t// A partner's display segment — its live effective keys once overridden, otherwise the\n\t\t// `with` entry's own default display (falling back to the partner's own keys).\n\t\tconst partnerSegment = (\n\t\t\tpartnerBinding: KeyBinding<string, KeyboardEvent>,\n\t\t\tpartner: { keys?: readonly SheetDisplayEntry[] },\n\t\t): readonly SheetDisplayEntry[] =>\n\t\t\tpartnerBinding.overridden ? partnerBinding.keys : (partner.keys ?? partnerBinding.keys);\n\n\t\tconst rows: KeymapSheetRow[] = [];\n\t\t// Walk descriptors (not just `this.bindings`) so a visible descriptor disabled by an override\n\t\t// can still surface a row when one of its `with` partners is still registered.\n\t\tfor (const group of this.registrationGroups) {\n\t\t\tfor (const descriptor of group) {\n\t\t\t\tif (descriptor.sheet === 'hidden') continue;\n\n\t\t\t\tconst sheet = descriptor.sheet;\n\t\t\t\tconst binding = this.bindingByDescriptor.get(descriptor);\n\n\t\t\t\tconst keys: SheetDisplayEntry[] = [];\n\t\t\t\tconst ids: string[] = [];\n\n\t\t\t\tif (binding != null) {\n\t\t\t\t\tconst self = binding.overridden ? binding.keys : (sheet.keysOverride ?? binding.keys);\n\t\t\t\t\tkeys.push(...self);\n\t\t\t\t\tif (binding.id != null) {\n\t\t\t\t\t\tids.push(binding.id);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const partner of sheet.with ?? []) {\n\t\t\t\t\tconst partnerBinding = byId.get(partner.id);\n\t\t\t\t\tif (partnerBinding == null) continue; // disabled (or unregistered) partner contributes nothing\n\n\t\t\t\t\tif (keys.length > 0) {\n\t\t\t\t\t\tkeys.push('sep:/');\n\t\t\t\t\t}\n\t\t\t\t\tkeys.push(...partnerSegment(partnerBinding, partner));\n\t\t\t\t\tids.push(partner.id);\n\t\t\t\t}\n\n\t\t\t\t// The owner is disabled AND no `with` partner survived — nothing left to show.\n\t\t\t\tif (binding == null && ids.length === 0) continue;\n\n\t\t\t\trows.push({\n\t\t\t\t\tgroup: sheet.group,\n\t\t\t\t\tlabel: sheet.label,\n\t\t\t\t\torder: sheet.order,\n\t\t\t\t\tkeys: keys,\n\t\t\t\t\tsubline: sheet.subline,\n\t\t\t\t\tsublineText: sheet.sublineText,\n\t\t\t\t\tids: ids.length > 0 ? ids : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn rows;\n\t}\n\n\tprivate readonly _onKeydown = (e: KeyboardEvent): void => {\n\t\tif (e.defaultPrevented) return;\n\t\tif (this.root != null && !e.composedPath().includes(this.root)) return;\n\n\t\tif (e.key === 'Escape' && this.overlayStack.length > 0 && this.closeTopOverlay()) {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\treturn;\n\t\t}\n\n\t\tconst chain: string[] = [];\n\t\tfor (const element of e.composedPath()) {\n\t\t\tfor (const [id, entry] of this.scopes) {\n\t\t\t\tif (entry.registration === 'always') continue;\n\t\t\t\tif (chain.includes(id)) continue;\n\n\t\t\t\tconst registration = entry.registration;\n\t\t\t\tconst matches =\n\t\t\t\t\t('root' in registration && registration.root === element) ||\n\t\t\t\t\t('selector' in registration &&\n\t\t\t\t\t\telement instanceof Element &&\n\t\t\t\t\t\telement.matches(registration.selector));\n\t\t\t\tif (matches) {\n\t\t\t\t\tchain.push(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const id of this.alwaysOrder) {\n\t\t\tif (!chain.includes(id)) {\n\t\t\t\tchain.push(id);\n\t\t\t}\n\t\t}\n\n\t\tconst candidates = resolveKeydown(this.bindings, chain, e);\n\t\tfor (const candidate of candidates) {\n\t\t\tconst guards = this.scopes.get(candidate.scope)?.guards ?? [];\n\t\t\tif (guards.some(guard => !guard(e))) continue;\n\n\t\t\tif (candidate.when?.some(when => !when(e))) continue;\n\n\t\t\tconst chordIndex = candidate.chords.findIndex(chord => matchesChord(chord, e));\n\t\t\tif (!candidate.run(e, chordIndex)) continue;\n\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\treturn;\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;AAoDA,IAAa,mBAAb,MAAqD;CACpD;CACA;CACA,yBAA0B,IAAI,IAAwB;CACtD,cAAgC,CAAC;;;CAGjC,qBAAyF,CAAC;CAC1F;CACA,WAAwD,CAAC;;;;CAIzD,sCAA8B,IAAI,IAGhC;CACF,eAAuC,CAAC;CACxC,iBAAyB;CACzB,WAAmB;CACnB;CAEA,YAAY,SAAiF;EAC5F,KAAK,QAAQ,QAAQ;EACrB,KAAK,SAAS,QAAQ;EACtB,KAAK,OAAO,QAAQ;CACrB;CAEA,cACC,IACA,cACA,SAAqD,CAAC,GACzC;EACb,OAAO,KAAK,SAAS,IAAI,cAAc,MAAM;CAC9C;CAEA,iBAAiB,aAAiF;EACjG,OAAO,KAAK,YAAY,WAAW;CACpC;CAEA,kBAA2C;EAC1C,MAAM,SAAS,IAAI,EAAE,KAAK;EAC1B,MAAM,wBAAQ,I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ACD;AACD"}
@@ -2,32 +2,64 @@ import * as l10n from "@vscode/l10n";
2
2
  //#region ../utils/src/pausedOperation.ts
3
3
  const pausedOperationStatusStringsByType = {
4
4
  "cherry-pick": {
5
- name: l10n.t("Cherry Pick"),
6
- prose: l10n.t("Cherry-pick"),
7
- label: l10n.t("Cherry picking"),
8
- conflicts: l10n.t("Resolve conflicts to continue cherry picking"),
5
+ get name() {
6
+ return l10n.t("Cherry Pick");
7
+ },
8
+ get prose() {
9
+ return l10n.t("Cherry-pick");
10
+ },
11
+ get label() {
12
+ return l10n.t("Cherry picking");
13
+ },
14
+ get conflicts() {
15
+ return l10n.t("Resolve conflicts to continue cherry picking");
16
+ },
9
17
  directionality: "into"
10
18
  },
11
19
  merge: {
12
- name: l10n.t("Merge"),
13
- prose: l10n.t("Merge"),
14
- label: l10n.t("Merging"),
15
- conflicts: l10n.t("Resolve conflicts to continue merging"),
20
+ get name() {
21
+ return l10n.t("Merge");
22
+ },
23
+ get prose() {
24
+ return l10n.t("Merge");
25
+ },
26
+ get label() {
27
+ return l10n.t("Merging");
28
+ },
29
+ get conflicts() {
30
+ return l10n.t("Resolve conflicts to continue merging");
31
+ },
16
32
  directionality: "into"
17
33
  },
18
34
  rebase: {
19
- name: l10n.t("Rebase"),
20
- prose: l10n.t("Rebase"),
21
- label: l10n.t("Rebasing"),
22
- conflicts: l10n.t("Resolve conflicts to continue rebasing"),
35
+ get name() {
36
+ return l10n.t("Rebase");
37
+ },
38
+ get prose() {
39
+ return l10n.t("Rebase");
40
+ },
41
+ get label() {
42
+ return l10n.t("Rebasing");
43
+ },
44
+ get conflicts() {
45
+ return l10n.t("Resolve conflicts to continue rebasing");
46
+ },
23
47
  directionality: "onto",
24
48
  pending: "Pending rebase of"
25
49
  },
26
50
  revert: {
27
- name: l10n.t("Revert"),
28
- prose: l10n.t("Revert"),
29
- label: l10n.t("Reverting"),
30
- conflicts: l10n.t("Resolve conflicts to continue reverting"),
51
+ get name() {
52
+ return l10n.t("Revert");
53
+ },
54
+ get prose() {
55
+ return l10n.t("Revert");
56
+ },
57
+ get label() {
58
+ return l10n.t("Reverting");
59
+ },
60
+ get conflicts() {
61
+ return l10n.t("Resolve conflicts to continue reverting");
62
+ },
31
63
  directionality: "in"
32
64
  }
33
65
  };
@@ -1 +1 @@
1
- {"version":3,"file":"pausedOperation.js","names":[],"sources":["../../../utils/src/pausedOperation.ts"],"sourcesContent":["import * as l10n from '@vscode/l10n';\n\n/** Git vocabulary shared by `packages/git`, the host, and the renderer kernel\n * (`@gitkraken/commit-graph-ui`), which must not depend on `@gitlens/git`; it lives here for that reason. */\nexport type PausedOperationType = 'cherry-pick' | 'merge' | 'rebase' | 'revert';\n\nexport type PausedOperationStatus = {\n\ttype: PausedOperationType;\n\tsteps?: { total: number };\n};\n\n/** `name` is Title Case for actions; `prose` is the sentence form. */\ntype PausedOperationStrings = {\n\treadonly name: string;\n\treadonly prose: string;\n\treadonly label: string;\n\treadonly conflicts: string;\n};\n\nexport const pausedOperationStatusStringsByType: {\n\treadonly 'cherry-pick': PausedOperationStrings & { readonly directionality: 'into' };\n\treadonly merge: PausedOperationStrings & { readonly directionality: 'into' };\n\treadonly rebase: PausedOperationStrings & {\n\t\treadonly directionality: 'onto';\n\t\treadonly pending: 'Pending rebase of';\n\t};\n\treadonly revert: PausedOperationStrings & { readonly directionality: 'in' };\n} = {\n\t'cherry-pick': {\n\t\tname: l10n.t('Cherry Pick'),\n\t\tprose: l10n.t('Cherry-pick'),\n\t\tlabel: l10n.t('Cherry picking'),\n\t\tconflicts: l10n.t('Resolve conflicts to continue cherry picking'),\n\t\tdirectionality: 'into',\n\t},\n\tmerge: {\n\t\tname: l10n.t('Merge'),\n\t\tprose: l10n.t('Merge'),\n\t\tlabel: l10n.t('Merging'),\n\t\tconflicts: l10n.t('Resolve conflicts to continue merging'),\n\t\tdirectionality: 'into',\n\t},\n\trebase: {\n\t\tname: l10n.t('Rebase'),\n\t\tprose: l10n.t('Rebase'),\n\t\tlabel: l10n.t('Rebasing'),\n\t\tconflicts: l10n.t('Resolve conflicts to continue rebasing'),\n\t\tdirectionality: 'onto',\n\t\tpending: 'Pending rebase of',\n\t},\n\trevert: {\n\t\tname: l10n.t('Revert'),\n\t\tprose: l10n.t('Revert'),\n\t\tlabel: l10n.t('Reverting'),\n\t\tconflicts: l10n.t('Resolve conflicts to continue reverting'),\n\t\tdirectionality: 'in',\n\t},\n} as const;\n\nexport type PausedOperationVariant = 'conflicts' | 'pending' | 'ready';\n\nexport const pausedOperationVariantIcons: Readonly<Record<PausedOperationVariant, string>> = Object.freeze({\n\tconflicts: 'warning',\n\tpending: 'circle-outline',\n\tready: 'check',\n});\n\n/** Unresolved conflicts outrank a rebase that has not reached its first step. */\nexport function getPausedOperationVariant(\n\tstatus: PausedOperationStatus,\n\thasConflicts: boolean,\n): PausedOperationVariant {\n\tif (hasConflicts) return 'conflicts';\n\tif (status.type === 'rebase' && status.steps?.total === 0) return 'pending';\n\treturn 'ready';\n}\n\n/** The leading phrase naming the operation's state — shared by the paused-operation bar, the WIP header\n * badge, and the graph's work-directory row so they can't disagree. Callers whose surface needs a\n * different conflicts phrasing substitute their own for that variant only. */\nexport function getPausedOperationLabel(status: PausedOperationStatus, variant: PausedOperationVariant): string {\n\tconst strings = pausedOperationStatusStringsByType[status.type];\n\t// Title Case throughout — these read as state names on a pill or a bar, not as prose.\n\tif (variant === 'conflicts') {\n\t\tswitch (status.type) {\n\t\t\tcase 'cherry-pick':\n\t\t\t\treturn l10n.t('Cherry-pick Paused');\n\t\t\tcase 'merge':\n\t\t\t\treturn l10n.t('Merge Paused');\n\t\t\tcase 'rebase':\n\t\t\t\treturn l10n.t('Rebase Paused');\n\t\t\tcase 'revert':\n\t\t\t\treturn l10n.t('Revert Paused');\n\t\t}\n\t}\n\t// The shared `pending` string trails a preposition for callers that append a ref inline (the tree\n\t// view). The bar's refs can shed, so it carries that \"of\" inside the refs group instead.\n\tif (variant === 'pending' && status.type === 'rebase') return l10n.t('Pending Rebase');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AAS,UAAU,OAAO,KAAK,EAAE,gBAAgB;CAErF,OAAO,QAAQ;AAChB"}
1
+ {"version":3,"file":"pausedOperation.js","names":[],"sources":["../../../utils/src/pausedOperation.ts"],"sourcesContent":["import * as l10n from '@vscode/l10n';\n\n/** Git vocabulary shared by `packages/git`, the host, and the renderer kernel\n * (`@gitkraken/commit-graph-ui`), which must not depend on `@gitlens/git`; it lives here for that reason. */\nexport type PausedOperationType = 'cherry-pick' | 'merge' | 'rebase' | 'revert';\n\nexport type PausedOperationStatus = {\n\ttype: PausedOperationType;\n\tsteps?: { total: number };\n};\n\n/** `name` is Title Case for actions; `prose` is the sentence form. */\ntype PausedOperationStrings = {\n\treadonly name: string;\n\treadonly prose: string;\n\treadonly label: string;\n\treadonly conflicts: string;\n};\n\nexport const pausedOperationStatusStringsByType: {\n\treadonly 'cherry-pick': PausedOperationStrings & { readonly directionality: 'into' };\n\treadonly merge: PausedOperationStrings & { readonly directionality: 'into' };\n\treadonly rebase: PausedOperationStrings & {\n\t\treadonly directionality: 'onto';\n\t\treadonly pending: 'Pending rebase of';\n\t};\n\treadonly revert: PausedOperationStrings & { readonly directionality: 'in' };\n} = {\n\t'cherry-pick': {\n\t\tget name() {\n\t\t\treturn l10n.t('Cherry Pick');\n\t\t},\n\t\tget prose() {\n\t\t\treturn l10n.t('Cherry-pick');\n\t\t},\n\t\tget label() {\n\t\t\treturn l10n.t('Cherry picking');\n\t\t},\n\t\tget conflicts() {\n\t\t\treturn l10n.t('Resolve conflicts to continue cherry picking');\n\t\t},\n\t\tdirectionality: 'into',\n\t},\n\tmerge: {\n\t\tget name() {\n\t\t\treturn l10n.t('Merge');\n\t\t},\n\t\tget prose() {\n\t\t\treturn l10n.t('Merge');\n\t\t},\n\t\tget label() {\n\t\t\treturn l10n.t('Merging');\n\t\t},\n\t\tget conflicts() {\n\t\t\treturn l10n.t('Resolve conflicts to continue merging');\n\t\t},\n\t\tdirectionality: 'into',\n\t},\n\trebase: {\n\t\tget name() {\n\t\t\treturn l10n.t('Rebase');\n\t\t},\n\t\tget prose() {\n\t\t\treturn l10n.t('Rebase');\n\t\t},\n\t\tget label() {\n\t\t\treturn l10n.t('Rebasing');\n\t\t},\n\t\tget conflicts() {\n\t\t\treturn l10n.t('Resolve conflicts to continue rebasing');\n\t\t},\n\t\tdirectionality: 'onto',\n\t\tpending: 'Pending rebase of',\n\t},\n\trevert: {\n\t\tget name() {\n\t\t\treturn l10n.t('Revert');\n\t\t},\n\t\tget prose() {\n\t\t\treturn l10n.t('Revert');\n\t\t},\n\t\tget label() {\n\t\t\treturn l10n.t('Reverting');\n\t\t},\n\t\tget conflicts() {\n\t\t\treturn l10n.t('Resolve conflicts to continue reverting');\n\t\t},\n\t\tdirectionality: 'in',\n\t},\n} as const;\n\nexport type PausedOperationVariant = 'conflicts' | 'pending' | 'ready';\n\nexport const pausedOperationVariantIcons: Readonly<Record<PausedOperationVariant, string>> = Object.freeze({\n\tconflicts: 'warning',\n\tpending: 'circle-outline',\n\tready: 'check',\n});\n\n/** Unresolved conflicts outrank a rebase that has not reached its first step. */\nexport function getPausedOperationVariant(\n\tstatus: PausedOperationStatus,\n\thasConflicts: boolean,\n): PausedOperationVariant {\n\tif (hasConflicts) return 'conflicts';\n\tif (status.type === 'rebase' && status.steps?.total === 0) return 'pending';\n\treturn 'ready';\n}\n\n/** The leading phrase naming the operation's state — shared by the paused-operation bar, the WIP header\n * badge, and the graph's work-directory row so they can't disagree. Callers whose surface needs a\n * different conflicts phrasing substitute their own for that variant only. */\nexport function getPausedOperationLabel(status: PausedOperationStatus, variant: PausedOperationVariant): string {\n\tconst strings = pausedOperationStatusStringsByType[status.type];\n\t// Title Case throughout — these read as state names on a pill or a bar, not as prose.\n\tif (variant === 'conflicts') {\n\t\tswitch (status.type) {\n\t\t\tcase 'cherry-pick':\n\t\t\t\treturn l10n.t('Cherry-pick Paused');\n\t\t\tcase 'merge':\n\t\t\t\treturn l10n.t('Merge Paused');\n\t\t\tcase 'rebase':\n\t\t\t\treturn l10n.t('Rebase Paused');\n\t\t\tcase 'revert':\n\t\t\t\treturn l10n.t('Revert Paused');\n\t\t}\n\t}\n\t// The shared `pending` string trails a preposition for callers that append a ref inline (the tree\n\t// view). The bar's refs can shed, so it carries that \"of\" inside the refs group instead.\n\tif (variant === 'pending' && status.type === 'rebase') return l10n.t('Pending Rebase');\n\n\treturn strings.label;\n}\n"],"mappings":";;AAmBA,MAAa,qCAQT;CACH,eAAe;EACd,IAAI,OAAO;GACV,OAAO,KAAK,EAAE,aAAa;EAC5B;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,aAAa;EAC5B;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,gBAAgB;EAC/B;EACA,IAAI,YAAY;GACf,OAAO,KAAK,EAAE,8CAA8C;EAC7D;EACA,gBAAgB;CACjB;CACA,OAAO;EACN,IAAI,OAAO;GACV,OAAO,KAAK,EAAE,OAAO;EACtB;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,OAAO;EACtB;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,SAAS;EACxB;EACA,IAAI,YAAY;GACf,OAAO,KAAK,EAAE,uCAAuC;EACtD;EACA,gBAAgB;CACjB;CACA,QAAQ;EACP,IAAI,OAAO;GACV,OAAO,KAAK,EAAE,QAAQ;EACvB;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,QAAQ;EACvB;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,UAAU;EACzB;EACA,IAAI,YAAY;GACf,OAAO,KAAK,EAAE,wCAAwC;EACvD;EACA,gBAAgB;EAChB,SAAS;CACV;CACA,QAAQ;EACP,IAAI,OAAO;GACV,OAAO,KAAK,EAAE,QAAQ;EACvB;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,QAAQ;EACvB;EACA,IAAI,QAAQ;GACX,OAAO,KAAK,EAAE,WAAW;EAC1B;EACA,IAAI,YAAY;GACf,OAAO,KAAK,EAAE,yCAAyC;EACxD;EACA,gBAAgB;CACjB;AACD;AAIA,MAAa,8BAAgF,OAAO,OAAO;CAC1G,WAAW;CACX,SAAS;CACT,OAAO;AACR,CAAC;;AAGD,SAAgB,0BACf,QACA,cACyB;CACzB,IAAI,cAAc,OAAO;CACzB,IAAI,OAAO,SAAS,YAAY,OAAO,OAAO,UAAU,GAAG,OAAO;CAClE,OAAO;AACR;;;;AAKA,SAAgB,wBAAwB,QAA+B,SAAyC;CAC/G,MAAM,UAAU,mCAAmC,OAAO;CAE1D,IAAI,YAAY,aACf,QAAQ,OAAO,MAAf;EACC,KAAK,eACJ,OAAO,KAAK,EAAE,oBAAoB;EACnC,KAAK,SACJ,OAAO,KAAK,EAAE,cAAc;EAC7B,KAAK,UACJ,OAAO,KAAK,EAAE,eAAe;EAC9B,KAAK,UACJ,OAAO,KAAK,EAAE,eAAe;CAC/B;CAID,IAAI,YAAY,aAAa,OAAO,SAAS,UAAU,OAAO,KAAK,EAAE,gBAAgB;CAErF,OAAO,QAAQ;AAChB"}
@@ -1,6 +1,7 @@
1
1
  //#region ../utils/src/plural.d.ts
2
2
  /** Sets the UI locale used to categorize counts. `undefined` resets to the default (see {@link getPluralCategory}). */
3
3
  export declare function setPluralLocale(locale: string | undefined): void;
4
+ export declare function getPluralLocale(): string | undefined;
4
5
  /**
5
6
  * Returns the CLDR plural category for `count` in the current UI locale. Until {@link setPluralLocale} is
6
7
  * called, the document language is used when there is a document (a host that only configures