Skip to content

Commit

Permalink
Merge branch 'v1.0.0' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
sbannigan committed Dec 13, 2018
2 parents 4c7b07e + 45bb8e4 commit 29c81f4
Show file tree
Hide file tree
Showing 163 changed files with 30,191 additions and 4,929 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ log.txt
*.sublime-project
*.sublime-workspace

.stencil/
.idea/
.vscode/
.sass-cache/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "pdf.js"]
path = pdf.js
url = https://github.com/TeamHive/pdf.js.git
2 changes: 0 additions & 2 deletions copy-pdf-worker.sh

This file was deleted.

5,316 changes: 1,680 additions & 3,636 deletions package-lock.json

Large diffs are not rendered by default.

70 changes: 27 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,40 @@
{
"name": "@teamhive/stencil-pdf-viewer",
"version": "0.2.2",
"description": "Stencil PDF Viewer",
"name": "@teamhive/pdf-viewer",
"version": "1.0.0",
"description": "PDF Viewer Web Component. Built with stencil and pdfjs.",
"homepage": "https://github.com/TeamHive/pdf-viewer",
"repository": {
"type": "git",
"url": "github:TeamHive/pdf-viewer"
},
"author": "TeamHive",
"module": "dist/esm/index.js",
"main": "dist/index.js",
"unpkg": "dist/ionic.js",
"types": "dist/types/components.d.ts",
"collection": "dist/collection/collection-manifest.json",
"files": [
"dist/"
],
"scripts": {
"build": "npm run copyPdfWorker && stencil build --prod",
"dev": "npm run copyPdfWorker && sd concurrent \"stencil build --dev --watch\" \"stencil-dev-server\" ",
"serve": "stencil-dev-server",
"start": "npm run dev",
"test": "jest",
"test.watch": "jest --watch",
"copyPdfWorker": "./copy-pdf-worker.sh",
"prepublishOnly": "npm run build"
},
"dependencies": {
"print-js": "^1.0.47",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0"
"prepare": "npm run pdf.js:build && npm run prepare-assets",
"build": "npm run pdf.js:build && npm run prepare-assets && npm run build:stencil",
"build:stencil": "stencil build && node ./scripts/asset-import.js",
"start": "stencil build --dev --watch --serve",
"prepare-assets": "node ./scripts/prepare-assets.js",
"pdf.js:install": "cd pdf.js && npm install",
"pdf.js:build": "npm run pdf.js:install && npm run pdf.js:dist && npm run pdf.js:pack",
"pdf.js:dist": "cd pdf.js && gulp dist-pre",
"pdf.js:pack": "node ./scripts/package-cleanup.js && cd pdf.js/build/dist && npm pack && cd ../../../ && node ./scripts/package-rename.js && npm i pdf.js/build/dist/pdfjs-dist.tgz --no-save",
"prepublishOnly": "npm run build:stencil"
},
"dependencies": {},
"devDependencies": {
"@stencil/core": "^0.16.0",
"@stencil/dev-server": "latest",
"@stencil/sass": "^0.1.1",
"@stencil/utils": "latest",
"@types/jest": "^22.2.3",
"@types/pdfjs-dist": "^0.1.2",
"jest": "^22.4.3",
"pdfjs-dist": "^2.0.489"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TeamHive/stencil-pdf-viewer.git"
"@stencil/core": "0.16.1",
"@stencil/sass": "0.1.1",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"webpack": "^4.27.1"
},
"author": "TeamHive",
"license": "MIT",
"jest": {
"transform": {
"^.+\\.(ts|tsx)$": "<rootDir>/node_modules/@stencil/core/testing/jest.preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json",
"jsx"
]
}
"license": "MIT"
}
1 change: 1 addition & 0 deletions pdf.js
Submodule pdf.js added at c35f4d
45 changes: 11 additions & 34 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,47 @@
# Hive Stencil PDF Viewer
This web component allows you to add PDF rendering support to your web (and Ionic native) applications.
![Built With Stencil](https://img.shields.io/badge/-Built%20With%20Stencil-16161d.svg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D&colorA=16161d&style=flat-square)

# Hive PDF Viewer

This web component allows you to add PDF rendering support to your web applications.

## Features
- Rendering PDFs on web (Angular, Ionic, React, Stencil, etc.)
- Search
- Rotation of Documents
- Fit to Page / Fit to Width
- Side panel for quick thumbnail navigation

## Preview

|Mobile|Web|
:---:|:---:
|![Mobile Image](https://i.gyazo.com/8f0af76f1e0d1b138baeed3d25266b81.gif)|![Web Image](https://i.gyazo.com/8e0b44567b15e4aec1b20df550aae817.gif)|

## Installation
- `npm i @teamhive/stencil-pdf-viewer`
- `npm i @teamhive/pdf-viewer`

## Usage
```
<hive-pdf-viewer src="http://www.mydomain.com/example.pdf"></hive-pdf-viewer>
```

### Angular (6+) / Ionic (4+)
In your `angular.json` file add the following assets matcher in your `projects.app.architect.build.options.assets` collection:
Somewhere in your project (e.g. `main.ts`):
```
{
"glob": "**/*",
"input": "node_modules/@teamhive/stencil-pdf-viewer/dist/pdfviewer",
"output": "./pdfviewer"
}
import { defineCustomElements } from '@teamhive/pdf-viewer/dist/loader';
defineCustomElements(window);
```

In your main `AppModule` (i.e. `app.module.ts`) add the following import statement:
```
import '@teamhive/stencil-pdf-viewer/dist/pdfviewer';
```
Follow the [Stencil JS Framework Integration](https://stenciljs.com/docs/overview) guide for more info.

## Properties
|Property|Default|Description
:---:|:---:|:---:
|`src`||The PDF web address location (file://|http|https)|
|`src`||The PDF web address location (file://, http, https)|
|`page`|`1`|The default page index.|
|`zoom`|`1`|The current zoom target for the document.|
|`minZoom`|`0.25`|The minimum zoom target allowed for the document.|
|`maxZoom`|`4`|The maximum zoom target allowed for the document.|
|`rotation`|`0`|The rotated document value.
|`allowPrint`|`false`|If the document allows printing (hides print button).|
|`searchOpen`|`false`|If the search pop-up panel should be displayed by default.|
|`enableSideDrawer`|`true`|If the side drawer UI (and button) is available for display.|
|`enableRotate`|`true`|If the document can be rotated. Hides the button when false.|
|`enableSearch`|`true`|If the document can be searched through. Hides the button when false.|


### Events
|Event|Description|
:---:|:---:
|`onLinkClick(href: string)`|Emits the `href` clicked when it's not an internal document annotation.|
|`pageChange(currentPage: number)`|Emits the current page number when the current page changes.|
|`afterLoadComplete(pdf: PDFDocumentProxy)`|Emits the pdf document when the loading task completes.|
|`onError(error: any)`|Emitted when the document fails to load.|
|`onProgress(progressData: PDFProgressData)`|Emit when the loading task returns back progress.|

---


## Contributors

[<img alt="Sean Bannigan" src="https://avatars1.githubusercontent.com/u/15218748?s=460&v=4" width="117">](https://github.com/sbannigan) | [<img alt="Sean Perkins" src="https://avatars1.githubusercontent.com/u/13732623?v=4&s=117" width="117">](https://github.com/sean-perkins) |[<img alt="Justin True" src="https://avatars3.githubusercontent.com/u/17008383?s=400&v=4" width="117">](https://github.com/bbjdt2224) |
Expand Down
23 changes: 23 additions & 0 deletions scripts/asset-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs');
const definePaths = [
'./dist/esm/es5/pdf-viewer.define.js',
'./dist/esm/es2017/pdf-viewer.define.js',
];

definePaths.forEach(function (path) {
fs.readFile(path, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}

data = data + "import '../../pdf-viewer/pdfjs-assets';"

fs.writeFile(path, data, 'utf8', function (err) {
if (err) {
return console.error(err);
}

console.log(`Asset import added to ${path}`)
})
});
})
17 changes: 17 additions & 0 deletions scripts/package-cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const glob = require('glob')
const fs = require('fs')

const distPath = 'pdf.js/build/dist';
glob(`${distPath}/*.tgz`, function (err, files) {
if (err) {
return console.error(err);
}

files.forEach(function (file) {
fs.unlink(file, (err) => {
if (err) {
return console.error(err);
}
});
});
});
14 changes: 14 additions & 0 deletions scripts/package-rename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const glob = require('glob')
const fs = require('fs')

const distPath = 'pdf.js/build/dist';
glob(`${distPath}/*.tgz`, function (err, files) {
if (err) {
return console.error(err);
}
fs.rename(files[0], `${distPath}/pdfjs-dist.tgz`, function (err) {
if (err) {
return console.error(err);
}
});
});
53 changes: 53 additions & 0 deletions scripts/prepare-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const fs = require('fs');

// Copy Worker
const workerPath = 'pdf.js/build/dist/build/pdf.worker.min.js';
const destPath = 'src/components/pdf-viewer/pdfjs-assets/pdf.worker.min.js';
fs.readFile(workerPath, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}
fs.writeFile(destPath, data, 'utf8', function (err) {
if (err) {
return console.error(err);
}
console.log(`Worker copied to ${destPath}`)
})
});

const localeRootPath = 'pdf.js/build/generic/web/locale';
const destRootPath = 'src/components/pdf-viewer/pdfjs-assets/locale';
// rewrite locale.properties
fs.readFile(`${localeRootPath}/locale.properties`, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}
data = data.replace(/\//g, '.');
fs.writeFile(`${destRootPath}/locale.properties`, data, 'utf8', function (err) {
if (err) {
return console.error(err);
}
console.log(`locale.properties copied to ${destRootPath}`)
});
});

fs.readdir(`${localeRootPath}`, 'utf8', function (err, files) {
if (err) {
return console.error(err);
}
files.forEach(file => {
if (file !== 'locale.properties') {
fs.readFile(`${localeRootPath}/${file}/viewer.properties`, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}
fs.writeFile(`${destRootPath}/${file}.viewer.properties`, data, 'utf8', function (err) {
if (err) {
return console.error(err);
}
});
});
}
});
console.log(`viewer.properties copied to ${destRootPath}`)
});
Binary file removed src/assets/test-pdf.pdf
Binary file not shown.
46 changes: 4 additions & 42 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,23 @@
import '@stencil/core';


