@design.estate/dees-catalog 3.41.2 → 3.41.3

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.
@@ -136810,6 +136810,7 @@ var viewerStyles = [
136810
136810
  border-radius: 4px;
136811
136811
  overflow: hidden;
136812
136812
  display: inline-block;
136813
+ position: relative;
136813
136814
  }
136814
136815
 
136815
136816
  .page-canvas {
@@ -136818,6 +136819,52 @@ var viewerStyles = [
136818
136819
  image-rendering: crisp-edges;
136819
136820
  }
136820
136821
 
136822
+ /* Text layer for selection */
136823
+ .text-layer {
136824
+ position: absolute;
136825
+ inset: 0;
136826
+ overflow: visible;
136827
+ line-height: 1;
136828
+ text-size-adjust: none;
136829
+ forced-color-adjust: none;
136830
+ transform-origin: 0 0;
136831
+ z-index: 1;
136832
+ user-select: text;
136833
+ -webkit-user-select: text;
136834
+ }
136835
+
136836
+ .text-layer span,
136837
+ .text-layer br {
136838
+ color: transparent;
136839
+ position: absolute;
136840
+ white-space: pre;
136841
+ cursor: text;
136842
+ transform-origin: 0% 0%;
136843
+ user-select: text;
136844
+ -webkit-user-select: text;
136845
+ }
136846
+
136847
+ .text-layer ::selection {
136848
+ background: rgba(0, 100, 200, 0.3);
136849
+ }
136850
+
136851
+ .text-layer br::selection {
136852
+ background: transparent;
136853
+ }
136854
+
136855
+ .text-layer .endOfContent {
136856
+ display: block;
136857
+ position: absolute;
136858
+ inset: 100% 0 0;
136859
+ z-index: 0;
136860
+ cursor: default;
136861
+ user-select: none;
136862
+ }
136863
+
136864
+ .text-layer.selecting .endOfContent {
136865
+ top: 0;
136866
+ }
136867
+
136821
136868
  .pdf-viewer.with-sidebar .viewer-main {
136822
136869
  margin-left: 0;
136823
136870
  }
@@ -136923,6 +136970,7 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
136923
136970
  __publicField(this, "currentRenderPromise", null);
136924
136971
  __publicField(this, "thumbnailRenderTasks", []);
136925
136972
  __publicField(this, "pageRenderTasks", /* @__PURE__ */ new Map());
136973
+ __publicField(this, "textLayerRenderTasks", /* @__PURE__ */ new Map());
136926
136974
  __publicField(this, "canvas");
136927
136975
  __publicField(this, "ctx");
136928
136976
  __publicField(this, "viewerMain", null);
@@ -137095,6 +137143,7 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
137095
137143
  <div class="page-wrapper" data-page="${item.page}">
137096
137144
  <div class="canvas-container">
137097
137145
  <canvas class="page-canvas" data-page="${item.page}"></canvas>
137146
+ <div class="text-layer" data-page="${item.page}"></div>
137098
137147
  </div>
137099
137148
  </div>
137100
137149
  `
@@ -137167,7 +137216,8 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
137167
137216
  this.pageData = Array.from({ length: this.totalPages }, (_4, i11) => ({
137168
137217
  page: i11 + 1,
137169
137218
  rendered: false,
137170
- rendering: false
137219
+ rendering: false,
137220
+ textLayerRendered: false
137171
137221
  }));
137172
137222
  this.loading = false;
137173
137223
  await this.updateComplete;
@@ -137273,6 +137323,7 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
137273
137323
  pageInfo.rendered = true;
137274
137324
  pageInfo.rendering = false;
137275
137325
  this.pageRenderTasks.delete(pageNum);
137326
+ await this.renderTextLayer(pageNum);
137276
137327
  this.requestUpdate("pageData");
137277
137328
  } catch (error) {
137278
137329
  if (error?.name !== "RenderingCancelledException") {
@@ -137282,6 +137333,100 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
137282
137333
  this.pageRenderTasks.delete(pageNum);
137283
137334
  }
137284
137335
  }
137336
+ async renderTextLayer(pageNum) {
137337
+ const pageInfo = this.pageData.find((p7) => p7.page === pageNum);
137338
+ if (!pageInfo || pageInfo.textLayerRendered) return;
137339
+ try {
137340
+ const textLayerDiv = this.shadowRoot?.querySelector(
137341
+ `.text-layer[data-page="${pageNum}"]`
137342
+ );
137343
+ if (!textLayerDiv) return;
137344
+ textLayerDiv.innerHTML = "";
137345
+ const page = await this.pdfDocument.getPage(pageNum);
137346
+ const textContent = await page.getTextContent();
137347
+ const viewport = this.computeViewport(page);
137348
+ const pdfjs = await import("https://cdn.jsdelivr.net/npm/pdfjs-dist@4.0.379/+esm");
137349
+ textLayerDiv.style.width = `${viewport.width}px`;
137350
+ textLayerDiv.style.height = `${viewport.height}px`;
137351
+ textLayerDiv.style.setProperty("--scale-factor", String(viewport.scale));
137352
+ const textLayerRenderTask = pdfjs.renderTextLayer({
137353
+ textContentSource: textContent,
137354
+ container: textLayerDiv,
137355
+ viewport
137356
+ });
137357
+ this.textLayerRenderTasks.set(pageNum, textLayerRenderTask);
137358
+ await textLayerRenderTask.promise;
137359
+ const endOfContent = document.createElement("div");
137360
+ endOfContent.className = "endOfContent";
137361
+ textLayerDiv.appendChild(endOfContent);
137362
+ let isDragging = false;
137363
+ let anchorNode = null;
137364
+ let anchorOffset = 0;
137365
+ const getTextPositionFromPoint = (x3, y5) => {
137366
+ const spans = Array.from(textLayerDiv.querySelectorAll("span"));
137367
+ for (const span of spans) {
137368
+ const rect = span.getBoundingClientRect();
137369
+ if (x3 >= rect.left && x3 <= rect.right && y5 >= rect.top && y5 <= rect.bottom) {
137370
+ const textNode = span.firstChild;
137371
+ if (textNode && textNode.nodeType === Node.TEXT_NODE) {
137372
+ const text9 = textNode.textContent || "";
137373
+ const charWidth = rect.width / text9.length;
137374
+ const relativeX = x3 - rect.left;
137375
+ const offset = Math.min(Math.round(relativeX / charWidth), text9.length);
137376
+ return { node: textNode, offset };
137377
+ }
137378
+ }
137379
+ }
137380
+ return null;
137381
+ };
137382
+ const handleMouseUp = () => {
137383
+ if (isDragging) {
137384
+ isDragging = false;
137385
+ anchorNode = null;
137386
+ textLayerDiv.classList.remove("selecting");
137387
+ }
137388
+ document.removeEventListener("mouseup", handleMouseUp);
137389
+ document.removeEventListener("mousemove", handleMouseMove);
137390
+ };
137391
+ const handleMouseMove = (e11) => {
137392
+ if (!isDragging || !anchorNode) return;
137393
+ e11.preventDefault();
137394
+ const pos = getTextPositionFromPoint(e11.clientX, e11.clientY);
137395
+ if (pos) {
137396
+ const selection = window.getSelection();
137397
+ if (selection) {
137398
+ try {
137399
+ selection.setBaseAndExtent(anchorNode, anchorOffset, pos.node, pos.offset);
137400
+ } catch (err) {
137401
+ }
137402
+ }
137403
+ }
137404
+ };
137405
+ textLayerDiv.addEventListener("mousedown", (e11) => {
137406
+ if (e11.button !== 0) return;
137407
+ const pos = getTextPositionFromPoint(e11.clientX, e11.clientY);
137408
+ if (pos) {
137409
+ e11.preventDefault();
137410
+ isDragging = true;
137411
+ anchorNode = pos.node;
137412
+ anchorOffset = pos.offset;
137413
+ textLayerDiv.classList.add("selecting");
137414
+ const selection = window.getSelection();
137415
+ selection?.removeAllRanges();
137416
+ document.addEventListener("mousemove", handleMouseMove);
137417
+ document.addEventListener("mouseup", handleMouseUp);
137418
+ }
137419
+ });
137420
+ pageInfo.textLayerRendered = true;
137421
+ page.cleanup?.();
137422
+ this.textLayerRenderTasks.delete(pageNum);
137423
+ } catch (error) {
137424
+ if (error?.name !== "RenderingCancelledException") {
137425
+ console.error(`Error rendering text layer for page ${pageNum}:`, error);
137426
+ }
137427
+ this.textLayerRenderTasks.delete(pageNum);
137428
+ }
137429
+ }
137285
137430
  updateCurrentPage() {
137286
137431
  if (!this.viewerMain) return;
137287
137432
  const scrollTop = this.viewerMain.scrollTop;
@@ -137478,6 +137623,7 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
137478
137623
  this.pageData.forEach((page) => {
137479
137624
  page.rendered = false;
137480
137625
  page.rendering = false;
137626
+ page.textLayerRendered = false;
137481
137627
  });
137482
137628
  this.pageRenderTasks.forEach((task) => {
137483
137629
  try {
@@ -137486,55 +137632,130 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
137486
137632
  }
137487
137633
  });
137488
137634
  this.pageRenderTasks.clear();
137635
+ this.textLayerRenderTasks.forEach((task) => {
137636
+ try {
137637
+ task.cancel?.();
137638
+ } catch (error) {
137639
+ }
137640
+ });
137641
+ this.textLayerRenderTasks.clear();
137489
137642
  this.requestUpdate();
137490
137643
  this.updateComplete.then(() => {
137491
137644
  this.renderVisiblePages();
137492
137645
  });
137493
137646
  }
137494
- downloadPdf() {
137495
- const link3 = document.createElement("a");
137496
- link3.href = this.pdfUrl;
137497
- link3.download = this.pdfUrl.split("/").pop() || "document.pdf";
137498
- link3.click();
137647
+ async downloadPdf() {
137648
+ if (!this.pdfDocument) return;
137649
+ try {
137650
+ const data = await this.pdfDocument.getData();
137651
+ const blob = new Blob([data.buffer], { type: "application/pdf" });
137652
+ const blobUrl = URL.createObjectURL(blob);
137653
+ const link3 = document.createElement("a");
137654
+ link3.href = blobUrl;
137655
+ link3.download = this.pdfUrl ? this.pdfUrl.split("/").pop() || "document.pdf" : "document.pdf";
137656
+ link3.click();
137657
+ setTimeout(() => URL.revokeObjectURL(blobUrl), 1e3);
137658
+ } catch (error) {
137659
+ console.error("Error downloading PDF:", error);
137660
+ }
137499
137661
  }
137500
- printPdf() {
137501
- window.open(this.pdfUrl, "_blank")?.print();
137662
+ async printPdf() {
137663
+ if (!this.pdfDocument) return;
137664
+ try {
137665
+ const data = await this.pdfDocument.getData();
137666
+ const blob = new Blob([data.buffer], { type: "application/pdf" });
137667
+ const pdfUrl = URL.createObjectURL(blob);
137668
+ const htmlContent = `
137669
+ <!DOCTYPE html>
137670
+ <html>
137671
+ <head>
137672
+ <title>Print PDF</title>
137673
+ <style>
137674
+ * { margin: 0; padding: 0; }
137675
+ html, body { width: 100%; height: 100%; overflow: hidden; }
137676
+ iframe { width: 100%; height: 100%; border: none; }
137677
+ @media print {
137678
+ html, body, iframe { width: 100%; height: 100%; }
137679
+ }
137680
+ </style>
137681
+ </head>
137682
+ <body>
137683
+ <iframe src="${pdfUrl}" type="application/pdf"></iframe>
137684
+ <script>
137685
+ window.onload = function() {
137686
+ setTimeout(function() {
137687
+ window.focus();
137688
+ window.print();
137689
+ }, 500);
137690
+ };
137691
+ window.onafterprint = function() {
137692
+ window.close();
137693
+ };
137694
+ // Safety close after 2 minutes
137695
+ setTimeout(function() { window.close(); }, 120000);
137696
+ <\/script>
137697
+ </body>
137698
+ </html>
137699
+ `;
137700
+ const htmlBlob = new Blob([htmlContent], { type: "text/html" });
137701
+ const htmlUrl = URL.createObjectURL(htmlBlob);
137702
+ const printWindow = window.open(htmlUrl, "_blank", "width=800,height=600");
137703
+ if (printWindow) {
137704
+ const checkClosed = setInterval(() => {
137705
+ if (printWindow.closed) {
137706
+ clearInterval(checkClosed);
137707
+ URL.revokeObjectURL(pdfUrl);
137708
+ URL.revokeObjectURL(htmlUrl);
137709
+ }
137710
+ }, 500);
137711
+ setTimeout(() => {
137712
+ clearInterval(checkClosed);
137713
+ URL.revokeObjectURL(pdfUrl);
137714
+ URL.revokeObjectURL(htmlUrl);
137715
+ }, 12e4);
137716
+ } else {
137717
+ window.open(pdfUrl, "_blank");
137718
+ setTimeout(() => URL.revokeObjectURL(pdfUrl), 6e4);
137719
+ URL.revokeObjectURL(htmlUrl);
137720
+ }
137721
+ } catch (error) {
137722
+ console.error("Error printing PDF:", error);
137723
+ }
137502
137724
  }
137503
137725
  /**
137504
137726
  * Provide context menu items for right-click functionality
137505
137727
  */
137506
137728
  getContextMenuItems() {
137507
- return [
137508
- {
137509
- name: "Open PDF in New Tab",
137510
- iconName: "lucide:ExternalLink",
137511
- action: async () => {
137512
- window.open(this.pdfUrl, "_blank");
137513
- }
137514
- },
137515
- { divider: true },
137516
- {
137517
- name: "Copy PDF URL",
137729
+ const items = [];
137730
+ const selection = window.getSelection();
137731
+ const selectedText = selection?.toString() || "";
137732
+ if (selectedText) {
137733
+ items.push({
137734
+ name: "Copy",
137518
137735
  iconName: "lucide:Copy",
137519
137736
  action: async () => {
137520
- await navigator.clipboard.writeText(this.pdfUrl);
137737
+ await navigator.clipboard.writeText(selectedText);
137521
137738
  }
137522
- },
137739
+ });
137740
+ items.push({ divider: true });
137741
+ }
137742
+ items.push(
137523
137743
  {
137524
137744
  name: "Download PDF",
137525
137745
  iconName: "lucide:Download",
137526
137746
  action: async () => {
137527
- this.downloadPdf();
137747
+ await this.downloadPdf();
137528
137748
  }
137529
137749
  },
137530
137750
  {
137531
137751
  name: "Print PDF",
137532
137752
  iconName: "lucide:Printer",
137533
137753
  action: async () => {
137534
- this.printPdf();
137754
+ await this.printPdf();
137535
137755
  }
137536
137756
  }
137537
- ];
137757
+ );
137758
+ return items;
137538
137759
  }
137539
137760
  get canZoomIn() {
137540
137761
  return this.viewportMode !== "custom" || this.currentZoom < this.MANUAL_MAX_ZOOM;
@@ -137658,6 +137879,13 @@ var DeesPdfViewer = class extends (_a73 = DeesElement, _pdfUrl_dec = [n5({ type:
137658
137879
  }
137659
137880
  });
137660
137881
  this.pageRenderTasks.clear();
137882
+ this.textLayerRenderTasks.forEach((task) => {
137883
+ try {
137884
+ task.cancel?.();
137885
+ } catch (error) {
137886
+ }
137887
+ });
137888
+ this.textLayerRenderTasks.clear();
137661
137889
  for (const task of this.thumbnailRenderTasks || []) {
137662
137890
  try {
137663
137891
  task.cancel();
@@ -147636,7 +147864,7 @@ init_group_runtime();
147636
147864
  // ts_web/00_commitinfo_data.ts
147637
147865
  var commitinfo = {
147638
147866
  name: "@design.estate/dees-catalog",
147639
- version: "3.41.2",
147867
+ version: "3.41.3",
147640
147868
  description: "A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript."
147641
147869
  };
147642
147870
  export {
@@ -147881,4 +148109,4 @@ ibantools/jsnext/ibantools.js:
147881
148109
  * @preferred
147882
148110
  *)
147883
148111
  */
147884
- //# sourceMappingURL=bundle-1769617037472.js.map
148112
+ //# sourceMappingURL=bundle-1769672791046.js.map
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@design.estate/dees-catalog',
6
- version: '3.41.2',
6
+ version: '3.41.3',
7
7
  description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHNfd2ViLzAwX2NvbW1pdGluZm9fZGF0YS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLFVBQVUsR0FBRztJQUN4QixJQUFJLEVBQUUsNkJBQTZCO0lBQ25DLE9BQU8sRUFBRSxRQUFRO0lBQ2pCLFdBQVcsRUFBRSxzSkFBc0o7Q0FDcEssQ0FBQSJ9
@@ -27,6 +27,7 @@ export declare class DeesPdfViewer extends DeesElement {
27
27
  page: number;
28
28
  rendered: boolean;
29
29
  rendering: boolean;
30
+ textLayerRendered: boolean;
30
31
  }>;
31
32
  private pdfDocument;
32
33
  private renderState;
@@ -37,6 +38,7 @@ export declare class DeesPdfViewer extends DeesElement {
37
38
  private currentRenderPromise;
38
39
  private thumbnailRenderTasks;
39
40
  private pageRenderTasks;
41
+ private textLayerRenderTasks;
40
42
  private canvas;
41
43
  private ctx;
42
44
  private viewerMain;
@@ -60,6 +62,7 @@ export declare class DeesPdfViewer extends DeesElement {
60
62
  private setupIntersectionObserver;
61
63
  private renderVisiblePages;
62
64
  private renderPageIfNeeded;
65
+ private renderTextLayer;
63
66
  private handleScroll;
64
67
  private updateCurrentPage;
65
68
  private scrollThumbnailIntoView;
@@ -80,17 +83,7 @@ export declare class DeesPdfViewer extends DeesElement {
80
83
  /**
81
84
  * Provide context menu items for right-click functionality
82
85
  */
83
- getContextMenuItems(): ({
84
- name: string;
85
- iconName: string;
86
- action: () => Promise<void>;
87
- divider?: undefined;
88
- } | {
89
- divider: boolean;
90
- name?: undefined;
91
- iconName?: undefined;
92
- action?: undefined;
93
- })[];
86
+ getContextMenuItems(): any[];
94
87
  private get canZoomIn();
95
88
  private get canZoomOut();
96
89
  private ensureViewerRefs;