MCPcopy Create free account
hub / github.com/pacexy/flow / Annotation

Class Annotation

packages/epubjs/src/annotations.js:211–280  ·  view source on GitHub ↗

* Annotation object * @class * @param {object} options * @param {string} options.type Type of annotation to add: "highlight", "underline", "mark" * @param {EpubCFI} options.cfiRange EpubCFI range to attach annotation to * @param {object} options.data Data to assign to annotation * @param {int}

Source from the content-addressed store, hash-verified

209 * @returns {Annotation} annotation
210 */
211class Annotation {
212 constructor({ type, cfiRange, data, sectionIndex, cb, className, styles }) {
213 this.type = type
214 this.cfiRange = cfiRange
215 this.data = data
216 this.sectionIndex = sectionIndex
217 this.mark = undefined
218 this.cb = cb
219 this.className = className
220 this.styles = styles
221 }
222
223 /**
224 * Update stored data
225 * @param {object} data
226 */
227 update(data) {
228 this.data = data
229 }
230
231 /**
232 * Add to a view
233 * @param {View} view
234 */
235 attach(view) {
236 let { cfiRange, data, type, mark, cb, className, styles } = this
237 let result
238
239 if (type === 'highlight') {
240 result = view.highlight(cfiRange, data, cb, className, styles)
241 } else if (type === 'underline') {
242 result = view.underline(cfiRange, data, cb, className, styles)
243 } else if (type === 'mark') {
244 result = view.mark(cfiRange, data, cb)
245 }
246
247 this.mark = result
248 this.emit(EVENTS.ANNOTATION.ATTACH, result)
249 return result
250 }
251
252 /**
253 * Remove from a view
254 * @param {View} view
255 */
256 detach(view) {
257 let { cfiRange, type } = this
258 let result
259
260 if (view) {
261 if (type === 'highlight') {
262 result = view.unhighlight(cfiRange)
263 } else if (type === 'underline') {
264 result = view.ununderline(cfiRange)
265 } else if (type === 'mark') {
266 result = view.unmark(cfiRange)
267 }
268 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected