securemark 0.240.2 → 0.243.0

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/securemark.js +1082 -2461
  3. package/global.dev.d.ts +6 -2
  4. package/index.d.ts +0 -1
  5. package/markdown.d.ts +61 -32
  6. package/package-lock.json +169 -77
  7. package/package.json +5 -4
  8. package/src/combinator/control/manipulation/fallback.ts +0 -1
  9. package/src/combinator/control/manipulation/indent.test.ts +3 -1
  10. package/src/combinator/control/manipulation/indent.ts +7 -6
  11. package/src/debug.test.ts +1 -1
  12. package/src/parser/api/bind.test.ts +1 -1
  13. package/src/parser/api/parse.test.ts +1 -1
  14. package/src/parser/api/parse.ts +1 -1
  15. package/src/parser/block/blockquote.test.ts +4 -4
  16. package/src/parser/block/blockquote.ts +2 -8
  17. package/src/parser/block/codeblock.test.ts +27 -27
  18. package/src/parser/block/codeblock.ts +2 -2
  19. package/src/parser/block/dlist.ts +1 -1
  20. package/src/parser/block/extension/aside.ts +1 -1
  21. package/src/parser/block/extension/example.ts +1 -1
  22. package/src/parser/block/extension/fig.test.ts +3 -3
  23. package/src/parser/block/extension/fig.ts +7 -6
  24. package/src/parser/block/extension/figbase.ts +1 -1
  25. package/src/parser/block/extension/figure.test.ts +10 -10
  26. package/src/parser/block/extension/figure.ts +16 -6
  27. package/src/parser/block/extension/message.test.ts +7 -7
  28. package/src/parser/block/extension/message.ts +6 -2
  29. package/src/parser/block/extension/placeholder.ts +9 -3
  30. package/src/parser/block/extension/table.test.ts +1 -1
  31. package/src/parser/block/extension/table.ts +1 -1
  32. package/src/parser/block/heading.ts +1 -1
  33. package/src/parser/block/horizontalrule.ts +1 -1
  34. package/src/parser/block/ilist.ts +1 -1
  35. package/src/parser/block/indentblock.test.ts +30 -0
  36. package/src/parser/block/indentblock.ts +13 -0
  37. package/src/parser/block/mathblock.ts +1 -1
  38. package/src/parser/block/olist.ts +6 -6
  39. package/src/parser/block/paragraph.ts +1 -1
  40. package/src/parser/block/reply/cite.ts +1 -1
  41. package/src/parser/block/reply/quote.ts +1 -1
  42. package/src/parser/block/reply.ts +1 -1
  43. package/src/parser/block/sidefence.test.ts +66 -0
  44. package/src/parser/block/sidefence.ts +31 -0
  45. package/src/parser/block/table.ts +1 -1
  46. package/src/parser/block/ulist.ts +1 -1
  47. package/src/parser/block.ts +8 -2
  48. package/src/parser/header.ts +1 -1
  49. package/src/parser/inline/annotation.ts +1 -1
  50. package/src/parser/inline/autolink/account.ts +1 -1
  51. package/src/parser/inline/autolink/anchor.ts +1 -1
  52. package/src/parser/inline/autolink/channel.ts +1 -1
  53. package/src/parser/inline/autolink/email.ts +1 -1
  54. package/src/parser/inline/autolink/hashnum.ts +1 -1
  55. package/src/parser/inline/autolink/hashtag.ts +1 -1
  56. package/src/parser/inline/bracket.ts +1 -1
  57. package/src/parser/inline/code.ts +1 -1
  58. package/src/parser/inline/comment.ts +1 -1
  59. package/src/parser/inline/deletion.ts +1 -1
  60. package/src/parser/inline/emphasis.ts +1 -1
  61. package/src/parser/inline/emstrong.ts +1 -1
  62. package/src/parser/inline/extension/index.ts +1 -1
  63. package/src/parser/inline/extension/indexee.ts +1 -1
  64. package/src/parser/inline/extension/indexer.ts +1 -1
  65. package/src/parser/inline/extension/label.ts +1 -1
  66. package/src/parser/inline/extension/placeholder.ts +3 -3
  67. package/src/parser/inline/html.ts +1 -1
  68. package/src/parser/inline/htmlentity.ts +1 -1
  69. package/src/parser/inline/insertion.ts +1 -1
  70. package/src/parser/inline/link.ts +1 -1
  71. package/src/parser/inline/mark.ts +1 -1
  72. package/src/parser/inline/math.ts +1 -1
  73. package/src/parser/inline/media.ts +1 -1
  74. package/src/parser/inline/reference.ts +1 -1
  75. package/src/parser/inline/ruby.ts +1 -1
  76. package/src/parser/inline/strong.ts +1 -1
  77. package/src/parser/inline/template.ts +1 -1
  78. package/src/parser/locale.ts +1 -1
  79. package/src/parser/processor/figure.test.ts +1 -1
  80. package/src/parser/processor/figure.ts +4 -4
  81. package/src/parser/processor/footnote.test.ts +1 -1
  82. package/src/parser/processor/footnote.ts +6 -5
  83. package/src/parser/source/text.ts +1 -1
  84. package/src/renderer/render/math.ts +1 -1
  85. package/src/renderer/render/media/audio.ts +1 -1
  86. package/src/renderer/render/media/image.ts +1 -1
  87. package/src/renderer/render/media/pdf.ts +1 -1
  88. package/src/renderer/render/media/twitter.ts +21 -23
  89. package/src/renderer/render/media/video.ts +1 -1
  90. package/src/renderer/render/media/youtube.ts +1 -1
  91. package/src/renderer/render/media.test.ts +1 -1
  92. package/src/renderer/render.ts +3 -5
  93. package/src/util/info.ts +3 -7
  94. package/src/util/quote.ts +1 -1
  95. package/src/util/toc.test.ts +1 -1
  96. package/src/util/toc.ts +1 -1
  97. package/src/util.ts +0 -1
  98. package/src/util/sync.ts +0 -57
