@patch-adams/core 1.5.23 → 1.6.0
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 +140 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +140 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +224 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +222 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5637,7 +5637,6 @@ window.pa_patcher = window.pa_patcher || {
|
|
|
5637
5637
|
try {
|
|
5638
5638
|
var xhr = new XMLHttpRequest();
|
|
5639
5639
|
xhr.open('GET', ASSET_VERSION_URL, false);
|
|
5640
|
-
xhr.timeout = 2000;
|
|
5641
5640
|
xhr.send();
|
|
5642
5641
|
if (xhr.status === 200) {
|
|
5643
5642
|
window.__pa_v = JSON.parse(xhr.responseText).v || '1';
|
|
@@ -6019,6 +6018,139 @@ function buildSkinJsOptions(config) {
|
|
|
6019
6018
|
};
|
|
6020
6019
|
}
|
|
6021
6020
|
|
|
6021
|
+
// src/templates/class-mappings.ts
|
|
6022
|
+
function hasClassMappings(mappings) {
|
|
6023
|
+
if (!mappings) return false;
|
|
6024
|
+
if (mappings.course?.trim()) return true;
|
|
6025
|
+
if (mappings.lessons && Object.values(mappings.lessons).some((v) => v?.trim())) return true;
|
|
6026
|
+
if (mappings.blocks && Object.values(mappings.blocks).some((v) => v?.trim())) return true;
|
|
6027
|
+
return false;
|
|
6028
|
+
}
|
|
6029
|
+
function generateClassMappingsScript(mappings) {
|
|
6030
|
+
if (!hasClassMappings(mappings)) return "";
|
|
6031
|
+
const courseClasses = (mappings.course || "").trim();
|
|
6032
|
+
const blockMap = {};
|
|
6033
|
+
const lessonMap = {};
|
|
6034
|
+
if (mappings.blocks) {
|
|
6035
|
+
for (const [id, classes] of Object.entries(mappings.blocks)) {
|
|
6036
|
+
const trimmed = classes?.trim();
|
|
6037
|
+
if (trimmed) blockMap[id] = trimmed;
|
|
6038
|
+
}
|
|
6039
|
+
}
|
|
6040
|
+
if (mappings.lessons) {
|
|
6041
|
+
for (const [id, classes] of Object.entries(mappings.lessons)) {
|
|
6042
|
+
const trimmed = classes?.trim();
|
|
6043
|
+
if (trimmed) lessonMap[id] = trimmed;
|
|
6044
|
+
}
|
|
6045
|
+
}
|
|
6046
|
+
const hasBlocks = Object.keys(blockMap).length > 0;
|
|
6047
|
+
const hasLessons = Object.keys(lessonMap).length > 0;
|
|
6048
|
+
const parts = [];
|
|
6049
|
+
parts.push(`// PA-Patcher: Custom Class Mappings`);
|
|
6050
|
+
parts.push(`(function() {`);
|
|
6051
|
+
parts.push(` 'use strict';`);
|
|
6052
|
+
parts.push(``);
|
|
6053
|
+
if (courseClasses) {
|
|
6054
|
+
parts.push(` // Course-level classes (applied to <html>)`);
|
|
6055
|
+
parts.push(` var courseClasses = ${JSON.stringify(courseClasses)};`);
|
|
6056
|
+
parts.push(` courseClasses.split(' ').forEach(function(cls) {`);
|
|
6057
|
+
parts.push(` if (cls) document.documentElement.classList.add(cls);`);
|
|
6058
|
+
parts.push(` });`);
|
|
6059
|
+
parts.push(``);
|
|
6060
|
+
}
|
|
6061
|
+
if (hasBlocks) {
|
|
6062
|
+
parts.push(` // Block-level classes (applied to [data-block-id] elements)`);
|
|
6063
|
+
parts.push(` var blockMap = ${JSON.stringify(blockMap)};`);
|
|
6064
|
+
parts.push(``);
|
|
6065
|
+
parts.push(` function applyBlockClasses() {`);
|
|
6066
|
+
parts.push(` var ids = Object.keys(blockMap);`);
|
|
6067
|
+
parts.push(` for (var i = 0; i < ids.length; i++) {`);
|
|
6068
|
+
parts.push(` var el = document.querySelector('[data-block-id="' + ids[i] + '"]');`);
|
|
6069
|
+
parts.push(` if (el) {`);
|
|
6070
|
+
parts.push(` var classes = blockMap[ids[i]].split(' ');`);
|
|
6071
|
+
parts.push(` for (var j = 0; j < classes.length; j++) {`);
|
|
6072
|
+
parts.push(` if (classes[j]) el.classList.add(classes[j]);`);
|
|
6073
|
+
parts.push(` }`);
|
|
6074
|
+
parts.push(` }`);
|
|
6075
|
+
parts.push(` }`);
|
|
6076
|
+
parts.push(` }`);
|
|
6077
|
+
parts.push(``);
|
|
6078
|
+
}
|
|
6079
|
+
if (hasLessons) {
|
|
6080
|
+
parts.push(` // Lesson-level classes (toggled on <html> via hash navigation)`);
|
|
6081
|
+
parts.push(` var lessonMap = ${JSON.stringify(lessonMap)};`);
|
|
6082
|
+
parts.push(` var allLessonClasses = [];`);
|
|
6083
|
+
parts.push(` Object.keys(lessonMap).forEach(function(id) {`);
|
|
6084
|
+
parts.push(` lessonMap[id].split(' ').forEach(function(cls) {`);
|
|
6085
|
+
parts.push(` if (cls && allLessonClasses.indexOf(cls) === -1) allLessonClasses.push(cls);`);
|
|
6086
|
+
parts.push(` });`);
|
|
6087
|
+
parts.push(` });`);
|
|
6088
|
+
parts.push(``);
|
|
6089
|
+
parts.push(` var currentLessonId = null;`);
|
|
6090
|
+
parts.push(``);
|
|
6091
|
+
parts.push(` function detectCurrentLesson() {`);
|
|
6092
|
+
parts.push(` var hash = window.location.hash || '';`);
|
|
6093
|
+
parts.push(` var match = hash.match(/#\\/lessons\\/([^/]+)/);`);
|
|
6094
|
+
parts.push(` return match ? match[1] : null;`);
|
|
6095
|
+
parts.push(` }`);
|
|
6096
|
+
parts.push(``);
|
|
6097
|
+
parts.push(` function applyLessonClasses() {`);
|
|
6098
|
+
parts.push(` var lessonId = detectCurrentLesson();`);
|
|
6099
|
+
parts.push(` if (lessonId === currentLessonId) return;`);
|
|
6100
|
+
parts.push(` currentLessonId = lessonId;`);
|
|
6101
|
+
parts.push(` for (var i = 0; i < allLessonClasses.length; i++) {`);
|
|
6102
|
+
parts.push(` document.documentElement.classList.remove(allLessonClasses[i]);`);
|
|
6103
|
+
parts.push(` }`);
|
|
6104
|
+
parts.push(` if (lessonId && lessonMap[lessonId]) {`);
|
|
6105
|
+
parts.push(` var classes = lessonMap[lessonId].split(' ');`);
|
|
6106
|
+
parts.push(` for (var j = 0; j < classes.length; j++) {`);
|
|
6107
|
+
parts.push(` if (classes[j]) document.documentElement.classList.add(classes[j]);`);
|
|
6108
|
+
parts.push(` }`);
|
|
6109
|
+
parts.push(` }`);
|
|
6110
|
+
parts.push(` }`);
|
|
6111
|
+
parts.push(``);
|
|
6112
|
+
}
|
|
6113
|
+
parts.push(` // Initialization`);
|
|
6114
|
+
parts.push(` function init() {`);
|
|
6115
|
+
if (hasBlocks) {
|
|
6116
|
+
parts.push(` applyBlockClasses();`);
|
|
6117
|
+
}
|
|
6118
|
+
if (hasLessons) {
|
|
6119
|
+
parts.push(` applyLessonClasses();`);
|
|
6120
|
+
parts.push(``);
|
|
6121
|
+
parts.push(` // Watch for Rise SPA navigation`);
|
|
6122
|
+
parts.push(` window.addEventListener('hashchange', function() {`);
|
|
6123
|
+
parts.push(` applyLessonClasses();`);
|
|
6124
|
+
if (hasBlocks) {
|
|
6125
|
+
parts.push(` setTimeout(applyBlockClasses, 200);`);
|
|
6126
|
+
}
|
|
6127
|
+
parts.push(` });`);
|
|
6128
|
+
}
|
|
6129
|
+
if (hasBlocks) {
|
|
6130
|
+
parts.push(``);
|
|
6131
|
+
parts.push(` // MutationObserver for lazily-rendered Rise blocks`);
|
|
6132
|
+
parts.push(` var observer = new MutationObserver(function(mutations) {`);
|
|
6133
|
+
parts.push(` for (var i = 0; i < mutations.length; i++) {`);
|
|
6134
|
+
parts.push(` if (mutations[i].addedNodes.length > 0) {`);
|
|
6135
|
+
parts.push(` applyBlockClasses();`);
|
|
6136
|
+
parts.push(` return;`);
|
|
6137
|
+
parts.push(` }`);
|
|
6138
|
+
parts.push(` }`);
|
|
6139
|
+
parts.push(` });`);
|
|
6140
|
+
parts.push(` var container = document.querySelector('#app') || document.body;`);
|
|
6141
|
+
parts.push(` observer.observe(container, { childList: true, subtree: true });`);
|
|
6142
|
+
}
|
|
6143
|
+
parts.push(` }`);
|
|
6144
|
+
parts.push(``);
|
|
6145
|
+
parts.push(` if (document.readyState === 'loading') {`);
|
|
6146
|
+
parts.push(` document.addEventListener('DOMContentLoaded', init);`);
|
|
6147
|
+
parts.push(` } else {`);
|
|
6148
|
+
parts.push(` init();`);
|
|
6149
|
+
parts.push(` }`);
|
|
6150
|
+
parts.push(`})();`);
|
|
6151
|
+
return parts.join("\n");
|
|
6152
|
+
}
|
|
6153
|
+
|
|
6022
6154
|
// src/patcher/html-injector.ts
|
|
6023
6155
|
var HtmlInjector = class {
|
|
6024
6156
|
config;
|
|
@@ -7099,6 +7231,13 @@ var Patcher = class {
|
|
|
7099
7231
|
console.log(`[Patcher] Fetched ${fetchedCount} remote files`);
|
|
7100
7232
|
}
|
|
7101
7233
|
const pluginAssets = this.generatePluginAssets();
|
|
7234
|
+
if (hasClassMappings(options.classMappings)) {
|
|
7235
|
+
const classMappingsJs = generateClassMappingsScript(options.classMappings);
|
|
7236
|
+
if (classMappingsJs) {
|
|
7237
|
+
pluginAssets.jsAfter = classMappingsJs + (pluginAssets.jsAfter ? "\n" + pluginAssets.jsAfter : "");
|
|
7238
|
+
console.log("[Patcher] Class mappings JS will be injected inline into HTML");
|
|
7239
|
+
}
|
|
7240
|
+
}
|
|
7102
7241
|
const hasPluginAssets = pluginAssets.cssBefore || pluginAssets.cssAfter || pluginAssets.jsBefore || pluginAssets.jsAfter;
|
|
7103
7242
|
if (hasPluginAssets) {
|
|
7104
7243
|
htmlInjector.setPluginAssets(pluginAssets);
|