@promptbook/node 0.112.0-53 â 0.112.0-56
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/esm/index.es.js +3577 -204
- package/esm/index.es.js.map +1 -1
- package/esm/src/_packages/cli.index.d.ts +10 -0
- package/esm/src/_packages/core.index.d.ts +12 -0
- package/esm/src/_packages/types.index.d.ts +8 -0
- package/esm/src/_packages/wizard.index.d.ts +10 -0
- package/esm/src/avatars/index.d.ts +1 -1
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/esm/src/avatars/visuals/avatarVisualRegistry.d.ts +12 -0
- package/esm/src/avatars/visuals/orbAvatarVisual.d.ts +48 -0
- package/esm/src/avatars/visuals/orbAvatarVisual.test.d.ts +1 -0
- package/esm/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
- package/esm/src/book-2.0/agent-source/parseAgentSourceWithCommitments.use.test.d.ts +1 -0
- package/esm/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.d.ts +9 -8
- package/esm/src/commitments/ACTION/ACTION.d.ts +8 -2
- package/esm/src/commitments/ACTION/ACTION.test.d.ts +1 -0
- package/esm/src/commitments/DELETE/DELETE.d.ts +7 -3
- package/esm/src/commitments/DELETE/DELETE.test.d.ts +1 -0
- package/esm/src/commitments/FORMAT/FORMAT.d.ts +10 -4
- package/esm/src/commitments/FORMAT/FORMAT.test.d.ts +1 -0
- package/esm/src/commitments/GOAL/GOAL.d.ts +4 -0
- package/esm/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +4 -0
- package/esm/src/commitments/META/META.d.ts +2 -0
- package/esm/src/commitments/META_AVATAR/META_AVATAR.d.ts +26 -0
- package/esm/src/commitments/MODEL/MODEL.d.ts +4 -0
- package/esm/src/commitments/MODEL/MODEL.test.d.ts +1 -0
- package/esm/src/commitments/RULE/RULE.d.ts +4 -0
- package/esm/src/commitments/TEAM/TEAM.d.ts +4 -0
- package/esm/src/commitments/TEMPLATE/TEMPLATE.d.ts +10 -4
- package/esm/src/commitments/_base/BaseCommitmentDefinition.d.ts +12 -0
- package/esm/src/commitments/_base/CommitmentDefinition.d.ts +21 -1
- package/esm/src/commitments/_common/getAllCommitmentDefinitions.test.d.ts +1 -0
- package/esm/src/commitments/_common/getCommitmentNoticeMetadata.d.ts +51 -0
- package/esm/src/commitments/_common/getCommitmentNoticeMetadata.test.d.ts +1 -0
- package/esm/src/commitments/_common/getGroupedCommitmentDefinitions.openClosed.test.d.ts +1 -0
- package/esm/src/commitments/_common/getGroupedCommitmentDefinitions.order.test.d.ts +1 -0
- package/esm/src/commitments/_common/getGroupedCommitmentDefinitions.use.test.d.ts +1 -0
- package/esm/src/commitments/_common/sortCommitmentDefinitions.d.ts +31 -0
- package/esm/src/commitments/_common/teamInternalAgentAccess.d.ts +51 -0
- package/esm/src/commitments/_common/toolRuntimeContext.d.ts +4 -0
- package/esm/src/commitments/index.d.ts +2 -2
- package/esm/src/commitments/index.test.d.ts +1 -0
- package/esm/src/llm-providers/agent/Agent.d.ts +2 -0
- package/esm/src/llm-providers/agent/RemoteAgent.d.ts +1 -0
- package/esm/src/llm-providers/agent/RemoteAgentOptions.d.ts +4 -0
- package/esm/src/playground/playground.d.ts +1 -0
- package/esm/src/transpilers/_common/BookTranspilerOptions.d.ts +20 -0
- package/esm/src/transpilers/_common/TranspiledTeamExport.d.ts +80 -0
- package/esm/src/transpilers/_common/createTranspiledTeamRuntimeSection.d.ts +55 -0
- package/esm/src/transpilers/_common/createZodSchemaSource.d.ts +40 -0
- package/esm/src/transpilers/_common/formatUsedToolFunctions.d.ts +18 -0
- package/esm/src/transpilers/_common/formatUsedToolFunctions.test.d.ts +1 -0
- package/esm/src/transpilers/_common/prepareSdkTranspilerContext.d.ts +48 -0
- package/esm/src/transpilers/_common/resolveClaudeModelName.d.ts +12 -0
- package/esm/src/transpilers/_common/transpiledTeamTranspilers.test.d.ts +1 -0
- package/esm/src/transpilers/agent-os/AgentOsTranspiler.d.ts +16 -0
- package/esm/src/transpilers/agent-os/AgentOsTranspiler.test.d.ts +1 -0
- package/esm/src/transpilers/agent-os/register.d.ts +12 -0
- package/esm/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.d.ts +16 -0
- package/esm/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.test.d.ts +1 -0
- package/esm/src/transpilers/anthropic-claude-managed/register.d.ts +12 -0
- package/esm/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.d.ts +16 -0
- package/esm/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.test.d.ts +1 -0
- package/esm/src/transpilers/anthropic-claude-sdk/register.d.ts +12 -0
- package/esm/src/transpilers/e2b/E2BTranspiler.d.ts +16 -0
- package/esm/src/transpilers/e2b/E2BTranspiler.test.d.ts +1 -0
- package/esm/src/transpilers/e2b/register.d.ts +12 -0
- package/esm/src/transpilers/openai-agents/OpenAiAgentsTranspiler.d.ts +16 -0
- package/esm/src/transpilers/openai-agents/OpenAiAgentsTranspiler.test.d.ts +1 -0
- package/esm/src/transpilers/openai-agents/register.d.ts +12 -0
- package/esm/src/utils/agents/resolveAgentAvatarImageUrl.d.ts +15 -0
- package/esm/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -1
- package/esm/src/version.d.ts +1 -1
- package/package.json +3 -3
- package/umd/index.umd.js +3577 -204
- package/umd/index.umd.js.map +1 -1
- package/umd/src/_packages/cli.index.d.ts +10 -0
- package/umd/src/_packages/core.index.d.ts +12 -0
- package/umd/src/_packages/types.index.d.ts +8 -0
- package/umd/src/_packages/wizard.index.d.ts +10 -0
- package/umd/src/avatars/index.d.ts +1 -1
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/umd/src/avatars/visuals/avatarVisualRegistry.d.ts +12 -0
- package/umd/src/avatars/visuals/orbAvatarVisual.d.ts +48 -0
- package/umd/src/avatars/visuals/orbAvatarVisual.test.d.ts +1 -0
- package/umd/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -0
- package/umd/src/book-2.0/agent-source/parseAgentSourceWithCommitments.use.test.d.ts +1 -0
- package/umd/src/book-components/BookEditor/createDeprecatedCommitmentDiagnostics.d.ts +9 -8
- package/umd/src/commitments/ACTION/ACTION.d.ts +8 -2
- package/umd/src/commitments/ACTION/ACTION.test.d.ts +1 -0
- package/umd/src/commitments/DELETE/DELETE.d.ts +7 -3
- package/umd/src/commitments/DELETE/DELETE.test.d.ts +1 -0
- package/umd/src/commitments/FORMAT/FORMAT.d.ts +10 -4
- package/umd/src/commitments/FORMAT/FORMAT.test.d.ts +1 -0
- package/umd/src/commitments/GOAL/GOAL.d.ts +4 -0
- package/umd/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +4 -0
- package/umd/src/commitments/META/META.d.ts +2 -0
- package/umd/src/commitments/META_AVATAR/META_AVATAR.d.ts +26 -0
- package/umd/src/commitments/MODEL/MODEL.d.ts +4 -0
- package/umd/src/commitments/MODEL/MODEL.test.d.ts +1 -0
- package/umd/src/commitments/RULE/RULE.d.ts +4 -0
- package/umd/src/commitments/TEAM/TEAM.d.ts +4 -0
- package/umd/src/commitments/TEMPLATE/TEMPLATE.d.ts +10 -4
- package/umd/src/commitments/_base/BaseCommitmentDefinition.d.ts +12 -0
- package/umd/src/commitments/_base/CommitmentDefinition.d.ts +21 -1
- package/umd/src/commitments/_common/getAllCommitmentDefinitions.test.d.ts +1 -0
- package/umd/src/commitments/_common/getCommitmentNoticeMetadata.d.ts +51 -0
- package/umd/src/commitments/_common/getCommitmentNoticeMetadata.test.d.ts +1 -0
- package/umd/src/commitments/_common/getGroupedCommitmentDefinitions.openClosed.test.d.ts +1 -0
- package/umd/src/commitments/_common/getGroupedCommitmentDefinitions.order.test.d.ts +1 -0
- package/umd/src/commitments/_common/getGroupedCommitmentDefinitions.use.test.d.ts +1 -0
- package/umd/src/commitments/_common/sortCommitmentDefinitions.d.ts +31 -0
- package/umd/src/commitments/_common/teamInternalAgentAccess.d.ts +51 -0
- package/umd/src/commitments/_common/toolRuntimeContext.d.ts +4 -0
- package/umd/src/commitments/index.d.ts +2 -2
- package/umd/src/commitments/index.test.d.ts +1 -0
- package/umd/src/llm-providers/agent/Agent.d.ts +2 -0
- package/umd/src/llm-providers/agent/RemoteAgent.d.ts +1 -0
- package/umd/src/llm-providers/agent/RemoteAgentOptions.d.ts +4 -0
- package/umd/src/playground/playground.d.ts +1 -0
- package/umd/src/transpilers/_common/BookTranspilerOptions.d.ts +20 -0
- package/umd/src/transpilers/_common/TranspiledTeamExport.d.ts +80 -0
- package/umd/src/transpilers/_common/createTranspiledTeamRuntimeSection.d.ts +55 -0
- package/umd/src/transpilers/_common/createZodSchemaSource.d.ts +40 -0
- package/umd/src/transpilers/_common/formatUsedToolFunctions.d.ts +18 -0
- package/umd/src/transpilers/_common/formatUsedToolFunctions.test.d.ts +1 -0
- package/umd/src/transpilers/_common/prepareSdkTranspilerContext.d.ts +48 -0
- package/umd/src/transpilers/_common/resolveClaudeModelName.d.ts +12 -0
- package/umd/src/transpilers/_common/transpiledTeamTranspilers.test.d.ts +1 -0
- package/umd/src/transpilers/agent-os/AgentOsTranspiler.d.ts +16 -0
- package/umd/src/transpilers/agent-os/AgentOsTranspiler.test.d.ts +1 -0
- package/umd/src/transpilers/agent-os/register.d.ts +12 -0
- package/umd/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.d.ts +16 -0
- package/umd/src/transpilers/anthropic-claude-managed/AnthropicClaudeManagedTranspiler.test.d.ts +1 -0
- package/umd/src/transpilers/anthropic-claude-managed/register.d.ts +12 -0
- package/umd/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.d.ts +16 -0
- package/umd/src/transpilers/anthropic-claude-sdk/AnthropicClaudeSdkTranspiler.test.d.ts +1 -0
- package/umd/src/transpilers/anthropic-claude-sdk/register.d.ts +12 -0
- package/umd/src/transpilers/e2b/E2BTranspiler.d.ts +16 -0
- package/umd/src/transpilers/e2b/E2BTranspiler.test.d.ts +1 -0
- package/umd/src/transpilers/e2b/register.d.ts +12 -0
- package/umd/src/transpilers/openai-agents/OpenAiAgentsTranspiler.d.ts +16 -0
- package/umd/src/transpilers/openai-agents/OpenAiAgentsTranspiler.test.d.ts +1 -0
- package/umd/src/transpilers/openai-agents/register.d.ts +12 -0
- package/umd/src/utils/agents/resolveAgentAvatarImageUrl.d.ts +15 -0
- package/umd/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -1
- package/umd/src/version.d.ts +1 -1
- package/esm/src/commitments/USE/USE.d.ts +0 -51
- package/umd/src/commitments/USE/USE.d.ts +0 -51
package/umd/index.umd.js
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-56';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [đ] Ignore a discrepancy between file name and entity name
|
|
@@ -14399,6 +14399,24 @@
|
|
|
14399
14399
|
get requiresContent() {
|
|
14400
14400
|
return true;
|
|
14401
14401
|
}
|
|
14402
|
+
/**
|
|
14403
|
+
* Whether this commitment should be prioritized in menus, documentation, and intellisense.
|
|
14404
|
+
*/
|
|
14405
|
+
get isImportant() {
|
|
14406
|
+
return false;
|
|
14407
|
+
}
|
|
14408
|
+
/**
|
|
14409
|
+
* Whether this commitment is unfinished and not ready to use.
|
|
14410
|
+
*/
|
|
14411
|
+
get isUnfinished() {
|
|
14412
|
+
return false;
|
|
14413
|
+
}
|
|
14414
|
+
/**
|
|
14415
|
+
* Whether this commitment is low-level and should be surfaced with caution.
|
|
14416
|
+
*/
|
|
14417
|
+
get isLowLevel() {
|
|
14418
|
+
return false;
|
|
14419
|
+
}
|
|
14402
14420
|
/**
|
|
14403
14421
|
* Optional UI/docs-only deprecation metadata.
|
|
14404
14422
|
*/
|
|
@@ -14515,8 +14533,8 @@
|
|
|
14515
14533
|
/**
|
|
14516
14534
|
* ACTION commitment definition
|
|
14517
14535
|
*
|
|
14518
|
-
*
|
|
14519
|
-
*
|
|
14536
|
+
* Deprecated legacy commitment for broad capability notes.
|
|
14537
|
+
* New books should prefer the appropriate `USE*` commitment instead.
|
|
14520
14538
|
*
|
|
14521
14539
|
* Example usage in agent source:
|
|
14522
14540
|
*
|
|
@@ -14535,7 +14553,15 @@
|
|
|
14535
14553
|
* Short one-line description of ACTION.
|
|
14536
14554
|
*/
|
|
14537
14555
|
get description() {
|
|
14538
|
-
return '
|
|
14556
|
+
return 'Deprecated legacy capability commitment. Prefer concrete `USE*` commitments.';
|
|
14557
|
+
}
|
|
14558
|
+
/**
|
|
14559
|
+
* Optional UI/docs-only deprecation metadata.
|
|
14560
|
+
*/
|
|
14561
|
+
get deprecation() {
|
|
14562
|
+
return {
|
|
14563
|
+
message: 'Use a concrete `USE*` commitment instead.',
|
|
14564
|
+
};
|
|
14539
14565
|
}
|
|
14540
14566
|
/**
|
|
14541
14567
|
* Icon for this commitment.
|
|
@@ -14550,33 +14576,43 @@
|
|
|
14550
14576
|
return _spaceTrim.spaceTrim(`
|
|
14551
14577
|
# ${this.type}
|
|
14552
14578
|
|
|
14553
|
-
|
|
14579
|
+
Deprecated legacy commitment for broad capability notes.
|
|
14554
14580
|
|
|
14555
|
-
##
|
|
14581
|
+
## Migration
|
|
14556
14582
|
|
|
14557
|
-
-
|
|
14558
|
-
-
|
|
14559
|
-
-
|
|
14583
|
+
- Existing \`${this.type}\` and \`ACTIONS\` books still parse and compile.
|
|
14584
|
+
- New books should prefer the appropriate \`USE*\` commitment instead.
|
|
14585
|
+
- Keep \`${this.type}\` only when maintaining older books that already rely on it.
|
|
14560
14586
|
|
|
14561
|
-
##
|
|
14587
|
+
## Preferred replacement
|
|
14562
14588
|
|
|
14563
14589
|
\`\`\`book
|
|
14564
|
-
|
|
14590
|
+
Research Assistant
|
|
14565
14591
|
|
|
14566
|
-
PERSONA You are a
|
|
14567
|
-
|
|
14568
|
-
|
|
14569
|
-
|
|
14592
|
+
PERSONA You are a helpful research assistant
|
|
14593
|
+
USE SEARCH ENGINE
|
|
14594
|
+
RULE Always cite your sources when providing information from the web
|
|
14595
|
+
\`\`\`
|
|
14596
|
+
|
|
14597
|
+
## Legacy compatibility example
|
|
14598
|
+
|
|
14599
|
+
\`\`\`book
|
|
14600
|
+
Research Assistant
|
|
14601
|
+
|
|
14602
|
+
PERSONA You are a helpful research assistant
|
|
14603
|
+
ACTION Can search for current information and summarize findings
|
|
14604
|
+
RULE Always cite your sources when providing information from the web
|
|
14570
14605
|
\`\`\`
|
|
14571
14606
|
|
|
14607
|
+
## Legacy compatibility example with additional tools
|
|
14608
|
+
|
|
14572
14609
|
\`\`\`book
|
|
14573
|
-
|
|
14610
|
+
Code Assistant
|
|
14574
14611
|
|
|
14575
|
-
PERSONA You are a
|
|
14576
|
-
|
|
14577
|
-
|
|
14578
|
-
|
|
14579
|
-
KNOWLEDGE Data analysis best practices and statistical methods
|
|
14612
|
+
PERSONA You are a programming assistant
|
|
14613
|
+
USE BROWSER
|
|
14614
|
+
USE SEARCH ENGINE
|
|
14615
|
+
RULE Prefer the narrowest useful capability for the task.
|
|
14580
14616
|
\`\`\`
|
|
14581
14617
|
`);
|
|
14582
14618
|
}
|
|
@@ -14585,7 +14621,7 @@
|
|
|
14585
14621
|
if (!trimmedContent) {
|
|
14586
14622
|
return requirements;
|
|
14587
14623
|
}
|
|
14588
|
-
//
|
|
14624
|
+
// Keep the legacy capability note for backward compatibility.
|
|
14589
14625
|
const actionSection = `Capability: ${trimmedContent}`;
|
|
14590
14626
|
return this.appendToSystemMessage(requirements, actionSection, '\n\n');
|
|
14591
14627
|
}
|
|
@@ -14720,9 +14756,9 @@
|
|
|
14720
14756
|
/**
|
|
14721
14757
|
* DELETE commitment definition
|
|
14722
14758
|
*
|
|
14723
|
-
* The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is
|
|
14724
|
-
* remove or disregard certain information or context.
|
|
14725
|
-
*
|
|
14759
|
+
* The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is a low-level
|
|
14760
|
+
* unfinished commitment used to remove or disregard certain information or context.
|
|
14761
|
+
* It is intentionally surfaced with caution because it is not ready for broad use yet.
|
|
14726
14762
|
*
|
|
14727
14763
|
* Example usage in agent source:
|
|
14728
14764
|
*
|
|
@@ -14743,7 +14779,13 @@
|
|
|
14743
14779
|
* Short one-line description of DELETE/CANCEL/DISCARD/REMOVE.
|
|
14744
14780
|
*/
|
|
14745
14781
|
get description() {
|
|
14746
|
-
return '
|
|
14782
|
+
return 'Unfinished low-level commitment for removing or disregarding information. Use carefully.';
|
|
14783
|
+
}
|
|
14784
|
+
/**
|
|
14785
|
+
* Marks DELETE as unfinished and not ready to use.
|
|
14786
|
+
*/
|
|
14787
|
+
get isUnfinished() {
|
|
14788
|
+
return true;
|
|
14747
14789
|
}
|
|
14748
14790
|
/**
|
|
14749
14791
|
* Icon for this commitment.
|
|
@@ -14758,7 +14800,13 @@
|
|
|
14758
14800
|
return _spaceTrim.spaceTrim(`
|
|
14759
14801
|
# DELETE (CANCEL, DISCARD, REMOVE)
|
|
14760
14802
|
|
|
14761
|
-
A commitment to remove or disregard certain information or context.
|
|
14803
|
+
A low-level unfinished commitment to remove or disregard certain information or context. It is not ready to use broadly yet, so use it carefully.
|
|
14804
|
+
|
|
14805
|
+
## Status
|
|
14806
|
+
|
|
14807
|
+
- This commitment is unfinished and not ready to use yet.
|
|
14808
|
+
- Treat it as a low-level prompt-surgery tool rather than a general-purpose commitment.
|
|
14809
|
+
- Prefer higher-level commitments when a clearer dedicated commitment exists.
|
|
14762
14810
|
|
|
14763
14811
|
## Aliases
|
|
14764
14812
|
|
|
@@ -14773,6 +14821,7 @@
|
|
|
14773
14821
|
- Useful for overriding previous commitments in the same agent definition.
|
|
14774
14822
|
- Can be used to remove inherited behaviors from base personas.
|
|
14775
14823
|
- Helps fine-tune agent behavior by explicitly removing unwanted elements.
|
|
14824
|
+
- Because this commitment is unfinished, keep an eye on future changes before relying on it in production books.
|
|
14776
14825
|
|
|
14777
14826
|
## Use cases
|
|
14778
14827
|
|
|
@@ -14780,6 +14829,7 @@
|
|
|
14780
14829
|
- Removing conflicting or outdated instructions
|
|
14781
14830
|
- Disabling specific response patterns
|
|
14782
14831
|
- Canceling previous formatting or style requirements
|
|
14832
|
+
- Experimenting with low-level prompt rewrites when you know exactly what needs to be removed
|
|
14783
14833
|
|
|
14784
14834
|
## Examples
|
|
14785
14835
|
|
|
@@ -14946,11 +14996,10 @@
|
|
|
14946
14996
|
/**
|
|
14947
14997
|
* FORMAT commitment definition
|
|
14948
14998
|
*
|
|
14949
|
-
*
|
|
14950
|
-
*
|
|
14951
|
-
* response templates, and structural requirements.
|
|
14999
|
+
* Deprecated legacy commitment for output formatting and response structure.
|
|
15000
|
+
* New books should prefer `WRITING SAMPLE` and `WRITING RULES`.
|
|
14952
15001
|
*
|
|
14953
|
-
*
|
|
15002
|
+
* Legacy example usage in agent source:
|
|
14954
15003
|
*
|
|
14955
15004
|
* ```book
|
|
14956
15005
|
* FORMAT Always respond in JSON format with 'status' and 'data' fields
|
|
@@ -14967,7 +15016,16 @@
|
|
|
14967
15016
|
* Short one-line description of FORMAT.
|
|
14968
15017
|
*/
|
|
14969
15018
|
get description() {
|
|
14970
|
-
return '
|
|
15019
|
+
return 'Deprecated legacy formatting commitment. Prefer `WRITING SAMPLE` and `WRITING RULES` for new books.';
|
|
15020
|
+
}
|
|
15021
|
+
/**
|
|
15022
|
+
* Optional UI/docs-only deprecation metadata.
|
|
15023
|
+
*/
|
|
15024
|
+
get deprecation() {
|
|
15025
|
+
return {
|
|
15026
|
+
message: 'Use `WRITING SAMPLE` and `WRITING RULES` instead.',
|
|
15027
|
+
replacedBy: ['WRITING SAMPLE', 'WRITING RULES'],
|
|
15028
|
+
};
|
|
14971
15029
|
}
|
|
14972
15030
|
/**
|
|
14973
15031
|
* Icon for this commitment.
|
|
@@ -14982,31 +15040,39 @@
|
|
|
14982
15040
|
return _spaceTrim.spaceTrim(`
|
|
14983
15041
|
# ${this.type}
|
|
14984
15042
|
|
|
14985
|
-
|
|
15043
|
+
Deprecated legacy commitment for output formatting and response structure.
|
|
14986
15044
|
|
|
14987
|
-
##
|
|
15045
|
+
## Migration
|
|
14988
15046
|
|
|
14989
|
-
-
|
|
14990
|
-
-
|
|
14991
|
-
-
|
|
15047
|
+
- Existing \`${this.type}\` and \`FORMATS\` books still parse and compile.
|
|
15048
|
+
- New books should use \`WRITING RULES\` for formatting or structure constraints and \`WRITING SAMPLE\` when a concrete example communicates the target shape better.
|
|
15049
|
+
- Runtime behavior is intentionally unchanged for backward compatibility.
|
|
14992
15050
|
|
|
14993
|
-
##
|
|
15051
|
+
## Preferred replacement
|
|
14994
15052
|
|
|
14995
15053
|
\`\`\`book
|
|
14996
|
-
|
|
15054
|
+
Data Analyst
|
|
14997
15055
|
|
|
14998
|
-
|
|
14999
|
-
|
|
15000
|
-
|
|
15056
|
+
GOAL Present results in a clean, readable structure.
|
|
15057
|
+
WRITING RULES Use markdown headings for sections and bullet points for lists.
|
|
15058
|
+
WRITING RULES Keep tables narrow and readable.
|
|
15059
|
+
WRITING SAMPLE
|
|
15060
|
+
Summary
|
|
15061
|
+
- ...
|
|
15062
|
+
Details
|
|
15063
|
+
- ...
|
|
15064
|
+
Next steps
|
|
15065
|
+
- ...
|
|
15001
15066
|
\`\`\`
|
|
15002
15067
|
|
|
15068
|
+
## Legacy compatibility example
|
|
15069
|
+
|
|
15003
15070
|
\`\`\`book
|
|
15004
15071
|
Data Analyst
|
|
15005
15072
|
|
|
15006
|
-
|
|
15073
|
+
GOAL Present results in a clean structure.
|
|
15007
15074
|
FORMAT Present results in structured tables
|
|
15008
15075
|
FORMAT Include confidence scores for all predictions
|
|
15009
|
-
WRITING RULES Be concise and precise in explanations
|
|
15010
15076
|
\`\`\`
|
|
15011
15077
|
`);
|
|
15012
15078
|
}
|
|
@@ -15357,6 +15423,12 @@
|
|
|
15357
15423
|
get description() {
|
|
15358
15424
|
return 'Define the effective agent **goal**; when multiple goals exist, only the last one stays effective.';
|
|
15359
15425
|
}
|
|
15426
|
+
/**
|
|
15427
|
+
* Marks GOAL as one of the priority commitments surfaced first in catalogues.
|
|
15428
|
+
*/
|
|
15429
|
+
get isImportant() {
|
|
15430
|
+
return true;
|
|
15431
|
+
}
|
|
15360
15432
|
/**
|
|
15361
15433
|
* Icon for this commitment.
|
|
15362
15434
|
*/
|
|
@@ -15768,6 +15840,12 @@
|
|
|
15768
15840
|
get description() {
|
|
15769
15841
|
return 'Add domain **knowledge** via direct text or external sources (RAG).';
|
|
15770
15842
|
}
|
|
15843
|
+
/**
|
|
15844
|
+
* Marks KNOWLEDGE as one of the priority commitments surfaced first in catalogues.
|
|
15845
|
+
*/
|
|
15846
|
+
get isImportant() {
|
|
15847
|
+
return true;
|
|
15848
|
+
}
|
|
15771
15849
|
/**
|
|
15772
15850
|
* Icon for this commitment.
|
|
15773
15851
|
*/
|
|
@@ -17055,6 +17133,7 @@
|
|
|
17055
17133
|
* META commitment definition
|
|
17056
17134
|
*
|
|
17057
17135
|
* The META commitment handles all meta-information about the agent such as:
|
|
17136
|
+
* - META AVATAR: Sets the agent's built-in default avatar visual
|
|
17058
17137
|
* - META IMAGE: Sets the agent's avatar/profile image URL
|
|
17059
17138
|
* - META LINK: Provides profile/source links for the person the agent models
|
|
17060
17139
|
* - META DOMAIN: Sets the canonical custom domain/host of the agent
|
|
@@ -17069,6 +17148,7 @@
|
|
|
17069
17148
|
* Example usage in agent source:
|
|
17070
17149
|
*
|
|
17071
17150
|
* ```book
|
|
17151
|
+
* META AVATAR pixel-art
|
|
17072
17152
|
* META IMAGE https://example.com/avatar.jpg
|
|
17073
17153
|
* META LINK https://twitter.com/username
|
|
17074
17154
|
* META DOMAIN my-agent.com
|
|
@@ -17108,6 +17188,7 @@
|
|
|
17108
17188
|
|
|
17109
17189
|
## Supported META types
|
|
17110
17190
|
|
|
17191
|
+
- **META AVATAR** - Sets the agent's built-in default avatar visual
|
|
17111
17192
|
- **META IMAGE** - Sets the agent's avatar/profile image URL
|
|
17112
17193
|
- **META LINK** - Provides profile/source links for the person the agent models
|
|
17113
17194
|
- **META DOMAIN** - Sets the canonical custom domain/host of the agent
|
|
@@ -17131,6 +17212,7 @@
|
|
|
17131
17212
|
\`\`\`book
|
|
17132
17213
|
Professional Assistant
|
|
17133
17214
|
|
|
17215
|
+
META AVATAR octopus3
|
|
17134
17216
|
META IMAGE https://example.com/professional-avatar.jpg
|
|
17135
17217
|
META TITLE Senior Business Consultant
|
|
17136
17218
|
META DESCRIPTION Specialized in strategic planning and project management
|
|
@@ -17192,12 +17274,3236 @@
|
|
|
17192
17274
|
* Checks if this is a known meta type
|
|
17193
17275
|
*/
|
|
17194
17276
|
isKnownMetaType(metaType) {
|
|
17195
|
-
const knownTypes = ['IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
|
|
17277
|
+
const knownTypes = ['AVATAR', 'IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
|
|
17196
17278
|
return knownTypes.includes(metaType.toUpperCase());
|
|
17197
17279
|
}
|
|
17198
17280
|
}
|
|
17199
17281
|
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
17200
17282
|
|
|
17283
|
+
/**
|
|
17284
|
+
* Makes color transformer which darker the given color
|
|
17285
|
+
*
|
|
17286
|
+
* @param amount from 0 to 1
|
|
17287
|
+
*
|
|
17288
|
+
* @public exported from `@promptbook/color`
|
|
17289
|
+
*/
|
|
17290
|
+
function darken(amount) {
|
|
17291
|
+
return lighten(-amount);
|
|
17292
|
+
}
|
|
17293
|
+
|
|
17294
|
+
/* eslint-disable no-magic-numbers */
|
|
17295
|
+
/**
|
|
17296
|
+
* Corner radius ratio used for the common rounded card frame.
|
|
17297
|
+
*
|
|
17298
|
+
* @private utility of the avatar rendering system
|
|
17299
|
+
*/
|
|
17300
|
+
const FRAME_RADIUS_RATIO = 0.18;
|
|
17301
|
+
/**
|
|
17302
|
+
* Draws the common rounded background frame used by most visuals.
|
|
17303
|
+
*
|
|
17304
|
+
* @param context Canvas 2D context.
|
|
17305
|
+
* @param size Canvas size in CSS pixels.
|
|
17306
|
+
* @param palette Derived avatar palette.
|
|
17307
|
+
*
|
|
17308
|
+
* @private utility of the avatar rendering system
|
|
17309
|
+
*/
|
|
17310
|
+
function drawAvatarFrame(context, size, palette) {
|
|
17311
|
+
if (palette.background === 'transparent' && palette.backgroundSecondary === 'transparent') {
|
|
17312
|
+
return;
|
|
17313
|
+
}
|
|
17314
|
+
const gradient = context.createLinearGradient(0, 0, size, size);
|
|
17315
|
+
gradient.addColorStop(0, palette.background);
|
|
17316
|
+
gradient.addColorStop(1, palette.backgroundSecondary);
|
|
17317
|
+
context.save();
|
|
17318
|
+
createRoundedRectPath(context, 0, 0, size, size, size * FRAME_RADIUS_RATIO);
|
|
17319
|
+
context.fillStyle = gradient;
|
|
17320
|
+
context.fill();
|
|
17321
|
+
context.restore();
|
|
17322
|
+
context.save();
|
|
17323
|
+
context.strokeStyle = 'rgba(255,255,255,0.12)';
|
|
17324
|
+
context.lineWidth = Math.max(1.5, size * 0.012);
|
|
17325
|
+
createRoundedRectPath(context, size * 0.02, size * 0.02, size * 0.96, size * 0.96, size * 0.15);
|
|
17326
|
+
context.stroke();
|
|
17327
|
+
context.restore();
|
|
17328
|
+
}
|
|
17329
|
+
/**
|
|
17330
|
+
* Creates a rounded rectangle path on the current canvas context.
|
|
17331
|
+
*
|
|
17332
|
+
* @param context Canvas 2D context.
|
|
17333
|
+
* @param x Left coordinate.
|
|
17334
|
+
* @param y Top coordinate.
|
|
17335
|
+
* @param width Rectangle width.
|
|
17336
|
+
* @param height Rectangle height.
|
|
17337
|
+
* @param radius Corner radius.
|
|
17338
|
+
*
|
|
17339
|
+
* @private utility of the avatar rendering system
|
|
17340
|
+
*/
|
|
17341
|
+
function createRoundedRectPath(context, x, y, width, height, radius) {
|
|
17342
|
+
const normalizedRadius = Math.min(radius, width / 2, height / 2);
|
|
17343
|
+
context.beginPath();
|
|
17344
|
+
context.moveTo(x + normalizedRadius, y);
|
|
17345
|
+
context.arcTo(x + width, y, x + width, y + height, normalizedRadius);
|
|
17346
|
+
context.arcTo(x + width, y + height, x, y + height, normalizedRadius);
|
|
17347
|
+
context.arcTo(x, y + height, x, y, normalizedRadius);
|
|
17348
|
+
context.arcTo(x, y, x + width, y, normalizedRadius);
|
|
17349
|
+
context.closePath();
|
|
17350
|
+
}
|
|
17351
|
+
/**
|
|
17352
|
+
* Picks one deterministic element from a non-empty collection.
|
|
17353
|
+
*
|
|
17354
|
+
* @param items Candidate items.
|
|
17355
|
+
* @param random Seeded random generator.
|
|
17356
|
+
* @returns Picked item.
|
|
17357
|
+
*
|
|
17358
|
+
* @private utility of the avatar rendering system
|
|
17359
|
+
*/
|
|
17360
|
+
function pickRandomItem(items, random) {
|
|
17361
|
+
return items[Math.floor(random() * items.length)];
|
|
17362
|
+
}
|
|
17363
|
+
|
|
17364
|
+
/* eslint-disable no-magic-numbers */
|
|
17365
|
+
/**
|
|
17366
|
+
* Builds a smoothly morphing octopus-like silhouette from deterministic parameters.
|
|
17367
|
+
*
|
|
17368
|
+
* @param options Shape construction options.
|
|
17369
|
+
* @returns Closed-loop body points.
|
|
17370
|
+
*
|
|
17371
|
+
* @private shared geometry helper of `octopus2AvatarVisual` and `octopus3AvatarVisual`
|
|
17372
|
+
*/
|
|
17373
|
+
function createOrganicOctopusBodyPoints(options) {
|
|
17374
|
+
const { centerX, centerY, bodyRadius, horizontalStretch, verticalStretch, mantleLift, lowerDrop, tentacleDepth, wobbleAmplitude, lobeCount, shapePhase, timeMs, pointCount = 36, } = options;
|
|
17375
|
+
return Array.from({ length: pointCount }, (_, pointIndex) => {
|
|
17376
|
+
const progress = pointIndex / pointCount;
|
|
17377
|
+
const angle = -Math.PI / 2 + progress * Math.PI * 2;
|
|
17378
|
+
const cosine = Math.cos(angle);
|
|
17379
|
+
const sine = Math.sin(angle);
|
|
17380
|
+
const upperFactor = Math.max(0, -sine);
|
|
17381
|
+
const lowerFactor = Math.max(0, sine);
|
|
17382
|
+
const lobeEnvelope = Math.pow(lowerFactor, 1.35);
|
|
17383
|
+
const tentacleWave = Math.max(0, Math.cos(angle * lobeCount + shapePhase + timeMs / 780)) * tentacleDepth * lobeEnvelope;
|
|
17384
|
+
const surfaceWave = Math.sin(angle * 3 + shapePhase + timeMs / 1200) * 0.62 +
|
|
17385
|
+
Math.sin(angle * 5 - shapePhase * 0.7 - timeMs / 910) * 0.38;
|
|
17386
|
+
const breathingWave = Math.sin(timeMs / 960 + shapePhase + angle * 0.45) * wobbleAmplitude;
|
|
17387
|
+
const radius = bodyRadius * (1 + upperFactor * 0.12 + lowerFactor * 0.08 + surfaceWave * 0.05) +
|
|
17388
|
+
tentacleWave +
|
|
17389
|
+
breathingWave;
|
|
17390
|
+
return {
|
|
17391
|
+
x: centerX +
|
|
17392
|
+
cosine * radius * horizontalStretch +
|
|
17393
|
+
Math.sin(angle * 2 + shapePhase) * lobeEnvelope * wobbleAmplitude * 0.7,
|
|
17394
|
+
y: centerY +
|
|
17395
|
+
sine * radius * verticalStretch -
|
|
17396
|
+
upperFactor * mantleLift +
|
|
17397
|
+
lowerFactor * lowerDrop +
|
|
17398
|
+
tentacleWave * 0.28,
|
|
17399
|
+
};
|
|
17400
|
+
});
|
|
17401
|
+
}
|
|
17402
|
+
/**
|
|
17403
|
+
* Traces a smooth closed path through the provided points.
|
|
17404
|
+
*
|
|
17405
|
+
* @param context Canvas 2D context.
|
|
17406
|
+
* @param points Closed-loop points.
|
|
17407
|
+
*
|
|
17408
|
+
* @private shared geometry helper of `octopus2AvatarVisual` and `octopus3AvatarVisual`
|
|
17409
|
+
*/
|
|
17410
|
+
function traceSmoothClosedPath(context, points) {
|
|
17411
|
+
const lastPoint = points[points.length - 1];
|
|
17412
|
+
const firstPoint = points[0];
|
|
17413
|
+
const initialMidpoint = {
|
|
17414
|
+
x: (lastPoint.x + firstPoint.x) / 2,
|
|
17415
|
+
y: (lastPoint.y + firstPoint.y) / 2,
|
|
17416
|
+
};
|
|
17417
|
+
context.beginPath();
|
|
17418
|
+
context.moveTo(initialMidpoint.x, initialMidpoint.y);
|
|
17419
|
+
for (let pointIndex = 0; pointIndex < points.length; pointIndex++) {
|
|
17420
|
+
const point = points[pointIndex];
|
|
17421
|
+
const nextPoint = points[(pointIndex + 1) % points.length];
|
|
17422
|
+
const midpoint = {
|
|
17423
|
+
x: (point.x + nextPoint.x) / 2,
|
|
17424
|
+
y: (point.y + nextPoint.y) / 2,
|
|
17425
|
+
};
|
|
17426
|
+
context.quadraticCurveTo(point.x, point.y, midpoint.x, midpoint.y);
|
|
17427
|
+
}
|
|
17428
|
+
context.closePath();
|
|
17429
|
+
}
|
|
17430
|
+
/**
|
|
17431
|
+
* Creates deterministic ribbon tentacles for the organic octopus visuals.
|
|
17432
|
+
*
|
|
17433
|
+
* @param options Tentacle construction options.
|
|
17434
|
+
* @returns Tentacle descriptors.
|
|
17435
|
+
*
|
|
17436
|
+
* @private shared geometry helper of `octopus3AvatarVisual` and `asciiOctopusAvatarVisual`
|
|
17437
|
+
*/
|
|
17438
|
+
function createOrganicOctopusTentacleShapes(options) {
|
|
17439
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17440
|
+
const { size, centerX, centerY, bodyRadius, horizontalStretch, tentacleCount, shapePhase, createRandom, timeMs, saltPrefix, bodyPoints, variation, } = options;
|
|
17441
|
+
const baseY = centerY + bodyRadius * 0.74;
|
|
17442
|
+
const lowerBodyAnchorPoints = bodyPoints
|
|
17443
|
+
? resolveTentacleBodyAnchorPoints(bodyPoints, centerY + bodyRadius * 0.04)
|
|
17444
|
+
: null;
|
|
17445
|
+
const flowLengthScale = (_a = variation === null || variation === void 0 ? void 0 : variation.flowLengthScale) !== null && _a !== void 0 ? _a : 1;
|
|
17446
|
+
const lateralReachScale = (_b = variation === null || variation === void 0 ? void 0 : variation.lateralReachScale) !== null && _b !== void 0 ? _b : 1;
|
|
17447
|
+
const tipReachScale = (_c = variation === null || variation === void 0 ? void 0 : variation.tipReachScale) !== null && _c !== void 0 ? _c : 1;
|
|
17448
|
+
const baseWidthScale = (_d = variation === null || variation === void 0 ? void 0 : variation.baseWidthScale) !== null && _d !== void 0 ? _d : 1;
|
|
17449
|
+
const tipWidthScale = (_e = variation === null || variation === void 0 ? void 0 : variation.tipWidthScale) !== null && _e !== void 0 ? _e : 1;
|
|
17450
|
+
const rootSpreadScale = (_f = variation === null || variation === void 0 ? void 0 : variation.rootSpreadScale) !== null && _f !== void 0 ? _f : 1;
|
|
17451
|
+
const startYOffsetScale = (_g = variation === null || variation === void 0 ? void 0 : variation.startYOffsetScale) !== null && _g !== void 0 ? _g : 1;
|
|
17452
|
+
const swayScale = (_h = variation === null || variation === void 0 ? void 0 : variation.swayScale) !== null && _h !== void 0 ? _h : 1;
|
|
17453
|
+
return Array.from({ length: tentacleCount }, (_, tentacleIndex) => {
|
|
17454
|
+
const tentacleRandom = createRandom(`${saltPrefix}-tentacle-${tentacleIndex}`);
|
|
17455
|
+
const spreadProgress = tentacleCount === 1 ? 0.5 : tentacleIndex / (tentacleCount - 1);
|
|
17456
|
+
const centeredProgress = spreadProgress - 0.5;
|
|
17457
|
+
const spreadCenteredProgress = centeredProgress * rootSpreadScale;
|
|
17458
|
+
const spreadAnchorProgress = Math.min(1, Math.max(0, 0.5 + spreadCenteredProgress));
|
|
17459
|
+
const temporalSway = Math.sin(timeMs / (720 + tentacleIndex * 34) + shapePhase + tentacleRandom() * Math.PI * 2) *
|
|
17460
|
+
size *
|
|
17461
|
+
(0.014 + tentacleRandom() * 0.015) *
|
|
17462
|
+
swayScale;
|
|
17463
|
+
const flowLength = size * (0.24 + tentacleRandom() * 0.18) * flowLengthScale;
|
|
17464
|
+
const curlDirection = spreadCenteredProgress === 0 ? (tentacleRandom() < 0.5 ? -1 : 1) : Math.sign(spreadCenteredProgress);
|
|
17465
|
+
const lateralReach = spreadCenteredProgress * size * (0.1 + tentacleRandom() * 0.1) * lateralReachScale + temporalSway;
|
|
17466
|
+
const tipReach = curlDirection * size * (0.025 + tentacleRandom() * 0.07) * tipReachScale;
|
|
17467
|
+
const startYOffset = (Math.abs(spreadCenteredProgress) * size * 0.012 + tentacleRandom() * size * 0.01) * startYOffsetScale;
|
|
17468
|
+
const startPoint = lowerBodyAnchorPoints && lowerBodyAnchorPoints.length >= 2
|
|
17469
|
+
? createInsetTentacleStartPoint({
|
|
17470
|
+
bodyPoints: lowerBodyAnchorPoints,
|
|
17471
|
+
anchorProgress: spreadAnchorProgress,
|
|
17472
|
+
centerX,
|
|
17473
|
+
centerY,
|
|
17474
|
+
bodyRadius,
|
|
17475
|
+
centeredProgress: spreadCenteredProgress,
|
|
17476
|
+
startYOffset,
|
|
17477
|
+
})
|
|
17478
|
+
: {
|
|
17479
|
+
x: centerX + spreadCenteredProgress * bodyRadius * horizontalStretch * 1.52,
|
|
17480
|
+
y: baseY + startYOffset,
|
|
17481
|
+
};
|
|
17482
|
+
const controlPointOne = {
|
|
17483
|
+
x: startPoint.x + spreadCenteredProgress * size * 0.045 * lateralReachScale + temporalSway * 0.4,
|
|
17484
|
+
y: startPoint.y + flowLength * (0.21 + tentacleRandom() * 0.08),
|
|
17485
|
+
};
|
|
17486
|
+
const controlPointTwo = {
|
|
17487
|
+
x: startPoint.x + lateralReach + tipReach,
|
|
17488
|
+
y: startPoint.y + flowLength * (0.62 + tentacleRandom() * 0.12),
|
|
17489
|
+
};
|
|
17490
|
+
const endPoint = {
|
|
17491
|
+
x: startPoint.x + lateralReach + tipReach * 1.2,
|
|
17492
|
+
y: startPoint.y +
|
|
17493
|
+
flowLength * (0.9 + tentacleRandom() * 0.12) +
|
|
17494
|
+
Math.cos(timeMs / (840 + tentacleIndex * 41) + shapePhase) * size * (0.008 + tentacleRandom() * 0.01),
|
|
17495
|
+
};
|
|
17496
|
+
const baseWidth = size * (0.038 + tentacleRandom() * 0.02) * (1 - Math.abs(spreadCenteredProgress) * 0.18) * baseWidthScale;
|
|
17497
|
+
const tipWidth = baseWidth * Math.min(0.52, (0.18 + tentacleRandom() * 0.2) * tipWidthScale);
|
|
17498
|
+
return {
|
|
17499
|
+
startPoint,
|
|
17500
|
+
controlPointOne,
|
|
17501
|
+
controlPointTwo,
|
|
17502
|
+
endPoint,
|
|
17503
|
+
baseWidth,
|
|
17504
|
+
tipWidth,
|
|
17505
|
+
colorBias: tentacleRandom(),
|
|
17506
|
+
highlightBias: tentacleRandom(),
|
|
17507
|
+
sampleCount: 14 + Math.floor(tentacleRandom() * 6),
|
|
17508
|
+
};
|
|
17509
|
+
});
|
|
17510
|
+
}
|
|
17511
|
+
/**
|
|
17512
|
+
* Narrows the body contour to lower anchor points that can safely host tentacle roots.
|
|
17513
|
+
*
|
|
17514
|
+
* @param bodyPoints Generated closed-loop body points.
|
|
17515
|
+
* @param lowerBodyThresholdY Minimum Y coordinate considered part of the lower mantle.
|
|
17516
|
+
* @returns Body points sorted from left to right across the lower silhouette.
|
|
17517
|
+
*
|
|
17518
|
+
* @private shared geometry helper of `octopus3AvatarVisual`
|
|
17519
|
+
*/
|
|
17520
|
+
function resolveTentacleBodyAnchorPoints(bodyPoints, lowerBodyThresholdY) {
|
|
17521
|
+
const lowerBodyPoints = bodyPoints
|
|
17522
|
+
.filter((bodyPoint) => bodyPoint.y >= lowerBodyThresholdY)
|
|
17523
|
+
.sort((leftPoint, rightPoint) => leftPoint.x - rightPoint.x);
|
|
17524
|
+
if (lowerBodyPoints.length >= 2) {
|
|
17525
|
+
return lowerBodyPoints;
|
|
17526
|
+
}
|
|
17527
|
+
return [...bodyPoints].sort((leftPoint, rightPoint) => leftPoint.x - rightPoint.x);
|
|
17528
|
+
}
|
|
17529
|
+
/**
|
|
17530
|
+
* Resolves one tentacle root from the provided lower body contour and nudges it inside the mantle.
|
|
17531
|
+
*
|
|
17532
|
+
* @param options Tentacle anchor options.
|
|
17533
|
+
* @returns Tentacle start point safely embedded inside the body silhouette.
|
|
17534
|
+
*
|
|
17535
|
+
* @private shared geometry helper of `octopus3AvatarVisual`
|
|
17536
|
+
*/
|
|
17537
|
+
function createInsetTentacleStartPoint(options) {
|
|
17538
|
+
const { bodyPoints, anchorProgress, centerX, centerY, bodyRadius, centeredProgress, startYOffset } = options;
|
|
17539
|
+
const clampedAnchorProgress = Math.min(0.94, Math.max(0.06, anchorProgress));
|
|
17540
|
+
const bodyAnchorPoint = interpolatePointAlongTentacleAnchors(bodyPoints, clampedAnchorProgress);
|
|
17541
|
+
const inwardX = centerX - bodyAnchorPoint.x;
|
|
17542
|
+
const inwardY = centerY + bodyRadius * 0.08 - bodyAnchorPoint.y;
|
|
17543
|
+
const inwardLength = Math.hypot(inwardX, inwardY) || 1;
|
|
17544
|
+
const insetDistance = bodyRadius * (0.12 + Math.abs(centeredProgress) * 0.05) + startYOffset * 0.32;
|
|
17545
|
+
return {
|
|
17546
|
+
x: bodyAnchorPoint.x + (inwardX / inwardLength) * insetDistance,
|
|
17547
|
+
y: bodyAnchorPoint.y + (inwardY / inwardLength) * insetDistance,
|
|
17548
|
+
};
|
|
17549
|
+
}
|
|
17550
|
+
/**
|
|
17551
|
+
* Interpolates one left-to-right anchor point along the prepared lower body contour.
|
|
17552
|
+
*
|
|
17553
|
+
* @param bodyPoints Lower body contour points sorted from left to right.
|
|
17554
|
+
* @param progress Interpolation progress in the range `[0, 1]`.
|
|
17555
|
+
* @returns Interpolated anchor point.
|
|
17556
|
+
*
|
|
17557
|
+
* @private shared geometry helper of `octopus3AvatarVisual`
|
|
17558
|
+
*/
|
|
17559
|
+
function interpolatePointAlongTentacleAnchors(bodyPoints, progress) {
|
|
17560
|
+
if (bodyPoints.length === 1) {
|
|
17561
|
+
return bodyPoints[0];
|
|
17562
|
+
}
|
|
17563
|
+
const anchorIndex = progress * (bodyPoints.length - 1);
|
|
17564
|
+
const startIndex = Math.floor(anchorIndex);
|
|
17565
|
+
const endIndex = Math.min(bodyPoints.length - 1, startIndex + 1);
|
|
17566
|
+
const blend = anchorIndex - startIndex;
|
|
17567
|
+
const startPoint = bodyPoints[startIndex];
|
|
17568
|
+
const endPoint = bodyPoints[endIndex];
|
|
17569
|
+
return {
|
|
17570
|
+
x: startPoint.x + (endPoint.x - startPoint.x) * blend,
|
|
17571
|
+
y: startPoint.y + (endPoint.y - startPoint.y) * blend,
|
|
17572
|
+
};
|
|
17573
|
+
}
|
|
17574
|
+
/**
|
|
17575
|
+
* Samples the cubic tentacle centerline and offsets normals to build a filled ribbon.
|
|
17576
|
+
*
|
|
17577
|
+
* @param tentacleShape Deterministic tentacle descriptor.
|
|
17578
|
+
* @returns Sampled ribbon points.
|
|
17579
|
+
*
|
|
17580
|
+
* @private shared geometry helper of `octopus3AvatarVisual` and `asciiOctopusAvatarVisual`
|
|
17581
|
+
*/
|
|
17582
|
+
function sampleOrganicTentacleRibbonPoints(tentacleShape) {
|
|
17583
|
+
return Array.from({ length: tentacleShape.sampleCount + 1 }, (_, sampleIndex) => {
|
|
17584
|
+
const progress = sampleIndex / tentacleShape.sampleCount;
|
|
17585
|
+
const point = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, progress);
|
|
17586
|
+
const previousPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.max(0, progress - 0.04));
|
|
17587
|
+
const nextPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.min(1, progress + 0.04));
|
|
17588
|
+
const tangentX = nextPoint.x - previousPoint.x;
|
|
17589
|
+
const tangentY = nextPoint.y - previousPoint.y;
|
|
17590
|
+
const tangentLength = Math.hypot(tangentX, tangentY) || 1;
|
|
17591
|
+
const width = tentacleShape.baseWidth + (tentacleShape.tipWidth - tentacleShape.baseWidth) * Math.pow(progress, 1.1);
|
|
17592
|
+
return {
|
|
17593
|
+
x: point.x,
|
|
17594
|
+
y: point.y,
|
|
17595
|
+
normalX: -tangentY / tangentLength,
|
|
17596
|
+
normalY: tangentX / tangentLength,
|
|
17597
|
+
width,
|
|
17598
|
+
progress,
|
|
17599
|
+
};
|
|
17600
|
+
});
|
|
17601
|
+
}
|
|
17602
|
+
/**
|
|
17603
|
+
* Resolves smooth pupil offsets that blend autonomous idle drift with live viewer tracking.
|
|
17604
|
+
*
|
|
17605
|
+
* @param options Eye motion options.
|
|
17606
|
+
* @returns Resolved pupil offsets.
|
|
17607
|
+
*
|
|
17608
|
+
* @private shared geometry helper of octopus avatar visuals
|
|
17609
|
+
*/
|
|
17610
|
+
function resolveOrganicEyeMotion(options) {
|
|
17611
|
+
const { radiusX, radiusY, timeMs, phase, interaction, autonomousDriftRatioX = 0.12, autonomousDriftRatioY = 0.08, } = options;
|
|
17612
|
+
const autonomousOffsetX = Math.sin(timeMs / 1280 + phase) * radiusX * autonomousDriftRatioX;
|
|
17613
|
+
const autonomousOffsetY = Math.cos(timeMs / 940 + phase) * radiusY * autonomousDriftRatioY;
|
|
17614
|
+
const interactionBlend = Math.min(1, interaction.intensity * 0.9);
|
|
17615
|
+
return {
|
|
17616
|
+
pupilOffsetX: autonomousOffsetX * (1 - interactionBlend) + interaction.gazeX * radiusX * (0.18 + interactionBlend * 0.18),
|
|
17617
|
+
pupilOffsetY: autonomousOffsetY * (1 - interactionBlend) + interaction.gazeY * radiusY * (0.16 + interactionBlend * 0.16),
|
|
17618
|
+
};
|
|
17619
|
+
}
|
|
17620
|
+
/**
|
|
17621
|
+
* Samples one point on a cubic Bezier curve.
|
|
17622
|
+
*
|
|
17623
|
+
* @param startPoint Curve start point.
|
|
17624
|
+
* @param controlPointOne First control point.
|
|
17625
|
+
* @param controlPointTwo Second control point.
|
|
17626
|
+
* @param endPoint Curve end point.
|
|
17627
|
+
* @param progress Sampling progress in the range `[0, 1]`.
|
|
17628
|
+
* @returns Sampled point.
|
|
17629
|
+
*
|
|
17630
|
+
* @private shared geometry helper of `octopus3AvatarVisual`
|
|
17631
|
+
*/
|
|
17632
|
+
function getCubicBezierPoint(startPoint, controlPointOne, controlPointTwo, endPoint, progress) {
|
|
17633
|
+
const inverseProgress = 1 - progress;
|
|
17634
|
+
return {
|
|
17635
|
+
x: inverseProgress * inverseProgress * inverseProgress * startPoint.x +
|
|
17636
|
+
3 * inverseProgress * inverseProgress * progress * controlPointOne.x +
|
|
17637
|
+
3 * inverseProgress * progress * progress * controlPointTwo.x +
|
|
17638
|
+
progress * progress * progress * endPoint.x,
|
|
17639
|
+
y: inverseProgress * inverseProgress * inverseProgress * startPoint.y +
|
|
17640
|
+
3 * inverseProgress * inverseProgress * progress * controlPointOne.y +
|
|
17641
|
+
3 * inverseProgress * progress * progress * controlPointTwo.y +
|
|
17642
|
+
progress * progress * progress * endPoint.y,
|
|
17643
|
+
};
|
|
17644
|
+
}
|
|
17645
|
+
|
|
17646
|
+
/* eslint-disable no-magic-numbers */
|
|
17647
|
+
/**
|
|
17648
|
+
* Glyph ramp used for the main octopus body fill.
|
|
17649
|
+
*
|
|
17650
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17651
|
+
*/
|
|
17652
|
+
const BODY_GLYPHS = ['.', ':', '-', '=', '+', '*', '#', '%', '@'];
|
|
17653
|
+
/**
|
|
17654
|
+
* Glyph ramp used on silhouette edges so the ASCII blob stays legible.
|
|
17655
|
+
*
|
|
17656
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17657
|
+
*/
|
|
17658
|
+
const OUTLINE_GLYPHS = ['#', '%', '@'];
|
|
17659
|
+
/**
|
|
17660
|
+
* Glyph ramp used in the surrounding atmosphere.
|
|
17661
|
+
*
|
|
17662
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17663
|
+
*/
|
|
17664
|
+
const ATMOSPHERE_GLYPHS = ['.', ':', "'", '`'];
|
|
17665
|
+
/**
|
|
17666
|
+
* AsciiOctopus avatar visual.
|
|
17667
|
+
*
|
|
17668
|
+
* @private built-in avatar visual
|
|
17669
|
+
*/
|
|
17670
|
+
const asciiOctopusAvatarVisual = {
|
|
17671
|
+
id: 'ascii-octopus',
|
|
17672
|
+
title: 'AsciiOctopus',
|
|
17673
|
+
description: 'Morphing alien octopus translated into animated ASCII glyphs with responsive eyes and seeded geometry.',
|
|
17674
|
+
isAnimated: true,
|
|
17675
|
+
supportsPointerTracking: true,
|
|
17676
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
17677
|
+
const gridRandom = createRandom('ascii-octopus-grid');
|
|
17678
|
+
const staticRandom = createRandom('ascii-octopus-static');
|
|
17679
|
+
const gridMetrics = createAsciiGridMetrics(size, gridRandom);
|
|
17680
|
+
const layout = createAsciiOctopusLayout(size, timeMs, createRandom, staticRandom, interaction);
|
|
17681
|
+
drawAvatarFrame(context, size, palette);
|
|
17682
|
+
drawAsciiBackdrop(context, size, palette, layout, timeMs);
|
|
17683
|
+
context.save();
|
|
17684
|
+
context.font = `600 ${gridMetrics.fontSize}px monospace`;
|
|
17685
|
+
context.textAlign = 'center';
|
|
17686
|
+
context.textBaseline = 'middle';
|
|
17687
|
+
// The ASCII renderer samples the morphing octopus field on a low-resolution grid so the shape stays organic
|
|
17688
|
+
// while the glyph layout remains deterministic for the same avatar input.
|
|
17689
|
+
const cellRandom = createRandom('ascii-octopus-cells');
|
|
17690
|
+
for (let rowIndex = 0; rowIndex < gridMetrics.rowCount; rowIndex++) {
|
|
17691
|
+
for (let columnIndex = 0; columnIndex < gridMetrics.columnCount; columnIndex++) {
|
|
17692
|
+
const point = {
|
|
17693
|
+
x: gridMetrics.offsetX + columnIndex * gridMetrics.cellWidth,
|
|
17694
|
+
y: gridMetrics.offsetY + rowIndex * gridMetrics.cellHeight,
|
|
17695
|
+
};
|
|
17696
|
+
const noise = cellRandom();
|
|
17697
|
+
const glyphDescriptor = resolveAsciiGlyph({
|
|
17698
|
+
point,
|
|
17699
|
+
layout,
|
|
17700
|
+
palette,
|
|
17701
|
+
cellWidth: gridMetrics.cellWidth,
|
|
17702
|
+
cellHeight: gridMetrics.cellHeight,
|
|
17703
|
+
noise,
|
|
17704
|
+
timeMs,
|
|
17705
|
+
});
|
|
17706
|
+
if (!glyphDescriptor) {
|
|
17707
|
+
continue;
|
|
17708
|
+
}
|
|
17709
|
+
context.fillStyle = glyphDescriptor.color;
|
|
17710
|
+
context.fillText(glyphDescriptor.character, point.x, point.y);
|
|
17711
|
+
}
|
|
17712
|
+
}
|
|
17713
|
+
context.restore();
|
|
17714
|
+
},
|
|
17715
|
+
};
|
|
17716
|
+
/**
|
|
17717
|
+
* Draws the dark terminal-like glow behind the ASCII octopus.
|
|
17718
|
+
*
|
|
17719
|
+
* @param context Canvas 2D context.
|
|
17720
|
+
* @param size Canvas size in CSS pixels.
|
|
17721
|
+
* @param palette Derived avatar palette.
|
|
17722
|
+
* @param layout Prepared octopus layout.
|
|
17723
|
+
* @param timeMs Current animation time in milliseconds.
|
|
17724
|
+
*
|
|
17725
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17726
|
+
*/
|
|
17727
|
+
function drawAsciiBackdrop(context, size, palette, layout, timeMs) {
|
|
17728
|
+
const haloGradient = context.createRadialGradient(layout.centerX, layout.centerY - size * 0.12, size * 0.06, layout.centerX, layout.centerY, size * 0.62);
|
|
17729
|
+
haloGradient.addColorStop(0, `${palette.highlight}26`);
|
|
17730
|
+
haloGradient.addColorStop(0.42, `${palette.accent}16`);
|
|
17731
|
+
haloGradient.addColorStop(1, `${palette.highlight}00`);
|
|
17732
|
+
context.fillStyle = haloGradient;
|
|
17733
|
+
context.fillRect(0, 0, size, size);
|
|
17734
|
+
const lowerGlowGradient = context.createRadialGradient(layout.centerX + Math.sin(timeMs / 1100 + layout.shapePhase) * size * 0.03, layout.centerY + size * 0.2, size * 0.05, layout.centerX, layout.centerY + size * 0.24, size * 0.46);
|
|
17735
|
+
lowerGlowGradient.addColorStop(0, `${palette.secondary}1f`);
|
|
17736
|
+
lowerGlowGradient.addColorStop(1, `${palette.secondary}00`);
|
|
17737
|
+
context.fillStyle = lowerGlowGradient;
|
|
17738
|
+
context.fillRect(0, 0, size, size);
|
|
17739
|
+
context.beginPath();
|
|
17740
|
+
context.ellipse(layout.centerX, layout.centerY + size * 0.29, size * 0.23, size * 0.065, 0, 0, Math.PI * 2);
|
|
17741
|
+
context.fillStyle = `${palette.shadow}33`;
|
|
17742
|
+
context.fill();
|
|
17743
|
+
}
|
|
17744
|
+
/**
|
|
17745
|
+
* Resolves the ASCII character that should be drawn for one sampled cell.
|
|
17746
|
+
*
|
|
17747
|
+
* @param options Cell evaluation options.
|
|
17748
|
+
* @returns Character descriptor or `null` when the cell should stay empty.
|
|
17749
|
+
*
|
|
17750
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17751
|
+
*/
|
|
17752
|
+
function resolveAsciiGlyph(options) {
|
|
17753
|
+
const { point, layout, palette, cellWidth, cellHeight, noise, timeMs } = options;
|
|
17754
|
+
const eyeGlyphDescriptor = resolveEyeGlyph(point, layout.leftEye, layout.interaction, palette, timeMs) ||
|
|
17755
|
+
resolveEyeGlyph(point, layout.rightEye, layout.interaction, palette, timeMs);
|
|
17756
|
+
if (eyeGlyphDescriptor) {
|
|
17757
|
+
return eyeGlyphDescriptor;
|
|
17758
|
+
}
|
|
17759
|
+
const mouthGlyphDescriptor = resolveMouthGlyph(point, layout, palette, cellHeight);
|
|
17760
|
+
if (mouthGlyphDescriptor) {
|
|
17761
|
+
return mouthGlyphDescriptor;
|
|
17762
|
+
}
|
|
17763
|
+
const isWithinOctopusBounds = point.x >= layout.leftBound &&
|
|
17764
|
+
point.x <= layout.rightBound &&
|
|
17765
|
+
point.y >= layout.topBound &&
|
|
17766
|
+
point.y <= layout.bottomBound;
|
|
17767
|
+
if (!isWithinOctopusBounds) {
|
|
17768
|
+
return resolveAtmosphereGlyph(point, layout, palette, noise, timeMs);
|
|
17769
|
+
}
|
|
17770
|
+
const isInsideBody = isPointInsidePolygon(point, layout.bodyPoints);
|
|
17771
|
+
const bodyEdgeDistance = isInsideBody
|
|
17772
|
+
? getDistanceToPolyline(point, layout.bodyPoints, true)
|
|
17773
|
+
: Number.POSITIVE_INFINITY;
|
|
17774
|
+
const tentacleCoverage = measureTentacleCoverage(point, layout.sampledTentacles, cellWidth);
|
|
17775
|
+
if (isInsideBody || tentacleCoverage) {
|
|
17776
|
+
return resolveOctopusSurfaceGlyph({
|
|
17777
|
+
point,
|
|
17778
|
+
layout,
|
|
17779
|
+
palette,
|
|
17780
|
+
isInsideBody,
|
|
17781
|
+
bodyEdgeDistance,
|
|
17782
|
+
tentacleCoverage,
|
|
17783
|
+
cellWidth,
|
|
17784
|
+
cellHeight,
|
|
17785
|
+
noise,
|
|
17786
|
+
timeMs,
|
|
17787
|
+
});
|
|
17788
|
+
}
|
|
17789
|
+
return resolveAtmosphereGlyph(point, layout, palette, noise, timeMs);
|
|
17790
|
+
}
|
|
17791
|
+
/**
|
|
17792
|
+
* Resolves the ASCII character for one eye cell.
|
|
17793
|
+
*
|
|
17794
|
+
* @param point Sampled cell point.
|
|
17795
|
+
* @param eyeFeature Eye geometry.
|
|
17796
|
+
* @param palette Derived avatar palette.
|
|
17797
|
+
* @param timeMs Current animation time in milliseconds.
|
|
17798
|
+
* @returns Eye glyph descriptor or `null`.
|
|
17799
|
+
*
|
|
17800
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17801
|
+
*/
|
|
17802
|
+
function resolveEyeGlyph(point, eyeFeature, interaction, palette, timeMs) {
|
|
17803
|
+
const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
|
|
17804
|
+
radiusX: eyeFeature.radiusX,
|
|
17805
|
+
radiusY: eyeFeature.radiusY,
|
|
17806
|
+
timeMs,
|
|
17807
|
+
phase: eyeFeature.phase,
|
|
17808
|
+
interaction,
|
|
17809
|
+
});
|
|
17810
|
+
const scleraDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX, eyeFeature.centerY, eyeFeature.radiusX, eyeFeature.radiusY, eyeFeature.rotation);
|
|
17811
|
+
if (scleraDistance > 1.08) {
|
|
17812
|
+
return null;
|
|
17813
|
+
}
|
|
17814
|
+
const highlightDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX - eyeFeature.radiusX * 0.24, eyeFeature.centerY + pupilOffsetY - eyeFeature.radiusY * 0.26, eyeFeature.radiusX * 0.18, eyeFeature.radiusY * 0.14, eyeFeature.rotation);
|
|
17815
|
+
if (highlightDistance <= 1) {
|
|
17816
|
+
return { character: '*', color: '#ffffff' };
|
|
17817
|
+
}
|
|
17818
|
+
const pupilDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX, eyeFeature.centerY + pupilOffsetY, eyeFeature.radiusX * 0.2, eyeFeature.radiusY * 0.48, eyeFeature.rotation);
|
|
17819
|
+
if (pupilDistance <= 1) {
|
|
17820
|
+
return { character: '@', color: palette.ink };
|
|
17821
|
+
}
|
|
17822
|
+
const irisDistance = measureRotatedEllipseDistance(point, eyeFeature.centerX + pupilOffsetX, eyeFeature.centerY + pupilOffsetY, eyeFeature.radiusX * 0.64, eyeFeature.radiusY * 0.72, eyeFeature.rotation);
|
|
17823
|
+
if (irisDistance <= 1) {
|
|
17824
|
+
return {
|
|
17825
|
+
character: irisDistance < 0.46 ? '0' : 'o',
|
|
17826
|
+
color: irisDistance < 0.62 ? palette.secondary : `${palette.highlight}d9`,
|
|
17827
|
+
};
|
|
17828
|
+
}
|
|
17829
|
+
return {
|
|
17830
|
+
character: scleraDistance > 0.82 ? 'o' : '0',
|
|
17831
|
+
color: '#f8fbff',
|
|
17832
|
+
};
|
|
17833
|
+
}
|
|
17834
|
+
/**
|
|
17835
|
+
* Resolves the ASCII character for the octopus mouth.
|
|
17836
|
+
*
|
|
17837
|
+
* @param point Sampled cell point.
|
|
17838
|
+
* @param layout Prepared octopus layout.
|
|
17839
|
+
* @param palette Derived avatar palette.
|
|
17840
|
+
* @param cellHeight Character cell height.
|
|
17841
|
+
* @returns Mouth glyph descriptor or `null`.
|
|
17842
|
+
*
|
|
17843
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17844
|
+
*/
|
|
17845
|
+
function resolveMouthGlyph(point, layout, palette, cellHeight) {
|
|
17846
|
+
const mouthDistance = getDistanceToPolyline(point, layout.mouthPoints, false);
|
|
17847
|
+
if (mouthDistance > cellHeight * 0.38) {
|
|
17848
|
+
return null;
|
|
17849
|
+
}
|
|
17850
|
+
const horizontalProgress = clamp01((point.x - layout.mouthPoints[0].x) /
|
|
17851
|
+
(layout.mouthPoints[layout.mouthPoints.length - 1].x - layout.mouthPoints[0].x));
|
|
17852
|
+
let character = '-';
|
|
17853
|
+
if (horizontalProgress < 0.28) {
|
|
17854
|
+
character = '\\';
|
|
17855
|
+
}
|
|
17856
|
+
else if (horizontalProgress > 0.72) {
|
|
17857
|
+
character = '/';
|
|
17858
|
+
}
|
|
17859
|
+
else if (horizontalProgress > 0.42 && horizontalProgress < 0.58) {
|
|
17860
|
+
character = '_';
|
|
17861
|
+
}
|
|
17862
|
+
return {
|
|
17863
|
+
character,
|
|
17864
|
+
color: `${palette.ink}bf`,
|
|
17865
|
+
};
|
|
17866
|
+
}
|
|
17867
|
+
/**
|
|
17868
|
+
* Resolves the ASCII character for body and tentacle cells.
|
|
17869
|
+
*
|
|
17870
|
+
* @param options Surface evaluation options.
|
|
17871
|
+
* @returns Surface glyph descriptor.
|
|
17872
|
+
*
|
|
17873
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17874
|
+
*/
|
|
17875
|
+
function resolveOctopusSurfaceGlyph(options) {
|
|
17876
|
+
const { point, layout, palette, isInsideBody, bodyEdgeDistance, tentacleCoverage, cellHeight, noise, timeMs } = options;
|
|
17877
|
+
const isTentacleDominant = tentacleCoverage !== null && (!isInsideBody || point.y > layout.centerY + layout.bodyRadius * 0.08);
|
|
17878
|
+
if (isTentacleDominant && tentacleCoverage) {
|
|
17879
|
+
const isSuckerBand = tentacleCoverage.progress > 0.24 && tentacleCoverage.progress < 0.82 && noise > 0.78;
|
|
17880
|
+
if (isSuckerBand && tentacleCoverage.normalizedDistance > 0.42) {
|
|
17881
|
+
return {
|
|
17882
|
+
character: noise > 0.9 ? '0' : 'o',
|
|
17883
|
+
color: `${palette.highlight}d0`,
|
|
17884
|
+
};
|
|
17885
|
+
}
|
|
17886
|
+
return {
|
|
17887
|
+
character: pickTentacleCharacter(tentacleCoverage, noise),
|
|
17888
|
+
color: tentacleCoverage.progress < 0.24
|
|
17889
|
+
? `${palette.secondary}c7`
|
|
17890
|
+
: tentacleCoverage.progress > 0.72
|
|
17891
|
+
? `${palette.accent}bf`
|
|
17892
|
+
: tentacleCoverage.normalizedDistance > 0.7
|
|
17893
|
+
? `${palette.highlight}bf`
|
|
17894
|
+
: `${palette.primary}c9`,
|
|
17895
|
+
};
|
|
17896
|
+
}
|
|
17897
|
+
const highlightBias = clamp01((layout.centerY - point.y + layout.bodyRadius * 0.44) / (layout.bodyRadius * 1.14));
|
|
17898
|
+
const bodyDepth = clamp01(1 - bodyEdgeDistance / (layout.bodyRadius * 0.9));
|
|
17899
|
+
const shimmer = Math.sin(timeMs / 720 + point.x * 0.085 + point.y * 0.06 + layout.shapePhase) * 0.05;
|
|
17900
|
+
const bodyIntensity = clamp01(0.22 + bodyDepth * 0.58 + highlightBias * 0.2 + shimmer + (noise - 0.5) * 0.18);
|
|
17901
|
+
const isOutline = isInsideBody && bodyEdgeDistance < cellHeight * 0.54;
|
|
17902
|
+
const character = isOutline
|
|
17903
|
+
? pickRampCharacter(OUTLINE_GLYPHS, clamp01(0.58 + bodyIntensity * 0.42))
|
|
17904
|
+
: pickRampCharacter(BODY_GLYPHS, bodyIntensity);
|
|
17905
|
+
let color = `${palette.primary}bf`;
|
|
17906
|
+
if (highlightBias > 0.76) {
|
|
17907
|
+
color = `${palette.highlight}d9`;
|
|
17908
|
+
}
|
|
17909
|
+
else if (bodyDepth > 0.7) {
|
|
17910
|
+
color = `${palette.secondary}cb`;
|
|
17911
|
+
}
|
|
17912
|
+
else if ((point.x < layout.centerX && noise > 0.58) || (point.x >= layout.centerX && noise < 0.42)) {
|
|
17913
|
+
color = `${palette.accent}ba`;
|
|
17914
|
+
}
|
|
17915
|
+
return {
|
|
17916
|
+
character,
|
|
17917
|
+
color: isOutline ? `${palette.highlight}c9` : color,
|
|
17918
|
+
};
|
|
17919
|
+
}
|
|
17920
|
+
/**
|
|
17921
|
+
* Resolves faint atmosphere glyphs around the ASCII octopus.
|
|
17922
|
+
*
|
|
17923
|
+
* @param point Sampled cell point.
|
|
17924
|
+
* @param layout Prepared octopus layout.
|
|
17925
|
+
* @param palette Derived avatar palette.
|
|
17926
|
+
* @param noise Stable per-cell noise.
|
|
17927
|
+
* @param timeMs Current animation time in milliseconds.
|
|
17928
|
+
* @returns Atmosphere glyph descriptor or `null`.
|
|
17929
|
+
*
|
|
17930
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17931
|
+
*/
|
|
17932
|
+
function resolveAtmosphereGlyph(point, layout, palette, noise, timeMs) {
|
|
17933
|
+
const horizontalDistance = Math.abs(point.x - layout.centerX) / (layout.bodyRadius * layout.horizontalStretch * 2.2);
|
|
17934
|
+
const verticalDistance = Math.abs(point.y - (layout.centerY + layout.bodyRadius * 0.04)) / (layout.bodyRadius * 2.1);
|
|
17935
|
+
const haloDistance = Math.hypot(horizontalDistance, verticalDistance);
|
|
17936
|
+
const shimmer = Math.sin(timeMs / 1450 + point.x * 0.03 + point.y * 0.04 + layout.shapePhase) * 0.06;
|
|
17937
|
+
const density = clamp01(1.16 - haloDistance + shimmer + (noise - 0.5) * 0.14);
|
|
17938
|
+
if (density < 0.18 || noise > density * 0.84 + 0.34) {
|
|
17939
|
+
return null;
|
|
17940
|
+
}
|
|
17941
|
+
return {
|
|
17942
|
+
character: pickRampCharacter(ATMOSPHERE_GLYPHS, density),
|
|
17943
|
+
color: point.y < layout.centerY ? `${palette.highlight}63` : `${palette.accent}47`,
|
|
17944
|
+
};
|
|
17945
|
+
}
|
|
17946
|
+
/**
|
|
17947
|
+
* Builds the grid used by the ASCII renderer.
|
|
17948
|
+
*
|
|
17949
|
+
* @param size Canvas size in CSS pixels.
|
|
17950
|
+
* @param staticRandom Stable random generator for this avatar.
|
|
17951
|
+
* @returns Grid metrics.
|
|
17952
|
+
*
|
|
17953
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17954
|
+
*/
|
|
17955
|
+
function createAsciiGridMetrics(size, staticRandom) {
|
|
17956
|
+
const fontSize = Math.max(9, Math.round(size * (0.048 + staticRandom() * 0.006)));
|
|
17957
|
+
const cellWidth = fontSize * (0.58 + staticRandom() * 0.04);
|
|
17958
|
+
const cellHeight = fontSize * 0.82;
|
|
17959
|
+
const columnCount = Math.max(12, Math.floor(size / cellWidth) - 1);
|
|
17960
|
+
const rowCount = Math.max(12, Math.floor(size / cellHeight) - 1);
|
|
17961
|
+
const offsetX = (size - (columnCount - 1) * cellWidth) / 2;
|
|
17962
|
+
const offsetY = (size - (rowCount - 1) * cellHeight) / 2;
|
|
17963
|
+
return {
|
|
17964
|
+
fontSize,
|
|
17965
|
+
cellWidth,
|
|
17966
|
+
cellHeight,
|
|
17967
|
+
columnCount,
|
|
17968
|
+
rowCount,
|
|
17969
|
+
offsetX,
|
|
17970
|
+
offsetY,
|
|
17971
|
+
};
|
|
17972
|
+
}
|
|
17973
|
+
/**
|
|
17974
|
+
* Builds the deterministic octopus geometry that will later be sampled into ASCII cells.
|
|
17975
|
+
*
|
|
17976
|
+
* @param size Canvas size in CSS pixels.
|
|
17977
|
+
* @param timeMs Current animation time in milliseconds.
|
|
17978
|
+
* @param createRandom Seeded random factory scoped to the avatar.
|
|
17979
|
+
* @param staticRandom Stable random generator for this avatar.
|
|
17980
|
+
* @returns Prepared octopus layout.
|
|
17981
|
+
*
|
|
17982
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
17983
|
+
*/
|
|
17984
|
+
function createAsciiOctopusLayout(size, timeMs, createRandom, staticRandom, interaction) {
|
|
17985
|
+
const centerX = size * (0.5 + (staticRandom() - 0.5) * 0.02) + interaction.bodyOffsetX * size * 0.05;
|
|
17986
|
+
const centerY = size * (0.41 + staticRandom() * 0.05) + interaction.bodyOffsetY * size * 0.035;
|
|
17987
|
+
const bodyRadius = size * (0.195 + staticRandom() * 0.05);
|
|
17988
|
+
const horizontalStretch = 1.08 + staticRandom() * 0.22;
|
|
17989
|
+
const verticalStretch = 0.88 + staticRandom() * 0.14;
|
|
17990
|
+
const mantleLift = size * (0.1 + staticRandom() * 0.03);
|
|
17991
|
+
const lowerDrop = size * (0.03 + staticRandom() * 0.024);
|
|
17992
|
+
const tentacleDepth = size * (0.026 + staticRandom() * 0.022);
|
|
17993
|
+
const wobbleAmplitude = size * (0.008 + staticRandom() * 0.01);
|
|
17994
|
+
const lobeCount = 5 + Math.floor(staticRandom() * 4);
|
|
17995
|
+
const shapePhase = staticRandom() * Math.PI * 2;
|
|
17996
|
+
const tentacleCount = 8 + Math.floor(staticRandom() * 5);
|
|
17997
|
+
const eyeSpacing = size * (0.108 + staticRandom() * 0.042);
|
|
17998
|
+
const eyeRadiusX = size * (0.05 + staticRandom() * 0.015);
|
|
17999
|
+
const eyeRadiusY = eyeRadiusX * (1.16 + staticRandom() * 0.2);
|
|
18000
|
+
const bodyPoints = createOrganicOctopusBodyPoints({
|
|
18001
|
+
centerX,
|
|
18002
|
+
centerY,
|
|
18003
|
+
bodyRadius,
|
|
18004
|
+
horizontalStretch,
|
|
18005
|
+
verticalStretch,
|
|
18006
|
+
mantleLift,
|
|
18007
|
+
lowerDrop,
|
|
18008
|
+
tentacleDepth,
|
|
18009
|
+
wobbleAmplitude,
|
|
18010
|
+
lobeCount,
|
|
18011
|
+
shapePhase,
|
|
18012
|
+
timeMs,
|
|
18013
|
+
pointCount: 40,
|
|
18014
|
+
});
|
|
18015
|
+
const tentacleShapes = createOrganicOctopusTentacleShapes({
|
|
18016
|
+
size,
|
|
18017
|
+
centerX,
|
|
18018
|
+
centerY,
|
|
18019
|
+
bodyRadius,
|
|
18020
|
+
horizontalStretch,
|
|
18021
|
+
tentacleCount,
|
|
18022
|
+
shapePhase,
|
|
18023
|
+
createRandom,
|
|
18024
|
+
timeMs,
|
|
18025
|
+
saltPrefix: 'ascii-octopus',
|
|
18026
|
+
bodyPoints,
|
|
18027
|
+
});
|
|
18028
|
+
const sampledTentacles = tentacleShapes.map(sampleOrganicTentacleRibbonPoints);
|
|
18029
|
+
const leftEye = {
|
|
18030
|
+
centerX: centerX - eyeSpacing,
|
|
18031
|
+
centerY: centerY - size * 0.01,
|
|
18032
|
+
radiusX: eyeRadiusX,
|
|
18033
|
+
radiusY: eyeRadiusY,
|
|
18034
|
+
rotation: (staticRandom() - 0.5) * 0.24,
|
|
18035
|
+
phase: shapePhase,
|
|
18036
|
+
};
|
|
18037
|
+
const rightEye = {
|
|
18038
|
+
centerX: centerX + eyeSpacing,
|
|
18039
|
+
centerY: centerY - size * 0.01,
|
|
18040
|
+
radiusX: eyeRadiusX,
|
|
18041
|
+
radiusY: eyeRadiusY,
|
|
18042
|
+
rotation: (staticRandom() - 0.5) * 0.24,
|
|
18043
|
+
phase: shapePhase + Math.PI / 4,
|
|
18044
|
+
};
|
|
18045
|
+
const mouthPoints = sampleQuadraticBezierPoints({ x: centerX - size * 0.074, y: centerY + size * 0.092 }, {
|
|
18046
|
+
x: centerX,
|
|
18047
|
+
y: centerY +
|
|
18048
|
+
size * (0.142 + Math.sin(timeMs / 620 + shapePhase) * 0.016) +
|
|
18049
|
+
interaction.gazeY * size * 0.012,
|
|
18050
|
+
}, { x: centerX + size * 0.074, y: centerY + size * 0.092 }, 12);
|
|
18051
|
+
let leftBound = Number.POSITIVE_INFINITY;
|
|
18052
|
+
let rightBound = Number.NEGATIVE_INFINITY;
|
|
18053
|
+
let topBound = Number.POSITIVE_INFINITY;
|
|
18054
|
+
let bottomBound = Number.NEGATIVE_INFINITY;
|
|
18055
|
+
for (const bodyPoint of bodyPoints) {
|
|
18056
|
+
leftBound = Math.min(leftBound, bodyPoint.x);
|
|
18057
|
+
rightBound = Math.max(rightBound, bodyPoint.x);
|
|
18058
|
+
topBound = Math.min(topBound, bodyPoint.y);
|
|
18059
|
+
bottomBound = Math.max(bottomBound, bodyPoint.y);
|
|
18060
|
+
}
|
|
18061
|
+
for (const sampledTentacle of sampledTentacles) {
|
|
18062
|
+
for (const ribbonPoint of sampledTentacle) {
|
|
18063
|
+
leftBound = Math.min(leftBound, ribbonPoint.x - ribbonPoint.width);
|
|
18064
|
+
rightBound = Math.max(rightBound, ribbonPoint.x + ribbonPoint.width);
|
|
18065
|
+
topBound = Math.min(topBound, ribbonPoint.y - ribbonPoint.width);
|
|
18066
|
+
bottomBound = Math.max(bottomBound, ribbonPoint.y + ribbonPoint.width);
|
|
18067
|
+
}
|
|
18068
|
+
}
|
|
18069
|
+
return {
|
|
18070
|
+
centerX,
|
|
18071
|
+
centerY,
|
|
18072
|
+
bodyRadius,
|
|
18073
|
+
horizontalStretch,
|
|
18074
|
+
shapePhase,
|
|
18075
|
+
interaction,
|
|
18076
|
+
bodyPoints,
|
|
18077
|
+
sampledTentacles,
|
|
18078
|
+
leftEye,
|
|
18079
|
+
rightEye,
|
|
18080
|
+
mouthPoints,
|
|
18081
|
+
leftBound: leftBound - size * 0.08,
|
|
18082
|
+
rightBound: rightBound + size * 0.08,
|
|
18083
|
+
topBound: topBound - size * 0.08,
|
|
18084
|
+
bottomBound: bottomBound + size * 0.08,
|
|
18085
|
+
};
|
|
18086
|
+
}
|
|
18087
|
+
/**
|
|
18088
|
+
* Samples points along a quadratic Bezier curve.
|
|
18089
|
+
*
|
|
18090
|
+
* @param startPoint Curve start point.
|
|
18091
|
+
* @param controlPoint Curve control point.
|
|
18092
|
+
* @param endPoint Curve end point.
|
|
18093
|
+
* @param pointCount Number of intervals to sample.
|
|
18094
|
+
* @returns Sampled curve points.
|
|
18095
|
+
*
|
|
18096
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18097
|
+
*/
|
|
18098
|
+
function sampleQuadraticBezierPoints(startPoint, controlPoint, endPoint, pointCount) {
|
|
18099
|
+
return Array.from({ length: pointCount + 1 }, (_, pointIndex) => {
|
|
18100
|
+
const progress = pointIndex / pointCount;
|
|
18101
|
+
const inverseProgress = 1 - progress;
|
|
18102
|
+
return {
|
|
18103
|
+
x: inverseProgress * inverseProgress * startPoint.x +
|
|
18104
|
+
2 * inverseProgress * progress * controlPoint.x +
|
|
18105
|
+
progress * progress * endPoint.x,
|
|
18106
|
+
y: inverseProgress * inverseProgress * startPoint.y +
|
|
18107
|
+
2 * inverseProgress * progress * controlPoint.y +
|
|
18108
|
+
progress * progress * endPoint.y,
|
|
18109
|
+
};
|
|
18110
|
+
});
|
|
18111
|
+
}
|
|
18112
|
+
/**
|
|
18113
|
+
* Measures how strongly the sampled cell intersects with the generated tentacles.
|
|
18114
|
+
*
|
|
18115
|
+
* @param point Sampled cell point.
|
|
18116
|
+
* @param sampledTentacles Pre-sampled tentacle ribbons.
|
|
18117
|
+
* @param cellWidth Character cell width.
|
|
18118
|
+
* @returns Nearest tentacle coverage or `null`.
|
|
18119
|
+
*
|
|
18120
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18121
|
+
*/
|
|
18122
|
+
function measureTentacleCoverage(point, sampledTentacles, cellWidth) {
|
|
18123
|
+
let bestTentacleCoverage = null;
|
|
18124
|
+
let bestNormalizedDistance = 0;
|
|
18125
|
+
for (const sampledTentacle of sampledTentacles) {
|
|
18126
|
+
for (const ribbonPoint of sampledTentacle) {
|
|
18127
|
+
const deltaX = point.x - ribbonPoint.x;
|
|
18128
|
+
const deltaY = point.y - ribbonPoint.y;
|
|
18129
|
+
const distance = Math.hypot(deltaX, deltaY);
|
|
18130
|
+
const coverageRadius = ribbonPoint.width + cellWidth * 0.22;
|
|
18131
|
+
const normalizedDistance = 1 - distance / coverageRadius;
|
|
18132
|
+
if (normalizedDistance <= bestNormalizedDistance || normalizedDistance <= 0) {
|
|
18133
|
+
continue;
|
|
18134
|
+
}
|
|
18135
|
+
bestNormalizedDistance = normalizedDistance;
|
|
18136
|
+
bestTentacleCoverage = {
|
|
18137
|
+
tangentAngle: Math.atan2(-ribbonPoint.normalX, ribbonPoint.normalY),
|
|
18138
|
+
progress: ribbonPoint.progress,
|
|
18139
|
+
normalizedDistance,
|
|
18140
|
+
};
|
|
18141
|
+
}
|
|
18142
|
+
}
|
|
18143
|
+
return bestTentacleCoverage;
|
|
18144
|
+
}
|
|
18145
|
+
/**
|
|
18146
|
+
* Picks one ASCII character that matches the nearest tentacle direction.
|
|
18147
|
+
*
|
|
18148
|
+
* @param tentacleCoverage Nearest tentacle coverage.
|
|
18149
|
+
* @param noise Stable per-cell noise.
|
|
18150
|
+
* @returns Tentacle ASCII character.
|
|
18151
|
+
*
|
|
18152
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18153
|
+
*/
|
|
18154
|
+
function pickTentacleCharacter(tentacleCoverage, noise) {
|
|
18155
|
+
const isSuckerBand = tentacleCoverage.progress > 0.24 && tentacleCoverage.progress < 0.82 && noise > 0.82;
|
|
18156
|
+
if (isSuckerBand && tentacleCoverage.normalizedDistance > 0.34) {
|
|
18157
|
+
return noise > 0.91 ? '0' : 'o';
|
|
18158
|
+
}
|
|
18159
|
+
const horizontalWeight = Math.abs(Math.cos(tentacleCoverage.tangentAngle));
|
|
18160
|
+
const verticalWeight = Math.abs(Math.sin(tentacleCoverage.tangentAngle));
|
|
18161
|
+
if (horizontalWeight > 0.84) {
|
|
18162
|
+
return noise > 0.52 ? '=' : '-';
|
|
18163
|
+
}
|
|
18164
|
+
if (verticalWeight > 0.82) {
|
|
18165
|
+
return noise > 0.56 ? '|' : '!';
|
|
18166
|
+
}
|
|
18167
|
+
return Math.sin(tentacleCoverage.tangentAngle) * Math.cos(tentacleCoverage.tangentAngle) > 0 ? '\\' : '/';
|
|
18168
|
+
}
|
|
18169
|
+
/**
|
|
18170
|
+
* Picks one character from an ordered ramp.
|
|
18171
|
+
*
|
|
18172
|
+
* @param glyphRamp Ordered glyph ramp.
|
|
18173
|
+
* @param intensity Normalized intensity in the range `[0, 1]`.
|
|
18174
|
+
* @returns Selected glyph.
|
|
18175
|
+
*
|
|
18176
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18177
|
+
*/
|
|
18178
|
+
function pickRampCharacter(glyphRamp, intensity) {
|
|
18179
|
+
const characterIndex = Math.min(glyphRamp.length - 1, Math.floor(clamp01(intensity) * glyphRamp.length));
|
|
18180
|
+
return glyphRamp[characterIndex];
|
|
18181
|
+
}
|
|
18182
|
+
/**
|
|
18183
|
+
* Measures the normalized distance from a point to a rotated ellipse.
|
|
18184
|
+
*
|
|
18185
|
+
* @param point Sampled cell point.
|
|
18186
|
+
* @param centerX Ellipse center X coordinate.
|
|
18187
|
+
* @param centerY Ellipse center Y coordinate.
|
|
18188
|
+
* @param radiusX Horizontal ellipse radius.
|
|
18189
|
+
* @param radiusY Vertical ellipse radius.
|
|
18190
|
+
* @param rotation Ellipse rotation in radians.
|
|
18191
|
+
* @returns Normalized ellipse distance where values below `1` are inside.
|
|
18192
|
+
*
|
|
18193
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18194
|
+
*/
|
|
18195
|
+
function measureRotatedEllipseDistance(point, centerX, centerY, radiusX, radiusY, rotation) {
|
|
18196
|
+
const cosine = Math.cos(rotation);
|
|
18197
|
+
const sine = Math.sin(rotation);
|
|
18198
|
+
const translatedX = point.x - centerX;
|
|
18199
|
+
const translatedY = point.y - centerY;
|
|
18200
|
+
const localX = translatedX * cosine + translatedY * sine;
|
|
18201
|
+
const localY = -translatedX * sine + translatedY * cosine;
|
|
18202
|
+
return Math.sqrt((localX * localX) / (radiusX * radiusX) + (localY * localY) / (radiusY * radiusY));
|
|
18203
|
+
}
|
|
18204
|
+
/**
|
|
18205
|
+
* Checks whether a point lies inside the given closed polygon.
|
|
18206
|
+
*
|
|
18207
|
+
* @param point Sampled cell point.
|
|
18208
|
+
* @param polygonPoints Polygon points in order.
|
|
18209
|
+
* @returns `true` when the point lies inside the polygon.
|
|
18210
|
+
*
|
|
18211
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18212
|
+
*/
|
|
18213
|
+
function isPointInsidePolygon(point, polygonPoints) {
|
|
18214
|
+
let isInside = false;
|
|
18215
|
+
for (let currentPointIndex = 0, previousPointIndex = polygonPoints.length - 1; currentPointIndex < polygonPoints.length; previousPointIndex = currentPointIndex++) {
|
|
18216
|
+
const currentPoint = polygonPoints[currentPointIndex];
|
|
18217
|
+
const previousPoint = polygonPoints[previousPointIndex];
|
|
18218
|
+
const isIntersecting = currentPoint.y > point.y !== previousPoint.y > point.y &&
|
|
18219
|
+
point.x <
|
|
18220
|
+
((previousPoint.x - currentPoint.x) * (point.y - currentPoint.y)) / (previousPoint.y - currentPoint.y) +
|
|
18221
|
+
currentPoint.x;
|
|
18222
|
+
if (isIntersecting) {
|
|
18223
|
+
isInside = !isInside;
|
|
18224
|
+
}
|
|
18225
|
+
}
|
|
18226
|
+
return isInside;
|
|
18227
|
+
}
|
|
18228
|
+
/**
|
|
18229
|
+
* Measures the shortest distance from a point to a polyline.
|
|
18230
|
+
*
|
|
18231
|
+
* @param point Sampled cell point.
|
|
18232
|
+
* @param polylinePoints Polyline points in order.
|
|
18233
|
+
* @param isClosed Whether the final point should connect back to the first point.
|
|
18234
|
+
* @returns Shortest distance to the polyline.
|
|
18235
|
+
*
|
|
18236
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18237
|
+
*/
|
|
18238
|
+
function getDistanceToPolyline(point, polylinePoints, isClosed) {
|
|
18239
|
+
let shortestDistance = Number.POSITIVE_INFINITY;
|
|
18240
|
+
const segmentCount = isClosed ? polylinePoints.length : polylinePoints.length - 1;
|
|
18241
|
+
for (let segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) {
|
|
18242
|
+
const startPoint = polylinePoints[segmentIndex];
|
|
18243
|
+
const endPoint = polylinePoints[(segmentIndex + 1) % polylinePoints.length];
|
|
18244
|
+
shortestDistance = Math.min(shortestDistance, getDistanceToLineSegment(point, startPoint, endPoint));
|
|
18245
|
+
}
|
|
18246
|
+
return shortestDistance;
|
|
18247
|
+
}
|
|
18248
|
+
/**
|
|
18249
|
+
* Measures the shortest distance from a point to one line segment.
|
|
18250
|
+
*
|
|
18251
|
+
* @param point Sampled cell point.
|
|
18252
|
+
* @param startPoint Segment start point.
|
|
18253
|
+
* @param endPoint Segment end point.
|
|
18254
|
+
* @returns Shortest distance to the segment.
|
|
18255
|
+
*
|
|
18256
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18257
|
+
*/
|
|
18258
|
+
function getDistanceToLineSegment(point, startPoint, endPoint) {
|
|
18259
|
+
const deltaX = endPoint.x - startPoint.x;
|
|
18260
|
+
const deltaY = endPoint.y - startPoint.y;
|
|
18261
|
+
const segmentLengthSquared = deltaX * deltaX + deltaY * deltaY;
|
|
18262
|
+
if (segmentLengthSquared === 0) {
|
|
18263
|
+
return Math.hypot(point.x - startPoint.x, point.y - startPoint.y);
|
|
18264
|
+
}
|
|
18265
|
+
const progress = clamp01(((point.x - startPoint.x) * deltaX + (point.y - startPoint.y) * deltaY) / segmentLengthSquared);
|
|
18266
|
+
const projectionX = startPoint.x + deltaX * progress;
|
|
18267
|
+
const projectionY = startPoint.y + deltaY * progress;
|
|
18268
|
+
return Math.hypot(point.x - projectionX, point.y - projectionY);
|
|
18269
|
+
}
|
|
18270
|
+
/**
|
|
18271
|
+
* Clamps a number into the inclusive range `[0, 1]`.
|
|
18272
|
+
*
|
|
18273
|
+
* @param value Arbitrary numeric value.
|
|
18274
|
+
* @returns Clamped value.
|
|
18275
|
+
*
|
|
18276
|
+
* @private helper of `asciiOctopusAvatarVisual`
|
|
18277
|
+
*/
|
|
18278
|
+
function clamp01(value) {
|
|
18279
|
+
return Math.max(0, Math.min(1, value));
|
|
18280
|
+
}
|
|
18281
|
+
|
|
18282
|
+
/* eslint-disable no-magic-numbers */
|
|
18283
|
+
/**
|
|
18284
|
+
* Fractal avatar visual.
|
|
18285
|
+
*
|
|
18286
|
+
* @private built-in avatar visual
|
|
18287
|
+
*/
|
|
18288
|
+
const fractalAvatarVisual = {
|
|
18289
|
+
id: 'fractal',
|
|
18290
|
+
title: 'Fractal',
|
|
18291
|
+
description: 'Layered dragon-curve ribbons with deterministic glows, bends, and seeded color interplay.',
|
|
18292
|
+
isAnimated: true,
|
|
18293
|
+
render({ context, size, palette, createRandom, timeMs }) {
|
|
18294
|
+
const staticRandom = createRandom('fractal-static');
|
|
18295
|
+
const centerX = size * 0.5;
|
|
18296
|
+
const centerY = size * 0.5;
|
|
18297
|
+
const layerCount = 2 + Math.floor(staticRandom() * 3);
|
|
18298
|
+
const haloRotation = staticRandom() * Math.PI * 2;
|
|
18299
|
+
const colorSequence = [palette.primary, palette.secondary, palette.accent, palette.highlight];
|
|
18300
|
+
drawAvatarFrame(context, size, palette);
|
|
18301
|
+
drawFractalBackground(context, size, palette, timeMs, haloRotation);
|
|
18302
|
+
for (let layerIndex = 0; layerIndex < layerCount; layerIndex++) {
|
|
18303
|
+
const layerRandom = createRandom(`fractal-layer-${layerIndex}`);
|
|
18304
|
+
const order = 8 + Math.floor(layerRandom() * 4);
|
|
18305
|
+
const turnSequence = createDragonCurveTurns(order);
|
|
18306
|
+
const basePoints = createDragonCurvePoints(turnSequence);
|
|
18307
|
+
const transformedPoints = transformDragonCurvePoints(basePoints, {
|
|
18308
|
+
size,
|
|
18309
|
+
centerX: centerX + (layerRandom() - 0.5) * size * 0.08,
|
|
18310
|
+
centerY: centerY + (layerRandom() - 0.5) * size * 0.08,
|
|
18311
|
+
rotation: layerRandom() * Math.PI * 2 + Math.sin(timeMs / (1700 + layerIndex * 280) + layerIndex) * 0.14,
|
|
18312
|
+
scale: size * (0.19 + layerIndex * 0.055 + layerRandom() * 0.045),
|
|
18313
|
+
horizontalStretch: 0.74 + layerRandom() * 0.9,
|
|
18314
|
+
verticalStretch: 0.74 + layerRandom() * 0.9,
|
|
18315
|
+
warpAmplitude: size * (0.008 + layerRandom() * 0.012),
|
|
18316
|
+
warpPhase: layerRandom() * Math.PI * 2,
|
|
18317
|
+
mirrorX: layerRandom() < 0.5 ? -1 : 1,
|
|
18318
|
+
mirrorY: layerRandom() < 0.38 ? -1 : 1,
|
|
18319
|
+
timeMs,
|
|
18320
|
+
});
|
|
18321
|
+
const primaryColor = colorSequence[layerIndex % colorSequence.length];
|
|
18322
|
+
const secondaryColor = colorSequence[(layerIndex + 1) % colorSequence.length];
|
|
18323
|
+
const tertiaryColor = colorSequence[(layerIndex + 2) % colorSequence.length];
|
|
18324
|
+
const strokeWidth = size * (0.026 - layerIndex * 0.0035);
|
|
18325
|
+
drawDragonCurveLayer(context, transformedPoints, {
|
|
18326
|
+
size,
|
|
18327
|
+
primaryColor,
|
|
18328
|
+
secondaryColor,
|
|
18329
|
+
tertiaryColor,
|
|
18330
|
+
shadowColor: palette.shadow,
|
|
18331
|
+
strokeWidth,
|
|
18332
|
+
timeMs,
|
|
18333
|
+
layerIndex,
|
|
18334
|
+
});
|
|
18335
|
+
}
|
|
18336
|
+
drawFractalCore(context, size, palette, timeMs, staticRandom());
|
|
18337
|
+
},
|
|
18338
|
+
};
|
|
18339
|
+
/**
|
|
18340
|
+
* Draws the shared luminous atmosphere behind the curve layers.
|
|
18341
|
+
*
|
|
18342
|
+
* @param context Canvas 2D context.
|
|
18343
|
+
* @param size Canvas size in CSS pixels.
|
|
18344
|
+
* @param palette Derived avatar palette.
|
|
18345
|
+
* @param timeMs Current animation time in milliseconds.
|
|
18346
|
+
* @param haloRotation Seed-based phase offset.
|
|
18347
|
+
*
|
|
18348
|
+
* @private helper of `fractalAvatarVisual`
|
|
18349
|
+
*/
|
|
18350
|
+
function drawFractalBackground(context, size, palette, timeMs, haloRotation) {
|
|
18351
|
+
const centerX = size * 0.5;
|
|
18352
|
+
const centerY = size * 0.5;
|
|
18353
|
+
const radialGlow = context.createRadialGradient(centerX, centerY, size * 0.06, centerX, centerY, size * 0.72);
|
|
18354
|
+
radialGlow.addColorStop(0, `${palette.highlight}55`);
|
|
18355
|
+
radialGlow.addColorStop(0.4, `${palette.secondary}1f`);
|
|
18356
|
+
radialGlow.addColorStop(1, `${palette.highlight}00`);
|
|
18357
|
+
context.fillStyle = radialGlow;
|
|
18358
|
+
context.fillRect(0, 0, size, size);
|
|
18359
|
+
for (let haloIndex = 0; haloIndex < 3; haloIndex++) {
|
|
18360
|
+
const radius = size * (0.17 + haloIndex * 0.09);
|
|
18361
|
+
const rotation = haloRotation + haloIndex * 0.85 + timeMs / (4400 + haloIndex * 700);
|
|
18362
|
+
context.beginPath();
|
|
18363
|
+
context.ellipse(centerX, centerY, radius, radius * (0.62 + haloIndex * 0.06), rotation, 0, Math.PI * 2);
|
|
18364
|
+
context.strokeStyle = haloIndex % 2 === 0 ? `${palette.secondary}24` : `${palette.accent}20`;
|
|
18365
|
+
context.lineWidth = size * 0.006;
|
|
18366
|
+
context.stroke();
|
|
18367
|
+
}
|
|
18368
|
+
}
|
|
18369
|
+
/**
|
|
18370
|
+
* Generates the left-right turn sequence for a dragon curve.
|
|
18371
|
+
*
|
|
18372
|
+
* @param order Number of folding iterations.
|
|
18373
|
+
* @returns Turn sequence where `1` means right and `-1` means left.
|
|
18374
|
+
*
|
|
18375
|
+
* @private helper of `fractalAvatarVisual`
|
|
18376
|
+
*/
|
|
18377
|
+
function createDragonCurveTurns(order) {
|
|
18378
|
+
let turns = [];
|
|
18379
|
+
for (let iteration = 0; iteration < order; iteration++) {
|
|
18380
|
+
turns = [
|
|
18381
|
+
...turns,
|
|
18382
|
+
1,
|
|
18383
|
+
...turns
|
|
18384
|
+
.slice()
|
|
18385
|
+
.reverse()
|
|
18386
|
+
.map((turn) => (turn === 1 ? -1 : 1)),
|
|
18387
|
+
];
|
|
18388
|
+
}
|
|
18389
|
+
return turns;
|
|
18390
|
+
}
|
|
18391
|
+
/**
|
|
18392
|
+
* Converts a dragon-curve turn sequence into a raw grid polyline.
|
|
18393
|
+
*
|
|
18394
|
+
* @param turnSequence Ordered turn sequence.
|
|
18395
|
+
* @returns Unscaled polyline points.
|
|
18396
|
+
*
|
|
18397
|
+
* @private helper of `fractalAvatarVisual`
|
|
18398
|
+
*/
|
|
18399
|
+
function createDragonCurvePoints(turnSequence) {
|
|
18400
|
+
const points = [{ x: 0, y: 0 }];
|
|
18401
|
+
const directions = [
|
|
18402
|
+
{ x: 1, y: 0 },
|
|
18403
|
+
{ x: 0, y: 1 },
|
|
18404
|
+
{ x: -1, y: 0 },
|
|
18405
|
+
{ x: 0, y: -1 },
|
|
18406
|
+
];
|
|
18407
|
+
let directionIndex = 0;
|
|
18408
|
+
for (let segmentIndex = 0; segmentIndex <= turnSequence.length; segmentIndex++) {
|
|
18409
|
+
const currentPoint = points[points.length - 1];
|
|
18410
|
+
const direction = directions[directionIndex];
|
|
18411
|
+
points.push({
|
|
18412
|
+
x: currentPoint.x + direction.x,
|
|
18413
|
+
y: currentPoint.y + direction.y,
|
|
18414
|
+
});
|
|
18415
|
+
if (segmentIndex < turnSequence.length) {
|
|
18416
|
+
directionIndex = (directionIndex + turnSequence[segmentIndex] + directions.length) % directions.length;
|
|
18417
|
+
}
|
|
18418
|
+
}
|
|
18419
|
+
return points;
|
|
18420
|
+
}
|
|
18421
|
+
/**
|
|
18422
|
+
* Normalizes and decorates the dragon-curve polyline for avatar rendering.
|
|
18423
|
+
*
|
|
18424
|
+
* @param points Raw grid polyline points.
|
|
18425
|
+
* @param options Transformation parameters.
|
|
18426
|
+
* @returns Transformed canvas points.
|
|
18427
|
+
*
|
|
18428
|
+
* @private helper of `fractalAvatarVisual`
|
|
18429
|
+
*/
|
|
18430
|
+
function transformDragonCurvePoints(points, options) {
|
|
18431
|
+
const { size, centerX, centerY, rotation, scale, horizontalStretch, verticalStretch, warpAmplitude, warpPhase, mirrorX, mirrorY, timeMs, } = options;
|
|
18432
|
+
const bounds = getPointBounds(points);
|
|
18433
|
+
const width = Math.max(1, bounds.maxX - bounds.minX);
|
|
18434
|
+
const height = Math.max(1, bounds.maxY - bounds.minY);
|
|
18435
|
+
const normalizationScale = scale / Math.max(width, height);
|
|
18436
|
+
const cosine = Math.cos(rotation);
|
|
18437
|
+
const sine = Math.sin(rotation);
|
|
18438
|
+
return points.map((point, pointIndex) => {
|
|
18439
|
+
const normalizedX = (point.x - (bounds.minX + width / 2)) * normalizationScale * horizontalStretch * mirrorX;
|
|
18440
|
+
const normalizedY = (point.y - (bounds.minY + height / 2)) * normalizationScale * verticalStretch * mirrorY;
|
|
18441
|
+
const progress = pointIndex / Math.max(1, points.length - 1);
|
|
18442
|
+
const localWarp = Math.sin(progress * Math.PI * 4 + warpPhase + timeMs / 1400) * warpAmplitude +
|
|
18443
|
+
Math.cos(progress * Math.PI * 7 - warpPhase + timeMs / 1800) * warpAmplitude * 0.45;
|
|
18444
|
+
const rotatedX = normalizedX * cosine - normalizedY * sine;
|
|
18445
|
+
const rotatedY = normalizedX * sine + normalizedY * cosine;
|
|
18446
|
+
return {
|
|
18447
|
+
x: centerX + rotatedX + Math.sin(progress * Math.PI * 2 + warpPhase) * localWarp,
|
|
18448
|
+
y: centerY +
|
|
18449
|
+
rotatedY +
|
|
18450
|
+
Math.cos(progress * Math.PI * 3 + warpPhase * 0.6) * localWarp +
|
|
18451
|
+
(progress - 0.5) * size * 0.02,
|
|
18452
|
+
};
|
|
18453
|
+
});
|
|
18454
|
+
}
|
|
18455
|
+
/**
|
|
18456
|
+
* Returns the bounding box of a point cloud.
|
|
18457
|
+
*
|
|
18458
|
+
* @param points Point cloud to inspect.
|
|
18459
|
+
* @returns Bounding box.
|
|
18460
|
+
*
|
|
18461
|
+
* @private helper of `fractalAvatarVisual`
|
|
18462
|
+
*/
|
|
18463
|
+
function getPointBounds(points) {
|
|
18464
|
+
return points.reduce((bounds, point) => ({
|
|
18465
|
+
minX: Math.min(bounds.minX, point.x),
|
|
18466
|
+
maxX: Math.max(bounds.maxX, point.x),
|
|
18467
|
+
minY: Math.min(bounds.minY, point.y),
|
|
18468
|
+
maxY: Math.max(bounds.maxY, point.y),
|
|
18469
|
+
}), {
|
|
18470
|
+
minX: Number.POSITIVE_INFINITY,
|
|
18471
|
+
maxX: Number.NEGATIVE_INFINITY,
|
|
18472
|
+
minY: Number.POSITIVE_INFINITY,
|
|
18473
|
+
maxY: Number.NEGATIVE_INFINITY,
|
|
18474
|
+
});
|
|
18475
|
+
}
|
|
18476
|
+
/**
|
|
18477
|
+
* Draws one stylized dragon-curve ribbon with glow and spark nodes.
|
|
18478
|
+
*
|
|
18479
|
+
* @param context Canvas 2D context.
|
|
18480
|
+
* @param points Transformed polyline points.
|
|
18481
|
+
* @param options Layer styling options.
|
|
18482
|
+
*
|
|
18483
|
+
* @private helper of `fractalAvatarVisual`
|
|
18484
|
+
*/
|
|
18485
|
+
function drawDragonCurveLayer(context, points, options) {
|
|
18486
|
+
const { size, primaryColor, secondaryColor, tertiaryColor, shadowColor, strokeWidth, timeMs, layerIndex } = options;
|
|
18487
|
+
const firstPoint = points[0];
|
|
18488
|
+
const lastPoint = points[points.length - 1];
|
|
18489
|
+
const ribbonGradient = context.createLinearGradient(firstPoint.x, firstPoint.y, lastPoint.x, lastPoint.y);
|
|
18490
|
+
ribbonGradient.addColorStop(0, `${primaryColor}f2`);
|
|
18491
|
+
ribbonGradient.addColorStop(0.5, `${secondaryColor}e6`);
|
|
18492
|
+
ribbonGradient.addColorStop(1, `${tertiaryColor}f2`);
|
|
18493
|
+
context.save();
|
|
18494
|
+
context.beginPath();
|
|
18495
|
+
tracePolyline(context, points);
|
|
18496
|
+
context.strokeStyle = `${shadowColor}82`;
|
|
18497
|
+
context.lineWidth = strokeWidth * 1.8;
|
|
18498
|
+
context.lineJoin = 'round';
|
|
18499
|
+
context.lineCap = 'round';
|
|
18500
|
+
context.filter = `blur(${size * 0.022}px)`;
|
|
18501
|
+
context.stroke();
|
|
18502
|
+
context.restore();
|
|
18503
|
+
context.beginPath();
|
|
18504
|
+
tracePolyline(context, points);
|
|
18505
|
+
context.strokeStyle = ribbonGradient;
|
|
18506
|
+
context.lineWidth = strokeWidth;
|
|
18507
|
+
context.lineJoin = 'round';
|
|
18508
|
+
context.lineCap = 'round';
|
|
18509
|
+
context.stroke();
|
|
18510
|
+
context.beginPath();
|
|
18511
|
+
tracePolyline(context, points);
|
|
18512
|
+
context.strokeStyle = 'rgba(255,255,255,0.22)';
|
|
18513
|
+
context.lineWidth = Math.max(1.2, strokeWidth * 0.28);
|
|
18514
|
+
context.lineJoin = 'round';
|
|
18515
|
+
context.lineCap = 'round';
|
|
18516
|
+
context.stroke();
|
|
18517
|
+
const sparkStride = Math.max(24, Math.floor(points.length / 18));
|
|
18518
|
+
for (let pointIndex = sparkStride; pointIndex < points.length; pointIndex += sparkStride) {
|
|
18519
|
+
const point = points[pointIndex];
|
|
18520
|
+
const pulse = 0.7 + 0.3 * Math.sin(timeMs / 700 + pointIndex * 0.12 + layerIndex);
|
|
18521
|
+
const radius = strokeWidth * (0.24 + pulse * 0.22);
|
|
18522
|
+
context.beginPath();
|
|
18523
|
+
context.arc(point.x, point.y, radius * 1.8, 0, Math.PI * 2);
|
|
18524
|
+
context.fillStyle = `${secondaryColor}20`;
|
|
18525
|
+
context.fill();
|
|
18526
|
+
context.beginPath();
|
|
18527
|
+
context.arc(point.x, point.y, radius, 0, Math.PI * 2);
|
|
18528
|
+
context.fillStyle = tertiaryColor;
|
|
18529
|
+
context.fill();
|
|
18530
|
+
}
|
|
18531
|
+
}
|
|
18532
|
+
/**
|
|
18533
|
+
* Traces a polyline through the provided points.
|
|
18534
|
+
*
|
|
18535
|
+
* @param context Canvas 2D context.
|
|
18536
|
+
* @param points Polyline points.
|
|
18537
|
+
*
|
|
18538
|
+
* @private helper of `fractalAvatarVisual`
|
|
18539
|
+
*/
|
|
18540
|
+
function tracePolyline(context, points) {
|
|
18541
|
+
const firstPoint = points[0];
|
|
18542
|
+
context.moveTo(firstPoint.x, firstPoint.y);
|
|
18543
|
+
for (let pointIndex = 1; pointIndex < points.length; pointIndex++) {
|
|
18544
|
+
const point = points[pointIndex];
|
|
18545
|
+
context.lineTo(point.x, point.y);
|
|
18546
|
+
}
|
|
18547
|
+
}
|
|
18548
|
+
/**
|
|
18549
|
+
* Draws the central crystalline accent tying the dragon-curve layers together.
|
|
18550
|
+
*
|
|
18551
|
+
* @param context Canvas 2D context.
|
|
18552
|
+
* @param size Canvas size in CSS pixels.
|
|
18553
|
+
* @param palette Derived avatar palette.
|
|
18554
|
+
* @param timeMs Current animation time in milliseconds.
|
|
18555
|
+
* @param corePhase Seed-based phase offset.
|
|
18556
|
+
*
|
|
18557
|
+
* @private helper of `fractalAvatarVisual`
|
|
18558
|
+
*/
|
|
18559
|
+
function drawFractalCore(context, size, palette, timeMs, corePhase) {
|
|
18560
|
+
const centerX = size * 0.5;
|
|
18561
|
+
const centerY = size * 0.5;
|
|
18562
|
+
const radius = size * 0.082;
|
|
18563
|
+
const rotation = corePhase * Math.PI * 2 + timeMs / 2200;
|
|
18564
|
+
const innerRotation = -rotation * 1.35;
|
|
18565
|
+
context.save();
|
|
18566
|
+
context.translate(centerX, centerY);
|
|
18567
|
+
context.rotate(rotation);
|
|
18568
|
+
context.beginPath();
|
|
18569
|
+
for (let pointIndex = 0; pointIndex < 4; pointIndex++) {
|
|
18570
|
+
const angle = (pointIndex / 4) * Math.PI * 2;
|
|
18571
|
+
const x = Math.cos(angle) * radius;
|
|
18572
|
+
const y = Math.sin(angle) * radius;
|
|
18573
|
+
if (pointIndex === 0) {
|
|
18574
|
+
context.moveTo(x, y);
|
|
18575
|
+
}
|
|
18576
|
+
else {
|
|
18577
|
+
context.lineTo(x, y);
|
|
18578
|
+
}
|
|
18579
|
+
}
|
|
18580
|
+
context.closePath();
|
|
18581
|
+
context.fillStyle = `${palette.highlight}88`;
|
|
18582
|
+
context.shadowColor = `${palette.highlight}77`;
|
|
18583
|
+
context.shadowBlur = size * 0.05;
|
|
18584
|
+
context.fill();
|
|
18585
|
+
context.restore();
|
|
18586
|
+
context.save();
|
|
18587
|
+
context.translate(centerX, centerY);
|
|
18588
|
+
context.rotate(innerRotation);
|
|
18589
|
+
context.beginPath();
|
|
18590
|
+
for (let pointIndex = 0; pointIndex < 4; pointIndex++) {
|
|
18591
|
+
const angle = Math.PI / 4 + (pointIndex / 4) * Math.PI * 2;
|
|
18592
|
+
const x = Math.cos(angle) * radius * 0.55;
|
|
18593
|
+
const y = Math.sin(angle) * radius * 0.55;
|
|
18594
|
+
if (pointIndex === 0) {
|
|
18595
|
+
context.moveTo(x, y);
|
|
18596
|
+
}
|
|
18597
|
+
else {
|
|
18598
|
+
context.lineTo(x, y);
|
|
18599
|
+
}
|
|
18600
|
+
}
|
|
18601
|
+
context.closePath();
|
|
18602
|
+
context.fillStyle = `${palette.ink}cc`;
|
|
18603
|
+
context.fill();
|
|
18604
|
+
context.restore();
|
|
18605
|
+
}
|
|
18606
|
+
|
|
18607
|
+
/* eslint-disable no-magic-numbers */
|
|
18608
|
+
/**
|
|
18609
|
+
* Minecraft-style 3D avatar visual.
|
|
18610
|
+
*
|
|
18611
|
+
* @private built-in avatar visual
|
|
18612
|
+
*/
|
|
18613
|
+
const minecraftAvatarVisual = {
|
|
18614
|
+
id: 'minecraft',
|
|
18615
|
+
title: 'Minecraft 3D',
|
|
18616
|
+
description: 'Blocky 3D portrait with deterministic pixel textures, shoulders, and hovering depth.',
|
|
18617
|
+
isAnimated: true,
|
|
18618
|
+
render({ context, size, palette, createRandom, timeMs }) {
|
|
18619
|
+
const random = createRandom('minecraft');
|
|
18620
|
+
const bob = Math.sin(timeMs / 880) * size * 0.015;
|
|
18621
|
+
const headSize = size * 0.34;
|
|
18622
|
+
const depth = headSize * 0.22;
|
|
18623
|
+
const headX = size * 0.31;
|
|
18624
|
+
const headY = size * 0.18 + bob;
|
|
18625
|
+
const bodyWidth = headSize * 0.86;
|
|
18626
|
+
const bodyHeight = headSize * 0.82;
|
|
18627
|
+
const bodyDepth = depth * 0.8;
|
|
18628
|
+
const bodyX = size * 0.33;
|
|
18629
|
+
const bodyY = headY + headSize * 0.96;
|
|
18630
|
+
const hasHeadband = random() < 0.5;
|
|
18631
|
+
const faceTexture = createMinecraftFaceTexture(createRandom('minecraft-face'), palette, hasHeadband);
|
|
18632
|
+
const shirtTexture = createMinecraftShirtTexture(createRandom('minecraft-shirt'), palette);
|
|
18633
|
+
drawAvatarFrame(context, size, palette);
|
|
18634
|
+
const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
|
|
18635
|
+
spotlight.addColorStop(0, `${palette.highlight}66`);
|
|
18636
|
+
spotlight.addColorStop(1, `${palette.highlight}00`);
|
|
18637
|
+
context.fillStyle = spotlight;
|
|
18638
|
+
context.fillRect(0, 0, size, size);
|
|
18639
|
+
context.save();
|
|
18640
|
+
context.fillStyle = 'rgba(0, 0, 0, 0.22)';
|
|
18641
|
+
context.filter = `blur(${size * 0.018}px)`;
|
|
18642
|
+
context.beginPath();
|
|
18643
|
+
context.ellipse(size * 0.5, size * 0.86, size * 0.2, size * 0.06, 0, 0, Math.PI * 2);
|
|
18644
|
+
context.fill();
|
|
18645
|
+
context.restore();
|
|
18646
|
+
drawVoxelCuboid(context, {
|
|
18647
|
+
x: bodyX,
|
|
18648
|
+
y: bodyY,
|
|
18649
|
+
width: bodyWidth,
|
|
18650
|
+
height: bodyHeight,
|
|
18651
|
+
depth: bodyDepth,
|
|
18652
|
+
frontTexture: shirtTexture,
|
|
18653
|
+
topColor: `${palette.highlight}cc`,
|
|
18654
|
+
sideColor: `${palette.secondary}dd`,
|
|
18655
|
+
outlineColor: `${palette.shadow}aa`,
|
|
18656
|
+
});
|
|
18657
|
+
drawVoxelCuboid(context, {
|
|
18658
|
+
x: headX,
|
|
18659
|
+
y: headY,
|
|
18660
|
+
width: headSize,
|
|
18661
|
+
height: headSize,
|
|
18662
|
+
depth,
|
|
18663
|
+
frontTexture: faceTexture,
|
|
18664
|
+
topColor: `${palette.highlight}ee`,
|
|
18665
|
+
sideColor: `${palette.secondary}ee`,
|
|
18666
|
+
outlineColor: `${palette.shadow}cc`,
|
|
18667
|
+
});
|
|
18668
|
+
},
|
|
18669
|
+
};
|
|
18670
|
+
/**
|
|
18671
|
+
* Draws a stylized voxel cuboid with a front pixel texture.
|
|
18672
|
+
*
|
|
18673
|
+
* @param context Canvas 2D context.
|
|
18674
|
+
* @param cuboid Cuboid settings.
|
|
18675
|
+
*
|
|
18676
|
+
* @private helper of `minecraftAvatarVisual`
|
|
18677
|
+
*/
|
|
18678
|
+
function drawVoxelCuboid(context, cuboid) {
|
|
18679
|
+
var _a;
|
|
18680
|
+
const { x, y, width, height, depth, frontTexture, topColor, sideColor, outlineColor } = cuboid;
|
|
18681
|
+
const lift = depth * 0.6;
|
|
18682
|
+
context.save();
|
|
18683
|
+
context.beginPath();
|
|
18684
|
+
context.moveTo(x, y);
|
|
18685
|
+
context.lineTo(x + depth, y - lift);
|
|
18686
|
+
context.lineTo(x + width + depth, y - lift);
|
|
18687
|
+
context.lineTo(x + width, y);
|
|
18688
|
+
context.closePath();
|
|
18689
|
+
context.fillStyle = topColor;
|
|
18690
|
+
context.fill();
|
|
18691
|
+
context.restore();
|
|
18692
|
+
context.save();
|
|
18693
|
+
context.beginPath();
|
|
18694
|
+
context.moveTo(x + width, y);
|
|
18695
|
+
context.lineTo(x + width + depth, y - lift);
|
|
18696
|
+
context.lineTo(x + width + depth, y + height - lift);
|
|
18697
|
+
context.lineTo(x + width, y + height);
|
|
18698
|
+
context.closePath();
|
|
18699
|
+
context.fillStyle = sideColor;
|
|
18700
|
+
context.fill();
|
|
18701
|
+
context.restore();
|
|
18702
|
+
const rows = frontTexture.length;
|
|
18703
|
+
const columns = ((_a = frontTexture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
18704
|
+
const pixelWidth = width / Math.max(columns, 1);
|
|
18705
|
+
const pixelHeight = height / Math.max(rows, 1);
|
|
18706
|
+
context.save();
|
|
18707
|
+
createRoundedRectPath(context, x, y, width, height, width * 0.03);
|
|
18708
|
+
context.clip();
|
|
18709
|
+
for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
|
|
18710
|
+
for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
|
|
18711
|
+
context.fillStyle = frontTexture[rowIndex][columnIndex];
|
|
18712
|
+
context.fillRect(x + columnIndex * pixelWidth, y + rowIndex * pixelHeight, pixelWidth, pixelHeight);
|
|
18713
|
+
}
|
|
18714
|
+
}
|
|
18715
|
+
context.restore();
|
|
18716
|
+
context.strokeStyle = outlineColor;
|
|
18717
|
+
context.lineWidth = Math.max(1.2, width * 0.025);
|
|
18718
|
+
context.beginPath();
|
|
18719
|
+
context.moveTo(x, y);
|
|
18720
|
+
context.lineTo(x + depth, y - lift);
|
|
18721
|
+
context.lineTo(x + width + depth, y - lift);
|
|
18722
|
+
context.lineTo(x + width + depth, y + height - lift);
|
|
18723
|
+
context.lineTo(x + width, y + height);
|
|
18724
|
+
context.lineTo(x, y + height);
|
|
18725
|
+
context.closePath();
|
|
18726
|
+
context.stroke();
|
|
18727
|
+
}
|
|
18728
|
+
/**
|
|
18729
|
+
* Creates the front-face pixel texture for the cube head.
|
|
18730
|
+
*
|
|
18731
|
+
* @param random Seeded random generator.
|
|
18732
|
+
* @param palette Derived avatar palette.
|
|
18733
|
+
* @param hasHeadband Whether the avatar should render a headband row.
|
|
18734
|
+
* @returns 8x8 pixel texture.
|
|
18735
|
+
*
|
|
18736
|
+
* @private helper of `minecraftAvatarVisual`
|
|
18737
|
+
*/
|
|
18738
|
+
function createMinecraftFaceTexture(random, palette, hasHeadband) {
|
|
18739
|
+
const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.highlight));
|
|
18740
|
+
const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
|
|
18741
|
+
const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
|
|
18742
|
+
for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
|
|
18743
|
+
for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
|
|
18744
|
+
texture[rowIndex][columnIndex] = hairlineColor;
|
|
18745
|
+
}
|
|
18746
|
+
}
|
|
18747
|
+
texture[2][0] = hairlineColor;
|
|
18748
|
+
texture[2][7] = hairlineColor;
|
|
18749
|
+
texture[3][0] = hairlineColor;
|
|
18750
|
+
texture[3][7] = hairlineColor;
|
|
18751
|
+
if (hasHeadband) {
|
|
18752
|
+
for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
|
|
18753
|
+
texture[2][columnIndex] = palette.accent;
|
|
18754
|
+
}
|
|
18755
|
+
}
|
|
18756
|
+
texture[3][2] = palette.ink;
|
|
18757
|
+
texture[3][5] = palette.ink;
|
|
18758
|
+
texture[4][2] = '#ffffff';
|
|
18759
|
+
texture[4][5] = '#ffffff';
|
|
18760
|
+
texture[5][1] = cheekColor;
|
|
18761
|
+
texture[5][6] = cheekColor;
|
|
18762
|
+
texture[5][3] = palette.shadow;
|
|
18763
|
+
texture[5][4] = palette.shadow;
|
|
18764
|
+
texture[6][3] = palette.shadow;
|
|
18765
|
+
texture[6][4] = palette.shadow;
|
|
18766
|
+
return texture;
|
|
18767
|
+
}
|
|
18768
|
+
/**
|
|
18769
|
+
* Creates the front-face pixel texture for the torso.
|
|
18770
|
+
*
|
|
18771
|
+
* @param random Seeded random generator.
|
|
18772
|
+
* @param palette Derived avatar palette.
|
|
18773
|
+
* @returns 8x8 torso texture.
|
|
18774
|
+
*
|
|
18775
|
+
* @private helper of `minecraftAvatarVisual`
|
|
18776
|
+
*/
|
|
18777
|
+
function createMinecraftShirtTexture(random, palette) {
|
|
18778
|
+
const texture = Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => palette.primary));
|
|
18779
|
+
const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
|
|
18780
|
+
for (let rowIndex = 0; rowIndex < 2; rowIndex++) {
|
|
18781
|
+
for (let columnIndex = 0; columnIndex < 8; columnIndex++) {
|
|
18782
|
+
texture[rowIndex][columnIndex] = palette.shadow;
|
|
18783
|
+
}
|
|
18784
|
+
}
|
|
18785
|
+
for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
|
|
18786
|
+
texture[rowIndex][3] = stripeColor;
|
|
18787
|
+
texture[rowIndex][4] = stripeColor;
|
|
18788
|
+
}
|
|
18789
|
+
texture[4][1] = palette.accent;
|
|
18790
|
+
texture[4][6] = palette.accent;
|
|
18791
|
+
texture[5][2] = palette.highlight;
|
|
18792
|
+
texture[5][5] = palette.highlight;
|
|
18793
|
+
return texture;
|
|
18794
|
+
}
|
|
18795
|
+
|
|
18796
|
+
/* eslint-disable no-magic-numbers */
|
|
18797
|
+
/**
|
|
18798
|
+
* Octopus avatar visual.
|
|
18799
|
+
*
|
|
18800
|
+
* @private built-in avatar visual
|
|
18801
|
+
*/
|
|
18802
|
+
const octopusAvatarVisual = {
|
|
18803
|
+
id: 'octopus',
|
|
18804
|
+
title: 'Octopus',
|
|
18805
|
+
description: 'Playful underwater mascot with cursor-following eyes, animated tentacles, bubbles, and seeded markings.',
|
|
18806
|
+
isAnimated: true,
|
|
18807
|
+
supportsPointerTracking: true,
|
|
18808
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
18809
|
+
const staticRandom = createRandom('octopus-static');
|
|
18810
|
+
const bubbleRandom = createRandom('octopus-bubbles');
|
|
18811
|
+
const bubbleCount = 8;
|
|
18812
|
+
const bubbleRadiusBase = size * 0.02;
|
|
18813
|
+
const centerX = size * 0.5 + interaction.bodyOffsetX * size * 0.035;
|
|
18814
|
+
const centerY = size * 0.42 + interaction.bodyOffsetY * size * 0.024;
|
|
18815
|
+
const headRadius = size * (0.19 + staticRandom() * 0.03);
|
|
18816
|
+
const mantleHeight = headRadius * 1.18;
|
|
18817
|
+
const tentacleLength = size * (0.18 + staticRandom() * 0.06);
|
|
18818
|
+
const tentaclePhases = Array.from({ length: 8 }, () => staticRandom() * Math.PI * 2);
|
|
18819
|
+
const spotCount = 3 + Math.floor(staticRandom() * 4);
|
|
18820
|
+
const spotColors = [palette.secondary, palette.accent, palette.highlight];
|
|
18821
|
+
drawAvatarFrame(context, size, palette);
|
|
18822
|
+
const waterGlow = context.createRadialGradient(centerX, size * 0.22, size * 0.06, centerX, size * 0.22, size * 0.58);
|
|
18823
|
+
waterGlow.addColorStop(0, `${palette.highlight}66`);
|
|
18824
|
+
waterGlow.addColorStop(1, `${palette.highlight}00`);
|
|
18825
|
+
context.fillStyle = waterGlow;
|
|
18826
|
+
context.fillRect(0, 0, size, size);
|
|
18827
|
+
for (let bubbleIndex = 0; bubbleIndex < bubbleCount; bubbleIndex++) {
|
|
18828
|
+
const x = size * (0.15 + bubbleRandom() * 0.7);
|
|
18829
|
+
const y = size * (0.12 + bubbleRandom() * 0.68);
|
|
18830
|
+
const radius = bubbleRadiusBase * (0.6 + bubbleRandom() * 2.3);
|
|
18831
|
+
context.beginPath();
|
|
18832
|
+
context.arc(x, y, radius, 0, Math.PI * 2);
|
|
18833
|
+
context.fillStyle = 'rgba(255,255,255,0.08)';
|
|
18834
|
+
context.fill();
|
|
18835
|
+
context.beginPath();
|
|
18836
|
+
context.arc(x - radius * 0.22, y - radius * 0.22, radius * 0.25, 0, Math.PI * 2);
|
|
18837
|
+
context.fillStyle = 'rgba(255,255,255,0.28)';
|
|
18838
|
+
context.fill();
|
|
18839
|
+
}
|
|
18840
|
+
for (let tentacleIndex = 0; tentacleIndex < 8; tentacleIndex++) {
|
|
18841
|
+
const startX = centerX + (tentacleIndex - 3.5) * headRadius * 0.19;
|
|
18842
|
+
const startY = centerY + headRadius * 0.62;
|
|
18843
|
+
const animationPhase = tentaclePhases[tentacleIndex];
|
|
18844
|
+
const sway = Math.sin(timeMs / 520 + animationPhase) * size * 0.03;
|
|
18845
|
+
const endX = startX + (tentacleIndex - 3.5) * size * 0.025 + sway;
|
|
18846
|
+
const endY = startY + tentacleLength + Math.cos(timeMs / 700 + animationPhase) * size * 0.01;
|
|
18847
|
+
const controlX = (startX + endX) / 2 + sway * 0.8;
|
|
18848
|
+
const controlY = startY + tentacleLength * 0.45;
|
|
18849
|
+
const lineWidth = size * (0.042 - tentacleIndex * 0.0022);
|
|
18850
|
+
context.beginPath();
|
|
18851
|
+
context.moveTo(startX, startY);
|
|
18852
|
+
context.quadraticCurveTo(controlX, controlY, endX, endY);
|
|
18853
|
+
context.lineCap = 'round';
|
|
18854
|
+
context.strokeStyle = palette.primary;
|
|
18855
|
+
context.lineWidth = lineWidth;
|
|
18856
|
+
context.stroke();
|
|
18857
|
+
for (let cupIndex = 1; cupIndex <= 3; cupIndex++) {
|
|
18858
|
+
const cupT = cupIndex / 4;
|
|
18859
|
+
const cupX = (1 - cupT) * (1 - cupT) * startX + 2 * (1 - cupT) * cupT * controlX + cupT * cupT * endX;
|
|
18860
|
+
const cupY = (1 - cupT) * (1 - cupT) * startY + 2 * (1 - cupT) * cupT * controlY + cupT * cupT * endY;
|
|
18861
|
+
context.beginPath();
|
|
18862
|
+
context.arc(cupX, cupY, lineWidth * 0.18, 0, Math.PI * 2);
|
|
18863
|
+
context.fillStyle = `${palette.highlight}cc`;
|
|
18864
|
+
context.fill();
|
|
18865
|
+
}
|
|
18866
|
+
}
|
|
18867
|
+
context.save();
|
|
18868
|
+
context.fillStyle = palette.primary;
|
|
18869
|
+
context.shadowColor = `${palette.shadow}88`;
|
|
18870
|
+
context.shadowBlur = size * 0.08;
|
|
18871
|
+
context.beginPath();
|
|
18872
|
+
context.ellipse(centerX, centerY, headRadius, mantleHeight, 0, Math.PI, 0, true);
|
|
18873
|
+
context.lineTo(centerX + headRadius, centerY);
|
|
18874
|
+
context.ellipse(centerX, centerY, headRadius, headRadius * 0.82, 0, 0, Math.PI);
|
|
18875
|
+
context.closePath();
|
|
18876
|
+
context.fill();
|
|
18877
|
+
context.restore();
|
|
18878
|
+
context.beginPath();
|
|
18879
|
+
context.ellipse(centerX, centerY - headRadius * 0.22, headRadius * 0.74, headRadius * 0.42, 0, Math.PI, Math.PI * 2);
|
|
18880
|
+
context.fillStyle = `${palette.highlight}55`;
|
|
18881
|
+
context.fill();
|
|
18882
|
+
for (let spotIndex = 0; spotIndex < spotCount; spotIndex++) {
|
|
18883
|
+
const spotRandom = createRandom(`octopus-spot-${spotIndex}`);
|
|
18884
|
+
const spotX = centerX + (spotRandom() - 0.5) * headRadius * 1.1;
|
|
18885
|
+
const spotY = centerY - headRadius * 0.05 + (spotRandom() - 0.5) * headRadius * 0.9;
|
|
18886
|
+
const spotRadius = headRadius * (0.07 + spotRandom() * 0.07);
|
|
18887
|
+
context.beginPath();
|
|
18888
|
+
context.arc(spotX, spotY, spotRadius, 0, Math.PI * 2);
|
|
18889
|
+
context.fillStyle = pickRandomItem(spotColors, spotRandom);
|
|
18890
|
+
context.fill();
|
|
18891
|
+
}
|
|
18892
|
+
const eyeOffsetX = headRadius * 0.42;
|
|
18893
|
+
const eyeY = centerY + headRadius * 0.04;
|
|
18894
|
+
const eyeRadius = headRadius * 0.22;
|
|
18895
|
+
drawEye(context, centerX - eyeOffsetX, eyeY, eyeRadius, palette, timeMs, interaction, 0);
|
|
18896
|
+
drawEye(context, centerX + eyeOffsetX, eyeY, eyeRadius, palette, timeMs, interaction, Math.PI / 5);
|
|
18897
|
+
context.beginPath();
|
|
18898
|
+
context.arc(centerX - headRadius * 0.28, centerY + headRadius * 0.3, headRadius * 0.12, 0, Math.PI * 2);
|
|
18899
|
+
context.arc(centerX + headRadius * 0.28, centerY + headRadius * 0.3, headRadius * 0.12, 0, Math.PI * 2);
|
|
18900
|
+
context.fillStyle = `${palette.accent}44`;
|
|
18901
|
+
context.fill();
|
|
18902
|
+
context.beginPath();
|
|
18903
|
+
context.moveTo(centerX - headRadius * 0.18, centerY + headRadius * 0.24);
|
|
18904
|
+
context.quadraticCurveTo(centerX, centerY + headRadius * 0.42, centerX + headRadius * 0.18, centerY + headRadius * 0.24);
|
|
18905
|
+
context.strokeStyle = palette.shadow;
|
|
18906
|
+
context.lineWidth = size * 0.016;
|
|
18907
|
+
context.lineCap = 'round';
|
|
18908
|
+
context.stroke();
|
|
18909
|
+
},
|
|
18910
|
+
};
|
|
18911
|
+
/**
|
|
18912
|
+
* Draws one expressive octopus eye.
|
|
18913
|
+
*
|
|
18914
|
+
* @param context Canvas 2D context.
|
|
18915
|
+
* @param centerX Eye center X coordinate.
|
|
18916
|
+
* @param centerY Eye center Y coordinate.
|
|
18917
|
+
* @param radius Eye radius.
|
|
18918
|
+
* @param palette Derived avatar palette.
|
|
18919
|
+
* @param timeMs Current animation time in milliseconds.
|
|
18920
|
+
* @param interaction Smoothed avatar interaction state.
|
|
18921
|
+
* @param phase Seed-based phase offset.
|
|
18922
|
+
*
|
|
18923
|
+
* @private helper of `octopusAvatarVisual`
|
|
18924
|
+
*/
|
|
18925
|
+
function drawEye(context, centerX, centerY, radius, palette, timeMs, interaction, phase) {
|
|
18926
|
+
const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
|
|
18927
|
+
radiusX: radius,
|
|
18928
|
+
radiusY: radius,
|
|
18929
|
+
timeMs,
|
|
18930
|
+
phase,
|
|
18931
|
+
interaction,
|
|
18932
|
+
autonomousDriftRatioX: 0.05,
|
|
18933
|
+
autonomousDriftRatioY: 0.03,
|
|
18934
|
+
});
|
|
18935
|
+
context.beginPath();
|
|
18936
|
+
context.arc(centerX, centerY, radius, 0, Math.PI * 2);
|
|
18937
|
+
context.fillStyle = '#ffffff';
|
|
18938
|
+
context.fill();
|
|
18939
|
+
context.beginPath();
|
|
18940
|
+
context.arc(centerX + pupilOffsetX, centerY + pupilOffsetY, radius * 0.45, 0, Math.PI * 2);
|
|
18941
|
+
context.fillStyle = palette.ink;
|
|
18942
|
+
context.fill();
|
|
18943
|
+
context.beginPath();
|
|
18944
|
+
context.arc(centerX + pupilOffsetX - radius * 0.12, centerY + pupilOffsetY - radius * 0.12, radius * 0.15, 0, Math.PI * 2);
|
|
18945
|
+
context.fillStyle = '#ffffff';
|
|
18946
|
+
context.fill();
|
|
18947
|
+
context.beginPath();
|
|
18948
|
+
context.arc(centerX, centerY, radius, 0, Math.PI * 2);
|
|
18949
|
+
context.strokeStyle = palette.shadow;
|
|
18950
|
+
context.lineWidth = radius * 0.18;
|
|
18951
|
+
context.stroke();
|
|
18952
|
+
}
|
|
18953
|
+
|
|
18954
|
+
/* eslint-disable no-magic-numbers */
|
|
18955
|
+
/**
|
|
18956
|
+
* Octopus2 avatar visual.
|
|
18957
|
+
*
|
|
18958
|
+
* @private built-in avatar visual
|
|
18959
|
+
*/
|
|
18960
|
+
const octopus2AvatarVisual = {
|
|
18961
|
+
id: 'octopus2',
|
|
18962
|
+
title: 'Octopus2',
|
|
18963
|
+
description: 'Organic alien octopus rendered as one continuously morphing blob with responsive luminous eyes.',
|
|
18964
|
+
isAnimated: true,
|
|
18965
|
+
supportsPointerTracking: true,
|
|
18966
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
18967
|
+
const staticRandom = createRandom('octopus2-static');
|
|
18968
|
+
const centerX = size * 0.5 + interaction.bodyOffsetX * size * 0.042;
|
|
18969
|
+
const centerY = size * (0.48 + staticRandom() * 0.03) + interaction.bodyOffsetY * size * 0.028;
|
|
18970
|
+
const bodyRadius = size * (0.25 + staticRandom() * 0.035);
|
|
18971
|
+
const horizontalStretch = 1.04 + staticRandom() * 0.16;
|
|
18972
|
+
const verticalStretch = 0.94 + staticRandom() * 0.12;
|
|
18973
|
+
const mantleLift = size * (0.075 + staticRandom() * 0.025);
|
|
18974
|
+
const lowerDrop = size * (0.05 + staticRandom() * 0.02);
|
|
18975
|
+
const tentacleDepth = size * (0.08 + staticRandom() * 0.03);
|
|
18976
|
+
const wobbleAmplitude = size * (0.014 + staticRandom() * 0.008);
|
|
18977
|
+
const lobeCount = 6 + Math.floor(staticRandom() * 3);
|
|
18978
|
+
const shapePhase = staticRandom() * Math.PI * 2;
|
|
18979
|
+
const bodyPoints = createOrganicOctopusBodyPoints({
|
|
18980
|
+
centerX,
|
|
18981
|
+
centerY,
|
|
18982
|
+
bodyRadius,
|
|
18983
|
+
horizontalStretch,
|
|
18984
|
+
verticalStretch,
|
|
18985
|
+
mantleLift,
|
|
18986
|
+
lowerDrop,
|
|
18987
|
+
tentacleDepth,
|
|
18988
|
+
wobbleAmplitude,
|
|
18989
|
+
lobeCount,
|
|
18990
|
+
shapePhase,
|
|
18991
|
+
timeMs,
|
|
18992
|
+
});
|
|
18993
|
+
drawAvatarFrame(context, size, palette);
|
|
18994
|
+
const hazeGradient = context.createRadialGradient(centerX, size * 0.22, size * 0.05, centerX, centerY, size * 0.6);
|
|
18995
|
+
hazeGradient.addColorStop(0, `${palette.highlight}4d`);
|
|
18996
|
+
hazeGradient.addColorStop(0.45, `${palette.accent}24`);
|
|
18997
|
+
hazeGradient.addColorStop(1, `${palette.highlight}00`);
|
|
18998
|
+
context.fillStyle = hazeGradient;
|
|
18999
|
+
context.fillRect(0, 0, size, size);
|
|
19000
|
+
const rimGlowGradient = context.createRadialGradient(centerX, centerY + size * 0.08, size * 0.14, centerX, centerY, size * 0.5);
|
|
19001
|
+
rimGlowGradient.addColorStop(0, `${palette.secondary}26`);
|
|
19002
|
+
rimGlowGradient.addColorStop(1, `${palette.secondary}00`);
|
|
19003
|
+
context.fillStyle = rimGlowGradient;
|
|
19004
|
+
context.fillRect(0, 0, size, size);
|
|
19005
|
+
context.save();
|
|
19006
|
+
traceSmoothClosedPath(context, bodyPoints);
|
|
19007
|
+
const bodyGradient = context.createRadialGradient(centerX - size * 0.09, centerY - size * 0.18, size * 0.06, centerX, centerY + size * 0.14, size * 0.5);
|
|
19008
|
+
bodyGradient.addColorStop(0, palette.highlight);
|
|
19009
|
+
bodyGradient.addColorStop(0.25, palette.secondary);
|
|
19010
|
+
bodyGradient.addColorStop(0.68, palette.primary);
|
|
19011
|
+
bodyGradient.addColorStop(1, palette.shadow);
|
|
19012
|
+
context.fillStyle = bodyGradient;
|
|
19013
|
+
context.shadowColor = `${palette.shadow}aa`;
|
|
19014
|
+
context.shadowBlur = size * 0.08;
|
|
19015
|
+
context.shadowOffsetY = size * 0.018;
|
|
19016
|
+
context.fill();
|
|
19017
|
+
context.restore();
|
|
19018
|
+
context.save();
|
|
19019
|
+
traceSmoothClosedPath(context, bodyPoints);
|
|
19020
|
+
context.clip();
|
|
19021
|
+
const interiorGlowGradient = context.createLinearGradient(centerX, centerY - size * 0.22, centerX, centerY + size * 0.36);
|
|
19022
|
+
interiorGlowGradient.addColorStop(0, `${palette.highlight}59`);
|
|
19023
|
+
interiorGlowGradient.addColorStop(0.45, `${palette.accent}1a`);
|
|
19024
|
+
interiorGlowGradient.addColorStop(1, `${palette.shadow}00`);
|
|
19025
|
+
context.fillStyle = interiorGlowGradient;
|
|
19026
|
+
context.fillRect(centerX - size * 0.36, centerY - size * 0.34, size * 0.72, size * 0.76);
|
|
19027
|
+
drawInteriorFilaments(context, centerX, centerY, size, palette, timeMs, shapePhase);
|
|
19028
|
+
drawLowerSuckers(context, centerX, centerY, size, palette, createRandom, timeMs);
|
|
19029
|
+
context.restore();
|
|
19030
|
+
context.save();
|
|
19031
|
+
traceSmoothClosedPath(context, bodyPoints);
|
|
19032
|
+
context.strokeStyle = `${palette.highlight}59`;
|
|
19033
|
+
context.lineWidth = size * 0.014;
|
|
19034
|
+
context.stroke();
|
|
19035
|
+
context.restore();
|
|
19036
|
+
const eyeOffsetX = size * 0.13;
|
|
19037
|
+
const eyeCenterY = centerY - size * 0.02;
|
|
19038
|
+
const eyeRadiusX = size * 0.072;
|
|
19039
|
+
const eyeRadiusY = size * 0.086;
|
|
19040
|
+
drawAlienEye(context, centerX - eyeOffsetX, eyeCenterY, eyeRadiusX, eyeRadiusY, palette, timeMs, shapePhase, interaction);
|
|
19041
|
+
drawAlienEye(context, centerX + eyeOffsetX, eyeCenterY, eyeRadiusX, eyeRadiusY, palette, timeMs, shapePhase + Math.PI / 5, interaction);
|
|
19042
|
+
context.beginPath();
|
|
19043
|
+
context.moveTo(centerX - size * 0.08, centerY + size * 0.12);
|
|
19044
|
+
context.quadraticCurveTo(centerX, centerY + size * (0.175 + Math.sin(timeMs / 520 + shapePhase) * 0.012) + interaction.gazeY * size * 0.01, centerX + size * 0.08, centerY + size * 0.12);
|
|
19045
|
+
context.strokeStyle = `${palette.ink}b3`;
|
|
19046
|
+
context.lineWidth = size * 0.013;
|
|
19047
|
+
context.lineCap = 'round';
|
|
19048
|
+
context.stroke();
|
|
19049
|
+
context.beginPath();
|
|
19050
|
+
context.ellipse(centerX, centerY - size * 0.13, size * 0.16, size * 0.065, 0, Math.PI, Math.PI * 2);
|
|
19051
|
+
context.fillStyle = `${palette.highlight}33`;
|
|
19052
|
+
context.fill();
|
|
19053
|
+
},
|
|
19054
|
+
};
|
|
19055
|
+
/**
|
|
19056
|
+
* Draws translucent inner filaments clipped inside the main body mesh.
|
|
19057
|
+
*
|
|
19058
|
+
* @param context Canvas 2D context.
|
|
19059
|
+
* @param centerX Body center X coordinate.
|
|
19060
|
+
* @param centerY Body center Y coordinate.
|
|
19061
|
+
* @param size Canvas size in CSS pixels.
|
|
19062
|
+
* @param palette Derived avatar palette.
|
|
19063
|
+
* @param timeMs Current animation time in milliseconds.
|
|
19064
|
+
* @param shapePhase Seed-based phase offset.
|
|
19065
|
+
*
|
|
19066
|
+
* @private helper of `octopus2AvatarVisual`
|
|
19067
|
+
*/
|
|
19068
|
+
function drawInteriorFilaments(context, centerX, centerY, size, palette, timeMs, shapePhase) {
|
|
19069
|
+
for (let filamentIndex = 0; filamentIndex < 5; filamentIndex++) {
|
|
19070
|
+
const horizontalOffset = (filamentIndex - 2) * size * 0.075;
|
|
19071
|
+
const sway = Math.sin(timeMs / 720 + filamentIndex * 0.8 + shapePhase) * size * 0.028;
|
|
19072
|
+
context.beginPath();
|
|
19073
|
+
context.moveTo(centerX + horizontalOffset * 0.35, centerY - size * 0.11);
|
|
19074
|
+
context.bezierCurveTo(centerX + horizontalOffset - sway * 0.35, centerY - size * 0.01, centerX + horizontalOffset + sway, centerY + size * 0.13, centerX + horizontalOffset * 0.85 + sway * 0.55, centerY + size * 0.3);
|
|
19075
|
+
context.strokeStyle = filamentIndex % 2 === 0 ? `${palette.highlight}29` : `${palette.accent}24`;
|
|
19076
|
+
context.lineWidth = size * (0.01 + filamentIndex * 0.0008);
|
|
19077
|
+
context.lineCap = 'round';
|
|
19078
|
+
context.stroke();
|
|
19079
|
+
}
|
|
19080
|
+
}
|
|
19081
|
+
/**
|
|
19082
|
+
* Draws soft sucker-like highlights in the lower body area.
|
|
19083
|
+
*
|
|
19084
|
+
* @param context Canvas 2D context.
|
|
19085
|
+
* @param centerX Body center X coordinate.
|
|
19086
|
+
* @param centerY Body center Y coordinate.
|
|
19087
|
+
* @param size Canvas size in CSS pixels.
|
|
19088
|
+
* @param palette Derived avatar palette.
|
|
19089
|
+
* @param createRandom Seeded random factory scoped to the avatar.
|
|
19090
|
+
* @param timeMs Current animation time in milliseconds.
|
|
19091
|
+
*
|
|
19092
|
+
* @private helper of `octopus2AvatarVisual`
|
|
19093
|
+
*/
|
|
19094
|
+
function drawLowerSuckers(context, centerX, centerY, size, palette, createRandom, timeMs) {
|
|
19095
|
+
const suckerRandom = createRandom('octopus2-suckers');
|
|
19096
|
+
for (let suckerIndex = 0; suckerIndex < 12; suckerIndex++) {
|
|
19097
|
+
const x = centerX + (suckerRandom() - 0.5) * size * 0.36;
|
|
19098
|
+
const y = centerY + size * (0.11 + suckerRandom() * 0.22);
|
|
19099
|
+
const radiusX = size * (0.015 + suckerRandom() * 0.012);
|
|
19100
|
+
const radiusY = radiusX * (0.72 + suckerRandom() * 0.34);
|
|
19101
|
+
const rotation = suckerRandom() * Math.PI + Math.sin(timeMs / 1100 + suckerIndex) * 0.08;
|
|
19102
|
+
context.beginPath();
|
|
19103
|
+
context.ellipse(x, y, radiusX, radiusY, rotation, 0, Math.PI * 2);
|
|
19104
|
+
context.fillStyle = `${palette.highlight}24`;
|
|
19105
|
+
context.fill();
|
|
19106
|
+
context.strokeStyle = `${palette.highlight}40`;
|
|
19107
|
+
context.lineWidth = Math.max(1, size * 0.005);
|
|
19108
|
+
context.stroke();
|
|
19109
|
+
}
|
|
19110
|
+
}
|
|
19111
|
+
/**
|
|
19112
|
+
* Draws one luminous alien eye on top of the organic octopus mesh.
|
|
19113
|
+
*
|
|
19114
|
+
* @param context Canvas 2D context.
|
|
19115
|
+
* @param centerX Eye center X coordinate.
|
|
19116
|
+
* @param centerY Eye center Y coordinate.
|
|
19117
|
+
* @param radiusX Eye horizontal radius.
|
|
19118
|
+
* @param radiusY Eye vertical radius.
|
|
19119
|
+
* @param palette Derived avatar palette.
|
|
19120
|
+
* @param timeMs Current animation time in milliseconds.
|
|
19121
|
+
* @param phase Seed-based animation phase.
|
|
19122
|
+
* @param interaction Smoothed avatar interaction state.
|
|
19123
|
+
*
|
|
19124
|
+
* @private helper of `octopus2AvatarVisual`
|
|
19125
|
+
*/
|
|
19126
|
+
function drawAlienEye(context, centerX, centerY, radiusX, radiusY, palette, timeMs, phase, interaction) {
|
|
19127
|
+
const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
|
|
19128
|
+
radiusX,
|
|
19129
|
+
radiusY,
|
|
19130
|
+
timeMs,
|
|
19131
|
+
phase,
|
|
19132
|
+
interaction,
|
|
19133
|
+
autonomousDriftRatioY: 0.1,
|
|
19134
|
+
});
|
|
19135
|
+
context.save();
|
|
19136
|
+
context.beginPath();
|
|
19137
|
+
context.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, Math.PI * 2);
|
|
19138
|
+
context.fillStyle = '#f8fbff';
|
|
19139
|
+
context.fill();
|
|
19140
|
+
context.clip();
|
|
19141
|
+
const irisGradient = context.createRadialGradient(centerX - radiusX * 0.18, centerY - radiusY * 0.22, radiusX * 0.05, centerX, centerY, radiusX * 0.9);
|
|
19142
|
+
irisGradient.addColorStop(0, palette.highlight);
|
|
19143
|
+
irisGradient.addColorStop(0.55, palette.secondary);
|
|
19144
|
+
irisGradient.addColorStop(1, palette.shadow);
|
|
19145
|
+
context.beginPath();
|
|
19146
|
+
context.ellipse(centerX + pupilOffsetX, centerY + pupilOffsetY, radiusX * 0.68, radiusY * 0.72, 0, 0, Math.PI * 2);
|
|
19147
|
+
context.fillStyle = irisGradient;
|
|
19148
|
+
context.fill();
|
|
19149
|
+
context.beginPath();
|
|
19150
|
+
context.ellipse(centerX + pupilOffsetX, centerY + pupilOffsetY, radiusX * 0.16, radiusY * 0.48, 0, 0, Math.PI * 2);
|
|
19151
|
+
context.fillStyle = palette.ink;
|
|
19152
|
+
context.fill();
|
|
19153
|
+
context.beginPath();
|
|
19154
|
+
context.ellipse(centerX + pupilOffsetX - radiusX * 0.18, centerY + pupilOffsetY - radiusY * 0.24, radiusX * 0.12, radiusY * 0.14, 0, 0, Math.PI * 2);
|
|
19155
|
+
context.fillStyle = '#ffffff';
|
|
19156
|
+
context.fill();
|
|
19157
|
+
context.restore();
|
|
19158
|
+
context.beginPath();
|
|
19159
|
+
context.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, Math.PI * 2);
|
|
19160
|
+
context.strokeStyle = `${palette.shadow}cc`;
|
|
19161
|
+
context.lineWidth = radiusX * 0.2;
|
|
19162
|
+
context.stroke();
|
|
19163
|
+
}
|
|
19164
|
+
|
|
19165
|
+
/* eslint-disable no-magic-numbers */
|
|
19166
|
+
/**
|
|
19167
|
+
* Builds one deterministic morphology profile for `Octopus3`.
|
|
19168
|
+
*
|
|
19169
|
+
* @param createRandom Seeded random factory scoped to the current avatar.
|
|
19170
|
+
* @returns Stable morphology profile.
|
|
19171
|
+
*
|
|
19172
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19173
|
+
*/
|
|
19174
|
+
function createOctopus3MorphologyProfile(createRandom) {
|
|
19175
|
+
const bodyRandom = createRandom('octopus3-body-profile');
|
|
19176
|
+
const faceRandom = createRandom('octopus3-face-profile');
|
|
19177
|
+
const detailRandom = createRandom('octopus3-detail-profile');
|
|
19178
|
+
const bodyFamilyRoll = bodyRandom();
|
|
19179
|
+
let bodyFamily;
|
|
19180
|
+
let body;
|
|
19181
|
+
let tentacles;
|
|
19182
|
+
if (bodyFamilyRoll < 0.34) {
|
|
19183
|
+
bodyFamily = 'lantern';
|
|
19184
|
+
body = {
|
|
19185
|
+
centerXJitterRatio: resolveSeededRange(bodyRandom, -0.018, 0.018),
|
|
19186
|
+
centerYRatio: resolveSeededRange(bodyRandom, 0.39, 0.435),
|
|
19187
|
+
bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.19, 0.23),
|
|
19188
|
+
horizontalStretch: resolveSeededRange(bodyRandom, 0.94, 1.08),
|
|
19189
|
+
verticalStretch: resolveSeededRange(bodyRandom, 1.02, 1.18),
|
|
19190
|
+
mantleLiftRatio: resolveSeededRange(bodyRandom, 0.115, 0.148),
|
|
19191
|
+
lowerDropRatio: resolveSeededRange(bodyRandom, 0.042, 0.066),
|
|
19192
|
+
tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.018, 0.03),
|
|
19193
|
+
wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.009, 0.017),
|
|
19194
|
+
lobeCount: resolveSeededIntegerRange(bodyRandom, 4, 6),
|
|
19195
|
+
pointCount: resolveSeededIntegerRange(bodyRandom, 38, 42),
|
|
19196
|
+
shadowWidthRatio: resolveSeededRange(bodyRandom, 0.18, 0.23),
|
|
19197
|
+
shadowHeightRatio: resolveSeededRange(bodyRandom, 0.055, 0.075),
|
|
19198
|
+
crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.14, 0.18),
|
|
19199
|
+
crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.045, 0.062),
|
|
19200
|
+
crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.165, -0.135),
|
|
19201
|
+
};
|
|
19202
|
+
tentacles = {
|
|
19203
|
+
count: resolveSeededIntegerRange(bodyRandom, 7, 10),
|
|
19204
|
+
flowLengthScale: resolveSeededRange(bodyRandom, 1.08, 1.34),
|
|
19205
|
+
lateralReachScale: resolveSeededRange(bodyRandom, 0.72, 0.94),
|
|
19206
|
+
tipReachScale: resolveSeededRange(bodyRandom, 0.82, 1.06),
|
|
19207
|
+
baseWidthScale: resolveSeededRange(bodyRandom, 0.82, 0.98),
|
|
19208
|
+
tipWidthScale: resolveSeededRange(bodyRandom, 0.9, 1.08),
|
|
19209
|
+
rootSpreadScale: resolveSeededRange(bodyRandom, 0.76, 0.94),
|
|
19210
|
+
startYOffsetScale: resolveSeededRange(bodyRandom, 0.82, 1),
|
|
19211
|
+
swayScale: resolveSeededRange(bodyRandom, 0.82, 1.02),
|
|
19212
|
+
};
|
|
19213
|
+
}
|
|
19214
|
+
else if (bodyFamilyRoll < 0.68) {
|
|
19215
|
+
bodyFamily = 'drifter';
|
|
19216
|
+
body = {
|
|
19217
|
+
centerXJitterRatio: resolveSeededRange(bodyRandom, -0.025, 0.025),
|
|
19218
|
+
centerYRatio: resolveSeededRange(bodyRandom, 0.425, 0.46),
|
|
19219
|
+
bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.175, 0.215),
|
|
19220
|
+
horizontalStretch: resolveSeededRange(bodyRandom, 1.22, 1.42),
|
|
19221
|
+
verticalStretch: resolveSeededRange(bodyRandom, 0.82, 0.92),
|
|
19222
|
+
mantleLiftRatio: resolveSeededRange(bodyRandom, 0.092, 0.115),
|
|
19223
|
+
lowerDropRatio: resolveSeededRange(bodyRandom, 0.02, 0.036),
|
|
19224
|
+
tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.032, 0.052),
|
|
19225
|
+
wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.013, 0.022),
|
|
19226
|
+
lobeCount: resolveSeededIntegerRange(bodyRandom, 7, 9),
|
|
19227
|
+
pointCount: resolveSeededIntegerRange(bodyRandom, 40, 46),
|
|
19228
|
+
shadowWidthRatio: resolveSeededRange(bodyRandom, 0.24, 0.28),
|
|
19229
|
+
shadowHeightRatio: resolveSeededRange(bodyRandom, 0.06, 0.082),
|
|
19230
|
+
crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.17, 0.22),
|
|
19231
|
+
crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.038, 0.055),
|
|
19232
|
+
crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.14, -0.11),
|
|
19233
|
+
};
|
|
19234
|
+
tentacles = {
|
|
19235
|
+
count: resolveSeededIntegerRange(bodyRandom, 10, 13),
|
|
19236
|
+
flowLengthScale: resolveSeededRange(bodyRandom, 0.88, 1.08),
|
|
19237
|
+
lateralReachScale: resolveSeededRange(bodyRandom, 1.18, 1.42),
|
|
19238
|
+
tipReachScale: resolveSeededRange(bodyRandom, 1.12, 1.42),
|
|
19239
|
+
baseWidthScale: resolveSeededRange(bodyRandom, 0.9, 1.06),
|
|
19240
|
+
tipWidthScale: resolveSeededRange(bodyRandom, 0.88, 1.08),
|
|
19241
|
+
rootSpreadScale: resolveSeededRange(bodyRandom, 1.12, 1.32),
|
|
19242
|
+
startYOffsetScale: resolveSeededRange(bodyRandom, 0.92, 1.14),
|
|
19243
|
+
swayScale: resolveSeededRange(bodyRandom, 1.04, 1.22),
|
|
19244
|
+
};
|
|
19245
|
+
}
|
|
19246
|
+
else {
|
|
19247
|
+
bodyFamily = 'rounded';
|
|
19248
|
+
body = {
|
|
19249
|
+
centerXJitterRatio: resolveSeededRange(bodyRandom, -0.02, 0.02),
|
|
19250
|
+
centerYRatio: resolveSeededRange(bodyRandom, 0.398, 0.442),
|
|
19251
|
+
bodyRadiusRatio: resolveSeededRange(bodyRandom, 0.208, 0.248),
|
|
19252
|
+
horizontalStretch: resolveSeededRange(bodyRandom, 1.06, 1.22),
|
|
19253
|
+
verticalStretch: resolveSeededRange(bodyRandom, 0.9, 1.01),
|
|
19254
|
+
mantleLiftRatio: resolveSeededRange(bodyRandom, 0.1, 0.128),
|
|
19255
|
+
lowerDropRatio: resolveSeededRange(bodyRandom, 0.032, 0.052),
|
|
19256
|
+
tentacleDepthRatio: resolveSeededRange(bodyRandom, 0.038, 0.06),
|
|
19257
|
+
wobbleAmplitudeRatio: resolveSeededRange(bodyRandom, 0.014, 0.024),
|
|
19258
|
+
lobeCount: resolveSeededIntegerRange(bodyRandom, 5, 8),
|
|
19259
|
+
pointCount: resolveSeededIntegerRange(bodyRandom, 39, 44),
|
|
19260
|
+
shadowWidthRatio: resolveSeededRange(bodyRandom, 0.2, 0.25),
|
|
19261
|
+
shadowHeightRatio: resolveSeededRange(bodyRandom, 0.055, 0.08),
|
|
19262
|
+
crownHighlightWidthRatio: resolveSeededRange(bodyRandom, 0.16, 0.2),
|
|
19263
|
+
crownHighlightHeightRatio: resolveSeededRange(bodyRandom, 0.05, 0.07),
|
|
19264
|
+
crownHighlightYOffsetRatio: resolveSeededRange(bodyRandom, -0.155, -0.122),
|
|
19265
|
+
};
|
|
19266
|
+
tentacles = {
|
|
19267
|
+
count: resolveSeededIntegerRange(bodyRandom, 8, 12),
|
|
19268
|
+
flowLengthScale: resolveSeededRange(bodyRandom, 0.94, 1.16),
|
|
19269
|
+
lateralReachScale: resolveSeededRange(bodyRandom, 0.9, 1.14),
|
|
19270
|
+
tipReachScale: resolveSeededRange(bodyRandom, 0.96, 1.22),
|
|
19271
|
+
baseWidthScale: resolveSeededRange(bodyRandom, 1.02, 1.2),
|
|
19272
|
+
tipWidthScale: resolveSeededRange(bodyRandom, 1.02, 1.22),
|
|
19273
|
+
rootSpreadScale: resolveSeededRange(bodyRandom, 0.94, 1.08),
|
|
19274
|
+
startYOffsetScale: resolveSeededRange(bodyRandom, 0.9, 1.08),
|
|
19275
|
+
swayScale: resolveSeededRange(bodyRandom, 0.9, 1.1),
|
|
19276
|
+
};
|
|
19277
|
+
}
|
|
19278
|
+
const faceFamilyRoll = faceRandom();
|
|
19279
|
+
let faceFamily;
|
|
19280
|
+
let face;
|
|
19281
|
+
if (faceFamilyRoll < 0.34) {
|
|
19282
|
+
faceFamily = 'watchful';
|
|
19283
|
+
face = {
|
|
19284
|
+
eyeSpacingRatio: resolveSeededRange(faceRandom, 0.118, 0.152),
|
|
19285
|
+
eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.026, -0.002),
|
|
19286
|
+
eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.05, 0.062),
|
|
19287
|
+
eyeHeightRatio: resolveSeededRange(faceRandom, 1.18, 1.38),
|
|
19288
|
+
eyeRotationRange: resolveSeededRange(faceRandom, 0.16, 0.28),
|
|
19289
|
+
eyeTiltBias: resolveSeededRange(faceRandom, 0.02, 0.06),
|
|
19290
|
+
mouthWidthRatio: resolveSeededRange(faceRandom, 0.058, 0.074),
|
|
19291
|
+
mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.086, 0.104),
|
|
19292
|
+
mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.126, 0.15),
|
|
19293
|
+
mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.006, 0.006),
|
|
19294
|
+
mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.002, 0.002),
|
|
19295
|
+
eyeStyle: {
|
|
19296
|
+
irisScale: resolveSeededRange(faceRandom, 1, 1.1),
|
|
19297
|
+
pupilWidthScale: resolveSeededRange(faceRandom, 0.86, 1.02),
|
|
19298
|
+
pupilHeightScale: resolveSeededRange(faceRandom, 0.94, 1.08),
|
|
19299
|
+
upperLidArchRatio: resolveSeededRange(faceRandom, 0.96, 1.12),
|
|
19300
|
+
upperLidInsetRatio: resolveSeededRange(faceRandom, 0.08, 0.14),
|
|
19301
|
+
lowerLidOpacity: resolveSeededRange(faceRandom, 0.12, 0.22),
|
|
19302
|
+
},
|
|
19303
|
+
};
|
|
19304
|
+
}
|
|
19305
|
+
else if (faceFamilyRoll < 0.68) {
|
|
19306
|
+
faceFamily = 'sleepy';
|
|
19307
|
+
face = {
|
|
19308
|
+
eyeSpacingRatio: resolveSeededRange(faceRandom, 0.092, 0.124),
|
|
19309
|
+
eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.002, 0.024),
|
|
19310
|
+
eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.058, 0.074),
|
|
19311
|
+
eyeHeightRatio: resolveSeededRange(faceRandom, 0.96, 1.14),
|
|
19312
|
+
eyeRotationRange: resolveSeededRange(faceRandom, 0.1, 0.22),
|
|
19313
|
+
eyeTiltBias: resolveSeededRange(faceRandom, 0.01, 0.05),
|
|
19314
|
+
mouthWidthRatio: resolveSeededRange(faceRandom, 0.066, 0.086),
|
|
19315
|
+
mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.094, 0.118),
|
|
19316
|
+
mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.118, 0.145),
|
|
19317
|
+
mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.004, 0.004),
|
|
19318
|
+
mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.004, 0.004),
|
|
19319
|
+
eyeStyle: {
|
|
19320
|
+
irisScale: resolveSeededRange(faceRandom, 0.9, 1),
|
|
19321
|
+
pupilWidthScale: resolveSeededRange(faceRandom, 1, 1.18),
|
|
19322
|
+
pupilHeightScale: resolveSeededRange(faceRandom, 0.78, 0.92),
|
|
19323
|
+
upperLidArchRatio: resolveSeededRange(faceRandom, 0.7, 0.88),
|
|
19324
|
+
upperLidInsetRatio: resolveSeededRange(faceRandom, -0.02, 0.06),
|
|
19325
|
+
lowerLidOpacity: resolveSeededRange(faceRandom, 0.22, 0.34),
|
|
19326
|
+
},
|
|
19327
|
+
};
|
|
19328
|
+
}
|
|
19329
|
+
else {
|
|
19330
|
+
faceFamily = 'mischief';
|
|
19331
|
+
face = {
|
|
19332
|
+
eyeSpacingRatio: resolveSeededRange(faceRandom, 0.086, 0.114),
|
|
19333
|
+
eyeCenterYOffsetRatio: resolveSeededRange(faceRandom, -0.018, 0.01),
|
|
19334
|
+
eyeRadiusXRatio: resolveSeededRange(faceRandom, 0.046, 0.06),
|
|
19335
|
+
eyeHeightRatio: resolveSeededRange(faceRandom, 1.08, 1.28),
|
|
19336
|
+
eyeRotationRange: resolveSeededRange(faceRandom, 0.28, 0.44),
|
|
19337
|
+
eyeTiltBias: resolveSeededRange(faceRandom, 0.12, 0.22),
|
|
19338
|
+
mouthWidthRatio: resolveSeededRange(faceRandom, 0.052, 0.074),
|
|
19339
|
+
mouthYOffsetRatio: resolveSeededRange(faceRandom, 0.082, 0.1),
|
|
19340
|
+
mouthCurveDepthRatio: resolveSeededRange(faceRandom, 0.116, 0.15),
|
|
19341
|
+
mouthCenterOffsetRatio: resolveSeededRange(faceRandom, -0.018, 0.018),
|
|
19342
|
+
mouthCornerTiltRatio: resolveSeededRange(faceRandom, -0.01, 0.01),
|
|
19343
|
+
eyeStyle: {
|
|
19344
|
+
irisScale: resolveSeededRange(faceRandom, 1.04, 1.12),
|
|
19345
|
+
pupilWidthScale: resolveSeededRange(faceRandom, 0.72, 0.9),
|
|
19346
|
+
pupilHeightScale: resolveSeededRange(faceRandom, 0.96, 1.14),
|
|
19347
|
+
upperLidArchRatio: resolveSeededRange(faceRandom, 0.88, 1.02),
|
|
19348
|
+
upperLidInsetRatio: resolveSeededRange(faceRandom, 0.04, 0.12),
|
|
19349
|
+
lowerLidOpacity: resolveSeededRange(faceRandom, 0.08, 0.18),
|
|
19350
|
+
},
|
|
19351
|
+
};
|
|
19352
|
+
}
|
|
19353
|
+
return {
|
|
19354
|
+
bodyFamily,
|
|
19355
|
+
faceFamily,
|
|
19356
|
+
body,
|
|
19357
|
+
tentacles,
|
|
19358
|
+
face,
|
|
19359
|
+
details: {
|
|
19360
|
+
mantleCurrentCount: resolveSeededIntegerRange(detailRandom, 4, 8),
|
|
19361
|
+
mantleNodeCount: resolveSeededIntegerRange(detailRandom, 3, 7),
|
|
19362
|
+
},
|
|
19363
|
+
};
|
|
19364
|
+
}
|
|
19365
|
+
/**
|
|
19366
|
+
* Resolves one seeded floating-point number inside the provided range.
|
|
19367
|
+
*
|
|
19368
|
+
* @param random Seeded random generator.
|
|
19369
|
+
* @param minimumValue Inclusive lower bound.
|
|
19370
|
+
* @param maximumValue Inclusive upper bound.
|
|
19371
|
+
* @returns Seeded number within the range.
|
|
19372
|
+
*
|
|
19373
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19374
|
+
*/
|
|
19375
|
+
function resolveSeededRange(random, minimumValue, maximumValue) {
|
|
19376
|
+
return minimumValue + random() * (maximumValue - minimumValue);
|
|
19377
|
+
}
|
|
19378
|
+
/**
|
|
19379
|
+
* Resolves one seeded integer inside the provided inclusive range.
|
|
19380
|
+
*
|
|
19381
|
+
* @param random Seeded random generator.
|
|
19382
|
+
* @param minimumValue Inclusive lower bound.
|
|
19383
|
+
* @param maximumValue Inclusive upper bound.
|
|
19384
|
+
* @returns Seeded integer within the range.
|
|
19385
|
+
*
|
|
19386
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19387
|
+
*/
|
|
19388
|
+
function resolveSeededIntegerRange(random, minimumValue, maximumValue) {
|
|
19389
|
+
return minimumValue + Math.floor(random() * (maximumValue - minimumValue + 1));
|
|
19390
|
+
}
|
|
19391
|
+
/**
|
|
19392
|
+
* Converts an opacity ratio into a two-digit hexadecimal alpha suffix.
|
|
19393
|
+
*
|
|
19394
|
+
* @param opacity Opacity ratio in the range `[0, 1]`.
|
|
19395
|
+
* @returns Two-digit hexadecimal alpha string.
|
|
19396
|
+
*
|
|
19397
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19398
|
+
*/
|
|
19399
|
+
function formatAlphaHex(opacity) {
|
|
19400
|
+
return Math.round(Math.min(1, Math.max(0, opacity)) * 255)
|
|
19401
|
+
.toString(16)
|
|
19402
|
+
.padStart(2, '0');
|
|
19403
|
+
}
|
|
19404
|
+
/**
|
|
19405
|
+
* Octopus3 avatar visual.
|
|
19406
|
+
*
|
|
19407
|
+
* @private built-in avatar visual
|
|
19408
|
+
*/
|
|
19409
|
+
const octopus3AvatarVisual = {
|
|
19410
|
+
id: 'octopus3',
|
|
19411
|
+
title: 'Octopus3',
|
|
19412
|
+
description: 'Gelatinous alien octopus with a morphing mantle, responsive eyes, and visible ribbon tentacles.',
|
|
19413
|
+
isAnimated: true,
|
|
19414
|
+
supportsPointerTracking: true,
|
|
19415
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
19416
|
+
const morphologyProfile = createOctopus3MorphologyProfile(createRandom);
|
|
19417
|
+
const animationRandom = createRandom('octopus3-animation-profile');
|
|
19418
|
+
const eyeRandom = createRandom('octopus3-eye-profile');
|
|
19419
|
+
const centerX = size * (0.5 + morphologyProfile.body.centerXJitterRatio) + interaction.bodyOffsetX * size * 0.05;
|
|
19420
|
+
const centerY = size * morphologyProfile.body.centerYRatio + interaction.bodyOffsetY * size * 0.035;
|
|
19421
|
+
const bodyRadius = size * morphologyProfile.body.bodyRadiusRatio;
|
|
19422
|
+
const horizontalStretch = morphologyProfile.body.horizontalStretch;
|
|
19423
|
+
const verticalStretch = morphologyProfile.body.verticalStretch;
|
|
19424
|
+
const mantleLift = size * morphologyProfile.body.mantleLiftRatio;
|
|
19425
|
+
const lowerDrop = size * morphologyProfile.body.lowerDropRatio;
|
|
19426
|
+
const tentacleDepth = size * morphologyProfile.body.tentacleDepthRatio;
|
|
19427
|
+
const wobbleAmplitude = size * morphologyProfile.body.wobbleAmplitudeRatio;
|
|
19428
|
+
const lobeCount = morphologyProfile.body.lobeCount;
|
|
19429
|
+
const shapePhase = animationRandom() * Math.PI * 2;
|
|
19430
|
+
const eyeSpacing = size * morphologyProfile.face.eyeSpacingRatio;
|
|
19431
|
+
const eyeCenterY = centerY + size * morphologyProfile.face.eyeCenterYOffsetRatio;
|
|
19432
|
+
const eyeRadiusX = size * morphologyProfile.face.eyeRadiusXRatio;
|
|
19433
|
+
const eyeRadiusY = eyeRadiusX * morphologyProfile.face.eyeHeightRatio;
|
|
19434
|
+
const bodyPoints = createOrganicOctopusBodyPoints({
|
|
19435
|
+
centerX,
|
|
19436
|
+
centerY,
|
|
19437
|
+
bodyRadius,
|
|
19438
|
+
horizontalStretch,
|
|
19439
|
+
verticalStretch,
|
|
19440
|
+
mantleLift,
|
|
19441
|
+
lowerDrop,
|
|
19442
|
+
tentacleDepth,
|
|
19443
|
+
wobbleAmplitude,
|
|
19444
|
+
lobeCount,
|
|
19445
|
+
shapePhase,
|
|
19446
|
+
timeMs,
|
|
19447
|
+
pointCount: morphologyProfile.body.pointCount,
|
|
19448
|
+
});
|
|
19449
|
+
const tentacleShapes = createOrganicOctopusTentacleShapes({
|
|
19450
|
+
size,
|
|
19451
|
+
centerX,
|
|
19452
|
+
centerY,
|
|
19453
|
+
bodyRadius,
|
|
19454
|
+
horizontalStretch,
|
|
19455
|
+
tentacleCount: morphologyProfile.tentacles.count,
|
|
19456
|
+
shapePhase,
|
|
19457
|
+
createRandom,
|
|
19458
|
+
timeMs,
|
|
19459
|
+
saltPrefix: 'octopus3',
|
|
19460
|
+
bodyPoints,
|
|
19461
|
+
variation: {
|
|
19462
|
+
flowLengthScale: morphologyProfile.tentacles.flowLengthScale,
|
|
19463
|
+
lateralReachScale: morphologyProfile.tentacles.lateralReachScale,
|
|
19464
|
+
tipReachScale: morphologyProfile.tentacles.tipReachScale,
|
|
19465
|
+
baseWidthScale: morphologyProfile.tentacles.baseWidthScale,
|
|
19466
|
+
tipWidthScale: morphologyProfile.tentacles.tipWidthScale,
|
|
19467
|
+
rootSpreadScale: morphologyProfile.tentacles.rootSpreadScale,
|
|
19468
|
+
startYOffsetScale: morphologyProfile.tentacles.startYOffsetScale,
|
|
19469
|
+
swayScale: morphologyProfile.tentacles.swayScale,
|
|
19470
|
+
},
|
|
19471
|
+
});
|
|
19472
|
+
drawAvatarFrame(context, size, palette);
|
|
19473
|
+
drawOctopus3Atmosphere(context, size, palette, centerX, centerY, timeMs, shapePhase, morphologyProfile);
|
|
19474
|
+
context.beginPath();
|
|
19475
|
+
context.ellipse(centerX, centerY + size * 0.25, size * morphologyProfile.body.shadowWidthRatio, size * morphologyProfile.body.shadowHeightRatio, 0, 0, Math.PI * 2);
|
|
19476
|
+
context.fillStyle = `${palette.shadow}33`;
|
|
19477
|
+
context.fill();
|
|
19478
|
+
for (const tentacleShape of tentacleShapes) {
|
|
19479
|
+
drawTentacleRibbon(context, tentacleShape, palette);
|
|
19480
|
+
}
|
|
19481
|
+
context.save();
|
|
19482
|
+
traceSmoothClosedPath(context, bodyPoints);
|
|
19483
|
+
const bodyGradient = context.createRadialGradient(centerX - size * 0.1, centerY - size * 0.18, size * 0.04, centerX, centerY + size * 0.16, size * 0.54);
|
|
19484
|
+
bodyGradient.addColorStop(0, palette.highlight);
|
|
19485
|
+
bodyGradient.addColorStop(0.18, palette.secondary);
|
|
19486
|
+
bodyGradient.addColorStop(0.55, palette.primary);
|
|
19487
|
+
bodyGradient.addColorStop(1, palette.shadow);
|
|
19488
|
+
context.fillStyle = bodyGradient;
|
|
19489
|
+
context.shadowColor = `${palette.shadow}aa`;
|
|
19490
|
+
context.shadowBlur = size * 0.08;
|
|
19491
|
+
context.shadowOffsetY = size * 0.02;
|
|
19492
|
+
context.fill();
|
|
19493
|
+
context.restore();
|
|
19494
|
+
context.save();
|
|
19495
|
+
traceSmoothClosedPath(context, bodyPoints);
|
|
19496
|
+
context.clip();
|
|
19497
|
+
const innerGlowGradient = context.createLinearGradient(centerX, centerY - size * 0.24, centerX, centerY + size * 0.26);
|
|
19498
|
+
innerGlowGradient.addColorStop(0, `${palette.highlight}66`);
|
|
19499
|
+
innerGlowGradient.addColorStop(0.4, `${palette.secondary}26`);
|
|
19500
|
+
innerGlowGradient.addColorStop(1, `${palette.shadow}00`);
|
|
19501
|
+
context.fillStyle = innerGlowGradient;
|
|
19502
|
+
context.fillRect(centerX - size * 0.36, centerY - size * 0.34, size * 0.72, size * 0.72);
|
|
19503
|
+
drawMantleCurrents(context, centerX, centerY, size, palette, timeMs, shapePhase, morphologyProfile);
|
|
19504
|
+
drawMantleNodes(context, centerX, centerY, size, palette, createRandom, morphologyProfile);
|
|
19505
|
+
context.restore();
|
|
19506
|
+
context.save();
|
|
19507
|
+
traceSmoothClosedPath(context, bodyPoints);
|
|
19508
|
+
context.strokeStyle = `${palette.highlight}73`;
|
|
19509
|
+
context.lineWidth = size * 0.013;
|
|
19510
|
+
context.stroke();
|
|
19511
|
+
context.restore();
|
|
19512
|
+
context.beginPath();
|
|
19513
|
+
context.ellipse(centerX, centerY + size * morphologyProfile.body.crownHighlightYOffsetRatio, size * morphologyProfile.body.crownHighlightWidthRatio, size * morphologyProfile.body.crownHighlightHeightRatio, 0, Math.PI, Math.PI * 2);
|
|
19514
|
+
context.fillStyle = `${palette.highlight}3d`;
|
|
19515
|
+
context.fill();
|
|
19516
|
+
drawSeededEye(context, centerX - eyeSpacing, eyeCenterY, eyeRadiusX, eyeRadiusY, -morphologyProfile.face.eyeTiltBias + (eyeRandom() - 0.5) * morphologyProfile.face.eyeRotationRange, palette, timeMs, shapePhase, interaction, morphologyProfile.face.eyeStyle);
|
|
19517
|
+
drawSeededEye(context, centerX + eyeSpacing, eyeCenterY, eyeRadiusX, eyeRadiusY, morphologyProfile.face.eyeTiltBias + (eyeRandom() - 0.5) * morphologyProfile.face.eyeRotationRange, palette, timeMs, shapePhase + Math.PI / 4, interaction, morphologyProfile.face.eyeStyle);
|
|
19518
|
+
const mouthHalfWidth = size * morphologyProfile.face.mouthWidthRatio;
|
|
19519
|
+
const mouthY = centerY + size * morphologyProfile.face.mouthYOffsetRatio;
|
|
19520
|
+
const mouthCornerTilt = size * morphologyProfile.face.mouthCornerTiltRatio;
|
|
19521
|
+
context.beginPath();
|
|
19522
|
+
context.moveTo(centerX - mouthHalfWidth, mouthY - mouthCornerTilt);
|
|
19523
|
+
context.quadraticCurveTo(centerX + size * morphologyProfile.face.mouthCenterOffsetRatio, centerY +
|
|
19524
|
+
size * (morphologyProfile.face.mouthCurveDepthRatio + Math.sin(timeMs / 620 + shapePhase) * 0.016) +
|
|
19525
|
+
interaction.gazeY * size * 0.012, centerX + mouthHalfWidth, mouthY + mouthCornerTilt);
|
|
19526
|
+
context.strokeStyle = `${palette.ink}b3`;
|
|
19527
|
+
context.lineWidth = size * 0.012;
|
|
19528
|
+
context.lineCap = 'round';
|
|
19529
|
+
context.stroke();
|
|
19530
|
+
},
|
|
19531
|
+
};
|
|
19532
|
+
/**
|
|
19533
|
+
* Draws the deep-sea glow around the Octopus3 silhouette.
|
|
19534
|
+
*
|
|
19535
|
+
* @param context Canvas 2D context.
|
|
19536
|
+
* @param size Canvas size in CSS pixels.
|
|
19537
|
+
* @param palette Derived avatar palette.
|
|
19538
|
+
* @param centerX Body center X coordinate.
|
|
19539
|
+
* @param centerY Body center Y coordinate.
|
|
19540
|
+
* @param timeMs Current animation time in milliseconds.
|
|
19541
|
+
* @param shapePhase Seed-based phase offset.
|
|
19542
|
+
* @param morphologyProfile Seeded morphology profile.
|
|
19543
|
+
*
|
|
19544
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19545
|
+
*/
|
|
19546
|
+
function drawOctopus3Atmosphere(context, size, palette, centerX, centerY, timeMs, shapePhase, morphologyProfile) {
|
|
19547
|
+
const haloGradient = context.createRadialGradient(centerX, centerY - size * (0.07 + (morphologyProfile.body.verticalStretch - 0.9) * 0.05), size * 0.06, centerX, centerY, size * (0.56 + morphologyProfile.body.bodyRadiusRatio * 0.45));
|
|
19548
|
+
haloGradient.addColorStop(0, `${palette.highlight}5c`);
|
|
19549
|
+
haloGradient.addColorStop(0.35, `${palette.accent}26`);
|
|
19550
|
+
haloGradient.addColorStop(1, `${palette.highlight}00`);
|
|
19551
|
+
context.fillStyle = haloGradient;
|
|
19552
|
+
context.fillRect(0, 0, size, size);
|
|
19553
|
+
const lowerGlowGradient = context.createRadialGradient(centerX + Math.sin(timeMs / 1600 + shapePhase) * size * 0.04, centerY + size * (0.18 + morphologyProfile.tentacles.flowLengthScale * 0.025), size * 0.04, centerX, centerY + size * (0.18 + morphologyProfile.tentacles.flowLengthScale * 0.025), size * (0.42 + morphologyProfile.tentacles.lateralReachScale * 0.06));
|
|
19554
|
+
lowerGlowGradient.addColorStop(0, `${palette.secondary}1f`);
|
|
19555
|
+
lowerGlowGradient.addColorStop(1, `${palette.secondary}00`);
|
|
19556
|
+
context.fillStyle = lowerGlowGradient;
|
|
19557
|
+
context.fillRect(0, 0, size, size);
|
|
19558
|
+
}
|
|
19559
|
+
/**
|
|
19560
|
+
* Draws one ribbon tentacle with a filled organic profile and visible sucker highlights.
|
|
19561
|
+
*
|
|
19562
|
+
* @param context Canvas 2D context.
|
|
19563
|
+
* @param tentacleShape Deterministic tentacle descriptor.
|
|
19564
|
+
* @param palette Derived avatar palette.
|
|
19565
|
+
*
|
|
19566
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19567
|
+
*/
|
|
19568
|
+
function drawTentacleRibbon(context, tentacleShape, palette) {
|
|
19569
|
+
const ribbonPoints = sampleOrganicTentacleRibbonPoints(tentacleShape);
|
|
19570
|
+
const gradient = context.createLinearGradient(tentacleShape.startPoint.x, tentacleShape.startPoint.y, tentacleShape.endPoint.x, tentacleShape.endPoint.y);
|
|
19571
|
+
gradient.addColorStop(0, tentacleShape.colorBias < 0.35 ? palette.secondary : palette.primary);
|
|
19572
|
+
gradient.addColorStop(0.58, palette.primary);
|
|
19573
|
+
gradient.addColorStop(1, tentacleShape.colorBias > 0.65 ? palette.highlight : palette.accent);
|
|
19574
|
+
context.save();
|
|
19575
|
+
traceTentacleRibbonPath(context, ribbonPoints);
|
|
19576
|
+
context.fillStyle = gradient;
|
|
19577
|
+
context.shadowColor = `${palette.shadow}80`;
|
|
19578
|
+
context.shadowBlur = tentacleShape.baseWidth * 1.2;
|
|
19579
|
+
context.shadowOffsetY = tentacleShape.baseWidth * 0.2;
|
|
19580
|
+
context.fill();
|
|
19581
|
+
context.restore();
|
|
19582
|
+
context.save();
|
|
19583
|
+
traceTentacleRibbonPath(context, ribbonPoints);
|
|
19584
|
+
context.strokeStyle = tentacleShape.highlightBias > 0.5 ? `${palette.highlight}52` : `${palette.highlight}38`;
|
|
19585
|
+
context.lineWidth = Math.max(1, tentacleShape.baseWidth * 0.12);
|
|
19586
|
+
context.stroke();
|
|
19587
|
+
context.restore();
|
|
19588
|
+
context.beginPath();
|
|
19589
|
+
context.moveTo(tentacleShape.startPoint.x, tentacleShape.startPoint.y);
|
|
19590
|
+
context.bezierCurveTo(tentacleShape.controlPointOne.x, tentacleShape.controlPointOne.y, tentacleShape.controlPointTwo.x, tentacleShape.controlPointTwo.y, tentacleShape.endPoint.x, tentacleShape.endPoint.y);
|
|
19591
|
+
context.strokeStyle = `${palette.highlight}2e`;
|
|
19592
|
+
context.lineWidth = Math.max(1, tentacleShape.tipWidth * 0.9);
|
|
19593
|
+
context.lineCap = 'round';
|
|
19594
|
+
context.stroke();
|
|
19595
|
+
drawTentacleSuckers(context, tentacleShape, palette);
|
|
19596
|
+
}
|
|
19597
|
+
/**
|
|
19598
|
+
* Traces a closed ribbon path from sampled tentacle points.
|
|
19599
|
+
*
|
|
19600
|
+
* @param context Canvas 2D context.
|
|
19601
|
+
* @param ribbonPoints Sampled ribbon points.
|
|
19602
|
+
*
|
|
19603
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19604
|
+
*/
|
|
19605
|
+
function traceTentacleRibbonPath(context, ribbonPoints) {
|
|
19606
|
+
const firstRibbonPoint = ribbonPoints[0];
|
|
19607
|
+
context.beginPath();
|
|
19608
|
+
context.moveTo(firstRibbonPoint.x + firstRibbonPoint.normalX * firstRibbonPoint.width, firstRibbonPoint.y + firstRibbonPoint.normalY * firstRibbonPoint.width);
|
|
19609
|
+
for (const ribbonPoint of ribbonPoints.slice(1)) {
|
|
19610
|
+
context.lineTo(ribbonPoint.x + ribbonPoint.normalX * ribbonPoint.width, ribbonPoint.y + ribbonPoint.normalY * ribbonPoint.width);
|
|
19611
|
+
}
|
|
19612
|
+
for (const ribbonPoint of [...ribbonPoints].reverse()) {
|
|
19613
|
+
context.lineTo(ribbonPoint.x - ribbonPoint.normalX * ribbonPoint.width, ribbonPoint.y - ribbonPoint.normalY * ribbonPoint.width);
|
|
19614
|
+
}
|
|
19615
|
+
context.closePath();
|
|
19616
|
+
}
|
|
19617
|
+
/**
|
|
19618
|
+
* Draws a row of soft sucker highlights along one side of the ribbon tentacle.
|
|
19619
|
+
*
|
|
19620
|
+
* @param context Canvas 2D context.
|
|
19621
|
+
* @param tentacleShape Deterministic tentacle descriptor.
|
|
19622
|
+
* @param palette Derived avatar palette.
|
|
19623
|
+
*
|
|
19624
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19625
|
+
*/
|
|
19626
|
+
function drawTentacleSuckers(context, tentacleShape, palette) {
|
|
19627
|
+
const undersideDirection = tentacleShape.endPoint.x >= tentacleShape.startPoint.x ? -1 : 1;
|
|
19628
|
+
for (let suckerIndex = 0; suckerIndex < 4; suckerIndex++) {
|
|
19629
|
+
const progress = 0.22 + suckerIndex * 0.17;
|
|
19630
|
+
const point = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, progress);
|
|
19631
|
+
const previousPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.max(0, progress - 0.03));
|
|
19632
|
+
const nextPoint = getCubicBezierPoint(tentacleShape.startPoint, tentacleShape.controlPointOne, tentacleShape.controlPointTwo, tentacleShape.endPoint, Math.min(1, progress + 0.03));
|
|
19633
|
+
const tangentX = nextPoint.x - previousPoint.x;
|
|
19634
|
+
const tangentY = nextPoint.y - previousPoint.y;
|
|
19635
|
+
const tangentLength = Math.hypot(tangentX, tangentY) || 1;
|
|
19636
|
+
const normalX = (-tangentY / tangentLength) * undersideDirection;
|
|
19637
|
+
const normalY = (tangentX / tangentLength) * undersideDirection;
|
|
19638
|
+
const width = tentacleShape.baseWidth + (tentacleShape.tipWidth - tentacleShape.baseWidth) * Math.pow(progress, 1.1);
|
|
19639
|
+
const suckerX = point.x + normalX * width * 0.52;
|
|
19640
|
+
const suckerY = point.y + normalY * width * 0.52;
|
|
19641
|
+
const rotation = Math.atan2(normalY, normalX);
|
|
19642
|
+
context.beginPath();
|
|
19643
|
+
context.ellipse(suckerX, suckerY, width * 0.22, width * 0.11, rotation, 0, Math.PI * 2);
|
|
19644
|
+
context.fillStyle = `${palette.highlight}73`;
|
|
19645
|
+
context.fill();
|
|
19646
|
+
context.strokeStyle = `${palette.highlight}99`;
|
|
19647
|
+
context.lineWidth = Math.max(1, width * 0.08);
|
|
19648
|
+
context.stroke();
|
|
19649
|
+
}
|
|
19650
|
+
}
|
|
19651
|
+
/**
|
|
19652
|
+
* Draws slow inner currents inside the clipped Octopus3 mantle.
|
|
19653
|
+
*
|
|
19654
|
+
* @param context Canvas 2D context.
|
|
19655
|
+
* @param centerX Body center X coordinate.
|
|
19656
|
+
* @param centerY Body center Y coordinate.
|
|
19657
|
+
* @param size Canvas size in CSS pixels.
|
|
19658
|
+
* @param palette Derived avatar palette.
|
|
19659
|
+
* @param timeMs Current animation time in milliseconds.
|
|
19660
|
+
* @param shapePhase Seed-based phase offset.
|
|
19661
|
+
* @param morphologyProfile Seeded morphology profile.
|
|
19662
|
+
*
|
|
19663
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19664
|
+
*/
|
|
19665
|
+
function drawMantleCurrents(context, centerX, centerY, size, palette, timeMs, shapePhase, morphologyProfile) {
|
|
19666
|
+
const centeredCurrentIndex = (morphologyProfile.details.mantleCurrentCount - 1) / 2;
|
|
19667
|
+
for (let currentIndex = 0; currentIndex < morphologyProfile.details.mantleCurrentCount; currentIndex++) {
|
|
19668
|
+
const horizontalOffset = (currentIndex - centeredCurrentIndex) *
|
|
19669
|
+
size *
|
|
19670
|
+
(0.05 + (morphologyProfile.body.horizontalStretch - 0.9) * 0.025);
|
|
19671
|
+
const sway = Math.sin(timeMs / 680 + currentIndex * 0.78 + shapePhase) * size * 0.024;
|
|
19672
|
+
context.beginPath();
|
|
19673
|
+
context.moveTo(centerX + horizontalOffset * 0.3, centerY - size * (0.11 + morphologyProfile.body.verticalStretch * 0.02));
|
|
19674
|
+
context.bezierCurveTo(centerX + horizontalOffset - sway * 0.25, centerY - size * 0.04, centerX + horizontalOffset + sway, centerY + size * 0.06, centerX + horizontalOffset * 0.7 + sway * 0.46, centerY + size * (0.16 + morphologyProfile.body.verticalStretch * 0.035));
|
|
19675
|
+
context.strokeStyle = currentIndex % 2 === 0 ? `${palette.highlight}30` : `${palette.accent}26`;
|
|
19676
|
+
context.lineWidth =
|
|
19677
|
+
size * (0.0075 + currentIndex * 0.00065 + morphologyProfile.tentacles.baseWidthScale * 0.0005);
|
|
19678
|
+
context.lineCap = 'round';
|
|
19679
|
+
context.stroke();
|
|
19680
|
+
}
|
|
19681
|
+
}
|
|
19682
|
+
/**
|
|
19683
|
+
* Draws seeded luminous nodes inside the Octopus3 mantle.
|
|
19684
|
+
*
|
|
19685
|
+
* @param context Canvas 2D context.
|
|
19686
|
+
* @param centerX Body center X coordinate.
|
|
19687
|
+
* @param centerY Body center Y coordinate.
|
|
19688
|
+
* @param size Canvas size in CSS pixels.
|
|
19689
|
+
* @param palette Derived avatar palette.
|
|
19690
|
+
* @param createRandom Seeded random factory scoped to the avatar.
|
|
19691
|
+
* @param morphologyProfile Seeded morphology profile.
|
|
19692
|
+
*
|
|
19693
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19694
|
+
*/
|
|
19695
|
+
function drawMantleNodes(context, centerX, centerY, size, palette, createRandom, morphologyProfile) {
|
|
19696
|
+
for (let nodeIndex = 0; nodeIndex < morphologyProfile.details.mantleNodeCount; nodeIndex++) {
|
|
19697
|
+
const nodeRandom = createRandom(`octopus3-node-${nodeIndex}`);
|
|
19698
|
+
const nodeX = centerX + (nodeRandom() - 0.5) * size * (0.2 + (morphologyProfile.body.horizontalStretch - 0.9) * 0.16);
|
|
19699
|
+
const nodeY = centerY -
|
|
19700
|
+
size * 0.03 +
|
|
19701
|
+
(nodeRandom() - 0.5) * size * (0.16 + (morphologyProfile.body.verticalStretch - 0.82) * 0.1);
|
|
19702
|
+
const nodeRadius = size * (0.016 + nodeRandom() * 0.016);
|
|
19703
|
+
context.beginPath();
|
|
19704
|
+
context.arc(nodeX, nodeY, nodeRadius, 0, Math.PI * 2);
|
|
19705
|
+
context.fillStyle = nodeIndex % 2 === 0 ? `${palette.highlight}40` : `${palette.accent}33`;
|
|
19706
|
+
context.fill();
|
|
19707
|
+
}
|
|
19708
|
+
}
|
|
19709
|
+
/**
|
|
19710
|
+
* Draws one expressive seeded eye with a slit pupil and slightly tilted eyelids.
|
|
19711
|
+
*
|
|
19712
|
+
* @param context Canvas 2D context.
|
|
19713
|
+
* @param centerX Eye center X coordinate.
|
|
19714
|
+
* @param centerY Eye center Y coordinate.
|
|
19715
|
+
* @param radiusX Eye horizontal radius.
|
|
19716
|
+
* @param radiusY Eye vertical radius.
|
|
19717
|
+
* @param rotation Eye rotation in radians.
|
|
19718
|
+
* @param palette Derived avatar palette.
|
|
19719
|
+
* @param timeMs Current animation time in milliseconds.
|
|
19720
|
+
* @param phase Seed-based animation phase.
|
|
19721
|
+
* @param interaction Smoothed avatar interaction state.
|
|
19722
|
+
* @param eyeStyle Seeded eye-style traits.
|
|
19723
|
+
*
|
|
19724
|
+
* @private helper of `octopus3AvatarVisual`
|
|
19725
|
+
*/
|
|
19726
|
+
function drawSeededEye(context, centerX, centerY, radiusX, radiusY, rotation, palette, timeMs, phase, interaction, eyeStyle) {
|
|
19727
|
+
const { pupilOffsetX, pupilOffsetY } = resolveOrganicEyeMotion({
|
|
19728
|
+
radiusX,
|
|
19729
|
+
radiusY,
|
|
19730
|
+
timeMs,
|
|
19731
|
+
phase,
|
|
19732
|
+
interaction,
|
|
19733
|
+
});
|
|
19734
|
+
context.save();
|
|
19735
|
+
context.translate(centerX, centerY);
|
|
19736
|
+
context.rotate(rotation);
|
|
19737
|
+
context.beginPath();
|
|
19738
|
+
context.ellipse(0, 0, radiusX, radiusY, 0, 0, Math.PI * 2);
|
|
19739
|
+
context.fillStyle = '#f8fbff';
|
|
19740
|
+
context.fill();
|
|
19741
|
+
context.clip();
|
|
19742
|
+
const irisGradient = context.createRadialGradient(-radiusX * 0.18, -radiusY * 0.24, radiusX * 0.05, 0, 0, radiusX * 0.92);
|
|
19743
|
+
irisGradient.addColorStop(0, palette.highlight);
|
|
19744
|
+
irisGradient.addColorStop(0.58, palette.secondary);
|
|
19745
|
+
irisGradient.addColorStop(1, palette.shadow);
|
|
19746
|
+
context.beginPath();
|
|
19747
|
+
context.ellipse(pupilOffsetX, pupilOffsetY, radiusX * 0.66 * eyeStyle.irisScale, radiusY * 0.74 * eyeStyle.irisScale, 0, 0, Math.PI * 2);
|
|
19748
|
+
context.fillStyle = irisGradient;
|
|
19749
|
+
context.fill();
|
|
19750
|
+
context.beginPath();
|
|
19751
|
+
context.ellipse(pupilOffsetX, pupilOffsetY, radiusX * 0.14 * eyeStyle.pupilWidthScale, radiusY * 0.5 * eyeStyle.pupilHeightScale, 0, 0, Math.PI * 2);
|
|
19752
|
+
context.fillStyle = palette.ink;
|
|
19753
|
+
context.fill();
|
|
19754
|
+
context.beginPath();
|
|
19755
|
+
context.ellipse(pupilOffsetX - radiusX * 0.22, pupilOffsetY - radiusY * 0.24, radiusX * 0.12, radiusY * 0.14, 0, 0, Math.PI * 2);
|
|
19756
|
+
context.fillStyle = '#ffffff';
|
|
19757
|
+
context.fill();
|
|
19758
|
+
context.restore();
|
|
19759
|
+
context.save();
|
|
19760
|
+
context.translate(centerX, centerY);
|
|
19761
|
+
context.rotate(rotation);
|
|
19762
|
+
context.beginPath();
|
|
19763
|
+
context.ellipse(0, 0, radiusX, radiusY, 0, 0, Math.PI * 2);
|
|
19764
|
+
context.strokeStyle = `${palette.shadow}d9`;
|
|
19765
|
+
context.lineWidth = radiusX * 0.18;
|
|
19766
|
+
context.stroke();
|
|
19767
|
+
context.beginPath();
|
|
19768
|
+
context.moveTo(-radiusX * 0.88, -radiusY * eyeStyle.upperLidInsetRatio);
|
|
19769
|
+
context.quadraticCurveTo(0, -radiusY * (eyeStyle.upperLidArchRatio - interaction.gazeY * 0.16 + interaction.intensity * 0.08), radiusX * 0.88, -radiusY * eyeStyle.upperLidInsetRatio);
|
|
19770
|
+
context.strokeStyle = `${palette.shadow}73`;
|
|
19771
|
+
context.lineWidth = radiusX * 0.16;
|
|
19772
|
+
context.lineCap = 'round';
|
|
19773
|
+
context.stroke();
|
|
19774
|
+
if (eyeStyle.lowerLidOpacity > 0) {
|
|
19775
|
+
context.beginPath();
|
|
19776
|
+
context.moveTo(-radiusX * 0.74, radiusY * 0.2);
|
|
19777
|
+
context.quadraticCurveTo(0, radiusY * 0.38, radiusX * 0.74, radiusY * 0.2);
|
|
19778
|
+
context.strokeStyle = `${palette.highlight}${formatAlphaHex(eyeStyle.lowerLidOpacity)}`;
|
|
19779
|
+
context.lineWidth = radiusX * 0.08;
|
|
19780
|
+
context.lineCap = 'round';
|
|
19781
|
+
context.stroke();
|
|
19782
|
+
}
|
|
19783
|
+
context.restore();
|
|
19784
|
+
}
|
|
19785
|
+
|
|
19786
|
+
/* eslint-disable no-magic-numbers */
|
|
19787
|
+
/**
|
|
19788
|
+
* Family variants used by the orb renderer.
|
|
19789
|
+
*
|
|
19790
|
+
* @private helper of `orbAvatarVisual`
|
|
19791
|
+
*/
|
|
19792
|
+
const ORB_FAMILIES = ['pearl', 'nebula', 'ember', 'glacier'];
|
|
19793
|
+
/**
|
|
19794
|
+
* Built-in Orb avatar visual.
|
|
19795
|
+
*
|
|
19796
|
+
* @private built-in avatar visual
|
|
19797
|
+
*/
|
|
19798
|
+
const orbAvatarVisual = {
|
|
19799
|
+
id: 'orb',
|
|
19800
|
+
title: 'Orb',
|
|
19801
|
+
description: 'Glowing morphing circle-orb with seeded gradients, smooth deformations, and luminous layered depth.',
|
|
19802
|
+
isAnimated: true,
|
|
19803
|
+
render({ context, size, palette, createRandom, timeMs }) {
|
|
19804
|
+
const profile = createOrbMorphologyProfile(createRandom);
|
|
19805
|
+
const colorSet = resolveOrbColorSet(palette, profile.family);
|
|
19806
|
+
const centerX = size * 0.5 + profile.coreShiftX * size * 0.06 + Math.sin(timeMs / 2600) * size * 0.009;
|
|
19807
|
+
const centerY = size * 0.5 +
|
|
19808
|
+
profile.coreShiftY * size * 0.06 +
|
|
19809
|
+
Math.cos(timeMs / 3100 + profile.highlightAngle) * size * 0.01;
|
|
19810
|
+
const radius = size * profile.baseRadiusRatio;
|
|
19811
|
+
const silhouettePoints = createOrbSilhouettePoints({
|
|
19812
|
+
centerX,
|
|
19813
|
+
centerY,
|
|
19814
|
+
radius,
|
|
19815
|
+
profile,
|
|
19816
|
+
timeMs,
|
|
19817
|
+
});
|
|
19818
|
+
drawAvatarFrame(context, size, palette);
|
|
19819
|
+
drawOrbAtmosphere(context, size, centerX, centerY, radius, colorSet, profile, timeMs);
|
|
19820
|
+
drawOrbBody(context, silhouettePoints, centerX, centerY, radius, colorSet, profile, size);
|
|
19821
|
+
context.save();
|
|
19822
|
+
traceSmoothClosedPath(context, silhouettePoints);
|
|
19823
|
+
context.clip();
|
|
19824
|
+
drawOrbInteriorRings(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
|
|
19825
|
+
drawOrbSparkles(context, centerX, centerY, radius, colorSet, profile, size, createRandom, timeMs);
|
|
19826
|
+
drawOrbSheen(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
|
|
19827
|
+
drawOrbCore(context, centerX, centerY, radius, colorSet, profile, size, timeMs);
|
|
19828
|
+
context.restore();
|
|
19829
|
+
drawOrbRim(context, silhouettePoints, colorSet, size);
|
|
19830
|
+
},
|
|
19831
|
+
};
|
|
19832
|
+
/**
|
|
19833
|
+
* Builds the deterministic orb profile from the seeded avatar random factory.
|
|
19834
|
+
*
|
|
19835
|
+
* @param createRandom Seeded random factory.
|
|
19836
|
+
* @returns Stable orb morphology profile.
|
|
19837
|
+
*
|
|
19838
|
+
* @private helper of `orbAvatarVisual`
|
|
19839
|
+
*/
|
|
19840
|
+
function createOrbMorphologyProfile(createRandom) {
|
|
19841
|
+
const family = pickRandomItem(ORB_FAMILIES, createRandom('orb-family'));
|
|
19842
|
+
const familyAdjustment = resolveOrbFamilyAdjustment(family);
|
|
19843
|
+
const layoutRandom = createRandom('orb-layout');
|
|
19844
|
+
const effectRandom = createRandom('orb-effects');
|
|
19845
|
+
return {
|
|
19846
|
+
family,
|
|
19847
|
+
baseRadiusRatio: clampNumber(0.255 + layoutRandom() * 0.055 + familyAdjustment.baseRadiusRatio, 0.22, 0.335),
|
|
19848
|
+
horizontalStretch: clampNumber(0.93 + layoutRandom() * 0.13 + familyAdjustment.horizontalStretch, 0.88, 1.16),
|
|
19849
|
+
verticalStretch: clampNumber(0.91 + layoutRandom() * 0.13 + familyAdjustment.verticalStretch, 0.88, 1.15),
|
|
19850
|
+
wobbleAmplitude: clampNumber(0.038 + effectRandom() * 0.042 + familyAdjustment.wobbleAmplitude, 0.022, 0.12),
|
|
19851
|
+
wobbleFrequencyOne: clampInteger(2 + Math.floor(effectRandom() * 3) + familyAdjustment.wobbleFrequency, 2, 7),
|
|
19852
|
+
wobbleFrequencyTwo: clampInteger(3 + Math.floor(layoutRandom() * 3) + familyAdjustment.wobbleFrequency, 3, 8),
|
|
19853
|
+
wobbleFrequencyThree: clampInteger(5 + Math.floor(effectRandom() * 3) + familyAdjustment.wobbleFrequency, 4, 9),
|
|
19854
|
+
ringCount: clampInteger(2 + Math.floor(effectRandom() * 3) + familyAdjustment.ringCount, 2, 5),
|
|
19855
|
+
sparkleCount: clampInteger(6 + Math.floor(effectRandom() * 7) + familyAdjustment.sparkleCount, 4, 16),
|
|
19856
|
+
haloCount: clampInteger(2 + Math.floor(layoutRandom() * 2) + familyAdjustment.haloCount, 1, 4),
|
|
19857
|
+
coreShiftX: (layoutRandom() - 0.5) * 0.08,
|
|
19858
|
+
coreShiftY: (effectRandom() - 0.5) * 0.08,
|
|
19859
|
+
highlightAngle: layoutRandom() * Math.PI * 2,
|
|
19860
|
+
bandRotation: effectRandom() * Math.PI * 2,
|
|
19861
|
+
pulseSpeed: 0.82 + effectRandom() * 0.72,
|
|
19862
|
+
haloBlurRatio: clampNumber(0.18 + layoutRandom() * 0.12 + familyAdjustment.haloBlurRatio, 0.16, 0.34),
|
|
19863
|
+
sheenStrength: clampNumber(0.46 + effectRandom() * 0.28 + familyAdjustment.sheenStrength, 0.38, 0.88),
|
|
19864
|
+
};
|
|
19865
|
+
}
|
|
19866
|
+
/**
|
|
19867
|
+
* Resolves the family-specific adjustments that keep the orb surface varied while still circular.
|
|
19868
|
+
*
|
|
19869
|
+
* @param family Selected orb family.
|
|
19870
|
+
* @returns Family-specific profile adjustments.
|
|
19871
|
+
*
|
|
19872
|
+
* @private helper of `orbAvatarVisual`
|
|
19873
|
+
*/
|
|
19874
|
+
function resolveOrbFamilyAdjustment(family) {
|
|
19875
|
+
switch (family) {
|
|
19876
|
+
case 'nebula':
|
|
19877
|
+
return {
|
|
19878
|
+
baseRadiusRatio: 0.006,
|
|
19879
|
+
horizontalStretch: 0.05,
|
|
19880
|
+
verticalStretch: -0.01,
|
|
19881
|
+
wobbleAmplitude: 0.012,
|
|
19882
|
+
wobbleFrequency: 1,
|
|
19883
|
+
ringCount: 1,
|
|
19884
|
+
sparkleCount: 2,
|
|
19885
|
+
haloCount: 0,
|
|
19886
|
+
haloBlurRatio: 0.02,
|
|
19887
|
+
sheenStrength: 0.08,
|
|
19888
|
+
};
|
|
19889
|
+
case 'ember':
|
|
19890
|
+
return {
|
|
19891
|
+
baseRadiusRatio: -0.004,
|
|
19892
|
+
horizontalStretch: -0.03,
|
|
19893
|
+
verticalStretch: 0.03,
|
|
19894
|
+
wobbleAmplitude: 0.02,
|
|
19895
|
+
wobbleFrequency: 1,
|
|
19896
|
+
ringCount: 0,
|
|
19897
|
+
sparkleCount: 3,
|
|
19898
|
+
haloCount: 0,
|
|
19899
|
+
haloBlurRatio: 0.04,
|
|
19900
|
+
sheenStrength: 0.06,
|
|
19901
|
+
};
|
|
19902
|
+
case 'glacier':
|
|
19903
|
+
return {
|
|
19904
|
+
baseRadiusRatio: 0.012,
|
|
19905
|
+
horizontalStretch: 0.01,
|
|
19906
|
+
verticalStretch: 0.02,
|
|
19907
|
+
wobbleAmplitude: -0.006,
|
|
19908
|
+
wobbleFrequency: -1,
|
|
19909
|
+
ringCount: 0,
|
|
19910
|
+
sparkleCount: 0,
|
|
19911
|
+
haloCount: 0,
|
|
19912
|
+
haloBlurRatio: -0.01,
|
|
19913
|
+
sheenStrength: 0.12,
|
|
19914
|
+
};
|
|
19915
|
+
case 'pearl':
|
|
19916
|
+
default:
|
|
19917
|
+
return {
|
|
19918
|
+
baseRadiusRatio: 0.02,
|
|
19919
|
+
horizontalStretch: 0.025,
|
|
19920
|
+
verticalStretch: 0.02,
|
|
19921
|
+
wobbleAmplitude: -0.01,
|
|
19922
|
+
wobbleFrequency: 0,
|
|
19923
|
+
ringCount: 0,
|
|
19924
|
+
sparkleCount: -1,
|
|
19925
|
+
haloCount: 1,
|
|
19926
|
+
haloBlurRatio: 0.02,
|
|
19927
|
+
sheenStrength: 0.1,
|
|
19928
|
+
};
|
|
19929
|
+
}
|
|
19930
|
+
}
|
|
19931
|
+
/**
|
|
19932
|
+
* Resolves the color set used by the orb renderer.
|
|
19933
|
+
*
|
|
19934
|
+
* @param palette Base avatar palette.
|
|
19935
|
+
* @param family Selected orb family.
|
|
19936
|
+
* @returns Derived orb-specific color set.
|
|
19937
|
+
*
|
|
19938
|
+
* @private helper of `orbAvatarVisual`
|
|
19939
|
+
*/
|
|
19940
|
+
function resolveOrbColorSet(palette, family) {
|
|
19941
|
+
const primaryColor = Color.fromSafe(palette.primary);
|
|
19942
|
+
const secondaryColor = Color.fromSafe(palette.secondary);
|
|
19943
|
+
const accentColor = Color.fromSafe(palette.accent);
|
|
19944
|
+
const highlightColor = Color.fromSafe(palette.highlight);
|
|
19945
|
+
const shadowColor = Color.fromSafe(palette.shadow);
|
|
19946
|
+
switch (family) {
|
|
19947
|
+
case 'nebula':
|
|
19948
|
+
return {
|
|
19949
|
+
core: accentColor.then(lighten(0.16)).then(saturate(0.14)).toHex(),
|
|
19950
|
+
mid: secondaryColor.then(lighten(0.08)).then(saturate(0.08)).toHex(),
|
|
19951
|
+
outer: primaryColor.then(darken(0.03)).then(saturate(0.04)).toHex(),
|
|
19952
|
+
rim: shadowColor.then(lighten(0.08)).toHex(),
|
|
19953
|
+
highlight: highlightColor.then(lighten(0.14)).toHex(),
|
|
19954
|
+
aura: secondaryColor.then(lighten(0.18)).toHex(),
|
|
19955
|
+
};
|
|
19956
|
+
case 'ember':
|
|
19957
|
+
return {
|
|
19958
|
+
core: accentColor.then(lighten(0.2)).then(saturate(0.16)).toHex(),
|
|
19959
|
+
mid: primaryColor.then(lighten(0.1)).then(saturate(0.08)).toHex(),
|
|
19960
|
+
outer: secondaryColor.then(darken(0.04)).then(saturate(0.04)).toHex(),
|
|
19961
|
+
rim: shadowColor.then(lighten(0.08)).toHex(),
|
|
19962
|
+
highlight: highlightColor.then(lighten(0.18)).toHex(),
|
|
19963
|
+
aura: accentColor.then(lighten(0.12)).toHex(),
|
|
19964
|
+
};
|
|
19965
|
+
case 'glacier':
|
|
19966
|
+
return {
|
|
19967
|
+
core: highlightColor.then(lighten(0.18)).then(saturate(-0.04)).toHex(),
|
|
19968
|
+
mid: secondaryColor.then(lighten(0.1)).then(saturate(-0.06)).toHex(),
|
|
19969
|
+
outer: primaryColor.then(lighten(0.06)).toHex(),
|
|
19970
|
+
rim: shadowColor.then(lighten(0.12)).toHex(),
|
|
19971
|
+
highlight: highlightColor.then(lighten(0.26)).toHex(),
|
|
19972
|
+
aura: primaryColor.then(lighten(0.18)).toHex(),
|
|
19973
|
+
};
|
|
19974
|
+
case 'pearl':
|
|
19975
|
+
default:
|
|
19976
|
+
return {
|
|
19977
|
+
core: highlightColor.then(lighten(0.2)).then(saturate(-0.06)).toHex(),
|
|
19978
|
+
mid: primaryColor.then(lighten(0.12)).then(saturate(-0.02)).toHex(),
|
|
19979
|
+
outer: secondaryColor.then(lighten(0.08)).then(saturate(-0.04)).toHex(),
|
|
19980
|
+
rim: shadowColor.then(lighten(0.12)).toHex(),
|
|
19981
|
+
highlight: highlightColor.then(lighten(0.3)).toHex(),
|
|
19982
|
+
aura: highlightColor.then(lighten(0.18)).toHex(),
|
|
19983
|
+
};
|
|
19984
|
+
}
|
|
19985
|
+
}
|
|
19986
|
+
/**
|
|
19987
|
+
* Creates the orb silhouette points from the deterministic profile.
|
|
19988
|
+
*
|
|
19989
|
+
* @param options Orb geometry options.
|
|
19990
|
+
* @returns Smoothly varying orb outline.
|
|
19991
|
+
*
|
|
19992
|
+
* @private helper of `orbAvatarVisual`
|
|
19993
|
+
*/
|
|
19994
|
+
function createOrbSilhouettePoints(options) {
|
|
19995
|
+
const { centerX, centerY, radius, profile, timeMs } = options;
|
|
19996
|
+
const pointCount = 48;
|
|
19997
|
+
return Array.from({ length: pointCount }, (_, pointIndex) => {
|
|
19998
|
+
const progress = pointIndex / pointCount;
|
|
19999
|
+
const angle = -Math.PI / 2 + progress * Math.PI * 2;
|
|
20000
|
+
const breathing = Math.sin(timeMs / (1450 / profile.pulseSpeed) + profile.bandRotation) * profile.wobbleAmplitude;
|
|
20001
|
+
const surfaceWaveOne = Math.sin(angle * profile.wobbleFrequencyOne + profile.highlightAngle + timeMs / (980 / profile.pulseSpeed)) * profile.wobbleAmplitude;
|
|
20002
|
+
const surfaceWaveTwo = Math.cos(angle * profile.wobbleFrequencyTwo - profile.bandRotation * 0.8 + timeMs / (1320 / profile.pulseSpeed)) *
|
|
20003
|
+
profile.wobbleAmplitude *
|
|
20004
|
+
0.62;
|
|
20005
|
+
const surfaceWaveThree = Math.sin(angle * profile.wobbleFrequencyThree +
|
|
20006
|
+
profile.highlightAngle * 1.4 -
|
|
20007
|
+
timeMs / (1710 / profile.pulseSpeed)) *
|
|
20008
|
+
profile.wobbleAmplitude *
|
|
20009
|
+
0.38;
|
|
20010
|
+
const surfaceTaper = Math.sin(angle * 2 + profile.highlightAngle) * profile.wobbleAmplitude * 0.2;
|
|
20011
|
+
const localRadius = radius * (1 + breathing * 0.12 + surfaceWaveOne + surfaceWaveTwo + surfaceWaveThree + surfaceTaper);
|
|
20012
|
+
return {
|
|
20013
|
+
x: centerX +
|
|
20014
|
+
Math.cos(angle) * localRadius * profile.horizontalStretch +
|
|
20015
|
+
Math.sin(angle * 3 + profile.highlightAngle + timeMs / 2100) * radius * 0.012,
|
|
20016
|
+
y: centerY +
|
|
20017
|
+
Math.sin(angle) * localRadius * profile.verticalStretch +
|
|
20018
|
+
Math.cos(angle * 2 - profile.highlightAngle + timeMs / 2400) * radius * 0.01,
|
|
20019
|
+
};
|
|
20020
|
+
});
|
|
20021
|
+
}
|
|
20022
|
+
/**
|
|
20023
|
+
* Draws the atmospheric glow behind the orb.
|
|
20024
|
+
*
|
|
20025
|
+
* @param context Canvas 2D context.
|
|
20026
|
+
* @param size Canvas size in CSS pixels.
|
|
20027
|
+
* @param centerX Orb center X coordinate.
|
|
20028
|
+
* @param centerY Orb center Y coordinate.
|
|
20029
|
+
* @param radius Orb base radius.
|
|
20030
|
+
* @param colorSet Derived orb color set.
|
|
20031
|
+
* @param profile Deterministic orb profile.
|
|
20032
|
+
* @param timeMs Current animation time in milliseconds.
|
|
20033
|
+
*
|
|
20034
|
+
* @private helper of `orbAvatarVisual`
|
|
20035
|
+
*/
|
|
20036
|
+
function drawOrbAtmosphere(context, size, centerX, centerY, radius, colorSet, profile, timeMs) {
|
|
20037
|
+
const atmosphereGradient = context.createRadialGradient(centerX, centerY, radius * 0.08, centerX, centerY, radius * (1.9 + profile.haloBlurRatio));
|
|
20038
|
+
atmosphereGradient.addColorStop(0, `${colorSet.highlight}26`);
|
|
20039
|
+
atmosphereGradient.addColorStop(0.32, `${colorSet.aura}16`);
|
|
20040
|
+
atmosphereGradient.addColorStop(1, `${colorSet.aura}00`);
|
|
20041
|
+
context.save();
|
|
20042
|
+
context.globalCompositeOperation = 'screen';
|
|
20043
|
+
context.fillStyle = atmosphereGradient;
|
|
20044
|
+
context.fillRect(0, 0, size, size);
|
|
20045
|
+
for (let haloIndex = 0; haloIndex < profile.haloCount; haloIndex++) {
|
|
20046
|
+
const haloPulse = Math.sin(timeMs / (1200 + haloIndex * 180) + profile.highlightAngle) * radius * 0.025;
|
|
20047
|
+
const haloRadiusX = radius * (1.18 + haloIndex * 0.18) + haloPulse;
|
|
20048
|
+
const haloRadiusY = radius * (0.98 + haloIndex * 0.16) + haloPulse * 0.82;
|
|
20049
|
+
const haloGradient = context.createRadialGradient(centerX, centerY, radius * 0.12, centerX, centerY, haloRadiusX * 1.12);
|
|
20050
|
+
haloGradient.addColorStop(0, `${colorSet.aura}${haloIndex === 0 ? '38' : '24'}`);
|
|
20051
|
+
haloGradient.addColorStop(0.5, `${colorSet.highlight}${haloIndex === 0 ? '1f' : '12'}`);
|
|
20052
|
+
haloGradient.addColorStop(1, `${colorSet.aura}00`);
|
|
20053
|
+
context.beginPath();
|
|
20054
|
+
context.ellipse(centerX, centerY, haloRadiusX, haloRadiusY, profile.highlightAngle * 0.12 + haloIndex * 0.2 + Math.sin(timeMs / 3800) * 0.04, 0, Math.PI * 2);
|
|
20055
|
+
context.fillStyle = haloGradient;
|
|
20056
|
+
context.fill();
|
|
20057
|
+
}
|
|
20058
|
+
context.restore();
|
|
20059
|
+
}
|
|
20060
|
+
/**
|
|
20061
|
+
* Draws the main orb body using the smooth silhouette path.
|
|
20062
|
+
*
|
|
20063
|
+
* @param context Canvas 2D context.
|
|
20064
|
+
* @param points Smooth orb outline points.
|
|
20065
|
+
* @param centerX Orb center X coordinate.
|
|
20066
|
+
* @param centerY Orb center Y coordinate.
|
|
20067
|
+
* @param radius Orb base radius.
|
|
20068
|
+
* @param colorSet Derived orb color set.
|
|
20069
|
+
* @param profile Deterministic orb profile.
|
|
20070
|
+
* @param size Canvas size in CSS pixels.
|
|
20071
|
+
*
|
|
20072
|
+
* @private helper of `orbAvatarVisual`
|
|
20073
|
+
*/
|
|
20074
|
+
function drawOrbBody(context, points, centerX, centerY, radius, colorSet, profile, size) {
|
|
20075
|
+
const bodyGradient = context.createRadialGradient(centerX - radius * 0.22, centerY - radius * 0.24, radius * 0.05, centerX + radius * 0.02, centerY + radius * 0.1, radius * (1.14 + profile.haloBlurRatio * 0.3));
|
|
20076
|
+
bodyGradient.addColorStop(0, `${colorSet.highlight}f8`);
|
|
20077
|
+
bodyGradient.addColorStop(0.22, `${colorSet.core}f2`);
|
|
20078
|
+
bodyGradient.addColorStop(0.58, `${colorSet.mid}e8`);
|
|
20079
|
+
bodyGradient.addColorStop(0.86, `${colorSet.outer}dc`);
|
|
20080
|
+
bodyGradient.addColorStop(1, `${colorSet.rim}ea`);
|
|
20081
|
+
context.save();
|
|
20082
|
+
traceSmoothClosedPath(context, points);
|
|
20083
|
+
context.shadowColor = `${colorSet.rim}aa`;
|
|
20084
|
+
context.shadowBlur = size * (0.06 + profile.haloBlurRatio * 0.15);
|
|
20085
|
+
context.fillStyle = bodyGradient;
|
|
20086
|
+
context.fill();
|
|
20087
|
+
context.restore();
|
|
20088
|
+
context.save();
|
|
20089
|
+
traceSmoothClosedPath(context, points);
|
|
20090
|
+
context.strokeStyle = `${colorSet.highlight}${profile.family === 'pearl' ? '72' : '58'}`;
|
|
20091
|
+
context.lineWidth = Math.max(1.2, size * 0.012);
|
|
20092
|
+
context.lineJoin = 'round';
|
|
20093
|
+
context.lineCap = 'round';
|
|
20094
|
+
context.stroke();
|
|
20095
|
+
context.restore();
|
|
20096
|
+
}
|
|
20097
|
+
/**
|
|
20098
|
+
* Draws the layered energy rings and soft internal gradients inside the orb.
|
|
20099
|
+
*
|
|
20100
|
+
* @param context Canvas 2D context.
|
|
20101
|
+
* @param centerX Orb center X coordinate.
|
|
20102
|
+
* @param centerY Orb center Y coordinate.
|
|
20103
|
+
* @param radius Orb base radius.
|
|
20104
|
+
* @param colorSet Derived orb color set.
|
|
20105
|
+
* @param profile Deterministic orb profile.
|
|
20106
|
+
* @param size Canvas size in CSS pixels.
|
|
20107
|
+
* @param timeMs Current animation time in milliseconds.
|
|
20108
|
+
*
|
|
20109
|
+
* @private helper of `orbAvatarVisual`
|
|
20110
|
+
*/
|
|
20111
|
+
function drawOrbInteriorRings(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
|
|
20112
|
+
const internalGradient = context.createRadialGradient(centerX - radius * 0.08, centerY - radius * 0.1, radius * 0.06, centerX, centerY, radius * (0.95 + profile.sheenStrength * 0.15));
|
|
20113
|
+
internalGradient.addColorStop(0, `${colorSet.highlight}70`);
|
|
20114
|
+
internalGradient.addColorStop(0.48, `${colorSet.core}22`);
|
|
20115
|
+
internalGradient.addColorStop(1, `${colorSet.rim}00`);
|
|
20116
|
+
context.fillStyle = internalGradient;
|
|
20117
|
+
context.fillRect(centerX - radius, centerY - radius, radius * 2, radius * 2);
|
|
20118
|
+
for (let ringIndex = 0; ringIndex < profile.ringCount; ringIndex++) {
|
|
20119
|
+
const ringProgress = (ringIndex + 1) / (profile.ringCount + 1);
|
|
20120
|
+
const ringRadiusX = radius * (0.34 + ringProgress * 0.44);
|
|
20121
|
+
const ringRadiusY = radius * (0.28 + ringProgress * 0.38);
|
|
20122
|
+
const ringRotation = profile.highlightAngle * 0.24 +
|
|
20123
|
+
ringIndex * 0.4 +
|
|
20124
|
+
Math.sin(timeMs / (1800 + ringIndex * 180) + profile.bandRotation) * 0.08;
|
|
20125
|
+
context.beginPath();
|
|
20126
|
+
context.ellipse(centerX + Math.cos(profile.highlightAngle) * radius * 0.03, centerY + Math.sin(profile.highlightAngle) * radius * 0.02, ringRadiusX, ringRadiusY, ringRotation, 0, Math.PI * 2);
|
|
20127
|
+
context.strokeStyle = ringIndex % 2 === 0 ? `${colorSet.highlight}32` : `${colorSet.aura}24`;
|
|
20128
|
+
context.lineWidth = Math.max(1.2, size * (0.007 - ringIndex * 0.001));
|
|
20129
|
+
context.shadowColor = `${colorSet.highlight}55`;
|
|
20130
|
+
context.shadowBlur = size * 0.02;
|
|
20131
|
+
context.stroke();
|
|
20132
|
+
}
|
|
20133
|
+
}
|
|
20134
|
+
/**
|
|
20135
|
+
* Draws soft sparkles and seeded dust inside the orb.
|
|
20136
|
+
*
|
|
20137
|
+
* @param context Canvas 2D context.
|
|
20138
|
+
* @param centerX Orb center X coordinate.
|
|
20139
|
+
* @param centerY Orb center Y coordinate.
|
|
20140
|
+
* @param radius Orb base radius.
|
|
20141
|
+
* @param colorSet Derived orb color set.
|
|
20142
|
+
* @param profile Deterministic orb profile.
|
|
20143
|
+
* @param size Canvas size in CSS pixels.
|
|
20144
|
+
* @param createRandom Seeded random factory.
|
|
20145
|
+
* @param timeMs Current animation time in milliseconds.
|
|
20146
|
+
*
|
|
20147
|
+
* @private helper of `orbAvatarVisual`
|
|
20148
|
+
*/
|
|
20149
|
+
function drawOrbSparkles(context, centerX, centerY, radius, colorSet, profile, size, createRandom, timeMs) {
|
|
20150
|
+
const sparkleStride = Math.max(1, Math.floor(profile.sparkleCount / 6));
|
|
20151
|
+
for (let sparkleIndex = 0; sparkleIndex < profile.sparkleCount; sparkleIndex++) {
|
|
20152
|
+
const sparkleRandom = createRandom(`orb-sparkle-${sparkleIndex}`);
|
|
20153
|
+
const sparkleAngle = sparkleRandom() * Math.PI * 2 + profile.highlightAngle * 0.4;
|
|
20154
|
+
const sparkleOrbitRadius = radius * (0.42 + sparkleRandom() * 0.55);
|
|
20155
|
+
const sparkleOrbitPulse = 0.92 + Math.sin(timeMs / (700 + sparkleIndex * 70) + profile.bandRotation) * 0.08;
|
|
20156
|
+
const sparkleCenterX = centerX + Math.cos(sparkleAngle + timeMs / (4600 / profile.pulseSpeed)) * sparkleOrbitRadius;
|
|
20157
|
+
const sparkleCenterY = centerY + Math.sin(sparkleAngle + timeMs / (4600 / profile.pulseSpeed)) * sparkleOrbitRadius;
|
|
20158
|
+
const sparkleRadius = size * (0.0028 + sparkleRandom() * 0.0058) * sparkleOrbitPulse;
|
|
20159
|
+
context.beginPath();
|
|
20160
|
+
context.arc(sparkleCenterX, sparkleCenterY, sparkleRadius * 2, 0, Math.PI * 2);
|
|
20161
|
+
context.fillStyle = `${colorSet.highlight}14`;
|
|
20162
|
+
context.fill();
|
|
20163
|
+
context.beginPath();
|
|
20164
|
+
context.arc(sparkleCenterX, sparkleCenterY, sparkleRadius, 0, Math.PI * 2);
|
|
20165
|
+
context.fillStyle = sparkleIndex % sparkleStride === 0 ? `${colorSet.highlight}d2` : `${colorSet.aura}c8`;
|
|
20166
|
+
context.shadowColor = `${colorSet.highlight}66`;
|
|
20167
|
+
context.shadowBlur = size * 0.012;
|
|
20168
|
+
context.fill();
|
|
20169
|
+
}
|
|
20170
|
+
}
|
|
20171
|
+
/**
|
|
20172
|
+
* Draws the specular sweep that makes the orb feel glossy and dimensional.
|
|
20173
|
+
*
|
|
20174
|
+
* @param context Canvas 2D context.
|
|
20175
|
+
* @param centerX Orb center X coordinate.
|
|
20176
|
+
* @param centerY Orb center Y coordinate.
|
|
20177
|
+
* @param radius Orb base radius.
|
|
20178
|
+
* @param colorSet Derived orb color set.
|
|
20179
|
+
* @param profile Deterministic orb profile.
|
|
20180
|
+
* @param size Canvas size in CSS pixels.
|
|
20181
|
+
* @param timeMs Current animation time in milliseconds.
|
|
20182
|
+
*
|
|
20183
|
+
* @private helper of `orbAvatarVisual`
|
|
20184
|
+
*/
|
|
20185
|
+
function drawOrbSheen(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
|
|
20186
|
+
const sheenAngle = profile.bandRotation + timeMs / (2400 / profile.pulseSpeed);
|
|
20187
|
+
const sheenDirectionX = Math.cos(sheenAngle);
|
|
20188
|
+
const sheenDirectionY = Math.sin(sheenAngle);
|
|
20189
|
+
const sheenGradient = context.createLinearGradient(centerX - sheenDirectionX * radius, centerY - sheenDirectionY * radius, centerX + sheenDirectionX * radius, centerY + sheenDirectionY * radius);
|
|
20190
|
+
sheenGradient.addColorStop(0, `${colorSet.highlight}00`);
|
|
20191
|
+
sheenGradient.addColorStop(0.24, `${colorSet.highlight}0e`);
|
|
20192
|
+
sheenGradient.addColorStop(0.43, `${colorSet.highlight}${profile.sheenStrength > 0.65 ? '66' : '48'}`);
|
|
20193
|
+
sheenGradient.addColorStop(0.57, `${colorSet.core}${profile.sheenStrength > 0.65 ? '42' : '2e'}`);
|
|
20194
|
+
sheenGradient.addColorStop(0.75, `${colorSet.aura}1e`);
|
|
20195
|
+
sheenGradient.addColorStop(1, `${colorSet.highlight}00`);
|
|
20196
|
+
context.fillStyle = sheenGradient;
|
|
20197
|
+
context.fillRect(centerX - radius * 1.6, centerY - radius * 1.6, radius * 3.2, radius * 3.2);
|
|
20198
|
+
context.beginPath();
|
|
20199
|
+
context.ellipse(centerX - radius * 0.18, centerY - radius * 0.2, radius * 0.44, radius * 0.24, profile.highlightAngle * 0.32, 0, Math.PI * 2);
|
|
20200
|
+
context.fillStyle = `${colorSet.highlight}${profile.family === 'ember' ? '26' : '2e'}`;
|
|
20201
|
+
context.shadowColor = `${colorSet.highlight}55`;
|
|
20202
|
+
context.shadowBlur = size * 0.02;
|
|
20203
|
+
context.fill();
|
|
20204
|
+
}
|
|
20205
|
+
/**
|
|
20206
|
+
* Draws the bright nucleus that gives the orb a recognisable center.
|
|
20207
|
+
*
|
|
20208
|
+
* @param context Canvas 2D context.
|
|
20209
|
+
* @param centerX Orb center X coordinate.
|
|
20210
|
+
* @param centerY Orb center Y coordinate.
|
|
20211
|
+
* @param radius Orb base radius.
|
|
20212
|
+
* @param colorSet Derived orb color set.
|
|
20213
|
+
* @param profile Deterministic orb profile.
|
|
20214
|
+
* @param size Canvas size in CSS pixels.
|
|
20215
|
+
* @param timeMs Current animation time in milliseconds.
|
|
20216
|
+
*
|
|
20217
|
+
* @private helper of `orbAvatarVisual`
|
|
20218
|
+
*/
|
|
20219
|
+
function drawOrbCore(context, centerX, centerY, radius, colorSet, profile, size, timeMs) {
|
|
20220
|
+
const coreRadiusX = radius * (0.18 + profile.sheenStrength * 0.06);
|
|
20221
|
+
const coreRadiusY = radius * (0.15 + profile.sheenStrength * 0.045);
|
|
20222
|
+
const corePulse = 1 + Math.sin(timeMs / (1100 / profile.pulseSpeed) + profile.bandRotation) * 0.04;
|
|
20223
|
+
context.beginPath();
|
|
20224
|
+
context.ellipse(centerX + profile.coreShiftX * radius * 0.18, centerY + profile.coreShiftY * radius * 0.18, coreRadiusX * corePulse, coreRadiusY * corePulse, profile.highlightAngle * 0.12, 0, Math.PI * 2);
|
|
20225
|
+
context.fillStyle = `${colorSet.core}f0`;
|
|
20226
|
+
context.shadowColor = `${colorSet.highlight}88`;
|
|
20227
|
+
context.shadowBlur = size * 0.03;
|
|
20228
|
+
context.fill();
|
|
20229
|
+
context.beginPath();
|
|
20230
|
+
context.arc(centerX - radius * 0.06, centerY - radius * 0.07, radius * 0.06, 0, Math.PI * 2);
|
|
20231
|
+
context.fillStyle = `${colorSet.highlight}d6`;
|
|
20232
|
+
context.fill();
|
|
20233
|
+
}
|
|
20234
|
+
/**
|
|
20235
|
+
* Draws the final rim stroke so the orb stays crisp against busy backgrounds.
|
|
20236
|
+
*
|
|
20237
|
+
* @param context Canvas 2D context.
|
|
20238
|
+
* @param points Smooth orb outline points.
|
|
20239
|
+
* @param colorSet Derived orb color set.
|
|
20240
|
+
* @param size Canvas size in CSS pixels.
|
|
20241
|
+
*
|
|
20242
|
+
* @private helper of `orbAvatarVisual`
|
|
20243
|
+
*/
|
|
20244
|
+
function drawOrbRim(context, points, colorSet, size) {
|
|
20245
|
+
context.save();
|
|
20246
|
+
traceSmoothClosedPath(context, points);
|
|
20247
|
+
context.strokeStyle = `${colorSet.rim}c0`;
|
|
20248
|
+
context.lineWidth = Math.max(1.25, size * 0.013);
|
|
20249
|
+
context.lineJoin = 'round';
|
|
20250
|
+
context.lineCap = 'round';
|
|
20251
|
+
context.shadowColor = `${colorSet.highlight}4f`;
|
|
20252
|
+
context.shadowBlur = size * 0.018;
|
|
20253
|
+
context.stroke();
|
|
20254
|
+
context.restore();
|
|
20255
|
+
}
|
|
20256
|
+
/**
|
|
20257
|
+
* Clamps a number into the provided range.
|
|
20258
|
+
*
|
|
20259
|
+
* @param value Number to clamp.
|
|
20260
|
+
* @param minimum Minimum accepted value.
|
|
20261
|
+
* @param maximum Maximum accepted value.
|
|
20262
|
+
* @returns Clamped number.
|
|
20263
|
+
*
|
|
20264
|
+
* @private helper of `orbAvatarVisual`
|
|
20265
|
+
*/
|
|
20266
|
+
function clampNumber(value, minimum, maximum) {
|
|
20267
|
+
return Math.min(maximum, Math.max(minimum, value));
|
|
20268
|
+
}
|
|
20269
|
+
/**
|
|
20270
|
+
* Clamps a number into the provided integer range.
|
|
20271
|
+
*
|
|
20272
|
+
* @param value Number to clamp.
|
|
20273
|
+
* @param minimum Minimum accepted value.
|
|
20274
|
+
* @param maximum Maximum accepted value.
|
|
20275
|
+
* @returns Clamped integer.
|
|
20276
|
+
*
|
|
20277
|
+
* @private helper of `orbAvatarVisual`
|
|
20278
|
+
*/
|
|
20279
|
+
function clampInteger(value, minimum, maximum) {
|
|
20280
|
+
return Math.min(maximum, Math.max(minimum, Math.round(value)));
|
|
20281
|
+
}
|
|
20282
|
+
|
|
20283
|
+
/* eslint-disable no-magic-numbers */
|
|
20284
|
+
/**
|
|
20285
|
+
* Pixel-art avatar visual.
|
|
20286
|
+
*
|
|
20287
|
+
* @private built-in avatar visual
|
|
20288
|
+
*/
|
|
20289
|
+
const pixelArtAvatarVisual = {
|
|
20290
|
+
id: 'pixel-art',
|
|
20291
|
+
title: 'Pixel art',
|
|
20292
|
+
description: 'Symmetric retro badge with a deterministic face and palette-driven pixels.',
|
|
20293
|
+
isAnimated: false,
|
|
20294
|
+
render({ context, size, palette, createRandom, avatarDefinition }) {
|
|
20295
|
+
const random = createRandom('pixel-art');
|
|
20296
|
+
const panelSize = size * 0.62;
|
|
20297
|
+
const panelX = (size - panelSize) / 2;
|
|
20298
|
+
const panelY = size * 0.19;
|
|
20299
|
+
const pixelGridSize = 10;
|
|
20300
|
+
const pixelSize = panelSize / pixelGridSize;
|
|
20301
|
+
const halfColumns = Math.ceil(pixelGridSize / 2);
|
|
20302
|
+
const colorStops = [palette.primary, palette.secondary, palette.accent, palette.highlight];
|
|
20303
|
+
const foreheadRowCount = 2 + Math.floor(random() * 2);
|
|
20304
|
+
const cheekInset = 1 + Math.floor(random() * 2);
|
|
20305
|
+
const emblemHeight = 2 + Math.floor(random() * 2);
|
|
20306
|
+
drawAvatarFrame(context, size, palette);
|
|
20307
|
+
const glow = context.createRadialGradient(size * 0.5, size * 0.32, size * 0.05, size * 0.5, size * 0.32, size * 0.5);
|
|
20308
|
+
glow.addColorStop(0, `${palette.highlight}aa`);
|
|
20309
|
+
glow.addColorStop(1, `${palette.highlight}00`);
|
|
20310
|
+
context.fillStyle = glow;
|
|
20311
|
+
context.fillRect(0, 0, size, size);
|
|
20312
|
+
context.save();
|
|
20313
|
+
createRoundedRectPath(context, panelX, panelY, panelSize, panelSize, panelSize * 0.16);
|
|
20314
|
+
context.fillStyle = palette.shadow;
|
|
20315
|
+
context.shadowColor = `${palette.shadow}66`;
|
|
20316
|
+
context.shadowBlur = size * 0.08;
|
|
20317
|
+
context.fill();
|
|
20318
|
+
context.restore();
|
|
20319
|
+
for (let rowIndex = 0; rowIndex < pixelGridSize; rowIndex++) {
|
|
20320
|
+
for (let columnIndex = 0; columnIndex < halfColumns; columnIndex++) {
|
|
20321
|
+
const mirroredColumnIndex = pixelGridSize - columnIndex - 1;
|
|
20322
|
+
const normalizedRowDistance = Math.abs(rowIndex - pixelGridSize / 2) / (pixelGridSize / 2);
|
|
20323
|
+
const normalizedColumnDistance = columnIndex / halfColumns;
|
|
20324
|
+
const fillChance = 0.85 - normalizedRowDistance * 0.32 - normalizedColumnDistance * 0.08;
|
|
20325
|
+
if (random() > fillChance) {
|
|
20326
|
+
continue;
|
|
20327
|
+
}
|
|
20328
|
+
const color = colorStops[Math.min(colorStops.length - 1, Math.floor(random() *
|
|
20329
|
+
(rowIndex < foreheadRowCount
|
|
20330
|
+
? 2
|
|
20331
|
+
: rowIndex > pixelGridSize - emblemHeight - 1
|
|
20332
|
+
? colorStops.length
|
|
20333
|
+
: 3)))];
|
|
20334
|
+
if (columnIndex === 0 &&
|
|
20335
|
+
rowIndex >= cheekInset &&
|
|
20336
|
+
rowIndex <= pixelGridSize - cheekInset - 1 &&
|
|
20337
|
+
random() < 0.4) {
|
|
20338
|
+
continue;
|
|
20339
|
+
}
|
|
20340
|
+
drawPixel(context, panelX + columnIndex * pixelSize, panelY + rowIndex * pixelSize, pixelSize, color);
|
|
20341
|
+
if (mirroredColumnIndex !== columnIndex) {
|
|
20342
|
+
drawPixel(context, panelX + mirroredColumnIndex * pixelSize, panelY + rowIndex * pixelSize, pixelSize, color);
|
|
20343
|
+
}
|
|
20344
|
+
}
|
|
20345
|
+
}
|
|
20346
|
+
const eyeRowIndex = 3 + Math.floor(random() * 2);
|
|
20347
|
+
const eyeColumnOffset = 2 + Math.floor(random() * 2);
|
|
20348
|
+
drawPixel(context, panelX + eyeColumnOffset * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize, palette.ink);
|
|
20349
|
+
drawPixel(context, panelX + (pixelGridSize - eyeColumnOffset - 1) * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize, palette.ink);
|
|
20350
|
+
drawPixel(context, panelX + eyeColumnOffset * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize * 0.44, '#ffffff');
|
|
20351
|
+
drawPixel(context, panelX + (pixelGridSize - eyeColumnOffset - 1) * pixelSize, panelY + eyeRowIndex * pixelSize, pixelSize * 0.44, '#ffffff');
|
|
20352
|
+
const mouthRowIndex = eyeRowIndex + 3;
|
|
20353
|
+
const mouthWidth = 2 + Math.floor(random() * 2);
|
|
20354
|
+
for (let mouthOffset = 0; mouthOffset < mouthWidth; mouthOffset++) {
|
|
20355
|
+
drawPixel(context, panelX + (4 + mouthOffset) * pixelSize, panelY + mouthRowIndex * pixelSize, pixelSize, palette.shadow);
|
|
20356
|
+
}
|
|
20357
|
+
context.save();
|
|
20358
|
+
context.fillStyle = `${palette.highlight}44`;
|
|
20359
|
+
context.font = `${Math.round(size * 0.12)}px sans-serif`;
|
|
20360
|
+
context.textAlign = 'center';
|
|
20361
|
+
context.fillText(avatarDefinition.agentName.charAt(0).toUpperCase(), size * 0.5, size * 0.88);
|
|
20362
|
+
context.restore();
|
|
20363
|
+
},
|
|
20364
|
+
};
|
|
20365
|
+
/**
|
|
20366
|
+
* Draws one pixel-art block with a tiny inner highlight.
|
|
20367
|
+
*
|
|
20368
|
+
* @param context Canvas 2D context.
|
|
20369
|
+
* @param x Left coordinate.
|
|
20370
|
+
* @param y Top coordinate.
|
|
20371
|
+
* @param size Pixel size.
|
|
20372
|
+
* @param color Pixel fill color.
|
|
20373
|
+
*
|
|
20374
|
+
* @private helper of `pixelArtAvatarVisual`
|
|
20375
|
+
*/
|
|
20376
|
+
function drawPixel(context, x, y, size, color) {
|
|
20377
|
+
const normalizedSize = size * 0.9;
|
|
20378
|
+
const offset = (size - normalizedSize) / 2;
|
|
20379
|
+
context.fillStyle = color;
|
|
20380
|
+
context.fillRect(x + offset, y + offset, normalizedSize, normalizedSize);
|
|
20381
|
+
context.fillStyle = 'rgba(255,255,255,0.18)';
|
|
20382
|
+
context.fillRect(x + offset, y + offset, normalizedSize, normalizedSize * 0.14);
|
|
20383
|
+
}
|
|
20384
|
+
|
|
20385
|
+
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
20386
|
+
/**
|
|
20387
|
+
* Built-in avatar visuals available to the app.
|
|
20388
|
+
*
|
|
20389
|
+
* @private shared registry for the avatar rendering system
|
|
20390
|
+
*/
|
|
20391
|
+
const AVATAR_VISUALS = [
|
|
20392
|
+
pixelArtAvatarVisual,
|
|
20393
|
+
octopusAvatarVisual,
|
|
20394
|
+
octopus2AvatarVisual,
|
|
20395
|
+
octopus3AvatarVisual,
|
|
20396
|
+
asciiOctopusAvatarVisual,
|
|
20397
|
+
minecraftAvatarVisual,
|
|
20398
|
+
fractalAvatarVisual,
|
|
20399
|
+
orbAvatarVisual,
|
|
20400
|
+
];
|
|
20401
|
+
/**
|
|
20402
|
+
* Normalizes user-facing avatar visual names so ids can be matched case-insensitively
|
|
20403
|
+
* across spaces, hyphens, underscores, and future separator variants.
|
|
20404
|
+
*
|
|
20405
|
+
* @param value Raw avatar visual id or title.
|
|
20406
|
+
* @returns Stable lookup key.
|
|
20407
|
+
*
|
|
20408
|
+
* @private shared registry for the avatar rendering system
|
|
20409
|
+
*/
|
|
20410
|
+
function normalizeAvatarVisualLookupKey(value) {
|
|
20411
|
+
return value
|
|
20412
|
+
.trim()
|
|
20413
|
+
.toLowerCase()
|
|
20414
|
+
.replace(/[^a-z0-9]+/g, '');
|
|
20415
|
+
}
|
|
20416
|
+
/**
|
|
20417
|
+
* Resolves a user-facing avatar visual value to a supported built-in visual id.
|
|
20418
|
+
*
|
|
20419
|
+
* The lookup is derived from `AVATAR_VISUALS`, so new visuals become selectable by
|
|
20420
|
+
* adding them to the registry rather than updating parser-specific option lists.
|
|
20421
|
+
*
|
|
20422
|
+
* @param value Raw visual id/title, for example `PIXEL_ART`, `pixel art`, or `pixel-art`.
|
|
20423
|
+
* @returns Matching visual id or `null` when the value is empty/unknown.
|
|
20424
|
+
*
|
|
20425
|
+
* @private shared registry for the avatar rendering system
|
|
20426
|
+
*/
|
|
20427
|
+
function resolveAvatarVisualId(value) {
|
|
20428
|
+
if (!value) {
|
|
20429
|
+
return null;
|
|
20430
|
+
}
|
|
20431
|
+
const normalizedValue = normalizeAvatarVisualLookupKey(value);
|
|
20432
|
+
if (!normalizedValue) {
|
|
20433
|
+
return null;
|
|
20434
|
+
}
|
|
20435
|
+
const avatarVisual = AVATAR_VISUALS.find((candidateAvatarVisual) => normalizeAvatarVisualLookupKey(candidateAvatarVisual.id) === normalizedValue ||
|
|
20436
|
+
normalizeAvatarVisualLookupKey(candidateAvatarVisual.title) === normalizedValue);
|
|
20437
|
+
return (avatarVisual === null || avatarVisual === void 0 ? void 0 : avatarVisual.id) || null;
|
|
20438
|
+
}
|
|
20439
|
+
|
|
20440
|
+
/**
|
|
20441
|
+
* META AVATAR commitment definition
|
|
20442
|
+
*
|
|
20443
|
+
* The `META AVATAR` commitment sets the built-in default avatar visual used when
|
|
20444
|
+
* the agent does not provide an explicit `META IMAGE`.
|
|
20445
|
+
*
|
|
20446
|
+
* @private [đĒ] Maybe export the commitments through some package
|
|
20447
|
+
*/
|
|
20448
|
+
class MetaAvatarCommitmentDefinition extends BaseCommitmentDefinition {
|
|
20449
|
+
constructor() {
|
|
20450
|
+
super('META AVATAR');
|
|
20451
|
+
}
|
|
20452
|
+
/**
|
|
20453
|
+
* Short one-line description of META AVATAR.
|
|
20454
|
+
*/
|
|
20455
|
+
get description() {
|
|
20456
|
+
return "Set the agent's built-in avatar visual.";
|
|
20457
|
+
}
|
|
20458
|
+
/**
|
|
20459
|
+
* Icon for this commitment.
|
|
20460
|
+
*/
|
|
20461
|
+
get icon() {
|
|
20462
|
+
return 'đ¤';
|
|
20463
|
+
}
|
|
20464
|
+
/**
|
|
20465
|
+
* Markdown documentation for META AVATAR commitment.
|
|
20466
|
+
*/
|
|
20467
|
+
get documentation() {
|
|
20468
|
+
const supportedVisuals = AVATAR_VISUALS.map((avatarVisual) => `\`${avatarVisual.id}\``).join(', ');
|
|
20469
|
+
return _spaceTrim.spaceTrim(`
|
|
20470
|
+
# META AVATAR
|
|
20471
|
+
|
|
20472
|
+
Sets the built-in avatar visual used for the agent when no explicit \`META IMAGE\` is provided.
|
|
20473
|
+
|
|
20474
|
+
## Key aspects
|
|
20475
|
+
|
|
20476
|
+
- Does not modify the agent's behavior or responses.
|
|
20477
|
+
- Only one \`META AVATAR\` should be used per agent.
|
|
20478
|
+
- If multiple are specified, the last one takes precedence.
|
|
20479
|
+
- Values are matched case-insensitively and spaces, hyphens, and underscores are normalized.
|
|
20480
|
+
- Supported visuals are derived from the shared avatar registry: ${supportedVisuals}.
|
|
20481
|
+
|
|
20482
|
+
## Examples
|
|
20483
|
+
|
|
20484
|
+
\`\`\`book
|
|
20485
|
+
Pixel Assistant
|
|
20486
|
+
|
|
20487
|
+
META AVATAR PIXEL_ART
|
|
20488
|
+
GOAL Help users with concise answers.
|
|
20489
|
+
\`\`\`
|
|
20490
|
+
|
|
20491
|
+
\`\`\`book
|
|
20492
|
+
Orb Assistant
|
|
20493
|
+
|
|
20494
|
+
META AVATAR orb
|
|
20495
|
+
GOAL Answer in a calm and focused way.
|
|
20496
|
+
\`\`\`
|
|
20497
|
+
`);
|
|
20498
|
+
}
|
|
20499
|
+
applyToAgentModelRequirements(requirements, content) {
|
|
20500
|
+
// META AVATAR doesn't modify the system message or model requirements.
|
|
20501
|
+
// It's handled separately in the parsing logic for profile avatar resolution.
|
|
20502
|
+
return requirements;
|
|
20503
|
+
}
|
|
20504
|
+
}
|
|
20505
|
+
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
20506
|
+
|
|
17201
20507
|
/**
|
|
17202
20508
|
* META COLOR commitment definition
|
|
17203
20509
|
*
|
|
@@ -17867,7 +21173,13 @@
|
|
|
17867
21173
|
* Short one-line description of MODEL.
|
|
17868
21174
|
*/
|
|
17869
21175
|
get description() {
|
|
17870
|
-
return '
|
|
21176
|
+
return 'Low-level commitment for explicit model selection and technical parameters. Use carefully.';
|
|
21177
|
+
}
|
|
21178
|
+
/**
|
|
21179
|
+
* Marks MODEL as a low-level commitment surfaced with caution.
|
|
21180
|
+
*/
|
|
21181
|
+
get isLowLevel() {
|
|
21182
|
+
return true;
|
|
17871
21183
|
}
|
|
17872
21184
|
/**
|
|
17873
21185
|
* Icon for this commitment.
|
|
@@ -17882,11 +21194,17 @@
|
|
|
17882
21194
|
return _spaceTrim.spaceTrim(`
|
|
17883
21195
|
# ${this.type}
|
|
17884
21196
|
|
|
17885
|
-
|
|
21197
|
+
Low-level commitment for explicit AI model selection and technical parameters.
|
|
21198
|
+
|
|
21199
|
+
## Status
|
|
21200
|
+
|
|
21201
|
+
- This commitment is low-level and not used by most of the users.
|
|
21202
|
+
- Use it when you need to pin a specific model or fine-tune model parameters directly.
|
|
21203
|
+
- Prefer automatic model selection when you do not need manual control.
|
|
17886
21204
|
|
|
17887
21205
|
## Key aspects
|
|
17888
21206
|
|
|
17889
|
-
- When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments
|
|
21207
|
+
- When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments.
|
|
17890
21208
|
- Multiple \`MODEL\` commitments can be used to specify different parameters
|
|
17891
21209
|
- Both \`MODEL\` and \`MODELS\` terms work identically and can be used interchangeably
|
|
17892
21210
|
- Parameters control the randomness, creativity, and technical aspects of model responses
|
|
@@ -18415,6 +21733,12 @@
|
|
|
18415
21733
|
get description() {
|
|
18416
21734
|
return 'Add behavioral rules the agent must follow.';
|
|
18417
21735
|
}
|
|
21736
|
+
/**
|
|
21737
|
+
* Marks RULE as one of the priority commitments surfaced first in catalogues.
|
|
21738
|
+
*/
|
|
21739
|
+
get isImportant() {
|
|
21740
|
+
return true;
|
|
21741
|
+
}
|
|
18418
21742
|
/**
|
|
18419
21743
|
* Icon for this commitment.
|
|
18420
21744
|
*/
|
|
@@ -19034,6 +22358,46 @@
|
|
|
19034
22358
|
}
|
|
19035
22359
|
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
19036
22360
|
|
|
22361
|
+
/**
|
|
22362
|
+
* Header used for same-server TEAM calls that may access private teammate agents.
|
|
22363
|
+
*
|
|
22364
|
+
* @private internal Agents Server access wiring
|
|
22365
|
+
*/
|
|
22366
|
+
const TEAM_INTERNAL_AGENT_ACCESS_HEADER = 'x-promptbook-team-agent-access-token';
|
|
22367
|
+
/**
|
|
22368
|
+
* Creates request headers for same-server TEAM calls.
|
|
22369
|
+
*
|
|
22370
|
+
* @param options - Target agent URL, local server URL, and resolved access token.
|
|
22371
|
+
* @returns Header map when the target is same-origin; otherwise an empty map.
|
|
22372
|
+
*
|
|
22373
|
+
* @private internal Agents Server access wiring
|
|
22374
|
+
*/
|
|
22375
|
+
function createTeamInternalAgentAccessHeaders(options) {
|
|
22376
|
+
if (!options.accessToken || !isSameOriginAgentUrl(options.agentUrl, options.localServerUrl)) {
|
|
22377
|
+
return {};
|
|
22378
|
+
}
|
|
22379
|
+
return {
|
|
22380
|
+
[TEAM_INTERNAL_AGENT_ACCESS_HEADER]: options.accessToken,
|
|
22381
|
+
};
|
|
22382
|
+
}
|
|
22383
|
+
/**
|
|
22384
|
+
* Checks whether a teammate URL points back to the current Agents Server origin.
|
|
22385
|
+
*
|
|
22386
|
+
* @private internal Agents Server access wiring
|
|
22387
|
+
*/
|
|
22388
|
+
function isSameOriginAgentUrl(agentUrl, localServerUrl) {
|
|
22389
|
+
if (!localServerUrl) {
|
|
22390
|
+
return false;
|
|
22391
|
+
}
|
|
22392
|
+
try {
|
|
22393
|
+
return new URL(agentUrl).origin === new URL(localServerUrl).origin;
|
|
22394
|
+
}
|
|
22395
|
+
catch (_a) {
|
|
22396
|
+
return false;
|
|
22397
|
+
}
|
|
22398
|
+
}
|
|
22399
|
+
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
22400
|
+
|
|
19037
22401
|
/**
|
|
19038
22402
|
* Map of team tool functions.
|
|
19039
22403
|
*/
|
|
@@ -19079,11 +22443,17 @@
|
|
|
19079
22443
|
get description() {
|
|
19080
22444
|
return 'Enable the agent to consult teammate agents via dedicated tools.';
|
|
19081
22445
|
}
|
|
22446
|
+
/**
|
|
22447
|
+
* Marks TEAM as one of the priority commitments surfaced first in catalogues.
|
|
22448
|
+
*/
|
|
22449
|
+
get isImportant() {
|
|
22450
|
+
return true;
|
|
22451
|
+
}
|
|
19082
22452
|
/**
|
|
19083
22453
|
* Icon for this commitment.
|
|
19084
22454
|
*/
|
|
19085
22455
|
get icon() {
|
|
19086
|
-
return '
|
|
22456
|
+
return 'đĨ';
|
|
19087
22457
|
}
|
|
19088
22458
|
/**
|
|
19089
22459
|
* Markdown documentation for TEAM commitment.
|
|
@@ -19385,21 +22755,28 @@
|
|
|
19385
22755
|
/**
|
|
19386
22756
|
* Resolves a RemoteAgent for the given teammate URL, caching the connection.
|
|
19387
22757
|
*/
|
|
19388
|
-
async function getRemoteTeammateAgent(agentUrl) {
|
|
19389
|
-
|
|
22758
|
+
async function getRemoteTeammateAgent(agentUrl, runtimeContext) {
|
|
22759
|
+
var _a, _b;
|
|
22760
|
+
const requestHeaders = createTeamInternalAgentAccessHeaders({
|
|
22761
|
+
agentUrl,
|
|
22762
|
+
localServerUrl: (_a = runtimeContext.agentsServer) === null || _a === void 0 ? void 0 : _a.localServerUrl,
|
|
22763
|
+
accessToken: (_b = runtimeContext.agentsServer) === null || _b === void 0 ? void 0 : _b.teamInternalAccessToken,
|
|
22764
|
+
});
|
|
22765
|
+
const cacheKey = `${agentUrl}|${requestHeaders[TEAM_INTERNAL_AGENT_ACCESS_HEADER] || ''}`;
|
|
22766
|
+
const cached = remoteAgentsByUrl.get(cacheKey);
|
|
19390
22767
|
if (cached) {
|
|
19391
22768
|
return cached;
|
|
19392
22769
|
}
|
|
19393
22770
|
const connection = (async () => {
|
|
19394
22771
|
const { RemoteAgent } = await Promise.resolve().then(function () { return RemoteAgent$1; });
|
|
19395
|
-
return RemoteAgent.connect({ agentUrl });
|
|
22772
|
+
return RemoteAgent.connect({ agentUrl, requestHeaders });
|
|
19396
22773
|
})();
|
|
19397
|
-
remoteAgentsByUrl.set(
|
|
22774
|
+
remoteAgentsByUrl.set(cacheKey, connection);
|
|
19398
22775
|
try {
|
|
19399
22776
|
return await connection;
|
|
19400
22777
|
}
|
|
19401
22778
|
catch (error) {
|
|
19402
|
-
remoteAgentsByUrl.delete(
|
|
22779
|
+
remoteAgentsByUrl.delete(cacheKey);
|
|
19403
22780
|
throw error;
|
|
19404
22781
|
}
|
|
19405
22782
|
}
|
|
@@ -19429,8 +22806,9 @@
|
|
|
19429
22806
|
let error = null;
|
|
19430
22807
|
let toolCalls;
|
|
19431
22808
|
try {
|
|
19432
|
-
const
|
|
19433
|
-
const
|
|
22809
|
+
const runtimeContext = createTeamConversationRuntimeContext(args[TOOL_RUNTIME_CONTEXT_ARGUMENT]);
|
|
22810
|
+
const remoteAgent = await getRemoteTeammateAgent(entry.teammate.url, runtimeContext);
|
|
22811
|
+
const prompt = buildTeammatePrompt(request, runtimeContext);
|
|
19434
22812
|
const teammateResult = await remoteAgent.callChatModel(prompt);
|
|
19435
22813
|
response = teammateResult.content || '';
|
|
19436
22814
|
toolCalls =
|
|
@@ -19469,11 +22847,10 @@
|
|
|
19469
22847
|
/**
|
|
19470
22848
|
* TEMPLATE commitment definition
|
|
19471
22849
|
*
|
|
19472
|
-
*
|
|
19473
|
-
*
|
|
19474
|
-
* consistent message formatting across all agent interactions.
|
|
22850
|
+
* Deprecated legacy commitment for response templates and output structure.
|
|
22851
|
+
* New books should prefer `WRITING SAMPLE` and `WRITING RULES`.
|
|
19475
22852
|
*
|
|
19476
|
-
*
|
|
22853
|
+
* Legacy example usage in agent source:
|
|
19477
22854
|
*
|
|
19478
22855
|
* ```book
|
|
19479
22856
|
* TEMPLATE Always structure your response with: 1) Summary, 2) Details, 3) Next steps
|
|
@@ -19493,7 +22870,16 @@
|
|
|
19493
22870
|
* Short one-line description of TEMPLATE.
|
|
19494
22871
|
*/
|
|
19495
22872
|
get description() {
|
|
19496
|
-
return '
|
|
22873
|
+
return 'Deprecated legacy template commitment. Prefer `WRITING SAMPLE` and `WRITING RULES` for new books.';
|
|
22874
|
+
}
|
|
22875
|
+
/**
|
|
22876
|
+
* Optional UI/docs-only deprecation metadata.
|
|
22877
|
+
*/
|
|
22878
|
+
get deprecation() {
|
|
22879
|
+
return {
|
|
22880
|
+
message: 'Use `WRITING SAMPLE` and `WRITING RULES` instead.',
|
|
22881
|
+
replacedBy: ['WRITING SAMPLE', 'WRITING RULES'],
|
|
22882
|
+
};
|
|
19497
22883
|
}
|
|
19498
22884
|
/**
|
|
19499
22885
|
* Icon for this commitment.
|
|
@@ -19508,38 +22894,32 @@
|
|
|
19508
22894
|
return _spaceTrim.spaceTrim(`
|
|
19509
22895
|
# ${this.type}
|
|
19510
22896
|
|
|
19511
|
-
|
|
22897
|
+
Deprecated legacy commitment for response structure and templates.
|
|
19512
22898
|
|
|
19513
|
-
##
|
|
22899
|
+
## Migration
|
|
19514
22900
|
|
|
19515
|
-
-
|
|
19516
|
-
-
|
|
19517
|
-
-
|
|
19518
|
-
- When used with content, defines the specific template structure to follow.
|
|
19519
|
-
- Multiple templates can be combined, with later ones taking precedence.
|
|
22901
|
+
- Existing \`${this.type}\` and \`TEMPLATES\` books still parse and compile.
|
|
22902
|
+
- New books should use \`WRITING SAMPLE\` for concrete response exemplars and \`WRITING RULES\` for structure or formatting constraints.
|
|
22903
|
+
- Runtime behavior is intentionally unchanged for backward compatibility.
|
|
19520
22904
|
|
|
19521
|
-
##
|
|
22905
|
+
## Preferred replacement
|
|
19522
22906
|
|
|
19523
22907
|
\`\`\`book
|
|
19524
22908
|
Customer Support Agent
|
|
19525
22909
|
|
|
19526
|
-
|
|
19527
|
-
|
|
19528
|
-
|
|
22910
|
+
GOAL Help the user with support questions.
|
|
22911
|
+
WRITING SAMPLE
|
|
22912
|
+
Thanks for reaching out. Here is the summary, details, and next step.
|
|
22913
|
+
WRITING RULES Keep the response structured as: summary, details, next step.
|
|
19529
22914
|
\`\`\`
|
|
19530
22915
|
|
|
19531
|
-
|
|
19532
|
-
Technical Documentation Assistant
|
|
19533
|
-
|
|
19534
|
-
PERSONA You are a technical writing expert
|
|
19535
|
-
TEMPLATE Use the following format: **Topic:** [topic] | **Explanation:** [details] | **Example:** [code]
|
|
19536
|
-
FORMAT Use markdown with clear headings
|
|
19537
|
-
\`\`\`
|
|
22916
|
+
## Legacy compatibility example
|
|
19538
22917
|
|
|
19539
22918
|
\`\`\`book
|
|
19540
|
-
|
|
22919
|
+
Customer Support Agent
|
|
19541
22920
|
|
|
19542
|
-
|
|
22921
|
+
GOAL Help the user with support questions.
|
|
22922
|
+
TEMPLATE Always structure your response with: 1) Acknowledgment, 2) Solution, 3) Follow-up question
|
|
19543
22923
|
TEMPLATE
|
|
19544
22924
|
\`\`\`
|
|
19545
22925
|
`);
|
|
@@ -19587,120 +22967,6 @@
|
|
|
19587
22967
|
}
|
|
19588
22968
|
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
19589
22969
|
|
|
19590
|
-
/**
|
|
19591
|
-
* USE commitment definition
|
|
19592
|
-
*
|
|
19593
|
-
* The USE commitment indicates that the agent should utilize specific tools or capabilities
|
|
19594
|
-
* to access and interact with external systems when necessary.
|
|
19595
|
-
*
|
|
19596
|
-
* Supported USE types:
|
|
19597
|
-
* - USE BROWSER: Enables the agent to use a web browser tool
|
|
19598
|
-
* - USE SEARCH ENGINE (future): Enables search engine access
|
|
19599
|
-
* - USE DEEPSEARCH: Enables deeper research-oriented search access
|
|
19600
|
-
* - USE FILE SYSTEM (future): Enables file system operations
|
|
19601
|
-
* - USE MCP (future): Enables MCP server connections
|
|
19602
|
-
*
|
|
19603
|
-
* The content following the USE commitment is ignored (similar to NOTE).
|
|
19604
|
-
*
|
|
19605
|
-
* Example usage in agent source:
|
|
19606
|
-
*
|
|
19607
|
-
* ```book
|
|
19608
|
-
* USE BROWSER
|
|
19609
|
-
* USE SEARCH ENGINE
|
|
19610
|
-
* ```
|
|
19611
|
-
*
|
|
19612
|
-
* @private [đĒ] Maybe export the commitments through some package
|
|
19613
|
-
*/
|
|
19614
|
-
class UseCommitmentDefinition extends BaseCommitmentDefinition {
|
|
19615
|
-
constructor() {
|
|
19616
|
-
super('USE');
|
|
19617
|
-
}
|
|
19618
|
-
/**
|
|
19619
|
-
* Short one-line description of USE commitments.
|
|
19620
|
-
*/
|
|
19621
|
-
get description() {
|
|
19622
|
-
return 'Enable the agent to use specific tools or capabilities (BROWSER, SEARCH ENGINE, DEEPSEARCH, etc.).';
|
|
19623
|
-
}
|
|
19624
|
-
/**
|
|
19625
|
-
* Icon for this commitment.
|
|
19626
|
-
*/
|
|
19627
|
-
get icon() {
|
|
19628
|
-
return 'đ§';
|
|
19629
|
-
}
|
|
19630
|
-
/**
|
|
19631
|
-
* Markdown documentation for USE commitment.
|
|
19632
|
-
*/
|
|
19633
|
-
get documentation() {
|
|
19634
|
-
return _spaceTrim.spaceTrim(`
|
|
19635
|
-
# USE
|
|
19636
|
-
|
|
19637
|
-
Enables the agent to use specific tools or capabilities for interacting with external systems.
|
|
19638
|
-
|
|
19639
|
-
## Supported USE types
|
|
19640
|
-
|
|
19641
|
-
- **USE BROWSER** - Enables the agent to use a web browser tool to access and retrieve information from the internet
|
|
19642
|
-
- **USE SEARCH ENGINE** (future) - Enables search engine access
|
|
19643
|
-
- **USE DEEPSEARCH** - Enables deeper research-oriented search access
|
|
19644
|
-
- **USE FILE SYSTEM** (future) - Enables file system operations
|
|
19645
|
-
- **USE MCP** (future) - Enables MCP server connections
|
|
19646
|
-
|
|
19647
|
-
## Key aspects
|
|
19648
|
-
|
|
19649
|
-
- The content following the USE commitment is ignored (similar to NOTE)
|
|
19650
|
-
- Multiple USE commitments can be specified to enable multiple capabilities
|
|
19651
|
-
- The actual tool usage is handled by the agent runtime
|
|
19652
|
-
|
|
19653
|
-
## Examples
|
|
19654
|
-
|
|
19655
|
-
### Basic browser usage
|
|
19656
|
-
|
|
19657
|
-
\`\`\`book
|
|
19658
|
-
Research Assistant
|
|
19659
|
-
|
|
19660
|
-
PERSONA You are a helpful research assistant
|
|
19661
|
-
USE BROWSER
|
|
19662
|
-
KNOWLEDGE Can search the web for up-to-date information
|
|
19663
|
-
\`\`\`
|
|
19664
|
-
|
|
19665
|
-
### Multiple tools
|
|
19666
|
-
|
|
19667
|
-
\`\`\`book
|
|
19668
|
-
Data Analyst
|
|
19669
|
-
|
|
19670
|
-
PERSONA You are a data analyst assistant
|
|
19671
|
-
USE BROWSER
|
|
19672
|
-
USE FILE SYSTEM
|
|
19673
|
-
ACTION Can analyze data from various sources
|
|
19674
|
-
\`\`\`
|
|
19675
|
-
`);
|
|
19676
|
-
}
|
|
19677
|
-
applyToAgentModelRequirements(requirements, content) {
|
|
19678
|
-
// USE commitments don't modify the system message or model requirements directly
|
|
19679
|
-
// They are handled separately in the parsing logic for capability extraction
|
|
19680
|
-
// This method exists for consistency with the CommitmentDefinition interface
|
|
19681
|
-
return requirements;
|
|
19682
|
-
}
|
|
19683
|
-
/**
|
|
19684
|
-
* Extracts the tool type from the USE commitment
|
|
19685
|
-
* This is used by the parsing logic
|
|
19686
|
-
*/
|
|
19687
|
-
extractToolType(content) {
|
|
19688
|
-
var _a, _b;
|
|
19689
|
-
const trimmedContent = content.trim();
|
|
19690
|
-
// The tool type is the first word after USE (already stripped)
|
|
19691
|
-
const match = trimmedContent.match(/^(\w+)/);
|
|
19692
|
-
return (_b = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : null;
|
|
19693
|
-
}
|
|
19694
|
-
/**
|
|
19695
|
-
* Checks if this is a known USE type
|
|
19696
|
-
*/
|
|
19697
|
-
isKnownUseType(useType) {
|
|
19698
|
-
const knownTypes = ['BROWSER', 'SEARCH ENGINE', 'DEEPSEARCH', 'FILE SYSTEM', 'MCP'];
|
|
19699
|
-
return knownTypes.includes(useType.toUpperCase());
|
|
19700
|
-
}
|
|
19701
|
-
}
|
|
19702
|
-
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
19703
|
-
|
|
19704
22970
|
/**
|
|
19705
22971
|
* All `USE` commitment types currently participating in final system-message aggregation.
|
|
19706
22972
|
*
|
|
@@ -25667,10 +28933,10 @@
|
|
|
25667
28933
|
new MemoryCommitmentDefinition('MEMORIES'),
|
|
25668
28934
|
new StyleCommitmentDefinition('STYLE'),
|
|
25669
28935
|
new StyleCommitmentDefinition('STYLES'),
|
|
25670
|
-
new RuleCommitmentDefinition('RULES'),
|
|
25671
28936
|
new RuleCommitmentDefinition('RULE'),
|
|
25672
|
-
new
|
|
28937
|
+
new RuleCommitmentDefinition('RULES'),
|
|
25673
28938
|
new LanguageCommitmentDefinition('LANGUAGE'),
|
|
28939
|
+
new LanguageCommitmentDefinition('LANGUAGES'),
|
|
25674
28940
|
new WritingSampleCommitmentDefinition(),
|
|
25675
28941
|
new WritingRulesCommitmentDefinition(),
|
|
25676
28942
|
new SampleCommitmentDefinition('SAMPLE'),
|
|
@@ -25687,6 +28953,7 @@
|
|
|
25687
28953
|
new ActionCommitmentDefinition('ACTION'),
|
|
25688
28954
|
new ActionCommitmentDefinition('ACTIONS'),
|
|
25689
28955
|
new ComponentCommitmentDefinition(),
|
|
28956
|
+
new MetaAvatarCommitmentDefinition(),
|
|
25690
28957
|
new MetaImageCommitmentDefinition(),
|
|
25691
28958
|
new MetaColorCommitmentDefinition(),
|
|
25692
28959
|
new MetaFontCommitmentDefinition(),
|
|
@@ -25734,7 +29001,6 @@
|
|
|
25734
29001
|
new UseMcpCommitmentDefinition(),
|
|
25735
29002
|
new UsePrivacyCommitmentDefinition(),
|
|
25736
29003
|
new UseProjectCommitmentDefinition(),
|
|
25737
|
-
new UseCommitmentDefinition(),
|
|
25738
29004
|
// Not yet implemented commitments (using placeholder)
|
|
25739
29005
|
new NotYetImplementedCommitmentDefinition('EXPECT'),
|
|
25740
29006
|
new NotYetImplementedCommitmentDefinition('BEHAVIOUR'),
|
|
@@ -25747,6 +29013,92 @@
|
|
|
25747
29013
|
// TODO: [đ§ ] Maybe create through standardized $register
|
|
25748
29014
|
// Note: [đ] Ignore a discrepancy between file name and entity name
|
|
25749
29015
|
|
|
29016
|
+
/**
|
|
29017
|
+
* Priority order for the important commitments shown first in catalogues and intellisense.
|
|
29018
|
+
*
|
|
29019
|
+
* Canonical singular names stay ahead of their plural aliases so the most important
|
|
29020
|
+
* commitments remain easy to scan.
|
|
29021
|
+
*
|
|
29022
|
+
* @private internal constant of commitment catalog sorting
|
|
29023
|
+
*/
|
|
29024
|
+
const IMPORTANT_COMMITMENT_TYPE_SORT_ORDER = new Map([
|
|
29025
|
+
['GOAL', 0],
|
|
29026
|
+
['GOALS', 1],
|
|
29027
|
+
['RULE', 2],
|
|
29028
|
+
['RULES', 3],
|
|
29029
|
+
['KNOWLEDGE', 4],
|
|
29030
|
+
['TEAM', 5],
|
|
29031
|
+
]);
|
|
29032
|
+
/**
|
|
29033
|
+
* Sort rank used when unfinished, low-level, and deprecated commitments should be grouped last.
|
|
29034
|
+
*
|
|
29035
|
+
* @private internal constant of commitment catalog sorting
|
|
29036
|
+
*/
|
|
29037
|
+
const COMMITMENT_STATUS_SORT_ORDER = {
|
|
29038
|
+
normal: 0,
|
|
29039
|
+
deprecated: 1,
|
|
29040
|
+
unfinished: 2,
|
|
29041
|
+
lowLevel: 3,
|
|
29042
|
+
};
|
|
29043
|
+
/**
|
|
29044
|
+
* Resolves the relative sort rank of one commitment status.
|
|
29045
|
+
*
|
|
29046
|
+
* @param definition - Commitment definition to rank.
|
|
29047
|
+
* @param options - Sorting options.
|
|
29048
|
+
* @returns Relative sort rank for the definition.
|
|
29049
|
+
*
|
|
29050
|
+
* @private internal helper of commitment catalog sorting
|
|
29051
|
+
*/
|
|
29052
|
+
function resolveCommitmentStatusSortRank(definition, options) {
|
|
29053
|
+
let statusSortRank = COMMITMENT_STATUS_SORT_ORDER.normal;
|
|
29054
|
+
if (options.isDeprecatedLast && definition.deprecation) {
|
|
29055
|
+
statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.deprecated);
|
|
29056
|
+
}
|
|
29057
|
+
if (options.isUnfinishedLast && definition.isUnfinished) {
|
|
29058
|
+
statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.unfinished);
|
|
29059
|
+
}
|
|
29060
|
+
if (options.isLowLevelLast && definition.isLowLevel) {
|
|
29061
|
+
statusSortRank = Math.max(statusSortRank, COMMITMENT_STATUS_SORT_ORDER.lowLevel);
|
|
29062
|
+
}
|
|
29063
|
+
return statusSortRank;
|
|
29064
|
+
}
|
|
29065
|
+
/**
|
|
29066
|
+
* Sorts commitment definitions so the important ones stay at the top.
|
|
29067
|
+
*
|
|
29068
|
+
* @param commitmentDefinitions - Definitions to sort.
|
|
29069
|
+
* @param options - Sorting options.
|
|
29070
|
+
* @returns Sorted commitment definitions.
|
|
29071
|
+
*
|
|
29072
|
+
* @private internal helper of commitment catalog sorting
|
|
29073
|
+
*/
|
|
29074
|
+
function sortCommitmentDefinitions(commitmentDefinitions, options = {}) {
|
|
29075
|
+
return [...commitmentDefinitions]
|
|
29076
|
+
.map((definition, index) => ({
|
|
29077
|
+
definition,
|
|
29078
|
+
index,
|
|
29079
|
+
}))
|
|
29080
|
+
.sort((left, right) => {
|
|
29081
|
+
var _a, _b;
|
|
29082
|
+
if (left.definition.isImportant !== right.definition.isImportant) {
|
|
29083
|
+
return left.definition.isImportant ? -1 : 1;
|
|
29084
|
+
}
|
|
29085
|
+
if (left.definition.isImportant && right.definition.isImportant) {
|
|
29086
|
+
const leftPriority = (_a = IMPORTANT_COMMITMENT_TYPE_SORT_ORDER.get(left.definition.type)) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;
|
|
29087
|
+
const rightPriority = (_b = IMPORTANT_COMMITMENT_TYPE_SORT_ORDER.get(right.definition.type)) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER;
|
|
29088
|
+
if (leftPriority !== rightPriority) {
|
|
29089
|
+
return leftPriority - rightPriority;
|
|
29090
|
+
}
|
|
29091
|
+
}
|
|
29092
|
+
const leftStatusSortRank = resolveCommitmentStatusSortRank(left.definition, options);
|
|
29093
|
+
const rightStatusSortRank = resolveCommitmentStatusSortRank(right.definition, options);
|
|
29094
|
+
if (leftStatusSortRank !== rightStatusSortRank) {
|
|
29095
|
+
return leftStatusSortRank - rightStatusSortRank;
|
|
29096
|
+
}
|
|
29097
|
+
return left.index - right.index;
|
|
29098
|
+
})
|
|
29099
|
+
.map(({ definition }) => definition);
|
|
29100
|
+
}
|
|
29101
|
+
|
|
25750
29102
|
/**
|
|
25751
29103
|
* Gets all available commitment definitions
|
|
25752
29104
|
*
|
|
@@ -25755,7 +29107,7 @@
|
|
|
25755
29107
|
* @public exported from `@promptbook/core`
|
|
25756
29108
|
*/
|
|
25757
29109
|
function getAllCommitmentDefinitions() {
|
|
25758
|
-
return $deepFreeze(
|
|
29110
|
+
return $deepFreeze(sortCommitmentDefinitions(COMMITMENT_REGISTRY, { isUnfinishedLast: true, isLowLevelLast: true }));
|
|
25759
29111
|
}
|
|
25760
29112
|
|
|
25761
29113
|
/**
|
|
@@ -27954,7 +31306,7 @@
|
|
|
27954
31306
|
lastPreparationIndex = index;
|
|
27955
31307
|
}
|
|
27956
31308
|
else {
|
|
27957
|
-
// Remove earlier duplicate
|
|
31309
|
+
// Remove earlier duplicate - keep only the last (most recent) one.
|
|
27958
31310
|
toolCalls.splice(index, 1);
|
|
27959
31311
|
}
|
|
27960
31312
|
}
|
|
@@ -28367,6 +31719,7 @@
|
|
|
28367
31719
|
* @private internal utility of `parseAgentSource`
|
|
28368
31720
|
*/
|
|
28369
31721
|
const META_COMMITMENT_APPLIERS = {
|
|
31722
|
+
'META AVATAR': applyMetaAvatarContent,
|
|
28370
31723
|
'META LINK': applyMetaLinkContent,
|
|
28371
31724
|
'META DOMAIN': applyMetaDomainContent,
|
|
28372
31725
|
'META IMAGE': applyMetaImageContent,
|
|
@@ -28730,9 +32083,26 @@
|
|
|
28730
32083
|
if (metaTypeRaw === 'LINK') {
|
|
28731
32084
|
state.links.push(metaValue);
|
|
28732
32085
|
}
|
|
32086
|
+
if (metaTypeRaw.toUpperCase() === 'AVATAR') {
|
|
32087
|
+
applyMetaAvatarContent(state, metaValue);
|
|
32088
|
+
return;
|
|
32089
|
+
}
|
|
28733
32090
|
const metaType = normalizeTo_camelCase(metaTypeRaw);
|
|
28734
32091
|
state.meta[metaType] = metaValue;
|
|
28735
32092
|
}
|
|
32093
|
+
/**
|
|
32094
|
+
* Applies META AVATAR content into the canonical `meta.avatar` field.
|
|
32095
|
+
*
|
|
32096
|
+
* @private internal utility of `parseAgentSource`
|
|
32097
|
+
*/
|
|
32098
|
+
function applyMetaAvatarContent(state, content) {
|
|
32099
|
+
const avatarVisualId = resolveAvatarVisualId(content);
|
|
32100
|
+
if (avatarVisualId) {
|
|
32101
|
+
state.meta.avatar = avatarVisualId;
|
|
32102
|
+
return;
|
|
32103
|
+
}
|
|
32104
|
+
delete state.meta.avatar;
|
|
32105
|
+
}
|
|
28736
32106
|
/**
|
|
28737
32107
|
* Applies META LINK content into links and the canonical `meta.link` field.
|
|
28738
32108
|
*
|
|
@@ -30317,7 +33687,7 @@
|
|
|
30317
33687
|
// Note: [đ] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
|
|
30318
33688
|
|
|
30319
33689
|
/**
|
|
30320
|
-
* Change dash-like characters to regular dashes
|
|
33690
|
+
* Change dash-like characters to regular dashes `-` -> `-` and remove soft hyphens
|
|
30321
33691
|
*
|
|
30322
33692
|
* Note: [đ] This function is idempotent.
|
|
30323
33693
|
* Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
|
|
@@ -30325,7 +33695,7 @@
|
|
|
30325
33695
|
* @public exported from `@promptbook/markdown-utils`
|
|
30326
33696
|
*/
|
|
30327
33697
|
function humanizeAiTextEmdashed(aiText) {
|
|
30328
|
-
return aiText.replace(/\u00AD/g, '').replace(/[
|
|
33698
|
+
return aiText.replace(/\u00AD/g, '').replace(/[ââââ-âââīšŖīŧ]/g, '-');
|
|
30329
33699
|
}
|
|
30330
33700
|
// Note: [đ] This function is not tested by itself but together with other cleanup functions with `humanizeAiText`
|
|
30331
33701
|
|
|
@@ -37038,6 +40408,7 @@
|
|
|
37038
40408
|
const isMetaImageExplicit = profile.isMetaImageExplicit !== false;
|
|
37039
40409
|
const metaLines = [
|
|
37040
40410
|
formatMetaLine('FULLNAME', meta === null || meta === void 0 ? void 0 : meta.fullname),
|
|
40411
|
+
formatMetaLine('AVATAR', meta === null || meta === void 0 ? void 0 : meta.avatar),
|
|
37041
40412
|
formatMetaLine('IMAGE', isMetaImageExplicit ? meta === null || meta === void 0 ? void 0 : meta.image : undefined),
|
|
37042
40413
|
formatMetaLine('DESCRIPTION', meta === null || meta === void 0 ? void 0 : meta.description),
|
|
37043
40414
|
formatMetaLine('COLOR', meta === null || meta === void 0 ? void 0 : meta.color),
|
|
@@ -37078,7 +40449,7 @@
|
|
|
37078
40449
|
var _a, _b, _c;
|
|
37079
40450
|
const agentProfileUrl = `${options.agentUrl}/api/profile`;
|
|
37080
40451
|
const profileResponse = await fetch(agentProfileUrl, {
|
|
37081
|
-
headers: attachClientVersionHeader(),
|
|
40452
|
+
headers: attachClientVersionHeader(options.requestHeaders),
|
|
37082
40453
|
});
|
|
37083
40454
|
// <- TODO: [đąâđ] What about closed-source agents?
|
|
37084
40455
|
// <- TODO: [đąâđ] Maybe use promptbookFetch
|
|
@@ -37158,6 +40529,7 @@
|
|
|
37158
40529
|
this.avatarVisualId = undefined;
|
|
37159
40530
|
this.knowledgeSources = [];
|
|
37160
40531
|
this.agentUrl = options.agentUrl;
|
|
40532
|
+
this.requestHeaders = options.requestHeaders || {};
|
|
37161
40533
|
}
|
|
37162
40534
|
get agentName() {
|
|
37163
40535
|
return this._remoteAgentName || super.agentName;
|
|
@@ -37194,7 +40566,7 @@
|
|
|
37194
40566
|
}
|
|
37195
40567
|
const response = await fetch(`${this.agentUrl}/api/voice`, {
|
|
37196
40568
|
method: 'POST',
|
|
37197
|
-
headers: attachClientVersionHeader(),
|
|
40569
|
+
headers: attachClientVersionHeader(this.requestHeaders),
|
|
37198
40570
|
body: formData,
|
|
37199
40571
|
});
|
|
37200
40572
|
if (!response.ok) {
|
|
@@ -37225,6 +40597,7 @@
|
|
|
37225
40597
|
const bookResponse = await fetch(`${this.agentUrl}/api/chat`, {
|
|
37226
40598
|
method: 'POST',
|
|
37227
40599
|
headers: attachClientVersionHeader({
|
|
40600
|
+
...this.requestHeaders,
|
|
37228
40601
|
'Content-Type': 'application/json',
|
|
37229
40602
|
}),
|
|
37230
40603
|
body: JSON.stringify({
|