From 91344ea6de3716654be62a65c5c4ce7928679c6e Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Thu, 5 Sep 2024 11:29:02 +0200 Subject: [PATCH] prepare for 1.0.0 --- README.md | 19 +++- package.json | 3 +- src/over-the-top.ts | 139 +++++++++------------------ src/types.ts | 17 +++- src/vanilla.ts | 222 +++++++++++++++++++++++++++++--------------- 5 files changed, 225 insertions(+), 175 deletions(-) diff --git a/README.md b/README.md index 4e2c274..abbb304 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # 🚸 ElementCrossing + Transfer selected element states across cross-document view transitions. ![Build Status](https://github.com/vtbag/element-crossing/actions/workflows/run-tests.yml/badge.svg) @@ -13,4 +14,20 @@ First official release of this code! ## What is it? -This library provides a robust solution for maintaining HTML elements and their associated state across cross-document view transitions. +Boost the smoothness of your cross-document view transitions with the Element Crossing library! No more resetting to static states! This library preserves the current dynamic state of your DOM and CSS properties, ensuring a seamless user experience. + +With Element Crossing, you can automatically retain: + +- Current form inputs +- Current scrollbar positions +- Current state of active CSS animations +- Current media playback time +- Current toggle states +- Current values of dynamically added classes and CSS properties +- ...and (current) anything else you'd like to carry over from the previous page to the new one! + +Simply annotate your elements in the HTML source or DOM, and let the library handle the rest. Keep your users engaged by preserving the exact state they left off, making transitions across documents smoother than ever! + +Address any CSS property or DOM element property, any CSS class, or CSS animation. + +[View configuration examples](https://vtbag.pages.dev/tools/element-crossing/#applications-with-real-world-examples) and [see the Element Crossing in action](https://vtbag.pages.dev/crossing/vanilla/1/) \ No newline at end of file diff --git a/package.json b/package.json index 2a7304a..41e9a38 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,7 @@ ], "exports": { ".": "./lib/vanilla.js", - "./vanilla": "./lib/vanilla.js", - "./over-the-top": "./lib/over-the-top.js" + "./experimental": "./lib/over-the-top.js" }, "scripts": { "dev": "bin/bundle dev", diff --git a/src/over-the-top.ts b/src/over-the-top.ts index 6501560..fd6c5cd 100644 --- a/src/over-the-top.ts +++ b/src/over-the-top.ts @@ -1,103 +1,54 @@ -import { Spec } from './types'; - top!.__vtbag ??= {}; -top!.__vtbag.elementCrossing ??= {}; -const elementCrossing = top!.__vtbag.elementCrossing!; -console.log('[elc]', 'init'); -if (top === self) { - initBorderLands(); -} else if (self.parent === top) { - initHeartLand(); -} else { - console.log('[elc]', 'neither BorderLands nor HeartLand'); -} +const crossing = (top!.__vtbag.elementCrossing ??= { + storageMap: new Map(), + addrWeakMap: new WeakMap(), + fun: { + pseudoAddress(object: object): string { + let addr = '0x000000'; + if (object === null || object === undefined) return addr; + while (addr === '0x000000') { + addr = + crossing.addrWeakMap.get(object) ?? + '0x' + Math.random().toString(16).slice(2, 8).toUpperCase(); + } + crossing.addrWeakMap.set(object, addr); + return addr; + }, + setItem(id: string, element: Element) { + crossing.storageMap!.set(id, element); + }, + getItem(id: string): Element | undefined { + const element = crossing.storageMap!.get(id); + return element; + }, + removeItem(id: string): void { + crossing.storageMap!.delete(id); + }, + clear(): void { + crossing.storageMap!.clear(); + }, + }, +}); + +top === self && initBorderLands(); function initBorderLands() { - console.log('[elc]', 'init BorderLands'); - addEventListener('pagereveal', () => { - console.log('[elc]', 'DOMContentLoaded'); + top!.addEventListener('pagereveal', () => { const topDoc = top!.document; - const root = topDoc.documentElement; - root.innerHTML = `