@skvggor/pharos 1.0.0

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.
@@ -0,0 +1,21 @@
1
+ import { PixelShape } from '../../domain/index';
2
+ import { HTMLAttributes } from 'react';
3
+ export interface PixelTextProps extends Omit<HTMLAttributes<HTMLSpanElement>, "children"> {
4
+ text: string;
5
+ pixelSize?: number | string;
6
+ gap?: number | string;
7
+ letterSpacing?: number | string;
8
+ color?: string;
9
+ offColor?: string;
10
+ pixelShape?: PixelShape;
11
+ smartCorners?: boolean;
12
+ smoothness?: number;
13
+ proportional?: boolean;
14
+ spaceWidth?: number;
15
+ renderOff?: boolean;
16
+ fluid?: boolean;
17
+ gapRatio?: number;
18
+ letterSpacingRatio?: number;
19
+ "aria-label"?: string;
20
+ }
21
+ export declare function PixelText({ text, pixelSize, gap, letterSpacing, color, offColor, pixelShape, smartCorners, smoothness, proportional, spaceWidth, renderOff, fluid, gapRatio, letterSpacingRatio, className, style, ...rest }: PixelTextProps): import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ export type Cell = "off" | "on" | "tl" | "tr" | "bl" | "br";
2
+ export type PixelRow = Cell[];
3
+ export type PixelMatrix = PixelRow[];
4
+ export type GlyphSource = readonly string[];
5
+ export type PixelShape = "square" | "squircle" | "dot" | "diamond" | "ring";
6
+ export interface RenderedGlyph {
7
+ character: string;
8
+ matrix: PixelMatrix;
9
+ isFallback: boolean;
10
+ }
11
+ export interface CanvasMetrics {
12
+ width: number;
13
+ height: number;
14
+ accentTop: number;
15
+ capTop: number;
16
+ xHeight: number;
17
+ baseline: number;
18
+ descenderBottom: number;
19
+ }
@@ -0,0 +1,9 @@
1
+ import { Cell, CanvasMetrics } from '../../domain/index';
2
+ /**
3
+ * Glyph source markers. `#` full pixel, `.` empty. Numpad-mnemonic corner
4
+ * triangles smooth diagonals and curves: 7=top-left, 9=top-right,
5
+ * 1=bottom-left, 3=bottom-right (the corner each triangle fills).
6
+ */
7
+ export declare const CELL_MARKERS: Record<string, Cell>;
8
+ export declare const METRICS: CanvasMetrics;
9
+ export declare function isLit(cell: Cell): boolean;
@@ -0,0 +1,3 @@
1
+ import { GlyphSource, PixelMatrix } from '../../domain/index';
2
+ export declare function parseGlyph(source: GlyphSource): PixelMatrix;
3
+ export declare function emptyMatrix(): PixelMatrix;
@@ -0,0 +1,10 @@
1
+ import { GlyphSource, PixelMatrix, RenderedGlyph } from '../../domain/index';
2
+ /**
3
+ * Register (or override) a glyph at runtime. The source is validated against
4
+ * the canvas metrics and the parsed matrix cache is invalidated.
5
+ */
6
+ export declare function registerGlyph(character: string, source: GlyphSource): void;
7
+ export declare function getCharacters(): string[];
8
+ export declare function getGlyphMatrix(character: string): PixelMatrix | undefined;
9
+ export declare function hasGlyph(character: string): boolean;
10
+ export declare function renderText(text: string): RenderedGlyph[];
@@ -0,0 +1,10 @@
1
+ import { PixelMatrix } from '../../domain/index';
2
+ export interface GlyphBounds {
3
+ start: number;
4
+ end: number;
5
+ }
6
+ /**
7
+ * Horizontal ink bounds of a glyph (inclusive column range that contains any
8
+ * lit pixel). Returns null for empty glyphs such as the space character.
9
+ */
10
+ export declare function glyphBounds(matrix: PixelMatrix): GlyphBounds | null;
@@ -0,0 +1,8 @@
1
+ import { GlyphSource } from '../../domain/index';
2
+ /**
3
+ * Pilot serif glyph set on the 12x18 canvas.
4
+ * `#` full pixel, `.` empty, 7/9/1/3 corner triangles (numpad-mnemonic).
5
+ * Vertical zones: rows 0-2 accent, 3-13 cap body, 6-13 x-height, 14-17 descender.
6
+ */
7
+ export declare const GLYPHS: Record<string, GlyphSource>;
8
+ export declare const FALLBACK_CHARACTER = " ";
@@ -0,0 +1,8 @@
1
+ export { PixelText } from '../components/PixelText';
2
+ export type { PixelTextProps } from '../components/PixelText';
3
+ export { METRICS, isLit } from '../engine/metrics';
4
+ export { renderText, getGlyphMatrix, hasGlyph, registerGlyph, getCharacters, } from '../engine/render-text';
5
+ export { glyphBounds } from '../engine/spacing';
6
+ export type { GlyphBounds } from '../engine/spacing';
7
+ export { GLYPHS } from '../glyphs/registry';
8
+ export type { CanvasMetrics, Cell, GlyphSource, PixelMatrix, PixelRow, PixelShape, RenderedGlyph, } from '../domain/index';
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@skvggor/pharos",
3
+ "version": "1.0.0",
4
+ "description": "A serif pixel display font for React — text as a configurable grid of pixels.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "author": "Marcos Lima (https://skvggor.dev)",
11
+ "homepage": "https://skvggor.github.io/pharos/",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/skvggor/pharos.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/skvggor/pharos/issues"
18
+ },
19
+ "keywords": [
20
+ "react",
21
+ "pixel-font",
22
+ "display-font",
23
+ "dot-matrix",
24
+ "led",
25
+ "bitmap-font",
26
+ "serif",
27
+ "css"
28
+ ],
29
+ "main": "./dist/pharos.cjs",
30
+ "module": "./dist/pharos.js",
31
+ "types": "./dist/src/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/src/index.d.ts",
35
+ "import": "./dist/pharos.js",
36
+ "require": "./dist/pharos.cjs"
37
+ },
38
+ "./styles.css": "./dist/pharos.css"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "LICENSE",
43
+ "README.md"
44
+ ],
45
+ "sideEffects": [
46
+ "**/*.css"
47
+ ],
48
+ "scripts": {
49
+ "dev": "vite",
50
+ "build": "tsc --noEmit && vite build",
51
+ "build:demo": "vite build --mode demo",
52
+ "preview": "vite preview",
53
+ "typecheck": "tsc --noEmit",
54
+ "test": "vitest run",
55
+ "test:watch": "vitest",
56
+ "test:coverage": "vitest run --coverage",
57
+ "prepack": "npm run build"
58
+ },
59
+ "peerDependencies": {
60
+ "react": ">=18",
61
+ "react-dom": ">=18"
62
+ },
63
+ "devDependencies": {
64
+ "@phosphor-icons/react": "^2.1.10",
65
+ "@testing-library/jest-dom": "^6.9.1",
66
+ "@testing-library/react": "^16.3.2",
67
+ "@types/node": "^25.9.1",
68
+ "@types/react": "^19.2.16",
69
+ "@types/react-dom": "^19.2.3",
70
+ "@vitejs/plugin-react": "^6.0.2",
71
+ "@vitest/coverage-v8": "^4.1.8",
72
+ "jsdom": "^29.1.1",
73
+ "react": "^19.2.7",
74
+ "react-dom": "^19.2.7",
75
+ "typescript": "^6.0.3",
76
+ "vite": "^8.0.16",
77
+ "vite-plugin-dts": "^5.0.2",
78
+ "vitest": "^4.1.8"
79
+ }
80
+ }