feat: add shared infiplot workspace packages

Signed-off-by: baizhi958216 <1475289190@qq.com>
This commit is contained in:
baizhi958216
2026-06-30 00:44:36 +08:00
parent caca4369aa
commit e585bb2eed
17 changed files with 240 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
{
"name": "@infiplot/api-client",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
}
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@infiplot/types": "workspace:*"
},
"devDependencies": {
"typescript": "^6.0.3"
}
}
+36
View File
@@ -0,0 +1,36 @@
import type { SceneRequest, SceneResponse } from "@infiplot/types";
export interface InfiplotApiClientOptions {
baseUrl: string;
fetcher?: typeof fetch;
}
export class InfiplotApiClient {
private readonly baseUrl: string;
private readonly fetcher: typeof fetch;
constructor(options: InfiplotApiClientOptions) {
this.baseUrl = options.baseUrl.replace(/\/$/, "");
this.fetcher = options.fetcher ?? fetch;
}
async createScene(request: SceneRequest): Promise<SceneResponse> {
return this.post<SceneResponse>("/api/scene", request);
}
private async post<TResponse>(path: string, body: unknown): Promise<TResponse> {
const response = await this.fetcher(`${this.baseUrl}${path}`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error(`Infiplot API request failed: ${response.status}`);
}
return response.json() as Promise<TResponse>;
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2022", "DOM"],
"noEmit": true
},
"include": ["src/**/*.ts"]
}
+21
View File
@@ -0,0 +1,21 @@
{
"name": "@infiplot/core",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
}
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@infiplot/types": "workspace:*"
},
"devDependencies": {
"typescript": "^6.0.3"
}
}
+12
View File
@@ -0,0 +1,12 @@
import type { Locale } from "@infiplot/types";
const DEFAULT_LOCALE: Locale = "zh-CN";
const SUPPORTED_LOCALES = new Set<Locale>(["en", "ja", "zh-CN"]);
export function normalizeLocale(locale: string | undefined): Locale {
if (locale && SUPPORTED_LOCALES.has(locale as Locale)) {
return locale as Locale;
}
return DEFAULT_LOCALE;
}
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src/**/*.ts"]
}
+18
View File
@@ -0,0 +1,18 @@
{
"name": "@infiplot/types",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
}
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"typescript": "^6.0.3"
}
}
+33
View File
@@ -0,0 +1,33 @@
export type Locale = "en" | "ja" | "zh-CN";
export type ApiResult<TData, TError = ApiError> =
| { ok: true; data: TData }
| { ok: false; error: TError };
export interface ApiError {
code: string;
message: string;
details?: unknown;
}
export interface StorySummary {
id: string;
title: string;
description?: string;
locale: Locale;
coverImageUrl?: string;
updatedAt?: string;
}
export interface SceneRequest {
storyId?: string;
prompt: string;
locale?: Locale;
}
export interface SceneResponse {
sceneId: string;
text: string;
imageUrl?: string;
audioUrl?: string;
}
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src/**/*.ts"]
}
+25
View File
@@ -0,0 +1,25 @@
{
"name": "@infiplot/ui",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": {
"react-native": "./src/index.native.tsx",
"types": "./src/index.ts",
"default": "./src/index.web.tsx"
}
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"react": ">=19",
"react-native": ">=0.85"
},
"devDependencies": {
"@types/react": "~19.2.2",
"react-native": "0.85.3",
"typescript": "^6.0.3"
}
}
+2
View File
@@ -0,0 +1,2 @@
export type { SurfaceProps } from "./surface.types";
export { Surface } from "./surface.native";
+1
View File
@@ -0,0 +1 @@
export type { SurfaceProps } from "./surface.types";
+2
View File
@@ -0,0 +1,2 @@
export type { SurfaceProps } from "./surface.types";
export { Surface } from "./surface.web";
+16
View File
@@ -0,0 +1,16 @@
import { View } from "react-native";
import type { ViewStyle } from "react-native";
import type { SurfaceProps } from "./surface.types";
const styles: Record<NonNullable<SurfaceProps["tone"]>, ViewStyle> = {
default: {
backgroundColor: "#ffffff"
},
muted: {
backgroundColor: "#f4f6f8"
}
};
export function Surface({ children, tone = "default" }: SurfaceProps) {
return <View style={styles[tone]}>{children}</View>;
}
+6
View File
@@ -0,0 +1,6 @@
import type { ReactNode } from "react";
export interface SurfaceProps {
children: ReactNode;
tone?: "default" | "muted";
}
+17
View File
@@ -0,0 +1,17 @@
import type { CSSProperties } from "react";
import type { SurfaceProps } from "./surface.types";
const styles: Record<NonNullable<SurfaceProps["tone"]>, CSSProperties> = {
default: {
backgroundColor: "#ffffff",
color: "#111827"
},
muted: {
backgroundColor: "#f4f6f8",
color: "#111827"
}
};
export function Surface({ children, tone = "default" }: SurfaceProps) {
return <div style={styles[tone]}>{children}</div>;
}
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"noEmit": true
},
"include": ["src/**/*.ts", "src/**/*.tsx"]
}