simplyview 3.3.0 → 3.4.1
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/dist/simply.app.js +100 -0
- package/dist/simply.app.min.js +1 -1
- package/dist/simply.app.min.js.map +4 -4
- package/dist/simply.everything.js +185 -45
- package/dist/simply.everything.min.js +1 -1
- package/dist/simply.everything.min.js.map +4 -4
- package/package.json +1 -1
- package/src/app.mjs +112 -6
- package/src/everything.mjs +2 -0
- package/src/highlight.mjs +11 -0
- package/src/include.mjs +1 -1
- package/src/path.mjs +38 -0
|
@@ -179,30 +179,30 @@
|
|
|
179
179
|
finish: {}
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
|
-
match(
|
|
182
|
+
match(path2, options) {
|
|
183
183
|
let args = {
|
|
184
|
-
path,
|
|
184
|
+
path: path2,
|
|
185
185
|
options
|
|
186
186
|
};
|
|
187
187
|
args = this.runListeners("match", args);
|
|
188
|
-
|
|
188
|
+
path2 = args.path ? args.path : path2;
|
|
189
189
|
let matches;
|
|
190
|
-
if (!
|
|
190
|
+
if (!path2) {
|
|
191
191
|
if (this.match(document.location.pathname + document.location.hash)) {
|
|
192
192
|
return true;
|
|
193
193
|
} else {
|
|
194
194
|
return this.match(document.location.pathname);
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
path2 = getPath(path2);
|
|
198
198
|
for (let route of this.routeInfo) {
|
|
199
|
-
matches = route.match.exec(
|
|
199
|
+
matches = route.match.exec(path2);
|
|
200
200
|
if (this.addMissingSlash && !matches?.length) {
|
|
201
|
-
if (
|
|
202
|
-
matches = route.match.exec(
|
|
201
|
+
if (path2 && path2[path2.length - 1] != "/") {
|
|
202
|
+
matches = route.match.exec(path2 + "/");
|
|
203
203
|
if (matches) {
|
|
204
|
-
|
|
205
|
-
history.replaceState({}, "", getURL(
|
|
204
|
+
path2 += "/";
|
|
205
|
+
history.replaceState({}, "", getURL(path2, this.baseURL));
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
@@ -264,12 +264,12 @@
|
|
|
264
264
|
}
|
|
265
265
|
if (link && link.pathname && link.hostname == globalThis.location.hostname && !link.link && !link.dataset.simplyCommand) {
|
|
266
266
|
let check = [link.hash, link.pathname + link.hash, link.pathname];
|
|
267
|
-
let
|
|
267
|
+
let path2;
|
|
268
268
|
do {
|
|
269
|
-
|
|
270
|
-
} while (check.length && !this.has(
|
|
271
|
-
if (this.has(
|
|
272
|
-
let params = this.runListeners("goto", { path });
|
|
269
|
+
path2 = getPath(check.shift(), this.baseURL);
|
|
270
|
+
} while (check.length && !this.has(path2));
|
|
271
|
+
if (this.has(path2)) {
|
|
272
|
+
let params = this.runListeners("goto", { path: path2 });
|
|
273
273
|
if (params.path) {
|
|
274
274
|
if (this.goto(params.path)) {
|
|
275
275
|
evt.preventDefault();
|
|
@@ -280,14 +280,14 @@
|
|
|
280
280
|
}
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
|
-
goto(
|
|
284
|
-
history.pushState({}, "", getURL(
|
|
285
|
-
return this.match(
|
|
283
|
+
goto(path2) {
|
|
284
|
+
history.pushState({}, "", getURL(path2, this.baseURL));
|
|
285
|
+
return this.match(path2);
|
|
286
286
|
}
|
|
287
|
-
has(
|
|
288
|
-
|
|
287
|
+
has(path2) {
|
|
288
|
+
path2 = getPath(path2, this.baseURL);
|
|
289
289
|
for (let route of this.routeInfo) {
|
|
290
|
-
var matches = route.match.exec(
|
|
290
|
+
var matches = route.match.exec(path2);
|
|
291
291
|
if (matches && matches.length) {
|
|
292
292
|
return true;
|
|
293
293
|
}
|
|
@@ -320,24 +320,24 @@
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
|
-
function getPath(
|
|
324
|
-
if (
|
|
325
|
-
|
|
323
|
+
function getPath(path2, baseURL = "/") {
|
|
324
|
+
if (path2.substring(0, baseURL.length) == baseURL || baseURL[baseURL.length - 1] == "/" && path2.length == baseURL.length - 1 && path2 == baseURL.substring(0, path2.length)) {
|
|
325
|
+
path2 = path2.substring(baseURL.length);
|
|
326
326
|
}
|
|
327
|
-
if (
|
|
328
|
-
|
|
327
|
+
if (path2[0] != "/" && path2[0] != "#") {
|
|
328
|
+
path2 = "/" + path2;
|
|
329
329
|
}
|
|
330
|
-
return
|
|
330
|
+
return path2;
|
|
331
331
|
}
|
|
332
|
-
function getURL(
|
|
333
|
-
|
|
334
|
-
if (baseURL[baseURL.length - 1] === "/" &&
|
|
335
|
-
|
|
332
|
+
function getURL(path2, baseURL) {
|
|
333
|
+
path2 = getPath(path2, baseURL);
|
|
334
|
+
if (baseURL[baseURL.length - 1] === "/" && path2[0] === "/") {
|
|
335
|
+
path2 = path2.substring(1);
|
|
336
336
|
}
|
|
337
|
-
if (
|
|
338
|
-
return
|
|
337
|
+
if (path2[0] == "#") {
|
|
338
|
+
return path2;
|
|
339
339
|
}
|
|
340
|
-
return baseURL +
|
|
340
|
+
return baseURL + path2;
|
|
341
341
|
}
|
|
342
342
|
function getRegexpFromRoute(route, exact = false) {
|
|
343
343
|
if (exact) {
|
|
@@ -348,19 +348,19 @@
|
|
|
348
348
|
function parseRoutes(routes2, routeInfo, exact = false) {
|
|
349
349
|
const paths = Object.keys(routes2);
|
|
350
350
|
const matchParams = /:(\w+|\*)/g;
|
|
351
|
-
for (let
|
|
351
|
+
for (let path2 of paths) {
|
|
352
352
|
let matches = [];
|
|
353
353
|
let params = [];
|
|
354
354
|
do {
|
|
355
|
-
matches = matchParams.exec(
|
|
355
|
+
matches = matchParams.exec(path2);
|
|
356
356
|
if (matches) {
|
|
357
357
|
params.push(matches[1]);
|
|
358
358
|
}
|
|
359
359
|
} while (matches);
|
|
360
360
|
routeInfo.push({
|
|
361
|
-
match: getRegexpFromRoute(
|
|
361
|
+
match: getRegexpFromRoute(path2, exact),
|
|
362
362
|
params,
|
|
363
|
-
action: routes2[
|
|
363
|
+
action: routes2[path2]
|
|
364
364
|
});
|
|
365
365
|
}
|
|
366
366
|
return routeInfo;
|
|
@@ -622,8 +622,8 @@
|
|
|
622
622
|
options.app.view = options.view || {};
|
|
623
623
|
const load = () => {
|
|
624
624
|
const data = options.app.view;
|
|
625
|
-
const
|
|
626
|
-
options.app.view = globalThis.editor.currentData[
|
|
625
|
+
const path2 = globalThis.editor.data.getDataPath(options.app.container || document.body);
|
|
626
|
+
options.app.view = globalThis.editor.currentData[path2];
|
|
627
627
|
Object.assign(options.app.view, data);
|
|
628
628
|
};
|
|
629
629
|
if (globalThis.editor && globalThis.editor.currentData) {
|
|
@@ -637,12 +637,52 @@
|
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
639
|
|
|
640
|
+
// src/highlight.mjs
|
|
641
|
+
function html(strings, ...values) {
|
|
642
|
+
const outputArray = values.map(
|
|
643
|
+
(value, index) => `${strings[index]}${value}`
|
|
644
|
+
);
|
|
645
|
+
return outputArray.join("") + strings[strings.length - 1];
|
|
646
|
+
}
|
|
647
|
+
function css(strings, ...values) {
|
|
648
|
+
return html(strings, ...values);
|
|
649
|
+
}
|
|
650
|
+
|
|
640
651
|
// src/app.mjs
|
|
641
652
|
var SimplyApp = class {
|
|
642
653
|
constructor(options = {}) {
|
|
643
654
|
this.container = options.container || document.body;
|
|
655
|
+
if (options.components) {
|
|
656
|
+
mergeComponents(options, options.components);
|
|
657
|
+
}
|
|
644
658
|
for (let key in options) {
|
|
645
659
|
switch (key) {
|
|
660
|
+
case "html":
|
|
661
|
+
for (const name in options.html) {
|
|
662
|
+
const element = document.createElement("div");
|
|
663
|
+
element.innerHTML = options.html[name];
|
|
664
|
+
let template = this.container.querySelector("template#" + name);
|
|
665
|
+
if (!template) {
|
|
666
|
+
template = document.createElement("template");
|
|
667
|
+
template.id = name;
|
|
668
|
+
template.content.append(...element.children);
|
|
669
|
+
this.container.appendChild(template);
|
|
670
|
+
} else {
|
|
671
|
+
template.content.replaceChildren(...element.children);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
break;
|
|
675
|
+
case "css":
|
|
676
|
+
for (const name in options.css) {
|
|
677
|
+
let style = this.container.querySelector("style#" + name);
|
|
678
|
+
if (!style) {
|
|
679
|
+
style = document.createElement("style");
|
|
680
|
+
style.id = name;
|
|
681
|
+
this.container.appendChild(style);
|
|
682
|
+
}
|
|
683
|
+
style.innerHTML = options.css[name];
|
|
684
|
+
}
|
|
685
|
+
break;
|
|
646
686
|
case "commands":
|
|
647
687
|
this.commands = commands({ app: this, container: this.container, commands: options.commands });
|
|
648
688
|
break;
|
|
@@ -692,6 +732,12 @@
|
|
|
692
732
|
};
|
|
693
733
|
this[key] = new Proxy(options[key], moduleHandler);
|
|
694
734
|
break;
|
|
735
|
+
components:
|
|
736
|
+
this.components = components;
|
|
737
|
+
break;
|
|
738
|
+
prototype:
|
|
739
|
+
__proto__:
|
|
740
|
+
break;
|
|
695
741
|
default:
|
|
696
742
|
console.log('simply.app: unknown initialization option "' + key + '", added as-is');
|
|
697
743
|
this[key] = options[key];
|
|
@@ -703,6 +749,13 @@
|
|
|
703
749
|
return this;
|
|
704
750
|
}
|
|
705
751
|
async start() {
|
|
752
|
+
if (this.components) {
|
|
753
|
+
for (const name in this.components) {
|
|
754
|
+
if (this.components[name].hooks?.start) {
|
|
755
|
+
await this.components[name].hooks.start();
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
706
759
|
if (this.hooks?.start) {
|
|
707
760
|
await this.hooks.start();
|
|
708
761
|
}
|
|
@@ -724,6 +777,53 @@
|
|
|
724
777
|
function app(options = {}) {
|
|
725
778
|
return new SimplyApp(options);
|
|
726
779
|
}
|
|
780
|
+
if (!globalThis.html) {
|
|
781
|
+
globalThis.html = html;
|
|
782
|
+
}
|
|
783
|
+
if (!globalThis.css) {
|
|
784
|
+
globalThis.css = css;
|
|
785
|
+
}
|
|
786
|
+
function mergeOptions(options, otherOptions) {
|
|
787
|
+
for (const key in otherOptions) {
|
|
788
|
+
switch (typeof otherOptions[key]) {
|
|
789
|
+
case "object":
|
|
790
|
+
if (!otherOptions[key]) {
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
if (!options[key]) {
|
|
794
|
+
options[key] = otherOptions[key];
|
|
795
|
+
} else {
|
|
796
|
+
mergeOptions(options[key], otherOptions[key]);
|
|
797
|
+
}
|
|
798
|
+
break;
|
|
799
|
+
default:
|
|
800
|
+
options[key] = otherOptions[key];
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
function mergeComponents(options, components2) {
|
|
805
|
+
for (const name in components2) {
|
|
806
|
+
const component = components2[name];
|
|
807
|
+
if (component.components) {
|
|
808
|
+
mergeComponents(options, component.components);
|
|
809
|
+
}
|
|
810
|
+
options.components[name] = component;
|
|
811
|
+
for (const key in component) {
|
|
812
|
+
switch (key) {
|
|
813
|
+
case "hooks":
|
|
814
|
+
// don't merge these, app.hooks.start will trigger each components start hook
|
|
815
|
+
case "components":
|
|
816
|
+
break;
|
|
817
|
+
default:
|
|
818
|
+
if (!options[key]) {
|
|
819
|
+
options[key] = /* @__PURE__ */ Object.create(null);
|
|
820
|
+
}
|
|
821
|
+
mergeOptions(options[key], component[key]);
|
|
822
|
+
break;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
727
827
|
|
|
728
828
|
// src/include.mjs
|
|
729
829
|
function throttle(callbackFunction, intervalTime) {
|
|
@@ -766,7 +866,7 @@
|
|
|
766
866
|
var scripts = document.getElementsByTagName("script");
|
|
767
867
|
var index = scripts.length - 1;
|
|
768
868
|
var myScript = scripts[index];
|
|
769
|
-
return () => myScript
|
|
869
|
+
return () => myScript?.src;
|
|
770
870
|
})();
|
|
771
871
|
currentScriptURL = getScriptURL();
|
|
772
872
|
} else {
|
|
@@ -826,8 +926,8 @@
|
|
|
826
926
|
importScript();
|
|
827
927
|
}
|
|
828
928
|
},
|
|
829
|
-
html: (
|
|
830
|
-
let fragment = globalThis.document.createRange().createContextualFragment(
|
|
929
|
+
html: (html2, link) => {
|
|
930
|
+
let fragment = globalThis.document.createRange().createContextualFragment(html2);
|
|
831
931
|
const stylesheets = fragment.querySelectorAll('link[rel="stylesheet"],style');
|
|
832
932
|
for (let stylesheet of stylesheets) {
|
|
833
933
|
if (stylesheet.href) {
|
|
@@ -874,8 +974,8 @@
|
|
|
874
974
|
continue;
|
|
875
975
|
}
|
|
876
976
|
console.log("simply-include: loaded " + link.href);
|
|
877
|
-
const
|
|
878
|
-
include.html(
|
|
977
|
+
const html2 = await response.text();
|
|
978
|
+
include.html(html2, link);
|
|
879
979
|
link.parentNode.removeChild(link);
|
|
880
980
|
}
|
|
881
981
|
};
|
|
@@ -897,6 +997,45 @@
|
|
|
897
997
|
observe();
|
|
898
998
|
handleChanges2();
|
|
899
999
|
|
|
1000
|
+
// src/path.mjs
|
|
1001
|
+
var path = {
|
|
1002
|
+
get(dataset, pointer) {
|
|
1003
|
+
if (typeof pointer !== "string") {
|
|
1004
|
+
return pointer;
|
|
1005
|
+
}
|
|
1006
|
+
if (!pointer) {
|
|
1007
|
+
return dataset;
|
|
1008
|
+
}
|
|
1009
|
+
pointer.split(".").reduce(function(acc, name) {
|
|
1010
|
+
return acc && acc[name] ? acc[name] : null;
|
|
1011
|
+
}, dataset);
|
|
1012
|
+
return dataset;
|
|
1013
|
+
},
|
|
1014
|
+
set: function(dataset, pointer, value) {
|
|
1015
|
+
const parent = path.get(dataset, path.parent(pointer));
|
|
1016
|
+
parent[path.pop(pointer)] = value;
|
|
1017
|
+
},
|
|
1018
|
+
pop: function(pointer) {
|
|
1019
|
+
return pointer.split(".").pop();
|
|
1020
|
+
},
|
|
1021
|
+
push: function(pointer, name) {
|
|
1022
|
+
return (pointer ? pointer + "." : "") + name;
|
|
1023
|
+
},
|
|
1024
|
+
parent: function(dataset, pointer) {
|
|
1025
|
+
const names = pointer.split(".");
|
|
1026
|
+
names.pop();
|
|
1027
|
+
return names.join(".");
|
|
1028
|
+
},
|
|
1029
|
+
parents: function(dataset, pointer) {
|
|
1030
|
+
let result = [];
|
|
1031
|
+
while (pointer) {
|
|
1032
|
+
pointer = path.parent(pointer);
|
|
1033
|
+
result.unshift(pointer);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
var path_default = path;
|
|
1038
|
+
|
|
900
1039
|
// src/render.mjs
|
|
901
1040
|
var SimplyRender = class extends HTMLElement {
|
|
902
1041
|
constructor() {
|
|
@@ -930,6 +1069,7 @@
|
|
|
930
1069
|
command: commands,
|
|
931
1070
|
include,
|
|
932
1071
|
key: keys,
|
|
1072
|
+
path: path_default,
|
|
933
1073
|
route: routes,
|
|
934
1074
|
view
|
|
935
1075
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{Symbol.onDestroy||(Symbol.onDestroy=Symbol("onDestroy"));var h=new Map,C={addListener:(t,e)=>{h.has(t)||h.set(t,[]),h.get(t).push(e),V(t)},removeListener:(t,e)=>{if(!h.has(t))return!1;h.set(t,h.get(t).filter(r=>r!=e))}};function V(t){let e=document.querySelectorAll('[data-simply-activate="'+t+'"]');if(e)for(let r of e)N(r)}function N(t){let e=t?.dataset?.simplyActivate;if(e&&h.has(e))for(let r of h.get(e)){let a=r.call(t);typeof a=="function"?t[Symbol.onDestroy]=a:typeof a<"u"&&console.warn("activate listener may only return a de-activate function, instead got",a)}}function z(t){let e=[];for(let r of t)if(r.type=="childList"){for(let a of r.addedNodes)if(a.querySelectorAll){let i=Array.from(a.querySelectorAll("[data-simply-activate]"));a.matches("[data-simply-activate]")&&i.push(a),e=e.concat(i)}for(let a of r.removedNodes)if(a.querySelectorAll){let i=Array.from(a.querySelectorAll("[data-simply-activate]"));a.matches["[data-simply-activate"]&&i.push(a);for(let s of i)s[Symbol.onDestroy]&&s[Symbol.onDestroy].call(s)}}for(let r of e)N(r)}var W=new MutationObserver(z);W.observe(document,{subtree:!0,childList:!0});function y(t,e){if(e){let r=t;t=e,t.app=r}if(t.app){let r={apply(s,n,l){try{let c=s(...l);return c instanceof Promise?(t.app.hooks.wait(!0),c.finally(()=>{t.app.hooks.wait(!1,s)})):c}catch{}}},a={apply(s,n,l){try{let c=s(...l);return c instanceof Promise?t.app.hooks.wait?(t.app.hooks.wait(!0,s),c.catch(o=>t.app.hooks.error(o,s)).finally(()=>{t.app.hooks.wait(!1,s)})):c.catch(o=>t.app.hooks.error(o,s)):c}catch(c){return t.app.hooks.error(c,s)}}},i={get(s,n){if(s[n])return t.app.hooks?.error?new Proxy(s[n].bind(t.app),a):t.app.hooks?.wait?new Proxy(s[n].bind(t.app),r):s[n].bind(t.app)}};return new Proxy(t.actions,i)}else return t}function g(t,e){if(e){let r=t;t=e,t.app=t}return new L(t)}var L=class{constructor(e={}){this.baseURL=e.baseURL||"/",this.app=e.app||{},this.addMissingSlash=!!e.addMissingSlash,this.matchExact=!!e.matchExact,this.clear(),e.routes&&this.load(e.routes)}load(e){Y(e,this.routeInfo,this.matchExact)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},goto:{},finish:{}}}match(e,r){let a={path:e,options:r};a=this.runListeners("match",a),e=a.path?a.path:e;let i;if(!e)return this.match(document.location.pathname+document.location.hash)?!0:this.match(document.location.pathname);e=f(e);for(let s of this.routeInfo)if(i=s.match.exec(e),this.addMissingSlash&&!i?.length&&e&&e[e.length-1]!="/"&&(i=s.match.exec(e+"/"),i&&(e+="/",history.replaceState({},"",P(e,this.baseURL)))),i&&i.length){let n={};s.params.forEach((c,o)=>{c=="*"&&(c="remainder"),n[c]=i[o+1]}),Object.assign(n,r),a.route=s,a.params=n,a=this.runListeners("call",a),n=a.params?a.params:n;let l=new URLSearchParams(document.location.search);return a.result=s.action.call(this.app,n,l),this.runListeners("finish",a),a.result}return!1}runListeners(e,r){if(!(!this.listeners[e]||!Object.keys(this.listeners[e])))return Object.keys(this.listeners[e]).forEach(a=>{var i=D(a);if(i.exec(r.path)){var s;for(let n of this.listeners[e][a])s=n.call(this.app,r),s&&(r=s)}}),r}handleEvents(){globalThis.addEventListener("popstate",()=>{this.match(f(document.location.pathname+document.location.hash,this.baseURL))===!1&&this.match(f(document.location.pathname,this.baseURL))}),this.app.container.addEventListener("click",e=>{if(!e.ctrlKey&&e.which==1){for(var r=e.target;r&&r.tagName!="A";)r=r.parentElement;if(r&&r.pathname&&r.hostname==globalThis.location.hostname&&!r.link&&!r.dataset.simplyCommand){let a=[r.hash,r.pathname+r.hash,r.pathname],i;do i=f(a.shift(),this.baseURL);while(a.length&&!this.has(i));if(this.has(i)){let s=this.runListeners("goto",{path:i});if(s.path&&this.goto(s.path))return e.preventDefault(),!1}}}})}goto(e){return history.pushState({},"",P(e,this.baseURL)),this.match(e)}has(e){e=f(e,this.baseURL);for(let a of this.routeInfo){var r=a.match.exec(e);if(r&&r.length)return!0}return!1}addListener(e,r,a){if(["goto","match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]||(this.listeners[e][r]=[]),this.listeners[e][r].push(a)}removeListener(e,r,a){if(["match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]&&(this.listeners[e][r]=this.listeners[e][r].filter(i=>i!=a))}init(e){e.baseURL&&(this.baseURL=e.baseURL)}};function f(t,e="/"){return(t.substring(0,e.length)==e||e[e.length-1]=="/"&&t.length==e.length-1&&t==e.substring(0,t.length))&&(t=t.substring(e.length)),t[0]!="/"&&t[0]!="#"&&(t="/"+t),t}function P(t,e){return t=f(t,e),e[e.length-1]==="/"&&t[0]==="/"&&(t=t.substring(1)),t[0]=="#"?t:e+t}function D(t,e=!1){return e?new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)")+"(\\?|$)"):new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)"))}function Y(t,e,r=!1){let a=Object.keys(t),i=/:(\w+|\*)/g;for(let s of a){let n=[],l=[];do n=i.exec(s),n&&l.push(n[1]);while(n);e.push({match:D(s,r),params:l,action:t[s]})}return e}var T=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),this.app=e.app,this.$handlers=e.handlers||J,e.commands&&Object.assign(this,e.commands);let r=a=>{let i=G(a,this.$handlers);if(!i)return;if(!this[i.name]){console.error("simply.command: undefined command "+i.name,i.source);return}if(this[i.name].call(e.app,i.source,i.value)!==!0)return a.preventDefault(),a.stopPropagation(),!1};e.app.container.addEventListener("click",r),e.app.container.addEventListener("submit",r),e.app.container.addEventListener("change",r),e.app.container.addEventListener("input",r)}call(e,r,a){if(!this[e]){console.error("simply.command: undefined command "+e);return}return this[e].call(this.app,r,a)}action(e){console.warn("deprecated call to `this.commands.action`");let r=Array.from(arguments).slice();return r.shift(),this.app.actions[e](...r)}appendHandler(e){this.$handlers.push(e)}prependHandler(e){this.$handlers.unshift(e)}};function b(t={},e){if(e){let r=t;t=e,t.app=t}return new T(t)}function G(t,e){var r=t.target.closest("[data-simply-command]");if(r){for(let a of e)if(r.matches(a.match))return a.check(r,t)?{name:r.dataset.simplyCommand,source:r,value:a.get(r)}:null}return null}var J=[{match:"input,select,textarea",get:function(t){if(t.tagName==="SELECT"&&t.multiple){let e=[];for(let r of t.options)r.selected&&e.push(r.value);return e}return t.dataset.simplyValue||t.value},check:function(t,e){return e.type=="change"||t.dataset.simplyImmediate&&e.type=="input"}},{match:"a,button",get:function(t){return t.dataset.simplyValue||t.href||t.value},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}},{match:"form",get:function(t){let e={};for(let r of Array.from(t.elements)){if(r.tagName=="INPUT"&&(r.type=="checkbox"||r.type=="radio")&&!r.checked)return;e[r.name]&&!Array.isArray(e[r.name])&&(e[r.name]=[e[r.name]]),Array.isArray(e[r.name])?e[r.name].push(r.value):e[r.name]=r.value}return e},check:function(t,e){return e.type=="submit"}},{match:"*",get:function(t){return t.dataset.simplyValue},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}}];var m=Object.freeze({Compose:229,Control:17,Meta:224,Alt:18,Shift:16}),x=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),Object.assign(this,e.keys);let r=a=>{if(a.isComposing||a.keyCode===m.Compose||a.defaultPrevented||!a.target)return;let i="default";a.target.closest("[data-simply-keyboard]")&&(i=a.target.closest("[data-simply-keyboard]").dataset.simplyKeyboard);let s=[];a.ctrlKey&&a.keyCode!=m.Control&&s.push("Control"),a.metaKey&&a.keyCode!=m.Meta&&s.push("Meta"),a.altKey&&a.keyCode!=m.Alt&&s.push("Alt"),a.shiftKey&&a.keyCode!=m.Shift&&s.push("Shift"),s.push(a.key.toLowerCase());let n=[],l=event.target.closest("[data-simply-keyboard]");for(;l;)n.push(l.dataset.simplyKeyboard),l=l.parentNode.closest("[data-simply-keyboard]");n.push("");let c,o,K=["+","-"];for(let F in n){c=n[F],c==""?o="default":(o=c,c+=".");for(let _ of K){let u=s.join(_);if(this[o]&&typeof this[o][u]=="function"&&!this[o][u].call(e.app,a)){a.preventDefault();return}if(typeof this[o+u]=="function"&&!this[o+u].call(e.app,a)){a.preventDefault();return}if(this[i]&&this[i][u]){let p=e.app.container.querySelectorAll('[data-simply-accesskey="'+c+u+'"]');p.length&&(p.forEach($=>$.click()),a.preventDefault())}}}};e.app.container.addEventListener("keydown",r)}};function v(t={},e){if(e){let r=t;t=e,t.app=t}return new x(t)}function k(t,e){if(e){let r=t;t=e,t.app=t}if(t.app){t.app.view=t.view||{};let r=()=>{let a=t.app.view,i=globalThis.editor.data.getDataPath(t.app.container||document.body);t.app.view=globalThis.editor.currentData[i],Object.assign(t.app.view,a)};return globalThis.editor&&globalThis.editor.currentData?r():document.addEventListener("simply-content-loaded",r),t.app.view}else return t.view}var E=class{constructor(e={}){this.container=e.container||document.body;for(let r in e)switch(r){case"commands":this.commands=b({app:this,container:this.container,commands:e.commands});break;case"keys":case"keyboard":this.keys=v({app:this,keys:e.keys});break;case"root":case"baseURL":this.baseURL=e[r];break;case"routes":this.routes=g({app:this,routes:e.routes});break;case"actions":this.actions=y({app:this,actions:e.actions}),this.action=function(s){console.warn("deprecated call to `this.action`");let n=Array.from(arguments).slice();return n.shift(),this.actions[s](...n)};break;case"view":this.view=k({app:this,view:e.view});break;case"hooks":let a={get:(s,n)=>{if(s[n])return typeof s[n]=="function"?new Proxy(s[n],i):s[n]&&typeof s[n]=="object"?new Proxy(s[n],a):s[n]}},i={apply:(s,n,l)=>s.apply(this,l)};this[r]=new Proxy(e[r],a);break;default:console.log('simply.app: unknown initialization option "'+r+'", added as-is'),this[r]=e[r];break}}get app(){return this}async start(){this.hooks?.start&&await this.hooks.start(),this.routes&&(this.baseURL&&this.routes.init({baseURL:this.baseURL}),this.routes.handleEvents(),globalThis.setTimeout(()=>{this.routes.has(globalThis.location?.hash)?this.routes.match(globalThis.location.hash):this.routes.match(globalThis.location?.pathname+globalThis.location?.hash)}))}};function R(t={}){return new E(t)}function Q(t,e){let r=0;return()=>{let a=arguments;r||(r=globalThis.setTimeout(()=>{t.apply(this,a),r=0},e))}}var X=globalThis.requestIdleCallback?t=>{globalThis.requestIdleCallback(t,{timeout:500})}:globalThis.requestAnimationFrame;function U(t,e){let r=new URL(t,e);return d.cacheBuster&&r.searchParams.set("cb",d.cacheBuster),r.href}var q,Z={},A=globalThis.document.querySelector("head"),H=globalThis.document.currentScript,M,O;H?O=H.src:(M=(()=>{var t=document.getElementsByTagName("script"),e=t.length-1,r=t[e];return()=>r.src})(),O=M());var ee=async()=>new Promise(function(t){var e=globalThis.document.createElement("script");e.src="https://cdn.jsdelivr.net/gh/simplyedit/simplyview/dist/simply.include.next.js",e.async=!1,globalThis.document.addEventListener("simply-include-next",()=>{A.removeChild(e),t()},{once:!0,passive:!0}),A.appendChild(e)}),w=[],d={cacheBuster:null,scripts:(t,e)=>{let r=t.slice(),a=()=>{let i=r.shift();if(!i)return;let s=[].map.call(i.attributes,l=>l.name),n=globalThis.document.createElement("script");for(let l of s)n.setAttribute(l,i.getAttribute(l));if(n.removeAttribute("data-simply-location"),!n.src)n.innerHTML=i.innerHTML,ee().then(()=>{let l=w[i.dataset.simplyLocation];l.parentNode.insertBefore(n,l),l.parentNode.removeChild(l),a()});else{n.src=U(n.src,e),!n.hasAttribute("async")&&!n.hasAttribute("defer")&&(n.async=!1);let l=w[i.dataset.simplyLocation];l.parentNode.insertBefore(n,l),l.parentNode.removeChild(l),Z[n.src]=!0,a()}};r.length&&a()},html:(t,e)=>{let r=globalThis.document.createRange().createContextualFragment(t),a=r.querySelectorAll('link[rel="stylesheet"],style');for(let n of a)n.href&&(n.href=U(n.href,e.href)),A.appendChild(n);let i=globalThis.document.createDocumentFragment(),s=r.querySelectorAll("script");if(s.length){for(let n of s){let l=globalThis.document.createComment(n.src||"inline script");n.parentNode.insertBefore(l,n),n.dataset.simplyLocation=w.length,w.push(l),i.appendChild(n)}globalThis.setTimeout(function(){d.scripts(Array.from(i.children),e?e.href:globalThis.location.href)},10)}e.parentNode.insertBefore(r,e||null)}},j={},te=async t=>{let e=[].reduce.call(t,(r,a)=>(a.rel=="simply-include-once"&&j[a.href]?a.parentNode.removeChild(a):(j[a.href]=!0,a.rel="simply-include-loading",r.push(a)),r),[]);for(let r of e){if(!r.href)return;let a=await fetch(r.href);if(!a.ok){console.log("simply-include: failed to load "+r.href);continue}console.log("simply-include: loaded "+r.href);let i=await a.text();d.html(i,r),r.parentNode.removeChild(r)}},I=Q(()=>{X(()=>{var t=globalThis.document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');t.length&&te(t)})}),re=()=>{q=new MutationObserver(I),q.observe(globalThis.document,{subtree:!0,childList:!0})};re();I();var S=class extends HTMLElement{constructor(){super();let e=this.getAttribute("rel"),r=document.getElementById(e);if(r){let a=r.content.cloneNode(!0);for(let i of a.childNodes){let s=i.cloneNode(!0);s.nodeType==document.ELEMENT_NODE&&s.querySelectorAll("template").forEach(function(n){n.setAttribute("simply-render","")}),this.parentNode.insertBefore(s,this)}this.parentNode.removeChild(this)}}};customElements.get("simply-render")||customElements.define("simply-render",S);var B={activate:C,action:y,app:R,command:b,include:d,key:v,route:g,view:k};globalThis.simply=B;var Se=B;})();
|
|
1
|
+
(()=>{Symbol.onDestroy||(Symbol.onDestroy=Symbol("onDestroy"));var u=new Map,P={addListener:(t,e)=>{u.has(t)||u.set(t,[]),u.get(t).push(e),Q(t)},removeListener:(t,e)=>{if(!u.has(t))return!1;u.set(t,u.get(t).filter(r=>r!=e))}};function Q(t){let e=document.querySelectorAll('[data-simply-activate="'+t+'"]');if(e)for(let r of e)D(r)}function D(t){let e=t?.dataset?.simplyActivate;if(e&&u.has(e))for(let r of u.get(e)){let a=r.call(t);typeof a=="function"?t[Symbol.onDestroy]=a:typeof a<"u"&&console.warn("activate listener may only return a de-activate function, instead got",a)}}function X(t){let e=[];for(let r of t)if(r.type=="childList"){for(let a of r.addedNodes)if(a.querySelectorAll){let i=Array.from(a.querySelectorAll("[data-simply-activate]"));a.matches("[data-simply-activate]")&&i.push(a),e=e.concat(i)}for(let a of r.removedNodes)if(a.querySelectorAll){let i=Array.from(a.querySelectorAll("[data-simply-activate]"));a.matches["[data-simply-activate"]&&i.push(a);for(let s of i)s[Symbol.onDestroy]&&s[Symbol.onDestroy].call(s)}}for(let r of e)D(r)}var Z=new MutationObserver(X);Z.observe(document,{subtree:!0,childList:!0});function b(t,e){if(e){let r=t;t=e,t.app=r}if(t.app){let r={apply(s,n,l){try{let c=s(...l);return c instanceof Promise?(t.app.hooks.wait(!0),c.finally(()=>{t.app.hooks.wait(!1,s)})):c}catch{}}},a={apply(s,n,l){try{let c=s(...l);return c instanceof Promise?t.app.hooks.wait?(t.app.hooks.wait(!0,s),c.catch(o=>t.app.hooks.error(o,s)).finally(()=>{t.app.hooks.wait(!1,s)})):c.catch(o=>t.app.hooks.error(o,s)):c}catch(c){return t.app.hooks.error(c,s)}}},i={get(s,n){if(s[n])return t.app.hooks?.error?new Proxy(s[n].bind(t.app),a):t.app.hooks?.wait?new Proxy(s[n].bind(t.app),r):s[n].bind(t.app)}};return new Proxy(t.actions,i)}else return t}function g(t,e){if(e){let r=t;t=e,t.app=t}return new T(t)}var T=class{constructor(e={}){this.baseURL=e.baseURL||"/",this.app=e.app||{},this.addMissingSlash=!!e.addMissingSlash,this.matchExact=!!e.matchExact,this.clear(),e.routes&&this.load(e.routes)}load(e){ee(e,this.routeInfo,this.matchExact)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},goto:{},finish:{}}}match(e,r){let a={path:e,options:r};a=this.runListeners("match",a),e=a.path?a.path:e;let i;if(!e)return this.match(document.location.pathname+document.location.hash)?!0:this.match(document.location.pathname);e=f(e);for(let s of this.routeInfo)if(i=s.match.exec(e),this.addMissingSlash&&!i?.length&&e&&e[e.length-1]!="/"&&(i=s.match.exec(e+"/"),i&&(e+="/",history.replaceState({},"",R(e,this.baseURL)))),i&&i.length){let n={};s.params.forEach((c,o)=>{c=="*"&&(c="remainder"),n[c]=i[o+1]}),Object.assign(n,r),a.route=s,a.params=n,a=this.runListeners("call",a),n=a.params?a.params:n;let l=new URLSearchParams(document.location.search);return a.result=s.action.call(this.app,n,l),this.runListeners("finish",a),a.result}return!1}runListeners(e,r){if(!(!this.listeners[e]||!Object.keys(this.listeners[e])))return Object.keys(this.listeners[e]).forEach(a=>{var i=j(a);if(i.exec(r.path)){var s;for(let n of this.listeners[e][a])s=n.call(this.app,r),s&&(r=s)}}),r}handleEvents(){globalThis.addEventListener("popstate",()=>{this.match(f(document.location.pathname+document.location.hash,this.baseURL))===!1&&this.match(f(document.location.pathname,this.baseURL))}),this.app.container.addEventListener("click",e=>{if(!e.ctrlKey&&e.which==1){for(var r=e.target;r&&r.tagName!="A";)r=r.parentElement;if(r&&r.pathname&&r.hostname==globalThis.location.hostname&&!r.link&&!r.dataset.simplyCommand){let a=[r.hash,r.pathname+r.hash,r.pathname],i;do i=f(a.shift(),this.baseURL);while(a.length&&!this.has(i));if(this.has(i)){let s=this.runListeners("goto",{path:i});if(s.path&&this.goto(s.path))return e.preventDefault(),!1}}}})}goto(e){return history.pushState({},"",R(e,this.baseURL)),this.match(e)}has(e){e=f(e,this.baseURL);for(let a of this.routeInfo){var r=a.match.exec(e);if(r&&r.length)return!0}return!1}addListener(e,r,a){if(["goto","match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]||(this.listeners[e][r]=[]),this.listeners[e][r].push(a)}removeListener(e,r,a){if(["match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]&&(this.listeners[e][r]=this.listeners[e][r].filter(i=>i!=a))}init(e){e.baseURL&&(this.baseURL=e.baseURL)}};function f(t,e="/"){return(t.substring(0,e.length)==e||e[e.length-1]=="/"&&t.length==e.length-1&&t==e.substring(0,t.length))&&(t=t.substring(e.length)),t[0]!="/"&&t[0]!="#"&&(t="/"+t),t}function R(t,e){return t=f(t,e),e[e.length-1]==="/"&&t[0]==="/"&&(t=t.substring(1)),t[0]=="#"?t:e+t}function j(t,e=!1){return e?new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)")+"(\\?|$)"):new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)"))}function ee(t,e,r=!1){let a=Object.keys(t),i=/:(\w+|\*)/g;for(let s of a){let n=[],l=[];do n=i.exec(s),n&&l.push(n[1]);while(n);e.push({match:j(s,r),params:l,action:t[s]})}return e}var x=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),this.app=e.app,this.$handlers=e.handlers||re,e.commands&&Object.assign(this,e.commands);let r=a=>{let i=te(a,this.$handlers);if(!i)return;if(!this[i.name]){console.error("simply.command: undefined command "+i.name,i.source);return}if(this[i.name].call(e.app,i.source,i.value)!==!0)return a.preventDefault(),a.stopPropagation(),!1};e.app.container.addEventListener("click",r),e.app.container.addEventListener("submit",r),e.app.container.addEventListener("change",r),e.app.container.addEventListener("input",r)}call(e,r,a){if(!this[e]){console.error("simply.command: undefined command "+e);return}return this[e].call(this.app,r,a)}action(e){console.warn("deprecated call to `this.commands.action`");let r=Array.from(arguments).slice();return r.shift(),this.app.actions[e](...r)}appendHandler(e){this.$handlers.push(e)}prependHandler(e){this.$handlers.unshift(e)}};function k(t={},e){if(e){let r=t;t=e,t.app=t}return new x(t)}function te(t,e){var r=t.target.closest("[data-simply-command]");if(r){for(let a of e)if(r.matches(a.match))return a.check(r,t)?{name:r.dataset.simplyCommand,source:r,value:a.get(r)}:null}return null}var re=[{match:"input,select,textarea",get:function(t){if(t.tagName==="SELECT"&&t.multiple){let e=[];for(let r of t.options)r.selected&&e.push(r.value);return e}return t.dataset.simplyValue||t.value},check:function(t,e){return e.type=="change"||t.dataset.simplyImmediate&&e.type=="input"}},{match:"a,button",get:function(t){return t.dataset.simplyValue||t.href||t.value},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}},{match:"form",get:function(t){let e={};for(let r of Array.from(t.elements)){if(r.tagName=="INPUT"&&(r.type=="checkbox"||r.type=="radio")&&!r.checked)return;e[r.name]&&!Array.isArray(e[r.name])&&(e[r.name]=[e[r.name]]),Array.isArray(e[r.name])?e[r.name].push(r.value):e[r.name]=r.value}return e},check:function(t,e){return e.type=="submit"}},{match:"*",get:function(t){return t.dataset.simplyValue},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}}];var d=Object.freeze({Compose:229,Control:17,Meta:224,Alt:18,Shift:16}),E=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),Object.assign(this,e.keys);let r=a=>{if(a.isComposing||a.keyCode===d.Compose||a.defaultPrevented||!a.target)return;let i="default";a.target.closest("[data-simply-keyboard]")&&(i=a.target.closest("[data-simply-keyboard]").dataset.simplyKeyboard);let s=[];a.ctrlKey&&a.keyCode!=d.Control&&s.push("Control"),a.metaKey&&a.keyCode!=d.Meta&&s.push("Meta"),a.altKey&&a.keyCode!=d.Alt&&s.push("Alt"),a.shiftKey&&a.keyCode!=d.Shift&&s.push("Shift"),s.push(a.key.toLowerCase());let n=[],l=event.target.closest("[data-simply-keyboard]");for(;l;)n.push(l.dataset.simplyKeyboard),l=l.parentNode.closest("[data-simply-keyboard]");n.push("");let c,o,W=["+","-"];for(let Y in n){c=n[Y],c==""?o="default":(o=c,c+=".");for(let G of W){let h=s.join(G);if(this[o]&&typeof this[o][h]=="function"&&!this[o][h].call(e.app,a)){a.preventDefault();return}if(typeof this[o+h]=="function"&&!this[o+h].call(e.app,a)){a.preventDefault();return}if(this[i]&&this[i][h]){let y=e.app.container.querySelectorAll('[data-simply-accesskey="'+c+h+'"]');y.length&&(y.forEach(J=>J.click()),a.preventDefault())}}}};e.app.container.addEventListener("keydown",r)}};function v(t={},e){if(e){let r=t;t=e,t.app=t}return new E(t)}function w(t,e){if(e){let r=t;t=e,t.app=t}if(t.app){t.app.view=t.view||{};let r=()=>{let a=t.app.view,i=globalThis.editor.data.getDataPath(t.app.container||document.body);t.app.view=globalThis.editor.currentData[i],Object.assign(t.app.view,a)};return globalThis.editor&&globalThis.editor.currentData?r():document.addEventListener("simply-content-loaded",r),t.app.view}else return t.view}function A(t,...e){return e.map((a,i)=>`${t[i]}${a}`).join("")+t[t.length-1]}function q(t,...e){return A(t,...e)}var C=class{constructor(e={}){this.container=e.container||document.body,e.components&&U(e,e.components);for(let r in e)switch(r){case"html":for(let s in e.html){let n=document.createElement("div");n.innerHTML=e.html[s];let l=this.container.querySelector("template#"+s);l?l.content.replaceChildren(...n.children):(l=document.createElement("template"),l.id=s,l.content.append(...n.children),this.container.appendChild(l))}break;case"css":for(let s in e.css){let n=this.container.querySelector("style#"+s);n||(n=document.createElement("style"),n.id=s,this.container.appendChild(n)),n.innerHTML=e.css[s]}break;case"commands":this.commands=k({app:this,container:this.container,commands:e.commands});break;case"keys":case"keyboard":this.keys=v({app:this,keys:e.keys});break;case"root":case"baseURL":this.baseURL=e[r];break;case"routes":this.routes=g({app:this,routes:e.routes});break;case"actions":this.actions=b({app:this,actions:e.actions}),this.action=function(s){console.warn("deprecated call to `this.action`");let n=Array.from(arguments).slice();return n.shift(),this.actions[s](...n)};break;case"view":this.view=w({app:this,view:e.view});break;case"hooks":let a={get:(s,n)=>{if(s[n])return typeof s[n]=="function"?new Proxy(s[n],i):s[n]&&typeof s[n]=="object"?new Proxy(s[n],a):s[n]}},i={apply:(s,n,l)=>s.apply(this,l)};this[r]=new Proxy(e[r],a);break;default:console.log('simply.app: unknown initialization option "'+r+'", added as-is'),this[r]=e[r];break}}get app(){return this}async start(){if(this.components)for(let e in this.components)this.components[e].hooks?.start&&await this.components[e].hooks.start();this.hooks?.start&&await this.hooks.start(),this.routes&&(this.baseURL&&this.routes.init({baseURL:this.baseURL}),this.routes.handleEvents(),globalThis.setTimeout(()=>{this.routes.has(globalThis.location?.hash)?this.routes.match(globalThis.location.hash):this.routes.match(globalThis.location?.pathname+globalThis.location?.hash)}))}};function H(t={}){return new C(t)}globalThis.html||(globalThis.html=A);globalThis.css||(globalThis.css=q);function M(t,e){for(let r in e)switch(typeof e[r]){case"object":if(!e[r])continue;t[r]?M(t[r],e[r]):t[r]=e[r];break;default:t[r]=e[r]}}function U(t,e){for(let r in e){let a=e[r];a.components&&U(t,a.components),t.components[r]=a;for(let i in a)switch(i){case"hooks":case"components":break;default:t[i]||(t[i]=Object.create(null)),M(t[i],a[i]);break}}}function ae(t,e){let r=0;return()=>{let a=arguments;r||(r=globalThis.setTimeout(()=>{t.apply(this,a),r=0},e))}}var ne=globalThis.requestIdleCallback?t=>{globalThis.requestIdleCallback(t,{timeout:500})}:globalThis.requestAnimationFrame;function I(t,e){let r=new URL(t,e);return m.cacheBuster&&r.searchParams.set("cb",m.cacheBuster),r.href}var B,se={},S=globalThis.document.querySelector("head"),K=globalThis.document.currentScript,O,$;K?$=K.src:(O=(()=>{var t=document.getElementsByTagName("script"),e=t.length-1,r=t[e];return()=>r?.src})(),$=O());var ie=async()=>new Promise(function(t){var e=globalThis.document.createElement("script");e.src="https://cdn.jsdelivr.net/gh/simplyedit/simplyview/dist/simply.include.next.js",e.async=!1,globalThis.document.addEventListener("simply-include-next",()=>{S.removeChild(e),t()},{once:!0,passive:!0}),S.appendChild(e)}),L=[],m={cacheBuster:null,scripts:(t,e)=>{let r=t.slice(),a=()=>{let i=r.shift();if(!i)return;let s=[].map.call(i.attributes,l=>l.name),n=globalThis.document.createElement("script");for(let l of s)n.setAttribute(l,i.getAttribute(l));if(n.removeAttribute("data-simply-location"),!n.src)n.innerHTML=i.innerHTML,ie().then(()=>{let l=L[i.dataset.simplyLocation];l.parentNode.insertBefore(n,l),l.parentNode.removeChild(l),a()});else{n.src=I(n.src,e),!n.hasAttribute("async")&&!n.hasAttribute("defer")&&(n.async=!1);let l=L[i.dataset.simplyLocation];l.parentNode.insertBefore(n,l),l.parentNode.removeChild(l),se[n.src]=!0,a()}};r.length&&a()},html:(t,e)=>{let r=globalThis.document.createRange().createContextualFragment(t),a=r.querySelectorAll('link[rel="stylesheet"],style');for(let n of a)n.href&&(n.href=I(n.href,e.href)),S.appendChild(n);let i=globalThis.document.createDocumentFragment(),s=r.querySelectorAll("script");if(s.length){for(let n of s){let l=globalThis.document.createComment(n.src||"inline script");n.parentNode.insertBefore(l,n),n.dataset.simplyLocation=L.length,L.push(l),i.appendChild(n)}globalThis.setTimeout(function(){m.scripts(Array.from(i.children),e?e.href:globalThis.location.href)},10)}e.parentNode.insertBefore(r,e||null)}},F={},le=async t=>{let e=[].reduce.call(t,(r,a)=>(a.rel=="simply-include-once"&&F[a.href]?a.parentNode.removeChild(a):(F[a.href]=!0,a.rel="simply-include-loading",r.push(a)),r),[]);for(let r of e){if(!r.href)return;let a=await fetch(r.href);if(!a.ok){console.log("simply-include: failed to load "+r.href);continue}console.log("simply-include: loaded "+r.href);let i=await a.text();m.html(i,r),r.parentNode.removeChild(r)}},_=ae(()=>{ne(()=>{var t=globalThis.document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');t.length&&le(t)})}),ce=()=>{B=new MutationObserver(_),B.observe(globalThis.document,{subtree:!0,childList:!0})};ce();_();var p={get(t,e){return typeof e!="string"?e:(e&&e.split(".").reduce(function(r,a){return r&&r[a]?r[a]:null},t),t)},set:function(t,e,r){let a=p.get(t,p.parent(e));a[p.pop(e)]=r},pop:function(t){return t.split(".").pop()},push:function(t,e){return(t?t+".":"")+e},parent:function(t,e){let r=e.split(".");return r.pop(),r.join(".")},parents:function(t,e){let r=[];for(;e;)e=p.parent(e),r.unshift(e)}},V=p;var N=class extends HTMLElement{constructor(){super();let e=this.getAttribute("rel"),r=document.getElementById(e);if(r){let a=r.content.cloneNode(!0);for(let i of a.childNodes){let s=i.cloneNode(!0);s.nodeType==document.ELEMENT_NODE&&s.querySelectorAll("template").forEach(function(n){n.setAttribute("simply-render","")}),this.parentNode.insertBefore(s,this)}this.parentNode.removeChild(this)}}};customElements.get("simply-render")||customElements.define("simply-render",N);var z={activate:P,action:b,app:H,command:k,include:m,key:v,path:V,route:g,view:w};globalThis.simply=z;var Ue=z;})();
|
|
2
2
|
//# sourceMappingURL=simply.everything.min.js.map
|