Skip to content

Commit

Permalink
Adds .d.ts declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Oct 6, 2024
1 parent 6f47d3e commit 2ccb6db
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-jobs-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vtbag/element-crossing': patch
---

Adds .d.ts declarations
2 changes: 2 additions & 0 deletions bin/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ else
(cd lib && rm *.js.map) >> /dev/null 2>&1
fi
npx esbuild src/vanilla.ts src/over-the-top.ts --bundle $OPTS --target=ESnext --outdir=lib

tsc
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "@vtbag/element-crossing",
"type": "module",
"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"
"lib/vanilla.d.ts",
"lib/over-the-top.js",
"lib/over-the-top.d.ts"
],
"exports": {
".": "./lib/vanilla.js",
Expand Down
21 changes: 10 additions & 11 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ function pageSwap() {
}
}



function pageReveal() {
let values;
let storage;
Expand All @@ -51,8 +49,9 @@ function pageReveal() {
self.crossingStorage?.removeItem('@vtbag/element-crossing');
if (
performance?.navigation?.type !== 1 &&
'navigation' in self &&
// @ts-expect-error
('navigation' in self && self.navigation?.navigationType !== 'reload')
self.navigation?.navigationType !== 'reload'
) {
restore(values);
}
Expand Down Expand Up @@ -189,12 +188,12 @@ function restore(values: ElementSpec[]) {
values.forEach((elementSpec: ElementSpec) => {
let element = document.querySelector<HTMLElement>(
'#' +
elementSpec.id +
",[data-vtbag-x*='#" +
elementSpec.id +
"'],[data-vtbag-x*='id:" +
elementSpec.id +
"']"
elementSpec.id +
",[data-vtbag-x*='#" +
elementSpec.id +
"'],[data-vtbag-x*='id:" +
elementSpec.id +
"']"
);
if (element) {
elementSpec.specs.forEach((s) => {
Expand Down Expand Up @@ -237,8 +236,8 @@ function restore(values: ElementSpec[]) {
}
animations.forEach(
(a) =>
(a.currentTime =
~~(s.value ?? '0') + (new Date().getTime() - elementSpec.timestamp))
(a.currentTime =
~~(s.value ?? '0') + (new Date().getTime() - elementSpec.timestamp))
);
break;
case 'elem':
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */

/* Emit */
//"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
"emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
Expand All @@ -71,7 +71,7 @@
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
"declarationDir": "./lib", /* Specify the output directory for generated declaration files. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down

0 comments on commit 2ccb6db

Please sign in to comment.