@podoba/react 0.0.61 → 0.0.62
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podoba/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.62",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
|
|
6
6
|
"repository": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"typecheck": "tsc --build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@podoba/tokens": "^0.0.
|
|
36
|
-
"@podoba/tailwind": "^0.0.
|
|
35
|
+
"@podoba/tokens": "^0.0.62",
|
|
36
|
+
"@podoba/tailwind": "^0.0.62",
|
|
37
37
|
"react-aria-components": "1.20.0",
|
|
38
38
|
"class-variance-authority": "0.7.1",
|
|
39
39
|
"clsx": "2.1.1",
|
|
@@ -247,13 +247,16 @@ export function MediaReadableText({
|
|
|
247
247
|
const measure = () => {
|
|
248
248
|
cancelAnimationFrame(frame)
|
|
249
249
|
frame = requestAnimationFrame(async () => {
|
|
250
|
-
const
|
|
251
|
-
|
|
250
|
+
const media = panel.querySelector<HTMLImageElement | HTMLVideoElement>('img, video')
|
|
251
|
+
const isVideo = media instanceof HTMLVideoElement
|
|
252
|
+
const width = isVideo ? media.videoWidth : media?.naturalWidth ?? 0
|
|
253
|
+
const height = isVideo ? media.videoHeight : media?.naturalHeight ?? 0
|
|
254
|
+
if (!media || !width || !height || (isVideo ? media.readyState < 2 : !media.complete)) {
|
|
252
255
|
setPixels([])
|
|
253
256
|
return
|
|
254
257
|
}
|
|
255
258
|
const box = text.getBoundingClientRect(),
|
|
256
|
-
rect =
|
|
259
|
+
rect = media.getBoundingClientRect()
|
|
257
260
|
const bounds = panel.getBoundingClientRect()
|
|
258
261
|
setPanelBox({
|
|
259
262
|
left: bounds.left - box.left,
|
|
@@ -262,16 +265,16 @@ export function MediaReadableText({
|
|
|
262
265
|
height: bounds.height,
|
|
263
266
|
})
|
|
264
267
|
if (!box.width || !box.height || !rect.width || !rect.height) return
|
|
265
|
-
const imageStyle = getComputedStyle(
|
|
268
|
+
const imageStyle = getComputedStyle(media)
|
|
266
269
|
const scale =
|
|
267
270
|
imageStyle.objectFit === 'contain'
|
|
268
|
-
? Math.min(rect.width /
|
|
269
|
-
: Math.max(rect.width /
|
|
271
|
+
? Math.min(rect.width / width, rect.height / height)
|
|
272
|
+
: Math.max(rect.width / width, rect.height / height)
|
|
270
273
|
const position = imageStyle.objectPosition
|
|
271
274
|
.split(' ')
|
|
272
275
|
.map((part) => (part.endsWith('%') ? parseFloat(part) / 100 : 0.5))
|
|
273
|
-
const sx = (
|
|
274
|
-
const sy = (
|
|
276
|
+
const sx = (width - rect.width / scale) * (position[0] ?? 0.5) + (box.left - rect.left) / scale
|
|
277
|
+
const sy = (height - rect.height / scale) * (position[1] ?? 0.5) + (box.top - rect.top) / scale
|
|
275
278
|
const canvas = document.createElement('canvas')
|
|
276
279
|
canvas.width = 32
|
|
277
280
|
canvas.height = 16
|
|
@@ -280,8 +283,8 @@ export function MediaReadableText({
|
|
|
280
283
|
try {
|
|
281
284
|
ctx.fillStyle = getComputedStyle(panel).backgroundColor
|
|
282
285
|
ctx.fillRect(0, 0, 32, 16)
|
|
283
|
-
ctx.globalCompositeOperation =
|
|
284
|
-
const readable = await readableMediaImage(
|
|
286
|
+
ctx.globalCompositeOperation = media.closest('.mix-blend-multiply') ? 'multiply' : 'source-over'
|
|
287
|
+
const readable = isVideo ? media : await readableMediaImage(media)
|
|
285
288
|
if (!text.isConnected) return
|
|
286
289
|
ctx.drawImage(readable, sx, sy, box.width / scale, box.height / scale, 0, 0, 32, 16)
|
|
287
290
|
const data = ctx.getImageData(0, 0, 32, 16).data,
|
|
@@ -305,6 +308,9 @@ export function MediaReadableText({
|
|
|
305
308
|
mutation.observe(panel, { childList: true, subtree: true, attributes: true, attributeFilter: ['src', 'class'] })
|
|
306
309
|
panel.addEventListener('load', measure, true)
|
|
307
310
|
panel.addEventListener('error', measure, true)
|
|
311
|
+
panel.addEventListener('loadeddata', measure, true)
|
|
312
|
+
panel.addEventListener('seeked', measure, true)
|
|
313
|
+
panel.addEventListener('timeupdate', measure, true)
|
|
308
314
|
measure()
|
|
309
315
|
return () => {
|
|
310
316
|
cancelAnimationFrame(frame)
|
|
@@ -312,6 +318,9 @@ export function MediaReadableText({
|
|
|
312
318
|
mutation.disconnect()
|
|
313
319
|
panel.removeEventListener('load', measure, true)
|
|
314
320
|
panel.removeEventListener('error', measure, true)
|
|
321
|
+
panel.removeEventListener('loadeddata', measure, true)
|
|
322
|
+
panel.removeEventListener('seeked', measure, true)
|
|
323
|
+
panel.removeEventListener('timeupdate', measure, true)
|
|
315
324
|
}
|
|
316
325
|
}, [children])
|
|
317
326
|
const resolved = resolveMediaText(pixels, appearance, secondary)
|