kireji 0.6.6 → 0.6.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kireji",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "A web framework for stateful, entropy-perfect, multi-origin web applications. Currently in alpha. Expect breaking changes for version 0. Use with caution!",
5
5
  "files": [
6
6
  "src/",
package/src/build.js CHANGED
@@ -78,6 +78,19 @@ function ƒ(_, compressedSubjectOrigins) {
78
78
  sanitizeAttr = string => string.replaceAll(/&/g, '&amp;').replaceAll(/"/g, '&quot;').replaceAll(/'/g, '&#39;').replaceAll(/</g, '&lt;').replaceAll(/>/g, '&gt;')
79
79
 
80
80
  // Math Utilities
81
+ class Vector {
82
+ static magnitude(vector) {
83
+ return Math.hypot(...Object.values(vector))
84
+ }
85
+ static normalize(vector) {
86
+ const result = { ...vector }
87
+ const magnitude = this.magnitude(vector)
88
+ if (magnitude)
89
+ for (const dimension in vector)
90
+ result[dimension] = vector[dimension] / magnitude
91
+ return result
92
+ }
93
+ }
81
94
  class FenwickTree {
82
95
  static LSB = []
83
96
  constructor(size) {
@@ -10,11 +10,10 @@ const placeLimits = []
10
10
  let product = 1n
11
11
 
12
12
  for (const dimension of dimensions) {
13
- const placeLimit = BigInt(dimension)
14
13
  placeValues.push(product)
15
- placeStates.push(-1n)
16
- placeLimits.push(placeLimit)
17
- product *= placeLimit
14
+ placeStates.push(-1)
15
+ placeLimits.push(dimension)
16
+ product *= BigInt(dimension)
18
17
  }
19
18
 
20
19
  box.define({
@@ -2,6 +2,6 @@ box.updateRouteID(ROUTE_ID)
2
2
 
3
3
  for (let i = box.placeValues.length - 1; i >= 0; i--) {
4
4
  const placeValue = box.placeValues[i]
5
- box.placeStates[i] = ROUTE_ID / placeValue
5
+ box.placeStates[i] = Number(ROUTE_ID / placeValue)
6
6
  ROUTE_ID %= placeValue
7
7
  }
@@ -4,12 +4,10 @@ if (!Array.isArray(MODEL))
4
4
  if (MODEL.length !== box.placeValues.length)
5
5
  throw new RangeError(`Model To RouteID Error: Box "${box.host}" does not support computing a route ID from an array with a different length than the number of dimensions the box has.`)
6
6
 
7
- if (MODEL.some(member => typeof member !== "bigint" && isNaN(member)))
7
+ if (MODEL.some(member => isNaN(member)))
8
8
  throw new RangeError(`Model To RouteID Error: Box "${box.host}" does not support computing a route ID from an array with element(s) which are not numeric.`)
9
9
 
10
- let resultRouteID = 0n
11
-
12
- box.placeValues.forEach((placeValue, i) => resultRouteID += BigInt(MODEL[i]) * box.placeValues[i])
10
+ const resultRouteID = box.placeValues.reduce((resultRouteID, placeValue, i) => resultRouteID + BigInt(placeValue) * BigInt(Math.max(Math.min(Math.round(MODEL[i]), box.placeLimits[i] - 1), 0)), 0n)
13
11
 
14
12
  if (resultRouteID >= part.cardinality)
15
13
  throw new RangeError(`Model To RouteID Error: Part "${part.host}" returned a route ID that was too large (${resultRouteID}) (max ${part.cardinality}).`)
@@ -2,16 +2,16 @@ declare interface IBox<TOwner>
2
2
  extends IPart<TOwner, null> {
3
3
 
4
4
  // Serialized Properties.
5
- readonly "dimensions": [bigint | number]
5
+ readonly "dimensions": [number]
6
6
  // Runtime Properties.
7
7
  /** The array of dimension multipliers, (the value of a unit for each of the defined dimensions) where the box is viewed as a fixed-length mixed-radix string.
8
8
  *
9
9
  * Used to speed up computation. */
10
10
  readonly placeValues: bigint[]
11
11
  /** A cache of the individual dimension values as extracted from the box's overall route ID. */
12
- readonly placeStates: bigint[]
12
+ readonly placeStates: number[]
13
13
  /** A cache of the "dimensions" property, so that the array is not duplicated during arithmetic and so that the values are guaranteed to be bigints. */
14
- readonly placeLimits: bigint[]
14
+ readonly placeLimits: number[]
15
15
  }
16
16
 
17
17
  declare type IBoxAny =
@@ -0,0 +1 @@
1
+ part.setRouteID(part.modelToRouteID(MODEL))
@@ -8,6 +8,9 @@
8
8
  "ROUTE_ID",
9
9
  "DELTA = false"
10
10
  ],
11
+ "model-set": [
12
+ "MODEL"
13
+ ],
11
14
  "routeID-collect": [
12
15
  "SUBPARTS",
13
16
  "DEPTH"
@@ -15,7 +15,7 @@ client.promise.then(() => {
15
15
  pointerEvent.preventDefault()
16
16
  }
17
17
 
18
- taskBar.menu.setRouteID(taskBar.menu.modelToRouteID("closed"))
18
+ taskBar.menu.setModel("closed")
19
19
  }
20
20
  }, { capture: true })
21
21
  })
package/src/type.d.ts CHANGED
@@ -311,4 +311,11 @@ declare class FenwickTree {
311
311
  update(i: bigint, val: bigint): void
312
312
  query(i: bigint): bigint
313
313
  findNthAvailable(n: bigint): bigint
314
- }
314
+ }
315
+ /** A utility class for handling arbitrary-length vectors. Any object with entirely numeric values can be treated as a vector. */
316
+ declare class Vector {
317
+ static magnitude(vector: IVector): number
318
+ static normalize(vector: IVector): IVector
319
+ }
320
+
321
+ declare type IVector = Record<string, number>