ui_utils.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = exports.AutomationEventBus = exports.animationStarted = void 0;
  49. const DEFAULT_SCALE_VALUE = "auto";
  50. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  51. const DEFAULT_SCALE = 1.0;
  52. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  53. const DEFAULT_SCALE_DELTA = 1.1;
  54. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  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 params = new Map();
  183. for (const part of query.split("&")) {
  184. const param = part.split("="),
  185. key = param[0].toLowerCase(),
  186. value = param.length > 1 ? param[1] : "";
  187. params.set(decodeURIComponent(key), decodeURIComponent(value));
  188. }
  189. return params;
  190. }
  191. function binarySearchFirstItem(items, condition) {
  192. let minIndex = 0;
  193. let maxIndex = items.length - 1;
  194. if (maxIndex < 0 || !condition(items[maxIndex])) {
  195. return items.length;
  196. }
  197. if (condition(items[minIndex])) {
  198. return minIndex;
  199. }
  200. while (minIndex < maxIndex) {
  201. const currentIndex = minIndex + maxIndex >> 1;
  202. const currentItem = items[currentIndex];
  203. if (condition(currentItem)) {
  204. maxIndex = currentIndex;
  205. } else {
  206. minIndex = currentIndex + 1;
  207. }
  208. }
  209. return minIndex;
  210. }
  211. function approximateFraction(x) {
  212. if (Math.floor(x) === x) {
  213. return [x, 1];
  214. }
  215. const xinv = 1 / x;
  216. const limit = 8;
  217. if (xinv > limit) {
  218. return [1, limit];
  219. } else if (Math.floor(xinv) === xinv) {
  220. return [1, xinv];
  221. }
  222. const x_ = x > 1 ? xinv : x;
  223. let a = 0,
  224. b = 1,
  225. c = 1,
  226. d = 1;
  227. while (true) {
  228. const p = a + c,
  229. q = b + d;
  230. if (q > limit) {
  231. break;
  232. }
  233. if (x_ <= p / q) {
  234. c = p;
  235. d = q;
  236. } else {
  237. a = p;
  238. b = q;
  239. }
  240. }
  241. let result;
  242. if (x_ - a / b < c / d - x_) {
  243. result = x_ === x ? [a, b] : [b, a];
  244. } else {
  245. result = x_ === x ? [c, d] : [d, c];
  246. }
  247. return result;
  248. }
  249. function roundToDivide(x, div) {
  250. const r = x % div;
  251. return r === 0 ? x : Math.round(x - r + div);
  252. }
  253. function getPageSizeInches({
  254. view,
  255. userUnit,
  256. rotate
  257. }) {
  258. const [x1, y1, x2, y2] = view;
  259. const changeOrientation = rotate % 180 !== 0;
  260. const width = (x2 - x1) / 72 * userUnit;
  261. const height = (y2 - y1) / 72 * userUnit;
  262. return {
  263. width: changeOrientation ? height : width,
  264. height: changeOrientation ? width : height
  265. };
  266. }
  267. function backtrackBeforeAllVisibleElements(index, views, top) {
  268. if (index < 2) {
  269. return index;
  270. }
  271. let elt = views[index].div;
  272. let pageTop = elt.offsetTop + elt.clientTop;
  273. if (pageTop >= top) {
  274. elt = views[index - 1].div;
  275. pageTop = elt.offsetTop + elt.clientTop;
  276. }
  277. for (let i = index - 2; i >= 0; --i) {
  278. elt = views[i].div;
  279. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  280. break;
  281. }
  282. index = i;
  283. }
  284. return index;
  285. }
  286. function getVisibleElements({
  287. scrollEl,
  288. views,
  289. sortByVisibility = false,
  290. horizontal = false,
  291. rtl = false
  292. }) {
  293. const top = scrollEl.scrollTop,
  294. bottom = top + scrollEl.clientHeight;
  295. const left = scrollEl.scrollLeft,
  296. right = left + scrollEl.clientWidth;
  297. function isElementBottomAfterViewTop(view) {
  298. const element = view.div;
  299. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  300. return elementBottom > top;
  301. }
  302. function isElementNextAfterViewHorizontally(view) {
  303. const element = view.div;
  304. const elementLeft = element.offsetLeft + element.clientLeft;
  305. const elementRight = elementLeft + element.clientWidth;
  306. return rtl ? elementLeft < right : elementRight > left;
  307. }
  308. const visible = [],
  309. numViews = views.length;
  310. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  311. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  312. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  313. }
  314. let lastEdge = horizontal ? right : -1;
  315. for (let i = firstVisibleElementInd; i < numViews; i++) {
  316. const view = views[i],
  317. element = view.div;
  318. const currentWidth = element.offsetLeft + element.clientLeft;
  319. const currentHeight = element.offsetTop + element.clientTop;
  320. const viewWidth = element.clientWidth,
  321. viewHeight = element.clientHeight;
  322. const viewRight = currentWidth + viewWidth;
  323. const viewBottom = currentHeight + viewHeight;
  324. if (lastEdge === -1) {
  325. if (viewBottom >= bottom) {
  326. lastEdge = viewBottom;
  327. }
  328. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  329. break;
  330. }
  331. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  332. continue;
  333. }
  334. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  335. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  336. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  337. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  338. const percent = fractionHeight * fractionWidth * 100 | 0;
  339. visible.push({
  340. id: view.id,
  341. x: currentWidth,
  342. y: currentHeight,
  343. view,
  344. percent,
  345. widthPercent: fractionWidth * 100 | 0
  346. });
  347. }
  348. const first = visible[0],
  349. last = visible[visible.length - 1];
  350. if (sortByVisibility) {
  351. visible.sort(function (a, b) {
  352. const pc = a.percent - b.percent;
  353. if (Math.abs(pc) > 0.001) {
  354. return -pc;
  355. }
  356. return a.id - b.id;
  357. });
  358. }
  359. return {
  360. first,
  361. last,
  362. views: visible
  363. };
  364. }
  365. function noContextMenuHandler(evt) {
  366. evt.preventDefault();
  367. }
  368. function normalizeWheelEventDirection(evt) {
  369. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  370. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  371. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  372. delta = -delta;
  373. }
  374. return delta;
  375. }
  376. function normalizeWheelEventDelta(evt) {
  377. let delta = normalizeWheelEventDirection(evt);
  378. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  379. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  380. const MOUSE_PIXELS_PER_LINE = 30;
  381. const MOUSE_LINES_PER_PAGE = 30;
  382. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  383. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  384. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  385. delta /= MOUSE_LINES_PER_PAGE;
  386. }
  387. return delta;
  388. }
  389. function isValidRotation(angle) {
  390. return Number.isInteger(angle) && angle % 90 === 0;
  391. }
  392. function isValidScrollMode(mode) {
  393. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  394. }
  395. function isValidSpreadMode(mode) {
  396. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  397. }
  398. function isPortraitOrientation(size) {
  399. return size.width <= size.height;
  400. }
  401. const WaitOnType = {
  402. EVENT: "event",
  403. TIMEOUT: "timeout"
  404. };
  405. exports.WaitOnType = WaitOnType;
  406. function waitOnEventOrTimeout({
  407. target,
  408. name,
  409. delay = 0
  410. }) {
  411. return new Promise(function (resolve, reject) {
  412. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  413. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  414. }
  415. function handler(type) {
  416. if (target instanceof EventBus) {
  417. target._off(name, eventHandler);
  418. } else {
  419. target.removeEventListener(name, eventHandler);
  420. }
  421. if (timeout) {
  422. clearTimeout(timeout);
  423. }
  424. resolve(type);
  425. }
  426. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  427. if (target instanceof EventBus) {
  428. target._on(name, eventHandler);
  429. } else {
  430. target.addEventListener(name, eventHandler);
  431. }
  432. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  433. const timeout = setTimeout(timeoutHandler, delay);
  434. });
  435. }
  436. const animationStarted = new Promise(function (resolve) {
  437. if (typeof window === "undefined") {
  438. setTimeout(resolve, 20);
  439. return;
  440. }
  441. window.requestAnimationFrame(resolve);
  442. });
  443. exports.animationStarted = animationStarted;
  444. class EventBus {
  445. constructor() {
  446. this._listeners = Object.create(null);
  447. }
  448. on(eventName, listener, options = null) {
  449. this._on(eventName, listener, {
  450. external: true,
  451. once: options?.once
  452. });
  453. }
  454. off(eventName, listener, options = null) {
  455. this._off(eventName, listener, {
  456. external: true,
  457. once: options?.once
  458. });
  459. }
  460. dispatch(eventName, data) {
  461. const eventListeners = this._listeners[eventName];
  462. if (!eventListeners || eventListeners.length === 0) {
  463. return;
  464. }
  465. let externalListeners;
  466. for (const {
  467. listener,
  468. external,
  469. once
  470. } of eventListeners.slice(0)) {
  471. if (once) {
  472. this._off(eventName, listener);
  473. }
  474. if (external) {
  475. (externalListeners ||= []).push(listener);
  476. continue;
  477. }
  478. listener(data);
  479. }
  480. if (externalListeners) {
  481. for (const listener of externalListeners) {
  482. listener(data);
  483. }
  484. externalListeners = null;
  485. }
  486. }
  487. _on(eventName, listener, options = null) {
  488. const eventListeners = this._listeners[eventName] ||= [];
  489. eventListeners.push({
  490. listener,
  491. external: options?.external === true,
  492. once: options?.once === true
  493. });
  494. }
  495. _off(eventName, listener, options = null) {
  496. const eventListeners = this._listeners[eventName];
  497. if (!eventListeners) {
  498. return;
  499. }
  500. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  501. if (eventListeners[i].listener === listener) {
  502. eventListeners.splice(i, 1);
  503. return;
  504. }
  505. }
  506. }
  507. }
  508. exports.EventBus = EventBus;
  509. class AutomationEventBus extends EventBus {
  510. dispatch(eventName, data) {
  511. throw new Error("Not implemented: AutomationEventBus.dispatch");
  512. }
  513. }
  514. exports.AutomationEventBus = AutomationEventBus;
  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. }