@arraypress/effects-astro 0.7.0 → 0.9.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.
Files changed (40) hide show
  1. package/AGENTS.md +1 -1
  2. package/COMPONENTS.md +10 -1
  3. package/README.md +1 -1
  4. package/package.json +6 -2
  5. package/src/components/BorderSweep.astro +43 -4
  6. package/src/components/GlitchText.astro +17 -8
  7. package/src/components/Marquee.astro +34 -10
  8. package/src/components/text.js +29 -0
  9. package/src/index.d.ts +1 -0
  10. package/src/index.js +1 -0
  11. package/src/runtime/budget.d.ts +8 -0
  12. package/src/runtime/budget.js +49 -0
  13. package/src/runtime/export/clean-svg.d.ts +21 -0
  14. package/src/runtime/export/clean-svg.js +368 -0
  15. package/src/runtime/export/clock.d.ts +25 -0
  16. package/src/runtime/export/clock.js +122 -0
  17. package/src/runtime/export/fetch.d.ts +14 -0
  18. package/src/runtime/export/fetch.js +121 -0
  19. package/src/runtime/export/fonts.d.ts +30 -0
  20. package/src/runtime/export/fonts.js +202 -0
  21. package/src/runtime/export/format.d.ts +11 -0
  22. package/src/runtime/export/format.js +42 -0
  23. package/src/runtime/export/probe.d.ts +16 -0
  24. package/src/runtime/export/probe.js +89 -0
  25. package/src/runtime/export/raster.d.ts +17 -0
  26. package/src/runtime/export/raster.js +91 -0
  27. package/src/runtime/export/save.d.ts +5 -0
  28. package/src/runtime/export/save.js +41 -0
  29. package/src/runtime/export/snapshot.d.ts +43 -0
  30. package/src/runtime/export/snapshot.js +276 -0
  31. package/src/runtime/export/styles.d.ts +18 -0
  32. package/src/runtime/export/styles.js +152 -0
  33. package/src/runtime/export/svg-attrs.d.ts +8 -0
  34. package/src/runtime/export/svg-attrs.js +274 -0
  35. package/src/runtime/export/svg-text.d.ts +21 -0
  36. package/src/runtime/export/svg-text.js +124 -0
  37. package/src/runtime/export/video.d.ts +45 -0
  38. package/src/runtime/export/video.js +106 -0
  39. package/src/styles/border-sweep.css +35 -6
  40. package/src/styles/glitch-text.css +155 -2
package/AGENTS.md CHANGED
@@ -38,7 +38,7 @@ Pick by what is asked for:
38
38
  | Sections that arrive on scroll, site-wide | `<ScrollReveal />` once in the layout, then reveal.css classes (`fade-in-up`…) on elements |
39
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) |
40
40
  | Text that arrives or moves | `<Reveal>`, `<ScrambleText>`, `<Typewriter>`, `<HighlightSweep>`, `<Marquee>` |
41
- | A headline that glitches now and then (a label, a studio, a "make it yours" card) | `<GlitchText as="h2">` (CSS only; `blend="screen"` on a dark ground, `every`, `colors`) |
41
+ | A headline that glitches now and then (a label, a studio, a "make it yours" card) | `<GlitchText as="h2">` (CSS only; `blend="screen"` on a dark ground, `every`, `colors`; `variant="skew"` shakes the whole word; `copies="pseudo"` for one element of plain text) |
42
42
  | A small logo mark, a loading or "live" sign | `<PulseMark>`, `.fx-live` from `motion.css` |
43
43
  | A hero photo that reacts like water: ripples, a pond, "touch the photo" | `<ImageRipple src="…" alt="…">` (`strength`, `size`, `viscosity`, `fringe`, `fit="contain"`) |
44
44
  | A digital-goods or shop hero showing the products: their covers as the centrepiece, copy beside them | `<ProductStack items={[{ src, href, alt }, …]}>` (`layout="fan"`, `"stack"` or `"arc"`), or the covers as `<a><img></a>` children |
