Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/17941

Vanessac583ad47b86e
diff --git a/app/src/asset/pdf/pdf_find_utils.js b/app/src/asset/pdf/pdf_find_utils.js
index 78b747706b..2830322850 100644
--- a/app/src/asset/pdf/pdf_find_utils.js
+++ b/app/src/asset/pdf/pdf_find_utils.js
@@ -13,6 +13,8 @@
* limitations under the License.
*/
+import { FeatureTest } from "./pdfjs";
+
const CharacterType = {
SPACE: 0,
ALPHA_LETTER: 1,
@@ -34,8 +36,8 @@ function isAscii(charCode) {
function isAsciiAlpha(charCode) {
return (
- (charCode >= /* a = */ 0x61 && charCode <= /* z = */ 0x7a) ||
- (charCode >= /* A = */ 0x41 && charCode <= /* Z = */ 0x5a)
+ (charCode >= /* a = */ 0x61 && charCode <= /* z = */ 0x7a) ||
+ (charCode >= /* A = */ 0x41 && charCode <= /* Z = */ 0x5a)
);
}
@@ -45,17 +47,17 @@ function isAsciiDigit(charCode) {
function isAsciiSpace(charCode) {
return (
- charCode === /* SPACE = */ 0x20 ||
- charCode === /* TAB = */ 0x09 ||
- charCode === /* CR = */ 0x0d ||
- charCode === /* LF = */ 0x0a
+ charCode === /* SPACE = */ 0x20 ||
+ charCode === /* TAB = */ 0x09 ||
+ charCode === /* CR = */ 0x0d ||
+ charCode === /* LF = */ 0x0a
);
}
function isHan(charCode) {
return (
- (charCode >= 0x3400 && charCode <= 0x9fff) ||
- (charCode >= 0xf900 && charCode <= 0xfaff)
+ (charCode >= 0x3400 && charCode <= 0x9fff) ||
+ (charCode >= 0xf900 && charCode <= 0xfaff)
);
}
@@ -85,9 +87,9 @@ function getCharacterType(charCode) {
if (isAsciiSpace(charCode)) {
return CharacterType.SPACE;
} else if (
- isAsciiAlpha(charCode) ||
- isAsciiDigit(charCode) ||
- charCode === /* UNDERSCORE = */ 0x5f
+ isAsciiAlpha(charCode) ||
+ isAsciiDigit(charCode) ||
+ charCode === /* UNDERSCORE = */ 0x5f
) {
return CharacterType.ALPHA_LETTER;
}
@@ -114,15 +116,33 @@ function getCharacterType(charCode) {
let NormalizeWithNFKC;
function getNormalizeWithNFKC() {
- /* eslint-disable no-irregular-whitespace */
- NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
+ if (
+ (typeof PDFJSDev === "undefined" && FeatureTest.platform.isFirefox) ||
+ (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL"))
+ ) {
+ // The `NormalizeWithNFKC` string is generated with the for loop below.
+ // Because of a small difference between Chrome and Firefox, the string is
+ // only hardcoded for Firefox, and Chrome (or others) will generate it at
+ // runtime.
+ // In order to detect if the string is up to date, a check is performed in
+ // the loop below, and if a difference is detected, an error is thrown.
+ /* eslint-disable no-irregular-whitespace */
+ NormalizeWithNFKC ||= `\xA0¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰ꟱-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
+ }
- if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
+ if (
+ typeof PDFJSDev === "undefined" ||
+ PDFJSDev.test("TESTING") ||
+ (!PDFJSDev.test("MOZCENTRAL") && !NormalizeWithNFKC)
+ ) {
const ranges = [];
const range = [];
const diacriticsRegex = /^\p{M}$/u;
// Some chars must be replaced by their NFKC counterpart during a search.
for (let i = 0; i < 65536; i++) {
+ if (i >= 0xd800 && i <= 0xdfff) {
+ continue; // Skip surrogates since they're not valid Unicode scalar values.
+ }
const c = String.fromCharCode(i);
if (c.normalize("NFKC") !== c && !diacriticsRegex.test(c)) {
if (range.length !== 2) {
@@ -134,9 +154,9 @@ function getNormalizeWithNFKC() {
ranges.push(String.fromCharCode(range[0]));
} else {
ranges.push(
- `${String.fromCharCode(range[0])}-${String.fromCharCode(
- range[1]
- )}`
+ `${String.fromCharCode(range[0])}-${String.fromCharCode(
+ range[1]
+ )}`
);
}
range[0] = range[1] = i;
@@ -145,9 +165,26 @@ function getNormalizeWithNFKC() {
}
}
}
- if (ranges.join("") !== NormalizeWithNFKC) {
+
+ const rangesStr = ranges.join("");
+ if (!NormalizeWithNFKC) {
+ NormalizeWithNFKC = rangesStr;
+ } else if (rangesStr !== NormalizeWithNFKC) {
+ for (let i = 1; i < rangesStr.length; i++) {
+ if (rangesStr[i] !== NormalizeWithNFKC[i]) {
+ console.log(
+ `Difference at index ${i}: ` +
+ `U+${rangesStr.charCodeAt(i).toString(16).toUpperCase().padStart(4, "0")}` +
+ `!== U+${NormalizeWithNFKC.charCodeAt(i)
+ .toString(16)
+ .toUpperCase()
+ .padStart(4, "0")}`
+ );
+ break;
+ }
+ }
throw new Error(
- "getNormalizeWithNFKC - update the `NormalizeWithNFKC` string."
+ "getNormalizeWithNFKC - update the `NormalizeWithNFKC` string."
);
}
}
diff --git a/app/src/asset/pdf/viewer.js b/app/src/asset/pdf/viewer.js
index 7a6bcd3d88..17b47e6e86 100644
--- a/app/src/asset/pdf/viewer.js
+++ b/app/src/asset/pdf/viewer.js
@@ -234,6 +234,8 @@ function getViewerConfiguration(element) {
// NOTE
function webViewerLoad(file, element, pdfPage, annoId) {
+ // SiYuan 通过 AppOptions.set 显式配置 viewer,禁用从 localStorage 读取的 Preferences,
+ AppOptions.set("disablePreferences", true);
AppOptions.set("workerSrc", `${Constants.PROTYLE_CDN}/js/pdf/pdf.worker.min.mjs?v=4.7.85`);
AppOptions.set("defaultUrl", file);
AppOptions.set("cMapUrl", 'cmaps/');