pagedjs
Version:
Chunks up a document into paged media flows and applies print styles
81 lines (80 loc) • 5.07 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _handler = _interopRequireDefault(require("../handler.cjs"));
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
var Lists = /*#__PURE__*/function (_Handler) {
(0, _inherits2["default"])(Lists, _Handler);
var _super = _createSuper(Lists);
function Lists(chunker, polisher, caller) {
(0, _classCallCheck2["default"])(this, Lists);
return _super.call(this, chunker, polisher, caller);
}
(0, _createClass2["default"])(Lists, [{
key: "afterParsed",
value: function afterParsed(content) {
var orderedLists = content.querySelectorAll("ol");
var _iterator = _createForOfIteratorHelper(orderedLists),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var list = _step.value;
this.addDataNumbers(list);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
}, {
key: "afterPageLayout",
value: function afterPageLayout(pageElement, page, breakToken, chunker) {
var orderedLists = pageElement.getElementsByTagName("ol");
var _iterator2 = _createForOfIteratorHelper(orderedLists),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var list = _step2.value;
if (list.firstElementChild) {
list.start = list.firstElementChild.dataset.itemNum;
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
}, {
key: "addDataNumbers",
value: function addDataNumbers(list) {
var start = 1;
if (list.hasAttribute("start")) {
start = parseInt(list.getAttribute("start"), 10);
if (isNaN(start)) {
start = 1;
}
}
var items = list.children;
for (var i = 0; i < items.length; i++) {
items[i].setAttribute("data-item-num", i + start);
}
}
}]);
return Lists;
}(_handler["default"]);
var _default = Lists;
exports["default"] = _default;
;