0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-06 14:50:21 -05:00

feat: add some utilities to use fonts in plugins

This commit is contained in:
alonso.torres 2024-06-13 15:22:33 +02:00 committed by Alonso Torres
parent 69a13d6269
commit 0776ca671c
2 changed files with 105 additions and 0 deletions

View file

@ -1662,6 +1662,11 @@ export interface PenpotLibraryTypography extends PenpotLibraryElement {
* ```
*/
applyToTextRange(range: PenpotTextRange): void;
/**
* TODO setFont
*/
setFont(font: PenpotFont, variant?: PenpotFontVariant): void;
}
/**
@ -1756,6 +1761,96 @@ export type PenpotLibraryContext = {
connected: PenpotLibrary[];
};
/**
* TODO PenpotFontVariant
*/
export interface PenpotFontVariant {
/**
* TODO name
*/
name: string;
/**
* TODO fontVariantId
*/
fontVariantId: string;
/**
* TODO fontWeight
*/
fontWeight: string;
/**
* TODO fontStyle
*/
fontStyle: string;
}
/**
* TODO PenpotFont
*/
export interface PenpotFont {
/**
* TODO name
*/
name: string;
/**
* TODO fontId
*/
fontId: string;
/**
* TODO fontFamily
*/
fontFamily: string;
/**
* TODO fontStyle
*/
fontStyle: string;
/**
* TODO fontVariantId
*/
fontVariantId: string;
/**
* TODO fontWeight
*/
fontWeight: string;
/**
* TODO variants
*/
variants: PenpotFontVariant[];
/**
* TODO applyToText
*/
applyToText(text: PenpotText, variant?: PenpotFontVariant): void;
/**
* TODO applyToRange
*/
applyToRange(range: PenpotTextRange, variant?: PenpotFontVariant): void;
}
/**
* TODO PenpotFontsContext
*/
export interface PenpotFontsContext {
/**
* TODO all
*/
all: PenpotFont[];
/**
* TODO findById
*/
findById(id: string): PenpotFont | null;
/**
* TODO findByName
*/
findByName(name: string): PenpotFont | null;
/**
* TODO findAllById
*/
findAllById(id: string): PenpotFont[];
/**
* TODO findAllByName
*/
findAllByName(name: string): PenpotFont[];
}
/**
* Represents a user in Penpot.
*/
@ -1865,6 +1960,10 @@ export interface PenpotContext {
* ```
*/
readonly library: PenpotLibraryContext;
/**
* TODO
*/
readonly fonts: PenpotFontsContext;
/**
* The current user in the Penpot context.
* @example

View file

@ -18,6 +18,7 @@ import type {
PenpotBool,
PenpotUser,
PenpotActiveUser,
PenpotFontsContext,
} from '@penpot/plugin-types';
import { Manifest, Permissions } from '../models/manifest.model.js';
@ -196,6 +197,11 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
return context.library;
},
get fonts(): PenpotFontsContext {
// checkPermission('viewport:read');
return context.fonts;
},
get currentUser(): PenpotUser {
// checkPermission('user:read');
return context.currentUser;