@dumiflex/wp-kit 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +674 -0
  3. package/README.md +72 -2
  4. package/package.json +76 -4
  5. package/src/Avatar.vue +83 -0
  6. package/src/Badge.vue +97 -0
  7. package/src/Banner.vue +118 -0
  8. package/src/BookmarkButton.vue +27 -0
  9. package/src/BundleMeta.vue +51 -0
  10. package/src/Button.vue +103 -0
  11. package/src/Card.vue +68 -0
  12. package/src/Checkbox.vue +109 -0
  13. package/src/Chip.vue +163 -0
  14. package/src/ChoiceCards.vue +133 -0
  15. package/src/CloseButton.vue +69 -0
  16. package/src/CodeBlock.vue +119 -0
  17. package/src/ColorField.vue +188 -0
  18. package/src/ColorPicker.vue +201 -0
  19. package/src/Combobox.vue +331 -0
  20. package/src/ConfirmDialog.vue +165 -0
  21. package/src/ConfirmModal.vue +147 -0
  22. package/src/ConstraintMatrixPreview.vue +708 -0
  23. package/src/ContextMenu.vue +386 -0
  24. package/src/CopyButton.vue +156 -0
  25. package/src/DataTable.vue +292 -0
  26. package/src/DatePicker.vue +234 -0
  27. package/src/DescriptionList.vue +73 -0
  28. package/src/DiffView.vue +68 -0
  29. package/src/Disclosure.vue +166 -0
  30. package/src/DragHandle.vue +49 -0
  31. package/src/Drawer.vue +131 -0
  32. package/src/DropZone.vue +196 -0
  33. package/src/DropdownMenu.vue +72 -0
  34. package/src/EmptyState.vue +111 -0
  35. package/src/Field.vue +28 -0
  36. package/src/HsvPicker.vue +208 -0
  37. package/src/Icon.vue +39 -0
  38. package/src/IconPicker.vue +209 -0
  39. package/src/ImageGrid.vue +125 -0
  40. package/src/InlineEdit.vue +183 -0
  41. package/src/Input.vue +99 -0
  42. package/src/Kbd.vue +56 -0
  43. package/src/Lightbox.vue +173 -0
  44. package/src/ListFilter.vue +85 -0
  45. package/src/ListRow.vue +204 -0
  46. package/src/LoadingMark.vue +175 -0
  47. package/src/Logo.vue +60 -0
  48. package/src/Modal.vue +78 -0
  49. package/src/ModalShell.vue +109 -0
  50. package/src/Pagination.vue +106 -0
  51. package/src/Popover.vue +180 -0
  52. package/src/PostCard.vue +210 -0
  53. package/src/ProgressBar.vue +90 -0
  54. package/src/RadioGroup.vue +177 -0
  55. package/src/RangeSlider.vue +183 -0
  56. package/src/RelativeDate.vue +35 -0
  57. package/src/ResizeHandle.vue +143 -0
  58. package/src/SearchInput.vue +192 -0
  59. package/src/Select.vue +644 -0
  60. package/src/Separator.vue +54 -0
  61. package/src/Skeleton.vue +82 -0
  62. package/src/Slider.vue +198 -0
  63. package/src/SortableList.vue +260 -0
  64. package/src/SplitPane.vue +68 -0
  65. package/src/StarButton.vue +40 -0
  66. package/src/Stepper.vue +141 -0
  67. package/src/SupportLinks.vue +93 -0
  68. package/src/TagInput.vue +297 -0
  69. package/src/Textarea.vue +57 -0
  70. package/src/Timeline.vue +92 -0
  71. package/src/ToastCard.vue +119 -0
  72. package/src/ToastHost.vue +40 -0
  73. package/src/Toggle.vue +36 -0
  74. package/src/TokenizedValue.vue +310 -0
  75. package/src/Toolbar.vue +110 -0
  76. package/src/VirtualList.vue +87 -0
  77. package/src/VisuallyHidden.vue +29 -0
  78. package/src/WpButton.vue +75 -0
  79. package/src/WpCheck.vue +104 -0
  80. package/src/WpIconButton.vue +107 -0
  81. package/src/WpImageZoom.vue +544 -0
  82. package/src/WpNumber.vue +178 -0
  83. package/src/WpSegmented.vue +175 -0
  84. package/src/WpSelect.vue +93 -0
  85. package/src/WpSwitch.vue +163 -0
  86. package/src/WpTabs.vue +188 -0
  87. package/src/_modal-motion.css +33 -0
  88. package/src/_skeleton.css +50 -0
  89. package/src/axis-color.ts +42 -0
  90. package/src/button.css +169 -0
  91. package/src/calendar.ts +59 -0
  92. package/src/clipboard.ts +50 -0
  93. package/src/colour-presets.ts +12 -0
  94. package/src/diff.ts +51 -0
  95. package/src/drop-zone.ts +41 -0
  96. package/src/field.css +50 -0
  97. package/src/flip.ts +237 -0
  98. package/src/floating-layer.ts +48 -0
  99. package/src/floating.ts +99 -0
  100. package/src/hsv.ts +100 -0
  101. package/src/icon-catalog.ts +52 -0
  102. package/src/image-zoom.ts +93 -0
  103. package/src/kind-colour.ts +28 -0
  104. package/src/logo-paths.ts +21 -0
  105. package/src/matrix-axis.ts +91 -0
  106. package/src/pagination.ts +27 -0
  107. package/src/platform-keys.ts +29 -0
  108. package/src/rich-tokenize.ts +357 -0
  109. package/src/select-types.ts +32 -0
  110. package/src/slider-math.ts +45 -0
  111. package/src/sortable.ts +22 -0
  112. package/src/theme/fonts/OFL-Fraunces.txt +93 -0
  113. package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -0
  114. package/src/theme/fonts/OFL-Manrope.txt +93 -0
  115. package/src/theme/fonts/fraunces-latin-wght-normal.woff2 +0 -0
  116. package/src/theme/fonts/jetbrains-mono-latin.woff2 +0 -0
  117. package/src/theme/fonts/manrope-latin-wght-normal.woff2 +0 -0
  118. package/src/theme/looks.css +428 -0
  119. package/src/theme/palettes.css +254 -0
  120. package/src/theme/tokens.css +2896 -0
  121. package/src/tokens.ts +56 -0
  122. package/src/tooltip.css +43 -0
  123. package/src/tooltip.ts +146 -0
  124. package/src/useDialogFocus.ts +73 -0
  125. package/src/useGrowableField.ts +357 -0
  126. package/src/useModalKeyShield.ts +116 -0
  127. package/src/useToast.ts +48 -0
  128. package/src/wp-logo.svg +14 -0