package/COMPONENTS.md CHANGED
@@ -60,6 +60,10 @@ BorderSweep: a light travelling round an element's outline, on hover and focus o
60
60
  | `always` | `boolean` | Run all the time, not only on hover. Default false. |
61
61
  | `lights` | `1 \| 2` | How many lights go round, 1–2: two chase each other half a lap apart. Default 1. |
62
62
  | `inset` | `boolean` | Draw the ring inside the edge and over the content, for elements that clip (`overflow: hidden`) and fill themselves with a picture or a canvas. Default false. |
63
+ | `long` | `boolean` | A longer light: a faint lead-in over the quarter lap before it, then the light and its tail. Default false. |
64
+ | `outset` | `number` | How far the ring sits out past the edge, px: 1 lays it over a 1px border. Default 0. |
65
+ | `focus` | `'within' \| 'visible' \| 'none'` | Which focus lights it: `within` when it or anything in it has the focus, `visible` only its own keyboard focus, `none` never (hover only). Default `within`. |
66
+ | `still` | `'ring' \| 'none'` | What reduced motion shows: `ring` a still lit edge where the light would run, `none` nothing. Default `ring`. |
63
67
  | `class` | `string` | Classes for the element. |
64
68
 
65
69
  ## `<Caustics>`
@@ -327,6 +331,8 @@ GlitchText: a headline that glitches now and then. Every few seconds two coloure
327
331
  | `colors` | `string[]` | The two copies' colours. Default `['#ff3ea5', '#2e4bff']` (pink and blue). |
328
332
  | `palette` | `PaletteName \| (string & {})` | A shared palette by name (`PALETTES`, any case), its first two colours, when there are no `colors`. |
329
333
  | `blend` | `'multiply' \| 'screen' \| 'normal' \| 'difference' \| 'plus-lighter'` | How the copies blend with the text and what is behind: `multiply` on a light ground, `screen` on a dark one. Default `multiply`. |
334
+ | `copies` | `'spans' \| 'pseudo'` | How the copies are drawn: `spans`, the slot laid twice more (inline formatting kept), or `pseudo`, the element's `::before` and `::after` from a `data-text` of the slot's words (one element; plain text only). Default `spans`. |
335
+ | `variant` | `'slice' \| 'skew'` | The glitch: `slice`, the copies sliced into four bands and shifted a few pixels while the text nudges; `skew`, the whole word shaking and skewing while the copies tear through three bands, shifted by a share of the type size. Default `slice`. |
330
336
  | `class` | `string` | Classes for the element. |
331
337
 
332
338
  ## `<GlowField>`
@@ -632,7 +638,10 @@ Marquee: an endless strip that scrolls sideways, for "as featured in" logos, art
632
638
  | `gap` | `string` | Space between items, CSS length. Default `2.5rem`. |
633
639
  | `pauseOnHover` | `boolean` | Pause while the pointer is over it. Default true. |
634
640
  | `pauseButton` | `boolean` | Show a pause button. Default true. |
635
- | `fade` | `number` | How wide the faded edges are, % of the strip. Default 8. |
641
+ | `fade` | `number` | How wide the faded edges are, % of the strip; 0 cuts them. Default 8. |
642
+ | `copies` | `2 \| 3 \| 4` | How many times the content is laid, 2–4; the strip moves by one of them a loop. Two is enough when one set is always wider than the strip. Default 4. |
643
+ | `role` | `'region' \| 'marquee' \| 'note'` | What it is to assistive technology: `region` a landmark, `marquee` a ticker, `note` an aside. Default `region`. |
644
+ | `still` | `'scroll' \| 'hold'` | With reduced motion: `scroll`, one set as a still row to scroll by hand; `hold`, the strip held where it starts, every set laid. Default `scroll`. |
636
645
  | `labels` | `{ pause: string; resume: string }` | The pause button's labels, for other languages. Default English. |