@@ -2,7 +2,7 @@ import { undefined } from 'spica/global';
2
2
  import { TemplateParser } from '../inline';
3
3
  import { union, some, rewrite, creator, surround, lazy } from '../../combinator';
4
4
  import { escsource, str } from '../source';
5
- import { html } from 'typed-dom';
5
+ import { html } from 'typed-dom/dom';
6
6
  import { unshift } from 'spica/array';
7
7
 
8
8
  export const template: TemplateParser = lazy(() => creator(rewrite(
@@ -1,7 +1,7 @@
1
1
  import { Parser } from '../combinator/data/parser';
2
2
  import { fmap } from '../combinator';
3
3
  import { japanese } from './locale/ja';
4
- import { html } from 'typed-dom';
4
+ import { html } from 'typed-dom/dom';
5
5
 
6
6
  export function localize<P extends Parser<HTMLElement | string>>(parser: P): P;
7
7
  export function localize(parser: Parser<HTMLElement | string>): Parser<HTMLElement | string> {
@@ -1,6 +1,6 @@
1
1
  import { figure } from './figure';
2
2
  import { parse as parse_ } from '../../parser';
3
- import { html } from 'typed-dom';
3
+ import { html } from 'typed-dom/dom';
4
4
  import { normalize } from '../../debug.test';
5
5
 
6
6
  const parse = (s: string) => parse_(s, { test: true });
@@ -1,6 +1,6 @@
1
1
  import { Infinity, Set, Map } from 'spica/global';
2
2
  import { number as calculate, isFixed } from '../inline/extension/label';
3
- import { define } from 'typed-dom';
3
+ import { define } from 'typed-dom/dom';
4
4
  import { MultiMap } from 'spica/multimap';
5
5
  import { push, join } from 'spica/array';
6
6
 
@@ -12,9 +12,9 @@ export function* figure(
12
12
  }> = {},
13
13
  ): Generator<HTMLAnchorElement | undefined, undefined, undefined> {
14
14
  const refs = new MultiMap<string, HTMLAnchorElement>(push(push(push([],
15
- target.querySelectorAll<HTMLAnchorElement>('a.label:not(.disabled)[data-label]')),
16
- footnotes?.annotations.querySelectorAll<HTMLAnchorElement>('a.label:not(.disabled)') ?? []),
17
- footnotes?.references.querySelectorAll<HTMLAnchorElement>('a.label:not(.disabled)') ?? [])
15
+ target.querySelectorAll('a.label:not(.disabled)[data-label]')),
16
+ footnotes?.annotations.querySelectorAll('a.label:not(.disabled)') ?? []),
17
+ footnotes?.references.querySelectorAll('a.label:not(.disabled)') ?? [])
18
18
  .map(el => [el.getAttribute('data-label')!, el]));
19
19
  const labels = new Set<string>();
20
20
  const numbers = new Map<string, string>();
@@ -1,6 +1,6 @@
1
1
  import { annotation, reference } from './footnote';
2
2
  import { parse as parse_ } from '../../parser';
3
- import { html } from 'typed-dom';
3
+ import { html } from 'typed-dom/dom';
4
4
 
5
5
  const parse = (s: string) => parse_(s, { test: true });
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { undefined, Infinity, Map, WeakMap } from 'spica/global';
2
2
  import { text } from '../inline/extension/indexee';
3
- import { frag, html, define } from 'typed-dom';
3
+ import { frag, html, define } from 'typed-dom/dom';
4
4
  import { MultiMap } from 'spica/multimap';
5
5
  import { memoize } from 'spica/memoize';
6
6
 
@@ -42,7 +42,7 @@ function build(
42
42
  const check = footnotes.some(el => target.contains(el));
43
43
  let style: 'count' | 'abbr';
44
44
  for (
45
- let refs = target.querySelectorAll<HTMLElement>(`sup.${syntax}:not(.disabled)`),
45
+ let refs = target.querySelectorAll(`sup.${syntax}:not(.disabled)`),
46
46
  i = 0, len = refs.length; i < len; ++i) {
47
47
  yield;
48
48
  const ref = refs[i];
@@ -127,12 +127,13 @@ function build(
127
127
  }
128
128
  if (!footnote) return;
129
129
  const { children } = footnote;
130
+ const size = defs.size;
130
131
  let count = 0;
131
132
  let length = children.length;
132
133
  I:
133
134
  for (const def of defs.values()) {
134
135
  ++count;
135
- while (length > defs.size) {
136
+ while (length > size) {
136
137
  const node = children[count - 1] as HTMLLIElement;
137
138
  if (equal(node, def)) continue I;
138
139
  yield footnote.removeChild(node);
@@ -148,8 +149,8 @@ function build(
148
149
  ++length;
149
150
  assert(children.length === length);
150
151
  }
151
- while (length > defs.size) {
152
- yield footnote.removeChild(children[defs.size] as HTMLLIElement);
152
+ while (length > size) {
153
+ yield footnote.removeChild(children[size] as HTMLLIElement);
153
154
  --length;
154
155
  assert(children.length === length);
155
156
  }
@@ -2,7 +2,7 @@ import { undefined } from 'spica/global';
2
2
  import { TextParser, TxtParser, LinebreakParser } from '../source';
3
3
  import { union, focus, creator } from '../../combinator';
4
4
  import { str } from './str';
5
- import { html } from 'typed-dom';
5
+ import { html } from 'typed-dom/dom';
6
6
 
7
7
  export const separator = /[\s\x00-\x7F]|\S#|[、。!?][^\S\n]*(?=\\\n)/;
8
8
  export const nonWhitespace = /[\S\n]|$/;
@@ -1,6 +1,6 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { Collection } from 'spica/collection';
3
- import { html, define } from 'typed-dom';
3
+ import { html, define } from 'typed-dom/dom';
4
4
 
5
5
  export function math(target: HTMLElement, cache?: Collection<string, HTMLElement>): void {
6
6
  assert(target.children.length === 0);
@@ -1,4 +1,4 @@
1
- import { html } from 'typed-dom';
1
+ import { html } from 'typed-dom/dom';
2
2
 
3
3
  const extensions = [
4
4
  '.oga',
@@ -1,4 +1,4 @@
1
- import { define } from 'typed-dom';
1
+ import { define } from 'typed-dom/dom';
2
2
  import { Collection } from 'spica/collection';
3
3
  import { ObjectFromEntries } from 'spica/alias';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { parse } from '../../../parser';
2
- import { html, define } from 'typed-dom';
2
+ import { html, define } from 'typed-dom/dom';
3
3
 
4
4
  const extensions = [
5
5
  '.pdf',
@@ -1,6 +1,6 @@
1
1
  import { window, document } from 'spica/global';
2
2
  import { parse } from '../../../parser';
3
- import { HTML, define } from 'typed-dom';
3
+ import { html as h, define } from 'typed-dom/dom';
4
4
  import { sanitize } from 'dompurify';
5
5
 
6
6
  declare global {
@@ -21,26 +21,24 @@ export function twitter(source: HTMLImageElement, url: URL): HTMLElement | undef
21
21
  if (!origins.includes(url.origin)) return;
22
22
  if (url.pathname.split('/').pop()!.includes('.')) return;
23
23
  if (!url.pathname.match(/^\/\w+\/status\/[0-9]{15,}(?!\w)/)) return;
24
- return HTML.div({ class: source.className, 'data-type': 'twitter' },
25
- [HTML.em(`Loading ${source.getAttribute('data-src')}...`)],
26
- (h, tag) => {
27
- const el = h(tag);
28
- $.ajax(`https://publish.twitter.com/oembed?url=${url.href.replace('?', '&')}&omit_script=true`, {
29
- dataType: 'jsonp',
30
- timeout: 10 * 1e3,
31
- cache: true,
32
- success({ html }): void {
33
- el.innerHTML = sanitize(html);
34
- if (window.twttr) return void window.twttr.widgets.load(el);
35
- const id = 'twitter-wjs';
36
- if (document.getElementById(id)) return;
37
- document.body.appendChild(h('script', { id, src: 'https://platform.twitter.com/widgets.js' }));
38
- },
39
- error({ status, statusText }) {
40
- assert(Number.isSafeInteger(status));
41
- define(el, [parse(`*{ ${source.getAttribute('data-src')} }*\n\n\`\`\`\n${status}\n${statusText}\n\`\`\``)]);
42
- },
43
- });
44
- return el;
45
- }).element;
24
+ const el = h('div', { class: source.className, 'data-type': 'twitter' }, [
25
+ h('em', `Loading ${source.getAttribute('data-src')}...`),
26
+ ]);
27
+ $.ajax(`https://publish.twitter.com/oembed?url=${url.href.replace('?', '&')}&omit_script=true`, {
28
+ dataType: 'jsonp',
29
+ timeout: 10 * 1e3,
30
+ cache: true,
31
+ success({ html }): void {
32
+ el.innerHTML = sanitize(html);
33
+ if (window.twttr) return void window.twttr.widgets.load(el);
34
+ const id = 'twitter-wjs';
35
+ if (document.getElementById(id)) return;
36
+ document.body.appendChild(h('script', { id, src: 'https://platform.twitter.com/widgets.js' }));
37
+ },
38
+ error({ status, statusText }) {
39
+ assert(Number.isSafeInteger(status));
40
+ define(el, [parse(`*{ ${source.getAttribute('data-src')} }*\n\n\`\`\`\n${status}\n${statusText}\n\`\`\``)]);
41
+ },
42
+ });
43
+ return el;
46
44
  }
@@ -1,4 +1,4 @@
1
- import { html } from 'typed-dom';
1
+ import { html } from 'typed-dom/dom';
2
2
  import { ObjectFromEntries } from 'spica/alias';
3
3
 
4
4
  const extensions = [
@@ -1,4 +1,4 @@
1
- import { html } from 'typed-dom';
1
+ import { html } from 'typed-dom/dom';
2
2
 
3
3
  export function youtube(source: HTMLImageElement, url: URL): HTMLElement | undefined {
4
4
  const id = resolve(url);
@@ -1,6 +1,6 @@
1
1
  import { media } from './media';
2
2
  import { parse } from '../../parser';
3
- import { html } from 'typed-dom';
3
+ import { html } from 'typed-dom/dom';
4
4
  import { caches } from '../../parser/api';
5
5
 
6
6
  describe('Unit: renderer/render/media', () => {
@@ -3,6 +3,7 @@ import { RenderingOptions } from '../../';
3
3
  import { code } from './render/code';
4
4
  import { math } from './render/math';
5
5
  import { media } from './render/media';
6
+ import { querySelectorAll } from 'typed-dom/query';
6
7
  import { reduce } from 'spica/memoize';
7
8
 
8
9
  const selector = 'img.media:not(.invalid):not([src])[data-src], a > :not(img).media:not(.invalid), pre.code:not(.invalid), .math:not(.invalid)';
@@ -13,11 +14,8 @@ const extend = reduce((opts: RenderingOptions): RenderingOptions =>
13
14
  export function render(source: HTMLElement, opts: RenderingOptions = {}): void {
14
15
  opts = extend(opts);
15
16
  const base = location.href;
16
- if (source.matches(selector)) return void render_(base, source, opts);
17
- for (
18
- let es = source.querySelectorAll<HTMLElement>(selector),
19
- i = 0, len = es.length; i < len; ++i) {
20
- render_(base, es[i], opts);
17
+ for (const el of querySelectorAll<HTMLElement>(source, selector)) {
18
+ render_(base, el, opts);
21
19
  }
22
20
  }
23
21
 
package/src/util/info.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Info } from '../..';
2
2
  import { scope } from './scope';
3
+ import { querySelectorAll } from 'typed-dom/query';
3
4
 
4
5
  export function info(source: DocumentFragment | HTMLElement | ShadowRoot): Info {
5
6
  const match = scope(source, '.invalid');
@@ -19,12 +20,7 @@ export function info(source: DocumentFragment | HTMLElement | ShadowRoot): Info
19
20
  };
20
21
 
21
22
  function find<T extends HTMLElement>(selector: string): T[] {
22
- const acc: T[] = [];
23
- for (let es = source.querySelectorAll<T>(selector), i = 0, len = es.length; i < len; ++i) {
24
- const el = es[i];
25
- if (!match(el)) continue;
26
- acc.push(el);
27
- }
28
- return acc;
23
+ return querySelectorAll<T>(source, selector)
24
+ .filter(match);
29
25
  }
30
26
  }
package/src/util/quote.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Element } from 'spica/global';
2
2
  import { exec } from '../combinator/data/parser';
3
3
  import { cite } from '../parser/block/reply/cite';
4
- import { define } from 'typed-dom';
4
+ import { define } from 'typed-dom/dom';
5
5
 
6
6
  export function quote(anchor: string, range: Range): string {
7
7
  if (exec(cite(`>>${anchor}`, {})) !== '') throw new Error(`Invalid anchor: ${anchor}`);
@@ -1,6 +1,6 @@
1
1
  import { toc } from './toc';
2
2
  import { parse } from '../parser';
3
- import { html } from 'typed-dom';
3
+ import { html } from 'typed-dom/dom';
4
4
 
5
5
  describe('Unit: util/toc', () => {
6
6
  describe('toc', () => {
package/src/util/toc.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { undefined, Array } from 'spica/global';
2
- import { html } from 'typed-dom';
2
+ import { html } from 'typed-dom/dom';
3
3
  import { push } from 'spica/array';
4
4
 
5
5
  // Bug: Firefox
package/src/util.ts CHANGED
@@ -2,4 +2,3 @@ export { quote } from './util/quote';
2
2
  export { toc } from './util/toc';
3
3
  export { info } from './util/info';
4
4
  export { scope } from './util/scope';
5
- export { sync } from './util/sync';
package/src/util/sync.ts DELETED
@@ -1,57 +0,0 @@
1
- import { undefined, window, document } from 'spica/global';
2
- import { abs, ceil, sign } from 'spica/alias';
3
- import { aggregate } from 'spica/arrow';
4
- import { clear } from 'spica/function';
5
- import { bind, once } from 'typed-dom';
6
-
7
- export function sync(
8
- editor: HTMLElement,
9
- viewer: HTMLElement,
10
- bottom: Element | null = viewer.firstElementChild,
11
- ): () => void {
12
- let hover = document.activeElement?.contains(editor) ?? true;
13
- let scroll = editor.scrollTop;
14
- return clear(aggregate(
15
- once(viewer, 'mousemove', () => {
16
- hover = false;
17
- }, passive),
18
- once(viewer, 'mousedown', () => {
19
- hover = false;
20
- }, passive),
21
- once(viewer, 'wheel', () => {
22
- hover = false;
23
- }, passive),
24
- bind(editor, 'input', () => {
25
- hover = true;
26
- }, passive),
27
- bind(editor, 'keydown', () => {
28
- hover = true;
29
- }, passive),
30
- bind(editor, 'mouseenter', () => {
31
- hover = true;
32
- }, passive),
33
- bind(editor, 'mouseleave', () => {
34
- hover = false;
35
- }, passive),
36
- bind(editor, 'scroll', () => {
37
- if (!hover) return scroll = editor.scrollTop, undefined;
38
- const delta = editor.scrollTop - scroll;
39
- switch (scroll += delta) {
40
- case 0:
41
- return void viewer.scrollTo({ top: 0 });
42
- default:
43
- const last = bottom?.previousElementSibling as HTMLElement | null;
44
- const viewer_scrollHeight = last
45
- ? last.offsetTop + last.offsetHeight + +window.getComputedStyle(last).marginBottom.slice(0, -2)
46
- : viewer.scrollHeight;
47
- return void viewer.scrollBy({
48
- top: sign(delta) * ceil(
49
- + abs(delta)
50
- * (viewer_scrollHeight - viewer.clientHeight)
51
- / (editor.scrollHeight - editor.clientHeight)),
52
- });
53
- }
54
- }, passive)));
55
- }
56
-
57
- const passive = { passive: true };