@@ -0,0 +1,109 @@
1
+ <template>
2
+ <Teleport to="body">
3
+ <Transition name="wp-modal" appear>
4
+ <!-- The overlay is a click target only; keyboard users close with Escape. -->
5
+ <!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
6
+ <div v-if="visible" ref="overlayEl" class="wp-modal-overlay" @click="$emit('close')">
7
+ <div
8
+ class="wp-modal-wrapper"
9
+ role="dialog"
10
+ aria-modal="true"
11
+ :aria-label="label"
12
+ :aria-labelledby="labelledby"
13
+ @click.stop
14
+ >
15
+ <slot></slot>
16
+ </div>
17
+ </div>
18
+ </Transition>
19
+ </Teleport>
20
+ </template>
21
+
22
+ <script setup lang="ts">
23
+ import { ref, watch, onBeforeUnmount } from "vue";
24
+ import { useModalKeyShield } from "./useModalKeyShield";
25
+
26
+ const props = defineProps<{
27
+ visible: boolean;
28
+ /** The dialog's name when it has no visible title. */
29
+ label?: string | undefined;
30
+ /** Id of the element that names the dialog (its title). */
31
+ labelledby?: string | undefined;
32
+ }>();
33
+ const emit = defineEmits<{
34
+ (e: "close"): void;
35
+ /** Every keydown inside the modal. Consumers MUST use this instead of a
36
+ * window listener: the shield stops inside-modal keys at the overlay, so a
37
+ * window listener would never see them. */
38
+ (e: "keydown", ev: KeyboardEvent): void;
39
+ }>();
40
+
41
+ const overlayEl = ref<HTMLElement | null>(null);
42
+
43
+ function closeOnEscape(event: KeyboardEvent): void {
44
+ if (!props.visible || event.key !== "Escape") return;
45
+ event.preventDefault();
46
+ emit("close");
47
+ }
48
+
49
+ // Keys pressed INSIDE the modal are handled here and stop at the overlay, so
50
+ // they never reach ComfyUI's global shortcuts (see useModalKeyShield).
51
+ useModalKeyShield(overlayEl, {
52
+ onKey: (ev) => {
53
+ emit("keydown", ev);
54
+ closeOnEscape(ev);
55
+ },
56
+ });
57
+
58
+ // The window listener still covers the case where focus is OUTSIDE the modal
59
+ // — clicking the canvas leaves the modal open but unfocused, and Escape should
60
+ // still close it. Events from inside never get here; the shield stops them.
61
+ function onKeydown(event: KeyboardEvent) {
62
+ closeOnEscape(event);
63
+ }
64
+
65
+ watch(
66
+ () => props.visible,
67
+ (visible) => {
68
+ if (visible) window.addEventListener("keydown", onKeydown);
69
+ else window.removeEventListener("keydown", onKeydown);
70
+ },
71
+ { immediate: true },
72
+ );
73
+
74
+ onBeforeUnmount(() => window.removeEventListener("keydown", onKeydown));
75
+ </script>
76
+
77
+ <style>
78
+ @import "./_modal-motion.css";
79
+ </style>
80
+
81
+ <style scoped>
82
+ .wp-modal-overlay,
83
+ .wp-modal-overlay * {
84
+ box-sizing: border-box;
85
+ }
86
+ .wp-modal-overlay {
87
+ position: fixed;
88
+ inset: 0;
89
+ z-index: 9999;
90
+ display: flex;
91
+ align-items: center;
92
+ justify-content: center;
93
+ padding: 20px;
94
+ background: var(--wp-overlay-bg, rgba(0, 0, 0, 0.62));
95
+ font-family: var(--wp-font-sans, sans-serif);
96
+ cursor: default;
97
+ }
98
+ .wp-modal-wrapper {
99
+ display: flex;
100
+ justify-content: center;
101
+ width: 100%;
102
+ max-height: 100%;
103
+ }
104
+
105
+ /* `wp-modal` open/close transition lives in
106
+ * src/components/shared/_modal-motion.css (imported globally via
107
+ * ContextWidget) so every modal — ModalShell consumers, ConfirmDialog,
108
+ * InjectorBindingModal — animates with the same rules. */
109
+ </style>
@@ -0,0 +1,106 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Pagination: move through a long list a page at a time, or load more at
4
+ * its end. Works on the canvas and in the manager.
5
+ *
6
+ * <Pagination v-model:page="page" :total="rows.length" :page-size="50" />
7
+ * <Pagination mode="more" :shown="shown.length" :total="230" :loading="busy" @more="loadMore" />
8
+ *
9
+ * Pages: a `nav` with Previous / Next and the page numbers (first, last, the
10
+ * current page with `siblings` either side, "…" between), the current one
11
+ * marked `aria-current="page"`. More: one "Load more" button under a
12
+ * "Showing 50 of 230" line. Nothing is drawn when everything fits on one page.
13
+ */
14
+ import { computed } from "vue";
15
+ import { pageItems } from "./pagination";
16
+ import WpButton from "./WpButton.vue";
17
+
18
+ const props = withDefaults(defineProps<{
19
+ /** pages: numbered pages. more: a Load more button. */
20
+ mode?: "pages" | "more" | undefined;
21
+ /** The current page, from 1. */
22
+ page?: number | undefined;
23
+ /** How many items there are in all. */
24
+ total: number;
25
+ pageSize?: number | undefined;
26
+ /** Pages shown either side of the current one. */
27
+ siblings?: number | undefined;
28
+ /** In "more" mode: how many items are on screen. */
29
+ shown?: number | undefined;
30
+ loading?: boolean | undefined;
31
+ disabled?: boolean | undefined;
32
+ size?: "sm" | "md" | undefined;
33
+ /** The item's name in "Showing 50 of 230 modules". */
34
+ noun?: string | undefined;
35
+ ariaLabel?: string | undefined;
36
+ }>(), { mode: "pages", page: 1, pageSize: 25, siblings: 1, shown: 0, size: "md", noun: undefined, ariaLabel: "Pages" });
37
+
38
+ const emit = defineEmits<{ (e: "update:page", v: number): void; (e: "more"): void }>();
39
+
40
+ const pages = computed(() => Math.max(1, Math.ceil(props.total / Math.max(1, props.pageSize))));
41
+ const items = computed(() => pageItems(props.page, pages.value, props.siblings));
42
+ const from = computed(() => Math.min(props.total, (props.page - 1) * props.pageSize + 1));
43
+ const to = computed(() => Math.min(props.total, props.page * props.pageSize));
44
+
45
+ function go(p: number): void {
46
+ const next = Math.min(Math.max(1, p), pages.value);
47
+ if (next !== props.page && !props.disabled) emit("update:page", next);
48
+ }
49
+ const btnSize = computed(() => (props.size === "sm" ? "sm" : "md"));
50
+ </script>
51
+
52
+ <template>
53
+ <nav v-if="mode === 'pages' && pages > 1" class="wp-paging" :data-size="size" :aria-label="ariaLabel">
54
+ <span class="wp-paging__range" aria-live="polite">{{ from }}–{{ to }} of {{ total }}</span>
55
+ <ul class="wp-paging__list">
56
+ <li>
57
+ <WpButton variant="ghost" :size="btnSize" icon="pi-chevron-left" aria-label="Previous page" :disabled="disabled || props.page <= 1" @click="go(props.page - 1)" />
58
+ </li>
59
+ <li v-for="it in items" :key="it">
60
+ <span v-if="typeof it !== 'number'" class="wp-paging__gap" aria-hidden="true">…</span>
61
+ <button
62
+ v-else
63
+ type="button"
64
+ class="wp-paging__page"
65
+ :data-size="size"
66
+ :aria-current="it === page ? 'page' : undefined"
67
+ :aria-label="`Page ${it}`"
68
+ :disabled="disabled"
69
+ @click="go(it)"
70
+ >{{ it }}</button>
71
+ </li>
72
+ <li>
73
+ <WpButton variant="ghost" :size="btnSize" icon="pi-chevron-right" aria-label="Next page" :disabled="disabled || props.page >= pages" @click="go(props.page + 1)" />
74
+ </li>
75
+ </ul>
76
+ </nav>
77
+ <div v-else-if="mode === 'more' && total > 0" class="wp-paging wp-paging--more" :data-size="size">
78
+ <span class="wp-paging__range" aria-live="polite">Showing {{ Math.min(props.shown, total) }} of {{ total }}{{ noun ? ` ${noun}` : "" }}</span>
79
+ <WpButton v-if="props.shown < total" variant="secondary" :size="btnSize" :loading="loading" :disabled="disabled" @click="emit('more')">Load more</WpButton>
80
+ </div>
81
+ </template>
82
+
83
+ <style scoped>
84
+ .wp-paging {
85
+ display: flex; align-items: center; justify-content: space-between; gap: var(--wp-space-4); flex-wrap: wrap;
86
+ min-width: 0; color: var(--wp-text-muted); font: 400 var(--wp-text-sm)/1.2 var(--wp-font-sans);
87
+ }
88
+ .wp-paging[data-size="sm"] { font-size: var(--wp-text-xs); gap: var(--wp-space-3); }
89
+ .wp-paging--more { flex-direction: column; justify-content: center; }
90
+ .wp-paging__range { font-variant-numeric: tabular-nums; }
91
+ .wp-paging__list { display: flex; align-items: center; gap: 2px; margin: 0; padding: 0; list-style: none; }
92
+ .wp-paging__gap { display: inline-grid; place-items: center; min-width: 20px; color: var(--wp-text-dim); }
93
+ .wp-paging__page {
94
+ display: inline-grid; place-items: center; box-sizing: border-box;
95
+ min-width: var(--wp-control-h-md); height: var(--wp-control-h-md); margin: 0; padding: 0 var(--wp-space-2);
96
+ border: 1px solid transparent; border-radius: var(--wp-radius);
97
+ background: transparent; color: var(--wp-text-muted); font: 500 var(--wp-text-sm)/1 var(--wp-font-sans);
98
+ font-variant-numeric: tabular-nums; cursor: pointer;
99
+ transition: background var(--wp-motion-hover), color var(--wp-motion-hover);
100
+ }
101
+ .wp-paging__page[data-size="sm"] { min-width: var(--wp-control-h-sm); height: var(--wp-control-h-sm); border-radius: var(--wp-radius-sm); font-size: var(--wp-text-xs); }
102
+ .wp-paging__page:hover:not(:disabled) { background: var(--wp-row-hover); color: var(--wp-text); }
103
+ .wp-paging__page[aria-current="page"] { border-color: var(--wp-border-strong); background: var(--wp-bg-3); color: var(--wp-text); font-weight: 600; }
104
+ .wp-paging__page:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
105
+ .wp-paging__page:disabled { opacity: 0.45; cursor: not-allowed; }
106
+ </style>
@@ -0,0 +1,180 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A panel anchored to a trigger: opens below it (or wherever `placement`
4
+ * says), flips and stays on screen, follows the trigger on scroll and
5
+ * resize, and closes on Escape or a click outside, giving focus back to
6
+ * the trigger. Works on the canvas and in the manager. Anything that
7
+ * floats next to a control builds on this instead of its own Teleport.
8
+ *
9
+ * <Popover v-model:open="open" label="Category colour">
10
+ * <template #trigger="{ props }"><Button v-bind="props">Colour</Button></template>
11
+ * …panel content…
12
+ * </Popover>
13
+ *
14
+ * One panel shared by many triggers (the cells of a rule grid) passes the
15
+ * element it belongs to as `anchor` instead of a trigger slot; clicks on that
16
+ * element don't count as outside, so it can toggle the panel itself.
17
+ *
18
+ * <Popover :open="!!cell" :anchor="cell?.el" label="Cell rule" @update:open="cell = null">…</Popover>
19
+ */
20
+ import { computed, nextTick, onBeforeUnmount, ref, useId, watch } from "vue";
21
+ import { placeFloating, viewportSize, type Placement, type Side } from "./floating";
22
+ import { provideFloatingLayer, useFloatingChild } from "./floating-layer";
23
+
24
+ const props = withDefaults(defineProps<{
25
+ open: boolean;
26
+ placement?: Placement | undefined;
27
+ /** The panel's name for screen readers. */
28
+ label?: string | undefined;
29
+ /** Make the panel at least as wide as the trigger (lists under a field). */
30
+ matchWidth?: boolean | undefined;
31
+ /** Move focus into the panel when it opens. Off for panels you type past. */
32
+ autofocus?: boolean | undefined;
33
+ /** "dialog" for panels with controls, "menu"/"listbox" when the content is one. */
34
+ role?: "dialog" | "menu" | "listbox" | "group" | undefined;
35
+ /** Place the panel against this element instead of the trigger slot. */
36
+ anchor?: HTMLElement | null | undefined;
37
+ }>(), { placement: "bottom-start", autofocus: true, role: "dialog", anchor: null });
38
+
39
+ const emit = defineEmits<{ (e: "update:open", v: boolean): void }>();
40
+
41
+ const id = `wp-popover-${useId()}`;
42
+ const anchorEl = ref<HTMLElement | null>(null);
43
+ const panelEl = ref<HTMLElement | null>(null);
44
+ const pos = ref<{ x: number; y: number; side: Side; minWidth?: number | undefined }>({ x: -9999, y: -9999, side: "bottom" });
45
+
46
+ const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), '
47
+ + 'textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
48
+
49
+ function trigger(): HTMLElement | null {
50
+ if (props.anchor) return props.anchor;
51
+ const el = anchorEl.value;
52
+ return (el?.firstElementChild as HTMLElement | null) ?? el;
53
+ }
54
+
55
+ function setOpen(v: boolean): void {
56
+ if (v !== props.open) emit("update:open", v);
57
+ }
58
+
59
+ const triggerProps = computed(() => ({
60
+ "aria-haspopup": (props.role === "group" ? "true" : props.role) as "true" | "dialog" | "menu" | "listbox",
61
+ "aria-expanded": props.open,
62
+ "aria-controls": props.open ? id : undefined,
63
+ onClick: () => setOpen(!props.open),
64
+ }));
65
+
66
+ function place(): void {
67
+ const t = trigger();
68
+ const p = panelEl.value;
69
+ if (!t || !p) return;
70
+ const r = t.getBoundingClientRect();
71
+ const at = placeFloating(r, { width: Math.max(p.offsetWidth, props.matchWidth ? r.width : 0), height: p.offsetHeight }, viewportSize(), {
72
+ placement: props.placement,
73
+ });
74
+ pos.value = { ...at, minWidth: props.matchWidth ? r.width : undefined };
75
+ }
76
+
77
+ // A Select list, menu or Popover opened from inside this panel is part of it.
78
+ const layer = provideFloatingLayer();
79
+ // And this panel is part of a Popover it was opened from.
80
+ useFloatingChild(() => (props.open ? panelEl.value : null));
81
+
82
+ function onPointerDown(ev: PointerEvent): void {
83
+ const path = ev.composedPath();
84
+ if (layer.owns(path)) return;
85
+ if (panelEl.value && path.includes(panelEl.value)) return;
86
+ if (anchorEl.value && path.includes(anchorEl.value)) return;
87
+ if (props.anchor && path.includes(props.anchor)) return;
88
+ setOpen(false);
89
+ }
90
+
91
+ function onKeydown(ev: KeyboardEvent): void {
92
+ if (ev.key !== "Escape") return;
93
+ // An open list or menu inside the panel shuts first, on its own handler.
94
+ if (layer.childOpen()) return;
95
+ ev.preventDefault();
96
+ ev.stopPropagation();
97
+ setOpen(false);
98
+ trigger()?.focus();
99
+ }
100
+
101
+ function listen(on: boolean): void {
102
+ const m = on ? "addEventListener" : "removeEventListener";
103
+ window[m]("pointerdown", onPointerDown as EventListener, true);
104
+ window[m]("keydown", onKeydown as EventListener, true);
105
+ window[m]("resize", place);
106
+ window[m]("scroll", place, true);
107
+ }
108
+
109
+ watch(() => props.open, async (v) => {
110
+ if (typeof window === "undefined") return;
111
+ listen(v);
112
+ if (!v) return;
113
+ await nextTick();
114
+ place();
115
+ if (props.autofocus && panelEl.value && !panelEl.value.contains(document.activeElement)) {
116
+ (panelEl.value.querySelector<HTMLElement>(FOCUSABLE) ?? panelEl.value).focus();
117
+ }
118
+ }, { immediate: true });
119
+
120
+ // A shared panel moving to another trigger re-places without closing.
121
+ watch(() => props.anchor, () => { if (props.open) void nextTick(place); });
122
+
123
+ onBeforeUnmount(() => { if (typeof window !== "undefined") listen(false); });
124
+
125
+ defineExpose({ place });
126
+ </script>
127
+
128
+ <template>
129
+ <span v-if="$slots.trigger" ref="anchorEl" class="wp-popover-anchor">
130
+ <slot name="trigger" :props="triggerProps" :open="open" />
131
+ </span>
132
+ <Teleport to="body">
133
+ <div
134
+ v-if="open"
135
+ :id="id"
136
+ ref="panelEl"
137
+ class="wp-popover"
138
+ :data-side="pos.side"
139
+ :role="role"
140
+ :aria-label="label"
141
+ tabindex="-1"
142
+ :style="{ left: `${pos.x}px`, top: `${pos.y}px`, minWidth: pos.minWidth ? `${pos.minWidth}px` : undefined }"
143
+ >
144
+ <slot :close="() => setOpen(false)" />
145
+ </div>
146
+ </Teleport>
147
+ </template>
148
+
149
+ <style>
150
+ @layer wp-extension {
151
+ .wp-popover-anchor { display: inline-flex; }
152
+ .wp-popover {
153
+ position: fixed;
154
+ z-index: 10000;
155
+ max-width: min(420px, calc(100vw - 16px));
156
+ max-height: calc(100vh - 16px);
157
+ overflow: auto;
158
+ padding: var(--wp-space-3);
159
+ background: var(--wp-bg-2);
160
+ color: var(--wp-text);
161
+ border: 1px solid var(--wp-border-strong);
162
+ border-radius: var(--wp-radius);
163
+ box-shadow: var(--wp-shadow-md);
164
+ font-family: var(--wp-font-sans);
165
+ font-size: var(--wp-text-sm);
166
+ outline: none;
167
+ animation: wp-popover-in 120ms ease-out;
168
+ }
169
+ @keyframes wp-popover-in {
170
+ from { opacity: 0; transform: translateY(-2px); }
171
+ }
172
+ .wp-popover[data-side="top"] { animation-name: wp-popover-in-up; }
173
+ @keyframes wp-popover-in-up {
174
+ from { opacity: 0; transform: translateY(2px); }
175
+ }
176
+ @media (prefers-reduced-motion: reduce) {
177
+ .wp-popover { animation: none; }
178
+ }
179
+ }
180
+ </style>
@@ -0,0 +1,210 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A community post as a card: type chip, NSFW / Featured / recommended
4
+ * badges, version, `owner/name` slug, bundle contents, description, up to
5
+ * four tags, then stars, downloads and when it was updated. A coloured stripe
6
+ * on top says the type; a featured card is tinted, a deleted one faded.
7
+ *
8
+ * The whole card is one link. It renders an `<a>` by default; pass the app's
9
+ * router link as `as` (and its `to`) so the kit never imports a router:
10
+ *
11
+ * <PostCard :as="RouterLink" :to="`/p/${post.slug}`" :post="card(post)" />
12
+ * <PostCard href="/p/dumi/warm" :post="…" />
13
+ * <PostCard as="button" type="button" :post="…" @click="open" />
14
+ */
15
+ import { computed, type Component } from "vue";
16
+ import BundleMeta from "./BundleMeta.vue";
17
+ import Icon from "./Icon.vue";
18
+ import Chip from "./Chip.vue";
19
+ import { itemType, kindColour, type ItemType } from "./kind-colour";
20
+ import RelativeDate from "./RelativeDate.vue";
21
+
22
+ export interface PostCardData {
23
+ /** `owner/name`. */
24
+ slug: string;
25
+ kind: "module" | "bundle";
26
+ subtype?: ItemType | null | undefined;
27
+ description?: string | undefined;
28
+ tags?: string[] | undefined;
29
+ stars: number;
30
+ downloads: number;
31
+ /** ISO time of the last update. */
32
+ updatedAt: string;
33
+ rating?: "sfw" | "nsfw" | undefined;
34
+ featured?: boolean | undefined;
35
+ /** The latest version is marked recommended. */
36
+ recommended?: boolean | undefined;
37
+ /** Soft-deleted: the card fades and shows "deleted" where the version goes. */
38
+ deleted?: boolean | undefined;
39
+ version?: number | null | undefined;
40
+ bundleModules?: { count: number; names: string[] } | null | undefined;
41
+ }
42
+
43
+ const props = withDefaults(defineProps<{
44
+ post: PostCardData;
45
+ /** The viewer starred it: the star in the footer fills. */
46
+ starred?: boolean | undefined;
47
+ /** Element or component for the link, e.g. the app's RouterLink. */
48
+ as?: string | Component | undefined;
49
+ }>(), { starred: false, as: "a" });
50
+
51
+ const type = computed(() => itemType(props.post.kind, props.post.subtype));
52
+ const owner = computed(() => props.post.slug.split("/")[0]);
53
+ const name = computed(() => props.post.slug.split("/").slice(1).join("/"));
54
+ const tags = computed(() => props.post.tags ?? []);
55
+ </script>
56
+
57
+ <template>
58
+ <component
59
+ :is="as"
60
+ class="wp-post-card"
61
+ :data-type="type"
62
+ :data-featured="post.featured || undefined"
63
+ :data-deleted="post.deleted || undefined"
64
+ >
65
+ <div class="wp-post-card__top">
66
+ <div class="wp-post-card__badges">
67
+ <Chip :color="kindColour(type)">{{ type }}</Chip>
68
+ <Chip v-if="post.rating === 'nsfw'" tone="danger">NSFW</Chip>
69
+ <Chip v-if="post.featured" tone="warn" icon="star-fill">Featured</Chip>
70
+ <Chip v-if="post.recommended" tone="success" dot>recommended</Chip>
71
+ </div>
72
+ <span v-if="post.deleted" class="wp-chip wp-chip--danger"><Icon name="trash" :size="10" />deleted</span>
73
+ <span v-else class="wp-chip">v{{ post.version ?? 1 }}</span>
74
+ </div>
75
+
76
+ <div class="wp-post-card__slug">
77
+ <span class="wp-post-card__owner">{{ owner }}</span><span class="wp-post-card__sep">/</span>{{ name }}
78
+ </div>
79
+
80
+ <BundleMeta
81
+ v-if="post.kind === 'bundle' && post.bundleModules"
82
+ :count="post.bundleModules.count"
83
+ :names="post.bundleModules.names"
84
+ />
85
+
86
+ <p v-if="post.description" class="wp-post-card__desc">{{ post.description }}</p>
87
+
88
+ <div v-if="tags.length" class="wp-post-card__tags">
89
+ <span v-for="t in tags.slice(0, 4)" :key="t" class="wp-chip">{{ t }}</span>
90
+ <span v-if="tags.length > 4" class="wp-chip">+{{ tags.length - 4 }}</span>
91
+ </div>
92
+
93
+ <div class="wp-post-card__foot">
94
+ <span class="wp-post-card__stat" :data-active="starred || undefined">
95
+ <Icon :name="starred ? 'star-fill' : 'star'" :size="11" />{{ post.stars.toLocaleString() }}
96
+ </span>
97
+ <span class="wp-post-card__stat">
98
+ <Icon name="download" :size="11" />{{ post.downloads.toLocaleString() }}
99
+ </span>
100
+ <RelativeDate class="wp-post-card__when" :value="post.updatedAt" />
101
+ </div>
102
+ </component>
103
+ </template>
104
+
105
+ <style scoped>
106
+ .wp-post-card {
107
+ --post-card-c: var(--wp-text-dim);
108
+ position: relative;
109
+ display: flex;
110
+ flex-direction: column;
111
+ gap: 14px;
112
+ width: 100%;
113
+ padding: 20px 20px 18px;
114
+ overflow: hidden;
115
+ break-inside: avoid;
116
+ /* The page spaces its cards (a grid gap or margins); one set here would
117
+ beat the page's rule, since scoped styles win ties. */
118
+ font: inherit;
119
+ color: inherit;
120
+ text-align: left;
121
+ text-decoration: none;
122
+ cursor: pointer;
123
+ background: var(--wp-bg-1);
124
+ border: 1px solid var(--wp-border);
125
+ border-radius: min(12px, var(--wp-radius-cap, 999px));
126
+ transition: transform var(--wp-motion-quick) ease, border-color var(--wp-motion-quick) ease, box-shadow var(--wp-motion-quick) ease;
127
+ }
128
+ .wp-post-card::before {
129
+ content: "";
130
+ position: absolute;
131
+ inset: 0 0 auto;
132
+ height: 3px;
133
+ opacity: 0.85;
134
+ background: linear-gradient(90deg, var(--post-card-c), color-mix(in oklab, var(--post-card-c) 50%, transparent));
135
+ }
136
+ .wp-post-card[data-type="fixed_values"] { --post-card-c: var(--wp-kind-fixed); }
137
+ .wp-post-card[data-type="combine"] { --post-card-c: var(--wp-kind-combine); }
138
+ .wp-post-card[data-type="wildcard"] { --post-card-c: var(--wp-kind-wildcard); }
139
+ .wp-post-card[data-type="constraint"] { --post-card-c: var(--wp-kind-constraint); }
140
+ .wp-post-card[data-type="derivation"] { --post-card-c: var(--wp-kind-derivation); }
141
+ .wp-post-card[data-type="bundle"] { --post-card-c: var(--wp-bundle-default); }
142
+ .wp-post-card:hover {
143
+ transform: translateY(-3px);
144
+ border-color: var(--wp-border-strong);
145
+ box-shadow: var(--wp-shadow-lg);
146
+ }
147
+ .wp-post-card:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
148
+ .wp-post-card:hover .wp-post-card__slug { color: var(--wp-accent-text-strong); }
149
+ .wp-post-card[data-featured] {
150
+ background: linear-gradient(180deg, color-mix(in oklab, var(--wp-warn) 5%, var(--wp-bg-1)), var(--wp-bg-1) 60%);
151
+ border-color: color-mix(in oklab, var(--wp-warn) 25%, var(--wp-border));
152
+ }
153
+ .wp-post-card[data-featured]:hover { border-color: color-mix(in oklab, var(--wp-warn) 40%, var(--wp-border)); }
154
+ .wp-post-card[data-deleted] { opacity: 0.62; filter: grayscale(40%); }
155
+ .wp-post-card[data-deleted]:hover { opacity: 0.85; filter: none; }
156
+
157
+ .wp-post-card__top {
158
+ display: flex;
159
+ flex-wrap: wrap;
160
+ align-items: flex-start;
161
+ justify-content: space-between;
162
+ gap: 8px;
163
+ min-height: 22px;
164
+ }
165
+ .wp-post-card__badges { display: flex; flex: 1; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
166
+ .wp-post-card__slug {
167
+ font-family: var(--wp-font-mono);
168
+ font-size: 15.5px;
169
+ font-weight: 500;
170
+ line-height: 1.35;
171
+ color: var(--wp-text);
172
+ word-break: break-word;
173
+ transition: color var(--wp-motion-quick) ease;
174
+ }
175
+ .wp-post-card__owner { font-weight: 400; color: var(--wp-text-muted); }
176
+ .wp-post-card__sep { color: var(--wp-accent-text); }
177
+ .wp-post-card__desc {
178
+ display: -webkit-box;
179
+ margin: 0;
180
+ overflow: hidden;
181
+ font-size: 13px;
182
+ line-height: 19px;
183
+ color: var(--wp-text-muted);
184
+ text-wrap: pretty;
185
+ -webkit-line-clamp: 3;
186
+ -webkit-box-orient: vertical;
187
+ }
188
+ .wp-post-card__tags { display: flex; flex-wrap: wrap; gap: 4px; }
189
+ .wp-post-card__tags .wp-chip { padding: 2px 8px; font-size: 11px; }
190
+ .wp-post-card__foot {
191
+ display: flex;
192
+ align-items: center;
193
+ gap: 16px;
194
+ margin-top: 4px;
195
+ padding-top: 16px;
196
+ border-top: 1px solid var(--wp-border);
197
+ font-size: 12px;
198
+ color: var(--wp-text-muted);
199
+ }
200
+ .wp-post-card__stat {
201
+ display: inline-flex;
202
+ align-items: center;
203
+ gap: 5px;
204
+ font-family: var(--wp-font-mono);
205
+ font-variant-numeric: tabular-nums;
206
+ }
207
+ .wp-post-card__stat :deep(.pi) { color: var(--wp-text-dim); }
208
+ .wp-post-card__stat[data-active] :deep(.pi) { color: var(--wp-accent-text); }
209
+ .wp-post-card__when { margin-left: auto; font-size: 11.5px; color: var(--wp-text-dim); }
210
+ </style>