@d-i-t-a/reader 2.1.2 → 2.1.4

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/esm/index.js CHANGED
@@ -41973,6 +41973,39 @@ var ContentProtectionModule = class {
41973
41973
  }
41974
41974
  removeEventListenerOptional(window, "cut", this.preventCopy);
41975
41975
  removeEventListenerOptional(document, "cut", this.preventCopy);
41976
+ removeEventListenerOptional(this.delegate.mainElement, "keydown", this.preventCopyKey);
41977
+ removeEventListenerOptional(this.delegate.headerMenu, "keydown", this.preventCopyKey);
41978
+ for (const iframe of this.delegate.iframes) {
41979
+ removeEventListenerOptional(iframe.contentDocument, "keydown", this.preventCopyKey);
41980
+ removeEventListenerOptional(iframe.contentWindow, "keydown", this.preventCopyKey);
41981
+ }
41982
+ removeEventListenerOptional(window, "keydown", this.preventCopyKey);
41983
+ removeEventListenerOptional(document, "keydown", this.preventCopyKey);
41984
+ } else if (this.properties?.canCopy) {
41985
+ removeEventListenerOptional(this.delegate.mainElement, "copy", this.restrictCopy);
41986
+ removeEventListenerOptional(this.delegate.headerMenu, "copy", this.restrictCopy);
41987
+ for (const iframe of this.delegate.iframes) {
41988
+ removeEventListenerOptional(iframe.contentDocument, "copy", this.restrictCopy);
41989
+ removeEventListenerOptional(iframe.contentWindow, "copy", this.restrictCopy);
41990
+ }
41991
+ removeEventListenerOptional(window, "copy", this.restrictCopy);
41992
+ removeEventListenerOptional(document, "copy", this.restrictCopy);
41993
+ removeEventListenerOptional(this.delegate.mainElement, "cut", this.restrictCopy);
41994
+ removeEventListenerOptional(this.delegate.headerMenu, "cut", this.restrictCopy);
41995
+ for (const iframe of this.delegate.iframes) {
41996
+ removeEventListenerOptional(iframe.contentDocument, "cut", this.restrictCopy);
41997
+ removeEventListenerOptional(iframe.contentWindow, "cut", this.restrictCopy);
41998
+ }
41999
+ removeEventListenerOptional(window, "cut", this.restrictCopy);
42000
+ removeEventListenerOptional(document, "cut", this.restrictCopy);
42001
+ removeEventListenerOptional(this.delegate.mainElement, "keydown", this.restrictCopyKey);
42002
+ removeEventListenerOptional(this.delegate.headerMenu, "keydown", this.restrictCopyKey);
42003
+ for (const iframe of this.delegate.iframes) {
42004
+ removeEventListenerOptional(iframe.contentDocument, "keydown", this.restrictCopyKey);
42005
+ removeEventListenerOptional(iframe.contentWindow, "keydown", this.restrictCopyKey);
42006
+ }
42007
+ removeEventListenerOptional(window, "keydown", this.restrictCopyKey);
42008
+ removeEventListenerOptional(document, "keydown", this.restrictCopyKey);
41976
42009
  }
