@patch-adams/core 1.6.0 → 1.6.2
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.
- package/dist/cli.cjs +129 -22
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +129 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +129 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +129 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5308,18 +5308,21 @@ window.pa_patcher = window.pa_patcher || {
|
|
|
5308
5308
|
|
|
5309
5309
|
(function() {
|
|
5310
5310
|
'use strict';
|
|
5311
|
-
//
|
|
5312
|
-
|
|
5313
|
-
window.__pa_v
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5311
|
+
// Cache version \u2014 normally set by version resolver (injected before CSS Before).
|
|
5312
|
+
// Fallback: fetch here if version resolver didn't run (older patched packages).
|
|
5313
|
+
if (typeof window.__pa_v === 'undefined') {
|
|
5314
|
+
var ASSET_VERSION_URL = "${assetVersionUrl || ""}";
|
|
5315
|
+
window.__pa_v = '';
|
|
5316
|
+
if (ASSET_VERSION_URL) {
|
|
5317
|
+
try {
|
|
5318
|
+
var xhr = new XMLHttpRequest();
|
|
5319
|
+
xhr.open('GET', ASSET_VERSION_URL, false);
|
|
5320
|
+
xhr.send();
|
|
5321
|
+
if (xhr.status === 200) {
|
|
5322
|
+
window.__pa_v = JSON.parse(xhr.responseText).v || '1';
|
|
5323
|
+
}
|
|
5324
|
+
} catch(e) { window.__pa_v = '1'; }
|
|
5325
|
+
}
|
|
5323
5326
|
}
|
|
5324
5327
|
|
|
5325
5328
|
var REMOTE_URL = "${remoteUrl}" + (window.__pa_v ? "?v=" + window.__pa_v : "");
|
|
@@ -5702,6 +5705,7 @@ function hasClassMappings(mappings) {
|
|
|
5702
5705
|
if (mappings.course?.trim()) return true;
|
|
5703
5706
|
if (mappings.lessons && Object.values(mappings.lessons).some((v) => v?.trim())) return true;
|
|
5704
5707
|
if (mappings.blocks && Object.values(mappings.blocks).some((v) => v?.trim())) return true;
|
|
5708
|
+
if (mappings.blockGroups && mappings.blockGroups.length > 0) return true;
|
|
5705
5709
|
return false;
|
|
5706
5710
|
}
|
|
5707
5711
|
function generateClassMappingsScript(mappings) {
|
|
@@ -5723,6 +5727,10 @@ function generateClassMappingsScript(mappings) {
|
|
|
5723
5727
|
}
|
|
5724
5728
|
const hasBlocks = Object.keys(blockMap).length > 0;
|
|
5725
5729
|
const hasLessons = Object.keys(lessonMap).length > 0;
|
|
5730
|
+
const blockGroups = (mappings.blockGroups || []).filter(
|
|
5731
|
+
(g) => g.blockIds.length >= 2 && g.className.trim() && g.lessonId
|
|
5732
|
+
);
|
|
5733
|
+
const hasGroups = blockGroups.length > 0;
|
|
5726
5734
|
const parts = [];
|
|
5727
5735
|
parts.push(`// PA-Patcher: Custom Class Mappings`);
|
|
5728
5736
|
parts.push(`(function() {`);
|
|
@@ -5788,33 +5796,117 @@ function generateClassMappingsScript(mappings) {
|
|
|
5788
5796
|
parts.push(` }`);
|
|
5789
5797
|
parts.push(``);
|
|
5790
5798
|
}
|
|
5799
|
+
if (hasGroups) {
|
|
5800
|
+
const groupData = blockGroups.map((g) => ({
|
|
5801
|
+
id: g.id,
|
|
5802
|
+
lessonId: g.lessonId,
|
|
5803
|
+
blockIds: g.blockIds,
|
|
5804
|
+
className: g.className.trim()
|
|
5805
|
+
}));
|
|
5806
|
+
parts.push(` // Block groups (adjacent blocks wrapped in container divs)`);
|
|
5807
|
+
parts.push(` var groupMap = ${JSON.stringify(groupData)};`);
|
|
5808
|
+
parts.push(``);
|
|
5809
|
+
parts.push(` function applyBlockGroups() {`);
|
|
5810
|
+
parts.push(` var hash = window.location.hash || '';`);
|
|
5811
|
+
parts.push(` var match = hash.match(/#\\/lessons\\/([^/]+)/);`);
|
|
5812
|
+
parts.push(` var currentLesson = match ? match[1] : null;`);
|
|
5813
|
+
parts.push(` for (var g = 0; g < groupMap.length; g++) {`);
|
|
5814
|
+
parts.push(` var group = groupMap[g];`);
|
|
5815
|
+
parts.push(` if (group.lessonId !== currentLesson) continue;`);
|
|
5816
|
+
parts.push(` if (document.querySelector('[data-pa-group-id="' + group.id + '"]')) continue;`);
|
|
5817
|
+
parts.push(` var blocks = [];`);
|
|
5818
|
+
parts.push(` var allPresent = true;`);
|
|
5819
|
+
parts.push(` for (var b = 0; b < group.blockIds.length; b++) {`);
|
|
5820
|
+
parts.push(` var el = document.querySelector('[data-block-id="' + group.blockIds[b] + '"]');`);
|
|
5821
|
+
parts.push(` if (!el) { allPresent = false; break; }`);
|
|
5822
|
+
parts.push(` blocks.push(el);`);
|
|
5823
|
+
parts.push(` }`);
|
|
5824
|
+
parts.push(` if (!allPresent) continue;`);
|
|
5825
|
+
parts.push(` var parent = blocks[0].parentNode;`);
|
|
5826
|
+
parts.push(` var sameParent = true;`);
|
|
5827
|
+
parts.push(` for (var s = 1; s < blocks.length; s++) {`);
|
|
5828
|
+
parts.push(` if (blocks[s].parentNode !== parent) { sameParent = false; break; }`);
|
|
5829
|
+
parts.push(` }`);
|
|
5830
|
+
parts.push(` if (!sameParent) continue;`);
|
|
5831
|
+
parts.push(` var wrapper = document.createElement('div');`);
|
|
5832
|
+
parts.push(` wrapper.setAttribute('data-pa-group-id', group.id);`);
|
|
5833
|
+
parts.push(` var cls = group.className.split(' ');`);
|
|
5834
|
+
parts.push(` for (var c = 0; c < cls.length; c++) {`);
|
|
5835
|
+
parts.push(` if (cls[c]) wrapper.classList.add(cls[c]);`);
|
|
5836
|
+
parts.push(` }`);
|
|
5837
|
+
parts.push(` parent.insertBefore(wrapper, blocks[0]);`);
|
|
5838
|
+
parts.push(` for (var m = 0; m < blocks.length; m++) {`);
|
|
5839
|
+
parts.push(` wrapper.appendChild(blocks[m]);`);
|
|
5840
|
+
parts.push(` }`);
|
|
5841
|
+
parts.push(` }`);
|
|
5842
|
+
parts.push(` }`);
|
|
5843
|
+
parts.push(``);
|
|
5844
|
+
parts.push(` function teardownBlockGroups() {`);
|
|
5845
|
+
parts.push(` var wrappers = document.querySelectorAll('[data-pa-group-id]');`);
|
|
5846
|
+
parts.push(` for (var w = 0; w < wrappers.length; w++) {`);
|
|
5847
|
+
parts.push(` var wr = wrappers[w];`);
|
|
5848
|
+
parts.push(` var par = wr.parentNode;`);
|
|
5849
|
+
parts.push(` while (wr.firstChild) {`);
|
|
5850
|
+
parts.push(` par.insertBefore(wr.firstChild, wr);`);
|
|
5851
|
+
parts.push(` }`);
|
|
5852
|
+
parts.push(` par.removeChild(wr);`);
|
|
5853
|
+
parts.push(` }`);
|
|
5854
|
+
parts.push(` }`);
|
|
5855
|
+
parts.push(``);
|
|
5856
|
+
}
|
|
5791
5857
|
parts.push(` // Initialization`);
|
|
5792
5858
|
parts.push(` function init() {`);
|
|
5793
5859
|
if (hasBlocks) {
|
|
5794
5860
|
parts.push(` applyBlockClasses();`);
|
|
5795
5861
|
}
|
|
5862
|
+
if (hasGroups) {
|
|
5863
|
+
parts.push(` applyBlockGroups();`);
|
|
5864
|
+
}
|
|
5796
5865
|
if (hasLessons) {
|
|
5797
5866
|
parts.push(` applyLessonClasses();`);
|
|
5867
|
+
}
|
|
5868
|
+
if (hasLessons || hasGroups) {
|
|
5798
5869
|
parts.push(``);
|
|
5799
5870
|
parts.push(` // Watch for Rise SPA navigation`);
|
|
5800
5871
|
parts.push(` window.addEventListener('hashchange', function() {`);
|
|
5801
|
-
|
|
5872
|
+
if (hasGroups) {
|
|
5873
|
+
parts.push(` teardownBlockGroups();`);
|
|
5874
|
+
}
|
|
5875
|
+
if (hasLessons) {
|
|
5876
|
+
parts.push(` applyLessonClasses();`);
|
|
5877
|
+
}
|
|
5802
5878
|
if (hasBlocks) {
|
|
5803
5879
|
parts.push(` setTimeout(applyBlockClasses, 200);`);
|
|
5804
5880
|
}
|
|
5881
|
+
if (hasGroups) {
|
|
5882
|
+
parts.push(` setTimeout(applyBlockGroups, 300);`);
|
|
5883
|
+
}
|
|
5805
5884
|
parts.push(` });`);
|
|
5806
5885
|
}
|
|
5807
|
-
if (hasBlocks) {
|
|
5886
|
+
if (hasBlocks || hasGroups) {
|
|
5808
5887
|
parts.push(``);
|
|
5809
5888
|
parts.push(` // MutationObserver for lazily-rendered Rise blocks`);
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5889
|
+
if (hasGroups) {
|
|
5890
|
+
parts.push(` var debounceTimer = null;`);
|
|
5891
|
+
parts.push(` var observer = new MutationObserver(function() {`);
|
|
5892
|
+
parts.push(` if (debounceTimer) clearTimeout(debounceTimer);`);
|
|
5893
|
+
parts.push(` debounceTimer = setTimeout(function() {`);
|
|
5894
|
+
if (hasBlocks) {
|
|
5895
|
+
parts.push(` applyBlockClasses();`);
|
|
5896
|
+
}
|
|
5897
|
+
parts.push(` applyBlockGroups();`);
|
|
5898
|
+
parts.push(` }, 100);`);
|
|
5899
|
+
parts.push(` });`);
|
|
5900
|
+
} else {
|
|
5901
|
+
parts.push(` var observer = new MutationObserver(function(mutations) {`);
|
|
5902
|
+
parts.push(` for (var i = 0; i < mutations.length; i++) {`);
|
|
5903
|
+
parts.push(` if (mutations[i].addedNodes.length > 0) {`);
|
|
5904
|
+
parts.push(` applyBlockClasses();`);
|
|
5905
|
+
parts.push(` return;`);
|
|
5906
|
+
parts.push(` }`);
|
|
5907
|
+
parts.push(` }`);
|
|
5908
|
+
parts.push(` });`);
|
|
5909
|
+
}
|
|
5818
5910
|
parts.push(` var container = document.querySelector('#app') || document.body;`);
|
|
5819
5911
|
parts.push(` observer.observe(container, { childList: true, subtree: true });`);
|
|
5820
5912
|
}
|
|
@@ -5880,6 +5972,7 @@ var HtmlInjector = class {
|
|
|
5880
5972
|
inject(html) {
|
|
5881
5973
|
let result = html;
|
|
5882
5974
|
result = this.addHtmlAttributes(result);
|
|
5975
|
+
result = this.injectVersionResolver(result);
|
|
5883
5976
|
if (this.config.cssBefore.enabled) {
|
|
5884
5977
|
result = this.injectCssBefore(result);
|
|
5885
5978
|
}
|
|
@@ -5983,6 +6076,20 @@ ${pluginJs}
|
|
|
5983
6076
|
escapeAttr(str) {
|
|
5984
6077
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
5985
6078
|
}
|
|
6079
|
+
/**
|
|
6080
|
+
* Inject a tiny inline script that fetches the asset version BEFORE any loaders.
|
|
6081
|
+
* Sets window.__pa_v so CSS Before, JS Before, and all other loaders get ?v= cache bust.
|
|
6082
|
+
*/
|
|
6083
|
+
injectVersionResolver(html) {
|
|
6084
|
+
const assetVersionUrl = this.config.assetVersionUrl || "";
|
|
6085
|
+
if (!assetVersionUrl) return html;
|
|
6086
|
+
const script = `<!-- === PATCH-ADAMS: VERSION RESOLVER === -->
|
|
6087
|
+
<script data-pa="version-resolver">
|
|
6088
|
+
(function(){try{var x=new XMLHttpRequest();x.open('GET','${assetVersionUrl}',false);x.send();if(x.status===200){window.__pa_v=JSON.parse(x.responseText).v||'1'}}catch(e){window.__pa_v='1'}})();
|
|
6089
|
+
</script>`;
|
|
6090
|
+
return html.replace(/<head([^>]*)>/i, `<head$1>
|
|
6091
|
+
${script}`);
|
|
6092
|
+
}
|
|
5986
6093
|
/**
|
|
5987
6094
|
* Inject CSS Before loader at start of <head>
|
|
5988
6095
|
*/
|