@inkbar/vue 0.8.0 → 0.9.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/README.md +7 -2
- package/dist/components/InkHighlightMenu.js.map +1 -1
- package/dist/components/InkHighlightMenu.vue.d.ts.map +1 -1
- package/dist/components/InkHighlightMenu.vue_vue_type_script_setup_true_lang.js +67 -65
- package/dist/components/InkHighlightMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkRoot.js.map +1 -1
- package/dist/components/InkRoot.vue.d.ts +9 -4
- package/dist/components/InkRoot.vue.d.ts.map +1 -1
- package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js +176 -163
- package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkShapeMenu.js.map +1 -1
- package/dist/components/InkShapeMenu.vue.d.ts.map +1 -1
- package/dist/components/InkShapeMenu.vue_vue_type_script_setup_true_lang.js +58 -56
- package/dist/components/InkShapeMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkSignatureDialog.js.map +1 -1
- package/dist/components/InkSignatureDialog.vue.d.ts +3 -2
- package/dist/components/InkSignatureDialog.vue.d.ts.map +1 -1
- package/dist/components/InkSignatureDialog.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkSignatureMenu.js.map +1 -1
- package/dist/components/InkSignatureMenu.vue.d.ts.map +1 -1
- package/dist/components/InkSignatureMenu.vue_vue_type_script_setup_true_lang.js +77 -75
- package/dist/components/InkSignatureMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkToolButton.js.map +1 -1
- package/dist/components/InkToolButton.vue.d.ts.map +1 -1
- package/dist/components/InkToolButton.vue_vue_type_script_setup_true_lang.js +39 -36
- package/dist/components/InkToolButton.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkToolbarButton.js +7 -0
- package/dist/components/InkToolbarButton.js.map +1 -0
- package/dist/components/InkToolbarButton.vue.d.ts +22 -0
- package/dist/components/InkToolbarButton.vue.d.ts.map +1 -0
- package/dist/components/InkToolbarButton.vue_vue_type_script_setup_true_lang.js +32 -0
- package/dist/components/InkToolbarButton.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/InkViewport.js.map +1 -1
- package/dist/components/InkViewport.vue.d.ts.map +1 -1
- package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js +37 -36
- package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/SignatureForm.js.map +1 -1
- package/dist/components/SignatureForm.vue.d.ts.map +1 -1
- package/dist/components/SignatureForm.vue_vue_type_script_setup_true_lang.js +56 -55
- package/dist/components/SignatureForm.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/composables/useRegisteredTool.d.ts +21 -0
- package/dist/composables/useRegisteredTool.d.ts.map +1 -0
- package/dist/composables/useRegisteredTool.js +25 -0
- package/dist/composables/useRegisteredTool.js.map +1 -0
- package/dist/composables/useToolOptions.d.ts +8 -0
- package/dist/composables/useToolOptions.d.ts.map +1 -1
- package/dist/composables/useToolOptions.js +10 -5
- package/dist/composables/useToolOptions.js.map +1 -1
- package/dist/context.d.ts +5 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -20
- package/package.json +5 -5
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { provideInkContext as e } from "../context.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { registeredToolIds as t } from "../composables/useRegisteredTool.js";
|
|
3
|
+
import { useReadable as n } from "../use-readable.js";
|
|
4
|
+
import { createRefHistory as r } from "../ref-history.js";
|
|
5
|
+
import { computed as i, createBlock as a, defineComponent as o, onBeforeUnmount as ee, onMounted as te, onUnmounted as ne, onUpdated as re, openBlock as ie, ref as s, renderSlot as ae, shallowRef as c, unref as oe, useTemplateRef as l, watch as u, withCtx as se } from "vue";
|
|
6
|
+
import { InkError as d, createMemorySignatureStore as ce, createSignatureLibrary as le, openDocument as ue, readonly as f, writable as p } from "@inkbar/core";
|
|
7
|
+
import { FONT_FAMILIES as de, SIGNATURE_FONTS as fe, attachHistoryKeys as pe, createPluginHost as me, createSearchController as he, createToolOptions as ge, cssVariableDefaults as _e, handleFindKey as ve, keepHistoryFocus as ye, pageSelectionText as be, trackToolStyle as xe, unknownTool as Se, viewerSearchOf as m } from "@inkbar/core/dom";
|
|
8
|
+
import { Primitive as Ce } from "reka-ui";
|
|
8
9
|
//#region src/components/InkRoot.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
-
var
|
|
10
|
+
var h = /*@__PURE__*/ o({
|
|
10
11
|
__name: "InkRoot",
|
|
11
12
|
props: {
|
|
12
13
|
src: {},
|
|
@@ -52,230 +53,242 @@ var y = /*@__PURE__*/ a({
|
|
|
52
53
|
"error",
|
|
53
54
|
"activate"
|
|
54
55
|
],
|
|
55
|
-
setup(
|
|
56
|
-
let
|
|
57
|
-
function
|
|
58
|
-
let e =
|
|
59
|
-
|
|
56
|
+
setup(o, { expose: h, emit: g }) {
|
|
57
|
+
let _ = o, v = g, y = l("primitive"), b = c(null);
|
|
58
|
+
function x() {
|
|
59
|
+
let e = y.value?.$el;
|
|
60
|
+
b.value = e instanceof HTMLElement ? e : null;
|
|
60
61
|
}
|
|
61
|
-
let
|
|
62
|
-
function
|
|
63
|
-
|
|
62
|
+
let S = c(null), C = c(null), we = n(() => S.value?.status ?? null, { state: "idle" }), w = i(() => C.value ?? we.value), Te = n(() => S.value?.annotations.list ?? null, []), Ee = n(() => S.value?.annotations.selection ?? null, []), T = c(null), E = c(null), D = s(_.tool ?? "select-text"), O = s(null), k = i(() => _.annotations !== void 0), De = i(() => _.fields !== void 0);
|
|
63
|
+
function A(e) {
|
|
64
|
+
O.value = e, e && v("activate", e);
|
|
64
65
|
}
|
|
65
|
-
let
|
|
66
|
-
function
|
|
66
|
+
let j = () => {};
|
|
67
|
+
function Oe(e) {
|
|
67
68
|
return e === null ? null : typeof e == "string" ? e : "key" in e ? e.key : e;
|
|
68
69
|
}
|
|
69
|
-
let
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
let e =
|
|
73
|
-
|
|
70
|
+
let M = 0, N = j;
|
|
71
|
+
function P() {
|
|
72
|
+
N(), N = j;
|
|
73
|
+
let e = S.value;
|
|
74
|
+
S.value = null, e?.destroy();
|
|
74
75
|
}
|
|
75
|
-
async function
|
|
76
|
-
let e = ++
|
|
77
|
-
if (
|
|
78
|
-
|
|
76
|
+
async function F() {
|
|
77
|
+
let e = ++M, t = _.src;
|
|
78
|
+
if (P(), I.clear(), t === null) {
|
|
79
|
+
C.value = null;
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
C.value = { state: "loading" }, x();
|
|
82
83
|
let n;
|
|
83
84
|
try {
|
|
84
|
-
n = await
|
|
85
|
-
assets:
|
|
86
|
-
password:
|
|
87
|
-
defaults:
|
|
88
|
-
history:
|
|
89
|
-
annotations:
|
|
85
|
+
n = await ue(t, {
|
|
86
|
+
assets: _.assets,
|
|
87
|
+
password: _.password,
|
|
88
|
+
defaults: _.defaults ?? (b.value ? _e(b.value) : void 0),
|
|
89
|
+
history: k.value ? !1 : _.history ?? !0,
|
|
90
|
+
annotations: k.value ? {
|
|
90
91
|
mode: "controlled",
|
|
91
|
-
initial:
|
|
92
|
+
initial: _.annotations ?? [],
|
|
92
93
|
onChange: (e, t) => {
|
|
93
|
-
|
|
94
|
+
v("update:annotations", e), v("change", t);
|
|
94
95
|
}
|
|
95
96
|
} : { mode: "uncontrolled" },
|
|
96
|
-
fields:
|
|
97
|
+
fields: De.value ? {
|
|
97
98
|
mode: "controlled",
|
|
98
|
-
initial:
|
|
99
|
-
onChange: (e, t) =>
|
|
99
|
+
initial: _.fields ?? {},
|
|
100
|
+
onChange: (e, t) => v("update:fields", e, t)
|
|
100
101
|
} : { mode: "uncontrolled" }
|
|
101
102
|
});
|
|
102
103
|
} catch (t) {
|
|
103
|
-
if (e !==
|
|
104
|
-
let n = t instanceof
|
|
105
|
-
|
|
104
|
+
if (e !== M) return;
|
|
105
|
+
let n = t instanceof d ? t : new d("InvalidPdf", t instanceof Error ? t.message : String(t), {}, t);
|
|
106
|
+
C.value = {
|
|
106
107
|
state: "error",
|
|
107
108
|
error: n
|
|
108
|
-
},
|
|
109
|
+
}, v("error", n);
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
111
|
-
if (e !==
|
|
112
|
+
if (e !== M) {
|
|
112
113
|
n.destroy();
|
|
113
114
|
return;
|
|
114
115
|
}
|
|
115
|
-
n.annotations.mode === "controlled" &&
|
|
116
|
+
n.annotations.mode === "controlled" && _.annotations !== void 0 && n.annotations.setControlledValue(_.annotations), _.fields !== void 0 && n.form.setControlledValue(_.fields);
|
|
116
117
|
let r = [];
|
|
117
|
-
|
|
118
|
-
r ? r.push(e) :
|
|
119
|
-
}),
|
|
118
|
+
N = n.form.on("error", (e) => {
|
|
119
|
+
r ? r.push(e) : v("error", e);
|
|
120
|
+
}), S.value = n, C.value = null;
|
|
120
121
|
let i = n.status.get();
|
|
121
|
-
i.state === "ready" ?
|
|
122
|
+
i.state === "ready" ? v("ready", n) : i.state === "error" && v("error", i.error);
|
|
122
123
|
let a = r;
|
|
123
|
-
if (r = void 0, e ===
|
|
124
|
+
if (r = void 0, e === M) for (let e of a) v("error", e);
|
|
124
125
|
}
|
|
125
|
-
let
|
|
126
|
-
source: () =>
|
|
127
|
-
apply: (e) =>
|
|
128
|
-
enabled:
|
|
129
|
-
store: () =>
|
|
130
|
-
}),
|
|
131
|
-
canUndo:
|
|
132
|
-
canRedo:
|
|
133
|
-
undo: () =>
|
|
134
|
-
redo: () =>
|
|
135
|
-
clear: () =>
|
|
126
|
+
let I = r({
|
|
127
|
+
source: () => _.annotations,
|
|
128
|
+
apply: (e) => S.value?.annotations.replaceAll(e, "history"),
|
|
129
|
+
enabled: i(() => k.value && _.history === !0),
|
|
130
|
+
store: () => S.value?.annotations.mode === "controlled" ? S.value.annotations : null
|
|
131
|
+
}), ke = n(() => S.value?.history.canUndo ?? null, !1), Ae = n(() => S.value?.history.canRedo ?? null, !1), L = {
|
|
132
|
+
canUndo: i(() => k.value ? I.canUndo.value : ke.value),
|
|
133
|
+
canRedo: i(() => k.value ? I.canRedo.value : Ae.value),
|
|
134
|
+
undo: () => k.value ? I.undo() : S.value?.history.undo(),
|
|
135
|
+
redo: () => k.value ? I.redo() : S.value?.history.redo(),
|
|
136
|
+
clear: () => k.value ? I.clear() : S.value?.history.clear(),
|
|
136
137
|
batch: (e) => {
|
|
137
|
-
|
|
138
|
+
k.value ? I.batch(e) : S.value ? S.value.history.batch(e) : e();
|
|
138
139
|
},
|
|
139
|
-
track: (e) =>
|
|
140
|
-
react: (e) =>
|
|
140
|
+
track: (e) => k.value ? I.track(e) : S.value?.history.track(e) ?? j,
|
|
141
|
+
react: (e) => k.value ? I.react(e) : S.value?.history.react(e) ?? j
|
|
141
142
|
};
|
|
142
|
-
u(
|
|
143
|
+
u(b, (e, t, n) => {
|
|
143
144
|
if (!e) return;
|
|
144
|
-
let r =
|
|
145
|
-
canUndo:
|
|
146
|
-
canRedo:
|
|
147
|
-
undo:
|
|
148
|
-
redo:
|
|
149
|
-
})), i =
|
|
150
|
-
e.addEventListener("keydown",
|
|
151
|
-
r(), i(), e.removeEventListener("keydown",
|
|
145
|
+
let r = pe(e, () => ({
|
|
146
|
+
canUndo: L.canUndo.value,
|
|
147
|
+
canRedo: L.canRedo.value,
|
|
148
|
+
undo: L.undo,
|
|
149
|
+
redo: L.redo
|
|
150
|
+
})), i = ye(e, () => e.querySelector("[data-ink-scroll]"));
|
|
151
|
+
e.addEventListener("keydown", W), n(() => {
|
|
152
|
+
r(), i(), e.removeEventListener("keydown", W);
|
|
152
153
|
});
|
|
153
154
|
}, { immediate: !0 });
|
|
154
|
-
let
|
|
155
|
-
u(
|
|
156
|
-
let
|
|
157
|
-
u(
|
|
158
|
-
let
|
|
159
|
-
u(
|
|
160
|
-
let
|
|
161
|
-
function
|
|
162
|
-
let e =
|
|
163
|
-
document:
|
|
164
|
-
viewport: () =>
|
|
155
|
+
let R = p(null);
|
|
156
|
+
u(S, (e) => R.set(e), { flush: "sync" });
|
|
157
|
+
let z = c(null), B = p(null);
|
|
158
|
+
u(z, (e) => B.set(e), { flush: "sync" });
|
|
159
|
+
let V = p(null);
|
|
160
|
+
u(O, (e) => V.set(e), { flush: "sync" });
|
|
161
|
+
let H = c(null), U = c(null);
|
|
162
|
+
function je() {
|
|
163
|
+
let e = he({
|
|
164
|
+
document: f(R),
|
|
165
|
+
viewport: () => T.value
|
|
165
166
|
});
|
|
166
|
-
|
|
167
|
-
plugins:
|
|
168
|
-
document:
|
|
169
|
-
history: () =>
|
|
170
|
-
activated:
|
|
167
|
+
U.value = e, H.value = me({
|
|
168
|
+
plugins: _.plugins ?? [],
|
|
169
|
+
document: f(R),
|
|
170
|
+
history: () => L,
|
|
171
|
+
activated: f(V),
|
|
171
172
|
setActivated: (e) => {
|
|
172
|
-
(e === null ||
|
|
173
|
+
(e === null || S.value?.annotations.get(e)) && A(e);
|
|
173
174
|
},
|
|
174
|
-
root:
|
|
175
|
-
decorate: () =>
|
|
176
|
-
viewport: () =>
|
|
177
|
-
search:
|
|
175
|
+
root: f(B),
|
|
176
|
+
decorate: () => _.decorateAnnotation,
|
|
177
|
+
viewport: () => T.value,
|
|
178
|
+
search: m(e)
|
|
178
179
|
});
|
|
179
180
|
}
|
|
180
|
-
function
|
|
181
|
-
let t =
|
|
182
|
-
t && n instanceof HTMLElement &&
|
|
181
|
+
function W(e) {
|
|
182
|
+
let t = U.value, n = e.currentTarget;
|
|
183
|
+
t && n instanceof HTMLElement && ve(e, t, () => be(n));
|
|
183
184
|
}
|
|
184
|
-
let
|
|
185
|
-
u(
|
|
185
|
+
let G = c(null), K;
|
|
186
|
+
u(S, (e) => {
|
|
186
187
|
if (!e) {
|
|
187
|
-
|
|
188
|
+
G.value = null, K = void 0;
|
|
188
189
|
return;
|
|
189
190
|
}
|
|
190
|
-
let t =
|
|
191
|
+
let t = xe({
|
|
191
192
|
store: e.annotations,
|
|
192
|
-
history: { batch: (e) =>
|
|
193
|
-
tools: [...
|
|
194
|
-
tool:
|
|
193
|
+
history: { batch: (e) => L.batch(e) },
|
|
194
|
+
tools: [..._.tools ?? [], ...H.value?.tools ?? []],
|
|
195
|
+
tool: D.value
|
|
195
196
|
});
|
|
196
|
-
|
|
197
|
+
K = (e) => t.setTool(e), G.value = t.toolStyle;
|
|
197
198
|
}, {
|
|
198
199
|
immediate: !0,
|
|
199
200
|
flush: "sync"
|
|
200
|
-
}), u(
|
|
201
|
-
|
|
201
|
+
}), u(D, (e) => K?.(e)), te(() => {
|
|
202
|
+
x();
|
|
202
203
|
try {
|
|
203
|
-
|
|
204
|
+
je();
|
|
204
205
|
} finally {
|
|
205
|
-
|
|
206
|
+
q.value = !0, F();
|
|
206
207
|
}
|
|
207
|
-
}), re(
|
|
208
|
-
e &&
|
|
209
|
-
}), u(() =>
|
|
210
|
-
e &&
|
|
211
|
-
}), u(() => b.tool, (e) => {
|
|
212
|
-
e && (N.value = e);
|
|
208
|
+
}), re(x), u([() => Oe(_.src), () => _.password], () => void F()), u(() => _.annotations, (e) => {
|
|
209
|
+
e && S.value?.annotations.mode === "controlled" && S.value.annotations.setControlledValue(e);
|
|
210
|
+
}), u(() => _.fields, (e) => {
|
|
211
|
+
e && S.value?.form.setControlledValue(e);
|
|
213
212
|
});
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
let q = s(!1), J = c(null), Y = i(() => t(_.tools, H.value, J.value)), X = (e) => !q.value || Y.value.includes(e), Z = (e) => console.error(Se(e, Y.value));
|
|
214
|
+
function Q(e) {
|
|
215
|
+
Z(e), D.value = "select-text", v("update:tool", "select-text");
|
|
216
|
+
}
|
|
217
|
+
u(() => _.tool, (e) => {
|
|
218
|
+
e && (X(e) ? D.value = e : Q(e));
|
|
219
|
+
}), u([q, Y], () => {
|
|
220
|
+
X(D.value) || Q(D.value);
|
|
221
|
+
});
|
|
222
|
+
function Me(e) {
|
|
223
|
+
if (!X(e)) {
|
|
224
|
+
Z(e);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
let t = E.value;
|
|
228
|
+
D.value === e && t?.active.get() === e && t.set(e), D.value = e, v("update:tool", e);
|
|
217
229
|
}
|
|
218
230
|
ee(() => {
|
|
219
|
-
|
|
231
|
+
M++, P();
|
|
220
232
|
}), ne(() => {
|
|
221
|
-
|
|
233
|
+
H.value?.destroy(), H.value = null, U.value?.destroy(), U.value = null;
|
|
222
234
|
});
|
|
223
|
-
let $ =
|
|
235
|
+
let $ = i(() => le(_.signatures ?? ce()));
|
|
224
236
|
u($, (e) => void e.refresh(), { immediate: !0 });
|
|
225
|
-
let
|
|
237
|
+
let Ne = ge();
|
|
226
238
|
return e({
|
|
227
|
-
assets:
|
|
228
|
-
document:
|
|
229
|
-
status:
|
|
230
|
-
annotations:
|
|
231
|
-
selection:
|
|
232
|
-
viewport:
|
|
233
|
-
tools:
|
|
234
|
-
tool:
|
|
235
|
-
setTool:
|
|
236
|
-
hostTools:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
assets: i(() => _.assets),
|
|
240
|
+
document: S,
|
|
241
|
+
status: w,
|
|
242
|
+
annotations: Te,
|
|
243
|
+
selection: Ee,
|
|
244
|
+
viewport: T,
|
|
245
|
+
tools: E,
|
|
246
|
+
tool: D,
|
|
247
|
+
setTool: Me,
|
|
248
|
+
hostTools: i(() => _.tools),
|
|
249
|
+
openedToolIds: J,
|
|
250
|
+
decorateAnnotation: i(() => _.decorateAnnotation),
|
|
251
|
+
fonts: i(() => _.fonts ?? de),
|
|
252
|
+
toolOptions: Ne,
|
|
240
253
|
signatures: $,
|
|
241
|
-
signatureFonts:
|
|
242
|
-
toolStyle:
|
|
243
|
-
zoomModel:
|
|
244
|
-
pageModel:
|
|
245
|
-
reportZoom: (e) =>
|
|
246
|
-
reportPage: (e) =>
|
|
247
|
-
activated:
|
|
248
|
-
setActivated:
|
|
249
|
-
pluginHost:
|
|
250
|
-
search:
|
|
251
|
-
viewportEl:
|
|
252
|
-
history:
|
|
253
|
-
rootEl:
|
|
254
|
-
formHighlight:
|
|
255
|
-
reportFormAction: (e) =>
|
|
256
|
-
reportError: (e) =>
|
|
257
|
-
}),
|
|
258
|
-
document:
|
|
259
|
-
status:
|
|
260
|
-
rootEl:
|
|
261
|
-
history:
|
|
262
|
-
}), (e, t) => (ie(),
|
|
254
|
+
signatureFonts: i(() => _.signatureFonts ?? fe),
|
|
255
|
+
toolStyle: G,
|
|
256
|
+
zoomModel: i(() => _.zoom),
|
|
257
|
+
pageModel: i(() => _.page),
|
|
258
|
+
reportZoom: (e) => v("update:zoom", e),
|
|
259
|
+
reportPage: (e) => v("update:page", e),
|
|
260
|
+
activated: O,
|
|
261
|
+
setActivated: A,
|
|
262
|
+
pluginHost: H,
|
|
263
|
+
search: U,
|
|
264
|
+
viewportEl: z,
|
|
265
|
+
history: L,
|
|
266
|
+
rootEl: b,
|
|
267
|
+
formHighlight: i(() => _.formHighlight),
|
|
268
|
+
reportFormAction: (e) => v("form-action", e),
|
|
269
|
+
reportError: (e) => v("error", e)
|
|
270
|
+
}), h({
|
|
271
|
+
document: S,
|
|
272
|
+
status: w,
|
|
273
|
+
rootEl: b,
|
|
274
|
+
history: L
|
|
275
|
+
}), (e, t) => (ie(), a(oe(Ce), {
|
|
263
276
|
ref_key: "primitive",
|
|
264
|
-
ref:
|
|
265
|
-
"as-child":
|
|
277
|
+
ref: y,
|
|
278
|
+
"as-child": _.asChild,
|
|
266
279
|
as: "div",
|
|
267
280
|
"data-ink-root": "",
|
|
268
|
-
"data-state":
|
|
281
|
+
"data-state": w.value.state
|
|
269
282
|
}, {
|
|
270
|
-
default:
|
|
271
|
-
status:
|
|
272
|
-
document:
|
|
283
|
+
default: se(() => [ae(e.$slots, "default", {
|
|
284
|
+
status: w.value,
|
|
285
|
+
document: S.value
|
|
273
286
|
})]),
|
|
274
287
|
_: 3
|
|
275
288
|
}, 8, ["as-child", "data-state"]));
|
|
276
289
|
}
|
|
277
290
|
});
|
|
278
291
|
//#endregion
|
|
279
|
-
export {
|
|
292
|
+
export { h as default };
|
|
280
293
|
|
|
281
294
|
//# sourceMappingURL=InkRoot.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkRoot.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","_withCtx","_renderSlot","InkRoot_vue_vue_type_script_setup_true_lang_default","__expose","__emit","props","__props","emit","primitive","useTemplateRef","rootEl","shallowRef","syncRootEl","el","document","override","documentStatus","useReadable","status","computed","annotationList","selection","viewport","toolController","internalTool","ref","activated","controlled","fieldsControlled","setActivated","id","noop","identity","src","generation","stopFormErrors","release","doc","open","gen","refHistory","openDocument","cssVariableDefaults","next","change","cause","error","InkError","held","s","early","createRefHistory","list","coreCanUndo","coreCanRedo","inkHistory","fn","store","stopKeys","attachHistoryKeys","stopFocus","keepHistoryFocus","onKeydown","onCleanup","hostDocument","writable","viewportEl","hostRoot","hostActivated","pluginHost","search","setUpPlugins","controller","createSearchController","readonly","createPluginHost","viewerSearchOf","root","handleFindKey","pageSelectionText","toolStyle","setStyleTool","watch","tracker","trackToolStyle","onMounted","onUpdated","t","setTool","tc","onBeforeUnmount","onUnmounted","signatures","createSignatureLibrary","createMemorySignatureStore","lib","toolOptions","createToolOptions","provideInkContext","FONT_FAMILIES","SIGNATURE_FONTS","z","p","a","openBlock","createBlock","unref","Primitive","withCtx","renderSlot","_ctx"],"sources":["../../src/components/InkRoot.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n createMemorySignatureStore,\n createSignatureLibrary,\n InkError,\n openDocument,\n readonly,\n writable,\n} from '@inkbar/core'\nimport {\n attachHistoryKeys,\n createPluginHost,\n createSearchController,\n createToolOptions,\n handleFindKey,\n pageSelectionText,\n viewerSearchOf,\n cssVariableDefaults,\n FONT_FAMILIES,\n keepHistoryFocus,\n SIGNATURE_FONTS,\n trackToolStyle,\n} from '@inkbar/core/dom'\nimport { Primitive } from 'reka-ui'\nimport {\n computed,\n onBeforeUnmount,\n onUnmounted,\n onMounted,\n onUpdated,\n ref,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nimport { provideInkContext, type InkHistory, type InkStatus } from '../context'\nimport { createRefHistory } from '../ref-history'\nimport { useReadable } from '../use-readable'\n\nimport type {\n Annotation,\n AnnotationChange,\n AnnotationDefaults,\n DocumentSource,\n FieldsChange,\n FieldValues,\n FormAction,\n InkDocument,\n PdfAssets,\n SignatureStore,\n} from '@inkbar/core'\nimport type {\n DecorateAnnotation,\n InkPlugin,\n PluginHost,\n SearchController,\n Tool,\n ToolController,\n ToolId,\n ToolStyle,\n Viewport,\n ZoomValue,\n} from '@inkbar/core/dom'\n\nconst props = withDefaults(\n defineProps<{\n src: DocumentSource | null\n assets: PdfAssets\n password?: string | undefined\n /** Colour defaults. Without it, the theme's CSS variables on the root element apply. */\n defaults?: AnnotationDefaults | undefined\n /**\n * Pass (with v-model) to put annotations under the host's control. The mode is fixed when a\n * document opens: passing or dropping this prop later takes effect on the next open.\n */\n annotations?: Annotation[] | undefined\n /**\n * Pass (with `v-model:fields`) to put the form's field values under the host's control. A\n * commit shows at once and is reported after; the host's push wins. The mode is fixed when\n * a document opens, as for `annotations`.\n */\n fields?: FieldValues | undefined\n /** Tints fillable form fields. Default true. A change applies to the open document in place. */\n formHighlight?: boolean | undefined\n tool?: ToolId | undefined\n /**\n * Host tools, added to the built-ins; one with a built-in's id replaces it. Read when a\n * document opens.\n */\n tools?: Tool[] | undefined\n /**\n * Plugins, set up once when the root is created; a later change to this prop is not\n * applied. Their tools join `tools`, their decoration and page layers apply to every\n * document, and their commands are placed with `InkCommand` or `useCommand`.\n */\n plugins?: InkPlugin[] | undefined\n /**\n * Adds `data-*` attributes, classes and a screen-reader description to each annotation's\n * element (see `DecorateAnnotation`). Decorations re-apply whenever the annotations change\n * and when this prop changes, without rebuilding the viewer. Pass a new function when its\n * output would change for any other reason.\n */\n decorateAnnotation?: DecorateAnnotation | undefined\n /**\n * The font families text boxes offer, replacing the PDF standard families\n * (`FONT_FAMILIES`). Fonts beyond those are the PDF writer's to embed.\n */\n fonts?: string[] | undefined\n /**\n * Where saved signatures live. Default: memory, gone on reload.\n * `createLocalSignatureStore` keeps them in the browser; a host can keep them anywhere.\n * A new store takes effect at once, for the menus and the `signature` tool alike.\n */\n signatures?: SignatureStore | undefined\n /** The handwriting fonts a typed signature offers; the host loads them. */\n signatureFonts?: string[] | undefined\n page?: number | undefined\n zoom?: ZoomValue | undefined\n /** Undo history. Defaults to on for uncontrolled, off for controlled. */\n history?: boolean | undefined\n asChild?: boolean\n }>(),\n {\n password: undefined,\n defaults: undefined,\n annotations: undefined,\n fields: undefined,\n formHighlight: undefined,\n tool: undefined,\n tools: undefined,\n plugins: undefined,\n decorateAnnotation: undefined,\n fonts: undefined,\n signatures: undefined,\n signatureFonts: undefined,\n page: undefined,\n zoom: undefined,\n history: undefined,\n asChild: false,\n }\n)\n\nconst emit = defineEmits<{\n 'update:annotations': [next: Annotation[]]\n change: [change: AnnotationChange]\n /** Committed field values, in full, with what changed them. */\n 'update:fields': [next: FieldValues, change: FieldsChange]\n /** The form asked to submit, open a link, send mail, print or prompt. Inkbar does none. */\n 'form-action': [action: FormAction]\n 'update:tool': [tool: ToolId]\n 'update:page': [page: number]\n 'update:zoom': [zoom: ZoomValue]\n ready: [doc: InkDocument]\n /**\n * Opening failed, or later a form script failed or a signature field refused its signing.\n * An error from while the document opened comes after `ready`.\n */\n error: [error: InkError]\n activate: [id: string]\n}>()\n\ntype TestHookElement = HTMLElement & { __inkDocument?: InkDocument | undefined }\n\n// A template ref on Primitive is a component instance; the context needs its element.\nconst primitive = useTemplateRef<{ $el: unknown }>('primitive')\nconst rootEl = shallowRef<HTMLElement | null>(null)\nfunction syncRootEl(): void {\n const el = primitive.value?.$el\n rootEl.value = el instanceof HTMLElement ? el : null\n}\n\nconst document = shallowRef<InkDocument | null>(null)\n/** Overrides the document's status while opening, and when opening itself failed. */\nconst override = shallowRef<InkStatus | null>(null)\nconst idle: InkStatus = { state: 'idle' }\nconst documentStatus = useReadable<InkStatus>(() => document.value?.status ?? null, idle)\nconst status = computed<InkStatus>(() => override.value ?? documentStatus.value)\nconst annotationList = useReadable<readonly Annotation[]>(\n () => document.value?.annotations.list ?? null,\n []\n)\nconst selection = useReadable<readonly string[]>(\n () => document.value?.annotations.selection ?? null,\n []\n)\nconst viewport = shallowRef<Viewport | null>(null)\nconst toolController = shallowRef<ToolController | null>(null)\nconst internalTool = ref<ToolId>(props.tool ?? 'select-text')\nconst activated = ref<string | null>(null)\n\nconst controlled = computed(() => props.annotations !== undefined)\nconst fieldsControlled = computed(() => props.fields !== undefined)\n\nfunction setActivated(id: string | null): void {\n activated.value = id\n if (id) emit('activate', id)\n}\n\nconst noop = () => {}\n\n/** Signed URLs change; the key does not. Bytes and Blobs are their own identity. */\nfunction identity(src: DocumentSource | null): unknown {\n if (src === null) return null\n if (typeof src === 'string') return src\n if ('key' in src) return src.key\n return src\n}\n\nfunction setTestHook(doc: InkDocument | undefined): void {\n if (import.meta.env.DEV && rootEl.value)\n (rootEl.value as TestHookElement).__inkDocument = doc\n}\n\nlet generation = 0\nlet stopFormErrors: () => void = noop\nfunction release(): void {\n stopFormErrors()\n stopFormErrors = noop\n // Cleared first, so the plugins close their stores while the document is still alive.\n const doc = document.value\n document.value = null\n doc?.destroy()\n setTestHook(undefined)\n}\n\nasync function open(): Promise<void> {\n const gen = ++generation\n const src = props.src\n release()\n refHistory.clear()\n if (src === null) {\n override.value = null\n return\n }\n override.value = { state: 'loading' }\n syncRootEl()\n let doc: InkDocument\n try {\n doc = await openDocument(src, {\n assets: props.assets,\n password: props.password,\n defaults:\n props.defaults ?? (rootEl.value ? cssVariableDefaults(rootEl.value) : undefined),\n // Controlled hosts get the ref history below; core's own stack stays off.\n history: controlled.value ? false : (props.history ?? true),\n annotations: controlled.value\n ? {\n mode: 'controlled',\n initial: props.annotations ?? [],\n onChange: (next, change) => {\n emit('update:annotations', next)\n emit('change', change)\n },\n }\n : { mode: 'uncontrolled' },\n fields: fieldsControlled.value\n ? {\n mode: 'controlled',\n initial: props.fields ?? {},\n onChange: (next, change) => emit('update:fields', next, change),\n }\n : { mode: 'uncontrolled' },\n })\n } catch (cause) {\n if (gen !== generation) return\n const error =\n cause instanceof InkError\n ? cause\n : new InkError(\n 'InvalidPdf',\n cause instanceof Error ? cause.message : String(cause),\n {},\n cause\n )\n override.value = { state: 'error', error }\n emit('error', error)\n return\n }\n if (gen !== generation) {\n doc.destroy()\n return\n }\n // The prop may have changed while the file loaded, when there was no store to apply it to.\n if (doc.annotations.mode === 'controlled' && props.annotations !== undefined)\n doc.annotations.setControlledValue(props.annotations)\n // The same for the fields; a document whose fields opened uncontrolled ignores the push.\n if (props.fields !== undefined) doc.form.setControlledValue(props.fields)\n // A form script that fails leaves the form fillable; the failure goes to `error`. Subscribed\n // before anyone hears of the document, so the form replays the errors from while it opened\n // here, not to a listener added in `ready`; they are held until `ready` has gone out.\n let held: InkError[] | undefined = []\n stopFormErrors = doc.form.on('error', (e) => {\n if (held) held.push(e)\n else emit('error', e)\n })\n document.value = doc\n override.value = null\n setTestHook(doc)\n const s = doc.status.get()\n if (s.state === 'ready') emit('ready', doc)\n else if (s.state === 'error') emit('error', s.error)\n const early = held\n held = undefined\n if (gen === generation) for (const e of early) emit('error', e)\n}\n\nconst refHistory = createRefHistory({\n source: () => props.annotations,\n apply: (list) => document.value?.annotations.replaceAll(list, 'history'),\n enabled: computed(() => controlled.value && props.history === true),\n store: () =>\n document.value?.annotations.mode === 'controlled' ? document.value.annotations : null,\n})\nconst coreCanUndo = useReadable(() => document.value?.history.canUndo ?? null, false)\nconst coreCanRedo = useReadable(() => document.value?.history.canRedo ?? null, false)\nconst inkHistory: InkHistory = {\n canUndo: computed(() =>\n controlled.value ? refHistory.canUndo.value : coreCanUndo.value\n ),\n canRedo: computed(() =>\n controlled.value ? refHistory.canRedo.value : coreCanRedo.value\n ),\n undo: () => (controlled.value ? refHistory.undo() : document.value?.history.undo()),\n redo: () => (controlled.value ? refHistory.redo() : document.value?.history.redo()),\n clear: () => (controlled.value ? refHistory.clear() : document.value?.history.clear()),\n batch: (fn) => {\n if (controlled.value) refHistory.batch(fn)\n else if (document.value) document.value.history.batch(fn)\n else fn()\n },\n track: (store) =>\n controlled.value\n ? refHistory.track(store)\n : (document.value?.history.track(store) ?? noop),\n react: (fn) =>\n controlled.value ? refHistory.react(fn) : (document.value?.history.react(fn) ?? noop),\n}\n\n// The undo and redo keys anywhere in the root do what InkUndo and InkRedo do. When either\n// button undoes or redoes the last step and disables itself, focus goes back to the document.\n// The find key listens here too.\nwatch(\n rootEl,\n (el, _prev, onCleanup) => {\n if (!el) return\n const stopKeys = attachHistoryKeys(el, () => ({\n canUndo: inkHistory.canUndo.value,\n canRedo: inkHistory.canRedo.value,\n undo: inkHistory.undo,\n redo: inkHistory.redo,\n }))\n const stopFocus = keepHistoryFocus(el, () =>\n el.querySelector<HTMLElement>('[data-ink-scroll]')\n )\n // Not a template listener: Vue leaves those on the element when it unmounts.\n el.addEventListener('keydown', onKeydown)\n onCleanup(() => {\n stopKeys()\n stopFocus()\n el.removeEventListener('keydown', onKeydown)\n })\n },\n { immediate: true }\n)\n\n/*\n * One plugin host for the root's life, built once mounted so that no `setup` runs on the\n * server, where nothing would clean it up. Until then `pluginHost` is null, and InkCommand\n * renders its command disabled. The host follows `hostDocument`, which is set after `document`\n * (a sync watch): when the host reads `inkHistory` for a new document, it is that document's\n * history.\n */\nconst hostDocument = writable<InkDocument | null>(null)\nwatch(document, (doc) => hostDocument.set(doc), { flush: 'sync' })\nconst viewportEl = shallowRef<HTMLElement | null>(null)\nconst hostRoot = writable<HTMLElement | null>(null)\nwatch(viewportEl, (el) => hostRoot.set(el), { flush: 'sync' })\nconst hostActivated = writable<string | null>(null)\nwatch(activated, (id) => hostActivated.set(id), { flush: 'sync' })\nconst pluginHost = shallowRef<PluginHost | null>(null)\n/** One search controller for the root's life, built with the plugin host that shares it. */\nconst search = shallowRef<SearchController | null>(null)\nfunction setUpPlugins(): void {\n const controller = createSearchController({\n document: readonly(hostDocument),\n viewport: () => viewport.value,\n })\n search.value = controller\n pluginHost.value = createPluginHost({\n plugins: props.plugins ?? [],\n document: readonly(hostDocument),\n history: () => inkHistory,\n activated: readonly(hostActivated),\n // As in `createViewer`: an id not in the open document is ignored.\n setActivated: (id) => {\n if (id === null || document.value?.annotations.get(id)) setActivated(id)\n },\n root: readonly(hostRoot),\n decorate: () => props.decorateAnnotation,\n viewport: () => viewport.value,\n search: viewerSearchOf(controller),\n })\n}\n\n/** Ctrl/Cmd+F while focus is in the root and a find bar is mounted; else the browser's. */\nfunction onKeydown(e: KeyboardEvent): void {\n const controller = search.value\n const root = e.currentTarget\n if (controller && root instanceof HTMLElement)\n handleFindKey(e, controller, () => pageSelectionText(root))\n}\n\n/** The document's tool style; it batches through `inkHistory`, whichever mode is on. */\nconst toolStyle = shallowRef<ToolStyle | null>(null)\nlet setStyleTool: ((id: ToolId) => void) | undefined\nwatch(\n document,\n (doc) => {\n if (!doc) {\n toolStyle.value = null\n setStyleTool = undefined\n return\n }\n const tracker = trackToolStyle({\n store: doc.annotations,\n history: { batch: (fn) => inkHistory.batch(fn) },\n // The plugins' tools too, so a plugin tool's style group applies (the host is set by now:\n // it is built on mount, before the first document opens).\n tools: [...(props.tools ?? []), ...(pluginHost.value?.tools ?? [])],\n tool: internalTool.value,\n })\n setStyleTool = (id) => tracker.setTool(id)\n toolStyle.value = tracker.toolStyle\n },\n // Sync: the style is in place before InkViewport's watcher mounts the engine with it.\n { immediate: true, flush: 'sync' }\n)\nwatch(internalTool, (id) => setStyleTool?.(id))\n\n// Plugins and the document on the client only: on the server InkRoot renders its empty slot.\n// The plugins first, so the first document opens with their stores and reactions.\nonMounted(() => {\n syncRootEl()\n // A plugin whose setup throws still leaves the document to open; the error then goes to\n // Vue's error handling (`onErrorCaptured`, `app.config.errorHandler`).\n try {\n setUpPlugins()\n } finally {\n void open()\n }\n})\nonUpdated(syncRootEl)\n\n// Separate sources, so a new `{ url, key }` object with the same key compares equal.\nwatch([() => identity(props.src), () => props.password], () => void open())\n\nwatch(\n () => props.annotations,\n (next) => {\n if (next && document.value?.annotations.mode === 'controlled')\n document.value.annotations.setControlledValue(next)\n }\n)\n\nwatch(\n () => props.fields,\n (next) => {\n if (next) document.value?.form.setControlledValue(next)\n }\n)\n\nwatch(\n () => props.tool,\n (t) => {\n if (t) internalTool.value = t\n }\n)\n\nfunction setTool(id: ToolId): void {\n // Picking the active tool again starts it afresh, as after a one-shot tool's use.\n const tc = toolController.value\n if (internalTool.value === id && tc?.active.get() === id) tc.set(id)\n internalTool.value = id\n emit('update:tool', id)\n}\n\nonBeforeUnmount(() => {\n generation++\n release()\n})\n\n// After the children: InkViewport's engine, and the plugin layers with it, are gone by now, as\n// in `createViewer`, so no layer `destroy` runs after the plugins' cleanups.\nonUnmounted(() => {\n pluginHost.value?.destroy()\n pluginHost.value = null\n search.value?.destroy()\n search.value = null\n})\n\nconst signatures = computed(() =>\n createSignatureLibrary(props.signatures ?? createMemorySignatureStore())\n)\nwatch(signatures, (lib) => void lib.refresh(), { immediate: true })\n/** Tool options last as long as the root; the tool style is per document. */\nconst toolOptions = createToolOptions()\n\nprovideInkContext({\n assets: computed(() => props.assets),\n document,\n status,\n annotations: annotationList,\n selection,\n viewport,\n tools: toolController,\n tool: internalTool,\n setTool,\n hostTools: computed(() => props.tools),\n decorateAnnotation: computed(() => props.decorateAnnotation),\n fonts: computed(() => props.fonts ?? FONT_FAMILIES),\n toolOptions,\n signatures,\n signatureFonts: computed(() => props.signatureFonts ?? SIGNATURE_FONTS),\n toolStyle,\n zoomModel: computed(() => props.zoom),\n pageModel: computed(() => props.page),\n reportZoom: (z) => emit('update:zoom', z),\n reportPage: (p) => emit('update:page', p),\n activated,\n setActivated,\n pluginHost,\n search,\n viewportEl,\n history: inkHistory,\n rootEl,\n formHighlight: computed(() => props.formHighlight),\n reportFormAction: (a) => emit('form-action', a),\n reportError: (e) => emit('error', e),\n})\n\n// `history` is what `useHistory()` returns inside the root, for hosts that hold a template ref:\n// a controlled host calls `history.clear()` after loading its saved list.\ndefineExpose({ document, status, rootEl, history: inkHistory })\n</script>\n\n<template>\n <Primitive\n ref=\"primitive\"\n :as-child=\"props.asChild\"\n as=\"div\"\n data-ink-root\n :data-state=\"status.state\"\n >\n <slot :status=\"status\" :document=\"document\" />\n </Primitive>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiEA,IAAMQ,IAAQC,GA8ERC,IAAOH,IAsBPI,IAAYC,EAAiC,WAAW,GACxDC,IAASC,EAA+B,IAAI;EAClD,SAASC,IAAmB;GAC1B,IAAMC,IAAKL,EAAU,OAAO;GAC5B,EAAO,QAAQK,aAAc,cAAcA,IAAK;EAClD;EAEA,IAAMC,IAAWH,EAA+B,IAAI,GAE9CI,IAAWJ,EAA6B,IAAI,GAE5CK,IAAiBC,QAA6BH,EAAS,OAAO,UAAU,MAAM,EAD1D,OAAO,OACmD,CAAI,GAClFI,IAASC,QAA0BJ,EAAS,SAASC,EAAe,KAAK,GACzEI,IAAiBH,QACfH,EAAS,OAAO,YAAY,QAAQ,MAC1C,CAAC,CACH,GACMO,IAAYJ,QACVH,EAAS,OAAO,YAAY,aAAa,MAC/C,CAAC,CACH,GACMQ,IAAWX,EAA4B,IAAI,GAC3CY,IAAiBZ,EAAkC,IAAI,GACvDa,IAAeC,EAAYpB,EAAM,QAAQ,aAAa,GACtDqB,IAAYD,EAAmB,IAA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js","names":["_openBlock","_createBlock","_unref","_withCtx","_renderSlot","InkRoot_vue_vue_type_script_setup_true_lang_default","__expose","__emit","props","__props","emit","primitive","useTemplateRef","rootEl","shallowRef","syncRootEl","el","document","override","documentStatus","useReadable","status","computed","annotationList","selection","viewport","toolController","internalTool","ref","activated","controlled","fieldsControlled","setActivated","id","noop","identity","src","generation","stopFormErrors","release","doc","open","gen","refHistory","openDocument","cssVariableDefaults","next","change","cause","error","InkError","held","s","early","createRefHistory","list","coreCanUndo","coreCanRedo","inkHistory","fn","store","stopKeys","attachHistoryKeys","stopFocus","keepHistoryFocus","onKeydown","onCleanup","hostDocument","writable","viewportEl","hostRoot","hostActivated","pluginHost","search","setUpPlugins","controller","createSearchController","readonly","createPluginHost","viewerSearchOf","root","handleFindKey","pageSelectionText","toolStyle","setStyleTool","watch","tracker","trackToolStyle","onMounted","onUpdated","mounted","openedToolIds","toolIds","registeredToolIds","isRegistered","logUnknownTool","unknownTool","fallBack","t","setTool","tc","onBeforeUnmount","onUnmounted","signatures","createSignatureLibrary","createMemorySignatureStore","lib","toolOptions","createToolOptions","provideInkContext","FONT_FAMILIES","SIGNATURE_FONTS","z","p","a","openBlock","createBlock","unref","Primitive","withCtx","renderSlot","_ctx"],"sources":["../../src/components/InkRoot.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n createMemorySignatureStore,\n createSignatureLibrary,\n InkError,\n openDocument,\n readonly,\n writable,\n} from '@inkbar/core'\nimport {\n attachHistoryKeys,\n createPluginHost,\n createSearchController,\n createToolOptions,\n handleFindKey,\n pageSelectionText,\n viewerSearchOf,\n cssVariableDefaults,\n FONT_FAMILIES,\n keepHistoryFocus,\n SIGNATURE_FONTS,\n trackToolStyle,\n unknownTool,\n} from '@inkbar/core/dom'\nimport { Primitive } from 'reka-ui'\nimport {\n computed,\n onBeforeUnmount,\n onUnmounted,\n onMounted,\n onUpdated,\n ref,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nimport { registeredToolIds } from '../composables/useRegisteredTool'\nimport { provideInkContext, type InkHistory, type InkStatus } from '../context'\nimport { createRefHistory } from '../ref-history'\nimport { useReadable } from '../use-readable'\n\nimport type {\n Annotation,\n AnnotationChange,\n AnnotationDefaults,\n DocumentSource,\n FieldsChange,\n FieldValues,\n FormAction,\n InkDocument,\n PdfAssets,\n SignatureStore,\n} from '@inkbar/core'\nimport type {\n DecorateAnnotation,\n InkPlugin,\n PluginHost,\n SearchController,\n Tool,\n ToolController,\n ToolId,\n ToolStyle,\n Viewport,\n ZoomValue,\n} from '@inkbar/core/dom'\n\nconst props = withDefaults(\n defineProps<{\n src: DocumentSource | null\n assets: PdfAssets\n password?: string | undefined\n /** Colour defaults. Without it, the theme's CSS variables on the root element apply. */\n defaults?: AnnotationDefaults | undefined\n /**\n * Pass (with v-model) to put annotations under the host's control. The mode is fixed when a\n * document opens: passing or dropping this prop later takes effect on the next open.\n */\n annotations?: Annotation[] | undefined\n /**\n * Pass (with `v-model:fields`) to put the form's field values under the host's control. A\n * commit shows at once and is reported after; the host's push wins. The mode is fixed when\n * a document opens, as for `annotations`.\n */\n fields?: FieldValues | undefined\n /** Tints fillable form fields. Default true. A change applies to the open document in place. */\n formHighlight?: boolean | undefined\n tool?: ToolId | undefined\n /**\n * The creation tools, such as `allTools()` or a pick of the tool factories. `select-text`\n * and `select` are always present; a tool with either id replaces it. They are read when a\n * document opens: a tool added later is usable from the next open, one removed stops at\n * once. When the active tool goes, the viewer switches to `select-text` and emits\n * `update:tool`. A controlled `tool` naming a missing tool is reported back as\n * `select-text` and is not applied again when the tool appears later. Each mounted control\n * for a missing tool logs its own `UnknownTool`.\n */\n tools?: Tool[] | undefined\n /**\n * Plugins, set up once when the root is created; a later change to this prop is not\n * applied. Their tools join `tools`, their decoration and page layers apply to every\n * document, and their commands are placed with `InkCommand` or `useCommand`.\n */\n plugins?: InkPlugin[] | undefined\n /**\n * Adds `data-*` attributes, classes and a screen-reader description to each annotation's\n * element (see `DecorateAnnotation`). Decorations re-apply whenever the annotations change\n * and when this prop changes, without rebuilding the viewer. Pass a new function when its\n * output would change for any other reason.\n */\n decorateAnnotation?: DecorateAnnotation | undefined\n /**\n * The font families text boxes offer, replacing the PDF standard families\n * (`FONT_FAMILIES`). Fonts beyond those are the PDF writer's to embed.\n */\n fonts?: string[] | undefined\n /**\n * Where saved signatures live. Default: memory, gone on reload.\n * `createLocalSignatureStore` keeps them in the browser; a host can keep them anywhere.\n * A new store takes effect at once, for the menus and the `signature` tool alike.\n */\n signatures?: SignatureStore | undefined\n /** The handwriting fonts a typed signature offers; the host loads them. */\n signatureFonts?: string[] | undefined\n page?: number | undefined\n zoom?: ZoomValue | undefined\n /** Undo history. Defaults to on for uncontrolled, off for controlled. */\n history?: boolean | undefined\n asChild?: boolean\n }>(),\n {\n password: undefined,\n defaults: undefined,\n annotations: undefined,\n fields: undefined,\n formHighlight: undefined,\n tool: undefined,\n tools: undefined,\n plugins: undefined,\n decorateAnnotation: undefined,\n fonts: undefined,\n signatures: undefined,\n signatureFonts: undefined,\n page: undefined,\n zoom: undefined,\n history: undefined,\n asChild: false,\n }\n)\n\nconst emit = defineEmits<{\n 'update:annotations': [next: Annotation[]]\n change: [change: AnnotationChange]\n /** Committed field values, in full, with what changed them. */\n 'update:fields': [next: FieldValues, change: FieldsChange]\n /** The form asked to submit, open a link, send mail, print or prompt. Inkbar does none. */\n 'form-action': [action: FormAction]\n 'update:tool': [tool: ToolId]\n 'update:page': [page: number]\n 'update:zoom': [zoom: ZoomValue]\n ready: [doc: InkDocument]\n /**\n * Opening failed, or later a form script failed or a signature field refused its signing.\n * An error from while the document opened comes after `ready`.\n */\n error: [error: InkError]\n activate: [id: string]\n}>()\n\ntype TestHookElement = HTMLElement & { __inkDocument?: InkDocument | undefined }\n\n// A template ref on Primitive is a component instance; the context needs its element.\nconst primitive = useTemplateRef<{ $el: unknown }>('primitive')\nconst rootEl = shallowRef<HTMLElement | null>(null)\nfunction syncRootEl(): void {\n const el = primitive.value?.$el\n rootEl.value = el instanceof HTMLElement ? el : null\n}\n\nconst document = shallowRef<InkDocument | null>(null)\n/** Overrides the document's status while opening, and when opening itself failed. */\nconst override = shallowRef<InkStatus | null>(null)\nconst idle: InkStatus = { state: 'idle' }\nconst documentStatus = useReadable<InkStatus>(() => document.value?.status ?? null, idle)\nconst status = computed<InkStatus>(() => override.value ?? documentStatus.value)\nconst annotationList = useReadable<readonly Annotation[]>(\n () => document.value?.annotations.list ?? null,\n []\n)\nconst selection = useReadable<readonly string[]>(\n () => document.value?.annotations.selection ?? null,\n []\n)\nconst viewport = shallowRef<Viewport | null>(null)\nconst toolController = shallowRef<ToolController | null>(null)\nconst internalTool = ref<ToolId>(props.tool ?? 'select-text')\nconst activated = ref<string | null>(null)\n\nconst controlled = computed(() => props.annotations !== undefined)\nconst fieldsControlled = computed(() => props.fields !== undefined)\n\nfunction setActivated(id: string | null): void {\n activated.value = id\n if (id) emit('activate', id)\n}\n\nconst noop = () => {}\n\n/** Signed URLs change; the key does not. Bytes and Blobs are their own identity. */\nfunction identity(src: DocumentSource | null): unknown {\n if (src === null) return null\n if (typeof src === 'string') return src\n if ('key' in src) return src.key\n return src\n}\n\nfunction setTestHook(doc: InkDocument | undefined): void {\n if (import.meta.env.DEV && rootEl.value)\n (rootEl.value as TestHookElement).__inkDocument = doc\n}\n\nlet generation = 0\nlet stopFormErrors: () => void = noop\nfunction release(): void {\n stopFormErrors()\n stopFormErrors = noop\n // Cleared first, so the plugins close their stores while the document is still alive.\n const doc = document.value\n document.value = null\n doc?.destroy()\n setTestHook(undefined)\n}\n\nasync function open(): Promise<void> {\n const gen = ++generation\n const src = props.src\n release()\n refHistory.clear()\n if (src === null) {\n override.value = null\n return\n }\n override.value = { state: 'loading' }\n syncRootEl()\n let doc: InkDocument\n try {\n doc = await openDocument(src, {\n assets: props.assets,\n password: props.password,\n defaults:\n props.defaults ?? (rootEl.value ? cssVariableDefaults(rootEl.value) : undefined),\n // Controlled hosts get the ref history below; core's own stack stays off.\n history: controlled.value ? false : (props.history ?? true),\n annotations: controlled.value\n ? {\n mode: 'controlled',\n initial: props.annotations ?? [],\n onChange: (next, change) => {\n emit('update:annotations', next)\n emit('change', change)\n },\n }\n : { mode: 'uncontrolled' },\n fields: fieldsControlled.value\n ? {\n mode: 'controlled',\n initial: props.fields ?? {},\n onChange: (next, change) => emit('update:fields', next, change),\n }\n : { mode: 'uncontrolled' },\n })\n } catch (cause) {\n if (gen !== generation) return\n const error =\n cause instanceof InkError\n ? cause\n : new InkError(\n 'InvalidPdf',\n cause instanceof Error ? cause.message : String(cause),\n {},\n cause\n )\n override.value = { state: 'error', error }\n emit('error', error)\n return\n }\n if (gen !== generation) {\n doc.destroy()\n return\n }\n // The prop may have changed while the file loaded, when there was no store to apply it to.\n if (doc.annotations.mode === 'controlled' && props.annotations !== undefined)\n doc.annotations.setControlledValue(props.annotations)\n // The same for the fields; a document whose fields opened uncontrolled ignores the push.\n if (props.fields !== undefined) doc.form.setControlledValue(props.fields)\n // A form script that fails leaves the form fillable; the failure goes to `error`. Subscribed\n // before anyone hears of the document, so the form replays the errors from while it opened\n // here, not to a listener added in `ready`; they are held until `ready` has gone out.\n let held: InkError[] | undefined = []\n stopFormErrors = doc.form.on('error', (e) => {\n if (held) held.push(e)\n else emit('error', e)\n })\n document.value = doc\n override.value = null\n setTestHook(doc)\n const s = doc.status.get()\n if (s.state === 'ready') emit('ready', doc)\n else if (s.state === 'error') emit('error', s.error)\n const early = held\n held = undefined\n if (gen === generation) for (const e of early) emit('error', e)\n}\n\nconst refHistory = createRefHistory({\n source: () => props.annotations,\n apply: (list) => document.value?.annotations.replaceAll(list, 'history'),\n enabled: computed(() => controlled.value && props.history === true),\n store: () =>\n document.value?.annotations.mode === 'controlled' ? document.value.annotations : null,\n})\nconst coreCanUndo = useReadable(() => document.value?.history.canUndo ?? null, false)\nconst coreCanRedo = useReadable(() => document.value?.history.canRedo ?? null, false)\nconst inkHistory: InkHistory = {\n canUndo: computed(() =>\n controlled.value ? refHistory.canUndo.value : coreCanUndo.value\n ),\n canRedo: computed(() =>\n controlled.value ? refHistory.canRedo.value : coreCanRedo.value\n ),\n undo: () => (controlled.value ? refHistory.undo() : document.value?.history.undo()),\n redo: () => (controlled.value ? refHistory.redo() : document.value?.history.redo()),\n clear: () => (controlled.value ? refHistory.clear() : document.value?.history.clear()),\n batch: (fn) => {\n if (controlled.value) refHistory.batch(fn)\n else if (document.value) document.value.history.batch(fn)\n else fn()\n },\n track: (store) =>\n controlled.value\n ? refHistory.track(store)\n : (document.value?.history.track(store) ?? noop),\n react: (fn) =>\n controlled.value ? refHistory.react(fn) : (document.value?.history.react(fn) ?? noop),\n}\n\n// The undo and redo keys anywhere in the root do what InkUndo and InkRedo do. When either\n// button undoes or redoes the last step and disables itself, focus goes back to the document.\n// The find key listens here too.\nwatch(\n rootEl,\n (el, _prev, onCleanup) => {\n if (!el) return\n const stopKeys = attachHistoryKeys(el, () => ({\n canUndo: inkHistory.canUndo.value,\n canRedo: inkHistory.canRedo.value,\n undo: inkHistory.undo,\n redo: inkHistory.redo,\n }))\n const stopFocus = keepHistoryFocus(el, () =>\n el.querySelector<HTMLElement>('[data-ink-scroll]')\n )\n // Not a template listener: Vue leaves those on the element when it unmounts.\n el.addEventListener('keydown', onKeydown)\n onCleanup(() => {\n stopKeys()\n stopFocus()\n el.removeEventListener('keydown', onKeydown)\n })\n },\n { immediate: true }\n)\n\n/*\n * One plugin host for the root's life, built once mounted so that no `setup` runs on the\n * server, where nothing would clean it up. Until then `pluginHost` is null, and InkCommand\n * renders its command disabled. The host follows `hostDocument`, which is set after `document`\n * (a sync watch): when the host reads `inkHistory` for a new document, it is that document's\n * history.\n */\nconst hostDocument = writable<InkDocument | null>(null)\nwatch(document, (doc) => hostDocument.set(doc), { flush: 'sync' })\nconst viewportEl = shallowRef<HTMLElement | null>(null)\nconst hostRoot = writable<HTMLElement | null>(null)\nwatch(viewportEl, (el) => hostRoot.set(el), { flush: 'sync' })\nconst hostActivated = writable<string | null>(null)\nwatch(activated, (id) => hostActivated.set(id), { flush: 'sync' })\nconst pluginHost = shallowRef<PluginHost | null>(null)\n/** One search controller for the root's life, built with the plugin host that shares it. */\nconst search = shallowRef<SearchController | null>(null)\nfunction setUpPlugins(): void {\n const controller = createSearchController({\n document: readonly(hostDocument),\n viewport: () => viewport.value,\n })\n search.value = controller\n pluginHost.value = createPluginHost({\n plugins: props.plugins ?? [],\n document: readonly(hostDocument),\n history: () => inkHistory,\n activated: readonly(hostActivated),\n // As in `createViewer`: an id not in the open document is ignored.\n setActivated: (id) => {\n if (id === null || document.value?.annotations.get(id)) setActivated(id)\n },\n root: readonly(hostRoot),\n decorate: () => props.decorateAnnotation,\n viewport: () => viewport.value,\n search: viewerSearchOf(controller),\n })\n}\n\n/** Ctrl/Cmd+F while focus is in the root and a find bar is mounted; else the browser's. */\nfunction onKeydown(e: KeyboardEvent): void {\n const controller = search.value\n const root = e.currentTarget\n if (controller && root instanceof HTMLElement)\n handleFindKey(e, controller, () => pageSelectionText(root))\n}\n\n/** The document's tool style; it batches through `inkHistory`, whichever mode is on. */\nconst toolStyle = shallowRef<ToolStyle | null>(null)\nlet setStyleTool: ((id: ToolId) => void) | undefined\nwatch(\n document,\n (doc) => {\n if (!doc) {\n toolStyle.value = null\n setStyleTool = undefined\n return\n }\n const tracker = trackToolStyle({\n store: doc.annotations,\n history: { batch: (fn) => inkHistory.batch(fn) },\n // The plugins' tools too, so a plugin tool's style group applies (the host is set by now:\n // it is built on mount, before the first document opens).\n tools: [...(props.tools ?? []), ...(pluginHost.value?.tools ?? [])],\n tool: internalTool.value,\n })\n setStyleTool = (id) => tracker.setTool(id)\n toolStyle.value = tracker.toolStyle\n },\n // Sync: the style is in place before InkViewport's watcher mounts the engine with it.\n { immediate: true, flush: 'sync' }\n)\nwatch(internalTool, (id) => setStyleTool?.(id))\n\n// Plugins and the document on the client only: on the server InkRoot renders its empty slot.\n// The plugins first, so the first document opens with their stores and reactions.\nonMounted(() => {\n syncRootEl()\n // A plugin whose setup throws still leaves the document to open; the error then goes to\n // Vue's error handling (`onErrorCaptured`, `app.config.errorHandler`).\n try {\n setUpPlugins()\n } finally {\n mounted.value = true\n void open()\n }\n})\nonUpdated(syncRootEl)\n\n// Separate sources, so a new `{ url, key }` object with the same key compares equal.\nwatch([() => identity(props.src), () => props.password], () => void open())\n\nwatch(\n () => props.annotations,\n (next) => {\n if (next && document.value?.annotations.mode === 'controlled')\n document.value.annotations.setControlledValue(next)\n }\n)\n\nwatch(\n () => props.fields,\n (next) => {\n if (next) document.value?.form.setControlledValue(next)\n }\n)\n\n/*\n * The tools are known once the plugins are set up on mount. A tool id nobody registered is\n * logged as `UnknownTool`; as the active tool, from a `tool` prop or because it left `tools`,\n * it falls back to `select-text`, reported through `update:tool`. A controlled `tool` that\n * stays on the missing id is not applied again.\n */\nconst mounted = ref(false)\n/** The ids of the tools the current viewer was built with; InkViewport sets them. */\nconst openedToolIds = shallowRef<readonly ToolId[] | null>(null)\nconst toolIds = computed(() =>\n registeredToolIds(props.tools, pluginHost.value, openedToolIds.value)\n)\nconst isRegistered = (id: ToolId): boolean => !mounted.value || toolIds.value.includes(id)\nconst logUnknownTool = (id: ToolId): void => console.error(unknownTool(id, toolIds.value))\n\nfunction fallBack(id: ToolId): void {\n logUnknownTool(id)\n internalTool.value = 'select-text'\n emit('update:tool', 'select-text')\n}\n\nwatch(\n () => props.tool,\n (t) => {\n if (!t) return\n if (isRegistered(t)) internalTool.value = t\n else fallBack(t)\n }\n)\nwatch([mounted, toolIds], () => {\n if (!isRegistered(internalTool.value)) fallBack(internalTool.value)\n})\n\nfunction setTool(id: ToolId): void {\n // As the tool controller does: a missing tool is logged and nothing changes.\n if (!isRegistered(id)) {\n logUnknownTool(id)\n return\n }\n // Picking the active tool again starts it afresh, as after a one-shot tool's use.\n const tc = toolController.value\n if (internalTool.value === id && tc?.active.get() === id) tc.set(id)\n internalTool.value = id\n emit('update:tool', id)\n}\n\nonBeforeUnmount(() => {\n generation++\n release()\n})\n\n// After the children: InkViewport's engine, and the plugin layers with it, are gone by now, as\n// in `createViewer`, so no layer `destroy` runs after the plugins' cleanups.\nonUnmounted(() => {\n pluginHost.value?.destroy()\n pluginHost.value = null\n search.value?.destroy()\n search.value = null\n})\n\nconst signatures = computed(() =>\n createSignatureLibrary(props.signatures ?? createMemorySignatureStore())\n)\nwatch(signatures, (lib) => void lib.refresh(), { immediate: true })\n/** Tool options last as long as the root; the tool style is per document. */\nconst toolOptions = createToolOptions()\n\nprovideInkContext({\n assets: computed(() => props.assets),\n document,\n status,\n annotations: annotationList,\n selection,\n viewport,\n tools: toolController,\n tool: internalTool,\n setTool,\n hostTools: computed(() => props.tools),\n openedToolIds,\n decorateAnnotation: computed(() => props.decorateAnnotation),\n fonts: computed(() => props.fonts ?? FONT_FAMILIES),\n toolOptions,\n signatures,\n signatureFonts: computed(() => props.signatureFonts ?? SIGNATURE_FONTS),\n toolStyle,\n zoomModel: computed(() => props.zoom),\n pageModel: computed(() => props.page),\n reportZoom: (z) => emit('update:zoom', z),\n reportPage: (p) => emit('update:page', p),\n activated,\n setActivated,\n pluginHost,\n search,\n viewportEl,\n history: inkHistory,\n rootEl,\n formHighlight: computed(() => props.formHighlight),\n reportFormAction: (a) => emit('form-action', a),\n reportError: (e) => emit('error', e),\n})\n\n// `history` is what `useHistory()` returns inside the root, for hosts that hold a template ref:\n// a controlled host calls `history.clear()` after loading its saved list.\ndefineExpose({ document, status, rootEl, history: inkHistory })\n</script>\n\n<template>\n <Primitive\n ref=\"primitive\"\n :as-child=\"props.asChild\"\n as=\"div\"\n data-ink-root\n :data-state=\"status.state\"\n >\n <slot :status=\"status\" :document=\"document\" />\n </Primitive>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmEA,IAAMQ,IAAQC,GAmFRC,IAAOH,GAsBPI,IAAYC,EAAiC,WAAW,GACxDC,IAASC,EAA+B,IAAI;EAClD,SAASC,IAAm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AAO,QAAQ,GACtB,EAAO,QAAQ;EACjB,CAAC;EAED,IAAM8B,IAAajF,QACjBkF,GAAuBhG,EAAM,cAAciG,GAA2B,CAAC,CACzE;EACA,EAAMF,IAAa,MAAQ,KAAKG,EAAI,QAAQ,GAAG,EAAE,WAAW,GAAK,CAAC;EAElE,IAAMC,KAAcC,GAAkB;SAEtCC,EAAkB;GAChB,QAAQvF,QAAed,EAAM,MAAM;GACnC;GACA;GACA,aAAae;GACb;GACA;GACA,OAAOG;GACP,MAAMC;GACN;GACA,WAAWL,QAAed,EAAM,KAAK;GACrC;GACA,oBAAoBc,QAAed,EAAM,kBAAkB;GAC3D,OAAOc,QAAed,EAAM,SAASsG,EAAa;GAClD;GACA;GACA,gBAAgBxF,QAAed,EAAM,kBAAkBuG,EAAe;GACtE;GACA,WAAWzF,QAAed,EAAM,IAAI;GACpC,WAAWc,QAAed,EAAM,IAAI;GACpC,aAAa,MAAME,EAAK,eAAesG,CAAC;GACxC,aAAa,MAAMtG,EAAK,eAAeuG,CAAC;GACxC;GACA;GACA;GACA;GACA;GACA,SAASvD;GACT;GACA,eAAepC,QAAed,EAAM,aAAa;GACjD,mBAAmB,MAAME,EAAK,eAAewG,CAAC;GAC9C,cAAc,MAAMxG,EAAK,SAAS,CAAC;EACrC,CAAC,GAIDJ,EAAa;GAAE;GAAU;GAAQ;GAAQ,SAASoD;EAAW,CAAC,cAI5D1D,GAAA,GAAAC,EAQYC,GAAAoH,EAAA,GAAA;GAPN,SAAA;GAAJ,KAAI3G;GACH,YAAUH,EAAM;GACjB,IAAG;GACH,iBAAA;GACC,cAAYa,EAAA,MAAO;;GAEpB,SAAAlB,SAA8C,CAA9CC,GAA8CqH,EAAA,QAAA,WAAA;IAAvC,QAAQpG,EAAA;IAAS,UAAUJ,EAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkShapeMenu.js","names":["_sfc_main","InkShapeMenu_vue_vue_type_script_setup_true_lang_default","InkShapeMenu_default"],"sources":["../../src/components/InkShapeMenu.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * A split button for the shape tool. The main part activates the tool with the current\n * kind and draws that kind's icon; the chevron opens a two-column grid of kinds. Choosing a\n * kind switches to the tool with it.\n */\nimport {\n focusInitialMenuItem,\n handleMenuKeys,\n menuItems,\n SHAPE_COLUMNS,\n SHAPE_ICONS,\n SHAPE_KINDS,\n shapeMenuModel,\n type ShapeKind,\n type ShapeOptions,\n} from '@inkbar/core/dom'\nimport { ChevronDown } from '@inkbar/icons'\nimport {\n PopoverAnchor,\n PopoverContent,\n PopoverPortal,\n PopoverRoot,\n PopoverTrigger,\n ToolbarButton,\n} from 'reka-ui'\nimport { computed, ref } from 'vue'\n\nimport { useTool } from '../composables/useTool'\nimport {
|
|
1
|
+
{"version":3,"file":"InkShapeMenu.js","names":["_sfc_main","InkShapeMenu_vue_vue_type_script_setup_true_lang_default","InkShapeMenu_default"],"sources":["../../src/components/InkShapeMenu.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * A split button for the shape tool. The main part activates the tool with the current\n * kind and draws that kind's icon; the chevron opens a two-column grid of kinds. Choosing a\n * kind switches to the tool with it.\n */\nimport {\n focusInitialMenuItem,\n handleMenuKeys,\n menuItems,\n SHAPE_COLUMNS,\n SHAPE_ICONS,\n SHAPE_KINDS,\n shapeMenuModel,\n type ShapeKind,\n type ShapeOptions,\n} from '@inkbar/core/dom'\nimport { ChevronDown } from '@inkbar/icons'\nimport {\n PopoverAnchor,\n PopoverContent,\n PopoverPortal,\n PopoverRoot,\n PopoverTrigger,\n ToolbarButton,\n} from 'reka-ui'\nimport { computed, ref } from 'vue'\n\nimport { useRegisteredTool } from '../composables/useRegisteredTool'\nimport { useTool } from '../composables/useTool'\nimport { useToolOptionsWhile } from '../composables/useToolOptions'\n\nimport InkIcon from './InkIcon.vue'\n\ndefineOptions({ inheritAttrs: false })\nconst { tool, setTool } = useTool()\n// Nothing renders while no `shape` tool is registered.\nconst registered = useRegisteredTool('shape')\nconst { options, setOptions } = useToolOptionsWhile<ShapeOptions>('shape', registered)\nconst open = ref(false)\n\nconst model = computed(() => shapeMenuModel(options.value, SHAPE_KINDS))\nconst active = computed(() => tool.value === 'shape')\nconst icon = computed(() => SHAPE_ICONS[model.value.kind])\n\n/** ArrowDown opens on the first item; a click opens on the checked one. */\nlet focusFirst = false\nfunction onTriggerKeydown(e: KeyboardEvent): void {\n if (e.key !== 'ArrowDown' || e.defaultPrevented || open.value) return\n e.preventDefault()\n focusFirst = true\n open.value = true\n}\n\nfunction onOpenAutoFocus(e: Event): void {\n e.preventDefault()\n // One menu is open at a time.\n const menu = document.querySelector('[data-ink-menu=\"shape\"] [role=\"menu\"]')\n if (menu) {\n if (focusFirst) menuItems(menu)[0]?.focus({ preventScroll: true })\n else focusInitialMenuItem(menu)\n }\n focusFirst = false\n}\n\nfunction choose(kind: ShapeKind): void {\n setOptions({ kind })\n setTool('shape')\n open.value = false\n}\n\n// Reka's typed props stop at its own; ARIA and listeners go through bound objects.\nconst mainAttrs = computed(() => ({\n 'aria-pressed': String(active.value),\n 'aria-label': model.value.label,\n title: model.value.label,\n onClick: () => setTool('shape'),\n}))\nconst triggerAttrs = {\n 'aria-label': 'Choose shape',\n title: 'Choose shape',\n 'aria-haspopup': 'menu' as const,\n onKeydown: onTriggerKeydown,\n}\nconst menuAttrs = { 'aria-label': 'Shapes' }\nconst innerAttrs = {\n role: 'menu',\n 'aria-label': 'Shapes',\n onKeydown: (e: KeyboardEvent) => handleMenuKeys(e, e.currentTarget as HTMLElement),\n}\n</script>\n\n<template>\n <PopoverRoot v-if=\"registered\" v-model:open=\"open\">\n <PopoverAnchor as-child>\n <div\n role=\"group\"\n aria-label=\"Shape\"\n class=\"ink-split-button ink-shape-menu\"\n data-ink-shape-menu\n v-bind=\"$attrs\"\n >\n <ToolbarButton\n class=\"ink-tool-button ink-shape-button\"\n data-ink-tool-button\n data-ink-shape-button\n data-tool=\"shape\"\n :data-kind=\"model.kind\"\n :data-state=\"active ? 'on' : 'off'\"\n v-bind=\"mainAttrs\"\n >\n <slot :active=\"active\" :kind=\"model.kind\"><InkIcon :icon=\"icon\" /></slot>\n </ToolbarButton>\n <ToolbarButton as-child>\n <PopoverTrigger as-child>\n <button\n type=\"button\"\n class=\"ink-menu-trigger ink-shape-menu-trigger\"\n data-ink-shape-menu-trigger\n :data-state=\"open ? 'open' : 'closed'\"\n v-bind=\"triggerAttrs\"\n >\n <InkIcon :icon=\"ChevronDown\" />\n </button>\n </PopoverTrigger>\n </ToolbarButton>\n <PopoverPortal>\n <PopoverContent\n class=\"ink-select-content ink-menu-content\"\n data-ink-select-content\n data-ink-menu=\"shape\"\n side=\"bottom\"\n align=\"start\"\n :side-offset=\"4\"\n :collision-padding=\"8\"\n v-bind=\"menuAttrs\"\n @open-auto-focus=\"onOpenAutoFocus\"\n >\n <div v-bind=\"innerAttrs\">\n <div\n role=\"group\"\n aria-label=\"Shapes\"\n class=\"ink-shape-grid\"\n :data-ink-menu-columns=\"SHAPE_COLUMNS\"\n >\n <button\n v-for=\"item in model.items\"\n :key=\"item.kind\"\n type=\"button\"\n role=\"menuitemradio\"\n class=\"ink-select-item ink-menu-item ink-shape-item\"\n data-ink-select-item\n tabindex=\"-1\"\n :data-key=\"item.kind\"\n :aria-checked=\"item.checked\"\n :data-state=\"item.checked ? 'checked' : 'unchecked'\"\n @click=\"choose(item.kind)\"\n >\n <InkIcon :icon=\"SHAPE_ICONS[item.kind]\" :size=\"16\" />\n {{ item.label }}\n </button>\n </div>\n </div>\n </PopoverContent>\n </PopoverPortal>\n </div>\n </PopoverAnchor>\n </PopoverRoot>\n</template>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkShapeMenu.vue.d.ts","sourceRoot":"","sources":["../../src/components/InkShapeMenu.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InkShapeMenu.vue.d.ts","sourceRoot":"","sources":["../../src/components/InkShapeMenu.vue"],"names":[],"mappings":"AAgLA,OAAO,EAQL,KAAK,SAAS,EAEf,MAAM,kBAAkB,CAAA;AAwTzB,QAAA,IAAI,QAAQ;;;CAAY,CAAC;AACzB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAGhD,QAAA,MAAM,UAAU,+QACd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|