41977
42010
  if (this.properties?.disablePrint) {
41978
42011
  removeEventListenerOptional(this.delegate.mainElement, "beforeprint", this.beforePrint.bind(this));
@@ -42075,6 +42108,51 @@ var ContentProtectionModule = class {
42075
42108
  }
42076
42109
  addEventListenerOptional(window, "cut", this.preventCopy);
42077
42110
  addEventListenerOptional(document, "cut", this.preventCopy);
42111
+ addEventListenerOptional(this.delegate.mainElement, "keydown", this.preventCopyKey);
42112
+ addEventListenerOptional(this.delegate.headerMenu, "keydown", this.preventCopyKey);
42113
+ for (const iframe of this.delegate.iframes) {
42114
+ addEventListenerOptional(iframe, "keydown", this.preventCopyKey);
42115
+ addEventListenerOptional(iframe.ownerDocument, "keydown", this.preventCopyKey);
42116
+ addEventListenerOptional(iframe.contentDocument, "keydown", this.preventCopyKey);
42117
+ addEventListenerOptional(iframe.contentWindow, "keydown", this.preventCopyKey);
42118
+ addEventListenerOptional(iframe.contentWindow?.document, "keydown", this.preventCopyKey);
42119
+ }
42120
+ addEventListenerOptional(window, "keydown", this.preventCopyKey);
42121
+ addEventListenerOptional(document, "keydown", this.preventCopyKey);
42122
+ } else if (this.properties?.canCopy) {
42123
+ addEventListenerOptional(this.delegate.mainElement, "copy", this.restrictCopy.bind(this));
42124
+ addEventListenerOptional(this.delegate.headerMenu, "copy", this.restrictCopy.bind(this));
42125
+ for (const iframe of this.delegate.iframes) {
42126
+ addEventListenerOptional(iframe, "copy", this.restrictCopy);
42127
+ addEventListenerOptional(iframe.ownerDocument, "copy", this.restrictCopy.bind(this));
42128
+ addEventListenerOptional(iframe.contentDocument, "copy", this.restrictCopy.bind(this));
42129
+ addEventListenerOptional(iframe.contentWindow, "copy", this.restrictCopy.bind(this));
42130
+ addEventListenerOptional(iframe.contentWindow?.document, "copy", this.restrictCopy.bind(this));
42131
+ }
42132
+ addEventListenerOptional(window, "copy", this.restrictCopy.bind(this));
42133
+ addEventListenerOptional(document, "copy", this.restrictCopy.bind(this));
42134
+ addEventListenerOptional(this.delegate.mainElement, "cut", this.restrictCopy.bind(this));
42135
+ addEventListenerOptional(this.delegate.headerMenu, "cut", this.restrictCopy.bind(this));
42136
+ for (const iframe of this.delegate.iframes) {
42137
+ addEventListenerOptional(iframe, "cut", this.restrictCopy.bind(this));
42138
+ addEventListenerOptional(iframe.ownerDocument, "cut", this.restrictCopy.bind(this));
42139
+ addEventListenerOptional(iframe.contentDocument, "cut", this.restrictCopy.bind(this));
42140
+ addEventListenerOptional(iframe.contentWindow, "cut", this.restrictCopy.bind(this));
42141
+ addEventListenerOptional(iframe.contentWindow?.document, "cut", this.restrictCopy.bind(this));
42142
+ }
42143
+ addEventListenerOptional(window, "cut", this.restrictCopy.bind(this));
42144
+ addEventListenerOptional(document, "cut", this.restrictCopy.bind(this));
42145
+ addEventListenerOptional(this.delegate.mainElement, "keydown", this.restrictCopyKey.bind(this));
42146
+ addEventListenerOptional(this.delegate.headerMenu, "keydown", this.restrictCopyKey.bind(this));
42147
+ for (const iframe of this.delegate.iframes) {
42148
+ addEventListenerOptional(iframe, "keydown", this.restrictCopyKey.bind(this));
42149
+ addEventListenerOptional(iframe.ownerDocument, "keydown", this.restrictCopyKey.bind(this));
42150
+ addEventListenerOptional(iframe.contentDocument, "keydown", this.restrictCopyKey.bind(this));
42151
+ addEventListenerOptional(iframe.contentWindow, "keydown", this.restrictCopyKey.bind(this));
42152
+ addEventListenerOptional(iframe.contentWindow?.document, "keydown", this.restrictCopyKey.bind(this));
42153
+ }
42154
+ addEventListenerOptional(window, "keydown", this.restrictCopyKey.bind(this));
42155
+ addEventListenerOptional(document, "keydown", this.restrictCopyKey.bind(this));
42078
42156
  }
