@prose-reader/enhancer-refit 1.303.0 → 1.304.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.
- package/dist/index.js +46 -61
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +55 -70
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,69 +1,54 @@
|
|
|
1
|
-
import { HTML_ATTRIBUTE_DATA_READER_ID, HTML_PREFIX_VIEWPORT, ReactiveEntity } from
|
|
2
|
-
import { combineLatest,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { HTML_ATTRIBUTE_DATA_READER_ID, HTML_PREFIX_VIEWPORT, ReactiveEntity } from "@prose-reader/core";
|
|
2
|
+
import { combineLatest, distinctUntilChanged, map, tap } from "rxjs";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
var Settings = class extends ReactiveEntity {
|
|
5
|
+
update(settings) {
|
|
6
|
+
super.mergeCompare(settings);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var refitEnhancer = (next) => (options) => {
|
|
10
|
+
const { refit = {}, ...rest } = options;
|
|
11
|
+
const reader = next(rest);
|
|
12
|
+
const settings = new Settings(refit);
|
|
13
|
+
const stylesheetId = `prose-reader-refit-${reader.id}`;
|
|
14
|
+
const maxWidthCssVariable = `--${stylesheetId}-max-width`;
|
|
15
|
+
const style = document.createElement("style");
|
|
16
|
+
style.id = stylesheetId;
|
|
17
|
+
style.textContent = `
|
|
18
18
|
[${HTML_ATTRIBUTE_DATA_READER_ID}] [data-${HTML_PREFIX_VIEWPORT}] {
|
|
19
19
|
margin: auto;
|
|
20
20
|
width: 100%;
|
|
21
21
|
max-width: var(${maxWidthCssVariable});
|
|
22
22
|
}
|
|
23
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
|
-
).subscribe();
|
|
52
|
-
const destroy = () => {
|
|
53
|
-
viewportFitSubscription.unsubscribe();
|
|
54
|
-
document.head.removeChild(style);
|
|
55
|
-
reader.destroy();
|
|
56
|
-
};
|
|
57
|
-
return {
|
|
58
|
-
...reader,
|
|
59
|
-
__PROSE_READER_ENHANCER_REFIT: true,
|
|
60
|
-
destroy,
|
|
61
|
-
refit: {
|
|
62
|
-
update: settings.update.bind(settings),
|
|
63
|
-
settings$: settings
|
|
64
|
-
}
|
|
65
|
-
};
|
|
24
|
+
document.head.appendChild(style);
|
|
25
|
+
const viewportFitSubscription = combineLatest([settings.watch(["viewportFit", "customWidth"]), reader.settings.watch(["computedPageTurnMode"])]).pipe(map(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {
|
|
26
|
+
if (computedPageTurnMode === "scrollable") {
|
|
27
|
+
if (viewportFit === "desktop") return "800px";
|
|
28
|
+
if (viewportFit === "tablet") return "600px";
|
|
29
|
+
if (viewportFit === "custom") return `${customWidth ?? 100}%`;
|
|
30
|
+
}
|
|
31
|
+
return "100%";
|
|
32
|
+
}), distinctUntilChanged(), tap((maxWidth) => {
|
|
33
|
+
document.documentElement.style.setProperty(maxWidthCssVariable, maxWidth);
|
|
34
|
+
reader.layout();
|
|
35
|
+
})).subscribe();
|
|
36
|
+
const destroy = () => {
|
|
37
|
+
viewportFitSubscription.unsubscribe();
|
|
38
|
+
document.head.removeChild(style);
|
|
39
|
+
reader.destroy();
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
...reader,
|
|
43
|
+
__PROSE_READER_ENHANCER_REFIT: true,
|
|
44
|
+
destroy,
|
|
45
|
+
refit: {
|
|
46
|
+
update: settings.update.bind(settings),
|
|
47
|
+
settings$: settings
|
|
48
|
+
}
|
|
49
|
+
};
|
|
66
50
|
};
|
|
67
|
-
|
|
51
|
+
//#endregion
|
|
68
52
|
export { refitEnhancer };
|
|
69
|
-
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import {\n HTML_ATTRIBUTE_DATA_READER_ID,\n HTML_PREFIX_VIEWPORT,\n ReactiveEntity,\n type Reader,\n} from \"@prose-reader/core\"\nimport {\n combineLatest,\n distinctUntilChanged,\n map,\n type Observable,\n tap,\n} from \"rxjs\"\n\nexport type RefitEnhancerAPI = {\n readonly __PROSE_READER_ENHANCER_REFIT: boolean\n refit: {\n update: (settings: Partial<RefitEnhancerOptions>) => void\n settings$: Observable<RefitEnhancerOptions>\n }\n}\n\nexport type RefitEnhancerOptions = {\n viewportFit?: \"desktop\" | \"tablet\" | \"fit\" | \"custom\"\n customWidth?: number\n}\n\nclass Settings extends ReactiveEntity<RefitEnhancerOptions> {\n update(settings: RefitEnhancerOptions) {\n super.mergeCompare(settings)\n }\n}\n\nexport const refitEnhancer =\n <InheritOptions, InheritOutput extends Reader>(\n next: (options: InheritOptions) => InheritOutput,\n ) =>\n (\n options: InheritOptions & {\n refit?: Partial<RefitEnhancerOptions>\n },\n ): InheritOutput & RefitEnhancerAPI => {\n const { refit = {}, ...rest } = options\n const reader = next(rest as InheritOptions)\n const settings = new Settings(refit)\n const stylesheetId = `prose-reader-refit-${reader.id}`\n const maxWidthCssVariable = `--${stylesheetId}-max-width`\n\n const style = document.createElement(\"style\")\n style.id = stylesheetId\n style.textContent = `\n [${HTML_ATTRIBUTE_DATA_READER_ID}] [data-${HTML_PREFIX_VIEWPORT}] {\n margin: auto;\n width: 100%;\n max-width: var(${maxWidthCssVariable});\n }\n `\n\n document.head.appendChild(style)\n\n const viewportFitSubscription = combineLatest([\n settings.watch([\"viewportFit\", \"customWidth\"]),\n reader.settings.watch([\"computedPageTurnMode\"]),\n ])\n .pipe(\n map(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {\n if (computedPageTurnMode === \"scrollable\") {\n if (viewportFit === \"desktop\") {\n return \"800px\"\n }\n\n if (viewportFit === \"tablet\") {\n return \"600px\"\n }\n\n if (viewportFit === \"custom\") {\n return `${customWidth ?? 100}%`\n }\n }\n\n return \"100%\"\n }),\n distinctUntilChanged(),\n tap((maxWidth) => {\n document.documentElement.style.setProperty(\n maxWidthCssVariable,\n maxWidth,\n )\n reader.layout()\n }),\n )\n .subscribe()\n\n const destroy = () => {\n viewportFitSubscription.unsubscribe()\n document.head.removeChild(style)\n reader.destroy()\n }\n\n return {\n ...reader,\n __PROSE_READER_ENHANCER_REFIT: true,\n destroy,\n refit: {\n update: settings.update.bind(settings),\n settings$: settings,\n },\n }\n }\n"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n HTML_ATTRIBUTE_DATA_READER_ID,\n HTML_PREFIX_VIEWPORT,\n ReactiveEntity,\n type Reader,\n} from \"@prose-reader/core\"\nimport {\n combineLatest,\n distinctUntilChanged,\n map,\n type Observable,\n tap,\n} from \"rxjs\"\n\nexport type RefitEnhancerAPI = {\n readonly __PROSE_READER_ENHANCER_REFIT: boolean\n refit: {\n update: (settings: Partial<RefitEnhancerOptions>) => void\n settings$: Observable<RefitEnhancerOptions>\n }\n}\n\nexport type RefitEnhancerOptions = {\n viewportFit?: \"desktop\" | \"tablet\" | \"fit\" | \"custom\"\n customWidth?: number\n}\n\nclass Settings extends ReactiveEntity<RefitEnhancerOptions> {\n update(settings: RefitEnhancerOptions) {\n super.mergeCompare(settings)\n }\n}\n\nexport const refitEnhancer =\n <InheritOptions, InheritOutput extends Reader>(\n next: (options: InheritOptions) => InheritOutput,\n ) =>\n (\n options: InheritOptions & {\n refit?: Partial<RefitEnhancerOptions>\n },\n ): InheritOutput & RefitEnhancerAPI => {\n const { refit = {}, ...rest } = options\n const reader = next(rest as InheritOptions)\n const settings = new Settings(refit)\n const stylesheetId = `prose-reader-refit-${reader.id}`\n const maxWidthCssVariable = `--${stylesheetId}-max-width`\n\n const style = document.createElement(\"style\")\n style.id = stylesheetId\n style.textContent = `\n [${HTML_ATTRIBUTE_DATA_READER_ID}] [data-${HTML_PREFIX_VIEWPORT}] {\n margin: auto;\n width: 100%;\n max-width: var(${maxWidthCssVariable});\n }\n `\n\n document.head.appendChild(style)\n\n const viewportFitSubscription = combineLatest([\n settings.watch([\"viewportFit\", \"customWidth\"]),\n reader.settings.watch([\"computedPageTurnMode\"]),\n ])\n .pipe(\n map(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {\n if (computedPageTurnMode === \"scrollable\") {\n if (viewportFit === \"desktop\") {\n return \"800px\"\n }\n\n if (viewportFit === \"tablet\") {\n return \"600px\"\n }\n\n if (viewportFit === \"custom\") {\n return `${customWidth ?? 100}%`\n }\n }\n\n return \"100%\"\n }),\n distinctUntilChanged(),\n tap((maxWidth) => {\n document.documentElement.style.setProperty(\n maxWidthCssVariable,\n maxWidth,\n )\n reader.layout()\n }),\n )\n .subscribe()\n\n const destroy = () => {\n viewportFitSubscription.unsubscribe()\n document.head.removeChild(style)\n reader.destroy()\n }\n\n return {\n ...reader,\n __PROSE_READER_ENHANCER_REFIT: true,\n destroy,\n refit: {\n update: settings.update.bind(settings),\n settings$: settings,\n },\n }\n }\n"],"mappings":";;;AA2BA,IAAM,WAAN,cAAuB,eAAqC;CAC1D,OAAO,UAAgC;EACrC,MAAM,aAAa,QAAQ;CAC7B;AAC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10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@prose-reader/core"), require("rxjs")) : typeof define === "function" && define.amd ? define([
|
|
3
|
+
"exports",
|
|
4
|
+
"@prose-reader/core",
|
|
5
|
+
"rxjs"
|
|
6
|
+
], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["prose-reader-enhancer-refit"] = {}, global._prose_reader_core, global.rxjs));
|
|
7
|
+
})(this, function(exports, _prose_reader_core, rxjs) {
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
var Settings = class extends _prose_reader_core.ReactiveEntity {
|
|
11
|
+
update(settings) {
|
|
12
|
+
super.mergeCompare(settings);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var refitEnhancer = (next) => (options) => {
|
|
16
|
+
const { refit = {}, ...rest } = options;
|
|
17
|
+
const reader = next(rest);
|
|
18
|
+
const settings = new Settings(refit);
|
|
19
|
+
const stylesheetId = `prose-reader-refit-${reader.id}`;
|
|
20
|
+
const maxWidthCssVariable = `--${stylesheetId}-max-width`;
|
|
21
|
+
const style = document.createElement("style");
|
|
22
|
+
style.id = stylesheetId;
|
|
23
|
+
style.textContent = `
|
|
24
|
+
[${_prose_reader_core.HTML_ATTRIBUTE_DATA_READER_ID}] [data-${_prose_reader_core.HTML_PREFIX_VIEWPORT}] {
|
|
22
25
|
margin: auto;
|
|
23
26
|
width: 100%;
|
|
24
27
|
max-width: var(${maxWidthCssVariable});
|
|
25
28
|
}
|
|
26
29
|
`;
|
|
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
|
-
document.head.removeChild(style);
|
|
58
|
-
reader.destroy();
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
...reader,
|
|
62
|
-
__PROSE_READER_ENHANCER_REFIT: true,
|
|
63
|
-
destroy,
|
|
64
|
-
refit: {
|
|
65
|
-
update: settings.update.bind(settings),
|
|
66
|
-
settings$: settings
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
exports.refitEnhancer = refitEnhancer;
|
|
72
|
-
|
|
73
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
30
|
+
document.head.appendChild(style);
|
|
31
|
+
const viewportFitSubscription = (0, rxjs.combineLatest)([settings.watch(["viewportFit", "customWidth"]), reader.settings.watch(["computedPageTurnMode"])]).pipe((0, rxjs.map)(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {
|
|
32
|
+
if (computedPageTurnMode === "scrollable") {
|
|
33
|
+
if (viewportFit === "desktop") return "800px";
|
|
34
|
+
if (viewportFit === "tablet") return "600px";
|
|
35
|
+
if (viewportFit === "custom") return `${customWidth ?? 100}%`;
|
|
36
|
+
}
|
|
37
|
+
return "100%";
|
|
38
|
+
}), (0, rxjs.distinctUntilChanged)(), (0, rxjs.tap)((maxWidth) => {
|
|
39
|
+
document.documentElement.style.setProperty(maxWidthCssVariable, maxWidth);
|
|
40
|
+
reader.layout();
|
|
41
|
+
})).subscribe();
|
|
42
|
+
const destroy = () => {
|
|
43
|
+
viewportFitSubscription.unsubscribe();
|
|
44
|
+
document.head.removeChild(style);
|
|
45
|
+
reader.destroy();
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
...reader,
|
|
49
|
+
__PROSE_READER_ENHANCER_REFIT: true,
|
|
50
|
+
destroy,
|
|
51
|
+
refit: {
|
|
52
|
+
update: settings.update.bind(settings),
|
|
53
|
+
settings$: settings
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.refitEnhancer = refitEnhancer;
|
|
59
|
+
});
|
|
74
60
|
|
|
75
|
-
|
|
76
|
-
//# sourceMappingURL=index.umd.cjs.map
|
|
61
|
+
//# sourceMappingURL=index.umd.cjs.map
|
package/dist/index.umd.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.cjs","sources":["../src/index.ts"],"sourcesContent":["import {\n HTML_ATTRIBUTE_DATA_READER_ID,\n HTML_PREFIX_VIEWPORT,\n ReactiveEntity,\n type Reader,\n} from \"@prose-reader/core\"\nimport {\n combineLatest,\n distinctUntilChanged,\n map,\n type Observable,\n tap,\n} from \"rxjs\"\n\nexport type RefitEnhancerAPI = {\n readonly __PROSE_READER_ENHANCER_REFIT: boolean\n refit: {\n update: (settings: Partial<RefitEnhancerOptions>) => void\n settings$: Observable<RefitEnhancerOptions>\n }\n}\n\nexport type RefitEnhancerOptions = {\n viewportFit?: \"desktop\" | \"tablet\" | \"fit\" | \"custom\"\n customWidth?: number\n}\n\nclass Settings extends ReactiveEntity<RefitEnhancerOptions> {\n update(settings: RefitEnhancerOptions) {\n super.mergeCompare(settings)\n }\n}\n\nexport const refitEnhancer =\n <InheritOptions, InheritOutput extends Reader>(\n next: (options: InheritOptions) => InheritOutput,\n ) =>\n (\n options: InheritOptions & {\n refit?: Partial<RefitEnhancerOptions>\n },\n ): InheritOutput & RefitEnhancerAPI => {\n const { refit = {}, ...rest } = options\n const reader = next(rest as InheritOptions)\n const settings = new Settings(refit)\n const stylesheetId = `prose-reader-refit-${reader.id}`\n const maxWidthCssVariable = `--${stylesheetId}-max-width`\n\n const style = document.createElement(\"style\")\n style.id = stylesheetId\n style.textContent = `\n [${HTML_ATTRIBUTE_DATA_READER_ID}] [data-${HTML_PREFIX_VIEWPORT}] {\n margin: auto;\n width: 100%;\n max-width: var(${maxWidthCssVariable});\n }\n `\n\n document.head.appendChild(style)\n\n const viewportFitSubscription = combineLatest([\n settings.watch([\"viewportFit\", \"customWidth\"]),\n reader.settings.watch([\"computedPageTurnMode\"]),\n ])\n .pipe(\n map(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {\n if (computedPageTurnMode === \"scrollable\") {\n if (viewportFit === \"desktop\") {\n return \"800px\"\n }\n\n if (viewportFit === \"tablet\") {\n return \"600px\"\n }\n\n if (viewportFit === \"custom\") {\n return `${customWidth ?? 100}%`\n }\n }\n\n return \"100%\"\n }),\n distinctUntilChanged(),\n tap((maxWidth) => {\n document.documentElement.style.setProperty(\n maxWidthCssVariable,\n maxWidth,\n )\n reader.layout()\n }),\n )\n .subscribe()\n\n const destroy = () => {\n viewportFitSubscription.unsubscribe()\n document.head.removeChild(style)\n reader.destroy()\n }\n\n return {\n ...reader,\n __PROSE_READER_ENHANCER_REFIT: true,\n destroy,\n refit: {\n update: settings.update.bind(settings),\n settings$: settings,\n },\n }\n }\n"],"
|
|
1
|
+
{"version":3,"file":"index.umd.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n HTML_ATTRIBUTE_DATA_READER_ID,\n HTML_PREFIX_VIEWPORT,\n ReactiveEntity,\n type Reader,\n} from \"@prose-reader/core\"\nimport {\n combineLatest,\n distinctUntilChanged,\n map,\n type Observable,\n tap,\n} from \"rxjs\"\n\nexport type RefitEnhancerAPI = {\n readonly __PROSE_READER_ENHANCER_REFIT: boolean\n refit: {\n update: (settings: Partial<RefitEnhancerOptions>) => void\n settings$: Observable<RefitEnhancerOptions>\n }\n}\n\nexport type RefitEnhancerOptions = {\n viewportFit?: \"desktop\" | \"tablet\" | \"fit\" | \"custom\"\n customWidth?: number\n}\n\nclass Settings extends ReactiveEntity<RefitEnhancerOptions> {\n update(settings: RefitEnhancerOptions) {\n super.mergeCompare(settings)\n }\n}\n\nexport const refitEnhancer =\n <InheritOptions, InheritOutput extends Reader>(\n next: (options: InheritOptions) => InheritOutput,\n ) =>\n (\n options: InheritOptions & {\n refit?: Partial<RefitEnhancerOptions>\n },\n ): InheritOutput & RefitEnhancerAPI => {\n const { refit = {}, ...rest } = options\n const reader = next(rest as InheritOptions)\n const settings = new Settings(refit)\n const stylesheetId = `prose-reader-refit-${reader.id}`\n const maxWidthCssVariable = `--${stylesheetId}-max-width`\n\n const style = document.createElement(\"style\")\n style.id = stylesheetId\n style.textContent = `\n [${HTML_ATTRIBUTE_DATA_READER_ID}] [data-${HTML_PREFIX_VIEWPORT}] {\n margin: auto;\n width: 100%;\n max-width: var(${maxWidthCssVariable});\n }\n `\n\n document.head.appendChild(style)\n\n const viewportFitSubscription = combineLatest([\n settings.watch([\"viewportFit\", \"customWidth\"]),\n reader.settings.watch([\"computedPageTurnMode\"]),\n ])\n .pipe(\n map(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {\n if (computedPageTurnMode === \"scrollable\") {\n if (viewportFit === \"desktop\") {\n return \"800px\"\n }\n\n if (viewportFit === \"tablet\") {\n return \"600px\"\n }\n\n if (viewportFit === \"custom\") {\n return `${customWidth ?? 100}%`\n }\n }\n\n return \"100%\"\n }),\n distinctUntilChanged(),\n tap((maxWidth) => {\n document.documentElement.style.setProperty(\n maxWidthCssVariable,\n maxWidth,\n )\n reader.layout()\n }),\n )\n .subscribe()\n\n const destroy = () => {\n viewportFitSubscription.unsubscribe()\n document.head.removeChild(style)\n reader.destroy()\n }\n\n return {\n ...reader,\n __PROSE_READER_ENHANCER_REFIT: true,\n destroy,\n refit: {\n update: settings.update.bind(settings),\n settings$: settings,\n },\n }\n }\n"],"mappings":";;;;;;;;;CA2BA,IAAM,WAAN,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 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prose-reader/enhancer-refit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.304.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.umd.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@prose-reader/core": "^1.117.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "1f4e4822d4d74fc2f6025409133db0f4f7f152af"
|
|
25
25
|
}
|