@johnmorrisdotca/dougu-sports 0.3.1 → 0.4.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.
- package/CHANGELOG.md +27 -1
- package/NOTICE.md +1 -0
- package/README.md +27 -11
- package/dist/emblems/ball/ball.art.d.ts +24 -0
- package/dist/emblems/ball/ball.art.js +67 -0
- package/dist/emblems/ball/ball.core.d.ts +6 -0
- package/dist/emblems/ball/ball.core.js +12 -1
- package/dist/emblems/ball/ball.face.d.ts +54 -0
- package/dist/emblems/ball/ball.face.js +287 -0
- package/dist/emblems/ball/ball.image.d.ts +8 -0
- package/dist/emblems/ball/ball.image.js +122 -0
- package/dist/emblems/ball/ball.index.d.ts +3 -1
- package/dist/emblems/ball/ball.index.js +7 -5
- package/dist/emblems/ball/ball.letters.d.ts +32 -0
- package/dist/emblems/ball/ball.letters.js +142 -0
- package/dist/emblems/ball/ball.object.js +1 -1
- package/dist/emblems/ball/ball.puck.d.ts +8 -0
- package/dist/emblems/ball/ball.puck.js +19 -12
- package/dist/emblems/ball/ball.puck.print.d.ts +76 -0
- package/dist/emblems/ball/ball.puck.print.js +46 -0
- package/dist/emblems/ball/ball.signature.d.ts +4 -0
- package/dist/emblems/ball/ball.signature.js +58 -0
- package/dist/emblems/ball/ball.stack.d.ts +10 -0
- package/dist/emblems/ball/ball.stack.js +8 -1
- package/dist/emblems/emblem.api.d.ts +5 -5
- package/dist/emblems/emblem.api.js +27 -8
- package/dist/emblems/emblem.core.d.ts +6 -0
- package/dist/emblems/emblem.descriptions.js +8 -0
- package/dist/emblems/emblem.ids.d.ts +6 -1
- package/dist/emblems/emblem.ids.js +4 -1
- package/dist/emblems/emblem.registry.js +2 -2
- package/dist/emblems-entry.d.ts +3 -2
- package/dist/emblems-entry.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,30 @@ All notable changes to this project are written here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.4.0] - 2026-10-14
|
|
10
|
+
|
|
11
|
+
Printed pucks: eight souvenir pucks with a print on the top face that turns with the puck, and a `face` option that takes any picture, emblem or flag code. 194 emblems.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **Eight printed pucks** ([docs/pucks.md](docs/pucks.md), [日本語](docs/pucks.ja.md)), a new group `puck:*`: `puck:canada` (our own flag of the Canadian pattern with CANADA under it in wide letters, in a ring of words), `puck:canada-red` (a red face with a big white leaf), `puck:canada-white` (a white face with red bands and a red leaf), `puck:usa` (a disc of stars and stripes with USA lettered across it), `puck:usa-navy` (a navy face, a red ring between white hairlines, stars and USA), `puck:player` (a made-up surname and a big number, like a jersey), `puck:signed` (the navy puck with a made-up gold signature) and `puck:souvenir` (a generic one with ring text from the caller). Each is the same puck as `ball:puck` (76.2 by 25.4 mm), in true 3D: the print sits on the top face and turns with the puck, foreshortens as it tips, and is gone when the top is turned away; the grip shows on the rim. `ball:puck` itself stays plain.
|
|
16
|
+
- **A `face` option** on every puck (`renderEmblem`, `emblemFrame`, `ballFrame`): `design`, `image` (any SVG, made safe first), `emblem` (a dougu id), `flag` (`"ca"` and `"us"` are drawn here; any other code goes through the caller's `flags(code, { shape, size, theme })`, the shape of the renderer hata exports), `text`, `ringText`, `number`, `name`, `signature` (a seed, or `false`) and `colors`. `ball:puck` given a face is drawn as `puck:souvenir` with it. New exports: `PUCK_IDS`, the `PUCK_*` constants and the types `PuckFace`, `PuckDesign`, `FaceColors`, `FlagRenderer` and `PuckId`; `isBallId`, `ballFrame` and `lineup` take the puck ids.
|
|
17
|
+
- **Our own lettering**: a stroke alphabet (adapted from senshu-jerseys, no font file), wide, heavy and leaning a little, set on a line or on an arc for the ring, with a made-up signature drawn by a seeded pen (the same seed, the same stroke, never a real hand) and our own eleven-point maple leaf, flags and stars.
|
|
18
|
+
- **A safe image path**: an outside SVG is taken apart and put back through a strict allow-list (shapes, gradients and clip paths; no script, style, text, image, use, foreignObject, filter, link or event handler), with its ids renamed under the puck's own prefix.
|
|
19
|
+
- A "Print a puck" section in the demo, both gallery pages list the eight, and tests for the face, escaping, the signature, the safe image, the turn box and the proportions (the printed pucks are measured against the rule like the plain one).
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- The stack renderer has an `overlay` that is drawn over the grain when the top face is toward you, and the puck's drawing is shared (`puckSpec`), so the plain puck's output is unchanged.
|
|
24
|
+
|
|
25
|
+
## [0.3.2] - 2026-10-14
|
|
26
|
+
|
|
27
|
+
The README pictures fill their frames: balls first, then trophies, then gear, each a full grid.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- **README pictures are full grids.** The opening picture is now thirty-six balls and pucks in four full rows of nine, followed by one of trophies, medals and crests and one of gear (each light and dark), then a turn strip of four rows of seven and a phone shot of twelve emblems. No row is ragged and there is no empty band. They are webp (made in the browser by `pnpm screenshots`, about 60 to 400 kB each) instead of png.
|
|
32
|
+
|
|
9
33
|
## [0.3.1] - 2026-10-14
|
|
10
34
|
|
|
11
35
|
Nothing is cut off when an emblem turns: every cup and the pieces that were clipped at rest now draw inside their box at every angle.
|
|
@@ -108,7 +132,9 @@ First preview: the name, the API and two sample emblems. The full set of trophie
|
|
|
108
132
|
- Tests for the drawing, the ids, the turns and the bundle size of one item; a package check that installs the packed tarball and bundles one item from it.
|
|
109
133
|
- The demo (a playground with a turn slider, and a gallery page), `docs/layout.md`, `docs/turning.md`, `docs/gallery.md`, the family header and footer, the CI, Pages and Release workflows, and `LICENSES/` and `NOTICE.md` ready for third-party art.
|
|
110
134
|
|
|
111
|
-
[Unreleased]: https://github.com/johnmorrisdotca/dougu-sports/compare/v0.
|
|
135
|
+
[Unreleased]: https://github.com/johnmorrisdotca/dougu-sports/compare/v0.4.0...HEAD
|
|
136
|
+
[0.4.0]: https://github.com/johnmorrisdotca/dougu-sports/compare/v0.3.2...v0.4.0
|
|
137
|
+
[0.3.2]: https://github.com/johnmorrisdotca/dougu-sports/compare/v0.3.1...v0.3.2
|
|
112
138
|
[0.3.1]: https://github.com/johnmorrisdotca/dougu-sports/compare/v0.3.0...v0.3.1
|
|
113
139
|
[0.3.0]: https://github.com/johnmorrisdotca/dougu-sports/compare/v0.2.1...v0.3.0
|
|
114
140
|
[0.2.1]: https://github.com/johnmorrisdotca/dougu-sports/compare/v0.2.0...v0.2.1
|
package/NOTICE.md
CHANGED
|
@@ -8,6 +8,7 @@ No emblem carries the name, mark or logo of a league, a team, a federation or an
|
|
|
8
8
|
|
|
9
9
|
- The trophies, medals, crests, awards and sport pictograms are drawn in SVG by hand in a simplified, generic form. No real trophy, medal, logo, mark or engraving was copied or traced, and no photograph was traced (photographs were looked at, never copied).
|
|
10
10
|
- The balls (`src/emblems/ball/`) are drawn by this package's own code: a rotation, a projection and our own geometry (a seam curve, the truncated icosahedron, a layout of curved panels, a fitted basketball channel).
|
|
11
|
+
- The printed pucks (`puck:*`, `src/emblems/ball/ball.puck.print.ts`) are our own drawings: the maple leaf, the flags of the Canadian and United States patterns and the stars are drawn from simple geometry, the lettering is a stroke alphabet adapted from the block letters of the author's own senshu-jerseys (same author, same MIT licence, no font file), and the signature is made by a seeded pen, so it is no real person's. Photographs of souvenir pucks were looked at for what such a puck shows (a flag, a name, a number, a signature, a ring of words) and nothing was copied or traced. No team's or league's logo or wordmark, no maker's mark and no real player's name is used.
|
|
11
12
|
- The gear (`src/emblems/gear/`) is drawn by us from a list of parts (a path, a colour, how it reads as a line); the bow, the arrow and the other tapering shapes are made by a small function of ours (`swell`), and the rest are paths written for this package.
|
|
12
13
|
- The Japanese words for the Japanese items are the ones the sports' governing bodies use in their own rules and equipment lists (kendo, judo, kyudo and karate federations and the sumo association); the bodies' names and marks are not used in any id, title or drawing.
|
|
13
14
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<h1 align="center">Dougu Sports <sub>道具</sub></h1>
|
|
2
2
|
|
|
3
3
|
<p align="center"><strong>Sports emblems as SVG strings, with optional 3D turning.</strong><br>
|
|
4
|
-
|
|
4
|
+
The ball and the gear of every sport, trophies, medals, crests and the icon of every sport, each one a function that returns SVG: in polished metal, in one line, or in flat colour, light and dark, any size, any tint. Turn one about its axis and it is another string. Each emblem is its own module, so a page that wants one trophy takes one trophy. MIT, with no dependencies.</p>
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
7
7
|
<a href="https://github.com/johnmorrisdotca/dougu-sports/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/johnmorrisdotca/dougu-sports/actions/workflows/ci.yml/badge.svg"></a>
|
|
@@ -15,23 +15,37 @@ Trophies, medals, crests, the icon of every sport, and the ball and gear of the
|
|
|
15
15
|
|
|
16
16
|
<p align="center">
|
|
17
17
|
<picture>
|
|
18
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/
|
|
19
|
-
<img alt="
|
|
18
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/balls-desk-dark.webp">
|
|
19
|
+
<img alt="Thirty-six balls and pucks drawn in 3D, in four rows of nine: soccer balls of several constructions and colours, then basketball, the 3x3 ball, baseball, softball, a football, a rugby ball, an Australian football and two volleyballs, then tennis, padel, pickleball with its holes, squash with its two dots, racquetball, golf, red and pink cricket and water polo, then sepak takraw, a shuttlecock, a puck, a curling stone, lacrosse, handball, table tennis, a sliotar and a roundnet ball." src="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/balls-desk-light.webp" width="760">
|
|
20
|
+
</picture>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
<picture>
|
|
25
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/hero-desk-dark.webp">
|
|
26
|
+
<img alt="Trophies, medals and crests, in four rows of nine: nine famous cups, then a gilded cup, a phoenix-handle cup, a soccer ball trophy, a wreath, a rosette, a belt, a banner, a ring and a plaque, then three medals, three place badges and three crests, and last three cups each in metal, line and colour." src="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/hero-desk-light.webp" width="760">
|
|
27
|
+
</picture>
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<picture>
|
|
32
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/gear-desk-dark.webp">
|
|
33
|
+
<img alt="Thirty-six pieces of gear in four rows of nine: hockey stick and skate, a goalie mask, field hockey, lacrosse and hurling sticks, a cricket bat and wicket, a baseball bat and glove, a football helmet and goalposts, a basketball hoop, a volleyball net, rackets and paddles, a curling broom, skates, swim goggles, starting blocks, a baton, a javelin, a hurdle, and the kendo, sumo, judo, kyudo and karate gear of Japan." src="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/gear-desk-light.webp" width="760">
|
|
20
34
|
</picture>
|
|
21
35
|
</p>
|
|
22
36
|
|
|
23
37
|
<table align="center">
|
|
24
38
|
<tr>
|
|
25
39
|
<td align="center" valign="top">
|
|
26
|
-
<img alt="A two-handled cup, a
|
|
40
|
+
<img alt="A two-handled cup, a medal, a soccer ball and a championship banner each turned through seven angles: the cup keeps its outline and moves its light and handles, the medal and the banner flip like a coin to show their plain backs, and the ball rolls." src="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/turn-desk-light.webp" width="470"><br><em>Turned: a ball rolls, a medal flips</em>
|
|
27
41
|
</td>
|
|
28
42
|
<td align="center" valign="top">
|
|
29
|
-
<img alt="
|
|
43
|
+
<img alt="Cups, a medal, balls and gear on a phone, three to a row." src="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/phone-light.webp" width="200"><br><em>On a phone</em>
|
|
30
44
|
</td>
|
|
31
45
|
</tr>
|
|
32
46
|
</table>
|
|
33
47
|
|
|
34
|
-
> **Status: preview.**
|
|
48
|
+
> **Status: preview.** 194 emblems: 24 trophies, 5 awards, 6 medals, 4 crests, a pictogram for each of the 38 sports, 66 balls and implements drawn in 3D, 8 printed pucks ([docs/pucks.md](./docs/pucks.md)), 42 pieces of gear (among them the Japanese sports and budo, [docs/japanese-sports.md](./docs/japanese-sports.md)) and a championship pennant; [docs/layout.md](./docs/layout.md) says where each goes. All of it is drawn for this package: no art is copied from another project.
|
|
35
49
|
|
|
36
50
|
## In 30 seconds
|
|
37
51
|
|
|
@@ -59,6 +73,7 @@ Put the string in a page (`element.innerHTML = svg`), write it to a file, or sen
|
|
|
59
73
|
|
|
60
74
|
## Features
|
|
61
75
|
|
|
76
|
+
- **Equipment first (道具 is the word for it)**: 66 balls and implements drawn in 3D, from the 32-panel soccer ball to the 26, 18, 14, 12 and 6 panel constructions, futsal, beach soccer and the pucks and stones, each with its official size, 8 printed pucks (a flag, a leaf, stars and stripes, a player's number, a made-up signature, your own picture: [docs/pucks.md](./docs/pucks.md)), and 42 pieces of gear (sticks, rackets, helmets, skates, nets, and the Japanese budo kit) drawn to match; see [docs/gallery.md](./docs/gallery.md).
|
|
62
77
|
- **Three styles** for every emblem: `metal` (polished metal: a gradient, a highlight and a soft rim of reflected light, edged in a darker tone of its own metal, with no heavy outline), `line` (one clean outline in the page's text colour, made to read at 14 pixels) and `color` (flat fills); see [Theming](#theming).
|
|
63
78
|
- **Size, tint, accent and theme** as options: a tint recolours the main part (a medal's metal, a crest's colour, a ball's patches), an accent the second colour (a ribbon, a crest's band, the pennants), a theme sets the ink for light, dark or either.
|
|
64
79
|
- **Turning**: `emblemFrame` and `ballFrame` return the emblem at an angle, in plain SVG: every emblem turns, a ball rolls, a cup keeps its outline and moves its light, and everything flat (gear, a bat, a crown, a sport's icon) flips like a coin; `bindTurn` lets a drag, the arrow keys or an auto-turn do the turning in a page; see [docs/turning.md](./docs/turning.md).
|
|
@@ -78,8 +93,8 @@ Put the string in a page (`element.innerHTML = svg`), write it to a file, or sen
|
|
|
78
93
|
|
|
79
94
|
<table>
|
|
80
95
|
<tr>
|
|
81
|
-
<td align="center" valign="top"><img alt="
|
|
82
|
-
<td align="center" valign="top"><img alt="
|
|
96
|
+
<td align="center" valign="top"><img alt="Balls and pucks in four rows of nine." src="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/balls-desk-light.webp" width="360"><br><em>Balls and pucks, trophies, medals and gear</em></td>
|
|
97
|
+
<td align="center" valign="top"><img alt="A cup, a medal, a ball and a banner turned through seven angles." src="https://raw.githubusercontent.com/johnmorrisdotca/dougu-sports/main/docs/images/turn-desk-light.webp" width="360"><br><em>Turned through seven angles</em></td>
|
|
83
98
|
</tr>
|
|
84
99
|
</table>
|
|
85
100
|
|
|
@@ -276,7 +291,7 @@ console.log(emblemName("medal:gold", "ja")); // 金メダル
|
|
|
276
291
|
```js
|
|
277
292
|
import { EMBLEM_GROUPS, EMBLEM_IDS, SPORT_NAMES } from "@johnmorrisdotca/dougu-sports";
|
|
278
293
|
|
|
279
|
-
console.log(Object.keys(EMBLEM_GROUPS).join(" ")); // award trophy medal crest ball gear sport pennant
|
|
294
|
+
console.log(Object.keys(EMBLEM_GROUPS).join(" ")); // award trophy medal crest ball puck gear sport pennant
|
|
280
295
|
console.log(EMBLEM_IDS.includes("ball:soccer")); // true
|
|
281
296
|
console.log(SPORT_NAMES.length); // 38
|
|
282
297
|
```
|
|
@@ -393,6 +408,7 @@ An emblem is a small object: `id`, `en` and `ja` names, a `source` (who drew it)
|
|
|
393
408
|
| `medal` | Gold, silver and bronze medals on a ribbon of five stripes, and a badge for each of the first three places | `src/emblems/medal/` |
|
|
394
409
|
| `crest` | Four generic crests, tinted by a team's colours, with its letters | `src/emblems/crest/` |
|
|
395
410
|
| `ball` | 66 balls and implements, in 3D, each with its official size: soccer (in 32, 26, 18, 14, 12 and 6 panels, in three colourways, with futsal and beach soccer; [docs/soccer-balls.md](./docs/soccer-balls.md)), basketball, baseball, tennis, rugby, the footballs, golf, the puck, the curling stone and the rest | `src/emblems/ball/` |
|
|
411
|
+
| `puck` | 8 printed pucks: the same puck with a print on its top face that turns with it (a flag and CANADA, a red leaf, stars and stripes, a player's name and number, a made-up signature, a souvenir), and a `face` option for any picture, emblem or flag code; [docs/pucks.md](./docs/pucks.md) | `src/emblems/ball/ball.puck.print.ts` |
|
|
396
412
|
| `gear` | 42 pieces of equipment: sticks, rackets, skates, a glove, a helmet, nets and posts, a javelin, starting blocks, and for the Japanese sports a war fan, a sumo belt, a bamboo sword, a kendo helmet, a judo suit, a belt, a long bow, an arrow and a karate suit | `src/emblems/gear/` |
|
|
397
413
|
| `sport` | One pictogram for each of the thirty-eight sports | `src/emblems/sport/` |
|
|
398
414
|
| `pennant` | A felt championship pennant on a dowel, with a stitched edge, lettered with its words and its year | `src/emblems/pennant/` |
|
|
@@ -426,7 +442,7 @@ The thirty-eight sports the ball, gear and sport emblems are made for are `SPORT
|
|
|
426
442
|
| `EMBLEM_TABLE` | Every emblem object, by id |
|
|
427
443
|
| `TROPHY_HOCKEY_CUP`, `MEDAL_GOLD`, `CREST_SHIELD`, `SPORT_NHL`, `BALL_SOCCER`, `GEAR_HURLEY`... | Each emblem as a constant, named by its id in capitals (`trophy:hockey-cup`); [docs/gallery.md](./docs/gallery.md) ([日本語](./docs/gallery.ja.md)) lists every emblem and states the rule for its constant and the module that takes it alone |
|
|
428
444
|
| `EMBLEM_IDS`, `EMBLEM_GROUPS`, `EMBLEM_FOLDERS`, `EMBLEM_ALIASES` | Every id, the groups, the folder of each group's art, and the short names (`cup` for `trophy:cup`) |
|
|
429
|
-
| `AWARD_IDS`, `TROPHY_IDS`, `MEDAL_IDS`, `CREST_IDS`, `BALL_IDS`, `GEAR_IDS`, `SPORT_IDS`, `PENNANT_IDS` | The ids of each group |
|
|
445
|
+
| `AWARD_IDS`, `TROPHY_IDS`, `MEDAL_IDS`, `CREST_IDS`, `BALL_IDS`, `PUCK_IDS`, `GEAR_IDS`, `SPORT_IDS`, `PENNANT_IDS` | The ids of each group |
|
|
430
446
|
| `MEDAL_KINDS`, `CREST_SHAPES` | The kinds of medal, and the shapes of crest |
|
|
431
447
|
| `SPORT_NAMES` | The thirty-eight sports |
|
|
432
448
|
| `JAPANESE_IDS` | The ids of the Japanese sports and budo, together: sumo, kendo, judo, kyudo and karate, with their trophies and gear ([docs/japanese-sports.md](./docs/japanese-sports.md)) |
|
|
@@ -577,7 +593,7 @@ Bug reports and ideas go in the [issues](https://github.com/johnmorrisdotca/doug
|
|
|
577
593
|
|
|
578
594
|
## Changes
|
|
579
595
|
|
|
580
|
-
See [CHANGELOG.md](./CHANGELOG.md). 0.3.0 adds nineteen soccer balls (26, 18, 14, 12 and 6 panels, winter orange and high-visibility yellow, futsal and beach soccer: 186 emblems); 0.2.1 draws every ball and implement to the rulebook's proportions; 0.2.0 is 167 emblems, every one drawn here, with the Japanese sports, engraving, a turn for every emblem and the compose helpers; 0.1.0 brought the first full set of 148; 0.0.1 was the first preview.
|
|
596
|
+
See [CHANGELOG.md](./CHANGELOG.md). 0.4.0 adds eight printed pucks and a `face` option (194 emblems: [docs/pucks.md](./docs/pucks.md)); 0.3.0 adds nineteen soccer balls (26, 18, 14, 12 and 6 panels, winter orange and high-visibility yellow, futsal and beach soccer: 186 emblems); 0.2.1 draws every ball and implement to the rulebook's proportions; 0.2.0 is 167 emblems, every one drawn here, with the Japanese sports, engraving, a turn for every emblem and the compose helpers; 0.1.0 brought the first full set of 148; 0.0.1 was the first preview.
|
|
581
597
|
|
|
582
598
|
## Credits
|
|
583
599
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A maple leaf with a stem, as a path about the origin: the blade spans -1 to 1 across and from -1 down to about 0.6, the stem to 1. */
|
|
2
|
+
export declare const LEAF_PATH: string;
|
|
3
|
+
/** A maple leaf: centre (`cx`, `cy`), the width of the blade `w`, and a fill. */
|
|
4
|
+
export declare function leaf(cx: number, cy: number, w: number, fill: string): string;
|
|
5
|
+
/** A five-point star, as a polygon's points, with the given outer radius, centred on (`cx`, `cy`), pointing up (turned by `deg`). */
|
|
6
|
+
export declare function starPoints(cx: number, cy: number, r: number, deg?: number): string;
|
|
7
|
+
export declare const star: (cx: number, cy: number, r: number, fill: string, deg?: number) => string;
|
|
8
|
+
/** The colours of the two flags: a red and a white, a navy and a red. Plain values of the flags' colours; the caller may replace them. */
|
|
9
|
+
export declare const FLAG: {
|
|
10
|
+
readonly red: "#d52b1e";
|
|
11
|
+
readonly white: "#ffffff";
|
|
12
|
+
readonly navy: "#0a3161";
|
|
13
|
+
readonly usRed: "#b31942";
|
|
14
|
+
};
|
|
15
|
+
/** A flag of Canada's pattern, 2 wide and 1 tall about the origin scaled to the width `w`: red, white, red, with the leaf on the white. */
|
|
16
|
+
export declare function canadaFlag(cx: number, cy: number, w: number, red?: "#d52b1e", white?: "#ffffff"): string;
|
|
17
|
+
/**
|
|
18
|
+
* The stars and stripes as a rectangle about the origin, `w` wide and `h` tall: thirteen stripes across, a canton of stars in the upper left (`canton` wide, seven stripes tall), and the stars in staggered rows, four
|
|
19
|
+
* and three to a row, which is what reads at a puck's size (the flag has fifty, in nine rows). A star whose centre lies farther than `reach` from the origin is left out, so a disc cut from the field has no
|
|
20
|
+
* half stars at its edge.
|
|
21
|
+
*/
|
|
22
|
+
export declare function starsAndStripes(w: number, h: number, canton: number, reach?: number, red?: string, white?: string, blue?: string): string;
|
|
23
|
+
/** A flag of the United States' pattern, 2 wide about the origin scaled to the width `w` (it is 1.9 to 1): stripes and a canton of stars. */
|
|
24
|
+
export declare function usaFlag(cx: number, cy: number, w: number): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// The small drawings a printed puck is made of, all our own: an eleven-point maple leaf, a five-point star, a Canadian-style flag (red, white, red, with that leaf) and the stars and stripes. Each is a string of SVG in
|
|
2
|
+
// a unit box (the leaf's blade is 2 wide and 2 tall about the origin) that the face scales and places; the flags take the width they are drawn at. Imports only the core's number writer.
|
|
3
|
+
import { num } from "./ball.core.js";
|
|
4
|
+
/** The right half of the leaf, from the top tip down to the stem: eleven points in all with the left half mirrored (a tip, then a notch, five times over). y runs down. */
|
|
5
|
+
const LEAF_HALF = [
|
|
6
|
+
[0, -1], [0.15, -0.6], [0.36, -0.7], [0.33, -0.36], [0.67, -0.5], [0.55, -0.2], [1, -0.12], [0.74, 0.12], [0.86, 0.36], [0.4, 0.3], [0.42, 0.56], [0.06, 0.42],
|
|
7
|
+
];
|
|
8
|
+
/** A maple leaf with a stem, as a path about the origin: the blade spans -1 to 1 across and from -1 down to about 0.6, the stem to 1. */
|
|
9
|
+
export const LEAF_PATH = (() => {
|
|
10
|
+
const right = LEAF_HALF.slice(1);
|
|
11
|
+
const left = [...LEAF_HALF.slice(1)].reverse().map(([x, y]) => [-x, y]);
|
|
12
|
+
const pts = [LEAF_HALF[0], ...right, [0.06, 0.92], [-0.06, 0.92], ...left];
|
|
13
|
+
return `M${pts.map(([x, y]) => `${num(x, 3)} ${num(y, 3)}`).join("L")}Z`;
|
|
14
|
+
})();
|
|
15
|
+
/** A maple leaf: centre (`cx`, `cy`), the width of the blade `w`, and a fill. */
|
|
16
|
+
export function leaf(cx, cy, w, fill) {
|
|
17
|
+
const k = w / 2;
|
|
18
|
+
return `<path d="${LEAF_PATH}" transform="translate(${num(cx, 3)} ${num(cy, 3)}) scale(${num(k, 4)})" fill="${fill}"/>`;
|
|
19
|
+
}
|
|
20
|
+
/** A five-point star, as a polygon's points, with the given outer radius, centred on (`cx`, `cy`), pointing up (turned by `deg`). */
|
|
21
|
+
export function starPoints(cx, cy, r, deg = 0) {
|
|
22
|
+
const pts = [];
|
|
23
|
+
for (let i = 0; i < 10; i++) {
|
|
24
|
+
const a = ((deg + i * 36) * Math.PI) / 180;
|
|
25
|
+
const rr = i % 2 === 0 ? r : r * 0.382;
|
|
26
|
+
pts.push(`${num(cx + rr * Math.sin(a), 3)} ${num(cy - rr * Math.cos(a), 3)}`);
|
|
27
|
+
}
|
|
28
|
+
return pts.join(" ");
|
|
29
|
+
}
|
|
30
|
+
export const star = (cx, cy, r, fill, deg = 0) => `<polygon points="${starPoints(cx, cy, r, deg)}" fill="${fill}"/>`;
|
|
31
|
+
/** The colours of the two flags: a red and a white, a navy and a red. Plain values of the flags' colours; the caller may replace them. */
|
|
32
|
+
export const FLAG = { red: "#d52b1e", white: "#ffffff", navy: "#0a3161", usRed: "#b31942" };
|
|
33
|
+
/** A flag of Canada's pattern, 2 wide and 1 tall about the origin scaled to the width `w`: red, white, red, with the leaf on the white. */
|
|
34
|
+
export function canadaFlag(cx, cy, w, red = FLAG.red, white = FLAG.white) {
|
|
35
|
+
const k = w / 2;
|
|
36
|
+
const t = `translate(${num(cx, 3)} ${num(cy, 3)}) scale(${num(k, 4)})`;
|
|
37
|
+
return `<g transform="${t}"><rect x="-1" y="-.5" width="2" height="1" fill="${white}"/><rect x="-1" y="-.5" width=".5" height="1" fill="${red}"/><rect x=".5" y="-.5" width=".5" height="1" fill="${red}"/><path d="${LEAF_PATH}" transform="translate(0 -.03) scale(.3)" fill="${red}"/></g>`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The stars and stripes as a rectangle about the origin, `w` wide and `h` tall: thirteen stripes across, a canton of stars in the upper left (`canton` wide, seven stripes tall), and the stars in staggered rows, four
|
|
41
|
+
* and three to a row, which is what reads at a puck's size (the flag has fifty, in nine rows). A star whose centre lies farther than `reach` from the origin is left out, so a disc cut from the field has no
|
|
42
|
+
* half stars at its edge.
|
|
43
|
+
*/
|
|
44
|
+
export function starsAndStripes(w, h, canton, reach = Infinity, red = FLAG.usRed, white = FLAG.white, blue = FLAG.navy) {
|
|
45
|
+
const x0 = -w / 2, y0 = -h / 2, sh = h / 13;
|
|
46
|
+
let out = `<rect x="${num(x0, 3)}" y="${num(y0, 3)}" width="${num(w, 3)}" height="${num(h, 3)}" fill="${white}"/>`;
|
|
47
|
+
for (let i = 0; i < 13; i += 2)
|
|
48
|
+
out += `<rect x="${num(x0, 3)}" y="${num(y0 + i * sh, 3)}" width="${num(w, 3)}" height="${num(sh, 3)}" fill="${red}"/>`;
|
|
49
|
+
const ch = sh * 7;
|
|
50
|
+
out += `<rect x="${num(x0, 3)}" y="${num(y0, 3)}" width="${num(canton, 3)}" height="${num(ch, 3)}" fill="${blue}"/>`;
|
|
51
|
+
const r = Math.min(canton / 9.5, ch / 15);
|
|
52
|
+
for (let row = 0; row < 7; row++) {
|
|
53
|
+
const n = row % 2 === 0 ? 4 : 3;
|
|
54
|
+
for (let c = 0; c < n; c++) {
|
|
55
|
+
const x = x0 + canton * ((row % 2 === 0 ? c + 0.5 : c + 1) / 4);
|
|
56
|
+
const y = y0 + ch * ((row + 0.5) / 7);
|
|
57
|
+
if (Math.hypot(x, y) <= reach)
|
|
58
|
+
out += star(x, y, r, white);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** A flag of the United States' pattern, 2 wide about the origin scaled to the width `w` (it is 1.9 to 1): stripes and a canton of stars. */
|
|
64
|
+
export function usaFlag(cx, cy, w) {
|
|
65
|
+
const k = w / 2;
|
|
66
|
+
return `<g transform="translate(${num(cx, 3)} ${num(cy, 3)}) scale(${num(k, 4)})">${starsAndStripes(2, 2 / 1.9, 0.8)}</g>`;
|
|
67
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PuckFace } from "./ball.face.ts";
|
|
1
2
|
/** `metal` (also written `colour`): full colour, with shading. `line`: one outline in `currentColor`. */
|
|
2
3
|
export type PieceStyle = "metal" | "colour" | "color" | "line";
|
|
3
4
|
/** `inherit` (the default): the page's text colour. `auto`: dark ink on a light device and pale ink on a dark one. `light` and `dark` force one. */
|
|
@@ -18,6 +19,8 @@ export interface PieceOptions {
|
|
|
18
19
|
locale?: "en" | "ja";
|
|
19
20
|
/** A string is the `<title>` (escaped); `false` drops it and marks the drawing `aria-hidden="true"`. */
|
|
20
21
|
title?: string | false;
|
|
22
|
+
/** A puck: the print on its top face (see `PuckFace`). The printed pucks (`puck:*`) take it, and so does `ball:puck` through `renderEmblem`, `emblemFrame` and `ballFrame`. Anything else ignores it. */
|
|
23
|
+
face?: PuckFace;
|
|
21
24
|
}
|
|
22
25
|
/** A turn: `yaw` degrees about the vertical axis (0 is the default view), `pitch` the tilt toward you, `roll` the turn about the line of sight. */
|
|
23
26
|
export interface BallFrameOptions extends PieceOptions {
|
|
@@ -85,6 +88,9 @@ export interface ResolvedOptions {
|
|
|
85
88
|
tint: string | undefined;
|
|
86
89
|
accent: string | undefined;
|
|
87
90
|
grain: boolean | undefined;
|
|
91
|
+
face: PuckFace | undefined;
|
|
92
|
+
/** A string that tells two faces apart, for the ids of a drawing. */
|
|
93
|
+
faceKey: string;
|
|
88
94
|
}
|
|
89
95
|
export declare function resolveOptions(o: PieceOptions | undefined): ResolvedOptions;
|
|
90
96
|
/** The ink of a drawing when a theme sets it, and the page it is made to read on. */
|
|
@@ -42,12 +42,23 @@ export function hashOf(text) {
|
|
|
42
42
|
h = Math.imul(h ^ text.charCodeAt(i), 16777619);
|
|
43
43
|
return (h >>> 0).toString(36);
|
|
44
44
|
}
|
|
45
|
+
/** What tells one face from another: its plain data (a renderer is a function, and only its name goes in). */
|
|
46
|
+
function faceKeyOf(face) {
|
|
47
|
+
if (typeof face !== "object" || face === null)
|
|
48
|
+
return "";
|
|
49
|
+
try {
|
|
50
|
+
return JSON.stringify(face, (k, v) => (typeof v === "function" ? `fn:${v.name}` : v)) ?? "";
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return "?";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
45
56
|
export function resolveOptions(o) {
|
|
46
57
|
const size = typeof o?.size === "number" && Number.isFinite(o.size) && o.size > 0 ? Math.min(Math.round(o.size * 100) / 100, 4096) : 64;
|
|
47
58
|
const theme = o?.theme === "auto" || o?.theme === "light" || o?.theme === "dark" ? o.theme : "inherit";
|
|
48
59
|
const tint = readColour(o?.tint);
|
|
49
60
|
const accent = readColour(o?.accent);
|
|
50
|
-
return { style: o?.style === "line" ? "line" : "colour", size, theme, tint: tint === undefined ? undefined : hexOf(tint), accent: accent === undefined ? undefined : hexOf(accent), grain: typeof o?.grain === "boolean" ? o.grain : undefined };
|
|
61
|
+
return { style: o?.style === "line" ? "line" : "colour", size, theme, tint: tint === undefined ? undefined : hexOf(tint), accent: accent === undefined ? undefined : hexOf(accent), grain: typeof o?.grain === "boolean" ? o.grain : undefined, face: typeof o?.face === "object" && o.face !== null ? o.face : undefined, faceKey: faceKeyOf(o?.face) };
|
|
51
62
|
}
|
|
52
63
|
/** The ink of a drawing when a theme sets it, and the page it is made to read on. */
|
|
53
64
|
export const PIECE_INK = { light: "#20262d", dark: "#eef1f3" };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** The designs a face starts from. */
|
|
2
|
+
export type PuckDesign = "canada" | "canada-red" | "canada-white" | "usa" | "usa-navy" | "player" | "souvenir";
|
|
3
|
+
/** What the renderer a caller supplies for a flag is asked: the code, the shape (`"4:3"`, `"1:1"` or `"round"`, the shapes hata draws), a size in pixels and the theme. It returns an SVG document. */
|
|
4
|
+
export type FlagRenderer = (code: string, options: {
|
|
5
|
+
shape: "4:3" | "1:1" | "round";
|
|
6
|
+
size: number;
|
|
7
|
+
theme: "light" | "dark" | "auto" | "inherit";
|
|
8
|
+
}) => string;
|
|
9
|
+
/** The colours of a face, by name. The array form is the same list in this order: field, ring, ink, accent, signature. */
|
|
10
|
+
export interface FaceColors {
|
|
11
|
+
/** The disc's own colour. */
|
|
12
|
+
field?: string;
|
|
13
|
+
/** The ring round the edge, where the face has one. */
|
|
14
|
+
ring?: string;
|
|
15
|
+
/** The lettering on the ring, and the main lettering on a dark face. */
|
|
16
|
+
ink?: string;
|
|
17
|
+
/** The second colour: the leaf, a number's fill, the stars. */
|
|
18
|
+
accent?: string;
|
|
19
|
+
/** The marker of a signature. */
|
|
20
|
+
signature?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The print on a puck's top face. Everything is optional, and what is not given comes from the design (the puck's own id says which, or `design`). Text is cleaned (no control characters, 24 letters a line) and
|
|
24
|
+
* drawn in our own vector lettering, so any letter, digit or `- . , ' / : &` is available and any other character is left out.
|
|
25
|
+
*/
|
|
26
|
+
export interface PuckFace {
|
|
27
|
+
/** The design to start from. A puck with an id of its own already has one; `puck:souvenir` and `ball:puck` take it from here. */
|
|
28
|
+
design?: PuckDesign;
|
|
29
|
+
/** Any SVG: a logo, a crest, a drawing. Made safe first (see `safeImage`): shapes, gradients and clip paths only. It is fitted into the middle of the face and replaces the design's own picture. */
|
|
30
|
+
image?: string;
|
|
31
|
+
/** A country code (`"ca"` and `"us"` are drawn by this package; another needs `flags`). It replaces the design's own picture. */
|
|
32
|
+
flag?: string;
|
|
33
|
+
/** A renderer for the flag codes this package does not draw: `(code, { shape, size, theme }) => svg`, the shape of the function hata exports. */
|
|
34
|
+
flags?: FlagRenderer;
|
|
35
|
+
/** The id of a dougu emblem (`"trophy:cup"`, `"sport:nhl"`), drawn small in the middle. Resolved by `renderEmblem`, `emblemFrame` and `ballFrame`. */
|
|
36
|
+
emblem?: string;
|
|
37
|
+
/** The words under the picture (`"CANADA"`), one line. */
|
|
38
|
+
text?: string;
|
|
39
|
+
/** The words round the edge. A string is set on the top; a pair is the top and the bottom; `false` leaves the ring out. */
|
|
40
|
+
ringText?: string | readonly [string, string] | false;
|
|
41
|
+
/** A big number, like a jersey's. Up to three characters. */
|
|
42
|
+
number?: string | number;
|
|
43
|
+
/** A surname, set on the ring like a jersey's name. */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** A seed for a made-up signature, or `false` for none. A number or any text; the same seed always draws the same squiggle, and no seed is a real person's hand. */
|
|
46
|
+
signature?: number | string | false;
|
|
47
|
+
/** The colours: by name, or as an array in the order field, ring, ink, accent, signature. A colour is `#rgb`, `#rrggbb` or `rgb()`; anything else is ignored. */
|
|
48
|
+
colors?: FaceColors | readonly (string | undefined)[];
|
|
49
|
+
}
|
|
50
|
+
/** The face of a design, in the face's units (a disc of radius 1, up is up): its definitions and its drawing. `prefix` makes every id unique to this puck. */
|
|
51
|
+
export declare function faceMarkup(face: PuckFace | undefined, design: PuckDesign, own: PuckFace | undefined, prefix: string): {
|
|
52
|
+
defs: string;
|
|
53
|
+
body: string;
|
|
54
|
+
};
|