@vectoriox/iox-builder 1.0.8 → 1.0.9
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.
|
@@ -929,13 +929,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImpo
|
|
|
929
929
|
type: Injectable
|
|
930
930
|
}] });
|
|
931
931
|
|
|
932
|
+
const STORAGE_KEY = 'iox_builder_viewport';
|
|
932
933
|
class ViewportService {
|
|
933
934
|
constructor() {
|
|
934
|
-
this.state =
|
|
935
|
-
device: DeviceMode.Desktop,
|
|
936
|
-
width: DEVICE_OPTIONS[0].width,
|
|
937
|
-
scale: 0.75,
|
|
938
|
-
};
|
|
935
|
+
this.state = this.loadFromStorage();
|
|
939
936
|
this.stateSubject = new BehaviorSubject(this.state);
|
|
940
937
|
this.state$ = this.stateSubject.asObservable();
|
|
941
938
|
}
|
|
@@ -949,16 +946,13 @@ class ViewportService {
|
|
|
949
946
|
const option = DEVICE_OPTIONS.find(d => d.mode === device);
|
|
950
947
|
if (!option)
|
|
951
948
|
return;
|
|
952
|
-
this.
|
|
953
|
-
this.stateSubject.next(this.state);
|
|
949
|
+
this.update({ device, width: option.width });
|
|
954
950
|
}
|
|
955
951
|
setScale(scale) {
|
|
956
|
-
this.
|
|
957
|
-
this.stateSubject.next(this.state);
|
|
952
|
+
this.update({ scale: Math.max(0.1, Math.min(2, scale)) });
|
|
958
953
|
}
|
|
959
954
|
setWidth(width) {
|
|
960
|
-
this.
|
|
961
|
-
this.stateSubject.next(this.state);
|
|
955
|
+
this.update({ width });
|
|
962
956
|
}
|
|
963
957
|
/**
|
|
964
958
|
* Calculate the scale that makes the canvas fit inside the available editor width.
|
|
@@ -982,6 +976,42 @@ class ViewportService {
|
|
|
982
976
|
y: (screenY - canvasRect.top) / this.state.scale,
|
|
983
977
|
};
|
|
984
978
|
}
|
|
979
|
+
update(partial) {
|
|
980
|
+
this.state = { ...this.state, ...partial };
|
|
981
|
+
this.stateSubject.next(this.state);
|
|
982
|
+
this.saveToStorage();
|
|
983
|
+
}
|
|
984
|
+
saveToStorage() {
|
|
985
|
+
try {
|
|
986
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.state));
|
|
987
|
+
}
|
|
988
|
+
catch { }
|
|
989
|
+
}
|
|
990
|
+
loadFromStorage() {
|
|
991
|
+
const defaults = {
|
|
992
|
+
device: DeviceMode.Desktop,
|
|
993
|
+
width: DEVICE_OPTIONS[0].width,
|
|
994
|
+
scale: 0.75,
|
|
995
|
+
};
|
|
996
|
+
try {
|
|
997
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
998
|
+
if (!raw)
|
|
999
|
+
return defaults;
|
|
1000
|
+
const saved = JSON.parse(raw);
|
|
1001
|
+
const device = Object.values(DeviceMode).includes(saved.device)
|
|
1002
|
+
? saved.device
|
|
1003
|
+
: defaults.device;
|
|
1004
|
+
const option = DEVICE_OPTIONS.find(d => d.mode === device) ?? DEVICE_OPTIONS[0];
|
|
1005
|
+
return {
|
|
1006
|
+
device,
|
|
1007
|
+
width: typeof saved.width === 'number' && saved.width > 0 ? saved.width : option.width,
|
|
1008
|
+
scale: typeof saved.scale === 'number' ? Math.max(0.1, Math.min(2, saved.scale)) : defaults.scale,
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
catch {
|
|
1012
|
+
return defaults;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
985
1015
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: ViewportService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
986
1016
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: ViewportService }); }
|
|
987
1017
|
}
|