Skip to content

Commit

Permalink
fix(abc:pdf): fix ignore dependency pdfjs-dist
Browse files Browse the repository at this point in the history
  • Loading branch information
devcui committed Sep 27, 2023
1 parent e3da675 commit b804bb1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
"xlsx": "^0.18.5",
"jszip": "^3.10.1",
"plyr": "^3.7.8",
"pdfjs-dist": "~3.6.172",
"screenfull": "^6.0.2",
"less-bundle-promise": "^1.0.11",
"ng-alain-codelyzer": "^0.0.1",
Expand Down
1 change: 0 additions & 1 deletion packages/abc/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"jszip",
"xlsx",
"plyr",
"pdfjs-dist",
"@github/hotkey",
"ngx-countdown",
"@yelon/theme",
Expand Down
2 changes: 1 addition & 1 deletion packages/abc/pdf/demo/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class DemoComponent implements OnInit {
};

loadOutline(): void {
this.comp.pdf?.getOutline().then(outline => {
this.comp.pdf?.getOutline().then((outline: NzSafeAny) => {
this.outlineList = outline;
});
}
Expand Down
6 changes: 5 additions & 1 deletion packages/abc/pdf/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ pdf.js libary is lazy loading by default,you can change the default root CDN p
**Use local path**

```bash
yarn add pdfjs-dist
```

```json
// angular.json
{
"glob": "**/(build,web)/**",
"glob": "{build,web}/**",
"input": "./node_modules/pdfjs-dist/",
"ignore": ["*.js.map", "*.d.ts"],
"output": "assets/pdfjs/"
Expand Down
6 changes: 5 additions & 1 deletion packages/abc/pdf/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ module: import { PdfModule } from '@yelon/abc/pdf';
**使用本地路径**

```bash
yarn add pdfjs-dist
```

```json
// angular.json
{
"glob": "**/(build,web)/**",
"glob": "{build,web}/**",
"input": "./node_modules/pdfjs-dist/",
"ignore": ["*.js.map", "*.d.ts"],
"output": "assets/pdfjs/"
Expand Down
24 changes: 17 additions & 7 deletions packages/abc/pdf/pdf.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import {
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { fromEvent, timer, debounceTime, filter } from 'rxjs';

import type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist';
import type { EventBus } from 'pdfjs-dist/types/web/event_utils';
import type { PDFFindController } from 'pdfjs-dist/types/web/pdf_find_controller';
import type { PDFLinkService } from 'pdfjs-dist/types/web/pdf_link_service';
import type { PDFViewer } from 'pdfjs-dist/types/web/pdf_viewer';
// import type { PDFDocumentLoadingTask, PDFDocumentProxy } from 'pdfjs-dist';
// import type { EventBus } from 'pdfjs-dist/types/web/event_utils';
// import type { PDFFindController } from 'pdfjs-dist/types/web/pdf_find_controller';
// import type { PDFLinkService } from 'pdfjs-dist/types/web/pdf_link_service';
// import type { PDFViewer } from 'pdfjs-dist/types/web/pdf_viewer';

import { YunzaiConfigService } from '@yelon/util/config';
import { BooleanInput, InputBoolean, InputNumber, NumberInput, ZoneOutside } from '@yelon/util/decorator';
Expand All @@ -36,14 +36,24 @@ import type { NzSafeAny } from 'ng-zorro-antd/core/types';
import { PDF_DEFULAT_CONFIG } from './pdf.config';
import { PdfChangeEvent, PdfChangeEventType, PdfExternalLinkTarget, PdfTextLayerMode, PdfZoomScale } from './pdf.types';

// TODO: Although pdfjs-dist is an optional dependency on canvas
// will be installed automatically when the dependency is installed by default;
// This requires a higher environment and often fails to install
type PDFDocumentLoadingTask = NzSafeAny;
type PDFDocumentProxy = NzSafeAny;
type EventBus = NzSafeAny;
type PDFFindController = NzSafeAny;
type PDFLinkService = NzSafeAny;
type PDFViewer = NzSafeAny;

const CSS_UNITS: number = 96.0 / 72.0;
const BORDER_WIDTH = 9;

@Component({
selector: 'pdf',
exportAs: 'pdf',
template: `
<nz-skeleton *ngIf="!inited || loading"></nz-skeleton>
<nz-skeleton *ngIf="!inited || loading" />
<div class="pdf-container">
<div class="pdfViewer"></div>
</div>
Expand Down Expand Up @@ -325,7 +335,7 @@ export class PdfComponent implements OnChanges, AfterViewInit, OnDestroy {
const currentViewer = this.pageViewer;
if (!currentViewer) return;

this._pdf!.getPage(currentViewer.currentPageNumber).then(page => {
this._pdf!.getPage(currentViewer.currentPageNumber).then((page: NzSafeAny) => {
const { _rotation, _zoom } = this;
const rotation = _rotation || page.rotate;
const viewportWidth =
Expand Down
4 changes: 3 additions & 1 deletion packages/abc/pdf/pdf.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PDFDocumentProxy } from 'pdfjs-dist';
// import type { PDFDocumentProxy } from 'pdfjs-dist';

import type { NzSafeAny } from 'ng-zorro-antd/core/types';

type PDFDocumentProxy = NzSafeAny;

export type PdfChangeEventType =
| 'loaded'
| 'load-progress'
Expand Down
6 changes: 3 additions & 3 deletions src/app/global-config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const yunzaiConfig: YunzaiConfig = {
qr: {
lib: '/assets/qrious/qrious.min.js'
},
pdf: {
lib: '/assets/pdfjs/'
},
// pdf: {
// lib: '/assets/pdfjs/'
// },
media: {
urls: ['assets/plyr/plyr.min.js', 'assets/plyr/plyr.css'],
options: {
Expand Down

0 comments on commit b804bb1

Please sign in to comment.