@joplo-app/kit 0.2.18 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/props.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ /** Shared theme tokens and pure style scales; no host or framework dependency. */
2
+ export declare const SPACING: Record<string, number>;
3
+ export declare const FONT: Record<string, number>;
4
+ export declare const RADIUS: Record<string, number>;
5
+ export declare const INK = "var(--jp-ink)";
6
+ /** 次一级的文字与线条:正文色与底色混合。 */
7
+ export declare const INK2 = "color-mix(in srgb, var(--jp-ink) 78%, var(--jp-bg))";
8
+ export declare const SOFT = "var(--jp-faint)";
9
+ export declare const DIMMED = "var(--jp-muted)";
10
+ export declare const BG = "var(--jp-bg)";
11
+ export declare const SURFACE = "var(--jp-surface)";
12
+ export declare const SUBTLE = "var(--jp-subtle)";
13
+ export declare const LINE = "var(--jp-line)";
14
+ export declare const LINE_STRONG = "var(--jp-line-strong)";
15
+ export declare const ACCENT = "var(--jp-accent)";
16
+ export declare const INFO = "var(--jp-info)";
17
+ export declare const OK = "var(--jp-ok)";
18
+ export declare const WARN = "var(--jp-warn)";
19
+ export declare const DANGER = "var(--jp-danger)";
20
+ export declare const MONO = "var(--jp-font-mono)";
21
+ /** 实心底上的文字:底是正文色(例如 color="dark")时用舞台底色,其余用白色。 */
22
+ export declare const onFill: (c: string) => "var(--jp-bg)" | "#fff";
23
+ /** 某个颜色的浅色底(混入卡片底色,深色主题里也是“浅一点”的那一档)。 */
24
+ export declare const tint: (c: string, pct?: number) => string;
25
+ /** 颜色:dimmed、调色板名(可带 .0-9 色阶)、或原样的 CSS 颜色;无法识别返回 undefined。 */
26
+ export declare function color(v: unknown): string | undefined;
27
+ /** 浅色底(light 变体、Alert 背景):混入主题的卡片底色。 */
28
+ export declare const light: (c: string) => string;
29
+ /** 间距:刻度名 → px;数字 → px;其余字符串原样(如 'auto'、'1rem')。 */
30
+ export declare function space(v: unknown): string | undefined;
31
+ export declare const spaceNum: (v: unknown, d: number) => number;
32
+ /** 尺寸:数字 → px;字符串原样('100%'、'auto')。 */
33
+ export declare function dim(v: unknown): string | undefined;
34
+ export declare function fontSize(v: unknown): string | undefined;
35
+ export declare function radius(v: unknown): string | undefined;
36
+ export declare const TITLE_SIZE: number[];
@@ -0,0 +1,107 @@
1
+ /** Shared theme tokens and pure style scales; no host or framework dependency. */
2
+ export const SPACING = { xs: 10, sm: 12, md: 16, lg: 20, xl: 32 };
3
+ export const FONT = { xs: 12, sm: 14, md: 16, lg: 18, xl: 20 };
4
+ export const RADIUS = { xs: 2, sm: 4, md: 8, lg: 16, xl: 32 };
5
+ // 主题色(D51):全部读主题的 CSS 变量(renderer/themes.ts),不写死颜色
6
+ export const INK = 'var(--jp-ink)';
7
+ /** 次一级的文字与线条:正文色与底色混合。 */
8
+ export const INK2 = 'color-mix(in srgb, var(--jp-ink) 78%, var(--jp-bg))';
9
+ export const SOFT = 'var(--jp-faint)';
10
+ export const DIMMED = 'var(--jp-muted)';
11
+ export const BG = 'var(--jp-bg)';
12
+ export const SURFACE = 'var(--jp-surface)';
13
+ export const SUBTLE = 'var(--jp-subtle)';
14
+ export const LINE = 'var(--jp-line)';
15
+ export const LINE_STRONG = 'var(--jp-line-strong)';
16
+ export const ACCENT = 'var(--jp-accent)';
17
+ export const INFO = 'var(--jp-info)';
18
+ export const OK = 'var(--jp-ok)';
19
+ export const WARN = 'var(--jp-warn)';
20
+ export const DANGER = 'var(--jp-danger)';
21
+ export const MONO = 'var(--jp-font-mono)';
22
+ /** 实心底上的文字:底是正文色(例如 color="dark")时用舞台底色,其余用白色。 */
23
+ export const onFill = (c) => (c === INK || c === 'var(--jp-ink)' ? BG : '#fff');
24
+ /** 某个颜色的浅色底(混入卡片底色,深色主题里也是“浅一点”的那一档)。 */
25
+ export const tint = (c, pct = 12) => `color-mix(in srgb, ${c} ${pct}%, var(--jp-surface))`;
26
+ const PALETTE = {
27
+ dark: 'var(--jp-ink)',
28
+ gray: 'var(--jp-muted)',
29
+ red: 'var(--jp-danger)',
30
+ pink: '#c2255c',
31
+ grape: '#9c36b5',
32
+ violet: '#7048e8',
33
+ indigo: '#4263eb',
34
+ blue: 'var(--jp-info)',
35
+ cyan: '#1098ad',
36
+ teal: '#0ca678',
37
+ green: 'var(--jp-ok)',
38
+ lime: '#66a80f',
39
+ yellow: '#f08c00',
40
+ orange: '#e8590c',
41
+ white: '#ffffff',
42
+ black: '#000000',
43
+ };
44
+ /** 颜色:dimmed、调色板名(可带 .0-9 色阶)、或原样的 CSS 颜色;无法识别返回 undefined。 */
45
+ export function color(v) {
46
+ if (typeof v !== 'string' || !v)
47
+ return undefined;
48
+ if (v === 'dimmed')
49
+ return DIMMED;
50
+ if (v === 'bright' || v === 'ink')
51
+ return INK;
52
+ const m = /^([a-z]+)(?:\.(\d))?$/.exec(v);
53
+ if (m && PALETTE[m[1]]) {
54
+ const base = PALETTE[m[1]];
55
+ if (m[2] === undefined)
56
+ return base;
57
+ const n = Number(m[2]);
58
+ if (n < 6)
59
+ return `color-mix(in srgb, ${base} ${100 - (6 - n) * 15}%, var(--jp-surface))`;
60
+ if (n > 6)
61
+ return `color-mix(in srgb, ${base} ${100 - (n - 6) * 12}%, var(--jp-ink))`;
62
+ return base;
63
+ }
64
+ if (/^(#|rgb|hsl|oklch|var\()/.test(v))
65
+ return v;
66
+ return undefined;
67
+ }
68
+ /** 浅色底(light 变体、Alert 背景):混入主题的卡片底色。 */
69
+ export const light = (c) => `color-mix(in srgb, ${c} 11%, var(--jp-surface))`;
70
+ /** 间距:刻度名 → px;数字 → px;其余字符串原样(如 'auto'、'1rem')。 */
71
+ export function space(v) {
72
+ if (typeof v === 'number' && Number.isFinite(v))
73
+ return `${v}px`;
74
+ if (typeof v !== 'string' || !v)
75
+ return undefined;
76
+ if (v in SPACING)
77
+ return `${SPACING[v]}px`;
78
+ return v;
79
+ }
80
+ export const spaceNum = (v, d) => (typeof v === 'number' ? v : typeof v === 'string' && v in SPACING ? SPACING[v] : d);
81
+ /** 尺寸:数字 → px;字符串原样('100%'、'auto')。 */
82
+ export function dim(v) {
83
+ if (typeof v === 'number' && Number.isFinite(v))
84
+ return `${v}px`;
85
+ if (typeof v === 'string' && v)
86
+ return v in SPACING ? `${SPACING[v]}px` : v;
87
+ return undefined;
88
+ }
89
+ export function fontSize(v) {
90
+ if (typeof v === 'number' && Number.isFinite(v))
91
+ return `${v}px`;
92
+ if (typeof v !== 'string' || !v)
93
+ return undefined;
94
+ if (v in FONT)
95
+ return `${FONT[v]}px`;
96
+ if (/^h[1-6]$/.test(v))
97
+ return `${TITLE_SIZE[Number(v[1]) - 1]}px`;
98
+ return v;
99
+ }
100
+ export function radius(v) {
101
+ if (typeof v === 'number')
102
+ return `${v}px`;
103
+ if (typeof v === 'string' && v)
104
+ return v in RADIUS ? `${RADIUS[v]}px` : v;
105
+ return undefined;
106
+ }
107
+ export const TITLE_SIZE = [30, 24, 20, 17, 15, 14];
@@ -0,0 +1,138 @@
1
+ /** Browser renderer services supplied by the host, shared by React content packages. */
2
+ import type { CSSProperties, ReactNode, ComponentType } from 'react';
3
+ import type { ActionDispatch, EngineFrame, ActionPresentation, PluginIRNode, PluginState } from './plugin.js';
4
+ export type NodeProps = {
5
+ node: PluginIRNode;
6
+ p: Record<string, unknown>;
7
+ disabled: boolean;
8
+ children: ReactNode;
9
+ };
10
+ export type RendererContext = {
11
+ act?: ActionDispatch;
12
+ hover?: (id: string | null) => void;
13
+ interactive?: boolean;
14
+ clock?: EngineFrame;
15
+ gesture?: ActionPresentation | null;
16
+ resetKey?: string;
17
+ playground?: boolean;
18
+ scene: {
19
+ id: string;
20
+ route: string;
21
+ };
22
+ state: PluginState;
23
+ width: number;
24
+ animate: boolean;
25
+ selectedId: string | null;
26
+ focus?: string[] | null;
27
+ ext?: Readonly<Record<string, unknown>>;
28
+ stage?: HTMLElement | null;
29
+ dialogLayer: HTMLElement | null;
30
+ preview: {
31
+ nodeId: string;
32
+ text: string;
33
+ } | null;
34
+ mode: 'review' | 'demo' | 'render';
35
+ changed?: readonly {
36
+ path: string;
37
+ before: unknown;
38
+ after: unknown;
39
+ }[];
40
+ };
41
+ export type RendererServices = {
42
+ motion: Record<keyof import('react').JSX.IntrinsicElements, ComponentType<any>>;
43
+ RendererContextProvider: ComponentType<{
44
+ value: Pick<RendererContext, 'width' | 'dialogLayer'>;
45
+ children?: ReactNode;
46
+ }>;
47
+ useLook(): {
48
+ theme: string;
49
+ font: string | null;
50
+ style: Record<string, string> | undefined;
51
+ };
52
+ atWidth(value: unknown, width: number): unknown;
53
+ childWidth(node: PluginIRNode, width: number, props?: Record<string, unknown>): number;
54
+ choicesOf(node: PluginIRNode, state: PluginState): {
55
+ value: string;
56
+ label: string;
57
+ }[] | null;
58
+ layoutRegions(node: PluginIRNode, state: PluginState, width: number): Record<string, {
59
+ size: number;
60
+ collapsed: boolean;
61
+ mobile: boolean;
62
+ } | null>;
63
+ resolveValue(value: unknown, state: PluginState): unknown;
64
+ styleOf(props: Record<string, unknown>, width: number): CSSProperties;
65
+ nodeLabel(node: PluginIRNode): string;
66
+ useCtx(): RendererContext;
67
+ useI18n(): {
68
+ t: {
69
+ stage: Record<string, unknown>;
70
+ };
71
+ };
72
+ useR(p: Record<string, unknown>): (key: string) => unknown;
73
+ useRoot(n: PluginIRNode, p: Record<string, unknown>, options?: {
74
+ disabled?: boolean;
75
+ className?: string;
76
+ style?: CSSProperties;
77
+ }): Record<string, any>;
78
+ useRootAttrs(n: PluginIRNode, disabled?: boolean): Record<string, any>;
79
+ useStroke(): 'rough' | 'clean';
80
+ RenderNode: ComponentType<{
81
+ node: PluginIRNode;
82
+ }>;
83
+ Rough: ComponentType<any>;
84
+ RoughPath: ComponentType<any>;
85
+ roundRectPath(x: number, y: number, w: number, h: number, radius: number): string;
86
+ rectOf(el: Element): {
87
+ x: number;
88
+ y: number;
89
+ left: number;
90
+ top: number;
91
+ width: number;
92
+ height: number;
93
+ right: number;
94
+ bottom: number;
95
+ };
96
+ resolveProps(n: PluginIRNode, state: PluginState): Record<string, unknown>;
97
+ isSelfVisible(n: PluginIRNode, state: PluginState, width?: number): boolean;
98
+ walkNodes(n: PluginIRNode, visit: (node: PluginIRNode) => void): void;
99
+ };
100
+ export declare function registerRendererServices(services: RendererServices): void;
101
+ export declare const useCtx: () => RendererContext;
102
+ export declare const useI18n: <Messages extends Record<string, unknown>>() => {
103
+ t: {
104
+ stage: Messages;
105
+ };
106
+ };
107
+ export declare const useR: RendererServices['useR'];
108
+ export declare const useRoot: RendererServices['useRoot'];
109
+ export declare const useRootAttrs: RendererServices['useRootAttrs'];
110
+ export declare const useStroke: () => "rough" | "clean";
111
+ export declare const RenderNode: (p: {
112
+ node: PluginIRNode;
113
+ }) => ReactNode;
114
+ export declare const Rough: (p: any) => ReactNode;
115
+ export declare const RoughPath: (p: any) => ReactNode;
116
+ export declare const roundRectPath: RendererServices['roundRectPath'];
117
+ export declare const rectOf: RendererServices['rectOf'];
118
+ export declare const resolveProps: RendererServices['resolveProps'];
119
+ export declare const isSelfVisible: RendererServices['isSelfVisible'];
120
+ export declare const walkNodes: RendererServices['walkNodes'];
121
+ export declare const RendererContextProvider: (props: {
122
+ value: Pick<RendererContext, "width" | "dialogLayer">;
123
+ children?: ReactNode;
124
+ }) => ReactNode;
125
+ export declare const useLook: () => {
126
+ theme: string;
127
+ font: string | null;
128
+ style: Record<string, string> | undefined;
129
+ };
130
+ export declare const atWidth: RendererServices['atWidth'];
131
+ export declare const childWidth: RendererServices['childWidth'];
132
+ export declare const choicesOf: RendererServices['choicesOf'];
133
+ export declare const layoutRegions: RendererServices['layoutRegions'];
134
+ export declare const resolveValue: RendererServices['resolveValue'];
135
+ export declare const styleOf: RendererServices['styleOf'];
136
+ export declare const nodeLabel: RendererServices['nodeLabel'];
137
+ /** Clocked drawing primitives provided by the host; no plugin animation timers. */
138
+ export declare const motion: Record<keyof import("react").JSX.IntrinsicElements, ComponentType<any>>;
@@ -0,0 +1,31 @@
1
+ const KEY = Symbol.for('joplo.renderer.services.v2');
2
+ const global = globalThis;
3
+ export function registerRendererServices(services) { global[KEY] = Object.freeze(services); }
4
+ const host = () => { if (!global[KEY])
5
+ throw new Error('Joplo renderer services are not initialized'); return global[KEY]; };
6
+ export const useCtx = () => host().useCtx();
7
+ export const useI18n = () => host().useI18n();
8
+ export const useR = (...args) => host().useR(...args);
9
+ export const useRoot = (...args) => host().useRoot(...args);
10
+ export const useRootAttrs = (...args) => host().useRootAttrs(...args);
11
+ export const useStroke = () => host().useStroke();
12
+ // Function components delegate to the host's identical React context, adding no DOM wrapper.
13
+ export const RenderNode = (p) => host().RenderNode(p);
14
+ export const Rough = (p) => host().Rough(p);
15
+ export const RoughPath = (p) => host().RoughPath(p);
16
+ export const roundRectPath = (...args) => host().roundRectPath(...args);
17
+ export const rectOf = (...args) => host().rectOf(...args);
18
+ export const resolveProps = (...args) => host().resolveProps(...args);
19
+ export const isSelfVisible = (...args) => host().isSelfVisible(...args);
20
+ export const walkNodes = (...args) => host().walkNodes(...args);
21
+ export const RendererContextProvider = (props) => host().RendererContextProvider(props);
22
+ export const useLook = () => host().useLook();
23
+ export const atWidth = (...args) => host().atWidth(...args);
24
+ export const childWidth = (...args) => host().childWidth(...args);
25
+ export const choicesOf = (...args) => host().choicesOf(...args);
26
+ export const layoutRegions = (...args) => host().layoutRegions(...args);
27
+ export const resolveValue = (...args) => host().resolveValue(...args);
28
+ export const styleOf = (...args) => host().styleOf(...args);
29
+ export const nodeLabel = (...args) => host().nodeLabel(...args);
30
+ /** Clocked drawing primitives provided by the host; no plugin animation timers. */
31
+ export const motion = new Proxy({}, { get: (_target, key) => host().motion[key] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/kit",
3
- "version": "0.2.18",
3
+ "version": "0.4.0",
4
4
  "description": "Joplo 创作 SDK:组件、feature/option/flow 与 JSX 运行时(收集成数据,不作为 React 执行)",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",
@@ -9,10 +9,6 @@
9
9
  "types": "./dist/index.d.ts",
10
10
  "default": "./dist/index.js"
11
11
  },
12
- "./ui": {
13
- "types": "./dist/ui.d.ts",
14
- "default": "./dist/ui.js"
15
- },
16
12
  "./jsx-runtime": {
17
13
  "types": "./dist/jsx-runtime.d.ts",
18
14
  "default": "./dist/jsx-runtime.js"
@@ -25,7 +21,19 @@
25
21
  "types": "./dist/node.d.ts",
26
22
  "default": "./dist/node.js"
27
23
  },
28
- "./package.json": "./package.json"
24
+ "./plugin": {
25
+ "types": "./dist/plugin.d.ts",
26
+ "default": "./dist/plugin.js"
27
+ },
28
+ "./package.json": "./package.json",
29
+ "./renderer": {
30
+ "types": "./dist/renderer.d.ts",
31
+ "default": "./dist/renderer.js"
32
+ },
33
+ "./renderer-style": {
34
+ "types": "./dist/renderer-style.d.ts",
35
+ "default": "./dist/renderer-style.js"
36
+ }
29
37
  },
30
38
  "files": [
31
39
  "dist"
@@ -45,6 +53,9 @@
45
53
  "bugs": {
46
54
  "url": "https://github.com/Joplo-app/Joplo/issues"
47
55
  },
56
+ "devDependencies": {
57
+ "@types/react": "^19.3.0"
58
+ },
48
59
  "scripts": {
49
60
  "build": "node ../../scripts/build-package.mjs"
50
61
  }