@yuhuanowo/yunui 0.1.6 → 0.1.7

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 CHANGED
@@ -92,7 +92,7 @@ import { useTranslations } from "next-intl";
92
92
 
93
93
  **工具 / hooks**(从 `@yuhuanowo/yunui` 导出):`cn`、`toast` / `Toaster`(基于 sonner)、`MotionDiv` / `MotionSpan` / `fadeIn` / `staggerContainer` / `staggerItem`、`useEscapeKey` / `useBodyScrollLock` / `useModalBehavior`。
94
94
 
95
- > ⚠️ **`yunui/ai` 的图标素材需要你自备。** `ProviderIcon` / `ModelIcon` / `ModelAvatar` / `ModelCard` 会从 `/icons/providers/*.png`、`/icons/models/*.png` 加载图标 —— 这些素材**不随 npm 包发布**(包里只有 `dist` / `styles`)。消费方需把对应图标放到自己 `public/icons/...` 下(可从本仓库 `site/public/icons/` 取),否则图标会显示为裂图。自定义图标 URL 可通过组件 `iconUrl` prop 传入。(让 base path 可配置 = roadmap 待办。)
95
+ > ⚠️ **`yunui/ai` 的图标素材需要你自备。** `ProviderIcon` / `ModelIcon` / `ModelAvatar` / `ModelCard` 会从 `/icons/providers/*.png`、`/icons/models/*.png` 加载图标 —— 这些素材**不随 npm 包发布**(包里只有 `dist` / `styles`)。消费方需把对应图标托管到 `iconBasePath` 指向的位置(默认 `/icons`,可从本仓库 `site/public/icons/` 取),否则图标会显示为裂图。base path 可通过适配器配置:`<YunUIProvider adapters={{ iconBasePath: "/assets/icons" }}>`(也可指向 CDN)。单个自定义图标 URL 通过组件 `iconUrl` prop 传入,原样使用。
96
96
  >
97
97
  > 同样,`./_deferred/ai-search`(文档 AI 搜索)**未导出** —— 它绑定 `@ai-sdk/react` + 聊天栈,是产品功能而非通用组件,导出会给库强加 ai-sdk peer 依赖。
98
98
 
@@ -33,6 +33,14 @@ interface YunUIAdapters {
33
33
  Image: React.ComponentType<YunUIImageProps>;
34
34
  useRouter: () => YunUIRouter;
35
35
  useT: TranslateFactory;
36
+ /**
37
+ * Base URL/path under which the AI provider/model icon assets are served.
38
+ * The library resolves icons to `<iconBasePath>/providers/*.png` and
39
+ * `<iconBasePath>/models/*.png`. These assets are NOT bundled — host them
40
+ * yourself (e.g. copy this repo's `site/public/icons`) and point this at
41
+ * them (`/icons`, `/assets/icons`, a CDN origin, …). Defaults to `/icons`.
42
+ */
43
+ iconBasePath: string;
36
44
  }
37
45
  declare const YunUIContext: React.Context<YunUIAdapters>;
38
46
  interface YunUIProviderProps {
package/dist/adapters.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use client";
2
- export { YunUIContext, YunUIProvider, useYunUI } from './chunk-XZGNL5A6.js';
2
+ export { YunUIContext, YunUIProvider, useYunUI } from './chunk-T37N6OZA.js';
3
3
  //# sourceMappingURL=adapters.js.map
4
4
  //# sourceMappingURL=adapters.js.map
package/dist/ai.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { copyToClipboard } from './chunk-WASCOOVD.js';
3
- import { cn, ThemeToggle } from './chunk-DRZ7UCRU.js';
4
- import { useYunUI } from './chunk-XZGNL5A6.js';
3
+ import { cn, ThemeToggle } from './chunk-ORS36OUN.js';
4
+ import { useYunUI } from './chunk-T37N6OZA.js';
5
5
  import { useState, useRef, useEffect, useMemo } from 'react';
6
6
  import { AnimatePresence, motion } from 'framer-motion';
7
7
  import { Brain, ChevronUp, ChevronDown, Check, Copy, Waves, SlidersHorizontal, Layers, Fingerprint, Ban, Image, Code, Eye, PauseCircle, Bot, Globe, X, Menu, Radio, Box, Shield, Shuffle, Music, Video, Mic, Volume2, Headphones, Palette, Hash, FileText, MessageSquare, Pencil } from 'lucide-react';
@@ -469,6 +469,10 @@ function getIconPath(providerId) {
469
469
  }
470
470
  return null;
471
471
  }
472
+ function applyIconBase(path, base) {
473
+ if (!path || base === "/icons") return path;
474
+ return path.startsWith("/icons/") ? base + path.slice(6) : path;
475
+ }
472
476
  function ProviderIcon({
473
477
  provider,
474
478
  className = "",
@@ -476,7 +480,7 @@ function ProviderIcon({
476
480
  rounded = false,
477
481
  iconUrl
478
482
  }) {
479
- const { Image } = useYunUI();
483
+ const { Image, iconBasePath } = useYunUI();
480
484
  const [customError, setCustomError] = useState(false);
481
485
  const effectiveIconUrl = iconUrl;
482
486
  if (effectiveIconUrl && !customError) {
@@ -493,7 +497,7 @@ function ProviderIcon({
493
497
  }
494
498
  return /* @__PURE__ */ jsx("img", { src: effectiveIconUrl, alt: provider, width: size, height: size, className: `object-contain ${className}`, onError: () => setCustomError(true) });
495
499
  }
496
- const iconPath = getIconPath(provider);
500
+ const iconPath = applyIconBase(getIconPath(provider), iconBasePath);
497
501
  const getRadiusClass = () => {
498
502
  if (size <= 14) return "rounded-sm";
499
503
  if (size <= 20) return "rounded-md";
@@ -668,7 +672,7 @@ function ModelIcon({
668
672
  size = 20,
669
673
  rounded = false
670
674
  }) {
671
- const { Image } = useYunUI();
675
+ const { Image, iconBasePath } = useYunUI();
672
676
  const [failedPriority, setFailedPriority] = useState(0);
673
677
  const getRadiusClass = () => {
674
678
  if (size <= 14) return "rounded-sm";
@@ -676,7 +680,7 @@ function ModelIcon({
676
680
  return "rounded-lg";
677
681
  };
678
682
  if (failedPriority < 1 && iconUrl && iconUrl.trim()) {
679
- const src = iconUrl.startsWith("http") ? getProxiedImageUrl(iconUrl) : iconUrl.startsWith("/") ? iconUrl : `/icons/models/${iconUrl}`;
683
+ const src = iconUrl.startsWith("http") ? getProxiedImageUrl(iconUrl) : iconUrl.startsWith("/") ? iconUrl : `${iconBasePath}/models/${iconUrl}`;
680
684
  const handleError = () => setFailedPriority(1);
681
685
  if (rounded) {
682
686
  return /* @__PURE__ */ jsx(
@@ -715,7 +719,7 @@ function ModelIcon({
715
719
  if (failedPriority < 2 && developer) {
716
720
  const developerIconFile = getDeveloperIconFile(developer);
717
721
  if (developerIconFile) {
718
- const src = `/icons/models/${developerIconFile}`;
722
+ const src = `${iconBasePath}/models/${developerIconFile}`;
719
723
  const handleError = () => setFailedPriority(2);
720
724
  if (rounded) {
721
725
  return /* @__PURE__ */ jsx(