aptechka 0.4.15 → 0.4.16
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.
- package/lib/morph/Link.d.ts +1 -1
- package/lib/morph/Morph.d.ts +1 -1
- package/lib/morph/index.cjs +1 -1
- package/lib/morph/index.js +49 -46
- package/package.json +1 -1
package/lib/morph/Link.d.ts
CHANGED
package/lib/morph/Morph.d.ts
CHANGED
|
@@ -22,6 +22,6 @@ export declare class Morph {
|
|
|
22
22
|
constructor(parameters?: MorphParameters);
|
|
23
23
|
beforeNavigationEvent(callback: MorphNavigationCallback): () => void;
|
|
24
24
|
afterNavigationEvent(callback: MorphNavigationCallback): () => void;
|
|
25
|
-
prefetch(
|
|
25
|
+
prefetch(path: string): Promise<Document>;
|
|
26
26
|
navigate(path: string, historyAction?: MorphHistoryAction): Promise<void>;
|
|
27
27
|
}
|
package/lib/morph/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var st=(n,t)=>(t=Symbol[n])?t:Symbol.for("Symbol."+n);var _=(n,t,e)=>{if(!t.has(n))throw TypeError("Cannot "+e)};var s=(n,t,e)=>(_(n,t,"read from private field"),e?e.call(n):t.get(n)),r=(n,t,e)=>{if(t.has(n))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(n):t.set(n,e)},c=(n,t,e,o)=>(_(n,t,"write to private field"),o?o.call(n,e):t.set(n,e),e);var d=(n,t,e)=>(_(n,t,"access private method"),e);var T=(n,t,e)=>new Promise((o,i)=>{var a=l=>{try{f(e.next(l))}catch(m){i(m)}},w=l=>{try{f(e.throw(l))}catch(m){i(m)}},f=l=>l.done?o(l.value):Promise.resolve(l.value).then(a,w);f((e=e.apply(n,t)).next())});var it=(n,t,e)=>(t=n[st("asyncIterator")])?t.call(n):(n=n[st("iterator")](),t={},e=(o,i)=>(i=n[o])&&(t[o]=a=>new Promise((w,f,l)=>(a=i.call(n,a),l=a.done,Promise.resolve(a.value).then(m=>w({value:m,done:l}),f)))),e("next"),e("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const nt=require("../notifier/index.cjs"),ut=require("../browser-CpzFX2xg.cjs");require("../path-data-polyfill-CXsOR7Oc.cjs");var y,u,L,H,P,S;class dt{constructor(t,e,o){r(this,y,void 0);r(this,u,void 0);r(this,L,void 0);r(this,H,void 0);r(this,P,t=>{t.preventDefault(),s(this,y).navigate(s(this,L),s(this,H))});r(this,S,()=>{s(this,y).prefetch(s(this,L))});c(this,y,e),c(this,u,t),c(this,L,s(this,u).getAttribute("href")||"/"),c(this,H,s(this,u).getAttribute("data-history-action")||"push"),s(this,u).addEventListener("click",s(this,P)),s(this,L)===location.pathname.replace(o.slice(0,-1),"")&&s(this,u).classList.add("current"),s(this,u).hasAttribute("data-prefetch")&&s(this,u).addEventListener("pointerenter",s(this,S))}destroy(){s(this,u).removeEventListener("click",s(this,P)),s(this,u).removeEventListener("pointerenter",s(this,S)),s(this,u).classList.remove("current")}}y=new WeakMap,u=new WeakMap,L=new WeakMap,H=new WeakMap,P=new WeakMap,S=new WeakMap;var g,N,A,C,k,j,b,v,M,x,W,q,z,D,G,R,J,F,Q,B,rt,I,U,K;class ft{constructor(t){r(this,q);r(this,D);r(this,R);r(this,F);r(this,B);r(this,I);r(this,g,null);r(this,N,null);r(this,A,null);r(this,C,null);r(this,k,[]);r(this,j,new DOMParser);r(this,b,new Map);r(this,v,void 0);r(this,M,null);r(this,x,new nt.Notifier);r(this,W,new nt.Notifier);r(this,K,t=>{t.state&&this.navigate(t.state,"none")});ut.isBrowser&&(c(this,g,(t==null?void 0:t.base)||"/"),t!=null&&t.base?(c(this,g,t.base),t.base.endsWith("/")||c(this,g,s(this,g)+"/")):c(this,g,"/"),c(this,N,(t==null?void 0:t.waitForHeadToLoad)!==!1),c(this,A,(t==null?void 0:t.cachePages)!==!1),c(this,C,d(this,F,Q).call(this,document)),c(this,M,location.pathname),d(this,R,J).call(this),addEventListener("popstate",s(this,K)))}beforeNavigationEvent(t){return s(this,x).subscribe(t)}afterNavigationEvent(t){return s(this,W).subscribe(t)}prefetch(t){return T(this,null,function*(){const e=d(this,D,G).call(this,t);return d(this,q,z).call(this,e.pathname)})}navigate(t,e="push"){return T(this,null,function*(){var l;const o=d(this,D,G).call(this,t);let{pathname:i,hash:a,parameters:w}=o;if(s(this,v)===i||s(this,M)===i)return;c(this,v,i);const f=s(this,b).has(i);try{let m=!0;if(s(this,x).notify({pathname:i,isCached:f}),this.preprocessor)try{yield new Promise((h,p)=>{var E;(E=this.preprocessor)==null||E.call(this,{pathname:i,resolve:h,reject:p,isCached:f})})}catch(h){h?console.error(h):console.log("Route change canceled"),m=!1}if(!m||s(this,v)!==i)return;const V=s(this,b).get(i)||(yield d(this,q,z).call(this,i));if(s(this,v)!==i)return;const X=Array.from(document.head.children),Z=Array.from(V.head.cloneNode(!0).children),tt=d(this,B,rt).call(this,X,Z),ot=d(this,I,U).call(this,X,tt),O=d(this,I,U).call(this,Z,tt);ot.forEach(h=>{h.remove()}),O.forEach((h,p)=>{if(h.tagName==="SCRIPT"&&h.getAttribute("src")){const E=document.createElement("script");E.type="module",E.src=h.getAttribute("src"),O[p]=E}}),O.forEach((h,p)=>{document.head.appendChild(h)});const Y=O.filter(h=>h.tagName==="STYLE"||h.tagName==="SCRIPT"||h.tagName==="LINK");s(this,N)&&Y.length&&(yield new Promise(h=>T(this,null,function*(){let p=0;try{for(var E=it(Y),pt,Et,vt;pt=!(Et=yield E.next()).done;pt=!1){const lt=Et.value;lt.onload=()=>{p++,p===Y.length&&h()}}}catch(Et){vt=[Et]}finally{try{pt&&(Et=E.return)&&(yield Et.call(E))}finally{if(vt)throw vt[0]}}}))),c(this,M,i);const $=w||location.search,ht=a?a.startsWith("#")?a:"#"+a:"",ct=$?$.startsWith("?")?$:"?"+$:"",et=`${i}${ht}${ct}`;e==="push"?history.pushState(i,"",et):e==="replace"&&history.replaceState(i,"",et);const at=d(this,F,Q).call(this,V);s(this,C).forEach((h,p)=>{const E=at[p];h.innerHTML=E.innerHTML}),d(this,R,J).call(this),(l=this.postprocessor)==null||l.call(this,{pathname:i,isCached:f}),s(this,W).notify({pathname:i,isCached:f})}catch(m){console.error(m)}c(this,v,void 0)})}}g=new WeakMap,N=new WeakMap,A=new WeakMap,C=new WeakMap,k=new WeakMap,j=new WeakMap,b=new WeakMap,v=new WeakMap,M=new WeakMap,x=new WeakMap,W=new WeakMap,q=new WeakSet,z=function(t){return T(this,null,function*(){const e=s(this,b).get(t);if(e)return e;const i=yield(yield fetch(t)).text(),a=s(this,j).parseFromString(i,"text/html");return s(this,A)&&s(this,b).set(t,a),a})},D=new WeakSet,G=function(t){t=t.replace(s(this,g),""),t.startsWith("/")&&(t=t.slice(1));const e=t.split("#"),o=e[0].split("?"),i=s(this,g)+o[0],a=o==null?void 0:o[1],w=e==null?void 0:e[1];return{pathname:i,parameters:a,hash:w}},R=new WeakSet,J=function(){const t=[...document.documentElement.querySelectorAll("a")].filter(e=>{var o;return(o=e.getAttribute("href"))==null?void 0:o.startsWith("/")});s(this,k).forEach(e=>e.destroy()),c(this,k,t.map(e=>new dt(e,this,s(this,g))))},F=new WeakSet,Q=function(t){const e=t.querySelectorAll("[data-morph]");return e.length?[...e]:[t.body]},B=new WeakSet,rt=function(t,e){return t.filter(o=>e.find(i=>i.outerHTML===o.outerHTML))},I=new WeakSet,U=function(t,e){return t.filter(o=>!e.find(i=>i.outerHTML===o.outerHTML))},K=new WeakMap;exports.Morph=ft;
|
package/lib/morph/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var st = (n, t) => (t = Symbol[n]) ? t : Symbol.for("Symbol." + n);
|
|
2
2
|
var z = (n, t, e) => {
|
|
3
3
|
if (!t.has(n))
|
|
4
4
|
throw TypeError("Cannot " + e);
|
|
@@ -9,7 +9,7 @@ var s = (n, t, e) => (z(n, t, "read from private field"), e ? e.call(n) : t.get(
|
|
|
9
9
|
t instanceof WeakSet ? t.add(n) : t.set(n, e);
|
|
10
10
|
}, c = (n, t, e, r) => (z(n, t, "write to private field"), r ? r.call(n, e) : t.set(n, e), e);
|
|
11
11
|
var f = (n, t, e) => (z(n, t, "access private method"), e);
|
|
12
|
-
var
|
|
12
|
+
var T = (n, t, e) => new Promise((r, i) => {
|
|
13
13
|
var a = (l) => {
|
|
14
14
|
try {
|
|
15
15
|
d(e.next(l));
|
|
@@ -25,56 +25,56 @@ var P = (n, t, e) => new Promise((r, i) => {
|
|
|
25
25
|
}, d = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(a, v);
|
|
26
26
|
d((e = e.apply(n, t)).next());
|
|
27
27
|
});
|
|
28
|
-
var
|
|
29
|
-
import { Notifier as
|
|
28
|
+
var it = (n, t, e) => (t = n[st("asyncIterator")]) ? t.call(n) : (n = n[st("iterator")](), t = {}, e = (r, i) => (i = n[r]) && (t[r] = (a) => new Promise((v, d, l) => (a = i.call(n, a), l = a.done, Promise.resolve(a.value).then((m) => v({ value: m, done: l }), d)))), e("next"), e("return"), t);
|
|
29
|
+
import { Notifier as nt } from "../notifier/index.js";
|
|
30
30
|
import { i as ut } from "../browser-0zX67oeU.js";
|
|
31
31
|
import "../path-data-polyfill-DgeDWYeI.js";
|
|
32
|
-
var b, u, w,
|
|
32
|
+
var b, u, w, M, P, N;
|
|
33
33
|
class ft {
|
|
34
|
-
constructor(t, e) {
|
|
34
|
+
constructor(t, e, r) {
|
|
35
35
|
o(this, b, void 0);
|
|
36
36
|
o(this, u, void 0);
|
|
37
37
|
o(this, w, void 0);
|
|
38
|
-
o(this,
|
|
39
|
-
o(this,
|
|
40
|
-
t.preventDefault(), s(this, b).navigate(s(this, w), s(this,
|
|
38
|
+
o(this, M, void 0);
|
|
39
|
+
o(this, P, (t) => {
|
|
40
|
+
t.preventDefault(), s(this, b).navigate(s(this, w), s(this, M));
|
|
41
41
|
});
|
|
42
42
|
o(this, N, () => {
|
|
43
43
|
s(this, b).prefetch(s(this, w));
|
|
44
44
|
});
|
|
45
|
-
c(this, b, e), c(this, u, t), c(this, w, s(this, u).getAttribute("href") || "/"), c(this,
|
|
45
|
+
c(this, b, e), c(this, u, t), c(this, w, s(this, u).getAttribute("href") || "/"), c(this, M, s(this, u).getAttribute(
|
|
46
46
|
"data-history-action"
|
|
47
|
-
) || "push"), s(this, u).addEventListener("click", s(this,
|
|
47
|
+
) || "push"), s(this, u).addEventListener("click", s(this, P)), s(this, w) === location.pathname.replace(r.slice(0, -1), "") && s(this, u).classList.add("current"), s(this, u).hasAttribute("data-prefetch") && s(this, u).addEventListener("pointerenter", s(this, N));
|
|
48
48
|
}
|
|
49
49
|
destroy() {
|
|
50
|
-
s(this, u).removeEventListener("click", s(this,
|
|
50
|
+
s(this, u).removeEventListener("click", s(this, P)), s(this, u).removeEventListener("pointerenter", s(this, N)), s(this, u).classList.remove("current");
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
b = new WeakMap(), u = new WeakMap(), w = new WeakMap(),
|
|
54
|
-
var p, S, A, C, k,
|
|
53
|
+
b = new WeakMap(), u = new WeakMap(), w = new WeakMap(), M = new WeakMap(), P = new WeakMap(), N = new WeakMap();
|
|
54
|
+
var p, S, A, C, k, B, y, L, H, x, W, D, G, R, J, F, Q, I, U, K, ot, $, V, Y;
|
|
55
55
|
class Et {
|
|
56
56
|
constructor(t) {
|
|
57
57
|
o(this, D);
|
|
58
|
-
o(this, B);
|
|
59
58
|
o(this, R);
|
|
60
59
|
o(this, F);
|
|
61
|
-
o(this, K);
|
|
62
60
|
o(this, I);
|
|
61
|
+
o(this, K);
|
|
62
|
+
o(this, $);
|
|
63
63
|
o(this, p, null);
|
|
64
64
|
o(this, S, null);
|
|
65
65
|
o(this, A, null);
|
|
66
66
|
o(this, C, null);
|
|
67
67
|
o(this, k, []);
|
|
68
|
-
o(this,
|
|
68
|
+
o(this, B, new DOMParser());
|
|
69
69
|
o(this, y, /* @__PURE__ */ new Map());
|
|
70
70
|
o(this, L, void 0);
|
|
71
71
|
o(this, H, null);
|
|
72
|
-
o(this, x, new
|
|
73
|
-
o(this, W, new
|
|
72
|
+
o(this, x, new nt());
|
|
73
|
+
o(this, W, new nt());
|
|
74
74
|
o(this, Y, (t) => {
|
|
75
75
|
t.state && this.navigate(t.state, "none");
|
|
76
76
|
});
|
|
77
|
-
ut && (c(this, p, (t == null ? void 0 : t.base) || "/"), t != null && t.base ? (c(this, p, t.base), t.base.endsWith("/") || c(this, p, s(this, p) + "/")) : c(this, p, "/"), c(this, S, (t == null ? void 0 : t.waitForHeadToLoad) !== !1), c(this, A, (t == null ? void 0 : t.cachePages) !== !1), c(this, C, f(this,
|
|
77
|
+
ut && (c(this, p, (t == null ? void 0 : t.base) || "/"), t != null && t.base ? (c(this, p, t.base), t.base.endsWith("/") || c(this, p, s(this, p) + "/")) : c(this, p, "/"), c(this, S, (t == null ? void 0 : t.waitForHeadToLoad) !== !1), c(this, A, (t == null ? void 0 : t.cachePages) !== !1), c(this, C, f(this, I, U).call(this, document)), c(this, H, location.pathname), f(this, F, Q).call(this), addEventListener("popstate", s(this, Y)));
|
|
78
78
|
}
|
|
79
79
|
beforeNavigationEvent(t) {
|
|
80
80
|
return s(this, x).subscribe(t);
|
|
@@ -83,14 +83,15 @@ class Et {
|
|
|
83
83
|
return s(this, W).subscribe(t);
|
|
84
84
|
}
|
|
85
85
|
prefetch(t) {
|
|
86
|
-
return
|
|
87
|
-
|
|
86
|
+
return T(this, null, function* () {
|
|
87
|
+
const e = f(this, R, J).call(this, t);
|
|
88
|
+
return f(this, D, G).call(this, e.pathname);
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
91
|
navigate(t, e = "push") {
|
|
91
|
-
return
|
|
92
|
+
return T(this, null, function* () {
|
|
92
93
|
var l;
|
|
93
|
-
const r = f(this,
|
|
94
|
+
const r = f(this, R, J).call(this, t);
|
|
94
95
|
let { pathname: i, hash: a, parameters: v } = r;
|
|
95
96
|
if (s(this, L) === i || s(this, H) === i)
|
|
96
97
|
return;
|
|
@@ -112,29 +113,29 @@ class Et {
|
|
|
112
113
|
}
|
|
113
114
|
if (!m || s(this, L) !== i)
|
|
114
115
|
return;
|
|
115
|
-
const
|
|
116
|
+
const X = s(this, y).get(i) || (yield f(this, D, G).call(this, i));
|
|
116
117
|
if (s(this, L) !== i)
|
|
117
118
|
return;
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
),
|
|
119
|
+
const Z = Array.from(document.head.children), _ = Array.from(
|
|
120
|
+
X.head.cloneNode(!0).children
|
|
121
|
+
), tt = f(this, K, ot).call(this, Z, _), rt = f(this, $, V).call(this, Z, tt), q = f(this, $, V).call(this, _, tt);
|
|
121
122
|
rt.forEach((h) => {
|
|
122
123
|
h.remove();
|
|
123
|
-
}),
|
|
124
|
+
}), q.forEach((h, g) => {
|
|
124
125
|
if (h.tagName === "SCRIPT" && h.getAttribute("src")) {
|
|
125
126
|
const E = document.createElement("script");
|
|
126
|
-
E.type = "module", E.src = h.getAttribute("src"),
|
|
127
|
+
E.type = "module", E.src = h.getAttribute("src"), q[g] = E;
|
|
127
128
|
}
|
|
128
|
-
}),
|
|
129
|
+
}), q.forEach((h, g) => {
|
|
129
130
|
document.head.appendChild(h);
|
|
130
131
|
});
|
|
131
|
-
const j =
|
|
132
|
+
const j = q.filter(
|
|
132
133
|
(h) => h.tagName === "STYLE" || h.tagName === "SCRIPT" || h.tagName === "LINK"
|
|
133
134
|
);
|
|
134
|
-
s(this, S) && j.length && (yield new Promise((h) =>
|
|
135
|
+
s(this, S) && j.length && (yield new Promise((h) => T(this, null, function* () {
|
|
135
136
|
let g = 0;
|
|
136
137
|
try {
|
|
137
|
-
for (var E =
|
|
138
|
+
for (var E = it(j), wt, yt, bt; wt = !(yt = yield E.next()).done; wt = !1) {
|
|
138
139
|
const lt = yt.value;
|
|
139
140
|
lt.onload = () => {
|
|
140
141
|
g++, g === j.length && h();
|
|
@@ -151,13 +152,13 @@ class Et {
|
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
}))), c(this, H, i);
|
|
154
|
-
const
|
|
155
|
-
e === "push" ? history.pushState(i, "",
|
|
156
|
-
const at = f(this,
|
|
155
|
+
const O = v || location.search, ht = a ? a.startsWith("#") ? a : "#" + a : "", ct = O ? O.startsWith("?") ? O : "?" + O : "", et = `${i}${ht}${ct}`;
|
|
156
|
+
e === "push" ? history.pushState(i, "", et) : e === "replace" && history.replaceState(i, "", et);
|
|
157
|
+
const at = f(this, I, U).call(this, X);
|
|
157
158
|
s(this, C).forEach((h, g) => {
|
|
158
159
|
const E = at[g];
|
|
159
160
|
h.innerHTML = E.innerHTML;
|
|
160
|
-
}), f(this,
|
|
161
|
+
}), f(this, F, Q).call(this), (l = this.postprocessor) == null || l.call(this, { pathname: i, isCached: d }), s(this, W).notify({ pathname: i, isCached: d });
|
|
161
162
|
} catch (m) {
|
|
162
163
|
console.error(m);
|
|
163
164
|
}
|
|
@@ -165,15 +166,15 @@ class Et {
|
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
p = new WeakMap(), S = new WeakMap(), A = new WeakMap(), C = new WeakMap(), k = new WeakMap(),
|
|
169
|
-
return
|
|
169
|
+
p = new WeakMap(), S = new WeakMap(), A = new WeakMap(), C = new WeakMap(), k = new WeakMap(), B = new WeakMap(), y = new WeakMap(), L = new WeakMap(), H = new WeakMap(), x = new WeakMap(), W = new WeakMap(), D = new WeakSet(), G = function(t) {
|
|
170
|
+
return T(this, null, function* () {
|
|
170
171
|
const e = s(this, y).get(t);
|
|
171
172
|
if (e)
|
|
172
173
|
return e;
|
|
173
|
-
const i = yield (yield fetch(t)).text(), a = s(this,
|
|
174
|
+
const i = yield (yield fetch(t)).text(), a = s(this, B).parseFromString(i, "text/html");
|
|
174
175
|
return s(this, A) && s(this, y).set(t, a), a;
|
|
175
176
|
});
|
|
176
|
-
},
|
|
177
|
+
}, R = new WeakSet(), J = function(t) {
|
|
177
178
|
t = t.replace(s(this, p), ""), t.startsWith("/") && (t = t.slice(1));
|
|
178
179
|
const e = t.split("#"), r = e[0].split("?"), i = s(this, p) + r[0], a = r == null ? void 0 : r[1], v = e == null ? void 0 : e[1];
|
|
179
180
|
return {
|
|
@@ -181,15 +182,17 @@ p = new WeakMap(), S = new WeakMap(), A = new WeakMap(), C = new WeakMap(), k =
|
|
|
181
182
|
parameters: a,
|
|
182
183
|
hash: v
|
|
183
184
|
};
|
|
184
|
-
},
|
|
185
|
+
}, F = new WeakSet(), Q = function() {
|
|
185
186
|
const t = [
|
|
186
187
|
...document.documentElement.querySelectorAll("a")
|
|
187
188
|
].filter((e) => {
|
|
188
189
|
var r;
|
|
189
190
|
return (r = e.getAttribute("href")) == null ? void 0 : r.startsWith("/");
|
|
190
191
|
});
|
|
191
|
-
s(this, k).forEach((e) => e.destroy()), c(this, k, t.map(
|
|
192
|
-
|
|
192
|
+
s(this, k).forEach((e) => e.destroy()), c(this, k, t.map(
|
|
193
|
+
(e) => new ft(e, this, s(this, p))
|
|
194
|
+
));
|
|
195
|
+
}, I = new WeakSet(), U = function(t) {
|
|
193
196
|
const e = t.querySelectorAll("[data-morph]");
|
|
194
197
|
return e.length ? [...e] : [t.body];
|
|
195
198
|
}, K = new WeakSet(), ot = function(t, e) {
|
|
@@ -198,7 +201,7 @@ p = new WeakMap(), S = new WeakMap(), A = new WeakMap(), C = new WeakMap(), k =
|
|
|
198
201
|
(i) => i.outerHTML === r.outerHTML
|
|
199
202
|
)
|
|
200
203
|
);
|
|
201
|
-
},
|
|
204
|
+
}, $ = new WeakSet(), V = function(t, e) {
|
|
202
205
|
return t.filter(
|
|
203
206
|
(r) => !e.find(
|
|
204
207
|
(i) => i.outerHTML === r.outerHTML
|