All files / json-crdt-extensions/peritext/slice constants.ts

100% Statements 84/84
100% Branches 14/14
100% Functions 7/7
100% Lines 84/84

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214            59x 59x 59x                                                                                                                                     59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x   59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x     59x 59x 59x 59x     59x 59x 59x 59x     59x             59x                       59x                 59x                       59x             59x     59x 59x 59x 59x 59x 59x           59x 59x 59x 59x 59x 59x    
/**
 * Specifies whether the start or the end of the cursor is the "anchor", e.g.
 * the end which does not move when user changes selection. The other
 * end is free to move, the moving end of the cursor is "focus". By default
 * "anchor" is usually the start of the cursor.
 */
export enum CursorAnchor {
  Start = 0,
  End = 1,
}
 
export const enum SliceTypeCon {
  // ---------------------------------------------------- block slices (0 to 64)
  p = 0, // <p>
  blockquote = 1, // <blockquote>
  codeblock = 2, // <pre><code>
  pre = 3, // <pre>
  ul = 4, // <ul>
  ol = 5, // <ol>
  tasklist = 6, // - [ ] Task list
  h1 = 7, // <h1>
  h2 = 8, // <h2>
  h3 = 9, // <h3>
  h4 = 10, // <h4>
  h5 = 11, // <h5>
  h6 = 12, // <h6>
  title = 13, // <title>
  subtitle = 14, // <subtitle>
  br = 15, // <br>
  nl = 16, // \n
  hr = 17, // <hr>
  page = 18, // Page break
  aside = 19, // <aside>
  embed = 20, // <embed>, <iframe>, <object>, <video>, <audio>, etc.
  column = 21, // <div style="column-count: ..."> (represents 2 and 3 column layouts)
  contents = 22, // Table of contents
  table = 23, // <table>
  row = 24, // Table row
  cell = 25, // Table cell
  collapselist = 26, // Collapsible list - > List item
  collapse = 27, // Collapsible block
  note = 28, // Note block
 
  // ------------------------------------------------ inline slices (-64 to -1)
  Cursor = -1,
  RemoteCursor = -2,
  b = -3, // <b>
  i = -4, // <i>
  u = -5, // <u>
  s = -6, // <s>
  code = -7, // <code>
  mark = -8, // <mark>
  a = -9, // <a>
  comment = -10, // User comment attached to a slice
  del = -11, // <del>
  ins = -12, // <ins>
  sup = -13, // <sup>
  sub = -14, // <sub>
  math = -15, // <math>
  font = -16, // <span style="font-family: ...">
  col = -17, // <span style="color: ...">
  bg = -18, // <span style="background: ...">
  kbd = -19, // <kbd>
  hidden = -20, // <span style="color: transparent; background: black">
  footnote = -21, // <sup> or <a> with href="#footnote-..." and title="Footnote ..."
  ref = -22, // <a> with href="#ref-..." and title="Reference ..." (Reference to some element in the document)
  iaside = -23, // Inline <aside>
  iembed = -24, // inline embed (any media, dropdown, Google Docs-like chips: date, person, file, etc.)
  bookmark = -25, // UI for creating a link to this slice
}
 
/**
 * All type name must be fully lowercase, as HTML custom element tag names must
 * be lowercase.
 */
export enum SliceTypeName {
  p = SliceTypeCon.p,
  blockquote = SliceTypeCon.blockquote,
  codeblock = SliceTypeCon.codeblock,
  pre = SliceTypeCon.pre,
  ul = SliceTypeCon.ul,
  ol = SliceTypeCon.ol,
  tasklist = SliceTypeCon.tasklist,
  h1 = SliceTypeCon.h1,
  h2 = SliceTypeCon.h2,
  h3 = SliceTypeCon.h3,
  h4 = SliceTypeCon.h4,
  h5 = SliceTypeCon.h5,
  h6 = SliceTypeCon.h6,
  title = SliceTypeCon.title,
  subtitle = SliceTypeCon.subtitle,
  br = SliceTypeCon.br,
  nl = SliceTypeCon.nl,
  hr = SliceTypeCon.hr,
  page = SliceTypeCon.page,
  aside = SliceTypeCon.aside,
  embed = SliceTypeCon.embed,
  column = SliceTypeCon.column,
  contents = SliceTypeCon.contents,
  table = SliceTypeCon.table,
  row = SliceTypeCon.row,
  cell = SliceTypeCon.cell,
  collapselist = SliceTypeCon.collapselist,
  collapse = SliceTypeCon.collapse,
  note = SliceTypeCon.note,
 
