2021-04-07 04:26:24 +03:00
|
|
|
console.log("Loaded HMR");
|
|
|
|
var eventSource = null;
|
|
|
|
|
2021-04-12 01:35:02 +03:00
|
|
|
/** @type {Promise<() => void>} */
|
|
|
|
let updateAppContentJson = new Promise((resolve, reject) => resolve(() => {}));
|
|
|
|
|
2021-04-23 21:37:33 +03:00
|
|
|
function connect(sendContentJsonPort, initialErrorPage) {
|
2023-02-09 02:23:35 +03:00
|
|
|
let reconnectFrequencySeconds = 1;
|
|
|
|
// reconnect logic based on: https://stackoverflow.com/a/61148682/383983
|
2021-04-07 04:26:24 +03:00
|
|
|
// Listen for the server to tell us that an HMR update is available
|
2023-02-09 02:23:35 +03:00
|
|
|
function waitFunc() {
|
|
|
|
return reconnectFrequencySeconds * 1000;
|
2021-04-23 21:37:33 +03:00
|
|
|
}
|
2023-02-09 02:23:35 +03:00
|
|
|
function tryToSetupFunc() {
|
|
|
|
setupEventSource();
|
|
|
|
reconnectFrequencySeconds *= 2;
|
|
|
|
if (reconnectFrequencySeconds >= 8) {
|
|
|
|
reconnectFrequencySeconds = 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function reconnectFunc() {
|
|
|
|
console.log(
|
|
|
|
`Attempting dev server reconnect in ${reconnectFrequencySeconds}...`
|
|
|
|
);
|
|
|
|
setTimeout(tryToSetupFunc, waitFunc());
|
|
|
|
}
|
|
|
|
function setupEventSource() {
|
|
|
|
eventSource = new EventSource("/stream");
|
|
|
|
window.reloadOnOk = initialErrorPage;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (initialErrorPage) {
|
|
|
|
handleEvent(sendContentJsonPort, { data: "content.dat" });
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
eventSource.onopen = async function () {
|
|
|
|
hideError();
|
|
|
|
reconnectFrequencySeconds = 1;
|
|
|
|
};
|
|
|
|
eventSource.onerror = async function (evt) {
|
|
|
|
eventSource && eventSource.close();
|
|
|
|
reconnectFunc();
|
|
|
|
|
|
|
|
showReconnectBanner();
|
|
|
|
};
|
|
|
|
eventSource.onmessage = async function (evt) {
|
|
|
|
handleEvent(sendContentJsonPort, evt);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
setupEventSource();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showReconnectBanner() {
|
|
|
|
showError({
|
|
|
|
type: "compile-errors",
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
path: "",
|
|
|
|
name: "",
|
|
|
|
problems: [
|
|
|
|
{
|
|
|
|
title: "",
|
|
|
|
// region: "",
|
|
|
|
message: ["Dev server is disconnected..."],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2021-04-23 23:51:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async function handleEvent(sendContentJsonPort, evt) {
|
2022-02-03 22:51:17 +03:00
|
|
|
if (evt.data === "content.dat") {
|
2021-07-08 21:59:40 +03:00
|
|
|
showCompiling("");
|
2021-04-23 23:51:12 +03:00
|
|
|
const elmJsRequest = elmJsFetch();
|
|
|
|
const fetchContentJson = fetchContentJsonForCurrentPage();
|
|
|
|
updateAppContentJson = updateContentJsonWith(
|
|
|
|
fetchContentJson,
|
|
|
|
sendContentJsonPort
|
|
|
|
);
|
2021-04-12 05:42:26 +03:00
|
|
|
|
2021-04-23 23:51:12 +03:00
|
|
|
try {
|
|
|
|
await fetchContentJson;
|
2023-02-09 23:02:06 +03:00
|
|
|
thenApplyHmr(await elmJsRequest);
|
2021-04-23 23:51:12 +03:00
|
|
|
} catch (errorJson) {
|
2021-08-03 03:38:38 +03:00
|
|
|
if (typeof errorJson === "string") {
|
2022-02-03 22:51:17 +03:00
|
|
|
errorJson = JSON.parse(errorJson);
|
2021-08-03 03:38:38 +03:00
|
|
|
}
|
|
|
|
if (errorJson.type) {
|
|
|
|
showError(errorJson);
|
|
|
|
} else if (errorJson.length > 0) {
|
|
|
|
showError({
|
|
|
|
type: "compile-errors",
|
|
|
|
errors: errorJson,
|
|
|
|
});
|
|
|
|
} else {
|
2022-02-03 22:51:17 +03:00
|
|
|
showError(JSON.parse(errorJson.errorsJson.errors));
|
2021-08-03 03:38:38 +03:00
|
|
|
}
|
2021-04-07 18:22:46 +03:00
|
|
|
}
|
2021-07-08 21:59:40 +03:00
|
|
|
} else if (evt.data === "elm.js") {
|
|
|
|
showCompiling("");
|
2021-04-23 23:51:12 +03:00
|
|
|
elmJsFetch().then(thenApplyHmr);
|
2021-07-08 21:59:40 +03:00
|
|
|
} else {
|
|
|
|
console.log("Unhandled", evt.data);
|
2021-04-23 23:51:12 +03:00
|
|
|
}
|
2021-04-07 04:26:24 +03:00
|
|
|
}
|
|
|
|
|
2021-04-12 01:35:02 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {*} fetchContentJsonPromise
|
|
|
|
* @param {*} sendContentJsonPort
|
|
|
|
* @returns {Promise<() => void>}
|
|
|
|
*/
|
|
|
|
async function updateContentJsonWith(
|
|
|
|
fetchContentJsonPromise,
|
|
|
|
sendContentJsonPort
|
|
|
|
) {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const newContentJson = await fetchContentJsonPromise;
|
|
|
|
hideError();
|
|
|
|
|
|
|
|
resolve(() => {
|
|
|
|
sendContentJsonPort(newContentJson);
|
2021-04-12 02:26:22 +03:00
|
|
|
hideCompiling("fast");
|
2021-04-12 01:35:02 +03:00
|
|
|
});
|
|
|
|
} catch (errorJson) {
|
2021-08-03 03:38:38 +03:00
|
|
|
if (errorJson.type) {
|
|
|
|
showError(errorJson);
|
2022-02-03 22:51:17 +03:00
|
|
|
} else if (typeof errorJson === "string") {
|
2021-08-03 03:38:38 +03:00
|
|
|
showError(JSON.parse(errorJson));
|
|
|
|
} else {
|
|
|
|
showError(errorJson);
|
|
|
|
}
|
2021-04-12 01:35:02 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchContentJsonForCurrentPage() {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
let currentPath = window.location.pathname.replace(/(\w)$/, "$1/");
|
|
|
|
|
|
|
|
const contentJsonForPage = await fetch(
|
2022-02-03 22:51:17 +03:00
|
|
|
`${window.location.origin}${currentPath}content.dat`
|
2021-04-12 01:35:02 +03:00
|
|
|
);
|
2021-04-21 16:09:26 +03:00
|
|
|
if (contentJsonForPage.ok || contentJsonForPage.status === 404) {
|
2022-02-03 22:51:17 +03:00
|
|
|
resolve(
|
|
|
|
new DataView(await (await contentJsonForPage.blob()).arrayBuffer())
|
|
|
|
);
|
2021-04-12 01:35:02 +03:00
|
|
|
} else {
|
2021-04-12 05:50:48 +03:00
|
|
|
try {
|
|
|
|
reject(await contentJsonForPage.json());
|
|
|
|
} catch (error) {
|
|
|
|
resolve(null);
|
|
|
|
}
|
2021-04-12 01:35:02 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-07 04:26:24 +03:00
|
|
|
// Expose the Webpack HMR API
|
|
|
|
|
|
|
|
// var myDisposeCallback = null;
|
|
|
|
var myDisposeCallback = function () {
|
|
|
|
console.log("dispose...");
|
|
|
|
};
|
|
|
|
|
|
|
|
// simulate the HMR api exposed by webpack
|
|
|
|
var module = {
|
|
|
|
hot: {
|
2021-04-12 01:35:02 +03:00
|
|
|
accept: async function () {
|
2023-02-09 23:02:06 +03:00
|
|
|
(await updateAppContentJson)();
|
2021-04-12 01:35:02 +03:00
|
|
|
},
|
2021-04-07 04:26:24 +03:00
|
|
|
|
|
|
|
dispose: function (callback) {
|
|
|
|
myDisposeCallback = callback;
|
|
|
|
},
|
|
|
|
|
|
|
|
data: null,
|
|
|
|
|
|
|
|
apply: function () {
|
|
|
|
var newData = {};
|
|
|
|
myDisposeCallback(newData);
|
|
|
|
module.hot.data = newData;
|
|
|
|
},
|
|
|
|
|
|
|
|
verbose: true,
|
|
|
|
},
|
|
|
|
};
|
2021-04-08 05:48:52 +03:00
|
|
|
|
|
|
|
// Thanks to the elm-live maintainers and contributors for this code for rendering errors as an HTML overlay
|
|
|
|
// https://github.com/wking-io/elm-live/blob/e317b4914c471addea7243c47f28dcebe27a5d36/lib/src/websocket.js
|
|
|
|
|
2022-02-03 22:51:34 +03:00
|
|
|
const pipe =
|
|
|
|
(...fns) =>
|
|
|
|
(x) =>
|
|
|
|
fns.reduce((y, f) => f(y), x);
|
2021-04-08 05:48:52 +03:00
|
|
|
|
2021-04-09 02:27:12 +03:00
|
|
|
function elmJsFetch() {
|
2022-02-21 20:00:34 +03:00
|
|
|
var elmJsRequest = new Request("/elm.js", { cache: "no-cache" });
|
2021-04-09 02:27:12 +03:00
|
|
|
return fetch(elmJsRequest);
|
|
|
|
}
|
|
|
|
|
2021-04-10 19:07:35 +03:00
|
|
|
async function waitFor(millis) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(resolve, millis);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-09 02:27:12 +03:00
|
|
|
async function thenApplyHmr(response) {
|
|
|
|
if (response.ok) {
|
2021-04-23 21:37:33 +03:00
|
|
|
if (window.reloadOnOk) {
|
|
|
|
location.reload();
|
|
|
|
} else {
|
|
|
|
response.text().then(function (value) {
|
|
|
|
module.hot.apply();
|
2022-02-21 20:00:34 +03:00
|
|
|
delete window.Elm;
|
2021-04-23 21:37:33 +03:00
|
|
|
eval(value);
|
|
|
|
});
|
|
|
|
}
|
2021-04-09 02:27:12 +03:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const errorJson = await response.json();
|
|
|
|
console.error("JSON", errorJson);
|
|
|
|
showError(errorJson);
|
|
|
|
} catch (jsonParsingError) {
|
|
|
|
console.log("Couldn't parse error", jsonParsingError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 05:48:52 +03:00
|
|
|
function colorConverter(color) {
|
|
|
|
return {
|
|
|
|
black: "#000000",
|
|
|
|
red: "#F77F00",
|
|
|
|
green: "#33ff00",
|
|
|
|
yellow: "#ffff00",
|
|
|
|
blue: "#99B1BC",
|
|
|
|
magenta: "#cc00ff",
|
|
|
|
cyan: "#00ffff",
|
|
|
|
white: "#d0d0d0",
|
|
|
|
BLACK: "#808080",
|
|
|
|
RED: "#ff0000",
|
|
|
|
GREEN: "#33ff00",
|
|
|
|
YELLOW: "#ffff00",
|
|
|
|
BLUE: "#0066ff",
|
|
|
|
MAGENTA: "#cc00ff",
|
|
|
|
CYAN: "#00ffff",
|
|
|
|
WHITE: "#ffffff",
|
|
|
|
}[color];
|
|
|
|
}
|
|
|
|
|
|
|
|
const addNewLine = (str) => str + "\n";
|
2021-08-27 20:27:37 +03:00
|
|
|
const styleColor = (str = "WHITE") => `color: ${colorConverter(str) || str};`;
|
2021-04-08 05:48:52 +03:00
|
|
|
const styleUnderline = `text-decoration: underline;`;
|
|
|
|
const styleBold = `text-decoration: bold;`;
|
|
|
|
const parseStyle = ({ underline, color, bold }) =>
|
|
|
|
`${underline ? styleUnderline : ""}${color ? styleColor(color) : ""}${
|
|
|
|
bold ? styleBold : ""
|
|
|
|
}`;
|
|
|
|
|
|
|
|
function capitalizeFirstLetter(str) {
|
|
|
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function consoleSanitize(str) {
|
|
|
|
return str.replace(/<(http[^>]*)>/, "$1");
|
|
|
|
}
|
|
|
|
|
|
|
|
function htmlSanitize(str, type) {
|
|
|
|
var temp = document.createElement("div");
|
|
|
|
temp.textContent = str;
|
|
|
|
return temp.innerHTML.replace(
|
|
|
|
/<(http[^>]*)>/,
|
|
|
|
"<<a style='color: inherit' target='_blank' href='$1'>$1</a>>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-13 22:08:47 +03:00
|
|
|
function parseHeader(title, path) {
|
|
|
|
return `-- ${(title || "ERROR").replace("-", " ")} --------------- ${
|
|
|
|
path || ""
|
|
|
|
}`;
|
|
|
|
}
|
2021-04-08 05:48:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
|-------------------------------------------------------------------------------
|
|
|
|
| Console Logging
|
|
|
|
|-------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
const wrapConsole = (str) => `%c${str}`;
|
|
|
|
const consoleHeader = pipe(parseHeader, wrapConsole, addNewLine, addNewLine);
|
|
|
|
|
|
|
|
const parseMsg = pipe(consoleSanitize, wrapConsole);
|
|
|
|
const consoleMsg = ({ error, style }, msg) => ({
|
|
|
|
error: error.concat(parseMsg(typeof msg === "string" ? msg : msg.string)),
|
|
|
|
style: style.concat(
|
|
|
|
parseStyle(typeof msg === "string" ? { color: "black" } : msg)
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
const joinMessage = ({ error, style }) => [error.join("")].concat(style);
|
|
|
|
|
2022-02-03 22:51:34 +03:00
|
|
|
const parseConsoleErrors =
|
|
|
|
(path) =>
|
2021-08-03 03:38:38 +03:00
|
|
|
/**
|
2022-02-03 22:51:34 +03:00
|
|
|
* @param {{ title: string; message: Message[]}} info
|
2021-08-03 03:38:38 +03:00
|
|
|
* */
|
2022-02-03 22:51:34 +03:00
|
|
|
(info) => {
|
|
|
|
if (info.rule) {
|
2023-01-13 22:08:47 +03:00
|
|
|
if (info.details) {
|
|
|
|
return joinMessage(
|
|
|
|
info.details.reduce(consoleMsg, {
|
|
|
|
error: [consoleHeader(info.rule, path)],
|
|
|
|
style: [styleColor("blue")],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2022-02-03 22:51:34 +03:00
|
|
|
return joinMessage(
|
|
|
|
info.formatted.reduce(consoleMsg, {
|
|
|
|
error: [consoleHeader(info.rule, path)],
|
|
|
|
style: [styleColor("blue")],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return joinMessage(
|
|
|
|
info.message.reduce(consoleMsg, {
|
|
|
|
error: [consoleHeader(info.title, path)],
|
|
|
|
style: [styleColor("blue")],
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2021-08-03 03:38:38 +03:00
|
|
|
|
2022-02-03 22:51:34 +03:00
|
|
|
/**
|
|
|
|
* @param {RootObject} error
|
|
|
|
* */
|
|
|
|
const restoreColorConsole = (error) => {
|
|
|
|
if (error.type === "compile-errors" && error.errors) {
|
2021-08-03 03:38:38 +03:00
|
|
|
return error.errors.reduce(
|
|
|
|
(acc, { problems, path }) =>
|
|
|
|
acc.concat(problems.map(parseConsoleErrors(path))),
|
|
|
|
[]
|
|
|
|
);
|
2022-02-03 22:51:34 +03:00
|
|
|
} else if (error.type === "review-errors" && error.errors) {
|
2021-08-27 20:27:37 +03:00
|
|
|
return error.errors.reduce(
|
|
|
|
(acc, { errors, path }) =>
|
|
|
|
acc.concat(errors.map(parseConsoleErrors(path))),
|
|
|
|
[]
|
|
|
|
);
|
2022-02-03 22:51:34 +03:00
|
|
|
} else if (error.type === "error") {
|
|
|
|
return parseConsoleErrors(error.path)(error);
|
2021-08-03 03:38:38 +03:00
|
|
|
} else {
|
|
|
|
console.error(`Unknown error type ${error}`);
|
|
|
|
}
|
2022-02-03 22:51:34 +03:00
|
|
|
};
|
2021-04-08 05:48:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
|-------------------------------------------------------------------------------
|
|
|
|
| Html Logging
|
|
|
|
|-------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
const htmlHeader = (title, path) =>
|
|
|
|
`<span style="${parseStyle({ color: "blue" })}">${parseHeader(
|
|
|
|
title,
|
|
|
|
path
|
|
|
|
)}</span>\n\n`;
|
|
|
|
|
|
|
|
const htmlMsg = (acc, msg) =>
|
|
|
|
`${acc}<span style="${parseStyle(
|
|
|
|
typeof msg === "string" ? { color: "WHITE" } : msg
|
|
|
|
)}">${htmlSanitize(typeof msg === "string" ? msg : msg.string)}</span>`;
|
|
|
|
|
2021-08-27 20:27:37 +03:00
|
|
|
const parseHtmlErrors = (path) => (info) => {
|
|
|
|
if (info.rule) {
|
2022-02-03 22:51:34 +03:00
|
|
|
return info.formatted.reduce(htmlMsg, htmlHeader(info.rule, path));
|
2021-08-27 20:27:37 +03:00
|
|
|
} else {
|
2023-01-13 22:08:47 +03:00
|
|
|
if (info.details) {
|
|
|
|
return info.details.reduce(htmlMsg, htmlHeader(info.title, path));
|
|
|
|
}
|
2022-02-03 22:51:34 +03:00
|
|
|
return info.message.reduce(htmlMsg, htmlHeader(info.title, path));
|
2021-08-27 20:27:37 +03:00
|
|
|
}
|
2022-02-03 22:51:34 +03:00
|
|
|
};
|
2021-04-08 05:48:52 +03:00
|
|
|
|
2022-02-03 22:51:34 +03:00
|
|
|
const restoreColorHtml =
|
|
|
|
/**
|
|
|
|
* @param {RootObject} error
|
|
|
|
* */
|
|
|
|
(error) => {
|
|
|
|
if (error.type === "compile-errors") {
|
|
|
|
return error.errors.reduce(
|
|
|
|
(acc, { problems, path }) =>
|
|
|
|
acc.concat(problems.map(parseHtmlErrors(path))),
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
} else if (error.type === "review-errors") {
|
|
|
|
return error.errors.reduce(
|
|
|
|
(acc, { errors, path }) =>
|
|
|
|
acc.concat(errors.map(parseHtmlErrors(path))),
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
} else if (error.type === "error") {
|
|
|
|
return parseHtmlErrors(error.path)(error);
|
|
|
|
} else {
|
|
|
|
throw new Error(`Unknown error type ${error}`);
|
|
|
|
}
|
|
|
|
};
|
2021-04-08 05:48:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
|-------------------------------------------------------------------------------
|
|
|
|
| TODO: Refactor Below
|
|
|
|
|-------------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
var speed = 400;
|
|
|
|
var delay = 20;
|
|
|
|
|
2021-08-03 03:38:38 +03:00
|
|
|
/**
|
|
|
|
* @param {RootObject} error
|
|
|
|
*/
|
2021-04-08 05:48:52 +03:00
|
|
|
function showError(error) {
|
2022-02-24 01:39:17 +03:00
|
|
|
try {
|
|
|
|
restoreColorConsole(error).forEach((error) => {
|
|
|
|
console.log.apply(this, error);
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Error", error);
|
|
|
|
}
|
2021-04-12 02:26:22 +03:00
|
|
|
hideCompiling("fast");
|
2021-04-08 05:48:52 +03:00
|
|
|
setTimeout(function () {
|
|
|
|
showError_(restoreColorHtml(error));
|
|
|
|
}, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showError_(error) {
|
|
|
|
var nodeContainer = document.getElementById("elm-live:elmErrorContainer");
|
|
|
|
|
|
|
|
if (!nodeContainer) {
|
|
|
|
nodeContainer = document.createElement("div");
|
|
|
|
nodeContainer.id = "elm-live:elmErrorContainer";
|
|
|
|
document.body.appendChild(nodeContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeContainer.innerHTML = `
|
|
|
|
<div
|
|
|
|
id="elm-live:elmErrorBackground"
|
|
|
|
style="
|
|
|
|
z-index: 100;
|
|
|
|
perspective: 500px;
|
|
|
|
transition: opacity 400ms;
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
background-color: rgba(13,31,45,0.2);
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content:center;
|
|
|
|
align-items: center;
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
onclick="elmLive.hideError()"
|
|
|
|
style="
|
|
|
|
background-color: rgba(0,0,0,0);
|
|
|
|
position: fixed;
|
|
|
|
top:0;
|
|
|
|
left:0;
|
|
|
|
bottom:0;
|
|
|
|
right:0
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<pre
|
|
|
|
id="elm-live:elmError"
|
|
|
|
style="
|
2021-04-08 16:04:56 +03:00
|
|
|
white-space: pre-wrap;
|
2021-04-08 05:48:52 +03:00
|
|
|
transform: rotateX(0deg);
|
|
|
|
transition: transform 400ms;
|
|
|
|
transform-style: preserve-3d;
|
|
|
|
font-size: 16px;
|
|
|
|
overflow: scroll;
|
|
|
|
background-color: rgba(13, 31, 45, 0.9);
|
|
|
|
color: #ddd;
|
|
|
|
width: calc(100% - 150px);
|
|
|
|
height: calc(100% - 150px);
|
|
|
|
margin: 0;
|
|
|
|
padding: 30px;
|
|
|
|
font-family: 'Fira Mono', Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
|
|
|
"
|
|
|
|
>${error}</pre>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
setTimeout(function () {
|
2022-02-25 20:02:36 +03:00
|
|
|
try {
|
|
|
|
document.getElementById("elm-live:elmErrorBackground").style.opacity = 1;
|
|
|
|
document.getElementById("elm-live:elmError").style.transform =
|
|
|
|
"rotateX(0deg)";
|
|
|
|
} catch (error) {}
|
2021-04-08 05:48:52 +03:00
|
|
|
}, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideError(velocity) {
|
|
|
|
var node = document.getElementById("elm-live:elmErrorContainer");
|
|
|
|
if (node) {
|
|
|
|
if (velocity === "fast") {
|
2022-02-25 20:02:36 +03:00
|
|
|
try {
|
|
|
|
document.getElementById("elm-live:elmErrorContainer").remove();
|
|
|
|
} catch (error) {}
|
2021-04-08 05:48:52 +03:00
|
|
|
} else {
|
2022-02-25 20:02:36 +03:00
|
|
|
try {
|
|
|
|
document.getElementById(
|
|
|
|
"elm-live:elmErrorBackground"
|
|
|
|
).style.opacity = 0;
|
|
|
|
document.getElementById("elm-live:elmError").style.transform =
|
|
|
|
"rotateX(90deg)";
|
|
|
|
} catch (error) {}
|
2021-04-08 05:48:52 +03:00
|
|
|
setTimeout(function () {
|
2022-02-25 20:02:36 +03:00
|
|
|
try {
|
|
|
|
document.getElementById("elm-live:elmErrorContainer").remove();
|
|
|
|
} catch (error) {}
|
2021-04-08 05:48:52 +03:00
|
|
|
}, speed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-10 02:36:18 +03:00
|
|
|
|
|
|
|
function showCompiling(message) {
|
|
|
|
hideError("fast");
|
|
|
|
setTimeout(function () {
|
|
|
|
showCompiling_(message);
|
|
|
|
}, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showCompiling_(message) {
|
2021-04-12 02:26:22 +03:00
|
|
|
var nodeContainer = document.getElementById("__elm-pages-loading");
|
2021-04-10 02:36:18 +03:00
|
|
|
|
|
|
|
if (!nodeContainer) {
|
|
|
|
nodeContainer = document.createElement("div");
|
|
|
|
nodeContainer.id = "__elm-pages-loading";
|
2021-04-10 19:07:35 +03:00
|
|
|
nodeContainer.class = "lds-default";
|
2021-04-10 02:36:18 +03:00
|
|
|
nodeContainer.style = `
|
|
|
|
position: fixed;
|
|
|
|
bottom: 10px;
|
|
|
|
right: 110px;
|
|
|
|
width: 80px;
|
|
|
|
height: 80px;
|
|
|
|
background-color: white;
|
|
|
|
display: block;
|
|
|
|
box-shadow: rgba(0, 0, 0, 0.25) 0px 8px 15px 0px,
|
|
|
|
rgba(0, 0, 0, 0.12) 0px 2px 10px 0px;
|
2021-04-10 19:07:35 +03:00
|
|
|
`;
|
2021-04-10 02:36:18 +03:00
|
|
|
document.body.appendChild(nodeContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeContainer.innerHTML = `
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear 0s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 37px;
|
|
|
|
left: 66px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.1s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 22px;
|
|
|
|
left: 62px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.2s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 11px;
|
|
|
|
left: 52px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.3s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 7px;
|
|
|
|
left: 37px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.4s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 11px;
|
|
|
|
left: 22px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.5s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 22px;
|
|
|
|
left: 11px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.6s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 37px;
|
|
|
|
left: 7px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.7s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 52px;
|
|
|
|
left: 11px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.8s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 62px;
|
|
|
|
left: 22px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -0.9s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 66px;
|
|
|
|
left: 37px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -1s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 62px;
|
|
|
|
left: 52px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
style="
|
|
|
|
animation: 1.2s linear -1.1s infinite normal none running lds-default;
|
|
|
|
background: rgb(0, 0, 0);
|
|
|
|
position: absolute;
|
|
|
|
width: 6px;
|
|
|
|
height: 6px;
|
|
|
|
border-radius: 50%;
|
|
|
|
top: 52px;
|
|
|
|
left: 62px;
|
|
|
|
"
|
|
|
|
></div>
|
|
|
|
`;
|
|
|
|
setTimeout(function () {
|
2022-08-08 20:58:34 +03:00
|
|
|
nodeContainer && (nodeContainer.style.opacity = "1");
|
2021-04-10 02:36:18 +03:00
|
|
|
}, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideCompiling(velocity) {
|
2021-04-12 02:26:22 +03:00
|
|
|
const node = document.getElementById("__elm-pages-loading");
|
2021-04-10 02:36:18 +03:00
|
|
|
if (node) {
|
|
|
|
if (velocity === "fast") {
|
|
|
|
node.remove();
|
|
|
|
} else {
|
|
|
|
document.getElementById("__elm-pages-loading").style.opacity = 0;
|
|
|
|
setTimeout(function () {
|
|
|
|
node.remove();
|
|
|
|
}, speed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 03:38:38 +03:00
|
|
|
|
|
|
|
/** @typedef { CompilerError | ReportError } RootObject */
|
|
|
|
|
|
|
|
/** @typedef { { type: "compile-errors"; errors: Error_[]; } } CompilerError */
|
|
|
|
/** @typedef { { type: "error"; path: string; title: string; message: Message[]; } } ReportError */
|
|
|
|
|
|
|
|
/** @typedef { { line: number; column: number; } } CodeLocation */
|
|
|
|
|
|
|
|
/** @typedef { { start: CodeLocation; end: CodeLocation; } } Region */
|
|
|
|
|
|
|
|
/** @typedef { { title: string; region: Region; message: Message[]; } } Problem */
|
|
|
|
/** @typedef {string | {underline: boolean; color: string?; string: string}} Message */
|
2021-08-27 20:27:37 +03:00
|
|
|
/** @typedef { { path: string; name: string; problems: Problem[]; } } Error_ */
|
|
|
|
|
|
|
|
/** @typedef { { type: "review-errors"; errors: IFileError[]; } } IElmReviewError */
|
|
|
|
|
|
|
|
/** @typedef { { path: string; errors: IError[]; } } IFileError */
|
|
|
|
|
|
|
|
/** @typedef { { rule: string; ruleLink: string; message: string; details: string[]; region: IRegion; fix?: { range: IRegion; string: string; }[]; } } IError */
|
|
|
|
|
|
|
|
/** @typedef { { start: IPosition; end: IPosition; } } IRegion */
|
|
|
|
/** @typedef { { line: number; column: number; } } IPosition */
|
2022-02-21 20:00:34 +03:00
|
|
|
|
|
|
|
window.connect = connect;
|