暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

card.ts 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. module RpgCards {
  2. function normalizeTag(tag: string): string {
  3. return tag.trim().toLowerCase();
  4. }
  5. function splitParams(value: string): string[] {
  6. return value.split("|").map(function (str) { return str.trim(); });
  7. }
  8. export class Options {
  9. foreground_color: string;
  10. background_color: string;
  11. empty_color: string;
  12. default_color: string;
  13. default_icon: string;
  14. default_title_size: string;
  15. page_size: string;
  16. page_rows: number;
  17. page_columns: number;
  18. card_arrangement: string;
  19. card_size: string;
  20. card_count: number;
  21. icon_inline: boolean;
  22. constructor() {
  23. this.foreground_color = "white";
  24. this.background_color = "white";
  25. this.empty_color = "black";
  26. this.default_color = "black";
  27. this.default_icon = "ace";
  28. this.default_title_size = "13";
  29. this.page_size = "A4";
  30. this.page_rows = 3;
  31. this.page_columns = 3;
  32. this.card_arrangement = "doublesided";
  33. this.card_size = "25x35";
  34. this.card_count = null;
  35. this.icon_inline = true;
  36. }
  37. }
  38. export class Card {
  39. count: number;
  40. title: string;
  41. title_size: string;
  42. color: string;
  43. color_front: string;
  44. color_back: string;
  45. icon: string;
  46. icon_front: string;
  47. icon_back: string;
  48. contents: string[];
  49. tags: string[];
  50. userData: any;
  51. constructor() {
  52. this.count = 1;
  53. this.title = "New card";
  54. this.title_size = null;
  55. this.color = null;
  56. this.color_front = null;
  57. this.color_back = null;
  58. this.icon = null;
  59. this.icon_front = null;
  60. this.icon_back = null;
  61. this.contents = [];
  62. this.tags = [];
  63. this.userData = null;
  64. }
  65. static fromJSON(json: any): Card {
  66. var result = new Card;
  67. result.count = json.count || 1;
  68. result.title = json.title || "";
  69. result.title_size = json.title_size || null;
  70. result.color = json.color || null;
  71. result.color_front = json.color_front || null;
  72. result.color_back = json.color_back || null;
  73. result.icon = json.icon || null;
  74. result.icon_front = json.icon_front || null;
  75. result.icon_back = json.icon_back || null;
  76. result.contents = json.contents || [];
  77. result.tags = json.tags || [];
  78. return result;
  79. }
  80. public toJSON(): any {
  81. return {
  82. count: this.count,
  83. title: this.title,
  84. title_size: this.title_size,
  85. color: this.color,
  86. color_front: this.color_front,
  87. color_back: this.color_back,
  88. icon: this.icon,
  89. icon_front: this.icon_front,
  90. icon_back: this.icon_back,
  91. contents: this.contents.slice(),
  92. tags: this.tags.slice()
  93. }
  94. }
  95. public duplicate(): Card {
  96. var result = Card.fromJSON(this.toJSON());
  97. result.title += " (Copy)";
  98. return result;
  99. }
  100. public hasTag(tag: string): boolean {
  101. var index = this.tags.indexOf(normalizeTag(tag));
  102. return index > -1;
  103. }
  104. public addTag(tag: string): void {
  105. if (!this.hasTag(tag)) {
  106. this.tags.push(normalizeTag(tag));
  107. }
  108. }
  109. public removeTag(tag: string): void {
  110. var ntag = normalizeTag(tag);
  111. this.tags = this.tags.filter(function (t) {
  112. return ntag != t;
  113. });
  114. }
  115. public getTitle(options: Options): string {
  116. return this.title || "";
  117. }
  118. public getTitleSize(options: Options): string {
  119. return this.title_size || options.default_title_size || "13";
  120. }
  121. public getColorFront(options: Options): string {
  122. return this.color_front || this.color || options.default_color || "black";
  123. }
  124. public getColorBack(options: Options): string {
  125. return this.color_back || this.color || options.default_color || "black";
  126. }
  127. public getIconFront(options: Options): string {
  128. return this.icon_front || this.icon || options.default_icon || "ace";
  129. }
  130. public getIconBack(options: Options): string {
  131. return this.icon_back || this.icon || options.default_icon || "ace";
  132. }
  133. };
  134. interface CardAction {
  135. fn: string;
  136. card: Card;
  137. ref: Card;
  138. }
  139. export class CardDeck {
  140. cards: Card[];
  141. private _actions: CardAction[];
  142. constructor() {
  143. this.cards = [];
  144. this._actions = [];
  145. }
  146. public toJSON(): any {
  147. return this.cards.map((card) => card.toJSON());
  148. }
  149. public static fromJSON(data: any): CardDeck {
  150. if (Array.isArray(data)) {
  151. var result = new CardDeck;
  152. for (var i = 0; i < data.length; ++i) {
  153. result.cards.push(Card.fromJSON(data[i]));
  154. }
  155. return result;
  156. } else {
  157. throw new Error("Invalid data");
  158. }
  159. }
  160. public addCards(cards: Card[]): void {
  161. cards.forEach((card) => {
  162. this._actions.push({fn:"add", card: card, ref: null});
  163. });
  164. }
  165. public addNewCard(): Card {
  166. var newCard = new Card();
  167. this._actions.push({ fn: "add", card: newCard, ref: null });
  168. return newCard;
  169. }
  170. public duplicateCard(card: Card): Card {
  171. var newCard = card.duplicate();
  172. this._actions.push({ fn: "add", card: newCard, ref: card });
  173. return newCard;
  174. }
  175. public deleteCard(card: Card): void {
  176. this._actions.push({ fn: "del", card: card, ref: null });
  177. }
  178. public commit() {
  179. for (var i = 0; i < this._actions.length; ++i) {
  180. var action = this._actions[i];
  181. if (action.fn === "add") {
  182. var index = this.cards.indexOf(action.ref);
  183. if (index > -1) {
  184. this.cards.splice(index + 1, 0, action.card);
  185. } else {
  186. this.cards.push(action.card);
  187. }
  188. } else if (action.fn === "del") {
  189. var index = this.cards.indexOf(action.card);
  190. if (index > -1) {
  191. this.cards.splice(index, 1);
  192. }
  193. }
  194. }
  195. this._actions = [];
  196. }
  197. }
  198. type ContentGeneratorFunction = (params: string[], card: Card, options: Options, ind: string, ind0: string) => string;
  199. type CardGeneratorFunction = (card: Card, options: Options, ind: string, ind0: string) => string;
  200. export class CardHtmlGenerator {
  201. constructor() {
  202. }
  203. private _icon(src: string, ind: string, ind0: string): string {
  204. return ind + '<card-icon src="/icons/' + src + '.svg"></card-icon>\n';
  205. }
  206. private _subtitle(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  207. var text = params[0] || "";
  208. return ind + '<card-subtitle>' + text + '</card-subtitle>\n';
  209. }
  210. private _ruler(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  211. return ind + '<card-rule></card-rule>\n';
  212. }
  213. private _boxes(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  214. var count = params[0] || 1;
  215. var size = params[1] || 3;
  216. return ind + '<card-boxes size="' + size + '" count="' + count + '"></card-boxes>\n';
  217. }
  218. private _property(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  219. var header = params[0] || "";
  220. var text = params[1] || "";
  221. var result = "";
  222. result += ind + '<card-property>\n';
  223. result += ind + ind0 + '<h4>' + header + '</h4>\n';
  224. result += ind + ind0 + '<p>' + text + '</p>\n';
  225. result += ind + '</card-property>\n';
  226. return result;
  227. }
  228. private _description(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  229. var header = params[0] || "";
  230. var text = params[1] || "";
  231. var result = "";
  232. result += ind + '<card-description>\n';
  233. result += ind + ind0 + '<h4>' + header + '</h4>\n';
  234. result += ind + ind0 + '<p>' + text + '</p>\n';
  235. result += ind + '</card-description>\n';
  236. return result;
  237. }
  238. private _text(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  239. var text = params[0] || "";
  240. var result = "";
  241. result += ind + '<card-description>\n';
  242. result += ind + ind0 + '<p>' + text + '</p>\n';
  243. result += ind + '</card-description>\n';
  244. return result;
  245. }
  246. private _dndstats(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  247. var stats = ["str", "dex", "con", "int", "wis", "cha"];
  248. var result = "";
  249. result += ind + '<card-dndstats';
  250. for (var i = 0; i < stats.length; ++i) {
  251. var value = parseInt(params[i], 10) || "";
  252. var stat = stats[i];
  253. result += ' ' + stat + '="' + value + '"';
  254. }
  255. result += '></card-dndstats>\n';
  256. return result;
  257. }
  258. private _bullet(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  259. var text = params[0] || "";
  260. return ind + '<card-bullet>' + text + '</card-bullet>\n';
  261. }
  262. private _section(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  263. var text = params[0] || "";
  264. return ind + '<card-section>' + text + '</card-section>\n';
  265. }
  266. private _fill(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  267. var size = params[0] || "1";
  268. return ind + '<card-fill size="' + size + '"></card-fill>\n';
  269. }
  270. private _unknown(params: string[], card: Card, options: Options, ind: string, ind0: string): string {
  271. var text = params.join(' | ');
  272. return ind + '<card-description><p>' + text + '</p></card-description>\n';
  273. }
  274. private _empty(params: string[], card: Card, options: Options, ind: string, ind0: string) {
  275. return '';
  276. }
  277. private _contents(contents: string[], card: Card, options: Options, ind: string, ind0: string): string {
  278. var result = "";
  279. result += ind + '<card-contents>\n';
  280. result += contents.map((value) => {
  281. var parts = splitParams(value);
  282. var name = parts[0];
  283. var params = parts.splice(1);
  284. var generator: ContentGeneratorFunction = null;
  285. switch (name) {
  286. case "subtitle": generator = this._subtitle; break;
  287. case "property": generator = this._property; break;
  288. case "rule": generator = this._ruler; break;
  289. case "ruler": generator = this._ruler; break;
  290. case "boxes": generator = this._boxes; break;
  291. case "description": generator = this._description; break;
  292. case "dndstats": generator = this._dndstats; break;
  293. case "text": generator = this._text; break;
  294. case "bullet": generator = this._bullet; break;
  295. case "fill": generator = this._fill; break;
  296. case "section": generator = this._section; break;
  297. case "disabled": generator = this._empty; break;
  298. case "": generator = this._empty; break;
  299. default: return this._unknown(parts, card, options, ind, ind0);
  300. }
  301. return generator(params, card, options, ind + ind0, ind);
  302. }).join("\n");
  303. result += ind + '</card-contents>\n';
  304. return result;
  305. }
  306. private _title(card: Card, options: Options, ind: string, ind0: string): string {
  307. var title = card.getTitle(options);
  308. var title_size = card.getTitleSize(options)
  309. var icon = card.getIconFront(options);
  310. var result = "";
  311. result += ind + '<card-title size="' + title_size + '">\n';
  312. result += ind + ind0 + '<h1>' + title + '</h1>\n';
  313. result += ind + ind0 + '<h2>' + "" + '</h2>\n';
  314. result += this._icon(icon, ind + ind0, ind0);
  315. result += ind + '</card-title>\n';
  316. return result;
  317. }
  318. private _card_front(card: Card, options: Options, ind: string, ind0: string): string {
  319. var result = "";
  320. result += this._title(card, options, ind + ind0, ind0);
  321. result += this._contents(card.contents, card, options, ind + ind0, ind0);
  322. return result;
  323. }
  324. private _card_back(card: Card, options: Options, ind: string, ind0: string): string {
  325. var icon = card.getIconBack(options);
  326. var result = "";
  327. result += ind + '<card-back>\n';
  328. result += this._icon(icon, ind + ind0, ind);
  329. result += ind + '</card-back>\n';
  330. return result;
  331. }
  332. private _card_empty(options: Options, ind: string, ind0: string): string {
  333. var result = "";
  334. result += ind + '<card-contents>\n';
  335. result += ind + '</card-contents>\n';
  336. return result;
  337. }
  338. private _card(options: Options, ind: string, ind0: string, content: string, color: string): string {
  339. var size = options.card_size || "25x35";
  340. var result = "";
  341. result += ind + '<rpg-card color="' + color + '" size="' + size + '">\n';
  342. result += content;
  343. result += ind + '</rpg-card>\n';
  344. return result;
  345. }
  346. /** Generates HTML for the front side of the given card */
  347. public card_front(card: Card, options: Options, indent: string): string {
  348. var content = this._card_front(card, options, "", indent);
  349. return this._card(options, "", indent, content, card.getColorFront(options));
  350. }
  351. /** Generates HTML for the back side of the given card */
  352. public card_back(card: Card, options: Options, indent: string): string {
  353. var content = this._card_back(card, options, "", indent);
  354. return this._card(options, "", indent, content, card.getColorBack(options));
  355. }
  356. /** Generates HTML for an empty given card */
  357. public card_empty(options: Options, indent: string): string {
  358. var content = this._card_empty(options, "", indent);
  359. return this._card(options, "", indent, content, options.empty_color);
  360. }
  361. }
  362. class CardPage<T> {
  363. rows: number;
  364. cols: number;
  365. cards: T[];
  366. constructor(rows: number, cols: number) {
  367. this.rows = rows;
  368. this.cols = cols;
  369. this.cards = [];
  370. }
  371. /** Returns an empty page with the same dimensions */
  372. public newPage(): CardPage<T> {
  373. return new CardPage<T>(this.rows, this.cols);
  374. }
  375. private _posToIndex(row: number, col: number): number {
  376. return row * this.cols + col;
  377. }
  378. /** Adds one card to the page */
  379. public addCard(card: T): void {
  380. if (this.capacity() === 0) {
  381. throw new Error("This page is full.");
  382. }
  383. this.cards.push(card);
  384. }
  385. /**
  386. Adds several copies of a card to the page.
  387. Returns the number of copies that did not fit on the page.
  388. */
  389. public addCards(card: T, count: number): number {
  390. while (this.capacity() > 0 && count > 0) {
  391. this.addCard(card);
  392. --count;
  393. }
  394. return count;
  395. }
  396. /** Fills all remaining slots on the current row with the given card */
  397. public fillRow(card: T): void {
  398. while (this.capacityRow() > 0) {
  399. this.addCard(card);
  400. }
  401. }
  402. /** Fills all remaining slots on the page with empty cards */
  403. public fillPage(card: T): void {
  404. while (this.capacity() > 0) {
  405. this.addCard(card);
  406. }
  407. }
  408. /** Empty slots on the page */
  409. public capacity(): number {
  410. return this.rows * this.cols - this.cards.length;
  411. }
  412. /** Empty slots on the current line */
  413. public capacityRow(): number {
  414. return this.capacity() % this.cols;
  415. }
  416. /** Flip card slots horizontally */
  417. public flipH() {
  418. if (this.capacity() > 0) {
  419. throw new Error("Cannot perform this operation while the page is not full");
  420. }
  421. for (var r = 0; r < this.rows; ++r) {
  422. for (var c = 0; c < Math.floor(this.cols / 2); ++c) {
  423. var indexL = this._posToIndex(r, c);
  424. var indexR = this._posToIndex(r, this.cols - c - 1);
  425. var cardL = this.cards[indexL];
  426. var cardR = this.cards[indexR];
  427. this.cards[indexL] = cardR;
  428. this.cards[indexR] = cardL;
  429. }
  430. }
  431. }
  432. }
  433. class CardPageSet<T> {
  434. rows: number;
  435. cols: number;
  436. pages: CardPage<T>[];
  437. constructor(rows: number, cols: number) {
  438. this.rows = rows;
  439. this.cols = cols;
  440. this.pages = [];
  441. }
  442. public lastPage(): CardPage<T> {
  443. if (this.pages.length === 0) {
  444. return null;
  445. } else {
  446. return this.pages[this.pages.length - 1];
  447. }
  448. }
  449. public addPage(): CardPage<T> {
  450. var newPage = new CardPage<T>(this.rows, this.cols);
  451. this.pages.push(newPage);
  452. return newPage;
  453. }
  454. /**
  455. Adds one card to the last page.
  456. Adds a new pages if necessary.
  457. */
  458. public addCard(card: T): void {
  459. var page = this.lastPage();
  460. if (page === null || page.capacity() === 0) {
  461. page = this.addPage();
  462. }
  463. page.addCard(card);
  464. }
  465. /**
  466. Adds several copies of a card to the last page.
  467. Adds new pages if necessary.
  468. */
  469. public addCards(card: T, count: number): void {
  470. for (var i = 0; i < count; ++i) {
  471. this.addCard(card);
  472. }
  473. }
  474. public forEach(fn: (page: CardPage<T>)=>void) {
  475. this.pages.forEach(fn);
  476. }
  477. public merge(other: CardPageSet<T>): CardPageSet<T> {
  478. if (this.pages.length !== other.pages.length) {
  479. throw new Error("This function is only for merging two equally sized page sets");
  480. }
  481. var result = new CardPageSet<T>(this.rows, this.cols);
  482. for (var i = 0; i < this.pages.length; ++i) {
  483. result.pages.push(this.pages[i]);
  484. result.pages.push(other.pages[i]);
  485. }
  486. return result;
  487. }
  488. }
  489. export class PageHtmlGenerator {
  490. indent: string;
  491. constructor() {
  492. this.indent = " ";
  493. }
  494. private _pageColor(page: number, options: Options): string {
  495. if ((options.card_arrangement == "doublesided") && (page % 2 == 1)) {
  496. return options.background_color;
  497. } else {
  498. return options.foreground_color;
  499. }
  500. }
  501. private _wrap(pageSet: CardPageSet<string>, options: Options) {
  502. var size = options.page_size || "A4";
  503. var result = "";
  504. for (var i = 0; i < pageSet.pages.length; ++i) {
  505. var page = pageSet.pages[i];
  506. var style = 'style="background-color:' + this._pageColor(i, options) + '"';
  507. result += '<page class="page page-preview" size="' + size + '" ' + style + '>\n';
  508. result += page.cards.join("");
  509. result += '</page>\n';
  510. }
  511. return result;
  512. }
  513. private _generatePagesDoublesided(cards: Card[], options: Options, rows: number, cols: number, generator: CardHtmlGenerator): CardPageSet<string> {
  514. var front_pages: CardPageSet<string> = new CardPageSet<string>(rows, cols);
  515. var back_pages: CardPageSet<string> = new CardPageSet<string>(rows, cols);
  516. var empty = generator.card_empty(options, this.indent);
  517. // Fill pages with cards
  518. for (var i = 0; i < cards.length; ++i) {
  519. var card = cards[i];
  520. var front = generator.card_front(card, options, this.indent);
  521. var back = generator.card_back(card, options, this.indent);
  522. front_pages.addCards(front, card.count);
  523. back_pages.addCards(back, card.count);
  524. }
  525. // Fill empty slots
  526. front_pages.forEach((page) => page.fillPage(empty));
  527. back_pages.forEach((page) => page.fillPage(empty));
  528. // Shuffle back cards so that they line up with their corresponding front cards
  529. back_pages.forEach((page) => page.flipH());
  530. // Interleave front and back pages so that we can print double-sided
  531. return front_pages.merge(back_pages);
  532. }
  533. private _generatePagesFrontOnly(cards: Card[], options: Options, rows: number, cols: number, generator: CardHtmlGenerator): CardPageSet<string> {
  534. var pages: CardPageSet<string> = new CardPageSet<string>(rows, cols);
  535. var empty = generator.card_empty(options, this.indent);
  536. // Fill pages with cards
  537. for (var i = 0; i < cards.length; ++i) {
  538. var card = cards[i];
  539. var front = generator.card_front(card, options, this.indent);
  540. pages.addCards(front, card.count);
  541. }
  542. // Fill empty slots
  543. pages.forEach((page) => page.fillPage(empty));
  544. return pages;
  545. }
  546. private _generatePagesSideBySide(cards: Card[], options: Options, rows: number, cols: number, generator: CardHtmlGenerator): CardPageSet<string> {
  547. if (cols < 2) {
  548. throw new Error("Need at least two columns for side-by-side");
  549. }
  550. var pages: CardPageSet<string> = new CardPageSet<string>(rows, cols);
  551. var empty = generator.card_empty(options, this.indent);
  552. // Fill pages with cards (two at a time)
  553. for (var i = 0; i < cards.length; ++i) {
  554. var card = cards[i];
  555. var front = generator.card_front(card, options, this.indent);
  556. var back = generator.card_back(card, options, this.indent);
  557. for (var j = 0; j < card.count; ++j) {
  558. if (pages.pages.length > 0 && pages.lastPage().capacityRow() < 2) {
  559. pages.lastPage().fillRow(empty);
  560. }
  561. pages.addCard(front);
  562. pages.addCard(back);
  563. }
  564. }
  565. // Fill empty slots
  566. pages.forEach((page) => page.fillPage(empty));
  567. return pages;
  568. }
  569. private _generatePages(cards: Card[], options: Options, rows: number, cols: number, generator: CardHtmlGenerator): CardPageSet<string> {
  570. switch (options.card_arrangement) {
  571. case "doublesided": return this._generatePagesDoublesided(cards, options, rows, cols, generator);
  572. case "front_only": return this._generatePagesFrontOnly(cards, options, rows, cols, generator);
  573. case "side_by_side": return this._generatePagesSideBySide(cards, options, rows, cols, generator);
  574. default: throw new Error("Unknown card arrangement");
  575. }
  576. }
  577. private _generateStyle(options) {
  578. var size = "a4";
  579. switch (options.page_size) {
  580. case "A3": size = "A3 portrait"; break;
  581. case "A4": size = "210mm 297mm"; break;
  582. case "A5": size = "A5 portrait"; break;
  583. case "Letter": size = "letter portrait"; break;
  584. case "25x35": size = "2.5in 3.5in"; break;
  585. default: size = "auto";
  586. }
  587. var result = "";
  588. result += "<style>\n";
  589. result += "@page {\n";
  590. result += " margin: 0;\n";
  591. result += " size:" + size + ";\n";
  592. result += " -webkit-print-color-adjust: exact;\n";
  593. result += "}\n";
  594. result += "</style>\n";
  595. return result;
  596. }
  597. public generateHtml(cards: Card[], options: Options) {
  598. options = options || new Options();
  599. var rows = options.page_rows || 3;
  600. var cols = options.page_columns || 3;
  601. // Generate the HTML for each card
  602. var generator = new CardHtmlGenerator();
  603. var pages: CardPageSet<string> = this._generatePages(cards, options, rows, cols, generator);
  604. // Wrap all pages in a <page> element
  605. var document = this._wrap(pages, options);
  606. // Generate the HTML for the page layout
  607. var style = this._generateStyle(options);
  608. // Wrap all pages in a <page> element and add CSS for the page size
  609. var result = "";
  610. result += style
  611. result += document;
  612. return result;
  613. }
  614. public insertInto(cards: Card[], options: Options, container: HTMLElement) {
  615. // Clear the previous content of the document
  616. while (container.hasChildNodes()) {
  617. container.removeChild(container.lastChild);
  618. }
  619. // Insert the HTML
  620. var html = this.generateHtml(cards, options);
  621. container.innerHTML = html;
  622. }
  623. }
  624. }