@aphexcms/ui 0.8.6 → 0.8.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.
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { onMount } from 'svelte';
3
3
  import type { HTMLAttributes } from 'svelte/elements';
4
- import { cn, type WithElementRef } from '../../../utils.js';
4
+ import { cn, randomId, type WithElementRef } from '../../../utils.js';
5
5
  import { useMessageScroller } from './message-scroller-context.svelte.js';
6
6
 
7
7
  type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
@@ -21,7 +21,7 @@
21
21
 
22
22
  onMount(() => {
23
23
  if (!ref) return;
24
- const id = messageId ?? crypto.randomUUID();
24
+ const id = messageId ?? randomId();
25
25
  const unregister = state.registerItem(id, ref, scrollAnchor);
26
26
  const observer = new IntersectionObserver(
27
27
  ([entry]) => state.setItemVisible(id, entry?.isIntersecting ?? false),
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,15 @@
1
1
  import { type ClassValue } from 'clsx';
2
2
  export declare function cn(...inputs: ClassValue[]): string;
3
+ /**
4
+ * A v4 UUID that also works outside a secure context.
5
+ *
6
+ * `crypto.randomUUID` is only defined on HTTPS or `localhost`, so opening the
7
+ * dev server's Network URL (`vite dev --host` prints one) from a phone or
8
+ * another machine leaves it `undefined` and every call throws. Kept here rather
9
+ * than imported from `@aphexcms/cms-core` because the dependency runs the other
10
+ * way — cms-core consumes this package.
11
+ */
12
+ export declare function randomId(): string;
3
13
  export type WithoutChild<T> = T extends {
4
14
  child?: any;
5
15
  } ? Omit<T, 'child'> : T;
package/dist/utils.js CHANGED
@@ -3,3 +3,26 @@ import { twMerge } from 'tailwind-merge';
3
3
  export function cn(...inputs) {
4
4
  return twMerge(clsx(inputs));
5
5
  }
6
+ /**
7
+ * A v4 UUID that also works outside a secure context.
8
+ *
9
+ * `crypto.randomUUID` is only defined on HTTPS or `localhost`, so opening the
10
+ * dev server's Network URL (`vite dev --host` prints one) from a phone or
11
+ * another machine leaves it `undefined` and every call throws. Kept here rather
12
+ * than imported from `@aphexcms/cms-core` because the dependency runs the other
13
+ * way — cms-core consumes this package.
14
+ */
15
+ export function randomId() {
16
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
17
+ return crypto.randomUUID();
18
+ }
19
+ if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
20
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
21
+ const hex = Array.from(bytes, (byte, index) => {
22
+ const value = index === 6 ? (byte & 0x0f) | 0x40 : index === 8 ? (byte & 0x3f) | 0x80 : byte;
23
+ return value.toString(16).padStart(2, '0');
24
+ }).join('');
25
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
26
+ }
27
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aphexcms/ui",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "description": "Shared UI components for Aphex CMS (shadcn-svelte)",
5
5
  "license": "MIT",
6
6
  "publishConfig": {