vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
1 lines • 12.1 kB
Source Map (JSON)
{"version":3,"file":"annotations.mjs","sources":["../../../../../node_modules/epubjs/src/annotations.js"],"sourcesContent":["import EventEmitter from \"event-emitter\";\nimport EpubCFI from \"./epubcfi\";\nimport { EVENTS } from \"./utils/constants\";\n\n/**\n\t* Handles managing adding & removing Annotations\n\t* @param {Rendition} rendition\n\t* @class\n\t*/\nclass Annotations {\n\n\tconstructor (rendition) {\n\t\tthis.rendition = rendition;\n\t\tthis.highlights = [];\n\t\tthis.underlines = [];\n\t\tthis.marks = [];\n\t\tthis._annotations = {};\n\t\tthis._annotationsBySectionIndex = {};\n\n\t\tthis.rendition.hooks.render.register(this.inject.bind(this));\n\t\tthis.rendition.hooks.unloaded.register(this.clear.bind(this));\n\t}\n\n\t/**\n\t * Add an annotation to store\n\t * @param {string} type Type of annotation to add: \"highlight\", \"underline\", \"mark\"\n\t * @param {EpubCFI} cfiRange EpubCFI range to attach annotation to\n\t * @param {object} data Data to assign to annotation\n\t * @param {function} [cb] Callback after annotation is added\n\t * @param {string} className CSS class to assign to annotation\n\t * @param {object} styles CSS styles to assign to annotation\n\t * @returns {Annotation} annotation\n\t */\n\tadd (type, cfiRange, data, cb, className, styles) {\n\t\tlet hash = encodeURI(cfiRange + type);\n\t\tlet cfi = new EpubCFI(cfiRange);\n\t\tlet sectionIndex = cfi.spinePos;\n\t\tlet annotation = new Annotation({\n\t\t\ttype,\n\t\t\tcfiRange,\n\t\t\tdata,\n\t\t\tsectionIndex,\n\t\t\tcb,\n\t\t\tclassName,\n\t\t\tstyles\n\t\t});\n\n\t\tthis._annotations[hash] = annotation;\n\n\t\tif (sectionIndex in this._annotationsBySectionIndex) {\n\t\t\tthis._annotationsBySectionIndex[sectionIndex].push(hash);\n\t\t} else {\n\t\t\tthis._annotationsBySectionIndex[sectionIndex] = [hash];\n\t\t}\n\n\t\tlet views = this.rendition.views();\n\n\t\tviews.forEach( (view) => {\n\t\t\tif (annotation.sectionIndex === view.index) {\n\t\t\t\tannotation.attach(view);\n\t\t\t}\n\t\t});\n\n\t\treturn annotation;\n\t}\n\n\t/**\n\t * Remove an annotation from store\n\t * @param {EpubCFI} cfiRange EpubCFI range the annotation is attached to\n\t * @param {string} type Type of annotation to add: \"highlight\", \"underline\", \"mark\"\n\t */\n\tremove (cfiRange, type) {\n\t\tlet hash = encodeURI(cfiRange + type);\n\n\t\tif (hash in this._annotations) {\n\t\t\tlet annotation = this._annotations[hash];\n\n\t\t\tif (type && annotation.type !== type) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet views = this.rendition.views();\n\t\t\tviews.forEach( (view) => {\n\t\t\t\tthis._removeFromAnnotationBySectionIndex(annotation.sectionIndex, hash);\n\t\t\t\tif (annotation.sectionIndex === view.index) {\n\t\t\t\t\tannotation.detach(view);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tdelete this._annotations[hash];\n\t\t}\n\t}\n\n\t/**\n\t * Remove an annotations by Section Index\n\t * @private\n\t */\n\t_removeFromAnnotationBySectionIndex (sectionIndex, hash) {\n\t\tthis._annotationsBySectionIndex[sectionIndex] = this._annotationsAt(sectionIndex).filter(h => h !== hash);\n\t}\n\n\t/**\n\t * Get annotations by Section Index\n\t * @private\n\t */\n\t_annotationsAt (index) {\n\t\treturn this._annotationsBySectionIndex[index];\n\t}\n\n\n\t/**\n\t * Add a highlight to the store\n\t * @param {EpubCFI} cfiRange EpubCFI range to attach annotation to\n\t * @param {object} data Data to assign to annotation\n\t * @param {function} cb Callback after annotation is clicked\n\t * @param {string} className CSS class to assign to annotation\n\t * @param {object} styles CSS styles to assign to annotation\n\t */\n\thighlight (cfiRange, data, cb, className, styles) {\n\t\treturn this.add(\"highlight\", cfiRange, data, cb, className, styles);\n\t}\n\n\t/**\n\t * Add a underline to the store\n\t * @param {EpubCFI} cfiRange EpubCFI range to attach annotation to\n\t * @param {object} data Data to assign to annotation\n\t * @param {function} cb Callback after annotation is clicked\n\t * @param {string} className CSS class to assign to annotation\n\t * @param {object} styles CSS styles to assign to annotation\n\t */\n\tunderline (cfiRange, data, cb, className, styles) {\n\t\treturn this.add(\"underline\", cfiRange, data, cb, className, styles);\n\t}\n\n\t/**\n\t * Add a mark to the store\n\t * @param {EpubCFI} cfiRange EpubCFI range to attach annotation to\n\t * @param {object} data Data to assign to annotation\n\t * @param {function} cb Callback after annotation is clicked\n\t */\n\tmark (cfiRange, data, cb) {\n\t\treturn this.add(\"mark\", cfiRange, data, cb);\n\t}\n\n\t/**\n\t * iterate over annotations in the store\n\t */\n\teach () {\n\t\treturn this._annotations.forEach.apply(this._annotations, arguments);\n\t}\n\n\t/**\n\t * Hook for injecting annotation into a view\n\t * @param {View} view\n\t * @private\n\t */\n\tinject (view) {\n\t\tlet sectionIndex = view.index;\n\t\tif (sectionIndex in this._annotationsBySectionIndex) {\n\t\t\tlet annotations = this._annotationsBySectionIndex[sectionIndex];\n\t\t\tannotations.forEach((hash) => {\n\t\t\t\tlet annotation = this._annotations[hash];\n\t\t\t\tannotation.attach(view);\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Hook for removing annotation from a view\n\t * @param {View} view\n\t * @private\n\t */\n\tclear (view) {\n\t\tlet sectionIndex = view.index;\n\t\tif (sectionIndex in this._annotationsBySectionIndex) {\n\t\t\tlet annotations = this._annotationsBySectionIndex[sectionIndex];\n\t\t\tannotations.forEach((hash) => {\n\t\t\t\tlet annotation = this._annotations[hash];\n\t\t\t\tannotation.detach(view);\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * [Not Implemented] Show annotations\n\t * @TODO: needs implementation in View\n\t */\n\tshow () {\n\n\t}\n\n\t/**\n\t * [Not Implemented] Hide annotations\n\t * @TODO: needs implementation in View\n\t */\n\thide () {\n\n\t}\n\n}\n\n/**\n * Annotation object\n * @class\n * @param {object} options\n * @param {string} options.type Type of annotation to add: \"highlight\", \"underline\", \"mark\"\n * @param {EpubCFI} options.cfiRange EpubCFI range to attach annotation to\n * @param {object} options.data Data to assign to annotation\n * @param {int} options.sectionIndex Index in the Spine of the Section annotation belongs to\n * @param {function} [options.cb] Callback after annotation is clicked\n * @param {string} className CSS class to assign to annotation\n * @param {object} styles CSS styles to assign to annotation\n * @returns {Annotation} annotation\n */\nclass Annotation {\n\n\tconstructor ({\n\t\ttype,\n\t\tcfiRange,\n\t\tdata,\n\t\tsectionIndex,\n\t\tcb,\n\t\tclassName,\n\t\tstyles\n\t}) {\n\t\tthis.type = type;\n\t\tthis.cfiRange = cfiRange;\n\t\tthis.data = data;\n\t\tthis.sectionIndex = sectionIndex;\n\t\tthis.mark = undefined;\n\t\tthis.cb = cb;\n\t\tthis.className = className;\n\t\tthis.styles = styles;\n\t}\n\n\t/**\n\t * Update stored data\n\t * @param {object} data\n\t */\n\tupdate (data) {\n\t\tthis.data = data;\n\t}\n\n\t/**\n\t * Add to a view\n\t * @param {View} view\n\t */\n\tattach (view) {\n\t\tlet {cfiRange, data, type, mark, cb, className, styles} = this;\n\t\tlet result;\n\n\t\tif (type === \"highlight\") {\n\t\t\tresult = view.highlight(cfiRange, data, cb, className, styles);\n\t\t} else if (type === \"underline\") {\n\t\t\tresult = view.underline(cfiRange, data, cb, className, styles);\n\t\t} else if (type === \"mark\") {\n\t\t\tresult = view.mark(cfiRange, data, cb);\n\t\t}\n\n\t\tthis.mark = result;\n\t\tthis.emit(EVENTS.ANNOTATION.ATTACH, result);\n\t\treturn result;\n\t}\n\n\t/**\n\t * Remove from a view\n\t * @param {View} view\n\t */\n\tdetach (view) {\n\t\tlet {cfiRange, type} = this;\n\t\tlet result;\n\n\t\tif (view) {\n\t\t\tif (type === \"highlight\") {\n\t\t\t\tresult = view.unhighlight(cfiRange);\n\t\t\t} else if (type === \"underline\") {\n\t\t\t\tresult = view.ununderline(cfiRange);\n\t\t\t} else if (type === \"mark\") {\n\t\t\t\tresult = view.unmark(cfiRange);\n\t\t\t}\n\t\t}\n\n\t\tthis.mark = undefined;\n\t\tthis.emit(EVENTS.ANNOTATION.DETACH, result);\n\t\treturn result;\n\t}\n\n\t/**\n\t * [Not Implemented] Get text of an annotation\n\t * @TODO: needs implementation in contents\n\t */\n\ttext () {\n\n\t}\n\n}\n\nEventEmitter(Annotation.prototype);\n\n\nexport default Annotations\n"],"names":["Annotations","rendition","type","cfiRange","data","cb","className","styles","hash","sectionIndex","EpubCFI","annotation","Annotation","view","h","index","mark","result","EVENTS","EventEmitter"],"mappings":";;;AASA,MAAMA,EAAY;AAAA,EAEjB,YAAaC,GAAW;AACvB,SAAK,YAAYA,GACjB,KAAK,aAAa,CAAA,GAClB,KAAK,aAAa,CAAA,GAClB,KAAK,QAAQ,CAAA,GACb,KAAK,eAAe,CAAA,GACpB,KAAK,6BAA6B,CAAA,GAElC,KAAK,UAAU,MAAM,OAAO,SAAS,KAAK,OAAO,KAAK,IAAI,CAAC,GAC3D,KAAK,UAAU,MAAM,SAAS,SAAS,KAAK,MAAM,KAAK,IAAI,CAAC;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,IAAKC,GAAMC,GAAUC,GAAMC,GAAIC,GAAWC,GAAQ;AACjD,QAAIC,IAAO,UAAUL,IAAWD,CAAI,GAEhCO,IADM,IAAIC,EAAQP,CAAQ,EACP,UACnBQ,IAAa,IAAIC,EAAW;AAAA,MAC/B,MAAAV;AAAA,MACA,UAAAC;AAAA,MACA,MAAAC;AAAA,MACA,cAAAK;AAAA,MACA,IAAAJ;AAAA,MACA,WAAAC;AAAA,MACA,QAAAC;AAAA,IACH,CAAG;AAED,gBAAK,aAAaC,CAAI,IAAIG,GAEtBF,KAAgB,KAAK,6BACxB,KAAK,2BAA2BA,CAAY,EAAE,KAAKD,CAAI,IAEvD,KAAK,2BAA2BC,CAAY,IAAI,CAACD,CAAI,GAG1C,KAAK,UAAU,MAAK,EAE1B,QAAS,CAACK,MAAS;AACxB,MAAIF,EAAW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