BboxConfiguration.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.BboxConfiguration = exports.BboxMethods = void 0;
  7. var Configuration_js_1 = require("../Configuration.js");
  8. var SymbolMap_js_1 = require("../SymbolMap.js");
  9. var TexError_js_1 = __importDefault(require("../TexError.js"));
  10. exports.BboxMethods = {};
  11. exports.BboxMethods.BBox = function (parser, name) {
  12. var bbox = parser.GetBrackets(name, '');
  13. var math = parser.ParseArg(name);
  14. var parts = bbox.split(/,/);
  15. var def, background, style;
  16. for (var i = 0, m = parts.length; i < m; i++) {
  17. var part = parts[i].trim();
  18. var match = part.match(/^(\.\d+|\d+(\.\d*)?)(pt|em|ex|mu|px|in|cm|mm)$/);
  19. if (match) {
  20. if (def) {
  21. throw new TexError_js_1.default('MultipleBBoxProperty', '%1 specified twice in %2', 'Padding', name);
  22. }
  23. var pad = BBoxPadding(match[1] + match[3]);
  24. if (pad) {
  25. def = {
  26. height: '+' + pad,
  27. depth: '+' + pad,
  28. lspace: pad,
  29. width: '+' + (2 * parseInt(match[1], 10)) + match[3]
  30. };
  31. }
  32. }
  33. else if (part.match(/^([a-z0-9]+|\#[0-9a-f]{6}|\#[0-9a-f]{3})$/i)) {
  34. if (background) {
  35. throw new TexError_js_1.default('MultipleBBoxProperty', '%1 specified twice in %2', 'Background', name);
  36. }
  37. background = part;
  38. }
  39. else if (part.match(/^[-a-z]+:/i)) {
  40. if (style) {
  41. throw new TexError_js_1.default('MultipleBBoxProperty', '%1 specified twice in %2', 'Style', name);
  42. }
  43. style = BBoxStyle(part);
  44. }
  45. else if (part !== '') {
  46. throw new TexError_js_1.default('InvalidBBoxProperty', '"%1" doesn\'t look like a color, a padding dimension, or a style', part);
  47. }
  48. }
  49. if (def) {
  50. math = parser.create('node', 'mpadded', [math], def);
  51. }
  52. if (background || style) {
  53. def = {};
  54. if (background) {
  55. Object.assign(def, { mathbackground: background });
  56. }
  57. if (style) {
  58. Object.assign(def, { style: style });
  59. }
  60. math = parser.create('node', 'mstyle', [math], def);
  61. }
  62. parser.Push(math);
  63. };
  64. var BBoxStyle = function (styles) {
  65. return styles;
  66. };
  67. var BBoxPadding = function (pad) {
  68. return pad;
  69. };
  70. new SymbolMap_js_1.CommandMap('bbox', { bbox: 'BBox' }, exports.BboxMethods);
  71. exports.BboxConfiguration = Configuration_js_1.Configuration.create('bbox', { handler: { macro: ['bbox'] } });
  72. //# sourceMappingURL=BboxConfiguration.js.map