@arraypress/effects-astro 0.6.1 → 0.8.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/AGENTS.md +2 -0
- package/COMPONENTS.md +33 -0
- package/README.md +2 -2
- package/package.json +6 -2
- package/src/components/EffectCanvas.astro +4 -1
- package/src/components/PixelFountain.astro +70 -0
- package/src/index.d.ts +4 -1
- package/src/index.js +3 -1
- package/src/runtime/budget.d.ts +8 -0
- package/src/runtime/budget.js +49 -0
- package/src/runtime/export/clean-svg.d.ts +21 -0
- package/src/runtime/export/clean-svg.js +368 -0
- package/src/runtime/export/clock.d.ts +25 -0
- package/src/runtime/export/clock.js +122 -0
- package/src/runtime/export/fetch.d.ts +14 -0
- package/src/runtime/export/fetch.js +121 -0
- package/src/runtime/export/fonts.d.ts +30 -0
- package/src/runtime/export/fonts.js +202 -0
- package/src/runtime/export/format.d.ts +11 -0
- package/src/runtime/export/format.js +42 -0
- package/src/runtime/export/probe.d.ts +16 -0
- package/src/runtime/export/probe.js +89 -0
- package/src/runtime/export/raster.d.ts +17 -0
- package/src/runtime/export/raster.js +91 -0
- package/src/runtime/export/save.d.ts +5 -0
- package/src/runtime/export/save.js +41 -0
- package/src/runtime/export/snapshot.d.ts +43 -0
- package/src/runtime/export/snapshot.js +276 -0
- package/src/runtime/export/styles.d.ts +18 -0
- package/src/runtime/export/styles.js +152 -0
- package/src/runtime/export/svg-attrs.d.ts +8 -0
- package/src/runtime/export/svg-attrs.js +274 -0
- package/src/runtime/export/svg-text.d.ts +21 -0
- package/src/runtime/export/svg-text.js +124 -0
- package/src/runtime/export/video.d.ts +45 -0
- package/src/runtime/export/video.js +106 -0
- package/src/runtime/pixel-fountain.d.ts +134 -0
- package/src/runtime/pixel-fountain.js +730 -0
- package/src/runtime/pixel-glitch.js +2 -24
- package/src/runtime/text.d.ts +6 -0
- package/src/runtime/text.js +57 -1
package/AGENTS.md
CHANGED
|
@@ -34,6 +34,7 @@ Pick by what is asked for:
|
|
|
34
34
|
| A light or texture over a background (a spotlight, film grain) | `<GlowField>`, `<Grain>` (`still` for either to hold) |
|
|
35
35
|
| The brand's logo as the hero's centrepiece | `<GlassGlyph>`, `<LiquidMetal>` (liquid chrome you can poke and splash; `tint="gold"`…), `<ParticleLogo>`, `<NeonSwarm>` (a flowing neon swarm), `<NebulaLogo>` (filled with nebula gas), `<VoxelLogo>`, `<PointCloud>`, all with `src="/logo.svg"` or `text` |
|
|
36
36
|
| A footer wordmark | `<SpotlightText fit>`, `<PixelGlitchText fit>`, `<OutlineWordmark>` |
|
|
37
|
+
| Something retro or 8-bit on a footer: pixels firing out of it, sparks, "insert coin" | `<PixelFountain>` inside the footer (its top edge must not clip: `overflow-x: clip`, not `overflow: hidden`); `source="text"` sheds pixels from a wordmark; `color` or `colors` for the ramp |
|
|
37
38
|
| Sections that arrive on scroll, site-wide | `<ScrollReveal />` once in the layout, then reveal.css classes (`fade-in-up`…) on elements |
|
|
38
39
|
| A type foundry or bold brand headline: big variable-font letters that swell under the pointer | `<VariableType as="h1" fit>` set in a variable font (`axes` for which axes swell) |
|
|
39
40
|
| Text that arrives or moves | `<Reveal>`, `<ScrambleText>`, `<Typewriter>`, `<HighlightSweep>`, `<Marquee>` |
|
|
@@ -58,6 +59,7 @@ Things that trip people up:
|
|
|
58
59
|
- **Audio from another origin** needs CORS to be followed: `crossorigin="anonymous"` on the element (WaveformPlayer: `data-cross-origin="anonymous"`) and `Access-Control-Allow-Origin` on the server. Without it the effect keeps its own motion.
|
|
59
60
|
- **`<Glass refract>` bends only in Chromium.** Safari and Firefox show the frosted glass instead; do not sniff browsers around it. It needs something detailed behind it (type, a photo) for the bending to show, and its bezel should be well under half the panel's shorter side.
|
|
60
61
|
- **Clicks:** effects that react to clicks ignore links, buttons and form fields. Add `data-effect-ignore` to anything else whose clicks are its own.
|
|
62
|
+
- **`<PixelFountain>` draws above its host's top edge**, so a host with `overflow: hidden` clips it away. Use `overflow-x: clip` on the host, or put the fountain in a zero-height positioned strip on the edge and name the host with `host="…"`.
|
|
61
63
|
- **`<SpotlightText fill="dodge">`** blends with what is behind it: no stacking context may sit between them (no `z-index` on a positioned ancestor, no `opacity`, `transform`, `filter` or `isolation`). Use `fill="solid"` where that cannot be arranged.
|
|
62
64
|
- **Styling a component's element** from the page needs `:global(.its-class)`, since the element belongs to the component.
|
|
63
65
|
- **`<Scene>` takes a palette by name** (`palette="Barbie"`); `@logomarks/shaders` itself takes the palette object (`PALETTES.Barbie`), never the name. Its `lazy` is the scene's own (a context held near the screen, given back four seconds after leaving on a fresh canvas), not `mount()`'s.
|
package/COMPONENTS.md
CHANGED
|
@@ -847,6 +847,39 @@ ParticleLogo: a logo or a word in thousands of twinkling particles that scatter
|
|
|
847
847
|
| `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
|
|
848
848
|
| `class` | `string` | Classes for the element. |
|
|
849
849
|
|
|
850
|
+
## `<PixelFountain>`
|
|
851
|
+
|
|
852
|
+
PixelFountain: retro 8-bit sparks. Chunky square pixels fire up out of the host's top edge (a footer) or, with `source="text"`, out of the letters of its wordmark, arc under gravity and break down as they go: through a short ramp of colours, shrinking in whole-pixel steps or splitting into pieces that scatter, some flickering out like a dying CRT pixel. A few trickle up on their own; the pointer moving over the host fires a stream, a click or tap a power-up. See src/runtime/pixel-fountain.js.
|
|
853
|
+
|
|
854
|
+
```astro
|
|
855
|
+
<footer class="site-footer" style="position: relative">
|
|
856
|
+
<PixelFountain cell={8} />
|
|
857
|
+
…
|
|
858
|
+
</footer>
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
| Prop | Type | |
|
|
862
|
+
|---|---|---|
|
|
863
|
+
| `color` | `string` | The pixels' colour when they fire; the darker steps they fade through are made from it. Default `#c8ff00`. |
|
|
864
|
+
| `colors` | `string[]` | The steps a pixel fades through, first to last (overrides `color`). Default made from `color`. |
|
|
865
|
+
| `palette` | `string` | A shared palette by name, its colours as the steps, when there are no `colors`. Default none. |
|
|
866
|
+
| `cell` | `number` | A pixel's size, CSS px (a power-up's biggest blocks are two). Default 8. |
|
|
867
|
+
| `rise` | `number` | How far above the edge the pixels can fly, CSS px. Default 240. |
|
|
868
|
+
| `rate` | `number` | Pixels a second trickling up on their own, per 1,000 CSS px of edge; 0 for none. Default 14. |
|
|
869
|
+
| `burst` | `number` | Pixels a click or tap fires. Default 40. |
|
|
870
|
+
| `gravity` | `number` | How hard they are pulled back, 0–2. Default 1. |
|
|
871
|
+
| `spread` | `number` | How widely they fan out, 0–1. Default 0.5. |
|
|
872
|
+
| `drift` | `number` | How much a wind pushes them sideways, 0–1. Default 0.3. |
|
|
873
|
+
| `life` | `number` | The longest a pixel lives, seconds. Default 1.4. |
|
|
874
|
+
| `split` | `number` | The chance a pixel splits into smaller ones rather than shrinking, 0–1. Default 0.4. |
|
|
875
|
+
| `flicker` | `number` | The chance a pixel flickers out on and off before it goes, 0–1. Default 0.35. |
|
|
876
|
+
| `source` | `'edge' \| 'text'` | Fire from the host's top edge, or from the filled pixels of its text. Default `edge`. |
|
|
877
|
+
| `host` | `string` | A selector for the element the pixels fire from and the pointer is followed over: the nearest ancestor that matches, else the first on the page. Default the element's positioned parent. |
|
|
878
|
+
| `seed` | `number` | Seeds the randomness. Default 1. |
|
|
879
|
+
| `zIndex` | `number` | The canvas's `z-index`, over what is above the host. Default none (auto). |
|
|
880
|
+
| `lazy` | `boolean \| string` | Run only while near the screen (true, or how near as a CSS length; default `200px`). Default false. |
|
|
881
|
+
| `class` | `string` | Classes for the element. |
|
|
882
|
+
|
|
850
883
|
## `<PixelGlitchText>`
|
|
851
884
|
|
|
852
885
|
PixelGlitchText: one line of text that breaks into pixels under the pointer and knits back together behind it. With `stroke`, a hollow outline at rest that the pixels fill in; `tear="row"` tears whole rows, and `ghost` lays a coloured copy behind the blocks. See src/runtime/pixel-glitch.js.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @arraypress/effects-astro
|
|
2
2
|
|
|
3
|
-
Effects for Astro sites, as components: shader backgrounds, a real fluid, logos made of glass, particles or cubes, text that glitches, scrambles or types itself, glass panels and marquees. Plain WebGL, Canvas and CSS with no third-party dependencies, and the fallbacks a theme needs built in.
|
|
3
|
+
Effects for Astro sites, as components: shader backgrounds, a real fluid, logos made of glass, particles or cubes, text that glitches, scrambles or types itself, retro pixels firing out of a footer, glass panels and marquees. Plain WebGL, Canvas and CSS with no third-party dependencies, and the fallbacks a theme needs built in.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ import LightField from '@arraypress/effects-astro/LightField.astro';
|
|
|
26
26
|
- [What every effect does for you](https://github.com/arraypress/effects-astro/blob/main/docs/guarantees.md): runs only when seen, reduced motion, fallbacks
|
|
27
27
|
- [Your own logo](https://github.com/arraypress/effects-astro/blob/main/docs/logos.md)
|
|
28
28
|
- [Palettes and colours](https://github.com/arraypress/effects-astro/blob/main/docs/colours.md)
|
|
29
|
-
- [Runtime](https://github.com/arraypress/effects-astro/blob/main/docs/runtime.md): the effects without Astro
|
|
29
|
+
- [Runtime](https://github.com/arraypress/effects-astro/blob/main/docs/runtime.md): the effects without Astro, and an element saved as a PNG, SVG or video
|
|
30
30
|
- [Credits](https://github.com/arraypress/effects-astro/blob/main/docs/credits.md)
|
|
31
31
|
|
|
32
32
|
## Links
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arraypress/effects-astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "GPU effects for Astro sites, as components: liquid light with a real fluid under it, ink in water, and outline text a spotlight fills. Plain WebGL, no third-party dependencies, with the fallbacks a theme needs (reduced motion, no WebGL, touch screens, off-screen pausing).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -47,11 +47,15 @@
|
|
|
47
47
|
"@logomarks/shaders": "^0.1.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"astro": "^6 || ^7"
|
|
50
|
+
"astro": "^6 || ^7",
|
|
51
|
+
"mediabunny": "^1.62.1"
|
|
51
52
|
},
|
|
52
53
|
"peerDependenciesMeta": {
|
|
53
54
|
"astro": {
|
|
54
55
|
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"mediabunny": {
|
|
58
|
+
"optional": true
|
|
55
59
|
}
|
|
56
60
|
},
|
|
57
61
|
"repository": {
|
|
@@ -36,14 +36,17 @@ interface Props {
|
|
|
36
36
|
lazy?: boolean | string;
|
|
37
37
|
/** Fade the canvas in once it starts, over the `background`. Default false. */
|
|
38
38
|
fadeIn?: boolean;
|
|
39
|
+
/** More inline style for the element (a component's own custom properties, a z-index). */
|
|
40
|
+
style?: string;
|
|
39
41
|
class?: string;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
const { name, config, fixed = false, behind = false, background, pixelated = false, fade = false, opacity, blend, lazy = false, fadeIn = false, class: className } = Astro.props;
|
|
44
|
+
const { name, config, fixed = false, behind = false, background, pixelated = false, fade = false, opacity, blend, lazy = false, fadeIn = false, style: extra, class: className } = Astro.props;
|
|
43
45
|
const style = [
|
|
44
46
|
background && `background: ${background}`,
|
|
45
47
|
opacity !== undefined && opacity < 1 && `opacity: ${opacity}`,
|
|
46
48
|
blend && blend !== 'normal' && `mix-blend-mode: ${blend}`,
|
|
49
|
+
extra?.trim().replace(/;$/, ''),
|
|
47
50
|
]
|
|
48
51
|
.filter(Boolean)
|
|
49
52
|
.join('; ');
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* PixelFountain: retro 8-bit sparks. Chunky square pixels fire up out of
|
|
4
|
+
* the host's top edge (a footer) or, with `source="text"`, out of the
|
|
5
|
+
* letters of its wordmark, arc under gravity and break down as they go:
|
|
6
|
+
* through a short ramp of colours, shrinking in whole-pixel steps or
|
|
7
|
+
* splitting into pieces that scatter, some flickering out like a dying CRT
|
|
8
|
+
* pixel. A few trickle up on their own; the pointer moving over the host
|
|
9
|
+
* fires a stream, a click or tap a power-up. See
|
|
10
|
+
* src/runtime/pixel-fountain.js.
|
|
11
|
+
*
|
|
12
|
+
* Put it inside the host (its nearest positioned ancestor): the canvas sits
|
|
13
|
+
* above the host's top edge, `rise` px tall (over the host and above it
|
|
14
|
+
* with `source="text"`), so the host must not clip its top (no
|
|
15
|
+
* `overflow: hidden`; `overflow-x: clip` is fine). Or put it in a
|
|
16
|
+
* zero-height positioned strip on the host's top edge and name the host
|
|
17
|
+
* with `host`. The canvas takes no pointer events; the host's are read.
|
|
18
|
+
* With reduced motion, a still scatter of pixels.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <footer class="site-footer" style="position: relative">
|
|
22
|
+
* <PixelFountain cell={8} />
|
|
23
|
+
* …
|
|
24
|
+
* </footer>
|
|
25
|
+
*/
|
|
26
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
27
|
+
import type { PixelFountainConfig } from '../runtime/pixel-fountain.js';
|
|
28
|
+
|
|
29
|
+
interface Props extends PixelFountainConfig {
|
|
30
|
+
/** The canvas's `z-index`, over what is above the host. Default none (auto). */
|
|
31
|
+
zIndex?: number;
|
|
32
|
+
/** Run only while near the screen (true, or how near as a CSS length; default `200px`). Default false. */
|
|
33
|
+
lazy?: boolean | string;
|
|
34
|
+
class?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { zIndex, lazy = false, class: className, ...config } = Astro.props;
|
|
38
|
+
const rise = config.rise ?? 240;
|
|
39
|
+
const text = config.source === 'text';
|
|
40
|
+
const classes = ['effect-pixel-fountain', text && 'is-text', className].filter(Boolean).join(' ');
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
<EffectCanvas
|
|
44
|
+
name="pixel-fountain"
|
|
45
|
+
config={config}
|
|
46
|
+
lazy={lazy}
|
|
47
|
+
pixelated
|
|
48
|
+
class={classes}
|
|
49
|
+
style={[`--fountain-rise: ${rise}px`, zIndex !== undefined && `z-index: ${zIndex}`].filter(Boolean).join('; ')}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
<script>
|
|
53
|
+
import { mount } from '../runtime/mount.js';
|
|
54
|
+
import { pixelFountain } from '../runtime/pixel-fountain.js';
|
|
55
|
+
|
|
56
|
+
mount('[data-effect-pixel-fountain]', pixelFountain);
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<style>
|
|
60
|
+
/* Above the host's top edge: the canvas's bottom on it, `rise` tall. Global, as the element is EffectCanvas's. */
|
|
61
|
+
:global(.effect-canvas.effect-pixel-fountain[data-effect-pixel-fountain]) {
|
|
62
|
+
inset: auto 0 100% 0;
|
|
63
|
+
height: var(--fountain-rise);
|
|
64
|
+
}
|
|
65
|
+
/* From the text: over the host and the space above it. */
|
|
66
|
+
:global(.effect-canvas.effect-pixel-fountain.is-text[data-effect-pixel-fountain]) {
|
|
67
|
+
inset: auto 0 0 0;
|
|
68
|
+
height: calc(100% + var(--fountain-rise));
|
|
69
|
+
}
|
|
70
|
+
</style>
|
package/src/index.d.ts
CHANGED
|
@@ -18,8 +18,10 @@ export { voxelLogo } from './runtime/voxel-logo.js';
|
|
|
18
18
|
export type { VoxelLogoConfig } from './runtime/voxel-logo.js';
|
|
19
19
|
export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
|
|
20
20
|
export type { PixelGlitchConfig } from './runtime/pixel-glitch.js';
|
|
21
|
+
export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
|
|
22
|
+
export type { PixelFountainConfig, Pixel, EmitKind, FountainOptions, Fountain } from './runtime/pixel-fountain.js';
|
|
21
23
|
export { fit, fitText } from './runtime/fit-text.js';
|
|
22
|
-
export { textNodes, textRange, splitLetters, joinLetters } from './runtime/text.js';
|
|
24
|
+
export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
|
|
23
25
|
export { variableType, DEFAULT_AXES } from './runtime/variable-type.js';
|
|
24
26
|
export type { VariableTypeConfig, Axes } from './runtime/variable-type.js';
|
|
25
27
|
export { dotGrid } from './runtime/dot-grid.js';
|
|
@@ -96,6 +98,7 @@ export { loadImage, imageTexture, coverScale, GLSL_COVER } from './runtime/image
|
|
|
96
98
|
export { boxBlur } from './runtime/blur.js';
|
|
97
99
|
export { paperShader, paperSettings, paperUniforms } from './runtime/paper.js';
|
|
98
100
|
export { whenNear, lazyMargin } from './runtime/near.js';
|
|
101
|
+
export { budget } from './runtime/budget.js';
|
|
99
102
|
export { liveGradient } from './runtime/live-gradient.js';
|
|
100
103
|
export type { LiveGradientOptions } from './runtime/live-gradient.js';
|
|
101
104
|
export type { PaperConfig, PaperShaderName } from './runtime/paper.js';
|
package/src/index.js
CHANGED
|
@@ -21,8 +21,9 @@ export { particleLogo } from './runtime/particle-logo.js';
|
|
|
21
21
|
export { pointCloud } from './runtime/point-cloud.js';
|
|
22
22
|
export { voxelLogo } from './runtime/voxel-logo.js';
|
|
23
23
|
export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
|
|
24
|
+
export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
|
|
24
25
|
export { fit, fitText } from './runtime/fit-text.js';
|
|
25
|
-
export { textNodes, textRange, splitLetters, joinLetters } from './runtime/text.js';
|
|
26
|
+
export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
|
|
26
27
|
export { variableType, DEFAULT_AXES } from './runtime/variable-type.js';
|
|
27
28
|
export { dotGrid } from './runtime/dot-grid.js';
|
|
28
29
|
export { signalLines, waveBars } from './runtime/waves.js';
|
|
@@ -67,6 +68,7 @@ export { loadImage, imageTexture, coverScale, GLSL_COVER } from './runtime/image
|
|
|
67
68
|
export { boxBlur } from './runtime/blur.js';
|
|
68
69
|
export { paperShader, paperSettings, paperUniforms } from './runtime/paper.js';
|
|
69
70
|
export { whenNear, lazyMargin } from './runtime/near.js';
|
|
71
|
+
export { budget } from './runtime/budget.js';
|
|
70
72
|
export { liveGradient } from './runtime/live-gradient.js';
|
|
71
73
|
export { paperLook, paperLookSettings } from './runtime/paper-look.js';
|
|
72
74
|
export { scene, sceneSettings } from './runtime/scene.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Starts something and returns how to stop it. */
|
|
2
|
+
export type Run = () => () => void;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A budget of `cap` things running at once. `take(key, run)` runs `run` now if there is room, or when a turn comes up
|
|
6
|
+
* (the longest-waiting first); the function it returns gives the turn back, stopping what ran or leaving the queue.
|
|
7
|
+
*/
|
|
8
|
+
export function budget(cap: number): (key: object, run: Run) => () => void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/budget
|
|
3
|
+
*
|
|
4
|
+
* A cap on how many things run at once. Live effects share two scarce
|
|
5
|
+
* things: WebGL contexts (a browser keeps about sixteen and drops the
|
|
6
|
+
* oldest past that, which leaves an effect's canvas blank) and the main
|
|
7
|
+
* thread (the costly ones). A budget lets only so many run together; the
|
|
8
|
+
* rest wait their turn, in the order they asked, and start as one stops.
|
|
9
|
+
* It pairs with `whenNear`: an effect takes a turn as it nears the screen
|
|
10
|
+
* and gives it back as it leaves.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A budget of `cap` things running at once.
|
|
15
|
+
*
|
|
16
|
+
* @param {number} cap How many may run together.
|
|
17
|
+
* @returns {(key: object, run: () => () => void) => () => void} `take(key, run)`: runs `run` now if there is room, or when a turn comes up, and returns how to give the turn back (stopping what ran, or leaving the queue), which lets the longest-waiting one start.
|
|
18
|
+
*/
|
|
19
|
+
export function budget(cap) {
|
|
20
|
+
/** @type {Map<object, () => void>} */
|
|
21
|
+
const live = new Map();
|
|
22
|
+
/** @type {Map<object, () => () => void>} */
|
|
23
|
+
const waiting = new Map();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Runs one now.
|
|
27
|
+
*
|
|
28
|
+
* @param {object} key What it is.
|
|
29
|
+
* @param {() => () => void} run Starts it; returns how to stop it.
|
|
30
|
+
*/
|
|
31
|
+
const start = (key, run) => {
|
|
32
|
+
waiting.delete(key);
|
|
33
|
+
live.set(key, run());
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (key, run) => {
|
|
37
|
+
if (live.size < cap) start(key, run);
|
|
38
|
+
else waiting.set(key, run);
|
|
39
|
+
return () => {
|
|
40
|
+
waiting.delete(key);
|
|
41
|
+
const stop = live.get(key);
|
|
42
|
+
if (!stop) return;
|
|
43
|
+
live.delete(key);
|
|
44
|
+
stop();
|
|
45
|
+
const next = waiting.entries().next().value;
|
|
46
|
+
if (next) start(next[0], next[1]);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Whether a computed transform is a translate and scale only (no rotation or skew). */
|
|
2
|
+
export function plainTransform(t: string): boolean;
|
|
3
|
+
|
|
4
|
+
/** An element as an issue's message names it: its tag and first two classes (`div.card.wide`). */
|
|
5
|
+
export function describe(el: Element): string;
|
|
6
|
+
|
|
7
|
+
/** Markup in a `<g opacity>` when `opacity` is under 1 and there is markup; as it is otherwise. */
|
|
8
|
+
export function faded(markup: string, opacity: number): string;
|
|
9
|
+
|
|
10
|
+
/** Swaps each picture's `data-src` in SVG markup for an `href` to its file as a `data:` URL (empty for one that cannot be fetched). */
|
|
11
|
+
export function inlinePictures(body: string): Promise<string>;
|
|
12
|
+
|
|
13
|
+
/** What stops an element (shown, laid out) being rebuilt faithfully as plain SVG, each once; empty when it can be. */
|
|
14
|
+
export function cleanIssues(el: HTMLElement): string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* An element (shown, laid out) as a plain SVG document: rects, pictures, its inline SVGs and its words as `<text>`, its
|
|
18
|
+
* fonts inlined; `long` (default 1080) px on its longer side, its viewBox the element's CSS size. Throws, listing why,
|
|
19
|
+
* when it cannot be rebuilt faithfully (see `cleanIssues`).
|
|
20
|
+
*/
|
|
21
|
+
export function cleanSvg(el: HTMLElement, long?: number): Promise<string>;
|