@ibgib/web-gib 0.0.2 → 0.0.4

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.
@@ -6,10 +6,8 @@
6
6
 
7
7
  import { delay, extractErrorMsg, pretty, } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
8
8
  import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
9
- import { Gib, IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
10
- import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
11
- import { GIB } from "@ibgib/ts-gib/dist/V1/constants.mjs";
12
- import { getGibInfo, isPrimitive } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
9
+ import { getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
10
+ import { isPrimitive } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
13
11
  import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
14
12
  import { MetaspaceService } from "@ibgib/core-gib/dist/witness/space/metaspace/metaspace-types.mjs";
15
13
  import { RawExportIbGib_V1 } from "@ibgib/core-gib/dist/common/import-export/import-export-types.mjs";
@@ -19,13 +17,13 @@ import { getRawExportIbGib } from "@ibgib/core-gib/dist/common/import-export/imp
19
17
  import { IbGibSpaceAny } from "@ibgib/core-gib/dist/witness/space/space-base-v1.mjs";
20
18
 
21
19
  import {
22
- GLOBAL_LOG_A_LOT, DEFAULT_IBGIB_COLOR, DEFAULT_IBGIB_COLOR_CONTRAST,
23
- DEFAULT_IBGIB_TRANSLUCENT, GEMINI_API_KEY_REGEXP,
20
+ GLOBAL_LOG_A_LOT, GEMINI_API_KEY_REGEXP,
24
21
  CONFIG_OPTION_GEMINI_API_KEY_LOCATION_HELP
25
22
  } from "./constants.mjs";
26
23
  import { showFullscreenDialog } from "./ui/ui-helpers.mjs";
27
- import { initializeStorage, storageCreateStoreIfNotExist, storageDBExists, storageGet, storagePut } from "./storage/storage-helpers.web.mjs";
28
- import { GibColorInfo } from "./types.mjs";
24
+ import {
25
+ initializeStorage, storageCreateStoreIfNotExist, storageDBExists, storagePut
26
+ } from "./storage/storage-helpers.web.mjs";
29
27
  import { getIbGibGlobalThis_IbGib } from "./helpers.mjs";
30
28
 
31
29
 
@@ -755,145 +753,6 @@ export async function unhighlightElement({
755
753
  }
756
754
  }
757
755
 
758
- /**
759
- * builds a color schema based on the gib.
760
- *
761
- * note that the alpha drives the translucent property, but the solid color is
762
- * always built
763
- */
764
- export function getDeterministicColorInfo({
765
- ibGibAddr,
766
- gib,
767
- ibGib,
768
- translucentAlpha = 10,
769
- }: {
770
- ibGibAddr?: IbGibAddr,
771
- gib?: Gib,
772
- ibGib?: IbGib_V1,
773
- /**
774
- * drives the translucent color.
775
- *
776
- * @default 10
777
- */
778
- translucentAlpha?: number
779
- }): GibColorInfo {
780
- const lc = `[${getDeterministicColorInfo.name}]`;
781
- try {
782
- if (logalot) { console.log(`${lc} starting... (I: 3b70af42d1c4f6ae91870f3a15c6c625)`); }
783
- if (!ibGibAddr && !gib && !ibGib) { gib = GIB; }
784
- gib ??= ibGib?.gib ?? getIbAndGib({ ibGibAddr }).gib;
785
- const gibInfo = getGibInfo({ gib });
786
- translucentAlpha ??= 10;
787
- /**
788
- * we want to color coordinate according to timeline if possible, i.e.,
789
- * by tjpGib.
790
- */
791
- let drivingHash = '';
792
- if (gibInfo.isPrimitive) {
793
- return {
794
- gib,
795
- gibInfo,
796
- punctiliarColor: DEFAULT_IBGIB_COLOR,
797
- punctiliarColorTranslucent: DEFAULT_IBGIB_TRANSLUCENT,
798
- punctiliarColorContrast: DEFAULT_IBGIB_COLOR_CONTRAST,
799
- }; /* <<<< returns early */
800
- } else {
801
- drivingHash = gibInfo.tjpGib ?? gibInfo.punctiliarHash ?? gib; // hmm, gib should be punctiliar but meh
802
- }
803
-
804
-
805
-
806
- /**
807
- * gets the color string
808
- */
809
- // const fnGetColorStr = (drivingHash: string) => {
810
- // function getContrastColor(hexcolor: string) {
811
- // const c = hexcolor.concat().replace("#", "");
812
- // var r = parseInt(c.substr(0, 2), 16);
813
- // var g = parseInt(c.substr(2, 2), 16);
814
- // var b = parseInt(c.substr(4, 2), 16);
815
- // var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
816
- // return (yiq >= 128) ? '#000000' : '#FFFFFF';
817
- // }
818
- // let alphaStr = '';
819
- // if (translucentAlpha || translucentAlpha === 0) {
820
- // if (translucentAlpha < 0 || translucentAlpha > 100) {
821
- // throw new Error(`alpha must be between 0 and 100 (E: c78faeb1477482c739b03dd32d2e1825)`);
822
- // }
823
- // if (translucentAlpha === 100) {
824
- // alphaStr = '';
825
- // } else if (translucentAlpha >= 0 && translucentAlpha < 10) {
826
- // // single digit
827
- // alphaStr = `0${translucentAlpha}`;
828
- // } else {
829
- // alphaStr = translucentAlpha.toString();
830
- // }
831
- // }
832
- // const color = `#${drivingHash.substring(0, 6)}`;
833
- // const colorTranslucent = `#${drivingHash.substring(0, 6)}${alphaStr}`;
834
- // const colorContrast = getContrastColor(color);
835
- // return [color, colorTranslucent, colorContrast];
836
- // };
837
-
838
- const [punctiliarColor, punctiliarColorTranslucent, punctiliarColorContrast] = getColorStrings(translucentAlpha, gibInfo.punctiliarHash ?? gib);
839
- const [tjpColor, tjpColorTranslucent, tjpColorContrast] = !!gibInfo.tjpGib ?
840
- getColorStrings(translucentAlpha, gibInfo.tjpGib) :
841
- [undefined, undefined, undefined];
842
-
843
- return {
844
- gib,
845
- gibInfo,
846
- punctiliarColor, punctiliarColorTranslucent, punctiliarColorContrast,
847
- tjpColor, tjpColorTranslucent, tjpColorContrast,
848
- };
849
- } catch (error) {
850
- const errorMsg = `${lc} ${extractErrorMsg(error)}`;
851
- console.error(errorMsg);
852
- return {
853
- gib: gib ?? GIB,
854
- gibInfo: { isPrimitive: true },
855
- punctiliarColor: '#ff0000', // red
856
- punctiliarColorTranslucent: '#ff000010', // translucent red
857
- punctiliarColorContrast: '#ffffff', // black
858
- errorMsg,
859
- };
860
- } finally {
861
- if (logalot) { console.log(`${lc} complete.`); }
862
- }
863
- }
864
-
865
- /**
866
- * gets the color, colorTranslucent and colorContrast
867
- */
868
- export function getColorStrings(translucentAlpha: number, drivingHash: string): [string, string, string] {
869
- function getContrastColor(hexcolor: string) {
870
- const c = hexcolor.concat().replace("#", "");
871
- var r = parseInt(c.substr(0, 2), 16);
872
- var g = parseInt(c.substr(2, 2), 16);
873
- var b = parseInt(c.substr(4, 2), 16);
874
- var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
875
- return (yiq >= 128) ? '#000000' : '#FFFFFF';
876
- }
877
- let alphaStr = '';
878
- if (translucentAlpha || translucentAlpha === 0) {
879
- if (translucentAlpha < 0 || translucentAlpha > 100) {
880
- throw new Error(`alpha must be between 0 and 100 (E: c78faeb1477482c739b03dd32d2e1825)`);
881
- }
882
- if (translucentAlpha === 100) {
883
- alphaStr = '';
884
- } else if (translucentAlpha >= 0 && translucentAlpha < 10) {
885
- // single digit
886
- alphaStr = `0${translucentAlpha}`;
887
- } else {
888
- alphaStr = translucentAlpha.toString();
889
- }
890
- }
891
- const color = `#${drivingHash.substring(0, 6)}`;
892
- const colorTranslucent = `#${drivingHash.substring(0, 6)}${alphaStr}`;
893
- const colorContrast = getContrastColor(color);
894
- return [color, colorTranslucent, colorContrast];
895
- };
896
-
897
756
  /**
898
757
  * Takes an incoming string. Assumes it's invalid. Does best effort at validating this.
899
758
  * Gets the raw export ibgib if it can. If so, and if it is compressed, decompresses the
@@ -1266,3 +1125,62 @@ export function getGlobalIndexedDbKey_APIKey(): string {
1266
1125
  if (logalot) { console.log(`${lc} complete.`); }
1267
1126
  }
1268
1127
  }
1128
+
1129
+ /**
1130
+ * helper info for {@link initAppStorage}
1131
+ */
1132
+ interface AppStorageInfo {
1133
+ dbName: string;
1134
+ storeNames: string[];
1135
+ }
1136
+ /**
1137
+ * ensures db and stores are created and can be used.
1138
+ */
1139
+ export async function initAppStorage({
1140
+ infos,
1141
+ }: {
1142
+ infos: AppStorageInfo[],
1143
+ }): Promise<void> {
1144
+ const lc = `[${initAppStorage.name}]`;
1145
+ try {
1146
+ if (logalot) { console.log(`${lc} starting... (I: 4d41880fb748ee2302a624a255665825)`); }
1147
+
1148
+ for (const info of infos) {
1149
+ const { dbName, storeNames } = info;
1150
+ const dbExists = await storageDBExists({
1151
+ dbName,
1152
+ // dbName: BLANK_GIB_DB_NAME,
1153
+ });
1154
+ if (!dbExists) {
1155
+ await initializeStorage({
1156
+ dbName,
1157
+ // dbName: BLANK_GIB_DB_NAME,
1158
+ });
1159
+ }
1160
+ for (const storeName of storeNames) {
1161
+ await storageCreateStoreIfNotExist({
1162
+ dbName,
1163
+ storeName,
1164
+ // dbName: BLANK_GIB_DB_NAME,
1165
+ // storeName: ARMY_STORE,
1166
+ });
1167
+ }
1168
+ // await storageCreateStoreIfNotExist({
1169
+ // dbName: BLANK_GIB_DB_NAME,
1170
+ // storeName: ARMY_STORE,
1171
+ // });
1172
+
1173
+ // await storageCreateStoreIfNotExist({
1174
+ // dbName: BLANK_GIB_DB_NAME,
1175
+ // storeName: ZERO_SPACE_ID,
1176
+ // logalot,
1177
+ // });
1178
+ }
1179
+
1180
+ } catch (error) {
1181
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1182
+ throw error;
1183
+ } finally {
1184
+ if (logalot) { console.log(`${lc} complete.`); }
1185
+ }
1186
+ }
@@ -37,8 +37,11 @@ import { mut8Timeline } from "@ibgib/core-gib/dist/timeline/timeline-api.mjs";
37
37
 
38
38
  import { GLOBAL_LOG_A_LOT } from "../../constants.mjs";
39
39
  import {
40
- exportIbGib, getDeterministicColorInfo,
41
- getRawExportIbGibAndGraphFromJsonString
40
+ coupleDomainIbGibWithLocalIbGibViaIndex, getLocalCoupledIbGibForDomainIbGib,
41
+ getDeterministicColorInfo,
42
+ } from "../../helpers.mjs";
43
+ import {
44
+ exportIbGib, getRawExportIbGibAndGraphFromJsonString
42
45
  } from "../../helpers.web.mjs";
43
46
  import { LiveProxyIbGib } from "../../witness/live-proxy-ibgib/live-proxy-ibgib-one-file.mjs";
44
47
  import { AgentWitnessAny, } from "../../witness/agent/agent-one-file.mjs";
@@ -48,7 +51,6 @@ import { getAgentForDomainIbGib } from "../../witness/agent/agent-helpers.mjs";
48
51
  import { createSettings, getSectionName, getSettingsScope, getSettingsSection } from "../../common/settings/settings-helpers.mjs";
49
52
  import { IbGibSettings, SettingsIbGib_V1, SettingsWithTabs } from "../../common/settings/settings-types.mjs";
50
53
  import { SettingsType } from "../../common/settings/settings-constants.mjs";
51
- import { coupleDomainIbGibWithLocalIbGibViaIndex, getLocalCoupledIbGibForDomainIbGib } from "../../helpers.mjs";
52
54
 
53
55
  const logalot = GLOBAL_LOG_A_LOT;
54
56