@difizen/libro-rendermime 0.0.2-alpha.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/components/html-render.d.ts +6 -0
  4. package/es/components/html-render.d.ts.map +1 -0
  5. package/es/components/html-render.js +39 -0
  6. package/es/components/image-render.d.ts +6 -0
  7. package/es/components/image-render.d.ts.map +1 -0
  8. package/es/components/image-render.js +36 -0
  9. package/es/components/index.d.ts +7 -0
  10. package/es/components/index.d.ts.map +1 -0
  11. package/es/components/index.js +6 -0
  12. package/es/components/latex-render.d.ts +6 -0
  13. package/es/components/latex-render.d.ts.map +1 -0
  14. package/es/components/latex-render.js +23 -0
  15. package/es/components/markdown-render.d.ts +6 -0
  16. package/es/components/markdown-render.d.ts.map +1 -0
  17. package/es/components/markdown-render.js +38 -0
  18. package/es/components/svg-render.d.ts +6 -0
  19. package/es/components/svg-render.d.ts.map +1 -0
  20. package/es/components/svg-render.js +33 -0
  21. package/es/components/text-render.d.ts +9 -0
  22. package/es/components/text-render.d.ts.map +1 -0
  23. package/es/components/text-render.js +44 -0
  24. package/es/index.d.ts +7 -0
  25. package/es/index.d.ts.map +1 -0
  26. package/es/index.js +6 -0
  27. package/es/renderers.d.ts +42 -0
  28. package/es/renderers.d.ts.map +1 -0
  29. package/es/renderers.js +327 -0
  30. package/es/rendermime-factory.d.ts +30 -0
  31. package/es/rendermime-factory.d.ts.map +1 -0
  32. package/es/rendermime-factory.js +73 -0
  33. package/es/rendermime-module.d.ts +3 -0
  34. package/es/rendermime-module.d.ts.map +1 -0
  35. package/es/rendermime-module.js +11 -0
  36. package/es/rendermime-protocol.d.ts +405 -0
  37. package/es/rendermime-protocol.d.ts.map +1 -0
  38. package/es/rendermime-protocol.js +60 -0
  39. package/es/rendermime-registry.d.ts +135 -0
  40. package/es/rendermime-registry.d.ts.map +1 -0
  41. package/es/rendermime-registry.js +392 -0
  42. package/es/rendermime-utils.d.ts +87 -0
  43. package/es/rendermime-utils.d.ts.map +1 -0
  44. package/es/rendermime-utils.js +603 -0
  45. package/package.json +61 -0
  46. package/src/components/html-render.tsx +42 -0
  47. package/src/components/image-render.tsx +46 -0
  48. package/src/components/index.ts +6 -0
  49. package/src/components/latex-render.tsx +30 -0
  50. package/src/components/markdown-render.tsx +42 -0
  51. package/src/components/svg-render.tsx +38 -0
  52. package/src/components/text-render.tsx +51 -0
  53. package/src/index.ts +6 -0
  54. package/src/renderers.ts +325 -0
  55. package/src/rendermime-factory.ts +92 -0
  56. package/src/rendermime-module.ts +19 -0
  57. package/src/rendermime-protocol.ts +516 -0
  58. package/src/rendermime-registry.ts +301 -0
  59. package/src/rendermime-utils.ts +665 -0