import {
PDFSource,
} from 'pdfjs-dist';


export namespace Components {

interface HivePdfViewer {
'allowPrint': boolean;
'canAutoResize': boolean;
'currentMatchIndex': number;
'enableRotate': boolean;
'enableSearch': boolean;
'enableSideDrawer': boolean;
'externalLinkTarget': string;
'fitToPage': boolean;
'maxZoom': number;
'minZoom': number;
'openDrawer': boolean;
'originalSize': boolean;
'page': number;
'renderText': boolean;
'rotation': number;
'searchOpen': boolean;
'src': string | Uint8Array | PDFSource;
'stickToPage': boolean;
'totalMatchCount': number;
'zoom': number;
'src': string | Uint8Array;
}
interface HivePdfViewerAttributes extends StencilHTMLAttributes {
'allowPrint'?: boolean;
'canAutoResize'?: boolean;
'currentMatchIndex'?: number;
'enableRotate'?: boolean;
'enableSearch'?: boolean;
'enableSideDrawer'?: boolean;
'externalLinkTarget'?: string;
'fitToPage'?: boolean;
'maxZoom'?: number;
'minZoom'?: number;
'onAfterLoadComplete'?: (event: CustomEvent) => void;
'onOnError'?: (event: CustomEvent) => void;
'onOnLinkClick'?: (event: CustomEvent) => void;
'onOnProgress'?: (event: CustomEvent) => void;
'onPageChange'?: (event: CustomEvent) => void;
'openDrawer'?: boolean;
'originalSize'?: boolean;
'onOnLinkClick'?: (event: CustomEvent<string>) => void;
'onPageChange'?: (event: CustomEvent<number>) => void;
'page'?: number;
'renderText'?: boolean;
'rotation'?: number;
'searchOpen'?: boolean;
'src'?: string | Uint8Array | PDFSource;
'stickToPage'?: boolean;
'totalMatchCount'?: number;
'zoom'?: number;
'src'?: string | Uint8Array;
}
}

Expand Down
Loading

0 comments on commit 29c81f4

Please sign in to comment.