@omem-ai/plugin-sdk 0.0.1 → 0.0.2
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 +126 -1
- package/dist/agent-login.d.ts +69 -0
- package/dist/blocks.d.ts +58 -9
- package/dist/blocks.js +229 -222
- package/dist/charts.d.ts +125 -0
- package/dist/charts.js +686 -0
- package/dist/client.d.ts +18 -1
- package/dist/credential.d.ts +181 -0
- package/dist/hook.d.ts +50 -0
- package/dist/objects.d.ts +85 -0
- package/dist/server.d.ts +355 -0
- package/dist/server.js +1 -0
- package/dist/slots.d.ts +58 -0
- package/package.json +4 -1
package/dist/blocks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { metricsElement as M, mountChart as _ } from "./charts.js";
|
|
2
|
+
const A = ["ask", "view"], q = `
|
|
2
3
|
.ob { display: grid; gap: 12px; min-width: 0; color: var(--ink); }
|
|
3
4
|
.ob h3 { margin: 0; font: 600 16px/1.35 var(--serif); }
|
|
4
5
|
.ob h4 { margin: 4px 0 0; font: 600 14.5px/1.4 var(--serif); }
|
|
@@ -18,13 +19,16 @@ const P = ["ask", "view"], Z = `
|
|
|
18
19
|
.ob .ob-spacer { flex: 1; }
|
|
19
20
|
.ob .ob-err { color: var(--danger); font-size: 12.5px; }
|
|
20
21
|
.ob .ob-value { color: var(--ink-2); overflow-wrap: anywhere; white-space: pre-wrap; }
|
|
21
|
-
.ob
|
|
22
|
-
.ob .ob-
|
|
23
|
-
.ob .ob-
|
|
24
|
-
.ob .ob-
|
|
25
|
-
.ob .ob-
|
|
26
|
-
.ob .ob-
|
|
27
|
-
.ob .ob-
|
|
22
|
+
.ob .ob-chart + *, .ob * + .ob-chart { margin-top: 8px; }
|
|
23
|
+
.ob .ob-callout { --c: var(--accent); display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px 14px; border-radius: 8px; background: var(--sunken); }
|
|
24
|
+
.ob .ob-callout[data-tone="success"] { --c: var(--ok); }
|
|
25
|
+
.ob .ob-callout[data-tone="warning"] { --c: var(--warn); }
|
|
26
|
+
.ob .ob-callout[data-tone="danger"] { --c: var(--danger); }
|
|
27
|
+
.ob .ob-callout[data-tone="neutral"] { --c: var(--muted); }
|
|
28
|
+
.ob .ob-callout-icon { width: 16px; height: 16px; margin-top: 4px; fill: none; stroke: var(--c); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
|
|
29
|
+
.ob .ob-callout-body { display: grid; gap: 2px; min-width: 0; }
|
|
30
|
+
.ob .ob-callout-body > b { color: var(--ink); font-weight: 650; }
|
|
31
|
+
.ob .ob-callout-body .prose > :first-child, .ob .ob-callout-body .prose > :last-child { margin-top: 0; margin-bottom: 0; }
|
|
28
32
|
.ob details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
|
|
29
33
|
.ob .ob-scroll { overflow-x: auto; max-width: 100%; }
|
|
30
34
|
.ob table { border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
|
|
@@ -33,9 +37,6 @@ const P = ["ask", "view"], Z = `
|
|
|
33
37
|
.ob thead th button { all: unset; cursor: pointer; }
|
|
34
38
|
.ob thead th button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
35
39
|
.ob td.num { text-align: right; font-variant-numeric: tabular-nums; }
|
|
36
|
-
.ob .ob-metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
|
|
37
|
-
.ob .ob-metric { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 2px; min-width: 0; }
|
|
38
|
-
.ob .ob-metric b { font: 600 20px/1.2 var(--sans); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
39
40
|
.ob .ob-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
|
|
40
41
|
.ob .ob-pcard { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 6px; align-content: start; min-width: 0; background: var(--panel); text-align: left; font: inherit; color: inherit; }
|
|
41
42
|
.ob button.ob-pcard { cursor: pointer; }
|
|
@@ -51,295 +52,301 @@ const P = ["ask", "view"], Z = `
|
|
|
51
52
|
.ob .ob-check:last-child { border-bottom: 0; }
|
|
52
53
|
.ob .ob-rank { list-style: none; margin: 0; padding: 0; }
|
|
53
54
|
.ob .ob-rank .ob-check { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
|
|
54
|
-
.ob {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
.ob .ob-list { list-style: none; margin: 0; padding: 0; display: grid; }
|
|
56
|
+
.ob .ob-list li { display: grid; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--line); min-width: 0; }
|
|
57
|
+
.ob .ob-list li:first-child { padding-top: 2px; }
|
|
58
|
+
.ob .ob-list li:last-child { border-bottom: 0; padding-bottom: 0; }
|
|
59
|
+
.ob .ob-li-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
|
|
60
|
+
.ob .ob-li-head .badge { flex: none; height: 19px; font-size: 12px; transform: translateY(-1px); }
|
|
61
|
+
.ob .ob-li-title { font-size: 14px; font-weight: 600; line-height: 1.55; min-width: 0; overflow-wrap: anywhere; }
|
|
62
|
+
.ob .ob-li-title a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
|
|
63
|
+
.ob .ob-li-title a:hover { text-decoration-color: currentColor; }
|
|
64
|
+
.ob .ob-li-title a::after { content: " ↗"; color: var(--muted); font-weight: 400; }
|
|
65
|
+
.ob .ob-list li > .ob-md, .ob .ob-list li > .ob-md .prose { color: var(--ink-2); font-size: 13px; line-height: 1.65; }
|
|
66
|
+
.ob .ob-list li > .ob-md .prose > :first-child { margin-top: 0; }
|
|
67
|
+
.ob .ob-list li > .ob-md .prose > :last-child { margin-bottom: 0; }
|
|
68
|
+
.ob .ob-group { display: grid; gap: 4px; min-width: 0; }
|
|
69
|
+
.ob .ob-caption { font-size: 13px; font-weight: 650; color: var(--ink-2); }
|
|
70
|
+
.ob .ob-kv { display: grid; grid-template-columns: repeat(var(--kv, 2), minmax(0, 1fr)); gap: 10px 16px; margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--sunken); }
|
|
71
|
+
.ob .ob-kv > div { display: grid; gap: 1px; min-width: 0; }
|
|
72
|
+
.ob .ob-kv dt { color: var(--muted); font-size: 12px; line-height: 1.5; }
|
|
73
|
+
.ob .ob-kv dd { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
|
|
74
|
+
.ob .ob-fold { border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; }
|
|
75
|
+
.ob .ob-fold > summary { padding: 8px 0; color: var(--ink-2); font-size: 13px; font-weight: 600; list-style-position: inside; }
|
|
76
|
+
.ob .ob-fold[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 8px; }
|
|
77
|
+
.ob .ob-fold > .ob-md { padding-bottom: 10px; }
|
|
78
|
+
|
|
79
|
+
.ob .ob-figure { margin: 0; display: grid; gap: 6px; justify-items: start; }
|
|
80
|
+
.ob .ob-figure img { max-width: 100%; max-height: 480px; border-radius: 8px; border: 1px solid var(--line); }
|
|
81
|
+
@media (max-width: 520px) { .ob .ob-timeline li { grid-template-columns: minmax(0, 1fr); } .ob .ob-kv { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
58
82
|
`;
|
|
59
|
-
function
|
|
83
|
+
function C(t) {
|
|
60
84
|
if (t.getElementById("omem-block-style")) return;
|
|
61
|
-
const
|
|
62
|
-
|
|
85
|
+
const a = t.createElement("style");
|
|
86
|
+
a.id = "omem-block-style", a.textContent = q, t.head.appendChild(a);
|
|
63
87
|
}
|
|
64
|
-
function e(t,
|
|
65
|
-
const
|
|
66
|
-
for (const [
|
|
67
|
-
|
|
68
|
-
for (const
|
|
69
|
-
return
|
|
88
|
+
function e(t, a, o = {}, ...i) {
|
|
89
|
+
const n = t.createElement(a);
|
|
90
|
+
for (const [s, d] of Object.entries(o))
|
|
91
|
+
d === void 0 || d === !1 || (typeof d == "function" ? n.addEventListener(s.replace(/^on/, ""), d) : n.setAttribute(s, d === !0 ? "" : String(d)));
|
|
92
|
+
for (const s of i) s != null && s !== !1 && n.append(typeof s == "string" ? t.createTextNode(s) : s);
|
|
93
|
+
return n;
|
|
70
94
|
}
|
|
71
|
-
const
|
|
72
|
-
function
|
|
73
|
-
const
|
|
74
|
-
for (const [
|
|
75
|
-
return
|
|
95
|
+
const D = "http://www.w3.org/2000/svg";
|
|
96
|
+
function S(t, a, o = {}, i) {
|
|
97
|
+
const n = t.createElementNS(D, a);
|
|
98
|
+
for (const [s, d] of Object.entries(o)) n.setAttribute(s, String(d));
|
|
99
|
+
return n;
|
|
76
100
|
}
|
|
77
|
-
const
|
|
78
|
-
function
|
|
79
|
-
for (const
|
|
80
|
-
|
|
101
|
+
const w = /* @__PURE__ */ new WeakMap();
|
|
102
|
+
function z(t) {
|
|
103
|
+
for (const a of w.get(t) ?? []) a();
|
|
104
|
+
w.delete(t);
|
|
81
105
|
}
|
|
82
|
-
function
|
|
83
|
-
if (!
|
|
84
|
-
if (
|
|
85
|
-
const
|
|
86
|
-
t.replaceChildren(
|
|
87
|
-
const
|
|
88
|
-
return
|
|
106
|
+
function W(t, a, o) {
|
|
107
|
+
if (!A.includes(a.kind)) return !1;
|
|
108
|
+
if (C(t.ownerDocument), z(t), a.kind === "view") {
|
|
109
|
+
const i = a.data, n = e(t.ownerDocument, "section", { class: "ob card pad", "aria-label": i.title || "展示" });
|
|
110
|
+
t.replaceChildren(n), i.title && n.append(e(t.ownerDocument, "h3", {}, i.title));
|
|
111
|
+
const s = e(t.ownerDocument, "div", { class: "ob" });
|
|
112
|
+
return n.append(s), $(s, i.components, o, t), !0;
|
|
89
113
|
}
|
|
90
|
-
return t.replaceChildren(
|
|
114
|
+
return t.replaceChildren(K(t, a, o)), !0;
|
|
91
115
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
|
|
116
|
+
function $(t, a, o = {}, i = t) {
|
|
117
|
+
const n = t.ownerDocument;
|
|
118
|
+
C(n), i === t && z(t), t.classList.add("ob"), t.replaceChildren(...a.map((s) => I(n, s, o, i)));
|
|
95
119
|
}
|
|
96
|
-
function
|
|
97
|
-
switch (
|
|
120
|
+
function I(t, a, o, i) {
|
|
121
|
+
switch (a.type) {
|
|
98
122
|
case "markdown":
|
|
99
|
-
return
|
|
123
|
+
return y(t, a.text, o);
|
|
100
124
|
case "heading":
|
|
101
|
-
return e(t, "h4", {},
|
|
125
|
+
return e(t, "h4", {}, a.text);
|
|
102
126
|
case "table":
|
|
103
|
-
return
|
|
127
|
+
return V(t, a);
|
|
104
128
|
case "chart":
|
|
105
|
-
return
|
|
129
|
+
return G(t, a, i);
|
|
106
130
|
case "metric":
|
|
107
|
-
return
|
|
131
|
+
return M(t, { title: a.title, note: a.note, items: a.items.map(({ label: n, value: s, unit: d, change: f, trend: g, good: c, note: p, spark: r }) => ({ label: n, value: s, unit: d, change: f, trend: g, good: c, note: p, spark: r })) });
|
|
132
|
+
case "callout":
|
|
133
|
+
return Z(t, a, o);
|
|
108
134
|
case "compare":
|
|
109
|
-
return e(t, "div", { class: "ob-field" },
|
|
135
|
+
return e(t, "div", { class: "ob-field" }, a.title ? e(t, "span", { class: "ob-label" }, a.title) : null, e(t, "div", { class: "ob-cards" }, ...a.items.map((n) => N(t, e(t, "div", { class: "ob-pcard" }), n))));
|
|
110
136
|
case "page":
|
|
111
|
-
return e(t, "p", { class: "ob-muted" }, `交互页“${
|
|
137
|
+
return e(t, "p", { class: "ob-muted" }, `交互页“${a.title || a.id}”:在 omem 的问答页里打开`);
|
|
112
138
|
case "timeline":
|
|
113
|
-
return e(t, "ol", { class: "ob-timeline" }, ...
|
|
139
|
+
return e(t, "ol", { class: "ob-timeline" }, ...a.items.map((n) => e(t, "li", {}, e(t, "time", {}, n.time), e(t, "div", {}, e(t, "div", { class: "ob-label" }, n.title), n.text ? e(t, "p", { class: "ob-muted ob-text" }, n.text) : null))));
|
|
140
|
+
case "list":
|
|
141
|
+
return B(t, a, o);
|
|
142
|
+
case "fields":
|
|
143
|
+
return e(t, "dl", { class: "ob-kv", style: `--kv: ${a.items.length <= 4 ? a.items.length : a.items.length % 3 === 0 ? 3 : 4}` }, ...a.items.map((n) => e(t, "div", {}, e(t, "dt", {}, n.label), e(t, "dd", {}, n.value))));
|
|
144
|
+
case "fold": {
|
|
145
|
+
const n = y(t, a.text, o);
|
|
146
|
+
return e(t, "details", { class: "ob-fold", open: !!a.open }, e(t, "summary", {}, a.title), n);
|
|
147
|
+
}
|
|
148
|
+
case "image":
|
|
149
|
+
return e(
|
|
150
|
+
t,
|
|
151
|
+
"figure",
|
|
152
|
+
{ class: "ob-figure" },
|
|
153
|
+
L(a.url) ? e(t, "img", { src: a.url, alt: a.alt ?? a.caption ?? "", loading: "lazy", referrerpolicy: "no-referrer" }) : e(t, "p", { class: "ob-muted" }, "(图片地址不可用)"),
|
|
154
|
+
a.caption ? e(t, "figcaption", { class: "ob-muted" }, a.caption) : null
|
|
155
|
+
);
|
|
114
156
|
}
|
|
115
157
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
158
|
+
const L = (t) => !!t && /^https?:\/\//i.test(t), j = { info: "accent", success: "ok", warning: "warn", danger: "danger", neutral: "" };
|
|
159
|
+
function B(t, a, o) {
|
|
160
|
+
const i = a.items.map((n) => {
|
|
161
|
+
const s = L(n.url) ? e(t, "a", { href: n.url, target: "_blank", rel: "noopener" }, n.title) : e(t, "span", {}, n.title), d = n.tag ? e(t, "span", { class: `badge ${j[n.tone ?? "neutral"]}` }, n.tag) : null;
|
|
162
|
+
return e(t, "li", {}, e(t, "div", { class: "ob-li-head" }, d, e(t, "span", { class: "ob-li-title" }, s)), n.text ? y(t, n.text, o) : null);
|
|
163
|
+
});
|
|
164
|
+
return e(t, "div", { class: "ob-group" }, a.title ? e(t, "div", { class: "ob-caption" }, a.title) : null, e(t, "ul", { class: "ob-list" }, ...i));
|
|
119
165
|
}
|
|
120
|
-
function
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
166
|
+
function y(t, a, o) {
|
|
167
|
+
const i = e(t, "div", { class: "ob-md" });
|
|
168
|
+
return o.markdown ? o.markdown(i, a) : (i.classList.add("ob-text"), i.textContent = a), i;
|
|
169
|
+
}
|
|
170
|
+
function N(t, a, o) {
|
|
171
|
+
const i = [
|
|
172
|
+
e(t, "span", { class: "ob-label" }, o.title),
|
|
173
|
+
o.summary ? e(t, "p", { class: "ob-text" }, o.summary) : null,
|
|
174
|
+
o.pros?.length ? e(t, "ul", { "aria-label": "优点" }, ...o.pros.map((n) => e(t, "li", { class: "ob-pro" }, n))) : null,
|
|
175
|
+
o.cons?.length ? e(t, "ul", { "aria-label": "代价" }, ...o.cons.map((n) => e(t, "li", { class: "ob-con" }, n))) : null
|
|
126
176
|
];
|
|
127
|
-
return
|
|
177
|
+
return a.append(...i.filter((n) => !!n)), a;
|
|
178
|
+
}
|
|
179
|
+
const E = {
|
|
180
|
+
info: "M8 1.5a6.5 6.5 0 1 1 0 13 6.5 6.5 0 0 1 0-13ZM8 7.2v3.8M8 5v.2",
|
|
181
|
+
success: "M8 1.5a6.5 6.5 0 1 1 0 13 6.5 6.5 0 0 1 0-13ZM5.3 8.2l1.8 1.8 3.6-3.8",
|
|
182
|
+
warning: "M8 2 14.5 13.5h-13ZM8 6.5v3.2M8 11.4v.2",
|
|
183
|
+
danger: "M8 1.5a6.5 6.5 0 1 1 0 13 6.5 6.5 0 0 1 0-13ZM5.9 5.9l4.2 4.2M10.1 5.9l-4.2 4.2"
|
|
184
|
+
};
|
|
185
|
+
function Z(t, a, o) {
|
|
186
|
+
const i = a.tone ?? "info", n = S(t, "svg", { viewBox: "0 0 16 16", class: "ob-callout-icon", "aria-hidden": "true" });
|
|
187
|
+
n.append(S(t, "path", { d: E[i] ?? E.info }));
|
|
188
|
+
const s = { info: "说明", success: "达成", warning: "注意", danger: "风险", neutral: "说明" }[i];
|
|
189
|
+
return e(t, "div", { class: "ob-callout", "data-tone": i, role: "note", "aria-label": s }, n, e(t, "div", { class: "ob-callout-body" }, a.title ? e(t, "b", {}, a.title) : null, y(t, a.text, o)));
|
|
128
190
|
}
|
|
129
|
-
const
|
|
130
|
-
function
|
|
131
|
-
let
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
const { col:
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
return (
|
|
191
|
+
const O = (t) => typeof t == "number" || typeof t == "string" && t.trim() !== "" && Number.isFinite(Number(t));
|
|
192
|
+
function V(t, a) {
|
|
193
|
+
let o = null;
|
|
194
|
+
const i = e(t, "tbody"), n = a.columns.map((g, c) => a.rows.length > 0 && a.rows.every((p) => p[c] === null || p[c] === void 0 || p[c] === "" || O(p[c]))), s = () => {
|
|
195
|
+
const g = [...a.rows];
|
|
196
|
+
if (o) {
|
|
197
|
+
const { col: c, dir: p } = o;
|
|
198
|
+
g.sort((r, l) => {
|
|
199
|
+
const b = r[c], h = l[c];
|
|
200
|
+
return (n[c] ? Number(b ?? -1 / 0) - Number(h ?? -1 / 0) : String(b ?? "").localeCompare(String(h ?? ""), "zh-CN")) * p;
|
|
139
201
|
});
|
|
140
202
|
}
|
|
141
|
-
|
|
142
|
-
},
|
|
143
|
-
const
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
}),
|
|
147
|
-
}),
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
function U(t, n, a) {
|
|
151
|
-
const o = e(t, "div", { class: "ob-field" });
|
|
152
|
-
let i = 0;
|
|
153
|
-
const b = () => {
|
|
154
|
-
const c = Math.max(280, Math.min(900, Math.round(o.clientWidth || a.clientWidth || 600)));
|
|
155
|
-
Math.abs(c - i) < 8 || (i = c, o.replaceChildren(...X(t, n, c)));
|
|
156
|
-
};
|
|
157
|
-
if (b(), typeof ResizeObserver < "u") {
|
|
158
|
-
const c = new ResizeObserver(b);
|
|
159
|
-
c.observe(o), D.set(a, [...D.get(a) ?? [], c]);
|
|
160
|
-
}
|
|
161
|
-
return o;
|
|
203
|
+
i.replaceChildren(...g.map((c) => e(t, "tr", {}, ...a.columns.map((p, r) => e(t, "td", n[r] ? { class: "num" } : {}, c[r] === null || c[r] === void 0 ? "" : String(c[r]))))));
|
|
204
|
+
}, d = a.columns.map((g, c) => {
|
|
205
|
+
const p = e(t, "th", { scope: "col", "aria-sort": "none" }), r = e(t, "button", { type: "button", title: "排序" }, g);
|
|
206
|
+
return r.addEventListener("click", () => {
|
|
207
|
+
o = o?.col === c ? o.dir === 1 ? { col: c, dir: -1 } : null : { col: c, dir: 1 }, f.querySelectorAll("th").forEach((l, b) => l.setAttribute("aria-sort", o?.col === b ? o.dir === 1 ? "ascending" : "descending" : "none")), s();
|
|
208
|
+
}), p.append(r), p;
|
|
209
|
+
}), f = e(t, "thead", {}, e(t, "tr", {}, ...d));
|
|
210
|
+
return s(), e(t, "div", { class: "ob-field" }, a.title ? e(t, "span", { class: "ob-label" }, a.title) : null, e(t, "div", { class: "ob-scroll" }, e(t, "table", {}, f, i)), a.note ? e(t, "p", { class: "ob-muted" }, a.note) : null);
|
|
162
211
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
t,
|
|
167
|
-
"details",
|
|
168
|
-
{},
|
|
169
|
-
e(t, "summary", {}, "看数据"),
|
|
170
|
-
e(t, "div", { class: "ob-scroll" }, e(t, "table", {}, e(t, "thead", {}, e(t, "tr", {}, e(t, "th", {}, ""), ...i.map((u) => e(t, "th", {}, u.name)))), e(t, "tbody", {}, ...n.labels.map((u, y) => e(t, "tr", {}, e(t, "th", {}, u), ...i.map((v) => e(t, "td", { class: "num" }, `${q(v.values[y])}${n.unit ?? ""}`)))))))
|
|
171
|
-
), c = n.note ? e(t, "p", { class: "ob-muted" }, n.note) : null;
|
|
172
|
-
if (n.kind === "pie") {
|
|
173
|
-
const u = i[0].values.map((S) => Math.max(0, S)), y = u.reduce((S, $) => S + $, 0) || 1, v = 180, M = 80, L = v / 2, k = v / 2, N = E(t, "svg", { viewBox: `0 0 ${v} ${v}`, role: "img", "aria-label": n.title, style: `max-width:${v}px` });
|
|
174
|
-
let w = -Math.PI / 2;
|
|
175
|
-
u.forEach((S, $) => {
|
|
176
|
-
const I = w + S / y * Math.PI * 2, B = I - w > Math.PI ? 1 : 0, V = S >= y ? E(t, "circle", { cx: L, cy: k, r: M, fill: A($) }) : E(t, "path", { d: `M${L},${k} L${L + M * Math.cos(w)},${k + M * Math.sin(w)} A${M},${M} 0 ${B} 1 ${L + M * Math.cos(I)},${k + M * Math.sin(I)} Z`, fill: A($), stroke: "var(--panel)", "stroke-width": 1.5 });
|
|
177
|
-
V.append(E(t, "title", {}, `${n.labels[$]}:${q(S)}${n.unit ?? ""}(${Math.round(S / y * 100)}%)`)), N.append(V), w = I;
|
|
178
|
-
});
|
|
179
|
-
const _ = e(t, "div", { class: "ob-legend" }, ...n.labels.map((S, $) => e(t, "span", { class: "ob-key" }, e(t, "i", { style: `background:${A($)}` }), `${S} ${Math.round(u[$] / y * 100)}%`)));
|
|
180
|
-
return [o, N, _, c, b].filter((S) => !!S);
|
|
181
|
-
}
|
|
182
|
-
const C = 200, f = 36, h = 8, d = 10, s = 26, l = i.flatMap((u) => u.values), r = Math.min(0, ...l), g = Math.max(0, ...l) || 1, p = (u) => d + (C - d - s) * (1 - (u - r) / (g - r)), x = (a - f - h) / n.labels.length, m = E(t, "svg", { viewBox: `0 0 ${a} ${C}`, role: "img", "aria-label": `${n.title}${n.unit ? `(${n.unit})` : ""}` });
|
|
183
|
-
for (const u of [r, (r + g) / 2, g])
|
|
184
|
-
m.append(E(t, "line", { x1: f, x2: a - h, y1: p(u), y2: p(u), class: "ob-grid" })), m.append(E(t, "text", { x: f - 6, y: p(u) + 4, "text-anchor": "end", class: "ob-tick" }, q(u)));
|
|
185
|
-
m.append(E(t, "line", { x1: f, x2: a - h, y1: p(0), y2: p(0), class: "ob-axis" }));
|
|
186
|
-
const z = Math.max(1, Math.ceil(n.labels.length / Math.max(2, Math.floor(a / 56))));
|
|
187
|
-
if (n.labels.forEach((u, y) => {
|
|
188
|
-
y % z === 0 && m.append(E(t, "text", { x: f + x * (y + 0.5), y: C - 8, "text-anchor": "middle", class: "ob-tick" }, u.length > 8 ? u.slice(0, 7) + "…" : u));
|
|
189
|
-
}), n.kind === "line")
|
|
190
|
-
i.forEach((u, y) => {
|
|
191
|
-
const v = u.values.map((M, L) => [f + x * (L + 0.5), p(M)]);
|
|
192
|
-
m.append(E(t, "polyline", { points: v.map((M) => M.join(",")).join(" "), fill: "none", stroke: A(y), "stroke-width": 2, "stroke-linejoin": "round", "stroke-linecap": "round" })), v.forEach(([M, L], k) => {
|
|
193
|
-
const N = E(t, "circle", { cx: M, cy: L, r: 4, fill: A(y), stroke: "var(--panel)", "stroke-width": 2 });
|
|
194
|
-
N.append(E(t, "title", {}, `${n.labels[k]} · ${u.name}:${q(u.values[k])}${n.unit ?? ""}`)), m.append(N);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
else {
|
|
198
|
-
const u = i.length, y = 2, v = Math.max(2, Math.min(28, (x * 0.7 - y * (u - 1)) / u));
|
|
199
|
-
i.forEach((M, L) => {
|
|
200
|
-
M.values.forEach((k, N) => {
|
|
201
|
-
const w = f + x * (N + 0.5) - (u * v + y * (u - 1)) / 2 + L * (v + y), _ = p(Math.max(k, 0)), S = Math.max(0, Math.abs(p(k) - p(0))), $ = Math.min(4, v / 2, S), I = k >= 0 ? `M${w},${p(0)} V${_ + $} Q${w},${_} ${w + $},${_} H${w + v - $} Q${w + v},${_} ${w + v},${_ + $} V${p(0)} Z` : `M${w},${p(0)} V${p(k) - $} Q${w},${p(k)} ${w + $},${p(k)} H${w + v - $} Q${w + v},${p(k)} ${w + v},${p(k) - $} V${p(0)} Z`, B = E(t, "path", { d: I, fill: A(L) });
|
|
202
|
-
B.append(E(t, "title", {}, `${n.labels[N]} · ${M.name}:${q(k)}${n.unit ?? ""}`)), m.append(B);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const j = i.length > 1 ? e(t, "div", { class: "ob-legend" }, ...i.map((u, y) => e(t, "span", { class: "ob-key" }, e(t, "i", { style: `background:${A(y)}` }), u.name))) : null;
|
|
207
|
-
return [o, j, m, c, b].filter((u) => !!u);
|
|
212
|
+
function G(t, a, o) {
|
|
213
|
+
const i = e(t, "div", { class: "ob-chart" }), n = _(i, a);
|
|
214
|
+
return w.set(o, [...w.get(o) ?? [], n]), i;
|
|
208
215
|
}
|
|
209
|
-
function
|
|
216
|
+
function T(t, a) {
|
|
210
217
|
if (!t.show_if) return !0;
|
|
211
|
-
const
|
|
212
|
-
return t.show_if.in ? t.show_if.in.some((
|
|
218
|
+
const o = a[t.show_if.field], i = Array.isArray(o) ? o.map(String) : o == null || o === "" ? [] : [String(o)];
|
|
219
|
+
return t.show_if.in ? t.show_if.in.some((n) => i.includes(n)) : t.show_if.equals !== void 0 ? i.includes(String(t.show_if.equals)) : i.length > 0;
|
|
213
220
|
}
|
|
214
|
-
function
|
|
215
|
-
const
|
|
216
|
-
for (const
|
|
217
|
-
"default" in
|
|
218
|
-
return
|
|
221
|
+
function F(t) {
|
|
222
|
+
const a = {};
|
|
223
|
+
for (const o of t)
|
|
224
|
+
"default" in o && o.default !== void 0 && (a[o.id] = o.default), o.type === "rank" && (a[o.id] = o.items.map((i) => i.id)), o.type === "table" && (a[o.id] = o.rows.length ? o.rows.map((i) => ({ ...i })) : [{}]);
|
|
225
|
+
return a;
|
|
219
226
|
}
|
|
220
|
-
function
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
const
|
|
224
|
-
|
|
227
|
+
function K(t, a, o) {
|
|
228
|
+
const i = t.ownerDocument, n = a.data, s = a.status === "open", d = e(i, "section", { class: "ob card pad", "aria-label": "需要你回答" });
|
|
229
|
+
if (d.append(y(i, n.question, o)), n.view?.length) {
|
|
230
|
+
const r = e(i, "div", { class: "ob" });
|
|
231
|
+
d.append(r), $(r, n.view, o, t);
|
|
225
232
|
}
|
|
226
|
-
const
|
|
227
|
-
l && (l.disabled = !0),
|
|
233
|
+
const f = e(i, "span", { class: "ob-err", role: "alert" }), g = async (r, l) => {
|
|
234
|
+
l && (l.disabled = !0), f.textContent = "";
|
|
228
235
|
try {
|
|
229
|
-
await
|
|
230
|
-
} catch (
|
|
231
|
-
|
|
236
|
+
await o.submit(r);
|
|
237
|
+
} catch (b) {
|
|
238
|
+
f.textContent = b.message, l && (l.disabled = !1);
|
|
232
239
|
}
|
|
233
240
|
};
|
|
234
|
-
if (!
|
|
235
|
-
const
|
|
236
|
-
return
|
|
241
|
+
if (!s) {
|
|
242
|
+
const r = a.result;
|
|
243
|
+
return d.append(e(i, "p", { class: "ob-muted" }, r?.cancelled ? "已失效" : "已回答")), r?.answer && d.append(e(i, "p", { class: "ob-value" }, r.answer)), d;
|
|
237
244
|
}
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
240
|
-
const
|
|
241
|
-
l(),
|
|
242
|
-
const
|
|
243
|
-
return
|
|
245
|
+
const c = { ...F(n.fields ?? []) }, p = n.allowText ? e(i, n.fields?.length ? "textarea" : "input", { class: n.fields?.length ? "textarea" : "input", rows: 2, placeholder: n.fields?.length ? "补充说明(可不填)" : n.options.length ? "也可以写别的回答" : "你的回答", "aria-label": "文字回答" }) : null;
|
|
246
|
+
if (n.fields?.length) {
|
|
247
|
+
const r = e(i, "div", { class: "ob" }), l = () => r.replaceChildren(...n.fields.filter((h) => T(h, c)).map((h) => R(i, a.id, h, c, l)));
|
|
248
|
+
l(), d.append(r), p && d.append(p);
|
|
249
|
+
const b = e(i, "button", { type: "button", class: "btn primary" }, n.submitLabel || "提交");
|
|
250
|
+
return b.addEventListener("click", () => g({ value: c, ...p?.value.trim() ? { text: p.value.trim() } : {} }, b)), d.append(e(i, "div", { class: "ob-foot" }, f, e(i, "span", { class: "ob-spacer" }), b)), d;
|
|
244
251
|
}
|
|
245
|
-
if (
|
|
246
|
-
const
|
|
247
|
-
return
|
|
248
|
-
}))),
|
|
249
|
-
const
|
|
250
|
-
|
|
252
|
+
if (n.options.length && d.append(e(i, "div", { class: "ob-options" }, ...n.options.map((r, l) => {
|
|
253
|
+
const b = e(i, "button", { type: "button", class: `btn sm${l === 0 ? " primary" : ""}` }, r.label);
|
|
254
|
+
return b.addEventListener("click", () => g({ choice: l, ...p?.value.trim() ? { text: p.value.trim() } : {} }, b)), b;
|
|
255
|
+
}))), p) {
|
|
256
|
+
const r = e(i, "button", { type: "button", class: "btn sm" }, "回答");
|
|
257
|
+
r.addEventListener("click", () => p.value.trim() && g({ text: p.value.trim() }, r)), d.append(e(i, "div", { class: "ob-foot" }, p, r));
|
|
251
258
|
}
|
|
252
|
-
return
|
|
259
|
+
return d.append(f), d;
|
|
253
260
|
}
|
|
254
|
-
function
|
|
255
|
-
const
|
|
256
|
-
o
|
|
257
|
-
},
|
|
258
|
-
let
|
|
259
|
-
switch (
|
|
261
|
+
function R(t, a, o, i, n) {
|
|
262
|
+
const s = `ob-${a}-${o.id}`, d = e(t, "span", { class: "ob-label", id: s }, o.label, o.required ? e(t, "span", { class: "ob-req", "aria-hidden": "true" }, "*") : null), f = o.help ? e(t, "span", { class: "ob-muted" }, o.help) : null, g = (r, l = !1) => {
|
|
263
|
+
i[o.id] = r, l && n();
|
|
264
|
+
}, c = !0;
|
|
265
|
+
let p;
|
|
266
|
+
switch (o.type) {
|
|
260
267
|
case "textarea":
|
|
261
|
-
|
|
268
|
+
p = e(t, "textarea", { class: "textarea", rows: 3, placeholder: o.placeholder, "aria-labelledby": s, oninput: (r) => g(r.target.value) }), p.value = String(i[o.id] ?? "");
|
|
262
269
|
break;
|
|
263
270
|
case "text":
|
|
264
271
|
case "number":
|
|
265
272
|
case "date":
|
|
266
273
|
case "datetime": {
|
|
267
|
-
const
|
|
268
|
-
|
|
274
|
+
const r = o.type === "datetime" ? "datetime-local" : o.type;
|
|
275
|
+
p = e(t, "input", { class: "input", type: r, placeholder: "placeholder" in o ? o.placeholder : void 0, min: "min" in o ? o.min : void 0, max: "max" in o ? o.max : void 0, "aria-labelledby": s, oninput: (l) => g(l.target.value), onchange: () => n() }), p.value = String(i[o.id] ?? "");
|
|
269
276
|
break;
|
|
270
277
|
}
|
|
271
278
|
case "toggle": {
|
|
272
|
-
const
|
|
273
|
-
|
|
279
|
+
const r = e(t, "button", { type: "button", class: "btn sm ob-opt", "aria-pressed": String(!!i[o.id]), "aria-labelledby": s }, i[o.id] ? "是" : "否");
|
|
280
|
+
r.addEventListener("click", () => g(!i[o.id], c)), p = r;
|
|
274
281
|
break;
|
|
275
282
|
}
|
|
276
283
|
case "pick":
|
|
277
|
-
|
|
278
|
-
const l =
|
|
279
|
-
return l.addEventListener("click", () =>
|
|
284
|
+
p = e(t, "div", { class: "ob-cards", role: "radiogroup", "aria-labelledby": s }, ...o.items.map((r) => {
|
|
285
|
+
const l = N(t, e(t, "button", { type: "button", role: "radio", class: "ob-pcard", "aria-checked": String(i[o.id] === r.id) }), r);
|
|
286
|
+
return l.addEventListener("click", () => g(r.id, c)), l;
|
|
280
287
|
}));
|
|
281
288
|
break;
|
|
282
289
|
case "rank": {
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
[
|
|
290
|
+
const r = i[o.id];
|
|
291
|
+
p = e(t, "ol", { class: "ob-rank", "aria-labelledby": s }, ...r.map((l, b) => {
|
|
292
|
+
const h = o.items.find((x) => x.id === l), m = (x) => {
|
|
293
|
+
const u = [...r];
|
|
294
|
+
[u[b], u[b + x]] = [u[b + x], u[b]], g(u, !0);
|
|
288
295
|
};
|
|
289
|
-
return e(t, "li", { class: "ob-check" }, e(t, "span", {}, `${
|
|
296
|
+
return e(t, "li", { class: "ob-check" }, e(t, "span", {}, `${b + 1}. ${h.title}`), e(
|
|
290
297
|
t,
|
|
291
298
|
"span",
|
|
292
299
|
{ class: "ob-options" },
|
|
293
|
-
e(t, "button", { type: "button", class: "btn sm", disabled:
|
|
294
|
-
e(t, "button", { type: "button", class: "btn sm", disabled:
|
|
300
|
+
e(t, "button", { type: "button", class: "btn sm", disabled: b === 0, "aria-label": `${h.title} 上移`, onclick: () => m(-1) }, "上移"),
|
|
301
|
+
e(t, "button", { type: "button", class: "btn sm", disabled: b === r.length - 1, "aria-label": `${h.title} 下移`, onclick: () => m(1) }, "下移")
|
|
295
302
|
));
|
|
296
303
|
}));
|
|
297
304
|
break;
|
|
298
305
|
}
|
|
299
306
|
case "table": {
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
return
|
|
303
|
-
}), e(t, "td", {}, e(t, "button", { type: "button", class: "btn sm", "aria-label": `删除第 ${x + 1} 行`, onclick: () =>
|
|
304
|
-
|
|
307
|
+
const r = i[o.id], l = e(t, "tr", {}, ...o.columns.map((m) => e(t, "th", {}, m.label)), e(t, "th", {}, "")), b = r.map((m, x) => e(t, "tr", {}, ...o.columns.map((u) => {
|
|
308
|
+
const v = u.type === "choice" ? e(t, "select", { class: "input", "aria-label": `第 ${x + 1} 行 ${u.label}` }, e(t, "option", { value: "" }, ""), ...(u.options ?? []).map((k) => e(t, "option", { value: k }, k))) : e(t, "input", { class: "input", type: u.type === "number" ? "number" : "text", "aria-label": `第 ${x + 1} 行 ${u.label}` });
|
|
309
|
+
return v.value = m[u.id] == null ? "" : String(m[u.id]), v.addEventListener("input", () => m[u.id] = v.value), e(t, "td", {}, v);
|
|
310
|
+
}), e(t, "td", {}, e(t, "button", { type: "button", class: "btn sm", "aria-label": `删除第 ${x + 1} 行`, onclick: () => g(r.filter((u, v) => v !== x), !0) }, "删除")))), h = e(t, "button", { type: "button", class: "btn sm", disabled: r.length >= o.max_rows, onclick: () => g([...r, {}], !0) }, "加一行");
|
|
311
|
+
p = e(t, "div", { class: "ob-field" }, e(t, "div", { class: "ob-scroll" }, e(t, "table", { "aria-labelledby": s }, e(t, "thead", {}, l), e(t, "tbody", {}, ...b))), h);
|
|
305
312
|
break;
|
|
306
313
|
}
|
|
307
314
|
case "checklist": {
|
|
308
|
-
const
|
|
309
|
-
o
|
|
310
|
-
const
|
|
311
|
-
const x = e(t, "button", { type: "button", role: "radio", class: "btn sm ob-opt", "aria-checked": String(
|
|
315
|
+
const r = i[o.id] ?? {};
|
|
316
|
+
i[o.id] = r, p = e(t, "div", { role: "group", "aria-labelledby": s }, ...o.items.map((l) => {
|
|
317
|
+
const b = e(t, "div", { class: "ob-check" }, e(t, "span", {}, l.title), l.detail ? e(t, "span", { class: "ob-muted ob-text" }, l.detail) : null), h = e(t, "div", { class: "ob-options", role: "radiogroup", "aria-label": l.title }, ...o.choices.map((m) => {
|
|
318
|
+
const x = e(t, "button", { type: "button", role: "radio", class: "btn sm ob-opt", "aria-checked": String(r[l.id]?.choice === m) }, m);
|
|
312
319
|
return x.addEventListener("click", () => {
|
|
313
|
-
|
|
320
|
+
r[l.id] = { ...r[l.id], choice: m }, h.querySelectorAll("button").forEach((u) => u.setAttribute("aria-checked", String(u.textContent === m)));
|
|
314
321
|
}), x;
|
|
315
322
|
}));
|
|
316
|
-
if (
|
|
317
|
-
const
|
|
318
|
-
|
|
323
|
+
if (b.append(h), o.note) {
|
|
324
|
+
const m = e(t, "input", { class: "input", placeholder: "备注(可不填)", "aria-label": `${l.title} 的备注` });
|
|
325
|
+
m.value = r[l.id]?.note ?? "", m.addEventListener("input", () => r[l.id] = { choice: r[l.id]?.choice ?? "", note: m.value }), b.append(m);
|
|
319
326
|
}
|
|
320
|
-
return
|
|
327
|
+
return b;
|
|
321
328
|
}));
|
|
322
329
|
break;
|
|
323
330
|
}
|
|
324
331
|
default: {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
const
|
|
332
|
+
const r = o.type === "scale" ? ["1", "2", "3", "4", "5"] : o.options, l = o.type === "multi";
|
|
333
|
+
p = e(t, "div", { class: "ob-options", role: l ? "group" : "radiogroup", "aria-labelledby": s }, ...r.map((b) => {
|
|
334
|
+
const h = i[o.id], m = l ? (h ?? []).includes(b) : String(h ?? "") === b, x = e(t, "button", { type: "button", class: "btn sm ob-opt", ...l ? { "aria-pressed": String(m) } : { role: "radio", "aria-checked": String(m) } }, b);
|
|
328
335
|
return x.addEventListener("click", () => {
|
|
329
336
|
if (l) {
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
} else
|
|
337
|
+
const u = new Set(i[o.id] ?? []);
|
|
338
|
+
u.has(b) ? u.delete(b) : u.add(b), g([...u], c);
|
|
339
|
+
} else g(o.type === "scale" ? Number(b) : b, c);
|
|
333
340
|
}), x;
|
|
334
341
|
}));
|
|
335
342
|
}
|
|
336
343
|
}
|
|
337
|
-
return e(t, "div", { class: "ob-field" },
|
|
344
|
+
return e(t, "div", { class: "ob-field" }, d, f, p);
|
|
338
345
|
}
|
|
339
346
|
export {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
347
|
+
A as GENERIC_KINDS,
|
|
348
|
+
T as fieldVisible,
|
|
349
|
+
F as initialValues,
|
|
350
|
+
W as renderBlock,
|
|
351
|
+
$ as renderView
|
|
345
352
|
};
|