UNPKG

docxml

Version:

TypeScript (component) library for building and parsing a DOCX file

42 lines (41 loc) 1.77 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _Bookmarks_bookmarks; Object.defineProperty(exports, "__esModule", { value: true }); exports.Bookmarks = void 0; const NumberMap_js_1 = require("./NumberMap.js"); class Bookmarks { constructor() { _Bookmarks_bookmarks.set(this, new NumberMap_js_1.NumberMap(0)); } /** * Marks a unique identifier as taken. * * @todo When loading an existing document, bookmarks are not registered from it yet. */ registerIdentifier(id, name) { if (__classPrivateFieldGet(this, _Bookmarks_bookmarks, "f").has(id)) { throw new Error(`Bookmark with identifier "${id}" already exists.`); } __classPrivateFieldGet(this, _Bookmarks_bookmarks, "f").set(id, name || null); } /** * Create a unique ID and name for a new bookmark. * * @remarks * Not using a GUID because this causes Word to not make the link clickable. A much shorter * identifier works as expected. */ create() { const id = __classPrivateFieldGet(this, _Bookmarks_bookmarks, "f").getNextAvailableKey(); const name = `__docxml_bookmark_${id}`; this.registerIdentifier(id); return { id, name }; } } exports.Bookmarks = Bookmarks; _Bookmarks_bookmarks = new WeakMap();