public IncrementalDocumentSizer(Document document, IncrementalSizer sizer)
 {
     this.document = document;
     this.sizer = sizer;
     var maxWidth = GetSized(int.MaxValue).Size.X;
     GetSized(int.MinValue + maxWidth);
 }
 public SizedDocument GetSized(Document document, int preferredWidth)
 {
     var sizeFunc = documentSizers.Get(document).Eval(
         () => unwrappables.Get(document).Select<Func<int, SizedDocument>>(s => i => s).Default(() =>
     {
         var maxSize = document.GetSizedDocument(int.MaxValue).Size.X;
         var minSizedDocument = document.GetSizedDocument(int.MinValue + maxSize);
         var wrappable = minSizedDocument.Size.X != maxSize;
         if (wrappable)
             return (documentSizers[document] = new IncrementalDocumentSizer(document, this)).GetSized;
         unwrappables[document] = minSizedDocument;
         return s => minSizedDocument;
     }), d => d.GetSized);
     return sizeFunc(preferredWidth);
 }
 public Document Concat(Document seperator, Document right)
 {
     if (IsEmpty || right.IsEmpty)
         return this + right;
     return this + seperator + right;
 }
 public static Document Seperated(Document seperator, params object[] items)
 {
     return items.Seperated(seperator);
 }
 public TopBottom(Document top, Document bottom)
 {
     this.top = top;
     this.bottom = bottom;
     _hashCode = new Memory<int>(CalculateHashCode);
 }
 public DocumentWriter WriteLine()
 {
     Done ^= currentLine.IsEmpty ? DocumentUtil.Space : currentLine;
     currentLine = DocumentUtil.Empty;
     return this;
 }
 public DocumentWriter WriteLine(Document text)
 {
     Write(text);
     WriteLine();
     return this;
 }
 public DocumentWriter Write([NotNull]Document text)
 {
     currentLine += text;
     return this;
 }
 public DocumentWriter FinishLine()
 {
     Done ^= currentLine;
     currentLine = DocumentUtil.Empty;
     return this;
 }
 public void EndBlock()
 {
     WriteLine();
     var block = indentStack.Pop().Indent(indentations.Pop());
     Done ^= block;
 }
 public LeftRight(Document left, Document right)
 {
     this.left = left; this.right = right;
     _hashCode = new Memory<int>(CalculateHashCode);
 }