  Cursor = SliceTypeCon.Cursor,
  RemoteCursor = SliceTypeCon.RemoteCursor,
  b = SliceTypeCon.b,
  i = SliceTypeCon.i,
  u = SliceTypeCon.u,
  s = SliceTypeCon.s,
  code = SliceTypeCon.code,
  mark = SliceTypeCon.mark,
  a = SliceTypeCon.a,
  comment = SliceTypeCon.comment,
  del = SliceTypeCon.del,
  ins = SliceTypeCon.ins,
  sup = SliceTypeCon.sup,
  sub = SliceTypeCon.sub,
  math = SliceTypeCon.math,
  font = SliceTypeCon.font,
  col = SliceTypeCon.col,
  bg = SliceTypeCon.bg,
  kbd = SliceTypeCon.kbd,
  hidden = SliceTypeCon.hidden,
  footnote = SliceTypeCon.footnote,
  ref = SliceTypeCon.ref,
  iaside = SliceTypeCon.iaside,
  iembed = SliceTypeCon.iembed,
  bookmark = SliceTypeCon.bookmark,
}
 
export enum SliceHeaderMask {
  X1Anchor = 0b1,
  X2Anchor = 0b10,
  Behavior = 0b11100,
}
 
export enum SliceHeaderShift {
  X1Anchor = 0,
  X2Anchor = 1,
  Behavior = 2,
}
 
export enum SliceBehavior {
  /**
   * The `Marker` slices are used to mark a block split position in the
   * document. For example, paragraph, heading, blockquote, etc. It separates
   * adjacent blocks and is used to determine the block type of the contents
   * following the marker, until the next marker is encountered.
   */
  Marker = 0b000,
 
  /**
   * The `Many` slices are inline formatting annotations, which allow one
   * or more annotations of the same type to apply to the same text. Slices with
   * behavior `Many` are appended to the stack of attributes for a specific
   * slice type. With the most recent annotation on top.
   *
   * Slices with behavior `Many` are used for inline formatting, like for links,
   * comments, etc. Where multiple annotations of the same type can be applied
   * to the same text.
   */
  Many = 0b001,
 
  /**
   * The slices with behavior `One` are used for inline formatting annotations,
   * they overwrite the stack of attributes for a specific slice type. This type
   * of slice is used when only one annotation of a specific type can be applied
   * to the same text. For example, those could be used for simple inline
   * formatting, like bold, italic, etc.
   */
  One = 0b010,
 
  /**
   * The `Erase` slices are used to soft remove all annotations
   * (`Many` or `One`) of the same type which are applied to the same text
   * range. The erase slices soft remove only the annotations which were applied
   * before the erase slice, as determined by the logical clock (there could
   * be many layers of annotations applied and erased).
   *
   * Usually slices with behavior `Erase` are used to reverse inline exclusive
   * (`One`) inline formatting, like bold, italic, etc.
   */
  Erase = 0b011,
 
  /**
   * Used to mark the user's cursor position in the document.
   *
   * @todo Consider removing this.
   */
  Cursor = 0b100,
}
 
export enum SliceBehaviorName {
  Marker = SliceBehavior.Marker,
  Many = SliceBehavior.Many,
  One = SliceBehavior.One,
  Erase = SliceBehavior.Erase,
  Cursor = SliceBehavior.Cursor,
}
 
/**
 * Specifies `vec` offsets in the {@link SliceView}.
 */
export enum SliceTupleIndex {
  Header = 0,
  X1 = 1,
  X2 = 2,
  Type = 3,
  Data = 4,
}