@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/cli.js
CHANGED
|
@@ -5630,18 +5630,21 @@ window.pa_patcher = window.pa_patcher || {
|
|
|
5630
5630
|
|
|
5631
5631
|
(function() {
|
|
5632
5632
|
'use strict';
|
|
5633
|
-
//
|
|
5634
|
-
|
|
5635
|
-
window.__pa_v
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5633
|
+
// Cache version \u2014 normally set by version resolver (injected before CSS Before).
|
|
5634
|
+
// Fallback: fetch here if version resolver didn't run (older patched packages).
|
|
5635
|
+
if (typeof window.__pa_v === 'undefined') {
|
|
5636
|
+
var ASSET_VERSION_URL = "${assetVersionUrl || ""}";
|
|
5637
|
+
window.__pa_v = '';
|
|
5638
|
+
if (ASSET_VERSION_URL) {
|
|
5639
|
+
try {
|
|
5640
|
+
var xhr = new XMLHttpRequest();
|
|
5641
|
+
xhr.open('GET', ASSET_VERSION_URL, false);
|
|
5642
|
+
xhr.send();
|
|
5643
|
+
if (xhr.status === 200) {
|
|
5644
|
+
window.__pa_v = JSON.parse(xhr.responseText).v || '1';
|
|
5645
|
+
}
|
|
5646
|
+
} catch(e) { window.__pa_v = '1'; }
|
|
5647
|
+
}
|
|
5645
5648
|
}
|
|
5646
5649
|
|
|
5647
5650
|
var REMOTE_URL = "${remoteUrl}" + (window.__pa_v ? "?v=" + window.__pa_v : "");
|
|
@@ -6024,6 +6027,7 @@ function hasClassMappings(mappings) {
|
|
|
6024
6027
|
if (mappings.course?.trim()) return true;
|
|
6025
6028
|
if (mappings.lessons && Object.values(mappings.lessons).some((v) => v?.trim())) return true;
|
|
6026
6029
|
if (mappings.blocks && Object.values(mappings.blocks).some((v) => v?.trim())) return true;
|
|
6030
|
+
if (mappings.blockGroups && mappings.blockGroups.length > 0) return true;
|
|
6027
6031
|
return false;
|
|
6028
6032
|
}
|
|
6029
6033
|
function generateClassMappingsScript(mappings) {
|
|
@@ -6045,6 +6049,10 @@ function generateClassMappingsScript(mappings) {
|
|
|
6045
6049
|
}
|
|
6046
6050
|
const hasBlocks = Object.keys(blockMap).length > 0;
|
|
6047
6051
|
const hasLessons = Object.keys(lessonMap).length > 0;
|
|
6052
|
+
const blockGroups = (mappings.blockGroups || []).filter(
|
|
6053
|
+
(g) => g.blockIds.length >= 2 && g.className.trim() && g.lessonId
|
|
6054
|
+
);
|
|
6055
|
+
const hasGroups = blockGroups.length > 0;
|
|
6048
6056
|
const parts = [];
|
|
6049
6057
|
parts.push(`// PA-Patcher: Custom Class Mappings`);
|
|
6050
6058
|
parts.push(`(function() {`);
|
|
@@ -6110,33 +6118,117 @@ function generateClassMappingsScript(mappings) {
|
|
|
6110
6118
|
parts.push(` }`);
|
|
6111
6119
|
parts.push(``);
|
|
6112
6120
|
}
|
|
6121
|
+
if (hasGroups) {
|
|
6122
|
+
const groupData = blockGroups.map((g) => ({
|
|
6123
|
+
id: g.id,
|
|
6124
|
+
lessonId: g.lessonId,
|
|
6125
|
+
blockIds: g.blockIds,
|
|
6126
|
+
className: g.className.trim()
|
|
6127
|
+
}));
|
|
6128
|
+
parts.push(` // Block groups (adjacent blocks wrapped in container divs)`);
|
|
6129
|
+
parts.push(` var groupMap = ${JSON.stringify(groupData)};`);
|
|
6130
|
+
parts.push(``);
|
|
6131
|
+
parts.push(` function applyBlockGroups() {`);
|
|
6132
|
+
parts.push(` var hash = window.location.hash || '';`);
|
|
6133
|
+
parts.push(` var match = hash.match(/#\\/lessons\\/([^/]+)/);`);
|
|
6134
|
+
parts.push(` var currentLesson = match ? match[1] : null;`);
|
|
6135
|
+
parts.push(` for (var g = 0; g < groupMap.length; g++) {`);
|
|
6136
|
+
parts.push(` var group = groupMap[g];`);
|
|
6137
|
+
parts.push(` if (group.lessonId !== currentLesson) continue;`);
|
|
6138
|
+
parts.push(` if (document.querySelector('[data-pa-group-id="' + group.id + '"]')) continue;`);
|
|
6139
|
+
parts.push(` var blocks = [];`);
|
|
6140
|
+
parts.push(` var allPresent = true;`);
|
|
6141
|
+
parts.push(` for (var b = 0; b < group.blockIds.length; b++) {`);
|
|
6142
|
+
parts.push(` var el = document.querySelector('[data-block-id="' + group.blockIds[b] + '"]');`);
|
|
6143
|
+
parts.push(` if (!el) { allPresent = false; break; }`);
|
|
6144
|
+
parts.push(` blocks.push(el);`);
|
|
6145
|
+
parts.push(` }`);
|
|
6146
|
+
parts.push(` if (!allPresent) continue;`);
|
|
6147
|
+
parts.push(` var parent = blocks[0].parentNode;`);
|
|
6148
|
+
parts.push(` var sameParent = true;`);
|
|
6149
|
+
parts.push(` for (var s = 1; s < blocks.length; s++) {`);
|
|
6150
|
+
parts.push(` if (blocks[s].parentNode !== parent) { sameParent = false; break; }`);
|
|
6151
|
+
parts.push(` }`);
|
|
6152
|
+
parts.push(` if (!sameParent) continue;`);
|
|
6153
|
+
parts.push(` var wrapper = document.createElement('div');`);
|
|
6154
|
+
parts.push(` wrapper.setAttribute('data-pa-group-id', group.id);`);
|
|
6155
|
+
parts.push(` var cls = group.className.split(' ');`);
|
|
6156
|
+
parts.push(` for (var c = 0; c < cls.length; c++) {`);
|
|
6157
|
+
parts.push(` if (cls[c]) wrapper.classList.add(cls[c]);`);
|
|
6158
|
+
parts.push(` }`);
|
|
6159
|
+
parts.push(` parent.insertBefore(wrapper, blocks[0]);`);
|
|
6160
|
+
parts.push(` for (var m = 0; m < blocks.length; m++) {`);
|
|
6161
|
+
parts.push(` wrapper.appendChild(blocks[m]);`);
|
|
6162
|
+
parts.push(` }`);
|
|
6163
|
+
parts.push(` }`);
|
|
6164
|
+
parts.push(` }`);
|
|
6165
|
+
parts.push(``);
|
|
6166
|
+
parts.push(` function teardownBlockGroups() {`);
|
|
6167
|
+
parts.push(` var wrappers = document.querySelectorAll('[data-pa-group-id]');`);
|
|
6168
|
+
parts.push(` for (var w = 0; w < wrappers.length; w++) {`);
|
|
6169
|
+
parts.push(` var wr = wrappers[w];`);
|
|
6170
|
+
parts.push(` var par = wr.parentNode;`);
|
|
6171
|
+
parts.push(` while (wr.firstChild) {`);
|
|
6172
|
+
parts.push(` par.insertBefore(wr.firstChild, wr);`);
|
|
6173
|
+
parts.push(` }`);
|
|
6174
|
+
parts.push(` par.removeChild(wr);`);
|
|
6175
|
+
parts.push(` }`);
|
|
6176
|
+
parts.push(` }`);
|
|
6177
|
+
parts.push(``);
|
|
6178
|
+
}
|
|
6113
6179
|
parts.push(` // Initialization`);
|
|
6114
6180
|
parts.push(` function init() {`);
|
|
6115
6181
|
if (hasBlocks) {
|
|
6116
6182
|
parts.push(` applyBlockClasses();`);
|
|
6117
6183
|
}
|
|
6184
|
+
if (hasGroups) {
|
|
6185
|
+
parts.push(` applyBlockGroups();`);
|
|
6186
|
+
}
|
|
6118
6187
|
if (hasLessons) {
|
|
6119
6188
|
parts.push(` applyLessonClasses();`);
|
|
6189
|
+
}
|
|
6190
|
+
if (hasLessons || hasGroups) {
|
|
6120
6191
|
parts.push(``);
|
|
6121
6192
|
parts.push(` // Watch for Rise SPA navigation`);
|
|
6122
6193
|
parts.push(` window.addEventListener('hashchange', function() {`);
|
|
6123
|
-
|
|
6194
|
+
if (hasGroups) {
|
|
6195
|
+
parts.push(` teardownBlockGroups();`);
|
|
6196
|
+
}
|
|
6197
|
+
if (hasLessons) {
|
|
6198
|
+
parts.push(` applyLessonClasses();`);
|
|
6199
|
+
}
|
|
6124
6200
|
if (hasBlocks) {
|
|
6125
6201
|
parts.push(` setTimeout(applyBlockClasses, 200);`);
|
|
6126
6202
|
}
|
|
6203
|
+
if (hasGroups) {
|
|
6204
|
+
parts.push(` setTimeout(applyBlockGroups, 300);`);
|
|
6205
|
+
}
|
|
6127
6206
|
parts.push(` });`);
|
|
6128
6207
|
}
|
|
6129
|
-
if (hasBlocks) {
|
|
6208
|
+
if (hasBlocks || hasGroups) {
|
|
6130
6209
|
parts.push(``);
|
|
6131
6210
|
parts.push(` // MutationObserver for lazily-rendered Rise blocks`);
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6211
|
+
if (hasGroups) {
|
|
6212
|
+
parts.push(` var debounceTimer = null;`);
|
|
6213
|
+
parts.push(` var observer = new MutationObserver(function() {`);
|
|
6214
|
+
parts.push(` if (debounceTimer) clearTimeout(debounceTimer);`);
|
|
6215
|
+
parts.push(` debounceTimer = setTimeout(function() {`);
|
|
6216
|
+
if (hasBlocks) {
|
|
6217
|
+
parts.push(` applyBlockClasses();`);
|
|
6218
|
+
}
|
|
6219
|
+
parts.push(` applyBlockGroups();`);
|
|
6220
|
+
parts.push(` }, 100);`);
|
|
6221
|
+
parts.push(` });`);
|
|
6222
|
+
} else {
|
|
6223
|
+
parts.push(` var observer = new MutationObserver(function(mutations) {`);
|
|
6224
|
+
parts.push(` for (var i = 0; i < mutations.length; i++) {`);
|
|
6225
|
+
parts.push(` if (mutations[i].addedNodes.length > 0) {`);
|
|
6226
|
+
parts.push(` applyBlockClasses();`);
|
|
6227
|
+
parts.push(` return;`);
|
|
6228
|
+
parts.push(` }`);
|
|
6229
|
+
parts.push(` }`);
|
|
6230
|
+
parts.push(` });`);
|
|
6231
|
+
}
|
|
6140
6232
|
parts.push(` var container = document.querySelector('#app') || document.body;`);
|
|
6141
6233
|
parts.push(` observer.observe(container, { childList: true, subtree: true });`);
|
|
6142
6234
|
}
|
|
@@ -6202,6 +6294,7 @@ var HtmlInjector = class {
|
|
|
6202
6294
|
inject(html) {
|
|
6203
6295
|
let result = html;
|
|
6204
6296
|
result = this.addHtmlAttributes(result);
|
|
6297
|
+
result = this.injectVersionResolver(result);
|
|
6205
6298
|
if (this.config.cssBefore.enabled) {
|
|
6206
6299
|
result = this.injectCssBefore(result);
|
|
6207
6300
|
}
|
|
@@ -6305,6 +6398,20 @@ ${pluginJs}
|
|
|
6305
6398
|
escapeAttr(str) {
|
|
6306
6399
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
6307
6400
|
}
|
|
6401
|
+
/**
|
|
6402
|
+
* Inject a tiny inline script that fetches the asset version BEFORE any loaders.
|
|
6403
|
+
* Sets window.__pa_v so CSS Before, JS Before, and all other loaders get ?v= cache bust.
|
|
6404
|
+
*/
|
|
6405
|
+
injectVersionResolver(html) {
|
|
6406
|
+
const assetVersionUrl = this.config.assetVersionUrl || "";
|
|
6407
|
+
if (!assetVersionUrl) return html;
|
|
6408
|
+
const script = `<!-- === PATCH-ADAMS: VERSION RESOLVER === -->
|
|
6409
|
+
<script data-pa="version-resolver">
|
|
6410
|
+
(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'}})();
|
|
6411
|
+
</script>`;
|
|
6412
|
+
return html.replace(/<head([^>]*)>/i, `<head$1>
|
|
6413
|
+
${script}`);
|
|
6414
|
+
}
|
|
6308
6415
|
/**
|
|
6309
6416
|
* Inject CSS Before loader at start of <head>
|
|
6310
6417
|
*/
|