@pairdraw/core 0.22.1 → 0.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/providers.d.ts +1 -1
- package/dist/ai/providers.d.ts.map +1 -1
- package/dist/ai/providers.js +12 -0
- package/dist/ai/providers.js.map +1 -1
- package/dist/canvas/images/previews.d.ts +1 -1
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/overlays/presence.d.ts +16 -1
- package/dist/canvas/overlays/presence.d.ts.map +1 -1
- package/dist/canvas/overlays/presence.js +90 -3
- package/dist/canvas/overlays/presence.js.map +1 -1
- package/dist/canvas/renderer/picture.d.ts +4 -1
- package/dist/canvas/renderer/picture.d.ts.map +1 -1
- package/dist/canvas/renderer/picture.js +13 -1
- package/dist/canvas/renderer/picture.js.map +1 -1
- package/dist/canvas/renderer/transient-previews.d.ts +9 -1
- package/dist/canvas/renderer/transient-previews.d.ts.map +1 -1
- package/dist/canvas/renderer/transient-previews.js +29 -3
- package/dist/canvas/renderer/transient-previews.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +11 -0
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +1 -1
- package/dist/design-jsx/preview/picture.d.ts +4 -0
- package/dist/design-jsx/preview/picture.d.ts.map +1 -1
- package/dist/design-jsx/preview/picture.js +13 -1
- package/dist/design-jsx/preview/picture.js.map +1 -1
- package/dist/design-jsx/preview/stage.d.ts +2 -0
- package/dist/design-jsx/preview/stage.d.ts.map +1 -1
- package/dist/design-jsx/preview/stage.js +11 -2
- package/dist/design-jsx/preview/stage.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/create.d.ts +1 -1
- package/dist/figma-api/reactions.d.ts +4 -4
- package/dist/io/formats/design-tokens/apply.d.ts +1 -1
- package/package.json +9 -9
- package/src/ai/providers.ts +10 -1
- package/src/canvas/index.ts +1 -0
- package/src/canvas/overlays/presence.ts +114 -13
- package/src/canvas/renderer/picture.ts +17 -0
- package/src/canvas/renderer/transient-previews.ts +38 -4
- package/src/canvas/renderer/types.ts +8 -0
- package/src/design-jsx/preview/picture.ts +27 -1
- package/src/design-jsx/preview/stage.ts +11 -3
package/dist/ai/providers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/ai/providers.d.ts
|
|
2
2
|
/** ACP agents, direct AI providers, and the models each provider recommends. */
|
|
3
|
-
type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli' | 'omp';
|
|
3
|
+
type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli' | 'agy' | 'omp';
|
|
4
4
|
interface ACPAgentDef {
|
|
5
5
|
id: ACPAgentID;
|
|
6
6
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","names":[],"sources":["../../src/ai/providers.ts"],"mappings":";;KAIY;UAEK;EACf,IAAI;EACJ;EACA;EACA;;EAEA;;EAEA;;EAEA;EACA;;;;;;EAMA;IAAW;IAAY;;IAAqB;IAAiB;IAAgB;;;;;;EAK7E;;cAGW,YAAY;
|
|
1
|
+
{"version":3,"file":"providers.d.ts","names":[],"sources":["../../src/ai/providers.ts"],"mappings":";;KAIY;UAEK;EACf,IAAI;EACJ;EACA;EACA;;EAEA;;EAEA;;EAEA;EACA;;;;;;EAMA;IAAW;IAAY;;IAAqB;IAAiB;IAAgB;;;;;;EAK7E;;cAGW,YAAY;KAuDb,oVAuBD;cAEE;KACD,0BAA0B;UAErB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA,qBAAqB;;EAErB;IAAY;IAAsB;IAAuB;;;UAG1C;EACf,IAAI;EACJ;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;;EAEA;;cAmDW;cAEA,cAAc;cAoSd,qBAAqB;cACrB"}
|
package/dist/ai/providers.js
CHANGED
|
@@ -44,6 +44,18 @@ const ACP_AGENTS = [
|
|
|
44
44
|
setupURL: "https://geminicli.com/docs/get-started/installation/",
|
|
45
45
|
installCommand: "npm i -g @google/gemini-cli"
|
|
46
46
|
},
|
|
47
|
+
{
|
|
48
|
+
id: "agy",
|
|
49
|
+
name: "agy",
|
|
50
|
+
command: "agy",
|
|
51
|
+
args: ["acp"],
|
|
52
|
+
setupURL: "https://antigravity.google/docs/cli/overview",
|
|
53
|
+
installCommand: "curl -fsSL https://antigravity.google/cli/install.sh | bash",
|
|
54
|
+
signIn: {
|
|
55
|
+
via: "acp",
|
|
56
|
+
method: "oauth-personal"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
47
59
|
{
|
|
48
60
|
id: "omp",
|
|
49
61
|
name: "omp",
|
package/dist/ai/providers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","names":[],"sources":["../../src/ai/providers.ts"],"sourcesContent":["/** ACP agents, direct AI providers, and the models each provider recommends. */\n\nimport { OPENAI_COMPATIBLE_PRESETS } from './presets'\n\nexport type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli' | 'omp'\n\nexport interface ACPAgentDef {\n id: ACPAgentID\n name: string\n command: string\n args: string[]\n /** The agent's own CLI, when the ACP program is a separate adapter for it. */\n cliCommand?: string\n /** npm package that provides `command` when it is an adapter. */\n adapterPackage?: string\n /** The vendor's installation guide for the agent itself. */\n setupURL?: string\n installCommand?: string\n /**\n * The ACP auth method setup signs in with, once the agent offers it. `acp` methods run inside\n * the agent through `authenticate`; `terminal` methods run the agent's command with `args`,\n * which the desktop shell scope pins under `<command>-sign-in`.\n */\n signIn?: { via: 'acp'; method: string } | { via: 'terminal'; method: string; args: string[] }\n /**\n * The agent runs on the providers and keys already set up in its own configuration and has no\n * account to sign in to, so setup shows no sign-in step.\n */\n ownCredentials?: boolean\n}\n\nexport const ACP_AGENTS: ACPAgentDef[] = [\n {\n id: 'claude-code',\n name: 'Claude Code',\n command: 'claude-agent-acp',\n args: [],\n cliCommand: 'claude',\n adapterPackage: '@agentclientprotocol/claude-agent-acp',\n setupURL: 'https://code.claude.com/docs/en/setup',\n installCommand: 'npm i -g @agentclientprotocol/claude-agent-acp',\n signIn: {\n via: 'terminal',\n method: 'claude-ai-login',\n args: ['--cli', 'auth', 'login', '--claudeai']\n }\n },\n {\n id: 'codex',\n name: 'Codex',\n command: 'codex-acp',\n args: [],\n cliCommand: 'codex',\n adapterPackage: '@agentclientprotocol/codex-acp',\n setupURL: 'https://developers.openai.com/codex/cli',\n installCommand: 'npm i -g @agentclientprotocol/codex-acp',\n signIn: { via: 'acp', method: 'chat-gpt' }\n },\n {\n id: 'gemini-cli',\n name: 'Gemini CLI',\n command: 'gemini',\n args: ['--acp'],\n setupURL: 'https://geminicli.com/docs/get-started/installation/',\n installCommand: 'npm i -g @google/gemini-cli'\n },\n {\n id: 'omp',\n name: 'omp',\n command: 'omp',\n args: ['acp'],\n setupURL: 'https://omp.sh',\n installCommand: 'bun i -g @oh-my-pi/pi-coding-agent',\n ownCredentials: true\n }\n]\n\nexport type AIProviderID =\n | 'openrouter'\n | 'anthropic'\n | 'openai'\n | 'chatgpt'\n | 'google'\n | 'deepseek'\n | 'openai-compatible'\n | 'zai'\n | 'minimax'\n | 'xai'\n | 'meta'\n | 'kimi-for-coding'\n | 'moonshot'\n | 'together'\n | 'fireworks'\n | 'opencode-zen'\n | 'opencode-go'\n | 'anthropic-compatible'\n | 'amazon-bedrock'\n | 'google-vertex'\n | 'pairdraw'\n | 'harness:pi'\n | `acp:${ACPAgentID}`\n\nexport const REASONING_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh'] as const\nexport type ReasoningEffort = (typeof REASONING_EFFORTS)[number]\n\nexport interface ModelOption {\n id: string\n name: string\n tag?: string\n capabilities?: readonly ('tools' | 'vision')[]\n recommendedMaxOutputTokens?: number\n releaseDate?: string\n status?: 'active' | 'beta' | 'deprecated'\n /** Lowest reasoning effort the model accepts; lower thinking levels, Off included, use it. */\n minReasoningEffort?: ReasoningEffort\n /** List price in US dollars per million tokens, when the catalog knows it; absent otherwise. */\n pricing?: { inputPerMTok: number; outputPerMTok: number; cacheReadPerMTok?: number }\n}\n\nexport interface AIProviderDef {\n id: AIProviderID\n name: string\n keyPlaceholder: string\n keyURL: string\n models: ModelOption[]\n defaultModel: string\n supportsCustomBaseURL?: boolean\n supportsCustomModel?: boolean\n /** The credential comes from signing in to an account; there is no key to paste. */\n signInOnly?: boolean\n}\n\nconst OPENAI_MODELS: ModelOption[] = [\n {\n id: 'gpt-6.1-sol',\n name: 'GPT-6.1 Sol',\n tag: 'Best',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'gpt-6-astra',\n name: 'GPT-6 Astra',\n tag: 'Smartest',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n { id: 'gpt-6-luna', name: 'GPT-6 Luna', tag: 'Fast', capabilities: ['tools', 'vision'] }\n]\n\n/** Claude on a cloud platform: the same models under the platform's own IDs. */\nfunction claudeModels(prefix: string): ModelOption[] {\n return [\n {\n id: `${prefix}claude-sonnet-5-5`,\n name: 'Claude Sonnet 5.5',\n tag: 'Best for design',\n capabilities: ['tools', 'vision']\n },\n {\n id: `${prefix}claude-opus-5-5`,\n name: 'Claude Opus 5.5',\n tag: 'Deep reasoning',\n capabilities: ['tools', 'vision']\n },\n {\n id: `${prefix}claude-fable-5-1`,\n name: 'Claude Fable 5.1',\n tag: 'Most capable',\n capabilities: ['tools', 'vision']\n },\n {\n id: `${prefix}claude-haiku-5-5`,\n name: 'Claude Haiku 5.5',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n }\n ]\n}\n\nexport const HARNESS_PROVIDER_ID = 'harness:pi' as const\n\nexport const AI_PROVIDERS: AIProviderDef[] = [\n {\n id: HARNESS_PROVIDER_ID,\n name: 'Pi',\n keyPlaceholder: 'AI Gateway key (optional)',\n keyURL: '',\n defaultModel: '',\n supportsCustomModel: true,\n models: []\n },\n {\n id: 'openrouter',\n name: 'OpenRouter',\n keyPlaceholder: 'sk-or-…',\n keyURL: 'https://openrouter.ai/keys',\n defaultModel: 'anthropic/claude-sonnet-5.5',\n supportsCustomModel: true,\n models: [\n {\n id: 'anthropic/claude-sonnet-5.5',\n name: 'Claude Sonnet 5.5',\n tag: 'Best for design',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'anthropic/claude-opus-5.5',\n name: 'Claude Opus 5.5',\n tag: 'Deep reasoning',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'anthropic/claude-fable-5.1',\n name: 'Claude Fable 5.1',\n tag: 'Most capable',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'anthropic/claude-haiku-5.5',\n name: 'Claude Haiku 5.5',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'openai/gpt-6.1-sol',\n name: 'GPT-6.1 Sol',\n tag: 'Latest OpenAI',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'google/gemini-3.8-flash',\n name: 'Gemini 3.8 Flash',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n },\n { id: 'z-ai/glm-5.3', name: 'GLM-5.3', capabilities: ['tools'] },\n {\n id: 'deepseek/deepseek-v4-pro',\n name: 'DeepSeek V4 Pro',\n tag: 'Reasoning',\n capabilities: ['tools']\n },\n {\n id: 'moonshotai/kimi-k3',\n name: 'Kimi K3',\n tag: 'Vision + code',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'minimax/minimax-m3.1-flash:free',\n name: 'MiniMax-M3.1-Flash',\n tag: 'Free',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'google/gemma-4-31b-it:free',\n name: 'Gemma 4 31B',\n tag: 'Free',\n capabilities: ['tools', 'vision']\n }\n ]\n },\n {\n id: 'anthropic',\n name: 'Anthropic',\n keyPlaceholder: 'sk-ant-…',\n keyURL: 'https://console.anthropic.com/settings/keys',\n defaultModel: 'claude-sonnet-5-5',\n models: [\n {\n id: 'claude-sonnet-5-5',\n name: 'Claude Sonnet 5.5',\n tag: 'Best for design',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'claude-opus-5-5',\n name: 'Claude Opus 5.5',\n tag: 'Deep reasoning',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'claude-fable-5-1',\n name: 'Claude Fable 5.1',\n tag: 'Most capable',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'claude-haiku-5-5',\n name: 'Claude Haiku 5.5',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n }\n ]\n },\n {\n id: 'openai',\n name: 'OpenAI',\n keyPlaceholder: 'sk-…',\n keyURL: 'https://platform.openai.com/api-keys',\n defaultModel: 'gpt-6.1-sol',\n models: OPENAI_MODELS\n },\n {\n id: 'chatgpt',\n name: 'ChatGPT',\n keyPlaceholder: '',\n keyURL: '',\n defaultModel: 'gpt-6.1-sol',\n signInOnly: true,\n // The Codex backend rejects minimal effort on every model.\n models: OPENAI_MODELS.map((model) => ({ ...model, minReasoningEffort: 'low' }))\n },\n {\n id: 'google',\n name: 'Google AI',\n keyPlaceholder: 'AIza…',\n keyURL: 'https://aistudio.google.com/apikey',\n defaultModel: 'gemini-3.8-flash',\n models: [\n {\n id: 'gemini-3.8-flash',\n name: 'Gemini 3.8 Flash',\n tag: 'Best',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'gemini-4-argon',\n name: 'Gemini 4 Argon',\n tag: 'Most capable',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'gemini-flash-latest',\n name: 'Gemini Flash Latest',\n tag: 'Alias',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'gemini-3.1-pro-preview',\n name: 'Gemini 3.1 Pro',\n tag: 'Pro',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n }\n ]\n },\n {\n id: 'deepseek',\n name: 'DeepSeek',\n keyPlaceholder: 'sk-…',\n keyURL: 'https://platform.deepseek.com/api_keys',\n defaultModel: 'deepseek-flash',\n models: [\n { id: 'deepseek-flash', name: 'DeepSeek Flash', tag: 'Fast' },\n { id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro', tag: 'Reasoning' }\n ]\n },\n {\n id: 'zai',\n name: 'Z.ai',\n keyPlaceholder: 'API key',\n keyURL: 'https://docs.z.ai/devpack/quick-start',\n defaultModel: 'glm-5.3',\n models: [\n { id: 'glm-5.3', name: 'GLM-5.3', tag: 'Best', minReasoningEffort: 'low' },\n {\n id: 'glm-5.3-flash',\n name: 'GLM-5.3-Flash',\n tag: 'Fast',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'glm-5.3-flashx',\n name: 'GLM-5.3-FlashX',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'glm-5v-turbo',\n name: 'GLM-5V-Turbo',\n tag: 'Vision',\n capabilities: ['tools', 'vision']\n },\n { id: 'glm-5.2', name: 'GLM-5.2' },\n { id: 'glm-4.7-flash', name: 'GLM-4.7-Flash', tag: 'Free' }\n ]\n },\n {\n id: 'minimax',\n name: 'MiniMax',\n keyPlaceholder: 'API key',\n keyURL: 'https://platform.minimax.io/user-center/basic-information/interface-key',\n defaultModel: 'MiniMax-M3.1-Flash',\n models: [\n {\n id: 'MiniMax-M3.1-Flash',\n name: 'MiniMax-M3.1-Flash',\n tag: 'Best',\n minReasoningEffort: 'low'\n },\n { id: 'MiniMax-M3', name: 'MiniMax-M3' }\n ]\n },\n ...OPENAI_COMPATIBLE_PRESETS,\n {\n id: 'openai-compatible',\n name: 'OpenAI-compatible',\n keyPlaceholder: 'API key',\n keyURL: '',\n defaultModel: '',\n models: [],\n supportsCustomBaseURL: true,\n supportsCustomModel: true\n },\n {\n id: 'anthropic-compatible',\n name: 'Anthropic-compatible',\n keyPlaceholder: 'API key',\n keyURL: '',\n defaultModel: '',\n models: [],\n supportsCustomBaseURL: true,\n supportsCustomModel: true\n },\n {\n // Claude in Amazon Bedrock: the Messages API at `bedrock-mantle.<region>.api.aws`, reached\n // with a Bedrock API key or AWS access keys. The connection's base URL holds the region.\n id: 'amazon-bedrock',\n name: 'Amazon Bedrock',\n keyPlaceholder: 'ABSK… / bedrock-api-key-…',\n keyURL: 'https://console.aws.amazon.com/bedrock/home#/api-keys',\n defaultModel: 'anthropic.claude-sonnet-5-5',\n supportsCustomModel: true,\n models: claudeModels('anthropic.')\n },\n {\n // Vertex AI serves Claude through `:rawPredict` and Gemini through `:generateContent`. The\n // connection's base URL holds the project and location.\n id: 'google-vertex',\n name: 'Google Vertex AI',\n keyPlaceholder: 'ya29.… / AIza…',\n keyURL: 'https://console.cloud.google.com/vertex-ai',\n defaultModel: 'claude-sonnet-5-5',\n supportsCustomModel: true,\n models: [\n ...claudeModels(''),\n {\n id: 'gemini-3.8-flash',\n name: 'Gemini 3.8 Flash',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'gemini-4-argon',\n name: 'Gemini 4 Argon',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n }\n ]\n },\n {\n id: 'pairdraw',\n name: 'Pairdraw Cloud',\n keyPlaceholder: '',\n keyURL: '',\n defaultModel: '',\n models: []\n }\n]\n\nexport const DEFAULT_AI_PROVIDER: AIProviderID = 'openai-compatible'\nexport const DEFAULT_AI_MODEL =\n AI_PROVIDERS.find((provider) => provider.id === DEFAULT_AI_PROVIDER)?.defaultModel ?? ''\n"],"mappings":";;;AA+BA,MAAa,aAA4B;CACvC;EACE,IAAI;EACJ,MAAM;EACN,SAAS;EACT,MAAM,CAAC;EACP,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,gBAAgB;EAChB,QAAQ;GACN,KAAK;GACL,QAAQ;GACR,MAAM;IAAC;IAAS;IAAQ;IAAS;GAAY;EAC/C;CACF;CACA;EACE,IAAI;EACJ,MAAM;EACN,SAAS;EACT,MAAM,CAAC;EACP,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,gBAAgB;EAChB,QAAQ;GAAE,KAAK;GAAO,QAAQ;EAAW;CAC3C;CACA;EACE,IAAI;EACJ,MAAM;EACN,S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;EAChB,QAAQ;EACR,cAAc;EACd,QAAQ,CACN;GACE,IAAI;GACJ,MAAM;GACN,KAAK;GACL,oBAAoB;EACtB,GACA;GAAE,IAAI;GAAc,MAAM;EAAa,CACzC;CACF;CACA,GAAG;CACH;EACE,IAAI;EACJ,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,QAAQ,CAAC;EACT,uBAAuB;EACvB,qBAAqB;CACvB;CACA;EACE,IAAI;EACJ,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,QAAQ,CAAC;EACT,uBAAuB;EACvB,qBAAqB;CACvB;CACA;EAGE,IAAI;EACJ,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,qBAAqB;EACrB,QAAQ,aAAa,YAAY;CACnC;CACA;EAGE,IAAI;EACJ,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,qBAAqB;EACrB,QAAQ;GACN,GAAG,aAAa,EAAE;GAClB;IACE,IAAI;IACJ,MAAM;IACN,KAAK;IACL,cAAc,CAAC,SAAS,QAAQ;GAClC;GACA;IACE,IAAI;IACJ,MAAM;IACN,cAAc,CAAC,SAAS,QAAQ;IAChC,oBAAoB;GACtB;EACF;CACF;CACA;EACE,IAAI;EACJ,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,QAAQ,CAAC;CACX;AACF;AAEA,MAAa,sBAAoC;AACjD,MAAa,mBACX,aAAa,MAAM,aAAa,SAAS,OAAA,mBAA0B,CAAC,EAAE,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"providers.js","names":[],"sources":["../../src/ai/providers.ts"],"sourcesContent":["/** ACP agents, direct AI providers, and the models each provider recommends. */\n\nimport { OPENAI_COMPATIBLE_PRESETS } from './presets'\n\nexport type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli' | 'agy' | 'omp'\n\nexport interface ACPAgentDef {\n id: ACPAgentID\n name: string\n command: string\n args: string[]\n /** The agent's own CLI, when the ACP program is a separate adapter for it. */\n cliCommand?: string\n /** npm package that provides `command` when it is an adapter. */\n adapterPackage?: string\n /** The vendor's installation guide for the agent itself. */\n setupURL?: string\n installCommand?: string\n /**\n * The ACP auth method setup signs in with, once the agent offers it. `acp` methods run inside\n * the agent through `authenticate`; `terminal` methods run the agent's command with `args`,\n * which the desktop shell scope pins under `<command>-sign-in`.\n */\n signIn?: { via: 'acp'; method: string } | { via: 'terminal'; method: string; args: string[] }\n /**\n * The agent runs on the providers and keys already set up in its own configuration and has no\n * account to sign in to, so setup shows no sign-in step.\n */\n ownCredentials?: boolean\n}\n\nexport const ACP_AGENTS: ACPAgentDef[] = [\n {\n id: 'claude-code',\n name: 'Claude Code',\n command: 'claude-agent-acp',\n args: [],\n cliCommand: 'claude',\n adapterPackage: '@agentclientprotocol/claude-agent-acp',\n setupURL: 'https://code.claude.com/docs/en/setup',\n installCommand: 'npm i -g @agentclientprotocol/claude-agent-acp',\n signIn: {\n via: 'terminal',\n method: 'claude-ai-login',\n args: ['--cli', 'auth', 'login', '--claudeai']\n }\n },\n {\n id: 'codex',\n name: 'Codex',\n command: 'codex-acp',\n args: [],\n cliCommand: 'codex',\n adapterPackage: '@agentclientprotocol/codex-acp',\n setupURL: 'https://developers.openai.com/codex/cli',\n installCommand: 'npm i -g @agentclientprotocol/codex-acp',\n signIn: { via: 'acp', method: 'chat-gpt' }\n },\n {\n id: 'gemini-cli',\n name: 'Gemini CLI',\n command: 'gemini',\n args: ['--acp'],\n setupURL: 'https://geminicli.com/docs/get-started/installation/',\n installCommand: 'npm i -g @google/gemini-cli'\n },\n {\n id: 'agy',\n name: 'agy',\n command: 'agy',\n args: ['acp'],\n setupURL: 'https://antigravity.google/docs/cli/overview',\n installCommand: 'curl -fsSL https://antigravity.google/cli/install.sh | bash',\n signIn: { via: 'acp', method: 'oauth-personal' }\n },\n {\n id: 'omp',\n name: 'omp',\n command: 'omp',\n args: ['acp'],\n setupURL: 'https://omp.sh',\n installCommand: 'bun i -g @oh-my-pi/pi-coding-agent',\n ownCredentials: true\n }\n]\n\nexport type AIProviderID =\n | 'openrouter'\n | 'anthropic'\n | 'openai'\n | 'chatgpt'\n | 'google'\n | 'deepseek'\n | 'openai-compatible'\n | 'zai'\n | 'minimax'\n | 'xai'\n | 'meta'\n | 'kimi-for-coding'\n | 'moonshot'\n | 'together'\n | 'fireworks'\n | 'opencode-zen'\n | 'opencode-go'\n | 'anthropic-compatible'\n | 'amazon-bedrock'\n | 'google-vertex'\n | 'pairdraw'\n | 'harness:pi'\n | `acp:${ACPAgentID}`\n\nexport const REASONING_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh'] as const\nexport type ReasoningEffort = (typeof REASONING_EFFORTS)[number]\n\nexport interface ModelOption {\n id: string\n name: string\n tag?: string\n capabilities?: readonly ('tools' | 'vision')[]\n recommendedMaxOutputTokens?: number\n releaseDate?: string\n status?: 'active' | 'beta' | 'deprecated'\n /** Lowest reasoning effort the model accepts; lower thinking levels, Off included, use it. */\n minReasoningEffort?: ReasoningEffort\n /** List price in US dollars per million tokens, when the catalog knows it; absent otherwise. */\n pricing?: { inputPerMTok: number; outputPerMTok: number; cacheReadPerMTok?: number }\n}\n\nexport interface AIProviderDef {\n id: AIProviderID\n name: string\n keyPlaceholder: string\n keyURL: string\n models: ModelOption[]\n defaultModel: string\n supportsCustomBaseURL?: boolean\n supportsCustomModel?: boolean\n /** The credential comes from signing in to an account; there is no key to paste. */\n signInOnly?: boolean\n}\n\nconst OPENAI_MODELS: ModelOption[] = [\n {\n id: 'gpt-6.1-sol',\n name: 'GPT-6.1 Sol',\n tag: 'Best',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'gpt-6-astra',\n name: 'GPT-6 Astra',\n tag: 'Smartest',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n { id: 'gpt-6-luna', name: 'GPT-6 Luna', tag: 'Fast', capabilities: ['tools', 'vision'] }\n]\n\n/** Claude on a cloud platform: the same models under the platform's own IDs. */\nfunction claudeModels(prefix: string): ModelOption[] {\n return [\n {\n id: `${prefix}claude-sonnet-5-5`,\n name: 'Claude Sonnet 5.5',\n tag: 'Best for design',\n capabilities: ['tools', 'vision']\n },\n {\n id: `${prefix}claude-opus-5-5`,\n name: 'Claude Opus 5.5',\n tag: 'Deep reasoning',\n capabilities: ['tools', 'vision']\n },\n {\n id: `${prefix}claude-fable-5-1`,\n name: 'Claude Fable 5.1',\n tag: 'Most capable',\n capabilities: ['tools', 'vision']\n },\n {\n id: `${prefix}claude-haiku-5-5`,\n name: 'Claude Haiku 5.5',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n }\n ]\n}\n\nexport const HARNESS_PROVIDER_ID = 'harness:pi' as const\n\nexport const AI_PROVIDERS: AIProviderDef[] = [\n {\n id: HARNESS_PROVIDER_ID,\n name: 'Pi',\n keyPlaceholder: 'AI Gateway key (optional)',\n keyURL: '',\n defaultModel: '',\n supportsCustomModel: true,\n models: []\n },\n {\n id: 'openrouter',\n name: 'OpenRouter',\n keyPlaceholder: 'sk-or-…',\n keyURL: 'https://openrouter.ai/keys',\n defaultModel: 'anthropic/claude-sonnet-5.5',\n supportsCustomModel: true,\n models: [\n {\n id: 'anthropic/claude-sonnet-5.5',\n name: 'Claude Sonnet 5.5',\n tag: 'Best for design',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'anthropic/claude-opus-5.5',\n name: 'Claude Opus 5.5',\n tag: 'Deep reasoning',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'anthropic/claude-fable-5.1',\n name: 'Claude Fable 5.1',\n tag: 'Most capable',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'anthropic/claude-haiku-5.5',\n name: 'Claude Haiku 5.5',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'openai/gpt-6.1-sol',\n name: 'GPT-6.1 Sol',\n tag: 'Latest OpenAI',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'google/gemini-3.8-flash',\n name: 'Gemini 3.8 Flash',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n },\n { id: 'z-ai/glm-5.3', name: 'GLM-5.3', capabilities: ['tools'] },\n {\n id: 'deepseek/deepseek-v4-pro',\n name: 'DeepSeek V4 Pro',\n tag: 'Reasoning',\n capabilities: ['tools']\n },\n {\n id: 'moonshotai/kimi-k3',\n name: 'Kimi K3',\n tag: 'Vision + code',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'minimax/minimax-m3.1-flash:free',\n name: 'MiniMax-M3.1-Flash',\n tag: 'Free',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'google/gemma-4-31b-it:free',\n name: 'Gemma 4 31B',\n tag: 'Free',\n capabilities: ['tools', 'vision']\n }\n ]\n },\n {\n id: 'anthropic',\n name: 'Anthropic',\n keyPlaceholder: 'sk-ant-…',\n keyURL: 'https://console.anthropic.com/settings/keys',\n defaultModel: 'claude-sonnet-5-5',\n models: [\n {\n id: 'claude-sonnet-5-5',\n name: 'Claude Sonnet 5.5',\n tag: 'Best for design',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'claude-opus-5-5',\n name: 'Claude Opus 5.5',\n tag: 'Deep reasoning',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'claude-fable-5-1',\n name: 'Claude Fable 5.1',\n tag: 'Most capable',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'claude-haiku-5-5',\n name: 'Claude Haiku 5.5',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n }\n ]\n },\n {\n id: 'openai',\n name: 'OpenAI',\n keyPlaceholder: 'sk-…',\n keyURL: 'https://platform.openai.com/api-keys',\n defaultModel: 'gpt-6.1-sol',\n models: OPENAI_MODELS\n },\n {\n id: 'chatgpt',\n name: 'ChatGPT',\n keyPlaceholder: '',\n keyURL: '',\n defaultModel: 'gpt-6.1-sol',\n signInOnly: true,\n // The Codex backend rejects minimal effort on every model.\n models: OPENAI_MODELS.map((model) => ({ ...model, minReasoningEffort: 'low' }))\n },\n {\n id: 'google',\n name: 'Google AI',\n keyPlaceholder: 'AIza…',\n keyURL: 'https://aistudio.google.com/apikey',\n defaultModel: 'gemini-3.8-flash',\n models: [\n {\n id: 'gemini-3.8-flash',\n name: 'Gemini 3.8 Flash',\n tag: 'Best',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'gemini-4-argon',\n name: 'Gemini 4 Argon',\n tag: 'Most capable',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'gemini-flash-latest',\n name: 'Gemini Flash Latest',\n tag: 'Alias',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'gemini-3.1-pro-preview',\n name: 'Gemini 3.1 Pro',\n tag: 'Pro',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n }\n ]\n },\n {\n id: 'deepseek',\n name: 'DeepSeek',\n keyPlaceholder: 'sk-…',\n keyURL: 'https://platform.deepseek.com/api_keys',\n defaultModel: 'deepseek-flash',\n models: [\n { id: 'deepseek-flash', name: 'DeepSeek Flash', tag: 'Fast' },\n { id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro', tag: 'Reasoning' }\n ]\n },\n {\n id: 'zai',\n name: 'Z.ai',\n keyPlaceholder: 'API key',\n keyURL: 'https://docs.z.ai/devpack/quick-start',\n defaultModel: 'glm-5.3',\n models: [\n { id: 'glm-5.3', name: 'GLM-5.3', tag: 'Best', minReasoningEffort: 'low' },\n {\n id: 'glm-5.3-flash',\n name: 'GLM-5.3-Flash',\n tag: 'Fast',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'glm-5.3-flashx',\n name: 'GLM-5.3-FlashX',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n },\n {\n id: 'glm-5v-turbo',\n name: 'GLM-5V-Turbo',\n tag: 'Vision',\n capabilities: ['tools', 'vision']\n },\n { id: 'glm-5.2', name: 'GLM-5.2' },\n { id: 'glm-4.7-flash', name: 'GLM-4.7-Flash', tag: 'Free' }\n ]\n },\n {\n id: 'minimax',\n name: 'MiniMax',\n keyPlaceholder: 'API key',\n keyURL: 'https://platform.minimax.io/user-center/basic-information/interface-key',\n defaultModel: 'MiniMax-M3.1-Flash',\n models: [\n {\n id: 'MiniMax-M3.1-Flash',\n name: 'MiniMax-M3.1-Flash',\n tag: 'Best',\n minReasoningEffort: 'low'\n },\n { id: 'MiniMax-M3', name: 'MiniMax-M3' }\n ]\n },\n ...OPENAI_COMPATIBLE_PRESETS,\n {\n id: 'openai-compatible',\n name: 'OpenAI-compatible',\n keyPlaceholder: 'API key',\n keyURL: '',\n defaultModel: '',\n models: [],\n supportsCustomBaseURL: true,\n supportsCustomModel: true\n },\n {\n id: 'anthropic-compatible',\n name: 'Anthropic-compatible',\n keyPlaceholder: 'API key',\n keyURL: '',\n defaultModel: '',\n models: [],\n supportsCustomBaseURL: true,\n supportsCustomModel: true\n },\n {\n // Claude in Amazon Bedrock: the Messages API at `bedrock-mantle.<region>.api.aws`, reached\n // with a Bedrock API key or AWS access keys. The connection's base URL holds the region.\n id: 'amazon-bedrock',\n name: 'Amazon Bedrock',\n keyPlaceholder: 'ABSK… / bedrock-api-key-…',\n keyURL: 'https://console.aws.amazon.com/bedrock/home#/api-keys',\n defaultModel: 'anthropic.claude-sonnet-5-5',\n supportsCustomModel: true,\n models: claudeModels('anthropic.')\n },\n {\n // Vertex AI serves Claude through `:rawPredict` and Gemini through `:generateContent`. The\n // connection's base URL holds the project and location.\n id: 'google-vertex',\n name: 'Google Vertex AI',\n keyPlaceholder: 'ya29.… / AIza…',\n keyURL: 'https://console.cloud.google.com/vertex-ai',\n defaultModel: 'claude-sonnet-5-5',\n supportsCustomModel: true,\n models: [\n ...claudeModels(''),\n {\n id: 'gemini-3.8-flash',\n name: 'Gemini 3.8 Flash',\n tag: 'Fast',\n capabilities: ['tools', 'vision']\n },\n {\n id: 'gemini-4-argon',\n name: 'Gemini 4 Argon',\n capabilities: ['tools', 'vision'],\n minReasoningEffort: 'low'\n }\n ]\n },\n {\n id: 'pairdraw',\n name: 'Pairdraw Cloud',\n keyPlaceholder: '',\n keyURL: '',\n defaultModel: '',\n models: []\n }\n]\n\nexport const DEFAULT_AI_PROVIDER: AIProviderID = 'openai-compatible'\nexport const DEFAULT_AI_MODEL =\n AI_PROVIDERS.find((provider) => provider.id === DEFAULT_AI_PROVIDER)?.defaultModel ?? ''\n"],"mappings":";;;AA+BA,MAAa,aAA4B;CACvC;EACE,IAAI;EACJ,MAAM;EACN,SAAS;EACT,MAAM,CAAC;EACP,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,gBAAgB;EAChB,QAAQ;GACN,KAAK;GACL,QAAQ;GACR,MAAM;IAAC;IAAS;IAAQ;IAAS;GAAY;EAC/C;CACF;CACA;EACE,IAAI;EACJ,MAAM;EACN,SAAS;EACT,MAAM,CAAC;EACP,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,gBAAgB;EAChB,QAAQ;GAAE,KAAK;GAAO,QAAQ;EAAW;CAC3C;CACA;EACE,IAAI;EACJ,MAAM;EACN,SAAS;EACT,MAAM,CAAC,OAAO;EACd,UAAU;EACV,gBAAgB;CAClB;CACA;EACE,IAAI;EACJ,MAAM;EACN,SAAS;EACT,MAAM,CAAC,KAAK;EACZ,UAAU;EACV,gBAAgB;EAChB,QAAQ;GAAE,KAAK;GAAO,QAAQ;EAAiB;CACjD;CACA;EACE,IAAI;EACJ,MAAM;EACN,SAAS;EACT,MAAM,CAAC,KAAK;EACZ,UAAU;EACV,gBAAgB;EAChB,gBAAgB;CAClB;AACF;AA2BA,MAAa,oBAAoB;CAAC;CAAW;CAAO;CAAU;CAAQ;AAAO;AA8B7E,MAAM,gBAA+B;CACnC;EACE,IAAI;EACJ,MAAM;EACN,KAAK;EACL,cAAc,CAAC,SAAS,QAAQ;EAChC,oBAAoB;CACtB;CACA;EACE,IAAI;EACJ,MAAM;EACN,KAAK;EACL,cAAc,CAAC,SAAS,QAAQ;EAChC,oBAAoB;CACt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AChB,QAAQ;EACR,cAAc;EACd,qBAAqB;EACrB,QAAQ,aAAa,YAAY;CACnC;CACA;EAGE,IAAI;EACJ,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,qBAAqB;EACrB,QAAQ;GACN,GAAG,aAAa,EAAE;GAClB;IACE,IAAI;IACJ,MAAM;IACN,KAAK;IACL,cAAc,CAAC,SAAS,QAAQ;GAClC;GACA;IACE,IAAI;IACJ,MAAM;IACN,cAAc,CAAC,SAAS,QAAQ;IAChC,oBAAoB;GACtB;EACF;CACF;CACA;EACE,IAAI;EACJ,MAAM;EACN,gBAAgB;EAChB,QAAQ;EACR,cAAc;EACd,QAAQ,CAAC;CACX;AACF;AAEA,MAAa,sBAAoC;AACjD,MAAa,mBACX,aAAa,MAAM,aAAa,SAAS,OAAA,mBAA0B,CAAC,EAAE,gBAAgB"}
|
|
@@ -5,7 +5,7 @@ import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
|
5
5
|
* images. Kept per document and image count, since the renderer asks on every frame.
|
|
6
6
|
*/
|
|
7
7
|
declare function needsImagePreviews(graph: SceneGraph): boolean;
|
|
8
|
-
declare function previewEdge(node: Pick<SceneNode, 'width' | 'height'>, zoom: number, dpr?: number):
|
|
8
|
+
declare function previewEdge(node: Pick<SceneNode, 'width' | 'height'>, zoom: number, dpr?: number): 256 | 128 | 1024 | 512 | 2048;
|
|
9
9
|
interface ImagePreview {
|
|
10
10
|
bytes: Uint8Array<ArrayBuffer>;
|
|
11
11
|
originalWidth: number;
|
package/dist/canvas/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { VectorFlattenProps, flattenNodesToVectorProps } from "./flatten.js";
|
|
|
6
6
|
import { OutlinePiece, OutlinedLayer, canOutlineStroke, layersToOutline, outlineStrokeLayer } from "./outline-stroke.js";
|
|
7
7
|
import { GuideScreenSegment, GuideViewport, distanceToGuideSegment, getGuideScreenSegment } from "./guides/geometry.js";
|
|
8
8
|
import { computeGuideRedline } from "./guides/redlines.js";
|
|
9
|
+
import { TransientCanvasPreview } from "./renderer/transient-previews.js";
|
|
9
10
|
import { GuideHit, hitTestGuides } from "./guides/hit-test.js";
|
|
10
11
|
import { canvasLabelForeground } from "./labels/color.js";
|
|
11
12
|
import { ImagePreview, ImagePreviewDecoder } from "./images/previews.js";
|
|
@@ -15,4 +16,4 @@ import { withFigExportRuntime } from "./text/shape.js";
|
|
|
15
16
|
import { DrawnFontAxes, DrawnFontAxis, drawnFontAxes } from "./text/font-families.js";
|
|
16
17
|
import { PresenceCursor, RenderOverlays, RenderedPlayScene, RulerTheme, SelectionTheme } from "./renderer/types.js";
|
|
17
18
|
import { SkiaRenderer } from "./renderer.js";
|
|
18
|
-
export { type CachedComponent, type CachedSection, type ColorSpaceContext, type DesignIssueHighlight, type DesignIssueSeverity, type DrawnFontAxes, type DrawnFontAxis, type FloatTargetContext, type GuideHit, type GuideOverlayState, type GuidePreview, type GuideScreenSegment, type GuideSelection, type GuideViewport, type ImagePreview, type ImagePreviewDecoder, LabelCache, type OutlinePiece, type OutlinedLayer, type PlacedStatusLabel, type PresenceCursor, type RenderOverlays, type RenderedPlayScene, type RulerTheme, type SelectionTheme, SkiaRenderer, type VectorFlattenProps, canMakeBooleanSourceNode, canMakeBooleanSourcePath, canOutlineStroke, canvasLabelForeground, computeGuideRedline, distanceToGuideSegment, drawnFontAxes, flattenNodesToVectorProps, getGuideScreenSegment, hasFloatRenderTarget, hitTestGuides, hitTestStatusLabels, isHardwareRenderer, isSoftwareRenderer, layersToOutline, nodeHasVisibleStroke, outlineStrokeLayer, rendererName, supportsFloatRenderTarget, withFigExportRuntime };
|
|
19
|
+
export { type CachedComponent, type CachedSection, type ColorSpaceContext, type DesignIssueHighlight, type DesignIssueSeverity, type DrawnFontAxes, type DrawnFontAxis, type FloatTargetContext, type GuideHit, type GuideOverlayState, type GuidePreview, type GuideScreenSegment, type GuideSelection, type GuideViewport, type ImagePreview, type ImagePreviewDecoder, LabelCache, type OutlinePiece, type OutlinedLayer, type PlacedStatusLabel, type PresenceCursor, type RenderOverlays, type RenderedPlayScene, type RulerTheme, type SelectionTheme, SkiaRenderer, type TransientCanvasPreview, type VectorFlattenProps, canMakeBooleanSourceNode, canMakeBooleanSourcePath, canOutlineStroke, canvasLabelForeground, computeGuideRedline, distanceToGuideSegment, drawnFontAxes, flattenNodesToVectorProps, getGuideScreenSegment, hasFloatRenderTarget, hitTestGuides, hitTestStatusLabels, isHardwareRenderer, isSoftwareRenderer, layersToOutline, nodeHasVisibleStroke, outlineStrokeLayer, rendererName, supportsFloatRenderTarget, withFigExportRuntime };
|
|
@@ -3,8 +3,23 @@ import { SkiaRenderer } from "../renderer.js";
|
|
|
3
3
|
import { Canvas } from "canvaskit-wasm";
|
|
4
4
|
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
5
5
|
//#region src/canvas/overlays/presence.d.ts
|
|
6
|
+
/** What a cursor's focus outline showed, so a newer element fades the old one out. */
|
|
7
|
+
interface FocusTransition {
|
|
8
|
+
current: Rect | null;
|
|
9
|
+
previous: Rect | null;
|
|
10
|
+
/** When the previous outline was replaced. */
|
|
11
|
+
since: number;
|
|
12
|
+
}
|
|
13
|
+
declare const NO_FOCUS: FocusTransition;
|
|
14
|
+
/** Move the outline to `focus`, keeping the one it replaces for its fade. */
|
|
15
|
+
declare function nextFocus(state: FocusTransition, focus: Rect | undefined, now: number): FocusTransition;
|
|
16
|
+
/** The outline to draw now: the current one, pulsing, and the replaced one fading out. */
|
|
17
|
+
declare function focusOutlines(state: FocusTransition, pulse: boolean | undefined, now: number): Array<{
|
|
18
|
+
rect: Rect;
|
|
19
|
+
alpha: number;
|
|
20
|
+
}>;
|
|
6
21
|
/** Cursors of people and agents in screen space, with outlines of what they selected. */
|
|
7
22
|
declare function drawPresenceCursors(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph, cursors?: PresenceCursor[]): void;
|
|
8
23
|
//#endregion
|
|
9
|
-
export { drawPresenceCursors };
|
|
24
|
+
export { FocusTransition, NO_FOCUS, drawPresenceCursors, focusOutlines, nextFocus };
|
|
10
25
|
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presence.d.ts","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"presence.d.ts","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"mappings":";;;;;;UA4BiB;EACf,SAAS;EACT,UAAU;;EAEV;;cAGW,UAAU;;iBAoBP,UACd,OAAO,iBACP,OAAO,kBACP,cACC;;iBAOa,cACd,OAAO,iBACP,4BACA,cACC;EAAQ,MAAM;EAAM;;;iBAiMP,oBACd,GAAG,cACH,QAAQ,QACR,OAAO,YACP,UAAU"}
|
|
@@ -11,15 +11,97 @@ const LABEL_OFFSET_Y = 20;
|
|
|
11
11
|
const LABEL_MAX_WIDTH = 160;
|
|
12
12
|
/** The provider mark before an agent's name, and the gap after it. */
|
|
13
13
|
const LABEL_LOGO_SIZE = 9;
|
|
14
|
+
/** The newest outline's soft pulse, and how long a replaced one takes to fade. */
|
|
15
|
+
const FOCUS_PULSE_MS = 1200;
|
|
16
|
+
const FOCUS_FADE_MS = 200;
|
|
17
|
+
/** One sheen across what a finished preview built. */
|
|
18
|
+
const SHEEN_MS = 400;
|
|
14
19
|
/** Decoded once per logo byte array; the app keeps one array per provider, so this is tiny. */
|
|
15
20
|
const labelLogoImages = /* @__PURE__ */ new WeakMap();
|
|
21
|
+
const NO_FOCUS = {
|
|
22
|
+
current: null,
|
|
23
|
+
previous: null,
|
|
24
|
+
since: 0
|
|
25
|
+
};
|
|
26
|
+
/** Draw a world-space rectangle in the overlay's screen coordinates. */
|
|
27
|
+
function drawWorldRect(r, canvas, rect, paint) {
|
|
28
|
+
canvas.drawRect(r.ck.XYWHRect(rect.x * r.zoom + r.panX, rect.y * r.zoom + r.panY, rect.width * r.zoom, rect.height * r.zoom), paint);
|
|
29
|
+
}
|
|
30
|
+
function sameRect(a, b) {
|
|
31
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
32
|
+
}
|
|
33
|
+
/** Move the outline to `focus`, keeping the one it replaces for its fade. */
|
|
34
|
+
function nextFocus(state, focus, now) {
|
|
35
|
+
if (!focus) return NO_FOCUS;
|
|
36
|
+
if (state.current && sameRect(state.current, focus)) return state;
|
|
37
|
+
return {
|
|
38
|
+
current: focus,
|
|
39
|
+
previous: state.current,
|
|
40
|
+
since: now
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The outline to draw now: the current one, pulsing, and the replaced one fading out. */
|
|
44
|
+
function focusOutlines(state, pulse, now) {
|
|
45
|
+
const outlines = [];
|
|
46
|
+
const age = now - state.since;
|
|
47
|
+
if (pulse && state.previous && age < FOCUS_FADE_MS) outlines.push({
|
|
48
|
+
rect: state.previous,
|
|
49
|
+
alpha: .75 * (1 - age / FOCUS_FADE_MS)
|
|
50
|
+
});
|
|
51
|
+
if (state.current) {
|
|
52
|
+
const alpha = pulse ? .35 + .65 * (.5 + .5 * Math.sin(now / FOCUS_PULSE_MS * 2 * Math.PI)) : .75;
|
|
53
|
+
outlines.push({
|
|
54
|
+
rect: state.current,
|
|
55
|
+
alpha
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return outlines;
|
|
59
|
+
}
|
|
60
|
+
/** Each canvas keeps its own focus transitions, so two documents' agents never collide. */
|
|
61
|
+
const focusHistories = /* @__PURE__ */ new WeakMap();
|
|
62
|
+
function focusHistoryFor(r) {
|
|
63
|
+
const existing = focusHistories.get(r);
|
|
64
|
+
if (existing) return existing;
|
|
65
|
+
const history = /* @__PURE__ */ new Map();
|
|
66
|
+
focusHistories.set(r, history);
|
|
67
|
+
return history;
|
|
68
|
+
}
|
|
69
|
+
/** The element being written, pulsing in the accent color, and the one it replaced fading out. */
|
|
70
|
+
function drawFocus(r, canvas, cursor) {
|
|
71
|
+
if (cursor.kind !== "agent") return;
|
|
72
|
+
const key = cursor.id ?? cursor.name;
|
|
73
|
+
const history = focusHistoryFor(r);
|
|
74
|
+
const now = performance.now();
|
|
75
|
+
const state = nextFocus(history.get(key) ?? NO_FOCUS, cursor.focus, now);
|
|
76
|
+
if (state === NO_FOCUS) history.delete(key);
|
|
77
|
+
else history.set(key, state);
|
|
78
|
+
const { r: red, g, b } = cursor.color;
|
|
79
|
+
r.auxStroke.setStrokeWidth(2);
|
|
80
|
+
r.auxStroke.setPathEffect(null);
|
|
81
|
+
for (const { rect, alpha } of focusOutlines(state, cursor.pulse, now)) {
|
|
82
|
+
if (alpha <= 0) continue;
|
|
83
|
+
r.auxStroke.setColor(r.ck.Color4f(red, g, b, alpha));
|
|
84
|
+
drawWorldRect(r, canvas, rect, r.auxStroke);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** One soft pass of light across what a finished preview built. */
|
|
88
|
+
function drawSheen(r, canvas, cursor) {
|
|
89
|
+
if (!cursor.sheen) return;
|
|
90
|
+
const age = performance.now() - cursor.sheen.at;
|
|
91
|
+
if (age < 0 || age >= SHEEN_MS) return;
|
|
92
|
+
const { rect } = cursor.sheen;
|
|
93
|
+
r.auxFill.setColor(r.ck.Color4f(1, 1, 1, .07 * Math.sin(age / SHEEN_MS * Math.PI)));
|
|
94
|
+
drawWorldRect(r, canvas, rect, r.auxFill);
|
|
95
|
+
}
|
|
16
96
|
function drawSelection(r, canvas, graph, cursor) {
|
|
97
|
+
drawSheen(r, canvas, cursor);
|
|
98
|
+
drawFocus(r, canvas, cursor);
|
|
17
99
|
if (!cursor.selection?.length && !cursor.outline?.length) return;
|
|
18
100
|
const { r: red, g, b } = cursor.color;
|
|
19
101
|
r.auxStroke.setColor(r.ck.Color4f(red, g, b, .6));
|
|
20
102
|
r.auxStroke.setStrokeWidth(1.5);
|
|
21
103
|
r.auxStroke.setPathEffect(null);
|
|
22
|
-
for (const rect of cursor.outline ?? [])
|
|
104
|
+
for (const rect of cursor.outline ?? []) drawWorldRect(r, canvas, rect, r.auxStroke);
|
|
23
105
|
for (const nodeId of cursor.selection ?? []) {
|
|
24
106
|
const node = graph.getNode(nodeId);
|
|
25
107
|
if (!node) continue;
|
|
@@ -88,10 +170,11 @@ function drawLabel(r, canvas, x, y, cursor) {
|
|
|
88
170
|
const agent = cursor.kind === "agent";
|
|
89
171
|
const logo = agent ? labelLogo(r, cursor.logo) : null;
|
|
90
172
|
const badge = logo ? 12 : 0;
|
|
173
|
+
const label = cursor.status ? `${cursor.name} ${cursor.status}` : cursor.name;
|
|
91
174
|
const pillX = x + LABEL_OFFSET_X - LABEL_PADDING_X;
|
|
92
175
|
const pillY = y + LABEL_OFFSET_Y - LABEL_FONT_SIZE - LABEL_PADDING_Y + 2;
|
|
93
176
|
const pillHeight = 14;
|
|
94
|
-
r.labelParagraphCache.use(r.ck, provider,
|
|
177
|
+
r.labelParagraphCache.use(r.ck, provider, label, LABEL_FONT_SIZE, LABEL_MAX_WIDTH, agent ? color : r.ck.WHITE, r.fontGeneration, ({ paragraph, metrics }) => {
|
|
95
178
|
const pill = r.ck.RRectXY(r.ck.XYWHRect(pillX, pillY, badge + metrics.width + 8, pillHeight), 4, 4);
|
|
96
179
|
r.auxFill.setColor(agent ? r.ck.WHITE : color);
|
|
97
180
|
canvas.drawRRect(pill, r.auxFill);
|
|
@@ -110,15 +193,19 @@ function drawLabel(r, canvas, x, y, cursor) {
|
|
|
110
193
|
}
|
|
111
194
|
/** Cursors of people and agents in screen space, with outlines of what they selected. */
|
|
112
195
|
function drawPresenceCursors(r, canvas, graph, cursors) {
|
|
196
|
+
const history = focusHistoryFor(r);
|
|
197
|
+
const drawn = /* @__PURE__ */ new Set();
|
|
113
198
|
for (const cursor of cursors ?? []) {
|
|
199
|
+
drawn.add(cursor.id ?? cursor.name);
|
|
114
200
|
const x = cursor.x * r.zoom + r.panX;
|
|
115
201
|
const y = cursor.y * r.zoom + r.panY;
|
|
116
202
|
drawSelection(r, canvas, graph, cursor);
|
|
117
203
|
drawArrow(r, canvas, x, y, cursor);
|
|
118
204
|
drawLabel(r, canvas, x, y, cursor);
|
|
119
205
|
}
|
|
206
|
+
for (const key of history.keys()) if (!drawn.has(key)) history.delete(key);
|
|
120
207
|
}
|
|
121
208
|
//#endregion
|
|
122
|
-
export { drawPresenceCursors };
|
|
209
|
+
export { NO_FOCUS, drawPresenceCursors, focusOutlines, nextFocus };
|
|
123
210
|
|
|
124
211
|
//# sourceMappingURL=presence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presence.js","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"sourcesContent":["import type { Canvas, Image } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport type { PresenceCursor, SkiaRenderer } from '#core/canvas/renderer'\n\nconst CURSOR_SIZE = 9\nconst LABEL_PADDING_X = 4\nconst LABEL_PADDING_Y = 2\nconst LABEL_FONT_SIZE = 10\nconst LABEL_OFFSET_X = 12\nconst LABEL_OFFSET_Y = 20\n/** Longer names end with an ellipsis. */\nconst LABEL_MAX_WIDTH = 160\n/** The provider mark before an agent's name, and the gap after it. */\nconst LABEL_LOGO_SIZE = 9\nconst LABEL_LOGO_GAP = 3\n\n/** Decoded once per logo byte array; the app keeps one array per provider, so this is tiny. */\nconst labelLogoImages = new WeakMap<Uint8Array, Image | null>()\n\nfunction drawSelection(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph, cursor: PresenceCursor) {\n if (!cursor.selection?.length && !cursor.outline?.length) return\n const { r: red, g, b } = cursor.color\n r.auxStroke.setColor(r.ck.Color4f(red, g, b, 0.6))\n r.auxStroke.setStrokeWidth(1.5)\n r.auxStroke.setPathEffect(null)\n // Outlines of what is not a layer yet, such as JSX an agent is still streaming.\n for (const rect of cursor.outline ?? []) {\n canvas.drawRect(\n r.ck.XYWHRect(\n rect.x * r.zoom + r.panX,\n rect.y * r.zoom + r.panY,\n rect.width * r.zoom,\n rect.height * r.zoom\n ),\n r.auxStroke\n )\n }\n for (const nodeId of cursor.selection ?? []) {\n const node = graph.getNode(nodeId)\n if (!node) continue\n // Map the corners through the node's world matrix, as the shape is rendered, so the\n // box tracks rotation, flips, and parent transforms.\n const corners = Matrix.mapPoints(getWorldMatrix(node, graph), [\n 0,\n 0,\n node.width,\n 0,\n node.width,\n node.height,\n 0,\n node.height\n ])\n const box = new r.ck.PathBuilder()\n box.moveTo(corners[0] * r.zoom + r.panX, corners[1] * r.zoom + r.panY)\n for (let i = 2; i < corners.length; i += 2) {\n box.lineTo(corners[i] * r.zoom + r.panX, corners[i + 1] * r.zoom + r.panY)\n }\n box.close()\n const path = box.detachAndDelete()\n canvas.drawPath(path, r.auxStroke)\n path.delete()\n }\n}\n\nfunction arrowPath(r: SkiaRenderer, x: number, y: number) {\n const S = CURSOR_SIZE\n const builder = new r.ck.PathBuilder()\n builder.moveTo(x, y)\n builder.lineTo(x, y + S * 1.35)\n builder.lineTo(x + S * 0.38, y + S * 1.0)\n builder.lineTo(x + S * 0.72, y + S * 1.5)\n builder.lineTo(x + S * 0.92, y + S * 1.38)\n builder.lineTo(x + S * 0.58, y + S * 0.88)\n builder.lineTo(x + S * 1.0, y + S * 0.82)\n builder.close()\n return builder.detachAndDelete()\n}\n\n/** The pointer, filled with a person's color, or for an agent its owner's, and outlined in white. */\nfunction drawArrow(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const path = arrowPath(r, x, y)\n r.auxStroke.setColor(r.ck.WHITE)\n r.auxStroke.setStrokeWidth(2)\n r.auxStroke.setPathEffect(null)\n canvas.drawPath(path, r.auxStroke)\n const { r: red, g, b } = cursor.color\n r.auxFill.setColor(r.ck.Color4f(red, g, b, 1))\n canvas.drawPath(path, r.auxFill)\n path.delete()\n}\n\n/** The provider's mark decoded for the canvas, or null while none is available. */\nfunction labelLogo(r: SkiaRenderer, bytes: Uint8Array | undefined): Image | null {\n if (!bytes) return null\n const cached = labelLogoImages.get(bytes)\n if (cached !== undefined) return cached\n const image = r.ck.MakeImageFromEncoded(bytes)\n labelLogoImages.set(bytes, image)\n return image\n}\n\n/**\n * A name pill: filled for people; for agents outlined in the owner's color, with the\n * provider's real mark before the name when the app supplied one.\n */\nfunction drawLabel(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const provider = r.fontProvider\n if (!cursor.name || !provider) return\n const { r: red, g, b } = cursor.color\n const color = r.ck.Color4f(red, g, b, 1)\n const agent = cursor.kind === 'agent'\n const logo = agent ? labelLogo(r, cursor.logo) : null\n const badge = logo ? LABEL_LOGO_SIZE + LABEL_LOGO_GAP : 0\n const pillX = x + LABEL_OFFSET_X - LABEL_PADDING_X\n const pillY = y + LABEL_OFFSET_Y - LABEL_FONT_SIZE - LABEL_PADDING_Y + 2\n const pillHeight = LABEL_FONT_SIZE + LABEL_PADDING_Y * 2\n // Shaped like other canvas labels: kerning, fallback fonts, and RTL names.\n r.labelParagraphCache.use(\n r.ck,\n provider,\n cursor.name,\n LABEL_FONT_SIZE,\n LABEL_MAX_WIDTH,\n agent ? color : r.ck.WHITE,\n r.fontGeneration,\n ({ paragraph, metrics }) => {\n const pill = r.ck.RRectXY(\n r.ck.XYWHRect(pillX, pillY, badge + metrics.width + LABEL_PADDING_X * 2, pillHeight),\n 4,\n 4\n )\n r.auxFill.setColor(agent ? r.ck.WHITE : color)\n canvas.drawRRect(pill, r.auxFill)\n if (agent) {\n r.auxStroke.setColor(color)\n r.auxStroke.setStrokeWidth(1)\n r.auxStroke.setPathEffect(null)\n canvas.drawRRect(pill, r.auxStroke)\n if (logo) {\n r.auxFill.setColor(r.ck.Color4f(1, 1, 1, 1))\n canvas.drawImageRect(\n logo,\n r.ck.XYWHRect(0, 0, logo.width(), logo.height()),\n r.ck.XYWHRect(\n pillX + LABEL_PADDING_X,\n pillY + (pillHeight - LABEL_LOGO_SIZE) / 2,\n LABEL_LOGO_SIZE,\n LABEL_LOGO_SIZE\n ),\n r.auxFill\n )\n }\n }\n canvas.drawParagraph(\n paragraph,\n pillX + LABEL_PADDING_X + badge,\n pillY + (pillHeight - metrics.height) / 2\n )\n }\n )\n}\n\n/** Cursors of people and agents in screen space, with outlines of what they selected. */\nexport function drawPresenceCursors(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n cursors?: PresenceCursor[]\n): void {\n for (const cursor of cursors ?? []) {\n const x = cursor.x * r.zoom + r.panX\n const y = cursor.y * r.zoom + r.panY\n drawSelection(r, canvas, graph, cursor)\n drawArrow(r, canvas, x, y, cursor)\n drawLabel(r, canvas, x, y, cursor)\n }\n}\n"],"mappings":";;;AAQA,MAAM,cAAc;AACpB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;;AAEvB,MAAM,kBAAkB;;AAExB,MAAM,kBAAkB;;AAIxB,MAAM,kCAAkB,IAAI,QAAkC;AAE9D,SAAS,cAAc,GAAiB,QAAgB,OAAmB,QAAwB;CACjG,IAAI,CAAC,OAAO,WAAW,UAAU,CAAC,OAAO,SAAS,QAAQ;CAC1D,MAAM,EAAE,GAAG,KAAK,GAAG,MAAM,OAAO;CAChC,EAAE,UAAU,SAAS,EAAE,GAAG,QAAQ,KAAK,GAAG,GAAG,EAAG,CAAC;CACjD,EAAE,UAAU,eAAe,GAAG;CAC9B,EAAE,UAAU,cAAc,IAAI;CAE9B,KAAK,MAAM,QAAQ,OAAO,WAAW,CAAC,GACpC,OAAO,SACL,EAAE,GAAG,SACH,KAAK,IAAI,EAAE,OAAO,EAAE,MACpB,KAAK,IAAI,EAAE,OAAO,EAAE,MACpB,KAAK,QAAQ,EAAE,MACf,KAAK,SAAS,EAAE,IAClB,GACA,EAAE,SACJ;CAEF,KAAK,MAAM,UAAU,OAAO,aAAa,CAAC,GAAG;EAC3C,MAAM,OAAO,MAAM,QAAQ,MAAM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K;EAC7C,OAAO,UAAU,MAAM,EAAE,OAAO;EAChC,IAAI,OAAO;GACT,EAAE,UAAU,SAAS,KAAK;GAC1B,EAAE,UAAU,eAAe,CAAC;GAC5B,EAAE,UAAU,cAAc,IAAI;GAC9B,OAAO,UAAU,MAAM,EAAE,SAAS;GAClC,IAAI,MAAM;IACR,EAAE,QAAQ,SAAS,EAAE,GAAG,QAAQ,GAAG,GAAG,GAAG,CAAC,CAAC;IAC3C,OAAO,cACL,MACA,EAAE,GAAG,SAAS,GAAG,GAAG,KAAK,MAAM,GAAG,KAAK,OAAO,CAAC,GAC/C,EAAE,GAAG,SACH,QAAQ,iBACR,QAAS,IAAgC,GACzC,iBACA,eACF,GACA,EAAE,OACJ;GACF;EACF;EACA,OAAO,cACL,WACA,QAAQ,kBAAkB,OAC1B,SAAS,aAAa,QAAQ,UAAU,CAC1C;CACF,CACF;AACF;;AAGA,SAAgB,oBACd,GACA,QACA,OACA,SACM;CACN,KAAK,MAAM,UAAU,WAAW,CAAC,GAAG;EAClC,MAAM,IAAI,OAAO,IAAI,EAAE,OAAO,EAAE;EAChC,MAAM,IAAI,OAAO,IAAI,EAAE,OAAO,EAAE;EAChC,cAAc,GAAG,QAAQ,OAAO,MAAM;EACtC,UAAU,GAAG,QAAQ,GAAG,GAAG,MAAM;EACjC,UAAU,GAAG,QAAQ,GAAG,GAAG,MAAM;CACnC;AACF"}
|
|
1
|
+
{"version":3,"file":"presence.js","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"sourcesContent":["import type { Canvas, Image, Paint } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport type { PresenceCursor, SkiaRenderer } from '#core/canvas/renderer'\n\nconst CURSOR_SIZE = 9\nconst LABEL_PADDING_X = 4\nconst LABEL_PADDING_Y = 2\nconst LABEL_FONT_SIZE = 10\nconst LABEL_OFFSET_X = 12\nconst LABEL_OFFSET_Y = 20\n/** Longer names end with an ellipsis. */\nconst LABEL_MAX_WIDTH = 160\n/** The provider mark before an agent's name, and the gap after it. */\nconst LABEL_LOGO_SIZE = 9\nconst LABEL_LOGO_GAP = 3\n/** The newest outline's soft pulse, and how long a replaced one takes to fade. */\nconst FOCUS_PULSE_MS = 1200\nconst FOCUS_FADE_MS = 200\n/** One sheen across what a finished preview built. */\nconst SHEEN_MS = 400\n\n/** Decoded once per logo byte array; the app keeps one array per provider, so this is tiny. */\nconst labelLogoImages = new WeakMap<Uint8Array, Image | null>()\n/** What a cursor's focus outline showed, so a newer element fades the old one out. */\nexport interface FocusTransition {\n current: Rect | null\n previous: Rect | null\n /** When the previous outline was replaced. */\n since: number\n}\n\nexport const NO_FOCUS: FocusTransition = { current: null, previous: null, since: 0 }\n\n/** Draw a world-space rectangle in the overlay's screen coordinates. */\nfunction drawWorldRect(r: SkiaRenderer, canvas: Canvas, rect: Rect, paint: Paint) {\n canvas.drawRect(\n r.ck.XYWHRect(\n rect.x * r.zoom + r.panX,\n rect.y * r.zoom + r.panY,\n rect.width * r.zoom,\n rect.height * r.zoom\n ),\n paint\n )\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height\n}\n\n/** Move the outline to `focus`, keeping the one it replaces for its fade. */\nexport function nextFocus(\n state: FocusTransition,\n focus: Rect | undefined,\n now: number\n): FocusTransition {\n if (!focus) return NO_FOCUS\n if (state.current && sameRect(state.current, focus)) return state\n return { current: focus, previous: state.current, since: now }\n}\n\n/** The outline to draw now: the current one, pulsing, and the replaced one fading out. */\nexport function focusOutlines(\n state: FocusTransition,\n pulse: boolean | undefined,\n now: number\n): Array<{ rect: Rect; alpha: number }> {\n const outlines: Array<{ rect: Rect; alpha: number }> = []\n const age = now - state.since\n if (pulse && state.previous && age < FOCUS_FADE_MS) {\n outlines.push({ rect: state.previous, alpha: 0.75 * (1 - age / FOCUS_FADE_MS) })\n }\n if (state.current) {\n const alpha = pulse\n ? 0.35 + 0.65 * (0.5 + 0.5 * Math.sin((now / FOCUS_PULSE_MS) * 2 * Math.PI))\n : 0.75\n outlines.push({ rect: state.current, alpha })\n }\n return outlines\n}\n\n/** Each canvas keeps its own focus transitions, so two documents' agents never collide. */\nconst focusHistories = new WeakMap<SkiaRenderer, Map<string, FocusTransition>>()\n\nfunction focusHistoryFor(r: SkiaRenderer): Map<string, FocusTransition> {\n const existing = focusHistories.get(r)\n if (existing) return existing\n const history = new Map<string, FocusTransition>()\n focusHistories.set(r, history)\n return history\n}\n\n/** The element being written, pulsing in the accent color, and the one it replaced fading out. */\nfunction drawFocus(r: SkiaRenderer, canvas: Canvas, cursor: PresenceCursor) {\n if (cursor.kind !== 'agent') return\n const key = cursor.id ?? cursor.name\n const history = focusHistoryFor(r)\n const now = performance.now()\n const state = nextFocus(history.get(key) ?? NO_FOCUS, cursor.focus, now)\n if (state === NO_FOCUS) history.delete(key)\n else history.set(key, state)\n const { r: red, g, b } = cursor.color\n r.auxStroke.setStrokeWidth(2)\n r.auxStroke.setPathEffect(null)\n for (const { rect, alpha } of focusOutlines(state, cursor.pulse, now)) {\n if (alpha <= 0) continue\n r.auxStroke.setColor(r.ck.Color4f(red, g, b, alpha))\n drawWorldRect(r, canvas, rect, r.auxStroke)\n }\n}\n\n/** One soft pass of light across what a finished preview built. */\nfunction drawSheen(r: SkiaRenderer, canvas: Canvas, cursor: PresenceCursor) {\n if (!cursor.sheen) return\n const age = performance.now() - cursor.sheen.at\n if (age < 0 || age >= SHEEN_MS) return\n const { rect } = cursor.sheen\n r.auxFill.setColor(r.ck.Color4f(1, 1, 1, 0.07 * Math.sin((age / SHEEN_MS) * Math.PI)))\n drawWorldRect(r, canvas, rect, r.auxFill)\n}\n\nfunction drawSelection(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph, cursor: PresenceCursor) {\n drawSheen(r, canvas, cursor)\n drawFocus(r, canvas, cursor)\n if (!cursor.selection?.length && !cursor.outline?.length) return\n const { r: red, g, b } = cursor.color\n r.auxStroke.setColor(r.ck.Color4f(red, g, b, 0.6))\n r.auxStroke.setStrokeWidth(1.5)\n r.auxStroke.setPathEffect(null)\n // Outlines of what is not a layer yet, such as JSX an agent is still streaming.\n for (const rect of cursor.outline ?? []) drawWorldRect(r, canvas, rect, r.auxStroke)\n for (const nodeId of cursor.selection ?? []) {\n const node = graph.getNode(nodeId)\n if (!node) continue\n // Map the corners through the node's world matrix, as the shape is rendered, so the\n // box tracks rotation, flips, and parent transforms.\n const corners = Matrix.mapPoints(getWorldMatrix(node, graph), [\n 0,\n 0,\n node.width,\n 0,\n node.width,\n node.height,\n 0,\n node.height\n ])\n const box = new r.ck.PathBuilder()\n box.moveTo(corners[0] * r.zoom + r.panX, corners[1] * r.zoom + r.panY)\n for (let i = 2; i < corners.length; i += 2) {\n box.lineTo(corners[i] * r.zoom + r.panX, corners[i + 1] * r.zoom + r.panY)\n }\n box.close()\n const path = box.detachAndDelete()\n canvas.drawPath(path, r.auxStroke)\n path.delete()\n }\n}\n\nfunction arrowPath(r: SkiaRenderer, x: number, y: number) {\n const S = CURSOR_SIZE\n const builder = new r.ck.PathBuilder()\n builder.moveTo(x, y)\n builder.lineTo(x, y + S * 1.35)\n builder.lineTo(x + S * 0.38, y + S * 1.0)\n builder.lineTo(x + S * 0.72, y + S * 1.5)\n builder.lineTo(x + S * 0.92, y + S * 1.38)\n builder.lineTo(x + S * 0.58, y + S * 0.88)\n builder.lineTo(x + S * 1.0, y + S * 0.82)\n builder.close()\n return builder.detachAndDelete()\n}\n\n/** The pointer, filled with a person's color, or for an agent its owner's, and outlined in white. */\nfunction drawArrow(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const path = arrowPath(r, x, y)\n r.auxStroke.setColor(r.ck.WHITE)\n r.auxStroke.setStrokeWidth(2)\n r.auxStroke.setPathEffect(null)\n canvas.drawPath(path, r.auxStroke)\n const { r: red, g, b } = cursor.color\n r.auxFill.setColor(r.ck.Color4f(red, g, b, 1))\n canvas.drawPath(path, r.auxFill)\n path.delete()\n}\n\n/** The provider's mark decoded for the canvas, or null while none is available. */\nfunction labelLogo(r: SkiaRenderer, bytes: Uint8Array | undefined): Image | null {\n if (!bytes) return null\n const cached = labelLogoImages.get(bytes)\n if (cached !== undefined) return cached\n const image = r.ck.MakeImageFromEncoded(bytes)\n labelLogoImages.set(bytes, image)\n return image\n}\n\n/**\n * A name pill: filled for people; for agents outlined in the owner's color, with the\n * provider's real mark before the name when the app supplied one.\n */\nfunction drawLabel(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const provider = r.fontProvider\n if (!cursor.name || !provider) return\n const { r: red, g, b } = cursor.color\n const color = r.ck.Color4f(red, g, b, 1)\n const agent = cursor.kind === 'agent'\n const logo = agent ? labelLogo(r, cursor.logo) : null\n const badge = logo ? LABEL_LOGO_SIZE + LABEL_LOGO_GAP : 0\n // The status climbs through its dots while the agent rests; the name stays first.\n const label = cursor.status ? `${cursor.name} ${cursor.status}` : cursor.name\n const pillX = x + LABEL_OFFSET_X - LABEL_PADDING_X\n const pillY = y + LABEL_OFFSET_Y - LABEL_FONT_SIZE - LABEL_PADDING_Y + 2\n const pillHeight = LABEL_FONT_SIZE + LABEL_PADDING_Y * 2\n // Shaped like other canvas labels: kerning, fallback fonts, and RTL names.\n r.labelParagraphCache.use(\n r.ck,\n provider,\n label,\n LABEL_FONT_SIZE,\n LABEL_MAX_WIDTH,\n agent ? color : r.ck.WHITE,\n r.fontGeneration,\n ({ paragraph, metrics }) => {\n const pill = r.ck.RRectXY(\n r.ck.XYWHRect(pillX, pillY, badge + metrics.width + LABEL_PADDING_X * 2, pillHeight),\n 4,\n 4\n )\n r.auxFill.setColor(agent ? r.ck.WHITE : color)\n canvas.drawRRect(pill, r.auxFill)\n if (agent) {\n r.auxStroke.setColor(color)\n r.auxStroke.setStrokeWidth(1)\n r.auxStroke.setPathEffect(null)\n canvas.drawRRect(pill, r.auxStroke)\n if (logo) {\n r.auxFill.setColor(r.ck.Color4f(1, 1, 1, 1))\n canvas.drawImageRect(\n logo,\n r.ck.XYWHRect(0, 0, logo.width(), logo.height()),\n r.ck.XYWHRect(\n pillX + LABEL_PADDING_X,\n pillY + (pillHeight - LABEL_LOGO_SIZE) / 2,\n LABEL_LOGO_SIZE,\n LABEL_LOGO_SIZE\n ),\n r.auxFill\n )\n }\n }\n canvas.drawParagraph(\n paragraph,\n pillX + LABEL_PADDING_X + badge,\n pillY + (pillHeight - metrics.height) / 2\n )\n }\n )\n}\n\n/** Cursors of people and agents in screen space, with outlines of what they selected. */\nexport function drawPresenceCursors(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n cursors?: PresenceCursor[]\n): void {\n const history = focusHistoryFor(r)\n const drawn = new Set<string>()\n for (const cursor of cursors ?? []) {\n drawn.add(cursor.id ?? cursor.name)\n const x = cursor.x * r.zoom + r.panX\n const y = cursor.y * r.zoom + r.panY\n drawSelection(r, canvas, graph, cursor)\n drawArrow(r, canvas, x, y, cursor)\n drawLabel(r, canvas, x, y, cursor)\n }\n // A cursor no longer drawn (an agent at rest) leaves no outline to flash on its return.\n for (const key of history.keys()) if (!drawn.has(key)) history.delete(key)\n}\n"],"mappings":";;;AAQA,MAAM,cAAc;AACpB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;;AAEvB,MAAM,kBAAkB;;AAExB,MAAM,kBAAkB;;AAGxB,MAAM,iBAAiB;AACvB,MAAM,gBAAgB;;AAEtB,MAAM,WAAW;;AAGjB,MAAM,kCAAkB,IAAI,QAAkC;AAS9D,MAAa,WAA4B;CAAE,SAAS;CAAM,UAAU;CAAM,OAAO;AAAE;;AAGnF,SAAS,cAAc,GAAiB,QAAgB,MAAY,OAAc;CAChF,OAAO,SACL,EAAE,GAAG,SACH,KAAK,IAAI,EAAE,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C,MAAM,IAAI,GAAG,GAAG,QAAQ,OAAO,GAAG;AAC3E"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { SkiaRenderer } from "../renderer.js";
|
|
2
2
|
import { Canvas, SkPicture } from "canvaskit-wasm";
|
|
3
3
|
import { VisualBounds } from "@pairdraw/scene-graph/geometry";
|
|
4
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
4
5
|
//#region src/canvas/renderer/picture.d.ts
|
|
5
6
|
/** Run `draw` with the renderer's culling viewport set to world-space `bounds`. */
|
|
6
7
|
declare function withWorldViewport<T>(r: SkiaRenderer, bounds: VisualBounds, draw: () => T): T;
|
|
8
|
+
/** Record one node, its children included, into a picture of world-space `bounds`. */
|
|
9
|
+
declare function recordNodePicture(r: SkiaRenderer, graph: SceneGraph, nodeId: string, bounds: VisualBounds, signal?: AbortSignal): SkPicture;
|
|
7
10
|
/** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */
|
|
8
11
|
declare function recordWorldPicture(r: SkiaRenderer, bounds: VisualBounds, draw: (canvas: Canvas) => void): SkPicture;
|
|
9
12
|
//#endregion
|
|
10
|
-
export { recordWorldPicture, withWorldViewport };
|
|
13
|
+
export { recordNodePicture, recordWorldPicture, withWorldViewport };
|
|
11
14
|
//# sourceMappingURL=picture.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.d.ts","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"picture.d.ts","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"mappings":";;;;;;iBAQgB,kBAAkB,GAAG,GAAG,cAAc,QAAQ,cAAc,YAAY,IAAI;;iBAgB5E,kBACd,GAAG,cACH,OAAO,YACP,gBACA,QAAQ,cACR,SAAS,cACR;;iBAUa,mBACd,GAAG,cACH,QAAQ,cACR,OAAO,QAAQ,kBACd"}
|
|
@@ -14,6 +14,18 @@ function withWorldViewport(r, bounds, draw) {
|
|
|
14
14
|
r.worldViewport = previous;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
/** Record one node, its children included, into a picture of world-space `bounds`. */
|
|
18
|
+
function recordNodePicture(r, graph, nodeId, bounds, signal) {
|
|
19
|
+
return recordWorldPicture(r, bounds, (canvas) => {
|
|
20
|
+
signal?.throwIfAborted();
|
|
21
|
+
const parentId = graph.getNode(nodeId)?.parentId;
|
|
22
|
+
const parent = parentId ? graph.getAbsolutePosition(parentId) : {
|
|
23
|
+
x: 0,
|
|
24
|
+
y: 0
|
|
25
|
+
};
|
|
26
|
+
r.renderNode(canvas, graph, nodeId, {}, parent.x, parent.y);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
17
29
|
/** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */
|
|
18
30
|
function recordWorldPicture(r, bounds, draw) {
|
|
19
31
|
const recorder = new r.ck.PictureRecorder();
|
|
@@ -26,6 +38,6 @@ function recordWorldPicture(r, bounds, draw) {
|
|
|
26
38
|
}
|
|
27
39
|
}
|
|
28
40
|
//#endregion
|
|
29
|
-
export { recordWorldPicture, withWorldViewport };
|
|
41
|
+
export { recordNodePicture, recordWorldPicture, withWorldViewport };
|
|
30
42
|
|
|
31
43
|
//# sourceMappingURL=picture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.js","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { VisualBounds } from '@pairdraw/scene-graph/geometry'\n\nimport type { SkiaRenderer } from '#core/canvas/renderer'\n\n/** Run `draw` with the renderer's culling viewport set to world-space `bounds`. */\nexport function withWorldViewport<T>(r: SkiaRenderer, bounds: VisualBounds, draw: () => T): T {\n const previous = r.worldViewport\n r.worldViewport = {\n x: bounds.minX,\n y: bounds.minY,\n w: bounds.maxX - bounds.minX,\n h: bounds.maxY - bounds.minY\n }\n try {\n return draw()\n } finally {\n r.worldViewport = previous\n }\n}\n\n/** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */\nexport function recordWorldPicture(\n r: SkiaRenderer,\n bounds: VisualBounds,\n draw: (canvas: Canvas) => void\n): SkPicture {\n const recorder = new r.ck.PictureRecorder()\n try {\n const canvas = recorder.beginRecording(\n r.ck.LTRBRect(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY)\n )\n withWorldViewport(r, bounds, () => draw(canvas))\n return recorder.finishRecordingAsPicture()\n } finally {\n recorder.delete()\n }\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"picture.js","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport type { VisualBounds } from '@pairdraw/scene-graph/geometry'\n\nimport type { SkiaRenderer } from '#core/canvas/renderer'\n\n/** Run `draw` with the renderer's culling viewport set to world-space `bounds`. */\nexport function withWorldViewport<T>(r: SkiaRenderer, bounds: VisualBounds, draw: () => T): T {\n const previous = r.worldViewport\n r.worldViewport = {\n x: bounds.minX,\n y: bounds.minY,\n w: bounds.maxX - bounds.minX,\n h: bounds.maxY - bounds.minY\n }\n try {\n return draw()\n } finally {\n r.worldViewport = previous\n }\n}\n\n/** Record one node, its children included, into a picture of world-space `bounds`. */\nexport function recordNodePicture(\n r: SkiaRenderer,\n graph: SceneGraph,\n nodeId: string,\n bounds: VisualBounds,\n signal?: AbortSignal\n): SkPicture {\n return recordWorldPicture(r, bounds, (canvas) => {\n signal?.throwIfAborted()\n const parentId = graph.getNode(nodeId)?.parentId\n const parent = parentId ? graph.getAbsolutePosition(parentId) : { x: 0, y: 0 }\n r.renderNode(canvas, graph, nodeId, {}, parent.x, parent.y)\n })\n}\n\n/** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */\nexport function recordWorldPicture(\n r: SkiaRenderer,\n bounds: VisualBounds,\n draw: (canvas: Canvas) => void\n): SkPicture {\n const recorder = new r.ck.PictureRecorder()\n try {\n const canvas = recorder.beginRecording(\n r.ck.LTRBRect(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY)\n )\n withWorldViewport(r, bounds, () => draw(canvas))\n return recorder.finishRecordingAsPicture()\n } finally {\n recorder.delete()\n }\n}\n"],"mappings":";;AAQA,SAAgB,kBAAqB,GAAiB,QAAsB,MAAkB;CAC5F,MAAM,WAAW,EAAE;CACnB,EAAE,gBAAgB;EAChB,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO,OAAO,OAAO;EACxB,GAAG,OAAO,OAAO,OAAO;CAC1B;CACA,IAAI;EACF,OAAO,KAAK;CACd,UAAU;EACR,EAAE,gBAAgB;CACpB;AACF;;AAGA,SAAgB,kBACd,GACA,OACA,QACA,QACA,QACW;CACX,OAAO,mBAAmB,GAAG,SAAS,WAAW;EAC/C,QAAQ,eAAe;EACvB,MAAM,WAAW,MAAM,QAAQ,MAAM,CAAC,EAAE;EACxC,MAAM,SAAS,WAAW,MAAM,oBAAoB,QAAQ,IAAI;GAAE,GAAG;GAAG,GAAG;EAAE;EAC7E,EAAE,WAAW,QAAQ,OAAO,QAAQ,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC;CAC5D,CAAC;AACH;;AAGA,SAAgB,mBACd,GACA,QACA,MACW;CACX,MAAM,WAAW,IAAI,EAAE,GAAG,gBAAgB;CAC1C,IAAI;EACF,MAAM,SAAS,SAAS,eACtB,EAAE,GAAG,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI,CAClE;EACA,kBAAkB,GAAG,cAAc,KAAK,MAAM,CAAC;EAC/C,OAAO,SAAS,yBAAyB;CAC3C,UAAU;EACR,SAAS,OAAO;CAClB;AACF"}
|
|
@@ -7,11 +7,19 @@ import { SceneGraph } from "@pairdraw/scene-graph";
|
|
|
7
7
|
interface TransientCanvasPreview {
|
|
8
8
|
graph: SceneGraph;
|
|
9
9
|
pageId: string;
|
|
10
|
-
|
|
10
|
+
/** The settled preview; absent while every element enters for the first time. */
|
|
11
|
+
picture?: SkPicture;
|
|
11
12
|
/** Substitute a whole page child, including its proposed descendant layout. */
|
|
12
13
|
replaceId?: string;
|
|
13
14
|
/** Insert before this page-child index, or append when omitted. */
|
|
14
15
|
insertIndex?: number;
|
|
16
|
+
/** New elements fading in over the picture, with how far their entrance has come (0 to 1). */
|
|
17
|
+
entrance?: {
|
|
18
|
+
pictures: SkPicture[];
|
|
19
|
+
progress: number;
|
|
20
|
+
};
|
|
21
|
+
/** How opaque the whole preview is while a finished call hands off to the committed nodes. */
|
|
22
|
+
fade?: number;
|
|
15
23
|
}
|
|
16
24
|
declare function hasTransientPreviews(r: SkiaRenderer, graph: SceneGraph): boolean;
|
|
17
25
|
/** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transient-previews.d.ts","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"mappings":";;;;;;UAOiB;EACf,OAAO;EACP
|
|
1
|
+
{"version":3,"file":"transient-previews.d.ts","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"mappings":";;;;;;UAOiB;EACf,OAAO;EACP;;EAEA,UAAU;;EAEV;;EAEA;;EAEA;IAAa,UAAU;IAAa;;;EAEpC;;iBASc,qBAAqB,GAAG,cAAc,OAAO;;iBA8B7C,uBACd,GAAG,cACH,QAAQ,QACR,OAAO,YACP,UAAU"}
|
|
@@ -5,6 +5,30 @@ function activePreviews(r, graph) {
|
|
|
5
5
|
function hasTransientPreviews(r, graph) {
|
|
6
6
|
return activePreviews(r, graph).length > 0;
|
|
7
7
|
}
|
|
8
|
+
/** One preview picture, with new elements easing up 4 screen pixels while they fade in. */
|
|
9
|
+
function drawPreview(r, canvas, preview) {
|
|
10
|
+
const fade = preview.fade ?? 1;
|
|
11
|
+
if (fade <= 0) return;
|
|
12
|
+
try {
|
|
13
|
+
if (preview.picture) {
|
|
14
|
+
r.auxFill.setAlphaf(fade);
|
|
15
|
+
canvas.saveLayer(r.auxFill);
|
|
16
|
+
canvas.drawPicture(preview.picture);
|
|
17
|
+
canvas.restore();
|
|
18
|
+
}
|
|
19
|
+
const entrance = preview.entrance;
|
|
20
|
+
if (!entrance || entrance.progress <= 0) return;
|
|
21
|
+
r.auxFill.setAlphaf(fade * entrance.progress);
|
|
22
|
+
canvas.save();
|
|
23
|
+
canvas.translate(0, (1 - entrance.progress) * 4 / (r.zoom || 1));
|
|
24
|
+
canvas.saveLayer(r.auxFill);
|
|
25
|
+
for (const picture of entrance.pictures) canvas.drawPicture(picture);
|
|
26
|
+
canvas.restore();
|
|
27
|
+
canvas.restore();
|
|
28
|
+
} finally {
|
|
29
|
+
r.auxFill.setAlphaf(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
8
32
|
/** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */
|
|
9
33
|
function renderPageWithPreviews(r, canvas, graph, overlays) {
|
|
10
34
|
const previews = activePreviews(r, graph);
|
|
@@ -20,12 +44,14 @@ function renderPageWithPreviews(r, canvas, graph, overlays) {
|
|
|
20
44
|
insertions.set(index, atIndex);
|
|
21
45
|
}
|
|
22
46
|
for (let index = 0; index <= children.length; index++) {
|
|
23
|
-
for (const preview of insertions.get(index) ?? []) canvas
|
|
47
|
+
for (const preview of insertions.get(index) ?? []) drawPreview(r, canvas, preview);
|
|
24
48
|
const id = children[index];
|
|
25
49
|
if (!id) continue;
|
|
26
50
|
const replacement = replacements.get(id);
|
|
27
|
-
if (replacement)
|
|
28
|
-
|
|
51
|
+
if (replacement) {
|
|
52
|
+
if (replacement.fade !== void 0 && replacement.fade < 1) r.renderNode(canvas, graph, id, overlays);
|
|
53
|
+
drawPreview(r, canvas, replacement);
|
|
54
|
+
} else r.renderNode(canvas, graph, id, overlays);
|
|
29
55
|
}
|
|
30
56
|
return true;
|
|
31
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transient-previews.js","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { RenderOverlays, SkiaRenderer } from '#core/canvas/renderer'\n\n/** Borrowed picture. The publisher owns disposal, including removal from every renderer. */\nexport interface TransientCanvasPreview {\n graph: SceneGraph\n pageId: string\n picture
|
|
1
|
+
{"version":3,"file":"transient-previews.js","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { RenderOverlays, SkiaRenderer } from '#core/canvas/renderer'\n\n/** Borrowed picture. The publisher owns disposal, including removal from every renderer. */\nexport interface TransientCanvasPreview {\n graph: SceneGraph\n pageId: string\n /** The settled preview; absent while every element enters for the first time. */\n picture?: SkPicture\n /** Substitute a whole page child, including its proposed descendant layout. */\n replaceId?: string\n /** Insert before this page-child index, or append when omitted. */\n insertIndex?: number\n /** New elements fading in over the picture, with how far their entrance has come (0 to 1). */\n entrance?: { pictures: SkPicture[]; progress: number }\n /** How opaque the whole preview is while a finished call hands off to the committed nodes. */\n fade?: number\n}\n\nfunction activePreviews(r: SkiaRenderer, graph: SceneGraph): TransientCanvasPreview[] {\n return [...r.transientPreviews.values()].filter(\n (preview) => preview.graph === graph && preview.pageId === r.pageId\n )\n}\n\nexport function hasTransientPreviews(r: SkiaRenderer, graph: SceneGraph): boolean {\n return activePreviews(r, graph).length > 0\n}\n\n/** One preview picture, with new elements easing up 4 screen pixels while they fade in. */\nfunction drawPreview(r: SkiaRenderer, canvas: Canvas, preview: TransientCanvasPreview): void {\n const fade = preview.fade ?? 1\n if (fade <= 0) return\n try {\n if (preview.picture) {\n r.auxFill.setAlphaf(fade)\n canvas.saveLayer(r.auxFill)\n canvas.drawPicture(preview.picture)\n canvas.restore()\n }\n const entrance = preview.entrance\n if (!entrance || entrance.progress <= 0) return\n r.auxFill.setAlphaf(fade * entrance.progress)\n canvas.save()\n canvas.translate(0, ((1 - entrance.progress) * 4) / (r.zoom || 1))\n canvas.saveLayer(r.auxFill)\n for (const picture of entrance.pictures) canvas.drawPicture(picture)\n canvas.restore()\n canvas.restore()\n } finally {\n r.auxFill.setAlphaf(1)\n }\n}\n\n/** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */\nexport function renderPageWithPreviews(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n overlays: RenderOverlays\n): boolean {\n const previews = activePreviews(r, graph)\n if (previews.length === 0) return false\n const children = graph.getNode(r.pageId ?? graph.rootId)?.childIds ?? []\n const replacements = new Map<string, TransientCanvasPreview>()\n const insertions = new Map<number, TransientCanvasPreview[]>()\n for (const preview of previews) {\n if (preview.replaceId) {\n replacements.set(preview.replaceId, preview)\n } else {\n const index = Math.min(preview.insertIndex ?? children.length, children.length)\n const atIndex = insertions.get(index) ?? []\n atIndex.push(preview)\n insertions.set(index, atIndex)\n }\n }\n for (let index = 0; index <= children.length; index++) {\n for (const preview of insertions.get(index) ?? []) drawPreview(r, canvas, preview)\n const id = children[index]\n if (!id) continue\n const replacement = replacements.get(id)\n if (replacement) {\n // A fading replacement uncovers the committed node it replaced, so no frame is blank.\n if (replacement.fade !== undefined && replacement.fade < 1)\n r.renderNode(canvas, graph, id, overlays)\n drawPreview(r, canvas, replacement)\n } else r.renderNode(canvas, graph, id, overlays)\n }\n return true\n}\n"],"mappings":";AAsBA,SAAS,eAAe,GAAiB,OAA6C;CACpF,OAAO,CAAC,GAAG,EAAE,kBAAkB,OAAO,CAAC,CAAC,CAAC,QACtC,YAAY,QAAQ,UAAU,SAAS,QAAQ,WAAW,EAAE,MAC/D;AACF;AAEA,SAAgB,qBAAqB,GAAiB,OAA4B;CAChF,OAAO,eAAe,GAAG,KAAK,CAAC,CAAC,SAAS;AAC3C;;AAGA,SAAS,YAAY,GAAiB,QAAgB,SAAuC;CAC3F,M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QAAQ,OAAO;EACjF,MAAM,KAAK,SAAS;EACpB,IAAI,CAAC,IAAI;EACT,MAAM,cAAc,aAAa,IAAI,EAAE;EACvC,IAAI,aAAa;GAEf,IAAI,YAAY,SAAS,KAAA,KAAa,YAAY,OAAO,GACvD,EAAE,WAAW,QAAQ,OAAO,IAAI,QAAQ;GAC1C,YAAY,GAAG,QAAQ,WAAW;EACpC,OAAO,EAAE,WAAW,QAAQ,OAAO,IAAI,QAAQ;CACjD;CACA,OAAO;AACT"}
|
|
@@ -31,8 +31,19 @@ interface PresenceCursor {
|
|
|
31
31
|
x: number;
|
|
32
32
|
y: number;
|
|
33
33
|
selection?: string[];
|
|
34
|
+
/** What the label says after the name while the agent works, such as `Writing...`. */
|
|
35
|
+
status?: string;
|
|
34
36
|
/** Outlines in world coordinates of what is not a layer yet, such as streamed JSX. */
|
|
35
37
|
outline?: Rect[];
|
|
38
|
+
/** The element being written, outlined with a soft pulse while the agent rests on it. */
|
|
39
|
+
focus?: Rect;
|
|
40
|
+
/** Whether the focus outline may pulse; false under reduced motion. */
|
|
41
|
+
pulse?: boolean;
|
|
42
|
+
/** One sheen over what a finished preview built, drawn once at `at`. */
|
|
43
|
+
sheen?: {
|
|
44
|
+
rect: Rect;
|
|
45
|
+
at: number;
|
|
46
|
+
};
|
|
36
47
|
/** PNG bytes of the mark of what an agent runs on, drawn in its label. */
|
|
37
48
|
logo?: Uint8Array;
|
|
38
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/renderer/types.ts"],"mappings":";;;;;;;;;;;;UAYiB;EACf,OAAO;EACP,YAAY;;UAGG;EACf,YAAY;EACZ,MAAM;EACN,MAAM;;KAGI;;UAGK;;EAEf;EACA;EACA;;EAEA,OAAO;EACP;EACA;EACA;;EAEA,UAAU;;EAEV,OAAO;;;;;;;UAQQ;WACN,OAAO;WACP;WACA,SAAS;;UAGH;;EAEf;;EAEA,aAAa,oBAAoB;;EAEjC,aAAa,oBAAoB;;EAEjC,cAAc;EACd;;EAEA;;EAEA;;EAEA;;EAEA,eAAe;;EAEf,YAAY;EACZ;EACA,kBAAkB;EAClB;;EAEA;EACA,aAAa;EACb,UAAU;EACV,aAAa;EACb,SAAS;EACT,kBAAkB;EAClB;EACA;IACE;IACA;IACA;IACA;;EAEF;IACE;IACA;;IAEA;IACA;IACA;;;EAGF;IAAkB;;;EAElB,mBAAmB;;EAEnB,kBAAkB;EAClB;IACE,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,aAAa;IACb,sBAAsB;IACtB;IACA;IACA;IACA;;EAEF,cAAc;EACd;IACE;IACA,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,SAAS;IACT,uBAAuB;IACvB,yBAAyB;IACzB,kBAAkB;IAClB;MAAsB;MAAsB;;;IAE5C;;IAEA,kBAAkB;;IAElB;;IAEA;;IAEA,eAAe;;EAEjB,kBAAkB;EAClB,uBAAuB;EACvB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/renderer/types.ts"],"mappings":";;;;;;;;;;;;UAYiB;EACf,OAAO;EACP,YAAY;;UAGG;EACf,YAAY;EACZ,MAAM;EACN,MAAM;;KAGI;;UAGK;;EAEf;EACA;EACA;;EAEA,OAAO;EACP;EACA;EACA;;EAEA;;EAEA,UAAU;;EAEV,QAAQ;;EAER;;EAEA;IAAU,MAAM;IAAM;;;EAEtB,OAAO;;;;;;;UAQQ;WACN,OAAO;WACP;WACA,SAAS;;UAGH;;EAEf;;EAEA,aAAa,oBAAoB;;EAEjC,aAAa,oBAAoB;;EAEjC,cAAc;EACd;;EAEA;;EAEA;;EAEA;;EAEA,eAAe;;EAEf,YAAY;EACZ;EACA,kBAAkB;EAClB;;EAEA;EACA,aAAa;EACb,UAAU;EACV,aAAa;EACb,SAAS;EACT,kBAAkB;EAClB;EACA;IACE;IACA;IACA;IACA;;EAEF;IACE;IACA;;IAEA;IACA;IACA;;;EAGF;IAAkB;;;EAElB,mBAAmB;;EAEnB,kBAAkB;EAClB;IACE,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,aAAa;IACb,sBAAsB;IACtB;IACA;IACA;IACA;;EAEF,cAAc;EACd;IACE;IACA,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,SAAS;IACT,uBAAuB;IACvB,yBAAyB;IACzB,kBAAkB;IAClB;MAAsB;MAAsB;;;IAE5C;;IAEA,kBAAkB;;IAElB;;IAEA;;IAEA,eAAe;;EAEjB,kBAAkB;EAClB,uBAAuB;EACvB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ResourceCache } from "../cache/resource.js";
|
|
2
|
+
import { TransientCanvasPreview } from "./renderer/transient-previews.js";
|
|
2
3
|
import { ImagePreviewCache } from "./images/previews.js";
|
|
3
4
|
import { FontResolutionSnapshot } from "../text/resolver/types.js";
|
|
4
5
|
import { LabelParagraphCache } from "./labels/paragraph-cache.js";
|
|
@@ -23,7 +24,6 @@ import { NodeFontReadiness } from "./text/index.js";
|
|
|
23
24
|
import { EffectRasterCache } from "./renderer/effect-raster-cache.js";
|
|
24
25
|
import { TiledSceneController } from "./renderer/tiles/controller.js";
|
|
25
26
|
import "./renderer/tiles/index.js";
|
|
26
|
-
import { TransientCanvasPreview } from "./renderer/transient-previews.js";
|
|
27
27
|
import { Blender, Canvas, CanvasKit, Font, FontMgr, Image, ImageFilter, MaskFilter, Paint, RuntimeEffect, SkPicture, Surface, TextureSource, TypefaceFontProvider } from "canvaskit-wasm";
|
|
28
28
|
import { RenderColorSpace, ResolvedRenderColor } from "@pairdraw/scene-graph/color";
|
|
29
29
|
import { ColorProfile, Fill, SceneGraph, SceneNode, Stroke } from "@pairdraw/scene-graph";
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { StagedJSXPreview } from "./stage.js";
|
|
2
2
|
import { CanvasKit, SkPicture } from "canvaskit-wasm";
|
|
3
|
+
import { VisualBounds } from "@pairdraw/scene-graph/geometry";
|
|
4
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
3
5
|
//#region src/design-jsx/preview/picture.d.ts
|
|
4
6
|
interface JSXPreviewRecorder {
|
|
5
7
|
/** Record `staged` as a picture the caller owns, even when its request becomes stale. */
|
|
6
8
|
record(staged: StagedJSXPreview, signal: AbortSignal): Promise<SkPicture | null>;
|
|
9
|
+
/** Record one layer of a staged graph, for an entrance drawn apart from the rest. */
|
|
10
|
+
recordNode(graph: SceneGraph, nodeId: string, bounds: VisualBounds, signal: AbortSignal): Promise<SkPicture | null>;
|
|
7
11
|
/** Free the private renderer once the records already asked for finish. */
|
|
8
12
|
destroy(): void;
|
|
9
13
|
}
|