@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 CHANGED
@@ -1,69 +1,54 @@
1
- import { HTML_ATTRIBUTE_DATA_READER_ID, HTML_PREFIX_VIEWPORT, ReactiveEntity } from '@prose-reader/core';
2
- import { combineLatest, map, distinctUntilChanged, tap } from 'rxjs';
3
-
4
- class Settings extends ReactiveEntity {
5
- update(settings) {
6
- super.mergeCompare(settings);
7
- }
8
- }
9
- const 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 = `
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
- document.head.appendChild(style);
25
- const viewportFitSubscription = combineLatest([
26
- settings.watch(["viewportFit", "customWidth"]),
27
- reader.settings.watch(["computedPageTurnMode"])
28
- ]).pipe(
29
- map(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {
30
- if (computedPageTurnMode === "scrollable") {
31
- if (viewportFit === "desktop") {
32
- return "800px";
33
- }
34
- if (viewportFit === "tablet") {
35
- return "600px";
36
- }
37
- if (viewportFit === "custom") {
38
- return `${customWidth ?? 100}%`;
39
- }
40
- }
41
- return "100%";
42
- }),
43
- distinctUntilChanged(),
44
- tap((maxWidth) => {
45
- document.documentElement.style.setProperty(
46
- maxWidthCssVariable,
47
- maxWidth
48
- );
49
- reader.layout();
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
- //# sourceMappingURL=index.js.map
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"],"names":[],"mappings":";;;AA2BA,MAAM,iBAAiB,cAAA,CAAqC;AAAA,EAC1D,OAAO,QAAA,EAAgC;AACrC,IAAA,KAAA,CAAM,aAAa,QAAQ,CAAA;AAAA,EAC7B;AACF;AAEO,MAAM,aAAA,GACX,CACE,IAAA,KAEF,CACE,OAAA,KAGqC;AACrC,EAAA,MAAM,EAAE,KAAA,GAAQ,EAAC,EAAG,GAAG,MAAK,GAAI,OAAA;AAChC,EAAA,MAAM,MAAA,GAAS,KAAK,IAAsB,CAAA;AAC1C,EAAA,MAAM,QAAA,GAAW,IAAI,QAAA,CAAS,KAAK,CAAA;AACnC,EAAA,MAAM,YAAA,GAAe,CAAA,mBAAA,EAAsB,MAAA,CAAO,EAAE,CAAA,CAAA;AACpD,EAAA,MAAM,mBAAA,GAAsB,KAAK,YAAY,CAAA,UAAA,CAAA;AAE7C,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,aAAA,CAAc,OAAO,CAAA;AAC5C,EAAA,KAAA,CAAM,EAAA,GAAK,YAAA;AACX,EAAA,KAAA,CAAM,WAAA,GAAc;AAAA,OAAA,EACf,6BAA6B,WAAW,oBAAoB,CAAA;AAAA;AAAA;AAAA,uBAAA,EAG5C,mBAAmB,CAAA;AAAA;AAAA,IAAA,CAAA;AAIxC,EAAA,QAAA,CAAS,IAAA,CAAK,YAA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AAQ,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA;AAAA,MACrC,SAAA,EAAW;AAAA;AACb,GACF;AACF;;;;"}
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;AACF;AAEA,IAAa,iBAET,UAGA,YAGqC;CACrC,MAAM,EAAE,QAAQ,CAAC,GAAG,GAAG,SAAS;CAChC,MAAM,SAAS,KAAK,IAAsB;CAC1C,MAAM,WAAW,IAAI,SAAS,KAAK;CACnC,MAAM,eAAe,sBAAsB,OAAO;CAClD,MAAM,sBAAsB,KAAK,aAAa;CAE9C,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,KAAK;CACX,MAAM,cAAc;SACf,8BAA8B,UAAU,qBAAqB;;;yBAG7C,oBAAoB;;;CAIzC,SAAS,KAAK,YAAY,KAAK;CAE/B,MAAM,0BAA0B,cAAc,CAC5C,SAAS,MAAM,CAAC,eAAe,aAAa,CAAC,GAC7C,OAAO,SAAS,MAAM,CAAC,sBAAsB,CAAC,CAChD,CAAC,EACE,KACC,KAAK,CAAC,EAAE,aAAa,eAAe,EAAE,4BAA4B;EAChE,IAAI,yBAAyB,cAAc;GACzC,IAAI,gBAAgB,WAClB,OAAO;GAGT,IAAI,gBAAgB,UAClB,OAAO;GAGT,IAAI,gBAAgB,UAClB,OAAO,GAAG,eAAe,IAAI;EAEjC;EAEA,OAAO;CACT,CAAC,GACD,qBAAqB,GACrB,KAAK,aAAa;EAChB,SAAS,gBAAgB,MAAM,YAC7B,qBACA,QACF;EACA,OAAO,OAAO;CAChB,CAAC,CACH,EACC,UAAU;CAEb,MAAM,gBAAgB;EACpB,wBAAwB,YAAY;EACpC,SAAS,KAAK,YAAY,KAAK;EAC/B,OAAO,QAAQ;CACjB;CAEA,OAAO;EACL,GAAG;EACH,+BAA+B;EAC/B;EACA,OAAO;GACL,QAAQ,SAAS,OAAO,KAAK,QAAQ;GACrC,WAAW;EACb;CACF;AACF"}
@@ -1,76 +1,61 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@prose-reader/core'), require('rxjs')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@prose-reader/core', 'rxjs'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["prose-reader-enhancer-refit"] = {}, global.core, global.rxjs));
5
- })(this, (function (exports, core, rxjs) { 'use strict';
6
-
7
- class Settings extends core.ReactiveEntity {
8
- update(settings) {
9
- super.mergeCompare(settings);
10
- }
11
- }
12
- const refitEnhancer = (next) => (options) => {
13
- const { refit = {}, ...rest } = options;
14
- const reader = next(rest);
15
- const settings = new Settings(refit);
16
- const stylesheetId = `prose-reader-refit-${reader.id}`;
17
- const maxWidthCssVariable = `--${stylesheetId}-max-width`;
18
- const style = document.createElement("style");
19
- style.id = stylesheetId;
20
- style.textContent = `
21
- [${core.HTML_ATTRIBUTE_DATA_READER_ID}] [data-${core.HTML_PREFIX_VIEWPORT}] {
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
- document.head.appendChild(style);
28
- const viewportFitSubscription = rxjs.combineLatest([
29
- settings.watch(["viewportFit", "customWidth"]),
30
- reader.settings.watch(["computedPageTurnMode"])
31
- ]).pipe(
32
- rxjs.map(([{ viewportFit, customWidth }, { computedPageTurnMode }]) => {
33
- if (computedPageTurnMode === "scrollable") {
34
- if (viewportFit === "desktop") {
35
- return "800px";
36
- }
37
- if (viewportFit === "tablet") {
38
- return "600px";
39
- }
40
- if (viewportFit === "custom") {
41
- return `${customWidth ?? 100}%`;
42
- }
43
- }
44
- return "100%";
45
- }),
46
- rxjs.distinctUntilChanged(),
47
- rxjs.tap((maxWidth) => {
48
- document.documentElement.style.setProperty(
49
- maxWidthCssVariable,
50
- maxWidth
51
- );
52
- reader.layout();
53
- })
54
- ).subscribe();
55
- const destroy = () => {
56
- viewportFitSubscription.unsubscribe();
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
@@ -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$: sett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AAY,EAAG,EAAE,oBAAA,EAAsB,CAAA,KAAM;EAChE,MAAA,IAAI,yBAAyB,YAAA,EAAc;EACzC,QAAA,IAAI,gBAAgB,SAAA,EAAW;EAC7B,UAAA,OAAO,OAAA;EAAA,QACT;EAEA,QAAA,IAAI,gBAAgB,QAAA,EAAU;EAC5B,UAAA,OAAO,OAAA;EAAA,QACT;EAEA,QAAA,IAAI,gBAAgB,QAAA,EAAU;EAC5B,UAAA,OAAO,CAAA,EAAG,eAAe,GAAG,CAAA,CAAA,CAAA;EAAA,QAC9B;EAAA,MACF;EAEA,MAAA,OAAO,MAAA;EAAA,IACT,CAAC,CAAA;EAAA,IACDC,yBAAA,EAAqB;EAAA,IACrBC,QAAA,CAAI,CAAC,QAAA,KAAa;EAChB,MAAA,QAAA,CAAS,gBAAgB,KAAA,CAAM,WAAA;EAAA,QAC7B,mBAAA;EAAA,QACA;EAAA,OACF;EACA,MAAA,MAAA,CAAO,MAAA,EAAO;EAAA,IAChB,CAAC;EAAA,IAEF,SAAA,EAAU;EAEb,EAAA,MAAM,UAAU,MAAM;EACpB,IAAA,uBAAA,CAAwB,WAAA,EAAY;EACpC,IAAA,QAAA,CAAS,IAAA,CAAK,YAAY,KAAK,CAAA;EAC/B,IAAA,MAAA,CAAO,OAAA,EAAQ;EAAA,EACjB,CAAA;EAEA,EAAA,OAAO;EAAA,IACL,GAAG,MAAA;EAAA,IACH,6BAAA,EAA+B,IAAA;EAAA,IAC/B,OAAA;EAAA,IACA,KAAA,EAAO;EAAA,MACL,MAAA,EAAQ,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA;EAAA,MACrC,SAAA,EAAW;EAAA;EACb,GACF;EACF;;;;;;;;;;"}
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,cAAuB,mBAAA,eAAqC;EAC1D,OAAO,UAAgC;GACrC,MAAM,aAAa,QAAQ;EAC7B;CACF;CAEA,IAAa,iBAET,UAGA,YAGqC;EACrC,MAAM,EAAE,QAAQ,CAAC,GAAG,GAAG,SAAS;EAChC,MAAM,SAAS,KAAK,IAAsB;EAC1C,MAAM,WAAW,IAAI,SAAS,KAAK;EACnC,MAAM,eAAe,sBAAsB,OAAO;EAClD,MAAM,sBAAsB,KAAK,aAAa;EAE9C,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,KAAK;EACX,MAAM,cAAc;SACf,mBAAA,8BAA8B,UAAU,mBAAA,qBAAqB;;;yBAG7C,oBAAoB;;;EAIzC,SAAS,KAAK,YAAY,KAAK;EAE/B,MAAM,2BAAA,GAAA,KAAA,eAAwC,CAC5C,SAAS,MAAM,CAAC,eAAe,aAAa,CAAC,GAC7C,OAAO,SAAS,MAAM,CAAC,sBAAsB,CAAC,CAChD,CAAC,EACE,MAAA,GAAA,KAAA,MACM,CAAC,EAAE,aAAa,eAAe,EAAE,4BAA4B;GAChE,IAAI,yBAAyB,cAAc;IACzC,IAAI,gBAAgB,WAClB,OAAO;IAGT,IAAI,gBAAgB,UAClB,OAAO;IAGT,IAAI,gBAAgB,UAClB,OAAO,GAAG,eAAe,IAAI;GAEjC;GAEA,OAAO;EACT,CAAC,IAAA,GAAA,KAAA,sBACoB,IAAA,GAAA,KAAA,MAChB,aAAa;GAChB,SAAS,gBAAgB,MAAM,YAC7B,qBACA,QACF;GACA,OAAO,OAAO;EAChB,CAAC,CACH,EACC,UAAU;EAEb,MAAM,gBAAgB;GACpB,wBAAwB,YAAY;GACpC,SAAS,KAAK,YAAY,KAAK;GAC/B,OAAO,QAAQ;EACjB;EAEA,OAAO;GACL,GAAG;GACH,+BAA+B;GAC/B;GACA,OAAO;IACL,QAAQ,SAAS,OAAO,KAAK,QAAQ;IACrC,WAAW;GACb;EACF;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prose-reader/enhancer-refit",
3
- "version": "1.303.0",
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": "dddc06869ba852fa280e050c1c1929433bb91c5e"
24
+ "gitHead": "1f4e4822d4d74fc2f6025409133db0f4f7f152af"
25
25
  }