create-prisma-php-app 1.17.10 → 1.17.12

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.
@@ -1,1468 +1 @@
1
- var eventAttributesB6B56 = [
2
- "onclick",
3
- "ondblclick",
4
- "onmousedown",
5
- "onmouseup",
6
- "onmouseover",
7
- "onmousemove",
8
- "onmouseout",
9
- "onwheel",
10
- "onkeypress",
11
- "onkeydown",
12
- "onkeyup",
13
- "onfocus",
14
- "onblur",
15
- "onchange",
16
- "oninput",
17
- "onselect",
18
- "onsubmit",
19
- "onreset",
20
- "onresize",
21
- "onscroll",
22
- "onload",
23
- "onunload",
24
- "onabort",
25
- "onerror",
26
- "onbeforeunload",
27
- "oncopy",
28
- "oncut",
29
- "onpaste",
30
- "ondrag",
31
- "ondragstart",
32
- "ondragend",
33
- "ondragover",
34
- "ondragenter",
35
- "ondragleave",
36
- "ondrop",
37
- "oncontextmenu",
38
- "ontouchstart",
39
- "ontouchmove",
40
- "ontouchend",
41
- "ontouchcancel",
42
- "onpointerdown",
43
- "onpointerup",
44
- "onpointermove",
45
- "onpointerover",
46
- "onpointerout",
47
- "onpointerenter",
48
- "onpointerleave",
49
- "onpointercancel",
50
- ];
51
- var stateA129A = {
52
- checkedElements: new Set(),
53
- };
54
- var responseDataDEAC2 = null;
55
- var store = null;
56
- var isNavigatingA12E1 = false;
57
- var redirectRegex3AE99 = /redirect_7F834=(.+)/;
58
- (() => {
59
- // Save a reference to the original addEventListener function
60
- const originalAddEventListener = EventTarget.prototype.addEventListener;
61
- // Create a Map to store the event listeners
62
- const listeners = new Map();
63
- // Override the addEventListener method
64
- EventTarget.prototype.addEventListener = function (type, listener, options) {
65
- // Ensure that the listeners map has a Map for this EventTarget instance
66
- if (!listeners.has(this)) {
67
- listeners.set(this, new Map());
68
- }
69
- const typeListeners = listeners.get(this).get(type) || new Set();
70
- typeListeners.add(listener);
71
- // Store the listener
72
- listeners.get(this).set(type, typeListeners);
73
- // Call the original addEventListener function
74
- originalAddEventListener.call(this, type, listener, options);
75
- };
76
- // Add a method to remove all event listeners of a specific type
77
- EventTarget.prototype.removeAllEventListeners = function (type) {
78
- if (listeners.has(this) && listeners.get(this).has(type)) {
79
- // Remove each listener of the specified type
80
- listeners
81
- .get(this)
82
- .get(type)
83
- .forEach((listener) => {
84
- this.removeEventListener(type, listener);
85
- });
86
- // Remove the type map after all listeners are removed
87
- listeners.get(this).delete(type);
88
- }
89
- };
90
- })();
91
- ((history) => {
92
- const pushState = history.pushState;
93
- const replaceState = history.replaceState;
94
- history.pushState = function (state, title, url) {
95
- const result = pushState.apply(history, arguments);
96
- window.dispatchEvent(new Event("urlchange"));
97
- return result;
98
- };
99
- history.replaceState = function (state, title, url) {
100
- const result = replaceState.apply(history, arguments);
101
- window.dispatchEvent(new Event("urlchange"));
102
- return result;
103
- };
104
- })(window.history);
105
- document.addEventListener("DOMContentLoaded", attachWireFunctionEvents);
106
- function attachWireFunctionEvents() {
107
- handleHiddenAttribute();
108
- const interactiveElements = document.querySelectorAll(
109
- "button, input, select, textarea, a, form, label, div, span"
110
- );
111
- interactiveElements.forEach((element) => {
112
- handleAnchorTag(element);
113
- eventAttributesB6B56.forEach((attr) => {
114
- const originalHandler = element.getAttribute(attr);
115
- const eventType = attr.slice(2); // Get the event type (e.g., "click" from "onclick")
116
- if (originalHandler) {
117
- element.removeAttribute(attr);
118
- handleDebounce(element, eventType, originalHandler);
119
- }
120
- });
121
- // Special handling for form submit
122
- if (element instanceof HTMLFormElement) {
123
- const submitHandler = element.getAttribute("onsubmit");
124
- if (submitHandler) {
125
- element.removeAttribute("onsubmit");
126
- handleDebounce(element, "submit", submitHandler);
127
- }
128
- }
129
- });
130
- initializePpOnListeners();
131
- }
132
- // Function to check if an element has any pp-on attribute
133
- function hasPpOnAttribute(element) {
134
- const attributes = element.attributes;
135
- if (!attributes) return false;
136
- for (let i = 0; i < attributes.length; i++) {
137
- const name = attributes[i].name;
138
- if (
139
- name.startsWith("pp-on:") ||
140
- name.startsWith("data-pp-on:") ||
141
- name.startsWith("pp-on-") ||
142
- name.startsWith("data-pp-on-")
143
- ) {
144
- return true;
145
- }
146
- }
147
- return false;
148
- }
149
- // Function to find all elements with any pp-on attribute within a given context
150
- function findAllPpOnElements(context) {
151
- const result = [];
152
- if (hasPpOnAttribute(context)) {
153
- result.push(context);
154
- }
155
- if (document.evaluate) {
156
- const xpathResult = document.evaluate(
157
- './/*[@*[starts-with(name(), "pp-on:") or starts-with(name(), "data-pp-on:") or' +
158
- ' starts-with(name(), "pp-on-") or starts-with(name(), "data-pp-on-")]]',
159
- context,
160
- null,
161
- XPathResult.ORDERED_NODE_ITERATOR_TYPE,
162
- null
163
- );
164
- let node = xpathResult.iterateNext();
165
- while (node) {
166
- result.push(node);
167
- node = xpathResult.iterateNext();
168
- }
169
- } else if (typeof context.getElementsByTagName === "function") {
170
- const elements = context.getElementsByTagName("*");
171
- for (let i = 0; i < elements.length; i++) {
172
- if (hasPpOnAttribute(elements[i])) {
173
- result.push(elements[i]);
174
- }
175
- }
176
- }
177
- return result;
178
- }
179
- // Function to initialize pp-on event listeners
180
- function initializePpOnListeners() {
181
- const elements = findAllPpOnElements(document);
182
- elements.forEach((element) => {
183
- Array.from(element.attributes).forEach((attr) => {
184
- if (attr.name.startsWith("pp-on:")) {
185
- const eventName = attr.name.split(":")[1];
186
- const handler = attr.value;
187
- if (handler) {
188
- element.addEventListener(eventName, (event) => {
189
- try {
190
- new Function("event", handler).call(element, event);
191
- } catch (error) {
192
- console.error("Error executing handler:", error);
193
- }
194
- });
195
- // Optionally, remove the attribute after adding the event listener
196
- // element.removeAttribute(attr.name);
197
- }
198
- }
199
- });
200
- });
201
- }
202
- function handleHiddenAttribute() {
203
- const visibilityElements = document.querySelectorAll("[pp-visibility]");
204
- const displayNoneElements = document.querySelectorAll("[pp-display]");
205
- visibilityElements.forEach((element) =>
206
- handleVisibilityElementAttribute(
207
- element,
208
- "pp-visibility",
209
- handleElementVisibility
210
- )
211
- );
212
- displayNoneElements.forEach((element) =>
213
- handleVisibilityElementAttribute(
214
- element,
215
- "pp-display",
216
- handleElementDisplay
217
- )
218
- );
219
- }
220
- function handleVisibilityElementAttribute(element, attributeName, handler) {
221
- const attributeValue = element.getAttribute(attributeName);
222
- if (!attributeValue) return;
223
- if (isJsonLike(attributeValue)) {
224
- const config = parseJson(attributeValue);
225
- handler(element, config);
226
- } else {
227
- const timeout = parseTime(attributeValue);
228
- if (timeout > 0) {
229
- // Map attribute names to style properties
230
- const styleProperty =
231
- attributeName === "pp-visibility" ? "visibility" : "display";
232
- const hiddenValue = styleProperty === "visibility" ? "hidden" : "none";
233
- scheduleChange(element, timeout, styleProperty, hiddenValue);
234
- }
235
- }
236
- }
237
- // Function to determine if a string is JSON-like
238
- function isJsonLike(str) {
239
- // A simple check to see if the string starts with '{' and ends with '}'
240
- return str.trim().startsWith("{") && str.trim().endsWith("}");
241
- }
242
- // Function to handle visibility changes based on config
243
- function handleElementVisibility(element, config) {
244
- handleElementChange(element, config, "visibility", "hidden", "visible");
245
- }
246
- // Function to handle display changes based on config
247
- function handleElementDisplay(element, config) {
248
- handleElementChange(element, config, "display", "none", "block");
249
- }
250
- function handleElementChange(
251
- element,
252
- config,
253
- styleProperty,
254
- hiddenValue,
255
- visibleValue
256
- ) {
257
- const startTimeout = config.start ? parseTime(config.start) : 0;
258
- const endTimeout = config.end ? parseTime(config.end) : 0;
259
- if (startTimeout > 0) {
260
- element.style[styleProperty] = hiddenValue;
261
- scheduleChange(element, startTimeout, styleProperty, visibleValue);
262
- if (endTimeout > 0) {
263
- scheduleChange(
264
- element,
265
- startTimeout + endTimeout,
266
- styleProperty,
267
- hiddenValue
268
- );
269
- }
270
- } else if (endTimeout > 0) {
271
- scheduleChange(element, endTimeout, styleProperty, hiddenValue);
272
- }
273
- }
274
- // Function to schedule visibility or display changes using requestAnimationFrame
275
- function scheduleChange(element, timeout, styleProperty, value) {
276
- setTimeout(() => {
277
- requestAnimationFrame(() => {
278
- element.style[styleProperty] = value;
279
- });
280
- }, timeout);
281
- }
282
- // Function to parse time strings into milliseconds
283
- function parseTime(time) {
284
- if (typeof time === "number") {
285
- return time;
286
- }
287
- const match = time.match(/^(\d+)(ms|s|m)?$/);
288
- if (match) {
289
- const value = parseInt(match[1], 10);
290
- const unit = match[2] || "ms"; // Default to milliseconds if no unit specified
291
- switch (unit) {
292
- case "ms":
293
- return value;
294
- case "s":
295
- return value * 1000;
296
- case "m":
297
- return value * 60 * 1000;
298
- default:
299
- return value; // Default to milliseconds
300
- }
301
- }
302
- return 0; // Default to 0 if parsing fails
303
- }
304
- async function handleDebounce(element, eventType, originalHandler) {
305
- const debounceTime = element.getAttribute("pp-debounce") || "";
306
- const executeBeforeRequest = element.getAttribute("pp-beforeRequest") || "";
307
- const executeAfterRequest = element.getAttribute("pp-afterRequest") || "";
308
- const combinedHandler = async (event) => {
309
- event.preventDefault();
310
- try {
311
- if (executeBeforeRequest)
312
- await invokeHandler(element, executeBeforeRequest, event);
313
- await invokeHandler(element, originalHandler, event);
314
- if (executeAfterRequest && executeAfterRequest !== "@close")
315
- await invokeHandler(element, executeAfterRequest, event);
316
- handlerAutofocusAttribute();
317
- } catch (error) {
318
- console.error("Error in debounced handler:", error);
319
- }
320
- };
321
- if (debounceTime) {
322
- const wait = parseTime(debounceTime);
323
- const debouncedHandler = debounce(combinedHandler, wait);
324
- if (element instanceof HTMLFormElement && eventType === "submit") {
325
- element.addEventListener(eventType, (event) => {
326
- event.preventDefault();
327
- debouncedHandler(event);
328
- });
329
- } else {
330
- element.addEventListener(eventType, debouncedHandler);
331
- }
332
- } else {
333
- element.addEventListener(eventType, combinedHandler);
334
- }
335
- }
336
- function handlerAutofocusAttribute() {
337
- const ppAutofocusElements = document.querySelectorAll("[pp-autofocus]");
338
- let hasFocusedElement = false;
339
- ppAutofocusElements.forEach((el) => {
340
- if (hasFocusedElement) return;
341
- const ppAutofocusAttribute = el.getAttribute("pp-autofocus");
342
- if (!ppAutofocusAttribute || !isJsonLike(ppAutofocusAttribute)) return;
343
- const ppAutofocusConfig = parseJson(ppAutofocusAttribute);
344
- if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
345
- if (el.type === "number" && el instanceof HTMLInputElement) {
346
- el.type = "text";
347
- const length = el.value.length || 0;
348
- el.setSelectionRange(length, length);
349
- el.type = "number";
350
- } else {
351
- if (ppAutofocusConfig.start) {
352
- el.setSelectionRange(0, 0);
353
- } else if (ppAutofocusConfig.end) {
354
- const currentAutofocusLength = el.value.length || 0;
355
- el.setSelectionRange(currentAutofocusLength, currentAutofocusLength);
356
- } else if (ppAutofocusConfig.length) {
357
- const length = parseInt(ppAutofocusConfig.length, 10) || 0;
358
- el.setSelectionRange(length, length);
359
- }
360
- }
361
- }
362
- el.focus();
363
- hasFocusedElement = true;
364
- });
365
- }
366
- async function invokeHandler(element, handler, event) {
367
- try {
368
- // Extract method details from the handler string
369
- const methodMatch = handler.match(/^(\w+(\.\w+)*)\((.*)\)$/);
370
- if (methodMatch) {
371
- const fullMethodName = methodMatch[1];
372
- const methodParts = fullMethodName.split(".");
373
- const { context, methodName } = resolveContext(methodParts);
374
- if (typeof context[methodName] === "function") {
375
- new Function("event", handler).call(element, event);
376
- } else {
377
- await handleParsedCallback(element, handler);
378
- }
379
- } else {
380
- await handleParsedCallback(element, handler);
381
- }
382
- } catch (error) {
383
- console.error(`Error executing handler ${handler}:`, error);
384
- }
385
- }
386
- /**
387
- * Resolve the context and method name for nested methods.
388
- * @param methodParts - Array of method parts split by dots.
389
- * @returns Object containing the resolved context and method name.
390
- */
391
- function resolveContext(methodParts) {
392
- let context = window;
393
- for (let i = 0; i < methodParts.length - 1; i++) {
394
- context = context[methodParts[i]];
395
- if (!context) {
396
- throw new Error(`Cannot find object ${methodParts[i]} in the context.`);
397
- }
398
- }
399
- return { context, methodName: methodParts[methodParts.length - 1] };
400
- }
401
- /**
402
- * Handle parsing and executing the callback from the element's handler.
403
- * @param element - HTML element that initiated the handler.
404
- * @param handler - Handler string to be parsed and executed.
405
- */
406
- async function handleParsedCallback(element, handler) {
407
- const { funcName, data } = parseCallback(element, handler);
408
- if (!funcName) return;
409
- const func = window[funcName];
410
- if (typeof func === "function") {
411
- const isAfterRequest = element.hasAttribute("pp-afterRequest");
412
- const args = Array.isArray(data.args) ? data.args : [];
413
- const response = responseDataDEAC2
414
- ? parseJson(responseDataDEAC2)
415
- : { response: responseDataDEAC2 };
416
- let params = {
417
- args,
418
- element,
419
- data,
420
- };
421
- if (isAfterRequest) {
422
- params = {
423
- ...params,
424
- ...response,
425
- };
426
- }
427
- await func(params);
428
- } else {
429
- responseDataDEAC2 = null;
430
- responseDataDEAC2 = await handleUndefinedFunction(element, funcName, data);
431
- }
432
- }
433
- function handleAnchorTag(element) {
434
- if (!(element instanceof HTMLAnchorElement)) return;
435
- element.addEventListener("click", async (event) => {
436
- const anchor = event.currentTarget;
437
- const href = anchor.getAttribute("href");
438
- const target = anchor.getAttribute("target");
439
- // If there's no href, or the target is _blank, or the meta key is pressed, allow default behavior
440
- if (!href || target === "_blank" || event.metaKey || event.ctrlKey) {
441
- return;
442
- }
443
- event.preventDefault(); // Prevent the default navigation
444
- if (isNavigatingA12E1) return; // Prevent multiple navigations
445
- isNavigatingA12E1 = true;
446
- try {
447
- const isExternal =
448
- /^(https?:)?\/\//i.test(href) &&
449
- !href.startsWith(window.location.origin);
450
- if (isExternal) {
451
- window.location.href = href;
452
- } else {
453
- const [_, hash] = href.split("#");
454
- history.pushState(null, "", href);
455
- if (hash) {
456
- const targetElement = document.getElementById(hash);
457
- if (targetElement) {
458
- targetElement.scrollIntoView({ behavior: "smooth" });
459
- }
460
- } else {
461
- await handleNavigation();
462
- }
463
- }
464
- } catch (error) {
465
- console.error("Anchor click error:", error);
466
- } finally {
467
- isNavigatingA12E1 = false;
468
- }
469
- });
470
- }
471
- // Handle browser's back/forward navigation
472
- window.addEventListener("popstate", async () => {
473
- await handleNavigation();
474
- });
475
- async function handleNavigation() {
476
- try {
477
- const dynamicPart = window.location.pathname;
478
- const parentElement = document.getElementById("loading-file-1B87E");
479
- if (parentElement) {
480
- // First, try to find the specific loading element
481
- let loadingElement = parentElement.querySelector(
482
- `div[pp-loading-url='${dynamicPart}']`
483
- );
484
- // If the specific element is not found, fall back to the global '/'
485
- if (!loadingElement) {
486
- loadingElement = parentElement.querySelector("div[pp-loading-url='/']");
487
- }
488
- if (loadingElement) {
489
- const pageContent = document.querySelector(
490
- "[pp-loading-content='true']"
491
- );
492
- if (pageContent) {
493
- pageContent.innerHTML = loadingElement.innerHTML;
494
- } else {
495
- document.body.innerHTML = loadingElement.innerHTML;
496
- }
497
- }
498
- }
499
- const data = await pphpFetch(window.location.href);
500
- const match = data.match(redirectRegex3AE99);
501
- if (match && match[1]) {
502
- const url = match[1];
503
- await handleRedirect(url);
504
- } else {
505
- updateDocumentContent(data);
506
- }
507
- } catch (error) {
508
- console.error("Navigation error:", error);
509
- }
510
- }
511
- window.addEventListener("urlchange", () => {
512
- // console.log("URL changed:", window.location.href);
513
- // Call your function here
514
- // onUrlChange();
515
- });
516
- function onUrlChange() {
517
- // console.log("Handling URL change");
518
- // Add your code to handle the URL change here
519
- }
520
- function updateDocumentContent(data) {
521
- const scrollPositions = saveScrollPositions();
522
- document.removeAllEventListeners("DOMContentLoaded");
523
- if (data.includes("<!DOCTYPE html>")) {
524
- const newDoc = new DOMParser().parseFromString(data, "text/html");
525
- const replaceDocumentContent = (newDoc) => {
526
- Array.from(newDoc.head.children).forEach((newHeadChild) => {
527
- const tagName = newHeadChild.tagName;
528
- if (tagName === "META") {
529
- // Exclude specific meta tags like <meta charset="UTF-8">
530
- if (
531
- newHeadChild.getAttribute("charset") ||
532
- newHeadChild.getAttribute("name") === "viewport"
533
- ) {
534
- return;
535
- }
536
- // Check if the meta tag already exists
537
- const nameAttr = newHeadChild.name;
538
- const propertyAttr = newHeadChild.getAttribute("property");
539
- const existingMeta = document.head.querySelector(
540
- nameAttr
541
- ? `meta[name="${nameAttr}"]`
542
- : `meta[property="${propertyAttr}"]`
543
- );
544
- // If the meta tag doesn't exist, add it
545
- if (existingMeta) {
546
- document.head.replaceChild(
547
- newHeadChild.cloneNode(true),
548
- existingMeta
549
- );
550
- } else {
551
- document.head.appendChild(newHeadChild.cloneNode(true));
552
- }
553
- } else if (tagName === "TITLE") {
554
- // Check if the title tag already exists
555
- const existingTitle = document.head.querySelector("title");
556
- if (existingTitle) {
557
- document.head.replaceChild(
558
- newHeadChild.cloneNode(true),
559
- existingTitle
560
- );
561
- } else {
562
- document.head.appendChild(newHeadChild.cloneNode(true));
563
- }
564
- } else if (tagName === "LINK") {
565
- const updateFavicon = (newFaviconHref) => {
566
- const existingLink =
567
- document.head.querySelector('link[rel="icon"]');
568
- if (existingLink) {
569
- document.head.replaceChild(
570
- newHeadChild.cloneNode(true),
571
- existingLink
572
- );
573
- } else {
574
- const newLink = document.createElement("link");
575
- newLink.rel = "icon";
576
- newLink.href = newFaviconHref;
577
- document.head.appendChild(newLink);
578
- }
579
- };
580
- if (newHeadChild.getAttribute("rel") === "icon") {
581
- const newFaviconHref = newHeadChild.href;
582
- updateFavicon(newFaviconHref);
583
- }
584
- }
585
- });
586
- loadAndValidateContent(newDoc);
587
- };
588
- // Replace the document content keeping positions of scripts and styles
589
- replaceDocumentContent(newDoc);
590
- } else {
591
- saveState();
592
- const newDoc = new DOMParser().parseFromString(data, "text/html");
593
- loadAndValidateContent(newDoc);
594
- restoreState();
595
- }
596
- restoreScrollPositions(scrollPositions);
597
- attachWireFunctionEvents();
598
- document.dispatchEvent(new Event("DOMContentLoaded"));
599
- }
600
- function loadAndValidateContent(newDoc) {
601
- const elementStore = new Map();
602
- const documentFragment = document.createDocumentFragment();
603
- function processElement(element, parentClone) {
604
- let newElement = null;
605
- if (element.tagName === "SCRIPT") {
606
- const newScript = document.createElement("script");
607
- const scriptElement = element;
608
- if (scriptElement.src) {
609
- newScript.src = scriptElement.src;
610
- newScript.async = false; // Ensure scripts execute in order
611
- } else {
612
- newScript.textContent = scriptElement.textContent;
613
- }
614
- newElement = newScript;
615
- } else {
616
- newElement = element.cloneNode(false);
617
- elementStore.set(element, newElement);
618
- Array.from(element.childNodes).forEach((childNode) => {
619
- if (childNode.nodeType === Node.TEXT_NODE) {
620
- newElement.appendChild(
621
- document.createTextNode(childNode.textContent || "")
622
- );
623
- } else if (childNode.nodeType === Node.ELEMENT_NODE) {
624
- processElement(childNode, newElement);
625
- }
626
- });
627
- }
628
- parentClone.appendChild(newElement);
629
- }
630
- Array.from(newDoc.body.children).forEach((newBodyChild) => {
631
- processElement(newBodyChild, documentFragment);
632
- });
633
- document.body.innerHTML = "";
634
- document.body.appendChild(documentFragment);
635
- }
636
- function saveState() {
637
- const focusElement = document.activeElement;
638
- stateA129A.focusId = focusElement?.id || focusElement?.name;
639
- stateA129A.focusValue = focusElement?.value;
640
- stateA129A.focusChecked = focusElement?.checked;
641
- stateA129A.focusType = focusElement?.type;
642
- stateA129A.focusSelectionStart = focusElement?.selectionStart;
643
- stateA129A.focusSelectionEnd = focusElement?.selectionEnd;
644
- stateA129A.isSuspense = focusElement.hasAttribute("pp-suspense");
645
- stateA129A.checkedElements.clear();
646
- document.querySelectorAll('input[type="checkbox"]:checked').forEach((el) => {
647
- stateA129A.checkedElements.add(el.id || el.name);
648
- });
649
- document.querySelectorAll('input[type="radio"]:checked').forEach((el) => {
650
- stateA129A.checkedElements.add(el.id || el.name);
651
- });
652
- }
653
- function restoreState() {
654
- if (stateA129A.focusId) {
655
- const newFocusElement =
656
- document.getElementById(stateA129A.focusId) ||
657
- document.querySelector(`[name="${stateA129A.focusId}"]`);
658
- if (newFocusElement instanceof HTMLInputElement) {
659
- const length = newFocusElement.value.length || 0;
660
- if (
661
- stateA129A.focusSelectionStart !== undefined &&
662
- stateA129A.focusSelectionEnd !== null
663
- ) {
664
- newFocusElement.setSelectionRange(length, length);
665
- }
666
- if (stateA129A.focusValue) {
667
- if (
668
- newFocusElement.type === "checkbox" ||
669
- newFocusElement.type === "radio"
670
- ) {
671
- newFocusElement.checked = !!stateA129A.focusChecked;
672
- } else if (newFocusElement.type === "number") {
673
- newFocusElement.type = "text";
674
- newFocusElement.setSelectionRange(length, length);
675
- newFocusElement.type = "number";
676
- } else {
677
- if (newFocusElement.value !== "")
678
- newFocusElement.value = stateA129A.focusValue;
679
- }
680
- }
681
- newFocusElement.focus();
682
- } else if (newFocusElement instanceof HTMLTextAreaElement) {
683
- const length = newFocusElement.value.length || 0;
684
- if (
685
- stateA129A.focusSelectionStart !== undefined &&
686
- stateA129A.focusSelectionEnd !== null
687
- ) {
688
- newFocusElement.setSelectionRange(length, length);
689
- }
690
- if (stateA129A.focusValue) {
691
- if (newFocusElement.value !== "")
692
- newFocusElement.value = stateA129A.focusValue;
693
- }
694
- newFocusElement.focus();
695
- } else if (newFocusElement instanceof HTMLSelectElement) {
696
- if (stateA129A.focusValue) {
697
- if (newFocusElement.value !== "")
698
- newFocusElement.value = stateA129A.focusValue;
699
- }
700
- newFocusElement.focus();
701
- }
702
- }
703
- stateA129A.checkedElements.forEach((id) => {
704
- const checkbox = document.getElementById(id);
705
- if (checkbox) {
706
- checkbox.checked = true;
707
- }
708
- });
709
- }
710
- function saveScrollPositions() {
711
- const scrollPositions = {};
712
- document.querySelectorAll("*").forEach((el) => {
713
- if (el.scrollTop || el.scrollLeft) {
714
- scrollPositions[getElementKey(el)] = {
715
- scrollTop: el.scrollTop,
716
- scrollLeft: el.scrollLeft,
717
- };
718
- }
719
- });
720
- return scrollPositions;
721
- }
722
- function restoreScrollPositions(scrollPositions) {
723
- document.querySelectorAll("*").forEach((el) => {
724
- const key = getElementKey(el);
725
- if (scrollPositions[key]) {
726
- el.scrollTop = scrollPositions[key].scrollTop;
727
- el.scrollLeft = scrollPositions[key].scrollLeft;
728
- }
729
- });
730
- }
731
- function getElementKey(el) {
732
- return el.id || el.className || el.tagName;
733
- }
734
- async function pphpFetch(url, options) {
735
- const data = await fetch(url, {
736
- ...options,
737
- headers: {
738
- ...options?.headers,
739
- "X-Requested-With": "XMLHttpRequest",
740
- },
741
- });
742
- return await data.text();
743
- }
744
- function parseCallback(element, callback) {
745
- let data = {};
746
- // Check if the element is inside a form
747
- const form = element.closest("form");
748
- if (form) {
749
- // Serialize the form data
750
- const formData = new FormData(form);
751
- formData.forEach((value, key) => {
752
- if (data[key]) {
753
- // Handle multiple values
754
- if (Array.isArray(data[key])) {
755
- data[key].push(value);
756
- } else {
757
- data[key] = [data[key], value];
758
- }
759
- } else {
760
- data[key] = value;
761
- }
762
- });
763
- } else {
764
- // Handle single input element
765
- if (element instanceof HTMLInputElement) {
766
- data = handleInputElement(element);
767
- } else if (element instanceof HTMLSelectElement) {
768
- data[element.name] = element.value;
769
- } else if (element instanceof HTMLTextAreaElement) {
770
- data[element.name] = element.value;
771
- }
772
- }
773
- // Parse function name and arguments from the callback string
774
- const match = callback.match(/(\w+)\((.*)\)/);
775
- if (match) {
776
- const funcName = match[1];
777
- let rawArgs = match[2].trim();
778
- if (rawArgs.startsWith("{") && rawArgs.endsWith("}")) {
779
- try {
780
- const parsedArg = parseJson(rawArgs);
781
- if (typeof parsedArg === "object" && parsedArg !== null) {
782
- data = { ...data, ...parsedArg };
783
- }
784
- } catch (e) {
785
- console.error("Error parsing JSON:", e);
786
- }
787
- } else {
788
- const args = rawArgs
789
- .split(/,(?=(?:[^'"]*['"][^'"]*['"])*[^'"]*$)/)
790
- .map((arg) => arg.trim().replace(/^['"]|['"]$/g, ""));
791
- data.args = args;
792
- }
793
- return { funcName, data };
794
- }
795
- return { funcName: callback, data };
796
- }
797
- function handleInputElement(element) {
798
- let data = {};
799
- // Only proceed if the element has a name
800
- if (element.name) {
801
- // Handle checkboxes
802
- if (element.type === "checkbox") {
803
- data[element.name] = {
804
- value: element.value,
805
- checked: element.checked,
806
- };
807
- } else if (element.type === "radio") {
808
- // Handle radio buttons
809
- const checkedRadio = document.querySelector(
810
- `input[name="${element.name}"]:checked`
811
- );
812
- data[element.name] = checkedRadio ? checkedRadio.value : null;
813
- } else {
814
- // Handle other input types
815
- data[element.name] = element.value;
816
- }
817
- } else {
818
- // Handle cases where the element does not have a name
819
- if (element.type === "checkbox" || element.type === "radio") {
820
- data.value = element.checked;
821
- } else {
822
- data.value = element.value;
823
- }
824
- }
825
- return data;
826
- }
827
- function updateElementAttributes(element, data) {
828
- for (const key in data) {
829
- if (!data.hasOwnProperty(key)) continue;
830
- switch (key) {
831
- case "innerHTML":
832
- case "outerHTML":
833
- case "textContent":
834
- case "innerText":
835
- element[key] = decodeHTML(data[key]);
836
- break;
837
- case "insertAdjacentHTML":
838
- element.insertAdjacentHTML(
839
- data.position || "beforeend",
840
- decodeHTML(data[key].html)
841
- );
842
- break;
843
- case "insertAdjacentText":
844
- element.insertAdjacentText(
845
- data.position || "beforeend",
846
- decodeHTML(data[key].text)
847
- );
848
- break;
849
- case "setAttribute":
850
- element.setAttribute(data.attrName, decodeHTML(data[key]));
851
- break;
852
- case "removeAttribute":
853
- element.removeAttribute(data[key]);
854
- break;
855
- case "className":
856
- element.className = decodeHTML(data[key]);
857
- break;
858
- case "classList.add":
859
- element.classList.add(...decodeHTML(data[key]).split(","));
860
- break;
861
- case "classList.remove":
862
- element.classList.remove(...decodeHTML(data[key]).split(","));
863
- break;
864
- case "classList.toggle":
865
- element.classList.toggle(decodeHTML(data[key]));
866
- break;
867
- case "classList.replace":
868
- const [oldClass, newClass] = decodeHTML(data[key]).split(",");
869
- element.classList.replace(oldClass, newClass);
870
- break;
871
- case "dataset":
872
- element.dataset[data.attrName] = decodeHTML(data[key]);
873
- break;
874
- case "style":
875
- Object.assign(element.style, data[key]);
876
- break;
877
- case "value":
878
- element.value = decodeHTML(data[key]);
879
- break;
880
- case "checked":
881
- element.checked = data[key];
882
- break;
883
- default:
884
- element.setAttribute(key, decodeHTML(data[key]));
885
- }
886
- }
887
- }
888
- function decodeHTML(html) {
889
- const txt = document.createElement("textarea");
890
- txt.innerHTML = html;
891
- return txt.value;
892
- }
893
- function saveElementOriginalState(element) {
894
- if (
895
- element.hasAttribute("pp-suspense") &&
896
- !element.hasAttribute("pp-original-state")
897
- ) {
898
- const originalState = {};
899
- // Save text content if the element has it
900
- if (element.textContent) {
901
- originalState.textContent = element.textContent.trim();
902
- }
903
- // Save value for input, textarea, and select elements
904
- if (
905
- element instanceof HTMLInputElement ||
906
- element instanceof HTMLTextAreaElement ||
907
- element instanceof HTMLSelectElement
908
- ) {
909
- originalState.value = element.value;
910
- }
911
- // Save other attributes if necessary
912
- for (let i = 0; i < element.attributes.length; i++) {
913
- const attr = element.attributes[i];
914
- originalState[attr.name] = attr.value;
915
- }
916
- // Save the original state as a JSON string in a custom attribute
917
- element.setAttribute("pp-original-state", JSON.stringify(originalState));
918
- }
919
- // Save the state of child elements with pp-suspense attribute
920
- const childrenWithSuspense = element.querySelectorAll("[pp-suspense]");
921
- childrenWithSuspense.forEach((child) => saveElementOriginalState(child));
922
- }
923
- async function handleSuspenseElement(element) {
924
- let suspenseElement = element.getAttribute("pp-suspense") || "";
925
- const handleFormElement = (form, data) => {
926
- for (const key in data) {
927
- if (!data.hasOwnProperty(key)) continue;
928
- for (const formElement of form.elements) {
929
- if (
930
- formElement instanceof HTMLInputElement ||
931
- formElement instanceof HTMLButtonElement ||
932
- formElement instanceof HTMLTextAreaElement ||
933
- formElement instanceof HTMLSelectElement
934
- ) {
935
- const suspenseElement = formElement.getAttribute("pp-suspense") || "";
936
- if (suspenseElement) {
937
- if (isJsonLike(suspenseElement)) {
938
- const suspenseData = parseJson(suspenseElement);
939
- if (suspenseData.onsubmit !== "disabled")
940
- updateElementAttributes(formElement, suspenseData);
941
- } else {
942
- updateElementTextContent(formElement, suspenseElement);
943
- }
944
- }
945
- }
946
- }
947
- }
948
- };
949
- const updateElementTextContent = (element, data) => {
950
- if (element instanceof HTMLInputElement) {
951
- element.value = data;
952
- } else {
953
- element.textContent = data;
954
- }
955
- };
956
- const handleTargetElement = (element, data) => {
957
- if (element instanceof HTMLFormElement) {
958
- handleFormElement(element, data);
959
- } else {
960
- updateElementAttributes(element, data);
961
- }
962
- };
963
- try {
964
- if (suspenseElement && isJsonLike(suspenseElement)) {
965
- const data = parseJson(suspenseElement);
966
- if (data) {
967
- if (element instanceof HTMLFormElement) {
968
- const formData = new FormData(element);
969
- const formDataToProcess = {};
970
- formData.forEach((value, key) => {
971
- formDataToProcess[key] = value;
972
- });
973
- if (data.disabled) {
974
- toggleFormElements(element, true);
975
- }
976
- const { disabled, ...restData } = data;
977
- updateElementAttributes(element, restData);
978
- handleFormElement(element, formDataToProcess);
979
- } else if (data.targets) {
980
- data.targets.forEach((target) => {
981
- const { id, ...rest } = target;
982
- const targetElement = document.querySelector(id);
983
- if (targetElement) {
984
- handleTargetElement(targetElement, rest);
985
- }
986
- });
987
- const { targets, ...restData } = data;
988
- updateElementAttributes(element, restData);
989
- } else {
990
- if (data.empty === "disabled" && element.value === "") return;
991
- const { empty, ...restData } = data;
992
- updateElementAttributes(element, restData);
993
- }
994
- }
995
- } else if (suspenseElement) {
996
- updateElementTextContent(element, suspenseElement);
997
- } else {
998
- if (element instanceof HTMLFormElement) {
999
- const formData = new FormData(element);
1000
- const formDataToProcess = {};
1001
- formData.forEach((value, key) => {
1002
- formDataToProcess[key] = value;
1003
- });
1004
- handleFormElement(element, formDataToProcess);
1005
- }
1006
- }
1007
- } catch (error) {
1008
- console.error("🚀 ~ handleSuspenseElement ~ JSON parse error:", error);
1009
- }
1010
- }
1011
- // Function to restore the original state of an element
1012
- function restoreSuspenseElement(element) {
1013
- const originalStateAttribute = element.getAttribute("pp-original-state");
1014
- if (element.hasAttribute("pp-suspense") && originalStateAttribute) {
1015
- const restoreElement = (element, data) => {
1016
- const newElement = document.createElement(element.tagName);
1017
- for (const key in data) {
1018
- if (data.hasOwnProperty(key)) {
1019
- if (key === "textContent") {
1020
- element.textContent = "";
1021
- newElement.textContent = data[key];
1022
- } else if (key === "disabled") {
1023
- if (data[key] === true) {
1024
- newElement.setAttribute("disabled", "true");
1025
- } else {
1026
- newElement.removeAttribute("disabled");
1027
- }
1028
- } else {
1029
- newElement.setAttribute(key, data[key]);
1030
- }
1031
- }
1032
- }
1033
- while (element.firstChild) {
1034
- newElement.appendChild(element.firstChild);
1035
- }
1036
- element.replaceWith(newElement);
1037
- return newElement;
1038
- };
1039
- const restoreFormElement = (form, data) => {
1040
- for (const key in data) {
1041
- if (!data.hasOwnProperty(key)) continue;
1042
- for (const formElement of Array.from(form.elements)) {
1043
- if (
1044
- formElement instanceof HTMLInputElement ||
1045
- formElement instanceof HTMLButtonElement ||
1046
- formElement instanceof HTMLTextAreaElement ||
1047
- formElement instanceof HTMLSelectElement
1048
- ) {
1049
- const originalStateAttribute =
1050
- formElement.getAttribute("pp-original-state") || "";
1051
- if (originalStateAttribute) {
1052
- if (isJsonLike(originalStateAttribute)) {
1053
- const originalData = parseJson(originalStateAttribute);
1054
- const newFormElement = restoreElement(
1055
- formElement,
1056
- originalData
1057
- );
1058
- formElement.replaceWith(newFormElement);
1059
- } else {
1060
- restoreElementTextContent(formElement, originalStateAttribute);
1061
- }
1062
- formElement.removeAttribute("pp-original-state");
1063
- }
1064
- }
1065
- }
1066
- }
1067
- };
1068
- const restoreElementTextContent = (element, data) => {
1069
- if (element instanceof HTMLInputElement) {
1070
- element.value = data;
1071
- } else {
1072
- element.textContent = data;
1073
- }
1074
- };
1075
- const restoreTargetElement = (element, data) => {
1076
- if (element instanceof HTMLFormElement) {
1077
- restoreFormElement(element, data);
1078
- } else {
1079
- const newElement = restoreElement(element, data);
1080
- element.replaceWith(newElement);
1081
- }
1082
- };
1083
- try {
1084
- const data = JSON.parse(originalStateAttribute);
1085
- if (data) {
1086
- if (element instanceof HTMLFormElement) {
1087
- const formData = new FormData(element);
1088
- const formDataToProcess = {};
1089
- formData.forEach((value, key) => {
1090
- formDataToProcess[key] = value;
1091
- });
1092
- restoreFormElement(element, formDataToProcess);
1093
- // Handle the removal of disabled attribute if it was set by suspense
1094
- if (element.hasAttribute("pp-suspense")) {
1095
- const suspenseDataAttribute =
1096
- element.getAttribute("pp-suspense") || "";
1097
- const suspenseData = parseJson(suspenseDataAttribute);
1098
- if (suspenseData.disabled) {
1099
- for (const formElement of Array.from(element.elements)) {
1100
- if (
1101
- formElement instanceof HTMLInputElement ||
1102
- formElement instanceof HTMLButtonElement ||
1103
- formElement instanceof HTMLTextAreaElement ||
1104
- formElement instanceof HTMLSelectElement
1105
- ) {
1106
- formElement.removeAttribute("disabled");
1107
- }
1108
- }
1109
- }
1110
- }
1111
- } else if (data.targets) {
1112
- data.targets.forEach((target) => {
1113
- const { id, ...rest } = target;
1114
- const targetElement = document.querySelector(id);
1115
- if (targetElement) {
1116
- restoreTargetElement(targetElement, rest);
1117
- }
1118
- });
1119
- const { targets, ...restData } = data;
1120
- const newElement = restoreElement(element, restData);
1121
- element.replaceWith(newElement);
1122
- } else {
1123
- const { empty, ...restData } = data;
1124
- const newElement = restoreElement(element, restData);
1125
- element.replaceWith(newElement);
1126
- }
1127
- }
1128
- } catch (error) {
1129
- console.error("🚀 ~ restoreSuspenseElement ~ JSON parse error:", error);
1130
- }
1131
- }
1132
- // Restore the state of child elements with pp-suspense attribute
1133
- const childrenWithSuspense = element.querySelectorAll("[pp-suspense]");
1134
- childrenWithSuspense.forEach((child) => restoreSuspenseElement(child));
1135
- // Clean up the saved state after restoration
1136
- element.removeAttribute("pp-original-state");
1137
- }
1138
- function parseJson(jsonString) {
1139
- if (!isJsonLike(jsonString)) return null;
1140
- return JSON.parse(jsonString.replace(/'/g, '"'));
1141
- }
1142
- function toggleFormElements(form, disable) {
1143
- Array.from(form.elements).forEach((element) => {
1144
- if (
1145
- element instanceof HTMLInputElement ||
1146
- element instanceof HTMLButtonElement ||
1147
- element instanceof HTMLSelectElement ||
1148
- element instanceof HTMLTextAreaElement
1149
- ) {
1150
- element.disabled = disable;
1151
- }
1152
- });
1153
- }
1154
- async function handleUndefinedFunction(element, funcName, data) {
1155
- const body = {
1156
- callback: funcName,
1157
- ...data,
1158
- };
1159
- const firstFetchOptions = {
1160
- method: "POST",
1161
- headers: {
1162
- "Content-Type": "application/json",
1163
- HTTP_PPHP_WIRE_REQUEST: "true",
1164
- },
1165
- body: JSON.stringify(body),
1166
- };
1167
- const secondFetchOptions = {
1168
- method: "POST",
1169
- headers: {
1170
- "Content-Type": "application/json",
1171
- HTTP_PPHP_WIRE_REQUEST: "true",
1172
- },
1173
- body: JSON.stringify({ secondRequestC69CD: true }),
1174
- };
1175
- try {
1176
- saveElementOriginalState(element);
1177
- handleSuspenseElement(element);
1178
- const url = window.location.pathname;
1179
- let firstResponseText = await pphpFetch(url, firstFetchOptions);
1180
- const firstResponseJSON = extractJson(firstResponseText) || "";
1181
- let jsonResponse = {
1182
- success: false,
1183
- };
1184
- if (firstResponseJSON) {
1185
- try {
1186
- jsonResponse = JSON.parse(firstResponseJSON);
1187
- } catch (error) {
1188
- // console.error("Error parsing JSON:", error);
1189
- }
1190
- }
1191
- const isPpOnAttribute = hasPpOnAttribute(element);
1192
- const beforeRequestAttribute =
1193
- element.getAttribute("pp-beforeRequest") || "";
1194
- const afterRequestAttribute = element.getAttribute("pp-afterRequest") || "";
1195
- if (
1196
- isPpOnAttribute ||
1197
- beforeRequestAttribute ||
1198
- (afterRequestAttribute && jsonResponse.success)
1199
- )
1200
- restoreSuspenseElement(element);
1201
- if (isPpOnAttribute || beforeRequestAttribute) {
1202
- let contentToAppend = "";
1203
- if (jsonResponse.success) {
1204
- const remainder = firstResponseText.replace(firstResponseJSON, "");
1205
- contentToAppend = remainder;
1206
- } else {
1207
- contentToAppend = firstResponseText;
1208
- }
1209
- appendAfterbegin(contentToAppend);
1210
- return;
1211
- }
1212
- if (afterRequestAttribute && jsonResponse.success) {
1213
- handleAfterRequest(afterRequestAttribute, firstResponseJSON);
1214
- const remainder = firstResponseText.replace(firstResponseJSON, "");
1215
- appendAfterbegin(remainder);
1216
- return firstResponseJSON;
1217
- }
1218
- const secondResponseText = await pphpFetch(url, secondFetchOptions);
1219
- const match = firstResponseText.match(redirectRegex3AE99);
1220
- if (match && match[1]) {
1221
- const url = match[1];
1222
- await handleRedirect(url);
1223
- } else {
1224
- const parser = new DOMParser();
1225
- const doc = parser.parseFromString(secondResponseText, "text/html");
1226
- let combinedHTML = document.createElement("div");
1227
- combinedHTML.id = "afterbegin-8D95D";
1228
- if (firstResponseJSON) {
1229
- if (jsonResponse.success) {
1230
- const remainder = firstResponseText.replace(firstResponseJSON, "");
1231
- combinedHTML.innerHTML = remainder;
1232
- } else {
1233
- combinedHTML.innerHTML = firstResponseText;
1234
- }
1235
- } else {
1236
- combinedHTML.innerHTML = firstResponseText;
1237
- }
1238
- if (combinedHTML.innerHTML)
1239
- doc.body.insertAdjacentElement("afterbegin", combinedHTML);
1240
- updateDocumentContent(doc.body.outerHTML);
1241
- }
1242
- } catch (error) {
1243
- console.error("Error:", error);
1244
- }
1245
- }
1246
- function appendAfterbegin(content) {
1247
- if (!content) return;
1248
- let afterBeginNode = document.getElementById("afterbegin-8D95D");
1249
- if (afterBeginNode) {
1250
- afterBeginNode.innerHTML = content;
1251
- document.body.insertAdjacentElement("afterbegin", afterBeginNode);
1252
- } else {
1253
- afterBeginNode = document.createElement("div");
1254
- afterBeginNode.id = "afterbegin-8D95D";
1255
- afterBeginNode.innerHTML = content;
1256
- document.body.insertAdjacentElement("afterbegin", afterBeginNode);
1257
- }
1258
- }
1259
- function extractJson(responseText) {
1260
- const jsonMatch = responseText.match(/\{[\s\S]*\}/);
1261
- return jsonMatch ? jsonMatch[0] : null;
1262
- }
1263
- function handleAfterRequest(functionOnlyAttribute, firstResponseText) {
1264
- if (!isJsonLike(functionOnlyAttribute)) return;
1265
- const functionOnlyData = parseJson(functionOnlyAttribute);
1266
- const responseData = firstResponseText ? parseJson(firstResponseText) : null;
1267
- const targets = functionOnlyData.targets; // Assuming targets is an array of objects
1268
- if (Array.isArray(targets)) {
1269
- targets.forEach((targetData) => {
1270
- const { id, ...restData } = targetData;
1271
- const targetToProcess = document.querySelector(id);
1272
- let targetAttributes = {};
1273
- if (responseData) {
1274
- for (const key in restData) {
1275
- if (restData.hasOwnProperty(key)) {
1276
- switch (key) {
1277
- case "innerHTML":
1278
- case "outerHTML":
1279
- case "textContent":
1280
- case "innerText":
1281
- if (restData[key] === "response") {
1282
- targetAttributes[key] = targetData.responseKey
1283
- ? responseData[targetData.responseKey]
1284
- : responseData.response;
1285
- }
1286
- break;
1287
- default:
1288
- targetAttributes[key] = restData[key];
1289
- break;
1290
- }
1291
- }
1292
- }
1293
- } else {
1294
- targetAttributes = restData;
1295
- }
1296
- if (targetToProcess) {
1297
- updateElementAttributes(targetToProcess, targetAttributes);
1298
- }
1299
- });
1300
- }
1301
- }
1302
- // Function to handle redirection without a full page reload
1303
- async function handleRedirect(url) {
1304
- if (!url) return;
1305
- try {
1306
- const fullUrl = new URL(url, window.location.origin);
1307
- const isExternal = fullUrl.origin !== window.location.origin;
1308
- if (isExternal) {
1309
- window.location.href = url;
1310
- } else {
1311
- history.pushState(null, "", url);
1312
- await handleNavigation();
1313
- }
1314
- } catch (error) {
1315
- console.error("Redirect error:", error);
1316
- }
1317
- }
1318
- /**
1319
- * Debounces a function to limit the rate at which it is called.
1320
- *
1321
- * The debounced function will postpone its execution until after the specified wait time
1322
- * has elapsed since the last time it was invoked. If `immediate` is `true`, the function
1323
- * will be called at the beginning of the wait period instead of at the end.
1324
- *
1325
- * @param {Function} func - The function to debounce.
1326
- * @param {number} [wait=300] - The number of milliseconds to wait before invoking the function.
1327
- * @param {boolean} [immediate=false] - If `true`, the function is invoked immediately on the leading edge.
1328
- * @returns {Function} - Returns the debounced version of the original function.
1329
- */
1330
- function debounce(func, wait = 300, immediate = false) {
1331
- let timeout;
1332
- return function (...args) {
1333
- const context = this;
1334
- if (timeout) clearTimeout(timeout);
1335
- timeout = setTimeout(() => {
1336
- timeout = null;
1337
- if (!immediate) func.apply(context, args);
1338
- }, wait);
1339
- if (immediate && !timeout) {
1340
- func.apply(context, args);
1341
- }
1342
- };
1343
- }
1344
- /**
1345
- * Copies code to the clipboard and updates the button icon.
1346
- *
1347
- * @param {HTMLElement} btnElement - The button element that triggered the copy action.
1348
- * @param {string} containerClass - The class of the container element that contains the code block.
1349
- * @param {string} initialIconClass - The initial class for the icon.
1350
- * @param {string} successIconClass - The class for the icon after a successful copy.
1351
- * @param {number} [timeout=2000] - The time in milliseconds to revert to the initial icon class.
1352
- */
1353
- function copyCode(
1354
- btnElement,
1355
- containerClass,
1356
- initialIconClass,
1357
- successIconClass,
1358
- timeout = 2000
1359
- ) {
1360
- // Ensure btnElement is an instance of HTMLElement
1361
- if (!(btnElement instanceof HTMLElement)) return;
1362
- // Find the closest container with the specified class relative to the button
1363
- const codeBlock = btnElement
1364
- .closest(`.${containerClass}`)
1365
- ?.querySelector("pre code");
1366
- const textToCopy = codeBlock?.textContent?.trim() || ""; // Get the text content of the code block and trim whitespace
1367
- if (textToCopy) {
1368
- navigator.clipboard.writeText(textToCopy).then(
1369
- () => {
1370
- // Clipboard successfully set
1371
- const icon = btnElement.querySelector("i");
1372
- if (icon) {
1373
- icon.className = successIconClass; // Change to success icon
1374
- }
1375
- // Set a timeout to change the icon back to initial after the specified timeout
1376
- setTimeout(() => {
1377
- if (icon) {
1378
- icon.className = initialIconClass; // Change back to initial icon
1379
- }
1380
- }, timeout); // Timeout delay
1381
- },
1382
- () => {
1383
- // Clipboard write failed
1384
- alert("Failed to copy command to clipboard");
1385
- }
1386
- );
1387
- } else {
1388
- alert("Failed to find the code block to copy");
1389
- }
1390
- }
1391
- if (store === null) {
1392
- class StateManager {
1393
- static instance = null;
1394
- state;
1395
- listeners;
1396
- /**
1397
- * Creates a new StateManager instance.
1398
- *
1399
- * @param {State} [initialState={}] - The initial state.
1400
- */
1401
- constructor(initialState = {}) {
1402
- this.state = initialState;
1403
- this.listeners = [];
1404
- }
1405
- /**
1406
- * Gets the singleton instance of StateManager.
1407
- *
1408
- * @param {State} [initialState={}] - The initial state.
1409
- * @returns {StateManager} - The StateManager instance.
1410
- */
1411
- static getInstance(initialState = {}) {
1412
- if (!StateManager.instance) {
1413
- StateManager.instance = new StateManager(initialState);
1414
- StateManager.instance.loadState(); // Load state immediately after instance creation
1415
- }
1416
- return StateManager.instance;
1417
- }
1418
- /**
1419
- * Sets the state.
1420
- *
1421
- * @param {Partial<State>} update - The state update.
1422
- */
1423
- setState(update) {
1424
- this.state = { ...this.state, ...update };
1425
- this.listeners.forEach((listener) => listener(this.state));
1426
- this.saveState();
1427
- }
1428
- /**
1429
- * Subscribes to state changes.
1430
- *
1431
- * @param {(state: State) => void} listener - The listener function.
1432
- * @returns {() => void} - A function to unsubscribe the listener.
1433
- */
1434
- subscribe(listener) {
1435
- this.listeners.push(listener);
1436
- listener(this.state); // Immediately invoke the listener with the current state
1437
- return () => {
1438
- this.listeners = this.listeners.filter((l) => l !== listener);
1439
- };
1440
- }
1441
- /**
1442
- * Saves the state to localStorage.
1443
- */
1444
- saveState() {
1445
- localStorage.setItem("appState_59E13", JSON.stringify(this.state));
1446
- }
1447
- /**
1448
- * Loads the state from localStorage.
1449
- */
1450
- loadState() {
1451
- const state = localStorage.getItem("appState_59E13");
1452
- if (state) {
1453
- this.state = JSON.parse(state);
1454
- this.listeners.forEach((listener) => listener(this.state));
1455
- }
1456
- }
1457
- /**
1458
- * Resets the state to its initial value.
1459
- * This will also clear the state from localStorage.
1460
- */
1461
- resetState() {
1462
- this.state = {}; // Reset the state to an empty object or a default state if you prefer
1463
- this.listeners.forEach((listener) => listener(this.state));
1464
- localStorage.removeItem("appState_59E13"); // Clear the state from localStorage
1465
- }
1466
- }
1467
- store = StateManager.getInstance();
1468
- }
1
+ var eventAttributesB6B56=["onclick","ondblclick","onmousedown","onmouseup","onmouseover","onmousemove","onmouseout","onwheel","onkeypress","onkeydown","onkeyup","onfocus","onblur","onchange","oninput","onselect","onsubmit","onreset","onresize","onscroll","onload","onunload","onabort","onerror","onbeforeunload","oncopy","oncut","onpaste","ondrag","ondragstart","ondragend","ondragover","ondragenter","ondragleave","ondrop","oncontextmenu","ontouchstart","ontouchmove","ontouchend","ontouchcancel","onpointerdown","onpointerup","onpointermove","onpointerover","onpointerout","onpointerenter","onpointerleave","onpointercancel"],stateA129A={checkedElements:new Set},responseDataDEAC2=null,store=null,isNavigatingA12E1=!1,redirectRegex3AE99=/redirect_7F834=(.+)/;function attachWireFunctionEvents(){handleHiddenAttribute();document.querySelectorAll("button, input, select, textarea, a, form, label, div, span").forEach((e=>{if(handleAnchorTag(e),eventAttributesB6B56.forEach((t=>{const n=e.getAttribute(t),s=t.slice(2);n&&(e.removeAttribute(t),handleDebounce(e,s,n))})),e instanceof HTMLFormElement){const t=e.getAttribute("onsubmit");t&&(e.removeAttribute("onsubmit"),handleDebounce(e,"submit",t))}})),initializePpOnListeners()}function hasPpOnAttribute(e){const t=e.attributes;if(!t)return!1;for(let e=0;e<t.length;e++){const n=t[e].name;if(n.startsWith("pp-on:")||n.startsWith("data-pp-on:")||n.startsWith("pp-on-")||n.startsWith("data-pp-on-"))return!0}return!1}function findAllPpOnElements(e){const t=[];if(hasPpOnAttribute(e)&&t.push(e),document.evaluate){const n=document.evaluate('.//*[@*[starts-with(name(), "pp-on:") or starts-with(name(), "data-pp-on:") or starts-with(name(), "pp-on-") or starts-with(name(), "data-pp-on-")]]',e,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s=n.iterateNext();for(;s;)t.push(s),s=n.iterateNext()}else if("function"==typeof e.getElementsByTagName){const n=e.getElementsByTagName("*");for(let e=0;e<n.length;e++)hasPpOnAttribute(n[e])&&t.push(n[e])}return t}function initializePpOnListeners(){findAllPpOnElements(document).forEach((e=>{Array.from(e.attributes).forEach((t=>{if(t.name.startsWith("pp-on:")){const n=t.name.split(":")[1],s=t.value;s&&e.addEventListener(n,(t=>{try{new Function("event",s).call(e,t)}catch(e){}}))}}))}))}function handleHiddenAttribute(){const e=document.querySelectorAll("[pp-visibility]"),t=document.querySelectorAll("[pp-display]");e.forEach((e=>handleVisibilityElementAttribute(e,"pp-visibility",handleElementVisibility))),t.forEach((e=>handleVisibilityElementAttribute(e,"pp-display",handleElementDisplay)))}function handleVisibilityElementAttribute(e,t,n){const s=e.getAttribute(t);if(s)if(isJsonLike(s)){n(e,parseJson(s))}else{const n=parseTime(s);if(n>0){const s="pp-visibility"===t?"visibility":"display";scheduleChange(e,n,s,"visibility"===s?"hidden":"none")}}}function isJsonLike(e){return e.trim().startsWith("{")&&e.trim().endsWith("}")}function handleElementVisibility(e,t){handleElementChange(e,t,"visibility","hidden","visible")}function handleElementDisplay(e,t){handleElementChange(e,t,"display","none","block")}function handleElementChange(e,t,n,s,o){const a=t.start?parseTime(t.start):0,i=t.end?parseTime(t.end):0;a>0?(e.style[n]=s,scheduleChange(e,a,n,o),i>0&&scheduleChange(e,a+i,n,s)):i>0&&scheduleChange(e,i,n,s)}function scheduleChange(e,t,n,s){setTimeout((()=>{requestAnimationFrame((()=>{e.style[n]=s}))}),t)}function parseTime(e){if("number"==typeof e)return e;const t=e.match(/^(\d+)(ms|s|m)?$/);if(t){const e=parseInt(t[1],10);switch(t[2]||"ms"){case"ms":return e;case"s":return 1e3*e;case"m":return 60*e*1e3;default:return e}}return 0}async function handleDebounce(e,t,n){const s=e.getAttribute("pp-debounce")||"",o=e.getAttribute("pp-beforeRequest")||"",a=e.getAttribute("pp-afterRequest")||"",i=async t=>{t.preventDefault();try{o&&await invokeHandler(e,o,t),await invokeHandler(e,n,t),a&&"@close"!==a&&await invokeHandler(e,a,t),handlerAutofocusAttribute()}catch(e){}};if(s){const n=debounce(i,parseTime(s));e instanceof HTMLFormElement&&"submit"===t?e.addEventListener(t,(e=>{e.preventDefault(),n(e)})):e.addEventListener(t,n)}else e.addEventListener(t,i)}function handlerAutofocusAttribute(){const e=document.querySelectorAll("[pp-autofocus]");let t=!1;e.forEach((e=>{if(t)return;const n=e.getAttribute("pp-autofocus");if(!n||!isJsonLike(n))return;const s=parseJson(n);if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)if("number"===e.type&&e instanceof HTMLInputElement){e.type="text";const t=e.value.length||0;e.setSelectionRange(t,t),e.type="number"}else if(s.start)e.setSelectionRange(0,0);else if(s.end){const t=e.value.length||0;e.setSelectionRange(t,t)}else if(s.length){const t=parseInt(s.length,10)||0;e.setSelectionRange(t,t)}e.focus(),t=!0}))}async function invokeHandler(e,t,n){try{const s=t.match(/^(\w+(\.\w+)*)\((.*)\)$/);if(s){const o=s[1].split("."),{context:a,methodName:i}=resolveContext(o);"function"==typeof a[i]?new Function("event",t).call(e,n):await handleParsedCallback(e,t)}else await handleParsedCallback(e,t)}catch(e){}}function resolveContext(e){let t=window;for(let n=0;n<e.length-1;n++)if(t=t[e[n]],!t)throw new Error(`Cannot find object ${e[n]} in the context.`);return{context:t,methodName:e[e.length-1]}}async function handleParsedCallback(e,t){const{funcName:n,data:s}=parseCallback(e,t);if(!n)return;const o=window[n];if("function"==typeof o){const t=e.hasAttribute("pp-afterRequest"),n=Array.isArray(s.args)?s.args:[],a=responseDataDEAC2?parseJson(responseDataDEAC2):{response:responseDataDEAC2};let i={args:n,element:e,data:s};t&&(i={...i,...a}),await o(i)}else responseDataDEAC2=null,responseDataDEAC2=await handleUndefinedFunction(e,n,s)}function handleAnchorTag(e){e instanceof HTMLAnchorElement&&e.addEventListener("click",(async e=>{const t=e.currentTarget,n=t.getAttribute("href"),s=t.getAttribute("target");if(n&&"_blank"!==s&&!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),!isNavigatingA12E1)){isNavigatingA12E1=!0;try{if(/^(https?:)?\/\//i.test(n)&&!n.startsWith(window.location.origin))window.location.href=n;else{const[e,t]=n.split("#");if(history.pushState(null,"",n),t){const e=document.getElementById(t);e&&e.scrollIntoView({behavior:"smooth"})}else await handleNavigation()}}catch(e){}finally{isNavigatingA12E1=!1}}}))}async function handleNavigation(){try{const e=window.location.pathname,t=document.getElementById("loading-file-1B87E");if(t){let n=t.querySelector(`div[pp-loading-url='${e}']`);if(n||(n=t.querySelector("div[pp-loading-url='/']")),n){const e=document.querySelector("[pp-loading-content='true']");e?e.innerHTML=n.innerHTML:document.body.innerHTML=n.innerHTML}}const n=await pphpFetch(window.location.href),s=n.match(redirectRegex3AE99);if(s&&s[1]){const e=s[1];await handleRedirect(e)}else updateDocumentContent(n)}catch(e){}}function onUrlChange(){}function updateDocumentContent(e){const t=saveScrollPositions();if(document.removeAllEventListeners("DOMContentLoaded"),e.includes("<!DOCTYPE html>")){const t=e=>{Array.from(e.head.children).forEach((e=>{const t=e.tagName;if("META"===t){if(e.getAttribute("charset")||"viewport"===e.getAttribute("name"))return;const t=e.name,n=e.getAttribute("property"),s=document.head.querySelector(t?`meta[name="${t}"]`:`meta[property="${n}"]`);s?document.head.replaceChild(e.cloneNode(!0),s):document.head.appendChild(e.cloneNode(!0))}else if("TITLE"===t){const t=document.head.querySelector("title");t?document.head.replaceChild(e.cloneNode(!0),t):document.head.appendChild(e.cloneNode(!0))}else if("LINK"===t){const t=t=>{const n=document.head.querySelector('link[rel="icon"]');if(n)document.head.replaceChild(e.cloneNode(!0),n);else{const e=document.createElement("link");e.rel="icon",e.href=t,document.head.appendChild(e)}};if("icon"===e.getAttribute("rel")){t(e.href)}}})),loadAndValidateContent(e)};t((new DOMParser).parseFromString(e,"text/html"))}else{saveState();loadAndValidateContent((new DOMParser).parseFromString(e,"text/html")),restoreState()}restoreScrollPositions(t),attachWireFunctionEvents(),document.dispatchEvent(new Event("DOMContentLoaded"))}function loadAndValidateContent(e){const t=new Map,n=document.createDocumentFragment();function s(e,n){let o=null;if("SCRIPT"===e.tagName){const t=document.createElement("script"),n=e;n.src?(t.src=n.src,t.async=!1):t.textContent=n.textContent,o=t}else o=e.cloneNode(!1),t.set(e,o),Array.from(e.childNodes).forEach((e=>{e.nodeType===Node.TEXT_NODE?o.appendChild(document.createTextNode(e.textContent||"")):e.nodeType===Node.ELEMENT_NODE&&s(e,o)}));n.appendChild(o)}Array.from(e.body.children).forEach((e=>{s(e,n)})),document.body.innerHTML="",document.body.appendChild(n)}function saveState(){const e=document.activeElement;stateA129A.focusId=e?.id||e?.name,stateA129A.focusValue=e?.value,stateA129A.focusChecked=e?.checked,stateA129A.focusType=e?.type,stateA129A.focusSelectionStart=e?.selectionStart,stateA129A.focusSelectionEnd=e?.selectionEnd,stateA129A.isSuspense=e.hasAttribute("pp-suspense"),stateA129A.checkedElements.clear(),document.querySelectorAll('input[type="checkbox"]:checked').forEach((e=>{stateA129A.checkedElements.add(e.id||e.name)})),document.querySelectorAll('input[type="radio"]:checked').forEach((e=>{stateA129A.checkedElements.add(e.id||e.name)}))}function restoreState(){if(stateA129A.focusId){const e=document.getElementById(stateA129A.focusId)||document.querySelector(`[name="${stateA129A.focusId}"]`);if(e instanceof HTMLInputElement){const t=e.value.length||0;void 0!==stateA129A.focusSelectionStart&&null!==stateA129A.focusSelectionEnd&&e.setSelectionRange(t,t),stateA129A.focusValue&&("checkbox"===e.type||"radio"===e.type?e.checked=!!stateA129A.focusChecked:"number"===e.type?(e.type="text",e.setSelectionRange(t,t),e.type="number"):""!==e.value&&(e.value=stateA129A.focusValue)),e.focus()}else if(e instanceof HTMLTextAreaElement){const t=e.value.length||0;void 0!==stateA129A.focusSelectionStart&&null!==stateA129A.focusSelectionEnd&&e.setSelectionRange(t,t),stateA129A.focusValue&&""!==e.value&&(e.value=stateA129A.focusValue),e.focus()}else e instanceof HTMLSelectElement&&(stateA129A.focusValue&&""!==e.value&&(e.value=stateA129A.focusValue),e.focus())}stateA129A.checkedElements.forEach((e=>{const t=document.getElementById(e);t&&(t.checked=!0)}))}function saveScrollPositions(){const e={};return document.querySelectorAll("*").forEach((t=>{(t.scrollTop||t.scrollLeft)&&(e[getElementKey(t)]={scrollTop:t.scrollTop,scrollLeft:t.scrollLeft})})),e}function restoreScrollPositions(e){document.querySelectorAll("*").forEach((t=>{const n=getElementKey(t);e[n]&&(t.scrollTop=e[n].scrollTop,t.scrollLeft=e[n].scrollLeft)}))}function getElementKey(e){return e.id||e.className||e.tagName}async function pphpFetch(e,t){const n=await fetch(e,{...t,headers:{...t?.headers,"X-Requested-With":"XMLHttpRequest"}});return await n.text()}function parseCallback(e,t){let n={};const s=e.closest("form");if(s){new FormData(s).forEach(((e,t)=>{n[t]?Array.isArray(n[t])?n[t].push(e):n[t]=[n[t],e]:n[t]=e}))}else e instanceof HTMLInputElement?n=handleInputElement(e):(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&(n[e.name]=e.value);const o=t.match(/(\w+)\((.*)\)/);if(o){const e=o[1];let t=o[2].trim();if(t.startsWith("{")&&t.endsWith("}"))try{const e=parseJson(t);"object"==typeof e&&null!==e&&(n={...n,...e})}catch(e){}else{const e=t.split(/,(?=(?:[^'"]*['"][^'"]*['"])*[^'"]*$)/).map((e=>e.trim().replace(/^['"]|['"]$/g,"")));n.args=e}return{funcName:e,data:n}}return{funcName:t,data:n}}function handleInputElement(e){let t={};if(e.name)if("checkbox"===e.type)t[e.name]={value:e.value,checked:e.checked};else if("radio"===e.type){const n=document.querySelector(`input[name="${e.name}"]:checked`);t[e.name]=n?n.value:null}else t[e.name]=e.value;else"checkbox"===e.type||"radio"===e.type?t.value=e.checked:t.value=e.value;return t}function updateElementAttributes(e,t){for(const n in t)if(t.hasOwnProperty(n))switch(n){case"innerHTML":case"outerHTML":case"textContent":case"innerText":e[n]=decodeHTML(t[n]);break;case"insertAdjacentHTML":e.insertAdjacentHTML(t.position||"beforeend",decodeHTML(t[n].html));break;case"insertAdjacentText":e.insertAdjacentText(t.position||"beforeend",decodeHTML(t[n].text));break;case"setAttribute":e.setAttribute(t.attrName,decodeHTML(t[n]));break;case"removeAttribute":e.removeAttribute(t[n]);break;case"className":e.className=decodeHTML(t[n]);break;case"classList.add":e.classList.add(...decodeHTML(t[n]).split(","));break;case"classList.remove":e.classList.remove(...decodeHTML(t[n]).split(","));break;case"classList.toggle":e.classList.toggle(decodeHTML(t[n]));break;case"classList.replace":const[s,o]=decodeHTML(t[n]).split(",");e.classList.replace(s,o);break;case"dataset":e.dataset[t.attrName]=decodeHTML(t[n]);break;case"style":Object.assign(e.style,t[n]);break;case"value":e.value=decodeHTML(t[n]);break;case"checked":e.checked=t[n];break;default:e.setAttribute(n,decodeHTML(t[n]))}}function decodeHTML(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}function saveElementOriginalState(e){if(e.hasAttribute("pp-suspense")&&!e.hasAttribute("pp-original-state")){const t={};e.textContent&&(t.textContent=e.textContent.trim()),(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(t.value=e.value);for(let n=0;n<e.attributes.length;n++){const s=e.attributes[n];t[s.name]=s.value}e.setAttribute("pp-original-state",JSON.stringify(t))}e.querySelectorAll("[pp-suspense]").forEach((e=>saveElementOriginalState(e)))}async function handleSuspenseElement(e){let t=e.getAttribute("pp-suspense")||"";const n=(e,t)=>{for(const n in t)if(t.hasOwnProperty(n))for(const t of e.elements)if(t instanceof HTMLInputElement||t instanceof HTMLButtonElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement){const e=t.getAttribute("pp-suspense")||"";if(e)if(isJsonLike(e)){const n=parseJson(e);"disabled"!==n.onsubmit&&updateElementAttributes(t,n)}else s(t,e)}},s=(e,t)=>{e instanceof HTMLInputElement?e.value=t:e.textContent=t};try{if(t&&isJsonLike(t)){const s=parseJson(t);if(s)if(e instanceof HTMLFormElement){const t=new FormData(e),o={};t.forEach(((e,t)=>{o[t]=e})),s.disabled&&toggleFormElements(e,!0);const{disabled:a,...i}=s;updateElementAttributes(e,i),n(e,o)}else if(s.targets){s.targets.forEach((e=>{const{id:t,...s}=e,o=document.querySelector(t);o&&((e,t)=>{e instanceof HTMLFormElement?n(e,t):updateElementAttributes(e,t)})(o,s)}));const{targets:t,...o}=s;updateElementAttributes(e,o)}else{if("disabled"===s.empty&&""===e.value)return;const{empty:t,...n}=s;updateElementAttributes(e,n)}}else if(t)s(e,t);else if(e instanceof HTMLFormElement){const t=new FormData(e),s={};t.forEach(((e,t)=>{s[t]=e})),n(e,s)}}catch(e){}}function restoreSuspenseElement(e){const t=e.getAttribute("pp-original-state");if(e.hasAttribute("pp-suspense")&&t){const n=(e,t)=>{const n=document.createElement(e.tagName);for(const s in t)t.hasOwnProperty(s)&&("textContent"===s?(e.textContent="",n.textContent=t[s]):"disabled"===s?!0===t[s]?n.setAttribute("disabled","true"):n.removeAttribute("disabled"):n.setAttribute(s,t[s]));for(;e.firstChild;)n.appendChild(e.firstChild);return e.replaceWith(n),n},s=(e,t)=>{for(const s in t)if(t.hasOwnProperty(s))for(const t of Array.from(e.elements))if(t instanceof HTMLInputElement||t instanceof HTMLButtonElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement){const e=t.getAttribute("pp-original-state")||"";if(e){if(isJsonLike(e)){const s=parseJson(e),o=n(t,s);t.replaceWith(o)}else o(t,e);t.removeAttribute("pp-original-state")}}},o=(e,t)=>{e instanceof HTMLInputElement?e.value=t:e.textContent=t},a=(e,t)=>{if(e instanceof HTMLFormElement)s(e,t);else{const s=n(e,t);e.replaceWith(s)}};try{const o=JSON.parse(t);if(o)if(e instanceof HTMLFormElement){const t=new FormData(e),n={};if(t.forEach(((e,t)=>{n[t]=e})),s(e,n),e.hasAttribute("pp-suspense")){const t=e.getAttribute("pp-suspense")||"";if(parseJson(t).disabled)for(const t of Array.from(e.elements))(t instanceof HTMLInputElement||t instanceof HTMLButtonElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&t.removeAttribute("disabled")}}else if(o.targets){o.targets.forEach((e=>{const{id:t,...n}=e,s=document.querySelector(t);s&&a(s,n)}));const{targets:t,...s}=o,i=n(e,s);e.replaceWith(i)}else{const{empty:t,...s}=o,a=n(e,s);e.replaceWith(a)}}catch(e){}}e.querySelectorAll("[pp-suspense]").forEach((e=>restoreSuspenseElement(e))),e.removeAttribute("pp-original-state")}function parseJson(e){return isJsonLike(e)?JSON.parse(e.replace(/'/g,'"')):null}function toggleFormElements(e,t){Array.from(e.elements).forEach((e=>{(e instanceof HTMLInputElement||e instanceof HTMLButtonElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&(e.disabled=t)}))}async function handleUndefinedFunction(e,t,n){const s={callback:t,...n},o={method:"POST",headers:{"Content-Type":"application/json",HTTP_PPHP_WIRE_REQUEST:"true"},body:JSON.stringify(s)},a={method:"POST",headers:{"Content-Type":"application/json",HTTP_PPHP_WIRE_REQUEST:"true"},body:JSON.stringify({secondRequestC69CD:!0})};try{saveElementOriginalState(e),handleSuspenseElement(e);const t=window.location.pathname;let n=await pphpFetch(t,o);const s=extractJson(n)||"";let i={success:!1};if(s)try{i=JSON.parse(s)}catch(e){}const r=hasPpOnAttribute(e),c=e.getAttribute("pp-beforeRequest")||"",l=e.getAttribute("pp-afterRequest")||"";if((r||c||l&&i.success)&&restoreSuspenseElement(e),r||c){let e="";if(i.success){e=n.replace(s,"")}else e=n;return void appendAfterbegin(e)}if(l&&i.success){handleAfterRequest(l,s);return appendAfterbegin(n.replace(s,"")),s}const u=await pphpFetch(t,a),d=n.match(redirectRegex3AE99);if(d&&d[1]){const e=d[1];await handleRedirect(e)}else{const e=(new DOMParser).parseFromString(u,"text/html");let t=document.createElement("div");if(t.id="afterbegin-8D95D",s)if(i.success){const e=n.replace(s,"");t.innerHTML=e}else t.innerHTML=n;else t.innerHTML=n;t.innerHTML&&e.body.insertAdjacentElement("afterbegin",t),updateDocumentContent(e.body.outerHTML)}}catch(e){}}function appendAfterbegin(e){if(!e)return;let t=document.getElementById("afterbegin-8D95D");t?(t.innerHTML=e,document.body.insertAdjacentElement("afterbegin",t)):(t=document.createElement("div"),t.id="afterbegin-8D95D",t.innerHTML=e,document.body.insertAdjacentElement("afterbegin",t))}function extractJson(e){const t=e.match(/\{[\s\S]*\}/);return t?t[0]:null}function handleAfterRequest(e,t){if(!isJsonLike(e))return;const n=parseJson(e),s=t?parseJson(t):null,o=n.targets;Array.isArray(o)&&o.forEach((e=>{const{id:t,...n}=e,o=document.querySelector(t);let a={};if(s){for(const t in n)if(n.hasOwnProperty(t))switch(t){case"innerHTML":case"outerHTML":case"textContent":case"innerText":"response"===n[t]&&(a[t]=e.responseKey?s[e.responseKey]:s.response);break;default:a[t]=n[t];break}}else a=n;o&&updateElementAttributes(o,a)}))}async function handleRedirect(e){if(e)try{const t=new URL(e,window.location.origin);t.origin!==window.location.origin?window.location.href=e:(history.pushState(null,"",e),await handleNavigation())}catch(e){}}function debounce(e,t=300,n=!1){let s;return function(...o){const a=this;s&&clearTimeout(s),s=setTimeout((()=>{s=null,n||e.apply(a,o)}),t),n&&!s&&e.apply(a,o)}}function copyCode(e,t,n,s,o=2e3){if(!(e instanceof HTMLElement))return;const a=e.closest(`.${t}`)?.querySelector("pre code"),i=a?.textContent?.trim()||"";i?navigator.clipboard.writeText(i).then((()=>{const t=e.querySelector("i");t&&(t.className=s),setTimeout((()=>{t&&(t.className=n)}),o)}),(()=>{alert("Failed to copy command to clipboard")})):alert("Failed to find the code block to copy")}if((()=>{const e=EventTarget.prototype.addEventListener,t=new Map;EventTarget.prototype.addEventListener=function(n,s,o){t.has(this)||t.set(this,new Map);const a=t.get(this).get(n)||new Set;a.add(s),t.get(this).set(n,a),e.call(this,n,s,o)},EventTarget.prototype.removeAllEventListeners=function(e){t.has(this)&&t.get(this).has(e)&&(t.get(this).get(e).forEach((t=>{this.removeEventListener(e,t)})),t.get(this).delete(e))}})(),(e=>{const t=e.pushState,n=e.replaceState;e.pushState=function(n,s,o){const a=t.apply(e,arguments);return window.dispatchEvent(new Event("urlchange")),a},e.replaceState=function(t,s,o){const a=n.apply(e,arguments);return window.dispatchEvent(new Event("urlchange")),a}})(window.history),document.addEventListener("DOMContentLoaded",attachWireFunctionEvents),window.addEventListener("popstate",(async()=>{await handleNavigation()})),window.addEventListener("urlchange",(()=>{})),null===store){class e{static instance=null;state;listeners;constructor(e={}){this.state=e,this.listeners=[]}static getInstance(t={}){return e.instance||(e.instance=new e(t),e.instance.loadState()),e.instance}setState(e){this.state={...this.state,...e},this.listeners.forEach((e=>e(this.state))),this.saveState()}subscribe(e){return this.listeners.push(e),e(this.state),()=>{this.listeners=this.listeners.filter((t=>t!==e))}}saveState(){localStorage.setItem("appState_59E13",JSON.stringify(this.state))}loadState(){const e=localStorage.getItem("appState_59E13");e&&(this.state=JSON.parse(e),this.listeners.forEach((e=>e(this.state))))}resetState(){this.state={},this.listeners.forEach((e=>e(this.state))),localStorage.removeItem("appState_59E13")}}store=e.getInstance()}