livereload-morph 0.1.5 → 0.2.0
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/README.md +22 -0
- package/dist/livereload-morph.cjs +53 -2
- package/dist/livereload-morph.esm.js +53 -2
- package/dist/livereload-morph.js +53 -2
- package/dist/livereload-morph.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,6 +100,27 @@ The following is preserved automatically during HTML morphs:
|
|
|
100
100
|
|
|
101
101
|
For best results, add IDs to form elements. Without IDs, idiomorph may recreate elements instead of morphing them.
|
|
102
102
|
|
|
103
|
+
### Declarative Shadow DOM
|
|
104
|
+
|
|
105
|
+
livereload-morph supports [declarative shadow DOM](https://developer.chrome.com/docs/css-ui/declarative-shadow-dom). When a `<template shadowrootmode="open">` is morphed, the library detects it and updates the shadow root content accordingly.
|
|
106
|
+
|
|
107
|
+
```html
|
|
108
|
+
<div id="my-component">
|
|
109
|
+
<template shadowrootmode="open">
|
|
110
|
+
<style>p { color: blue; }</style>
|
|
111
|
+
<p>Shadow content that will be live-reloaded</p>
|
|
112
|
+
</template>
|
|
113
|
+
</div>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
All standard declarative shadow DOM attributes are supported:
|
|
117
|
+
- `shadowrootmode` - "open" or "closed"
|
|
118
|
+
- `shadowrootdelegatesfocus` - delegates focus to first focusable element
|
|
119
|
+
- `shadowrootclonable` - allows cloning via `cloneNode()`
|
|
120
|
+
- `shadowrootserializable` - allows serialization via `getHTML()`
|
|
121
|
+
|
|
122
|
+
Set `morphShadowDOM: false` to skip this processing (the `<template>` will remain in the light DOM after morph, and no shadow root updates will occur).
|
|
123
|
+
|
|
103
124
|
## All Options
|
|
104
125
|
|
|
105
126
|
| Option | Type | Default | Description |
|
|
@@ -109,6 +130,7 @@ For best results, add IDs to form elements. Without IDs, idiomorph may recreate
|
|
|
109
130
|
| `path` | string | 'livereload' | WebSocket path |
|
|
110
131
|
| `https` | boolean | false | Use secure WebSocket (wss://) |
|
|
111
132
|
| `morphHTML` | boolean | true | Enable HTML morphing |
|
|
133
|
+
| `morphShadowDOM` | boolean | true | Process declarative shadow DOM templates during morph |
|
|
112
134
|
| `verbose` | boolean | false | Enable console logging |
|
|
113
135
|
| `importCacheWaitPeriod` | number | 200 | Legacy WebKit @import workaround delay. Set to 0 to disable |
|
|
114
136
|
| `mindelay` | number | 1000 | Min reconnection delay (ms) |
|
|
@@ -276,6 +276,7 @@ class Options {
|
|
|
276
276
|
this.maxdelay = 60000;
|
|
277
277
|
this.handshake_timeout = 5000;
|
|
278
278
|
this.morphHTML = true;
|
|
279
|
+
this.morphShadowDOM = true;
|
|
279
280
|
this.verbose = false;
|
|
280
281
|
this.importCacheWaitPeriod = 200;
|
|
281
282
|
}
|
|
@@ -318,6 +319,25 @@ Options.extract = function(document2) {
|
|
|
318
319
|
return options;
|
|
319
320
|
}
|
|
320
321
|
}
|
|
322
|
+
for (const script of scripts) {
|
|
323
|
+
const src = script.src || "";
|
|
324
|
+
if (src.includes("livereload-morph")) {
|
|
325
|
+
const queryIndex = src.indexOf("?");
|
|
326
|
+
if (queryIndex !== -1) {
|
|
327
|
+
const queryString = src.slice(queryIndex + 1);
|
|
328
|
+
const params = new URLSearchParams(queryString);
|
|
329
|
+
const host = params.get("host");
|
|
330
|
+
if (host) {
|
|
331
|
+
const options = new Options;
|
|
332
|
+
options.host = host;
|
|
333
|
+
for (const [key, value] of params.entries()) {
|
|
334
|
+
options.set(key, value);
|
|
335
|
+
}
|
|
336
|
+
return options;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
321
341
|
return null;
|
|
322
342
|
};
|
|
323
343
|
|
|
@@ -1105,7 +1125,37 @@ class Morpher {
|
|
|
1105
1125
|
}
|
|
1106
1126
|
},
|
|
1107
1127
|
callbacks: {
|
|
1108
|
-
|
|
1128
|
+
afterNodeMorphed: (oldNode) => {
|
|
1129
|
+
if (options.morphShadowDOM === false)
|
|
1130
|
+
return;
|
|
1131
|
+
if (oldNode.children) {
|
|
1132
|
+
for (const child of oldNode.children) {
|
|
1133
|
+
if (child.tagName === "TEMPLATE" && (child.hasAttribute("shadowrootmode") || child.hasAttribute("shadowroot"))) {
|
|
1134
|
+
const shadowOptions = {
|
|
1135
|
+
mode: child.getAttribute("shadowrootmode") || child.getAttribute("shadowroot") || "open"
|
|
1136
|
+
};
|
|
1137
|
+
if (child.hasAttribute("shadowrootdelegatesfocus")) {
|
|
1138
|
+
shadowOptions.delegatesFocus = true;
|
|
1139
|
+
}
|
|
1140
|
+
if (child.hasAttribute("shadowrootclonable")) {
|
|
1141
|
+
shadowOptions.clonable = true;
|
|
1142
|
+
}
|
|
1143
|
+
if (child.hasAttribute("shadowrootserializable")) {
|
|
1144
|
+
shadowOptions.serializable = true;
|
|
1145
|
+
}
|
|
1146
|
+
let shadow = oldNode.shadowRoot;
|
|
1147
|
+
if (!shadow) {
|
|
1148
|
+
shadow = oldNode.attachShadow(shadowOptions);
|
|
1149
|
+
}
|
|
1150
|
+
shadow.innerHTML = "";
|
|
1151
|
+
shadow.appendChild(child.content.cloneNode(true));
|
|
1152
|
+
child.remove();
|
|
1153
|
+
break;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
},
|
|
1158
|
+
beforeAttributeUpdated: (attributeName, node) => {
|
|
1109
1159
|
if (node.tagName === "INPUT" || node.tagName === "TEXTAREA" || node.tagName === "SELECT") {
|
|
1110
1160
|
if (attributeName === "value" || attributeName === "checked") {
|
|
1111
1161
|
return false;
|
|
@@ -1444,7 +1494,8 @@ class LiveMorph {
|
|
|
1444
1494
|
liveCSS: message.liveCSS != null ? message.liveCSS : true,
|
|
1445
1495
|
liveImg: message.liveImg != null ? message.liveImg : true,
|
|
1446
1496
|
reloadMissingCSS: message.reloadMissingCSS != null ? message.reloadMissingCSS : true,
|
|
1447
|
-
morphHTML: this.options.morphHTML
|
|
1497
|
+
morphHTML: this.options.morphHTML,
|
|
1498
|
+
morphShadowDOM: this.options.morphShadowDOM
|
|
1448
1499
|
};
|
|
1449
1500
|
this.log(`Reload options: ${JSON.stringify(options)}`);
|
|
1450
1501
|
return this.morpher.reload(message.path, options);
|
|
@@ -241,6 +241,7 @@ class Options {
|
|
|
241
241
|
this.maxdelay = 60000;
|
|
242
242
|
this.handshake_timeout = 5000;
|
|
243
243
|
this.morphHTML = true;
|
|
244
|
+
this.morphShadowDOM = true;
|
|
244
245
|
this.verbose = false;
|
|
245
246
|
this.importCacheWaitPeriod = 200;
|
|
246
247
|
}
|
|
@@ -283,6 +284,25 @@ Options.extract = function(document2) {
|
|
|
283
284
|
return options;
|
|
284
285
|
}
|
|
285
286
|
}
|
|
287
|
+
for (const script of scripts) {
|
|
288
|
+
const src = script.src || "";
|
|
289
|
+
if (src.includes("livereload-morph")) {
|
|
290
|
+
const queryIndex = src.indexOf("?");
|
|
291
|
+
if (queryIndex !== -1) {
|
|
292
|
+
const queryString = src.slice(queryIndex + 1);
|
|
293
|
+
const params = new URLSearchParams(queryString);
|
|
294
|
+
const host = params.get("host");
|
|
295
|
+
if (host) {
|
|
296
|
+
const options = new Options;
|
|
297
|
+
options.host = host;
|
|
298
|
+
for (const [key, value] of params.entries()) {
|
|
299
|
+
options.set(key, value);
|
|
300
|
+
}
|
|
301
|
+
return options;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
286
306
|
return null;
|
|
287
307
|
};
|
|
288
308
|
|
|
@@ -1070,7 +1090,37 @@ class Morpher {
|
|
|
1070
1090
|
}
|
|
1071
1091
|
},
|
|
1072
1092
|
callbacks: {
|
|
1073
|
-
|
|
1093
|
+
afterNodeMorphed: (oldNode) => {
|
|
1094
|
+
if (options.morphShadowDOM === false)
|
|
1095
|
+
return;
|
|
1096
|
+
if (oldNode.children) {
|
|
1097
|
+
for (const child of oldNode.children) {
|
|
1098
|
+
if (child.tagName === "TEMPLATE" && (child.hasAttribute("shadowrootmode") || child.hasAttribute("shadowroot"))) {
|
|
1099
|
+
const shadowOptions = {
|
|
1100
|
+
mode: child.getAttribute("shadowrootmode") || child.getAttribute("shadowroot") || "open"
|
|
1101
|
+
};
|
|
1102
|
+
if (child.hasAttribute("shadowrootdelegatesfocus")) {
|
|
1103
|
+
shadowOptions.delegatesFocus = true;
|
|
1104
|
+
}
|
|
1105
|
+
if (child.hasAttribute("shadowrootclonable")) {
|
|
1106
|
+
shadowOptions.clonable = true;
|
|
1107
|
+
}
|
|
1108
|
+
if (child.hasAttribute("shadowrootserializable")) {
|
|
1109
|
+
shadowOptions.serializable = true;
|
|
1110
|
+
}
|
|
1111
|
+
let shadow = oldNode.shadowRoot;
|
|
1112
|
+
if (!shadow) {
|
|
1113
|
+
shadow = oldNode.attachShadow(shadowOptions);
|
|
1114
|
+
}
|
|
1115
|
+
shadow.innerHTML = "";
|
|
1116
|
+
shadow.appendChild(child.content.cloneNode(true));
|
|
1117
|
+
child.remove();
|
|
1118
|
+
break;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
},
|
|
1123
|
+
beforeAttributeUpdated: (attributeName, node) => {
|
|
1074
1124
|
if (node.tagName === "INPUT" || node.tagName === "TEXTAREA" || node.tagName === "SELECT") {
|
|
1075
1125
|
if (attributeName === "value" || attributeName === "checked") {
|
|
1076
1126
|
return false;
|
|
@@ -1409,7 +1459,8 @@ class LiveMorph {
|
|
|
1409
1459
|
liveCSS: message.liveCSS != null ? message.liveCSS : true,
|
|
1410
1460
|
liveImg: message.liveImg != null ? message.liveImg : true,
|
|
1411
1461
|
reloadMissingCSS: message.reloadMissingCSS != null ? message.reloadMissingCSS : true,
|
|
1412
|
-
morphHTML: this.options.morphHTML
|
|
1462
|
+
morphHTML: this.options.morphHTML,
|
|
1463
|
+
morphShadowDOM: this.options.morphShadowDOM
|
|
1413
1464
|
};
|
|
1414
1465
|
this.log(`Reload options: ${JSON.stringify(options)}`);
|
|
1415
1466
|
return this.morpher.reload(message.path, options);
|
package/dist/livereload-morph.js
CHANGED
|
@@ -276,6 +276,7 @@
|
|
|
276
276
|
this.maxdelay = 60000;
|
|
277
277
|
this.handshake_timeout = 5000;
|
|
278
278
|
this.morphHTML = true;
|
|
279
|
+
this.morphShadowDOM = true;
|
|
279
280
|
this.verbose = false;
|
|
280
281
|
this.importCacheWaitPeriod = 200;
|
|
281
282
|
}
|
|
@@ -318,6 +319,25 @@
|
|
|
318
319
|
return options;
|
|
319
320
|
}
|
|
320
321
|
}
|
|
322
|
+
for (const script of scripts) {
|
|
323
|
+
const src = script.src || "";
|
|
324
|
+
if (src.includes("livereload-morph")) {
|
|
325
|
+
const queryIndex = src.indexOf("?");
|
|
326
|
+
if (queryIndex !== -1) {
|
|
327
|
+
const queryString = src.slice(queryIndex + 1);
|
|
328
|
+
const params = new URLSearchParams(queryString);
|
|
329
|
+
const host = params.get("host");
|
|
330
|
+
if (host) {
|
|
331
|
+
const options = new Options;
|
|
332
|
+
options.host = host;
|
|
333
|
+
for (const [key, value] of params.entries()) {
|
|
334
|
+
options.set(key, value);
|
|
335
|
+
}
|
|
336
|
+
return options;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
321
341
|
return null;
|
|
322
342
|
};
|
|
323
343
|
|
|
@@ -1105,7 +1125,37 @@
|
|
|
1105
1125
|
}
|
|
1106
1126
|
},
|
|
1107
1127
|
callbacks: {
|
|
1108
|
-
|
|
1128
|
+
afterNodeMorphed: (oldNode) => {
|
|
1129
|
+
if (options.morphShadowDOM === false)
|
|
1130
|
+
return;
|
|
1131
|
+
if (oldNode.children) {
|
|
1132
|
+
for (const child of oldNode.children) {
|
|
1133
|
+
if (child.tagName === "TEMPLATE" && (child.hasAttribute("shadowrootmode") || child.hasAttribute("shadowroot"))) {
|
|
1134
|
+
const shadowOptions = {
|
|
1135
|
+
mode: child.getAttribute("shadowrootmode") || child.getAttribute("shadowroot") || "open"
|
|
1136
|
+
};
|
|
1137
|
+
if (child.hasAttribute("shadowrootdelegatesfocus")) {
|
|
1138
|
+
shadowOptions.delegatesFocus = true;
|
|
1139
|
+
}
|
|
1140
|
+
if (child.hasAttribute("shadowrootclonable")) {
|
|
1141
|
+
shadowOptions.clonable = true;
|
|
1142
|
+
}
|
|
1143
|
+
if (child.hasAttribute("shadowrootserializable")) {
|
|
1144
|
+
shadowOptions.serializable = true;
|
|
1145
|
+
}
|
|
1146
|
+
let shadow = oldNode.shadowRoot;
|
|
1147
|
+
if (!shadow) {
|
|
1148
|
+
shadow = oldNode.attachShadow(shadowOptions);
|
|
1149
|
+
}
|
|
1150
|
+
shadow.innerHTML = "";
|
|
1151
|
+
shadow.appendChild(child.content.cloneNode(true));
|
|
1152
|
+
child.remove();
|
|
1153
|
+
break;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
},
|
|
1158
|
+
beforeAttributeUpdated: (attributeName, node) => {
|
|
1109
1159
|
if (node.tagName === "INPUT" || node.tagName === "TEXTAREA" || node.tagName === "SELECT") {
|
|
1110
1160
|
if (attributeName === "value" || attributeName === "checked") {
|
|
1111
1161
|
return false;
|
|
@@ -1444,7 +1494,8 @@
|
|
|
1444
1494
|
liveCSS: message.liveCSS != null ? message.liveCSS : true,
|
|
1445
1495
|
liveImg: message.liveImg != null ? message.liveImg : true,
|
|
1446
1496
|
reloadMissingCSS: message.reloadMissingCSS != null ? message.reloadMissingCSS : true,
|
|
1447
|
-
morphHTML: this.options.morphHTML
|
|
1497
|
+
morphHTML: this.options.morphHTML,
|
|
1498
|
+
morphShadowDOM: this.options.morphShadowDOM
|
|
1448
1499
|
};
|
|
1449
1500
|
this.log(`Reload options: ${JSON.stringify(options)}`);
|
|
1450
1501
|
return this.morpher.reload(message.path, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var{defineProperty:g,getOwnPropertyNames:l,getOwnPropertyDescriptor:o}=Object,n=Object.prototype.hasOwnProperty;var u=new WeakMap,t=(_)=>{var $=u.get(_),X;if($)return $;if($=g({},"__esModule",{value:!0}),_&&typeof _==="object"||typeof _==="function")l(_).map((K)=>!n.call($,K)&&g($,K,{get:()=>_[K],enumerable:!(X=o(_,K))||X.enumerable}));return u.set(_,$),$};var e=(_,$)=>{for(var X in $)g(_,X,{get:$[X],enumerable:!0,configurable:!0,set:(K)=>$[X]=()=>K})};var J_={};e(J_,{default:()=>G_});var p="http://livereload.com/protocols/official-6",m="http://livereload.com/protocols/official-7";class M{constructor(_,$){this.message=`LiveReload protocol error (${_}) after receiving data: "${$}".`}}class C{constructor(_){this.handlers=_,this.reset()}reset(){this.protocol=null}process(_){try{let $;if(!this.protocol){if(_.match(new RegExp("^!!ver:([\\d.]+)$")))this.protocol=6;else if($=this._parseMessage(_,["hello"]))if(!$.protocols.length)throw new M("no protocols specified in handshake message");else if(Array.from($.protocols).includes("http://livereload.com/protocols/official-7"))this.protocol=7;else if(Array.from($.protocols).includes("http://livereload.com/protocols/official-6"))this.protocol=6;else throw new M("no supported protocols found");return this.handlers.connected(this.protocol)}if(this.protocol===6){if($=JSON.parse(_),!$.length)throw new M("protocol 6 messages must be arrays");let[X,K]=Array.from($);if(X!=="refresh")throw new M("unknown protocol 6 command");return this.handlers.message({command:"reload",path:K.path,liveCSS:K.apply_css_live!=null?K.apply_css_live:!0})}return $=this._parseMessage(_,["reload","alert"]),this.handlers.message($)}catch($){if($ instanceof M)return this.handlers.error($);throw $}}_parseMessage(_,$){let X;try{X=JSON.parse(_)}catch(K){throw new M("unparsable JSON",_)}if(!X.command)throw new M('missing "command" key',_);if(!$.includes(X.command))throw new M(`invalid command '${X.command}', only valid commands are: ${$.join(", ")})`,_);return X}}var __="1.0.0";class N{constructor(_,$,X,K){this.options=_,this.WebSocket=$,this.Timer=X,this.handlers=K;let Y=this.options.path?`${this.options.path}`:"livereload",Z=this.options.port?`:${this.options.port}`:"";this._uri=`ws${this.options.https?"s":""}://${this.options.host}${Z}/${Y}`,this._nextDelay=this.options.mindelay,this._connectionDesired=!1,this.protocol=0,this.protocolParser=new C({connected:(V)=>{return this.protocol=V,this._handshakeTimeout.stop(),this._nextDelay=this.options.mindelay,this._disconnectionReason="broken",this.handlers.connected(this.protocol)},error:(V)=>{return this.handlers.error(V),this._closeOnError()},message:(V)=>{return this.handlers.message(V)}}),this._handshakeTimeout=new this.Timer(()=>{if(!this._isSocketConnected())return;return this._disconnectionReason="handshake-timeout",this.socket.close()}),this._reconnectTimer=new this.Timer(()=>{if(!this._connectionDesired)return;return this.connect()}),this.connect()}_isSocketConnected(){return this.socket&&this.socket.readyState===this.WebSocket.OPEN}connect(){if(this._connectionDesired=!0,this._isSocketConnected())return;this._reconnectTimer.stop(),this._disconnectionReason="cannot-connect",this.protocolParser.reset(),this.handlers.connecting(),this.socket=new this.WebSocket(this._uri),this.socket.onopen=(_)=>this._onopen(_),this.socket.onclose=(_)=>this._onclose(_),this.socket.onmessage=(_)=>this._onmessage(_),this.socket.onerror=(_)=>this._onerror(_)}disconnect(){if(this._connectionDesired=!1,this._reconnectTimer.stop(),!this._isSocketConnected())return;return this._disconnectionReason="manual",this.socket.close()}_scheduleReconnection(){if(!this._connectionDesired)return;if(!this._reconnectTimer.running)this._reconnectTimer.start(this._nextDelay),this._nextDelay=Math.min(this.options.maxdelay,this._nextDelay*2)}sendCommand(_){if(!this.protocol)return;return this._sendCommand(_)}_sendCommand(_){return this.socket.send(JSON.stringify(_))}_closeOnError(){return this._handshakeTimeout.stop(),this._disconnectionReason="error",this.socket.close()}_onopen(_){this.handlers.socketConnected(),this._disconnectionReason="handshake-failed";let $={command:"hello",protocols:[p,m]};return $.ver=__,this._sendCommand($),this._handshakeTimeout.start(this.options.handshake_timeout)}_onclose(_){return this.protocol=0,this.handlers.disconnected(this._disconnectionReason,this._nextDelay),this._scheduleReconnection()}_onerror(_){}_onmessage(_){return this.protocolParser.process(_.data)}}class k{constructor(_){this.func=_,this.running=!1,this.id=null,this._handler=()=>{return this.running=!1,this.id=null,this.func()}}start(_){if(this.running)clearTimeout(this.id);this.id=setTimeout(this._handler,_),this.running=!0}stop(){if(this.running)clearTimeout(this.id),this.running=!1,this.id=null}}k.start=(_,$)=>setTimeout($,_);class S{constructor(){this.https=!1,this.host=null;let _=35729;Object.defineProperty(this,"port",{get(){return _},set($){_=$?isNaN($)?$:+$:""}}),this.mindelay=1000,this.maxdelay=60000,this.handshake_timeout=5000,this.morphHTML=!0,this.verbose=!1,this.importCacheWaitPeriod=200}set(_,$){if(typeof $>"u")return;if(!isNaN(+$))$=+$;if($==="true")$=!0;else if($==="false")$=!1;this[_]=$}}S.extract=function(_){let $=_.defaultView||window;if($&&$.LiveMorphOptions){let K=new S;for(let[Y,Z]of Object.entries($.LiveMorphOptions))K.set(Y,Z);return K}let X=Array.from(_.getElementsByTagName("script"));for(let K of X){let Y=K.getAttribute("data-livereload-morph-host");if(Y){let Z=new S;Z.host=Y;let V=K.getAttribute("data-livereload-morph-port");if(V)Z.port=parseInt(V,10);let H=K.getAttribute("data-livereload-morph-verbose");if(H!==null)Z.verbose=H==="true";return Z}}return null};var c=function(){let _=()=>{},$={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:_,afterNodeAdded:_,beforeNodeMorphed:_,afterNodeMorphed:_,beforeNodeRemoved:_,afterNodeRemoved:_,beforeAttributeUpdated:_},head:{style:"merge",shouldPreserve:(j)=>j.getAttribute("im-preserve")==="true",shouldReAppend:(j)=>j.getAttribute("im-re-append")==="true",shouldRemove:_,afterHeadMorphed:_},restoreFocus:!0};function X(j,A,W={}){j=d(j);let B=x(A),T=r(j,B,W),q=Y(T,()=>{return H(T,j,B,(Q)=>{if(Q.morphStyle==="innerHTML")return Z(Q,j,B),Array.from(j.childNodes);else return K(Q,j,B)})});return T.pantry.remove(),q}function K(j,A,W){let B=x(A);return Z(j,B,W,A,A.nextSibling),Array.from(B.childNodes)}function Y(j,A){if(!j.config.restoreFocus)return A();let W=document.activeElement;if(!(W instanceof HTMLInputElement||W instanceof HTMLTextAreaElement))return A();let{id:B,selectionStart:T,selectionEnd:q}=W,Q=A();if(B&&B!==document.activeElement?.getAttribute("id"))W=j.target.querySelector(`[id="${B}"]`),W?.focus();if(W&&!W.selectionEnd&&q)W.setSelectionRange(T,q);return Q}let Z=function(){function j(G,J,D,z=null,R=null){if(J instanceof HTMLTemplateElement&&D instanceof HTMLTemplateElement)J=J.content,D=D.content;z||=J.firstChild;for(let F of D.childNodes){if(z&&z!=R){let U=W(G,F,z,R);if(U){if(U!==z)T(G,z,U);V(U,F,G),z=U.nextSibling;continue}}if(F instanceof Element){let U=F.getAttribute("id");if(G.persistentIds.has(U)){let I=q(J,U,z,G);V(I,F,G),z=I.nextSibling;continue}}let L=A(J,F,z,G);if(L)z=L.nextSibling}while(z&&z!=R){let F=z;z=z.nextSibling,B(G,F)}}function A(G,J,D,z){if(z.callbacks.beforeNodeAdded(J)===!1)return null;if(z.idMap.has(J)){let R=document.createElement(J.tagName);return G.insertBefore(R,D),V(R,J,z),z.callbacks.afterNodeAdded(R),R}else{let R=document.importNode(J,!0);return G.insertBefore(R,D),z.callbacks.afterNodeAdded(R),R}}let W=function(){function G(z,R,F,L){let U=null,I=R.nextSibling,w=0,f=F;while(f&&f!=L){if(D(f,R)){if(J(z,f,R))return f;if(U===null){if(!z.idMap.has(f))U=f}}if(U===null&&I&&D(f,I)){if(w++,I=I.nextSibling,w>=2)U=void 0}if(z.activeElementAndParents.includes(f))break;f=f.nextSibling}return U||null}function J(z,R,F){let L=z.idMap.get(R),U=z.idMap.get(F);if(!U||!L)return!1;for(let I of L)if(U.has(I))return!0;return!1}function D(z,R){let F=z,L=R;return F.nodeType===L.nodeType&&F.tagName===L.tagName&&(!F.getAttribute?.("id")||F.getAttribute?.("id")===L.getAttribute?.("id"))}return G}();function B(G,J){if(G.idMap.has(J))O(G.pantry,J,null);else{if(G.callbacks.beforeNodeRemoved(J)===!1)return;J.parentNode?.removeChild(J),G.callbacks.afterNodeRemoved(J)}}function T(G,J,D){let z=J;while(z&&z!==D){let R=z;z=z.nextSibling,B(G,R)}return z}function q(G,J,D,z){let R=z.target.getAttribute?.("id")===J&&z.target||z.target.querySelector(`[id="${J}"]`)||z.pantry.querySelector(`[id="${J}"]`);return Q(R,z),O(G,R,D),R}function Q(G,J){let D=G.getAttribute("id");while(G=G.parentNode){let z=J.idMap.get(G);if(z){if(z.delete(D),!z.size)J.idMap.delete(G)}}}function O(G,J,D){if(G.moveBefore)try{G.moveBefore(J,D)}catch(z){G.insertBefore(J,D)}else G.insertBefore(J,D)}return j}(),V=function(){function j(Q,O,G){if(G.ignoreActive&&Q===document.activeElement)return null;if(G.callbacks.beforeNodeMorphed(Q,O)===!1)return Q;if(Q instanceof HTMLHeadElement&&G.head.ignore);else if(Q instanceof HTMLHeadElement&&G.head.style!=="morph")y(Q,O,G);else if(A(Q,O,G),!q(Q,G))Z(G,Q,O);return G.callbacks.afterNodeMorphed(Q,O),Q}function A(Q,O,G){let J=O.nodeType;if(J===1){let D=Q,z=O,R=D.attributes,F=z.attributes;for(let L of F){if(T(L.name,D,"update",G))continue;if(D.getAttribute(L.name)!==L.value)D.setAttribute(L.name,L.value)}for(let L=R.length-1;0<=L;L--){let U=R[L];if(!U)continue;if(!z.hasAttribute(U.name)){if(T(U.name,D,"remove",G))continue;D.removeAttribute(U.name)}}if(!q(D,G))W(D,z,G)}if(J===8||J===3){if(Q.nodeValue!==O.nodeValue)Q.nodeValue=O.nodeValue}}function W(Q,O,G){if(Q instanceof HTMLInputElement&&O instanceof HTMLInputElement&&O.type!=="file"){let J=O.value,D=Q.value;if(B(Q,O,"checked",G),B(Q,O,"disabled",G),!O.hasAttribute("value")){if(!T("value",Q,"remove",G))Q.value="",Q.removeAttribute("value")}else if(D!==J){if(!T("value",Q,"update",G))Q.setAttribute("value",J),Q.value=J}}else if(Q instanceof HTMLOptionElement&&O instanceof HTMLOptionElement)B(Q,O,"selected",G);else if(Q instanceof HTMLTextAreaElement&&O instanceof HTMLTextAreaElement){let J=O.value,D=Q.value;if(T("value",Q,"update",G))return;if(J!==D)Q.value=J;if(Q.firstChild&&Q.firstChild.nodeValue!==J)Q.firstChild.nodeValue=J}}function B(Q,O,G,J){let D=O[G],z=Q[G];if(D!==z){let R=T(G,Q,"update",J);if(!R)Q[G]=O[G];if(D){if(!R)Q.setAttribute(G,"")}else if(!T(G,Q,"remove",J))Q.removeAttribute(G)}}function T(Q,O,G,J){if(Q==="value"&&J.ignoreActiveValue&&O===document.activeElement)return!0;return J.callbacks.beforeAttributeUpdated(Q,O,G)===!1}function q(Q,O){return!!O.ignoreActiveValue&&Q===document.activeElement&&Q!==document.body}return j}();function H(j,A,W,B){if(j.head.block){let T=A.querySelector("head"),q=W.querySelector("head");if(T&&q){let Q=y(T,q,j);return Promise.all(Q).then(()=>{let O=Object.assign(j,{head:{block:!1,ignore:!0}});return B(O)})}}return B(j)}function y(j,A,W){let B=[],T=[],q=[],Q=[],O=new Map;for(let J of A.children)O.set(J.outerHTML,J);for(let J of j.children){let D=O.has(J.outerHTML),z=W.head.shouldReAppend(J),R=W.head.shouldPreserve(J);if(D||R)if(z)T.push(J);else O.delete(J.outerHTML),q.push(J);else if(W.head.style==="append"){if(z)T.push(J),Q.push(J)}else if(W.head.shouldRemove(J)!==!1)T.push(J)}Q.push(...O.values());let G=[];for(let J of Q){let D=document.createRange().createContextualFragment(J.outerHTML).firstChild;if(W.callbacks.beforeNodeAdded(D)!==!1){if("href"in D&&D.href||"src"in D&&D.src){let z,R=new Promise(function(F){z=F});D.addEventListener("load",function(){z()}),G.push(R)}j.appendChild(D),W.callbacks.afterNodeAdded(D),B.push(D)}}for(let J of T)if(W.callbacks.beforeNodeRemoved(J)!==!1)j.removeChild(J),W.callbacks.afterNodeRemoved(J);return W.head.afterHeadMorphed(j,{added:B,kept:q,removed:T}),G}let r=function(){function j(G,J,D){let{persistentIds:z,idMap:R}=Q(G,J),F=A(D),L=F.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(L))throw`Do not understand how to morph style ${L}`;return{target:G,newContent:J,config:F,morphStyle:L,ignoreActive:F.ignoreActive,ignoreActiveValue:F.ignoreActiveValue,restoreFocus:F.restoreFocus,idMap:R,persistentIds:z,pantry:W(),activeElementAndParents:B(G),callbacks:F.callbacks,head:F.head}}function A(G){let J=Object.assign({},$);return Object.assign(J,G),J.callbacks=Object.assign({},$.callbacks,G.callbacks),J.head=Object.assign({},$.head,G.head),J}function W(){let G=document.createElement("div");return G.hidden=!0,document.body.insertAdjacentElement("afterend",G),G}function B(G){let J=[],D=document.activeElement;if(D?.tagName!=="BODY"&&G.contains(D))while(D){if(J.push(D),D===G)break;D=D.parentElement}return J}function T(G){let J=Array.from(G.querySelectorAll("[id]"));if(G.getAttribute?.("id"))J.push(G);return J}function q(G,J,D,z){for(let R of z){let F=R.getAttribute("id");if(J.has(F)){let L=R;while(L){let U=G.get(L);if(U==null)U=new Set,G.set(L,U);if(U.add(F),L===D)break;L=L.parentElement}}}}function Q(G,J){let D=T(G),z=T(J),R=O(D,z),F=new Map;q(F,R,G,D);let L=J.__idiomorphRoot||J;return q(F,R,L,z),{persistentIds:R,idMap:F}}function O(G,J){let D=new Set,z=new Map;for(let{id:F,tagName:L}of G)if(z.has(F))D.add(F);else z.set(F,L);let R=new Set;for(let{id:F,tagName:L}of J)if(R.has(F))D.add(F);else if(z.get(F)===L)R.add(F);for(let F of D)R.delete(F);return R}return j}(),{normalizeElement:d,normalizeParent:x}=function(){let j=new WeakSet;function A(q){if(q instanceof Document)return q.documentElement;else return q}function W(q){if(q==null)return document.createElement("div");else if(typeof q==="string")return W(T(q));else if(j.has(q))return q;else if(q instanceof Node)if(q.parentNode)return new B(q);else{let Q=document.createElement("div");return Q.append(q),Q}else{let Q=document.createElement("div");for(let O of[...q])Q.append(O);return Q}}class B{constructor(q){this.originalNode=q,this.realParentNode=q.parentNode,this.previousSibling=q.previousSibling,this.nextSibling=q.nextSibling}get childNodes(){let q=[],Q=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;while(Q&&Q!=this.nextSibling)q.push(Q),Q=Q.nextSibling;return q}querySelectorAll(q){return this.childNodes.reduce((Q,O)=>{if(O instanceof Element){if(O.matches(q))Q.push(O);let G=O.querySelectorAll(q);for(let J=0;J<G.length;J++)Q.push(G[J])}return Q},[])}insertBefore(q,Q){return this.realParentNode.insertBefore(q,Q)}moveBefore(q,Q){return this.realParentNode.moveBefore(q,Q)}get __idiomorphRoot(){return this.originalNode}}function T(q){let Q=new DOMParser,O=q.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(O.match(/<\/html>/)||O.match(/<\/head>/)||O.match(/<\/body>/)){let G=Q.parseFromString(q,"text/html");if(O.match(/<\/html>/))return j.add(G),G;else{let J=G.firstChild;if(J)j.add(J);return J}}else{let J=Q.parseFromString("<body><template>"+q+"</template></body>","text/html").body.querySelector("template").content;return j.add(J),J}}return{normalizeElement:A,normalizeParent:W}}();return{morph:X,defaults:$}}();function s(_){let $="",X="",K=_.indexOf("#");if(K>=0)$=_.slice(K),_=_.slice(0,K);let Y=_.indexOf("??");if(Y>=0){if(Y+1!==_.lastIndexOf("?"))K=_.lastIndexOf("?")}else K=_.indexOf("?");if(K>=0)X=_.slice(K),_=_.slice(0,K);return{url:_,params:X,hash:$}}function P(_){if(!_)return"";let $;if({url:_}=s(_),_.indexOf("file://")===0)$=_.replace(new RegExp("^file://(localhost)?"),"");else $=_.replace(new RegExp("^([^:]+:)?//([^:/]+)(:\\d*)?/"),"/");return decodeURIComponent($)}function $_(_,$){if(_=_.replace(/^\/+/,"").toLowerCase(),$=$.replace(/^\/+/,"").toLowerCase(),_===$)return 1e4;let X=_.split(/\/|\\/).reverse(),K=$.split(/\/|\\/).reverse(),Y=Math.min(X.length,K.length),Z=0;while(Z<Y&&X[Z]===K[Z])++Z;return Z}function a(_,$,X=(K)=>K){let K={score:0};for(let Y of $){let Z=$_(_,X(Y));if(Z>K.score)K={object:Y,score:Z}}if(K.score===0)return null;return K}function b(_){let{url:$,params:X,hash:K}=s(_),Y=`livereload=${Date.now()}`;if(!X)return`${$}?${Y}${K}`;if(X.includes("livereload=")){let Z=X.replace(/([?&])livereload=\d+/,`$1${Y}`);return`${$}${Z}${K}`}return`${$}${X}&${Y}${K}`}function i(_,$=15000){return new Promise((X)=>{let K=!1,Y=()=>{if(K)return;K=!0,X()};_.onload=()=>{Y()};let Z=50,V=()=>{if(K)return;if(_.sheet){Y();return}setTimeout(V,Z)};setTimeout(V,Z),setTimeout(Y,$)})}class h{constructor(_,$,X,K=200){this.window=_,this.console=$,this.Timer=X,this.document=_.document,this.importCacheWaitPeriod=K}reload(_,$={}){let X=_.match(/\.css(?:\.map)?$/i),K=_.match(/\.(jpe?g|png|gif|svg|webp|ico)$/i),Y=_.match(/\.m?js$/i);if(X&&$.liveCSS)return this.reloadStylesheet(_,$);if(K&&$.liveImg)return this.reloadImages(_);if(Y)return this.reloadPage();if($.morphHTML)return this.morphHTML(_,$);this.reloadPage()}async morphHTML(_,$={}){try{let X=await fetch(this.window.location.href,{cache:"no-cache",headers:{"X-Live-Morph":"true"}});if(!X.ok)throw Error(`Fetch failed: ${X.status} ${X.statusText}`);let K=await X.text();K=K.replace(/<!DOCTYPE[^>]*>/i,"").trim(),c.morph(this.document.documentElement,K,{head:{style:"merge",shouldPreserve:(Y)=>{if(Y.tagName==="SCRIPT"&&Y.src)return Y.src.toLowerCase().includes("livereload-morph");return!1}},callbacks:{beforeAttributeUpdated:(Y,Z,V)=>{if(Z.tagName==="INPUT"||Z.tagName==="TEXTAREA"||Z.tagName==="SELECT"){if(Y==="value"||Y==="checked")return!1}if(Z.tagName==="DETAILS"&&Y==="open")return!1;return!0}}}),this.console.log("HTML morphed successfully")}catch(X){if(this.console.error(`Morph failed: ${X.message}`),$.fallbackToReload!==!1)this.console.log("Falling back to full page reload"),this.reloadPage()}}async reloadStylesheet(_,$={}){try{let X=Array.from(this.document.getElementsByTagName("link")).filter((Z)=>Z.rel&&Z.rel.match(/^stylesheet$/i)&&!Z.__LiveReload_pendingRemoval),K=[];for(let Z of Array.from(this.document.getElementsByTagName("style")))if(Z.sheet)this.collectImportedStylesheets(Z,Z.sheet,K);for(let Z of X)if(Z.sheet)this.collectImportedStylesheets(Z,Z.sheet,K);if(this.window.StyleFix&&this.document.querySelectorAll)for(let Z of Array.from(this.document.querySelectorAll("style[data-href]")))X.push(Z);this.console.log(`CSS reload: found ${X.length} LINKed stylesheets, ${K.length} @imported stylesheets`);let Y=a(_,X.concat(K),(Z)=>P(Z.href||this.linkHref(Z)));if(!Y){if($.reloadMissingCSS!==!1){this.console.log(`CSS reload: no match found for '${_}', reloading all stylesheets`);for(let Z of X)await this.reattachStylesheetLink(Z)}else this.console.log(`CSS reload: no match found for '${_}', skipping (reloadMissingCSS=false)`);return}if(Y.object.rule)this.console.log(`CSS reload: reloading @imported stylesheet: ${Y.object.href}`),await this.reattachImportedRule(Y.object);else this.console.log(`CSS reload: reloading stylesheet: ${this.linkHref(Y.object)}`),await this.reattachStylesheetLink(Y.object)}catch(X){this.console.error(`Stylesheet reload failed: ${X.message}`),this.console.error("Stack:",X.stack)}}async reattachStylesheetLink(_){if(_.__LiveReload_pendingRemoval)return;_.__LiveReload_pendingRemoval=!0;let $;if(_.tagName==="STYLE")$=this.document.createElement("link"),$.rel="stylesheet",$.media=_.media,$.disabled=_.disabled;else $=_.cloneNode(!1);$.href=b(this.linkHref(_));let X=_.parentNode;if(X.lastChild===_)X.appendChild($);else X.insertBefore($,_.nextSibling);await i($);let K=/AppleWebKit/.test(this.window.navigator.userAgent)?5:200;if(await new Promise((Y)=>this.Timer.start(K,Y)),_.parentNode)_.parentNode.removeChild(_);if(this.window.StyleFix)this.window.StyleFix.link($)}reloadPage(){this.window.location.reload()}reloadImages(_){for(let K of Array.from(this.document.images))if(this.pathsMatch(_,P(K.src)))K.src=b(K.src);let $=["background","border"],X=["backgroundImage","borderImage","webkitBorderImage","MozBorderImage"];for(let K of $)for(let Y of Array.from(this.document.querySelectorAll(`[style*=${K}]`)))this.reloadStyleImages(Y.style,X,_);for(let K of Array.from(this.document.styleSheets))this.reloadStylesheetImages(K,_);this.console.log(`Image reload: ${_}`)}reloadStylesheetImages(_,$){let X;try{X=(_||{}).cssRules}catch(Y){return}if(!X)return;let K=["backgroundImage","borderImage","webkitBorderImage","MozBorderImage"];for(let Y of Array.from(X))switch(Y.type){case CSSRule.IMPORT_RULE:this.reloadStylesheetImages(Y.styleSheet,$);break;case CSSRule.STYLE_RULE:this.reloadStyleImages(Y.style,K,$);break;case CSSRule.MEDIA_RULE:this.reloadStylesheetImages(Y,$);break}}reloadStyleImages(_,$,X){for(let K of $){let Y=_[K];if(typeof Y==="string"){let Z=Y.replace(/\burl\s*\(([^)]*)\)/g,(V,H)=>{let y=H.replace(/^['"]|['"]$/g,"");if(this.pathsMatch(X,P(y)))return`url(${b(y)})`;return V});if(Z!==Y)_[K]=Z}}}pathsMatch(_,$){let X=_.replace(/^\//,"").split("/").reverse(),K=$.replace(/^\//,"").split("/").reverse(),Y=Math.min(X.length,K.length);for(let Z=0;Z<Y;Z++)if(X[Z]!==K[Z])return!1;return Y>0}linkHref(_){return _.href||_.getAttribute&&_.getAttribute("data-href")}collectImportedStylesheets(_,$,X){let K;try{K=($||{}).cssRules}catch(Y){return}if(K&&K.length)for(let Y=0;Y<K.length;Y++){let Z=K[Y];switch(Z.type){case CSSRule.CHARSET_RULE:continue;case CSSRule.IMPORT_RULE:X.push({link:_,rule:Z,index:Y,href:Z.href}),this.collectImportedStylesheets(_,Z.styleSheet,X);break;default:break}}}async reattachImportedRule({rule:_,index:$,link:X}){let K=_.parentStyleSheet,Y=b(_.href),Z="";try{Z=_.media.length?[].join.call(_.media,", "):""}catch(H){if(H.name!=="SecurityError")this.console.error(`Unexpected error accessing @import media: ${H.name}: ${H.message}`)}let V=`@import url("${Y}") ${Z};`;if(_.__LiveReload_newHref=Y,this.importCacheWaitPeriod>0){let H=this.document.createElement("link");if(H.rel="stylesheet",H.href=Y,H.__LiveReload_pendingRemoval=!0,X.parentNode)X.parentNode.insertBefore(H,X);if(await new Promise((y)=>this.Timer.start(this.importCacheWaitPeriod,y)),H.parentNode)H.parentNode.removeChild(H);if(_.__LiveReload_newHref!==Y)return}if(K.insertRule(V,$),K.deleteRule($+1),this.importCacheWaitPeriod>0){let H=K.cssRules[$];if(H.__LiveReload_newHref=Y,await new Promise((y)=>this.Timer.start(this.importCacheWaitPeriod,y)),H.__LiveReload_newHref!==Y)return;K.insertRule(V,$),K.deleteRule($+1)}}}class E{constructor(_){if(this.window=_,this.listeners={},!(this.WebSocket=this.window.WebSocket||this.window.MozWebSocket)){console.error("[LiveMorph] Disabled because the browser does not support WebSockets");return}if(this.options=S.extract(this.window.document),!this.options){console.error("[LiveMorph] Disabled - no configuration found"),console.error('[LiveMorph] Set window.LiveMorphOptions = { host: "localhost", port: 35729 }');return}console.log("[LiveMorph] Options loaded:",JSON.stringify({host:this.options.host,port:this.options.port,morphHTML:this.options.morphHTML,verbose:this.options.verbose})),this.console=this._setupConsole(),this.morpher=new h(this.window,this.console,k,this.options.importCacheWaitPeriod),this.connector=new N(this.options,this.WebSocket,k,{connecting:()=>{},socketConnected:()=>{},connected:($)=>{if(typeof this.listeners.connect==="function")this.listeners.connect();let{host:X}=this.options,K=this.options.port?`:${this.options.port}`:"";return this.log(`Connected to ${X}${K} (protocol v${$})`),this.sendInfo()},error:($)=>{if($ instanceof M)return console.log(`[LiveMorph] ${$.message}`);else return console.log(`[LiveMorph] Internal error: ${$.message}`)},disconnected:($,X)=>{if(typeof this.listeners.disconnect==="function")this.listeners.disconnect();let{host:K}=this.options,Y=this.options.port?`:${this.options.port}`:"",Z=(X/1000).toFixed(0);switch($){case"cannot-connect":return this.log(`Cannot connect to ${K}${Y}, will retry in ${Z} sec`);case"broken":return this.log(`Disconnected from ${K}${Y}, reconnecting in ${Z} sec`);case"handshake-timeout":return this.log(`Cannot connect to ${K}${Y} (handshake timeout), will retry in ${Z} sec`);case"handshake-failed":return this.log(`Cannot connect to ${K}${Y} (handshake failed), will retry in ${Z} sec`);case"manual":case"error":default:return this.log(`Disconnected from ${K}${Y} (${$}), reconnecting in ${Z} sec`)}},message:($)=>{switch($.command){case"reload":return this.performReload($);case"alert":return this.performAlert($)}}}),this.initialized=!0}_setupConsole(){if(!(this.window.console&&this.window.console.log&&this.window.console.error))return{log(){},error(){}};if(this.options.verbose)return this.window.console;return{log(){},error:this.window.console.error.bind(this.window.console)}}on(_,$){this.listeners[_]=$}log(_){return this.console.log(`[LiveMorph] ${_}`)}performReload(_){this.log(`Received reload request for: ${_.path}`);let $={liveCSS:_.liveCSS!=null?_.liveCSS:!0,liveImg:_.liveImg!=null?_.liveImg:!0,reloadMissingCSS:_.reloadMissingCSS!=null?_.reloadMissingCSS:!0,morphHTML:this.options.morphHTML};return this.log(`Reload options: ${JSON.stringify($)}`),this.morpher.reload(_.path,$)}performAlert(_){return alert(_.message)}sendInfo(){if(!this.initialized)return;if(!(this.connector.protocol>=7))return;this.connector.sendCommand({command:"info",plugins:{},url:this.window.location.href})}shutDown(){if(!this.initialized)return;if(this.connector.disconnect(),this.log("Disconnected"),typeof this.listeners.shutdown==="function")this.listeners.shutdown()}}var v=new E(window);window.LiveMorph=v;if(typeof document<"u")document.addEventListener("LiveMorphShutDown",()=>{v.shutDown()}),v.on("connect",()=>{let _=new CustomEvent("LiveMorphConnect");document.dispatchEvent(_)}),v.on("disconnect",()=>{let _=new CustomEvent("LiveMorphDisconnect");document.dispatchEvent(_)});var G_=v;})();
|
|
1
|
+
(()=>{var{defineProperty:h,getOwnPropertyNames:l,getOwnPropertyDescriptor:o}=Object,n=Object.prototype.hasOwnProperty;var m=new WeakMap,t=(_)=>{var $=m.get(_),Z;if($)return $;if($=h({},"__esModule",{value:!0}),_&&typeof _==="object"||typeof _==="function")l(_).map((K)=>!n.call($,K)&&h($,K,{get:()=>_[K],enumerable:!(Z=o(_,K))||Z.enumerable}));return m.set(_,$),$};var e=(_,$)=>{for(var Z in $)h(_,Z,{get:$[Z],enumerable:!0,configurable:!0,set:(K)=>$[Z]=()=>K})};var J_={};e(J_,{default:()=>G_});var c="http://livereload.com/protocols/official-6",s="http://livereload.com/protocols/official-7";class I{constructor(_,$){this.message=`LiveReload protocol error (${_}) after receiving data: "${$}".`}}class E{constructor(_){this.handlers=_,this.reset()}reset(){this.protocol=null}process(_){try{let $;if(!this.protocol){if(_.match(new RegExp("^!!ver:([\\d.]+)$")))this.protocol=6;else if($=this._parseMessage(_,["hello"]))if(!$.protocols.length)throw new I("no protocols specified in handshake message");else if(Array.from($.protocols).includes("http://livereload.com/protocols/official-7"))this.protocol=7;else if(Array.from($.protocols).includes("http://livereload.com/protocols/official-6"))this.protocol=6;else throw new I("no supported protocols found");return this.handlers.connected(this.protocol)}if(this.protocol===6){if($=JSON.parse(_),!$.length)throw new I("protocol 6 messages must be arrays");let[Z,K]=Array.from($);if(Z!=="refresh")throw new I("unknown protocol 6 command");return this.handlers.message({command:"reload",path:K.path,liveCSS:K.apply_css_live!=null?K.apply_css_live:!0})}return $=this._parseMessage(_,["reload","alert"]),this.handlers.message($)}catch($){if($ instanceof I)return this.handlers.error($);throw $}}_parseMessage(_,$){let Z;try{Z=JSON.parse(_)}catch(K){throw new I("unparsable JSON",_)}if(!Z.command)throw new I('missing "command" key',_);if(!$.includes(Z.command))throw new I(`invalid command '${Z.command}', only valid commands are: ${$.join(", ")})`,_);return Z}}var __="1.0.0";class x{constructor(_,$,Z,K){this.options=_,this.WebSocket=$,this.Timer=Z,this.handlers=K;let X=this.options.path?`${this.options.path}`:"livereload",Y=this.options.port?`:${this.options.port}`:"";this._uri=`ws${this.options.https?"s":""}://${this.options.host}${Y}/${X}`,this._nextDelay=this.options.mindelay,this._connectionDesired=!1,this.protocol=0,this.protocolParser=new E({connected:(V)=>{return this.protocol=V,this._handshakeTimeout.stop(),this._nextDelay=this.options.mindelay,this._disconnectionReason="broken",this.handlers.connected(this.protocol)},error:(V)=>{return this.handlers.error(V),this._closeOnError()},message:(V)=>{return this.handlers.message(V)}}),this._handshakeTimeout=new this.Timer(()=>{if(!this._isSocketConnected())return;return this._disconnectionReason="handshake-timeout",this.socket.close()}),this._reconnectTimer=new this.Timer(()=>{if(!this._connectionDesired)return;return this.connect()}),this.connect()}_isSocketConnected(){return this.socket&&this.socket.readyState===this.WebSocket.OPEN}connect(){if(this._connectionDesired=!0,this._isSocketConnected())return;this._reconnectTimer.stop(),this._disconnectionReason="cannot-connect",this.protocolParser.reset(),this.handlers.connecting(),this.socket=new this.WebSocket(this._uri),this.socket.onopen=(_)=>this._onopen(_),this.socket.onclose=(_)=>this._onclose(_),this.socket.onmessage=(_)=>this._onmessage(_),this.socket.onerror=(_)=>this._onerror(_)}disconnect(){if(this._connectionDesired=!1,this._reconnectTimer.stop(),!this._isSocketConnected())return;return this._disconnectionReason="manual",this.socket.close()}_scheduleReconnection(){if(!this._connectionDesired)return;if(!this._reconnectTimer.running)this._reconnectTimer.start(this._nextDelay),this._nextDelay=Math.min(this.options.maxdelay,this._nextDelay*2)}sendCommand(_){if(!this.protocol)return;return this._sendCommand(_)}_sendCommand(_){return this.socket.send(JSON.stringify(_))}_closeOnError(){return this._handshakeTimeout.stop(),this._disconnectionReason="error",this.socket.close()}_onopen(_){this.handlers.socketConnected(),this._disconnectionReason="handshake-failed";let $={command:"hello",protocols:[c,s]};return $.ver=__,this._sendCommand($),this._handshakeTimeout.start(this.options.handshake_timeout)}_onclose(_){return this.protocol=0,this.handlers.disconnected(this._disconnectionReason,this._nextDelay),this._scheduleReconnection()}_onerror(_){}_onmessage(_){return this.protocolParser.process(_.data)}}class b{constructor(_){this.func=_,this.running=!1,this.id=null,this._handler=()=>{return this.running=!1,this.id=null,this.func()}}start(_){if(this.running)clearTimeout(this.id);this.id=setTimeout(this._handler,_),this.running=!0}stop(){if(this.running)clearTimeout(this.id),this.running=!1,this.id=null}}b.start=(_,$)=>setTimeout($,_);class S{constructor(){this.https=!1,this.host=null;let _=35729;Object.defineProperty(this,"port",{get(){return _},set($){_=$?isNaN($)?$:+$:""}}),this.mindelay=1000,this.maxdelay=60000,this.handshake_timeout=5000,this.morphHTML=!0,this.morphShadowDOM=!0,this.verbose=!1,this.importCacheWaitPeriod=200}set(_,$){if(typeof $>"u")return;if(!isNaN(+$))$=+$;if($==="true")$=!0;else if($==="false")$=!1;this[_]=$}}S.extract=function(_){let $=_.defaultView||window;if($&&$.LiveMorphOptions){let K=new S;for(let[X,Y]of Object.entries($.LiveMorphOptions))K.set(X,Y);return K}let Z=Array.from(_.getElementsByTagName("script"));for(let K of Z){let X=K.getAttribute("data-livereload-morph-host");if(X){let Y=new S;Y.host=X;let V=K.getAttribute("data-livereload-morph-port");if(V)Y.port=parseInt(V,10);let B=K.getAttribute("data-livereload-morph-verbose");if(B!==null)Y.verbose=B==="true";return Y}}for(let K of Z){let X=K.src||"";if(X.includes("livereload-morph")){let Y=X.indexOf("?");if(Y!==-1){let V=X.slice(Y+1),B=new URLSearchParams(V),f=B.get("host");if(f){let k=new S;k.host=f;for(let[N,g]of B.entries())k.set(N,g);return k}}}}return null};var a=function(){let _=()=>{},$={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:_,afterNodeAdded:_,beforeNodeMorphed:_,afterNodeMorphed:_,beforeNodeRemoved:_,afterNodeRemoved:_,beforeAttributeUpdated:_},head:{style:"merge",shouldPreserve:(j)=>j.getAttribute("im-preserve")==="true",shouldReAppend:(j)=>j.getAttribute("im-re-append")==="true",shouldRemove:_,afterHeadMorphed:_},restoreFocus:!0};function Z(j,A,W={}){j=N(j);let T=g(A),U=k(j,T,W),O=X(U,()=>{return B(U,j,T,(Q)=>{if(Q.morphStyle==="innerHTML")return Y(Q,j,T),Array.from(j.childNodes);else return K(Q,j,T)})});return U.pantry.remove(),O}function K(j,A,W){let T=g(A);return Y(j,T,W,A,A.nextSibling),Array.from(T.childNodes)}function X(j,A){if(!j.config.restoreFocus)return A();let W=document.activeElement;if(!(W instanceof HTMLInputElement||W instanceof HTMLTextAreaElement))return A();let{id:T,selectionStart:U,selectionEnd:O}=W,Q=A();if(T&&T!==document.activeElement?.getAttribute("id"))W=j.target.querySelector(`[id="${T}"]`),W?.focus();if(W&&!W.selectionEnd&&O)W.setSelectionRange(U,O);return Q}let Y=function(){function j(G,J,D,z=null,R=null){if(J instanceof HTMLTemplateElement&&D instanceof HTMLTemplateElement)J=J.content,D=D.content;z||=J.firstChild;for(let F of D.childNodes){if(z&&z!=R){let H=W(G,F,z,R);if(H){if(H!==z)U(G,z,H);V(H,F,G),z=H.nextSibling;continue}}if(F instanceof Element){let H=F.getAttribute("id");if(G.persistentIds.has(H)){let y=O(J,H,z,G);V(y,F,G),z=y.nextSibling;continue}}let L=A(J,F,z,G);if(L)z=L.nextSibling}while(z&&z!=R){let F=z;z=z.nextSibling,T(G,F)}}function A(G,J,D,z){if(z.callbacks.beforeNodeAdded(J)===!1)return null;if(z.idMap.has(J)){let R=document.createElement(J.tagName);return G.insertBefore(R,D),V(R,J,z),z.callbacks.afterNodeAdded(R),R}else{let R=document.importNode(J,!0);return G.insertBefore(R,D),z.callbacks.afterNodeAdded(R),R}}let W=function(){function G(z,R,F,L){let H=null,y=R.nextSibling,p=0,M=F;while(M&&M!=L){if(D(M,R)){if(J(z,M,R))return M;if(H===null){if(!z.idMap.has(M))H=M}}if(H===null&&y&&D(M,y)){if(p++,y=y.nextSibling,p>=2)H=void 0}if(z.activeElementAndParents.includes(M))break;M=M.nextSibling}return H||null}function J(z,R,F){let L=z.idMap.get(R),H=z.idMap.get(F);if(!H||!L)return!1;for(let y of L)if(H.has(y))return!0;return!1}function D(z,R){let F=z,L=R;return F.nodeType===L.nodeType&&F.tagName===L.tagName&&(!F.getAttribute?.("id")||F.getAttribute?.("id")===L.getAttribute?.("id"))}return G}();function T(G,J){if(G.idMap.has(J))q(G.pantry,J,null);else{if(G.callbacks.beforeNodeRemoved(J)===!1)return;J.parentNode?.removeChild(J),G.callbacks.afterNodeRemoved(J)}}function U(G,J,D){let z=J;while(z&&z!==D){let R=z;z=z.nextSibling,T(G,R)}return z}function O(G,J,D,z){let R=z.target.getAttribute?.("id")===J&&z.target||z.target.querySelector(`[id="${J}"]`)||z.pantry.querySelector(`[id="${J}"]`);return Q(R,z),q(G,R,D),R}function Q(G,J){let D=G.getAttribute("id");while(G=G.parentNode){let z=J.idMap.get(G);if(z){if(z.delete(D),!z.size)J.idMap.delete(G)}}}function q(G,J,D){if(G.moveBefore)try{G.moveBefore(J,D)}catch(z){G.insertBefore(J,D)}else G.insertBefore(J,D)}return j}(),V=function(){function j(Q,q,G){if(G.ignoreActive&&Q===document.activeElement)return null;if(G.callbacks.beforeNodeMorphed(Q,q)===!1)return Q;if(Q instanceof HTMLHeadElement&&G.head.ignore);else if(Q instanceof HTMLHeadElement&&G.head.style!=="morph")f(Q,q,G);else if(A(Q,q,G),!O(Q,G))Y(G,Q,q);return G.callbacks.afterNodeMorphed(Q,q),Q}function A(Q,q,G){let J=q.nodeType;if(J===1){let D=Q,z=q,R=D.attributes,F=z.attributes;for(let L of F){if(U(L.name,D,"update",G))continue;if(D.getAttribute(L.name)!==L.value)D.setAttribute(L.name,L.value)}for(let L=R.length-1;0<=L;L--){let H=R[L];if(!H)continue;if(!z.hasAttribute(H.name)){if(U(H.name,D,"remove",G))continue;D.removeAttribute(H.name)}}if(!O(D,G))W(D,z,G)}if(J===8||J===3){if(Q.nodeValue!==q.nodeValue)Q.nodeValue=q.nodeValue}}function W(Q,q,G){if(Q instanceof HTMLInputElement&&q instanceof HTMLInputElement&&q.type!=="file"){let J=q.value,D=Q.value;if(T(Q,q,"checked",G),T(Q,q,"disabled",G),!q.hasAttribute("value")){if(!U("value",Q,"remove",G))Q.value="",Q.removeAttribute("value")}else if(D!==J){if(!U("value",Q,"update",G))Q.setAttribute("value",J),Q.value=J}}else if(Q instanceof HTMLOptionElement&&q instanceof HTMLOptionElement)T(Q,q,"selected",G);else if(Q instanceof HTMLTextAreaElement&&q instanceof HTMLTextAreaElement){let J=q.value,D=Q.value;if(U("value",Q,"update",G))return;if(J!==D)Q.value=J;if(Q.firstChild&&Q.firstChild.nodeValue!==J)Q.firstChild.nodeValue=J}}function T(Q,q,G,J){let D=q[G],z=Q[G];if(D!==z){let R=U(G,Q,"update",J);if(!R)Q[G]=q[G];if(D){if(!R)Q.setAttribute(G,"")}else if(!U(G,Q,"remove",J))Q.removeAttribute(G)}}function U(Q,q,G,J){if(Q==="value"&&J.ignoreActiveValue&&q===document.activeElement)return!0;return J.callbacks.beforeAttributeUpdated(Q,q,G)===!1}function O(Q,q){return!!q.ignoreActiveValue&&Q===document.activeElement&&Q!==document.body}return j}();function B(j,A,W,T){if(j.head.block){let U=A.querySelector("head"),O=W.querySelector("head");if(U&&O){let Q=f(U,O,j);return Promise.all(Q).then(()=>{let q=Object.assign(j,{head:{block:!1,ignore:!0}});return T(q)})}}return T(j)}function f(j,A,W){let T=[],U=[],O=[],Q=[],q=new Map;for(let J of A.children)q.set(J.outerHTML,J);for(let J of j.children){let D=q.has(J.outerHTML),z=W.head.shouldReAppend(J),R=W.head.shouldPreserve(J);if(D||R)if(z)U.push(J);else q.delete(J.outerHTML),O.push(J);else if(W.head.style==="append"){if(z)U.push(J),Q.push(J)}else if(W.head.shouldRemove(J)!==!1)U.push(J)}Q.push(...q.values());let G=[];for(let J of Q){let D=document.createRange().createContextualFragment(J.outerHTML).firstChild;if(W.callbacks.beforeNodeAdded(D)!==!1){if("href"in D&&D.href||"src"in D&&D.src){let z,R=new Promise(function(F){z=F});D.addEventListener("load",function(){z()}),G.push(R)}j.appendChild(D),W.callbacks.afterNodeAdded(D),T.push(D)}}for(let J of U)if(W.callbacks.beforeNodeRemoved(J)!==!1)j.removeChild(J),W.callbacks.afterNodeRemoved(J);return W.head.afterHeadMorphed(j,{added:T,kept:O,removed:U}),G}let k=function(){function j(G,J,D){let{persistentIds:z,idMap:R}=Q(G,J),F=A(D),L=F.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(L))throw`Do not understand how to morph style ${L}`;return{target:G,newContent:J,config:F,morphStyle:L,ignoreActive:F.ignoreActive,ignoreActiveValue:F.ignoreActiveValue,restoreFocus:F.restoreFocus,idMap:R,persistentIds:z,pantry:W(),activeElementAndParents:T(G),callbacks:F.callbacks,head:F.head}}function A(G){let J=Object.assign({},$);return Object.assign(J,G),J.callbacks=Object.assign({},$.callbacks,G.callbacks),J.head=Object.assign({},$.head,G.head),J}function W(){let G=document.createElement("div");return G.hidden=!0,document.body.insertAdjacentElement("afterend",G),G}function T(G){let J=[],D=document.activeElement;if(D?.tagName!=="BODY"&&G.contains(D))while(D){if(J.push(D),D===G)break;D=D.parentElement}return J}function U(G){let J=Array.from(G.querySelectorAll("[id]"));if(G.getAttribute?.("id"))J.push(G);return J}function O(G,J,D,z){for(let R of z){let F=R.getAttribute("id");if(J.has(F)){let L=R;while(L){let H=G.get(L);if(H==null)H=new Set,G.set(L,H);if(H.add(F),L===D)break;L=L.parentElement}}}}function Q(G,J){let D=U(G),z=U(J),R=q(D,z),F=new Map;O(F,R,G,D);let L=J.__idiomorphRoot||J;return O(F,R,L,z),{persistentIds:R,idMap:F}}function q(G,J){let D=new Set,z=new Map;for(let{id:F,tagName:L}of G)if(z.has(F))D.add(F);else z.set(F,L);let R=new Set;for(let{id:F,tagName:L}of J)if(R.has(F))D.add(F);else if(z.get(F)===L)R.add(F);for(let F of D)R.delete(F);return R}return j}(),{normalizeElement:N,normalizeParent:g}=function(){let j=new WeakSet;function A(O){if(O instanceof Document)return O.documentElement;else return O}function W(O){if(O==null)return document.createElement("div");else if(typeof O==="string")return W(U(O));else if(j.has(O))return O;else if(O instanceof Node)if(O.parentNode)return new T(O);else{let Q=document.createElement("div");return Q.append(O),Q}else{let Q=document.createElement("div");for(let q of[...O])Q.append(q);return Q}}class T{constructor(O){this.originalNode=O,this.realParentNode=O.parentNode,this.previousSibling=O.previousSibling,this.nextSibling=O.nextSibling}get childNodes(){let O=[],Q=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;while(Q&&Q!=this.nextSibling)O.push(Q),Q=Q.nextSibling;return O}querySelectorAll(O){return this.childNodes.reduce((Q,q)=>{if(q instanceof Element){if(q.matches(O))Q.push(q);let G=q.querySelectorAll(O);for(let J=0;J<G.length;J++)Q.push(G[J])}return Q},[])}insertBefore(O,Q){return this.realParentNode.insertBefore(O,Q)}moveBefore(O,Q){return this.realParentNode.moveBefore(O,Q)}get __idiomorphRoot(){return this.originalNode}}function U(O){let Q=new DOMParser,q=O.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");if(q.match(/<\/html>/)||q.match(/<\/head>/)||q.match(/<\/body>/)){let G=Q.parseFromString(O,"text/html");if(q.match(/<\/html>/))return j.add(G),G;else{let J=G.firstChild;if(J)j.add(J);return J}}else{let J=Q.parseFromString("<body><template>"+O+"</template></body>","text/html").body.querySelector("template").content;return j.add(J),J}}return{normalizeElement:A,normalizeParent:W}}();return{morph:Z,defaults:$}}();function i(_){let $="",Z="",K=_.indexOf("#");if(K>=0)$=_.slice(K),_=_.slice(0,K);let X=_.indexOf("??");if(X>=0){if(X+1!==_.lastIndexOf("?"))K=_.lastIndexOf("?")}else K=_.indexOf("?");if(K>=0)Z=_.slice(K),_=_.slice(0,K);return{url:_,params:Z,hash:$}}function C(_){if(!_)return"";let $;if({url:_}=i(_),_.indexOf("file://")===0)$=_.replace(new RegExp("^file://(localhost)?"),"");else $=_.replace(new RegExp("^([^:]+:)?//([^:/]+)(:\\d*)?/"),"/");return decodeURIComponent($)}function $_(_,$){if(_=_.replace(/^\/+/,"").toLowerCase(),$=$.replace(/^\/+/,"").toLowerCase(),_===$)return 1e4;let Z=_.split(/\/|\\/).reverse(),K=$.split(/\/|\\/).reverse(),X=Math.min(Z.length,K.length),Y=0;while(Y<X&&Z[Y]===K[Y])++Y;return Y}function r(_,$,Z=(K)=>K){let K={score:0};for(let X of $){let Y=$_(_,Z(X));if(Y>K.score)K={object:X,score:Y}}if(K.score===0)return null;return K}function v(_){let{url:$,params:Z,hash:K}=i(_),X=`livereload=${Date.now()}`;if(!Z)return`${$}?${X}${K}`;if(Z.includes("livereload=")){let Y=Z.replace(/([?&])livereload=\d+/,`$1${X}`);return`${$}${Y}${K}`}return`${$}${Z}&${X}${K}`}function d(_,$=15000){return new Promise((Z)=>{let K=!1,X=()=>{if(K)return;K=!0,Z()};_.onload=()=>{X()};let Y=50,V=()=>{if(K)return;if(_.sheet){X();return}setTimeout(V,Y)};setTimeout(V,Y),setTimeout(X,$)})}class w{constructor(_,$,Z,K=200){this.window=_,this.console=$,this.Timer=Z,this.document=_.document,this.importCacheWaitPeriod=K}reload(_,$={}){let Z=_.match(/\.css(?:\.map)?$/i),K=_.match(/\.(jpe?g|png|gif|svg|webp|ico)$/i),X=_.match(/\.m?js$/i);if(Z&&$.liveCSS)return this.reloadStylesheet(_,$);if(K&&$.liveImg)return this.reloadImages(_);if(X)return this.reloadPage();if($.morphHTML)return this.morphHTML(_,$);this.reloadPage()}async morphHTML(_,$={}){try{let Z=await fetch(this.window.location.href,{cache:"no-cache",headers:{"X-Live-Morph":"true"}});if(!Z.ok)throw Error(`Fetch failed: ${Z.status} ${Z.statusText}`);let K=await Z.text();K=K.replace(/<!DOCTYPE[^>]*>/i,"").trim(),a.morph(this.document.documentElement,K,{head:{style:"merge",shouldPreserve:(X)=>{if(X.tagName==="SCRIPT"&&X.src)return X.src.toLowerCase().includes("livereload-morph");return!1}},callbacks:{afterNodeMorphed:(X)=>{if($.morphShadowDOM===!1)return;if(X.children){for(let Y of X.children)if(Y.tagName==="TEMPLATE"&&(Y.hasAttribute("shadowrootmode")||Y.hasAttribute("shadowroot"))){let V={mode:Y.getAttribute("shadowrootmode")||Y.getAttribute("shadowroot")||"open"};if(Y.hasAttribute("shadowrootdelegatesfocus"))V.delegatesFocus=!0;if(Y.hasAttribute("shadowrootclonable"))V.clonable=!0;if(Y.hasAttribute("shadowrootserializable"))V.serializable=!0;let B=X.shadowRoot;if(!B)B=X.attachShadow(V);B.innerHTML="",B.appendChild(Y.content.cloneNode(!0)),Y.remove();break}}},beforeAttributeUpdated:(X,Y)=>{if(Y.tagName==="INPUT"||Y.tagName==="TEXTAREA"||Y.tagName==="SELECT"){if(X==="value"||X==="checked")return!1}if(Y.tagName==="DETAILS"&&X==="open")return!1;return!0}}}),this.console.log("HTML morphed successfully")}catch(Z){if(this.console.error(`Morph failed: ${Z.message}`),$.fallbackToReload!==!1)this.console.log("Falling back to full page reload"),this.reloadPage()}}async reloadStylesheet(_,$={}){try{let Z=Array.from(this.document.getElementsByTagName("link")).filter((Y)=>Y.rel&&Y.rel.match(/^stylesheet$/i)&&!Y.__LiveReload_pendingRemoval),K=[];for(let Y of Array.from(this.document.getElementsByTagName("style")))if(Y.sheet)this.collectImportedStylesheets(Y,Y.sheet,K);for(let Y of Z)if(Y.sheet)this.collectImportedStylesheets(Y,Y.sheet,K);if(this.window.StyleFix&&this.document.querySelectorAll)for(let Y of Array.from(this.document.querySelectorAll("style[data-href]")))Z.push(Y);this.console.log(`CSS reload: found ${Z.length} LINKed stylesheets, ${K.length} @imported stylesheets`);let X=r(_,Z.concat(K),(Y)=>C(Y.href||this.linkHref(Y)));if(!X){if($.reloadMissingCSS!==!1){this.console.log(`CSS reload: no match found for '${_}', reloading all stylesheets`);for(let Y of Z)await this.reattachStylesheetLink(Y)}else this.console.log(`CSS reload: no match found for '${_}', skipping (reloadMissingCSS=false)`);return}if(X.object.rule)this.console.log(`CSS reload: reloading @imported stylesheet: ${X.object.href}`),await this.reattachImportedRule(X.object);else this.console.log(`CSS reload: reloading stylesheet: ${this.linkHref(X.object)}`),await this.reattachStylesheetLink(X.object)}catch(Z){this.console.error(`Stylesheet reload failed: ${Z.message}`),this.console.error("Stack:",Z.stack)}}async reattachStylesheetLink(_){if(_.__LiveReload_pendingRemoval)return;_.__LiveReload_pendingRemoval=!0;let $;if(_.tagName==="STYLE")$=this.document.createElement("link"),$.rel="stylesheet",$.media=_.media,$.disabled=_.disabled;else $=_.cloneNode(!1);$.href=v(this.linkHref(_));let Z=_.parentNode;if(Z.lastChild===_)Z.appendChild($);else Z.insertBefore($,_.nextSibling);await d($);let K=/AppleWebKit/.test(this.window.navigator.userAgent)?5:200;if(await new Promise((X)=>this.Timer.start(K,X)),_.parentNode)_.parentNode.removeChild(_);if(this.window.StyleFix)this.window.StyleFix.link($)}reloadPage(){this.window.location.reload()}reloadImages(_){for(let K of Array.from(this.document.images))if(this.pathsMatch(_,C(K.src)))K.src=v(K.src);let $=["background","border"],Z=["backgroundImage","borderImage","webkitBorderImage","MozBorderImage"];for(let K of $)for(let X of Array.from(this.document.querySelectorAll(`[style*=${K}]`)))this.reloadStyleImages(X.style,Z,_);for(let K of Array.from(this.document.styleSheets))this.reloadStylesheetImages(K,_);this.console.log(`Image reload: ${_}`)}reloadStylesheetImages(_,$){let Z;try{Z=(_||{}).cssRules}catch(X){return}if(!Z)return;let K=["backgroundImage","borderImage","webkitBorderImage","MozBorderImage"];for(let X of Array.from(Z))switch(X.type){case CSSRule.IMPORT_RULE:this.reloadStylesheetImages(X.styleSheet,$);break;case CSSRule.STYLE_RULE:this.reloadStyleImages(X.style,K,$);break;case CSSRule.MEDIA_RULE:this.reloadStylesheetImages(X,$);break}}reloadStyleImages(_,$,Z){for(let K of $){let X=_[K];if(typeof X==="string"){let Y=X.replace(/\burl\s*\(([^)]*)\)/g,(V,B)=>{let f=B.replace(/^['"]|['"]$/g,"");if(this.pathsMatch(Z,C(f)))return`url(${v(f)})`;return V});if(Y!==X)_[K]=Y}}}pathsMatch(_,$){let Z=_.replace(/^\//,"").split("/").reverse(),K=$.replace(/^\//,"").split("/").reverse(),X=Math.min(Z.length,K.length);for(let Y=0;Y<X;Y++)if(Z[Y]!==K[Y])return!1;return X>0}linkHref(_){return _.href||_.getAttribute&&_.getAttribute("data-href")}collectImportedStylesheets(_,$,Z){let K;try{K=($||{}).cssRules}catch(X){return}if(K&&K.length)for(let X=0;X<K.length;X++){let Y=K[X];switch(Y.type){case CSSRule.CHARSET_RULE:continue;case CSSRule.IMPORT_RULE:Z.push({link:_,rule:Y,index:X,href:Y.href}),this.collectImportedStylesheets(_,Y.styleSheet,Z);break;default:break}}}async reattachImportedRule({rule:_,index:$,link:Z}){let K=_.parentStyleSheet,X=v(_.href),Y="";try{Y=_.media.length?[].join.call(_.media,", "):""}catch(B){if(B.name!=="SecurityError")this.console.error(`Unexpected error accessing @import media: ${B.name}: ${B.message}`)}let V=`@import url("${X}") ${Y};`;if(_.__LiveReload_newHref=X,this.importCacheWaitPeriod>0){let B=this.document.createElement("link");if(B.rel="stylesheet",B.href=X,B.__LiveReload_pendingRemoval=!0,Z.parentNode)Z.parentNode.insertBefore(B,Z);if(await new Promise((f)=>this.Timer.start(this.importCacheWaitPeriod,f)),B.parentNode)B.parentNode.removeChild(B);if(_.__LiveReload_newHref!==X)return}if(K.insertRule(V,$),K.deleteRule($+1),this.importCacheWaitPeriod>0){let B=K.cssRules[$];if(B.__LiveReload_newHref=X,await new Promise((f)=>this.Timer.start(this.importCacheWaitPeriod,f)),B.__LiveReload_newHref!==X)return;K.insertRule(V,$),K.deleteRule($+1)}}}class u{constructor(_){if(this.window=_,this.listeners={},!(this.WebSocket=this.window.WebSocket||this.window.MozWebSocket)){console.error("[LiveMorph] Disabled because the browser does not support WebSockets");return}if(this.options=S.extract(this.window.document),!this.options){console.error("[LiveMorph] Disabled - no configuration found"),console.error('[LiveMorph] Set window.LiveMorphOptions = { host: "localhost", port: 35729 }');return}console.log("[LiveMorph] Options loaded:",JSON.stringify({host:this.options.host,port:this.options.port,morphHTML:this.options.morphHTML,verbose:this.options.verbose})),this.console=this._setupConsole(),this.morpher=new w(this.window,this.console,b,this.options.importCacheWaitPeriod),this.connector=new x(this.options,this.WebSocket,b,{connecting:()=>{},socketConnected:()=>{},connected:($)=>{if(typeof this.listeners.connect==="function")this.listeners.connect();let{host:Z}=this.options,K=this.options.port?`:${this.options.port}`:"";return this.log(`Connected to ${Z}${K} (protocol v${$})`),this.sendInfo()},error:($)=>{if($ instanceof I)return console.log(`[LiveMorph] ${$.message}`);else return console.log(`[LiveMorph] Internal error: ${$.message}`)},disconnected:($,Z)=>{if(typeof this.listeners.disconnect==="function")this.listeners.disconnect();let{host:K}=this.options,X=this.options.port?`:${this.options.port}`:"",Y=(Z/1000).toFixed(0);switch($){case"cannot-connect":return this.log(`Cannot connect to ${K}${X}, will retry in ${Y} sec`);case"broken":return this.log(`Disconnected from ${K}${X}, reconnecting in ${Y} sec`);case"handshake-timeout":return this.log(`Cannot connect to ${K}${X} (handshake timeout), will retry in ${Y} sec`);case"handshake-failed":return this.log(`Cannot connect to ${K}${X} (handshake failed), will retry in ${Y} sec`);case"manual":case"error":default:return this.log(`Disconnected from ${K}${X} (${$}), reconnecting in ${Y} sec`)}},message:($)=>{switch($.command){case"reload":return this.performReload($);case"alert":return this.performAlert($)}}}),this.initialized=!0}_setupConsole(){if(!(this.window.console&&this.window.console.log&&this.window.console.error))return{log(){},error(){}};if(this.options.verbose)return this.window.console;return{log(){},error:this.window.console.error.bind(this.window.console)}}on(_,$){this.listeners[_]=$}log(_){return this.console.log(`[LiveMorph] ${_}`)}performReload(_){this.log(`Received reload request for: ${_.path}`);let $={liveCSS:_.liveCSS!=null?_.liveCSS:!0,liveImg:_.liveImg!=null?_.liveImg:!0,reloadMissingCSS:_.reloadMissingCSS!=null?_.reloadMissingCSS:!0,morphHTML:this.options.morphHTML,morphShadowDOM:this.options.morphShadowDOM};return this.log(`Reload options: ${JSON.stringify($)}`),this.morpher.reload(_.path,$)}performAlert(_){return alert(_.message)}sendInfo(){if(!this.initialized)return;if(!(this.connector.protocol>=7))return;this.connector.sendCommand({command:"info",plugins:{},url:this.window.location.href})}shutDown(){if(!this.initialized)return;if(this.connector.disconnect(),this.log("Disconnected"),typeof this.listeners.shutdown==="function")this.listeners.shutdown()}}var P=new u(window);window.LiveMorph=P;if(typeof document<"u")document.addEventListener("LiveMorphShutDown",()=>{P.shutDown()}),P.on("connect",()=>{let _=new CustomEvent("LiveMorphConnect");document.dispatchEvent(_)}),P.on("disconnect",()=>{let _=new CustomEvent("LiveMorphDisconnect");document.dispatchEvent(_)});var G_=P;})();
|