@@ -0,0 +1,405 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type { ISanitizer } from '@difizen/libro-common';
3
+ import type { BaseOutputView } from '@difizen/libro-core';
4
+ import type { MarkdownParser } from '@difizen/libro-markdown';
5
+ import { Syringe } from '@difizen/mana-app';
6
+ export declare const DefaultRenderMimeRegistry: unique symbol;
7
+ export declare const IRenderMimeRegistryOptions: unique symbol;
8
+ export declare const RenderMimeContribution: Syringe.DefinedToken;
9
+ export interface RenderMimeContribution {
10
+ canHandle: (model: BaseOutputView) => number;
11
+ safe: boolean;
12
+ renderType: string;
13
+ mimeTypes: string[];
14
+ render: React.FC<{
15
+ model: BaseOutputView;
16
+ options?: Record<string, any>;
17
+ }>;
18
+ }
19
+ /**
20
+ * The interface for a renderer factory.
21
+ */
22
+ export interface IRendererFactory {
23
+ /**
24
+ * Whether the factory is a "safe" factory.
25
+ *
26
+ * #### Notes
27
+ * A "safe" factory produces renderer widgets which can render
28
+ * untrusted model data in a usable way. *All* renderers must
29
+ * handle untrusted data safely, but some may simply failover
30
+ * with a "Run cell to view output" message. A "safe" renderer
31
+ * is an indication that its sanitized output will be useful.
32
+ */
33
+ readonly safe: boolean;
34
+ readonly renderType: string;
35
+ /**
36
+ * The mime types handled by this factory.
37
+ */
38
+ readonly mimeTypes: readonly string[];
39
+ /**
40
+ * The default rank of the factory. If not given, defaults to 100.
41
+ */
42
+ readonly defaultRank?: number;
43
+ /**
44
+ * Create a renderer which displays the mime data.
45
+ *
46
+ * @param options - The options used to render the data.
47
+ */
48
+ render: React.FC<{
49
+ model: BaseOutputView;
50
+ props?: Record<string, any>;
51
+ }>;
52
+ }
53
+ /**
54
+ * An object that resolves relative URLs.
55
+ */
56
+ export interface IResolver {
57
+ /**
58
+ * Resolve a relative url to an absolute url path.
59
+ */
60
+ resolveUrl: (url: string) => Promise<string>;
61
+ /**
62
+ * Get the download url for a given absolute url path.
63
+ *
64
+ * #### Notes
65
+ * This URL may include a query parameter.
66
+ */
67
+ getDownloadUrl: (url: string) => Promise<string>;
68
+ /**
69
+ * Whether the URL should be handled by the resolver
70
+ * or not.
71
+ *
72
+ * #### Notes
73
+ * This is similar to the `isLocal` check in `URL`,
74
+ * but can also perform additional checks on whether the
75
+ * resolver should handle a given URL.
76
+ */
77
+ isLocal?: (url: string) => boolean;
78
+ }
79
+ /**
80
+ * An object that handles links on a node.
81
+ */
82
+ export interface ILinkHandler {
83
+ /**
84
+ * Add the link handler to the node.
85
+ *
86
+ * @param node: the anchor node for which to handle the link.
87
+ *
88
+ * @param path: the path to open when the link is clicked.
89
+ *
90
+ * @param id: an optional element id to scroll to when the path is opened.
91
+ */
92
+ handleLink: (node: HTMLElement, path: string, id?: string) => void;
93
+ }
94
+ /**
95
+ * Interface for generic renderer.
96
+ */
97
+ export interface IRenderer {
98
+ readonly render: (container: HTMLElement, options?: any) => void;
99
+ readonly unrender?: (container: HTMLElement, options?: any) => void;
100
+ }
101
+ /**
102
+ * The options used to clone a rendermime instance.
103
+ */
104
+ export interface ICloneOptions {
105
+ /**
106
+ * The new sanitizer used to sanitize untrusted html inputs.
107
+ */
108
+ sanitizer?: ISanitizer;
109
+ /**
110
+ * The new resolver object.
111
+ */
112
+ resolver?: IResolver;
113
+ /**
114
+ * The new path handler.
115
+ */
116
+ linkHandler?: ILinkHandler;
117
+ /**
118
+ * The new Markdown parser.
119
+ */
120
+ markdownParser?: MarkdownParser;
121
+ }
122
+ export interface IRenderMimeRegistry {
123
+ /**
124
+ * The sanitizer used by the rendermime instance.
125
+ */
126
+ readonly sanitizer: ISanitizer;
127
+ /**
128
+ * The object used to resolve relative urls for the rendermime instance.
129
+ */
130
+ readonly resolver: IResolver | null;
131
+ /**
132
+ * The object used to handle path opening links.
133
+ */
134
+ readonly linkHandler: ILinkHandler | null;
135
+ /**
136
+ * The Markdown parser for the rendermime.
137
+ */
138
+ readonly markdownParser: MarkdownParser | null;
139
+ /**
140
+ * The ordered list of mimeTypes.
141
+ */
142
+ readonly mimeTypes: readonly string[];
143
+ /**
144
+ * Find the preferred mime type for a mime bundle.
145
+ *
146
+ * @param bundle - The bundle of mime data.
147
+ *
148
+ * @param safe - How to consider safe/unsafe factories. If 'ensure',
149
+ * it will only consider safe factories. If 'any', any factory will be
150
+ * considered. If 'prefer', unsafe factories will be considered, but
151
+ * only after the safe options have been exhausted.
152
+ *
153
+ * @returns The preferred mime type from the available factories,
154
+ * or `undefined` if the mime type cannot be rendered.
155
+ */
156
+ preferredMimeType: (model: BaseOutputView, safe?: 'ensure' | 'prefer' | 'any') => string | undefined;
157
+ defaultPreferredMimeType: (model: BaseOutputView, safe?: 'ensure' | 'prefer' | 'any') => string | undefined;
158
+ /**
159
+ * Create a renderer for a mime type.
160
+ *
161
+ * @param mimeType - The mime type of interest.
162
+ *
163
+ * @returns A new renderer for the given mime type.
164
+ *
165
+ * @throws An error if no factory exists for the mime type.
166
+ */
167
+ createRenderer: (mimeType: string, model: BaseOutputView) => React.FC<{
168
+ model: BaseOutputView;
169
+ }>;
170
+ /**
171
+ * Get the renderer factory registered for a mime type.
172
+ *
173
+ * @param mimeType - The mime type of interest.
174
+ *
175
+ * @returns The factory for the mime type, or `undefined`.
176
+ */
177
+ getFactory: (mimeType: string) => IRendererFactory | undefined;
178
+ /**
179
+ * Add a renderer factory to the rendermime.
180
+ *
181
+ * @param factory - The renderer factory of interest.
182
+ *
183
+ * @param rank - The rank of the renderer. A lower rank indicates
184
+ * a higher priority for rendering. If not given, the rank will
185
+ * defer to the `defaultRank` of the factory. If no `defaultRank`
186
+ * is given, it will default to 100.
187
+ *
188
+ * #### Notes
189
+ * The renderer will replace an existing renderer for the given
190
+ * mimeType.
191
+ */
192
+ addFactory: (factory: IRendererFactory, rank?: number) => void;
193
+ /**
194
+ * Remove a mime type.
195
+ *
196
+ * @param mimeType - The mime type of interest.
197
+ */
198
+ removeMimeType: (mimeType: string) => void;
199
+ /**
200
+ * Get the rank for a given mime type.
201
+ *
202
+ * @param mimeType - The mime type of interest.
203
+ *
204
+ * @returns The rank of the mime type or undefined.
205
+ */
206
+ getRank: (mimeType: string) => number | undefined;
207
+ /**
208
+ * Set the rank of a given mime type.
209
+ *
210
+ * @param mimeType - The mime type of interest.
211
+ *
212
+ * @param rank - The new rank to assign.
213
+ *
214
+ * #### Notes
215
+ * This is a no-op if the mime type is not registered.
216
+ */
217
+ setRank: (mimeType: string, rank: number) => void;
218
+ }
219
+ /**
220
+ * The options for the `renderText` function.
221
+ */
222
+ export interface IRenderTextOptions {
223
+ /**
224
+ * The host node for the text content.
225
+ */
226
+ host: HTMLElement;
227
+ /**
228
+ * The html sanitizer for untrusted source.
229
+ */
230
+ sanitizer: ISanitizer;
231
+ /**
232
+ * The source text to render.
233
+ */
234
+ source: string;
235
+ mimeType: string;
236
+ }
237
+ /**
238
+ * The options for the `renderImage` function.
239
+ */
240
+ export interface IRenderImageOptions {
241
+ /**
242
+ * The image node to update with the content.
243
+ */
244
+ host: HTMLElement;
245
+ /**
246
+ * The mime type for the image.
247
+ */
248
+ mimeType: string;
249
+ /**
250
+ * The base64 encoded source for the image.
251
+ */
252
+ source: string;
253
+ /**
254
+ * The optional width for the image.
255
+ */
256
+ width?: number;
257
+ /**
258
+ * The optional height for the image.
259
+ */
260
+ height?: number;
261
+ /**
262
+ * Whether an image requires a background for legibility.
263
+ */
264
+ needsBackground?: string;
265
+ /**
266
+ * Whether the image should be unconfined.
267
+ */
268
+ unconfined?: boolean;
269
+ }
270
+ /**
271
+ * The options for the `renderHTML` function.
272
+ */
273
+ export interface IRenderHTMLOptions {
274
+ /**
275
+ * The host node for the rendered HTML.
276
+ */
277
+ host: HTMLElement;
278
+ /**
279
+ * The HTML source to render.
280
+ */
281
+ source: string;
282
+ /**
283
+ * Whether the source is trusted.
284
+ */
285
+ trusted: boolean;
286
+ /**
287
+ * The html sanitizer for untrusted source.
288
+ */
289
+ sanitizer: ISanitizer;
290
+ /**
291
+ * An optional url resolver.
292
+ */
293
+ resolver: IResolver | null;
294
+ /**
295
+ * An optional link handler.
296
+ */
297
+ linkHandler: ILinkHandler | null;
298
+ /**
299
+ * Whether the node should be typeset.
300
+ */
301
+ shouldTypeset: boolean;
302
+ }
303
+ /**
304
+ * The options for the `renderMarkdown` function.
305
+ */
306
+ export interface IRenderMarkdownOptions {
307
+ /**
308
+ * The host node for the rendered Markdown.
309
+ */
310
+ host: HTMLElement;
311
+ /**
312
+ * The Markdown source to render.
313
+ */
314
+ source: string;
315
+ /**
316
+ * Whether the source is trusted.
317
+ */
318
+ trusted: boolean;
319
+ /**
320
+ * The html sanitizer for untrusted source.
321
+ */
322
+ sanitizer: ISanitizer;
323
+ /**
324
+ * An optional url resolver.
325
+ */
326
+ resolver: IResolver | null;
327
+ /**
328
+ * An optional link handler.
329
+ */
330
+ linkHandler: ILinkHandler | null;
331
+ /**
332
+ * Whether the node should be typeset.
333
+ */
334
+ /**
335
+ * The Markdown parser.
336
+ */
337
+ markdownParser: MarkdownParser | null;
338
+ cellId?: string;
339
+ }
340
+ /**
341
+ * The options for the `renderSVG` function.
342
+ */
343
+ export interface IRenderSVGOptions {
344
+ /**
345
+ * The host node for the rendered SVG.
346
+ */
347
+ host: HTMLElement;
348
+ /**
349
+ * The SVG source.
350
+ */
351
+ source: string;
352
+ /**
353
+ * Whether the source is trusted.
354
+ */
355
+ trusted: boolean;
356
+ /**
357
+ * Whether the svg should be unconfined.
358
+ */
359
+ unconfined?: boolean;
360
+ }
361
+ /**
362
+ * The options used to initialize a rendermime instance.
363
+ */
364
+ export interface IRenderMimeRegistryOptions {
365
+ /**
366
+ * Initial factories to add to the rendermime instance.
367
+ */
368
+ initialFactories?: readonly IRendererFactory[];
369
+ /**
370
+ * The sanitizer used to sanitize untrusted html inputs.
371
+ *
372
+ * If not given, a default sanitizer will be used.
373
+ */
374
+ sanitizer?: ISanitizer;
375
+ /**
376
+ * The initial resolver object.
377
+ *
378
+ * The default is `null`.
379
+ */
380
+ resolver?: IResolver;
381
+ /**
382
+ * An optional path handler.
383
+ */
384
+ linkHandler?: ILinkHandler;
385
+ /**
386
+ * An optional Markdown parser.
387
+ */
388
+ markdownParser?: MarkdownParser;
389
+ }
390
+ /**
391
+ * A type alias for a mime rank and tie-breaking id.
392
+ */
393
+ export type RankPair = {
394
+ readonly id: number;
395
+ readonly rank: number;
396
+ };
397
+ /**
398
+ * A type alias for a mapping of mime type -> rank pair.
399
+ */
400
+ export type RankMap = Record<string, RankPair>;
401
+ /**
402
+ * A type alias for a mapping of mime type -> ordered factories.
403
+ */
404
+ export type FactoryMap = Record<string, IRendererFactory>;
405
+ //# sourceMappingURL=rendermime-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rendermime-protocol.d.ts","sourceRoot":"","sources":["../src/rendermime-protocol.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,eAAO,MAAM,yBAAyB,eAA+B,CAAC;AACtE,eAAO,MAAM,0B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C,EAAE,SAAS,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAE3B;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CAMjC;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { Syringe } from '@difizen/mana-app';
2
+ export var DefaultRenderMimeRegistry = Symbol('RenderMimeRegistry');
3
+ export var IRenderMimeRegistryOptions = Symbol('IRenderMimeRegistryOptions');
4
+ export var RenderMimeContribution = Syringe.defineToken('RenderMimeTypeContribution');
5
+
6
+ /**
7
+ * The interface for a renderer factory.
8
+ */
9
+
10
+ /**
11
+ * An object that resolves relative URLs.
12
+ */
13
+
14
+ /**
15
+ * An object that handles links on a node.
16
+ */
17
+
18
+ /**
19
+ * Interface for generic renderer.
20
+ */
21
+
22
+ /**
23
+ * The options used to clone a rendermime instance.
24
+ */
25
+
26
+ /**
27
+ * The options for the `renderText` function.
28
+ */
29
+
30
+ /**
31
+ * The options for the `renderImage` function.
32
+ */
33
+
34
+ /**
35
+ * The options for the `renderHTML` function.
36
+ */
37
+
38
+ /**
39
+ * The options for the `renderMarkdown` function.
40
+ */
41
+
42
+ /**
43
+ * The options for the `renderSVG` function.
44
+ */
45
+
46
+ /**
47
+ * The options used to initialize a rendermime instance.
48
+ */
49
+
50
+ /**
51
+ * A type alias for a mime rank and tie-breaking id.
52
+ */
53
+
54
+ /**
55
+ * A type alias for a mapping of mime type -> rank pair.
56
+ */
57
+
58
+ /**
59
+ * A type alias for a mapping of mime type -> ordered factories.
60
+ */
@@ -0,0 +1,135 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type { BaseOutputView } from '@difizen/libro-core';
3
+ import { MarkdownParser } from '@difizen/libro-markdown';
4
+ import type { Contribution } from '@difizen/mana-app';
5
+ import { Emitter } from '@difizen/mana-app';
6
+ import { RenderMimeContribution, IRenderMimeRegistryOptions } from './rendermime-protocol.js';
7
+ import type { ILinkHandler, IRendererFactory, IRenderMimeRegistry, IResolver } from './rendermime-protocol.js';
8
+ /**
9
+ * An object which manages mime renderer factories.
10
+ *
11
+ * This object is used to render mime models using registered mime
12
+ * renderers, selecting the preferred mime renderer to render the
13
+ * model into a widget.
14
+ *
15
+ * #### Notes
16
+ * This class is not intended to be subclassed.
17
+ */
18
+ export declare class RenderMimeRegistry implements IRenderMimeRegistry {
19
+ renderMimeEmitter: Emitter<{
20
+ renderType: string;
21
+ mimeType: string;
22
+ }>;
23
+ get onMimeRender(): import("@difizen/mana-app").Event<{
24
+ renderType: string;
25
+ mimeType: string;
26
+ }>;
27
+ /**
28
+ * Construct a new rendermime.
29
+ *
30
+ * @param options - The options for initializing the instance.
31
+ */
32
+ constructor(options: IRenderMimeRegistryOptions, markdownParser: MarkdownParser);
33
+ renderMimeProvider: Contribution.Provider<RenderMimeContribution>;
34
+ /**
35
+ * The sanitizer used by the rendermime instance.
36
+ */
37
+ readonly sanitizer: import("@difizen/libro-common").ISanitizer;
38
+ /**
39
+ * The object used to resolve relative urls for the rendermime instance.
40
+ */
41
+ readonly resolver: IResolver | null;
42
+ /**
43
+ * The object used to handle path opening links.
44
+ */
45
+ readonly linkHandler: ILinkHandler | null;
46
+ /**
47
+ * The Markdown parser for the rendermime.
48
+ */
49
+ readonly markdownParser: MarkdownParser | null;
50
+ /**
51
+ * The ordered list of mimeTypes.
52
+ */
53
+ get mimeTypes(): readonly string[];
54
+ protected getSortedRenderMimes(model: BaseOutputView): RenderMimeContribution[];
55
+ defaultPreferredMimeType(model: BaseOutputView): string | undefined;
56
+ /**
57
+ * Find the preferred mime type for a mime bundle.
58
+ *
59
+ * @param bundle - The bundle of mime data.
60
+ *
61
+ * @param safe - How to consider safe/unsafe factories. If 'ensure',
62
+ * it will only consider safe factories. If 'any', any factory will be
63
+ * considered. If 'prefer', unsafe factories will be considered, but
64
+ * only after the safe options have been exhausted.
65
+ *
66
+ * @returns The preferred mime type from the available factories,
67
+ * or `undefined` if the mime type cannot be rendered.
68
+ */
69
+ preferredMimeType(model: BaseOutputView): string | undefined;
70
+ /**
71
+ * Create a renderer for a mime type.
72
+ *
73
+ * @param mimeType - The mime type of interest.
74
+ *
75
+ * @returns A new renderer for the given mime type.
76
+ *
77
+ * @throws An error if no factory exists for the mime type.
78
+ */
79
+ createRenderer(mimeType: string, model: BaseOutputView): React.FC<{
80
+ model: BaseOutputView;
81
+ }>;
82
+ /**
83
+ * Get the renderer factory registered for a mime type.
84
+ *
85
+ * @param mimeType - The mime type of interest.
86
+ *
87
+ * @returns The factory for the mime type, or `undefined`.
88
+ */
89
+ getFactory(mimeType: string): IRendererFactory | undefined;
90
+ /**
91
+ * Add a renderer factory to the rendermime.
92
+ *
93
+ * @param factory - The renderer factory of interest.
94
+ *
95
+ * @param _rank - The rank of the renderer. A lower rank indicates
96
+ * a higher priority for rendering. If not given, the rank will
97
+ * defer to the `defaultRank` of the factory. If no `defaultRank`
98
+ * is given, it will default to 100.
99
+ *
100
+ * #### Notes
101
+ * The renderer will replace an existing renderer for the given
102
+ * mimeType.
103
+ */
104
+ addFactory(factory: IRendererFactory, _rank?: number): void;
105
+ /**
106
+ * Remove a mime type.
107
+ *
108
+ * @param mimeType - The mime type of interest.
109
+ */
110
+ removeMimeType(mimeType: string): void;
111
+ /**
112
+ * Get the rank for a given mime type.
113
+ *
114
+ * @param mimeType - The mime type of interest.
115
+ *
116
+ * @returns The rank of the mime type or undefined.
117
+ */
118
+ getRank(mimeType: string): number | undefined;
119
+ /**
120
+ * Set the rank of a given mime type.
121
+ *
122
+ * @param mimeType - The mime type of interest.
123
+ *
124
+ * @param rank - The new rank to assign.
125
+ *
126
+ * #### Notes
127
+ * This is a no-op if the mime type is not registered.
128
+ */
129
+ setRank(mimeType: string, rank: number): void;
130
+ private _id;
131
+ private _ranks;
132
+ private _types;
133
+ private _factories;
134
+ }
135
+ //# sourceMappingURL=rendermime-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rendermime-registry.d.ts","sourceRoot":"","sources":["../src/rendermime-registry.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAEV,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAGlC;;;;;;;;;GASG;AACH,qBACa,kBAAmB,YAAW,mBAAmB;IAC5D,iBAAiB,EAAE,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAiB;IACrF,IAAI,YAAY;;;OAEf;IACD;;;;OAIG;gBAEmC,OAAO,EAAE,0BAA0B,EAC/C,cAAc,EAAE,cAAc;IAkBxD,kBAAkB,EAAE,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;IAElE;;OAEG;IACH,QAAQ,CAAC,SAAS,6CAAoB;IAEtC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,YAAY,GAAG,IAAI,CAAC;IAE1C;;OAEG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