document-ir 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { IdentityTransformer } from './IdentityTransformer.ts';
2
- import { CodeNode, DocumentNode, Node, TextNode } from './types.ts';
2
+ import { BadgeNode, CodeNode, DocumentNode, EmojiNode, Node, TextNode } from './types.ts';
3
3
  interface BlockInfo {
4
4
  type: "_block";
5
5
  content: WhiteSpaceContainer[];
@@ -20,6 +20,8 @@ export declare class WhitespaceStretchingTransformer extends IdentityTransformer
20
20
  protected beforeInline(): Promise<void>;
21
21
  protected afterInline(): Promise<void>;
22
22
  protected reviewBlock(block: BlockInfo): void;
23
+ protected emoji(node: EmojiNode): Promise<Node | null>;
24
+ protected badge(node: BadgeNode): Promise<Node | null>;
23
25
  protected code(node: CodeNode): Promise<Node | null>;
24
26
  protected text(node: TextNode): Promise<Node | null>;
25
27
  transform(node: DocumentNode): Promise<DocumentNode>;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- var y = Object.defineProperty;
2
- var d = (c, t, e) => t in c ? y(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
3
- var h = (c, t, e) => d(c, typeof t != "symbol" ? t + "" : t, e);
1
+ var d = Object.defineProperty;
2
+ var g = (c, t, e) => t in c ? d(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
3
+ var h = (c, t, e) => g(c, typeof t != "symbol" ? t + "" : t, e);
4
4
  class u {
5
5
  async beforeBlock() {
6
6
  }
@@ -855,7 +855,7 @@ class u {
855
855
  return await this.document(t);
856
856
  }
857
857
  }
858
- class g extends u {
858
+ class k extends u {
859
859
  async chooseChildren(t) {
860
860
  const e = await super.chooseChildren(t), i = [];
861
861
  for (const s of e)
@@ -867,7 +867,7 @@ class g extends u {
867
867
  return i;
868
868
  }
869
869
  }
870
- class I extends u {
870
+ class T extends u {
871
871
  async chooseChildren(t) {
872
872
  const e = await super.chooseChildren(t), i = [];
873
873
  let s = null, r;
@@ -888,12 +888,12 @@ class I extends u {
888
888
  return i;
889
889
  }
890
890
  }
891
- class k extends u {
891
+ class m extends u {
892
892
  async text(t) {
893
893
  return t.text == "" ? null : t;
894
894
  }
895
895
  }
896
- class T extends u {
896
+ class v extends u {
897
897
  constructor() {
898
898
  super();
899
899
  h(this, "stripWhitespace");
@@ -938,10 +938,10 @@ class T extends u {
938
938
  }
939
939
  async transform(e) {
940
940
  const i = await super.transform(e);
941
- return await new k().transform(i);
941
+ return await new m().transform(i);
942
942
  }
943
943
  }
944
- class v extends u {
944
+ class N extends u {
945
945
  constructor() {
946
946
  super();
947
947
  h(this, "root");
@@ -994,6 +994,16 @@ class v extends u {
994
994
  !n.node || !a.node || n.level != a.level && (n.level < a.level ? a.node.text.startsWith(" ") && (a.node.text = a.node.text.slice(1), n.node.text += " ") : n.level > a.level && n.node.text.endsWith(" ") && (n.node.text = n.node.text.slice(0, -1), a.node.text = ` ${a.node.text}`));
995
995
  }
996
996
  }
997
+ // Void inline elements (emoji, badge) don't call beforeInline/afterInline so they
998
+ // are invisible to the cursor by default. Push a _block sentinel so reviewBlock
999
+ // sees an opaque boundary at their position, preventing trailing spaces on
1000
+ // adjacent text nodes from migrating across them.
1001
+ async emoji(e) {
1002
+ return this.cursor.content.push({ type: "_block", content: [], parent: this.cursor }), super.emoji(e);
1003
+ }
1004
+ async badge(e) {
1005
+ return this.cursor.content.push({ type: "_block", content: [], parent: this.cursor }), super.badge(e);
1006
+ }
997
1007
  async code(e) {
998
1008
  const i = {
999
1009
  type: "code",
@@ -1013,7 +1023,7 @@ class v extends u {
1013
1023
  return this.reviewBlock(this.root), i;
1014
1024
  }
1015
1025
  }
1016
- class w {
1026
+ class b {
1017
1027
  beforeBlock() {
1018
1028
  }
1019
1029
  afterBlock() {
@@ -1314,7 +1324,7 @@ class w {
1314
1324
  t.type == "document" ? this.document(t) : this.choose(t);
1315
1325
  }
1316
1326
  }
1317
- class m extends w {
1327
+ class B extends b {
1318
1328
  constructor() {
1319
1329
  super();
1320
1330
  h(this, "textList");
@@ -1349,7 +1359,7 @@ class m extends w {
1349
1359
  return this.textList.join("");
1350
1360
  }
1351
1361
  }
1352
- class B extends g {
1362
+ class C extends k {
1353
1363
  async sticker(t) {
1354
1364
  if (t.content.length == 0)
1355
1365
  return null;
@@ -1540,7 +1550,7 @@ class B extends g {
1540
1550
  };
1541
1551
  }
1542
1552
  }
1543
- class C extends w {
1553
+ class x extends b {
1544
1554
  constructor() {
1545
1555
  super();
1546
1556
  h(this, "count");
@@ -1566,29 +1576,29 @@ class C extends w {
1566
1576
  return this.countText(), this.count;
1567
1577
  }
1568
1578
  }
1569
- function b(c) {
1579
+ function y(c) {
1570
1580
  const t = {
1571
1581
  headerText: c.header,
1572
1582
  headerId: c.headerId,
1573
1583
  words: 0,
1574
1584
  totalWords: 0,
1575
1585
  children: []
1576
- }, e = new C();
1586
+ }, e = new x();
1577
1587
  for (const i of c.nodes)
1578
1588
  e.visit(i);
1579
1589
  t.words = e.getCount(), t.totalWords = t.words;
1580
1590
  for (const i of c.children) {
1581
- const s = b(i);
1591
+ const s = y(i);
1582
1592
  t.children.push(s), t.totalWords += s.totalWords;
1583
1593
  }
1584
1594
  return t;
1585
1595
  }
1586
- class N extends u {
1596
+ class _ extends u {
1587
1597
  constructor() {
1588
1598
  super();
1589
1599
  }
1590
1600
  async transform(t) {
1591
- const e = JSON.parse(JSON.stringify(t)), i = await new B().transform(e), s = [], r = {
1601
+ const e = JSON.parse(JSON.stringify(t)), i = await new C().transform(e), s = [], r = {
1592
1602
  header: t.title,
1593
1603
  headerId: "title",
1594
1604
  nodes: [],
@@ -1604,32 +1614,32 @@ class N extends u {
1604
1614
  if (o.level <= n)
1605
1615
  for (let p = s.length - 1; p > 0; p--)
1606
1616
  s[p].depth >= o.level && s.pop();
1607
- const l = new m();
1617
+ const l = new B();
1608
1618
  l.visit(o);
1609
1619
  const f = {
1610
1620
  header: l.getText(),
1611
1621
  depth: o.level,
1612
1622
  children: [],
1613
1623
  nodes: []
1614
- };
1615
- o.htmlId && (f.headerId = o.htmlId), s[s.length - 1].children.push(f), s.push(f), n = o.level;
1624
+ }, w = o.htmlId || o.id;
1625
+ w && (f.headerId = w), s[s.length - 1].children.push(f), s.push(f), n = o.level;
1616
1626
  } else
1617
1627
  s[s.length - 1].nodes.push(o);
1618
1628
  const a = {
1619
1629
  ...t
1620
1630
  };
1621
- return a.hierarchy = b(r), a;
1631
+ return a.hierarchy = y(r), a;
1622
1632
  }
1623
1633
  }
1624
1634
  export {
1625
- g as ArrayCollapseTransformer,
1626
- B as DocumentThinningTransformer,
1635
+ k as ArrayCollapseTransformer,
1636
+ C as DocumentThinningTransformer,
1627
1637
  u as IdentityTransformer,
1628
- w as NodeVisitor,
1629
- I as TextCollapseTransformer,
1630
- m as TextVisitor,
1631
- v as WhitespaceStretchingTransformer,
1632
- T as WhitespaceTransformer,
1633
- N as WordCounterTransformer,
1634
- C as WordCounterVisitor
1638
+ b as NodeVisitor,
1639
+ T as TextCollapseTransformer,
1640
+ B as TextVisitor,
1641
+ N as WhitespaceStretchingTransformer,
1642
+ v as WhitespaceTransformer,
1643
+ _ as WordCounterTransformer,
1644
+ x as WordCounterVisitor
1635
1645
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-ir",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",