Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vtbag/element-crossing

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vtbag/element-crossing - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

lib/vanilla.js

@@ -1,1 +0,1 @@

"use strict";(()=>{var p=!1,l=top.__vtbag?.elementCrossing;d();function d(){if(l?.fun){if(self===top)return;top.document.title=self.document.title,top.history.replaceState(self.history.state,"",self.location.href),self.crossingStorage=l.fun}self.addEventListener("onpageswap"in self?"pageswap":"pagehide",k,{once:!0}),self.addEventListener("onpagereveal"in self?"pagereveal":"DOMContentLoaded",m,{once:!0})}function k(){self.crossingStorage?self.crossingStorage.setItem("@vtbag/element-crossing",u()):top.sessionStorage.setItem("@vtbag/element-crossing",JSON.stringify(u()))}function m(){let s;self.crossingStorage?s=self.crossingStorage.getItem("@vtbag/element-crossing")??[]:s=JSON.parse(top.sessionStorage.getItem("@vtbag/element-crossing")??"[]"),y(s)}function u(){let s=new Set,o=[];return self.document.querySelectorAll("[data-vtbag-x]").forEach(t=>{let e=b(t);e&&(s.has(e.id)&&console.error("[crossing]","non unique id",e.id),o.push(e),s.add(e.id))}),p&&console.log("[crossing]","retrieve",o),o}function b(s){function o(r,a){let[n,i]=r.split(":",2);if(!n)return console.error("[crossing]","syntax error:",r,"is not recognized as a valid specification in",a),["<none>",i];if(i===void 0)switch(i=n.slice(1),n[0]){case"#":n="id";break;case".":n="class";break;case"@":n="prop";break;case"-":n="style";break;case"~":n="anim";break;case"&":if(n="elem",l?.fun)break;default:console.error("[crossing]","syntax error:",r,"is not recognized as a valid specification in",a)}return[n,i]}let t=s.id,e=[];if(s.getAttribute("data-vtbag-x")?.trim().split(/\s+/).forEach(r=>{let[a,n]=o(r,s);switch(a){case"id":t=n;break;case"class":e.push({kind:a,key:n,value:s.classList.contains(n)?"true":"false"});break;case"style":e.push({kind:a,key:n,value:""+(s.style[n]??"")});break;case"bool":case"num":case"prop":let i=s[n],g=typeof i;e.push({kind:g==="boolean"?"bool":g==="number"?"num":"prop",key:n,value:""+i});break;case"anim":let c=s.getAnimations().filter(f=>f instanceof CSSAnimation&&f.animationName===n);c.length>1&&console.error("[crossing]",`retrieval: animation name ${n} is not unique for`,s),c.length>0&&e.push({kind:a,key:n,value:""+(c[0].currentTime??0)});break;case"elem":top?.__vtbag?.elementCrossing?.fun&&(self.crossingStorage.setItem(n,s),e.push({kind:a,key:n}));break;default:console.error("[crossing]","unknown kind",a);break}}),!t)console.error("[crossing]","missing id in",s);else return{id:t,specs:e}}function y(s){p&&console.log("[crossing]","restore",s),s.forEach(o=>{let t=document.querySelector("#"+o.id+",[data-vtbag-x*='#"+o.id+"'],[data-vtbag-x*='id:"+o.id+"']");t&&o.specs.forEach(e=>{switch(e.kind){case"class":t.classList[e.value==="true"?"add":"remove"](e.key);break;case"style":e.key==="length"||e.key==="parentRule"?console.error("[crossing]","Cannot assign to read-only property",e.key,"in",o.id):t.style.setProperty(e.key,e.value??"");break;case"prop":t[e.key]=e.value;break;case"bool":t[e.key]=e.value==="true";break;case"num":t[e.key]=parseFloat(e.value??"0");break;case"anim":let r=t.getAnimations().filter(n=>n instanceof CSSAnimation&&n.animationName===e.key);r.length>1&&console.warn("[crossing]",`restore: animation name ${e.key} is not unique for`,t),r.forEach(n=>n.currentTime=~~(e.value??"0")),t.setAttribute(e.key,e.value??"");break;case"elem":if(top?.__vtbag?.elementCrossing?.fun){let n=self.crossingStorage.getItem(e.key);n&&(t.replaceWith(n),t=n)}break;default:console.error("[crossing]","unknown kind",e.kind);break}})})}})();
"use strict";(()=>{var p=!1,l=top.__vtbag?.elementCrossing;m();function m(){if(l?.fun){if(self===top)return;top.document.title=self.document.title,top.history.replaceState(self.history.state,"",self.location.href),self.crossingStorage=l.fun}self.addEventListener("onpageswap"in self?"pageswap":"pagehide",d,{once:!0}),self.addEventListener("onpagereveal"in self?"pagereveal":"DOMContentLoaded",k,{once:!0})}function d(){self.crossingStorage?self.crossingStorage.setItem("@vtbag/element-crossing",u()):top.sessionStorage.setItem("@vtbag/element-crossing",JSON.stringify(u()))}function k(){if(performance?.navigation?.type===1||"navigation"in self&&self.navigation?.navigationType==="reload")return;let s,t;(t=self.crossingStorage)?s=t.getItem("@vtbag/element-crossing")??[]:(t=top.sessionStorage,s=JSON.parse(t.getItem("@vtbag/element-crossing")??"[]")),b(s)}function u(){let s=new Set,t=[];return self.document.querySelectorAll("[data-vtbag-x]").forEach(a=>{let e=y(a);e&&(s.has(e.id)&&console.error("[crossing]","non unique id",e.id),t.push(e),s.add(e.id))}),p&&console.log("[crossing]","retrieve",t),t}function y(s){function t(i,o){let[n,r]=i.split(":",2);if(!n)return console.error("[crossing]","syntax error:",i,"is not recognized as a valid specification in",o),["<none>",r];if(r===void 0)switch(r=n.slice(1),n[0]){case"#":n="id";break;case".":n="class";break;case"@":n="prop";break;case"-":n="style";break;case"~":n="anim";break;case"&":if(n="elem",l?.fun)break;default:console.error("[crossing]","syntax error:",i,"is not recognized as a valid specification in",o)}return[n,r]}let a=s.id,e=[];if(s.getAttribute("data-vtbag-x")?.trim().split(/\s+/).forEach(i=>{let[o,n]=t(i,s);switch(o){case"id":a=n;break;case"class":e.push({kind:o,key:n,value:s.classList.contains(n)?"true":"false"});break;case"style":e.push({kind:o,key:n,value:""+(s.style[n]??"")});break;case"bool":case"num":case"prop":let r=s[n],g=typeof r;e.push({kind:g==="boolean"?"bool":g==="number"?"num":"prop",key:n,value:""+r});break;case"anim":let c=s.getAnimations().filter(f=>f instanceof CSSAnimation&&f.animationName===n);c.length>1&&console.error("[crossing]",`retrieval: animation name ${n} is not unique for`,s),c.length>0&&e.push({kind:o,key:n,value:""+(c[0].currentTime??0)});break;case"elem":top?.__vtbag?.elementCrossing?.fun&&(self.crossingStorage.setItem(n,s),e.push({kind:o,key:n}));break;default:console.error("[crossing]","unknown kind",o);break}}),!a)console.error("[crossing]","missing id in",s);else return{id:a,timestamp:new Date().getTime(),specs:e}}function b(s){p&&console.log("[crossing]","restore",s),s.forEach(t=>{let a=document.querySelector("#"+t.id+",[data-vtbag-x*='#"+t.id+"'],[data-vtbag-x*='id:"+t.id+"']");a&&t.specs.forEach(e=>{switch(e.kind){case"class":a.classList[e.value==="true"?"add":"remove"](e.key);break;case"style":e.key==="length"||e.key==="parentRule"?console.error("[crossing]","Cannot assign to read-only property",e.key,"in",t.id):a.style.setProperty(e.key,e.value??"");break;case"prop":a[e.key]=e.value;break;case"bool":a[e.key]=e.value==="true";break;case"num":a[e.key]=parseFloat(e.value??"0");break;case"anim":let i=a.getAnimations().filter(n=>n instanceof CSSAnimation&&n.animationName===e.key);i.length>1&&console.warn("[crossing]",`restore: animation name ${e.key} is not unique for`,a),i.forEach(n=>n.currentTime=~~(e.value??"0")+(new Date().getTime()-t.timestamp));break;case"elem":if(top?.__vtbag?.elementCrossing?.fun){let n=self.crossingStorage.getItem(e.key);n&&(a.replaceWith(n),a=n)}break;default:console.error("[crossing]","unknown kind",e.kind);break}})})}})();
{
"name": "@vtbag/element-crossing",
"version": "1.0.0",
"main": "lib/vanilla.js",
"description": "Sites using cross-document view transitions look like SPAs but they still do full page loads on navigation. The element crossing provides a way to preserve DOM elements and data objects across page loads.",
"files": [
"lib/vanilla.js",
"lib/over-the-top.js"
],
"exports": {
".": "./lib/vanilla.js",
"./experimental": "./lib/over-the-top.js"
},
"scripts": {
"dev": "bin/bundle dev",
"build": "npm run format; bin/bundle",
"format": "prettier --write src | grep -v 'unchanged)$'",
"test": "bin/test",
"changeset": "changeset",
"release": "changeset publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vtbag/element-crossing.git"
},
"keywords": [
"view",
"transitions",
"view transition",
"view-transition",
"preserve",
"state",
"cross-document",
"DOM"
],
"author": "vtbag",
"license": "ISC",
"bugs": {
"url": "https://github.com/vtbag/element-crossing/issues"
},
"homepage": "https://vtbag.pages.dev",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/martrapp"
},
"devDependencies": {
"@changesets/cli": "^2.27.8",
"@eslint/js": "^9.9.1",
"@types/dom-view-transitions": "^1.0.5",
"esbuild": "^0.23.1",
"prettier": "^3.3.3",
"typescript": "^5.5.4"
}
"name": "@vtbag/element-crossing",
"version": "1.0.1",
"main": "lib/vanilla.js",
"description": "Sites using cross-document view transitions do full page loads of static content on navigation. The element crossing provides a way to preserve current dynamic state of selected elements across cross-document view transitions for a smoother user experience.",
"files": [
"lib/vanilla.js",
"lib/over-the-top.js"
],
"exports": {
".": "./lib/vanilla.js",
"./experimental": "./lib/over-the-top.js"
},
"scripts": {
"dev": "bin/bundle dev",
"build": "npm run format; bin/bundle",
"format": "prettier --write src | grep -v 'unchanged)$'",
"test": "bin/test",
"changeset": "changeset",
"release": "changeset publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vtbag/element-crossing.git"
},
"keywords": [
"view",
"transitions",
"view transition",
"view-transition",
"preserve",
"state",
"cross-document",
"DOM"
],
"author": "vtbag",
"license": "ISC",
"bugs": {
"url": "https://github.com/vtbag/element-crossing/issues"
},
"homepage": "https://vtbag.pages.dev",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/martrapp"
},
"devDependencies": {
"@changesets/cli": "^2.27.8",
"@eslint/js": "^9.9.1",
"@types/dom-view-transitions": "^1.0.5",
"esbuild": "^0.23.1",
"prettier": "^3.3.3",
"typescript": "^5.5.4"
}
}

@@ -0,6 +1,8 @@

[⭐️Please star to support this work⭐️](https://github.com/vtbag/element-crossing)
# 🚸 ElementCrossing
Transfer selected element states across cross-document view transitions.
Transfer selected element state across cross-document view transitions.
![Build Status](https://github.com/vtbag/element-crossing/actions/workflows/run-tests.yml/badge.svg)
![Build Status](https://github.com/vtbag/element-crossing/actions/workflows/run-build.yml/badge.svg)
[![npm version](https://img.shields.io/npm/v/@vtbag/element-crossing/latest)](https://www.npmjs.com/package/@vtbag/element-crossing)

@@ -7,0 +9,0 @@ [![NPM Downloads](https://img.shields.io/npm/dw/@vtbag/element-crossing)](https://www.npmjs.com/package/@vtbag/element-crossing)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc