single-file-core 1.2.5 → 1.2.7
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.
|
@@ -1973,6 +1973,7 @@ async function evalTemplate(template = "", options, util, content, dontReplaceSl
|
|
|
1973
1973
|
template = await evalTemplateVariable(template, "bookmark-pathname", () => bookmarkFolder, dontReplaceSlash === undefined ? true : dontReplaceSlash, options.filenameReplacementCharacter);
|
|
1974
1974
|
template = await evalTemplateVariable(template, "bookmark-pathname-flat", () => bookmarkFolder, false, options.filenameReplacementCharacter);
|
|
1975
1975
|
template = await evalTemplateVariable(template, "profile-name", () => options.profileName, dontReplaceSlash, options.filenameReplacementCharacter);
|
|
1976
|
+
template = await evalTemplateVariable(template, "filename-extension", () => getFilenameExtension(options), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
1976
1977
|
return template.trim();
|
|
1977
1978
|
|
|
1978
1979
|
function decode(value) {
|
|
@@ -2102,3 +2103,19 @@ function truncateText(content, maxSize) {
|
|
|
2102
2103
|
reader.addEventListener("error", reject, false);
|
|
2103
2104
|
});
|
|
2104
2105
|
}
|
|
2106
|
+
|
|
2107
|
+
function getFilenameExtension(options) {
|
|
2108
|
+
if (options.compressContent) {
|
|
2109
|
+
if (options.selfExtractingArchive) {
|
|
2110
|
+
if (options.extractDataFromPage) {
|
|
2111
|
+
return "u.zip.html";
|
|
2112
|
+
} else {
|
|
2113
|
+
return "zip.html";
|
|
2114
|
+
}
|
|
2115
|
+
} else {
|
|
2116
|
+
return "zip";
|
|
2117
|
+
}
|
|
2118
|
+
} else {
|
|
2119
|
+
return "html";
|
|
2120
|
+
}
|
|
2121
|
+
}
|
package/package.json
CHANGED
|
@@ -69,12 +69,26 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
69
69
|
options.password = prompt("Please enter the password to view the page");
|
|
70
70
|
}
|
|
71
71
|
name = entry.filename.match(/^([0-9_]+\/)?(.*)$/)[2];
|
|
72
|
+
let mimeType;
|
|
72
73
|
if (entry.filename.match(/index\.html$/) || entry.filename.match(/stylesheet_[0-9]+\.css/) || entry.filename.match(/scripts\/[0-9]+\.js/)) {
|
|
73
74
|
dataWriter = new zip.TextWriter();
|
|
74
75
|
textContent = await entry.getData(dataWriter, options);
|
|
76
|
+
if (entry.filename.match(/index\.html$/)) {
|
|
77
|
+
mimeType = "text/html";
|
|
78
|
+
} else {
|
|
79
|
+
if (entry.filename.match(/stylesheet_[0-9]+\.css/)) {
|
|
80
|
+
mimeType = "text/css";
|
|
81
|
+
} else if (entry.filename.match(/scripts\/[0-9]+\.js/)) {
|
|
82
|
+
mimeType = "text/javascript";
|
|
83
|
+
}
|
|
84
|
+
if (textContent !== undefined) {
|
|
85
|
+
content = noBlobURL ? await getDataURI(textContent, mimeType) : URL.createObjectURL(new Blob([textContent], { type: mimeType }));
|
|
86
|
+
} else {
|
|
87
|
+
content = "data:text/plain,";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
75
90
|
} else {
|
|
76
91
|
const extension = entry.filename.match(/\.([^.]+)/);
|
|
77
|
-
let mimeType;
|
|
78
92
|
if (extension && extension[1] && KNOWN_MIMETYPES[extension[1]]) {
|
|
79
93
|
mimeType = KNOWN_MIMETYPES[extension[1]];
|
|
80
94
|
} else {
|
|
@@ -87,7 +101,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
87
101
|
content = URL.createObjectURL(blob);
|
|
88
102
|
}
|
|
89
103
|
}
|
|
90
|
-
resources.push({ filename: entry.filename, name, url: entry.comment, content, blob, textContent, parentResources: [] });
|
|
104
|
+
resources.push({ filename: entry.filename, name, url: entry.comment, content, mimeType, blob, textContent, parentResources: [] });
|
|
91
105
|
}));
|
|
92
106
|
await zipReader.close();
|
|
93
107
|
let docContent, origDocContent, url;
|
|
@@ -105,7 +119,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
105
119
|
}
|
|
106
120
|
const isScript = resource.filename.match(/scripts\/[0-9]+\.js/);
|
|
107
121
|
if (!isScript) {
|
|
108
|
-
resources.
|
|
122
|
+
await Promise.all(resources.map(async innerResource => {
|
|
109
123
|
if (innerResource.filename.startsWith(prefixPath) && innerResource.filename != resource.filename) {
|
|
110
124
|
const filename = innerResource.filename.substring(prefixPath.length);
|
|
111
125
|
if (!filename.match(/manifest\.json$/)) {
|
|
@@ -117,15 +131,10 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
117
131
|
}
|
|
118
132
|
}
|
|
119
133
|
}
|
|
120
|
-
});
|
|
134
|
+
}));
|
|
135
|
+
resource.content = await getDataURI(resource.textContent, resource.mimeType);
|
|
121
136
|
}
|
|
122
|
-
|
|
123
|
-
if (resource.filename.match(/stylesheet_[0-9]+\.css/)) {
|
|
124
|
-
mimeType = "text/css";
|
|
125
|
-
} else if (isScript) {
|
|
126
|
-
mimeType = "text/javascript";
|
|
127
|
-
} else if (resource.filename.match(/index\.html$/)) {
|
|
128
|
-
mimeType = "text/html";
|
|
137
|
+
if (resource.filename.match(/index\.html$/)) {
|
|
129
138
|
if (shadowRootScriptURL) {
|
|
130
139
|
resource.textContent = resource.textContent.replace(/<script data-template-shadow-root.*<\/script>/g, "<script data-template-shadow-root src=" + shadowRootScriptURL + "></" + "script>");
|
|
131
140
|
}
|
|
@@ -133,19 +142,17 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
133
142
|
if (resource.filename.match(/^([0-9_]+\/)?index\.html$/)) {
|
|
134
143
|
docContent = resource.textContent;
|
|
135
144
|
url = resource.url;
|
|
136
|
-
} else {
|
|
137
|
-
const reader = new FileReader();
|
|
138
|
-
if (resource.textContent) {
|
|
139
|
-
reader.readAsDataURL(new Blob([resource.textContent], { type: mimeType + ";charset=utf-8" }));
|
|
140
|
-
resource.content = await new Promise((resolve, reject) => {
|
|
141
|
-
reader.addEventListener("load", () => resolve(reader.result), false);
|
|
142
|
-
reader.addEventListener("error", reject, false);
|
|
143
|
-
});
|
|
144
|
-
} else {
|
|
145
|
-
resource.content = "data:text/plain,";
|
|
146
|
-
}
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
}
|
|
150
148
|
return { docContent, origDocContent, resources, url };
|
|
149
|
+
|
|
150
|
+
async function getDataURI(textContent, mimeType) {
|
|
151
|
+
const reader = new FileReader();
|
|
152
|
+
reader.readAsDataURL(new Blob([textContent], { type: mimeType }));
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
reader.addEventListener("load", () => resolve(reader.result), false);
|
|
155
|
+
reader.addEventListener("error", reject, false);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
151
158
|
}
|