@pseudolux-ui/media-library 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +22 -4
- package/src/checks.ts +132 -0
- package/src/components/BinDialog.lsp +208 -0
- package/src/components/CommandBar.lsp +526 -0
- package/src/components/CropEditor.lsp +616 -0
- package/src/components/DescribeRun.lsp +527 -0
- package/src/components/GroupCover.lsp +227 -0
- package/src/components/LibraryDesk.lsp +415 -0
- package/src/components/LibraryFrame.lsp +362 -0
- package/src/components/LibraryGroups.lsp +197 -0
- package/src/components/LinkDialog.lsp +436 -0
- package/src/components/PictureEditor.lsp +1813 -0
- package/src/components/PicturePeek.lsp +428 -0
- package/src/components/PictureWall.lsp +1532 -0
- package/src/components/ResponsiveImage.lsp +297 -0
- package/src/components/SentenceBar.lsp +361 -0
- package/src/components/UploadBatch.lsp +1083 -0
- package/src/config.ts +206 -0
- package/src/cuts.ts +29 -0
- package/src/index.ts +44 -0
- package/src/ladder.ts +82 -0
- package/src/port.ts +217 -0
- package/src/rows.ts +142 -0
- package/src/sentence.ts +164 -0
- package/src/styles/px.css +152 -0
- package/src/survey.ts +75 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nick Paustian
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pseudolux-ui/media-library",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Lightspeed components for browsing, describing, cropping and uploading Pseudolux pictures, over a port the host implements.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Nick Paustian",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./src/index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts",
|
|
11
|
+
"./components": "./src/components/",
|
|
12
|
+
"./px.css": "./src/styles/px.css"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@pseudolux-ui/client": "^0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@lightspeed-js/core": "^0.5.6"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
]
|
|
24
|
+
}
|
package/src/checks.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the editor says about a picture's words and how complete it is.
|
|
3
|
+
* Advice, never a gate: every check is something a person may overrule.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface Check {
|
|
7
|
+
tone: "ok" | "warn"
|
|
8
|
+
text: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const FILE_NAME = /\.(jpe?g|png|webp|gif|avif|tiff?|heic|svg)\b/i
|
|
12
|
+
const SAYS_IMAGE = /^(an? |the )?(image|picture|photo(graph)?|pic|graphic) (of|showing|shows)\b/i
|
|
13
|
+
|
|
14
|
+
export const ALT_LENGTH = 150
|
|
15
|
+
|
|
16
|
+
/** The live checks under the alt text box. */
|
|
17
|
+
export const altChecks = (text: string): Check[] => {
|
|
18
|
+
const words = text.trim()
|
|
19
|
+
if (!words) {
|
|
20
|
+
return [{ tone: "warn", text: "Needs words. Say what matters on the pages it’s used on, in a sentence or two." }]
|
|
21
|
+
}
|
|
22
|
+
const out: Check[] = []
|
|
23
|
+
if (SAYS_IMAGE.test(words)) {
|
|
24
|
+
out.push({ tone: "warn", text: "No need to start with “image of”: screen readers already say it’s an image." })
|
|
25
|
+
}
|
|
26
|
+
if (FILE_NAME.test(words)) {
|
|
27
|
+
out.push({ tone: "warn", text: "Looks like a file name. Describe the picture instead." })
|
|
28
|
+
}
|
|
29
|
+
if (words.length > ALT_LENGTH) {
|
|
30
|
+
out.push({ tone: "warn", text: `${words.length} characters. Try to keep it under ${ALT_LENGTH}; put the rest in a caption.` })
|
|
31
|
+
}
|
|
32
|
+
if (!out.length) out.push({ tone: "ok", text: `${words.length} characters. Reads well.` })
|
|
33
|
+
return out
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Completeness {
|
|
37
|
+
done: number
|
|
38
|
+
of: number
|
|
39
|
+
missing: string[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** How much of a picture's record is filled in, and what is left. */
|
|
43
|
+
export const completeness = (item: {
|
|
44
|
+
altText?: string
|
|
45
|
+
credit?: string
|
|
46
|
+
labels?: unknown[]
|
|
47
|
+
focal?: unknown
|
|
48
|
+
crops?: Record<string, unknown>
|
|
49
|
+
}): Completeness => {
|
|
50
|
+
const parts: Array<[string, boolean]> = [
|
|
51
|
+
["alt text", Boolean(item.altText && item.altText.trim())],
|
|
52
|
+
["credit", Boolean(item.credit && item.credit.trim())],
|
|
53
|
+
["labels", Boolean(item.labels && item.labels.length)],
|
|
54
|
+
["focal point", Boolean(item.focal)],
|
|
55
|
+
]
|
|
56
|
+
return {
|
|
57
|
+
done: parts.filter(([, ok]) => ok).length,
|
|
58
|
+
of: parts.length,
|
|
59
|
+
missing: parts.filter(([, ok]) => !ok).map(([name]) => name),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const channel = (value: number): number => {
|
|
64
|
+
const c = value / 255
|
|
65
|
+
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const luminance = (hex: string): number => {
|
|
69
|
+
const match = /^#?([0-9a-f]{6})$/i.exec(hex.trim())
|
|
70
|
+
if (!match || !match[1]) return 0.5
|
|
71
|
+
const n = parseInt(match[1], 16)
|
|
72
|
+
return 0.2126 * channel((n >> 16) & 255) + 0.7152 * channel((n >> 8) & 255) + 0.0722 * channel(n & 255)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const contrast = (a: number, b: number): number => (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
|
|
76
|
+
|
|
77
|
+
/** Large text needs 3:1 against what is behind it. */
|
|
78
|
+
const LARGE_TEXT = 3
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Whether white or dark text can sit on a picture, judged by the colours it
|
|
82
|
+
* is mostly made of. A guide for a headline over a hero, not a measurement
|
|
83
|
+
* of any one spot.
|
|
84
|
+
*/
|
|
85
|
+
export const textOver = (palette: Array<{ hex: string; weight: number }>): string => {
|
|
86
|
+
if (!palette.length) return ""
|
|
87
|
+
const total = palette.reduce((sum, one) => sum + one.weight, 0) || 1
|
|
88
|
+
const share = (text: number) =>
|
|
89
|
+
palette.filter((one) => contrast(luminance(one.hex), text) >= LARGE_TEXT).reduce((sum, one) => sum + one.weight, 0) / total
|
|
90
|
+
const white = share(1)
|
|
91
|
+
const dark = share(luminance("#111111"))
|
|
92
|
+
const say = (portion: number, name: string): string =>
|
|
93
|
+
portion >= 0.9 ? `${name} text is readable over it.` : portion >= 0.4 ? `${name} text is readable over parts of it.` : `${name} text isn't readable over it.`
|
|
94
|
+
return say(white, "White") + " " + say(dark, "Dark")
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface Flag {
|
|
98
|
+
/** "danger" stops a picture doing its job; "warn" is worth a look. */
|
|
99
|
+
tone: "danger" | "warn"
|
|
100
|
+
label: string
|
|
101
|
+
detail: string
|
|
102
|
+
fix: string
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* What is wrong with a picture's file, judged from its size against the
|
|
107
|
+
* shapes the sites show it at. Too small for every shape is a problem; too
|
|
108
|
+
* small for some is a caution.
|
|
109
|
+
*/
|
|
110
|
+
export const flagsOf = (
|
|
111
|
+
item: { width?: number; height?: number },
|
|
112
|
+
presets: Array<{ label: string; ratio: number; minWidth?: number }>,
|
|
113
|
+
): Flag[] => {
|
|
114
|
+
if (!item.width || !item.height) return []
|
|
115
|
+
const sized = presets.filter((one) => one.minWidth)
|
|
116
|
+
if (!sized.length) return []
|
|
117
|
+
const aspect = item.width / item.height
|
|
118
|
+
// The widest cut of each shape the picture can give.
|
|
119
|
+
const short = sized.filter((one) => (one.ratio >= aspect ? item.width! : Math.round(item.height! * one.ratio)) < one.minWidth!)
|
|
120
|
+
if (!short.length) return []
|
|
121
|
+
const all = short.length === sized.length
|
|
122
|
+
return [
|
|
123
|
+
{
|
|
124
|
+
tone: all ? "danger" : "warn",
|
|
125
|
+
label: all ? "Too small" : "Small for " + short.map((one) => one.label.toLowerCase()).join(", "),
|
|
126
|
+
detail: all
|
|
127
|
+
? `At ${item.width} px wide it will look soft in every shape the sites use.`
|
|
128
|
+
: short.map((one) => `${one.label} is shown up to ${one.minWidth} px wide`).join("; ") + ".",
|
|
129
|
+
fix: "Replace it with a larger file, or find a bigger one.",
|
|
130
|
+
},
|
|
131
|
+
]
|
|
132
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<view>
|
|
2
|
+
<dialog
|
|
3
|
+
class="px-dialog bin-dialog"
|
|
4
|
+
role="alertdialog"
|
|
5
|
+
aria-labelledby="px-bin-title"
|
|
6
|
+
aria-describedby="px-bin-warning"
|
|
7
|
+
$ref="dialog"
|
|
8
|
+
@close="closed"
|
|
9
|
+
>
|
|
10
|
+
<div class="px-dialog-head">
|
|
11
|
+
<h3 id="px-bin-title" class="title">Move “{{ state.label }}” to the bin?</h3>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div class="body">
|
|
15
|
+
<div id="px-bin-warning">
|
|
16
|
+
<div class="px-callout px-callout-warn" $show="state.warnTitle">
|
|
17
|
+
<span><b>{{ state.warnTitle }}</b> {{ state.warnText }}</span>
|
|
18
|
+
</div>
|
|
19
|
+
<p class="px-subtle" $show="!state.warnTitle">{{ state.quietNote }}</p>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<label class="px-field">
|
|
23
|
+
<span class="px-label">Why? <span class="px-subtle quiet">Shown to anyone who finds it in the bin</span></span>
|
|
24
|
+
<select class="px-select" $model="state.reason">
|
|
25
|
+
<option $for="one in state.reasons" $key="one" $value="one" $text="one"></option>
|
|
26
|
+
</select>
|
|
27
|
+
</label>
|
|
28
|
+
|
|
29
|
+
<label class="px-field">
|
|
30
|
+
<span class="px-label">Note <span class="px-subtle quiet">Optional</span></span>
|
|
31
|
+
<input class="px-input" type="text" maxlength="400" $model="state.note" />
|
|
32
|
+
</label>
|
|
33
|
+
|
|
34
|
+
<div class="px-callout px-callout-danger" role="alert" $show="state.error"><span>{{ state.error }}</span></div>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div class="px-dialog-foot foot">
|
|
38
|
+
<button class="px-btn px-btn-secondary" type="button" autofocus $disabled="state.busy" @click="keep">Keep it</button>
|
|
39
|
+
<button class="px-btn px-btn-danger" type="button" $disabled="state.busy" @click="confirm">{{ state.confirmLabel }}</button>
|
|
40
|
+
</div>
|
|
41
|
+
</dialog>
|
|
42
|
+
</view>
|
|
43
|
+
|
|
44
|
+
<logic lang="ts">
|
|
45
|
+
import { reactive, shared, defineRefs, onMounted } from '@lightspeed-js/core'
|
|
46
|
+
import { getLibrary, BIN_DIALOG, SELECTED, CHANGED } from '../config.ts'
|
|
47
|
+
|
|
48
|
+
const REASONS = ['Duplicate', 'Poor quality', 'Rights have ended', 'Other…']
|
|
49
|
+
|
|
50
|
+
const state = reactive({
|
|
51
|
+
label: '',
|
|
52
|
+
reasons: REASONS,
|
|
53
|
+
reason: REASONS[0],
|
|
54
|
+
note: '',
|
|
55
|
+
warnTitle: '',
|
|
56
|
+
warnText: '',
|
|
57
|
+
quietNote: '',
|
|
58
|
+
confirmLabel: 'Move to bin',
|
|
59
|
+
busy: false,
|
|
60
|
+
error: '',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const request = shared(BIN_DIALOG)
|
|
64
|
+
const selected = shared(SELECTED)
|
|
65
|
+
const changed = shared(CHANGED)
|
|
66
|
+
const refs = defineRefs()
|
|
67
|
+
|
|
68
|
+
let asked = null
|
|
69
|
+
let opener = null
|
|
70
|
+
|
|
71
|
+
function plural(n, one, many) {
|
|
72
|
+
return n + ' ' + (n === 1 ? one : many)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function moveLabel() {
|
|
76
|
+
const pages = (asked && asked.pages && asked.pages.length) || 0
|
|
77
|
+
return pages ? 'Move to bin and remove from ' + plural(pages, 'page', 'pages') : 'Move to bin'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function describeUse(next) {
|
|
81
|
+
const pages = next.pages || []
|
|
82
|
+
const seen = next.seen || 0
|
|
83
|
+
state.warnTitle = ''
|
|
84
|
+
state.warnText = ''
|
|
85
|
+
if (pages.length) {
|
|
86
|
+
state.warnTitle = plural(pages.length, 'page', 'pages') + ' will show a gap:'
|
|
87
|
+
state.warnText =
|
|
88
|
+
pages.map((one) => (one.site ? one.site + ' · ' : '') + one.title).join('; ') +
|
|
89
|
+
'. Pictures in the bin are no longer served, so those pages lose it until it is restored or their editors choose another.'
|
|
90
|
+
} else if (seen) {
|
|
91
|
+
state.warnTitle = 'Still being requested.'
|
|
92
|
+
state.warnText =
|
|
93
|
+
'No page has reported using it, but ' + plural(seen, 'site has', 'sites have') +
|
|
94
|
+
' asked for it in the last 30 days. Pictures in the bin are no longer served.'
|
|
95
|
+
}
|
|
96
|
+
state.quietNote = next.usageKnown
|
|
97
|
+
? 'No page has reported using it. Restore puts it back as it was.'
|
|
98
|
+
: 'Restore puts it back as it was.'
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function reasonText() {
|
|
102
|
+
const reason = state.reason.replace(/…$/, '')
|
|
103
|
+
const note = state.note.trim()
|
|
104
|
+
return note ? reason + ': ' + note : reason
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function confirm() {
|
|
108
|
+
if (!asked || state.busy) return
|
|
109
|
+
const id = asked.id
|
|
110
|
+
const reason = reasonText()
|
|
111
|
+
state.busy = true
|
|
112
|
+
state.confirmLabel = 'Moving…'
|
|
113
|
+
state.error = ''
|
|
114
|
+
try {
|
|
115
|
+
const result = await getLibrary().remove(id, reason)
|
|
116
|
+
const deletedAt = (result && result.deletedAt) || new Date().toISOString()
|
|
117
|
+
const row = selected.value
|
|
118
|
+
if (row && row.id === id) selected.value = { ...row, deletedAt, deletedReason: reason }
|
|
119
|
+
changed.value = (changed.value || 0) + 1
|
|
120
|
+
close()
|
|
121
|
+
} catch (err) {
|
|
122
|
+
state.error = err && err.message ? err.message : 'Could not move it to the bin.'
|
|
123
|
+
} finally {
|
|
124
|
+
state.busy = false
|
|
125
|
+
state.confirmLabel = moveLabel()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function keep() {
|
|
130
|
+
close()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function close() {
|
|
134
|
+
const dialog = refs.dialog
|
|
135
|
+
if (dialog && dialog.open) dialog.close()
|
|
136
|
+
else closed()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function closed() {
|
|
140
|
+
if (opener && opener.isConnected && opener.focus) opener.focus()
|
|
141
|
+
opener = null
|
|
142
|
+
asked = null
|
|
143
|
+
if (request.value) request.value = null
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function open(next) {
|
|
147
|
+
if (!next) {
|
|
148
|
+
const dialog = refs.dialog
|
|
149
|
+
if (dialog && dialog.open) dialog.close()
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
asked = next
|
|
153
|
+
state.label = next.label || next.id
|
|
154
|
+
state.reason = REASONS[0]
|
|
155
|
+
state.note = ''
|
|
156
|
+
state.error = ''
|
|
157
|
+
state.busy = false
|
|
158
|
+
describeUse(next)
|
|
159
|
+
state.confirmLabel = moveLabel()
|
|
160
|
+
const dialog = refs.dialog
|
|
161
|
+
if (dialog && !dialog.open && dialog.showModal) {
|
|
162
|
+
opener = document.activeElement
|
|
163
|
+
dialog.showModal()
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
request.subscribe(open)
|
|
168
|
+
|
|
169
|
+
onMounted(() => {
|
|
170
|
+
if (request.value) open(request.value)
|
|
171
|
+
})
|
|
172
|
+
</logic>
|
|
173
|
+
|
|
174
|
+
<style>
|
|
175
|
+
.bin-dialog {
|
|
176
|
+
width: min(520px, calc(100vw - 32px));
|
|
177
|
+
max-width: none;
|
|
178
|
+
padding: 0;
|
|
179
|
+
color: var(--px-text);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.bin-dialog:not([open]) {
|
|
183
|
+
display: none;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.bin-dialog::backdrop {
|
|
187
|
+
background: var(--px-scrim);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.title {
|
|
191
|
+
overflow-wrap: anywhere;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.body {
|
|
195
|
+
display: flex;
|
|
196
|
+
flex-direction: column;
|
|
197
|
+
gap: 14px;
|
|
198
|
+
padding: 16px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.quiet {
|
|
202
|
+
font-weight: 400;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.foot {
|
|
206
|
+
justify-content: flex-end;
|
|
207
|
+
}
|
|
208
|
+
</style>
|