@logomarks/core 0.2.0 → 0.2.1
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.
- package/CHANGELOG.md +11 -0
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/analyse/index.d.ts +1 -0
- package/src/analyse/index.js +3 -2
- package/src/analyse/optical.d.ts +20 -0
- package/src/analyse/optical.js +76 -0
- package/src/edit/cells.d.ts +13 -0
- package/src/edit/cells.js +26 -0
- package/src/edit/index.d.ts +3 -1
- package/src/edit/index.js +4 -2
- package/src/edit/pixelate.d.ts +2 -0
- package/src/edit/pixelate.js +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to `@logomarks/core` are documented here.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.1] — 2026-11-15
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
The Lookbook's mark measures, moved here from `@logomarks/lookbook/marks` (the code unchanged, documented and typed), so the cards and anything else that sizes a mark share one copy. Browser-safe, like the rest of `/analyse` and `/edit`.
|
|
13
|
+
|
|
14
|
+
- **The optical size in `/analyse`:** `markBox(paths)` (the real box round a mark's outlines, the 448 fit's box when there is nothing to read), `inkShare(paths)` (how much of that box is ink, by scanline coverage 16 cells across), `opticalScale(box, ink)` (how much bigger to draw a wide, slim or light mark: 1 for a square solid, 448 × 200 about 1.22, never above 1.3) and `OPTICAL`, its limits.
|
|
15
|
+
- **Cells by count in `/edit`:** `cellsAcross(n, box)` beside `pixelGrid` (a grid `n` cells across the box's longest side, any `n`, where `pixelGrid` takes an amount and stops at 14 across), and `markCells(paths, n)` (shapes → rings → coverage → filled cells and their path in one call).
|
|
16
|
+
|
|
17
|
+
Proved on `@logomarks/lookbook` 0.1.0: its own functions give the same values as these on the golden cases, and its equivalence tests pass unchanged on them. The golden tests gain the five cases (`optical.*`, `cells.*`), on six live marks.
|
|
18
|
+
|
|
8
19
|
## [0.2.0] — 2026-11-15
|
|
9
20
|
|
|
10
21
|
### Added
|
package/README.md
CHANGED
|
@@ -27,10 +27,10 @@ checkFit(mark).problems; // []
|
|
|
27
27
|
- `/geometry`: shapes and real booleans, strokes, tracks, iso solids, badges and letter skeletons
|
|
28
28
|
- `/svg`: one SVG path parser, filled shapes, bounds and rings
|
|
29
29
|
- `/fit`: the 448 fit and its check (refitting a fitted mark gives the same file)
|
|
30
|
-
- `/analyse`: specks, slivers and pin-holes, gap and stroke widths, shape tags
|
|
30
|
+
- `/analyse`: specks, slivers and pin-holes, gap and stroke widths, shape tags, the optical size (a mark's box, its ink, how much bigger to draw it)
|
|
31
31
|
- `/similar`: outline and letter signatures, IoU and nearest marks
|
|
32
32
|
- `/raster`: scanline fill, components, distance transform
|
|
33
|
-
- `/edit`: the studio's shape edits (weight, soften, gap, detail) and pixelate
|
|
33
|
+
- `/edit`: the studio's shape edits (weight, soften, gap, detail) and pixelate, by amount or by a count of cells
|
|
34
34
|
- `/sdf`: shapes as signed distance fields, smooth unions and exact gap cuts, traced to kit shapes
|
|
35
35
|
- `/stitch`: a mark planned as machine embroidery (fill, satin and border stitches), for a renderer to draw as thread
|
|
36
36
|
- `/parts`: the parts the industry symbols are built from (Node)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logomarks/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Geometry, SVG reading, fitting, analysis and similarity for logomarks on a 512 grid: the kit the Logomarks set is drawn with (shapes, real booleans, strokes, tracks, iso solids, badges, letter skeletons), one SVG path parser, the 448 fit, speck and shape-tag analysis, outline signatures, signed distance fields traced to shapes, stitch plans for embroidery, and the parts the generators draw with: iso objects, letters and type, font glyphs, pixel dither, objects and the Bold, Line and Track forms, plus the batch runner.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/analyse/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export { SPECKS, vectorParts, rasterParts, markParts, smallParts } from './speck
|
|
|
6
6
|
export { SHAPE, shapeTags, tagsOf } from './tags.js';
|
|
7
7
|
export { MEASURE, shapeMeasures } from './shape/measures.js';
|
|
8
8
|
export { WIDTHS, groupRuns, widths } from './widths.js';
|
|
9
|
+
export { OPTICAL, markBox, inkShare, opticalScale } from './optical.js';
|
package/src/analyse/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Analysis of a mark: its pieces and holes (specks, slivers, pin-holes), its stroke and gap widths,
|
|
3
|
-
* (with the measures they are decided on).
|
|
2
|
+
* Analysis of a mark: its pieces and holes (specks, slivers, pin-holes), its stroke and gap widths, its shape tags
|
|
3
|
+
* (with the measures they are decided on), and its optical size (its real box and how much of it is ink).
|
|
4
4
|
*/
|
|
5
5
|
export { SPECKS, vectorParts, rasterParts, markParts, smallParts } from './specks.js';
|
|
6
6
|
export { SHAPE, shapeTags, tagsOf } from './tags.js';
|
|
7
7
|
export { MEASURE, shapeMeasures } from './shape/measures.js';
|
|
8
8
|
export { WIDTHS, groupRuns, widths } from './widths.js';
|
|
9
|
+
export { OPTICAL, markBox, inkShare, opticalScale } from './optical.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Bounds } from '../svg/outline.js';
|
|
2
|
+
|
|
3
|
+
/** The optical size's limits: the most a mark grows, and how much its box and its ink count. */
|
|
4
|
+
export const OPTICAL: {
|
|
5
|
+
/** The most a mark grows (× its 448 fit). */
|
|
6
|
+
readonly max: 1.3;
|
|
7
|
+
/** The box's term: (448² / its area) to this power, so a square is 1, 448 × 200 about 1.22. */
|
|
8
|
+
readonly power: 0.25;
|
|
9
|
+
/** The ink's term: up to this much more for a light mark … */
|
|
10
|
+
readonly light: 0.1;
|
|
11
|
+
/** … in full at or below this share of its box inked, none at or above `solid`. */
|
|
12
|
+
readonly thin: 0.2;
|
|
13
|
+
readonly solid: 0.45;
|
|
14
|
+
};
|
|
15
|
+
/** The real box round a mark's outlines (its paths, or the whole file), on the 512 canvas; the 448 fit's box when there is nothing to read. */
|
|
16
|
+
export function markBox(paths: string): Bounds;
|
|
17
|
+
/** How much of a mark's own box is ink, 0–1 (scanline coverage, 16 cells across its longest side); 1 when there is nothing to read. */
|
|
18
|
+
export function inkShare(paths: string): number;
|
|
19
|
+
/** The mark's optical size: how much bigger to draw a wide, slim or light mark, 1 to `OPTICAL.max`; `ink` 1 leaves the ink out of it. */
|
|
20
|
+
export function opticalScale(box: Pick<Bounds, 'w' | 'h'>, ink?: number): number;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @logomarks/core/analyse/optical
|
|
3
|
+
*
|
|
4
|
+
* A mark's optical size: its real box, how much of that box is ink, and how much bigger to draw it so a wide, slim or
|
|
5
|
+
* light mark holds as much of the eye as a square, solid one at the 448 fit. Browser-safe (core's SVG reader and
|
|
6
|
+
* scanline coverage, no renderer). From the Lookbook's mark measures (`@logomarks/lookbook/marks`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { shapes } from '../svg/shapes.js';
|
|
10
|
+
import { bounds } from '../svg/outline.js';
|
|
11
|
+
import { rings } from '../svg/rings.js';
|
|
12
|
+
import { cellsAcross, pixelCoverage } from '../edit/pixelate.js';
|
|
13
|
+
import { CANVAS, FIT } from '../fit/index.js';
|
|
14
|
+
|
|
15
|
+
/** The 448 fit's box on the 512 canvas: what `markBox` gives when there is nothing to read. */
|
|
16
|
+
const FITTED = { x: (CANVAS - FIT) / 2, y: (CANVAS - FIT) / 2, w: FIT, h: FIT };
|
|
17
|
+
|
|
18
|
+
/** The optical size's limits: the most a mark grows, and how much its box and its ink count. */
|
|
19
|
+
export const OPTICAL = {
|
|
20
|
+
/** The most a mark grows (× its 448 fit). */
|
|
21
|
+
max: 1.3,
|
|
22
|
+
/** The box's term: (448² / its area) to this power, so a square is 1, 448 × 200 about 1.22. */
|
|
23
|
+
power: 0.25,
|
|
24
|
+
/** The ink's term: up to this much more for a light mark … */
|
|
25
|
+
light: 0.1,
|
|
26
|
+
/** … in full at or below this share of its box inked, none at or above `solid`. */
|
|
27
|
+
thin: 0.2,
|
|
28
|
+
solid: 0.45,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The real box round a mark's outlines, on the 512 canvas (curves and arcs sampled, as the fit measures them); the
|
|
33
|
+
* 448 fit's box when there is nothing to read.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} paths The mark's markup: its paths, or the whole file.
|
|
36
|
+
* @returns {import('../svg/outline.js').Bounds} The box.
|
|
37
|
+
*/
|
|
38
|
+
export function markBox(paths) {
|
|
39
|
+
const list = shapes(paths);
|
|
40
|
+
if (!list.length) return { ...FITTED };
|
|
41
|
+
const b = bounds(list);
|
|
42
|
+
return Number.isFinite(b.w) && b.w > 0 ? b : { ...FITTED };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* How much of a mark's own box is ink, 0–1: the scanline coverage on a grid 16 cells across its longest side.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} paths The mark's markup: its paths, or the whole file.
|
|
49
|
+
* @returns {number} The share inked; 1 when there is nothing to read.
|
|
50
|
+
*/
|
|
51
|
+
export function inkShare(paths) {
|
|
52
|
+
const list = shapes(paths);
|
|
53
|
+
if (!list.length) return 1;
|
|
54
|
+
const grid = cellsAcross(16, markBox(paths));
|
|
55
|
+
const cov = pixelCoverage(list.map((s) => ({ rings: rings(s.segs, 3), evenodd: s.evenodd })), grid);
|
|
56
|
+
let sum = 0;
|
|
57
|
+
for (const v of cov) sum += v;
|
|
58
|
+
return cov.length ? sum / cov.length : 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The mark's optical size: how much bigger to draw it so it holds as much of the eye as a square, solid mark at the
|
|
63
|
+
* 448 fit. Every mark is fitted to 448 on its longest side, so a wide, short one (448 × 200) or a slim one (266 × 448)
|
|
64
|
+
* carries far less area, and a light, line-drawn one less weight. 1 for a square solid; 448 × 200 about 1.22; never
|
|
65
|
+
* below 1, never above `OPTICAL.max`.
|
|
66
|
+
*
|
|
67
|
+
* @param {{ w: number, h: number }} box The mark's box (`markBox`).
|
|
68
|
+
* @param {number} [ink=1] The share of its box inked (`inkShare`); 1 leaves the ink out of it.
|
|
69
|
+
* @returns {number} The scale, 1 to `OPTICAL.max`.
|
|
70
|
+
*/
|
|
71
|
+
export function opticalScale(box, ink = 1) {
|
|
72
|
+
const { max, power, light, thin, solid } = OPTICAL;
|
|
73
|
+
const area = (FIT * FIT) / Math.max(1, box.w * box.h);
|
|
74
|
+
const weight = 1 + light * Math.min(1, Math.max(0, (solid - ink) / (solid - thin)));
|
|
75
|
+
return Math.min(max, Math.max(1, area ** power * weight));
|
|
76
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PixelGrid } from './pixelate.js';
|
|
2
|
+
|
|
3
|
+
/** A mark as square cells: the grid, which cells are filled (row by row), and the filled cells as one path. */
|
|
4
|
+
export interface MarkCells {
|
|
5
|
+
grid: PixelGrid;
|
|
6
|
+
/** 1 per filled cell, row by row. */
|
|
7
|
+
on: Uint8Array;
|
|
8
|
+
/** The filled cells merged into rectangles, as one path's d; empty when none is filled. */
|
|
9
|
+
d: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The mark (its paths, or the whole file) as square cells, `n` across its longest side, by scanline coverage. */
|
|
13
|
+
export function markCells(paths: string, n: number): MarkCells;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @logomarks/core/edit/cells
|
|
3
|
+
*
|
|
4
|
+
* A mark as square cells by count: shapes → rings → scanline coverage → filled cells in one call, on a grid `n` cells
|
|
5
|
+
* across the mark's real box (`cellsAcross`). Browser-safe. From the Lookbook's mark measures (its pixel and LED looks).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { shapes } from '../svg/shapes.js';
|
|
9
|
+
import { rings } from '../svg/rings.js';
|
|
10
|
+
import { markBox } from '../analyse/optical.js';
|
|
11
|
+
import { cellsAcross, pixelCoverage, pixelCells, pixelPath } from './pixelate.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The mark as square cells, `n` across its longest side, measured by scanline coverage (half a cell covered, or a
|
|
15
|
+
* fifth where a cell would otherwise break a thin line: `pixelCells`).
|
|
16
|
+
*
|
|
17
|
+
* @param {string} paths The mark's markup: its paths, or the whole file.
|
|
18
|
+
* @param {number} n Cells across the longest side.
|
|
19
|
+
* @returns {import('./cells.js').MarkCells} The grid, the filled cells and the filled cells as one path (empty when none).
|
|
20
|
+
*/
|
|
21
|
+
export function markCells(paths, n) {
|
|
22
|
+
const list = shapes(paths);
|
|
23
|
+
const grid = cellsAcross(n, markBox(paths));
|
|
24
|
+
const cov = pixelCoverage(list.map((s) => ({ rings: rings(s.segs), evenodd: s.evenodd })), grid);
|
|
25
|
+
return { grid, on: pixelCells(cov, grid), d: pixelPath(cov, grid) ?? '' };
|
|
26
|
+
}
|
package/src/edit/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { ShapeInfo, SmallSizeInfo } from './reshape.js';
|
|
2
2
|
export type { Adjust, Frame, Similarity, AdjustEnv } from './adjust.js';
|
|
3
3
|
export type { PixelGrid } from './pixelate.js';
|
|
4
|
+
export type { MarkCells } from './cells.js';
|
|
4
5
|
export { loadShaper, shaperReady, hasCorners, reshape, pieceCount, shapeInfo, smallSizeInfo } from './reshape.js';
|
|
5
6
|
export { NO_ADJUST, isAdjusted, adjustSuffix, transformPath, adjustPaths } from './adjust.js';
|
|
6
|
-
export { SS, pixelGrid, pixelPath, pixelCells, pixelCoverage } from './pixelate.js';
|
|
7
|
+
export { SS, pixelGrid, cellsAcross, pixelPath, pixelCells, pixelCoverage } from './pixelate.js';
|
|
8
|
+
export { markCells } from './cells.js';
|
package/src/edit/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shape edits for a studio: weight, soften, gap and detail (Clipper, loaded on first use), turns, tilts, flips and
|
|
3
|
-
* frames, and pixel-art redraws. Browser-safe: what needs a renderer (exact
|
|
3
|
+
* frames, and pixel-art redraws (by amount, or by a count of cells across). Browser-safe: what needs a renderer (exact
|
|
4
|
+
* bounds, a canvas) is passed in.
|
|
4
5
|
*/
|
|
5
6
|
export { loadShaper, shaperReady, hasCorners, reshape, pieceCount, shapeInfo, smallSizeInfo } from './reshape.js';
|
|
6
7
|
export { NO_ADJUST, isAdjusted, adjustSuffix, transformPath, adjustPaths } from './adjust.js';
|
|
7
|
-
export { SS, pixelGrid, pixelPath, pixelCells, pixelCoverage } from './pixelate.js';
|
|
8
|
+
export { SS, pixelGrid, cellsAcross, pixelPath, pixelCells, pixelCoverage } from './pixelate.js';
|
|
9
|
+
export { markCells } from './cells.js';
|
package/src/edit/pixelate.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface PixelGrid {
|
|
|
13
13
|
export const SS: 6;
|
|
14
14
|
/** The grid for a box: 48 cells across its longest side at amount 0, 14 at amount 1, centred. */
|
|
15
15
|
export function pixelGrid(amount: number, box: { x: number; y: number; width: number; height: number }): PixelGrid;
|
|
16
|
+
/** The grid for a box by count: `n` cells across its longest side (any `n`), centred. */
|
|
17
|
+
export function cellsAcross(n: number, box: { x: number; y: number; w: number; h: number }): PixelGrid;
|
|
16
18
|
/** How much of each cell the mark's rings cover (0–1, row by row), by scanline at SS × SS samples a cell. */
|
|
17
19
|
export function pixelCoverage(paths: readonly FillPath[], grid: PixelGrid): Float32Array;
|
|
18
20
|
/** The filled cells (1 each, row by row): half covered, or a fifth where a cell stands alone or bridges two. */
|
package/src/edit/pixelate.js
CHANGED
|
@@ -36,6 +36,21 @@ export function pixelGrid(amount, box) {
|
|
|
36
36
|
return { cols, rows, cell, x0, y0 };
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* A pixel grid of `n` cells across a box's longest side, centred on it: `pixelGrid` sized by a count, any count
|
|
41
|
+
* (`pixelGrid` takes an amount and stops at 14 across).
|
|
42
|
+
*
|
|
43
|
+
* @param {number} n Cells across the longest side.
|
|
44
|
+
* @param {{ x: number, y: number, w: number, h: number }} box The mark's box (`markBox` in `/analyse`, or `bounds`).
|
|
45
|
+
* @returns {import('./index.js').PixelGrid} The grid: columns, rows, cell size and top-left corner.
|
|
46
|
+
*/
|
|
47
|
+
export function cellsAcross(n, box) {
|
|
48
|
+
const cell = Math.max(box.w, box.h) / n;
|
|
49
|
+
const cols = Math.max(1, Math.round(box.w / cell)), rows = Math.max(1, Math.round(box.h / cell));
|
|
50
|
+
const x0 = box.x + box.w / 2 - (cols * cell) / 2, y0 = box.y + box.h / 2 - (rows * cell) / 2;
|
|
51
|
+
return { cols, rows, cell, x0, y0 };
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
/**
|
|
40
55
|
* How much of each cell the mark covers, measured from its rings by scanline at `SS` × `SS` samples a cell: what a
|
|
41
56
|
* canvas would measure, without one.
|