qstd 0.3.84 → 0.3.86

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.
@@ -1089,6 +1089,126 @@ function remove(path, body, opts) {
1089
1089
  );
1090
1090
  }
1091
1091
 
1092
+ // src/shared/lexorank/index.ts
1093
+ var lexorank_exports = {};
1094
+ __export(lexorank_exports, {
1095
+ checkBalance: () => checkBalance,
1096
+ createOrderStr: () => createOrderStr,
1097
+ createRebalancedOrderList: () => createRebalancedOrderList,
1098
+ rebalance: () => rebalance,
1099
+ sortByOrder: () => sortByOrder
1100
+ });
1101
+
1102
+ // src/shared/lexorank/literals.ts
1103
+ var LOWER_BOUND = 96;
1104
+ var UPPER_BOUND = 123;
1105
+ var CHAR_A = 97;
1106
+ var CHAR_Z = 122;
1107
+ var ALPHABET_SIZE = 26;
1108
+ var DISTRIBUTION_TABLE = [
1109
+ 0,
1110
+ 4096,
1111
+ 65792,
1112
+ 528416,
1113
+ 1081872,
1114
+ 2167048,
1115
+ 2376776,
1116
+ 4756004,
1117
+ 4794660,
1118
+ 5411476,
1119
+ 9775442,
1120
+ 11097386,
1121
+ 11184810,
1122
+ 22369621
1123
+ ];
1124
+
1125
+ // src/shared/lexorank/fns.ts
1126
+ var stripTrailingAs = (str) => {
1127
+ let last = str.length - 1;
1128
+ while (str.charAt(last) === "a") --last;
1129
+ return str.slice(0, last + 1);
1130
+ };
1131
+ var partialAlphabet = (num2) => {
1132
+ let bits = num2 < 13 ? DISTRIBUTION_TABLE[num2] ?? 0 : 33554431 - (DISTRIBUTION_TABLE[25 - num2] ?? 0);
1133
+ const chars = [];
1134
+ for (let i = 1; i < ALPHABET_SIZE; i++, bits >>= 1) {
1135
+ if (bits & 1) chars.push(String.fromCharCode(CHAR_A + i));
1136
+ }
1137
+ return chars;
1138
+ };
1139
+
1140
+ // src/shared/lexorank/domain.ts
1141
+ var createOrderStr = (prev = "", next = "") => {
1142
+ let p;
1143
+ let n;
1144
+ let pos;
1145
+ let str;
1146
+ for (pos = 0; p === n; pos++) {
1147
+ p = pos < prev.length ? prev.charCodeAt(pos) : LOWER_BOUND;
1148
+ n = pos < next.length ? next.charCodeAt(pos) : UPPER_BOUND;
1149
+ }
1150
+ str = prev.slice(0, pos - 1);
1151
+ if (p === LOWER_BOUND) {
1152
+ while (n === CHAR_A) {
1153
+ n = pos < next.length ? next.charCodeAt(pos++) : UPPER_BOUND;
1154
+ str += "a";
1155
+ }
1156
+ if (n === CHAR_A + 1) {
1157
+ str += "a";
1158
+ n = UPPER_BOUND;
1159
+ }
1160
+ } else if (p !== void 0 && n !== void 0 && p + 1 === n) {
1161
+ str += String.fromCharCode(p);
1162
+ n = UPPER_BOUND;
1163
+ while ((p = pos < prev.length ? prev.charCodeAt(pos++) : LOWER_BOUND) === CHAR_Z) {
1164
+ str += "z";
1165
+ }
1166
+ }
1167
+ return str + String.fromCharCode(
1168
+ Math.ceil(((p ?? LOWER_BOUND) + (n ?? UPPER_BOUND)) / 2)
1169
+ );
1170
+ };
1171
+ var createRebalancedOrderList = (num2) => {
1172
+ const chars = Math.floor(Math.log(num2) / Math.log(ALPHABET_SIZE)) + 1;
1173
+ const prev = Math.pow(ALPHABET_SIZE, chars - 1);
1174
+ const ratio = chars > 1 ? (num2 + 1 - prev) / prev : num2;
1175
+ const part = Math.floor(ratio);
1176
+ const alpha = [partialAlphabet(part), partialAlphabet(part + 1)];
1177
+ const leapStep = ratio % 1;
1178
+ let leapTotal = 0.5;
1179
+ let first = true;
1180
+ const strings = [];
1181
+ const generate = (full, str) => {
1182
+ if (full) {
1183
+ for (let i = 0; i < ALPHABET_SIZE; i++) {
1184
+ generate(full - 1, str + String.fromCharCode(CHAR_A + i));
1185
+ }
1186
+ } else {
1187
+ if (!first) strings.push(stripTrailingAs(str));
1188
+ else first = false;
1189
+ const leap = Math.floor(leapTotal += leapStep);
1190
+ leapTotal %= 1;
1191
+ for (let i = 0; i < part + leap; i++) {
1192
+ strings.push(str + (alpha[leap]?.[i] ?? ""));
1193
+ }
1194
+ }
1195
+ };
1196
+ generate(chars - 1, "");
1197
+ return strings;
1198
+ };
1199
+ var checkBalance = (xs) => {
1200
+ let largestOrderStr = 0;
1201
+ xs.forEach(
1202
+ (x) => largestOrderStr = Math.max(largestOrderStr, x.order.length)
1203
+ );
1204
+ return largestOrderStr > xs.length / 2;
1205
+ };
1206
+ var rebalance = (xs) => {
1207
+ const rebalancedOrderList = createRebalancedOrderList(xs.length);
1208
+ return xs.map((x, i) => ({ ...x, order: rebalancedOrderList[i] ?? x.order }));
1209
+ };
1210
+ var sortByOrder = (xs) => xs.toSorted((a, b) => (a.order ?? "").localeCompare(b.order ?? ""));
1211
+
1092
1212
  // src/client/haptics.ts
