|
| 1 | +/*! |
| 2 | + * choco-theme v0.6.0 (https://github.com/chocolatey/choco-theme#readme) |
| 3 | + * Copyright 2020-2024 Chocolatey Software |
| 4 | + * Licensed under MIT (https://github.com/chocolatey/choco-theme/blob/main/LICENSE) |
| 5 | +*/ |
| 6 | +(() => { |
| 7 | + var __create = Object.create; |
| 8 | + var __defProp = Object.defineProperty; |
| 9 | + var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 10 | + var __getOwnPropNames = Object.getOwnPropertyNames; |
| 11 | + var __getProtoOf = Object.getPrototypeOf; |
| 12 | + var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 13 | + var __commonJS = (cb, mod) => function __require() { |
| 14 | + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 15 | + }; |
| 16 | + var __copyProps = (to, from, except, desc) => { |
| 17 | + if (from && typeof from === "object" || typeof from === "function") { |
| 18 | + for (let key of __getOwnPropNames(from)) |
| 19 | + if (!__hasOwnProp.call(to, key) && key !== except) |
| 20 | + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 21 | + } |
| 22 | + return to; |
| 23 | + }; |
| 24 | + var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 25 | + // If the importer is in node compatibility mode or this is not an ESM |
| 26 | + // file that has been converted to a CommonJS file using a Babel- |
| 27 | + // compatible transform (i.e. "__esModule" has not been set), then set |
| 28 | + // "default" to the CommonJS "module.exports" for node compatibility. |
| 29 | + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 30 | + mod |
| 31 | + )); |
| 32 | + var __async = (__this, __arguments, generator) => { |
| 33 | + return new Promise((resolve, reject) => { |
| 34 | + var fulfilled = (value) => { |
| 35 | + try { |
| 36 | + step(generator.next(value)); |
| 37 | + } catch (e) { |
| 38 | + reject(e); |
| 39 | + } |
| 40 | + }; |
| 41 | + var rejected = (value) => { |
| 42 | + try { |
| 43 | + step(generator.throw(value)); |
| 44 | + } catch (e) { |
| 45 | + reject(e); |
| 46 | + } |
| 47 | + }; |
| 48 | + var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); |
| 49 | + step((generator = generator.apply(__this, __arguments)).next()); |
| 50 | + }); |
| 51 | + }; |
| 52 | + |
| 53 | + // js/src/package-differ.js |
| 54 | + var require_package_differ = __commonJS({ |
| 55 | + "js/src/package-differ.js"(exports) { |
| 56 | + (() => { |
| 57 | + const diffContainer = document.querySelector("#diffs"); |
| 58 | + if (diffContainer) { |
| 59 | + const diffContent = document.querySelector("#diffContent"); |
| 60 | + const diffSelector = document.querySelector("#diffSelector"); |
| 61 | + const anyPackageRole = document.querySelector("#anyPackageRole").value.toLowerCase() === "true"; |
| 62 | + const callEndpoint = (url) => __async(exports, null, function* () { |
| 63 | + try { |
| 64 | + const response = yield fetch(url); |
| 65 | + const data = yield response.json(); |
| 66 | + return data; |
| 67 | + } catch (error) { |
| 68 | + console.error(error); |
| 69 | + } |
| 70 | + }); |
| 71 | + const getDiffFiles = (diffFolder) => { |
| 72 | + diffContent.innerHTML = ""; |
| 73 | + return callEndpoint(`${window.location.protocol}//${window.location.host}/json/JsonApi?invoke&action=GetDiffFileUrls&folderName=${diffFolder}`).then((filePaths) => { |
| 74 | + filePaths.forEach((filePath) => { |
| 75 | + let diffFilePath = filePath.replaceAll("\\", "/").replace(".patch", "").trim(); |
| 76 | + diffFilePath = diffFilePath.split("/").slice(3); |
| 77 | + diffFilePath = diffFilePath.join("\\"); |
| 78 | + const diffFileName = /[^\\]*$/.exec(diffFilePath)[0]; |
| 79 | + const diffTarget = `diff-path-${diffFileName.replaceAll(".", "-")}`; |
| 80 | + let diffLanguage = "language-diff"; |
| 81 | + if (diffFileName.includes(".ps1") || diffFileName.includes(".psm1")) { |
| 82 | + diffLanguage = "language-diff-powershell"; |
| 83 | + } else if (diffFileName.includes(".xml") || diffFileName.includes(".config") || diffFileName.includes(".nuspec")) { |
| 84 | + diffLanguage = "language-diff-xml"; |
| 85 | + } else if (diffFileName.includes(".json")) { |
| 86 | + diffLanguage = "language-diff-json"; |
| 87 | + } else if (diffFileName.includes(".js")) { |
| 88 | + diffLanguage = "language-diff-js"; |
| 89 | + } |
| 90 | + let fileContainer = ""; |
| 91 | + let diffCollapseShow = ""; |
| 92 | + let diffCollapseExpanded = "false"; |
| 93 | + let diffBtnText = "Show"; |
| 94 | + if (anyPackageRole) { |
| 95 | + diffCollapseShow = "show"; |
| 96 | + diffCollapseExpanded = "true"; |
| 97 | + diffBtnText = "Hide"; |
| 98 | + } |
| 99 | + fileContainer = `<div class="mb-1" data-file-path="${filePath}"> |
| 100 | + <div class="p-2 border border-start border-end text-bg-body-secondary d-flex align-items-center"> |
| 101 | + <button class="btn btn-sm btn-secondary btn-show-hide me-2" type="button" data-bs-toggle="collapse" data-bs-target=".${diffTarget}" aria-expanded="${diffCollapseExpanded}" aria-controls="${diffTarget}">${diffBtnText}</button> |
| 102 | + <span>${diffFilePath}</span> |
| 103 | + </div> |
| 104 | + <div class="collapse ${diffCollapseShow} ${diffTarget}"> |
| 105 | + <pre class="mt-0 border-top-0 ps-0 pe-0"><code class="${diffLanguage} diff-highlight"></code></pre> |
| 106 | + </div> |
| 107 | + </div>`; |
| 108 | + diffContent.insertAdjacentHTML("beforeend", fileContainer); |
| 109 | + const getDiffContent = (filePath2) => { |
| 110 | + callEndpoint(`${window.location.protocol}//${window.location.host}/json/JsonApi?invoke&action=GetDiffContent&key=${filePath2}`).then((fileContent) => { |
| 111 | + const diffItems = document.querySelectorAll("[data-file-path]"); |
| 112 | + let isDuplicate = false; |
| 113 | + if (!isDuplicate) { |
| 114 | + diffItems.forEach((el) => { |
| 115 | + if (el.getAttribute("data-file-path") == filePath2) { |
| 116 | + const elPre = el.querySelector("pre"); |
| 117 | + const elCode = el.querySelector("code"); |
| 118 | + const htmlEntities = { |
| 119 | + nbsp: " ", |
| 120 | + cent: "\xA2", |
| 121 | + pound: "\xA3", |
| 122 | + yen: "\xA5", |
| 123 | + euro: "\u20AC", |
| 124 | + copy: "\xA9", |
| 125 | + reg: "\xAE", |
| 126 | + lt: "<", |
| 127 | + gt: ">", |
| 128 | + quot: '"', |
| 129 | + amp: "&", |
| 130 | + apos: "'" |
| 131 | + }; |
| 132 | + const unescapeHTML = (str) => { |
| 133 | + return str.replace(/\&([^;]+);/g, (entity, entityCode) => { |
| 134 | + let match; |
| 135 | + if (entityCode in htmlEntities) { |
| 136 | + return htmlEntities[entityCode]; |
| 137 | + } else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) { |
| 138 | + return String.fromCharCode(parseInt(match[1], 16)); |
| 139 | + } else if (match = entityCode.match(/^#(\d+)$/)) { |
| 140 | + return String.fromCharCode(~~match[1]); |
| 141 | + } else { |
| 142 | + return entity; |
| 143 | + } |
| 144 | + }); |
| 145 | + }; |
| 146 | + elCode.insertAdjacentText("afterbegin", unescapeHTML(fileContent)); |
| 147 | + const extendDiffHighlight = () => { |
| 148 | + const isOverflowing = (element) => { |
| 149 | + return element.scrollWidth > element.offsetWidth; |
| 150 | + }; |
| 151 | + if (isOverflowing(elPre)) { |
| 152 | + const elPreStyle = window.getComputedStyle(elPre); |
| 153 | + const elPrePadding = parseInt(elPreStyle.getPropertyValue("padding-left")); |
| 154 | + const elPreScrollWidth = elPre.scrollWidth - elPrePadding; |
| 155 | + const insertedToken = elPre.querySelectorAll(".token.inserted-sign.inserted"); |
| 156 | + const deletedToken = elPre.querySelectorAll(".token.deleted-sign.deleted"); |
| 157 | + const coordToken = elPre.querySelectorAll(".token.coord"); |
| 158 | + for (const i of insertedToken) { |
| 159 | + i.style.width = `${elPreScrollWidth}px`; |
| 160 | + } |
| 161 | + for (const i of deletedToken) { |
| 162 | + i.style.width = `${elPreScrollWidth}px`; |
| 163 | + } |
| 164 | + for (const i of coordToken) { |
| 165 | + i.style.width = `${elPreScrollWidth}px`; |
| 166 | + } |
| 167 | + } |
| 168 | + }; |
| 169 | + Prism.highlightElement(elCode, false, extendDiffHighlight); |
| 170 | + isDuplicate = true; |
| 171 | + } |
| 172 | + }); |
| 173 | + } |
| 174 | + }); |
| 175 | + }; |
| 176 | + const btnShowHide = diffContent.querySelector("[data-file-path]:last-child .btn-show-hide"); |
| 177 | + let isInitilized = false; |
| 178 | + btnShowHide.addEventListener("click", () => { |
| 179 | + if (btnShowHide.textContent.includes("Show")) { |
| 180 | + btnShowHide.textContent = btnShowHide.textContent.replace("Show", "Hide"); |
| 181 | + } else { |
| 182 | + btnShowHide.textContent = btnShowHide.textContent.replace("Hide", "Show"); |
| 183 | + } |
| 184 | + if (!anyPackageRole && !isInitilized) { |
| 185 | + getDiffContent(filePath); |
| 186 | + isInitilized = true; |
| 187 | + } |
| 188 | + }); |
| 189 | + if (anyPackageRole) { |
| 190 | + getDiffContent(filePath); |
| 191 | + } |
| 192 | + }); |
| 193 | + }).catch((error) => { |
| 194 | + console.error(error.message); |
| 195 | + }); |
| 196 | + }; |
| 197 | + const initDiffSelector = () => { |
| 198 | + diffSelector.addEventListener("change", (e) => { |
| 199 | + const diffFolder = e.target.value; |
| 200 | + if (diffFolder !== "default") { |
| 201 | + getDiffFiles(diffFolder); |
| 202 | + } |
| 203 | + }); |
| 204 | + }; |
| 205 | + const isDiffContainerExpanded = diffContainer.classList.contains("show") || window.location.hash == `#${diffContainer.id}`; |
| 206 | + let isDiffContainerExpandedClick = false; |
| 207 | + if (isDiffContainerExpanded && diffSelector.nodeName == "INPUT") { |
| 208 | + getDiffFiles(diffSelector.value); |
| 209 | + } else if (isDiffContainerExpanded && diffSelector.nodeName == "SELECT") { |
| 210 | + initDiffSelector(); |
| 211 | + } else { |
| 212 | + diffContainer.addEventListener("show.bs.collapse", () => { |
| 213 | + if (!isDiffContainerExpandedClick) { |
| 214 | + if (diffSelector.nodeName === "INPUT") { |
| 215 | + getDiffFiles(diffSelector.value); |
| 216 | + } else { |
| 217 | + initDiffSelector(); |
| 218 | + } |
| 219 | + } |
| 220 | + isDiffContainerExpandedClick = true; |
| 221 | + }); |
| 222 | + } |
| 223 | + } |
| 224 | + })(); |
| 225 | + } |
| 226 | + }); |
| 227 | + |
| 228 | + // js/community-package-differ.js |
| 229 | + var import_package_differ = __toESM(require_package_differ()); |
| 230 | +})(); |
0 commit comments