637
646
  | `label` | `string` | What the strip is, for screen readers. Default the items joined. |
638
647
  | `class` | `string` | Classes for the element. |
package/README.md CHANGED
@@ -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.7.0",
3
+ "version": "0.9.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": {
@@ -8,7 +8,9 @@
8
8
  * Suits outlined things: cards, ghost buttons, a featured pricing tier. A
9
9
  * filled button has no outline for the light to travel. `lights={2}` sends
10
10
  * two round, chasing each other; `inset` keeps the ring over the content of
11
- * a card that clips and fills itself.
11
+ * a card that clips and fills itself. `long` draws a longer light with a
12
+ * faint lead-in, `outset` lays the ring over a border, `focus` picks which
13
+ * focus lights it, and `still` what reduced motion shows.
12
14
  *
13
15
  * @example
14
16
  * <BorderSweep as="a" href="/pricing" class="card" color="#a5b4fc" always>…</BorderSweep>
@@ -32,14 +34,51 @@ interface Props {
32
34
  lights?: 1 | 2;
33
35
  /** Draw the ring inside the edge and over the content, for elements that clip (`overflow: hidden`) and fill themselves with a picture or a canvas. Default false. */
34
36
  inset?: boolean;
37
+ /** A longer light: a faint lead-in over the quarter lap before it, then the light and its tail. Default false. */
38
+ long?: boolean;
39
+ /** How far the ring sits out past the edge, px: 1 lays it over a 1px border. Default 0. */
40
+ outset?: number;
41
+ /** Which focus lights it: `within` when it or anything in it has the focus, `visible` only its own keyboard focus, `none` never (hover only). Default `within`. */
42
+ focus?: 'within' | 'visible' | 'none';
43
+ /** What reduced motion shows: `ring` a still lit edge where the light would run, `none` nothing. Default `ring`. */
44
+ still?: 'ring' | 'none';
35
45
  class?: string;
36
46
  [attribute: string]: unknown;
37
47
  }
38
48
 
39
- const { as: Tag = 'div', color, speed, width, always = false, lights = 1, inset = false, class: className, style: given, ...attributes } = Astro.props;
40
- const style = [color && `--sweep-color: ${color}`, speed !== undefined && `--sweep-speed: ${speed}s`, width !== undefined && `--sweep-width: ${width}px`]
49
+ const {
50
+ as: Tag = 'div',
51
+ color,
52
+ speed,
53
+ width,
54
+ always = false,
55
+ lights = 1,
56
+ inset = false,
57
+ long = false,
58
+ outset,
59
+ focus = 'within',
60
+ still = 'ring',
61
+ class: className,
62
+ style: given,
63
+ ...attributes
64
+ } = Astro.props;
65
+ const style = [
66
+ color && `--sweep-color: ${color}`,
67
+ speed !== undefined && `--sweep-speed: ${speed}s`,
68
+ width !== undefined && `--sweep-width: ${width}px`,
69
+ outset !== undefined && `--sweep-outset: ${outset}px`,
70
+ ]
41
71
  .filter(Boolean)
42
72
  .join('; ');
43
73
  ---
44
74
 
45
- <Tag class:list={['sweep-ring', { 'sweep-ring--always': always, 'sweep-ring--two': lights === 2, 'sweep-ring--inset': inset }, className]} style={withStyle(style, given)} {...attributes}><slot /></Tag>
75
+ <Tag
76
+ class:list={['sweep-ring',
77
+ { 'sweep-ring--always': always, 'sweep-ring--two': lights === 2, 'sweep-ring--inset': inset, 'sweep-ring--long': long },
78
+ focus !== 'within' && `sweep-ring--focus-${focus}`,
79
+ still !== 'ring' && `sweep-ring--still-${still}`,
80
+ className,
81
+ ]}
82
+ style={withStyle(style, given)}
83
+ {...attributes}><slot /></Tag
84
+ >
@@ -11,7 +11,10 @@
11
11
  *
12
12
  * The slot is rendered three times: once as the real text, twice as the
13
13
  * copies (hidden from assistive technology and from focus), so keep it to
14
- * text and inline formatting. For elements you render yourself, import
14
+ * text and inline formatting. `copies="pseudo"` draws the copies as the
15
+ * element's `::before` and `::after` from a `data-text` instead: one
16
+ * element, for plain text. `variant="skew"` is another glitch, the whole
17
+ * word shaking and skewing. For elements you render yourself, import
15
18
  * `@arraypress/effects-astro/glitch-text.css` and follow its markup.
16
19
  *
17
20
  * @example
@@ -22,6 +25,7 @@ import type { PaletteName } from '../runtime/palettes.js';
22
25
  import { pickColors } from '../runtime/palettes.js';
23
26
  import '../styles/glitch-text.css';
24
27
  import { withStyle } from './style.js';
28
+ import { plainText } from './text.js';
25
29
 
26
30
  interface Props {
27
31
  /** The element to render. Default `span`. */
@@ -38,11 +42,15 @@ interface Props {
38
42
  palette?: PaletteName | (string & {});
39
43
  /** How the copies blend with the text and what is behind: `multiply` on a light ground, `screen` on a dark one. Default `multiply`. */
40
44
  blend?: 'multiply' | 'screen' | 'normal' | 'difference' | 'plus-lighter';
45
+ /** How the copies are drawn: `spans`, the slot laid twice more (inline formatting kept), or `pseudo`, the element's `::before` and `::after` from a `data-text` of the slot's words (one element; plain text only). Default `spans`. */
46
+ copies?: 'spans' | 'pseudo';
47
+ /** The glitch: `slice`, the copies sliced into four bands and shifted a few pixels while the text nudges; `skew`, the whole word shaking and skewing while the copies tear through three bands, shifted by a share of the type size. Default `slice`. */
48
+ variant?: 'slice' | 'skew';
41
49
  class?: string;
42
50
  [attribute: string]: unknown;
43
51
  }
44
52
 
45
- const { as: Tag = 'span', every, hoverEvery, delay, colors, palette, blend, class: className, style: given, ...attributes } = Astro.props;
53
+ const { as: Tag = 'span', every, hoverEvery, delay, colors, palette, blend, copies = 'spans', variant = 'slice', class: className, style: given, ...attributes } = Astro.props;
46
54
  const [a, b] = colors?.length || palette ? pickColors({ colors, palette }, ['#ff3ea5', '#2e4bff'], (p) => [p.colors[0], p.colors[1]]) : [];
47
55
  const cycle = every ?? 5;
48
56
  // Rendered once, at build time: each instance gets its own beat in the static page.
@@ -58,12 +66,13 @@ const style = [
58
66
  .filter(Boolean)
59
67
  .join('; ');
60
68
  const html = await Astro.slots.render('default');
69
+ const pseudo = copies === 'pseudo';
61
70
  ---
62
71
 
63
- <Tag class:list={['glitch-text', className]} style={withStyle(style, given)} {...attributes}
64
- ><span><Fragment set:html={html} /></span><span class="glitch-text-a" aria-hidden="true" inert><Fragment set:html={html} /></span><span
65
- class="glitch-text-b"
66
- aria-hidden="true"
67
- inert><Fragment set:html={html} /></span
68
- ></Tag
72
+ <Tag
73
+ class:list={['glitch-text', pseudo && 'glitch-text--pseudo', variant !== 'slice' && `glitch-text--${variant}`, className]}
74
+ data-text={pseudo ? plainText(html) : undefined}
75
+ style={withStyle(style, given)}
76
+ {...attributes}
77
+ >{pseudo ? <Fragment set:html={html} /> : <Fragment><span><Fragment set:html={html} /></span><span class="glitch-text-a" aria-hidden="true" inert><Fragment set:html={html} /></span><span class="glitch-text-b" aria-hidden="true" inert><Fragment set:html={html} /></span></Fragment>}</Tag
69
78
  >
@@ -5,10 +5,12 @@
5
5
  * anything as the slot (logos, images, cards).
6
6
  *
7
7
  * The content is laid four times and the strip moves by one set, so the
8
- * loop is seamless even when a set is narrower than the screen. The edges
9
- * fade out rather than cutting, it can pause under the pointer, and a
10
- * small pause button stops it for good (moving content needs one, WCAG
11
- * 2.2.2). With reduced motion it is a still row, scrollable by hand.
8
+ * loop is seamless even when a set is narrower than the screen (`copies`
9
+ * lays it fewer times, for a set that is always wider). The edges fade
10
+ * out rather than cutting (`fade={0}` cuts them), it can pause under the
11
+ * pointer, and a small pause button stops it for good (moving content
12
+ * needs one, WCAG 2.2.2). With reduced motion it is a still row,
13
+ * scrollable by hand, or (`still="hold"`) the strip held where it starts.
12
14
  * Screen readers get the content once.
13
15
  *
14
16
  * Merges the marquees of the WaveGrid, SellGrid, LinkGrid and LaunchGrid
@@ -34,8 +36,14 @@ interface Props {
34
36
  pauseOnHover?: boolean;
35
37
  /** Show a pause button. Default true. */
36
38
  pauseButton?: boolean;
37
- /** How wide the faded edges are, % of the strip. Default 8. */
39
+ /** How wide the faded edges are, % of the strip; 0 cuts them. Default 8. */
38
40
  fade?: number;
41
+ /** How many times the content is laid, 2–4; the strip moves by one of them a loop. Two is enough when one set is always wider than the strip. Default 4. */
42
+ copies?: 2 | 3 | 4;
43
+ /** What it is to assistive technology: `region` a landmark, `marquee` a ticker, `note` an aside. Default `region`. */
44
+ role?: 'region' | 'marquee' | 'note';
45
+ /** With reduced motion: `scroll`, one set as a still row to scroll by hand; `hold`, the strip held where it starts, every set laid. Default `scroll`. */
46
+ still?: 'scroll' | 'hold';
39
47
  /** The pause button's labels, for other languages. Default English. */
40
48
  labels?: { pause: string; resume: string };
41
49
  /** What the strip is, for screen readers. Default the items joined. */
@@ -52,6 +60,9 @@ const {
52
60
  pauseOnHover = true,
53
61
  pauseButton = true,
54
62
  fade = 8,
63
+ copies = 4,
64
+ role = 'region',
65
+ still = 'scroll',
55
66
  labels = { pause: 'Pause scrolling', resume: 'Resume scrolling' },
56
67
  label,
57
68
  class: className,
@@ -59,13 +70,14 @@ const {
59
70
 
60
71
  // Slot content is rendered once and laid again for the copies.
61
72
  const slotted = items ? '' : await Astro.slots.render('default');
62
- const sets = [0, 1, 2, 3];
73
+ const sets = Array.from({ length: copies }, (_, set) => set);
74
+ const shift = copies === 4 ? '' : `; --marquee-shift: ${-100 / copies}%`;
63
75
  ---
64
76
 
65
77
  <div
66
- class:list={['effect-marquee', `is-${direction}`, { 'pause-on-hover': pauseOnHover }, className]}
67
- style={`--marquee-speed: ${speed}s; --marquee-gap: ${gap}; --marquee-fade: ${fade}%`}
68
- role="region"
78
+ class:list={['effect-marquee', `is-${direction}`, { 'pause-on-hover': pauseOnHover, 'no-fade': fade === 0, 'still-hold': still === 'hold' }, className]}
79
+ style={`--marquee-speed: ${speed}s; --marquee-gap: ${gap}; --marquee-fade: ${fade}%${shift}`}
80
+ role={role}
69
81
  aria-label={label ?? items?.join(', ')}
70
82
  data-effect-marquee
71
83
  >
@@ -159,9 +171,14 @@ const sets = [0, 1, 2, 3];
159
171
  .effect-marquee:global(.is-paused) .track {
160
172
  animation-play-state: paused;
161
173
  }
174
+ .no-fade .viewport {
175
+ -webkit-mask-image: none;
176
+ mask-image: none;
177
+ }
178
+ /* One set a loop: a quarter of the four, or --marquee-shift for fewer. */
162
179
  @keyframes effect-marquee {
163
180
  to {
164
- transform: translateX(-25%);
181
+ transform: translateX(var(--marquee-shift, -25%));
165
182
  }
166
183
  }
167
184
 
@@ -212,5 +229,12 @@ const sets = [0, 1, 2, 3];
212
229
  .toggle {
213
230
  display: none;
214
231
  }
232
+ /* Held: every set laid, still, as it starts. */
233
+ .still-hold .viewport {
234
+ overflow-x: hidden;
235
+ }
236
+ .still-hold .set[aria-hidden='true'] {
237
+ display: flex;
238
+ }
215
239
  }
216
240
  </style>
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/components/text
3
+ *
4
+ * The words of a rendered slot, for an attribute that repeats them
5
+ * (`<GlitchText copies="pseudo">`'s `data-text`): its tags dropped and its
6
+ * character references read back into characters, so Astro escapes them
7
+ * once, as the attribute's own.
8
+ */
9
+
10
+ /** The named references Astro's escaping writes, and the no-break space. */
11
+ const NAMED = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
12
+
13
+ /**
14
+ * A slot's HTML as plain text.
15
+ *
16
+ * @param {string} html The rendered slot.
17
+ * @returns {string} Its text: no tags, each run of white space one space, trimmed, references decoded.
18
+ */
19
+ export function plainText(html) {
20
+ return html
21
+ .replace(/<[^>]*>/g, '')
22
+ .replace(/[ \t\n\r\f]+/g, ' ')
23
+ .trim()
24
+ .replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (whole, ref) => {
25
+ if (ref[0] !== '#') return NAMED[/** @type {keyof typeof NAMED} */ (ref.toLowerCase())] ?? whole;
26
+ const code = /^#x/i.test(ref) ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
27
+ return code <= 0x10ffff ? String.fromCodePoint(code) : whole;
28
+ });
29
+ }
package/src/index.d.ts CHANGED
@@ -98,6 +98,7 @@ export { loadImage, imageTexture, coverScale, GLSL_COVER } from './runtime/image
98
98
  export { boxBlur } from './runtime/blur.js';
99
99
  export { paperShader, paperSettings, paperUniforms } from './runtime/paper.js';
100
100
  export { whenNear, lazyMargin } from './runtime/near.js';
101
+ export { budget } from './runtime/budget.js';
101
102
  export { liveGradient } from './runtime/live-gradient.js';
102
103
  export type { LiveGradientOptions } from './runtime/live-gradient.js';
103
104
  export type { PaperConfig, PaperShaderName } from './runtime/paper.js';
package/src/index.js CHANGED
@@ -68,6 +68,7 @@ export { loadImage, imageTexture, coverScale, GLSL_COVER } from './runtime/image
68
68
  export { boxBlur } from './runtime/blur.js';
69
69
  export { paperShader, paperSettings, paperUniforms } from './runtime/paper.js';
70
70
  export { whenNear, lazyMargin } from './runtime/near.js';
71
+ export { budget } from './runtime/budget.js';
71
72
  export { liveGradient } from './runtime/live-gradient.js';
72
73
  export { paperLook, paperLookSettings } from './runtime/paper-look.js';
73
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>;