"use strict"; const entityMap = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'", "/": "/", "`": "`", "=": "=", }; function escapeHTML(s) { return s.replace(/[&<>"'`=\\/]/g, function (c) { return entityMap[c]; }); } module.exports = { template: "#gcode-viewer-template", data: function () { return { empty: true, file: "", line: -1, }; }, events: { "gcode-load": function (file) { this.load(file); }, "gcode-clear": function () { this.clear(); }, "gcode-reload": function (file) { this.reload(file); }, "gcode-line": function (line) { this.update_line(line); }, }, ready: function () { this.clusterize = new Clusterize({ rows: [], scrollElem: this.$el.querySelector(".clusterize-scroll"), contentElem: this.$el.querySelector(".clusterize-content"), no_data_text: "GCode view...", callbacks: { clusterChanged: this.highlight }, }); }, attached: function () { if (typeof this.clusterize != "undefined") { this.clusterize.refresh(true); } }, methods: { load: async function (file) { if (file == this.file) { return; } this.clear(); this.file = file; if (!file) { return; } const response = await fetch(`/api/file/${file}`, { cache: "no-cache" }); const text = await response.text(); if (text.length > 20e6) { this.clusterize.update(["File is large - gcode view disabled"]); } else { const lines = escapeHTML(text.trimRight()) .split(/[\r\n]/) .map((line, i) => `