diff --git a/src/components/ReloadOnThemeChange.astro b/src/components/ReloadOnThemeChange.astro index dc3f7d9..6101fac 100644 --- a/src/components/ReloadOnThemeChange.astro +++ b/src/components/ReloadOnThemeChange.astro @@ -3,6 +3,5 @@ --- \ No newline at end of file diff --git a/src/components/SidePicture.astro b/src/components/SidePicture.astro index 9906ae0..59a05d3 100644 --- a/src/components/SidePicture.astro +++ b/src/components/SidePicture.astro @@ -1,5 +1,10 @@ --- +export interface Props { + float: string; +} +const { float = "left" } = Astro.props; --- +
- -
\ No newline at end of file + + diff --git a/src/components/ToolsBar.astro b/src/components/ToolsBar.astro index 5d428d0..1ea73e0 100644 --- a/src/components/ToolsBar.astro +++ b/src/components/ToolsBar.astro @@ -7,7 +7,7 @@ + +
+
DOM
+
+
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
Stencil
+
Button
+
+
+
+ +These are the main ingredients of the stencil's styling: + +```css +#stencil { + view-transition-name: stencil; + pointer-events: none; + mask-image: url('data:image/svg+xml;utf8,'); + mask-mode: luminance; + ... +} +``` +The mask image used is a white SVG with a black rectangle embedded in it. Thanks to the luminance mask mode, the mask becomes transparent where the black rectangle appears. In this example, the coordinates for the mask are static, but they could be dynamically calculated using the bounding client rectangle of the list for more flexibility. +The overall effect is that the list items appear to float behind the scrollbar. -### Improved Scrollable List +## List Example Revisited -And this is [what I got so far](/basics/hide-and-seek/solution/) -as a solution. +Using the stencil approach on the original list examples now yields a [much better result](/basics/hide-and-seek/solution/). diff --git a/src/content/docs/basics/pseudos.mdx b/src/content/docs/basics/pseudos.mdx index 1b463f6..873c05a 100644 --- a/src/content/docs/basics/pseudos.mdx +++ b/src/content/docs/basics/pseudos.mdx @@ -50,7 +50,7 @@ Think of it like a theater: A curtain drops, painted with the last scene, while background-color: #000; } - div.small { + .container div.small { width: auto; height: auto; background-color: rgba(255, 128, 0, 0.1); @@ -237,10 +237,7 @@ With the one to one relation between groups and image pairs, the group looks a b ## Creation of Pseudo-Elements -The `::view-transition-old` pseudo elements are created in a pre-order depth first traversal of the old DOM. When an element with a `view-transition-name` is encountered, its old image is captured. During this process, other elements with view transition names are effectively ignored, as if their `visibility` were set to `hidden`. This ensures that the images have "holes" where other images can be properly placed. - -The ::view-transition-old pseudo-elements are created during a pre-order depth-first traversal of the old DOM. When an element with a view-transition-name is encountered, its old image is rendered. During this process, other elements with view transition names are effectively ignored, as if their visibility were set to hidden. This ensures that the images have "holes" where other images can be properly placed. - +The `::view-transition-old` pseudo elements are created **in the paint-order** of the elements of the old DOM. When an element with a `view-transition-name` is encountered, its old image is captured. During this process, other elements with view transition names are effectively ignored, as if their `visibility` were set to `hidden`. This ensures that the images have "holes" where other images can be properly placed. The image of the `:root` element, if not [opted out](#opt-out), covers the whole viewport. Its view transition group is the first in the list of `::view-transition-group` children of the `::view-transition` pseudo-element. Subsequent groups are added after the root group once their old images have been created. diff --git a/src/pages/basics/hide-and-seek/_solution_styles.css b/src/pages/basics/hide-and-seek/_solution_styles.css index bbc07b4..9e35b92 100644 --- a/src/pages/basics/hide-and-seek/_solution_styles.css +++ b/src/pages/basics/hide-and-seek/_solution_styles.css @@ -18,6 +18,7 @@ } ::view-transition-new(*) { animation: none; + transform: scale(1.01) } :root { --neon-pink: #ff2e88; diff --git a/src/pages/basics/hide-and-seek/cutter.ts b/src/pages/basics/hide-and-seek/cutter.ts new file mode 100644 index 0000000..af8e502 --- /dev/null +++ b/src/pages/basics/hide-and-seek/cutter.ts @@ -0,0 +1,38 @@ + +export function cutSVG(element: Element, cutters:{element:HTMLElement,inset: string}[]) { + if (!element) return; + const masks = ['']; + const outerRect = element.getBoundingClientRect(); + cutters.forEach((cutter) => { + const inner = cutter.element; + const insets = cutter.inset.split(" ").map(parseFloat); + for (let i = 0; i < 4; i++) { + const len = insets.length; + insets[i] = isNaN(insets[i] ?? 0) + ? 0 + : (insets[len === 3 && i === 3 ? 2 : i % len] ?? 0); + } + const innerRect = inner.getBoundingClientRect(); + const innerStyle = getComputedStyle(inner); + + const left = parseFloat(innerStyle.borderLeftWidth); + innerRect.width -= + left + + parseFloat(innerStyle.borderRightWidth) + + insets[1]! + + insets[3]!; + innerRect.x += left + insets[3]!; + const top = parseFloat(innerStyle.borderTopWidth); + innerRect.height -= + top + + parseFloat(innerStyle.borderBottomWidth) + + insets[0]! + + insets[2]!; + innerRect.y += top + insets[0]!; + masks.push( + `` + ); + }); + const svg = `${masks.join("")}`; + return svg; +} diff --git a/src/pages/basics/hide-and-seek/list-flat.astro b/src/pages/basics/hide-and-seek/list-flat.astro new file mode 100644 index 0000000..237bbfb --- /dev/null +++ b/src/pages/basics/hide-and-seek/list-flat.astro @@ -0,0 +1,104 @@ +--- +import LightDark from "@/components/LightDark.astro"; +// demonstrate hiding with other images +--- + + + + + + Document + + +
    +
  • Item 1
  • +
  • Item 2
  • +
  • Item 3
  • +
  • Item 4
  • +
  • Item 5
  • +
  • Item 6
  • +
  • Item 7
  • +
