@metamorph-labs/polymorph-vue-ui 1.0.16 → 1.0.17
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/CHANGELOG.md +134 -0
- package/dist/ai/ArtifactPane.js.map +1 -1
- package/dist/ai/ArtifactPane.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/archetypes/MasterDetailPage.js.map +1 -1
- package/dist/archetypes/MasterDetailPage.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/archetypes/MasterDetailPage.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/archetypes/app-shell.css +1 -1
- package/dist/archetypes/app-shell.module.js +2 -2
- package/dist/archetypes/app-shell.module.js.map +1 -1
- package/dist/controls/RichTextInput.js +7 -0
- package/dist/controls/RichTextInput.js.map +1 -0
- package/dist/controls/RichTextInput.vue_vue_type_script_setup_true_lang.js +1123 -0
- package/dist/controls/RichTextInput.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/controls/rich-text-input.css +1 -0
- package/dist/controls/rich-text-input.module.js +47 -0
- package/dist/controls/rich-text-input.module.js.map +1 -0
- package/dist/controls/selection-bar.css +1 -0
- package/dist/controls/selection-bar.module.js +11 -0
- package/dist/controls/selection-bar.module.js.map +1 -0
- package/dist/index.js +41 -39
- package/dist/index.js.map +1 -1
- package/dist/node/ai/ArtifactPane.js.map +1 -1
- package/dist/node/ai/ArtifactPane.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/archetypes/MasterDetailPage.js.map +1 -1
- package/dist/node/archetypes/MasterDetailPage.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/node/archetypes/MasterDetailPage.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/archetypes/app-shell.module.js +2 -2
- package/dist/node/archetypes/app-shell.module.js.map +1 -1
- package/dist/node/controls/RichTextInput.js +7 -0
- package/dist/node/controls/RichTextInput.js.map +1 -0
- package/dist/node/controls/RichTextInput.vue_vue_type_script_setup_true_lang.js +1123 -0
- package/dist/node/controls/RichTextInput.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/node/controls/rich-text-input.module.js +46 -0
- package/dist/node/controls/rich-text-input.module.js.map +1 -0
- package/dist/node/controls/selection-bar.module.js +10 -0
- package/dist/node/controls/selection-bar.module.js.map +1 -0
- package/dist/node/index.js +41 -39
- package/dist/node/index.js.map +1 -1
- package/dist/node/overlays/Toast.js.map +1 -1
- package/dist/node/overlays/Toast.vue_vue_type_script_setup_true_lang.js +27 -27
- package/dist/node/overlays/Toast.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/structure/Accordion.js.map +1 -1
- package/dist/node/structure/Accordion.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/node/structure/Accordion.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/structure/Collapsible.js.map +1 -1
- package/dist/node/structure/Collapsible.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/node/structure/Collapsible.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/structure/CursorPagination.js.map +1 -1
- package/dist/node/structure/CursorPagination.vue_vue_type_script_setup_true_lang.js +140 -93
- package/dist/node/structure/CursorPagination.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/structure/Image.js.map +1 -1
- package/dist/node/structure/Image.vue_vue_type_script_setup_true_lang.js +30 -18
- package/dist/node/structure/Image.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/structure/Pagination.js.map +1 -1
- package/dist/node/structure/Pagination.vue_vue_type_script_setup_true_lang.js +124 -71
- package/dist/node/structure/Pagination.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/node/structure/RichTextContent.js +7 -0
- package/dist/node/structure/RichTextContent.js.map +1 -0
- package/dist/node/structure/RichTextContent.vue_vue_type_script_setup_true_lang.js +298 -0
- package/dist/node/structure/RichTextContent.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/node/structure/RichTextContentBlocks.js +7 -0
- package/dist/node/structure/RichTextContentBlocks.js.map +1 -0
- package/dist/node/structure/RichTextContentBlocks.vue_vue_type_script_setup_true_lang.js +94 -0
- package/dist/node/structure/RichTextContentBlocks.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/node/structure/RichTextContentInlines.js +7 -0
- package/dist/node/structure/RichTextContentInlines.js.map +1 -0
- package/dist/node/structure/RichTextContentInlines.vue_vue_type_script_setup_true_lang.js +69 -0
- package/dist/node/structure/RichTextContentInlines.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/node/structure/RichTextContentItem.js +7 -0
- package/dist/node/structure/RichTextContentItem.js.map +1 -0
- package/dist/node/structure/RichTextContentItem.vue_vue_type_script_setup_true_lang.js +94 -0
- package/dist/node/structure/RichTextContentItem.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/node/structure/code-block.module.js +2 -2
- package/dist/node/structure/code-block.module.js.map +1 -1
- package/dist/node/structure/cursor-pagination.module.js +6 -3
- package/dist/node/structure/cursor-pagination.module.js.map +1 -1
- package/dist/node/structure/pagination.module.js +6 -3
- package/dist/node/structure/pagination.module.js.map +1 -1
- package/dist/node/structure/rich-text-content.module.js +18 -0
- package/dist/node/structure/rich-text-content.module.js.map +1 -0
- package/dist/overlays/Toast.js.map +1 -1
- package/dist/overlays/Toast.vue_vue_type_script_setup_true_lang.js +27 -27
- package/dist/overlays/Toast.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/structure/Accordion.js.map +1 -1
- package/dist/structure/Accordion.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/structure/Accordion.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/structure/Collapsible.js.map +1 -1
- package/dist/structure/Collapsible.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/structure/Collapsible.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/structure/CursorPagination.js.map +1 -1
- package/dist/structure/CursorPagination.vue_vue_type_script_setup_true_lang.js +140 -93
- package/dist/structure/CursorPagination.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/structure/Image.js.map +1 -1
- package/dist/structure/Image.vue_vue_type_script_setup_true_lang.js +30 -18
- package/dist/structure/Image.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/structure/Pagination.js.map +1 -1
- package/dist/structure/Pagination.vue_vue_type_script_setup_true_lang.js +124 -71
- package/dist/structure/Pagination.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/structure/RichTextContent.js +7 -0
- package/dist/structure/RichTextContent.js.map +1 -0
- package/dist/structure/RichTextContent.vue_vue_type_script_setup_true_lang.js +298 -0
- package/dist/structure/RichTextContent.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/structure/RichTextContentBlocks.js +7 -0
- package/dist/structure/RichTextContentBlocks.js.map +1 -0
- package/dist/structure/RichTextContentBlocks.vue_vue_type_script_setup_true_lang.js +94 -0
- package/dist/structure/RichTextContentBlocks.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/structure/RichTextContentInlines.js +7 -0
- package/dist/structure/RichTextContentInlines.js.map +1 -0
- package/dist/structure/RichTextContentInlines.vue_vue_type_script_setup_true_lang.js +69 -0
- package/dist/structure/RichTextContentInlines.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/structure/RichTextContentItem.js +7 -0
- package/dist/structure/RichTextContentItem.js.map +1 -0
- package/dist/structure/RichTextContentItem.vue_vue_type_script_setup_true_lang.js +94 -0
- package/dist/structure/RichTextContentItem.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/structure/code-block.css +1 -1
- package/dist/structure/code-block.module.js +2 -2
- package/dist/structure/code-block.module.js.map +1 -1
- package/dist/structure/cursor-pagination.css +1 -1
- package/dist/structure/cursor-pagination.module.js +6 -3
- package/dist/structure/cursor-pagination.module.js.map +1 -1
- package/dist/structure/pagination.css +1 -1
- package/dist/structure/pagination.module.js +6 -3
- package/dist/structure/pagination.module.js.map +1 -1
- package/dist/structure/rich-text-content.css +1 -0
- package/dist/structure/rich-text-content.module.js +19 -0
- package/dist/structure/rich-text-content.module.js.map +1 -0
- package/dist/types/ai/ArtifactPane.vue.d.ts +1 -1
- package/dist/types/ai/AttachmentChip.vue.d.ts +1 -1
- package/dist/types/ai/ToolCall.vue.d.ts +1 -1
- package/dist/types/controls/RichTextInput.vue.d.ts +210 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/overlays/CommandPanel.vue.d.ts +2 -2
- package/dist/types/structure/Accordion.vue.d.ts +7 -0
- package/dist/types/structure/Collapsible.vue.d.ts +7 -0
- package/dist/types/structure/CursorPagination.vue.d.ts +13 -0
- package/dist/types/structure/EmptyState.vue.d.ts +1 -1
- package/dist/types/structure/Image.vue.d.ts +13 -0
- package/dist/types/structure/Pagination.vue.d.ts +8 -0
- package/dist/types/structure/RichTextContent.vue.d.ts +59 -0
- package/dist/types/structure/RichTextContentBlocks.vue.d.ts +7 -0
- package/dist/types/structure/RichTextContentInlines.vue.d.ts +7 -0
- package/dist/types/structure/RichTextContentItem.vue.d.ts +7 -0
- package/package.json +17 -4
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import e from "../controls/Button.js";
|
|
2
2
|
import t from "../layout/Inline.js";
|
|
3
3
|
import n from "./cursor-pagination.module.js";
|
|
4
|
-
import {
|
|
5
|
-
import { Fragment as
|
|
4
|
+
import { Icon as r, agentMember as i, devWarning as a, useListening as o } from "@polymorph/vue";
|
|
5
|
+
import { Fragment as s, computed as c, createBlock as l, createCommentVNode as u, createElementBlock as d, createElementVNode as f, createTextVNode as ee, createVNode as p, defineComponent as m, normalizeClass as h, onBeforeUnmount as g, onMounted as _, openBlock as v, ref as y, toDisplayString as b, unref as x, useTemplateRef as te, watch as S, withCtx as C } from "vue";
|
|
6
6
|
//#region src/structure/CursorPagination.vue?vue&type=script&setup=true&lang.ts
|
|
7
7
|
var w = [
|
|
8
8
|
"aria-label",
|
|
9
9
|
"aria-busy",
|
|
10
10
|
"data-pending",
|
|
11
11
|
"data-disabled"
|
|
12
|
-
], T = /*@__PURE__*/
|
|
12
|
+
], T = ["href"], E = ["href"], D = ["href"], O = /*@__PURE__*/ m({
|
|
13
13
|
name: "CursorPagination",
|
|
14
14
|
inheritAttrs: !1,
|
|
15
15
|
__name: "CursorPagination",
|
|
@@ -28,173 +28,220 @@ var w = [
|
|
|
28
28
|
end: "No more to load"
|
|
29
29
|
}) },
|
|
30
30
|
mode: { default: "replace" },
|
|
31
|
+
nextHref: {},
|
|
31
32
|
pending: {
|
|
32
33
|
type: Boolean,
|
|
33
34
|
default: !1
|
|
34
35
|
},
|
|
35
|
-
position: {}
|
|
36
|
+
position: {},
|
|
37
|
+
previousHref: {}
|
|
36
38
|
},
|
|
37
39
|
emits: ["next", "previous"],
|
|
38
|
-
setup(
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
setup(m, { emit: O }) {
|
|
41
|
+
let k = m, A = O, j = o(), M = y(null), N = y(null), P = y(null), F = y(null), I = y(!1), L = te("root"), R = c(() => k.messages.more ?? "Load more"), z = c(() => k.messages.end ?? "No more to load"), B = c(() => !k.hasNext && !k.pending), V = c(() => k.mode === "append" ? k.hasNext || k.pending ? ["more"] : [] : ["previous", "next"]), H = c(() => (e) => {
|
|
42
|
+
let t = e.target, n = L.value, r = V.value, i = n === null ? -1 : [...n.querySelectorAll("button, a[href]")].indexOf(t);
|
|
43
|
+
M.value = t, N.value = i < 0 ? null : r[i] ?? null;
|
|
44
|
+
}), U = c(() => (e) => {
|
|
45
|
+
let t = e.target;
|
|
46
|
+
t.matches(":disabled") || queueMicrotask(() => {
|
|
47
|
+
M.value === t && t.isConnected && (M.value = null);
|
|
48
|
+
});
|
|
49
|
+
}), W = c(() => () => {
|
|
50
|
+
let e = L.value;
|
|
45
51
|
if (e === null) return;
|
|
46
|
-
let t =
|
|
47
|
-
if (!
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
let t = V.value, n = () => [...e.querySelectorAll("button, a[href]")], r = () => document.activeElement === null || document.activeElement === document.body, i = M.value;
|
|
53
|
+
if (i !== null && !i.isConnected) {
|
|
54
|
+
M.value = null;
|
|
55
|
+
let e = N.value, i = e === null ? void 0 : n()[t.indexOf(e)];
|
|
56
|
+
i !== void 0 && r() && (i.matches(":disabled") ? M.value = i : i.focus());
|
|
57
|
+
}
|
|
58
|
+
if (!k.disabled) {
|
|
59
|
+
let r = P.value;
|
|
60
|
+
if (P.value = null, r === null || document.activeElement !== e) return;
|
|
61
|
+
let i = n()[t.indexOf(r)];
|
|
62
|
+
i !== void 0 && !i.matches(":disabled") && i.focus();
|
|
52
63
|
return;
|
|
53
64
|
}
|
|
54
|
-
let
|
|
55
|
-
if (
|
|
56
|
-
let
|
|
57
|
-
|
|
65
|
+
let a = M.value;
|
|
66
|
+
if (a === null || !a.isConnected || !a.matches(":disabled")) return;
|
|
67
|
+
let o = document.activeElement;
|
|
68
|
+
o !== a && o !== null && o !== document.body || (P.value = t[n().indexOf(a)] ?? null, e.focus());
|
|
69
|
+
}), G = c(() => k.previousHref !== void 0 && k.hasPrevious && !k.pending && !k.disabled), K = c(() => k.nextHref !== void 0 && k.hasNext && !k.pending && !k.disabled), q = c(() => (e) => !e.defaultPrevented && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey), ne = c(() => (e) => {
|
|
70
|
+
q.value(e) && (e.preventDefault(), F.value = "previous", A("previous"));
|
|
71
|
+
}), J = c(() => (e) => {
|
|
72
|
+
q.value(e) && (e.preventDefault(), F.value = "next", k.mode === "append" && (I.value = !0), A("next"));
|
|
58
73
|
});
|
|
59
|
-
S(() =>
|
|
60
|
-
|
|
74
|
+
S(() => k.pending, () => {
|
|
75
|
+
k.pending || (F.value = null);
|
|
61
76
|
}, { flush: "post" });
|
|
62
|
-
let
|
|
63
|
-
|
|
77
|
+
let Y = () => {
|
|
78
|
+
a(k.mode !== "append" && k.hasPrevious && !j.previous, "CursorPagination: `hasPrevious` with no `onPrevious` draws a previous button that does nothing.");
|
|
64
79
|
};
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
|
|
80
|
+
_(Y), S(() => k.mode !== "append" && k.hasPrevious && !j.previous, Y, { flush: "post" });
|
|
81
|
+
let X = () => {
|
|
82
|
+
a(k.mode === "append" && (k.messages.more === void 0 || k.messages.end === void 0), "CursorPagination: the append form shows `messages.more` and `messages.end`; pass them with the others, so one control never mixes two languages.");
|
|
68
83
|
};
|
|
69
|
-
|
|
70
|
-
let
|
|
71
|
-
|
|
84
|
+
_(X), S(() => k.mode === "append" && (k.messages.more === void 0 || k.messages.end === void 0), X, { flush: "post" });
|
|
85
|
+
let Z, Q = () => {
|
|
86
|
+
Z?.();
|
|
72
87
|
let e = () => {
|
|
73
|
-
|
|
88
|
+
W.value();
|
|
74
89
|
}, t = typeof MutationObserver > "u" ? void 0 : new MutationObserver(e);
|
|
75
|
-
for (let e of [
|
|
90
|
+
for (let e of [L.value]) e && t?.observe(e, {
|
|
76
91
|
childList: !0,
|
|
77
92
|
characterData: !0,
|
|
78
93
|
subtree: !0,
|
|
79
94
|
attributeFilter: ["disabled"]
|
|
80
95
|
});
|
|
81
|
-
|
|
96
|
+
Z = () => {
|
|
82
97
|
t?.disconnect();
|
|
83
98
|
}, e();
|
|
84
99
|
};
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
_(Q), S(() => k.mode === "append" ? k.hasNext || k.pending || I.value : k.hasPrevious || k.hasNext || k.pending, Q, { flush: "post" }), g(() => Z?.()), S(() => k.disabled, () => {
|
|
101
|
+
W.value();
|
|
87
102
|
}, { flush: "post" });
|
|
88
|
-
let
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
let e =
|
|
103
|
+
let $;
|
|
104
|
+
return _(() => {
|
|
105
|
+
$?.();
|
|
106
|
+
let e = i({
|
|
92
107
|
member: "CursorPagination",
|
|
93
|
-
element: () =>
|
|
108
|
+
element: () => L.value,
|
|
94
109
|
state: () => ({
|
|
95
|
-
"has-previous":
|
|
96
|
-
"has-next":
|
|
97
|
-
position:
|
|
98
|
-
pending:
|
|
99
|
-
disabled:
|
|
110
|
+
"has-previous": k.mode !== "append" && k.hasPrevious,
|
|
111
|
+
"has-next": k.hasNext,
|
|
112
|
+
position: k.position ?? "",
|
|
113
|
+
pending: k.pending,
|
|
114
|
+
disabled: k.disabled
|
|
100
115
|
}),
|
|
101
116
|
actions: {
|
|
102
117
|
previous: () => (() => {
|
|
103
|
-
if (
|
|
104
|
-
if (!
|
|
105
|
-
if (
|
|
106
|
-
|
|
118
|
+
if (k.mode === "append") throw Error("The append form has no previous window.");
|
|
119
|
+
if (!k.hasPrevious) throw Error("There is no previous window.");
|
|
120
|
+
if (k.pending) throw Error("A window is in flight; wait for it to arrive.");
|
|
121
|
+
F.value = "previous", A("previous");
|
|
107
122
|
})(),
|
|
108
123
|
next: () => (() => {
|
|
109
|
-
if (!
|
|
110
|
-
if (
|
|
111
|
-
|
|
124
|
+
if (!k.hasNext) throw Error("There is no next window.");
|
|
125
|
+
if (k.pending) throw Error("A window is in flight; wait for it to arrive.");
|
|
126
|
+
F.value = "next", k.mode === "append" && (I.value = !0), A("next");
|
|
112
127
|
})()
|
|
113
128
|
},
|
|
114
|
-
withholds: () =>
|
|
129
|
+
withholds: () => L.value
|
|
115
130
|
});
|
|
116
|
-
|
|
131
|
+
$ = () => {
|
|
117
132
|
e();
|
|
118
133
|
};
|
|
119
|
-
}),
|
|
134
|
+
}), g(() => $?.()), (i, a) => (m.mode === "append" ? m.hasNext || m.pending || I.value : m.hasPrevious || m.hasNext || m.pending) ? (v(), d("nav", {
|
|
120
135
|
key: 0,
|
|
121
136
|
ref_key: "root",
|
|
122
|
-
ref:
|
|
123
|
-
class:
|
|
124
|
-
"aria-label":
|
|
125
|
-
"aria-busy":
|
|
126
|
-
"data-pending":
|
|
127
|
-
"data-disabled":
|
|
137
|
+
ref: L,
|
|
138
|
+
class: h(x(n).pagination),
|
|
139
|
+
"aria-label": m.label,
|
|
140
|
+
"aria-busy": m.pending ? !0 : void 0,
|
|
141
|
+
"data-pending": m.pending ? "" : void 0,
|
|
142
|
+
"data-disabled": m.disabled ? "" : void 0,
|
|
128
143
|
tabindex: "-1",
|
|
129
144
|
"data-member": "cursor-pagination",
|
|
130
|
-
onFocusin:
|
|
131
|
-
onFocusout:
|
|
132
|
-
}, [
|
|
145
|
+
onFocusin: a[6] ||= (e) => H.value(e),
|
|
146
|
+
onFocusout: a[7] ||= (e) => U.value(e)
|
|
147
|
+
}, [p(t, {
|
|
133
148
|
gap: 2,
|
|
134
149
|
align: "center",
|
|
135
150
|
wrap: !0
|
|
136
151
|
}, {
|
|
137
|
-
default: C(() => [
|
|
152
|
+
default: C(() => [m.mode === "append" ? (v(), d(s, { key: 0 }, [m.position === void 0 ? u("", !0) : (v(), d("span", {
|
|
138
153
|
key: 0,
|
|
139
|
-
class:
|
|
154
|
+
class: h(x(n).position),
|
|
140
155
|
"aria-live": "polite"
|
|
141
|
-
},
|
|
156
|
+
}, b(m.position), 3)), !B.value && K.value ? (v(), d("a", {
|
|
142
157
|
key: 1,
|
|
158
|
+
class: h(x(n).link),
|
|
159
|
+
href: m.nextHref,
|
|
160
|
+
"data-variant": "outline",
|
|
161
|
+
"data-size": "sm",
|
|
162
|
+
"data-tone": "neutral",
|
|
163
|
+
onClick: a[0] ||= (e) => J.value(e)
|
|
164
|
+
}, [f("span", { class: h(x(n).linkLabel) }, b(R.value), 3)], 10, T)) : B.value ? u("", !0) : (v(), l(e, {
|
|
165
|
+
key: 2,
|
|
143
166
|
variant: "outline",
|
|
144
167
|
tone: "neutral",
|
|
145
168
|
size: "sm",
|
|
146
|
-
label:
|
|
147
|
-
loading:
|
|
148
|
-
disabled:
|
|
149
|
-
onClick:
|
|
169
|
+
label: R.value,
|
|
170
|
+
loading: m.pending,
|
|
171
|
+
disabled: m.disabled && !m.pending,
|
|
172
|
+
onClick: a[1] ||= (e) => (F.value = "next", I.value = !0, A("next"))
|
|
150
173
|
}, null, 8, [
|
|
151
174
|
"label",
|
|
152
175
|
"loading",
|
|
153
176
|
"disabled"
|
|
154
|
-
]))], 64)) : (
|
|
155
|
-
|
|
177
|
+
]))], 64)) : (v(), d(s, { key: 1 }, [
|
|
178
|
+
G.value ? (v(), d("a", {
|
|
179
|
+
key: 0,
|
|
180
|
+
class: h(x(n).link),
|
|
181
|
+
href: m.previousHref,
|
|
182
|
+
"data-variant": "ghost",
|
|
183
|
+
"data-size": "sm",
|
|
184
|
+
"data-tone": "neutral",
|
|
185
|
+
onClick: a[2] ||= (e) => ne.value(e)
|
|
186
|
+
}, [f("span", { class: h(x(n).linkGlyph) }, [p(x(r), {
|
|
187
|
+
name: "previous",
|
|
188
|
+
size: "sm"
|
|
189
|
+
})], 2), f("span", { class: h(x(n).linkLabel) }, b(m.messages.previous), 3)], 10, E)) : (v(), l(e, {
|
|
190
|
+
key: 1,
|
|
156
191
|
variant: "ghost",
|
|
157
192
|
tone: "neutral",
|
|
158
193
|
size: "sm",
|
|
159
194
|
icon: "previous",
|
|
160
|
-
label:
|
|
161
|
-
loading:
|
|
162
|
-
disabled: !
|
|
163
|
-
onClick:
|
|
195
|
+
label: m.messages.previous,
|
|
196
|
+
loading: m.pending && F.value === "previous",
|
|
197
|
+
disabled: !m.hasPrevious || (m.pending ? F.value !== "previous" : m.disabled),
|
|
198
|
+
onClick: a[3] ||= (e) => (F.value = "previous", A("previous"))
|
|
164
199
|
}, null, 8, [
|
|
165
200
|
"label",
|
|
166
201
|
"loading",
|
|
167
202
|
"disabled"
|
|
168
|
-
]),
|
|
169
|
-
|
|
170
|
-
key:
|
|
171
|
-
class:
|
|
203
|
+
])),
|
|
204
|
+
m.position === void 0 ? u("", !0) : (v(), d("span", {
|
|
205
|
+
key: 2,
|
|
206
|
+
class: h(x(n).position),
|
|
172
207
|
"aria-live": "polite"
|
|
173
|
-
},
|
|
174
|
-
|
|
208
|
+
}, b(m.position), 3)),
|
|
209
|
+
K.value ? (v(), d("a", {
|
|
210
|
+
key: 3,
|
|
211
|
+
class: h(x(n).link),
|
|
212
|
+
href: m.nextHref,
|
|
213
|
+
"data-variant": "ghost",
|
|
214
|
+
"data-size": "sm",
|
|
215
|
+
"data-tone": "neutral",
|
|
216
|
+
onClick: a[4] ||= (e) => J.value(e)
|
|
217
|
+
}, [f("span", { class: h(x(n).linkLabel) }, b(m.messages.next), 3), f("span", { class: h(x(n).linkGlyph) }, [p(x(r), {
|
|
218
|
+
name: "next",
|
|
219
|
+
size: "sm"
|
|
220
|
+
})], 2)], 10, D)) : (v(), l(e, {
|
|
221
|
+
key: 4,
|
|
175
222
|
variant: "ghost",
|
|
176
223
|
tone: "neutral",
|
|
177
224
|
size: "sm",
|
|
178
225
|
trailingIcon: "next",
|
|
179
|
-
label:
|
|
180
|
-
loading:
|
|
181
|
-
disabled: !
|
|
182
|
-
onClick:
|
|
226
|
+
label: m.messages.next,
|
|
227
|
+
loading: m.pending && F.value === "next",
|
|
228
|
+
disabled: !m.hasNext || (m.pending ? F.value !== "next" : m.disabled),
|
|
229
|
+
onClick: a[5] ||= (e) => (F.value = "next", A("next"))
|
|
183
230
|
}, null, 8, [
|
|
184
231
|
"label",
|
|
185
232
|
"loading",
|
|
186
233
|
"disabled"
|
|
187
|
-
])
|
|
234
|
+
]))
|
|
188
235
|
], 64))]),
|
|
189
236
|
_: 1
|
|
190
|
-
}),
|
|
237
|
+
}), m.mode === "append" ? (v(), d("span", {
|
|
191
238
|
key: 0,
|
|
192
|
-
class:
|
|
239
|
+
class: h(x(n).end),
|
|
193
240
|
role: "status"
|
|
194
|
-
}, [
|
|
241
|
+
}, [B.value ? (v(), d(s, { key: 0 }, [ee(b(z.value), 1)], 64)) : u("", !0)], 2)) : u("", !0)], 42, w)) : u("", !0);
|
|
195
242
|
}
|
|
196
243
|
});
|
|
197
244
|
//#endregion
|
|
198
|
-
export {
|
|
245
|
+
export { O as default };
|
|
199
246
|
|
|
200
247
|
//# sourceMappingURL=CursorPagination.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CursorPagination.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../../src/structure/CursorPagination.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * Previous and next controls for a cursor-paged list (`design/components/cursor-pagination.md`).\n *\n * Generated by `pnpm shells` from `packages/shells/src/members/cursor-pagination.ts`, the member's\n * framework-neutral description. Never edit it by hand: change the description and\n * run `pnpm shells`.\n */\nimport { computed, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\n\nimport { agentMember, devWarning, useListening } from '@polymorph/vue'\nimport styles from '@polymorph/recipes/structure/cursor-pagination.module.css'\nimport Button from '../controls/Button.vue'\nimport Inline from '../layout/Inline.vue'\n\nexport interface CursorPaginationMessages {\n previous: string\n next: string\n more?: string\n end?: string\n}\n\nexport interface CursorPaginationProps {\n /**\n * The app holds the pager while it does something else to the list: every control is disabled\n * and none shows busy. Not `pending`, which says the pager's own request is in flight.\n */\n disabled?: boolean\n hasNext: boolean\n /**\n * Whether the list returned a cursor that way; controlled, as cursors belong to the list. The\n * append form does not read it: it has no previous direction.\n */\n hasPrevious: boolean\n label?: string\n /**\n * Omit for the generic English defaults; localized hosts pass their own.\n */\n messages?: CursorPaginationMessages\n /**\n * `replace` (the default) swaps the window for its neighbour, so the list stays bounded.\n * `append` is \"Load more\": one action that adds the next window below the ones on screen, for\n * a feed or a log read from the top.\n */\n mode?: 'replace' | 'append'\n /**\n * The requested window has not arrived: the pressed direction shows busy and the other is\n * disabled, so a slow fetch cannot be followed by a second request.\n */\n pending?: boolean\n /**\n * The current window in the app's words, such as \"26–50\" or \"Newest first, page 2\"; never a\n * total, because the list does not return one.\n */\n position?: string\n}\n\ndefineOptions({ name: 'CursorPagination', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CursorPaginationProps>(), {\n disabled: false,\n label: 'Pagination',\n messages: () => ({\n previous: 'Previous',\n next: 'Next',\n more: 'Load more',\n end: 'No more to load',\n }),\n mode: 'replace',\n pending: false,\n})\nconst emit = defineEmits<{ next: []; previous: [] }>()\nconst listening = useListening()\nconst focused = ref(null as HTMLElement | null)\nconst taken = ref(null as string | number | null)\nconst asked = ref(null as 'previous' | 'next' | null)\nconst paged = ref(false)\nconst root = useTemplateRef<HTMLElement>('root')\nconst more = computed(() => props.messages.more ?? 'Load more')\nconst end = computed(() => props.messages.end ?? 'No more to load')\nconst ended = computed(() => !props.hasNext && !props.pending)\nconst controls = computed(() =>\n props.mode === 'append' ? (props.hasNext || props.pending ? ['more'] : []) : ['previous', 'next'],\n)\nconst focusIn = computed(() => (event: FocusEvent) => {\n focused.value = event.target as HTMLElement\n})\nconst focusOut = computed(() => (event: FocusEvent) => {\n if (!(event.target as HTMLElement).matches(':disabled')) focused.value = null\n})\nconst keepPlace = computed(() => () => {\n const pager = root.value as HTMLElement | null\n if (pager === null) return\n const names: readonly (string | number)[] = controls.value\n if (!props.disabled) {\n const control = taken.value\n taken.value = null\n if (control === null || document.activeElement !== pager) return\n const button = [...pager.querySelectorAll('button')][names.indexOf(control)]\n if (button !== undefined && !button.matches(':disabled')) button.focus()\n return\n }\n const from = focused.value as HTMLElement | null\n if (from === null || !from.isConnected || !from.matches(':disabled')) return\n const active = document.activeElement\n if (active !== from && active !== null && active !== document.body) return\n taken.value =\n names[[...pager.querySelectorAll('button')].indexOf(from as HTMLButtonElement)] ?? null\n pager.focus()\n})\nconst effect1 = () => {\n props.pending || (asked.value = null)\n}\nwatch(() => props.pending, effect1, { flush: 'post' })\nconst effect2 = () => {\n devWarning(\n props.mode !== 'append' && props.hasPrevious && !listening.previous,\n 'CursorPagination: `hasPrevious` with no `onPrevious` draws a previous button that does nothing.',\n )\n}\nonMounted(effect2)\nwatch(() => props.mode !== 'append' && props.hasPrevious && !listening.previous, effect2, {\n flush: 'post',\n})\nconst effect3 = () => {\n devWarning(\n props.mode === 'append' &&\n (props.messages.more === undefined || props.messages.end === undefined),\n 'CursorPagination: the append form shows `messages.more` and `messages.end`; pass them with the others, so one control never mixes two languages.',\n )\n}\nonMounted(effect3)\nwatch(\n () =>\n props.mode === 'append' &&\n (props.messages.more === undefined || props.messages.end === undefined),\n effect3,\n { flush: 'post' },\n)\nlet release4: (() => void) | undefined\nconst effect4 = () => {\n release4?.()\n const run = () => {\n keepPlace.value()\n }\n const mutation = typeof MutationObserver === 'undefined' ? undefined : new MutationObserver(run)\n for (const element of [root.value])\n if (element)\n mutation?.observe(element, {\n childList: true,\n characterData: true,\n subtree: true,\n attributeFilter: ['disabled'],\n })\n release4 = () => {\n mutation?.disconnect()\n }\n run()\n}\nonMounted(effect4)\nwatch(\n () =>\n props.mode === 'append'\n ? props.hasNext || props.pending || paged.value\n : props.hasPrevious || props.hasNext || props.pending,\n effect4,\n { flush: 'post' },\n)\nonBeforeUnmount(() => release4?.())\nconst effect5 = () => {\n keepPlace.value()\n}\nwatch(() => props.disabled, effect5, { flush: 'post' })\nlet release6: (() => void) | undefined\nconst effect6 = () => {\n release6?.()\n const ran = agentMember({\n member: 'CursorPagination',\n element: () => root.value,\n state: () => ({\n 'has-previous': props.mode !== 'append' && props.hasPrevious,\n 'has-next': props.hasNext,\n position: props.position ?? '',\n pending: props.pending,\n disabled: props.disabled,\n }),\n actions: {\n previous: () =>\n (() => {\n if (props.mode === 'append') throw new Error('The append form has no previous window.')\n if (!props.hasPrevious) throw new Error('There is no previous window.')\n if (props.pending) throw new Error('A window is in flight; wait for it to arrive.')\n asked.value = 'previous'\n emit('previous')\n })(),\n next: () =>\n (() => {\n if (!props.hasNext) throw new Error('There is no next window.')\n if (props.pending) throw new Error('A window is in flight; wait for it to arrive.')\n asked.value = 'next'\n if (props.mode === 'append') paged.value = true\n emit('next')\n })(),\n },\n withholds: () => root.value,\n })\n release6 = () => {\n ran()\n }\n}\nonMounted(effect6)\nonBeforeUnmount(() => release6?.())\n</script>\n\n<template>\n <nav\n v-if=\"mode === 'append' ? hasNext || pending || paged : hasPrevious || hasNext || pending\"\n ref=\"root\"\n :class=\"styles.pagination\"\n :aria-label=\"label\"\n :aria-busy=\"pending ? true : undefined\"\n :data-pending=\"pending ? '' : undefined\"\n :data-disabled=\"disabled ? '' : undefined\"\n tabindex=\"-1\"\n data-member=\"cursor-pagination\"\n @focusin=\"focusIn($event)\"\n @focusout=\"focusOut($event)\"\n >\n <Inline :gap=\"2\" align=\"center\" :wrap=\"true\">\n <template v-if=\"mode === 'append'\">\n <!-- position -->\n <span v-if=\"position !== undefined\" :class=\"styles.position\" aria-live=\"polite\">\n {{ position }}\n </span>\n <Button\n v-if=\"!ended\"\n variant=\"outline\"\n tone=\"neutral\"\n size=\"sm\"\n :label=\"more\"\n :loading=\"pending\"\n :disabled=\"disabled && !pending\"\n @click=\"((asked = 'next'), (paged = true), emit('next'))\"\n />\n </template>\n <template v-else>\n <Button\n variant=\"ghost\"\n tone=\"neutral\"\n size=\"sm\"\n icon=\"previous\"\n :label=\"messages.previous\"\n :loading=\"pending && asked === 'previous'\"\n :disabled=\"!hasPrevious || (pending ? asked !== 'previous' : disabled)\"\n @click=\"((asked = 'previous'), emit('previous'))\"\n />\n <!-- position -->\n <span v-if=\"position !== undefined\" :class=\"styles.position\" aria-live=\"polite\">\n {{ position }}\n </span>\n <Button\n variant=\"ghost\"\n tone=\"neutral\"\n size=\"sm\"\n trailingIcon=\"next\"\n :label=\"messages.next\"\n :loading=\"pending && asked === 'next'\"\n :disabled=\"!hasNext || (pending ? asked !== 'next' : disabled)\"\n @click=\"((asked = 'next'), emit('next'))\"\n />\n </template>\n </Inline>\n <!-- end -->\n <span v-if=\"mode === 'append'\" :class=\"styles.end\" role=\"status\">\n <template v-if=\"ended\">{{ end }}</template>\n </span>\n </nav>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DA,IAAM,IAAQ,GAYR,IAAO,GACP,IAAY,EAAa,GACzB,IAAU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A,EAAA,GAAhB,EAEO,QAAA;;GAFyB,OAAK,EAAE,EAAA,CAAA,CAAM,CAAC,GAAG;GAAE,MAAK;MACtC,EAAA,SAAA,EAAA,GAAhB,EAA2C,GAAA,EAAA,KAAA,EAAA,GAAA,CAAA,EAAA,EAAjB,EAAA,KAAG,GAAA,CAAA,CAAA,GAAA,EAAA,KAAA,EAAA,IAAA,EAAA,CAAA,GAAA,CAAA,KAAA,EAAA,IAAA,EAAA,CAAA,GAAA,IAAA,CAAA,KAAA,EAAA,IAAA,EAAA"}
|
|
1
|
+
{"version":3,"file":"CursorPagination.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../../src/structure/CursorPagination.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * Previous and next controls for a cursor-paged list (`design/components/cursor-pagination.md`).\n *\n * Generated by `pnpm shells` from `packages/shells/src/members/cursor-pagination.ts`, the member's\n * framework-neutral description. Never edit it by hand: change the description and\n * run `pnpm shells`.\n */\nimport { computed, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue'\n\nimport { Icon, agentMember, devWarning, useListening } from '@polymorph/vue'\nimport styles from '@polymorph/recipes/structure/cursor-pagination.module.css'\nimport Button from '../controls/Button.vue'\nimport Inline from '../layout/Inline.vue'\n\nexport interface CursorPaginationMessages {\n previous: string\n next: string\n more?: string\n end?: string\n}\n\nexport interface CursorPaginationProps {\n /**\n * The app holds the pager while it does something else to the list: every control is disabled\n * and none shows busy. Not `pending`, which says the pager's own request is in flight.\n */\n disabled?: boolean\n hasNext: boolean\n /**\n * Whether the list returned a cursor that way; controlled, as cursors belong to the list. The\n * append form does not read it: it has no previous direction.\n */\n hasPrevious: boolean\n label?: string\n /**\n * Omit for the generic English defaults; localized hosts pass their own.\n */\n messages?: CursorPaginationMessages\n /**\n * `replace` (the default) swaps the window for its neighbour, so the list stays bounded.\n * `append` is \"Load more\": one action that adds the next window below the ones on screen, for\n * a feed or a log read from the top.\n */\n mode?: 'replace' | 'append'\n /**\n * The next window's address, as `previousHref` is the previous one's: next, or in the append\n * form its action, is a link to it while it can be pressed, and a plain click calls `onNext`.\n */\n nextHref?: string\n /**\n * The requested window has not arrived: the pressed direction shows busy and the other is\n * disabled, so a slow fetch cannot be followed by a second request.\n */\n pending?: boolean\n /**\n * The current window in the app's words, such as \"26–50\" or \"Newest first, page 2\"; never a\n * total, because the list does not return one.\n */\n position?: string\n /**\n * The previous window's address, such as `?before=c25`. Given, previous is a link to it while\n * it can be pressed, so a crawler, a new tab and a reader whose script has not loaded can\n * follow it. A click the browser would follow in this tab calls `onPrevious` in place of the\n * navigation; a click with a modifier key opens the address. The append form does not read it:\n * it has no previous direction.\n */\n previousHref?: string\n}\n\ndefineOptions({ name: 'CursorPagination', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CursorPaginationProps>(), {\n disabled: false,\n label: 'Pagination',\n messages: () => ({\n previous: 'Previous',\n next: 'Next',\n more: 'Load more',\n end: 'No more to load',\n }),\n mode: 'replace',\n pending: false,\n})\nconst emit = defineEmits<{ next: []; previous: [] }>()\nconst listening = useListening()\nconst focused = ref(null as HTMLElement | null)\nconst focusedControl = ref(null as string | number | null)\nconst taken = ref(null as string | number | null)\nconst asked = ref(null as 'previous' | 'next' | null)\nconst paged = ref(false)\nconst root = useTemplateRef<HTMLElement>('root')\nconst more = computed(() => props.messages.more ?? 'Load more')\nconst end = computed(() => props.messages.end ?? 'No more to load')\nconst ended = computed(() => !props.hasNext && !props.pending)\nconst controls = computed(() =>\n props.mode === 'append' ? (props.hasNext || props.pending ? ['more'] : []) : ['previous', 'next'],\n)\nconst focusIn = computed(() => (event: FocusEvent) => {\n const target = event.target as HTMLElement\n const pager = root.value as HTMLElement | null\n const names: readonly (string | number)[] = controls.value\n const at = pager === null ? -1 : [...pager.querySelectorAll('button, a[href]')].indexOf(target)\n focused.value = target\n focusedControl.value = at < 0 ? null : (names[at] ?? null)\n})\nconst focusOut = computed(() => (event: FocusEvent) => {\n const target = event.target as HTMLElement\n if (target.matches(':disabled')) return\n queueMicrotask(() => {\n if (focused.value === target && target.isConnected) focused.value = null\n })\n})\nconst keepPlace = computed(() => () => {\n const pager = root.value as HTMLElement | null\n if (pager === null) return\n const names: readonly (string | number)[] = controls.value\n const drawn = () => [...pager.querySelectorAll<HTMLElement>('button, a[href]')]\n const onPage = () => document.activeElement === null || document.activeElement === document.body\n const left = focused.value as HTMLElement | null\n if (left !== null && !left.isConnected) {\n focused.value = null\n const name = focusedControl.value\n const now = name === null ? undefined : drawn()[names.indexOf(name)]\n if (now !== undefined && onPage()) {\n if (now.matches(':disabled')) focused.value = now\n else now.focus()\n }\n }\n if (!props.disabled) {\n const control = taken.value\n taken.value = null\n if (control === null || document.activeElement !== pager) return\n const element = drawn()[names.indexOf(control)]\n if (element !== undefined && !element.matches(':disabled')) element.focus()\n return\n }\n const from = focused.value as HTMLElement | null\n if (from === null || !from.isConnected || !from.matches(':disabled')) return\n const active = document.activeElement\n if (active !== from && active !== null && active !== document.body) return\n taken.value = names[drawn().indexOf(from)] ?? null\n pager.focus()\n})\nconst previousLink = computed(\n () => props.previousHref !== undefined && props.hasPrevious && !props.pending && !props.disabled,\n)\nconst nextLink = computed(\n () => props.nextHref !== undefined && props.hasNext && !props.pending && !props.disabled,\n)\nconst navigatesHere = computed(\n () =>\n (event: MouseEvent): boolean =>\n !event.defaultPrevented &&\n event.button === 0 &&\n !event.metaKey &&\n !event.ctrlKey &&\n !event.shiftKey &&\n !event.altKey,\n)\nconst followPrevious = computed(() => (event: MouseEvent): void => {\n if (!navigatesHere.value(event)) return\n event.preventDefault()\n asked.value = 'previous'\n emit('previous')\n})\nconst followNext = computed(() => (event: MouseEvent): void => {\n if (!navigatesHere.value(event)) return\n event.preventDefault()\n asked.value = 'next'\n if (props.mode === 'append') paged.value = true\n emit('next')\n})\nconst effect1 = () => {\n props.pending || (asked.value = null)\n}\nwatch(() => props.pending, effect1, { flush: 'post' })\nconst effect2 = () => {\n devWarning(\n props.mode !== 'append' && props.hasPrevious && !listening.previous,\n 'CursorPagination: `hasPrevious` with no `onPrevious` draws a previous button that does nothing.',\n )\n}\nonMounted(effect2)\nwatch(() => props.mode !== 'append' && props.hasPrevious && !listening.previous, effect2, {\n flush: 'post',\n})\nconst effect3 = () => {\n devWarning(\n props.mode === 'append' &&\n (props.messages.more === undefined || props.messages.end === undefined),\n 'CursorPagination: the append form shows `messages.more` and `messages.end`; pass them with the others, so one control never mixes two languages.',\n )\n}\nonMounted(effect3)\nwatch(\n () =>\n props.mode === 'append' &&\n (props.messages.more === undefined || props.messages.end === undefined),\n effect3,\n { flush: 'post' },\n)\nlet release4: (() => void) | undefined\nconst effect4 = () => {\n release4?.()\n const run = () => {\n keepPlace.value()\n }\n const mutation = typeof MutationObserver === 'undefined' ? undefined : new MutationObserver(run)\n for (const element of [root.value])\n if (element)\n mutation?.observe(element, {\n childList: true,\n characterData: true,\n subtree: true,\n attributeFilter: ['disabled'],\n })\n release4 = () => {\n mutation?.disconnect()\n }\n run()\n}\nonMounted(effect4)\nwatch(\n () =>\n props.mode === 'append'\n ? props.hasNext || props.pending || paged.value\n : props.hasPrevious || props.hasNext || props.pending,\n effect4,\n { flush: 'post' },\n)\nonBeforeUnmount(() => release4?.())\nconst effect5 = () => {\n keepPlace.value()\n}\nwatch(() => props.disabled, effect5, { flush: 'post' })\nlet release6: (() => void) | undefined\nconst effect6 = () => {\n release6?.()\n const ran = agentMember({\n member: 'CursorPagination',\n element: () => root.value,\n state: () => ({\n 'has-previous': props.mode !== 'append' && props.hasPrevious,\n 'has-next': props.hasNext,\n position: props.position ?? '',\n pending: props.pending,\n disabled: props.disabled,\n }),\n actions: {\n previous: () =>\n (() => {\n if (props.mode === 'append') throw new Error('The append form has no previous window.')\n if (!props.hasPrevious) throw new Error('There is no previous window.')\n if (props.pending) throw new Error('A window is in flight; wait for it to arrive.')\n asked.value = 'previous'\n emit('previous')\n })(),\n next: () =>\n (() => {\n if (!props.hasNext) throw new Error('There is no next window.')\n if (props.pending) throw new Error('A window is in flight; wait for it to arrive.')\n asked.value = 'next'\n if (props.mode === 'append') paged.value = true\n emit('next')\n })(),\n },\n withholds: () => root.value,\n })\n release6 = () => {\n ran()\n }\n}\nonMounted(effect6)\nonBeforeUnmount(() => release6?.())\n</script>\n\n<template>\n <nav\n v-if=\"mode === 'append' ? hasNext || pending || paged : hasPrevious || hasNext || pending\"\n ref=\"root\"\n :class=\"styles.pagination\"\n :aria-label=\"label\"\n :aria-busy=\"pending ? true : undefined\"\n :data-pending=\"pending ? '' : undefined\"\n :data-disabled=\"disabled ? '' : undefined\"\n tabindex=\"-1\"\n data-member=\"cursor-pagination\"\n @focusin=\"focusIn($event)\"\n @focusout=\"focusOut($event)\"\n >\n <Inline :gap=\"2\" align=\"center\" :wrap=\"true\">\n <template v-if=\"mode === 'append'\">\n <!-- position -->\n <span v-if=\"position !== undefined\" :class=\"styles.position\" aria-live=\"polite\">\n {{ position }}\n </span>\n <!-- link -->\n <a\n v-if=\"!ended && nextLink\"\n :class=\"styles.link\"\n :href=\"nextHref\"\n data-variant=\"outline\"\n data-size=\"sm\"\n data-tone=\"neutral\"\n @click=\"followNext($event)\"\n >\n <!-- label -->\n <span :class=\"styles.linkLabel\">\n {{ more }}\n </span>\n </a>\n <Button\n v-else-if=\"!ended\"\n variant=\"outline\"\n tone=\"neutral\"\n size=\"sm\"\n :label=\"more\"\n :loading=\"pending\"\n :disabled=\"disabled && !pending\"\n @click=\"((asked = 'next'), (paged = true), emit('next'))\"\n />\n </template>\n <template v-else>\n <!-- link -->\n <a\n v-if=\"previousLink\"\n :class=\"styles.link\"\n :href=\"previousHref\"\n data-variant=\"ghost\"\n data-size=\"sm\"\n data-tone=\"neutral\"\n @click=\"followPrevious($event)\"\n >\n <!-- glyph -->\n <span :class=\"styles.linkGlyph\">\n <Icon name=\"previous\" size=\"sm\" />\n </span>\n <!-- label -->\n <span :class=\"styles.linkLabel\">\n {{ messages.previous }}\n </span>\n </a>\n <Button\n v-else\n variant=\"ghost\"\n tone=\"neutral\"\n size=\"sm\"\n icon=\"previous\"\n :label=\"messages.previous\"\n :loading=\"pending && asked === 'previous'\"\n :disabled=\"!hasPrevious || (pending ? asked !== 'previous' : disabled)\"\n @click=\"((asked = 'previous'), emit('previous'))\"\n />\n <!-- position -->\n <span v-if=\"position !== undefined\" :class=\"styles.position\" aria-live=\"polite\">\n {{ position }}\n </span>\n <!-- link -->\n <a\n v-if=\"nextLink\"\n :class=\"styles.link\"\n :href=\"nextHref\"\n data-variant=\"ghost\"\n data-size=\"sm\"\n data-tone=\"neutral\"\n @click=\"followNext($event)\"\n >\n <!-- label -->\n <span :class=\"styles.linkLabel\">\n {{ messages.next }}\n </span>\n <!-- glyph -->\n <span :class=\"styles.linkGlyph\">\n <Icon name=\"next\" size=\"sm\" />\n </span>\n </a>\n <Button\n v-else\n variant=\"ghost\"\n tone=\"neutral\"\n size=\"sm\"\n trailingIcon=\"next\"\n :label=\"messages.next\"\n :loading=\"pending && asked === 'next'\"\n :disabled=\"!hasNext || (pending ? asked !== 'next' : disabled)\"\n @click=\"((asked = 'next'), emit('next'))\"\n />\n </template>\n </Inline>\n <!-- end -->\n <span v-if=\"mode === 'append'\" :class=\"styles.end\" role=\"status\">\n <template v-if=\"ended\">{{ end }}</template>\n </span>\n </nav>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwEA,IAAM,IAAQ,GAYR,IAAO,GACP,IAAY,EAAa,GACzB,IAAU,EAAI,IAA0B,GACxC,IAAiB,EAAI,IAA8B,GACnD,IAAQ,EAAI,IAA8B,GAC1C,IAAQ,EAAI,IAAkC,GAC9C,IAAQ,EAAI,EAAK,GACjB,IAAO,GAA4B,MAAM,GACzC,IAAO,QAAe,EAAM,SAAS,QAAQ,WAAW,GACxD,IAAM,QAAe,EAAM,SAAS,OAAO,iBAAiB,GAC5D,IAAQ,QAAe,CAAC,EAAM,WAAW,CAAC,EAAM,OAAO,GACvD,IAAW,QACf,EAAM,SAAS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AA,EAAA,IAAA,EAAA,CAAA,GAAA,IAAA,CAAA,KAAA,EAAA,IAAA,EAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.js","names":[],"sources":["../../../src/structure/Image.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * A read-only picture (`design/components/image.md`).\n *\n * Generated by `pnpm shells` from `packages/shells/src/members/image.ts`, the member's\n * framework-neutral description. Never edit it by hand: change the description and\n * run `pnpm shells`.\n */\nimport { computed, onMounted, ref, useTemplateRef, watch } from 'vue'\n\nimport { Icon, devWarning } from '@polymorph/vue'\nimport styles from '@polymorph/recipes/structure/image.module.css'\n\nexport interface ImageProps {\n /**\n * The accessible name. An empty string declares the picture decorative and hides it from\n * assistive technology. Required, because only the caller knows which of the two a picture is.\n */\n alt: string\n /**\n * Width over height of a frame the picture sits in, for a source whose size is unknown or is\n * not the shape wanted. Alone, the frame is as wide as its container. With `width` and\n * `height`, it replaces their ratio.\n */\n aspectRatio?: number\n /**\n * The element's CORS mode. Absent, the request is made without CORS.\n */\n crossOrigin?: 'anonymous' | 'use-credentials'\n /**\n * How the picture sits in a frame whose ratio is not its own: `contain` shows all of it,\n * `cover` fills the frame and crops. Defaults to `contain`, because cropping removes content.\n */\n fit?: 'contain' | 'cover'\n /**\n * The picture's height in CSS pixels, given together with `width`.\n */\n height?: number\n /**\n * When the browser fetches the picture: `lazy` as the reader nears it, `eager` at once.\n * Defaults to `lazy`.\n */\n loading?: 'lazy' | 'eager'\n /**\n * The element's referrer policy. Absent, the page's own policy applies.\n */\n referrerPolicy?:\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url'\n /**\n * The picture's URL. An empty string is the failed state: there is nothing to request.\n */\n src: string\n /**\n * The picture's width in CSS pixels, given together with `height`. The two reserve the box\n * before the picture loads and are its natural size; the frame is never wider than its\n * container.\n */\n width?: number\n}\n\ndefineOptions({ name: 'Image', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ImageProps>(), { fit: 'contain', loading: 'lazy' })\nconst loaded = ref('')\nconst failed = ref('')\nconst image = useTemplateRef<HTMLElement>('image')\nconst status = computed(() =>\n props.src === '' || failed.value ===
|
|
1
|
+
{"version":3,"file":"Image.js","names":[],"sources":["../../../src/structure/Image.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * A read-only picture (`design/components/image.md`).\n *\n * Generated by `pnpm shells` from `packages/shells/src/members/image.ts`, the member's\n * framework-neutral description. Never edit it by hand: change the description and\n * run `pnpm shells`.\n */\nimport { computed, onMounted, ref, useTemplateRef, watch } from 'vue'\n\nimport { Icon, devWarning } from '@polymorph/vue'\nimport styles from '@polymorph/recipes/structure/image.module.css'\n\nexport interface ImageProps {\n /**\n * The accessible name. An empty string declares the picture decorative and hides it from\n * assistive technology. Required, because only the caller knows which of the two a picture is.\n */\n alt: string\n /**\n * Width over height of a frame the picture sits in, for a source whose size is unknown or is\n * not the shape wanted. Alone, the frame is as wide as its container. With `width` and\n * `height`, it replaces their ratio.\n */\n aspectRatio?: number\n /**\n * The element's CORS mode. Absent, the request is made without CORS.\n */\n crossOrigin?: 'anonymous' | 'use-credentials'\n /**\n * How the browser ranks this fetch among the page's others. `high` is for the one picture that\n * is the first view's largest content, with `loading=\"eager\"`. Absent, the browser decides.\n */\n fetchPriority?: 'auto' | 'high' | 'low'\n /**\n * How the picture sits in a frame whose ratio is not its own: `contain` shows all of it,\n * `cover` fills the frame and crops. Defaults to `contain`, because cropping removes content.\n */\n fit?: 'contain' | 'cover'\n /**\n * The picture's height in CSS pixels, given together with `width`.\n */\n height?: number\n /**\n * When the browser fetches the picture: `lazy` as the reader nears it, `eager` at once.\n * Defaults to `lazy`.\n */\n loading?: 'lazy' | 'eager'\n /**\n * The element's referrer policy. Absent, the page's own policy applies.\n */\n referrerPolicy?:\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url'\n /**\n * The picture's URL. An empty string is the failed state: there is nothing to request.\n */\n src: string\n /**\n * Other files of the same picture, in the element's `srcset` form: each a URL with a width\n * (`640w`) or a density (`2x`). The browser picks one for the screen, and one that does not\n * read the set requests `src`. For a set that gives widths the member writes the element's\n * `sizes` from the frame's box, so no caller writes a length, and the frame needs a box:\n * without one the set is ignored.\n */\n srcSet?: string\n /**\n * The picture's width in CSS pixels, given together with `height`. The two reserve the box\n * before the picture loads and are its natural size; the frame is never wider than its\n * container.\n */\n width?: number\n}\n\ndefineOptions({ name: 'Image', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ImageProps>(), { fit: 'contain', loading: 'lazy' })\nconst loaded = ref('')\nconst failed = ref('')\nconst image = useTemplateRef<HTMLElement>('image')\nconst ratio = computed(() =>\n props.aspectRatio !== undefined && props.aspectRatio > 0 && Number.isFinite(props.aspectRatio)\n ? props.aspectRatio\n : props.width !== undefined && props.height !== undefined && props.width > 0 && props.height > 0\n ? props.width / props.height\n : undefined,\n)\nconst sized = computed(() => ratio.value !== undefined)\nconst widths = computed(() => props.srcSet !== undefined && /\\d+w\\s*(?:,|$)/.test(props.srcSet))\nconst candidates = computed(() => (widths.value && !sized.value ? undefined : props.srcSet))\nconst request = computed(() =>\n candidates.value === undefined ? props.src : props.src + ' ' + candidates.value,\n)\nconst status = computed(() =>\n props.src === '' || failed.value === request.value\n ? 'failed'\n : loaded.value === request.value\n ? 'loaded'\n : 'loading',\n)\nconst spread = computed(() =>\n props.width !== undefined &&\n props.height !== undefined &&\n props.width > 0 &&\n props.height > 0 &&\n ratio.value !== undefined &&\n props.fit === 'cover'\n ? Math.max(1, Math.round((props.width / props.height / ratio.value) * 100) / 100)\n : 1,\n)\nconst sizes = computed(() =>\n !widths.value || !sized.value\n ? undefined\n : props.width !== undefined && props.height !== undefined && props.width > 0 && props.height > 0\n ? (props.loading === 'lazy' && spread.value === 1 ? 'auto, ' : '') +\n '(max-width: ' +\n props.width +\n 'px) ' +\n Math.round(100 * spread.value) +\n 'vw, ' +\n Math.round(props.width * spread.value) +\n 'px'\n : props.loading === 'lazy' && props.fit !== 'cover'\n ? 'auto, 100vw'\n : undefined,\n)\nconst decorative = computed(() => props.alt === '')\nconst settle = computed(() => () => {\n if (failed.value !== request.value) failed.value = ''\n const element = image.value as HTMLImageElement | null | undefined\n if (element == null || !element.complete) return\n if (element.naturalWidth > 0) loaded.value = request.value\n else element.src = props.src\n})\nconst effect1 = () => {\n settle.value()\n}\nonMounted(effect1)\nwatch(() => request.value, effect1, { flush: 'post' })\nconst effect2 = () => {\n devWarning(\n (props.width === undefined) !== (props.height === undefined),\n 'Image: `width` and `height` are given together. One alone gives no ratio and is ignored.',\n )\n}\nonMounted(effect2)\nwatch(() => (props.width === undefined) !== (props.height === undefined), effect2, {\n flush: 'post',\n})\nconst effect3 = () => {\n devWarning(\n widths.value && !sized.value,\n 'Image: a `srcSet` that gives widths needs a box, from `width` and `height` or from `aspectRatio`. Without one the set is ignored.',\n )\n}\nonMounted(effect3)\nwatch(() => widths.value && !sized.value, effect3, { flush: 'post' })\n</script>\n\n<template>\n <span\n :class=\"styles.frame\"\n :style=\"{\n aspectRatio: ratio,\n inlineSize:\n width !== undefined && height !== undefined && width > 0 && height > 0\n ? `${width}px`\n : undefined,\n }\"\n :data-state=\"status === 'loaded' ? undefined : status\"\n :data-fit=\"fit\"\n :data-sized=\"sized ? '' : undefined\"\n data-member=\"image\"\n >\n <!-- placeholder -->\n <span v-if=\"status === 'loading'\" :class=\"styles.placeholder\" aria-hidden=\"true\" />\n <!-- fallback -->\n <span\n v-if=\"status === 'failed'\"\n :class=\"styles.fallback\"\n data-image-part=\"fallback\"\n :role=\"!decorative ? 'img' : undefined\"\n :aria-label=\"!decorative ? alt : undefined\"\n :aria-hidden=\"decorative ? true : undefined\"\n >\n <Icon name=\"error\" />\n </span>\n <!-- image -->\n <img\n v-else\n ref=\"image\"\n :class=\"styles.image\"\n :loading=\"loading\"\n :fetchpriority=\"fetchPriority\"\n :crossorigin=\"crossOrigin\"\n :referrerpolicy=\"referrerPolicy\"\n :sizes=\"sizes\"\n :srcset=\"candidates\"\n :src=\"src\"\n :alt=\"alt\"\n @load=\"loaded = request\"\n @error=\"failed = request\"\n />\n </span>\n</template>\n"],"mappings":""}
|
|
@@ -12,8 +12,11 @@ var g = [
|
|
|
12
12
|
"aria-hidden"
|
|
13
13
|
], v = [
|
|
14
14
|
"loading",
|
|
15
|
+
"fetchpriority",
|
|
15
16
|
"crossorigin",
|
|
16
17
|
"referrerpolicy",
|
|
18
|
+
"sizes",
|
|
19
|
+
"srcset",
|
|
17
20
|
"src",
|
|
18
21
|
"alt"
|
|
19
22
|
], y = /*@__PURE__*/ s({
|
|
@@ -24,58 +27,67 @@ var g = [
|
|
|
24
27
|
alt: {},
|
|
25
28
|
aspectRatio: {},
|
|
26
29
|
crossOrigin: {},
|
|
30
|
+
fetchPriority: {},
|
|
27
31
|
fit: { default: "contain" },
|
|
28
32
|
height: {},
|
|
29
33
|
loading: { default: "lazy" },
|
|
30
34
|
referrerPolicy: {},
|
|
31
35
|
src: {},
|
|
36
|
+
srcSet: {},
|
|
32
37
|
width: {}
|
|
33
38
|
},
|
|
34
39
|
setup(s) {
|
|
35
|
-
let y = s, b = f(""), x = f(""), S = m("image"), C = r(() => y.src === "" || x.value ===
|
|
36
|
-
x.value !==
|
|
40
|
+
let y = s, b = f(""), x = f(""), S = m("image"), C = r(() => y.aspectRatio !== void 0 && y.aspectRatio > 0 && Number.isFinite(y.aspectRatio) ? y.aspectRatio : y.width !== void 0 && y.height !== void 0 && y.width > 0 && y.height > 0 ? y.width / y.height : void 0), w = r(() => C.value !== void 0), T = r(() => y.srcSet !== void 0 && /\d+w\s*(?:,|$)/.test(y.srcSet)), E = r(() => T.value && !w.value ? void 0 : y.srcSet), D = r(() => E.value === void 0 ? y.src : y.src + " " + E.value), O = r(() => y.src === "" || x.value === D.value ? "failed" : b.value === D.value ? "loaded" : "loading"), k = r(() => y.width !== void 0 && y.height !== void 0 && y.width > 0 && y.height > 0 && C.value !== void 0 && y.fit === "cover" ? Math.max(1, Math.round(y.width / y.height / C.value * 100) / 100) : 1), A = r(() => !T.value || !w.value ? void 0 : y.width !== void 0 && y.height !== void 0 && y.width > 0 && y.height > 0 ? (y.loading === "lazy" && k.value === 1 ? "auto, " : "") + "(max-width: " + y.width + "px) " + Math.round(100 * k.value) + "vw, " + Math.round(y.width * k.value) + "px" : y.loading === "lazy" && y.fit !== "cover" ? "auto, 100vw" : void 0), j = r(() => y.alt === ""), M = r(() => () => {
|
|
41
|
+
x.value !== D.value && (x.value = "");
|
|
37
42
|
let e = S.value;
|
|
38
|
-
e == null || !e.complete || (e.naturalWidth > 0 ? b.value =
|
|
39
|
-
}),
|
|
40
|
-
|
|
43
|
+
e == null || !e.complete || (e.naturalWidth > 0 ? b.value = D.value : e.src = y.src);
|
|
44
|
+
}), N = () => {
|
|
45
|
+
M.value();
|
|
41
46
|
};
|
|
42
|
-
u(
|
|
43
|
-
let
|
|
47
|
+
u(N), h(() => D.value, N, { flush: "post" });
|
|
48
|
+
let P = () => {
|
|
44
49
|
n(y.width === void 0 != (y.height === void 0), "Image: `width` and `height` are given together. One alone gives no ratio and is ignored.");
|
|
45
50
|
};
|
|
46
|
-
|
|
51
|
+
u(P), h(() => y.width === void 0 != (y.height === void 0), P, { flush: "post" });
|
|
52
|
+
let F = () => {
|
|
53
|
+
n(T.value && !w.value, "Image: a `srcSet` that gives widths needs a box, from `width` and `height` or from `aspectRatio`. Without one the set is ignored.");
|
|
54
|
+
};
|
|
55
|
+
return u(F), h(() => T.value && !w.value, F, { flush: "post" }), (n, r) => (d(), a("span", {
|
|
47
56
|
class: c(p(e).frame),
|
|
48
57
|
style: l({
|
|
49
|
-
aspectRatio:
|
|
58
|
+
aspectRatio: C.value,
|
|
50
59
|
inlineSize: s.width !== void 0 && s.height !== void 0 && s.width > 0 && s.height > 0 ? `${s.width}px` : void 0
|
|
51
60
|
}),
|
|
52
|
-
"data-state":
|
|
61
|
+
"data-state": O.value === "loaded" ? void 0 : O.value,
|
|
53
62
|
"data-fit": s.fit,
|
|
54
|
-
"data-sized":
|
|
63
|
+
"data-sized": w.value ? "" : void 0,
|
|
55
64
|
"data-member": "image"
|
|
56
|
-
}, [
|
|
65
|
+
}, [O.value === "loading" ? (d(), a("span", {
|
|
57
66
|
key: 0,
|
|
58
67
|
class: c(p(e).placeholder),
|
|
59
68
|
"aria-hidden": "true"
|
|
60
|
-
}, null, 2)) : i("", !0),
|
|
69
|
+
}, null, 2)) : i("", !0), O.value === "failed" ? (d(), a("span", {
|
|
61
70
|
key: 1,
|
|
62
71
|
class: c(p(e).fallback),
|
|
63
72
|
"data-image-part": "fallback",
|
|
64
|
-
role:
|
|
65
|
-
"aria-label":
|
|
66
|
-
"aria-hidden":
|
|
73
|
+
role: j.value ? void 0 : "img",
|
|
74
|
+
"aria-label": j.value ? void 0 : s.alt,
|
|
75
|
+
"aria-hidden": j.value ? !0 : void 0
|
|
67
76
|
}, [o(p(t), { name: "error" })], 10, _)) : (d(), a("img", {
|
|
68
77
|
key: 2,
|
|
69
78
|
ref_key: "image",
|
|
70
79
|
ref: S,
|
|
71
80
|
class: c(p(e).image),
|
|
72
81
|
loading: s.loading,
|
|
82
|
+
fetchpriority: s.fetchPriority,
|
|
73
83
|
crossorigin: s.crossOrigin,
|
|
74
84
|
referrerpolicy: s.referrerPolicy,
|
|
85
|
+
sizes: A.value,
|
|
86
|
+
srcset: E.value,
|
|
75
87
|
src: s.src,
|
|
76
88
|
alt: s.alt,
|
|
77
|
-
onLoad: r[0] ||= (e) => b.value =
|
|
78
|
-
onError: r[1] ||= (e) => x.value =
|
|
89
|
+
onLoad: r[0] ||= (e) => b.value = D.value,
|
|
90
|
+
onError: r[1] ||= (e) => x.value = D.value
|
|
79
91
|
}, null, 42, v))], 14, g));
|
|
80
92
|
}
|
|
81
93
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.vue_vue_type_script_setup_true_lang.js","names":[],"sources":["../../../src/structure/Image.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * A read-only picture (`design/components/image.md`).\n *\n * Generated by `pnpm shells` from `packages/shells/src/members/image.ts`, the member's\n * framework-neutral description. Never edit it by hand: change the description and\n * run `pnpm shells`.\n */\nimport { computed, onMounted, ref, useTemplateRef, watch } from 'vue'\n\nimport { Icon, devWarning } from '@polymorph/vue'\nimport styles from '@polymorph/recipes/structure/image.module.css'\n\nexport interface ImageProps {\n /**\n * The accessible name. An empty string declares the picture decorative and hides it from\n * assistive technology. Required, because only the caller knows which of the two a picture is.\n */\n alt: string\n /**\n * Width over height of a frame the picture sits in, for a source whose size is unknown or is\n * not the shape wanted. Alone, the frame is as wide as its container. With `width` and\n * `height`, it replaces their ratio.\n */\n aspectRatio?: number\n /**\n * The element's CORS mode. Absent, the request is made without CORS.\n */\n crossOrigin?: 'anonymous' | 'use-credentials'\n /**\n * How the picture sits in a frame whose ratio is not its own: `contain` shows all of it,\n * `cover` fills the frame and crops. Defaults to `contain`, because cropping removes content.\n */\n fit?: 'contain' | 'cover'\n /**\n * The picture's height in CSS pixels, given together with `width`.\n */\n height?: number\n /**\n * When the browser fetches the picture: `lazy` as the reader nears it, `eager` at once.\n * Defaults to `lazy`.\n */\n loading?: 'lazy' | 'eager'\n /**\n * The element's referrer policy. Absent, the page's own policy applies.\n */\n referrerPolicy?:\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url'\n /**\n * The picture's URL. An empty string is the failed state: there is nothing to request.\n */\n src: string\n /**\n * The picture's width in CSS pixels, given together with `height`. The two reserve the box\n * before the picture loads and are its natural size; the frame is never wider than its\n * container.\n */\n width?: number\n}\n\ndefineOptions({ name: 'Image', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ImageProps>(), { fit: 'contain', loading: 'lazy' })\nconst loaded = ref('')\nconst failed = ref('')\nconst image = useTemplateRef<HTMLElement>('image')\nconst status = computed(() =>\n props.src === '' || failed.value === props.src\n ? 'failed'\n : loaded.value === props.src\n ? 'loaded'\n : 'loading',\n)\nconst ratio = computed(() =>\n props.aspectRatio !== undefined && props.aspectRatio > 0 && Number.isFinite(props.aspectRatio)\n ? props.aspectRatio\n : props.width !== undefined && props.height !== undefined && props.width > 0 && props.height > 0\n ? props.width / props.height\n : undefined,\n)\nconst sized = computed(() => ratio.value !== undefined)\nconst decorative = computed(() => props.alt === '')\nconst settle = computed(() => () => {\n if (failed.value !== props.src) failed.value = ''\n const element = image.value as HTMLImageElement | null | undefined\n if (element == null || !element.complete) return\n if (element.naturalWidth > 0) loaded.value = props.src\n else element.src = props.src\n})\nconst effect1 = () => {\n settle.value()\n}\nonMounted(effect1)\nwatch(() => props.src, effect1, { flush: 'post' })\nconst effect2 = () => {\n devWarning(\n (props.width === undefined) !== (props.height === undefined),\n 'Image: `width` and `height` are given together. One alone gives no ratio and is ignored.',\n )\n}\nonMounted(effect2)\nwatch(() => (props.width === undefined) !== (props.height === undefined), effect2, {\n flush: 'post',\n})\n</script>\n\n<template>\n <span\n :class=\"styles.frame\"\n :style=\"{\n aspectRatio: ratio,\n inlineSize:\n width !== undefined && height !== undefined && width > 0 && height > 0\n ? `${width}px`\n : undefined,\n }\"\n :data-state=\"status === 'loaded' ? undefined : status\"\n :data-fit=\"fit\"\n :data-sized=\"sized ? '' : undefined\"\n data-member=\"image\"\n >\n <!-- placeholder -->\n <span v-if=\"status === 'loading'\" :class=\"styles.placeholder\" aria-hidden=\"true\" />\n <!-- fallback -->\n <span\n v-if=\"status === 'failed'\"\n :class=\"styles.fallback\"\n data-image-part=\"fallback\"\n :role=\"!decorative ? 'img' : undefined\"\n :aria-label=\"!decorative ? alt : undefined\"\n :aria-hidden=\"decorative ? true : undefined\"\n >\n <Icon name=\"error\" />\n </span>\n <!-- image -->\n <img\n v-else\n ref=\"image\"\n :class=\"styles.image\"\n :loading=\"loading\"\n :crossorigin=\"crossOrigin\"\n :referrerpolicy=\"referrerPolicy\"\n :src=\"src\"\n :alt=\"alt\"\n @load=\"loaded = src\"\n @error=\"failed = src\"\n />\n </span>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqEA,IAAM,IAAQ,GACR,IAAS,EAAI,EAAE,GACf,IAAS,EAAI,EAAE,GACf,IAAQ,EAA4B,OAAO,GAC3C,IAAS,QACb,EAAM,QAAQ,MAAM,EAAO,UAAU,EAAM,MACvC,WACA,EAAO,UAAU,EAAM,MACrB,WACA,SACR,GACM,IAAQ,QACZ,EAAM,gBAAgB,KAAA,KAAa,EAAM,cAAc,KAAK,OAAO,SAAS,EAAM,WAAW,IACzF,EAAM,cACN,EAAM,UAAU,KAAA,KAAa,EAAM,WAAW,KAAA,KAAa,EAAM,QAAQ,KAAK,EAAM,SAAS,IAC3F,EAAM,QAAQ,EAAM,SACpB,KAAA,CACR,GACM,IAAQ,QAAe,EAAM,UAAU,KAAA,CAAS,GAChD,IAAa,QAAe,EAAM,QAAQ,EAAE,GAC5C,IAAS,cAAqB;GAClC,AAAI,EAAO,UAAU,EAAM,QAAK,EAAO,QAAQ;GAC/C,IAAM,IAAU,EAAM;GAClB,KAAW,QAAQ,CAAC,EAAQ,aAC5B,EAAQ,eAAe,IAAG,EAAO,QAAQ,EAAM,MAC9C,EAAQ,MAAM,EAAM;EAC3B,CAAC,GACK,UAAgB;GACpB,EAAO,MAAM;EACf;EAEA,AADA,EAAU,CAAO,GACjB,QAAY,EAAM,KAAK,GAAS,EAAE,OAAO,OAAO,CAAC;EACjD,IAAM,UAAgB;GACpB,EACG,EAAM,UAAU,KAAA,MAAgB,EAAM,WAAW,KAAA,IAClD,0FACF;EACF;SACA,EAAU,CAAO,GACjB,QAAa,EAAM,UAA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up lang=\"ts\">\n/**\n * A read-only picture (`design/components/image.md`).\n *\n * Generated by `pnpm shells` from `packages/shells/src/members/image.ts`, the member's\n * framework-neutral description. Never edit it by hand: change the description and\n * run `pnpm shells`.\n */\nimport { computed, onMounted, ref, useTemplateRef, watch } from 'vue'\n\nimport { Icon, devWarning } from '@polymorph/vue'\nimport styles from '@polymorph/recipes/structure/image.module.css'\n\nexport interface ImageProps {\n /**\n * The accessible name. An empty string declares the picture decorative and hides it from\n * assistive technology. Required, because only the caller knows which of the two a picture is.\n */\n alt: string\n /**\n * Width over height of a frame the picture sits in, for a source whose size is unknown or is\n * not the shape wanted. Alone, the frame is as wide as its container. With `width` and\n * `height`, it replaces their ratio.\n */\n aspectRatio?: number\n /**\n * The element's CORS mode. Absent, the request is made without CORS.\n */\n crossOrigin?: 'anonymous' | 'use-credentials'\n /**\n * How the browser ranks this fetch among the page's others. `high` is for the one picture that\n * is the first view's largest content, with `loading=\"eager\"`. Absent, the browser decides.\n */\n fetchPriority?: 'auto' | 'high' | 'low'\n /**\n * How the picture sits in a frame whose ratio is not its own: `contain` shows all of it,\n * `cover` fills the frame and crops. Defaults to `contain`, because cropping removes content.\n */\n fit?: 'contain' | 'cover'\n /**\n * The picture's height in CSS pixels, given together with `width`.\n */\n height?: number\n /**\n * When the browser fetches the picture: `lazy` as the reader nears it, `eager` at once.\n * Defaults to `lazy`.\n */\n loading?: 'lazy' | 'eager'\n /**\n * The element's referrer policy. Absent, the page's own policy applies.\n */\n referrerPolicy?:\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url'\n /**\n * The picture's URL. An empty string is the failed state: there is nothing to request.\n */\n src: string\n /**\n * Other files of the same picture, in the element's `srcset` form: each a URL with a width\n * (`640w`) or a density (`2x`). The browser picks one for the screen, and one that does not\n * read the set requests `src`. For a set that gives widths the member writes the element's\n * `sizes` from the frame's box, so no caller writes a length, and the frame needs a box:\n * without one the set is ignored.\n */\n srcSet?: string\n /**\n * The picture's width in CSS pixels, given together with `height`. The two reserve the box\n * before the picture loads and are its natural size; the frame is never wider than its\n * container.\n */\n width?: number\n}\n\ndefineOptions({ name: 'Image', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ImageProps>(), { fit: 'contain', loading: 'lazy' })\nconst loaded = ref('')\nconst failed = ref('')\nconst image = useTemplateRef<HTMLElement>('image')\nconst ratio = computed(() =>\n props.aspectRatio !== undefined && props.aspectRatio > 0 && Number.isFinite(props.aspectRatio)\n ? props.aspectRatio\n : props.width !== undefined && props.height !== undefined && props.width > 0 && props.height > 0\n ? props.width / props.height\n : undefined,\n)\nconst sized = computed(() => ratio.value !== undefined)\nconst widths = computed(() => props.srcSet !== undefined && /\\d+w\\s*(?:,|$)/.test(props.srcSet))\nconst candidates = computed(() => (widths.value && !sized.value ? undefined : props.srcSet))\nconst request = computed(() =>\n candidates.value === undefined ? props.src : props.src + ' ' + candidates.value,\n)\nconst status = computed(() =>\n props.src === '' || failed.value === request.value\n ? 'failed'\n : loaded.value === request.value\n ? 'loaded'\n : 'loading',\n)\nconst spread = computed(() =>\n props.width !== undefined &&\n props.height !== undefined &&\n props.width > 0 &&\n props.height > 0 &&\n ratio.value !== undefined &&\n props.fit === 'cover'\n ? Math.max(1, Math.round((props.width / props.height / ratio.value) * 100) / 100)\n : 1,\n)\nconst sizes = computed(() =>\n !widths.value || !sized.value\n ? undefined\n : props.width !== undefined && props.height !== undefined && props.width > 0 && props.height > 0\n ? (props.loading === 'lazy' && spread.value === 1 ? 'auto, ' : '') +\n '(max-width: ' +\n props.width +\n 'px) ' +\n Math.round(100 * spread.value) +\n 'vw, ' +\n Math.round(props.width * spread.value) +\n 'px'\n : props.loading === 'lazy' && props.fit !== 'cover'\n ? 'auto, 100vw'\n : undefined,\n)\nconst decorative = computed(() => props.alt === '')\nconst settle = computed(() => () => {\n if (failed.value !== request.value) failed.value = ''\n const element = image.value as HTMLImageElement | null | undefined\n if (element == null || !element.complete) return\n if (element.naturalWidth > 0) loaded.value = request.value\n else element.src = props.src\n})\nconst effect1 = () => {\n settle.value()\n}\nonMounted(effect1)\nwatch(() => request.value, effect1, { flush: 'post' })\nconst effect2 = () => {\n devWarning(\n (props.width === undefined) !== (props.height === undefined),\n 'Image: `width` and `height` are given together. One alone gives no ratio and is ignored.',\n )\n}\nonMounted(effect2)\nwatch(() => (props.width === undefined) !== (props.height === undefined), effect2, {\n flush: 'post',\n})\nconst effect3 = () => {\n devWarning(\n widths.value && !sized.value,\n 'Image: a `srcSet` that gives widths needs a box, from `width` and `height` or from `aspectRatio`. Without one the set is ignored.',\n )\n}\nonMounted(effect3)\nwatch(() => widths.value && !sized.value, effect3, { flush: 'post' })\n</script>\n\n<template>\n <span\n :class=\"styles.frame\"\n :style=\"{\n aspectRatio: ratio,\n inlineSize:\n width !== undefined && height !== undefined && width > 0 && height > 0\n ? `${width}px`\n : undefined,\n }\"\n :data-state=\"status === 'loaded' ? undefined : status\"\n :data-fit=\"fit\"\n :data-sized=\"sized ? '' : undefined\"\n data-member=\"image\"\n >\n <!-- placeholder -->\n <span v-if=\"status === 'loading'\" :class=\"styles.placeholder\" aria-hidden=\"true\" />\n <!-- fallback -->\n <span\n v-if=\"status === 'failed'\"\n :class=\"styles.fallback\"\n data-image-part=\"fallback\"\n :role=\"!decorative ? 'img' : undefined\"\n :aria-label=\"!decorative ? alt : undefined\"\n :aria-hidden=\"decorative ? true : undefined\"\n >\n <Icon name=\"error\" />\n </span>\n <!-- image -->\n <img\n v-else\n ref=\"image\"\n :class=\"styles.image\"\n :loading=\"loading\"\n :fetchpriority=\"fetchPriority\"\n :crossorigin=\"crossOrigin\"\n :referrerpolicy=\"referrerPolicy\"\n :sizes=\"sizes\"\n :srcset=\"candidates\"\n :src=\"src\"\n :alt=\"alt\"\n @load=\"loaded = request\"\n @error=\"failed = request\"\n />\n </span>\n</template>\n"],"mappings":";;;;;;;;;;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