ui_utils.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  27. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  28. exports.approximateFraction = approximateFraction;
  29. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  30. exports.binarySearchFirstItem = binarySearchFirstItem;
  31. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  32. exports.getOutputScale = getOutputScale;
  33. exports.getPageSizeInches = getPageSizeInches;
  34. exports.getVisibleElements = getVisibleElements;
  35. exports.isPortraitOrientation = isPortraitOrientation;
  36. exports.isValidRotation = isValidRotation;
  37. exports.isValidScrollMode = isValidScrollMode;
  38. exports.isValidSpreadMode = isValidSpreadMode;
  39. exports.moveToEndOfArray = moveToEndOfArray;
  40. exports.noContextMenuHandler = noContextMenuHandler;
  41. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  42. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  43. exports.parseQueryString = parseQueryString;
  44. exports.roundToDivide = roundToDivide;
  45. exports.scrollIntoView = scrollIntoView;
  46. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  47. exports.watchScroll = watchScroll;
  48. exports.WaitOnType = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.EventBus = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE = exports.CSS_UNITS = exports.AutoPrintRegExp = exports.animationStarted = void 0;
  49. const CSS_UNITS = 96.0 / 72.0;
  50. exports.CSS_UNITS = CSS_UNITS;
  51. const DEFAULT_SCALE_VALUE = "auto";
  52. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  53. const DEFAULT_SCALE = 1.0;
  54. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  55. const MIN_SCALE = 0.1;
  56. exports.MIN_SCALE = MIN_SCALE;
  57. const MAX_SCALE = 10.0;
  58. exports.MAX_SCALE = MAX_SCALE;
  59. const UNKNOWN_SCALE = 0;
  60. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  61. const MAX_AUTO_SCALE = 1.25;
  62. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  63. const SCROLLBAR_PADDING = 40;
  64. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  65. const VERTICAL_PADDING = 5;
  66. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  67. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  68. const PresentationModeState = {
  69. UNKNOWN: 0,
  70. NORMAL: 1,
  71. CHANGING: 2,
  72. FULLSCREEN: 3
  73. };
  74. exports.PresentationModeState = PresentationModeState;
  75. const SidebarView = {
  76. UNKNOWN: -1,
  77. NONE: 0,
  78. THUMBS: 1,
  79. OUTLINE: 2,
  80. ATTACHMENTS: 3,
  81. LAYERS: 4
  82. };
  83. exports.SidebarView = SidebarView;
  84. const RendererType = {
  85. CANVAS: "canvas",
  86. SVG: "svg"
  87. };
  88. exports.RendererType = RendererType;
  89. const TextLayerMode = {
  90. DISABLE: 0,
  91. ENABLE: 1,
  92. ENABLE_ENHANCE: 2
  93. };
  94. exports.TextLayerMode = TextLayerMode;
  95. const ScrollMode = {
  96. UNKNOWN: -1,
  97. VERTICAL: 0,
  98. HORIZONTAL: 1,
  99. WRAPPED: 2
  100. };
  101. exports.ScrollMode = ScrollMode;
  102. const SpreadMode = {
  103. UNKNOWN: -1,
  104. NONE: 0,
  105. ODD: 1,
  106. EVEN: 2
  107. };
  108. exports.SpreadMode = SpreadMode;
  109. const AutoPrintRegExp = /\bprint\s*\(/;
  110. exports.AutoPrintRegExp = AutoPrintRegExp;
  111. function getOutputScale(ctx) {
  112. const devicePixelRatio = window.devicePixelRatio || 1;
  113. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  114. const pixelRatio = devicePixelRatio / backingStoreRatio;
  115. return {
  116. sx: pixelRatio,
  117. sy: pixelRatio,
  118. scaled: pixelRatio !== 1
  119. };
  120. }
  121. function scrollIntoView(element, spot, scrollMatches = false) {
  122. let parent = element.offsetParent;
  123. if (!parent) {
  124. console.error("offsetParent is not set -- cannot scroll");
  125. return;
  126. }
  127. let offsetY = element.offsetTop + element.clientTop;
  128. let offsetX = element.offsetLeft + element.clientLeft;
  129. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  130. offsetY += parent.offsetTop;
  131. offsetX += parent.offsetLeft;
  132. parent = parent.offsetParent;
  133. if (!parent) {
  134. return;
  135. }
  136. }
  137. if (spot) {
  138. if (spot.top !== undefined) {
  139. offsetY += spot.top;
  140. }
  141. if (spot.left !== undefined) {
  142. offsetX += spot.left;
  143. parent.scrollLeft = offsetX;
  144. }
  145. }
  146. parent.scrollTop = offsetY;
  147. }
  148. function watchScroll(viewAreaElement, callback) {
  149. const debounceScroll = function (evt) {
  150. if (rAF) {
  151. return;
  152. }
  153. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  154. rAF = null;
  155. const currentX = viewAreaElement.scrollLeft;
  156. const lastX = state.lastX;
  157. if (currentX !== lastX) {
  158. state.right = currentX > lastX;
  159. }
  160. state.lastX = currentX;
  161. const currentY = viewAreaElement.scrollTop;
  162. const lastY = state.lastY;
  163. if (currentY !== lastY) {
  164. state.down = currentY > lastY;
  165. }
  166. state.lastY = currentY;
  167. callback(state);
  168. });
  169. };
  170. const state = {
  171. right: true,
  172. down: true,
  173. lastX: viewAreaElement.scrollLeft,
  174. lastY: viewAreaElement.scrollTop,
  175. _eventHandler: debounceScroll
  176. };
  177. let rAF = null;
  178. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  179. return state;
  180. }
  181. function parseQueryString(query) {
  182. const parts = query.split("&");
  183. const params = Object.create(null);
  184. for (let i = 0, ii = parts.length; i < ii; ++i) {
  185. const param = parts[i].split("=");
  186. const key = param[0].toLowerCase();
  187. const value = param.length > 1 ? param[1] : null;
  188. params[decodeURIComponent(key)] = decodeURIComponent(value);
  189. }
  190. return params;
  191. }
  192. function binarySearchFirstItem(items, condition) {
  193. let minIndex = 0;
  194. let maxIndex = items.length - 1;
  195. if (maxIndex < 0 || !condition(items[maxIndex])) {
  196. return items.length;
  197. }
  198. if (condition(items[minIndex])) {
  199. return minIndex;
  200. }
  201. while (minIndex < maxIndex) {
  202. const currentIndex = minIndex + maxIndex >> 1;
  203. const currentItem = items[currentIndex];
  204. if (condition(currentItem)) {
  205. maxIndex = currentIndex;
  206. } else {
  207. minIndex = currentIndex + 1;
  208. }
  209. }
  210. return minIndex;
  211. }
  212. function approximateFraction(x) {
  213. if (Math.floor(x) === x) {
  214. return [x, 1];
  215. }
  216. const xinv = 1 / x;
  217. const limit = 8;
  218. if (xinv > limit) {
  219. return [1, limit];
  220. } else if (Math.floor(xinv) === xinv) {
  221. return [1, xinv];
  222. }
  223. const x_ = x > 1 ? xinv : x;
  224. let a = 0,
  225. b = 1,
  226. c = 1,
  227. d = 1;
  228. while (true) {
  229. const p = a + c,
  230. q = b + d;
  231. if (q > limit) {
  232. break;
  233. }
  234. if (x_ <= p / q) {
  235. c = p;
  236. d = q;
  237. } else {
  238. a = p;
  239. b = q;
  240. }
  241. }
  242. let result;
  243. if (x_ - a / b < c / d - x_) {
  244. result = x_ === x ? [a, b] : [b, a];
  245. } else {
  246. result = x_ === x ? [c, d] : [d, c];
  247. }
  248. return result;
  249. }
  250. function roundToDivide(x, div) {
  251. const r = x % div;
  252. return r === 0 ? x : Math.round(x - r + div);
  253. }
  254. function getPageSizeInches({
  255. view,
  256. userUnit,
  257. rotate
  258. }) {
  259. const [x1, y1, x2, y2] = view;
  260. const changeOrientation = rotate % 180 !== 0;
  261. const width = (x2 - x1) / 72 * userUnit;
  262. const height = (y2 - y1) / 72 * userUnit;
  263. return {
  264. width: changeOrientation ? height : width,
  265. height: changeOrientation ? width : height
  266. };
  267. }
  268. function backtrackBeforeAllVisibleElements(index, views, top) {
  269. if (index < 2) {
  270. return index;
  271. }
  272. let elt = views[index].div;
  273. let pageTop = elt.offsetTop + elt.clientTop;
  274. if (pageTop >= top) {
  275. elt = views[index - 1].div;
  276. pageTop = elt.offsetTop + elt.clientTop;
  277. }
  278. for (let i = index - 2; i >= 0; --i) {
  279. elt = views[i].div;
  280. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  281. break;
  282. }
  283. index = i;
  284. }
  285. return index;
  286. }
  287. function getVisibleElements({
  288. scrollEl,
  289. views,
  290. sortByVisibility = false,
  291. horizontal = false,
  292. rtl = false
  293. }) {
  294. const top = scrollEl.scrollTop,
  295. bottom = top + scrollEl.clientHeight;
  296. const left = scrollEl.scrollLeft,
  297. right = left + scrollEl.clientWidth;
  298. function isElementBottomAfterViewTop(view) {
  299. const element = view.div;
  300. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  301. return elementBottom > top;
  302. }
  303. function isElementNextAfterViewHorizontally(view) {
  304. const element = view.div;
  305. const elementLeft = element.offsetLeft + element.clientLeft;
  306. const elementRight = elementLeft + element.clientWidth;
  307. return rtl ? elementLeft < right : elementRight > left;
  308. }
  309. const visible = [],
  310. numViews = views.length;
  311. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  312. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  313. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  314. }
  315. let lastEdge = horizontal ? right : -1;
  316. for (let i = firstVisibleElementInd; i < numViews; i++) {
  317. const view = views[i],
  318. element = view.div;
  319. const currentWidth = element.offsetLeft + element.clientLeft;
  320. const currentHeight = element.offsetTop + element.clientTop;
  321. const viewWidth = element.clientWidth,
  322. viewHeight = element.clientHeight;
  323. const viewRight = currentWidth + viewWidth;
  324. const viewBottom = currentHeight + viewHeight;
  325. if (lastEdge === -1) {
  326. if (viewBottom >= bottom) {
  327. lastEdge = viewBottom;
  328. }
  329. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  330. break;
  331. }
  332. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  333. continue;
  334. }
  335. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  336. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  337. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  338. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  339. const percent = fractionHeight * fractionWidth * 100 | 0;
  340. visible.push({
  341. id: view.id,
  342. x: currentWidth,
  343. y: currentHeight,
  344. view,
  345. percent,
  346. widthPercent: fractionWidth * 100 | 0
  347. });
  348. }
  349. const first = visible[0],
  350. last = visible[visible.length - 1];
  351. if (sortByVisibility) {
  352. visible.sort(function (a, b) {
  353. const pc = a.percent - b.percent;
  354. if (Math.abs(pc) > 0.001) {
  355. return -pc;
  356. }
  357. return a.id - b.id;
  358. });
  359. }
  360. return {
  361. first,
  362. last,
  363. views: visible
  364. };
  365. }
  366. function noContextMenuHandler(evt) {
  367. evt.preventDefault();
  368. }
  369. function normalizeWheelEventDirection(evt) {
  370. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  371. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  372. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  373. delta = -delta;
  374. }
  375. return delta;
  376. }
  377. function normalizeWheelEventDelta(evt) {
  378. let delta = normalizeWheelEventDirection(evt);
  379. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  380. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  381. const MOUSE_PIXELS_PER_LINE = 30;
  382. const MOUSE_LINES_PER_PAGE = 30;
  383. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  384. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  385. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  386. delta /= MOUSE_LINES_PER_PAGE;
  387. }
  388. return delta;
  389. }
  390. function isValidRotation(angle) {
  391. return Number.isInteger(angle) && angle % 90 === 0;
  392. }
  393. function isValidScrollMode(mode) {
  394. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  395. }
  396. function isValidSpreadMode(mode) {
  397. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  398. }
  399. function isPortraitOrientation(size) {
  400. return size.width <= size.height;
  401. }
  402. const WaitOnType = {
  403. EVENT: "event",
  404. TIMEOUT: "timeout"
  405. };
  406. exports.WaitOnType = WaitOnType;
  407. function waitOnEventOrTimeout({
  408. target,
  409. name,
  410. delay = 0
  411. }) {
  412. return new Promise(function (resolve, reject) {
  413. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  414. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  415. }
  416. function handler(type) {
  417. if (target instanceof EventBus) {
  418. target._off(name, eventHandler);
  419. } else {
  420. target.removeEventListener(name, eventHandler);
  421. }
  422. if (timeout) {
  423. clearTimeout(timeout);
  424. }
  425. resolve(type);
  426. }
  427. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  428. if (target instanceof EventBus) {
  429. target._on(name, eventHandler);
  430. } else {
  431. target.addEventListener(name, eventHandler);
  432. }
  433. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  434. const timeout = setTimeout(timeoutHandler, delay);
  435. });
  436. }
  437. const animationStarted = new Promise(function (resolve) {
  438. if (typeof window === "undefined") {
  439. setTimeout(resolve, 20);
  440. return;
  441. }
  442. window.requestAnimationFrame(resolve);
  443. });
  444. exports.animationStarted = animationStarted;
  445. function dispatchDOMEvent(eventName, args = null) {
  446. throw new Error("Not implemented: dispatchDOMEvent");
  447. }
  448. class EventBus {
  449. constructor(options) {
  450. this._listeners = Object.create(null);
  451. }
  452. on(eventName, listener, options = null) {
  453. this._on(eventName, listener, {
  454. external: true,
  455. once: options?.once
  456. });
  457. }
  458. off(eventName, listener, options = null) {
  459. this._off(eventName, listener, {
  460. external: true,
  461. once: options?.once
  462. });
  463. }
  464. dispatch(eventName) {
  465. const eventListeners = this._listeners[eventName];
  466. if (!eventListeners || eventListeners.length === 0) {
  467. return;
  468. }
  469. const args = Array.prototype.slice.call(arguments, 1);
  470. let externalListeners;
  471. for (const {
  472. listener,
  473. external,
  474. once
  475. } of eventListeners.slice(0)) {
  476. if (once) {
  477. this._off(eventName, listener);
  478. }
  479. if (external) {
  480. (externalListeners || (externalListeners = [])).push(listener);
  481. continue;
  482. }
  483. listener.apply(null, args);
  484. }
  485. if (externalListeners) {
  486. for (const listener of externalListeners) {
  487. listener.apply(null, args);
  488. }
  489. externalListeners = null;
  490. }
  491. }
  492. _on(eventName, listener, options = null) {
  493. var _this$_listeners;
  494. const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  495. eventListeners.push({
  496. listener,
  497. external: options?.external === true,
  498. once: options?.once === true
  499. });
  500. }
  501. _off(eventName, listener, options = null) {
  502. const eventListeners = this._listeners[eventName];
  503. if (!eventListeners) {
  504. return;
  505. }
  506. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  507. if (eventListeners[i].listener === listener) {
  508. eventListeners.splice(i, 1);
  509. return;
  510. }
  511. }
  512. }
  513. }
  514. exports.EventBus = EventBus;
  515. function clamp(v, min, max) {
  516. return Math.min(Math.max(v, min), max);
  517. }
  518. class ProgressBar {
  519. constructor(id, {
  520. height,
  521. width,
  522. units
  523. } = {}) {
  524. this.visible = true;
  525. this.div = document.querySelector(id + " .progress");
  526. this.bar = this.div.parentNode;
  527. this.height = height || 100;
  528. this.width = width || 100;
  529. this.units = units || "%";
  530. this.div.style.height = this.height + this.units;
  531. this.percent = 0;
  532. }
  533. _updateBar() {
  534. if (this._indeterminate) {
  535. this.div.classList.add("indeterminate");
  536. this.div.style.width = this.width + this.units;
  537. return;
  538. }
  539. this.div.classList.remove("indeterminate");
  540. const progressSize = this.width * this._percent / 100;
  541. this.div.style.width = progressSize + this.units;
  542. }
  543. get percent() {
  544. return this._percent;
  545. }
  546. set percent(val) {
  547. this._indeterminate = isNaN(val);
  548. this._percent = clamp(val, 0, 100);
  549. this._updateBar();
  550. }
  551. setWidth(viewer) {
  552. if (!viewer) {
  553. return;
  554. }
  555. const container = viewer.parentNode;
  556. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  557. if (scrollbarWidth > 0) {
  558. const doc = document.documentElement;
  559. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  560. }
  561. }
  562. hide() {
  563. if (!this.visible) {
  564. return;
  565. }
  566. this.visible = false;
  567. this.bar.classList.add("hidden");
  568. }
  569. show() {
  570. if (this.visible) {
  571. return;
  572. }
  573. this.visible = true;
  574. this.bar.classList.remove("hidden");
  575. }
  576. }
  577. exports.ProgressBar = ProgressBar;
  578. function moveToEndOfArray(arr, condition) {
  579. const moved = [],
  580. len = arr.length;
  581. let write = 0;
  582. for (let read = 0; read < len; ++read) {
  583. if (condition(arr[read])) {
  584. moved.push(arr[read]);
  585. } else {
  586. arr[write] = arr[read];
  587. ++write;
  588. }
  589. }
  590. for (let read = 0; write < len; ++read, ++write) {
  591. arr[write] = moved[read];
  592. }
  593. }
  594. function getActiveOrFocusedElement() {
  595. let curRoot = document;
  596. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  597. while (curActiveOrFocused?.shadowRoot) {
  598. curRoot = curActiveOrFocused.shadowRoot;
  599. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  600. }
  601. return curActiveOrFocused;
  602. }
  603. function apiPageLayoutToSpreadMode(layout) {
  604. switch (layout) {
  605. case "SinglePage":
  606. case "OneColumn":
  607. return SpreadMode.NONE;
  608. case "TwoColumnLeft":
  609. case "TwoPageLeft":
  610. return SpreadMode.ODD;
  611. case "TwoColumnRight":
  612. case "TwoPageRight":
  613. return SpreadMode.EVEN;
  614. }
  615. return SpreadMode.NONE;
  616. }
  617. function apiPageModeToSidebarView(mode) {
  618. switch (mode) {
  619. case "UseNone":
  620. return SidebarView.NONE;
  621. case "UseThumbs":
  622. return SidebarView.THUMBS;
  623. case "UseOutlines":
  624. return SidebarView.OUTLINE;
  625. case "UseAttachments":
  626. return SidebarView.ATTACHMENTS;
  627. case "UseOC":
  628. return SidebarView.LAYERS;
  629. }
  630. return SidebarView.NONE;
  631. }