42079
42157
  if (this.properties?.disablePrint) {
42080
42158
  addEventListenerOptional(this.delegate.mainElement, "beforeprint", this.beforePrint);
@@ -42182,6 +42260,118 @@ var ContentProtectionModule = class {
42182
42260
  event.preventDefault();
42183
42261
  return false;
42184
42262
  }
42263
+ preventCopyKey(event) {
42264
+ if (navigator.platform === "MacIntel" || navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey && (event.key === "c" || event.keyCode === 67)) {
42265
+ event.preventDefault();
42266
+ event.stopPropagation();
42267
+ return false;
42268
+ }
42269
+ return true;
42270
+ }
42271
+ restrictCopy(event) {
42272
+ import_loglevel13.default.log("copy action initiated");
42273
+ let win = this.delegate.iframes[0].contentWindow;
42274
+ if (win) {
42275
+ let getCssSelector = function(element) {
42276
+ const options = {
42277
+ className: (str) => {
42278
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
42279
+ },
42280
+ idName: (str) => {
42281
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
42282
+ }
42283
+ };
42284
+ let doc = self2.delegate.iframes[0].contentDocument;
42285
+ if (doc) {
42286
+ return uniqueCssSelector(element, doc, options);
42287
+ } else {
42288
+ return void 0;
42289
+ }
42290
+ };
42291
+ let self2 = this;
42292
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
42293
+ if (selectionInfo === void 0) {
42294
+ let doc = this.delegate.iframes[0].contentDocument;
42295
+ selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc);
42296
+ }
42297
+ event.clipboardData.setData("text/plain", selectionInfo?.cleanText?.substring(0, this.properties?.charactersToCopy ?? 0));
42298
+ } else {
42299
+ event.clipboardData.setData("text/plain", "");
42300
+ }
42301
+ event.stopPropagation();
42302
+ event.preventDefault();
42303
+ return false;
42304
+ }
42305
+ restrictCopyKey(event) {
42306
+ if (navigator.platform === "MacIntel" || navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey && (event.key === "c" || event.keyCode === 67)) {
42307
+ let win = this.delegate.iframes[0].contentWindow;
42308
+ if (win) {
42309
+ let getCssSelector = function(element) {
42310
+ const options = {
42311
+ className: (str) => {
42312
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
42313
+ },
42314
+ idName: (str) => {
42315
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
42316
+ }
42317
+ };
42318
+ let doc = self2.delegate.iframes[0].contentDocument;
42319
+ if (doc) {
42320
+ return uniqueCssSelector(element, doc, options);
42321
+ } else {
42322
+ return void 0;
42323
+ }
42324
+ };
42325
+ let self2 = this;
42326
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
42327
+ if (selectionInfo === void 0) {
42328
+ let doc = this.delegate.iframes[0].contentDocument;
42329
+ selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc);
42330
+ }
42331
+ this.copyToClipboard(selectionInfo?.cleanText?.substring(0, this.properties?.charactersToCopy ?? 0));
42332
+ } else {
42333
+ this.copyToClipboard("");
42334
+ }
42335
+ event.stopPropagation();
42336
+ event.preventDefault();
42337
+ return false;
42338
+ }
42339
+ return true;
42340
+ }
42341
+ copyToClipboard(textToClipboard) {
42342
+ textToClipboard = textToClipboard.substring(0, this.properties?.charactersToCopy ?? 0);
42343
+ if (window.clipboardData) {
42344
+ window.clipboardData.setData("text/plain", textToClipboard);
42345
+ } else {
42346
+ const forExecElement = this.createElementForExecCommand(textToClipboard);
42347
+ this.selectContent(forExecElement);
42348
+ try {
42349
+ if (window.netscape && netscape.security) {
42350
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
42351
+ }
42352
+ document.execCommand("copy", false);
42353
+ } catch (e) {
42354
+ }
42355
+ document.body.removeChild(forExecElement);
42356
+ }
42357
+ }
42358
+ createElementForExecCommand(textToClipboard) {
42359
+ const forExecElement = document.createElement("div");
42360
+ forExecElement.style.position = "absolute";
42361
+ forExecElement.style.left = "-10000px";
42362
+ forExecElement.style.top = "-10000px";
42363
+ forExecElement.innerHTML = textToClipboard;
42364
+ document.body.appendChild(forExecElement);
42365
+ forExecElement.contentEditable = true;
42366
+ return forExecElement;
42367
+ }
42368
+ selectContent(element) {
42369
+ const rangeToSelect = document.createRange();
42370
+ rangeToSelect.selectNodeContents(element);
42371
+ const selection = window.getSelection();
42372
+ selection?.removeAllRanges();
42373
+ selection?.addRange(rangeToSelect);
42374
+ }
42185
42375
  beforePrint(event) {
42186
42376
  import_loglevel13.default.log("before print");
42187
42377
  if (this.delegate && this.delegate.headerMenu) {
@@ -45036,6 +45226,11 @@ var IFrameNavigator = class extends import_eventemitter3.default {
45036
45226
  this.goTo(locator);
45037
45227
  }
45038
45228
  }
45229
+ async goToPage(page) {
45230
+ if (this.pageBreakModule !== void 0) {
45231
+ await this.pageBreakModule.goToPageNumber(page);
45232
+ }
45233
+ }
45039
45234
  snapToSelector(selector2) {
45040
45235
  const doc = this.iframes[0].contentDocument;
45041
45236
  if (doc) {
@@ -48463,6 +48658,12 @@ var D2Reader = class {
48463
48658
  this.goToPosition = async (value) => {
48464
48659
  return this.navigator.goToPosition(value);
48465
48660
  };
48661
+ this.goToPage = async (page) => {
48662
+ await this.navigator.goToPage(page);
48663
+ };
48664
+ this.copyToClipboard = (text) => {
48665
+ this.contentProtectionModule?.copyToClipboard(text);
48666
+ };
48466
48667
  this.nextResource = () => {
48467
48668
  this.navigator.nextResource();
48468
48669
  };