diff --git a/packages/core/src/clipboard.ts b/packages/core/src/clipboard.ts index c536c6895..c5b88ef18 100644 --- a/packages/core/src/clipboard.ts +++ b/packages/core/src/clipboard.ts @@ -1,5 +1,7 @@ import { inflateSync, deflateSync } from 'fflate' +import { randomInt } from './random' + import { sceneNodeToKiwi, buildFigKiwi, @@ -313,7 +315,7 @@ export function buildFigmaClipboardHTML(nodes: SceneNode[], graph: SceneGraph): type: 'NODE_CHANGES', sessionID: 0, ackID: 0, - pasteID: crypto.getRandomValues(new Int32Array(1))[0], + pasteID: randomInt(), pasteFileKey: 'openpencil', nodeChanges } diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 394563773..7497cdd37 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -281,3 +281,4 @@ export const CJK_FALLBACK_FAMILIES_LINUX = [ ] export const CJK_GOOGLE_FONT = 'Noto Sans SC' + diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 3c02edc0f..bcdd810d2 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,5 +1,6 @@ export type { GUID, Color, Vector, Matrix, Rect } from './types' export { degToRad, radToDeg, rotatePoint, rotatedCorners, rotatedBBox } from './geometry' +export { randomHex, randomInt, randomIndex } from './random' export * from './constants' diff --git a/packages/core/src/random.ts b/packages/core/src/random.ts new file mode 100644 index 000000000..5f2244672 --- /dev/null +++ b/packages/core/src/random.ts @@ -0,0 +1,14 @@ +export function randomHex(bytes = 16): string { + const buf = crypto.getRandomValues(new Uint8Array(bytes)) + let hex = '' + for (const b of buf) hex += b.toString(16).padStart(2, '0') + return hex +} + +export function randomInt(): number { + return crypto.getRandomValues(new Int32Array(1))[0] +} + +export function randomIndex(length: number): number { + return crypto.getRandomValues(new Uint8Array(1))[0] % length +} diff --git a/src/app.css b/src/app.css index 154de2d2d..012400afc 100644 --- a/src/app.css +++ b/src/app.css @@ -37,6 +37,7 @@ --color-surface: #e0e0e0; --color-muted: #888888; --color-input: #1e1e1e; + --color-component: #9747ff; } html, diff --git a/src/automation/server.ts b/src/automation/server.ts index c4c24beb4..9eae53c8f 100644 --- a/src/automation/server.ts +++ b/src/automation/server.ts @@ -12,22 +12,15 @@ import { renderTreeNode, computeAllLayouts, selectionToJSX, - sceneNodeToJSX + sceneNodeToJSX, + randomHex } from '@open-pencil/core' import type { EditorStore } from '@/stores/editor' import type { ExportFormat } from '@open-pencil/core' -const TOKEN_LENGTH = 32 - -function generateToken(): string { - const bytes = new Uint8Array(TOKEN_LENGTH) - crypto.getRandomValues(bytes) - return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('') -} - export function connectAutomation(getStore: () => EditorStore) { - const token = generateToken() + const token = randomHex(32) let ws: WebSocket | null = null let reconnectTimer: ReturnType | undefined diff --git a/src/components/DesignPanel.vue b/src/components/DesignPanel.vue index b96b0483a..62f02836c 100644 --- a/src/components/DesignPanel.vue +++ b/src/components/DesignPanel.vue @@ -57,7 +57,7 @@ const isComponentType = computed(() => { data-test-id="design-node-header" class="flex items-center gap-1.5 border-b border-border px-3 py-2" > - {{ + {{ node.type }} {{ node.name }} @@ -70,7 +70,7 @@ const isComponentType = computed(() => { >