text: "use strict";
  /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.Typography = void 0;
  const Pt_1 = require("./Pt");
  class Typography {
      static textWidthEstimator(fn, samples = ["M", "n", "."], distribution = [0.06, 0.8, 0.14]) {
          let m = samples.map(fn);
          let avg = new Pt_1.Pt(distribution).dot(m);
          return (str) => str.length * avg;
      }
      static truncate(fn, str, width, tail = "") {
          let trim = Math.floor(str.length * Math.min(1, width / fn(str)));
          if (trim < str.length) {
              trim = Math.max(0, trim - tail.length);
              return [str.substr(0, trim) + tail, trim];
          }
          else {
              return [str, str.length];
          }
      }
      static fontSizeToBox(box, ratio = 1, byHeight = true) {
          let bound = Pt_1.Bound.fromGroup(box);
          let h = byHeight ? bound.height : bound.width;
          let f = ratio * h;
          return function (box2) {
              let bound2 = Pt_1.Bound.fromGroup(box2);
              let nh = (byHeight ? bound2.height : bound2.width) / h;
              return f * nh;
          };
      }
      static fontSizeToThreshold(threshold, direction = 0) {
          return function (defaultSize, val) {
              let d = defaultSize * val / threshold;
              if (direction < 0)
                  return Math.min(d, defaultSize);
              if (direction > 0)
                  return Math.max(d, defaultSize);
              return d;
          };
      }
  }
  exports.Typography = Typography;
  //# sourceMappingURL=Typography.js.map