@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
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
<view>
|
|
2
|
+
<div class="responsive-image" $ref="frame" $style="state.frameStyle">
|
|
3
|
+
<!-- The static render. A box of the right shape in the picture's own colour,
|
|
4
|
+
present before any JavaScript runs and removed only once the real image
|
|
5
|
+
has painted over it. -->
|
|
6
|
+
<div class="stand-in" $show="state.showStandIn" $style="state.standInStyle"></div>
|
|
7
|
+
|
|
8
|
+
<img
|
|
9
|
+
class="picture"
|
|
10
|
+
$show="state.src"
|
|
11
|
+
$src="state.src"
|
|
12
|
+
$alt="state.alt"
|
|
13
|
+
$width="state.width"
|
|
14
|
+
$height="state.height"
|
|
15
|
+
$loading="state.loading"
|
|
16
|
+
$style="state.pictureStyle"
|
|
17
|
+
@load="loaded"
|
|
18
|
+
@error="failed"
|
|
19
|
+
/>
|
|
20
|
+
|
|
21
|
+
<noscript>
|
|
22
|
+
<!-- Without JavaScript the box above is all there is, which is a coloured
|
|
23
|
+
rectangle where a picture should be. One default size is not the right
|
|
24
|
+
width for anybody and is the right order of magnitude for everybody. -->
|
|
25
|
+
<img class="picture plain" $src="state.fallback" $alt="state.alt" />
|
|
26
|
+
</noscript>
|
|
27
|
+
</div>
|
|
28
|
+
</view>
|
|
29
|
+
|
|
30
|
+
<logic lang="ts">
|
|
31
|
+
import { defineProps, reactive, onMounted, onUpdate, onUnmounted, defineRefs } from '@lightspeed-js/core'
|
|
32
|
+
import { getLibrary } from '../config.ts'
|
|
33
|
+
import { pixelsFor } from '../ladder.ts'
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A picture that asks for the size it is actually being shown at.
|
|
37
|
+
*
|
|
38
|
+
* The alternative is `srcset`, which asks the author to guess the layout at
|
|
39
|
+
* build time and then asks the browser to guess again from `sizes`. This
|
|
40
|
+
* measures instead - but it can only measure after layout, which is why the
|
|
41
|
+
* static HTML carries the *shape* and the colour, and hydration supplies the
|
|
42
|
+
* pixels.
|
|
43
|
+
*
|
|
44
|
+
* That split is what a Lightspeed island already is: one component, whose
|
|
45
|
+
* server render *is* the placeholder. React needs two components for it,
|
|
46
|
+
* because the halves sit on opposite sides of a boundary.
|
|
47
|
+
*
|
|
48
|
+
* **Props may change under it.** In a picker the same instance is reused as
|
|
49
|
+
* the selection moves, so everything derived from a prop is computed in
|
|
50
|
+
* `configure`, which `onUpdate` re-runs. Reading a prop once into a local at
|
|
51
|
+
* setup is what stops that working - the framework keeps `props` current, and
|
|
52
|
+
* a snapshot opts out of it.
|
|
53
|
+
*/
|
|
54
|
+
const props = defineProps({
|
|
55
|
+
/** The asset. */
|
|
56
|
+
pid: { default: '' },
|
|
57
|
+
/** Unique on the page. Only used to find this element in order to measure
|
|
58
|
+
* it - see the note above about why that is necessary. */
|
|
59
|
+
id: { default: '' },
|
|
60
|
+
alt: { default: '' },
|
|
61
|
+
/** A number or `"320px"` fixes it; `"100%"` or `"50vw"` measures it. */
|
|
62
|
+
width: { default: undefined },
|
|
63
|
+
height: { default: undefined },
|
|
64
|
+
/** Width over height. Reserves the box when only one dimension is given. */
|
|
65
|
+
aspectRatio: { default: undefined },
|
|
66
|
+
/** The picture's own colour, from its palette. Falls back to a neutral. */
|
|
67
|
+
standIn: { default: '#eee' },
|
|
68
|
+
/** `contain` rather than `cover`. */
|
|
69
|
+
fit: { default: 'cover' },
|
|
70
|
+
objectPosition: { default: '' },
|
|
71
|
+
/** Above the fold: load eagerly and do not fade. */
|
|
72
|
+
priority: { default: false },
|
|
73
|
+
format: { default: 'webp' },
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
/** How long the fade lasts, and the point past which it is worth having. */
|
|
77
|
+
const FADE_MS = 400
|
|
78
|
+
const INSTANT_MS = 1000
|
|
79
|
+
|
|
80
|
+
/** What no-JS gets. Wrong for everybody, and wrong by less than any other
|
|
81
|
+
* single number would be. */
|
|
82
|
+
const FALLBACK_WIDTH = 800
|
|
83
|
+
|
|
84
|
+
const fixed = (value) => {
|
|
85
|
+
if (typeof value === 'number') return value
|
|
86
|
+
if (typeof value === 'string') {
|
|
87
|
+
const px = value.match(/^(\d+)px$/)
|
|
88
|
+
if (px) return parseInt(px[1], 10)
|
|
89
|
+
}
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const responsive = (value) =>
|
|
94
|
+
typeof value === 'string' && !/^\d+px$/.test(value) ? value : null
|
|
95
|
+
|
|
96
|
+
const ratio = (value) => {
|
|
97
|
+
if (typeof value === 'number') return value > 0 ? value : null
|
|
98
|
+
if (typeof value === 'string' && value.includes('/')) {
|
|
99
|
+
const [w, h] = value.split('/').map((one) => parseFloat(one))
|
|
100
|
+
return w > 0 && h > 0 ? w / h : null
|
|
101
|
+
}
|
|
102
|
+
const parsed = parseFloat(value)
|
|
103
|
+
return parsed > 0 ? parsed : null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const refs = defineRefs()
|
|
107
|
+
|
|
108
|
+
const state = reactive({
|
|
109
|
+
src: '',
|
|
110
|
+
fallback: '',
|
|
111
|
+
alt: '',
|
|
112
|
+
width: 0,
|
|
113
|
+
height: 0,
|
|
114
|
+
loading: 'lazy',
|
|
115
|
+
showStandIn: true,
|
|
116
|
+
frameStyle: '',
|
|
117
|
+
standInStyle: '',
|
|
118
|
+
pictureStyle: '',
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
let root = null
|
|
122
|
+
let cleanUp = null
|
|
123
|
+
let startedAt = 0
|
|
124
|
+
let fade = FADE_MS
|
|
125
|
+
// The largest size already requested. Resizing smaller must not ask for a
|
|
126
|
+
// smaller file: the bigger one is in cache and the browser scales it for free,
|
|
127
|
+
// so a downward request costs a round trip to look identical.
|
|
128
|
+
let asked = 0
|
|
129
|
+
// What is on screen: the picture and the box it was given. The picker reuses
|
|
130
|
+
// one instance as the selection moves, so a new `pid` is a different picture
|
|
131
|
+
// in the same box rather than a new component - and a new shape for the same
|
|
132
|
+
// picture, which arrives when the detail refines a row's guess, is a new box.
|
|
133
|
+
let showing = ''
|
|
134
|
+
|
|
135
|
+
function signature() {
|
|
136
|
+
return [props.pid, props.aspectRatio, props.width, props.height, props.fit].join('|')
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function ask(cssWidth, cssHeight) {
|
|
140
|
+
// Device pixels, not CSS pixels - and capped, snapped and tolerance-checked
|
|
141
|
+
// in one place so no component quietly disagrees with another.
|
|
142
|
+
const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1
|
|
143
|
+
const want = pixelsFor(cssWidth, dpr)
|
|
144
|
+
if (want <= asked) return
|
|
145
|
+
|
|
146
|
+
asked = want
|
|
147
|
+
state.width = Math.round(cssWidth)
|
|
148
|
+
state.height = Math.round(cssHeight)
|
|
149
|
+
state.src = getLibrary().imageUrl(props.pid, {
|
|
150
|
+
width: want,
|
|
151
|
+
format: props.format,
|
|
152
|
+
...(props.fit === 'contain' ? { fit: 'inside' } : {}),
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function measure() {
|
|
157
|
+
if (!root) return
|
|
158
|
+
|
|
159
|
+
const box = root.getBoundingClientRect()
|
|
160
|
+
const aspect = ratio(props.aspectRatio)
|
|
161
|
+
const w = fixed(props.width) ?? box.width ?? 0
|
|
162
|
+
let h = fixed(props.height) ?? box.height ?? 0
|
|
163
|
+
|
|
164
|
+
// A box with a reserved aspect ratio and no measured height still knows its
|
|
165
|
+
// height. Asking the DOM before layout would report zero.
|
|
166
|
+
if (!h && aspect && w) h = Math.round(w / aspect)
|
|
167
|
+
|
|
168
|
+
if (w > 0) ask(w, h)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function loaded() {
|
|
172
|
+
// A picture that arrived in under a second was almost certainly cached, and
|
|
173
|
+
// fading it in makes a fast load look slow.
|
|
174
|
+
if (Date.now() - startedAt < INSTANT_MS) fade = 0
|
|
175
|
+
|
|
176
|
+
state.pictureStyle = pictureStyle(1)
|
|
177
|
+
// Held until the fade finishes, so nothing shows through a half-transparent
|
|
178
|
+
// image on the way in.
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
state.showStandIn = false
|
|
181
|
+
}, fade)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function failed() {
|
|
185
|
+
// The stand-in stays. A box in the picture's own colour is a better answer
|
|
186
|
+
// than a broken-image glyph, and the layout does not move either way.
|
|
187
|
+
state.src = ''
|
|
188
|
+
state.showStandIn = true
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function pictureStyle(opacity) {
|
|
192
|
+
return [
|
|
193
|
+
'opacity:' + opacity,
|
|
194
|
+
'transition: opacity ' + fade + 'ms ease-in',
|
|
195
|
+
'object-fit:' + (props.fit === 'contain' ? 'contain' : 'cover'),
|
|
196
|
+
props.objectPosition ? 'object-position:' + props.objectPosition : '',
|
|
197
|
+
]
|
|
198
|
+
.filter(Boolean)
|
|
199
|
+
.join(';')
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Everything derived from a prop, in one place so a prop change can redo it.
|
|
204
|
+
*
|
|
205
|
+
* Called on mount and again from `onUpdate`. The reset matters as much as the
|
|
206
|
+
* recompute: `asked` is the largest size requested *for the previous picture*,
|
|
207
|
+
* and leaving it set would make a newly selected image skip its own measure.
|
|
208
|
+
*/
|
|
209
|
+
function configure() {
|
|
210
|
+
startedAt = Date.now()
|
|
211
|
+
showing = signature()
|
|
212
|
+
|
|
213
|
+
asked = 0
|
|
214
|
+
state.src = ''
|
|
215
|
+
state.showStandIn = true
|
|
216
|
+
fade = props.priority ? 0 : FADE_MS
|
|
217
|
+
|
|
218
|
+
const aspect = ratio(props.aspectRatio)
|
|
219
|
+
const w = fixed(props.width)
|
|
220
|
+
const h = fixed(props.height)
|
|
221
|
+
|
|
222
|
+
state.alt = props.alt
|
|
223
|
+
state.loading = props.priority ? 'eager' : 'lazy'
|
|
224
|
+
|
|
225
|
+
// The frame is what holds space. Everything inside it is absolutely
|
|
226
|
+
// positioned, so swapping the stand-in for the picture cannot move the page.
|
|
227
|
+
const frame = []
|
|
228
|
+
const wide = responsive(props.width)
|
|
229
|
+
const tall = responsive(props.height)
|
|
230
|
+
if (wide) frame.push('width:' + wide)
|
|
231
|
+
else if (w !== null) frame.push('width:' + w + 'px')
|
|
232
|
+
if (tall) frame.push('height:' + tall)
|
|
233
|
+
else if (h !== null) frame.push('height:' + h + 'px')
|
|
234
|
+
if (aspect && h === null && !tall) frame.push('aspect-ratio:' + aspect)
|
|
235
|
+
|
|
236
|
+
state.frameStyle = frame.join(';')
|
|
237
|
+
state.standInStyle = 'background:' + props.standIn
|
|
238
|
+
state.pictureStyle = pictureStyle(0)
|
|
239
|
+
state.fallback = getLibrary().imageUrl(props.pid, {
|
|
240
|
+
width: FALLBACK_WIDTH,
|
|
241
|
+
format: props.format,
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
measure()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
onMounted(() => {
|
|
248
|
+
root = refs.frame
|
|
249
|
+
configure()
|
|
250
|
+
|
|
251
|
+
let pending
|
|
252
|
+
const onResize = () => {
|
|
253
|
+
clearTimeout(pending)
|
|
254
|
+
pending = setTimeout(measure, 150)
|
|
255
|
+
}
|
|
256
|
+
window.addEventListener('resize', onResize)
|
|
257
|
+
cleanUp = () => {
|
|
258
|
+
window.removeEventListener('resize', onResize)
|
|
259
|
+
clearTimeout(pending)
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
onUpdate(() => {
|
|
264
|
+
if (!root || signature() === showing) return
|
|
265
|
+
configure()
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
onUnmounted(() => {
|
|
269
|
+
if (cleanUp) cleanUp()
|
|
270
|
+
})
|
|
271
|
+
</logic>
|
|
272
|
+
|
|
273
|
+
<style>
|
|
274
|
+
.responsive-image {
|
|
275
|
+
position: relative;
|
|
276
|
+
overflow: hidden;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.stand-in {
|
|
280
|
+
position: absolute;
|
|
281
|
+
inset: 0;
|
|
282
|
+
z-index: 1;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.picture {
|
|
286
|
+
position: absolute;
|
|
287
|
+
inset: 0;
|
|
288
|
+
z-index: 2;
|
|
289
|
+
width: 100%;
|
|
290
|
+
height: 100%;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* No-JS: nothing measured it, so it is a plain image in a reserved box. */
|
|
294
|
+
.picture.plain {
|
|
295
|
+
opacity: 1;
|
|
296
|
+
}
|
|
297
|
+
</style>
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
<view>
|
|
2
|
+
<div class="sentence">
|
|
3
|
+
<p class="sent">
|
|
4
|
+
<button class="tk" type="button" $class="{ 'is-set': state.set.shape, 'is-open': state.pop === 'shape' }" $aria-expanded="state.pop === 'shape'" @click="toggle('shape')">{{ state.part.shape }}</button>
|
|
5
|
+
pictures of
|
|
6
|
+
<button class="tk" type="button" $class="{ 'is-set': state.set.about, 'is-open': state.pop === 'about' }" $aria-expanded="state.pop === 'about'" @click="toggle('about')">{{ state.part.about }}</button>
|
|
7
|
+
in
|
|
8
|
+
<button class="tk" type="button" $class="{ 'is-set': state.set.group, 'is-open': state.pop === 'group' }" $aria-expanded="state.pop === 'group'" $disabled="!state.hasGroups" @click="toggle('group')">{{ state.part.group }}</button>
|
|
9
|
+
that
|
|
10
|
+
<button class="tk" type="button" $class="{ 'is-set': state.set.condition, 'is-open': state.pop === 'condition' }" $aria-expanded="state.pop === 'condition'" @click="toggle('condition')">{{ state.part.condition }}</button>,
|
|
11
|
+
added
|
|
12
|
+
<button class="tk" type="button" $class="{ 'is-set': state.set.when, 'is-open': state.pop === 'when' }" $aria-expanded="state.pop === 'when'" @click="toggle('when')">{{ state.part.when }}</button>.
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<div class="pop" role="group" $aria-label="state.popLabel" $show="state.pop && state.pop !== 'about'" @keydown="onPopKey">
|
|
16
|
+
<b>{{ state.popLabel }}</b>
|
|
17
|
+
<button class="opt" type="button" $for="one in state.options" $key="one.key" $aria-pressed="one.on" @click="choose(one.value)">{{ one.label }}</button>
|
|
18
|
+
<button class="px-btn px-btn-ghost px-btn-sm done" type="button" @click="close">Done</button>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<form class="pop" role="group" aria-label="Pictures of" $show="state.pop === 'about'" @submit="submitAbout" @keydown="onPopKey">
|
|
22
|
+
<b>Pictures of</b>
|
|
23
|
+
<input class="px-input about" type="text" aria-label="Pictures of" $placeholder="state.aboutHint" $model="state.aboutText" $ref="about" @input="onAbout" />
|
|
24
|
+
<button class="px-btn px-btn-ghost px-btn-sm" type="button" @click="clearAbout">Anything</button>
|
|
25
|
+
<button class="px-btn px-btn-ghost px-btn-sm done" type="submit">Done</button>
|
|
26
|
+
</form>
|
|
27
|
+
|
|
28
|
+
<div class="px-row acts" $show="state.isSet || state.saved.length">
|
|
29
|
+
<button class="px-btn px-btn-ghost px-btn-sm" type="button" $show="state.isSet" @click="clear">Clear</button>
|
|
30
|
+
<button class="px-btn px-btn-secondary px-btn-sm" type="button" $show="state.isSet && !state.isSaved" @click="save">Save this sentence</button>
|
|
31
|
+
<span class="px-chip saved" $for="one in state.saved" $key="one.key" $class="{ 'is-on': one.on }">
|
|
32
|
+
<button class="saved-go" type="button" $title="one.said" $aria-pressed="one.on" @click="use(one)">{{ one.name }}</button>
|
|
33
|
+
<button type="button" $aria-label="'Forget the saved sentence ' + one.name" @click="forget(one)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"></path></svg></button>
|
|
34
|
+
</span>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<span class="sr-only" role="status">{{ state.said }}</span>
|
|
38
|
+
</div>
|
|
39
|
+
</view>
|
|
40
|
+
|
|
41
|
+
<logic lang="ts">
|
|
42
|
+
import { reactive, onMounted, shared, defineRefs } from '@lightspeed-js/core'
|
|
43
|
+
import { SENTENCE, CAPABILITIES } from '../config.ts'
|
|
44
|
+
import { BLANK, SHAPES, CONDITIONS, WHENS, isSet, sameSentence, said, words } from '../sentence.ts'
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The sentence the pictures are read through, each part a button that opens
|
|
48
|
+
* its choices underneath. The same idea as the "When" sentence on an event:
|
|
49
|
+
* the page says what it is showing in words, and the words are the controls.
|
|
50
|
+
*/
|
|
51
|
+
const refs = defineRefs()
|
|
52
|
+
|
|
53
|
+
const SAVED_KEY = 'pseudolux:sentences'
|
|
54
|
+
|
|
55
|
+
const state = reactive({
|
|
56
|
+
part: words(BLANK),
|
|
57
|
+
set: { shape: false, about: false, group: false, condition: false, when: false },
|
|
58
|
+
isSet: false,
|
|
59
|
+
isSaved: false,
|
|
60
|
+
pop: '',
|
|
61
|
+
popLabel: '',
|
|
62
|
+
options: [],
|
|
63
|
+
hasGroups: false,
|
|
64
|
+
aboutText: '',
|
|
65
|
+
aboutHint: 'Words in the name, alt text or labels',
|
|
66
|
+
saved: [],
|
|
67
|
+
said: '',
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const sentence = shared(SENTENCE)
|
|
71
|
+
const capabilities = shared(CAPABILITIES)
|
|
72
|
+
|
|
73
|
+
let groups = []
|
|
74
|
+
let usage = false
|
|
75
|
+
let saved = []
|
|
76
|
+
|
|
77
|
+
const current = () => ({ ...BLANK, ...(sentence.value || {}) })
|
|
78
|
+
|
|
79
|
+
const POP_LABELS = { shape: 'Shape', group: 'In', condition: 'That', when: 'Added' }
|
|
80
|
+
|
|
81
|
+
function optionsFor(part) {
|
|
82
|
+
const now = current()
|
|
83
|
+
if (part === 'shape') return SHAPES.map(([value, label]) => ({ value, label }))
|
|
84
|
+
if (part === 'when') return WHENS.map(([value, label]) => ({ value, label }))
|
|
85
|
+
if (part === 'group') return [{ value: '', label: 'any group' }].concat(groups.map((one) => ({ value: one, label: one })))
|
|
86
|
+
// Whether a picture is used anywhere is only a choice where the listing
|
|
87
|
+
// can answer it.
|
|
88
|
+
return CONDITIONS.filter(([value]) => usage || (value !== 'unused' && value !== 'used') || now.condition === value).map(([value, label]) => ({ value, label }))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function draw() {
|
|
92
|
+
const now = current()
|
|
93
|
+
state.part = words(now)
|
|
94
|
+
state.set = {
|
|
95
|
+
shape: Boolean(now.shape),
|
|
96
|
+
about: Boolean(now.about),
|
|
97
|
+
group: Boolean(now.group),
|
|
98
|
+
condition: Boolean(now.condition),
|
|
99
|
+
when: Boolean(now.when),
|
|
100
|
+
}
|
|
101
|
+
state.isSet = isSet(now)
|
|
102
|
+
state.said = state.isSet ? 'Showing ' + said(now) : ''
|
|
103
|
+
if (state.pop && state.pop !== 'about') {
|
|
104
|
+
state.popLabel = POP_LABELS[state.pop]
|
|
105
|
+
state.options = optionsFor(state.pop).map((one) => ({ ...one, key: state.pop + ':' + one.value, on: now[state.pop] === one.value }))
|
|
106
|
+
}
|
|
107
|
+
if (state.pop !== 'about') state.aboutText = now.about
|
|
108
|
+
state.isSaved = saved.some((one) => sameSentence({ ...BLANK, ...one.sentence }, now))
|
|
109
|
+
state.saved = saved.map((one, index) => ({
|
|
110
|
+
key: index + ':' + one.name,
|
|
111
|
+
index,
|
|
112
|
+
name: one.name,
|
|
113
|
+
said: said({ ...BLANK, ...one.sentence }),
|
|
114
|
+
on: sameSentence({ ...BLANK, ...one.sentence }, now),
|
|
115
|
+
}))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function toggle(part) {
|
|
119
|
+
state.pop = state.pop === part ? '' : part
|
|
120
|
+
draw()
|
|
121
|
+
if (state.pop === 'about') requestAnimationFrame(() => refs.about && refs.about.focus())
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function close() {
|
|
125
|
+
state.pop = ''
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function onPopKey(event) {
|
|
129
|
+
if (event.key !== 'Escape') return
|
|
130
|
+
event.preventDefault()
|
|
131
|
+
close()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function choose(value) {
|
|
135
|
+
sentence.value = { ...current(), [state.pop]: value }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let typing = null
|
|
139
|
+
function onAbout() {
|
|
140
|
+
if (typing) clearTimeout(typing)
|
|
141
|
+
typing = setTimeout(() => {
|
|
142
|
+
typing = null
|
|
143
|
+
sentence.value = { ...current(), about: state.aboutText.trim().toLowerCase() }
|
|
144
|
+
}, 250)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function submitAbout(event) {
|
|
148
|
+
event.preventDefault()
|
|
149
|
+
if (typing) clearTimeout(typing)
|
|
150
|
+
typing = null
|
|
151
|
+
sentence.value = { ...current(), about: state.aboutText.trim().toLowerCase() }
|
|
152
|
+
close()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function clearAbout() {
|
|
156
|
+
state.aboutText = ''
|
|
157
|
+
sentence.value = { ...current(), about: '' }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function clear() {
|
|
161
|
+
state.pop = ''
|
|
162
|
+
sentence.value = { ...BLANK }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// --- sentences kept for next time, in this browser -------------------------------
|
|
166
|
+
|
|
167
|
+
function nameOf(now) {
|
|
168
|
+
const part = words(now)
|
|
169
|
+
return [
|
|
170
|
+
now.shape ? part.shape : '',
|
|
171
|
+
now.about ? part.about : '',
|
|
172
|
+
now.group ? 'in ' + part.group : '',
|
|
173
|
+
now.condition ? 'that ' + part.condition : '',
|
|
174
|
+
now.when ? part.when : '',
|
|
175
|
+
].filter(Boolean).join(' ')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function keep() {
|
|
179
|
+
try {
|
|
180
|
+
localStorage.setItem(SAVED_KEY, JSON.stringify(saved))
|
|
181
|
+
} catch {
|
|
182
|
+
// Kept for this visit only, then.
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function save() {
|
|
187
|
+
const now = current()
|
|
188
|
+
if (!isSet(now) || state.isSaved) return
|
|
189
|
+
saved = saved.concat([{ name: nameOf(now), sentence: now }])
|
|
190
|
+
keep()
|
|
191
|
+
draw()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function use(one) {
|
|
195
|
+
const kept = saved[one.index]
|
|
196
|
+
if (!kept) return
|
|
197
|
+
state.pop = ''
|
|
198
|
+
sentence.value = one.on ? { ...BLANK } : { ...BLANK, ...kept.sentence }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function forget(one) {
|
|
202
|
+
saved = saved.filter((_, index) => index !== one.index)
|
|
203
|
+
keep()
|
|
204
|
+
draw()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
sentence.subscribe(draw)
|
|
208
|
+
|
|
209
|
+
capabilities.subscribe((value) => {
|
|
210
|
+
if (!value) return
|
|
211
|
+
groups = value.groups || []
|
|
212
|
+
usage = Boolean(value.usageFilter)
|
|
213
|
+
state.hasGroups = groups.length > 0
|
|
214
|
+
state.aboutHint = value.text ? 'Words in the name, alt text or labels' : 'Words in the name'
|
|
215
|
+
draw()
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
onMounted(() => {
|
|
219
|
+
try {
|
|
220
|
+
const kept = JSON.parse(localStorage.getItem(SAVED_KEY) || '[]')
|
|
221
|
+
if (Array.isArray(kept)) saved = kept.filter((one) => one && typeof one.name === 'string' && one.sentence)
|
|
222
|
+
} catch {
|
|
223
|
+
// None kept.
|
|
224
|
+
}
|
|
225
|
+
draw()
|
|
226
|
+
})
|
|
227
|
+
</logic>
|
|
228
|
+
|
|
229
|
+
<style>
|
|
230
|
+
.sentence {
|
|
231
|
+
display: flex;
|
|
232
|
+
flex-direction: column;
|
|
233
|
+
gap: 14px;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.sent {
|
|
237
|
+
font-family: var(--px-font-sentence);
|
|
238
|
+
font-size: clamp(20px, 1.4vw + 10px, 28px);
|
|
239
|
+
line-height: 1.6;
|
|
240
|
+
letter-spacing: -.01em;
|
|
241
|
+
max-width: 1100px;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.tk {
|
|
245
|
+
font: inherit;
|
|
246
|
+
border: 0;
|
|
247
|
+
background: transparent;
|
|
248
|
+
color: var(--px-text);
|
|
249
|
+
padding: 0 4px;
|
|
250
|
+
margin: 0 1px;
|
|
251
|
+
border-radius: var(--px-r-m);
|
|
252
|
+
border-bottom: 2px dashed var(--px-border-strong);
|
|
253
|
+
cursor: pointer;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.tk:hover {
|
|
257
|
+
background: var(--px-surface-2);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.tk:disabled {
|
|
261
|
+
border-bottom-color: transparent;
|
|
262
|
+
cursor: default;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.tk:disabled:hover {
|
|
266
|
+
background: transparent;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.tk.is-set {
|
|
270
|
+
color: var(--px-accent-text);
|
|
271
|
+
background: var(--px-accent-soft);
|
|
272
|
+
border-bottom: 2px solid var(--px-accent);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.tk.is-open {
|
|
276
|
+
box-shadow: 0 0 0 3px var(--px-focus);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.pop {
|
|
280
|
+
display: flex;
|
|
281
|
+
flex-wrap: wrap;
|
|
282
|
+
gap: 8px;
|
|
283
|
+
align-items: center;
|
|
284
|
+
padding: 12px 14px;
|
|
285
|
+
border: 1px solid var(--px-border);
|
|
286
|
+
border-radius: var(--px-r-l);
|
|
287
|
+
background: var(--px-surface);
|
|
288
|
+
box-shadow: var(--px-shadow);
|
|
289
|
+
max-width: 1100px;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.pop b {
|
|
293
|
+
font-size: var(--px-fs-s);
|
|
294
|
+
margin-right: 6px;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.opt {
|
|
298
|
+
min-height: 36px;
|
|
299
|
+
padding: 0 14px;
|
|
300
|
+
border-radius: 999px;
|
|
301
|
+
border: 1px solid var(--px-border);
|
|
302
|
+
background: var(--px-surface-2);
|
|
303
|
+
font: inherit;
|
|
304
|
+
font-size: 14px;
|
|
305
|
+
color: var(--px-text);
|
|
306
|
+
cursor: pointer;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.opt[aria-pressed="true"] {
|
|
310
|
+
background: var(--px-text);
|
|
311
|
+
color: var(--px-bg);
|
|
312
|
+
border-color: var(--px-text);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.done {
|
|
316
|
+
margin-left: auto;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.about {
|
|
320
|
+
flex: 1;
|
|
321
|
+
min-width: 200px;
|
|
322
|
+
max-width: 420px;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.acts {
|
|
326
|
+
gap: 8px;
|
|
327
|
+
flex-wrap: wrap;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.saved {
|
|
331
|
+
padding-right: 4px;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.saved.is-on {
|
|
335
|
+
background: var(--px-accent-soft);
|
|
336
|
+
color: var(--px-accent-text);
|
|
337
|
+
border-color: var(--px-accent);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.saved .saved-go {
|
|
341
|
+
width: auto;
|
|
342
|
+
height: auto;
|
|
343
|
+
border-radius: 0;
|
|
344
|
+
display: inline;
|
|
345
|
+
font: inherit;
|
|
346
|
+
color: inherit;
|
|
347
|
+
background: transparent;
|
|
348
|
+
border: 0;
|
|
349
|
+
padding: 0;
|
|
350
|
+
cursor: pointer;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.sr-only {
|
|
354
|
+
position: absolute;
|
|
355
|
+
width: 1px;
|
|
356
|
+
height: 1px;
|
|
357
|
+
overflow: hidden;
|
|
358
|
+
clip-path: inset(50%);
|
|
359
|
+
white-space: nowrap;
|
|
360
|
+
}
|
|
361
|
+
</style>
|