1093
1213
  var haptics_exports = {};
1094
1214
  __export(haptics_exports, {
@@ -1196,6 +1316,7 @@ exports.Dom = dom_exports;
1196
1316
  exports.Flow = flow_exports;
1197
1317
  exports.Haptics = haptics_exports;
1198
1318
  exports.Int = int_exports;
1319
+ exports.LexoRank = lexorank_exports;
1199
1320
  exports.List = list_exports;
1200
1321
  exports.Log = log_exports;
1201
1322
  exports.Money = money_exports;
@@ -8,6 +8,7 @@ export * as Flow from "../shared/flow";
8
8
  export * as Random from "../shared/random";
9
9
  export * as Log from "../shared/log";
10
10
  export * as Api from "../shared/api";
11
+ export * as LexoRank from "../shared/lexorank";
11
12
  export * as Haptics from "./haptics";
12
13
  export { Theme } from "./theme";
13
14
  export * as Dom from "./dom";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAGrC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAC;AAG/C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC"}
@@ -1082,6 +1082,126 @@ function remove(path, body, opts) {
1082
1082
  );
1083
1083
  }
1084
1084
 
1085
+ // src/shared/lexorank/index.ts
1086
+ var lexorank_exports = {};
1087
+ __export(lexorank_exports, {
1088
+ checkBalance: () => checkBalance,
1089
+ createOrderStr: () => createOrderStr,
1090
+ createRebalancedOrderList: () => createRebalancedOrderList,
1091
+ rebalance: () => rebalance,
1092
+ sortByOrder: () => sortByOrder
1093
+ });
1094
+
1095
+ // src/shared/lexorank/literals.ts
1096
+ var LOWER_BOUND = 96;
1097
+ var UPPER_BOUND = 123;
1098
+ var CHAR_A = 97;
1099
+ var CHAR_Z = 122;
1100
+ var ALPHABET_SIZE = 26;
1101
+ var DISTRIBUTION_TABLE = [
1102
+ 0,
1103
+ 4096,
1104
+ 65792,
1105
+ 528416,
1106
+ 1081872,
1107
+ 2167048,
1108
+ 2376776,
1109
+ 4756004,
1110
+ 4794660,
1111
+ 5411476,
1112
+ 9775442,
1113
+ 11097386,
1114
+ 11184810,
1115
+ 22369621
1116
+ ];
1117
+
1118
+ // src/shared/lexorank/fns.ts
1119
+ var stripTrailingAs = (str) => {
1120
+ let last = str.length - 1;
1121
+ while (str.charAt(last) === "a") --last;
1122
+ return str.slice(0, last + 1);
1123
+ };
1124
+ var partialAlphabet = (num2) => {
1125
+ let bits = num2 < 13 ? DISTRIBUTION_TABLE[num2] ?? 0 : 33554431 - (DISTRIBUTION_TABLE[25 - num2] ?? 0);
1126
+ const chars = [];
1127
+ for (let i = 1; i < ALPHABET_SIZE; i++, bits >>= 1) {
1128
+ if (bits & 1) chars.push(String.fromCharCode(CHAR_A + i));
1129
+ }
1130
+ return chars;
1131
+ };
1132
+
1133
+ // src/shared/lexorank/domain.ts
1134
+ var createOrderStr = (prev = "", next = "") => {
1135
+ let p;
1136
+ let n;
1137
+ let pos;
1138
+ let str;
1139
+ for (pos = 0; p === n; pos++) {
1140
+ p = pos < prev.length ? prev.charCodeAt(pos) : LOWER_BOUND;
1141
+ n = pos < next.length ? next.charCodeAt(pos) : UPPER_BOUND;
1142
+ }
1143
+ str = prev.slice(0, pos - 1);
1144
+ if (p === LOWER_BOUND) {
1145
+ while (n === CHAR_A) {
1146
+ n = pos < next.length ? next.charCodeAt(pos++) : UPPER_BOUND;
1147
+ str += "a";
1148
+ }
1149
+ if (n === CHAR_A + 1) {
1150
+ str += "a";
1151
+ n = UPPER_BOUND;
1152
+ }
1153
+ } else if (p !== void 0 && n !== void 0 && p + 1 === n) {
1154
+ str += String.fromCharCode(p);
1155
+ n = UPPER_BOUND;
1156
+ while ((p = pos < prev.length ? prev.charCodeAt(pos++) : LOWER_BOUND) === CHAR_Z) {
1157
+ str += "z";
1158
+ }
1159
+ }
1160
+ return str + String.fromCharCode(
1161
+ Math.ceil(((p ?? LOWER_BOUND) + (n ?? UPPER_BOUND)) / 2)
1162
+ );
1163
+ };
1164
+ var createRebalancedOrderList = (num2) => {
1165
+ const chars = Math.floor(Math.log(num2) / Math.log(ALPHABET_SIZE)) + 1;
1166
+ const prev = Math.pow(ALPHABET_SIZE, chars - 1);
1167
+ const ratio = chars > 1 ? (num2 + 1 - prev) / prev : num2;
1168
+ const part = Math.floor(ratio);
1169
+ const alpha = [partialAlphabet(part), partialAlphabet(part + 1)];
1170
+ const leapStep = ratio % 1;
1171
+ let leapTotal = 0.5;
1172
+ let first = true;
1173
+ const strings = [];
1174
+ const generate = (full, str) => {
1175
+ if (full) {
1176
+ for (let i = 0; i < ALPHABET_SIZE; i++) {
1177
+ generate(full - 1, str + String.fromCharCode(CHAR_A + i));
1178
+ }
1179
+ } else {
1180
+ if (!first) strings.push(stripTrailingAs(str));
1181
+ else first = false;
1182
+ const leap = Math.floor(leapTotal += leapStep);
1183
+ leapTotal %= 1;
1184
+ for (let i = 0; i < part + leap; i++) {
1185
+ strings.push(str + (alpha[leap]?.[i] ?? ""));
1186
+ }
1187
+ }
1188
+ };
1189
+ generate(chars - 1, "");
1190
+ return strings;
1191
+ };
1192
+ var checkBalance = (xs) => {
1193
+ let largestOrderStr = 0;
1194
+ xs.forEach(
1195
+ (x) => largestOrderStr = Math.max(largestOrderStr, x.order.length)
1196
+ );
1197
+ return largestOrderStr > xs.length / 2;
1198
+ };
1199
+ var rebalance = (xs) => {
1200
+ const rebalancedOrderList = createRebalancedOrderList(xs.length);
1201
+ return xs.map((x, i) => ({ ...x, order: rebalancedOrderList[i] ?? x.order }));
1202
+ };
1203
+ var sortByOrder = (xs) => xs.toSorted((a, b) => (a.order ?? "").localeCompare(b.order ?? ""));
1204
+
1085
1205
  // src/client/haptics.ts
1086
1206
  var haptics_exports = {};
1087
1207
  __export(haptics_exports, {
@@ -1183,4 +1303,4 @@ var copy = async (text) => {
1183
1303
  }
1184
1304
  };
1185
1305
 
1186
- export { api_exports as Api, dict_exports as Dict, dom_exports as Dom, flow_exports as Flow, haptics_exports as Haptics, int_exports as Int, list_exports as List, log_exports as Log, money_exports as Money, random_exports as Random, str_exports as Str, Theme, time_exports as Time };
1306
+ export { api_exports as Api, dict_exports as Dict, dom_exports as Dom, flow_exports as Flow, haptics_exports as Haptics, int_exports as Int, lexorank_exports as LexoRank, list_exports as List, log_exports as Log, money_exports as Money, random_exports as Random, str_exports as Str, Theme, time_exports as Time };
@@ -1101,6 +1101,126 @@ function remove(path, body, opts) {
1101
1101
  );
1102
1102
  }
1103
1103
 
1104
+ // src/shared/lexorank/index.ts
1105
+ var lexorank_exports = {};
1106
+ __export(lexorank_exports, {
1107
+ checkBalance: () => checkBalance,
1108
+ createOrderStr: () => createOrderStr,
1109
+ createRebalancedOrderList: () => createRebalancedOrderList,
1110
+ rebalance: () => rebalance,
1111
+ sortByOrder: () => sortByOrder
1112
+ });
1113
+
1114
+ // src/shared/lexorank/literals.ts
1115
+ var LOWER_BOUND = 96;
1116
+ var UPPER_BOUND = 123;
1117
+ var CHAR_A = 97;
1118
+ var CHAR_Z = 122;
1119
+ var ALPHABET_SIZE = 26;
1120
+ var DISTRIBUTION_TABLE = [
1121
+ 0,
1122
+ 4096,
1123
+ 65792,
1124
+ 528416,
1125
+ 1081872,
1126
+ 2167048,
1127
+ 2376776,
1128
+ 4756004,
1129
+ 4794660,
1130
+ 5411476,
1131
+ 9775442,
1132
+ 11097386,
1133
+ 11184810,
1134
+ 22369621
1135
+ ];
1136
+
1137
+ // src/shared/lexorank/fns.ts
1138
+ var stripTrailingAs = (str) => {
1139
+ let last = str.length - 1;
1140
+ while (str.charAt(last) === "a") --last;
1141
+ return str.slice(0, last + 1);
1142
+ };
1143
+ var partialAlphabet = (num2) => {
1144
+ let bits = num2 < 13 ? DISTRIBUTION_TABLE[num2] ?? 0 : 33554431 - (DISTRIBUTION_TABLE[25 - num2] ?? 0);
1145
+ const chars = [];
1146
+ for (let i = 1; i < ALPHABET_SIZE; i++, bits >>= 1) {
1147
+ if (bits & 1) chars.push(String.fromCharCode(CHAR_A + i));
1148
+ }
1149
+ return chars;
1150
+ };
1151
+
1152
+ // src/shared/lexorank/domain.ts
1153
+ var createOrderStr = (prev = "", next = "") => {
1154
+ let p;
1155
+ let n;
1156
+ let pos;
1157
+ let str;
1158
+ for (pos = 0; p === n; pos++) {
1159
+ p = pos < prev.length ? prev.charCodeAt(pos) : LOWER_BOUND;
1160
+ n = pos < next.length ? next.charCodeAt(pos) : UPPER_BOUND;
1161
+ }
1162
+ str = prev.slice(0, pos - 1);
1163
+ if (p === LOWER_BOUND) {
1164
+ while (n === CHAR_A) {
1165
+ n = pos < next.length ? next.charCodeAt(pos++) : UPPER_BOUND;
1166
+ str += "a";
1167
+ }
1168
+ if (n === CHAR_A + 1) {
1169
+ str += "a";
1170
+ n = UPPER_BOUND;
1171
+ }
1172
+ } else if (p !== void 0 && n !== void 0 && p + 1 === n) {
1173
+ str += String.fromCharCode(p);
1174
+ n = UPPER_BOUND;
1175
+ while ((p = pos < prev.length ? prev.charCodeAt(pos++) : LOWER_BOUND) === CHAR_Z) {
1176
+ str += "z";
1177
+ }
1178
+ }
1179
+ return str + String.fromCharCode(
1180
+ Math.ceil(((p ?? LOWER_BOUND) + (n ?? UPPER_BOUND)) / 2)
1181
+ );
1182
+ };
1183
+ var createRebalancedOrderList = (num2) => {
1184
+ const chars = Math.floor(Math.log(num2) / Math.log(ALPHABET_SIZE)) + 1;
1185
+ const prev = Math.pow(ALPHABET_SIZE, chars - 1);
1186
+ const ratio = chars > 1 ? (num2 + 1 - prev) / prev : num2;
1187
+ const part = Math.floor(ratio);
1188
+ const alpha = [partialAlphabet(part), partialAlphabet(part + 1)];
1189
+ const leapStep = ratio % 1;
1190
+ let leapTotal = 0.5;
1191
+ let first = true;
1192
+ const strings = [];
1193
+ const generate = (full, str) => {
1194
+ if (full) {
1195
+ for (let i = 0; i < ALPHABET_SIZE; i++) {
1196
+ generate(full - 1, str + String.fromCharCode(CHAR_A + i));
1197
+ }
1198
+ } else {
1199
+ if (!first) strings.push(stripTrailingAs(str));
1200
+ else first = false;
1201
+ const leap = Math.floor(leapTotal += leapStep);
1202
+ leapTotal %= 1;
1203
+ for (let i = 0; i < part + leap; i++) {
1204
+ strings.push(str + (alpha[leap]?.[i] ?? ""));
1205
+ }
1206
+ }
1207
+ };
1208
+ generate(chars - 1, "");
1209
+ return strings;
1210
+ };
1211
+ var checkBalance = (xs) => {
1212
+ let largestOrderStr = 0;
1213
+ xs.forEach(
1214
+ (x) => largestOrderStr = Math.max(largestOrderStr, x.order.length)
1215
+ );
1216
+ return largestOrderStr > xs.length / 2;
1217
+ };
1218
+ var rebalance = (xs) => {
1219
+ const rebalancedOrderList = createRebalancedOrderList(xs.length);
1220
+ return xs.map((x, i) => ({ ...x, order: rebalancedOrderList[i] ?? x.order }));
1221
+ };
1222
+ var sortByOrder = (xs) => xs.toSorted((a, b) => (a.order ?? "").localeCompare(b.order ?? ""));
1223
+
1104
1224
  // src/server/os/index.ts
1105
1225
  var os_exports = {};
1106
1226
  __export(os_exports, {
@@ -2794,6 +2914,7 @@ exports.File = file_exports;
2794
2914
  exports.Flow = flow_exports;
2795
2915
  exports.Int = int_exports;
2796
2916
  exports.Lambda = lambda_exports;
2917
+ exports.LexoRank = lexorank_exports;
2797
2918
  exports.List = list_exports;
2798
2919
  exports.Log = log_exports;
2799
2920
  exports.Money = money_exports;
@@ -8,6 +8,7 @@ export * as Flow from "../shared/flow";
8
8
  export * as Random from "../shared/random";
9
9
  export * as Log from "../shared/log";
10
10
  export * as Api from "../shared/api";
11
+ export * as LexoRank from "../shared/lexorank";
11
12
  export * as Os from "./os";
12
13
  export * as File from "./file";
13
14
  export * as Lambda from "./aws/lambda";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAGrC,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAC;AAG/C,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,UAAU,CAAC"}
@@ -1093,6 +1093,126 @@ function remove(path, body, opts) {
1093
1093
  );
1094
1094
  }
1095
1095
 
1096
+ // src/shared/lexorank/index.ts
1097
+ var lexorank_exports = {};
1098
+ __export(lexorank_exports, {
1099
+ checkBalance: () => checkBalance,
1100
+ createOrderStr: () => createOrderStr,
1101
+ createRebalancedOrderList: () => createRebalancedOrderList,
1102
+ rebalance: () => rebalance,
1103
+ sortByOrder: () => sortByOrder
1104
+ });
1105
+
1106
+ // src/shared/lexorank/literals.ts
1107
+ var LOWER_BOUND = 96;
1108
+ var UPPER_BOUND = 123;
1109
+ var CHAR_A = 97;
1110
+ var CHAR_Z = 122;
1111
+ var ALPHABET_SIZE = 26;
1112
+ var DISTRIBUTION_TABLE = [
1113
+ 0,
1114
+ 4096,
1115
+ 65792,
1116
+ 528416,
1117
+ 1081872,
1118
+ 2167048,
1119
+ 2376776,
1120
+ 4756004,
1121
+ 4794660,
1122
+ 5411476,
1123
+ 9775442,
1124
+ 11097386,
1125
+ 11184810,
1126
+ 22369621
1127
+ ];
1128
+
1129
+ // src/shared/lexorank/fns.ts
1130
+ var stripTrailingAs = (str) => {
1131
+ let last = str.length - 1;
1132
+ while (str.charAt(last) === "a") --last;
1133
+ return str.slice(0, last + 1);
1134
+ };
1135
+ var partialAlphabet = (num2) => {
1136
+ let bits = num2 < 13 ? DISTRIBUTION_TABLE[num2] ?? 0 : 33554431 - (DISTRIBUTION_TABLE[25 - num2] ?? 0);
1137
+ const chars = [];
1138
+ for (let i = 1; i < ALPHABET_SIZE; i++, bits >>= 1) {
1139
+ if (bits & 1) chars.push(String.fromCharCode(CHAR_A + i));
1140
+ }
1141
+ return chars;
1142
+ };
1143
+
1144
+ // src/shared/lexorank/domain.ts
1145
+ var createOrderStr = (prev = "", next = "") => {
1146
+ let p;
1147
+ let n;
1148
+ let pos;
1149
+ let str;
1150
+ for (pos = 0; p === n; pos++) {
1151
+ p = pos < prev.length ? prev.charCodeAt(pos) : LOWER_BOUND;
1152
+ n = pos < next.length ? next.charCodeAt(pos) : UPPER_BOUND;
1153
+ }
1154
+ str = prev.slice(0, pos - 1);
1155
+ if (p === LOWER_BOUND) {
1156
+ while (n === CHAR_A) {
1157
+ n = pos < next.length ? next.charCodeAt(pos++) : UPPER_BOUND;
1158
+ str += "a";
1159
+ }
1160
+ if (n === CHAR_A + 1) {
1161
+ str += "a";
1162
+ n = UPPER_BOUND;
1163
+ }
1164
+ } else if (p !== void 0 && n !== void 0 && p + 1 === n) {
1165
+ str += String.fromCharCode(p);
1166
+ n = UPPER_BOUND;
1167
+ while ((p = pos < prev.length ? prev.charCodeAt(pos++) : LOWER_BOUND) === CHAR_Z) {
1168
+ str += "z";
1169
+ }
1170
+ }
1171
+ return str + String.fromCharCode(
1172
+ Math.ceil(((p ?? LOWER_BOUND) + (n ?? UPPER_BOUND)) / 2)
1173
+ );
1174
+ };
1175
+ var createRebalancedOrderList = (num2) => {
1176
+ const chars = Math.floor(Math.log(num2) / Math.log(ALPHABET_SIZE)) + 1;
1177
+ const prev = Math.pow(ALPHABET_SIZE, chars - 1);
1178
+ const ratio = chars > 1 ? (num2 + 1 - prev) / prev : num2;
1179
+ const part = Math.floor(ratio);
1180
+ const alpha = [partialAlphabet(part), partialAlphabet(part + 1)];
1181
+ const leapStep = ratio % 1;
1182
+ let leapTotal = 0.5;
1183
+ let first = true;
1184
+ const strings = [];
1185
+ const generate = (full, str) => {
1186
+ if (full) {
1187
+ for (let i = 0; i < ALPHABET_SIZE; i++) {
1188
+ generate(full - 1, str + String.fromCharCode(CHAR_A + i));
1189
+ }
1190
+ } else {
1191
+ if (!first) strings.push(stripTrailingAs(str));
1192
+ else first = false;
1193
+ const leap = Math.floor(leapTotal += leapStep);
1194
+ leapTotal %= 1;
1195
+ for (let i = 0; i < part + leap; i++) {
1196
+ strings.push(str + (alpha[leap]?.[i] ?? ""));
1197
+ }
1198
+ }
1199
+ };
1200
+ generate(chars - 1, "");
1201
+ return strings;
1202
+ };
1203
+ var checkBalance = (xs) => {
1204
+ let largestOrderStr = 0;
1205
+ xs.forEach(
1206
+ (x) => largestOrderStr = Math.max(largestOrderStr, x.order.length)
1207
+ );
1208
+ return largestOrderStr > xs.length / 2;
1209
+ };
1210
+ var rebalance = (xs) => {
1211
+ const rebalancedOrderList = createRebalancedOrderList(xs.length);
1212
+ return xs.map((x, i) => ({ ...x, order: rebalancedOrderList[i] ?? x.order }));
1213
+ };
1214
+ var sortByOrder = (xs) => xs.toSorted((a, b) => (a.order ?? "").localeCompare(b.order ?? ""));
1215
+
1096
1216
  // src/server/os/index.ts
1097
1217
  var os_exports = {};
1098
1218
  __export(os_exports, {
@@ -2779,4 +2899,4 @@ var recordsFromSqs = (body) => {
2779
2899
  }
2780
2900
  };
2781
2901
 
2782
- export { api_exports as Api, ddb_exports as DDB, dict_exports as Dict, file_exports as File, flow_exports as Flow, int_exports as Int, lambda_exports as Lambda, list_exports as List, log_exports as Log, money_exports as Money, os_exports as Os, random_exports as Random, s3_exports as S3, ses_exports as SES, sns_exports as SNS, sqs_exports as SQS, str_exports as Str, time_exports as Time };
2902
+ export { api_exports as Api, ddb_exports as DDB, dict_exports as Dict, file_exports as File, flow_exports as Flow, int_exports as Int, lambda_exports as Lambda, lexorank_exports as LexoRank, list_exports as List, log_exports as Log, money_exports as Money, os_exports as Os, random_exports as Random, s3_exports as S3, ses_exports as SES, sns_exports as SNS, sqs_exports as SQS, str_exports as Str, time_exports as Time };
@@ -0,0 +1,71 @@
1
+ import * as _t from "./types";
2
+ /**
3
+ * Generate a new sort key between two adjacent items.
4
+ *
5
+ * Given the order strings of the previous and next items, produces a
6
+ * string that sorts lexicographically between them. Pass empty strings
7
+ * for boundaries (insert at start or end).
8
+ *
9
+ * Algorithm uses lowercase a-z (char codes 96-123) as the alphabet:
10
+ * - 96 = boundary before 'a'
11
+ * - 123 = boundary after 'z'
12
+ *
13
+ * @example
14
+ * createOrderStr("b", "d") // "c"
15
+ * createOrderStr("", "b") // "a" (or similar, insert at start)
16
+ * createOrderStr("n", "") // "t" (or similar, insert at end)
17
+ * createOrderStr("az", "b") // "an" (midpoint between "az" and "b")
18
+ */
19
+ export declare const createOrderStr: (prev?: string, next?: string) => string;
20
+ /**
21
+ * Generate evenly-spaced order keys for a list of a given size.
22
+ *
23
+ * Used for initial list creation and periodic rebalancing. Produces
24
+ * `num` strings that are roughly evenly distributed across the a-z
25
+ * alphabet space, minimizing future string growth.
26
+ *
27
+ * @example
28
+ * createRebalancedOrderList(3) // ["i", "r", "z"] (roughly evenly spaced)
29
+ * createRebalancedOrderList(5) // ["e", "j", "o", "t", "y"]
30
+ */
31
+ export declare const createRebalancedOrderList: (num: number) => string[];
32
+ /**
33
+ * Check if the order strings in a list need rebalancing.
34
+ *
35
+ * Returns true when the longest order string exceeds half the list size.
36
+ * This indicates too many consecutive edge insertions have caused string
37
+ * growth. Rebalancing is rare in normal usage patterns.
38
+ *
39
+ * @example
40
+ * checkBalance([{ order: "b" }, { order: "n" }]) // false (1 < 1)
41
+ * checkBalance([{ order: "aaaaax" }, { order: "b" }]) // true (6 > 1)
42
+ */
43
+ export declare const checkBalance: <T extends _t.Ordered>(xs: T[]) => boolean;
44
+ /**
45
+ * Rebalance a list by recomputing evenly-spaced order keys for every item.
46
+ *
47
+ * Eliminates long order strings caused by repeated edge insertions.
48
+ * Returns new items with fresh `order` values. Does not mutate input.
49
+ *
50
+ * @example
51
+ * const items = [
52
+ * { id: "a", order: "aaaaax" },
53
+ * { id: "b", order: "b" },
54
+ * { id: "c", order: "n" },
55
+ * ];
56
+ * rebalance(items);
57
+ * // [{ id: "a", order: "i" }, { id: "b", order: "r" }, { id: "c", order: "z" }]
58
+ */
59
+ export declare const rebalance: <T extends _t.Ordered>(xs: T[]) => (T & {
60
+ order: string;
61
+ })[];
62
+ /**
63
+ * Sort items by their lexicographic order strings.
64
+ *
65
+ * Returns a new sorted array (immutable). Items without an order
66
+ * field sort to the beginning.
67
+ */
68
+ export declare const sortByOrder: <T extends {
69
+ order?: string;
70
+ }>(xs: T[]) => T[];
71
+ //# sourceMappingURL=domain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/domain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAI9B;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,GAAI,aAAS,EAAE,aAAS,WA0ClD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,aAiCpD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,YAMzD,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE;;IAGtD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,IAAI,CAAC,EAAE,QACI,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Strip trailing 'a' characters from a string.
3
+ *
4
+ * During order list generation, intermediate strings can end with runs
5
+ * of 'a's that add length without information. Stripping them produces
6
+ * shorter, cleaner keys that still sort correctly.
7
+ *
8
+ * @example
9
+ * stripTrailingAs("naaa") // "n"
10
+ * stripTrailingAs("abc") // "abc"
11
+ * stripTrailingAs("a") // ""
12
+ */
13
+ export declare const stripTrailingAs: (str: string) => string;
14
+ /**
15
+ * Generate a partial alphabet for evenly distributing keys.
16
+ *
17
+ * Uses a bit-packed lookup table to select well-distributed
18
+ * characters from the a-z range based on the desired count.
19
+ * For counts >= 13, the table mirrors to cover the full range.
20
+ *
21
+ * @example
22
+ * partialAlphabet(3) // ["d", "n", "x"] (roughly evenly spaced)
23
+ */
24
+ export declare const partialAlphabet: (num: number) => string[];
25
+ //# sourceMappingURL=fns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fns.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/fns.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,WAI1C,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,aAW1C,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * LexoRank Ordering
3
+ *
4
+ * Lexicographic string-based ordering for collection items.
5
+ * Enables O(1) reorder operations: moving an item between two others
6
+ * generates a new order string between their existing orders.
7
+ *
8
+ * Key functions:
9
+ * - `createOrderStr(prev, next)` - Generate key between two adjacent items
10
+ * - `createRebalancedOrderList(num)` - Generate evenly-spaced keys for a list
11
+ * - `checkBalance(xs)` - Detect when rebalancing is needed
12
+ * - `rebalance(xs)` - Recompute all orders
13
+ * - `sortByOrder(xs)` - Sort items by lexicographic order
14
+ */
15
+ export type * from "./types";
16
+ export * from "./domain";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,mBAAmB,SAAS,CAAC;AAC7B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,20 @@
1
+ /** Char code for the lower bound sentinel (one below 'a') */
2
+ export declare const LOWER_BOUND = 96;
3
+ /** Char code for the upper bound sentinel (one above 'z') */
4
+ export declare const UPPER_BOUND = 123;
5
+ /** Char code for 'a' — first character in the usable alphabet */
6
+ export declare const CHAR_A = 97;
7
+ /** Char code for 'z' — last character in the usable alphabet */
8
+ export declare const CHAR_Z = 122;
9
+ /** Size of the a-z alphabet */
10
+ export declare const ALPHABET_SIZE = 26;
11
+ /**
12
+ * Bit-packed lookup table for selecting well-distributed characters
13
+ * from the a-z range when generating evenly-spaced order keys.
14
+ *
15
+ * Each entry encodes which of the 25 non-'a' characters to include
16
+ * when distributing `n` keys across the alphabet. For n >= 13, the
17
+ * table is mirrored using a 25-bit mask (2^25 - 1 = 33554431).
18
+ */
19
+ export declare const DISTRIBUTION_TABLE: readonly [0, 4096, 65792, 528416, 1081872, 2167048, 2376776, 4756004, 4794660, 5411476, 9775442, 11097386, 11184810, 22369621];
20
+ //# sourceMappingURL=literals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"literals.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/literals.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B,6DAA6D;AAC7D,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,iEAAiE;AACjE,eAAO,MAAM,MAAM,KAAK,CAAC;AAEzB,gEAAgE;AAChE,eAAO,MAAM,MAAM,MAAM,CAAC;AAE1B,+BAA+B;AAC/B,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,gIAGrB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Item with a lexicographic order field */
2
+ export interface Ordered {
3
+ order: string;
4
+ }
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/shared/lexorank/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;CACf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qstd",
3
- "version": "0.3.84",
3
+ "version": "0.3.86",
4
4
  "description": "Standard Block component and utilities library with Panda CSS",
5
5
  "author": "malin1",
6
6
  "license": "MIT",