Skip to content

AI-native design editor. Open-source Figma alternative.

Eliminate as Record<string, unknown> casts

Danila Poyarkov31326e8e5ee1
diff --git a/packages/core/src/canvaskit.ts b/packages/core/src/canvaskit.ts
index 0b1fca47f..872b8a57e 100644
--- a/packages/core/src/canvaskit.ts
+++ b/packages/core/src/canvaskit.ts
@@ -27,8 +27,9 @@ function loadCanvasKitWebGPU(): Promise<(opts?: Record<string, unknown>) => Prom
const script = document.createElement('script')
script.src = '/canvaskit-webgpu/canvaskit.js'
script.onload = () => {
- const init = (globalThis as Record<string, unknown>).CanvasKitInit as
- (opts?: Record<string, unknown>) => Promise<CanvasKit>
+ const init = 'CanvasKitInit' in globalThis
+ ? ((globalThis as typeof globalThis & { CanvasKitInit: unknown }).CanvasKitInit as (opts?: { locateFile?: (file: string) => string }) => Promise<CanvasKit>)
+ : null
if (!init) return reject(new Error('CanvasKitInit not found after loading WebGPU build'))
resolve(init)
}
diff --git a/packages/core/src/clipboard.ts b/packages/core/src/clipboard.ts
index 4dcacaa4b..3a8d93d99 100644
--- a/packages/core/src/clipboard.ts
+++ b/packages/core/src/clipboard.ts
@@ -135,7 +135,7 @@ export function importClipboardNodes(
const internalCanvasIds = new Set<string>()
for (const [id, nc] of guidMap) {
- if (nc.type === 'CANVAS' && (nc as unknown as Record<string, unknown>).internalOnly) {
+ if (nc.type === 'CANVAS' && nc.internalOnly) {
internalCanvasIds.add(id)
}
}
diff --git a/packages/core/src/kiwi-serialize.ts b/packages/core/src/kiwi-serialize.ts
index c497a332a..8d02ef7e3 100644
--- a/packages/core/src/kiwi-serialize.ts
+++ b/packages/core/src/kiwi-serialize.ts
@@ -270,8 +270,7 @@ export function sceneNodeToKiwi(
if (node.lineHeight != null) nc.lineHeight = { value: node.lineHeight, units: 'PIXELS' }
if (node.letterSpacing !== 0) nc.letterSpacing = { value: node.letterSpacing, units: 'PIXELS' }
if (node.textDecoration !== 'NONE') {
- ;(nc as Record<string, unknown>).textDecoration =
- node.textDecoration === 'UNDERLINE' ? 'UNDERLINE' : 'STRIKETHROUGH'
+ nc.textDecoration = node.textDecoration === 'UNDERLINE' ? 'UNDERLINE' : 'STRIKETHROUGH'
}
}
diff --git a/packages/core/src/kiwi/codec.ts b/packages/core/src/kiwi/codec.ts
index 977378410..6d3d241bb 100644
--- a/packages/core/src/kiwi/codec.ts
+++ b/packages/core/src/kiwi/codec.ts
@@ -210,6 +210,7 @@ export interface Effect {
}
export interface NodeChange {
+ [key: string]: unknown
guid: GUID
phase?: 'CREATED' | 'REMOVED'
parentIndex?: ParentIndex
@@ -296,6 +297,7 @@ export interface FigmaMessage {
ackID?: number
reconnectSequenceNumber?: number
nodeChanges?: NodeChange[]
+ blobs?: Array<{ bytes: Uint8Array }>
}
/**
diff --git a/packages/core/src/kiwi/fig-file.ts b/packages/core/src/kiwi/fig-file.ts
index 811d91ea5..1c364a76a 100644
--- a/packages/core/src/kiwi/fig-file.ts
+++ b/packages/core/src/kiwi/fig-file.ts
@@ -84,9 +84,7 @@ export async function parseFigFile(buffer: ArrayBuffer): Promise<SceneGraph> {
throw new Error('No nodes found in .fig file')
}
- const blobs: Uint8Array[] = (
- ((message as unknown as Record<string, unknown>).blobs as Array<{ bytes: Uint8Array }>) ?? []
- ).map((b) =>
+ const blobs: Uint8Array[] = (message.blobs ?? []).map((b) =>
b.bytes instanceof Uint8Array ? b.bytes : new Uint8Array(Object.values(b.bytes) as number[])
)
diff --git a/packages/core/src/kiwi/kiwi-convert.ts b/packages/core/src/kiwi/kiwi-convert.ts
index e90255f47..54eaa661e 100644
--- a/packages/core/src/kiwi/kiwi-convert.ts
+++ b/packages/core/src/kiwi/kiwi-convert.ts
@@ -33,9 +33,7 @@ import type {
} from '../scene-graph'
import type { NodeChange, Paint, Effect as KiwiEffect, GUID } from './codec'
-function ext(nc: NodeChange): Record<string, unknown> {
- return nc as unknown as Record<string, unknown>
-}
+
export function guidToString(guid: GUID): string {
return `${guid.sessionID}:${guid.localID}`
@@ -290,7 +288,7 @@ function convertLetterSpacing(
return ls.value
}
-function mapArcData(data?: Record<string, number>): ArcData | null {
+function mapArcData(data?: Partial<ArcData>): ArcData | null {
if (!data) return null
return {
startingAngle: data.startingAngle ?? 0,
@@ -309,7 +307,7 @@ function importStyleRuns(nc: NodeChange): StyleRun[] {
const styleMap = new Map<number, CharacterStyleOverride>()
for (const override of table) {
- const id = (override as unknown as Record<string, unknown>).styleID as number | undefined
+ const id = override.styleID as number | undefined
if (id === undefined) continue
const style: CharacterStyleOverride = {}
if (override.fontName) {
@@ -323,7 +321,7 @@ function importStyleRuns(nc: NodeChange): StyleRun[] {
const lh = convertLineHeight(override.lineHeight, override.fontSize)
if (lh != null) style.lineHeight = lh
}
- const deco = ext(override).textDecoration as string | undefined
+ const deco = override.textDecoration as string | undefined
if (deco) style.textDecoration = mapTextDecoration(deco)
if (Object.keys(style).length > 0) styleMap.set(id, style)
}
@@ -354,7 +352,7 @@ function resolveVectorNetwork(
nc: NodeChange,
blobs: Uint8Array[]
): VectorNetwork | null {
- const vectorData = (nc as unknown as Record<string, unknown>).vectorData as
+ const vectorData = nc.vectorData as
| {
vectorNetworkBlob?: number
normalizedSize?: { x: number; y: number }
@@ -453,7 +451,7 @@ export function nodeChangeToProps(
rotation = Math.atan2(nc.transform.m10 * sx, nc.transform.m00 * sx) * (180 / Math.PI)
}
- const dashPattern = (ext(nc).dashPattern as number[]) ?? []
+ const dashPattern = (nc.dashPattern as number[]) ?? []
return {
nodeType,
@@ -468,7 +466,7 @@ export function nodeChangeToProps(
opacity: nc.opacity ?? 1,
visible: nc.visible ?? true,
locked: nc.locked ?? false,
- blendMode: (ext(nc).blendMode as Fill['blendMode']) ?? 'PASS_THROUGH',
+ blendMode: (nc.blendMode as Fill['blendMode']) ?? 'PASS_THROUGH',
fills: convertFills(nc.fillPaints),
strokes: convertStrokes(
nc.strokePaints,
@@ -493,16 +491,16 @@ export function nodeChangeToProps(
italic: nc.fontName?.style?.toLowerCase().includes('italic') ?? false,
textAlignHorizontal:
(nc.textAlignHorizontal as 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED') ?? 'LEFT',
- textAlignVertical: (ext(nc).textAlignVertical as TextAlignVertical) ?? 'TOP',
- textAutoResize: (ext(nc).textAutoResize as TextAutoResize) ?? 'NONE',
- textCase: (ext(nc).textCase as TextCase) ?? 'ORIGINAL',
- textDecoration: mapTextDecoration(ext(nc).textDecoration as string),
+ textAlignVertical: (nc.textAlignVertical as TextAlignVertical) ?? 'TOP',
+ textAutoResize: (nc.textAutoResize as TextAutoResize) ?? 'NONE',
+ textCase: (nc.textCase as TextCase) ?? 'ORIGINAL',
+ textDecoration: mapTextDecoration(nc.textDecoration as string),
lineHeight: convertLineHeight(nc.lineHeight, nc.fontSize),
letterSpacing: convertLetterSpacing(nc.letterSpacing, nc.fontSize),
- maxLines: (ext(nc).maxLines as number) ?? null,
+ maxLines: (nc.maxLines as number) ?? null,
styleRuns: importStyleRuns(nc),
- horizontalConstraint: mapConstraint(ext(nc).horizontalConstraint as string),
- verticalConstraint: mapConstraint(ext(nc).verticalConstraint as string),
+ horizontalConstraint: mapConstraint(nc.horizontalConstraint as string),
+ verticalConstraint: mapConstraint(nc.verticalConstraint as string),
layoutMode: mapStackMode(nc.stackMode),
itemSpacing: nc.stackSpacing ?? 0,
paddingTop: nc.stackVerticalPadding ?? nc.stackPadding ?? 0,
@@ -513,37 +511,37 @@ export function nodeChangeToProps(
counterAxisSizing: mapStackSizing(nc.stackCounterSizing),
primaryAxisAlign: mapStackJustify(nc.stackPrimaryAlignItems ?? nc.stackJustify),
counterAxisAlign: mapStackCounterAlign(nc.stackCounterAlignItems ?? nc.stackCounterAlign),
- layoutWrap: ext(nc).stackWrap === 'WRAP' ? 'WRAP' : 'NO_WRAP',
- counterAxisSpacing: (ext(nc).stackCounterSpacing as number) ?? 0,
- layoutPositioning: ext(nc).stackPositioning === 'ABSOLUTE' ? 'ABSOLUTE' : 'AUTO',
- layoutGrow: (ext(nc).stackChildPrimaryGrow as number) ?? 0,
- layoutAlignSelf: (ext(nc).stackChildAlignSelf as string) === 'STRETCH' ? 'STRETCH' : 'AUTO',
+ layoutWrap: nc.stackWrap === 'WRAP' ? 'WRAP' : 'NO_WRAP',
+ counterAxisSpacing: (nc.stackCounterSpacing as number) ?? 0,
+ layoutPositioning: nc.stackPositioning === 'ABSOLUTE' ? 'ABSOLUTE' : 'AUTO',
+ layoutGrow: (nc.stackChildPrimaryGrow as number) ?? 0,
+ layoutAlignSelf: (nc.stackChildAlignSelf as string) === 'STRETCH' ? 'STRETCH' : 'AUTO',
vectorNetwork: resolveVectorNetwork(nc, blobs),
fillGeometry: resolveGeometryPaths(nc.fillGeometry, blobs),
strokeGeometry: resolveGeometryPaths(nc.strokeGeometry, blobs),
- arcData: mapArcData(ext(nc).arcData as Record<string, number> | undefined),
+ arcData: mapArcData(nc.arcData as Partial<ArcData> | undefined),
strokeCap: (nc.strokeCap ?? 'NONE') as StrokeCap,
strokeJoin: (nc.strokeJoin ?? 'MITER') as StrokeJoin,
dashPattern,
- borderTopWeight: (ext(nc).borderTopWeight as number) ?? 0,
- borderRightWeight: (ext(nc).borderRightWeight as number) ?? 0,
- borderBottomWeight: (ext(nc).borderBottomWeight as number) ?? 0,
- borderLeftWeight: (ext(nc).borderLeftWeight as number) ?? 0,
- independentStrokeWeights: (ext(nc).borderStrokeWeightsIndependent as boolean) ?? false,
+ borderTopWeight: (nc.borderTopWeight as number) ?? 0,
+ borderRightWeight: (nc.borderRightWeight as number) ?? 0,
+ borderBottomWeight: (nc.borderBottomWeight as number) ?? 0,
+ borderLeftWeight: (nc.borderLeftWeight as number) ?? 0,
+ independentStrokeWeights: (nc.borderStrokeWeightsIndependent as boolean) ?? false,
strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,
- minWidth: (ext(nc).minWidth as number) ?? null,
- maxWidth: (ext(nc).maxWidth as number) ?? null,
- minHeight: (ext(nc).minHeight as number) ?? null,
- maxHeight: (ext(nc).maxHeight as number) ?? null,
- isMask: (ext(nc).isMask as boolean) ?? false,
- maskType: ((ext(nc).maskType as string) ?? 'ALPHA') as 'ALPHA' | 'VECTOR' | 'LUMINANCE',
+ minWidth: (nc.minWidth as number) ?? null,
+ maxWidth: (nc.maxWidth as number) ?? null,
+ minHeight: (nc.minHeight as number) ?? null,
+ maxHeight: (nc.maxHeight as number) ?? null,
+ isMask: (nc.isMask as boolean) ?? false,
+ maskType: ((nc.maskType as string) ?? 'ALPHA') as 'ALPHA' | 'VECTOR' | 'LUMINANCE',
counterAxisAlignContent:
- (ext(nc).stackCounterAlignContent as string) === 'SPACE_BETWEEN' ? 'SPACE_BETWEEN' : 'AUTO',
- itemReverseZIndex: (ext(nc).stackReverseZIndex as boolean) ?? false,
- strokesIncludedInLayout: (ext(nc).strokesIncludedInLayout as boolean) ?? false,
+ (nc.stackCounterAlignContent as string) === 'SPACE_BETWEEN' ? 'SPACE_BETWEEN' : 'AUTO',
+ itemReverseZIndex: (nc.stackReverseZIndex as boolean) ?? false,
+ strokesIncludedInLayout: (nc.strokesIncludedInLayout as boolean) ?? false,
expanded: true,
- textTruncation: (ext(nc).textTruncation as string) === 'ENDING' ? 'ENDING' : 'DISABLED',
- autoRename: (ext(nc).autoRename as boolean) ?? true,
+ textTruncation: (nc.textTruncation as string) === 'ENDING' ? 'ENDING' : 'DISABLED',
+ autoRename: (nc.autoRename as boolean) ?? true,
boundVariables: extractBoundVariables(nc),
clipsContent: nc.frameMaskDisabled === false,
componentId: extractSymbolId(nc)
@@ -551,7 +549,7 @@ export function nodeChangeToProps(
}
function isComponentSet(nc: NodeChange): boolean {
- const defs = ext(nc).componentPropDefs as Array<{ type?: string }> | undefined
+ const defs = nc.componentPropDefs as Array<{ type?: string }> | undefined
if (!defs?.length) return false
return defs.some((d) => d.type === 'VARIANT')
}
@@ -561,7 +559,7 @@ export function sortChildren(
parentNc: NodeChange,
nodeMap: Map<string, NodeChange>
): void {
- const stackMode = (parentNc as unknown as Record<string, unknown>).stackMode as string | undefined
+ const stackMode = parentNc.stackMode as string | undefined
if (stackMode === 'HORIZONTAL' || stackMode === 'VERTICAL') {
const axis = stackMode === 'HORIZONTAL' ? 'm02' : 'm12'
children.sort((a, b) => {
@@ -579,7 +577,7 @@ export function sortChildren(
}
function extractSymbolId(nc: NodeChange): string {
- const sd = (nc as unknown as Record<string, unknown>).symbolData as
+ const sd = nc.symbolData as
| { symbolID?: GUID }
| undefined
if (!sd?.symbolID) return ''
@@ -699,7 +697,7 @@ export function convertOverrideToProps(ov: Record<string, unknown>): Partial<Sce
updates.textDecoration = mapTextDecoration(ov.textDecoration as string)
if (ov.arcData != null)
- updates.arcData = mapArcData(ov.arcData as Record<string, number> | undefined)
+ updates.arcData = mapArcData(ov.arcData as Partial<ArcData> | undefined)
if (ov.frameMaskDisabled != null) updates.clipsContent = ov.frameMaskDisabled === false
return updates
diff --git a/packages/core/src/profiler/draw-call-counter.ts b/packages/core/src/profiler/draw-call-counter.ts
index becc5be2e..789dfb283 100644
--- a/packages/core/src/profiler/draw-call-counter.ts
+++ b/packages/core/src/profiler/draw-call-counter.ts
@@ -20,10 +20,8 @@ export class DrawCallCounter {
for (const method of DRAW_METHODS) {
const original = gl[method].bind(gl) as (...args: unknown[]) => void
this.originals.set(method, original)
- ;(gl as unknown as Record<string, unknown>)[method] = (...args: unknown[]) => {
- this.count++
- original(...args)
- }
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- monkey-patching overloaded WebGL draw methods
+ ;(gl[method] as Function) = (...args: unknown[]) => { this.count++; original(...args) }
}
}
@@ -38,7 +36,7 @@ export class DrawCallCounter {
if (!gl) return
for (const [method, fn] of this.originals) {
- ;(gl as unknown as Record<string, unknown>)[method] = fn
+ ;(gl[method] as Function) = fn
}
this.originals.clear()
}
diff --git a/packages/core/src/render/components.ts b/packages/core/src/render/components.ts
index 14eadbc94..7c549e555 100644
--- a/packages/core/src/render/components.ts
+++ b/packages/core/src/render/components.ts
@@ -1,43 +1,43 @@
import { node, type BaseProps, type TextProps, type TreeNode } from './tree'
export function Frame(props: BaseProps): TreeNode {
- return node('frame', props as Record<string, unknown>)
+ return node('frame', props)
}
export function Text(props: TextProps): TreeNode {
- return node('text', props as Record<string, unknown>)
+ return node('text', props)
}
export function Rectangle(props: BaseProps): TreeNode {
- return node('rectangle', props as Record<string, unknown>)
+ return node('rectangle', props)
}
export function Ellipse(props: BaseProps): TreeNode {
- return node('ellipse', props as Record<string, unknown>)
+ return node('ellipse', props)
}
export function Line(props: BaseProps): TreeNode {
- return node('line', props as Record<string, unknown>)
+ return node('line', props)
}
export function Star(props: BaseProps & { points?: number; innerRadius?: number }): TreeNode {
- return node('star', props as Record<string, unknown>)
+ return node('star', props)
}
export function Polygon(props: BaseProps & { pointCount?: number }): TreeNode {
- return node('polygon', props as Record<string, unknown>)
+ return node('polygon', props)
}
export function Vector(props: BaseProps): TreeNode {
- return node('vector', props as Record<string, unknown>)
+ return node('vector', props)
}
export function Group(props: BaseProps): TreeNode {
- return node('group', props as Record<string, unknown>)
+ return node('group', props)
}
export function Section(props: BaseProps): TreeNode {
- return node('section', props as Record<string, unknown>)
+ return node('section', props)
}
export const View = Frame
diff --git a/packages/core/src/render/jsx-runtime.ts b/packages/core/src/render/jsx-runtime.ts
index 8681fc0df..a40452ed1 100644
--- a/packages/core/src/render/jsx-runtime.ts
+++ b/packages/core/src/render/jsx-runtime.ts
@@ -4,14 +4,14 @@ export function jsx(type: string | ((props: BaseProps) => TreeNode), props: Base
if (typeof type === 'function') {
return type(props)
}
- return node(type, props as Record<string, unknown>)
+ return node(type, props)
}
export const jsxs = jsx
export const jsxDEV = jsx
export function Fragment({ children }: { children?: unknown }): TreeNode {
- return node('fragment', { children } as Record<string, unknown>)
+ return node('fragment', { children })
}
export namespace JSX {
diff --git a/packages/core/src/render/tree.ts b/packages/core/src/render/tree.ts
index 30ed6d8f5..0bd185261 100644
--- a/packages/core/src/render/tree.ts
+++ b/packages/core/src/render/tree.ts
@@ -6,8 +6,7 @@ export interface TreeNode {
export function isTreeNode(x: unknown): x is TreeNode {
if (x === null || typeof x !== 'object') return false
- const obj = x as Record<string, unknown>
- return typeof obj.type === 'string' && 'props' in obj && Array.isArray(obj.children)
+ return 'type' in x && typeof x.type === 'string' && 'props' in x && 'children' in x && Array.isArray(x.children)
}
interface ReactElement {
@@ -64,7 +63,7 @@ function resolveChild(child: unknown): TreeNode | string | null {
return resolveToTree(child)
}
-export function node(type: string, props: Record<string, unknown>): TreeNode {
+export function node(type: string, props: { children?: unknown; [key: string]: unknown }): TreeNode {
const { children, ...rest } = props
const processed = [children]
.flat(Infinity)
diff --git a/packages/core/src/tools/ai-adapter.ts b/packages/core/src/tools/ai-adapter.ts
index 4b43f4871..c7a57d3ce 100644
--- a/packages/core/src/tools/ai-adapter.ts
+++ b/packages/core/src/tools/ai-adapter.ts
@@ -18,8 +18,8 @@ export interface AIAdapterOptions {
function extractIdsFromArray(arr: unknown[]): string[] {
const ids: string[] = []
for (const item of arr) {
- if (item && typeof item === 'object' && typeof (item as Record<string, unknown>).id === 'string') {
- ids.push((item as Record<string, unknown>).id as string)
+ if (item && typeof item === 'object' && 'id' in item && typeof item.id === 'string') {
+ ids.push(item.id)
}
}
return ids
@@ -27,12 +27,11 @@ function extractIdsFromArray(arr: unknown[]): string[] {
function extractNodeIds(result: unknown): string[] {
if (!result || typeof result !== 'object') return []
- const obj = result as Record<string, unknown>
- if (typeof obj.deleted === 'string') return []
+ if ('deleted' in result && typeof result.deleted === 'string') return []
const ids: string[] = []
- if (typeof obj.id === 'string') ids.push(obj.id)
- if (Array.isArray(obj.selection)) ids.push(...extractIdsFromArray(obj.selection))
- if (Array.isArray(obj.results)) ids.push(...extractIdsFromArray(obj.results))
+ if ('id' in result && typeof result.id === 'string') ids.push(result.id)
+ if ('selection' in result && Array.isArray(result.selection)) ids.push(...extractIdsFromArray(result.selection))
+ if ('results' in result && Array.isArray(result.results)) ids.push(...extractIdsFromArray(result.results))
return ids
}
diff --git a/packages/core/src/undo.ts b/packages/core/src/undo.ts
index cc8141a3f..bd65b55ac 100644
--- a/packages/core/src/undo.ts
+++ b/packages/core/src/undo.ts
@@ -97,10 +97,9 @@ export function createPropertyChange(
changes: Partial<SceneNode>,
label: string
): UndoEntry {
- const previous: Partial<SceneNode> = {}
- for (const key of Object.keys(changes) as (keyof SceneNode)[]) {
- ;(previous as Record<string, unknown>)[key] = node[key]
- }
+ const previous = Object.fromEntries(
+ (Object.keys(changes) as (keyof SceneNode)[]).map((key) => [key, node[key]])
+ ) as Partial<SceneNode>
return {
label,
diff --git a/packages/mcp/src/server.ts b/packages/mcp/src/server.ts
index e332d4259..dee9e8e9c 100644
--- a/packages/mcp/src/server.ts
+++ b/packages/mcp/src/server.ts
@@ -114,7 +114,7 @@ export function createServer(version: string, options: CreateServerOptions = {})
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic schema from ToolDef params
server.registerTool(def.name, { description: def.description, inputSchema: z.object(shape) } as any, async (args: any) => {
try {
- const result = await def.execute(makeFigma(), args as Record<string, unknown>) as Record<string, unknown>
+ const result = await def.execute(makeFigma(), args)
if (result && typeof result === 'object' && 'base64' in result && 'mimeType' in result) {
return {
content: [{ type: 'image' as const, data: result.base64 as string, mimeType: result.mimeType as string }]
diff --git a/src/App.vue b/src/App.vue
index c0fac150e..a4d318944 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -5,7 +5,7 @@ import { useHead } from '@unhead/vue'
import AppToast from '@/components/AppToast.vue'
import { toast } from '@/composables/use-toast'
-useHead({ titleTemplate: (title) => title ? `${title} — OpenPencil` : 'OpenPencil' })
+useHead({ titleTemplate: (title) => (title ? `${title} — OpenPencil` : 'OpenPencil') })
onMounted(() => {
toast.setupGlobalErrorHandler()
diff --git a/src/engine/fonts.ts b/src/engine/fonts.ts
index 3053bf054..df0b72f40 100644
--- a/src/engine/fonts.ts
+++ b/src/engine/fonts.ts
@@ -6,7 +6,12 @@ export {
getCJKFallbackFamily
} from '@open-pencil/core'
-import { loadFont as loadFontCore, markFontLoaded, styleToWeight } from '@open-pencil/core'
+import {
+ IS_TAURI,
+ loadFont as loadFontCore,
+ markFontLoaded,
+ styleToWeight
+} from '@open-pencil/core'
interface TauriFontFamily {
family: string
@@ -15,10 +20,6 @@ interface TauriFontFamily {
let tauriFontsCache: TauriFontFamily[] | null = null
-function isTauri(): boolean {
- return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window
-}
-
let tauriFontsPromise: Promise<TauriFontFamily[]> | null = null
async function getTauriFonts(): Promise<TauriFontFamily[]> {
@@ -36,7 +37,7 @@ async function getTauriFonts(): Promise<TauriFontFamily[]> {
}
export function preloadFonts(): void {
- if (isTauri()) {
+ if (IS_TAURI) {
getTauriFonts().then(registerFontFaces)
}
}
@@ -50,7 +51,7 @@ function registerFontFaces(fonts: TauriFontFamily[]): void {
}
export async function listFamilies(): Promise<string[]> {
- if (isTauri()) {
+ if (IS_TAURI) {
const fonts = await getTauriFonts()
return fonts.map((f) => f.family)
}
@@ -60,7 +61,7 @@ export async function listFamilies(): Promise<string[]> {
}
export async function loadFont(family: string, style = 'Regular'): Promise<ArrayBuffer | null> {
- if (isTauri()) {
+ if (IS_TAURI) {
try {
const { invoke } = await import('@tauri-apps/api/core')
const data = await invoke<number[]>('load_system_font', { family, style })
diff --git a/src/env.d.ts b/src/env.d.ts
index a7c1d3bb4..4a9769c46 100644
--- a/src/env.d.ts
+++ b/src/env.d.ts
@@ -7,5 +7,3 @@ declare module '*.vue' {
const component: DefineComponent<object, object, unknown>
export default component
}
-
-
diff --git a/src/main.ts b/src/main.ts
index 27c8f90af..5a3a42ebe 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,5 +1,5 @@
-import { createApp } from 'vue'
import { createHead } from '@unhead/vue/client'
+import { createApp } from 'vue'
import './app.css'
import { IS_TAURI } from '@/constants'