@domql/router 2.3.50 → 2.3.60

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.
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var router_exports = {};
20
+ __export(router_exports, {
21
+ getActiveRoute: () => getActiveRoute,
22
+ lastLevel: () => lastLevel,
23
+ router: () => router
24
+ });
25
+ module.exports = __toCommonJS(router_exports);
26
+ var import_globals = require("@domql/globals");
27
+ var import_utils = require("@domql/utils");
28
+ const getActiveRoute = (route = import_globals.window.location.pathname, level) => `/${route.split("/")[level + 1]}`;
29
+ let lastLevel = 0;
30
+ const defaultOptions = {
31
+ level: lastLevel,
32
+ pushState: true,
33
+ scrollToTop: true,
34
+ scrollToNode: false,
35
+ useFragment: false,
36
+ updateState: true
37
+ };
38
+ const router = (element, path, state = {}, options = defaultOptions) => {
39
+ (0, import_utils.merge)(options, defaultOptions);
40
+ lastLevel = options.lastLevel;
41
+ const [pathname, hash] = path.split("#");
42
+ const route = getActiveRoute(pathname, options.level);
43
+ const content = element.routes[route] || element.routes["/*"];
44
+ if (content) {
45
+ if (options.pushState)
46
+ import_globals.window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ""));
47
+ element.set({ tag: options.useFragment && "fragment", extend: content });
48
+ if (options.updateState)
49
+ element.state.update({ route, hash });
50
+ const rootNode = element.node;
51
+ if (options.scrollToTop)
52
+ rootNode.scrollTo({ behavior: "smooth", top: 0, left: 0 });
53
+ if (options.scrollToNode)
54
+ content.content.node.scrollTo({ behavior: "smooth", top: 0, left: 0 });
55
+ if (hash) {
56
+ const activeNode = document.getElementById(hash);
57
+ if (activeNode) {
58
+ const top = activeNode.getBoundingClientRect().top + rootNode.scrollToTopp - 140;
59
+ rootNode.scrollTo({ behavior: "smooth", top, left: 0 });
60
+ }
61
+ }
62
+ }
63
+ };
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "commonjs",
3
+ "main": "index.js"
4
+ }
@@ -0,0 +1,43 @@
1
+ import { window } from "@domql/globals";
2
+ import { merge } from "@domql/utils";
3
+ const getActiveRoute = (route = window.location.pathname, level) => `/${route.split("/")[level + 1]}`;
4
+ let lastLevel = 0;
5
+ const defaultOptions = {
6
+ level: lastLevel,
7
+ pushState: true,
8
+ scrollToTop: true,
9
+ scrollToNode: false,
10
+ useFragment: false,
11
+ updateState: true
12
+ };
13
+ const router = (element, path, state = {}, options = defaultOptions) => {
14
+ merge(options, defaultOptions);
15
+ lastLevel = options.lastLevel;
16
+ const [pathname, hash] = path.split("#");
17
+ const route = getActiveRoute(pathname, options.level);
18
+ const content = element.routes[route] || element.routes["/*"];
19
+ if (content) {
20
+ if (options.pushState)
21
+ window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ""));
22
+ element.set({ tag: options.useFragment && "fragment", extend: content });
23
+ if (options.updateState)
24
+ element.state.update({ route, hash });
25
+ const rootNode = element.node;
26
+ if (options.scrollToTop)
27
+ rootNode.scrollTo({ behavior: "smooth", top: 0, left: 0 });
28
+ if (options.scrollToNode)
29
+ content.content.node.scrollTo({ behavior: "smooth", top: 0, left: 0 });
30
+ if (hash) {
31
+ const activeNode = document.getElementById(hash);
32
+ if (activeNode) {
33
+ const top = activeNode.getBoundingClientRect().top + rootNode.scrollToTopp - 140;
34
+ rootNode.scrollTo({ behavior: "smooth", top, left: 0 });
35
+ }
36
+ }
37
+ }
38
+ };
39
+ export {
40
+ getActiveRoute,
41
+ lastLevel,
42
+ router
43
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ (() => {
3
+ var import_globals = require("@domql/globals");
4
+ var import_utils = require("@domql/utils");
5
+ const getActiveRoute = (route = import_globals.window.location.pathname, level) => `/${route.split("/")[level + 1]}`;
6
+ let lastLevel = 0;
7
+ const defaultOptions = {
8
+ level: lastLevel,
9
+ pushState: true,
10
+ scrollToTop: true,
11
+ scrollToNode: false,
12
+ useFragment: false,
13
+ updateState: true
14
+ };
15
+ const router = (element, path, state = {}, options = defaultOptions) => {
16
+ (0, import_utils.merge)(options, defaultOptions);
17
+ lastLevel = options.lastLevel;
18
+ const [pathname, hash] = path.split("#");
19
+ const route = getActiveRoute(pathname, options.level);
20
+ const content = element.routes[route] || element.routes["/*"];
21
+ if (content) {
22
+ if (options.pushState)
23
+ import_globals.window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ""));
24
+ element.set({ tag: options.useFragment && "fragment", extend: content });
25
+ if (options.updateState)
26
+ element.state.update({ route, hash });
27
+ const rootNode = element.node;
28
+ if (options.scrollToTop)
29
+ rootNode.scrollTo({ behavior: "smooth", top: 0, left: 0 });
30
+ if (options.scrollToNode)
31
+ content.content.node.scrollTo({ behavior: "smooth", top: 0, left: 0 });
32
+ if (hash) {
33
+ const activeNode = document.getElementById(hash);
34
+ if (activeNode) {
35
+ const top = activeNode.getBoundingClientRect().top + rootNode.scrollToTopp - 140;
36
+ rootNode.scrollTo({ behavior: "smooth", top, left: 0 });
37
+ }
38
+ }
39
+ }
40
+ };
41
+ })();
package/package.json CHANGED
@@ -1,14 +1,29 @@
1
1
  {
2
2
  "name": "@domql/router",
3
- "version": "2.3.50",
4
- "main": "index.js",
3
+ "version": "2.3.60",
5
4
  "license": "MIT",
5
+ "type": "module",
6
+ "module": "dist/esm/index.js",
7
+ "unpkg": "dist/iife/index.js",
8
+ "jsdelivr": "dist/iife/index.js",
9
+ "main": "dist/esm/index.js",
10
+ "exports": "./dist/cjs/index.js",
11
+ "source": "index.js",
12
+ "files": [
13
+ "*.js",
14
+ "dist"
15
+ ],
6
16
  "scripts": {
7
- "vpatch": "npm version patch && npm publish --access public"
17
+ "copy:package:cjs": "cp ../../package-cjs.json dist/cjs/package.json",
18
+ "build:esm": "npx esbuild *.js --target=es2020 --format=esm --outdir=dist/esm",
19
+ "build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs && yarn copy:package:cjs",
20
+ "build:iife": "npx esbuild *.js --target=node16 --format=iife --outdir=dist/iife",
21
+ "build": "rimraf -I dist && yarn build:esm && yarn build:cjs && yarn build:iife",
22
+ "postinstall": "yarn build",
23
+ "prepublish": "yarn build"
8
24
  },
9
25
  "dependencies": {
10
26
  "@domql/utils": "latest"
11
27
  },
12
- "gitHead": "d3e2a8cef1a70c00f05aaf7e91389ce046365df4",
13
- "source": "index.js"
28
+ "gitHead": "1c0635af260927e33f5e83507f1b126d23938fbc"
14
29
  }