@pallasoft/ps-mobile-components 1.6.0 → 1.8.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/components/ps-accessibility-gate/index.d.ts +2 -0
- package/dist/components/ps-accessibility-gate/index.js +2 -0
- package/dist/components/ps-accessibility-gate/ps-accessibility-gate-props.d.ts +5 -0
- package/dist/components/ps-accessibility-gate/ps-accessibility-gate-props.js +1 -0
- package/dist/components/ps-accessibility-gate/ps-accessibility-gate.d.ts +2 -0
- package/dist/components/ps-accessibility-gate/ps-accessibility-gate.js +4 -0
- package/dist/components/ps-app-lock-screen/ps-app-lock-screen.js +1 -1
- package/dist/components/ps-cartesian-chart/ps-cartesian-chart.d.ts +1 -1
- package/dist/components/ps-cartesian-chart/ps-cartesian-chart.js +25 -17
- package/dist/components/ps-chart-empty-state/ps-chart-empty-state.js +5 -1
- package/dist/components/ps-chart-frame/ps-chart-frame.js +10 -1
- package/dist/components/ps-chart-legend/ps-chart-legend.js +11 -2
- package/dist/components/ps-chart-readout/ps-chart-readout-props.d.ts +1 -0
- package/dist/components/ps-chart-readout/ps-chart-readout.d.ts +1 -1
- package/dist/components/ps-chart-readout/ps-chart-readout.js +8 -2
- package/dist/components/ps-chart-skeleton/ps-chart-skeleton.d.ts +1 -1
- package/dist/components/ps-chart-skeleton/ps-chart-skeleton.js +5 -1
- package/dist/components/ps-donut-chart/ps-donut-chart.js +23 -5
- package/dist/components/ps-kpi-card/ps-kpi-card.js +4 -1
- package/dist/components/ps-list/ps-list-select-row.js +8 -4
- package/dist/components/ps-menu-popup/ps-menu-popup-divider.js +8 -2
- package/dist/components/ps-menu-popup/ps-menu-popup-row.js +21 -9
- package/dist/components/ps-menu-popup/ps-menu-popup.js +28 -17
- package/dist/components/ps-privacy-cover/ps-privacy-cover-props.d.ts +1 -0
- package/dist/components/ps-privacy-cover/ps-privacy-cover.d.ts +1 -1
- package/dist/components/ps-privacy-cover/ps-privacy-cover.js +12 -3
- package/dist/components/ps-sortable-grid/ps-sortable-grid.js +8 -4
- package/dist/components/ps-sortable-grid/ps-sortable-item-props.d.ts +1 -0
- package/dist/components/ps-sortable-grid/ps-sortable-item.d.ts +1 -1
- package/dist/components/ps-sortable-grid/ps-sortable-item.js +3 -2
- package/dist/components/ps-sparkline/ps-sparkline.d.ts +1 -1
- package/dist/components/ps-sparkline/ps-sparkline.js +3 -1
- package/dist/components/ps-waterfall-chart/ps-waterfall-chart.d.ts +1 -1
- package/dist/components/ps-waterfall-chart/ps-waterfall-chart.js +15 -9
- package/dist/constants/ps-accessibility-config.d.ts +5 -0
- package/dist/constants/ps-accessibility-config.js +5 -0
- package/dist/constants/ps-chart-config.d.ts +26 -1
- package/dist/constants/ps-chart-config.js +26 -1
- package/dist/constants/ps-material-menu-config.d.ts +12 -0
- package/dist/constants/ps-material-menu-config.js +12 -0
- package/dist/constants/ps-scan-format.d.ts +4 -0
- package/dist/constants/ps-scan-format.js +5 -0
- package/dist/constants/ps-scan-output-config.d.ts +17 -0
- package/dist/constants/ps-scan-output-config.js +23 -0
- package/dist/constants/ps-screen-capture-config.d.ts +4 -0
- package/dist/constants/ps-screen-capture-config.js +4 -0
- package/dist/contexts/ps-widget-fill-context.d.ts +1 -0
- package/dist/contexts/ps-widget-fill-context.js +2 -0
- package/dist/hooks/use-ps-document-scanner.js +3 -2
- package/dist/hooks/use-ps-menu-popup-reveal.d.ts +3 -0
- package/dist/hooks/use-ps-menu-popup-reveal.js +28 -0
- package/dist/hooks/use-ps-screen-capture-prevention.d.ts +2 -0
- package/dist/hooks/use-ps-screen-capture-prevention.js +12 -0
- package/dist/hooks/use-ps-widget-fill.d.ts +1 -0
- package/dist/hooks/use-ps-widget-fill.js +3 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/interfaces/ps-capture-options.d.ts +2 -0
- package/dist/interfaces/ps-chart-bar-group.d.ts +4 -0
- package/dist/interfaces/ps-chart-bar-group.js +1 -0
- package/dist/interfaces/ps-chart-x-labels.d.ts +4 -0
- package/dist/interfaces/ps-chart-x-labels.js +1 -0
- package/dist/interfaces/ps-document-scanner-options.d.ts +2 -0
- package/dist/interfaces/ps-donut-chart-layout.d.ts +4 -0
- package/dist/interfaces/ps-donut-chart-layout.js +1 -0
- package/dist/interfaces/ps-image-manipulator-native.d.ts +19 -0
- package/dist/interfaces/ps-image-manipulator-native.js +1 -0
- package/dist/interfaces/ps-menu-popup-container-style.d.ts +8 -0
- package/dist/interfaces/ps-menu-popup-container-style.js +1 -0
- package/dist/interfaces/ps-menu-popup-divider-style.d.ts +4 -0
- package/dist/interfaces/ps-menu-popup-divider-style.js +1 -0
- package/dist/interfaces/ps-menu-popup-layout.d.ts +1 -0
- package/dist/interfaces/ps-menu-popup-row-style.d.ts +6 -0
- package/dist/interfaces/ps-menu-popup-row-style.js +1 -0
- package/dist/interfaces/ps-menu-popup-size.d.ts +4 -0
- package/dist/interfaces/ps-menu-popup-size.js +1 -0
- package/dist/interfaces/ps-page-size.d.ts +4 -0
- package/dist/interfaces/ps-page-size.js +1 -0
- package/dist/interfaces/ps-pdf-page.d.ts +5 -0
- package/dist/interfaces/ps-pdf-page.js +1 -0
- package/dist/interfaces/ps-scan-format-labels.d.ts +7 -0
- package/dist/interfaces/ps-scan-format-labels.js +1 -0
- package/dist/interfaces/ps-screen-capture-native.d.ts +4 -0
- package/dist/interfaces/ps-screen-capture-native.js +1 -0
- package/dist/interfaces/use-ps-screen-capture-prevention-options.d.ts +3 -0
- package/dist/interfaces/use-ps-screen-capture-prevention-options.js +1 -0
- package/dist/services/ps-capture-picker-service.js +1 -0
- package/dist/services/ps-chart-axis-service.d.ts +5 -0
- package/dist/services/ps-chart-axis-service.js +32 -0
- package/dist/services/ps-chart-bar-service.d.ts +2 -0
- package/dist/services/ps-chart-bar-service.js +11 -4
- package/dist/services/ps-chart-donut-service.d.ts +3 -0
- package/dist/services/ps-chart-donut-service.js +11 -0
- package/dist/services/ps-chart-readout-service.d.ts +3 -0
- package/dist/services/ps-chart-readout-service.js +25 -0
- package/dist/services/ps-chart-scale-service.d.ts +1 -1
- package/dist/services/ps-chart-scale-service.js +2 -2
- package/dist/services/ps-chart-text-service.d.ts +6 -0
- package/dist/services/ps-chart-text-service.js +23 -0
- package/dist/services/ps-document-scanner-service.d.ts +2 -0
- package/dist/services/ps-document-scanner-service.js +21 -4
- package/dist/services/ps-jpeg-size-service.d.ts +4 -0
- package/dist/services/ps-jpeg-size-service.js +32 -0
- package/dist/services/ps-menu-popup-service.js +1 -0
- package/dist/services/ps-menu-popup-style-service.d.ts +13 -0
- package/dist/services/ps-menu-popup-style-service.js +55 -0
- package/dist/services/ps-scan-format-prompt-service.d.ts +6 -0
- package/dist/services/ps-scan-format-prompt-service.js +21 -0
- package/dist/services/ps-scan-image-converter-service.d.ts +5 -0
- package/dist/services/ps-scan-image-converter-service.js +22 -0
- package/dist/services/ps-scan-output-service.d.ts +10 -0
- package/dist/services/ps-scan-output-service.js +55 -0
- package/dist/services/ps-scan-pdf-service.d.ts +4 -0
- package/dist/services/ps-scan-pdf-service.js +6 -0
- package/dist/services/ps-screen-capture-service.d.ts +6 -0
- package/dist/services/ps-screen-capture-service.js +35 -0
- package/dist/services/ps-sortable-grid-service.d.ts +2 -0
- package/dist/services/ps-sortable-grid-service.js +10 -3
- package/dist/services/ps-waterfall-service.js +2 -3
- package/jest-setup.js +1 -1
- package/package.json +10 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PsChartConfig } from '../constants/ps-chart-config';
|
|
2
|
+
import { PsChartTextService } from './ps-chart-text-service';
|
|
3
|
+
export class PsChartAxisService {
|
|
4
|
+
static yAxisWidth(labels, width) {
|
|
5
|
+
if (width <= 0)
|
|
6
|
+
return PsChartConfig.yAxisWidth;
|
|
7
|
+
const wanted = PsChartTextService.widest(labels, PsChartConfig.axisLabelSize) + PsChartConfig.axisTickGap;
|
|
8
|
+
return Math.min(Math.max(Math.ceil(wanted), PsChartConfig.yAxisMinWidth), Math.max(width * PsChartConfig.yAxisMaxRatio, PsChartConfig.yAxisMinWidth));
|
|
9
|
+
}
|
|
10
|
+
static xLabels(labels, available, isBand) {
|
|
11
|
+
const count = labels.length;
|
|
12
|
+
const all = Array.from({ length: count }, (_, index) => index);
|
|
13
|
+
if (count === 0 || available <= 0)
|
|
14
|
+
return { indexes: [], maxWidth: 0 };
|
|
15
|
+
const wanted = Math.min(PsChartTextService.widest(labels, PsChartConfig.axisLabelSize), PsChartConfig.axisLabelMaxWidth) + PsChartConfig.axisLabelGap;
|
|
16
|
+
if (isBand) {
|
|
17
|
+
const pitch = available / count;
|
|
18
|
+
const step = Math.max(Math.ceil(wanted / pitch), 1);
|
|
19
|
+
return {
|
|
20
|
+
indexes: all.filter((index) => index % step === 0),
|
|
21
|
+
maxWidth: Math.max(pitch * step - PsChartConfig.axisLabelGap, 0),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (count === 1)
|
|
25
|
+
return { indexes: all, maxWidth: available };
|
|
26
|
+
const shown = Math.min(Math.max(Math.floor(available / wanted) + 1, PsChartConfig.minXLabels), count);
|
|
27
|
+
return {
|
|
28
|
+
indexes: Array.from({ length: shown }, (_, index) => Math.round((index * (count - 1)) / (shown - 1))),
|
|
29
|
+
maxWidth: Math.max(available / (shown - 1) - PsChartConfig.axisLabelGap, 0),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PsAreaChartDatum } from '../interfaces/ps-area-chart-datum';
|
|
2
2
|
import type { PsCartesianChartSeries } from '../interfaces/ps-cartesian-chart-series';
|
|
3
|
+
import type { PsChartBarGroup } from '../interfaces/ps-chart-bar-group';
|
|
3
4
|
import type { PsChartBarRect } from '../interfaces/ps-chart-bar-rect';
|
|
4
5
|
import type { PsChartDomain } from '../interfaces/ps-chart-domain';
|
|
5
6
|
import type { PsChartPlot } from '../interfaces/ps-chart-plot';
|
|
@@ -7,5 +8,6 @@ export declare class PsChartBarService {
|
|
|
7
8
|
static grouped(data: PsAreaChartDatum[], series: PsCartesianChartSeries[], colors: string[], domain: PsChartDomain, plot: PsChartPlot): PsChartBarRect[];
|
|
8
9
|
static stacked(data: PsAreaChartDatum[], series: PsCartesianChartSeries[], colors: string[], domain: PsChartDomain, plot: PsChartPlot): PsChartBarRect[];
|
|
9
10
|
static slot(count: number, plot: PsChartPlot): number;
|
|
11
|
+
static group(slot: number, size: number): PsChartBarGroup;
|
|
10
12
|
private static rect;
|
|
11
13
|
}
|
|
@@ -4,18 +4,18 @@ import { PsChartSeriesService } from './ps-chart-series-service';
|
|
|
4
4
|
export class PsChartBarService {
|
|
5
5
|
static grouped(data, series, colors, domain, plot) {
|
|
6
6
|
const slot = PsChartBarService.slot(data.length, plot);
|
|
7
|
-
const width = (slot
|
|
7
|
+
const { offset, width } = PsChartBarService.group(slot, series.length);
|
|
8
8
|
const zero = PsChartScaleService.y(0, domain, plot);
|
|
9
9
|
return data.flatMap((datum, row) => series.map((entry, column) => {
|
|
10
10
|
const value = PsChartSeriesService.value(datum, entry.dataKey);
|
|
11
11
|
const top = PsChartScaleService.y(value, domain, plot);
|
|
12
|
-
const left = plot.left + row * slot +
|
|
12
|
+
const left = plot.left + row * slot + offset + column * width;
|
|
13
13
|
return PsChartBarService.rect(`${row}:${entry.dataKey}`, colors[column], left, width, zero, top, value < 0);
|
|
14
14
|
}));
|
|
15
15
|
}
|
|
16
16
|
static stacked(data, series, colors, domain, plot) {
|
|
17
17
|
const slot = PsChartBarService.slot(data.length, plot);
|
|
18
|
-
const width = slot
|
|
18
|
+
const { offset, width } = PsChartBarService.group(slot, 1);
|
|
19
19
|
return data.flatMap((datum, row) => {
|
|
20
20
|
let positive = 0;
|
|
21
21
|
let negative = 0;
|
|
@@ -27,13 +27,20 @@ export class PsChartBarService {
|
|
|
27
27
|
negative = to;
|
|
28
28
|
else
|
|
29
29
|
positive = to;
|
|
30
|
-
return PsChartBarService.rect(`${row}:${entry.dataKey}`, colors[column], plot.left + row * slot +
|
|
30
|
+
return PsChartBarService.rect(`${row}:${entry.dataKey}`, colors[column], plot.left + row * slot + offset, width, PsChartScaleService.y(from, domain, plot), PsChartScaleService.y(to, domain, plot), value < 0);
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
static slot(count, plot) {
|
|
35
35
|
return (plot.right - plot.left) / Math.max(count, 1);
|
|
36
36
|
}
|
|
37
|
+
static group(slot, size) {
|
|
38
|
+
const gap = slot < PsChartConfig.compactSlot
|
|
39
|
+
? PsChartConfig.compactBarGapRatio
|
|
40
|
+
: PsChartConfig.barGapRatio;
|
|
41
|
+
const total = Math.max(slot * (1 - gap), Math.min(PsChartConfig.minBarWidth * size, slot));
|
|
42
|
+
return { offset: (slot - total) / 2, width: total / size };
|
|
43
|
+
}
|
|
37
44
|
static rect(id, color, x, width, from, to, isNegative) {
|
|
38
45
|
return {
|
|
39
46
|
color,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { PsDonutChartDatum } from '../interfaces/ps-donut-chart-datum';
|
|
2
|
+
import type { PsDonutChartLayout } from '../interfaces/ps-donut-chart-layout';
|
|
2
3
|
import type { PsDonutSliceData } from '../interfaces/ps-donut-slice-data';
|
|
3
4
|
export declare class PsChartDonutService {
|
|
5
|
+
static layout(width: number, height: number): PsDonutChartLayout;
|
|
6
|
+
static centerFontSize(text: string, size: number): number;
|
|
4
7
|
static radius(size: number): number;
|
|
5
8
|
static circumference(size: number): number;
|
|
6
9
|
static slices(data: PsDonutChartDatum[], colors: string[], size: number): PsDonutSliceData[];
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { PsChartConfig } from '../constants/ps-chart-config';
|
|
2
|
+
import { PsChartTextService } from './ps-chart-text-service';
|
|
2
3
|
export class PsChartDonutService {
|
|
4
|
+
static layout(width, height) {
|
|
5
|
+
const side = height + PsChartConfig.donutGap + PsChartConfig.donutMinLegendWidth;
|
|
6
|
+
if (width >= side)
|
|
7
|
+
return { isStacked: false, size: height };
|
|
8
|
+
return { isStacked: true, size: Math.min(height, Math.max(width, 0)) };
|
|
9
|
+
}
|
|
10
|
+
static centerFontSize(text, size) {
|
|
11
|
+
const inner = size - 2 * (PsChartConfig.donutThickness + PsChartConfig.donutCenterPadding);
|
|
12
|
+
return PsChartTextService.fontSize(text, Math.max(inner, 0), PsChartConfig.donutCenterFontMax, PsChartConfig.donutCenterFontMin);
|
|
13
|
+
}
|
|
3
14
|
static radius(size) {
|
|
4
15
|
return (size - PsChartConfig.donutThickness) / 2;
|
|
5
16
|
}
|
|
@@ -4,4 +4,7 @@ import type { PsChartReadoutItem } from '../interfaces/ps-chart-readout-item';
|
|
|
4
4
|
export declare class PsChartReadoutService {
|
|
5
5
|
static items(datum: PsAreaChartDatum, series: PsCartesianChartSeries[], colors: string[], formatValue: (value: number) => string): PsChartReadoutItem[];
|
|
6
6
|
static summary(title: string, items: PsChartReadoutItem[]): string;
|
|
7
|
+
static lines(items: PsChartReadoutItem[], width: number): number;
|
|
8
|
+
static maxLines(rows: PsChartReadoutItem[][], width: number): number;
|
|
9
|
+
static height(lines: number): number;
|
|
7
10
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { PsChartConfig } from '../constants/ps-chart-config';
|
|
1
2
|
import { PsChartSeriesService } from './ps-chart-series-service';
|
|
3
|
+
import { PsChartTextService } from './ps-chart-text-service';
|
|
2
4
|
export class PsChartReadoutService {
|
|
3
5
|
static items(datum, series, colors, formatValue) {
|
|
4
6
|
return series.map((entry, index) => ({
|
|
@@ -10,4 +12,27 @@ export class PsChartReadoutService {
|
|
|
10
12
|
static summary(title, items) {
|
|
11
13
|
return [title, ...items.map((item) => `${item.label} ${item.value}`)].join(', ');
|
|
12
14
|
}
|
|
15
|
+
static lines(items, width) {
|
|
16
|
+
let lines = 1;
|
|
17
|
+
let used = 0;
|
|
18
|
+
items.forEach((item) => {
|
|
19
|
+
const wanted = PsChartConfig.legendDot +
|
|
20
|
+
PsChartConfig.axisTickGap +
|
|
21
|
+
PsChartTextService.estimateWidth(item.value, PsChartConfig.readoutValueSize);
|
|
22
|
+
if (used > 0 && used + PsChartConfig.readoutItemGap + wanted > width) {
|
|
23
|
+
lines += 1;
|
|
24
|
+
used = wanted;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
used += used > 0 ? PsChartConfig.readoutItemGap + wanted : wanted;
|
|
28
|
+
});
|
|
29
|
+
return lines;
|
|
30
|
+
}
|
|
31
|
+
static maxLines(rows, width) {
|
|
32
|
+
return rows.reduce((most, row) => Math.max(most, PsChartReadoutService.lines(row, width)), 1);
|
|
33
|
+
}
|
|
34
|
+
static height(lines) {
|
|
35
|
+
return (PsChartConfig.readoutHeight +
|
|
36
|
+
(Math.max(lines, 1) - 1) * (PsChartConfig.readoutLineHeight + PsChartConfig.readoutRowGap));
|
|
37
|
+
}
|
|
13
38
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PsChartDomain } from '../interfaces/ps-chart-domain';
|
|
2
2
|
import type { PsChartPlot } from '../interfaces/ps-chart-plot';
|
|
3
3
|
export declare class PsChartScaleService {
|
|
4
|
-
static plot(width: number, height: number): PsChartPlot;
|
|
4
|
+
static plot(width: number, height: number, yAxisWidth?: number): PsChartPlot;
|
|
5
5
|
static sparkPlot(width: number, height: number): PsChartPlot;
|
|
6
6
|
static domain(values: number[]): PsChartDomain;
|
|
7
7
|
static spanDomain(values: number[]): PsChartDomain;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PsChartConfig } from '../constants/ps-chart-config';
|
|
2
2
|
export class PsChartScaleService {
|
|
3
|
-
static plot(width, height) {
|
|
3
|
+
static plot(width, height, yAxisWidth = PsChartConfig.yAxisWidth) {
|
|
4
4
|
return {
|
|
5
5
|
bottom: height - PsChartConfig.paddingBottom,
|
|
6
|
-
left:
|
|
6
|
+
left: yAxisWidth,
|
|
7
7
|
right: width - PsChartConfig.paddingRight,
|
|
8
8
|
top: PsChartConfig.paddingTop,
|
|
9
9
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class PsChartTextService {
|
|
2
|
+
static estimateWidth(text: string, fontSize: number): number;
|
|
3
|
+
static widest(texts: string[], fontSize: number): number;
|
|
4
|
+
static fit(text: string, maxWidth: number, fontSize: number): string;
|
|
5
|
+
static fontSize(text: string, maxWidth: number, largest: number, smallest: number): number;
|
|
6
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PsChartConfig } from '../constants/ps-chart-config';
|
|
2
|
+
export class PsChartTextService {
|
|
3
|
+
static estimateWidth(text, fontSize) {
|
|
4
|
+
return text.length * fontSize * PsChartConfig.charWidthRatio;
|
|
5
|
+
}
|
|
6
|
+
static widest(texts, fontSize) {
|
|
7
|
+
return texts.reduce((widest, text) => Math.max(widest, PsChartTextService.estimateWidth(text, fontSize)), 0);
|
|
8
|
+
}
|
|
9
|
+
static fit(text, maxWidth, fontSize) {
|
|
10
|
+
if (PsChartTextService.estimateWidth(text, fontSize) <= maxWidth)
|
|
11
|
+
return text;
|
|
12
|
+
const characters = Math.floor(maxWidth / (fontSize * PsChartConfig.charWidthRatio));
|
|
13
|
+
if (characters < 1)
|
|
14
|
+
return '';
|
|
15
|
+
return `${text.slice(0, Math.max(characters - 1, 1))}${PsChartConfig.ellipsis}`;
|
|
16
|
+
}
|
|
17
|
+
static fontSize(text, maxWidth, largest, smallest) {
|
|
18
|
+
if (PsChartTextService.estimateWidth(text, largest) <= maxWidth)
|
|
19
|
+
return largest;
|
|
20
|
+
const fitted = Math.floor(maxWidth / (text.length * PsChartConfig.charWidthRatio));
|
|
21
|
+
return Math.min(Math.max(fitted, smallest), largest);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -3,7 +3,9 @@ import type { PsScannedFile } from '../interfaces/ps-scanned-file';
|
|
|
3
3
|
export declare class PsDocumentScannerService {
|
|
4
4
|
static isAvailable(): boolean;
|
|
5
5
|
static scan(options: PsDocumentScannerOptions): Promise<PsScannedFile[]>;
|
|
6
|
+
static format(files: PsScannedFile[], options: PsDocumentScannerOptions): Promise<PsScannedFile[]>;
|
|
6
7
|
static toFiles(uris: string[], fileName?: string): PsScannedFile[];
|
|
8
|
+
static base(fileName?: string): string;
|
|
7
9
|
static quality(jpegQuality?: number): number;
|
|
8
10
|
static pageLimit(maxPages?: number): number | null;
|
|
9
11
|
private static load;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { PsDocumentScannerConfig } from '../constants/ps-document-scanner-config';
|
|
2
|
+
import { PsScanOutputConfig } from '../constants/ps-scan-output-config';
|
|
3
|
+
import { PsScanFormatPromptService } from './ps-scan-format-prompt-service';
|
|
4
|
+
import { PsScanOutputService } from './ps-scan-output-service';
|
|
2
5
|
export class PsDocumentScannerService {
|
|
3
6
|
static isAvailable() {
|
|
4
7
|
return PsDocumentScannerService.load() !== null;
|
|
@@ -16,18 +19,32 @@ export class PsDocumentScannerService {
|
|
|
16
19
|
return [];
|
|
17
20
|
const uris = response.scannedImages === undefined ? [] : response.scannedImages;
|
|
18
21
|
const limited = maxPages === null ? uris : uris.slice(0, maxPages);
|
|
19
|
-
|
|
22
|
+
const files = PsDocumentScannerService.toFiles(limited, options.fileName);
|
|
23
|
+
return PsDocumentScannerService.format(files, options);
|
|
24
|
+
}
|
|
25
|
+
static async format(files, options) {
|
|
26
|
+
const labels = options.formatLabels;
|
|
27
|
+
if (labels === undefined || files.length === 0 || !PsScanOutputService.isAvailable())
|
|
28
|
+
return files;
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, PsScanOutputConfig.promptDelayMs));
|
|
30
|
+
const format = await PsScanFormatPromptService.ask(labels, PsScanFormatPromptService.preferred(files.length));
|
|
31
|
+
return format === null
|
|
32
|
+
? []
|
|
33
|
+
: PsScanOutputService.produce(files, format, PsDocumentScannerService.base(options.fileName));
|
|
20
34
|
}
|
|
21
35
|
static toFiles(uris, fileName) {
|
|
22
|
-
const base = fileName
|
|
23
|
-
? PsDocumentScannerConfig.defaultFileName
|
|
24
|
-
: fileName;
|
|
36
|
+
const base = PsDocumentScannerService.base(fileName);
|
|
25
37
|
return uris.map((uri, index) => ({
|
|
26
38
|
name: `${base}-${index + 1}.${PsDocumentScannerConfig.fileExtension}`,
|
|
27
39
|
type: PsDocumentScannerConfig.fileType,
|
|
28
40
|
uri,
|
|
29
41
|
}));
|
|
30
42
|
}
|
|
43
|
+
static base(fileName) {
|
|
44
|
+
return fileName === undefined || fileName === ''
|
|
45
|
+
? PsDocumentScannerConfig.defaultFileName
|
|
46
|
+
: fileName;
|
|
47
|
+
}
|
|
31
48
|
static quality(jpegQuality) {
|
|
32
49
|
if (jpegQuality === undefined)
|
|
33
50
|
return PsDocumentScannerConfig.defaultJpegQuality;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PsScanOutputConfig } from '../constants/ps-scan-output-config';
|
|
2
|
+
export class PsJpegSizeService {
|
|
3
|
+
static size(bytes) {
|
|
4
|
+
const prefix = PsScanOutputConfig.jpegMarkerPrefix;
|
|
5
|
+
if (bytes.length < 4 || bytes[0] !== prefix || bytes[1] !== PsScanOutputConfig.jpegStartMarker)
|
|
6
|
+
return null;
|
|
7
|
+
let cursor = 2;
|
|
8
|
+
while (cursor + 4 <= bytes.length) {
|
|
9
|
+
if (bytes[cursor] !== prefix) {
|
|
10
|
+
cursor += 1;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const marker = bytes[cursor + 1];
|
|
14
|
+
if (marker === prefix) {
|
|
15
|
+
cursor += 1;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const length = (bytes[cursor + 2] << 8) | bytes[cursor + 3];
|
|
19
|
+
if (PsScanOutputConfig.jpegSizeMarkers.some((size) => size === marker)) {
|
|
20
|
+
const at = cursor + 2 + PsScanOutputConfig.jpegSizeOffset;
|
|
21
|
+
if (at + 4 > bytes.length)
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
height: (bytes[at] << 8) | bytes[at + 1],
|
|
25
|
+
width: (bytes[at + 2] << 8) | bytes[at + 3],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
cursor += PsScanOutputConfig.jpegSegmentHeaderLength + length;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -14,6 +14,7 @@ export class PsMenuPopupService {
|
|
|
14
14
|
const alignedRight = anchor.x + menuWidth > window.width - margin;
|
|
15
15
|
const left = alignedRight ? anchor.x + anchor.width - menuWidth : anchor.x;
|
|
16
16
|
return {
|
|
17
|
+
isBelow,
|
|
17
18
|
left: Math.max(margin, Math.min(left, window.width - margin - menuWidth)),
|
|
18
19
|
maxHeight: Math.max(room, 0),
|
|
19
20
|
top,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PsFontWeight } from '../interfaces/ps-font-weight';
|
|
2
|
+
import type { PsMaterialScheme } from '../interfaces/ps-material-scheme';
|
|
3
|
+
import type { PsMenuPopupContainerStyle } from '../interfaces/ps-menu-popup-container-style';
|
|
4
|
+
import type { PsMenuPopupDividerStyle } from '../interfaces/ps-menu-popup-divider-style';
|
|
5
|
+
import type { PsMenuPopupRowStyle } from '../interfaces/ps-menu-popup-row-style';
|
|
6
|
+
import type { PsMobileTheme } from '../interfaces/ps-mobile-theme';
|
|
7
|
+
export declare class PsMenuPopupStyleService {
|
|
8
|
+
static isMaterial(os?: string): boolean;
|
|
9
|
+
static container(theme: PsMobileTheme, scheme: PsMaterialScheme, isMaterial: boolean): PsMenuPopupContainerStyle;
|
|
10
|
+
static row(theme: PsMobileTheme, scheme: PsMaterialScheme, isMaterial: boolean, isChecked: boolean, isPressed: boolean): PsMenuPopupRowStyle;
|
|
11
|
+
static divider(theme: PsMobileTheme, scheme: PsMaterialScheme, isMaterial: boolean): PsMenuPopupDividerStyle;
|
|
12
|
+
static labelWeight(isMaterial: boolean, isChecked: boolean): PsFontWeight;
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { PsMaterialMenuConfig } from '../constants/ps-material-menu-config';
|
|
3
|
+
import { PsMenuPopupConfig } from '../constants/ps-menu-popup-config';
|
|
4
|
+
export class PsMenuPopupStyleService {
|
|
5
|
+
static isMaterial(os = Platform.OS) {
|
|
6
|
+
return os === 'android';
|
|
7
|
+
}
|
|
8
|
+
static container(theme, scheme, isMaterial) {
|
|
9
|
+
if (isMaterial)
|
|
10
|
+
return {
|
|
11
|
+
backgroundColor: scheme.surfaceContainer,
|
|
12
|
+
borderColor: scheme.surfaceContainer,
|
|
13
|
+
borderRadius: PsMaterialMenuConfig.radius,
|
|
14
|
+
borderWidth: 0,
|
|
15
|
+
elevation: PsMaterialMenuConfig.elevation,
|
|
16
|
+
paddingVertical: PsMaterialMenuConfig.paddingVertical,
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
backgroundColor: theme.surface,
|
|
20
|
+
borderColor: theme.line,
|
|
21
|
+
borderRadius: PsMenuPopupConfig.radius,
|
|
22
|
+
borderWidth: 1,
|
|
23
|
+
elevation: 0,
|
|
24
|
+
paddingVertical: PsMenuPopupConfig.paddingVertical,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static row(theme, scheme, isMaterial, isChecked, isPressed) {
|
|
28
|
+
if (isMaterial)
|
|
29
|
+
return {
|
|
30
|
+
backgroundColor: isChecked ? scheme.secondaryContainer : 'transparent',
|
|
31
|
+
borderRadius: PsMaterialMenuConfig.itemRadius,
|
|
32
|
+
marginHorizontal: PsMaterialMenuConfig.itemInset,
|
|
33
|
+
paddingHorizontal: PsMaterialMenuConfig.rowPaddingHorizontal,
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
backgroundColor: isPressed ? theme.primarySoft : 'transparent',
|
|
37
|
+
borderRadius: 0,
|
|
38
|
+
marginHorizontal: 0,
|
|
39
|
+
paddingHorizontal: PsMenuPopupConfig.rowPaddingHorizontal,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
static divider(theme, scheme, isMaterial) {
|
|
43
|
+
if (isMaterial)
|
|
44
|
+
return {
|
|
45
|
+
backgroundColor: scheme.outlineVariant,
|
|
46
|
+
marginVertical: PsMaterialMenuConfig.dividerInset,
|
|
47
|
+
};
|
|
48
|
+
return { backgroundColor: theme.line, marginVertical: 0 };
|
|
49
|
+
}
|
|
50
|
+
static labelWeight(isMaterial, isChecked) {
|
|
51
|
+
if (isMaterial)
|
|
52
|
+
return 'medium';
|
|
53
|
+
return isChecked ? 'semibold' : 'regular';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PsScanFormat } from '../constants/ps-scan-format';
|
|
2
|
+
import type { PsScanFormatLabels } from '../interfaces/ps-scan-format-labels';
|
|
3
|
+
export declare class PsScanFormatPromptService {
|
|
4
|
+
static ask(labels: PsScanFormatLabels, preferred: PsScanFormat): Promise<PsScanFormat | null>;
|
|
5
|
+
static preferred(pageCount: number): PsScanFormat;
|
|
6
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Alert } from 'react-native';
|
|
2
|
+
import { PsScanFormat } from '../constants/ps-scan-format';
|
|
3
|
+
export class PsScanFormatPromptService {
|
|
4
|
+
static ask(labels, preferred) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const choice = (format, text) => ({
|
|
7
|
+
isPreferred: format === preferred,
|
|
8
|
+
onPress: () => resolve(format),
|
|
9
|
+
text,
|
|
10
|
+
});
|
|
11
|
+
Alert.alert(labels.title, labels.message, [
|
|
12
|
+
choice(PsScanFormat.Pdf, labels.pdf),
|
|
13
|
+
choice(PsScanFormat.Png, labels.images),
|
|
14
|
+
{ onPress: () => resolve(null), style: 'cancel', text: labels.cancel },
|
|
15
|
+
], { cancelable: true, onDismiss: () => resolve(null) });
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
static preferred(pageCount) {
|
|
19
|
+
return pageCount > 1 ? PsScanFormat.Pdf : PsScanFormat.Png;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class PsScanImageConverterService {
|
|
2
|
+
static isAvailable() {
|
|
3
|
+
return PsScanImageConverterService.load() !== null;
|
|
4
|
+
}
|
|
5
|
+
static async toPng(uri) {
|
|
6
|
+
const loaded = PsScanImageConverterService.load();
|
|
7
|
+
if (loaded === null)
|
|
8
|
+
return uri;
|
|
9
|
+
const rendered = await loaded.ImageManipulator.manipulate(uri).renderAsync();
|
|
10
|
+
const saved = await rendered.saveAsync({ format: loaded.SaveFormat.PNG });
|
|
11
|
+
return saved.uri;
|
|
12
|
+
}
|
|
13
|
+
static load() {
|
|
14
|
+
try {
|
|
15
|
+
const loaded = require('expo-image-manipulator');
|
|
16
|
+
return typeof loaded.ImageManipulator.manipulate === 'function' ? loaded : null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PsScanFormat } from '../constants/ps-scan-format';
|
|
2
|
+
import type { PsScannedFile } from '../interfaces/ps-scanned-file';
|
|
3
|
+
export declare class PsScanOutputService {
|
|
4
|
+
static isAvailable(): boolean;
|
|
5
|
+
static produce(pages: PsScannedFile[], format: PsScanFormat, fileName: string): Promise<PsScannedFile[]>;
|
|
6
|
+
static pageName(base: string, index: number): string;
|
|
7
|
+
private static toPdf;
|
|
8
|
+
private static toPng;
|
|
9
|
+
private static loadFileSystem;
|
|
10
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { PsScanFormat } from '../constants/ps-scan-format';
|
|
2
|
+
import { PsScanOutputConfig } from '../constants/ps-scan-output-config';
|
|
3
|
+
import { PsJpegSizeService } from './ps-jpeg-size-service';
|
|
4
|
+
import { PsScanImageConverterService } from './ps-scan-image-converter-service';
|
|
5
|
+
import { PsScanPdfService } from './ps-scan-pdf-service';
|
|
6
|
+
export class PsScanOutputService {
|
|
7
|
+
static isAvailable() {
|
|
8
|
+
return (PsScanOutputService.loadFileSystem() !== null && PsScanImageConverterService.isAvailable());
|
|
9
|
+
}
|
|
10
|
+
static async produce(pages, format, fileName) {
|
|
11
|
+
return format === PsScanFormat.Pdf
|
|
12
|
+
? [await PsScanOutputService.toPdf(pages, fileName)]
|
|
13
|
+
: PsScanOutputService.toPng(pages, fileName);
|
|
14
|
+
}
|
|
15
|
+
static pageName(base, index) {
|
|
16
|
+
return `${base}-${index + 1}.${PsScanOutputConfig.extensions[PsScanFormat.Png]}`;
|
|
17
|
+
}
|
|
18
|
+
static async toPdf(pages, fileName) {
|
|
19
|
+
const system = PsScanOutputService.loadFileSystem();
|
|
20
|
+
if (system === null)
|
|
21
|
+
throw new Error('expo-file-system is not available');
|
|
22
|
+
const loaded = [];
|
|
23
|
+
for (const page of pages) {
|
|
24
|
+
const bytes = new Uint8Array(await new system.File(page.uri).arrayBuffer());
|
|
25
|
+
const size = PsJpegSizeService.size(bytes);
|
|
26
|
+
if (size === null)
|
|
27
|
+
throw new Error('unreadable scan page');
|
|
28
|
+
loaded.push({ bytes, height: size.height, width: size.width });
|
|
29
|
+
}
|
|
30
|
+
const name = `${fileName}.${PsScanOutputConfig.extensions[PsScanFormat.Pdf]}`;
|
|
31
|
+
const file = new system.File(system.Paths.cache, `${Date.now()}-${name}`);
|
|
32
|
+
file.create({ overwrite: true });
|
|
33
|
+
await file.write(PsScanPdfService.fromJpegs(loaded));
|
|
34
|
+
return { name, type: PsScanOutputConfig.pdfType, uri: file.uri };
|
|
35
|
+
}
|
|
36
|
+
static async toPng(pages, fileName) {
|
|
37
|
+
const files = [];
|
|
38
|
+
for (const [index, page] of pages.entries())
|
|
39
|
+
files.push({
|
|
40
|
+
name: PsScanOutputService.pageName(fileName, index),
|
|
41
|
+
type: PsScanOutputConfig.pngType,
|
|
42
|
+
uri: await PsScanImageConverterService.toPng(page.uri),
|
|
43
|
+
});
|
|
44
|
+
return files;
|
|
45
|
+
}
|
|
46
|
+
static loadFileSystem() {
|
|
47
|
+
try {
|
|
48
|
+
const loaded = require('expo-file-system');
|
|
49
|
+
return typeof loaded.File === 'function' ? loaded : null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PsScreenCaptureConfig } from '../constants/ps-screen-capture-config';
|
|
2
|
+
export class PsScreenCaptureService {
|
|
3
|
+
static load() {
|
|
4
|
+
try {
|
|
5
|
+
const loaded = require('expo-screen-capture');
|
|
6
|
+
return typeof loaded.preventScreenCaptureAsync === 'function' ? loaded : null;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
static async prevent() {
|
|
13
|
+
const native = PsScreenCaptureService.load();
|
|
14
|
+
if (native === null)
|
|
15
|
+
return false;
|
|
16
|
+
try {
|
|
17
|
+
await native.preventScreenCaptureAsync(PsScreenCaptureConfig.key);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
static async allow() {
|
|
25
|
+
const native = PsScreenCaptureService.load();
|
|
26
|
+
if (native === null)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
await native.allowScreenCaptureAsync(PsScreenCaptureConfig.key);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -10,6 +10,8 @@ export declare class PsSortableGridService {
|
|
|
10
10
|
static isSameOrder(first: string[], second: string[]): boolean;
|
|
11
11
|
static rows(spans: PsSortableGridSpan[]): number[][];
|
|
12
12
|
static layout(spans: PsSortableGridSpan[], heights: number[], width: number): PsSortableRect[];
|
|
13
|
+
static extras(rects: PsSortableRect[], heights: number[]): number[];
|
|
14
|
+
static natural(total: number, extra: number): number;
|
|
13
15
|
static contentHeight(rects: PsSortableRect[]): number;
|
|
14
16
|
static indexAt(rects: PsSortableRect[], x: number, y: number, current: number): number;
|
|
15
17
|
static move<T>(items: T[], from: number, to: number): T[];
|
|
@@ -35,19 +35,26 @@ export class PsSortableGridService {
|
|
|
35
35
|
const rects = [];
|
|
36
36
|
let top = 0;
|
|
37
37
|
PsSortableGridService.rows(spans).forEach((row) => {
|
|
38
|
+
const rowHeight = Math.max(...row.map((index) => heights[index]));
|
|
38
39
|
row.forEach((index, column) => {
|
|
39
|
-
const isHalf = spans[index] === PsSortableGridSpan.half;
|
|
40
|
+
const isHalf = spans[index] === PsSortableGridSpan.half && row.length === 2;
|
|
40
41
|
rects[index] = {
|
|
41
|
-
height:
|
|
42
|
+
height: rowHeight,
|
|
42
43
|
width: isHalf ? half : width,
|
|
43
44
|
x: column === 0 ? 0 : half + PsSortableGridConfig.columnGap,
|
|
44
45
|
y: top,
|
|
45
46
|
};
|
|
46
47
|
});
|
|
47
|
-
top +=
|
|
48
|
+
top += rowHeight + PsSortableGridConfig.rowGap;
|
|
48
49
|
});
|
|
49
50
|
return rects;
|
|
50
51
|
}
|
|
52
|
+
static extras(rects, heights) {
|
|
53
|
+
return rects.map((rect, index) => Math.max(rect.height - heights[index], 0));
|
|
54
|
+
}
|
|
55
|
+
static natural(total, extra) {
|
|
56
|
+
return Math.max(total - extra, 0);
|
|
57
|
+
}
|
|
51
58
|
static contentHeight(rects) {
|
|
52
59
|
return rects.reduce((bottom, rect) => Math.max(bottom, rect.y + rect.height), 0);
|
|
53
60
|
}
|