@acornly/core 0.1.0 → 0.3.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 (134) hide show
  1. package/dist/adapter.d.ts +27 -2
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/adapter.js +5 -0
  4. package/dist/adapter.js.map +1 -1
  5. package/dist/anchoring/canvas.d.ts +33 -0
  6. package/dist/anchoring/canvas.d.ts.map +1 -0
  7. package/dist/anchoring/canvas.js +112 -0
  8. package/dist/anchoring/canvas.js.map +1 -0
  9. package/dist/anchoring/context-provider.d.ts +63 -0
  10. package/dist/anchoring/context-provider.d.ts.map +1 -0
  11. package/dist/anchoring/context-provider.js +78 -0
  12. package/dist/anchoring/context-provider.js.map +1 -0
  13. package/dist/anchoring/describe.d.ts +36 -2
  14. package/dist/anchoring/describe.d.ts.map +1 -1
  15. package/dist/anchoring/describe.js +102 -20
  16. package/dist/anchoring/describe.js.map +1 -1
  17. package/dist/anchoring/fingerprint.d.ts +47 -13
  18. package/dist/anchoring/fingerprint.d.ts.map +1 -1
  19. package/dist/anchoring/fingerprint.js +58 -68
  20. package/dist/anchoring/fingerprint.js.map +1 -1
  21. package/dist/anchoring/index.d.ts +5 -0
  22. package/dist/anchoring/index.d.ts.map +1 -1
  23. package/dist/anchoring/index.js +5 -0
  24. package/dist/anchoring/index.js.map +1 -1
  25. package/dist/anchoring/media.d.ts +2 -1
  26. package/dist/anchoring/media.d.ts.map +1 -1
  27. package/dist/anchoring/media.js +7 -2
  28. package/dist/anchoring/media.js.map +1 -1
  29. package/dist/anchoring/pdf.d.ts +204 -0
  30. package/dist/anchoring/pdf.d.ts.map +1 -0
  31. package/dist/anchoring/pdf.js +608 -0
  32. package/dist/anchoring/pdf.js.map +1 -0
  33. package/dist/anchoring/profiles.d.ts +140 -0
  34. package/dist/anchoring/profiles.d.ts.map +1 -0
  35. package/dist/anchoring/profiles.js +682 -0
  36. package/dist/anchoring/profiles.js.map +1 -0
  37. package/dist/anchoring/providers.d.ts +16 -1
  38. package/dist/anchoring/providers.d.ts.map +1 -1
  39. package/dist/anchoring/providers.js +15 -0
  40. package/dist/anchoring/providers.js.map +1 -1
  41. package/dist/anchoring/resolver.d.ts +23 -5
  42. package/dist/anchoring/resolver.d.ts.map +1 -1
  43. package/dist/anchoring/resolver.js +32 -13
  44. package/dist/anchoring/resolver.js.map +1 -1
  45. package/dist/anchoring/site-profiles.d.ts +31 -0
  46. package/dist/anchoring/site-profiles.d.ts.map +1 -0
  47. package/dist/anchoring/site-profiles.js +27 -0
  48. package/dist/anchoring/site-profiles.js.map +1 -0
  49. package/dist/body-prepare.d.ts +33 -0
  50. package/dist/body-prepare.d.ts.map +1 -0
  51. package/dist/body-prepare.js +88 -0
  52. package/dist/body-prepare.js.map +1 -0
  53. package/dist/body-size.d.ts +20 -0
  54. package/dist/body-size.d.ts.map +1 -0
  55. package/dist/body-size.js +137 -0
  56. package/dist/body-size.js.map +1 -0
  57. package/dist/body.d.ts +9 -42
  58. package/dist/body.d.ts.map +1 -1
  59. package/dist/body.js +6 -207
  60. package/dist/body.js.map +1 -1
  61. package/dist/composite.d.ts +17 -1
  62. package/dist/composite.d.ts.map +1 -1
  63. package/dist/composite.js +27 -2
  64. package/dist/composite.js.map +1 -1
  65. package/dist/document-key.d.ts +36 -0
  66. package/dist/document-key.d.ts.map +1 -0
  67. package/dist/document-key.js +40 -0
  68. package/dist/document-key.js.map +1 -0
  69. package/dist/document-url.d.ts +9 -0
  70. package/dist/document-url.d.ts.map +1 -1
  71. package/dist/document-url.js +9 -0
  72. package/dist/document-url.js.map +1 -1
  73. package/dist/ids.d.ts +4 -4
  74. package/dist/ids.d.ts.map +1 -1
  75. package/dist/ids.js +4 -4
  76. package/dist/ids.js.map +1 -1
  77. package/dist/index.d.ts +6 -0
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +6 -0
  80. package/dist/index.js.map +1 -1
  81. package/dist/kinds.d.ts +7 -2
  82. package/dist/kinds.d.ts.map +1 -1
  83. package/dist/kinds.js +12 -3
  84. package/dist/kinds.js.map +1 -1
  85. package/dist/model.d.ts +36 -5
  86. package/dist/model.d.ts.map +1 -1
  87. package/dist/model.js +7 -1
  88. package/dist/model.js.map +1 -1
  89. package/dist/page-placement.d.ts +2 -2
  90. package/dist/page-placement.js +3 -2
  91. package/dist/page-placement.js.map +1 -1
  92. package/dist/pdf-key.d.ts +10 -0
  93. package/dist/pdf-key.d.ts.map +1 -0
  94. package/dist/pdf-key.js +22 -0
  95. package/dist/pdf-key.js.map +1 -0
  96. package/dist/placement.d.ts +20 -4
  97. package/dist/placement.d.ts.map +1 -1
  98. package/dist/placement.js +41 -5
  99. package/dist/placement.js.map +1 -1
  100. package/dist/region-image.d.ts +45 -0
  101. package/dist/region-image.d.ts.map +1 -0
  102. package/dist/region-image.js +76 -0
  103. package/dist/region-image.js.map +1 -0
  104. package/dist/scope.d.ts +17 -2
  105. package/dist/scope.d.ts.map +1 -1
  106. package/dist/scope.js +28 -4
  107. package/dist/scope.js.map +1 -1
  108. package/dist/store/store.d.ts +1 -1
  109. package/dist/store/store.d.ts.map +1 -1
  110. package/dist/store/store.js +11 -8
  111. package/dist/store/store.js.map +1 -1
  112. package/dist/testing/anchor-provider-contract.d.ts +3 -2
  113. package/dist/testing/anchor-provider-contract.d.ts.map +1 -1
  114. package/dist/testing/anchor-provider-contract.js +75 -22
  115. package/dist/testing/anchor-provider-contract.js.map +1 -1
  116. package/dist/testing/contract.d.ts +6 -0
  117. package/dist/testing/contract.d.ts.map +1 -1
  118. package/dist/testing/contract.js +22 -0
  119. package/dist/testing/contract.js.map +1 -1
  120. package/dist/testing/thread-contract.d.ts.map +1 -1
  121. package/dist/testing/thread-contract.js +2 -1
  122. package/dist/testing/thread-contract.js.map +1 -1
  123. package/dist/thread-write.d.ts +35 -0
  124. package/dist/thread-write.d.ts.map +1 -0
  125. package/dist/thread-write.js +69 -0
  126. package/dist/thread-write.js.map +1 -0
  127. package/dist/thread.d.ts +0 -21
  128. package/dist/thread.d.ts.map +1 -1
  129. package/dist/thread.js +2 -53
  130. package/dist/thread.js.map +1 -1
  131. package/dist/w3c.d.ts.map +1 -1
  132. package/dist/w3c.js +35 -6
  133. package/dist/w3c.js.map +1 -1
  134. package/package.json +6 -2
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Site profiles: most sites the generic engine cannot see well need no code of their own, only a
3
+ * description of where their stable units are (the lines of a diff, keyed by line number). A
4
+ * profile is that description as plain JSON, read by one built-in anchor provider, `profile`. See
5
+ * the design doc's "Hard pages in M7 > Anchor providers".
6
+ *
7
+ * A profile names the sites it is for (`hosts`, `paths`) and, with CSS selectors only, the units
8
+ * (`unit`), what each unit's key is read from (`key`) and where its text is (`text`). No profile
9
+ * field is code or a regular expression, so a profile can be checked (`validateProfile`) and come
10
+ * from a list the extension did not ship with.
11
+ *
12
+ * The provider describes a text selection inside one unit as `{ profile, rev, unit, start, end }`:
13
+ * the profile's name and revision, the unit's key, and offsets in the unit's normalized text. To
14
+ * resolve, it finds the unit by key and checks that the offsets still cover the note's stored quote;
15
+ * when they don't, it looks for the quote in the same unit, then (with `follow`) in the other units,
16
+ * nearest key first, which is how a note on a line follows it to a newer commit. Anything else is
17
+ * left to the generic engine: a selection across units, a note without a quote, a page whose units
18
+ * are not rendered yet.
19
+ */
20
+ import { type AnchorProvider, type AnchorProviders, type ProviderContext, type ProviderMatch } from "./providers.js";
21
+ import type { ProviderTarget } from "./provider-stage.js";
22
+ export { FIRST_PARTY_PROFILES, GITHUB_DIFF_PROFILE } from "./site-profiles.js";
23
+ /** One step from a unit to the element its key is read from. Applied in this order: `closest`,
24
+ * then `prev`, then `in`; each is a CSS selector. */
25
+ export interface ProfileKeyPart {
26
+ /** The nearest ancestor matching this, the unit itself included. */
27
+ closest?: string;
28
+ /** The nearest earlier sibling matching this. */
29
+ prev?: string;
30
+ /** The first descendant matching this. */
31
+ in?: string;
32
+ /** The attribute holding the key (`id`, `data-line-number`). */
33
+ attr: string;
34
+ }
35
+ /** A site profile: plain JSON, at most PROFILE_MAX characters. */
36
+ export interface SiteProfile {
37
+ /** Stored in every selector it writes: lower case letters, digits and dashes, starting with a
38
+ * letter, at most 40 characters. */
39
+ name: string;
40
+ /** The key format revision, a positive integer: raise it when `unit` or `key` change meaning.
41
+ * Selectors written at a higher revision are left to the generic engine. */
42
+ rev: number;
43
+ /** Host names, lower case: `github.com`, or `*.example.com` for its subdomains. */
44
+ hosts: readonly string[];
45
+ /**
46
+ * Path patterns, each starting with `/`: `*` is one path segment, a final `**` is any number of
47
+ * them, anything else is literal. Default: every path.
48
+ */
49
+ paths?: readonly string[];
50
+ /** The units: a CSS selector. */
51
+ unit: string;
52
+ /** Where a unit's key comes from: one to three parts, joined with `:`. */
53
+ key: readonly ProfileKeyPart[];
54
+ /** The text of a unit: the first descendant matching this CSS selector. Default the unit. */
55
+ text?: string;
56
+ /** Whether a note whose unit lost its text may move to another unit holding it. */
57
+ follow?: boolean;
58
+ }
59
+ /** What the profile provider stores in its ProviderSelector. */
60
+ export interface ProfileValue {
61
+ /** The profile's name. */
62
+ profile: string;
63
+ /** The profile's `rev` when it was written. */
64
+ rev: number;
65
+ /** The unit's key. */
66
+ unit: string;
67
+ /** Offsets in the unit's normalized text. */
68
+ start: number;
69
+ end: number;
70
+ }
71
+ /** Longest a profile may be, as JSON text. */
72
+ export declare const PROFILE_MAX: number;
73
+ /** The name of the provider that reads profiles. */
74
+ export declare const PROFILE_PROVIDER = "profile";
75
+ /** Default time one resolve may take before it leaves the note to the generic engine: well under
76
+ * the registry's budget, so no stored value can get the provider turned off for the page. */
77
+ export declare const PROFILE_RESOLVE_MS = 8;
78
+ /** Thrown by `validateProfile` for a malformed profile. */
79
+ export declare class ProfileError extends TypeError {
80
+ constructor(message: string);
81
+ }
82
+ /**
83
+ * Checks a profile and returns a frozen copy of it. Throws a ProfileError for anything but plain
84
+ * JSON of the shape above within PROFILE_MAX characters: unknown fields, a path pattern that is not
85
+ * one, a selector that is not valid CSS. Selectors are parsed with `document` (default the global
86
+ * one); where there is none (a service worker), only their form is checked, and a selector the page
87
+ * later refuses turns that profile off for the page.
88
+ */
89
+ export declare function validateProfile(input: unknown, document?: Document | undefined): Readonly<SiteProfile>;
90
+ /** Whether `profile` is for this URL. */
91
+ export declare function profileMatches(profile: Readonly<SiteProfile>, url: URL): boolean;
92
+ export interface ProfileProviderOptions {
93
+ /** Longest one resolve may look before it leaves the note to the generic engine, in
94
+ * milliseconds. Default PROFILE_RESOLVE_MS. */
95
+ limitMs?: number;
96
+ /** The clock, for tests. Default `performance.now`. */
97
+ now?: () => number;
98
+ }
99
+ /**
100
+ * The `profile` provider: reads every profile added to it. The core keeps one for the page
101
+ * (`profileProvider`, registered by `registerAnchorProfiles`); tests and embedders can make their
102
+ * own.
103
+ */
104
+ export declare class ProfileProvider implements AnchorProvider {
105
+ readonly name = "profile";
106
+ readonly version = 1;
107
+ /** By the object it was added as, so adding the same list again (two SDK instances) is counted. */
108
+ private readonly entries;
109
+ private readonly now;
110
+ private readonly limitMs;
111
+ constructor(profiles?: readonly unknown[], options?: ProfileProviderOptions);
112
+ /**
113
+ * Adds profiles; returns a function that removes them. Throws a ProfileError, adding none, for a
114
+ * malformed profile or another one of the same name. A registry that already asked `matches`
115
+ * keeps its answer until told otherwise: use `registerAnchorProfiles`, or call the registry's
116
+ * `rematch` after adding to a registered provider.
117
+ */
118
+ add(profiles: readonly unknown[]): () => void;
119
+ /** The profiles added, in the order they were added. */
120
+ get profiles(): Readonly<SiteProfile>[];
121
+ matches(url: URL): boolean;
122
+ describe(target: ProviderTarget, context: ProviderContext): ProfileValue | null;
123
+ resolve(value: unknown, _version: number, context: ProviderContext): ProviderMatch | null;
124
+ /** Per document: the profiles whose selectors it refused. */
125
+ private readonly refused;
126
+ /**
127
+ * Runs one profile's work; a selector the page's engine refuses (checked without a DOM, or
128
+ * syntax this browser lacks) turns only that profile off for the document.
129
+ */
130
+ private guard;
131
+ }
132
+ /** The page's profile provider. */
133
+ export declare const profileProvider: ProfileProvider;
134
+ /**
135
+ * Adds site profiles for the page and registers the `profile` provider with the page's providers
136
+ * (`anchorProviders`). Returns a function that removes them. Throws a ProfileError for a malformed
137
+ * profile, or another of the same name; nothing is added then.
138
+ */
139
+ export declare function registerAnchorProfiles(profiles: readonly unknown[], providers?: AnchorProviders): () => void;
140
+ //# sourceMappingURL=profiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/anchoring/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE/E;qDACqD;AACrD,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,kEAAkE;AAClE,MAAM,WAAW,WAAW;IAC1B;wCACoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb;gFAC4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,GAAG,EAAE,SAAS,cAAc,EAAE,CAAC;IAC/B,6FAA6F;IAC7F,IAAI,CAA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