gouki510/MechInterp_ja
0
1/******/ (() => { // webpackBootstrap2/******/ "use strict";3 4;// ./src/fragmentLoader.js5function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }6function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }7function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }8function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }9function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }10function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }11function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }12function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }13function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }14function loadFragments() {15 return _loadFragments.apply(this, arguments);16}17function _loadFragments() {18 _loadFragments = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {19 var fragmentElements, FetchQueue, fetchQueue, currentIndex, elements;20 return _regeneratorRuntime().wrap(function _callee7$(_context7) {21 while (1) switch (_context7.prev = _context7.next) {22 case 0:23 // Find all elements with ids starting with 'fragment-'24 fragmentElements = Array.from(document.querySelectorAll('[id^="fragment-"]'));25 FetchQueue = /*#__PURE__*/function () {26 function FetchQueue() {27 var maxConcurrent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3;28 _classCallCheck(this, FetchQueue);29 this.queue = [];30 this.maxConcurrent = maxConcurrent;31 this.activeFetches = 0;32 this.maxRetries = 3; // Maximum number of retry attempts33 this.baseDelay = 1000; // Base delay in milliseconds (1 second)34 }35 return _createClass(FetchQueue, [{36 key: "sleep",37 value: function () {38 var _sleep = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(ms) {39 return _regeneratorRuntime().wrap(function _callee$(_context) {40 while (1) switch (_context.prev = _context.next) {41 case 0:42 return _context.abrupt("return", new Promise(function (resolve) {43 return setTimeout(resolve, ms);44 }));45 case 1:46 case "end":47 return _context.stop();48 }49 }, _callee);50 }));51 function sleep(_x) {52 return _sleep.apply(this, arguments);53 }54 return sleep;55 }()56 }, {57 key: "fetchWithRetry",58 value: function () {59 var _fetchWithRetry = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(fragmentPath) {60 var retryCount,61 response,62 delay,63 _args2 = arguments;64 return _regeneratorRuntime().wrap(function _callee2$(_context2) {65 while (1) switch (_context2.prev = _context2.next) {66 case 0:67 retryCount = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : 0;68 _context2.prev = 1;69 _context2.next = 4;70 return fetch(fragmentPath);71 case 4:72 response = _context2.sent;73 if (response.ok) {74 _context2.next = 7;75 break;76 }77 throw new Error("HTTP error! status: ".concat(response.status));78 case 7:79 _context2.next = 9;80 return response.text();81 case 9:82 return _context2.abrupt("return", _context2.sent);83 case 12:84 _context2.prev = 12;85 _context2.t0 = _context2["catch"](1);86 if (!(retryCount < this.maxRetries)) {87 _context2.next = 20;88 break;89 }90 // Exponential backoff: 1s, 2s, 4s91 delay = this.baseDelay * Math.pow(2, retryCount);92 console.warn("Retry ".concat(retryCount + 1, "/").concat(this.maxRetries, " for ").concat(fragmentPath, " after ").concat(delay, "ms"));93 _context2.next = 19;94 return this.sleep(delay);95 case 19:96 return _context2.abrupt("return", this.fetchWithRetry(fragmentPath, retryCount + 1));97 case 20:98 throw _context2.t0;99 case 21:100 case "end":101 return _context2.stop();102 }103 }, _callee2, this, [[1, 12]]);104 }));105 function fetchWithRetry(_x2) {106 return _fetchWithRetry.apply(this, arguments);107 }108 return fetchWithRetry;109 }()110 }, {111 key: "addFetch",112 value: function () {113 var _addFetch = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(element) {114 var _this = this;115 var fragmentName, fragmentPath;116 return _regeneratorRuntime().wrap(function _callee5$(_context5) {117 while (1) switch (_context5.prev = _context5.next) {118 case 0:119 fragmentName = element.id.replace('fragment-', '');120 fragmentPath = "fragments/".concat(fragmentName, ".html");121 return _context5.abrupt("return", new Promise(/*#__PURE__*/function () {122 var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(resolve, reject) {123 var fetchPromise;124 return _regeneratorRuntime().wrap(function _callee4$(_context4) {125 while (1) switch (_context4.prev = _context4.next) {126 case 0:127 try {128 fetchPromise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {129 var html, temp, scripts;130 return _regeneratorRuntime().wrap(function _callee3$(_context3) {131 while (1) switch (_context3.prev = _context3.next) {132 case 0:133 _context3.prev = 0;134 _context3.next = 3;135 return _this.fetchWithRetry(fragmentPath);136 case 3:137 html = _context3.sent;138 // Process the fragment139 temp = document.createElement('div');140 temp.innerHTML = html;141 element.innerHTML = temp.innerHTML;142 143 // Handle scripts144 scripts = temp.getElementsByTagName('script');145 Array.from(scripts).forEach(function (oldScript) {146 var newScript = document.createElement('script');147 Array.from(oldScript.attributes).forEach(function (attr) {148 newScript.setAttribute(attr.name, attr.value);149 });150 newScript.textContent = oldScript.textContent;151 oldScript.parentNode.removeChild(oldScript);152 document.body.appendChild(newScript);153 });154 _this.activeFetches--;155 resolve();156 _context3.next = 18;157 break;158 case 13:159 _context3.prev = 13;160 _context3.t0 = _context3["catch"](0);161 console.error("Failed to load fragment ".concat(fragmentPath, " after ").concat(_this.maxRetries, " retries:"), _context3.t0);162 _this.activeFetches--;163 reject(_context3.t0);164 case 18:165 case "end":166 return _context3.stop();167 }168 }, _callee3, null, [[0, 13]]);169 }))();170 _this.queue.push(fetchPromise);171 _this.activeFetches++;172 } catch (error) {173 reject(error);174 }175 case 1:176 case "end":177 return _context4.stop();178 }179 }, _callee4);180 }));181 return function (_x4, _x5) {182 return _ref.apply(this, arguments);183 };184 }()));185 case 3:186 case "end":187 return _context5.stop();188 }189 }, _callee5);190 }));191 function addFetch(_x3) {192 return _addFetch.apply(this, arguments);193 }194 return addFetch;195 }()196 }, {197 key: "processNext",198 value: function () {199 var _processNext = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(element) {200 return _regeneratorRuntime().wrap(function _callee6$(_context6) {201 while (1) switch (_context6.prev = _context6.next) {202 case 0:203 if (!(this.activeFetches < this.maxConcurrent && element)) {204 _context6.next = 3;205 break;206 }207 _context6.next = 3;208 return this.addFetch(element);209 case 3:210 case "end":211 return _context6.stop();212 }213 }, _callee6, this);214 }));215 function processNext(_x6) {216 return _processNext.apply(this, arguments);217 }218 return processNext;219 }()220 }]);221 }(); // Initialize queue222 fetchQueue = new FetchQueue(3);223 currentIndex = 0;224 elements = fragmentElements; // Assuming this is defined elsewhere225 // Initial loading of first 3 elements226 case 5:227 if (!(currentIndex < elements.length && currentIndex < 3)) {228 _context7.next = 11;229 break;230 }231 _context7.next = 8;232 return fetchQueue.processNext(elements[currentIndex]);233 case 8:234 currentIndex++;235 _context7.next = 5;236 break;237 case 11:238 if (!(currentIndex < elements.length)) {239 _context7.next = 20;240 break;241 }242 _context7.next = 14;243 return Promise.race(fetchQueue.queue);244 case 14:245 // Remove completed fetch from queue246 fetchQueue.queue = fetchQueue.queue.filter(function (p) {247 return p.status === 'pending';248 });249 // Add next element to queue250 _context7.next = 17;251 return fetchQueue.processNext(elements[currentIndex]);252 case 17:253 currentIndex++;254 _context7.next = 11;255 break;256 case 20:257 _context7.next = 22;258 return Promise.all(fetchQueue.queue);259 case 22:260 case "end":261 return _context7.stop();262 }263 }, _callee7);264 }));265 return _loadFragments.apply(this, arguments);266}267 268;// ./src/syncHFSpacesURLHash.js269var queryArg = "section";270function syncHFSpacesURLHash() {271 // Handle explicit section requests (don't update hash automatically on load)272 var hasExplicitRequest = handleExplicitSectionRequest();273 274 // Set up hash change monitoring275 updateHashBasedOnHashChange();276 277 // Always set up scroll monitoring to update hash during scrolling278 setupScrollMonitoring();279 280 // If no explicit request, we don't update the hash on initial load281 // The hash will only start updating when the user scrolls282}283function handleExplicitSectionRequest() {284 // Check for section parameter in URL285 var urlParams = new URLSearchParams(window.location.search);286 var sectionId = urlParams.get(queryArg);287 288 // If we have an explicit section request289 if (sectionId) {290 var targetElement = document.getElementById(sectionId);291 if (targetElement) {292 // Slight delay to ensure the browser doesn't try to do its own scrolling first293 setTimeout(function () {294 targetElement.scrollIntoView();295 history.replaceState(null, null, "#".concat(sectionId));296 }, 100);297 }298 return true;299 }300 301 // No explicit section parameter found302 return false;303}304function setupScrollMonitoring() {305 // Variables to manage throttling306 var isScrolling = false;307 var lastKnownScrollPosition = 0;308 var initialScroll = true;309 310 // Add the scroll event listener311 window.addEventListener('scroll', function () {312 lastKnownScrollPosition = window.scrollY;313 if (!isScrolling) {314 window.requestAnimationFrame(function () {315 // Skip the first scroll event which might be browser's automatic scroll316 // to a hash on page load317 if (initialScroll) {318 initialScroll = false;319 } else {320 updateHashBasedOnScroll(lastKnownScrollPosition);321 }322 isScrolling = false;323 });324 }325 isScrolling = true;326 });327}328 329// Function to update the URL hash based on scroll position330function updateHashBasedOnScroll(scrollPosition) {331 var closestHeading = findClosestHeading(scrollPosition);332 333 // Update the URL hash if we found a closest element334 if (closestHeading && closestHeading.id) {335 // Only update if the hash is different to avoid unnecessary operations336 if (window.location.hash !== "#".concat(closestHeading.id)) {337 silentlyUpdateHash(closestHeading.id);338 postMessageToHFSpaces(closestHeading.id);339 }340 }341}342 343// Find the closest heading to the current scroll position344function findClosestHeading(scrollPosition) {345 // Get only heading elements with IDs that we want to track346 var headingsWithIds = Array.from(document.querySelectorAll('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]'));347 348 // Skip if there are no headings with IDs349 if (headingsWithIds.length === 0) return null;350 351 // Find the element closest to the middle of the viewport352 var closestHeading = null;353 var closestDistance = Infinity;354 var viewportMiddle = scrollPosition + window.innerHeight / 2;355 356 // Iterate through all headings to find the closest one357 headingsWithIds.forEach(function (heading) {358 var headingTop = heading.getBoundingClientRect().top + scrollPosition;359 var distance = Math.abs(headingTop - viewportMiddle);360 if (distance < closestDistance) {361 closestDistance = distance;362 closestHeading = heading;363 }364 });365 return closestHeading;366}367 368// Update hash without triggering scroll or other side effects369function silentlyUpdateHash(id) {370 history.replaceState(null, null, "#".concat(id));371}372function updateHashBasedOnHashChange() {373 window.addEventListener('hashchange', function () {374 var elementId = window.location.hash.slice(1);375 postMessageToHFSpaces(elementId);376 });377}378function postMessageToHFSpaces(elementId) {379 var parentOrigin = "https://huggingface.co";380 window.parent.postMessage({381 queryString: "".concat(queryArg, "=").concat(elementId)382 }, parentOrigin);383}384 385;// ./src/index.js386// import { plotClusters } from './clusters'387 388 389document.addEventListener("DOMContentLoaded", function () {390 console.log("DOMContentLoaded");391 loadFragments();392 init_memory_plot();393 syncHFSpacesURLHash();394}, {395 once: true396});397/******/ })()398;399//# sourceMappingURL=main.bundle.js.map