@axium/core 0.19.7 → 0.20.1

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/access.d.ts CHANGED
@@ -29,6 +29,7 @@ export declare function fromTarget(target: AccessTarget): Partial<Pick<AccessCon
29
29
  export declare function pickPermissions<T extends AccessControl & object>(ac: T): Omit<T, 'itemId' | 'userId' | 'role' | 'tag' | 'user' | 'createdAt'>;
30
30
  export interface AccessControllable {
31
31
  userId: string;
32
+ parentId?: string | null;
32
33
  acl?: AccessControl[];
33
34
  }
34
35
  export declare const AccessTarget: z.ZodUnion<readonly [z.ZodUUID, z.ZodTemplateLiteral<`@${string}`>, z.ZodTemplateLiteral<`#${string}`>, z.ZodLiteral<"public">]>;
package/dist/color.d.ts CHANGED
@@ -1 +1,12 @@
1
- export declare function colorHash(input: string): `rgb(${number}, ${number}, ${number})`;
1
+ export declare function colorHash(input: string): number;
2
+ export declare function colorHashHex(input: string): string;
3
+ export declare function colorHashRGB(input: string): string;
4
+ /**
5
+ * color information for events and calendars
6
+ */
7
+ export declare const Color: import("zod").ZodCustomStringFormat<"hex">;
8
+ /**
9
+ * Convert style data to a CSS color
10
+ */
11
+ export declare function decodeColor(color: string): string;
12
+ export declare function encodeColor(hex: string, adaptive?: boolean): string;
package/dist/color.js CHANGED
@@ -1,11 +1,46 @@
1
+ import { hexToHSL } from 'utilium/color.js';
2
+ import { hex } from 'zod';
1
3
  export function colorHash(input) {
2
4
  let color = input.charCodeAt(0);
3
5
  for (let i = 1; i < input.length; i++) {
4
6
  color *= input.charCodeAt(i);
5
7
  }
6
8
  color &= 0xbfbfbf;
7
- const r = (color >> 16) & 0xff;
8
- const g = (color >> 8) & 0xff;
9
+ return color;
10
+ }
11
+ export function colorHashHex(input) {
12
+ return colorHash(input).toString(16).padStart(6, '0');
13
+ }
14
+ export function colorHashRGB(input) {
15
+ const color = colorHash(input);
16
+ const r = (color >>> 16) & 0xff;
17
+ const g = (color >>> 8) & 0xff;
9
18
  const b = color & 0xff;
10
19
  return `rgb(${r}, ${g}, ${b})`;
11
20
  }
21
+ /**
22
+ * color information for events and calendars
23
+ */
24
+ export const Color = hex().length(8);
25
+ var ColorFlags;
26
+ (function (ColorFlags) {
27
+ ColorFlags[ColorFlags["Adaptive"] = 64] = "Adaptive";
28
+ })(ColorFlags || (ColorFlags = {}));
29
+ /**
30
+ * Convert style data to a CSS color
31
+ */
32
+ export function decodeColor(color) {
33
+ const hex = color.slice(2);
34
+ const flags = parseInt(color.slice(0, 2), 16);
35
+ if (flags & ColorFlags.Adaptive) {
36
+ const [h, s, l] = hexToHSL(hex);
37
+ return `hsl(${Math.round(h * 360)} ${Math.round(s * 100)} calc(var(--bg-light, ${Math.round(l * 100)}) + var(--light-step, 7)))`;
38
+ }
39
+ return `#${hex}`;
40
+ }
41
+ export function encodeColor(hex, adaptive = false) {
42
+ if (hex[0] == '#')
43
+ hex = hex.slice(1);
44
+ const flags = adaptive ? ColorFlags.Adaptive : 0;
45
+ return flags.toString(16).padStart(2, '0') + hex;
46
+ }
package/dist/user.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as z from 'zod';
2
2
  import { Preferences } from './preferences.js';
3
3
  import { PasskeyRegistration } from './passkeys.js';
4
- import { colorHash } from './color.js';
4
+ import { colorHashRGB } from './color.js';
5
5
  import { pick } from 'utilium';
6
6
  export const User = z.object({
7
7
  id: z.uuid(),
@@ -45,7 +45,7 @@ export const UserAdminChange = z
45
45
  export function getUserImage(user) {
46
46
  if (user.image)
47
47
  return user.image;
48
- const color = colorHash(user.name ?? '\0');
48
+ const color = colorHashRGB(user.name ?? '\0');
49
49
  return `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" style="background-color:${color};display:flex;align-items:center;justify-content:center;">
50
50
  <text x="23" y="28" style="font-family:sans-serif;font-weight:bold;" fill="white">${(user.name ?? '?').replaceAll(/\W/g, '')[0]}</text>
51
51
  </svg>`.replaceAll(/[\t\n]/g, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.19.7",
3
+ "version": "0.20.1",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",