{"id":20885944,"url":"https://github.com/zotero/epub.js","last_synced_at":"2025-05-12T19:31:58.835Z","repository":{"id":186819672,"uuid":"598252638","full_name":"zotero/epub.js","owner":"zotero","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-06T18:26:10.000Z","size":27416,"stargazers_count":4,"open_issues_count":3,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-08T18:24:48.611Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zotero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-02-06T18:12:41.000Z","updated_at":"2024-03-19T06:17:58.000Z","dependencies_parsed_at":"2023-08-07T21:57:42.991Z","dependency_job_id":null,"html_url":"https://github.com/zotero/epub.js","commit_stats":null,"previous_names":["zotero/epub.js"],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotero%2Fepub.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotero%2Fepub.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotero%2Fepub.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotero%2Fepub.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zotero","download_url":"https://codeload.github.com/zotero/epub.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225148799,"owners_count":17428430,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T08:15:09.635Z","updated_at":"2024-11-18T08:15:10.200Z","avatar_url":"https://github.com/zotero.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Epub.js v0.3\n\n![FuturePress Views](http://fchasen.com/futurepress/fp.png)\n\nEpub.js is a JavaScript library for rendering ePub documents in the browser, across many devices.\n\nEpub.js provides an interface for common ebook functions (such as rendering, persistence and pagination) without the need to develop a dedicated application or plugin. Importantly, it has an incredibly permissive [Free BSD](http://en.wikipedia.org/wiki/BSD_licenses) license.\n\n[Try it while reading Moby Dick](https://futurepress.github.io/epubjs-reader/)\n\n## Why EPUB\n\n![Why EPUB](http://fchasen.com/futurepress/whyepub.png)\n\nThe [EPUB standard](http://www.idpf.org/epub/30/spec/epub30-overview.html) is a widely used and easily convertible format. Many books are currently in this format, and it is convertible to many other formats (such as PDF, Mobi and iBooks).\n\nAn unzipped EPUB3 is a collection of HTML5 files, CSS, images and other media – just like any other website. However, it enforces a schema of book components, which allows us to render a book and its parts based on a controlled vocabulary.\n\nMore specifically, the EPUB schema standardizes the table of contents, provides a manifest that enables the caching of the entire book, and separates the storage of the content from how it’s displayed.\n\n## Getting Started\n\nIf using archived `.epub` files include JSZip (this must precede inclusion of epub.js):\n\n```html\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js\"\u003e\u003c/script\u003e\n```\n\nGet the minified code from the build folder:\n\n```html\n\u003cscript src=\"../dist/epub.min.js\"\u003e\u003c/script\u003e\n```\n\nSet up a element to render to:\n\n```html\n\u003cdiv id=\"area\"\u003e\u003c/div\u003e\n```\n\nCreate the new ePub, and then render it to that element:\n\n```html\n\u003cscript\u003e\n  var book = ePub(\"url/to/book/package.opf\");\n  var rendition = book.renderTo(\"area\", {width: 600, height: 400});\n  var displayed = rendition.display();\n\u003c/script\u003e\n```\n\n## Render Methods\n\n### Default\n\n```js\nbook.renderTo(\"area\", { method: \"default\", width: \"100%\", height: \"100%\" });\n```\n\n[View example](http://futurepress.github.io/epub.js/examples/spreads.html)\n\nThe default manager only displays a single section at a time.\n\n### Continuous\n\n```js\nbook.renderTo(\"area\", { method: \"continuous\", width: \"100%\", height: \"100%\" });\n```\n[View example](http://futurepress.github.io/epub.js/examples/continuous-scrolled.html)\n\nThe continuous manager will display as many sections as need to fill the screen, and preload the next section offscreen. This enables seamless swiping / scrolling between pages on mobile and desktop, but is less performant than the default method.\n\n## Flow Overrides\n\n### Auto (Default)\n`book.renderTo(\"area\", { flow: \"auto\", width: \"900\", height: \"600\" });`\n\nFlow will be based on the settings in the OPF, defaults to `paginated`.\n\n### Paginated\n\n```js\nbook.renderTo(\"area\", { flow: \"paginated\", width: \"900\", height: \"600\" });\n```\n\n[View example](http://futurepress.github.io/epub.js/examples/spreads.html)\n\nScrolled: `book.renderTo(\"area\", { flow: \"scrolled-doc\" });`\n\n[View example](http://futurepress.github.io/epub.js/examples/scrolled.html)\n\n## Scripted Content\n\n[Scripted content](https://www.w3.org/TR/epub-33/#sec-scripted-content), JavasScript the ePub HTML content, is disabled by default due to the potential for executing malicious content. \n\nThis is done by sandboxing the iframe the content is rendered into, though it is still recommended to sanitize the ePub content server-side as well.\n\nIf a trusted ePub contains interactivity, it can be enabled by passing `allowScriptedContent: true` to the `Rendition` settings.\n\n```html\n\u003cscript\u003e\n  var rendition = book.renderTo(\"area\", {\n    width: 600,\n    height: 400,\n    allowScriptedContent: true\n  });\n\u003c/script\u003e\n```\n\nThis will allow the sandboxed content to run scripts, but currently makes the sandbox insecure.\n\n## Documentation\n\nAPI documentation is available at [epubjs.org/documentation/0.3/](http://epubjs.org/documentation/0.3/)\n\nA Markdown version is included in the repo at [documentation/API.md](https://github.com/futurepress/epub.js/blob/master/documentation/md/API.md)\n\n## Running Locally\n\ninstall [node.js](http://nodejs.org/)\n\nThen install the project dependences with npm\n\n```javascript\nnpm install\n```\n\nYou can run the reader locally with the command\n\n```javascript\nnpm start\n```\n\n## Examples\n\n+ [Spreads](http://futurepress.github.io/epub.js/examples/spreads.html)\n+ [Scrolled](http://futurepress.github.io/epub.js/examples/scrolled.html)\n+ [Swipe](http://futurepress.github.io/epub.js/examples/swipe.html)\n+ [Input](http://futurepress.github.io/epub.js/examples/input.html)\n+ [Highlights](http://futurepress.github.io/epub.js/examples/highlights.html)\n\n[View All Examples](http://futurepress.github.io/epub.js/examples/)\n\n## Testing\n\nTest can be run by Karma from NPM\n\n```js\nnpm test\n```\n\n## Building for Distribution\n\nBuilds are concatenated and minified using [webpack](https://webpack.js.org/) and [babel](https://babeljs.io/)\n\nTo generate a new build run\n\n```javascript\nnpm run prepare\n```\n\nor to continuously build run\n\n```javascript\nnpm run watch\n```\n\n## Hooks\n\nSimilar to a plugins, Epub.js implements events that can be \"hooked\" into. Thus you can interact with and manipulate the contents of the book.\n\nExamples of this functionality is loading videos from YouTube links before displaying a chapter's contents or implementing annotation.\n\nHooks require an event to register to and a can return a promise to block until they are finished.\n\nExample hook:\n\n```javascript\nrendition.hooks.content.register(function(contents, view) {\n\n    var elements = contents.document.querySelectorAll('[video]');\n    var items = Array.prototype.slice.call(elements);\n\n    items.forEach(function(item){\n      // do something with the video item\n    });\n\n})\n```\n\nThe parts of the rendering process that can be hooked into are below.\n\n```js\nbook.spine.hooks.serialize // Section is being converted to text\nbook.spine.hooks.content // Section has been loaded and parsed\nrendition.hooks.render // Section is rendered to the screen\nrendition.hooks.content // Section contents have been loaded\nrendition.hooks.unloaded // Section contents are being unloaded\n```\n\n## Reader\nThe reader has moved to its own repo at: https://github.com/futurepress/epubjs-reader/\n\n## Additional Resources\n\n[![Gitter Chat](https://badges.gitter.im/futurepress/epub.js.png)](https://gitter.im/futurepress/epub.js \"Gitter Chat\")\n\n[Epub.js Developer Mailing List](https://groups.google.com/forum/#!forum/epubjs)\n\nIRC Server: freenode.net Channel: #epub.js\n\nFollow us on twitter: @Epubjs\n\n+ http://twitter.com/#!/Epubjs\n\n## Other\n\nEPUB is a registered trademark of the [IDPF](http://idpf.org/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzotero%2Fepub.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzotero%2Fepub.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzotero%2Fepub.js/lists"}