@newtone-dev/ui-react-web 0.15.1 → 0.16.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.
|
@@ -83,3 +83,72 @@
|
|
|
83
83
|
object-fit: cover;
|
|
84
84
|
border-radius: inherit;
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
/* ---- fit, an area that is not a ratio, and an overlay: from 0.16.0, 2026-09-29 ----------------
|
|
88
|
+
*
|
|
89
|
+
* "we have a designated area, and we can either fit or fill" -- Joshua, on a deck whose contained
|
|
90
|
+
* pictures had their corner on the empty `<img>` box rather than on the picture. components/media-window.md,
|
|
91
|
+
* *Fit, and an area that is not a ratio*.
|
|
92
|
+
*
|
|
93
|
+
* THE TWO RULES ABOVE ARE NOT EDITED. These three wrap the window only when `fit`, `overlay` or an
|
|
94
|
+
* absent `ratio` asks for them, so every writer before 0.16.0 renders the one span it always did.
|
|
95
|
+
*
|
|
96
|
+
* AREA: the designated space. The parent's full size, or the given ratio at the parent's width. A size
|
|
97
|
+
* container, so the frame can be capped by it in `cqw` and `cqh`. */
|
|
98
|
+
.newtone-media-window-area {
|
|
99
|
+
display: grid;
|
|
100
|
+
place-items: center;
|
|
101
|
+
container-type: size;
|
|
102
|
+
inline-size: 100%;
|
|
103
|
+
block-size: 100%;
|
|
104
|
+
min-inline-size: 0;
|
|
105
|
+
min-block-size: 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.newtone-media-window-area[data-ratio] {
|
|
109
|
+
block-size: auto;
|
|
110
|
+
aspect-ratio: var(--newtone-media-window-area-ratio);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* FRAME: the picture's box, and the containing block of whatever `overlay` draws on it. Filling the area
|
|
114
|
+
* is fill, and it is also fit before the picture has been measured. */
|
|
115
|
+
.newtone-media-window-frame {
|
|
116
|
+
position: relative;
|
|
117
|
+
display: block;
|
|
118
|
+
inline-size: 100%;
|
|
119
|
+
block-size: 100%;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* FIT, MEASURED: the picture's own proportions, as large as the area allows. The width is the smaller of
|
|
123
|
+
* the area's width and the width the area's height gives at this shape; the height follows. So the window
|
|
124
|
+
* is exactly the picture -- nothing letterboxed, nothing cropped, and the corner is the picture's corner. */
|
|
125
|
+
.newtone-media-window-frame[data-fit='measured'] {
|
|
126
|
+
inline-size: min(100cqw, 100cqh * var(--newtone-media-window-shape));
|
|
127
|
+
block-size: auto;
|
|
128
|
+
aspect-ratio: var(--newtone-media-window-shape);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* The window inside a frame is the frame's size. `aspect-ratio: auto` is deliberate: an ancestor's
|
|
132
|
+
* `--newtone-media-window-ratio` would otherwise reach this window through inheritance and reshape it. */
|
|
133
|
+
.newtone-media-window-frame > .newtone-media-window {
|
|
134
|
+
inline-size: 100%;
|
|
135
|
+
block-size: 100%;
|
|
136
|
+
aspect-ratio: auto;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* FIT, PENDING: until the picture has loaded, contain it, so it is never stretched on the way in. */
|
|
140
|
+
.newtone-media-window-frame[data-fit='pending'] > .newtone-media-window > * {
|
|
141
|
+
object-fit: contain;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* OVERLAY: the picture's box, above it, outside the clip. It takes no pointer events itself, so the
|
|
145
|
+
* picture under it is still the picture; what is drawn in it takes them back. */
|
|
146
|
+
.newtone-media-window-overlay {
|
|
147
|
+
position: absolute;
|
|
148
|
+
inset: 0;
|
|
149
|
+
pointer-events: none;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.newtone-media-window-overlay > * {
|
|
153
|
+
pointer-events: auto;
|
|
154
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* The opening a picture is shown through. See the repo blueprint, section 3, and
|
|
4
4
|
* components/media-window.md there.
|
|
@@ -10,6 +10,10 @@ import type { HTMLAttributes, ReactNode } from 'react';
|
|
|
10
10
|
* named -- so the one setting became a prop, and a prop needs a component to sit on. Issue 201.
|
|
11
11
|
*
|
|
12
12
|
* **What the old argument still wins is the second setting.** There is no `side`: nothing has asked.
|
|
13
|
+
* **The second setting that WAS asked for is `fit`, from 0.16.0** (2026-09-29): "we have a designated
|
|
14
|
+
* area, and we can either fit or fill". A page that drew its own contained pictures put the corner on
|
|
15
|
+
* the `<img>` box, which was the whole cell, so the picture kept square corners. Here the window takes
|
|
16
|
+
* the picture's own shape, so the corner cannot land anywhere but on the picture.
|
|
13
17
|
*
|
|
14
18
|
* The library's own writers, `FeatureCard` and `Gallery`, keep wearing the class and setting their
|
|
15
19
|
* ratios in their own sheets. That is the library writing its own plumbing, and `Gallery`'s ratio
|
|
@@ -17,12 +21,25 @@ import type { HTMLAttributes, ReactNode } from 'react';
|
|
|
17
21
|
*/
|
|
18
22
|
export interface MediaWindowProps extends HTMLAttributes<HTMLSpanElement> {
|
|
19
23
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
24
|
+
* The AREA's shape: any CSS `aspect-ratio` value -- `"16 / 9"`, `"1"`, or a site's own `var()`.
|
|
25
|
+
* **A given ratio has no fallback**, for the reason media-window.css gives: an unresolved ratio
|
|
22
26
|
* shrink-wraps, which is visibly broken, where a default would look placed and be wrong.
|
|
27
|
+
* **Absent, from 0.16.0, the parent is the area** and the window fills it -- a different request,
|
|
28
|
+
* not a fallback.
|
|
23
29
|
*/
|
|
24
|
-
ratio
|
|
30
|
+
ratio?: string;
|
|
31
|
+
/**
|
|
32
|
+
* `false` (the default) is FILL: the picture covers the area and is cropped, as every window did
|
|
33
|
+
* before 0.16.0. `true` is FIT: the window takes the picture's own shape, as large as the area
|
|
34
|
+
* allows, centred in it -- nothing cropped, nothing letterboxed, the corner on the picture.
|
|
35
|
+
*/
|
|
36
|
+
fit?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* What is drawn ON the picture and outside the window's clip: a disc and its tooltip, whose bubble
|
|
39
|
+
* is absolutely positioned and would be cut by `overflow: hidden`. It lies over the picture's box.
|
|
40
|
+
*/
|
|
41
|
+
overlay?: ReactNode;
|
|
25
42
|
children?: ReactNode;
|
|
26
43
|
}
|
|
27
|
-
export declare function MediaWindow({ ratio, className, style, children, ...rest }: MediaWindowProps): import("react").JSX.Element;
|
|
44
|
+
export declare function MediaWindow({ ratio, fit, overlay, className, style, children, ...rest }: MediaWindowProps): import("react").JSX.Element;
|
|
28
45
|
//# sourceMappingURL=media-window.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-window.d.ts","sourceRoot":"","sources":["../../src/media-window/media-window.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"media-window.d.ts","sourceRoot":"","sources":["../../src/media-window/media-window.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmD,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAE5G;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,gBAAiB,SAAQ,cAAc,CAAC,eAAe,CAAC;IACrE;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACvB;AAED,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,GAAW,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,gBAAgB,+BAuDjH"}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
export function MediaWindow({ ratio, fit = false, overlay, className, style, children, ...rest }) {
|
|
4
|
+
const windowRef = useRef(null);
|
|
5
|
+
const [shape, setShape] = useState(null);
|
|
6
|
+
// THE ONE MEASUREMENT FIT NEEDS: the picture's natural proportions. Read at once if the image is
|
|
7
|
+
// already `complete`, else on `load`; a lazy image is neither until it scrolls near, and the frame
|
|
8
|
+
// fills the area with the picture contained until then, so it never stretches -- it settles once.
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!fit)
|
|
11
|
+
return;
|
|
12
|
+
const img = windowRef.current?.querySelector('img');
|
|
13
|
+
if (!img)
|
|
14
|
+
return;
|
|
15
|
+
const read = () => {
|
|
16
|
+
if (img.naturalWidth > 0 && img.naturalHeight > 0)
|
|
17
|
+
setShape(img.naturalWidth / img.naturalHeight);
|
|
18
|
+
};
|
|
19
|
+
read();
|
|
20
|
+
img.addEventListener('load', read);
|
|
21
|
+
return () => img.removeEventListener('load', read);
|
|
22
|
+
}, [fit, children]);
|
|
23
|
+
// A GIVEN RATIO, FILL, NOTHING ON TOP: the one-span window it has always been, same markup, same
|
|
24
|
+
// inline property. Every writer before 0.16.0 is this branch.
|
|
25
|
+
if (ratio !== undefined && !fit && overlay == null) {
|
|
26
|
+
return (_jsx("span", { className: ['newtone-media-window', className].filter(Boolean).join(' '), style: { '--newtone-media-window-ratio': ratio, ...style }, ...rest, children: children }));
|
|
27
|
+
}
|
|
28
|
+
const measured = fit && shape !== null;
|
|
29
|
+
return (_jsx("span", { className: ['newtone-media-window-area', className].filter(Boolean).join(' '), "data-ratio": ratio === undefined ? undefined : '', style: (ratio === undefined ? style : { '--newtone-media-window-area-ratio': ratio, ...style }), ...rest, children: _jsxs("span", { className: "newtone-media-window-frame", "data-fit": fit ? (measured ? 'measured' : 'pending') : undefined, style: measured ? { '--newtone-media-window-shape': shape } : undefined, children: [_jsx("span", { ref: windowRef, className: "newtone-media-window", children: children }), overlay == null ? null : _jsx("span", { className: "newtone-media-window-overlay", children: overlay })] }) }));
|
|
4
30
|
}
|
|
5
31
|
//# sourceMappingURL=media-window.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-window.js","sourceRoot":"","sources":["../../src/media-window/media-window.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"media-window.js","sourceRoot":"","sources":["../../src/media-window/media-window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAA2D,MAAM,OAAO,CAAA;AA6C5G,MAAM,UAAU,WAAW,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAoB;IAC9G,MAAM,SAAS,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAA;IAC/C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAA;IAEvD,iGAAiG;IACjG,mGAAmG;IACnG,kGAAkG;IAClG,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,CAAC,GAAG;YAAE,OAAM;QAChB,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;QACnD,IAAI,CAAC,GAAG;YAAE,OAAM;QAChB,MAAM,IAAI,GAAG,GAAG,EAAE;YACd,IAAI,GAAG,CAAC,YAAY,GAAG,CAAC,IAAI,GAAG,CAAC,aAAa,GAAG,CAAC;gBAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,aAAa,CAAC,CAAA;QACrG,CAAC,CAAA;QACD,IAAI,EAAE,CAAA;QACN,GAAG,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,MAAM,EAAE,I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