@yuhuanowo/yunui 0.2.17 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -5
- package/README.zh-CN.md +21 -3
- package/README.zh-TW.md +21 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/agent/catalog.generated.json +29368 -0
- package/agent/recipes/analytics.tsx +121 -0
- package/agent/recipes/chat.tsx +154 -0
- package/agent/recipes/conversation-units.tsx +28 -0
- package/agent/recipes/dashboard.tsx +38 -0
- package/agent/recipes/landing.tsx +26 -0
- package/agent/recipes/setup.md +44 -0
- package/agent/skills/yunui/SKILL.md +82 -0
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +1 -1
- package/dist/ai.d.ts +478 -273
- package/dist/ai.js +1334 -1964
- package/dist/ai.js.map +1 -1
- package/dist/charts.d.ts +149 -0
- package/dist/charts.js +849 -0
- package/dist/charts.js.map +1 -0
- package/dist/chat.d.ts +204 -18
- package/dist/chat.js +887 -132
- package/dist/chat.js.map +1 -1
- package/dist/{chunk-F2HG4TOQ.js → chunk-ASPPAL7E.js} +25 -29
- package/dist/chunk-ASPPAL7E.js.map +1 -0
- package/dist/chunk-AVXIR7ZQ.js +197 -0
- package/dist/chunk-AVXIR7ZQ.js.map +1 -0
- package/dist/chunk-FJ52MVRF.js +82 -0
- package/dist/chunk-FJ52MVRF.js.map +1 -0
- package/dist/chunk-GRUB2GXF.js +15 -0
- package/dist/chunk-GRUB2GXF.js.map +1 -0
- package/dist/{chunk-3RT24MSH.js → chunk-GWD5W5F5.js} +2 -2
- package/dist/{chunk-3RT24MSH.js.map → chunk-GWD5W5F5.js.map} +1 -1
- package/dist/{chunk-BCOKFWXC.js → chunk-I2DAKAD5.js} +423 -281
- package/dist/chunk-I2DAKAD5.js.map +1 -0
- package/dist/chunk-OM7B4O6K.js +193 -0
- package/dist/chunk-OM7B4O6K.js.map +1 -0
- package/dist/chunk-OZIDZFMF.js +70 -0
- package/dist/chunk-OZIDZFMF.js.map +1 -0
- package/dist/chunk-P6LU2FWV.js +35 -0
- package/dist/chunk-P6LU2FWV.js.map +1 -0
- package/dist/chunk-SXWMKFKM.js +41 -0
- package/dist/chunk-SXWMKFKM.js.map +1 -0
- package/dist/chunk-TMTXJFNN.js +2715 -0
- package/dist/chunk-TMTXJFNN.js.map +1 -0
- package/dist/chunk-VNKAEQKU.js +501 -0
- package/dist/chunk-VNKAEQKU.js.map +1 -0
- package/dist/chunk-VSS7ASN2.js +12 -0
- package/dist/chunk-VSS7ASN2.js.map +1 -0
- package/dist/chunk-VYVFMNM7.js +112 -0
- package/dist/chunk-VYVFMNM7.js.map +1 -0
- package/dist/chunk-YKUQ7GCJ.js +230 -0
- package/dist/chunk-YKUQ7GCJ.js.map +1 -0
- package/dist/chunk-Z6WXDNBJ.js +366 -0
- package/dist/chunk-Z6WXDNBJ.js.map +1 -0
- package/dist/chunk-ZBRV6NHL.js +1115 -0
- package/dist/chunk-ZBRV6NHL.js.map +1 -0
- package/dist/code.d.ts +42 -0
- package/dist/code.js +8 -0
- package/dist/code.js.map +1 -0
- package/dist/content.d.ts +26 -40
- package/dist/content.js +400 -418
- package/dist/content.js.map +1 -1
- package/dist/footer-BCd-S806.d.ts +122 -0
- package/dist/index.d.ts +814 -88
- package/dist/index.js +7 -5
- package/dist/language.d.ts +30 -0
- package/dist/language.js +5 -0
- package/dist/language.js.map +1 -0
- package/dist/model-card.d.ts +43 -0
- package/dist/model-card.js +116 -0
- package/dist/model-card.js.map +1 -0
- package/dist/model.d.ts +51 -0
- package/dist/model.js +91 -0
- package/dist/model.js.map +1 -0
- package/dist/motion.d.ts +11 -0
- package/dist/motion.js +9 -0
- package/dist/motion.js.map +1 -0
- package/dist/patterns.d.ts +913 -29
- package/dist/patterns.js +1987 -259
- package/dist/patterns.js.map +1 -1
- package/dist/pickers.d.ts +134 -0
- package/dist/pickers.js +751 -0
- package/dist/pickers.js.map +1 -0
- package/dist/provider-icons-bgBTnami.d.ts +88 -0
- package/dist/segmented-bar-Bsr0PZIL.d.ts +58 -0
- package/dist/sparkline-vy5ec5C6.d.ts +67 -0
- package/icons/apps/aistudio.webp +0 -0
- package/icons/apps/coze.webp +0 -0
- package/icons/apps/dify.webp +0 -0
- package/icons/apps/doubao.webp +0 -0
- package/icons/apps/flowith.webp +0 -0
- package/icons/apps/gemini.webp +0 -0
- package/icons/apps/github-copilot.webp +0 -0
- package/icons/apps/google.webp +0 -0
- package/icons/apps/grok.webp +0 -0
- package/icons/apps/kimi.webp +0 -0
- package/icons/apps/ling.webp +0 -0
- package/icons/apps/longcat.webp +0 -0
- package/icons/apps/monica.webp +0 -0
- package/icons/apps/n8n.webp +0 -0
- package/icons/apps/notebooklm.webp +0 -0
- package/icons/apps/perplexity.webp +0 -0
- package/icons/apps/poe.webp +0 -0
- package/icons/apps/qingyan.webp +0 -0
- package/icons/apps/stepfun.webp +0 -0
- package/icons/apps/tiangong.webp +0 -0
- package/icons/apps/yuanbao.webp +0 -0
- package/icons/apps/zai.webp +0 -0
- package/icons/models/ai21.webp +0 -0
- package/icons/models/aimass.webp +0 -0
- package/icons/models/anthropic.webp +0 -0
- package/icons/models/baichuan.webp +0 -0
- package/icons/models/byte_dance.webp +0 -0
- package/icons/models/chatglm.webp +0 -0
- package/icons/models/claude.webp +0 -0
- package/icons/models/codegeex.webp +0 -0
- package/icons/models/cogview3flash.webp +0 -0
- package/icons/models/cohere.webp +0 -0
- package/icons/models/copilot.webp +0 -0
- package/icons/models/dalle.webp +0 -0
- package/icons/models/dbrx.webp +0 -0
- package/icons/models/deepseek.webp +0 -0
- package/icons/models/doubao.webp +0 -0
- package/icons/models/flux.webp +0 -0
- package/icons/models/gemini.webp +0 -0
- package/icons/models/gemma.webp +0 -0
- package/icons/models/google.webp +0 -0
- package/icons/models/grok.webp +0 -0
- package/icons/models/hailuo.webp +0 -0
- package/icons/models/huggingface.webp +0 -0
- package/icons/models/hunyuan.webp +0 -0
- package/icons/models/ibm.webp +0 -0
- package/icons/models/ideogram.webp +0 -0
- package/icons/models/internlm.webp +0 -0
- package/icons/models/jina.webp +0 -0
- package/icons/models/ling.webp +0 -0
- package/icons/models/llava.webp +0 -0
- package/icons/models/luma.webp +0 -0
- package/icons/models/magic.webp +0 -0
- package/icons/models/microsoft.webp +0 -0
- package/icons/models/midjourney.webp +0 -0
- package/icons/models/minimax.webp +0 -0
- package/icons/models/mistral.webp +0 -0
- package/icons/models/moonshot.webp +0 -0
- package/icons/models/nousresearch.webp +0 -0
- package/icons/models/nvidia.webp +0 -0
- package/icons/models/o3.webp +0 -0
- package/icons/models/openai.webp +0 -0
- package/icons/models/palm.webp +0 -0
- package/icons/models/perplexity.webp +0 -0
- package/icons/models/qwen.webp +0 -0
- package/icons/models/stability.webp +0 -0
- package/icons/models/step.webp +0 -0
- package/icons/models/suno.webp +0 -0
- package/icons/models/upstage.webp +0 -0
- package/icons/models/vidu.webp +0 -0
- package/icons/models/volcengine.webp +0 -0
- package/icons/models/voyageai.webp +0 -0
- package/icons/models/wenxin.webp +0 -0
- package/icons/models/yi.webp +0 -0
- package/icons/models/zai.webp +0 -0
- package/icons/models/zero-one.webp +0 -0
- package/icons/models/zhipu.webp +0 -0
- package/icons/providers/302ai.webp +0 -0
- package/icons/providers/ace.webp +0 -0
- package/icons/providers/adobe.webp +0 -0
- package/icons/providers/adobefirefly.webp +0 -0
- package/icons/providers/agentvoice.webp +0 -0
- package/icons/providers/agnesai.webp +0 -0
- package/icons/providers/agui.webp +0 -0
- package/icons/providers/ai2.webp +0 -0
- package/icons/providers/ai21.webp +0 -0
- package/icons/providers/ai302.webp +0 -0
- package/icons/providers/ai360.webp +0 -0
- package/icons/providers/aihubmix.webp +0 -0
- package/icons/providers/aimass.webp +0 -0
- package/icons/providers/aimlapi.webp +0 -0
- package/icons/providers/aionlabs.webp +0 -0
- package/icons/providers/airjelly.webp +0 -0
- package/icons/providers/aistudio.webp +0 -0
- package/icons/providers/akashchat.webp +0 -0
- package/icons/providers/alephalpha.webp +0 -0
- package/icons/providers/alibaba.webp +0 -0
- package/icons/providers/alibabacloud.webp +0 -0
- package/icons/providers/amdradeoncloud.webp +0 -0
- package/icons/providers/amp.webp +0 -0
- package/icons/providers/anspire.webp +0 -0
- package/icons/providers/antgroup.webp +0 -0
- package/icons/providers/anthropic.webp +0 -0
- package/icons/providers/antigravity.webp +0 -0
- package/icons/providers/anyscale.webp +0 -0
- package/icons/providers/apertis.webp +0 -0
- package/icons/providers/apple.webp +0 -0
- package/icons/providers/appwrite.webp +0 -0
- package/icons/providers/arcee.webp +0 -0
- package/icons/providers/askverdict.webp +0 -0
- package/icons/providers/assemblyai.webp +0 -0
- package/icons/providers/atlascloud.webp +0 -0
- package/icons/providers/automatic.webp +0 -0
- package/icons/providers/aws-bedrock.webp +0 -0
- package/icons/providers/aws.webp +0 -0
- package/icons/providers/aya.webp +0 -0
- package/icons/providers/azure.webp +0 -0
- package/icons/providers/azureai.webp +0 -0
- package/icons/providers/baai.webp +0 -0
- package/icons/providers/baichuan.webp +0 -0
- package/icons/providers/baidu-cloud.webp +0 -0
- package/icons/providers/baidu.webp +0 -0
- package/icons/providers/baiducloud.webp +0 -0
- package/icons/providers/bailian.webp +0 -0
- package/icons/providers/baseten.webp +0 -0
- package/icons/providers/bedrock.webp +0 -0
- package/icons/providers/bfl.webp +0 -0
- package/icons/providers/bigModel.webp +0 -0
- package/icons/providers/bilibili.webp +0 -0
- package/icons/providers/bilibiliindex.webp +0 -0
- package/icons/providers/bing.webp +0 -0
- package/icons/providers/bocha.webp +0 -0
- package/icons/providers/brave.webp +0 -0
- package/icons/providers/briaai.webp +0 -0
- package/icons/providers/browserless.webp +0 -0
- package/icons/providers/burncloud.webp +0 -0
- package/icons/providers/bytedance.webp +0 -0
- package/icons/providers/capcut.webp +0 -0
- package/icons/providers/celestoai.webp +0 -0
- package/icons/providers/centml.webp +0 -0
- package/icons/providers/cerebras.webp +0 -0
- package/icons/providers/chatglm.webp +0 -0
- package/icons/providers/cheaperinference.webp +0 -0
- package/icons/providers/cherrystudio.webp +0 -0
- package/icons/providers/chutes.webp +0 -0
- package/icons/providers/civitai.webp +0 -0
- package/icons/providers/claude.webp +0 -0
- package/icons/providers/claudecode.webp +0 -0
- package/icons/providers/cline.webp +0 -0
- package/icons/providers/clipdrop.webp +0 -0
- package/icons/providers/cloudflare.webp +0 -0
- package/icons/providers/codebuddy.webp +0 -0
- package/icons/providers/codeflicker.webp +0 -0
- package/icons/providers/codegeex.webp +0 -0
- package/icons/providers/codex.webp +0 -0
- package/icons/providers/cogvideo.webp +0 -0
- package/icons/providers/cogview.webp +0 -0
- package/icons/providers/cogview3flash.webp +0 -0
- package/icons/providers/cohere.webp +0 -0
- package/icons/providers/colab.webp +0 -0
- package/icons/providers/cometapi.webp +0 -0
- package/icons/providers/comfyui.webp +0 -0
- package/icons/providers/commanda.webp +0 -0
- package/icons/providers/commandcode.webp +0 -0
- package/icons/providers/copilot.webp +0 -0
- package/icons/providers/copilotkit.webp +0 -0
- package/icons/providers/coqui.webp +0 -0
- package/icons/providers/coze.webp +0 -0
- package/icons/providers/crewai.webp +0 -0
- package/icons/providers/crusoe.webp +0 -0
- package/icons/providers/cursor.webp +0 -0
- package/icons/providers/cybercut.webp +0 -0
- package/icons/providers/dalle.webp +0 -0
- package/icons/providers/dbrx.webp +0 -0
- package/icons/providers/decart.webp +0 -0
- package/icons/providers/deepai.webp +0 -0
- package/icons/providers/deepcogito.webp +0 -0
- package/icons/providers/deepinfra.webp +0 -0
- package/icons/providers/deepl.webp +0 -0
- package/icons/providers/deepmind.webp +0 -0
- package/icons/providers/deepseek.webp +0 -0
- package/icons/providers/devin.webp +0 -0
- package/icons/providers/dify.webp +0 -0
- package/icons/providers/digitalocean.webp +0 -0
- package/icons/providers/doc2x.webp +0 -0
- package/icons/providers/docsearch.webp +0 -0
- package/icons/providers/dolphin.webp +0 -0
- package/icons/providers/dothoosh.webp +0 -0
- package/icons/providers/dotsstudio.webp +0 -0
- package/icons/providers/doubao.webp +0 -0
- package/icons/providers/dreammachine.webp +0 -0
- package/icons/providers/elevenlabs.webp +0 -0
- package/icons/providers/elevenx.webp +0 -0
- package/icons/providers/empiriolabs.webp +0 -0
- package/icons/providers/essentialai.webp +0 -0
- package/icons/providers/exa.webp +0 -0
- package/icons/providers/fal.webp +0 -0
- package/icons/providers/fastgpt.webp +0 -0
- package/icons/providers/featherless.webp +0 -0
- package/icons/providers/figma.webp +0 -0
- package/icons/providers/firecrawl.webp +0 -0
- package/icons/providers/fireworks.webp +0 -0
- package/icons/providers/fishaudio.webp +0 -0
- package/icons/providers/flexai.webp +0 -0
- package/icons/providers/flora.webp +0 -0
- package/icons/providers/flowith.webp +0 -0
- package/icons/providers/flux.webp +0 -0
- package/icons/providers/friendli.webp +0 -0
- package/icons/providers/gemini.webp +0 -0
- package/icons/providers/geminicli.webp +0 -0
- package/icons/providers/gemma.webp +0 -0
- package/icons/providers/gitee-ai.webp +0 -0
- package/icons/providers/giteeai.webp +0 -0
- package/icons/providers/github.webp +0 -0
- package/icons/providers/githubcopilot.webp +0 -0
- package/icons/providers/glama.webp +0 -0
- package/icons/providers/glif.webp +0 -0
- package/icons/providers/glmv.webp +0 -0
- package/icons/providers/gmi.svg +5 -0
- package/icons/providers/gmicloud.webp +0 -0
- package/icons/providers/google.webp +0 -0
- package/icons/providers/googlecloud.webp +0 -0
- package/icons/providers/goose.webp +0 -0
- package/icons/providers/gradio.webp +0 -0
- package/icons/providers/greenpt.webp +0 -0
- package/icons/providers/greptile.webp +0 -0
- package/icons/providers/grok.webp +0 -0
- package/icons/providers/grokbot.webp +0 -0
- package/icons/providers/groq.webp +0 -0
- package/icons/providers/hailuo.webp +0 -0
- package/icons/providers/haiper.webp +0 -0
- package/icons/providers/happyhorse.webp +0 -0
- package/icons/providers/hedra.webp +0 -0
- package/icons/providers/hermesagent.webp +0 -0
- package/icons/providers/higress.webp +0 -0
- package/icons/providers/huawei.webp +0 -0
- package/icons/providers/huaweicloud.webp +0 -0
- package/icons/providers/huggingface.webp +0 -0
- package/icons/providers/hunyuan.webp +0 -0
- package/icons/providers/hyperbolic.webp +0 -0
- package/icons/providers/ibm.webp +0 -0
- package/icons/providers/ideogram.webp +0 -0
- package/icons/providers/iflytekcloud.webp +0 -0
- package/icons/providers/inception.webp +0 -0
- package/icons/providers/inceptron.webp +0 -0
- package/icons/providers/inference.webp +0 -0
- package/icons/providers/infermatic.webp +0 -0
- package/icons/providers/infini.webp +0 -0
- package/icons/providers/infinigence.webp +0 -0
- package/icons/providers/inflection.webp +0 -0
- package/icons/providers/internlm.webp +0 -0
- package/icons/providers/ionet.webp +0 -0
- package/icons/providers/jimeng.webp +0 -0
- package/icons/providers/jina.webp +0 -0
- package/icons/providers/junie.webp +0 -0
- package/icons/providers/kagi.webp +0 -0
- package/icons/providers/kilocode.webp +0 -0
- package/icons/providers/kimi.webp +0 -0
- package/icons/providers/kiro.webp +0 -0
- package/icons/providers/kling.webp +0 -0
- package/icons/providers/kluster.webp +0 -0
- package/icons/providers/kolors.webp +0 -0
- package/icons/providers/krea.webp +0 -0
- package/icons/providers/kwaikat.webp +0 -0
- package/icons/providers/kwaipilot.webp +0 -0
- package/icons/providers/lambda.webp +0 -0
- package/icons/providers/langchain.webp +0 -0
- package/icons/providers/langfuse.webp +0 -0
- package/icons/providers/langgraph.webp +0 -0
- package/icons/providers/langsmith.webp +0 -0
- package/icons/providers/leptonai.webp +0 -0
- package/icons/providers/lg.webp +0 -0
- package/icons/providers/lightricks.webp +0 -0
- package/icons/providers/ling.webp +0 -0
- package/icons/providers/liquid.webp +0 -0
- package/icons/providers/livekit.webp +0 -0
- package/icons/providers/llamaindex.webp +0 -0
- package/icons/providers/llava.webp +0 -0
- package/icons/providers/llmapi.webp +0 -0
- package/icons/providers/llmgateway.webp +0 -0
- package/icons/providers/lmstudio.webp +0 -0
- package/icons/providers/lobehub.webp +0 -0
- package/icons/providers/lobot.webp +0 -0
- package/icons/providers/longcat.webp +0 -0
- package/icons/providers/lovable.webp +0 -0
- package/icons/providers/lovart.webp +0 -0
- package/icons/providers/luma.webp +0 -0
- package/icons/providers/magic.webp +0 -0
- package/icons/providers/magpie.webp +0 -0
- package/icons/providers/make.webp +0 -0
- package/icons/providers/manus.webp +0 -0
- package/icons/providers/mastra.webp +0 -0
- package/icons/providers/mcp.webp +0 -0
- package/icons/providers/mcpso.webp +0 -0
- package/icons/providers/menlo.webp +0 -0
- package/icons/providers/meshy.webp +0 -0
- package/icons/providers/meta.webp +0 -0
- package/icons/providers/metaai.webp +0 -0
- package/icons/providers/metagpt.webp +0 -0
- package/icons/providers/microsoft.webp +0 -0
- package/icons/providers/midjourney.webp +0 -0
- package/icons/providers/minimax.webp +0 -0
- package/icons/providers/mistral.webp +0 -0
- package/icons/providers/modelscope.webp +0 -0
- package/icons/providers/monica.webp +0 -0
- package/icons/providers/moonshot.webp +0 -0
- package/icons/providers/morph.webp +0 -0
- package/icons/providers/moxt.webp +0 -0
- package/icons/providers/muse.webp +0 -0
- package/icons/providers/myshell.webp +0 -0
- package/icons/providers/n8n.webp +0 -0
- package/icons/providers/nanobanana.webp +0 -0
- package/icons/providers/nebius.webp +0 -0
- package/icons/providers/newapi.webp +0 -0
- package/icons/providers/nextbit.webp +0 -0
- package/icons/providers/notebooklm.webp +0 -0
- package/icons/providers/notion.webp +0 -0
- package/icons/providers/nousresearch.webp +0 -0
- package/icons/providers/nova.webp +0 -0
- package/icons/providers/novelai.webp +0 -0
- package/icons/providers/novita.webp +0 -0
- package/icons/providers/nplcloud.webp +0 -0
- package/icons/providers/nvidia.webp +0 -0
- package/icons/providers/o3.webp +0 -0
- package/icons/providers/obsidian.webp +0 -0
- package/icons/providers/ollama.webp +0 -0
- package/icons/providers/omlx.webp +0 -0
- package/icons/providers/openai.webp +0 -0
- package/icons/providers/openchat.webp +0 -0
- package/icons/providers/openclaw.webp +0 -0
- package/icons/providers/opencode.webp +0 -0
- package/icons/providers/openhands.webp +0 -0
- package/icons/providers/openhuman.webp +0 -0
- package/icons/providers/openrouter.webp +0 -0
- package/icons/providers/openwebui.webp +0 -0
- package/icons/providers/paddleocr.webp +0 -0
- package/icons/providers/palm.webp +0 -0
- package/icons/providers/parasail.webp +0 -0
- package/icons/providers/perceptron.webp +0 -0
- package/icons/providers/perplexity.webp +0 -0
- package/icons/providers/phala.webp +0 -0
- package/icons/providers/phidata.webp +0 -0
- package/icons/providers/phind.webp +0 -0
- package/icons/providers/pi.webp +0 -0
- package/icons/providers/pika.webp +0 -0
- package/icons/providers/pixverse.webp +0 -0
- package/icons/providers/player2.webp +0 -0
- package/icons/providers/poe.webp +0 -0
- package/icons/providers/pollinations.webp +0 -0
- package/icons/providers/poolside.webp +0 -0
- package/icons/providers/ppio.webp +0 -0
- package/icons/providers/prunaai.webp +0 -0
- package/icons/providers/pydanticai.webp +0 -0
- package/icons/providers/qingyan.webp +0 -0
- package/icons/providers/qiniu.webp +0 -0
- package/icons/providers/qoder.webp +0 -0
- package/icons/providers/qwen.webp +0 -0
- package/icons/providers/railway.webp +0 -0
- package/icons/providers/recraft.webp +0 -0
- package/icons/providers/reflection.webp +0 -0
- package/icons/providers/reka.webp +0 -0
- package/icons/providers/relace.webp +0 -0
- package/icons/providers/replicate.webp +0 -0
- package/icons/providers/replit.webp +0 -0
- package/icons/providers/reve.webp +0 -0
- package/icons/providers/roocode.webp +0 -0
- package/icons/providers/rsshub.webp +0 -0
- package/icons/providers/runway.webp +0 -0
- package/icons/providers/rwkv.webp +0 -0
- package/icons/providers/sakana.webp +0 -0
- package/icons/providers/sambanova.webp +0 -0
- package/icons/providers/search1api.webp +0 -0
- package/icons/providers/searchapi.webp +0 -0
- package/icons/providers/searxng.webp +0 -0
- package/icons/providers/sensenova.webp +0 -0
- package/icons/providers/silicon.webp +0 -0
- package/icons/providers/siliconcloud.webp +0 -0
- package/icons/providers/sillytavern.webp +0 -0
- package/icons/providers/skywork.webp +0 -0
- package/icons/providers/slock.webp +0 -0
- package/icons/providers/smithery.webp +0 -0
- package/icons/providers/snowflake.webp +0 -0
- package/icons/providers/sophnet.webp +0 -0
- package/icons/providers/sora.webp +0 -0
- package/icons/providers/spark.webp +0 -0
- package/icons/providers/speedai.webp +0 -0
- package/icons/providers/stability.webp +0 -0
- package/icons/providers/statecloud.webp +0 -0
- package/icons/providers/step.webp +0 -0
- package/icons/providers/stepfun.webp +0 -0
- package/icons/providers/straico.webp +0 -0
- package/icons/providers/streamlake.webp +0 -0
- package/icons/providers/sub2api.webp +0 -0
- package/icons/providers/submodel.webp +0 -0
- package/icons/providers/suno.webp +0 -0
- package/icons/providers/sync.webp +0 -0
- package/icons/providers/tabbit.webp +0 -0
- package/icons/providers/targon.webp +0 -0
- package/icons/providers/tavily.webp +0 -0
- package/icons/providers/tencent-cloud-ti.webp +0 -0
- package/icons/providers/tencent.webp +0 -0
- package/icons/providers/tencentcloud.webp +0 -0
- package/icons/providers/tiangong.webp +0 -0
- package/icons/providers/tii.webp +0 -0
- package/icons/providers/together.webp +0 -0
- package/icons/providers/topazlabs.webp +0 -0
- package/icons/providers/trae.webp +0 -0
- package/icons/providers/tripo.webp +0 -0
- package/icons/providers/turix.webp +0 -0
- package/icons/providers/typesafeai.webp +0 -0
- package/icons/providers/udio.webp +0 -0
- package/icons/providers/unionalpha.webp +0 -0
- package/icons/providers/unsloth.webp +0 -0
- package/icons/providers/unstructured.webp +0 -0
- package/icons/providers/upstage.webp +0 -0
- package/icons/providers/v0.webp +0 -0
- package/icons/providers/vectorizerai.webp +0 -0
- package/icons/providers/venice.webp +0 -0
- package/icons/providers/vercel.webp +0 -0
- package/icons/providers/vertexai.webp +0 -0
- package/icons/providers/vidu.webp +0 -0
- package/icons/providers/viggle.webp +0 -0
- package/icons/providers/vllm.webp +0 -0
- package/icons/providers/volcengine.webp +0 -0
- package/icons/providers/voyage.webp +0 -0
- package/icons/providers/voyageai.webp +0 -0
- package/icons/providers/wafer.webp +0 -0
- package/icons/providers/wandb.webp +0 -0
- package/icons/providers/wavespeed.webp +0 -0
- package/icons/providers/wenxin.webp +0 -0
- package/icons/providers/windsurf.webp +0 -0
- package/icons/providers/workbuddy.webp +0 -0
- package/icons/providers/workersai.webp +0 -0
- package/icons/providers/worldrouter.webp +0 -0
- package/icons/providers/xai.webp +0 -0
- package/icons/providers/xiaomimimo.webp +0 -0
- package/icons/providers/xinference.webp +0 -0
- package/icons/providers/xpay.webp +0 -0
- package/icons/providers/xuanyuan.webp +0 -0
- package/icons/providers/yandex.webp +0 -0
- package/icons/providers/yi.webp +0 -0
- package/icons/providers/youmind.webp +0 -0
- package/icons/providers/yuanbao.webp +0 -0
- package/icons/providers/zai.webp +0 -0
- package/icons/providers/zapier.webp +0 -0
- package/icons/providers/zeabur.webp +0 -0
- package/icons/providers/zencoder.webp +0 -0
- package/icons/providers/zenmux.webp +0 -0
- package/icons/providers/zero-one.webp +0 -0
- package/icons/providers/zeroone.webp +0 -0
- package/icons/providers/zhipu.webp +0 -0
- package/licenses/beautiful-ui-MIT.txt +21 -0
- package/package.json +53 -10
- package/scripts/yunui-audit.mjs +664 -0
- package/scripts/yunui-cli.mjs +868 -0
- package/scripts/yunui-init.mjs +138 -0
- package/styles/content.css +37 -3
- package/styles/tokens.css +41 -0
- package/styles/yunui.css +1586 -141
- package/dist/chunk-BCOKFWXC.js.map +0 -1
- package/dist/chunk-DDUP7GAX.js +0 -86
- package/dist/chunk-DDUP7GAX.js.map +0 -1
- package/dist/chunk-F2HG4TOQ.js.map +0 -1
- package/dist/chunk-HH3JBHRP.js +0 -1211
- package/dist/chunk-HH3JBHRP.js.map +0 -1
- package/dist/chunk-N4QO7RN5.js +0 -98
- package/dist/chunk-N4QO7RN5.js.map +0 -1
- package/dist/chunk-QEIBYOG2.js +0 -188
- package/dist/chunk-QEIBYOG2.js.map +0 -1
- package/dist/footer-BoFu7Wqq.d.ts +0 -46
- package/icons/apps/ling.png +0 -0
- package/icons/models/ling.png +0 -0
- package/icons/providers/Kwaipilot.png +0 -0
|
@@ -0,0 +1,2715 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Sparkline, monotonePath } from './chunk-AVXIR7ZQ.js';
|
|
3
|
+
import { Spinner, ScrollFade } from './chunk-I2DAKAD5.js';
|
|
4
|
+
import { useDismissOnOutside, FloatingPanel, usePresence } from './chunk-Z6WXDNBJ.js';
|
|
5
|
+
import { cn } from './chunk-VSS7ASN2.js';
|
|
6
|
+
import { useYunUI } from './chunk-GWD5W5F5.js';
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import { forwardRef, useState, useEffect, useRef, useMemo, useId, useLayoutEffect, useCallback } from 'react';
|
|
9
|
+
import { ChevronDown, Search, Loader2, X, ArrowRight, AlertTriangle, Info, AlertCircle, CheckCircle2 } from 'lucide-react';
|
|
10
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
11
|
+
import * as Primitive from '@radix-ui/react-collapsible';
|
|
12
|
+
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
13
|
+
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
14
|
+
import { flushSync, createPortal } from 'react-dom';
|
|
15
|
+
import { Toaster as Toaster$1, toast as toast$1 } from 'sonner';
|
|
16
|
+
|
|
17
|
+
function CustomSelect({
|
|
18
|
+
options,
|
|
19
|
+
value,
|
|
20
|
+
onChange,
|
|
21
|
+
placeholder,
|
|
22
|
+
searchable = false,
|
|
23
|
+
className = "",
|
|
24
|
+
disabled = false,
|
|
25
|
+
onSearch,
|
|
26
|
+
searchDebounceMs = 250,
|
|
27
|
+
loading = false,
|
|
28
|
+
onLoadMore,
|
|
29
|
+
hasMore = false
|
|
30
|
+
}) {
|
|
31
|
+
const t = useYunUI().useT("common.select");
|
|
32
|
+
const resolvedPlaceholder = placeholder || t("placeholder");
|
|
33
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
34
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
35
|
+
const [highlighted, setHighlighted] = useState(-1);
|
|
36
|
+
const containerRef = useRef(null);
|
|
37
|
+
const inputRef = useRef(null);
|
|
38
|
+
const triggerRef = useRef(null);
|
|
39
|
+
const listRef = useRef(null);
|
|
40
|
+
const panelRef = useRef(null);
|
|
41
|
+
const insideRefs = useMemo(() => [panelRef], []);
|
|
42
|
+
const baseId = useId();
|
|
43
|
+
const listboxId = `${baseId}-listbox`;
|
|
44
|
+
const optionId = (i) => `${baseId}-opt-${i}`;
|
|
45
|
+
const remote = typeof onSearch === "function";
|
|
46
|
+
const showSearch = searchable || remote;
|
|
47
|
+
const selectedOption = options.find((o) => o.value === value);
|
|
48
|
+
const filteredOptions = !remote && searchQuery ? options.filter(
|
|
49
|
+
(o) => o.label.toLowerCase().includes(searchQuery.toLowerCase()) || o.value.toLowerCase().includes(searchQuery.toLowerCase())
|
|
50
|
+
) : options;
|
|
51
|
+
const onSearchRef = useRef(onSearch);
|
|
52
|
+
onSearchRef.current = onSearch;
|
|
53
|
+
const didDebounceMountRef = useRef(false);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!remote) return;
|
|
56
|
+
if (!didDebounceMountRef.current) {
|
|
57
|
+
didDebounceMountRef.current = true;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const id = setTimeout(() => onSearchRef.current?.(searchQuery), searchDebounceMs);
|
|
61
|
+
return () => clearTimeout(id);
|
|
62
|
+
}, [searchQuery, remote, searchDebounceMs]);
|
|
63
|
+
useDismissOnOutside(
|
|
64
|
+
isOpen,
|
|
65
|
+
() => {
|
|
66
|
+
setIsOpen(false);
|
|
67
|
+
setSearchQuery("");
|
|
68
|
+
},
|
|
69
|
+
containerRef,
|
|
70
|
+
{ escape: false, extraRefs: insideRefs }
|
|
71
|
+
);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!isOpen) return;
|
|
74
|
+
if (showSearch && inputRef.current) inputRef.current.focus();
|
|
75
|
+
else triggerRef.current?.focus();
|
|
76
|
+
}, [isOpen, showSearch]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (isOpen) {
|
|
79
|
+
const sel = filteredOptions.findIndex((o) => o.value === value);
|
|
80
|
+
setHighlighted(sel >= 0 ? sel : 0);
|
|
81
|
+
} else {
|
|
82
|
+
setHighlighted(-1);
|
|
83
|
+
}
|
|
84
|
+
}, [isOpen]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (highlighted >= filteredOptions.length) setHighlighted(filteredOptions.length - 1);
|
|
87
|
+
}, [filteredOptions.length, highlighted]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (!isOpen || highlighted < 0 || !listRef.current) return;
|
|
90
|
+
listRef.current.querySelector(`#${CSS.escape(optionId(highlighted))}`)?.scrollIntoView({ block: "nearest" });
|
|
91
|
+
}, [highlighted, isOpen]);
|
|
92
|
+
const open = () => !disabled && setIsOpen(true);
|
|
93
|
+
const close = () => {
|
|
94
|
+
setIsOpen(false);
|
|
95
|
+
setSearchQuery("");
|
|
96
|
+
triggerRef.current?.focus();
|
|
97
|
+
};
|
|
98
|
+
const handleSelect = (optionValue) => {
|
|
99
|
+
onChange(optionValue);
|
|
100
|
+
setIsOpen(false);
|
|
101
|
+
setSearchQuery("");
|
|
102
|
+
triggerRef.current?.focus();
|
|
103
|
+
};
|
|
104
|
+
const handleListScroll = () => {
|
|
105
|
+
if (!onLoadMore || !hasMore || loading) return;
|
|
106
|
+
const el = listRef.current;
|
|
107
|
+
if (el && el.scrollHeight - el.scrollTop - el.clientHeight < 48) onLoadMore();
|
|
108
|
+
};
|
|
109
|
+
const handleKeyDown = (e) => {
|
|
110
|
+
if (disabled) return;
|
|
111
|
+
switch (e.key) {
|
|
112
|
+
case "ArrowDown":
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
if (!isOpen) return open();
|
|
115
|
+
setHighlighted((h) => Math.min(h + 1, filteredOptions.length - 1));
|
|
116
|
+
break;
|
|
117
|
+
case "ArrowUp":
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
if (!isOpen) return open();
|
|
120
|
+
setHighlighted((h) => Math.max(h - 1, 0));
|
|
121
|
+
break;
|
|
122
|
+
case "Home":
|
|
123
|
+
if (isOpen) {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
setHighlighted(0);
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case "End":
|
|
129
|
+
if (isOpen) {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
setHighlighted(filteredOptions.length - 1);
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
case "Enter":
|
|
135
|
+
if (isOpen && filteredOptions[highlighted]) {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
handleSelect(filteredOptions[highlighted].value);
|
|
138
|
+
} else if (!isOpen) {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
open();
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case " ":
|
|
144
|
+
if (!isOpen && !showSearch) {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
open();
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
case "Escape":
|
|
150
|
+
if (isOpen) {
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
close();
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
case "Tab":
|
|
156
|
+
if (isOpen) setIsOpen(false);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: `relative ${className}`, onKeyDown: handleKeyDown, children: [
|
|
161
|
+
/* @__PURE__ */ jsxs(
|
|
162
|
+
"button",
|
|
163
|
+
{
|
|
164
|
+
ref: triggerRef,
|
|
165
|
+
type: "button",
|
|
166
|
+
onClick: () => !disabled && setIsOpen(!isOpen),
|
|
167
|
+
disabled,
|
|
168
|
+
"aria-haspopup": "listbox",
|
|
169
|
+
"aria-expanded": isOpen,
|
|
170
|
+
"aria-controls": isOpen ? listboxId : void 0,
|
|
171
|
+
"aria-activedescendant": isOpen && !searchable && highlighted >= 0 ? optionId(highlighted) : void 0,
|
|
172
|
+
className: `
|
|
173
|
+
w-full flex items-center justify-between gap-2 px-3 py-2
|
|
174
|
+
rounded-xl border border-(--border-default) bg-(--bg-elevated)
|
|
175
|
+
hover:border-(--border-strong) hover:bg-(--bg-hover)
|
|
176
|
+
transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-(--dur-fast) ease-(--ease-standard) text-sm
|
|
177
|
+
${disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}
|
|
178
|
+
${isOpen ? "border-primary ring-2 ring-primary/20" : ""}
|
|
179
|
+
`,
|
|
180
|
+
children: [
|
|
181
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-1 min-w-0", children: [
|
|
182
|
+
selectedOption?.icon && /* @__PURE__ */ jsx("span", { className: "shrink-0", children: selectedOption.icon }),
|
|
183
|
+
/* @__PURE__ */ jsx("span", { className: `truncate ${!selectedOption ? "text-muted-foreground" : ""}`, children: selectedOption ? selectedOption.label : resolvedPlaceholder })
|
|
184
|
+
] }),
|
|
185
|
+
/* @__PURE__ */ jsx(
|
|
186
|
+
ChevronDown,
|
|
187
|
+
{
|
|
188
|
+
size: 16,
|
|
189
|
+
className: `shrink-0 text-muted-foreground transition-transform ${isOpen ? "rotate-180" : ""}`
|
|
190
|
+
}
|
|
191
|
+
)
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
isOpen && /* @__PURE__ */ jsxs(
|
|
196
|
+
FloatingPanel,
|
|
197
|
+
{
|
|
198
|
+
ref: panelRef,
|
|
199
|
+
anchorRef: containerRef,
|
|
200
|
+
matchWidth: true,
|
|
201
|
+
tabExits: true,
|
|
202
|
+
className: `
|
|
203
|
+
z-50
|
|
204
|
+
rounded-2xl border border-border
|
|
205
|
+
bg-popover text-popover-foreground
|
|
206
|
+
shadow-lg shadow-black/5
|
|
207
|
+
max-h-64 overflow-hidden flex flex-col
|
|
208
|
+
motion-pop
|
|
209
|
+
`,
|
|
210
|
+
children: [
|
|
211
|
+
showSearch && /* @__PURE__ */ jsx("div", { className: "px-2.5 pb-2 pt-1.5 border-b border-(--border-subtle)", children: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
212
|
+
/* @__PURE__ */ jsx(Search, { size: 14, className: "absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" }),
|
|
213
|
+
/* @__PURE__ */ jsx(
|
|
214
|
+
"input",
|
|
215
|
+
{
|
|
216
|
+
ref: inputRef,
|
|
217
|
+
type: "text",
|
|
218
|
+
role: "combobox",
|
|
219
|
+
"aria-expanded": isOpen,
|
|
220
|
+
"aria-controls": listboxId,
|
|
221
|
+
"aria-activedescendant": highlighted >= 0 ? optionId(highlighted) : void 0,
|
|
222
|
+
"aria-autocomplete": "list",
|
|
223
|
+
value: searchQuery,
|
|
224
|
+
onChange: (e) => setSearchQuery(e.target.value),
|
|
225
|
+
placeholder: t("search"),
|
|
226
|
+
"aria-label": t("search"),
|
|
227
|
+
className: "w-full pl-9 pr-8 py-1.5 text-base md:text-sm rounded-lg\n bg-(--bg-muted) border border-transparent\n focus:border-primary focus:outline-none focus:bg-(--bg-elevated) transition-colors"
|
|
228
|
+
}
|
|
229
|
+
),
|
|
230
|
+
loading ? /* @__PURE__ */ jsx(
|
|
231
|
+
Loader2,
|
|
232
|
+
{
|
|
233
|
+
size: 14,
|
|
234
|
+
"aria-hidden": true,
|
|
235
|
+
className: "absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground animate-spin"
|
|
236
|
+
}
|
|
237
|
+
) : searchQuery && /* @__PURE__ */ jsx(
|
|
238
|
+
"button",
|
|
239
|
+
{
|
|
240
|
+
type: "button",
|
|
241
|
+
onClick: () => setSearchQuery(""),
|
|
242
|
+
"aria-label": t("clearSearch"),
|
|
243
|
+
className: "absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors p-0.5 rounded-md hover:bg-(--bg-hover)",
|
|
244
|
+
title: t("clearSearch"),
|
|
245
|
+
children: /* @__PURE__ */ jsx(X, { size: 12 })
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
] }) }),
|
|
249
|
+
/* @__PURE__ */ jsxs(
|
|
250
|
+
"div",
|
|
251
|
+
{
|
|
252
|
+
ref: listRef,
|
|
253
|
+
role: "listbox",
|
|
254
|
+
id: listboxId,
|
|
255
|
+
onScroll: handleListScroll,
|
|
256
|
+
className: "flex-1 min-h-0 max-h-52 overflow-y-auto overscroll-contain p-1",
|
|
257
|
+
children: [
|
|
258
|
+
filteredOptions.length === 0 ? loading ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center px-3 py-3 text-muted-foreground", children: /* @__PURE__ */ jsx(Loader2, { size: 16, "aria-hidden": true, className: "animate-spin" }) }) : /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-sm text-muted-foreground text-center whitespace-nowrap", children: t("noOptions") }) : filteredOptions.map((option, i) => {
|
|
259
|
+
const isSelected = option.value === value;
|
|
260
|
+
const isHigh = i === highlighted;
|
|
261
|
+
return /* @__PURE__ */ jsxs(
|
|
262
|
+
"button",
|
|
263
|
+
{
|
|
264
|
+
id: optionId(i),
|
|
265
|
+
type: "button",
|
|
266
|
+
role: "option",
|
|
267
|
+
"aria-selected": isSelected,
|
|
268
|
+
"data-highlighted": isHigh ? "" : void 0,
|
|
269
|
+
onClick: () => handleSelect(option.value),
|
|
270
|
+
onMouseEnter: () => setHighlighted(i),
|
|
271
|
+
className: `dropdown-item w-full text-left outline-none ${isSelected ? "active" : ""}`,
|
|
272
|
+
children: [
|
|
273
|
+
option.icon && /* @__PURE__ */ jsx("span", { className: "shrink-0 w-5 h-5 flex items-center justify-center", children: option.icon }),
|
|
274
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
275
|
+
/* @__PURE__ */ jsx("div", { className: "truncate", children: option.label }),
|
|
276
|
+
option.description && /* @__PURE__ */ jsx("div", { className: "text-xs font-normal text-muted-foreground truncate", children: option.description })
|
|
277
|
+
] })
|
|
278
|
+
]
|
|
279
|
+
},
|
|
280
|
+
option.value
|
|
281
|
+
);
|
|
282
|
+
}),
|
|
283
|
+
loading && filteredOptions.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-2 text-muted-foreground", children: /* @__PURE__ */ jsx(Loader2, { size: 16, "aria-hidden": true, className: "animate-spin" }) })
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
)
|
|
287
|
+
]
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
] });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/lib/balanced-breaks.ts
|
|
294
|
+
function balancedBreaks(widths, maxWidth, spacing, balanced) {
|
|
295
|
+
const pack = (perLine) => {
|
|
296
|
+
const lines = [];
|
|
297
|
+
let current = [];
|
|
298
|
+
let width = 0;
|
|
299
|
+
for (let index = 0; index < widths.length; index += 1) {
|
|
300
|
+
const advance = current.length === 0 ? widths[index] : widths[index] + spacing;
|
|
301
|
+
const full = perLine !== null && current.length >= perLine;
|
|
302
|
+
if (current.length > 0 && (full || width + advance > maxWidth)) {
|
|
303
|
+
lines.push(current);
|
|
304
|
+
current = [index];
|
|
305
|
+
width = widths[index];
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
current.push(index);
|
|
309
|
+
width += advance;
|
|
310
|
+
}
|
|
311
|
+
if (current.length > 0) lines.push(current);
|
|
312
|
+
return lines;
|
|
313
|
+
};
|
|
314
|
+
const greedy = pack(null);
|
|
315
|
+
if (!balanced || greedy.length <= 1) return greedy;
|
|
316
|
+
const even = pack(Math.ceil(widths.length / greedy.length));
|
|
317
|
+
return even.length <= greedy.length ? even : greedy;
|
|
318
|
+
}
|
|
319
|
+
var GAP = 4;
|
|
320
|
+
function SegmentedSelect({
|
|
321
|
+
options,
|
|
322
|
+
value,
|
|
323
|
+
onChange,
|
|
324
|
+
className,
|
|
325
|
+
disabled = false,
|
|
326
|
+
wrap = false,
|
|
327
|
+
fill = false
|
|
328
|
+
}) {
|
|
329
|
+
const balance = wrap || fill;
|
|
330
|
+
const containerRef = useRef(null);
|
|
331
|
+
const measureRef = useRef(null);
|
|
332
|
+
const [lines, setLines] = useState(null);
|
|
333
|
+
const signature = options.map((opt) => `${String(opt.value)}\0${opt.label}`).join("");
|
|
334
|
+
useLayoutEffect(() => {
|
|
335
|
+
if (!balance) return;
|
|
336
|
+
const container = containerRef.current;
|
|
337
|
+
const measure = measureRef.current;
|
|
338
|
+
if (!container || !measure) return;
|
|
339
|
+
const compute = () => {
|
|
340
|
+
const available = container.getBoundingClientRect().width;
|
|
341
|
+
const widths = Array.from(measure.children, (child) => child.getBoundingClientRect().width);
|
|
342
|
+
if (!(available > 0) || widths.some((w) => !(w > 0))) {
|
|
343
|
+
setLines(null);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const next = balancedBreaks(widths, available, GAP, true);
|
|
347
|
+
setLines((prev) => prev && JSON.stringify(prev) === JSON.stringify(next) ? prev : next);
|
|
348
|
+
};
|
|
349
|
+
compute();
|
|
350
|
+
if (typeof ResizeObserver === "undefined") {
|
|
351
|
+
window.addEventListener("resize", compute);
|
|
352
|
+
return () => window.removeEventListener("resize", compute);
|
|
353
|
+
}
|
|
354
|
+
const observer = new ResizeObserver(compute);
|
|
355
|
+
observer.observe(container);
|
|
356
|
+
return () => observer.disconnect();
|
|
357
|
+
}, [balance, signature]);
|
|
358
|
+
const renderOption = (opt, shared) => {
|
|
359
|
+
const Icon = opt.icon;
|
|
360
|
+
return /* @__PURE__ */ jsxs(
|
|
361
|
+
"button",
|
|
362
|
+
{
|
|
363
|
+
type: "button",
|
|
364
|
+
onClick: () => !disabled && onChange(opt.value),
|
|
365
|
+
disabled,
|
|
366
|
+
"aria-pressed": value === opt.value,
|
|
367
|
+
title: opt.desc,
|
|
368
|
+
className: cn(
|
|
369
|
+
"inline-flex items-center justify-center gap-2 px-3 py-1.5 text-xs font-medium border border-border rounded-lg whitespace-nowrap transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-(--dur-fast) ease-(--ease-standard) ease cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
370
|
+
value === opt.value ? (
|
|
371
|
+
// Same language as .btn-primary: a full-strength foreground outline. The
|
|
372
|
+
// previous accent-subtle fill matched the unselected muted fill in every
|
|
373
|
+
// theme (identical in light), so the current choice was invisible.
|
|
374
|
+
"text-foreground border-foreground bg-foreground/[0.06] shadow-xs hover:bg-foreground/10"
|
|
375
|
+
) : "text-muted-foreground border-(--border-default) bg-muted/50 hover:text-foreground hover:border-(--border-strong) hover:bg-muted",
|
|
376
|
+
disabled && "opacity-50 cursor-not-allowed pointer-events-none",
|
|
377
|
+
shared && "min-w-0"
|
|
378
|
+
),
|
|
379
|
+
children: [
|
|
380
|
+
Icon && /* @__PURE__ */ jsx(Icon, { size: 14 }),
|
|
381
|
+
opt.label
|
|
382
|
+
]
|
|
383
|
+
},
|
|
384
|
+
String(opt.value)
|
|
385
|
+
);
|
|
386
|
+
};
|
|
387
|
+
if (!balance) {
|
|
388
|
+
return /* @__PURE__ */ jsx("div", { className: cn("flex gap-1 flex-wrap", className), children: options.map((opt) => renderOption(opt)) });
|
|
389
|
+
}
|
|
390
|
+
const ghost = /* @__PURE__ */ jsx(
|
|
391
|
+
"div",
|
|
392
|
+
{
|
|
393
|
+
ref: measureRef,
|
|
394
|
+
"aria-hidden": "true",
|
|
395
|
+
"data-yunui": "segmented-measure",
|
|
396
|
+
className: "pointer-events-none invisible absolute left-0 top-0 flex h-0 overflow-hidden",
|
|
397
|
+
children: options.map((opt) => {
|
|
398
|
+
const Icon = opt.icon;
|
|
399
|
+
return /* @__PURE__ */ jsxs(
|
|
400
|
+
"span",
|
|
401
|
+
{
|
|
402
|
+
className: "inline-flex shrink-0 items-center justify-center gap-2 border px-3 py-1.5 text-xs font-medium whitespace-nowrap",
|
|
403
|
+
children: [
|
|
404
|
+
Icon && /* @__PURE__ */ jsx(Icon, { size: 14 }),
|
|
405
|
+
opt.label
|
|
406
|
+
]
|
|
407
|
+
},
|
|
408
|
+
String(opt.value)
|
|
409
|
+
);
|
|
410
|
+
})
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
return /* @__PURE__ */ jsxs(
|
|
414
|
+
"div",
|
|
415
|
+
{
|
|
416
|
+
ref: containerRef,
|
|
417
|
+
"data-yunui": "segmented-select",
|
|
418
|
+
"data-layout": fill ? "fill" : "wrap",
|
|
419
|
+
className: cn("relative flex flex-col gap-1.5", className),
|
|
420
|
+
children: [
|
|
421
|
+
ghost,
|
|
422
|
+
(lines ?? [options.map((_, i) => i)]).map((line) => /* @__PURE__ */ jsx(
|
|
423
|
+
"div",
|
|
424
|
+
{
|
|
425
|
+
"data-line": "",
|
|
426
|
+
className: cn(lines === null ? "flex flex-wrap gap-1" : fill ? "grid gap-1" : "flex gap-1"),
|
|
427
|
+
style: lines !== null && fill ? { gridTemplateColumns: `repeat(${line.length}, minmax(0, 1fr))` } : void 0,
|
|
428
|
+
children: line.map((i) => renderOption(options[i], fill))
|
|
429
|
+
},
|
|
430
|
+
line.join("-")
|
|
431
|
+
))
|
|
432
|
+
]
|
|
433
|
+
}
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
function useSlidingPill(selector, deps) {
|
|
437
|
+
const containerRef = useRef(null);
|
|
438
|
+
const pillRef = useRef(null);
|
|
439
|
+
const placed = useRef(false);
|
|
440
|
+
useLayoutEffect(() => {
|
|
441
|
+
const container = containerRef.current;
|
|
442
|
+
const pill = pillRef.current;
|
|
443
|
+
if (!container || !pill) return;
|
|
444
|
+
const place = (animate) => {
|
|
445
|
+
const el = container.querySelector(selector);
|
|
446
|
+
if (!el) {
|
|
447
|
+
pill.style.setProperty("--pill-o", "0");
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (!animate || !placed.current) pill.dataset.ready = "false";
|
|
451
|
+
pill.style.setProperty("--pill-x", `${el.offsetLeft}px`);
|
|
452
|
+
pill.style.setProperty("--pill-y", `${el.offsetTop}px`);
|
|
453
|
+
pill.style.setProperty("--pill-w", `${el.offsetWidth}px`);
|
|
454
|
+
pill.style.setProperty("--pill-h", `${el.offsetHeight}px`);
|
|
455
|
+
pill.style.setProperty("--pill-o", "1");
|
|
456
|
+
if (pill.dataset.ready === "false") {
|
|
457
|
+
void pill.offsetWidth;
|
|
458
|
+
requestAnimationFrame(() => {
|
|
459
|
+
pill.dataset.ready = "true";
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
placed.current = true;
|
|
463
|
+
};
|
|
464
|
+
place(true);
|
|
465
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
466
|
+
const ro = new ResizeObserver(() => place(false));
|
|
467
|
+
ro.observe(container);
|
|
468
|
+
return () => ro.disconnect();
|
|
469
|
+
}, [selector, ...deps]);
|
|
470
|
+
return { containerRef, pillRef };
|
|
471
|
+
}
|
|
472
|
+
function NavTabs({ tabs, activeKey, onChange, className = "", ariaLabel }) {
|
|
473
|
+
const { Link } = useYunUI();
|
|
474
|
+
const { containerRef, pillRef } = useSlidingPill(".nav-tab.active", [activeKey, tabs.length]);
|
|
475
|
+
return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsxs("nav", { ref: containerRef, className: "yunui-nav-tabs-slide relative flex items-center gap-1 overflow-x-auto overflow-y-hidden overscroll-x-contain", "aria-label": ariaLabel, children: [
|
|
476
|
+
/* @__PURE__ */ jsx("span", { ref: pillRef, "aria-hidden": "true", className: "yunui-slider-pill is-nav-underline", "data-ready": "false" }),
|
|
477
|
+
tabs.map((tab) => {
|
|
478
|
+
const active = tab.key === activeKey;
|
|
479
|
+
const cls = `nav-tab ${active ? "active" : ""}`;
|
|
480
|
+
return tab.href ? /* @__PURE__ */ jsx(Link, { href: tab.href, className: cls, "aria-current": active ? "page" : void 0, children: tab.label }, tab.key) : /* @__PURE__ */ jsx(
|
|
481
|
+
"button",
|
|
482
|
+
{
|
|
483
|
+
type: "button",
|
|
484
|
+
onClick: () => onChange?.(tab.key),
|
|
485
|
+
className: cls,
|
|
486
|
+
"aria-current": active ? "true" : void 0,
|
|
487
|
+
children: tab.label
|
|
488
|
+
},
|
|
489
|
+
tab.key
|
|
490
|
+
);
|
|
491
|
+
})
|
|
492
|
+
] }) });
|
|
493
|
+
}
|
|
494
|
+
function NavItem({ label, icon, href, onClick, active = false, expanded, chevron, depth = 0, className }) {
|
|
495
|
+
const { Link } = useYunUI();
|
|
496
|
+
const cls = cn("nav-item w-full text-left", active && "active", className);
|
|
497
|
+
const style = depth > 0 ? { "--nav-depth": depth } : void 0;
|
|
498
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
499
|
+
/* @__PURE__ */ jsx("span", { className: "nav-state-indicator", "data-active": active ? "true" : "false", "aria-hidden": "true" }),
|
|
500
|
+
icon,
|
|
501
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: label }),
|
|
502
|
+
chevron && /* @__PURE__ */ jsx("span", { className: "ml-auto flex shrink-0 items-center", children: chevron })
|
|
503
|
+
] });
|
|
504
|
+
if (href) {
|
|
505
|
+
return /* @__PURE__ */ jsx(Link, { href, className: cls, style, "aria-current": active ? "page" : void 0, "aria-expanded": expanded, children: content });
|
|
506
|
+
}
|
|
507
|
+
return /* @__PURE__ */ jsx(
|
|
508
|
+
"button",
|
|
509
|
+
{
|
|
510
|
+
type: "button",
|
|
511
|
+
onClick,
|
|
512
|
+
className: cls,
|
|
513
|
+
style,
|
|
514
|
+
"aria-current": active ? "true" : void 0,
|
|
515
|
+
"aria-expanded": expanded,
|
|
516
|
+
children: content
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
var ListItem = React.forwardRef(
|
|
521
|
+
({ className, asChild, children, ...props }, ref) => {
|
|
522
|
+
const classes = cn("dropdown-item w-full justify-start text-left hover:bg-muted", className);
|
|
523
|
+
if (asChild && React.isValidElement(children)) {
|
|
524
|
+
return React.cloneElement(children, {
|
|
525
|
+
className: cn(classes, children.props.className)
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
return /* @__PURE__ */ jsx("button", { ref, type: "button", className: classes, ...props, children });
|
|
529
|
+
}
|
|
530
|
+
);
|
|
531
|
+
ListItem.displayName = "ListItem";
|
|
532
|
+
function EmptyValue({ label, why, className, ...rest }) {
|
|
533
|
+
const description = why ?? (typeof label === "string" ? label : void 0);
|
|
534
|
+
return /* @__PURE__ */ jsx(
|
|
535
|
+
"span",
|
|
536
|
+
{
|
|
537
|
+
"data-yunui": "empty-value",
|
|
538
|
+
title: description,
|
|
539
|
+
className: cn("text-sm font-normal text-muted-foreground", className),
|
|
540
|
+
...rest,
|
|
541
|
+
children: label
|
|
542
|
+
}
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
function ShinyButton({
|
|
546
|
+
children,
|
|
547
|
+
className,
|
|
548
|
+
href,
|
|
549
|
+
onClick
|
|
550
|
+
}) {
|
|
551
|
+
const { Link } = useYunUI();
|
|
552
|
+
const ButtonContent = /* @__PURE__ */ jsxs(
|
|
553
|
+
"div",
|
|
554
|
+
{
|
|
555
|
+
className: cn(
|
|
556
|
+
"group relative flex items-center justify-center gap-2 overflow-hidden rounded-xl bg-(--text-primary) px-8 py-3 font-semibold text-background transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-(--dur-fast) ease-(--ease-standard) hover:ring-2 hover:ring-(--accent) hover:ring-offset-2 hover:ring-offset-background",
|
|
557
|
+
className
|
|
558
|
+
),
|
|
559
|
+
children: [
|
|
560
|
+
/* @__PURE__ */ jsxs("span", { className: "relative z-10 flex items-center gap-2", children: [
|
|
561
|
+
children,
|
|
562
|
+
/* @__PURE__ */ jsx(ArrowRight, { className: "h-4 w-4 transition-transform group-hover:translate-x-1" })
|
|
563
|
+
] }),
|
|
564
|
+
/* @__PURE__ */ jsx("div", { className: "absolute inset-0 block animate-shimmer bg-linear-to-r from-transparent via-(--text-primary)/10 to-transparent bg-size-[200%_100%]" })
|
|
565
|
+
]
|
|
566
|
+
}
|
|
567
|
+
);
|
|
568
|
+
const focusCls = "rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-(--accent) focus-visible:ring-offset-2 focus-visible:ring-offset-background";
|
|
569
|
+
if (href) {
|
|
570
|
+
return /* @__PURE__ */ jsx(Link, { href, onClick, className: focusCls, children: ButtonContent });
|
|
571
|
+
}
|
|
572
|
+
return /* @__PURE__ */ jsx("button", { type: "button", onClick, className: focusCls, children: ButtonContent });
|
|
573
|
+
}
|
|
574
|
+
function Marquee({
|
|
575
|
+
className,
|
|
576
|
+
reverse,
|
|
577
|
+
pauseOnHover = false,
|
|
578
|
+
children,
|
|
579
|
+
vertical = false,
|
|
580
|
+
repeat = 4,
|
|
581
|
+
...props
|
|
582
|
+
}) {
|
|
583
|
+
return /* @__PURE__ */ jsx(
|
|
584
|
+
"div",
|
|
585
|
+
{
|
|
586
|
+
...props,
|
|
587
|
+
className: cn(
|
|
588
|
+
"group flex overflow-hidden p-2 [--duration:40s] [--gap:1rem] gap-(--gap)",
|
|
589
|
+
{
|
|
590
|
+
"flex-row": !vertical,
|
|
591
|
+
"flex-col": vertical
|
|
592
|
+
},
|
|
593
|
+
className
|
|
594
|
+
),
|
|
595
|
+
children: Array(repeat).fill(0).map((_, i) => /* @__PURE__ */ jsx(
|
|
596
|
+
"div",
|
|
597
|
+
{
|
|
598
|
+
className: cn("flex shrink-0 justify-around gap-(--gap)", {
|
|
599
|
+
"animate-marquee flex-row": !vertical,
|
|
600
|
+
"animate-marquee-vertical flex-col": vertical,
|
|
601
|
+
"group-hover:[animation-play-state:paused]": pauseOnHover,
|
|
602
|
+
"[animation-direction:reverse]": reverse
|
|
603
|
+
}),
|
|
604
|
+
children
|
|
605
|
+
},
|
|
606
|
+
i
|
|
607
|
+
))
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
var BentoGrid = ({
|
|
612
|
+
className,
|
|
613
|
+
children
|
|
614
|
+
}) => {
|
|
615
|
+
return /* @__PURE__ */ jsx(
|
|
616
|
+
"div",
|
|
617
|
+
{
|
|
618
|
+
className: cn(
|
|
619
|
+
"grid grid-cols-1 md:grid-cols-3 gap-6 max-w-7xl mx-auto",
|
|
620
|
+
className
|
|
621
|
+
),
|
|
622
|
+
children
|
|
623
|
+
}
|
|
624
|
+
);
|
|
625
|
+
};
|
|
626
|
+
var BentoCard = ({
|
|
627
|
+
className,
|
|
628
|
+
title,
|
|
629
|
+
description,
|
|
630
|
+
header,
|
|
631
|
+
icon
|
|
632
|
+
}) => {
|
|
633
|
+
return /* @__PURE__ */ jsxs(
|
|
634
|
+
"div",
|
|
635
|
+
{
|
|
636
|
+
className: cn(
|
|
637
|
+
"row-span-1 glass-card relative p-6 flex flex-col justify-between space-y-4 group/bento overflow-hidden",
|
|
638
|
+
// The house hover, matching `.card-interactive`: a single-pixel
|
|
639
|
+
// lift and one step up the shadow ramp. Content stays put —
|
|
640
|
+
// sliding or scaling it (the stock bento-grid trick this card
|
|
641
|
+
// used to carry) reads as jitter and matches nothing else here.
|
|
642
|
+
// The richer glow treatment belongs to `FeatureCard`, which is a
|
|
643
|
+
// faithful extraction of Yunxin's marketing tile; keeping it out
|
|
644
|
+
// of here stops the two from competing.
|
|
645
|
+
"transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-(--dur-fast) ease-(--ease-standard) hover:-translate-y-px hover:shadow-md",
|
|
646
|
+
className
|
|
647
|
+
),
|
|
648
|
+
children: [
|
|
649
|
+
/* @__PURE__ */ jsx(
|
|
650
|
+
"div",
|
|
651
|
+
{
|
|
652
|
+
"aria-hidden": true,
|
|
653
|
+
className: "pointer-events-none absolute inset-x-0 top-0 h-px bg-linear-to-r from-transparent via-foreground/15 to-transparent"
|
|
654
|
+
}
|
|
655
|
+
),
|
|
656
|
+
header,
|
|
657
|
+
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
658
|
+
/* @__PURE__ */ jsx("div", { className: "mb-2 text-[var(--text-primary)]", children: icon }),
|
|
659
|
+
/* @__PURE__ */ jsx("div", { className: "font-semibold text-[var(--text-primary)] text-lg mb-2 mt-2", children: title }),
|
|
660
|
+
/* @__PURE__ */ jsx("div", { className: "font-normal text-[var(--text-secondary)] text-sm leading-relaxed", children: description })
|
|
661
|
+
] })
|
|
662
|
+
]
|
|
663
|
+
}
|
|
664
|
+
);
|
|
665
|
+
};
|
|
666
|
+
var Collapsible = Primitive.Root;
|
|
667
|
+
var CollapsibleTrigger2 = Primitive.CollapsibleTrigger;
|
|
668
|
+
var CollapsibleContent2 = forwardRef(({ children, ...props }, ref) => {
|
|
669
|
+
const [mounted, setMounted] = useState(false);
|
|
670
|
+
useEffect(() => {
|
|
671
|
+
setMounted(true);
|
|
672
|
+
}, []);
|
|
673
|
+
return /* @__PURE__ */ jsx(
|
|
674
|
+
Primitive.CollapsibleContent,
|
|
675
|
+
{
|
|
676
|
+
ref,
|
|
677
|
+
...props,
|
|
678
|
+
className: cn(
|
|
679
|
+
"overflow-hidden",
|
|
680
|
+
mounted && "data-[state=closed]:animate-fd-collapsible-up data-[state=open]:animate-fd-collapsible-down",
|
|
681
|
+
props.className
|
|
682
|
+
),
|
|
683
|
+
children
|
|
684
|
+
}
|
|
685
|
+
);
|
|
686
|
+
});
|
|
687
|
+
CollapsibleContent2.displayName = Primitive.CollapsibleContent.displayName;
|
|
688
|
+
var Popover = PopoverPrimitive.Root;
|
|
689
|
+
var PopoverTrigger = PopoverPrimitive.Trigger;
|
|
690
|
+
var PopoverContent = React.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsx(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
691
|
+
PopoverPrimitive.Content,
|
|
692
|
+
{
|
|
693
|
+
ref,
|
|
694
|
+
align,
|
|
695
|
+
sideOffset,
|
|
696
|
+
side: "bottom",
|
|
697
|
+
className: cn(
|
|
698
|
+
"z-50 origin-(--radix-popover-content-transform-origin) overflow-y-auto max-h-(--radix-popover-content-available-height) min-w-[240px] max-w-[98vw] rounded-2xl border border-border bg-popover p-2 text-sm text-popover-foreground shadow-lg shadow-black/5 focus-visible:outline-none motion-pop",
|
|
699
|
+
className
|
|
700
|
+
),
|
|
701
|
+
...props
|
|
702
|
+
}
|
|
703
|
+
) }));
|
|
704
|
+
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
|
705
|
+
var PopoverClose2 = PopoverPrimitive.PopoverClose;
|
|
706
|
+
var PopoverAnchor = PopoverPrimitive.Anchor;
|
|
707
|
+
var ScrollArea = React.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
708
|
+
ScrollAreaPrimitive.Root,
|
|
709
|
+
{
|
|
710
|
+
ref,
|
|
711
|
+
className: cn("relative overflow-hidden", className),
|
|
712
|
+
...props,
|
|
713
|
+
children: [
|
|
714
|
+
/* @__PURE__ */ jsx(ScrollAreaPrimitive.Viewport, { className: "h-full w-full rounded-[inherit]", children }),
|
|
715
|
+
/* @__PURE__ */ jsx(ScrollBar, {}),
|
|
716
|
+
/* @__PURE__ */ jsx(ScrollAreaPrimitive.Corner, {})
|
|
717
|
+
]
|
|
718
|
+
}
|
|
719
|
+
));
|
|
720
|
+
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
|
|
721
|
+
var ScrollBar = React.forwardRef(({ className, orientation = "vertical", ...props }, ref) => /* @__PURE__ */ jsx(
|
|
722
|
+
ScrollAreaPrimitive.ScrollAreaScrollbar,
|
|
723
|
+
{
|
|
724
|
+
ref,
|
|
725
|
+
orientation,
|
|
726
|
+
className: cn(
|
|
727
|
+
"flex touch-none select-none transition-colors",
|
|
728
|
+
orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-[1px]",
|
|
729
|
+
orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-[1px]",
|
|
730
|
+
className
|
|
731
|
+
),
|
|
732
|
+
...props,
|
|
733
|
+
children: /* @__PURE__ */ jsx(ScrollAreaPrimitive.ScrollAreaThumb, { className: "relative flex-1 rounded-full bg-border" })
|
|
734
|
+
}
|
|
735
|
+
));
|
|
736
|
+
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
|
|
737
|
+
var sizeClasses = {
|
|
738
|
+
sm: {
|
|
739
|
+
track: "w-8 h-4",
|
|
740
|
+
thumb: "w-2.5 h-2.5",
|
|
741
|
+
thumbTranslate: "translate-x-3.5"
|
|
742
|
+
},
|
|
743
|
+
md: {
|
|
744
|
+
track: "w-11 h-6",
|
|
745
|
+
thumb: "w-4 h-4",
|
|
746
|
+
thumbTranslate: "translate-x-5"
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
var variantClasses = {
|
|
750
|
+
default: {
|
|
751
|
+
checkedTrack: "border-primary bg-primary/10",
|
|
752
|
+
uncheckedTrack: "border-(--border-strong) bg-muted",
|
|
753
|
+
checkedThumb: "bg-primary",
|
|
754
|
+
uncheckedThumb: "bg-(--border-strong)"
|
|
755
|
+
},
|
|
756
|
+
success: {
|
|
757
|
+
checkedTrack: "border-(--success) bg-success-soft",
|
|
758
|
+
uncheckedTrack: "border-(--border-strong) bg-muted",
|
|
759
|
+
checkedThumb: "bg-(--success)",
|
|
760
|
+
uncheckedThumb: "bg-(--border-strong)"
|
|
761
|
+
},
|
|
762
|
+
warning: {
|
|
763
|
+
checkedTrack: "border-(--warning) bg-warning-soft",
|
|
764
|
+
uncheckedTrack: "border-(--border-strong) bg-muted",
|
|
765
|
+
checkedThumb: "bg-(--warning)",
|
|
766
|
+
uncheckedThumb: "bg-(--border-strong)"
|
|
767
|
+
},
|
|
768
|
+
danger: {
|
|
769
|
+
checkedTrack: "border-(--error) bg-error-soft",
|
|
770
|
+
uncheckedTrack: "border-(--border-strong) bg-muted",
|
|
771
|
+
checkedThumb: "bg-(--error)",
|
|
772
|
+
uncheckedThumb: "bg-(--border-strong)"
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
var Switch = forwardRef(
|
|
776
|
+
({ checked, onCheckedChange, disabled = false, size = "sm", variant = "default", className = "", id, label, ...props }, ref) => {
|
|
777
|
+
const sizeClass = sizeClasses[size];
|
|
778
|
+
const variantClass = variantClasses[variant];
|
|
779
|
+
return /* @__PURE__ */ jsx(
|
|
780
|
+
"button",
|
|
781
|
+
{
|
|
782
|
+
...props,
|
|
783
|
+
ref,
|
|
784
|
+
type: "button",
|
|
785
|
+
role: "switch",
|
|
786
|
+
"aria-checked": checked,
|
|
787
|
+
...label ? { "aria-label": label } : {},
|
|
788
|
+
id,
|
|
789
|
+
onClick: () => !disabled && onCheckedChange(!checked),
|
|
790
|
+
disabled,
|
|
791
|
+
className: `
|
|
792
|
+
yunui-switch ${sizeClass.track} rounded-full border-2 flex items-center px-0.5
|
|
793
|
+
transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-(--dur-fast) ease-(--ease-standard)
|
|
794
|
+
outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background
|
|
795
|
+
${checked ? variantClass.checkedTrack : variantClass.uncheckedTrack}
|
|
796
|
+
${disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}
|
|
797
|
+
${className}
|
|
798
|
+
`,
|
|
799
|
+
children: /* @__PURE__ */ jsx(
|
|
800
|
+
"span",
|
|
801
|
+
{
|
|
802
|
+
className: `
|
|
803
|
+
yunui-switch-thumb ${sizeClass.thumb} rounded-full transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-(--dur-fast) ease-(--ease-standard)
|
|
804
|
+
${checked ? variantClass.checkedThumb + " " + sizeClass.thumbTranslate : variantClass.uncheckedThumb + " translate-x-0"}
|
|
805
|
+
shadow-sm
|
|
806
|
+
`
|
|
807
|
+
}
|
|
808
|
+
)
|
|
809
|
+
}
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
);
|
|
813
|
+
Switch.displayName = "Switch";
|
|
814
|
+
function shouldSpring(lastChangeAt, now, settleMs) {
|
|
815
|
+
return lastChangeAt === null || now - lastChangeAt >= settleMs;
|
|
816
|
+
}
|
|
817
|
+
function format(value, decimals, suffix) {
|
|
818
|
+
const numStr = decimals > 0 ? value.toFixed(decimals) : Math.round(value).toString();
|
|
819
|
+
return Number(numStr).toString() + suffix;
|
|
820
|
+
}
|
|
821
|
+
function AnimatedNumber({
|
|
822
|
+
value,
|
|
823
|
+
suffix = "",
|
|
824
|
+
decimals = 0,
|
|
825
|
+
immediate,
|
|
826
|
+
settleMs = 5e3
|
|
827
|
+
}) {
|
|
828
|
+
const [autoImmediate, setAutoImmediate] = useState(() => {
|
|
829
|
+
const env = globalThis.process;
|
|
830
|
+
return env?.env?.NODE_ENV === "test";
|
|
831
|
+
});
|
|
832
|
+
useEffect(() => {
|
|
833
|
+
if (typeof window === "undefined" || !window.matchMedia) return;
|
|
834
|
+
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
835
|
+
const sync = () => setAutoImmediate((was) => was || mq.matches);
|
|
836
|
+
sync();
|
|
837
|
+
mq.addEventListener("change", sync);
|
|
838
|
+
return () => mq.removeEventListener("change", sync);
|
|
839
|
+
}, []);
|
|
840
|
+
const skip = immediate ?? autoImmediate;
|
|
841
|
+
const [shownValue, setShownValue] = useState(() => skip ? value : 0);
|
|
842
|
+
const lastChangeAt = useRef(null);
|
|
843
|
+
const current = useRef(skip ? value : 0);
|
|
844
|
+
useEffect(() => {
|
|
845
|
+
const now = Date.now();
|
|
846
|
+
const animate = !skip && shouldSpring(lastChangeAt.current, now, settleMs);
|
|
847
|
+
lastChangeAt.current = now;
|
|
848
|
+
if (!animate) {
|
|
849
|
+
current.current = value;
|
|
850
|
+
setShownValue(value);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const from = current.current;
|
|
854
|
+
const start = performance.now();
|
|
855
|
+
const duration = 900;
|
|
856
|
+
let raf = 0;
|
|
857
|
+
const tick = (t) => {
|
|
858
|
+
const k = Math.min(1, (t - start) / duration);
|
|
859
|
+
const eased = 1 - Math.pow(1 - k, 3);
|
|
860
|
+
current.current = from + (value - from) * eased;
|
|
861
|
+
setShownValue(current.current);
|
|
862
|
+
if (k < 1) raf = requestAnimationFrame(tick);
|
|
863
|
+
};
|
|
864
|
+
raf = requestAnimationFrame(tick);
|
|
865
|
+
return () => cancelAnimationFrame(raf);
|
|
866
|
+
}, [value, skip, settleMs]);
|
|
867
|
+
return /* @__PURE__ */ jsx("span", { className: "yunui-num", children: skip ? format(value, decimals, suffix) : format(shownValue, decimals, suffix) });
|
|
868
|
+
}
|
|
869
|
+
function Digit({ digit }) {
|
|
870
|
+
const [rolling, setRolling] = useState(false);
|
|
871
|
+
const first = useRef(true);
|
|
872
|
+
useEffect(() => {
|
|
873
|
+
if (first.current) {
|
|
874
|
+
first.current = false;
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
setRolling(true);
|
|
878
|
+
const id = window.setTimeout(() => setRolling(false), 280);
|
|
879
|
+
return () => window.clearTimeout(id);
|
|
880
|
+
}, [digit]);
|
|
881
|
+
return /* @__PURE__ */ jsx("span", { className: "yunui-mn-col", "aria-hidden": "true", children: /* @__PURE__ */ jsx("span", { className: "yunui-mn-strip", "data-rolling": rolling, style: { ["--mn-digit"]: digit } }) });
|
|
882
|
+
}
|
|
883
|
+
function MotionNumber({ value, decimals = 0, prefix = "", suffix = "", format: format2, grouping = false, locale, className }) {
|
|
884
|
+
const text = prefix + (typeof value === "string" ? value : format2 ? format2(value) : grouping ? new Intl.NumberFormat(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals }).format(value) : value.toFixed(decimals)) + suffix;
|
|
885
|
+
const chars = Array.from(text);
|
|
886
|
+
const outer = useRef(null);
|
|
887
|
+
const inner = useRef(null);
|
|
888
|
+
const mounted = useRef(false);
|
|
889
|
+
useLayoutEffect(() => {
|
|
890
|
+
const o = outer.current;
|
|
891
|
+
const i = inner.current;
|
|
892
|
+
if (!o || !i) return;
|
|
893
|
+
const w = i.getBoundingClientRect().width;
|
|
894
|
+
if (!mounted.current) {
|
|
895
|
+
o.style.transition = "none";
|
|
896
|
+
o.style.width = `${w}px`;
|
|
897
|
+
void o.offsetWidth;
|
|
898
|
+
o.style.transition = "";
|
|
899
|
+
mounted.current = true;
|
|
900
|
+
} else {
|
|
901
|
+
o.style.width = `${w}px`;
|
|
902
|
+
}
|
|
903
|
+
}, [text]);
|
|
904
|
+
return /* @__PURE__ */ jsxs("span", { ref: outer, className: cn("yunui-mn", className), "data-yunui": "motion-number", style: { overflow: "hidden" }, children: [
|
|
905
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: text }),
|
|
906
|
+
/* @__PURE__ */ jsx("span", { ref: inner, className: "inline-flex", "aria-hidden": "true", children: chars.map((ch, idx) => {
|
|
907
|
+
const fromRight = chars.length - idx;
|
|
908
|
+
return ch >= "0" && ch <= "9" ? /* @__PURE__ */ jsx(Digit, { digit: Number(ch) }, `d${fromRight}`) : /* @__PURE__ */ jsx("span", { className: "yunui-mn-glyph", "data-c": ch }, `c${fromRight}`);
|
|
909
|
+
}) })
|
|
910
|
+
] });
|
|
911
|
+
}
|
|
912
|
+
async function runViewTransition(update, kind = "page") {
|
|
913
|
+
const doc = typeof document === "undefined" ? void 0 : document;
|
|
914
|
+
const start = doc?.startViewTransition;
|
|
915
|
+
const reduced = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
916
|
+
if (!doc || typeof start !== "function" || reduced) {
|
|
917
|
+
if (kind === "theme" && doc) {
|
|
918
|
+
doc.documentElement.dataset.yunuiVt = "theme";
|
|
919
|
+
update();
|
|
920
|
+
await new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
921
|
+
delete doc.documentElement.dataset.yunuiVt;
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
update();
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
const root = doc.documentElement;
|
|
928
|
+
root.dataset.yunuiVt = kind;
|
|
929
|
+
try {
|
|
930
|
+
const transition = start.call(doc, () => {
|
|
931
|
+
flushSync(update);
|
|
932
|
+
});
|
|
933
|
+
await transition.finished.catch(() => void 0);
|
|
934
|
+
} finally {
|
|
935
|
+
delete root.dataset.yunuiVt;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
function useViewTransition() {
|
|
939
|
+
const start = useCallback((update, kind = "page") => runViewTransition(update, kind), []);
|
|
940
|
+
return { start };
|
|
941
|
+
}
|
|
942
|
+
var STATE_TONE = {
|
|
943
|
+
live: "accent",
|
|
944
|
+
held: "neutral",
|
|
945
|
+
idle: "accent"
|
|
946
|
+
};
|
|
947
|
+
function MetricHero({
|
|
948
|
+
value,
|
|
949
|
+
unit,
|
|
950
|
+
label,
|
|
951
|
+
state = "idle",
|
|
952
|
+
decimals = 0,
|
|
953
|
+
history,
|
|
954
|
+
min,
|
|
955
|
+
max,
|
|
956
|
+
animate = false,
|
|
957
|
+
labels,
|
|
958
|
+
className
|
|
959
|
+
}) {
|
|
960
|
+
const hasValue = value != null && Number.isFinite(value);
|
|
961
|
+
const stateText = state === "live" ? labels?.live ?? "Live" : state === "held" ? labels?.held ?? "Held" : null;
|
|
962
|
+
const spoken = `${label}: ${hasValue ? Number(value.toFixed(decimals)) : "\u2014"}${typeof unit === "string" ? ` ${unit}` : ""}${stateText ? `, ${stateText}` : ""}`;
|
|
963
|
+
return /* @__PURE__ */ jsxs(
|
|
964
|
+
"div",
|
|
965
|
+
{
|
|
966
|
+
role: "group",
|
|
967
|
+
"aria-label": label,
|
|
968
|
+
"data-state": state,
|
|
969
|
+
className: cn("flex items-end justify-between gap-4", className),
|
|
970
|
+
children: [
|
|
971
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
972
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs font-medium text-muted-foreground", children: [
|
|
973
|
+
/* @__PURE__ */ jsx("span", { children: label }),
|
|
974
|
+
stateText && /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5", children: [
|
|
975
|
+
/* @__PURE__ */ jsx(
|
|
976
|
+
"span",
|
|
977
|
+
{
|
|
978
|
+
"aria-hidden": true,
|
|
979
|
+
className: cn("h-1.5 w-1.5 rounded-full", state === "live" && "motion-safe:animate-pulse"),
|
|
980
|
+
style: {
|
|
981
|
+
backgroundColor: state === "live" ? "var(--success)" : "var(--color-muted-foreground)"
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
),
|
|
985
|
+
stateText
|
|
986
|
+
] })
|
|
987
|
+
] }),
|
|
988
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-baseline gap-1.5", children: [
|
|
989
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "text-4xl font-semibold leading-none tabular-nums text-foreground", children: hasValue ? /* @__PURE__ */ jsx(AnimatedNumber, { value, decimals, immediate: animate ? void 0 : true }) : "\u2014" }),
|
|
990
|
+
unit != null && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "text-sm font-medium text-muted-foreground", children: unit })
|
|
991
|
+
] }),
|
|
992
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: spoken })
|
|
993
|
+
] }),
|
|
994
|
+
history && history.length >= 2 && /* @__PURE__ */ jsx(
|
|
995
|
+
Sparkline,
|
|
996
|
+
{
|
|
997
|
+
data: history,
|
|
998
|
+
min,
|
|
999
|
+
max,
|
|
1000
|
+
tone: STATE_TONE[state],
|
|
1001
|
+
width: 120,
|
|
1002
|
+
height: 36,
|
|
1003
|
+
area: true,
|
|
1004
|
+
className: "shrink-0"
|
|
1005
|
+
}
|
|
1006
|
+
)
|
|
1007
|
+
]
|
|
1008
|
+
}
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
var TONE = {
|
|
1012
|
+
accent: "var(--color-accent, var(--text-primary))",
|
|
1013
|
+
info: "var(--info)",
|
|
1014
|
+
success: "var(--success)",
|
|
1015
|
+
warning: "var(--warning)",
|
|
1016
|
+
error: "var(--error)",
|
|
1017
|
+
neutral: "var(--color-muted-foreground)"
|
|
1018
|
+
};
|
|
1019
|
+
var clamp01 = (n) => Number.isFinite(n) ? Math.min(1, Math.max(0, n)) : 0;
|
|
1020
|
+
function stackedFractions(segments, total) {
|
|
1021
|
+
if (!(total > 0)) return segments.map(() => 0);
|
|
1022
|
+
let left = 1;
|
|
1023
|
+
return segments.map((s) => {
|
|
1024
|
+
const f = Math.min(left, clamp01(s.value / total));
|
|
1025
|
+
left -= f;
|
|
1026
|
+
return f;
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
function StackedProgress({ segments, total, label, valueText: valueText2, height = 4, className }) {
|
|
1030
|
+
const fractions = stackedFractions(segments, total);
|
|
1031
|
+
const filled = fractions.reduce((a, b) => a + b, 0);
|
|
1032
|
+
const tip = segments.filter((s, i) => s.label && fractions[i] > 0).map((s) => s.label).join(" \xB7 ");
|
|
1033
|
+
return /* @__PURE__ */ jsx(
|
|
1034
|
+
"div",
|
|
1035
|
+
{
|
|
1036
|
+
role: "progressbar",
|
|
1037
|
+
"aria-label": label,
|
|
1038
|
+
"aria-valuemin": 0,
|
|
1039
|
+
"aria-valuemax": 100,
|
|
1040
|
+
"aria-valuenow": Math.round(filled * 100),
|
|
1041
|
+
"aria-valuetext": valueText2,
|
|
1042
|
+
title: tip || valueText2,
|
|
1043
|
+
"data-yunui": "stacked-progress",
|
|
1044
|
+
className: cn("flex w-full overflow-hidden rounded-full bg-(--bg-elevated)", className),
|
|
1045
|
+
style: { height },
|
|
1046
|
+
children: segments.map(
|
|
1047
|
+
(s, i) => fractions[i] > 0 ? /* @__PURE__ */ jsx(
|
|
1048
|
+
"span",
|
|
1049
|
+
{
|
|
1050
|
+
"data-tone": s.tone,
|
|
1051
|
+
className: "h-full",
|
|
1052
|
+
style: { width: `${fractions[i] * 100}%`, backgroundColor: TONE[s.tone] }
|
|
1053
|
+
},
|
|
1054
|
+
i
|
|
1055
|
+
) : null
|
|
1056
|
+
)
|
|
1057
|
+
}
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
1060
|
+
var TONE_VAR = {
|
|
1061
|
+
accent: "var(--color-accent)",
|
|
1062
|
+
success: "var(--success)",
|
|
1063
|
+
warning: "var(--warning)",
|
|
1064
|
+
error: "var(--error)",
|
|
1065
|
+
info: "var(--info)",
|
|
1066
|
+
neutral: "var(--color-muted-foreground)"
|
|
1067
|
+
};
|
|
1068
|
+
function Gauge({
|
|
1069
|
+
value,
|
|
1070
|
+
size = 72,
|
|
1071
|
+
thickness = 6,
|
|
1072
|
+
tone = "accent",
|
|
1073
|
+
color,
|
|
1074
|
+
label,
|
|
1075
|
+
ariaLabel,
|
|
1076
|
+
counterClockwise = false,
|
|
1077
|
+
className
|
|
1078
|
+
}) {
|
|
1079
|
+
const pct = Math.max(0, Math.min(100, Number.isFinite(value) ? value : 0));
|
|
1080
|
+
const stroke = color ?? TONE_VAR[tone];
|
|
1081
|
+
const r = (size - thickness) / 2;
|
|
1082
|
+
const c = 2 * Math.PI * r;
|
|
1083
|
+
const dash = pct / 100 * c;
|
|
1084
|
+
return /* @__PURE__ */ jsxs(
|
|
1085
|
+
"div",
|
|
1086
|
+
{
|
|
1087
|
+
className: cn("relative inline-flex items-center justify-center", className),
|
|
1088
|
+
style: { width: size, height: size },
|
|
1089
|
+
role: "progressbar",
|
|
1090
|
+
"aria-label": typeof label === "string" ? label : ariaLabel,
|
|
1091
|
+
"aria-valuenow": Math.round(pct),
|
|
1092
|
+
"aria-valuemin": 0,
|
|
1093
|
+
"aria-valuemax": 100,
|
|
1094
|
+
children: [
|
|
1095
|
+
/* @__PURE__ */ jsxs("svg", { width: size, height: size, className: "-rotate-90", children: [
|
|
1096
|
+
/* @__PURE__ */ jsx(
|
|
1097
|
+
"circle",
|
|
1098
|
+
{
|
|
1099
|
+
cx: size / 2,
|
|
1100
|
+
cy: size / 2,
|
|
1101
|
+
r,
|
|
1102
|
+
fill: "none",
|
|
1103
|
+
stroke: "var(--color-border)",
|
|
1104
|
+
strokeWidth: thickness
|
|
1105
|
+
}
|
|
1106
|
+
),
|
|
1107
|
+
/* @__PURE__ */ jsx(
|
|
1108
|
+
"circle",
|
|
1109
|
+
{
|
|
1110
|
+
cx: size / 2,
|
|
1111
|
+
cy: size / 2,
|
|
1112
|
+
r,
|
|
1113
|
+
fill: "none",
|
|
1114
|
+
stroke,
|
|
1115
|
+
strokeWidth: thickness,
|
|
1116
|
+
strokeLinecap: "round",
|
|
1117
|
+
strokeDasharray: `${dash} ${c}`,
|
|
1118
|
+
className: "transition-[stroke-dasharray] duration-(--dur-slow) ease-out",
|
|
1119
|
+
transform: counterClockwise ? `scale(1,-1) translate(0,${-size})` : void 0
|
|
1120
|
+
}
|
|
1121
|
+
)
|
|
1122
|
+
] }),
|
|
1123
|
+
label !== null && /* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center text-sm font-semibold tabular-nums", children: label ?? `${Math.round(pct)}%` })
|
|
1124
|
+
]
|
|
1125
|
+
}
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
var TONE_VAR2 = {
|
|
1129
|
+
accent: "var(--color-accent)",
|
|
1130
|
+
success: "var(--success)",
|
|
1131
|
+
warning: "var(--warning)",
|
|
1132
|
+
error: "var(--error)",
|
|
1133
|
+
info: "var(--info)",
|
|
1134
|
+
neutral: "var(--color-muted-foreground)"
|
|
1135
|
+
};
|
|
1136
|
+
var markColor = (m) => m.color ?? (m.tone ? TONE_VAR2[m.tone] : "var(--color-foreground)");
|
|
1137
|
+
var segColor = (s) => s.color ?? TONE_VAR2[s.tone ?? "accent"];
|
|
1138
|
+
function SegmentedBar({
|
|
1139
|
+
segments,
|
|
1140
|
+
total,
|
|
1141
|
+
marks,
|
|
1142
|
+
height = 8,
|
|
1143
|
+
legend = false,
|
|
1144
|
+
formatValue,
|
|
1145
|
+
label,
|
|
1146
|
+
className
|
|
1147
|
+
}) {
|
|
1148
|
+
const sum = segments.reduce((a, s) => a + Math.max(0, s.value), 0);
|
|
1149
|
+
const axis = total ?? (sum || 1);
|
|
1150
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-2", className), children: [
|
|
1151
|
+
/* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
|
|
1152
|
+
/* @__PURE__ */ jsx(
|
|
1153
|
+
"div",
|
|
1154
|
+
{
|
|
1155
|
+
className: "flex w-full overflow-hidden rounded-full bg-muted",
|
|
1156
|
+
style: { height },
|
|
1157
|
+
role: label ? "img" : void 0,
|
|
1158
|
+
"aria-label": label,
|
|
1159
|
+
children: segments.map((s, i) => {
|
|
1160
|
+
const w = Math.max(0, s.value) / axis * 100;
|
|
1161
|
+
if (w <= 0) return null;
|
|
1162
|
+
return /* @__PURE__ */ jsx(
|
|
1163
|
+
"div",
|
|
1164
|
+
{
|
|
1165
|
+
className: "yunui-bar-fill h-full transition-[width] duration-(--dur-slow) first:rounded-l-full last:rounded-r-full",
|
|
1166
|
+
style: { width: `${w}%`, backgroundColor: segColor(s) },
|
|
1167
|
+
title: typeof s.label === "string" ? s.label : void 0
|
|
1168
|
+
},
|
|
1169
|
+
i
|
|
1170
|
+
);
|
|
1171
|
+
})
|
|
1172
|
+
}
|
|
1173
|
+
),
|
|
1174
|
+
(marks ?? []).map((m, i) => {
|
|
1175
|
+
if (!Number.isFinite(m.value)) return null;
|
|
1176
|
+
const pos = Math.min(100, Math.max(0, m.value / axis * 100));
|
|
1177
|
+
return /* @__PURE__ */ jsx(
|
|
1178
|
+
"span",
|
|
1179
|
+
{
|
|
1180
|
+
"aria-hidden": true,
|
|
1181
|
+
"data-bar-mark": "",
|
|
1182
|
+
title: typeof m.label === "string" ? m.label : void 0,
|
|
1183
|
+
className: "pointer-events-auto absolute -top-0.5 -bottom-0.5 w-0.5 -translate-x-1/2 rounded-full",
|
|
1184
|
+
style: { left: `${pos}%`, backgroundColor: markColor(m) }
|
|
1185
|
+
},
|
|
1186
|
+
i
|
|
1187
|
+
);
|
|
1188
|
+
})
|
|
1189
|
+
] }),
|
|
1190
|
+
legend && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
1191
|
+
segments.map((s, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
|
|
1192
|
+
/* @__PURE__ */ jsx(
|
|
1193
|
+
"span",
|
|
1194
|
+
{
|
|
1195
|
+
className: "h-2 w-2 shrink-0 rounded-full",
|
|
1196
|
+
style: { backgroundColor: segColor(s) }
|
|
1197
|
+
}
|
|
1198
|
+
),
|
|
1199
|
+
s.label != null && /* @__PURE__ */ jsx("span", { children: s.label }),
|
|
1200
|
+
/* @__PURE__ */ jsx("span", { className: "yunui-legend-value font-medium tabular-nums text-foreground/80", children: formatValue ? formatValue(s.value) : s.value })
|
|
1201
|
+
] }, i)),
|
|
1202
|
+
(marks ?? []).map(
|
|
1203
|
+
(m, i) => m.label != null && Number.isFinite(m.value) ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
|
|
1204
|
+
/* @__PURE__ */ jsx(
|
|
1205
|
+
"span",
|
|
1206
|
+
{
|
|
1207
|
+
"aria-hidden": true,
|
|
1208
|
+
className: "h-2.5 w-0.5 shrink-0 rounded-full",
|
|
1209
|
+
style: { backgroundColor: markColor(m) }
|
|
1210
|
+
}
|
|
1211
|
+
),
|
|
1212
|
+
/* @__PURE__ */ jsx("span", { children: m.label }),
|
|
1213
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium tabular-nums text-foreground/80", children: formatValue ? formatValue(m.value) : m.value })
|
|
1214
|
+
] }, `m${i}`) : null
|
|
1215
|
+
)
|
|
1216
|
+
] })
|
|
1217
|
+
] });
|
|
1218
|
+
}
|
|
1219
|
+
var TONE_COLOR = {
|
|
1220
|
+
accent: "var(--color-accent)",
|
|
1221
|
+
info: "var(--info)",
|
|
1222
|
+
success: "var(--success)",
|
|
1223
|
+
warning: "var(--warning)",
|
|
1224
|
+
error: "var(--error)",
|
|
1225
|
+
neutral: "var(--color-muted-foreground)"
|
|
1226
|
+
};
|
|
1227
|
+
function clamp012(value) {
|
|
1228
|
+
return Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0;
|
|
1229
|
+
}
|
|
1230
|
+
function meterPosition(value, curve = "linear") {
|
|
1231
|
+
const v = clamp012(value);
|
|
1232
|
+
if (curve === "linear" || v <= 0) return v;
|
|
1233
|
+
const db = Math.max(-60, Math.min(0, 20 * Math.log10(v)));
|
|
1234
|
+
if (curve === "log") return (db + 60) / 60;
|
|
1235
|
+
return db >= -20 ? 0.5 + 0.5 * ((db + 20) / 20) : 0.5 * ((db + 60) / 40);
|
|
1236
|
+
}
|
|
1237
|
+
function segmentBand(index, segments, warnAt, dangerAt) {
|
|
1238
|
+
const upper = (index + 1) / segments;
|
|
1239
|
+
if (dangerAt !== null && upper > dangerAt) return "danger";
|
|
1240
|
+
if (warnAt !== null && upper > warnAt) return "warning";
|
|
1241
|
+
return "tone";
|
|
1242
|
+
}
|
|
1243
|
+
function SegmentMeter({
|
|
1244
|
+
value,
|
|
1245
|
+
hold = 0,
|
|
1246
|
+
segments = 24,
|
|
1247
|
+
curve = "linear",
|
|
1248
|
+
warnAt = 0.9,
|
|
1249
|
+
dangerAt = 0.96,
|
|
1250
|
+
tone = "accent",
|
|
1251
|
+
label,
|
|
1252
|
+
valueText: valueText2,
|
|
1253
|
+
trackColor = "var(--bg-elevated)",
|
|
1254
|
+
className
|
|
1255
|
+
}) {
|
|
1256
|
+
const count = Math.max(1, Math.floor(segments));
|
|
1257
|
+
const position = meterPosition(value, curve);
|
|
1258
|
+
const filled = position * count;
|
|
1259
|
+
const holdIndex = Math.floor(meterPosition(hold, curve) * count);
|
|
1260
|
+
const percent = Math.round(clamp012(value) * 100);
|
|
1261
|
+
const cells = [];
|
|
1262
|
+
for (let index = 0; index < count; index += 1) {
|
|
1263
|
+
const band = segmentBand(index, count, warnAt, dangerAt);
|
|
1264
|
+
const color = band === "danger" ? "var(--error)" : band === "warning" ? "var(--warning)" : TONE_COLOR[tone];
|
|
1265
|
+
const lit = index < filled;
|
|
1266
|
+
const held = !lit && index === holdIndex && holdIndex > 0;
|
|
1267
|
+
cells.push(
|
|
1268
|
+
/* @__PURE__ */ jsx(
|
|
1269
|
+
"span",
|
|
1270
|
+
{
|
|
1271
|
+
"data-lit": lit ? "true" : void 0,
|
|
1272
|
+
"data-hold": held ? "true" : void 0,
|
|
1273
|
+
"data-band": band,
|
|
1274
|
+
className: "h-full rounded-[1.5px]",
|
|
1275
|
+
style: {
|
|
1276
|
+
backgroundColor: lit || held ? color : trackColor,
|
|
1277
|
+
opacity: held ? 0.45 : void 0
|
|
1278
|
+
}
|
|
1279
|
+
},
|
|
1280
|
+
index
|
|
1281
|
+
)
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
return /* @__PURE__ */ jsx(
|
|
1285
|
+
"div",
|
|
1286
|
+
{
|
|
1287
|
+
role: "meter",
|
|
1288
|
+
"aria-label": label,
|
|
1289
|
+
"aria-valuemin": 0,
|
|
1290
|
+
"aria-valuemax": 100,
|
|
1291
|
+
"aria-valuenow": percent,
|
|
1292
|
+
"aria-valuetext": valueText2 ?? `${percent}%`,
|
|
1293
|
+
"data-yunui": "segment-meter",
|
|
1294
|
+
className: cn("grid h-1.5 w-full gap-[2px]", className),
|
|
1295
|
+
style: { gridTemplateColumns: `repeat(${count}, minmax(0, 1fr))` },
|
|
1296
|
+
children: cells
|
|
1297
|
+
}
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
function FileDropzone({
|
|
1301
|
+
onFiles,
|
|
1302
|
+
accept,
|
|
1303
|
+
multiple = false,
|
|
1304
|
+
disabled = false,
|
|
1305
|
+
icon,
|
|
1306
|
+
label = "Drop a file here, or click to browse",
|
|
1307
|
+
hint,
|
|
1308
|
+
children,
|
|
1309
|
+
className
|
|
1310
|
+
}) {
|
|
1311
|
+
const inputRef = useRef(null);
|
|
1312
|
+
const [dragging, setDragging] = useState(false);
|
|
1313
|
+
const emit = (list) => {
|
|
1314
|
+
if (!list || list.length === 0) return;
|
|
1315
|
+
onFiles(Array.from(list));
|
|
1316
|
+
};
|
|
1317
|
+
const onDrop = (e) => {
|
|
1318
|
+
e.preventDefault();
|
|
1319
|
+
setDragging(false);
|
|
1320
|
+
if (disabled) return;
|
|
1321
|
+
emit(e.dataTransfer.files);
|
|
1322
|
+
};
|
|
1323
|
+
const onDragOver = (e) => {
|
|
1324
|
+
e.preventDefault();
|
|
1325
|
+
if (!disabled) setDragging(true);
|
|
1326
|
+
};
|
|
1327
|
+
return /* @__PURE__ */ jsxs(
|
|
1328
|
+
"div",
|
|
1329
|
+
{
|
|
1330
|
+
onClick: () => !disabled && inputRef.current?.click(),
|
|
1331
|
+
onDrop,
|
|
1332
|
+
onDragOver,
|
|
1333
|
+
onDragLeave: () => setDragging(false),
|
|
1334
|
+
role: "button",
|
|
1335
|
+
tabIndex: disabled ? -1 : 0,
|
|
1336
|
+
"aria-disabled": disabled,
|
|
1337
|
+
onKeyDown: (e) => {
|
|
1338
|
+
if (disabled) return;
|
|
1339
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1340
|
+
e.preventDefault();
|
|
1341
|
+
inputRef.current?.click();
|
|
1342
|
+
}
|
|
1343
|
+
},
|
|
1344
|
+
className: cn(
|
|
1345
|
+
"flex flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed px-6 py-8 text-center transition-colors",
|
|
1346
|
+
disabled ? "cursor-not-allowed opacity-50 border-border" : "cursor-pointer border-border hover:border-accent hover:bg-muted/40",
|
|
1347
|
+
dragging && !disabled && "border-accent bg-accent/10",
|
|
1348
|
+
className
|
|
1349
|
+
),
|
|
1350
|
+
children: [
|
|
1351
|
+
/* @__PURE__ */ jsx(
|
|
1352
|
+
"input",
|
|
1353
|
+
{
|
|
1354
|
+
ref: inputRef,
|
|
1355
|
+
type: "file",
|
|
1356
|
+
accept,
|
|
1357
|
+
multiple,
|
|
1358
|
+
disabled,
|
|
1359
|
+
className: "hidden",
|
|
1360
|
+
onChange: (e) => {
|
|
1361
|
+
emit(e.target.files);
|
|
1362
|
+
e.target.value = "";
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
),
|
|
1366
|
+
children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1367
|
+
icon && /* @__PURE__ */ jsx("div", { className: "text-muted-foreground", children: icon }),
|
|
1368
|
+
/* @__PURE__ */ jsx("div", { className: "text-sm font-medium", children: label }),
|
|
1369
|
+
hint && /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground", children: hint })
|
|
1370
|
+
] })
|
|
1371
|
+
]
|
|
1372
|
+
}
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
var TONE_VAR3 = {
|
|
1376
|
+
accent: "var(--color-accent)",
|
|
1377
|
+
success: "var(--success)",
|
|
1378
|
+
warning: "var(--warning)",
|
|
1379
|
+
error: "var(--error)",
|
|
1380
|
+
info: "var(--info)",
|
|
1381
|
+
neutral: "var(--color-muted-foreground)"
|
|
1382
|
+
};
|
|
1383
|
+
var VIEW_H = 140;
|
|
1384
|
+
function normalize(data) {
|
|
1385
|
+
return data.map((d) => typeof d === "number" ? { value: d } : d);
|
|
1386
|
+
}
|
|
1387
|
+
function AreaChart({
|
|
1388
|
+
data,
|
|
1389
|
+
tone = "accent",
|
|
1390
|
+
color,
|
|
1391
|
+
height = VIEW_H,
|
|
1392
|
+
formatValue,
|
|
1393
|
+
showGrid = true,
|
|
1394
|
+
showTooltip = true,
|
|
1395
|
+
showXAxis = false,
|
|
1396
|
+
strokeWidth = 2,
|
|
1397
|
+
ariaLabel = "Area chart",
|
|
1398
|
+
noDataLabel = "No data",
|
|
1399
|
+
className
|
|
1400
|
+
}) {
|
|
1401
|
+
const gradientId = useId();
|
|
1402
|
+
const stroke = color ?? TONE_VAR3[tone];
|
|
1403
|
+
const containerRef = useRef(null);
|
|
1404
|
+
const [width, setWidth] = useState(0);
|
|
1405
|
+
const [hovered, setHovered] = useState(null);
|
|
1406
|
+
const points = useMemo(() => normalize(data), [data]);
|
|
1407
|
+
useEffect(() => {
|
|
1408
|
+
if (!containerRef.current) return;
|
|
1409
|
+
const observer = new ResizeObserver((entries) => {
|
|
1410
|
+
if (entries[0]) setWidth(entries[0].contentRect.width);
|
|
1411
|
+
});
|
|
1412
|
+
observer.observe(containerRef.current);
|
|
1413
|
+
return () => observer.disconnect();
|
|
1414
|
+
}, []);
|
|
1415
|
+
const values = points.map((p) => Number.isFinite(p.value) ? p.value : 0);
|
|
1416
|
+
const maxVal = Math.max(...values, 1);
|
|
1417
|
+
const minVal = Math.min(...values, 0);
|
|
1418
|
+
const span = maxVal - minVal || 1;
|
|
1419
|
+
const chartWidth = width || 600;
|
|
1420
|
+
const getPoint = (i) => {
|
|
1421
|
+
const x = i / Math.max(points.length - 1, 1) * chartWidth;
|
|
1422
|
+
const normalized = (values[i] - minVal) / span;
|
|
1423
|
+
const y = VIEW_H - normalized * VIEW_H * 0.85 - VIEW_H * 0.05;
|
|
1424
|
+
return { x, y };
|
|
1425
|
+
};
|
|
1426
|
+
const linePath = useMemo(() => {
|
|
1427
|
+
if (points.length === 0) return "";
|
|
1428
|
+
const start = getPoint(0);
|
|
1429
|
+
let path = `M ${start.x},${start.y}`;
|
|
1430
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
1431
|
+
const curr = getPoint(i);
|
|
1432
|
+
const next = getPoint(i + 1);
|
|
1433
|
+
const cpx = (curr.x + next.x) / 2;
|
|
1434
|
+
path += ` C ${cpx},${curr.y} ${cpx},${next.y} ${next.x},${next.y}`;
|
|
1435
|
+
}
|
|
1436
|
+
return path;
|
|
1437
|
+
}, [points, values, maxVal, minVal, chartWidth]);
|
|
1438
|
+
const areaPath = linePath ? `${linePath} L ${chartWidth},${VIEW_H} L 0,${VIEW_H} Z` : "";
|
|
1439
|
+
const hoveredCoords = hovered !== null ? getPoint(hovered) : null;
|
|
1440
|
+
const fmt = formatValue ?? ((v) => String(v));
|
|
1441
|
+
const xLabels = points.filter((p) => p.label != null);
|
|
1442
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", className), children: [
|
|
1443
|
+
/* @__PURE__ */ jsxs("div", { ref: containerRef, className: "relative w-full", style: { height }, children: [
|
|
1444
|
+
points.length < 2 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center text-sm text-muted-foreground", children: noDataLabel }) : /* @__PURE__ */ jsxs(
|
|
1445
|
+
"svg",
|
|
1446
|
+
{
|
|
1447
|
+
viewBox: `0 0 ${chartWidth} ${VIEW_H}`,
|
|
1448
|
+
preserveAspectRatio: "none",
|
|
1449
|
+
className: "h-full w-full overflow-visible",
|
|
1450
|
+
role: "img",
|
|
1451
|
+
"aria-label": ariaLabel,
|
|
1452
|
+
onMouseMove: (e) => {
|
|
1453
|
+
if (!showTooltip) return;
|
|
1454
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
1455
|
+
const mouseX = e.clientX - rect.left;
|
|
1456
|
+
const idx = Math.min(
|
|
1457
|
+
Math.max(0, Math.round(mouseX / rect.width * (points.length - 1))),
|
|
1458
|
+
points.length - 1
|
|
1459
|
+
);
|
|
1460
|
+
setHovered(idx);
|
|
1461
|
+
},
|
|
1462
|
+
onMouseLeave: () => setHovered(null),
|
|
1463
|
+
children: [
|
|
1464
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
1465
|
+
/* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: stroke, stopOpacity: 0.32 }),
|
|
1466
|
+
/* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: stroke, stopOpacity: 0 })
|
|
1467
|
+
] }) }),
|
|
1468
|
+
showGrid && [0, 0.25, 0.5, 0.75, 1].map((tick) => /* @__PURE__ */ jsx(
|
|
1469
|
+
"line",
|
|
1470
|
+
{
|
|
1471
|
+
x1: 0,
|
|
1472
|
+
y1: VIEW_H * tick,
|
|
1473
|
+
x2: chartWidth,
|
|
1474
|
+
y2: VIEW_H * tick,
|
|
1475
|
+
stroke: "currentColor",
|
|
1476
|
+
strokeOpacity: 0.1,
|
|
1477
|
+
strokeDasharray: "4 4",
|
|
1478
|
+
className: "text-muted-foreground"
|
|
1479
|
+
},
|
|
1480
|
+
tick
|
|
1481
|
+
)),
|
|
1482
|
+
/* @__PURE__ */ jsx("path", { d: areaPath, fill: `url(#${gradientId})` }),
|
|
1483
|
+
/* @__PURE__ */ jsx(
|
|
1484
|
+
"path",
|
|
1485
|
+
{
|
|
1486
|
+
d: linePath,
|
|
1487
|
+
fill: "none",
|
|
1488
|
+
stroke,
|
|
1489
|
+
strokeWidth,
|
|
1490
|
+
strokeLinecap: "round",
|
|
1491
|
+
strokeLinejoin: "round",
|
|
1492
|
+
vectorEffect: "non-scaling-stroke"
|
|
1493
|
+
}
|
|
1494
|
+
),
|
|
1495
|
+
hoveredCoords && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1496
|
+
/* @__PURE__ */ jsx(
|
|
1497
|
+
"line",
|
|
1498
|
+
{
|
|
1499
|
+
x1: hoveredCoords.x,
|
|
1500
|
+
y1: 0,
|
|
1501
|
+
x2: hoveredCoords.x,
|
|
1502
|
+
y2: VIEW_H,
|
|
1503
|
+
stroke,
|
|
1504
|
+
strokeOpacity: 0.4,
|
|
1505
|
+
strokeDasharray: "4 4"
|
|
1506
|
+
}
|
|
1507
|
+
),
|
|
1508
|
+
/* @__PURE__ */ jsx(
|
|
1509
|
+
"circle",
|
|
1510
|
+
{
|
|
1511
|
+
cx: hoveredCoords.x,
|
|
1512
|
+
cy: hoveredCoords.y,
|
|
1513
|
+
r: 4,
|
|
1514
|
+
fill: stroke,
|
|
1515
|
+
stroke: "var(--color-background)",
|
|
1516
|
+
strokeWidth: 2,
|
|
1517
|
+
vectorEffect: "non-scaling-stroke"
|
|
1518
|
+
}
|
|
1519
|
+
)
|
|
1520
|
+
] })
|
|
1521
|
+
]
|
|
1522
|
+
}
|
|
1523
|
+
),
|
|
1524
|
+
showTooltip && hovered !== null && points[hovered] && chartWidth > 0 && /* @__PURE__ */ jsxs(
|
|
1525
|
+
"div",
|
|
1526
|
+
{
|
|
1527
|
+
className: "pointer-events-none absolute z-10 -translate-x-1/2 -translate-y-full rounded-lg border border-border bg-popover p-2 text-xs shadow-lg",
|
|
1528
|
+
style: {
|
|
1529
|
+
left: `${Math.min(Math.max(getPoint(hovered).x / chartWidth * 100, 8), 92)}%`,
|
|
1530
|
+
top: Math.max(getPoint(hovered).y / VIEW_H * height - 8, 0)
|
|
1531
|
+
},
|
|
1532
|
+
children: [
|
|
1533
|
+
points[hovered].label != null && /* @__PURE__ */ jsx("div", { className: "mb-0.5 font-medium", children: points[hovered].label }),
|
|
1534
|
+
/* @__PURE__ */ jsx("div", { className: "tabular-nums text-muted-foreground", children: fmt(values[hovered]) })
|
|
1535
|
+
]
|
|
1536
|
+
}
|
|
1537
|
+
)
|
|
1538
|
+
] }),
|
|
1539
|
+
showXAxis && xLabels.length > 1 && /* @__PURE__ */ jsx("div", { className: "mt-1.5 flex justify-between px-1 text-xs text-muted-foreground", children: points.filter((p, i) => p.label != null && i % Math.ceil(points.length / 6) === 0).map((p, i) => /* @__PURE__ */ jsx("span", { className: "truncate", children: p.label }, i)) })
|
|
1540
|
+
] });
|
|
1541
|
+
}
|
|
1542
|
+
var TONE_COLOR2 = {
|
|
1543
|
+
accent: "var(--color-accent)",
|
|
1544
|
+
info: "var(--info)",
|
|
1545
|
+
success: "var(--success)",
|
|
1546
|
+
warning: "var(--warning)",
|
|
1547
|
+
error: "var(--error)",
|
|
1548
|
+
neutral: "var(--color-muted-foreground)"
|
|
1549
|
+
};
|
|
1550
|
+
var DEFAULT_HEIGHT = 252;
|
|
1551
|
+
var DEFAULT_WIDTH = 640;
|
|
1552
|
+
var MARGIN = { top: 14, right: 14, bottom: 34, left: 54 };
|
|
1553
|
+
var Y_TICK_COUNT = 5;
|
|
1554
|
+
var X_TICK_COUNT = 5;
|
|
1555
|
+
function normalizeData(data) {
|
|
1556
|
+
const sorted = data.map((point, inputIndex) => ({ ...point, inputIndex })).filter((point) => Number.isFinite(point.x)).sort((a, b) => a.x - b.x || a.inputIndex - b.inputIndex);
|
|
1557
|
+
const byX = /* @__PURE__ */ new Map();
|
|
1558
|
+
for (const point of sorted) byX.set(point.x, { x: point.x, values: point.values });
|
|
1559
|
+
return [...byX.values()].sort((a, b) => a.x - b.x);
|
|
1560
|
+
}
|
|
1561
|
+
function validValue(value) {
|
|
1562
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
1563
|
+
}
|
|
1564
|
+
function niceStep(span) {
|
|
1565
|
+
if (!Number.isFinite(span) || span <= 0) return 1;
|
|
1566
|
+
const rough = span / (Y_TICK_COUNT - 1);
|
|
1567
|
+
const magnitude = 10 ** Math.floor(Math.log10(rough));
|
|
1568
|
+
const fraction = rough / magnitude;
|
|
1569
|
+
const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10;
|
|
1570
|
+
return nice * magnitude;
|
|
1571
|
+
}
|
|
1572
|
+
function makeYTicks(min, max, integerOnly = false, scale = 1) {
|
|
1573
|
+
const span = max - min;
|
|
1574
|
+
const base = integerOnly ? Math.max(1, Math.ceil(niceStep(span))) : niceStep(span);
|
|
1575
|
+
const step = base * scale;
|
|
1576
|
+
const first = Math.ceil(min / step) * step;
|
|
1577
|
+
const values = [];
|
|
1578
|
+
for (let value = first, guard = 0; value <= max + step * 1e-8 && guard < 12; value += step, guard += 1) {
|
|
1579
|
+
values.push(Number(value.toPrecision(12)));
|
|
1580
|
+
}
|
|
1581
|
+
if (!values.length) values.push(min, max);
|
|
1582
|
+
return values;
|
|
1583
|
+
}
|
|
1584
|
+
function selectXTickValues(points, min, max, count, plotWidth = Infinity, minSpacing = 0) {
|
|
1585
|
+
if (points.length <= 1) return points.map((point) => point.x);
|
|
1586
|
+
if (count <= 1) return [points[Math.floor((points.length - 1) / 2)].x];
|
|
1587
|
+
const candidates = Array.from({ length: count }, (_, index) => min + (max - min) * index / (count - 1));
|
|
1588
|
+
const selected = [];
|
|
1589
|
+
for (const candidate of candidates) {
|
|
1590
|
+
let nearest = points[0].x;
|
|
1591
|
+
let distance = Math.abs(nearest - candidate);
|
|
1592
|
+
for (let index = 1; index < points.length; index += 1) {
|
|
1593
|
+
const next = points[index].x;
|
|
1594
|
+
const nextDistance = Math.abs(next - candidate);
|
|
1595
|
+
if (nextDistance < distance) {
|
|
1596
|
+
nearest = next;
|
|
1597
|
+
distance = nextDistance;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
if (selected.at(-1) !== nearest) selected.push(nearest);
|
|
1601
|
+
}
|
|
1602
|
+
if (minSpacing <= 0 || !Number.isFinite(plotWidth) || max <= min) return selected;
|
|
1603
|
+
const px = (x) => (x - min) / (max - min) * plotWidth;
|
|
1604
|
+
const kept = [];
|
|
1605
|
+
for (const x of selected) if (!kept.length || px(x) - px(kept.at(-1)) >= minSpacing) kept.push(x);
|
|
1606
|
+
const last = selected.at(-1);
|
|
1607
|
+
if (kept.at(-1) !== last) {
|
|
1608
|
+
while (kept.length && px(last) - px(kept.at(-1)) < minSpacing) kept.pop();
|
|
1609
|
+
kept.push(last);
|
|
1610
|
+
}
|
|
1611
|
+
return kept;
|
|
1612
|
+
}
|
|
1613
|
+
function pointForX(points, x) {
|
|
1614
|
+
if (x == null || !points.length) return null;
|
|
1615
|
+
let nearest = points[0];
|
|
1616
|
+
let distance = Math.abs(nearest.x - x);
|
|
1617
|
+
for (let index = 1; index < points.length; index += 1) {
|
|
1618
|
+
const point = points[index];
|
|
1619
|
+
const nextDistance = Math.abs(point.x - x);
|
|
1620
|
+
if (nextDistance < distance) {
|
|
1621
|
+
nearest = point;
|
|
1622
|
+
distance = nextDistance;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
return nearest;
|
|
1626
|
+
}
|
|
1627
|
+
function formatDefault(value) {
|
|
1628
|
+
return new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(value);
|
|
1629
|
+
}
|
|
1630
|
+
function segmentsForSeries(points, definition, xScale, yScale, maxGap) {
|
|
1631
|
+
const segments = [];
|
|
1632
|
+
let current = [];
|
|
1633
|
+
let previousX;
|
|
1634
|
+
for (const point of points) {
|
|
1635
|
+
const value = validValue(point.values[definition.key]);
|
|
1636
|
+
const gap = previousX !== void 0 && maxGap !== void 0 && point.x - previousX > maxGap;
|
|
1637
|
+
if (value === void 0 || gap) {
|
|
1638
|
+
if (current.length) segments.push(current);
|
|
1639
|
+
current = [];
|
|
1640
|
+
}
|
|
1641
|
+
if (value !== void 0) {
|
|
1642
|
+
current.push({ x: xScale(point.x), y: yScale(value) });
|
|
1643
|
+
}
|
|
1644
|
+
previousX = point.x;
|
|
1645
|
+
}
|
|
1646
|
+
if (current.length) segments.push(current);
|
|
1647
|
+
return segments;
|
|
1648
|
+
}
|
|
1649
|
+
function closestPointIndex(points, value) {
|
|
1650
|
+
let result = 0;
|
|
1651
|
+
let distance = Math.abs(points[0].x - value);
|
|
1652
|
+
for (let index = 1; index < points.length; index += 1) {
|
|
1653
|
+
const nextDistance = Math.abs(points[index].x - value);
|
|
1654
|
+
if (nextDistance < distance) {
|
|
1655
|
+
result = index;
|
|
1656
|
+
distance = nextDistance;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
return result;
|
|
1660
|
+
}
|
|
1661
|
+
function TimeSeriesChart({
|
|
1662
|
+
data,
|
|
1663
|
+
series,
|
|
1664
|
+
ariaLabel,
|
|
1665
|
+
emptyLabel = "No data",
|
|
1666
|
+
unavailableLabel = "No finite values for the visible series",
|
|
1667
|
+
hiddenLabel = "All series are hidden",
|
|
1668
|
+
missingValueLabel = "\u2014",
|
|
1669
|
+
legendLabel = "series",
|
|
1670
|
+
keyboardHint = "Use left and right arrow keys, Home or End to inspect sample values.",
|
|
1671
|
+
height = DEFAULT_HEIGHT,
|
|
1672
|
+
formatX = formatDefault,
|
|
1673
|
+
formatY = formatDefault,
|
|
1674
|
+
maxGap,
|
|
1675
|
+
activeX,
|
|
1676
|
+
showReadout = true,
|
|
1677
|
+
onActiveXChange,
|
|
1678
|
+
showLegend = true,
|
|
1679
|
+
idle: idleProp = false,
|
|
1680
|
+
baseline = "zero",
|
|
1681
|
+
xDomain,
|
|
1682
|
+
xTicks,
|
|
1683
|
+
yMax,
|
|
1684
|
+
minSamples = 0,
|
|
1685
|
+
collectingLabel = (have, need) => `Collecting samples (${have}/${need})`,
|
|
1686
|
+
className
|
|
1687
|
+
}) {
|
|
1688
|
+
const instanceId = useId();
|
|
1689
|
+
const chartRef = useRef(null);
|
|
1690
|
+
const pointerSelectionRef = useRef(false);
|
|
1691
|
+
const [width, setWidth] = useState(DEFAULT_WIDTH);
|
|
1692
|
+
const [hiddenKeys, setHiddenKeys] = useState(() => /* @__PURE__ */ new Set());
|
|
1693
|
+
const [internalActiveX, setInternalActiveX] = useState(null);
|
|
1694
|
+
const [keyboardAnnouncement, setKeyboardAnnouncement] = useState("");
|
|
1695
|
+
const controlledActiveX = activeX !== void 0;
|
|
1696
|
+
const selectedX = controlledActiveX ? activeX != null && Number.isFinite(activeX) ? activeX : null : internalActiveX;
|
|
1697
|
+
const canSetActiveX = !controlledActiveX || Boolean(onActiveXChange);
|
|
1698
|
+
const points = useMemo(() => normalizeData(data), [data]);
|
|
1699
|
+
const definitions = useMemo(() => {
|
|
1700
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1701
|
+
return series.filter((item) => {
|
|
1702
|
+
if (!item.key || seen.has(item.key)) return false;
|
|
1703
|
+
seen.add(item.key);
|
|
1704
|
+
return true;
|
|
1705
|
+
});
|
|
1706
|
+
}, [series]);
|
|
1707
|
+
const visibleSeries = useMemo(() => definitions.filter((item) => !hiddenKeys.has(item.key)), [definitions, hiddenKeys]);
|
|
1708
|
+
const maxGapValue = maxGap !== void 0 && Number.isFinite(maxGap) && maxGap >= 0 ? maxGap : void 0;
|
|
1709
|
+
const plotWidth = Math.max(1, width - MARGIN.left - MARGIN.right);
|
|
1710
|
+
const plotHeight = Math.max(1, height - MARGIN.top - MARGIN.bottom);
|
|
1711
|
+
useEffect(() => {
|
|
1712
|
+
const element = chartRef.current;
|
|
1713
|
+
if (!element) return;
|
|
1714
|
+
const measure = () => {
|
|
1715
|
+
const next = Math.floor(element.getBoundingClientRect().width);
|
|
1716
|
+
if (next > 0) setWidth((current) => current === next ? current : next);
|
|
1717
|
+
};
|
|
1718
|
+
measure();
|
|
1719
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1720
|
+
const observer = new ResizeObserver(measure);
|
|
1721
|
+
observer.observe(element);
|
|
1722
|
+
return () => observer.disconnect();
|
|
1723
|
+
}
|
|
1724
|
+
window.addEventListener("resize", measure);
|
|
1725
|
+
return () => window.removeEventListener("resize", measure);
|
|
1726
|
+
}, []);
|
|
1727
|
+
const finiteValues = useMemo(() => {
|
|
1728
|
+
const result = [];
|
|
1729
|
+
for (const point of points) for (const definition of visibleSeries) {
|
|
1730
|
+
const value = validValue(point.values[definition.key]);
|
|
1731
|
+
if (value !== void 0) result.push(value);
|
|
1732
|
+
}
|
|
1733
|
+
return result;
|
|
1734
|
+
}, [points, visibleSeries]);
|
|
1735
|
+
const hasPlottableValues = finiteValues.length > 0;
|
|
1736
|
+
const fixedX = xDomain && Number.isFinite(xDomain[0]) && Number.isFinite(xDomain[1]) && xDomain[1] > xDomain[0] ? xDomain : void 0;
|
|
1737
|
+
const rawMinX = fixedX ? fixedX[0] : points[0]?.x ?? 0;
|
|
1738
|
+
const rawMaxX = fixedX ? fixedX[1] : points.at(-1)?.x ?? 1;
|
|
1739
|
+
const xPadding = rawMinX === rawMaxX ? 0.5 : 0;
|
|
1740
|
+
const minX = rawMinX - xPadding;
|
|
1741
|
+
const maxX = rawMaxX + xPadding;
|
|
1742
|
+
const dataMinY = hasPlottableValues ? finiteValues.reduce((min, value) => Math.min(min, value), Infinity) : 0;
|
|
1743
|
+
const rawMinY = baseline === "zero" && dataMinY >= 0 ? 0 : dataMinY;
|
|
1744
|
+
const collecting = minSamples > 0 && points.length < minSamples;
|
|
1745
|
+
const idle = idleProp || collecting;
|
|
1746
|
+
const dataMaxY = hasPlottableValues ? finiteValues.reduce((max, value) => Math.max(max, value), -Infinity) : 1;
|
|
1747
|
+
const rawMaxY = yMax !== void 0 && Number.isFinite(yMax) ? Math.max(yMax, dataMaxY) : dataMaxY;
|
|
1748
|
+
const yPadding = rawMinY === rawMaxY ? Math.max(Math.abs(rawMinY) * 0.05, 1) : 0;
|
|
1749
|
+
const minY = rawMinY - yPadding;
|
|
1750
|
+
const maxY = rawMaxY + yPadding;
|
|
1751
|
+
const integerOnly = finiteValues.every(Number.isInteger);
|
|
1752
|
+
const yTicks = useMemo(() => {
|
|
1753
|
+
if (!hasPlottableValues) return [];
|
|
1754
|
+
let ticks = [];
|
|
1755
|
+
for (const scale of [1, 2, 5, 10, 20, 50, 100]) {
|
|
1756
|
+
ticks = makeYTicks(minY, maxY, integerOnly, scale);
|
|
1757
|
+
const labels = ticks.map((tick) => formatY(tick));
|
|
1758
|
+
if (new Set(labels).size === labels.length) break;
|
|
1759
|
+
}
|
|
1760
|
+
return ticks;
|
|
1761
|
+
}, [hasPlottableValues, minY, maxY, integerOnly, formatY]);
|
|
1762
|
+
const widestXLabel = useMemo(() => points.reduce((length, point) => Math.max(length, formatX(point.x).length), 0), [points, formatX]);
|
|
1763
|
+
const minXLabelSpacing = Math.max(80, widestXLabel * 6.5 + 16);
|
|
1764
|
+
const xTickCount = Math.max(1, Math.min(X_TICK_COUNT, Math.floor(plotWidth / minXLabelSpacing) + 1));
|
|
1765
|
+
const xTickValues = useMemo(() => hasPlottableValues ? xTicks ? xTicks.filter((tick) => tick >= minX && tick <= maxX) : selectXTickValues(points, minX, maxX, xTickCount, plotWidth, minXLabelSpacing) : [], [hasPlottableValues, xTicks, points, minX, maxX, xTickCount, plotWidth, minXLabelSpacing]);
|
|
1766
|
+
const { xScale, yScale } = useMemo(() => ({
|
|
1767
|
+
xScale: (x) => MARGIN.left + (x - minX) / (maxX - minX || 1) * plotWidth,
|
|
1768
|
+
yScale: (y) => MARGIN.top + plotHeight - (y - minY) / (maxY - minY || 1) * plotHeight
|
|
1769
|
+
}), [minX, maxX, minY, maxY, plotWidth, plotHeight]);
|
|
1770
|
+
const plottedSeries = useMemo(() => visibleSeries.map((definition) => ({
|
|
1771
|
+
definition,
|
|
1772
|
+
color: definition.color ?? TONE_COLOR2[definition.tone ?? "accent"],
|
|
1773
|
+
segments: segmentsForSeries(points, definition, xScale, yScale, maxGapValue).flatMap((segment) => segment.length === 1 ? [{ point: segment[0] }] : collecting ? segment.map((point) => ({ point })) : [{ path: monotonePath(segment) }])
|
|
1774
|
+
})), [visibleSeries, points, xScale, yScale, maxGapValue, collecting]);
|
|
1775
|
+
const activePoint = pointForX(points, selectedX);
|
|
1776
|
+
const readoutPoint = activePoint ?? points.at(-1) ?? null;
|
|
1777
|
+
const canNavigate = points.length > 0 && hasPlottableValues && canSetActiveX;
|
|
1778
|
+
const xFormatter = formatX;
|
|
1779
|
+
const yFormatter = formatY;
|
|
1780
|
+
const clipId = `${instanceId}-plot-clip`;
|
|
1781
|
+
const chartWidth = Math.max(width, MARGIN.left + MARGIN.right + 1);
|
|
1782
|
+
const setActivePoint = (nextX, fromKeyboard) => {
|
|
1783
|
+
pointerSelectionRef.current = !fromKeyboard && !controlledActiveX && nextX !== null;
|
|
1784
|
+
if (fromKeyboard) {
|
|
1785
|
+
const nextPoint = pointForX(points, nextX);
|
|
1786
|
+
setKeyboardAnnouncement(nextPoint ? `${xFormatter(nextPoint.x)}. ${definitions.map((definition) => {
|
|
1787
|
+
const value = validValue(nextPoint.values[definition.key]);
|
|
1788
|
+
return `${definition.label}: ${value === void 0 ? missingValueLabel : yFormatter(value)}`;
|
|
1789
|
+
}).join(". ")}` : "");
|
|
1790
|
+
} else {
|
|
1791
|
+
setKeyboardAnnouncement("");
|
|
1792
|
+
}
|
|
1793
|
+
if (!canSetActiveX) return;
|
|
1794
|
+
if (!controlledActiveX) setInternalActiveX(nextX);
|
|
1795
|
+
onActiveXChange?.(nextX);
|
|
1796
|
+
};
|
|
1797
|
+
const handlePointerMove = (event) => {
|
|
1798
|
+
if (!canSetActiveX || !points.length || !hasPlottableValues) return;
|
|
1799
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1800
|
+
if (!rect.width) return;
|
|
1801
|
+
const svgX = (event.clientX - rect.left) / rect.width * chartWidth;
|
|
1802
|
+
const domainX = minX + (svgX - MARGIN.left) / plotWidth * (maxX - minX);
|
|
1803
|
+
const index = closestPointIndex(points, domainX);
|
|
1804
|
+
setActivePoint(points[index].x, false);
|
|
1805
|
+
};
|
|
1806
|
+
const handleKeyDown = (event) => {
|
|
1807
|
+
if (!canNavigate) return;
|
|
1808
|
+
if (event.key === "Escape") {
|
|
1809
|
+
event.preventDefault();
|
|
1810
|
+
setActivePoint(null, true);
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const currentIndex = activePoint ? closestPointIndex(points, activePoint.x) : -1;
|
|
1814
|
+
let nextIndex;
|
|
1815
|
+
if (event.key === "ArrowRight") nextIndex = currentIndex < 0 ? 0 : Math.min(points.length - 1, currentIndex + 1);
|
|
1816
|
+
else if (event.key === "ArrowLeft") nextIndex = currentIndex < 0 ? points.length - 1 : Math.max(0, currentIndex - 1);
|
|
1817
|
+
else if (event.key === "Home") nextIndex = 0;
|
|
1818
|
+
else if (event.key === "End") nextIndex = points.length - 1;
|
|
1819
|
+
if (nextIndex === void 0) return;
|
|
1820
|
+
event.preventDefault();
|
|
1821
|
+
setActivePoint(points[nextIndex].x, true);
|
|
1822
|
+
};
|
|
1823
|
+
const toggleSeries = (key) => {
|
|
1824
|
+
setHiddenKeys((current) => {
|
|
1825
|
+
const next = new Set(current);
|
|
1826
|
+
if (next.has(key)) next.delete(key);
|
|
1827
|
+
else next.add(key);
|
|
1828
|
+
return next;
|
|
1829
|
+
});
|
|
1830
|
+
};
|
|
1831
|
+
const tooltipX = activePoint ? xScale(activePoint.x) : 0;
|
|
1832
|
+
const tooltipMaxWidth = Math.max(0, Math.min(288, chartWidth - 16));
|
|
1833
|
+
const tooltipHalf = tooltipMaxWidth / 2;
|
|
1834
|
+
const tooltipLeft = activePoint ? Math.max(8 + tooltipHalf, Math.min(chartWidth - 8 - tooltipHalf, tooltipX)) : 0;
|
|
1835
|
+
const noDataText = data.length === 0 ? emptyLabel : definitions.length > 0 && visibleSeries.length === 0 ? hiddenLabel : unavailableLabel;
|
|
1836
|
+
return /* @__PURE__ */ jsxs("figure", { className: cn("min-w-0", className), "data-yunui": "time-series-chart", "data-active-x": activePoint?.x ?? void 0, children: [
|
|
1837
|
+
showLegend && definitions.length > 0 ? /* @__PURE__ */ jsx("div", { className: "mb-2 flex flex-wrap items-center gap-1.5", role: "group", "aria-label": `${ariaLabel} ${legendLabel}`, children: definitions.map((definition) => {
|
|
1838
|
+
const visible = !hiddenKeys.has(definition.key);
|
|
1839
|
+
const color = definition.color ?? TONE_COLOR2[definition.tone ?? "accent"];
|
|
1840
|
+
return /* @__PURE__ */ jsxs(
|
|
1841
|
+
"button",
|
|
1842
|
+
{
|
|
1843
|
+
type: "button",
|
|
1844
|
+
"aria-pressed": visible,
|
|
1845
|
+
onClick: () => toggleSeries(definition.key),
|
|
1846
|
+
className: cn(
|
|
1847
|
+
"btn btn-ghost btn-sm yunui-fine-print inline-flex h-7 items-center gap-1.5 rounded-full px-2.5 text-[11px]",
|
|
1848
|
+
!visible && "opacity-50"
|
|
1849
|
+
),
|
|
1850
|
+
children: [
|
|
1851
|
+
/* @__PURE__ */ jsx(
|
|
1852
|
+
"span",
|
|
1853
|
+
{
|
|
1854
|
+
"aria-hidden": "true",
|
|
1855
|
+
className: "inline-block w-3 shrink-0 border-t-2",
|
|
1856
|
+
style: { borderColor: color, borderStyle: definition.dashed ? "dashed" : "solid" }
|
|
1857
|
+
}
|
|
1858
|
+
),
|
|
1859
|
+
definition.label
|
|
1860
|
+
]
|
|
1861
|
+
},
|
|
1862
|
+
definition.key
|
|
1863
|
+
);
|
|
1864
|
+
}) }) : null,
|
|
1865
|
+
/* @__PURE__ */ jsxs(
|
|
1866
|
+
"div",
|
|
1867
|
+
{
|
|
1868
|
+
ref: chartRef,
|
|
1869
|
+
className: "relative min-w-0 rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
1870
|
+
role: "group",
|
|
1871
|
+
"aria-label": ariaLabel,
|
|
1872
|
+
tabIndex: canNavigate ? 0 : -1,
|
|
1873
|
+
onKeyDown: handleKeyDown,
|
|
1874
|
+
onPointerLeave: () => {
|
|
1875
|
+
if (!controlledActiveX && pointerSelectionRef.current && selectedX !== null) setActivePoint(null, false);
|
|
1876
|
+
},
|
|
1877
|
+
"data-yunui": "time-series-interaction",
|
|
1878
|
+
children: [
|
|
1879
|
+
hasPlottableValues ? /* @__PURE__ */ jsxs(
|
|
1880
|
+
"svg",
|
|
1881
|
+
{
|
|
1882
|
+
className: "block w-full overflow-visible",
|
|
1883
|
+
width: "100%",
|
|
1884
|
+
height,
|
|
1885
|
+
viewBox: `0 0 ${chartWidth} ${height}`,
|
|
1886
|
+
preserveAspectRatio: "none",
|
|
1887
|
+
"aria-hidden": "true",
|
|
1888
|
+
"data-idle": idle ? "true" : void 0,
|
|
1889
|
+
style: idle ? { opacity: 0.35 } : void 0,
|
|
1890
|
+
onPointerMove: handlePointerMove,
|
|
1891
|
+
children: [
|
|
1892
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", { id: clipId, children: /* @__PURE__ */ jsx("rect", { x: MARGIN.left, y: MARGIN.top, width: plotWidth, height: plotHeight }) }) }),
|
|
1893
|
+
yTicks.map((tick) => {
|
|
1894
|
+
const y = yScale(tick);
|
|
1895
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
1896
|
+
/* @__PURE__ */ jsx("line", { x1: MARGIN.left, x2: chartWidth - MARGIN.right, y1: y, y2: y, stroke: "var(--border-default)", strokeDasharray: "3 5", strokeOpacity: "0.72" }),
|
|
1897
|
+
/* @__PURE__ */ jsx("text", { "data-axis": "y", x: MARGIN.left - 8, y: y + 3.5, textAnchor: "end", fill: "var(--text-tertiary)", fontSize: "10", fontFamily: "var(--font-mono, ui-monospace, monospace)", children: yFormatter(tick) })
|
|
1898
|
+
] }, `y-${tick}`);
|
|
1899
|
+
}),
|
|
1900
|
+
xTickValues.map((tick) => {
|
|
1901
|
+
const x = xScale(tick);
|
|
1902
|
+
const anchor = x < MARGIN.left + 26 ? "start" : x > chartWidth - MARGIN.right - 26 ? "end" : "middle";
|
|
1903
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
1904
|
+
/* @__PURE__ */ jsx("line", { x1: x, x2: x, y1: MARGIN.top, y2: height - MARGIN.bottom, stroke: "var(--border-default)", strokeOpacity: "0.22" }),
|
|
1905
|
+
/* @__PURE__ */ jsx("text", { "data-axis": "x", x, y: height - 9, textAnchor: anchor, fill: "var(--text-tertiary)", fontSize: "10", fontFamily: "var(--font-mono, ui-monospace, monospace)", children: xFormatter(tick) })
|
|
1906
|
+
] }, `x-${tick}`);
|
|
1907
|
+
}),
|
|
1908
|
+
idle ? [1, 2].map((third) => {
|
|
1909
|
+
const y = MARGIN.top + plotHeight * third / 3;
|
|
1910
|
+
return /* @__PURE__ */ jsx("line", { "data-idle-rule": "true", x1: MARGIN.left, x2: chartWidth - MARGIN.right, y1: y, y2: y, stroke: "var(--border-hairline)", strokeWidth: "1", vectorEffect: "non-scaling-stroke" }, `idle-${third}`);
|
|
1911
|
+
}) : null,
|
|
1912
|
+
/* @__PURE__ */ jsxs("g", { clipPath: `url(#${clipId})`, children: [
|
|
1913
|
+
plottedSeries.map(({ definition, color, segments }) => {
|
|
1914
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
1915
|
+
segments.map((segment, index) => segment.point ? /* @__PURE__ */ jsx("circle", { cx: segment.point.x, cy: segment.point.y, r: collecting ? "2" : "3", fill: color }, `${definition.key}-point-${index}`) : /* @__PURE__ */ jsx("path", { d: segment.path ?? "", fill: "none", stroke: color, strokeWidth: "1.5", strokeDasharray: definition.dashed ? "5 4" : void 0, strokeLinecap: "round", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke" }, `${definition.key}-segment-${index}`)),
|
|
1916
|
+
activePoint ? (() => {
|
|
1917
|
+
const value = validValue(activePoint.values[definition.key]);
|
|
1918
|
+
return value === void 0 ? null : /* @__PURE__ */ jsx("circle", { cx: xScale(activePoint.x), cy: yScale(value), r: "3.25", fill: "var(--bg-card)", stroke: color, strokeWidth: "2", vectorEffect: "non-scaling-stroke" });
|
|
1919
|
+
})() : null
|
|
1920
|
+
] }, definition.key);
|
|
1921
|
+
}),
|
|
1922
|
+
activePoint ? /* @__PURE__ */ jsx("line", { x1: xScale(activePoint.x), x2: xScale(activePoint.x), y1: MARGIN.top, y2: height - MARGIN.bottom, stroke: "var(--text-tertiary)", strokeOpacity: "0.65", strokeDasharray: "3 4", vectorEffect: "non-scaling-stroke" }) : null
|
|
1923
|
+
] })
|
|
1924
|
+
]
|
|
1925
|
+
}
|
|
1926
|
+
) : /* @__PURE__ */ jsx("div", { role: "status", className: "flex min-h-[180px] items-center justify-center rounded-lg border border-dashed border-border text-sm text-muted-foreground", children: noDataText }),
|
|
1927
|
+
collecting && hasPlottableValues ? /* @__PURE__ */ jsx("div", { "data-yunui": "time-series-collecting", className: "pointer-events-none absolute inset-x-0 flex items-center justify-center text-xs text-muted-foreground", style: { top: MARGIN.top, height: height - MARGIN.top - MARGIN.bottom }, children: collectingLabel(points.length, minSamples) }) : null,
|
|
1928
|
+
activePoint && hasPlottableValues ? /* @__PURE__ */ jsxs(
|
|
1929
|
+
"div",
|
|
1930
|
+
{
|
|
1931
|
+
"aria-hidden": "true",
|
|
1932
|
+
className: "pointer-events-none absolute top-1 z-10 max-h-40 overflow-auto rounded-lg border border-border bg-card px-3 py-2 shadow-lg",
|
|
1933
|
+
style: { left: tooltipLeft, maxWidth: tooltipMaxWidth, transform: "translateX(-50%)" },
|
|
1934
|
+
children: [
|
|
1935
|
+
/* @__PURE__ */ jsx("p", { className: "yunui-fine-print mb-1 whitespace-nowrap font-mono text-[10px] text-muted-foreground", children: xFormatter(activePoint.x) }),
|
|
1936
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-1", children: definitions.map((definition) => {
|
|
1937
|
+
const value = validValue(activePoint.values[definition.key]);
|
|
1938
|
+
const color = definition.color ?? TONE_COLOR2[definition.tone ?? "accent"];
|
|
1939
|
+
return /* @__PURE__ */ jsxs("div", { className: "yunui-fine-print flex min-w-0 items-baseline justify-between gap-4 text-[11px]", children: [
|
|
1940
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", style: { color }, children: definition.label }),
|
|
1941
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0 font-mono tabular-nums text-foreground", children: value === void 0 ? missingValueLabel : yFormatter(value) })
|
|
1942
|
+
] }, definition.key);
|
|
1943
|
+
}) })
|
|
1944
|
+
]
|
|
1945
|
+
}
|
|
1946
|
+
) : null
|
|
1947
|
+
]
|
|
1948
|
+
}
|
|
1949
|
+
),
|
|
1950
|
+
showReadout && readoutPoint ? /* @__PURE__ */ jsxs("div", { className: "mt-2 flex min-h-8 flex-wrap items-baseline gap-x-3 gap-y-1 rounded-md bg-muted/40 px-2.5 py-2 text-[11px] yunui-fine-print", "aria-live": "off", "data-yunui": "time-series-readout", children: [
|
|
1951
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono text-muted-foreground", children: xFormatter(readoutPoint.x) }),
|
|
1952
|
+
definitions.map((definition) => {
|
|
1953
|
+
const value = validValue(readoutPoint.values[definition.key]);
|
|
1954
|
+
const visible = !hiddenKeys.has(definition.key);
|
|
1955
|
+
return /* @__PURE__ */ jsxs("span", { className: cn("inline-flex items-baseline gap-1", !visible && "opacity-50"), children: [
|
|
1956
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: definition.label }),
|
|
1957
|
+
/* @__PURE__ */ jsx("span", { className: "yunui-readout-value font-mono tabular-nums text-foreground", children: value === void 0 ? missingValueLabel : yFormatter(value) })
|
|
1958
|
+
] }, definition.key);
|
|
1959
|
+
})
|
|
1960
|
+
] }) : null,
|
|
1961
|
+
/* @__PURE__ */ jsxs("figcaption", { className: "sr-only", children: [
|
|
1962
|
+
ariaLabel,
|
|
1963
|
+
". ",
|
|
1964
|
+
keyboardHint
|
|
1965
|
+
] }),
|
|
1966
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", "data-yunui": "time-series-keyboard-announcement", "aria-live": keyboardAnnouncement ? "polite" : "off", "aria-atomic": "true", children: keyboardAnnouncement })
|
|
1967
|
+
] });
|
|
1968
|
+
}
|
|
1969
|
+
var TONE_COLOR3 = {
|
|
1970
|
+
accent: "var(--accent-solid-strong)",
|
|
1971
|
+
success: "var(--success-solid-strong)",
|
|
1972
|
+
warning: "var(--warning-solid-strong)",
|
|
1973
|
+
error: "var(--danger-solid-strong)",
|
|
1974
|
+
info: "var(--info-solid-strong)",
|
|
1975
|
+
neutral: "var(--neutral-solid-strong)"
|
|
1976
|
+
};
|
|
1977
|
+
var TONE_TEXT = {
|
|
1978
|
+
accent: "var(--accent-on-solid-strong)",
|
|
1979
|
+
success: "var(--success-on-solid-strong)",
|
|
1980
|
+
warning: "var(--warning-on-solid-strong)",
|
|
1981
|
+
error: "var(--danger-on-solid-strong)",
|
|
1982
|
+
info: "var(--info-on-solid-strong)",
|
|
1983
|
+
neutral: "var(--neutral-on-solid-strong)"
|
|
1984
|
+
};
|
|
1985
|
+
var monoColor = (index) => `color-mix(in srgb, var(--color-foreground) ${Math.max(16, 58 - index * 16)}%, transparent)`;
|
|
1986
|
+
var valueText = (value, formatValue) => formatValue ? formatValue(value) : String(value);
|
|
1987
|
+
var BAR_SLOT_PX = 56;
|
|
1988
|
+
var BAR_GUTTER_PX = 56;
|
|
1989
|
+
function BarChart({
|
|
1990
|
+
data,
|
|
1991
|
+
ariaLabel,
|
|
1992
|
+
formatValue,
|
|
1993
|
+
emptyLabel = "No data",
|
|
1994
|
+
unavailableLabel = "Unavailable",
|
|
1995
|
+
height = 240,
|
|
1996
|
+
onSelect,
|
|
1997
|
+
className
|
|
1998
|
+
}) {
|
|
1999
|
+
const values = data.map(
|
|
2000
|
+
(datum) => typeof datum.value === "number" && Number.isFinite(datum.value) && datum.value >= 0 ? datum.value : null
|
|
2001
|
+
);
|
|
2002
|
+
const max = Math.max(0, ...values.filter((value) => value !== null));
|
|
2003
|
+
const scroller = useRef(null);
|
|
2004
|
+
const [width, setWidth] = useState(0);
|
|
2005
|
+
useLayoutEffect(() => {
|
|
2006
|
+
const el = scroller.current;
|
|
2007
|
+
if (!el) return;
|
|
2008
|
+
setWidth(el.clientWidth);
|
|
2009
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
2010
|
+
const observer = new ResizeObserver(() => setWidth(el.clientWidth));
|
|
2011
|
+
observer.observe(el);
|
|
2012
|
+
return () => observer.disconnect();
|
|
2013
|
+
}, [data.length === 0]);
|
|
2014
|
+
const room = width > 0 ? Math.max(1, width - BAR_GUTTER_PX) : Number.POSITIVE_INFINITY;
|
|
2015
|
+
const fits = data.length * BAR_SLOT_PX <= room;
|
|
2016
|
+
const every = fits ? 1 : Math.max(1, Math.ceil(data.length * BAR_SLOT_PX / room));
|
|
2017
|
+
if (data.length === 0) {
|
|
2018
|
+
return /* @__PURE__ */ jsx("div", { role: "img", "aria-label": ariaLabel, className: cn("flex items-center justify-center text-sm text-muted-foreground", className), style: { height }, children: emptyLabel });
|
|
2019
|
+
}
|
|
2020
|
+
return /* @__PURE__ */ jsx("div", { role: "group", "aria-label": ariaLabel, className: cn("w-full", className), children: /* @__PURE__ */ jsxs("div", { ref: scroller, "data-fit": fits ? void 0 : "true", className: cn("relative min-w-0 border-b border-border/60 pb-2", fits ? "overflow-x-auto" : "overflow-x-hidden"), style: { height }, children: [
|
|
2021
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "absolute left-1 top-1 text-[10px] tabular-nums text-muted-foreground", children: valueText(max, formatValue) }),
|
|
2022
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "absolute bottom-8 left-1 text-[10px] tabular-nums text-muted-foreground", children: "0" }),
|
|
2023
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "absolute bottom-8 left-7 top-8 border-l border-border/60" }),
|
|
2024
|
+
/* @__PURE__ */ jsx("div", { className: cn("flex h-full min-w-0 items-end px-2 pl-10 pt-5", fits ? "gap-3" : "gap-1"), children: data.map((datum, index) => {
|
|
2025
|
+
const value = values[index];
|
|
2026
|
+
const unavailable = value === null;
|
|
2027
|
+
const percent = value === null ? 0 : max > 0 ? value / max * 100 : 0;
|
|
2028
|
+
const color = datum.color ?? TONE_COLOR3[datum.tone ?? "accent"];
|
|
2029
|
+
const text = unavailable ? unavailableLabel : valueText(value, formatValue);
|
|
2030
|
+
const label = `${datum.label}: ${text}`;
|
|
2031
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("group flex h-full flex-1 flex-col items-center justify-end gap-2", fits ? "min-w-14" : "min-w-0"), children: [
|
|
2032
|
+
/* @__PURE__ */ jsx("span", { className: cn("max-w-28 truncate text-center text-xs tabular-nums text-muted-foreground", index % every !== 0 && "invisible"), children: text }),
|
|
2033
|
+
/* @__PURE__ */ jsx("div", { className: "flex min-h-0 w-full flex-1 items-end justify-center", children: /* @__PURE__ */ jsx(
|
|
2034
|
+
"div",
|
|
2035
|
+
{
|
|
2036
|
+
role: onSelect ? "button" : "img",
|
|
2037
|
+
"aria-label": label,
|
|
2038
|
+
"aria-disabled": onSelect ? unavailable || void 0 : void 0,
|
|
2039
|
+
tabIndex: 0,
|
|
2040
|
+
onClick: (event) => {
|
|
2041
|
+
if (unavailable) return;
|
|
2042
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
2043
|
+
onSelect?.(datum);
|
|
2044
|
+
},
|
|
2045
|
+
onKeyDown: (event) => {
|
|
2046
|
+
if (onSelect && (event.key === "Enter" || event.key === " ")) {
|
|
2047
|
+
event.preventDefault();
|
|
2048
|
+
if (!unavailable) onSelect(datum);
|
|
2049
|
+
}
|
|
2050
|
+
},
|
|
2051
|
+
className: cn(
|
|
2052
|
+
"relative flex w-full max-w-12 justify-center rounded-t-md outline-none transition-[height,opacity] focus-visible:ring-2 focus-visible:ring-accent-solid-strong focus-visible:ring-offset-2",
|
|
2053
|
+
unavailable ? "min-h-1 border border-dashed border-border bg-muted/50" : value === 0 ? "h-px" : "",
|
|
2054
|
+
onSelect && !unavailable && "cursor-pointer hover:opacity-80",
|
|
2055
|
+
onSelect && unavailable && "cursor-not-allowed"
|
|
2056
|
+
),
|
|
2057
|
+
style: unavailable ? { height: "5%" } : { height: value === 0 ? "1px" : `${Math.max(percent, 2)}%`, backgroundColor: color },
|
|
2058
|
+
title: label
|
|
2059
|
+
}
|
|
2060
|
+
) }),
|
|
2061
|
+
/* @__PURE__ */ jsx("span", { className: cn("max-w-28 truncate text-center text-xs text-foreground", index % every !== 0 && "invisible"), children: datum.label })
|
|
2062
|
+
] }, `${datum.id}:${index}`);
|
|
2063
|
+
}) })
|
|
2064
|
+
] }) });
|
|
2065
|
+
}
|
|
2066
|
+
function DonutChart({
|
|
2067
|
+
data,
|
|
2068
|
+
ariaLabel,
|
|
2069
|
+
formatValue,
|
|
2070
|
+
emptyLabel = "No data",
|
|
2071
|
+
unavailableLabel = "Unavailable",
|
|
2072
|
+
center,
|
|
2073
|
+
monochrome = false,
|
|
2074
|
+
size = 208,
|
|
2075
|
+
onSelect,
|
|
2076
|
+
className
|
|
2077
|
+
}) {
|
|
2078
|
+
const values = data.map(
|
|
2079
|
+
(datum) => typeof datum.value === "number" && Number.isFinite(datum.value) && datum.value >= 0 ? datum.value : null
|
|
2080
|
+
);
|
|
2081
|
+
const total = values.reduce((sum, value) => sum + (value ?? 0), 0);
|
|
2082
|
+
const hasValidValues = values.some((value) => value !== null);
|
|
2083
|
+
let cursor = 0;
|
|
2084
|
+
const stops = data.flatMap((datum, index) => {
|
|
2085
|
+
const value = values[index];
|
|
2086
|
+
if (value === null || value <= 0 || total <= 0) return [];
|
|
2087
|
+
const start = cursor / total * 100;
|
|
2088
|
+
cursor += value;
|
|
2089
|
+
const end = cursor / total * 100;
|
|
2090
|
+
return [`${datum.color ?? (monochrome ? monoColor(index) : TONE_COLOR3[datum.tone ?? "accent"])} ${start}% ${end}%`];
|
|
2091
|
+
});
|
|
2092
|
+
const ring = total > 0 ? `conic-gradient(${stops.join(", ")})` : "conic-gradient(var(--border) 0% 100%)";
|
|
2093
|
+
return /* @__PURE__ */ jsxs("figure", { role: "group", "aria-label": ariaLabel, className: cn("flex min-w-0 flex-wrap items-center justify-center gap-6", className), children: [
|
|
2094
|
+
/* @__PURE__ */ jsx("div", { className: "relative shrink-0 rounded-full", style: { width: `min(${size}px, 100%)`, aspectRatio: "1 / 1", background: ring }, "aria-hidden": "true", children: /* @__PURE__ */ jsx("div", { className: "absolute inset-[18%] flex items-center justify-center overflow-hidden rounded-full border border-border/60 bg-background px-2 text-center text-sm font-medium tabular-nums", children: center ?? (hasValidValues ? valueText(total, formatValue) : emptyLabel) }) }),
|
|
2095
|
+
/* @__PURE__ */ jsx("ul", { className: "m-0 grid min-w-44 flex-1 list-none gap-2 p-0", children: data.length === 0 ? /* @__PURE__ */ jsx("li", { className: "text-sm text-muted-foreground", children: emptyLabel }) : data.map((datum, index) => {
|
|
2096
|
+
const value = values[index];
|
|
2097
|
+
const available = value !== null;
|
|
2098
|
+
const percent = available && total > 0 ? value / total * 100 : null;
|
|
2099
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2100
|
+
/* @__PURE__ */ jsx("span", { className: "mt-1 size-2.5 shrink-0 rounded-sm", style: { backgroundColor: available ? datum.color ?? (monochrome ? monoColor(index) : TONE_COLOR3[datum.tone ?? "accent"]) : "var(--border)" }, "aria-hidden": "true" }),
|
|
2101
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: datum.label }),
|
|
2102
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0 text-muted-foreground tabular-nums", children: available ? valueText(value, formatValue) : unavailableLabel }),
|
|
2103
|
+
/* @__PURE__ */ jsx("span", { className: "w-12 shrink-0 text-right text-muted-foreground tabular-nums", children: percent === null ? "\u2014" : `${percent.toFixed(1)}%` })
|
|
2104
|
+
] });
|
|
2105
|
+
return /* @__PURE__ */ jsx("li", { children: onSelect ? /* @__PURE__ */ jsx("button", { type: "button", disabled: !available, className: "flex w-full items-start gap-2 rounded-md px-2 py-1 text-left text-sm outline-none hover:bg-muted/60 focus-visible:ring-2 focus-visible:ring-accent-solid-strong disabled:cursor-not-allowed disabled:opacity-60", onClick: (event) => {
|
|
2106
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
2107
|
+
onSelect(datum);
|
|
2108
|
+
}, children: content }) : /* @__PURE__ */ jsx("div", { className: "flex items-start gap-2 px-2 py-1 text-sm", children: content }) }, `${datum.id}:${index}`);
|
|
2109
|
+
}) })
|
|
2110
|
+
] });
|
|
2111
|
+
}
|
|
2112
|
+
function Heatmap({
|
|
2113
|
+
rows,
|
|
2114
|
+
columns,
|
|
2115
|
+
data,
|
|
2116
|
+
ariaLabel,
|
|
2117
|
+
formatValue,
|
|
2118
|
+
emptyLabel = "No data",
|
|
2119
|
+
unavailableLabel = "Unavailable",
|
|
2120
|
+
tone = "accent",
|
|
2121
|
+
onSelect,
|
|
2122
|
+
className
|
|
2123
|
+
}) {
|
|
2124
|
+
const [active, setActive] = useState({ row: 0, column: 0 });
|
|
2125
|
+
const [hovered, setHovered] = useState(null);
|
|
2126
|
+
const refs = useRef([]);
|
|
2127
|
+
const color = TONE_COLOR3[tone];
|
|
2128
|
+
const values = useMemo(() => rows.flatMap((_, rowIndex) => columns.map((_2, columnIndex) => {
|
|
2129
|
+
const value = data[rowIndex]?.[columnIndex];
|
|
2130
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
2131
|
+
})), [rows, columns, data]);
|
|
2132
|
+
const maxMagnitude = Math.max(0, ...values.filter((value) => value !== null).map(Math.abs));
|
|
2133
|
+
const hasCells = rows.length > 0 && columns.length > 0;
|
|
2134
|
+
const rowCount = rows.length;
|
|
2135
|
+
const columnCount = columns.length;
|
|
2136
|
+
const readout = hovered ?? active;
|
|
2137
|
+
const activeRow = Math.min(active.row, Math.max(rowCount - 1, 0));
|
|
2138
|
+
const activeColumn = Math.min(active.column, Math.max(columnCount - 1, 0));
|
|
2139
|
+
useEffect(() => {
|
|
2140
|
+
setActive({ row: 0, column: 0 });
|
|
2141
|
+
setHovered(null);
|
|
2142
|
+
refs.current = [];
|
|
2143
|
+
}, [rowCount, columnCount]);
|
|
2144
|
+
const focusCell = (row, column) => {
|
|
2145
|
+
const next = { row: Math.max(0, Math.min(rowCount - 1, row)), column: Math.max(0, Math.min(columnCount - 1, column)) };
|
|
2146
|
+
setActive(next);
|
|
2147
|
+
refs.current[next.row * columnCount + next.column]?.focus();
|
|
2148
|
+
};
|
|
2149
|
+
const moveFocus = (event, row, column) => {
|
|
2150
|
+
let nextRow = row;
|
|
2151
|
+
let nextColumn = column;
|
|
2152
|
+
if (event.key === "ArrowUp") nextRow--;
|
|
2153
|
+
else if (event.key === "ArrowDown") nextRow++;
|
|
2154
|
+
else if (event.key === "ArrowLeft") nextColumn--;
|
|
2155
|
+
else if (event.key === "ArrowRight") nextColumn++;
|
|
2156
|
+
else if (event.key === "Home") nextColumn = 0;
|
|
2157
|
+
else if (event.key === "End") nextColumn = columnCount - 1;
|
|
2158
|
+
else return;
|
|
2159
|
+
event.preventDefault();
|
|
2160
|
+
focusCell(nextRow, nextColumn);
|
|
2161
|
+
};
|
|
2162
|
+
if (!hasCells) return /* @__PURE__ */ jsx("div", { role: "img", "aria-label": ariaLabel, className: cn("p-4 text-sm text-muted-foreground", className), children: emptyLabel });
|
|
2163
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("min-w-0", className), children: [
|
|
2164
|
+
/* @__PURE__ */ jsxs("div", { role: "grid", "aria-label": ariaLabel, className: "max-w-full overflow-x-auto rounded-md border border-border/60", children: [
|
|
2165
|
+
/* @__PURE__ */ jsxs("div", { role: "row", className: "grid w-max min-w-full border-b border-border/60", style: { gridTemplateColumns: `minmax(7rem,auto) repeat(${columnCount}, minmax(3.25rem, 1fr))` }, children: [
|
|
2166
|
+
/* @__PURE__ */ jsx("span", { role: "columnheader", className: "sticky left-0 z-10 bg-background p-2 text-xs font-medium text-muted-foreground" }),
|
|
2167
|
+
columns.map((column, index) => /* @__PURE__ */ jsx("span", { role: "columnheader", className: "p-2 text-center text-xs font-medium text-muted-foreground", children: column }, `${column}:${index}`))
|
|
2168
|
+
] }),
|
|
2169
|
+
rows.map((row, rowIndex) => /* @__PURE__ */ jsxs("div", { role: "row", className: "grid w-max min-w-full border-b border-border/40 last:border-0", style: { gridTemplateColumns: `minmax(7rem,auto) repeat(${columnCount}, minmax(3.25rem, 1fr))` }, children: [
|
|
2170
|
+
/* @__PURE__ */ jsx("span", { role: "rowheader", className: "sticky left-0 z-10 flex items-center bg-background px-2 py-1 text-xs font-medium", children: row }),
|
|
2171
|
+
columns.map((column, columnIndex) => {
|
|
2172
|
+
const index = rowIndex * columnCount + columnIndex;
|
|
2173
|
+
const value = values[index];
|
|
2174
|
+
const unavailable = value === null;
|
|
2175
|
+
const label = `${row}, ${column}: ${unavailable ? unavailableLabel : valueText(value, formatValue)}`;
|
|
2176
|
+
const opacity = unavailable || maxMagnitude === 0 ? 0 : Math.max(0.12, Math.abs(value) / maxMagnitude);
|
|
2177
|
+
return /* @__PURE__ */ jsx("div", { className: "group relative p-1", children: /* @__PURE__ */ jsx(
|
|
2178
|
+
"button",
|
|
2179
|
+
{
|
|
2180
|
+
ref: (node) => {
|
|
2181
|
+
refs.current[index] = node;
|
|
2182
|
+
},
|
|
2183
|
+
type: "button",
|
|
2184
|
+
role: "gridcell",
|
|
2185
|
+
"aria-label": label,
|
|
2186
|
+
tabIndex: activeRow === rowIndex && activeColumn === columnIndex ? 0 : -1,
|
|
2187
|
+
onFocus: () => setActive({ row: rowIndex, column: columnIndex }),
|
|
2188
|
+
onMouseEnter: () => setHovered({ row: rowIndex, column: columnIndex }),
|
|
2189
|
+
onMouseLeave: () => setHovered(null),
|
|
2190
|
+
onClick: (event) => {
|
|
2191
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
2192
|
+
setActive({ row: rowIndex, column: columnIndex });
|
|
2193
|
+
onSelect?.(rowIndex, columnIndex);
|
|
2194
|
+
},
|
|
2195
|
+
onKeyDown: (event) => moveFocus(event, rowIndex, columnIndex),
|
|
2196
|
+
className: cn("relative flex h-9 w-full min-w-12 items-center justify-center rounded-sm border border-border/50 text-xs tabular-nums outline-none focus-visible:z-20 focus-visible:ring-2 focus-visible:ring-accent-solid-strong", unavailable ? "border-dashed bg-muted/50 text-muted-foreground" : "hover:border-foreground/60"),
|
|
2197
|
+
style: unavailable ? void 0 : { backgroundColor: `color-mix(in srgb, ${color} ${opacity * 100}%, transparent)`, color: opacity >= 0.55 ? TONE_TEXT[tone] : "var(--foreground)" },
|
|
2198
|
+
title: label,
|
|
2199
|
+
children: /* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: unavailable ? unavailableLabel : valueText(value, formatValue) })
|
|
2200
|
+
}
|
|
2201
|
+
) }, `${rowIndex}:${columnIndex}`);
|
|
2202
|
+
})
|
|
2203
|
+
] }, `${row}:${rowIndex}`))
|
|
2204
|
+
] }),
|
|
2205
|
+
(() => {
|
|
2206
|
+
const row = rows[readout.row];
|
|
2207
|
+
const column = columns[readout.column];
|
|
2208
|
+
const value = data[readout.row]?.[readout.column];
|
|
2209
|
+
if (row === void 0 || column === void 0) return null;
|
|
2210
|
+
const available = typeof value === "number" && Number.isFinite(value);
|
|
2211
|
+
return /* @__PURE__ */ jsxs("p", { "aria-live": "off", className: "mt-2 break-words text-xs text-muted-foreground", children: [
|
|
2212
|
+
row,
|
|
2213
|
+
" \xB7 ",
|
|
2214
|
+
column,
|
|
2215
|
+
": ",
|
|
2216
|
+
available ? valueText(value, formatValue) : unavailableLabel
|
|
2217
|
+
] });
|
|
2218
|
+
})()
|
|
2219
|
+
] });
|
|
2220
|
+
}
|
|
2221
|
+
var defaultClassNames = {
|
|
2222
|
+
toast: "bg-card border border-border rounded-xl shadow-lg p-4",
|
|
2223
|
+
title: "text-sm font-medium",
|
|
2224
|
+
description: "text-xs text-muted-foreground",
|
|
2225
|
+
actionButton: "bg-foreground text-background text-xs px-3 py-1.5 rounded-lg",
|
|
2226
|
+
cancelButton: "text-muted-foreground text-xs px-3 py-1.5 rounded-lg hover:bg-muted"
|
|
2227
|
+
};
|
|
2228
|
+
function Toaster({
|
|
2229
|
+
position = "bottom-right",
|
|
2230
|
+
visibleToasts = 1,
|
|
2231
|
+
expand = true,
|
|
2232
|
+
toastOptions,
|
|
2233
|
+
...props
|
|
2234
|
+
}) {
|
|
2235
|
+
return /* @__PURE__ */ jsx(
|
|
2236
|
+
Toaster$1,
|
|
2237
|
+
{
|
|
2238
|
+
...props,
|
|
2239
|
+
position,
|
|
2240
|
+
visibleToasts,
|
|
2241
|
+
expand,
|
|
2242
|
+
toastOptions: {
|
|
2243
|
+
...toastOptions,
|
|
2244
|
+
classNames: {
|
|
2245
|
+
...defaultClassNames,
|
|
2246
|
+
...toastOptions?.classNames
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
);
|
|
2251
|
+
}
|
|
2252
|
+
var extras = (options) => ({
|
|
2253
|
+
...options?.action ? { action: { label: options.action.label, onClick: () => options.action.onClick() } } : {},
|
|
2254
|
+
...options?.duration !== void 0 ? { duration: options.duration } : {},
|
|
2255
|
+
...options?.id !== void 0 ? { id: options.id } : {}
|
|
2256
|
+
});
|
|
2257
|
+
var toast = {
|
|
2258
|
+
success: (message, description, options) => {
|
|
2259
|
+
toast$1.success(message, {
|
|
2260
|
+
description,
|
|
2261
|
+
...extras(options),
|
|
2262
|
+
icon: /* @__PURE__ */ jsx(CheckCircle2, { className: "w-5 h-5 text-success" })
|
|
2263
|
+
});
|
|
2264
|
+
},
|
|
2265
|
+
error: (message, description, options) => {
|
|
2266
|
+
toast$1.error(message, {
|
|
2267
|
+
description,
|
|
2268
|
+
...extras(options),
|
|
2269
|
+
icon: /* @__PURE__ */ jsx(AlertCircle, { className: "w-5 h-5 text-error" })
|
|
2270
|
+
});
|
|
2271
|
+
},
|
|
2272
|
+
info: (message, description, options) => {
|
|
2273
|
+
toast$1.info(message, {
|
|
2274
|
+
description,
|
|
2275
|
+
...extras(options),
|
|
2276
|
+
icon: /* @__PURE__ */ jsx(Info, { className: "w-5 h-5 text-info" })
|
|
2277
|
+
});
|
|
2278
|
+
},
|
|
2279
|
+
warning: (message, description, options) => {
|
|
2280
|
+
toast$1.warning(message, {
|
|
2281
|
+
description,
|
|
2282
|
+
...extras(options),
|
|
2283
|
+
icon: /* @__PURE__ */ jsx(AlertTriangle, { className: "w-5 h-5 text-warning" })
|
|
2284
|
+
});
|
|
2285
|
+
},
|
|
2286
|
+
loading: (message) => {
|
|
2287
|
+
return toast$1.loading(message, {
|
|
2288
|
+
icon: /* @__PURE__ */ jsx(Loader2, { className: "w-5 h-5 animate-spin" })
|
|
2289
|
+
});
|
|
2290
|
+
},
|
|
2291
|
+
dismiss: (id) => {
|
|
2292
|
+
toast$1.dismiss(id);
|
|
2293
|
+
},
|
|
2294
|
+
promise: (promise, messages) => {
|
|
2295
|
+
return toast$1.promise(promise, {
|
|
2296
|
+
loading: messages.loading,
|
|
2297
|
+
success: messages.success,
|
|
2298
|
+
error: messages.error
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2301
|
+
};
|
|
2302
|
+
var useIsoLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
2303
|
+
var CLIPPING_OVERFLOW = /^(auto|scroll|hidden|clip|overlay)$/;
|
|
2304
|
+
function getClippingAncestors(element) {
|
|
2305
|
+
const ancestors = [];
|
|
2306
|
+
for (let ancestor = element.parentElement; ancestor; ancestor = ancestor.parentElement) {
|
|
2307
|
+
if (ancestor === document.body || ancestor === document.documentElement) continue;
|
|
2308
|
+
const style = window.getComputedStyle(ancestor);
|
|
2309
|
+
if (CLIPPING_OVERFLOW.test(style.overflowX || style.overflow) || CLIPPING_OVERFLOW.test(style.overflowY || style.overflow)) {
|
|
2310
|
+
ancestors.push(ancestor);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
return ancestors;
|
|
2314
|
+
}
|
|
2315
|
+
function getClippingBounds(element) {
|
|
2316
|
+
const bounds = {
|
|
2317
|
+
top: 0,
|
|
2318
|
+
right: window.innerWidth,
|
|
2319
|
+
bottom: window.innerHeight,
|
|
2320
|
+
left: 0
|
|
2321
|
+
};
|
|
2322
|
+
for (const ancestor of getClippingAncestors(element)) {
|
|
2323
|
+
const style = window.getComputedStyle(ancestor);
|
|
2324
|
+
const clipsX = CLIPPING_OVERFLOW.test(style.overflowX || style.overflow);
|
|
2325
|
+
const clipsY = CLIPPING_OVERFLOW.test(style.overflowY || style.overflow);
|
|
2326
|
+
const rect = ancestor.getBoundingClientRect();
|
|
2327
|
+
if (clipsX) {
|
|
2328
|
+
bounds.left = Math.max(bounds.left, rect.left);
|
|
2329
|
+
bounds.right = Math.min(bounds.right, rect.right);
|
|
2330
|
+
}
|
|
2331
|
+
if (clipsY) {
|
|
2332
|
+
bounds.top = Math.max(bounds.top, rect.top);
|
|
2333
|
+
bounds.bottom = Math.min(bounds.bottom, rect.bottom);
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
return bounds;
|
|
2337
|
+
}
|
|
2338
|
+
function useAnchoredPosition(open, panelRef, opts) {
|
|
2339
|
+
const gutter = opts?.gutter ?? 8;
|
|
2340
|
+
const minHeight = opts?.minHeight ?? 160;
|
|
2341
|
+
const [pos, setPos] = useState({ shift: 0, maxHeight: void 0, maxWidth: void 0, placement: "bottom" });
|
|
2342
|
+
useIsoLayoutEffect(() => {
|
|
2343
|
+
if (!open) {
|
|
2344
|
+
setPos({ shift: 0, maxHeight: void 0, maxWidth: void 0, placement: "bottom" });
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2347
|
+
const el = panelRef.current;
|
|
2348
|
+
const parent = el?.offsetParent;
|
|
2349
|
+
if (!el || !parent) return;
|
|
2350
|
+
const compute = () => {
|
|
2351
|
+
const parentRect = parent.getBoundingClientRect();
|
|
2352
|
+
const bounds = getClippingBounds(el);
|
|
2353
|
+
const availableWidth = Math.max(0, bounds.right - bounds.left - gutter * 2);
|
|
2354
|
+
const maxWidth = opts?.maxWidth === void 0 ? void 0 : Math.min(opts.maxWidth, availableWidth);
|
|
2355
|
+
const naturalWidth = maxWidth === void 0 ? el.offsetWidth : Math.min(el.offsetWidth, maxWidth);
|
|
2356
|
+
const appliedShift = (Number.parseFloat(el.style.marginLeft) || 0) - (Number.parseFloat(el.style.marginRight) || 0);
|
|
2357
|
+
const naturalLeft = parentRect.left + el.offsetLeft - appliedShift;
|
|
2358
|
+
const naturalRight = naturalLeft + naturalWidth;
|
|
2359
|
+
let dx = 0;
|
|
2360
|
+
if (naturalRight > bounds.right - gutter) dx = bounds.right - gutter - naturalRight;
|
|
2361
|
+
if (naturalLeft + dx < bounds.left + gutter) dx = bounds.left + gutter - naturalLeft;
|
|
2362
|
+
dx = Math.round(dx);
|
|
2363
|
+
const belowSpace = Math.max(0, Math.floor(bounds.bottom - parentRect.bottom - gutter));
|
|
2364
|
+
const aboveSpace = Math.max(0, Math.floor(parentRect.top - bounds.top - gutter));
|
|
2365
|
+
const naturalHeight = el.scrollHeight;
|
|
2366
|
+
const preferredHeight = Math.min(naturalHeight, minHeight);
|
|
2367
|
+
const placement = belowSpace >= preferredHeight || belowSpace >= aboveSpace ? "bottom" : "top";
|
|
2368
|
+
const side = placement === "bottom" ? belowSpace : aboveSpace;
|
|
2369
|
+
const maxHeight = naturalHeight > side ? side : void 0;
|
|
2370
|
+
setPos((current) => current.shift === dx && current.maxHeight === maxHeight && current.maxWidth === maxWidth && current.placement === placement ? current : { shift: dx, maxHeight, maxWidth, placement });
|
|
2371
|
+
};
|
|
2372
|
+
let frame = 0;
|
|
2373
|
+
const scheduleMeasure = () => {
|
|
2374
|
+
if (frame) return;
|
|
2375
|
+
frame = requestAnimationFrame(() => {
|
|
2376
|
+
frame = 0;
|
|
2377
|
+
compute();
|
|
2378
|
+
});
|
|
2379
|
+
};
|
|
2380
|
+
compute();
|
|
2381
|
+
const resizeObserver = typeof ResizeObserver !== "undefined" ? new ResizeObserver(scheduleMeasure) : null;
|
|
2382
|
+
if (resizeObserver) {
|
|
2383
|
+
const observed = /* @__PURE__ */ new Set([el, parent, ...getClippingAncestors(el)]);
|
|
2384
|
+
observed.forEach((element) => resizeObserver.observe(element));
|
|
2385
|
+
}
|
|
2386
|
+
window.addEventListener("resize", compute);
|
|
2387
|
+
window.addEventListener("scroll", scheduleMeasure, { capture: true, passive: true });
|
|
2388
|
+
return () => {
|
|
2389
|
+
if (frame) cancelAnimationFrame(frame);
|
|
2390
|
+
resizeObserver?.disconnect();
|
|
2391
|
+
window.removeEventListener("resize", compute);
|
|
2392
|
+
window.removeEventListener("scroll", scheduleMeasure, true);
|
|
2393
|
+
};
|
|
2394
|
+
}, [open, gutter, minHeight, opts?.maxWidth, panelRef]);
|
|
2395
|
+
return pos;
|
|
2396
|
+
}
|
|
2397
|
+
var YUNUI_PALETTES = [
|
|
2398
|
+
"gray",
|
|
2399
|
+
"sand",
|
|
2400
|
+
"slate",
|
|
2401
|
+
"mint",
|
|
2402
|
+
"rose",
|
|
2403
|
+
"dusk",
|
|
2404
|
+
"red",
|
|
2405
|
+
"orange",
|
|
2406
|
+
"amber",
|
|
2407
|
+
"yellow",
|
|
2408
|
+
"lime",
|
|
2409
|
+
"moss",
|
|
2410
|
+
"green",
|
|
2411
|
+
"emerald",
|
|
2412
|
+
"teal",
|
|
2413
|
+
"aqua",
|
|
2414
|
+
"cyan",
|
|
2415
|
+
"blue",
|
|
2416
|
+
"indigo",
|
|
2417
|
+
"violet",
|
|
2418
|
+
"plum",
|
|
2419
|
+
"magenta",
|
|
2420
|
+
"fuchsia",
|
|
2421
|
+
"pink"
|
|
2422
|
+
];
|
|
2423
|
+
var YUNUI_THEME_PRESETS = {
|
|
2424
|
+
aurora: { label: "Aurora", brand: "blue", accent: "violet", neutral: "slate" },
|
|
2425
|
+
sunset: { label: "Sunset", brand: "orange", accent: "pink", neutral: "sand" },
|
|
2426
|
+
forest: { label: "Forest", brand: "green", accent: "lime", neutral: "gray" },
|
|
2427
|
+
ocean: { label: "Ocean", brand: "cyan", accent: "teal", neutral: "slate" },
|
|
2428
|
+
grape: { label: "Grape", brand: "violet", accent: "magenta", neutral: "dusk" },
|
|
2429
|
+
ember: { label: "Ember", brand: "red", accent: "amber", neutral: "sand" },
|
|
2430
|
+
lagoon: { label: "Lagoon", brand: "teal", accent: "emerald", neutral: "mint" },
|
|
2431
|
+
blossom: { label: "Blossom", brand: "pink", accent: "fuchsia", neutral: "rose" },
|
|
2432
|
+
royal: { label: "Royal", brand: "indigo", accent: "blue", neutral: "slate" },
|
|
2433
|
+
citrus: { label: "Citrus", brand: "lime", accent: "yellow", neutral: "sand" },
|
|
2434
|
+
orchid: { label: "Orchid", brand: "plum", accent: "violet", neutral: "dusk" },
|
|
2435
|
+
mono: { label: "Mono", brand: "gray", accent: "gray", neutral: "gray" }
|
|
2436
|
+
};
|
|
2437
|
+
var ATTR = {
|
|
2438
|
+
brand: "data-brand",
|
|
2439
|
+
accent: "data-accent",
|
|
2440
|
+
neutral: "data-neutral",
|
|
2441
|
+
solid: "data-solid",
|
|
2442
|
+
surface: "data-surface",
|
|
2443
|
+
theme: "data-theme",
|
|
2444
|
+
accentSource: "data-accent-source"
|
|
2445
|
+
};
|
|
2446
|
+
function resolveTarget(el) {
|
|
2447
|
+
if (el) return el;
|
|
2448
|
+
return typeof document !== "undefined" ? document.documentElement : null;
|
|
2449
|
+
}
|
|
2450
|
+
function applyTheme(theme, el) {
|
|
2451
|
+
const target = resolveTarget(el);
|
|
2452
|
+
if (!target) return;
|
|
2453
|
+
for (const key of Object.keys(theme)) {
|
|
2454
|
+
const value = theme[key];
|
|
2455
|
+
const attr = ATTR[key];
|
|
2456
|
+
if (!attr) continue;
|
|
2457
|
+
if (value == null) target.removeAttribute(attr);
|
|
2458
|
+
else target.setAttribute(attr, value);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
function readTheme(el) {
|
|
2462
|
+
const target = resolveTarget(el);
|
|
2463
|
+
const out = {};
|
|
2464
|
+
if (!target) return out;
|
|
2465
|
+
for (const key of Object.keys(ATTR)) {
|
|
2466
|
+
const v = target.getAttribute(ATTR[key]);
|
|
2467
|
+
if (v != null) out[key] = v;
|
|
2468
|
+
}
|
|
2469
|
+
return out;
|
|
2470
|
+
}
|
|
2471
|
+
var STORAGE_KEY = "yunui-theme";
|
|
2472
|
+
function useYunUITheme(defaults = {}) {
|
|
2473
|
+
const [theme, setTheme] = React.useState(defaults);
|
|
2474
|
+
React.useEffect(() => {
|
|
2475
|
+
let stored = {};
|
|
2476
|
+
try {
|
|
2477
|
+
stored = JSON.parse(localStorage.getItem(STORAGE_KEY) || "{}");
|
|
2478
|
+
} catch {
|
|
2479
|
+
}
|
|
2480
|
+
const merged = { ...defaults, ...stored };
|
|
2481
|
+
setTheme(merged);
|
|
2482
|
+
applyTheme(merged);
|
|
2483
|
+
}, []);
|
|
2484
|
+
const update = React.useCallback((patch) => {
|
|
2485
|
+
setTheme((prev) => {
|
|
2486
|
+
const next = { ...prev, ...patch };
|
|
2487
|
+
applyTheme(next);
|
|
2488
|
+
try {
|
|
2489
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
|
|
2490
|
+
} catch {
|
|
2491
|
+
}
|
|
2492
|
+
return next;
|
|
2493
|
+
});
|
|
2494
|
+
}, []);
|
|
2495
|
+
return [theme, update];
|
|
2496
|
+
}
|
|
2497
|
+
function CommandPalette({
|
|
2498
|
+
open,
|
|
2499
|
+
onClose,
|
|
2500
|
+
query,
|
|
2501
|
+
onQueryChange,
|
|
2502
|
+
items = [],
|
|
2503
|
+
loading = false,
|
|
2504
|
+
empty,
|
|
2505
|
+
initial,
|
|
2506
|
+
footer,
|
|
2507
|
+
labels,
|
|
2508
|
+
className
|
|
2509
|
+
}) {
|
|
2510
|
+
const { Link } = useYunUI();
|
|
2511
|
+
const [cursor, setCursor] = useState(0);
|
|
2512
|
+
const inputRef = useRef(null);
|
|
2513
|
+
const listRef = useRef(null);
|
|
2514
|
+
const [mounted, setMounted] = useState(false);
|
|
2515
|
+
const listId = useId();
|
|
2516
|
+
useEffect(() => setMounted(true), []);
|
|
2517
|
+
useEffect(() => setCursor(0), [items]);
|
|
2518
|
+
const { present, shown } = usePresence(open);
|
|
2519
|
+
useEffect(() => {
|
|
2520
|
+
if (open && present && mounted) inputRef.current?.focus();
|
|
2521
|
+
}, [open, present, mounted]);
|
|
2522
|
+
useEffect(() => {
|
|
2523
|
+
if (!open) return;
|
|
2524
|
+
const previous = document.body.style.overflow;
|
|
2525
|
+
document.body.style.overflow = "hidden";
|
|
2526
|
+
return () => {
|
|
2527
|
+
document.body.style.overflow = previous;
|
|
2528
|
+
};
|
|
2529
|
+
}, [open]);
|
|
2530
|
+
const select = useCallback(
|
|
2531
|
+
(item) => {
|
|
2532
|
+
if (!item) return;
|
|
2533
|
+
item.onSelect?.();
|
|
2534
|
+
onClose();
|
|
2535
|
+
},
|
|
2536
|
+
[onClose]
|
|
2537
|
+
);
|
|
2538
|
+
const onKeyDown = (event) => {
|
|
2539
|
+
if (event.key === "Escape") {
|
|
2540
|
+
event.preventDefault();
|
|
2541
|
+
onClose();
|
|
2542
|
+
return;
|
|
2543
|
+
}
|
|
2544
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
2545
|
+
event.preventDefault();
|
|
2546
|
+
if (items.length === 0) return;
|
|
2547
|
+
setCursor((c) => {
|
|
2548
|
+
const next = event.key === "ArrowDown" ? c + 1 : c - 1;
|
|
2549
|
+
const wrapped = (next + items.length) % items.length;
|
|
2550
|
+
listRef.current?.querySelectorAll("[data-command-item]")[wrapped]?.scrollIntoView({ block: "nearest" });
|
|
2551
|
+
return wrapped;
|
|
2552
|
+
});
|
|
2553
|
+
return;
|
|
2554
|
+
}
|
|
2555
|
+
if (event.key === "Enter") {
|
|
2556
|
+
const item = items[cursor];
|
|
2557
|
+
if (item?.href) {
|
|
2558
|
+
listRef.current?.querySelectorAll("[data-command-item]")[cursor]?.click();
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
event.preventDefault();
|
|
2562
|
+
select(item);
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
const grouped = useMemo(() => {
|
|
2566
|
+
const out = [];
|
|
2567
|
+
for (const item of items) {
|
|
2568
|
+
const last = out[out.length - 1];
|
|
2569
|
+
if (last && last.group === item.group) last.items.push(item);
|
|
2570
|
+
else out.push({ group: item.group, items: [item] });
|
|
2571
|
+
}
|
|
2572
|
+
return out;
|
|
2573
|
+
}, [items]);
|
|
2574
|
+
if (!present || !mounted) return null;
|
|
2575
|
+
let index = -1;
|
|
2576
|
+
return createPortal(
|
|
2577
|
+
/* @__PURE__ */ jsx(
|
|
2578
|
+
"div",
|
|
2579
|
+
{
|
|
2580
|
+
role: "dialog",
|
|
2581
|
+
"aria-modal": "true",
|
|
2582
|
+
"aria-label": labels?.title ?? "Search",
|
|
2583
|
+
"data-state": shown ? "open" : "closed",
|
|
2584
|
+
className: cn(
|
|
2585
|
+
"fixed inset-0 z-100 flex items-start justify-center bg-black/40 px-4 pt-[12vh] transition-opacity duration-(--dur-fast) ease-out motion-reduce:transition-none",
|
|
2586
|
+
shown ? "opacity-100" : "opacity-0"
|
|
2587
|
+
),
|
|
2588
|
+
onMouseDown: (e) => {
|
|
2589
|
+
if (e.target === e.currentTarget) onClose();
|
|
2590
|
+
},
|
|
2591
|
+
children: /* @__PURE__ */ jsxs(
|
|
2592
|
+
"div",
|
|
2593
|
+
{
|
|
2594
|
+
onKeyDown,
|
|
2595
|
+
className: cn(
|
|
2596
|
+
"w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-popover shadow-lg shadow-black/5 transition-[opacity,transform] duration-(--dur-fast) ease-out motion-reduce:transition-none",
|
|
2597
|
+
shown ? "translate-y-0 scale-100 opacity-100" : "-translate-y-1 scale-[0.98] opacity-0",
|
|
2598
|
+
className
|
|
2599
|
+
),
|
|
2600
|
+
children: [
|
|
2601
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2.5 border-b border-border px-4", children: [
|
|
2602
|
+
/* @__PURE__ */ jsx(Search, { "aria-hidden": true, className: "h-4 w-4 shrink-0 text-muted-foreground" }),
|
|
2603
|
+
/* @__PURE__ */ jsx(
|
|
2604
|
+
"input",
|
|
2605
|
+
{
|
|
2606
|
+
ref: inputRef,
|
|
2607
|
+
value: query,
|
|
2608
|
+
onChange: (e) => onQueryChange(e.target.value),
|
|
2609
|
+
placeholder: labels?.placeholder ?? "Search\u2026",
|
|
2610
|
+
className: "h-12 flex-1 bg-transparent text-[16px] outline-none placeholder:text-muted-foreground",
|
|
2611
|
+
autoComplete: "off",
|
|
2612
|
+
spellCheck: false,
|
|
2613
|
+
role: "combobox",
|
|
2614
|
+
"aria-expanded": items.length > 0,
|
|
2615
|
+
"aria-controls": listId,
|
|
2616
|
+
"aria-activedescendant": items.length ? `${listId}-${cursor}` : void 0
|
|
2617
|
+
}
|
|
2618
|
+
),
|
|
2619
|
+
loading && /* @__PURE__ */ jsx(Spinner, { className: "h-4 w-4 shrink-0" }),
|
|
2620
|
+
/* @__PURE__ */ jsx(
|
|
2621
|
+
"button",
|
|
2622
|
+
{
|
|
2623
|
+
type: "button",
|
|
2624
|
+
onClick: onClose,
|
|
2625
|
+
"aria-label": labels?.close ?? "Close",
|
|
2626
|
+
className: "rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
2627
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
2628
|
+
}
|
|
2629
|
+
)
|
|
2630
|
+
] }),
|
|
2631
|
+
/* @__PURE__ */ jsx(
|
|
2632
|
+
ScrollFade,
|
|
2633
|
+
{
|
|
2634
|
+
ref: listRef,
|
|
2635
|
+
id: listId,
|
|
2636
|
+
role: "listbox",
|
|
2637
|
+
"aria-label": labels?.title ?? "Search",
|
|
2638
|
+
className: "max-h-[55vh] p-1.5",
|
|
2639
|
+
tabIndex: -1,
|
|
2640
|
+
children: loading && items.length === 0 ? /* @__PURE__ */ jsx("div", { className: "p-8 text-center text-sm text-muted-foreground", children: "\u2026" }) : items.length === 0 ? /* @__PURE__ */ jsx("div", { className: "p-6 text-center text-sm text-muted-foreground", children: query ? empty : initial }) : grouped.map((section, s) => /* @__PURE__ */ jsxs("div", { children: [
|
|
2641
|
+
section.group && /* @__PURE__ */ jsx("div", { className: "px-3 pt-2 pb-1 text-[10px] font-semibold tracking-[0.08em] text-muted-foreground uppercase", children: section.group }),
|
|
2642
|
+
section.items.map((item) => {
|
|
2643
|
+
index += 1;
|
|
2644
|
+
const active = index === cursor;
|
|
2645
|
+
const myIndex = index;
|
|
2646
|
+
const rowClass = cn(
|
|
2647
|
+
"flex w-full items-start gap-2.5 rounded-xl px-3 py-2 text-left transition-colors outline-none",
|
|
2648
|
+
active ? "bg-foreground/5" : "hover:bg-foreground/5"
|
|
2649
|
+
);
|
|
2650
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2651
|
+
item.icon && /* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0 text-muted-foreground", children: item.icon }),
|
|
2652
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
2653
|
+
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm", children: item.title }),
|
|
2654
|
+
item.description && /* @__PURE__ */ jsx("span", { className: "text-caption block truncate", children: item.description })
|
|
2655
|
+
] })
|
|
2656
|
+
] });
|
|
2657
|
+
const shared = {
|
|
2658
|
+
id: `${listId}-${myIndex}`,
|
|
2659
|
+
role: "option",
|
|
2660
|
+
"aria-selected": active,
|
|
2661
|
+
"data-command-item": true,
|
|
2662
|
+
onMouseEnter: () => setCursor(myIndex),
|
|
2663
|
+
className: rowClass
|
|
2664
|
+
};
|
|
2665
|
+
return item.href ? /* @__PURE__ */ jsx(
|
|
2666
|
+
Link,
|
|
2667
|
+
{
|
|
2668
|
+
href: item.href,
|
|
2669
|
+
...shared,
|
|
2670
|
+
onClick: () => {
|
|
2671
|
+
item.onSelect?.();
|
|
2672
|
+
onClose();
|
|
2673
|
+
},
|
|
2674
|
+
children: body
|
|
2675
|
+
},
|
|
2676
|
+
item.id
|
|
2677
|
+
) : /* @__PURE__ */ jsx(
|
|
2678
|
+
"button",
|
|
2679
|
+
{
|
|
2680
|
+
type: "button",
|
|
2681
|
+
...shared,
|
|
2682
|
+
onClick: () => select(item),
|
|
2683
|
+
children: body
|
|
2684
|
+
},
|
|
2685
|
+
item.id
|
|
2686
|
+
);
|
|
2687
|
+
})
|
|
2688
|
+
] }, section.group ?? s))
|
|
2689
|
+
}
|
|
2690
|
+
),
|
|
2691
|
+
footer != null && /* @__PURE__ */ jsx("div", { className: "text-caption flex items-center justify-between gap-3 border-t border-border px-4 py-2.5", children: footer })
|
|
2692
|
+
]
|
|
2693
|
+
}
|
|
2694
|
+
)
|
|
2695
|
+
}
|
|
2696
|
+
),
|
|
2697
|
+
document.body
|
|
2698
|
+
);
|
|
2699
|
+
}
|
|
2700
|
+
function useCommandPaletteShortcut(onOpen) {
|
|
2701
|
+
useEffect(() => {
|
|
2702
|
+
const onKey = (event) => {
|
|
2703
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
|
|
2704
|
+
event.preventDefault();
|
|
2705
|
+
onOpen();
|
|
2706
|
+
}
|
|
2707
|
+
};
|
|
2708
|
+
document.addEventListener("keydown", onKey);
|
|
2709
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
2710
|
+
}, [onOpen]);
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
export { AnimatedNumber, AreaChart, BarChart, BentoCard, BentoGrid, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, CommandPalette, CustomSelect, DonutChart, EmptyValue, FileDropzone, Gauge, Heatmap, ListItem, Marquee, MetricHero, MotionNumber, NavItem, NavTabs, Popover, PopoverAnchor, PopoverClose2 as PopoverClose, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, SegmentMeter, SegmentedBar, SegmentedSelect, ShinyButton, StackedProgress, Switch, TimeSeriesChart, Toaster, YUNUI_PALETTES, YUNUI_THEME_PRESETS, applyTheme, balancedBreaks, meterPosition, readTheme, runViewTransition, segmentBand, stackedFractions, toast, useAnchoredPosition, useCommandPaletteShortcut, useSlidingPill, useViewTransition, useYunUITheme };
|
|
2714
|
+
//# sourceMappingURL=chunk-TMTXJFNN.js.map
|
|
2715
|
+
//# sourceMappingURL=chunk-TMTXJFNN.js.map
|