+ + + + + diff --git a/src/pages/basics/hide-and-seek/list-names.astro b/src/pages/basics/hide-and-seek/list-names.astro new file mode 100644 index 0000000..57be164 --- /dev/null +++ b/src/pages/basics/hide-and-seek/list-names.astro @@ -0,0 +1,112 @@ +--- +import LightDark from "@/components/LightDark.astro"; +// demonstrate list rotation with a reduced set of named elements +--- + + + + + + Document + + +
+
    +
  • Item 1
  • +
  • Item 2
  • +
  • Item 3
  • +
  • Item 4
  • +
  • Item 5
  • +
  • Item 6
  • +
  • Item 7
  • +
+ +
+ + + + diff --git a/src/pages/basics/hide-and-seek/list-stencil1.astro b/src/pages/basics/hide-and-seek/list-stencil1.astro new file mode 100644 index 0000000..4e5185b --- /dev/null +++ b/src/pages/basics/hide-and-seek/list-stencil1.astro @@ -0,0 +1,121 @@ +--- +import LightDark from "@/components/LightDark.astro"; +// demonstrate hiding with other images +--- + + + + + + Document + + +
+
+
+ +
+
    +
  • Item 1
  • +
  • Item 2
  • +
  • Item 3
  • +
  • Item 4
  • +
  • Item 5
  • +
  • Item 6
  • +
  • Item 7
  • +
  • Item 8
  • +
+ + + + + diff --git a/src/pages/basics/hide-and-seek/list-stencil2.astro b/src/pages/basics/hide-and-seek/list-stencil2.astro new file mode 100644 index 0000000..6d600c0 --- /dev/null +++ b/src/pages/basics/hide-and-seek/list-stencil2.astro @@ -0,0 +1,113 @@ +--- +import LightDark from "@/components/LightDark.astro"; +// demonstrate hiding with other images +--- + + + + + + Document + + +
    +
  • Item 1
  • +
  • Item 2
  • +
  • Item 3
  • +
  • Item 4
  • +
  • Item 5
  • +
  • Item 6
  • +
  • Item 7
  • +
+
+
+
+ +
+ + + + diff --git a/src/pages/basics/hide-and-seek/list.astro b/src/pages/basics/hide-and-seek/list.astro new file mode 100644 index 0000000..ca7ba34 --- /dev/null +++ b/src/pages/basics/hide-and-seek/list.astro @@ -0,0 +1,166 @@ +--- +import LightDark from "@/components/LightDark.astro"; +// demonstrate hiding with other images +--- + + + + + + Document + + +
+
    +
  • Item 1
  • +
  • Item 2
  • +
  • Item 3
  • +
  • Item 4
  • +
  • Item 5
  • +
  • Item 6
  • +
  • Item 7
  • +
+
+
    +
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • 1
  • +
+ +
+
+ + + + diff --git a/src/pages/basics/hide-and-seek/solution.astro b/src/pages/basics/hide-and-seek/solution.astro index 31bf0ec..8427c46 100644 --- a/src/pages/basics/hide-and-seek/solution.astro +++ b/src/pages/basics/hide-and-seek/solution.astro @@ -127,10 +127,10 @@ import Bsky from "../../../components/Bsky.astro";

    - Ok, not it works nicely! This is demo is rather elaborated solution. + Ok, now it works nicely! This is demo is rather elaborated solution. Keep in mind that view transitions were introduced to make things simple. This wasn't. Give us nested transition groups, please! ;-)
    [[Back to the Hide and Seek page]