carriera-intern 1.1.119 → 1.1.120

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.
@@ -4646,7 +4646,8 @@ class DocumentService {
4646
4646
  workerPool = [];
4647
4647
  workerPoolSize = Math.max(1, Math.min((navigator.hardwareConcurrency || 2) - 1, 3));
4648
4648
  workerCursor = 0;
4649
- isWorkerSrcConfigured = false;
4649
+ workerSrcReady = null;
4650
+ workerSrcBlobUrl = null;
4650
4651
  constructor() {
4651
4652
  this.destroyRef.onDestroy(() => this.destroyWorkers());
4652
4653
  }
@@ -4700,6 +4701,7 @@ class DocumentService {
4700
4701
  */
4701
4702
  async analyzePdf(file) {
4702
4703
  const data = new Uint8Array(await file.arrayBuffer());
4704
+ await this.ensureWorkerSrc();
4703
4705
  const loadingTask = pdfjsLib.getDocument({
4704
4706
  data,
4705
4707
  worker: this.getWorker(),
@@ -4719,10 +4721,6 @@ class DocumentService {
4719
4721
  }
4720
4722
  }
4721
4723
  getWorker() {
4722
- if (!this.isWorkerSrcConfigured) {
4723
- pdfjsLib.GlobalWorkerOptions.workerSrc = `${this.assetBase}pdf.worker.min.mjs`;
4724
- this.isWorkerSrcConfigured = true;
4725
- }
4726
4724
  const index = this.workerCursor++ % this.workerPoolSize;
4727
4725
  if (!this.workerPool[index] || this.workerPool[index].destroyed) {
4728
4726
  this.workerPool[index] = pdfjsLib.PDFWorker.create({
@@ -4731,6 +4729,31 @@ class DocumentService {
4731
4729
  }
4732
4730
  return this.workerPool[index];
4733
4731
  }
4732
+ ensureWorkerSrc() {
4733
+ this.workerSrcReady ??= this.configureWorkerSrc();
4734
+ return this.workerSrcReady;
4735
+ }
4736
+ async configureWorkerSrc() {
4737
+ const remoteWorkerUrl = `${this.assetBase}pdf.worker.min.mjs`;
4738
+ try {
4739
+ pdfjsLib.GlobalWorkerOptions.workerSrc =
4740
+ await this.workerSrcAsJavascriptModule(remoteWorkerUrl);
4741
+ }
4742
+ catch {
4743
+ pdfjsLib.GlobalWorkerOptions.workerSrc = remoteWorkerUrl;
4744
+ }
4745
+ }
4746
+ async workerSrcAsJavascriptModule(url) {
4747
+ const response = await fetch(url);
4748
+ if (!response.ok) {
4749
+ throw new Error(`Failed to load PDF worker (${response.status})`);
4750
+ }
4751
+ const javascriptBlob = new Blob([await response.blob()], {
4752
+ type: 'application/javascript',
4753
+ });
4754
+ this.workerSrcBlobUrl = URL.createObjectURL(javascriptBlob);
4755
+ return this.workerSrcBlobUrl;
4756
+ }
4734
4757
  destroyWorkers() {
4735
4758
  for (const worker of this.workerPool) {
4736
4759
  if (!worker.destroyed) {
@@ -4738,6 +4761,11 @@ class DocumentService {
4738
4761
  }
4739
4762
  }
4740
4763
  this.workerPool.length = 0;
4764
+ if (this.workerSrcBlobUrl) {
4765
+ URL.revokeObjectURL(this.workerSrcBlobUrl);
4766
+ this.workerSrcBlobUrl = null;
4767
+ }
4768
+ this.workerSrcReady = null;
4741
4769
  }
4742
4770
  async cleanupQuietly(teardown) {
4743
4771
  try {
@@ -4959,6 +4987,28 @@ class DropZoneDocumentsHelper {
4959
4987
  reader.readAsDataURL(file);
4960
4988
  });
4961
4989
  }
4990
+ static mapFileResponseToAppFile(fileResponse, extras) {
4991
+ const fileName = fileResponse.fileName ?? '';
4992
+ const fileExtension = fileName.split('.').pop()?.toLowerCase() || '';
4993
+ const serverFileId = fileResponse.fileId;
4994
+ return {
4995
+ fileName,
4996
+ baseName: fileName.split('.').slice(0, -1).join('.') || '',
4997
+ fileId: serverFileId,
4998
+ uid: serverFileId != null ? String(serverFileId) : crypto.randomUUID(),
4999
+ type: fileExtension,
5000
+ size: fileResponse.fileSize || 0,
5001
+ url: fileResponse.url || '',
5002
+ imagePreviewUrl: fileResponse.thumbnailUrl ?? '',
5003
+ file: fileResponse.file ?? null,
5004
+ pageCount: fileResponse.pageCount ?? undefined,
5005
+ tags: extras.tags,
5006
+ tagChanged: false,
5007
+ fileNameChanged: false,
5008
+ categoryTag: extras.categoryTag,
5009
+ base64Url: null,
5010
+ };
5011
+ }
4962
5012
  static async resolveFile(fileResponse) {
4963
5013
  return (fileResponse.file ??
4964
5014
  (await DropZoneDocumentsHelper.fetchFileAsFile(fileResponse)));
@@ -5226,7 +5276,7 @@ class DropZoneComponent {
5226
5276
  // Variables
5227
5277
  docsRatios = new Map();
5228
5278
  categoryTag = null;
5229
- clientFileId = 0;
5279
+ nextClientFileId = -1;
5230
5280
  lastFilesSignature = null;
5231
5281
  // Computed Signals
5232
5282
  cropDimensions = computed(() => {
@@ -5283,7 +5333,8 @@ class DropZoneComponent {
5283
5333
  const width = this.drawerViewportWidth();
5284
5334
  const fitted = width <= 0
5285
5335
  ? 1
5286
- : Math.max(1, Math.floor((width + DROP_ZONE_CARD_SLIDER.GAP_PX) / DROP_ZONE_CARD_SLIDER_ITEM_WITH_GAP_PX));
5336
+ : Math.max(1, Math.floor((width + DROP_ZONE_CARD_SLIDER.GAP_PX) /
5337
+ DROP_ZONE_CARD_SLIDER_ITEM_WITH_GAP_PX));
5287
5338
  return this.isCardSlider()
5288
5339
  ? Math.min(fitted, DROP_ZONE_CARD_SLIDER.MAX_VISIBLE_COUNT)
5289
5340
  : fitted;
@@ -5469,47 +5520,21 @@ class DropZoneComponent {
5469
5520
  return;
5470
5521
  }
5471
5522
  this.skeletonCount.set(currentFiles.length);
5472
- const newlyProcessed = await DropZoneConcurrencyHelper.mapWithConcurrency(currentFiles, FILE_PROCESSING_CONCURRENCY, async (fileResp) => {
5523
+ const mappedFiles = await DropZoneConcurrencyHelper.mapWithConcurrency(currentFiles, FILE_PROCESSING_CONCURRENCY, async (fileResp) => {
5473
5524
  if (fileResp.imagePreviewUrl)
5474
5525
  return fileResp;
5475
- const fileExtension = fileResp.fileName?.split('.').pop()?.toLowerCase() || 'pdf';
5476
- let previewUrl = fileResp?.url || '';
5477
- let pageCount;
5478
- const file = await DropZoneDocumentsHelper.resolveFile(fileResp);
5479
- const supportedBase64 = this.isImagePreviewVariant();
5480
- const base64Url = supportedBase64 && file
5481
- ? await DropZoneDocumentsHelper.fileToBase64(file)
5482
- : null;
5483
- if (file) {
5484
- const { thumbnailUrl, pageCount: pages } = await this.documentService.generateThumbnail(file);
5485
- previewUrl = DropZonePreviewUrlsHelper.track(this.previewUrlsState, thumbnailUrl);
5486
- pageCount = pages;
5487
- }
5488
- const serverFileId = fileResp.fileId || 0;
5489
- return {
5490
- fileName: fileResp.fileName || '',
5491
- baseName: fileResp.fileName?.split('.').slice(0, -1).join('.') || '',
5492
- fileId: serverFileId,
5493
- uid: serverFileId ? String(serverFileId) : crypto.randomUUID(),
5494
- type: fileExtension,
5495
- size: fileResp.fileSize || 0,
5496
- url: fileResp.url || '',
5497
- imagePreviewUrl: previewUrl,
5498
- file: file,
5499
- pageCount: pageCount,
5500
- tags: this.getTagIds(fileResp.tags || [], fileResp.tagGeneratedByUser ?? false),
5501
- tagChanged: false,
5502
- fileNameChanged: false,
5526
+ const serverFile = fileResp;
5527
+ const appFile = DropZoneDocumentsHelper.mapFileResponseToAppFile(serverFile, {
5528
+ tags: this.getTagIds(serverFile.tags || [], serverFile.tagGeneratedByUser ?? false),
5503
5529
  categoryTag: this.categoryTag,
5504
- base64Url,
5505
- };
5530
+ });
5531
+ if (appFile.imagePreviewUrl)
5532
+ return appFile;
5533
+ return this.hydrateMissingPreview(appFile, serverFile);
5506
5534
  });
5507
- const validNewFiles = newlyProcessed.filter(Boolean) || [];
5508
- if (validNewFiles.length > 0) {
5509
- this.releaseUnusedPreviewUrls(validNewFiles);
5510
- this.docs.set(validNewFiles);
5511
- this.setImagePreviewUrl(validNewFiles[0]?.imagePreviewUrl || '');
5512
- }
5535
+ this.releaseUnusedPreviewUrls(mappedFiles);
5536
+ this.docs.set(mappedFiles);
5537
+ this.setImagePreviewUrl(mappedFiles[0]?.imagePreviewUrl || '');
5513
5538
  if (this.crop()) {
5514
5539
  this.submitCrop(true);
5515
5540
  }
@@ -5521,6 +5546,21 @@ class DropZoneComponent {
5521
5546
  ]);
5522
5547
  }
5523
5548
  }
5549
+ async hydrateMissingPreview(appFile, serverFile) {
5550
+ const file = await DropZoneDocumentsHelper.resolveFile(serverFile);
5551
+ if (!file)
5552
+ return appFile;
5553
+ const { thumbnailUrl, pageCount } = await this.documentService.generateThumbnail(file);
5554
+ return {
5555
+ ...appFile,
5556
+ file,
5557
+ imagePreviewUrl: DropZonePreviewUrlsHelper.track(this.previewUrlsState, thumbnailUrl),
5558
+ pageCount: appFile.pageCount ?? pageCount,
5559
+ base64Url: this.isImagePreviewVariant()
5560
+ ? await DropZoneDocumentsHelper.fileToBase64(file)
5561
+ : appFile.base64Url,
5562
+ };
5563
+ }
5524
5564
  updateRangeBackground(input) {
5525
5565
  if (!input)
5526
5566
  return;
@@ -5652,7 +5692,7 @@ class DropZoneComponent {
5652
5692
  return;
5653
5693
  }
5654
5694
  const processedFiles = await DropZoneConcurrencyHelper.mapWithConcurrency(toProcess, FILE_PROCESSING_CONCURRENCY, async (file) => {
5655
- const fileId = this.clientFileId++;
5695
+ const fileId = this.nextClientFileId--;
5656
5696
  const fileExtension = file.name.split('.').pop()?.toLowerCase() || '';
5657
5697
  let pageCount;
5658
5698
  const supportedBase64 = this.isImagePreviewVariant();