histropediajs 1.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/LICENSE +8 -0
- package/README.md +480 -0
- package/dist/histropedia.esm.js +9545 -0
- package/dist/histropedia.umd.js +9563 -0
- package/dist/histropedia.umd.min.js +5 -0
- package/index.d.ts +1464 -0
- package/package.json +101 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
# HistropediaJS
|
|
2
|
+
|
|
3
|
+
An embeddable, high-performance, canvas-based timeline engine for rendering events (known as "articles" in the library)over timescales from days to billions of years. Offers smooth pan/zoom, stacking, card layouts, time bands, image loading, and a flexible API.
|
|
4
|
+
|
|
5
|
+
- **Canvas-based**: fast rendering and smooth animations
|
|
6
|
+
- **Huge ranges**: day -> billion-year scales, BCE support
|
|
7
|
+
- **Customizable**: styles, layouts, stacking, density, branding
|
|
8
|
+
- **Modular**: ESM default build + UMD for script tags
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install histropediajs
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Documentation
|
|
17
|
+
|
|
18
|
+
For comprehensive guides, options reference, and API docs, see the hosted documentation: [HistropediaJS Documentation](https://js.histropedia.com/documentation).
|
|
19
|
+
|
|
20
|
+
### Importing
|
|
21
|
+
|
|
22
|
+
`histropediajs` is published as an ESM package. Use `import` in bundlers or ESM-capable runtimes. `require('histropediajs')` is not supported. For non-module browser usage, load the UMD bundle with a `<script>` tag.
|
|
23
|
+
|
|
24
|
+
- ESM (npm / bundlers, recommended):
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import Histropedia from 'histropediajs';
|
|
28
|
+
// or named exports if you tree-shake
|
|
29
|
+
import { Timeline, Article, Dmy, Logger } from 'histropediajs';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- UMD (script tag) via CDN or self-host:
|
|
33
|
+
- CDN (jsDelivr):
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<script src="https://cdn.jsdelivr.net/npm/histropediajs@1/dist/histropedia.umd.min.js"></script>
|
|
37
|
+
<script>
|
|
38
|
+
const { Timeline, Dmy } = Histropedia; // global
|
|
39
|
+
// window.Histropedia is also available
|
|
40
|
+
</script>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- Self-host (copy dist file into your public assets during build):
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<script src="/assets/vendor/histropedia.umd.js"></script>
|
|
47
|
+
<script>
|
|
48
|
+
const { Timeline, Dmy } = Histropedia;
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<div id="timeline"></div>
|
|
56
|
+
<script type="module">
|
|
57
|
+
import { Timeline } from 'histropediajs';
|
|
58
|
+
|
|
59
|
+
const container = document.getElementById('timeline');
|
|
60
|
+
const options = {
|
|
61
|
+
width: 1000,
|
|
62
|
+
height: 500,
|
|
63
|
+
initialDate: { year: 1990, month: 1, day: 1 },
|
|
64
|
+
zoom: { initial: 34 },
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const timeline = new Timeline(container, options);
|
|
68
|
+
|
|
69
|
+
timeline.load([
|
|
70
|
+
{
|
|
71
|
+
id: 'apollo11',
|
|
72
|
+
title: 'Apollo 11',
|
|
73
|
+
subtitle: 'First Moon landing',
|
|
74
|
+
from: { year: 1969, month: 7, day: 16 },
|
|
75
|
+
to: { year: 1969, month: 7, day: 24 },
|
|
76
|
+
imageUrl: 'https://example.com/apollo11.jpg',
|
|
77
|
+
},
|
|
78
|
+
]);
|
|
79
|
+
</script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Data model
|
|
83
|
+
|
|
84
|
+
Each article (event) uses the following minimal shape. Short property aliases are also supported internally for compact data, but prefer the long form in your code.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
{
|
|
88
|
+
id: string|number,
|
|
89
|
+
title: string,
|
|
90
|
+
subtitle?: string,
|
|
91
|
+
lane?: string|number,
|
|
92
|
+
from: { year: number, month?: number, day?: number, precision?: number },
|
|
93
|
+
to?: { year: number, month?: number, day?: number, precision?: number },
|
|
94
|
+
isToPresent?: boolean,
|
|
95
|
+
rank?: number,
|
|
96
|
+
starred?: boolean,
|
|
97
|
+
hidePeriodLine?: boolean,
|
|
98
|
+
hiddenByFilter?: boolean,
|
|
99
|
+
imageUrl?: string,
|
|
100
|
+
cardLayout?: 'portrait' | 'landscape',
|
|
101
|
+
style?: object,
|
|
102
|
+
hoverStyle?: object,
|
|
103
|
+
activeStyle?: object
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Notes:
|
|
108
|
+
|
|
109
|
+
- BCE years are supported with negative year values; internally year 0 represents 1 BCE. Set `shiftBceDates: true` to shift year input by 1 so that -1 is 1BCE.
|
|
110
|
+
- If `to` is omitted and `isToPresent` is false, the article is treated as an instant event (uses `from`), but the `from.precision` will be used to determined the span of the periodLine.
|
|
111
|
+
|
|
112
|
+
## Lanes
|
|
113
|
+
|
|
114
|
+
Use `lane` when you need multiple horizontal event rows that share the same bottom axis. Articles, connectors, hit-testing, and period lines still render on the shared canvas, while lane headers, titles, and bodies render as DOM elements underneath the canvas so they can be styled independently. By default, period lines anchor to each lane bottom while lane layout is active; set `article.periodLine.position = 'axis'` to keep the legacy shared-axis behavior.
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
const timeline = new Timeline(container, {
|
|
118
|
+
lane: {
|
|
119
|
+
defaultClassName: 'timeline-lane',
|
|
120
|
+
defaultHeaderClassName: 'timeline-lane-header',
|
|
121
|
+
defaultBodyClassName: 'timeline-lane-body',
|
|
122
|
+
defaultTitleClassName: 'timeline-lane-title',
|
|
123
|
+
data: [
|
|
124
|
+
{ id: 'people', title: 'People', layout: { heightWeight: 2 } },
|
|
125
|
+
{ id: 'projects', title: 'Projects', layout: { heightWeight: 1 } },
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
timeline.load([
|
|
131
|
+
{
|
|
132
|
+
id: 'ada',
|
|
133
|
+
lane: 'people',
|
|
134
|
+
title: 'Ada Lovelace',
|
|
135
|
+
from: { year: 1815, month: 12, day: 10 },
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
timeline.loadLaneArticles('projects', [
|
|
140
|
+
{
|
|
141
|
+
id: 'analytical-engine',
|
|
142
|
+
title: 'Analytical Engine',
|
|
143
|
+
from: { year: 1837 },
|
|
144
|
+
},
|
|
145
|
+
]);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- Lane geometry stays inline so the renderer can place each lane correctly, but decorative inline styles are only written when you explicitly configure `lane.defaultStyle` or `LaneData.style`.
|
|
149
|
+
- Lane roots always include `histropedia-lane`, `histropedia-lane-index-N`, and a position class, where `N` follows the stable `timeline.lanes` order from the axis outward.
|
|
150
|
+
- Lower lanes stack above upper lanes with inline `z-index` values, making stacked CSS effects easier to write.
|
|
151
|
+
- `timeline.articles` stays flat across all lanes for backward compatibility.
|
|
152
|
+
- `ArticleData.lane` is the primary way to place events; omitted values fall back to `options.lane.defaultId` (`'default'`).
|
|
153
|
+
- `lane.topGap` reserves space above the topmost lane and reduces the height available for lane layout.
|
|
154
|
+
- `lane.axisGap` controls the space between the painted top edge of the shared main line and the lane area. Set it to `0` if the nearest lane body should meet the main line.
|
|
155
|
+
- `lane.layout.heightWeight` distributes the remaining automatic lane height across visible lanes only. Omit it to keep the default equal split, or use `lane.layout.height` for a fixed lane height.
|
|
156
|
+
- `timeline.loadLanes(...)` adds or updates lane definitions, including implicit lanes created from article data.
|
|
157
|
+
- Per-lane article defaults live under `lane.article` and merge over global `options.article` presentation defaults.
|
|
158
|
+
|
|
159
|
+
## API
|
|
160
|
+
|
|
161
|
+
### Default export
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
import Histropedia from 'histropediajs';
|
|
165
|
+
// Histropedia = { Timeline, Article, Lane, Dmy, Logger, ...constants, ...sorters, setDebug, isDebugEnabled, enableDebug, disableDebug }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Classes and utilities
|
|
169
|
+
|
|
170
|
+
- **Timeline**: main canvas timeline. `new Timeline(containerOrCanvas, options)`
|
|
171
|
+
- **Article**: article model used internally; available for advanced usage
|
|
172
|
+
- **Dmy**: lightweight date helper (year, month, day, BCE support)
|
|
173
|
+
- **Logger**: centralized console logger with `setEnabled(boolean)`
|
|
174
|
+
- **Constants**: zoom levels, precisions, density controls, etc.
|
|
175
|
+
|
|
176
|
+
### Timeline constructor
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
new Timeline(container: HTMLElement | HTMLCanvasElement, options?: TimelineOptions)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
If `container` is an element, the timeline creates and appends its own `<canvas>`. If you pass a `<canvas>`, it will use it directly and derive width from the element unless overridden.
|
|
183
|
+
|
|
184
|
+
### Core methods
|
|
185
|
+
|
|
186
|
+
- `load(articles: ArticleInput[])`: load or append articles (deduplicates by `id`).
|
|
187
|
+
- `loadLanes(lanes: LaneData[])`: add or update lane definitions.
|
|
188
|
+
- `loadLaneArticles(laneId, articles)`: stamp a lane id onto a batch and forward to `load(...)`.
|
|
189
|
+
- `loadTimeBands(...)`: add timeline-wide background bands.
|
|
190
|
+
- `setStartDate(dmyOrISO: Dmy | string, pixelOffset?: number)`: set left edge date.
|
|
191
|
+
- `setCentreDate(dmyOrISO: Dmy | string, pixelOffset?: number)`: center given date.
|
|
192
|
+
- `setSize(width: number, height: number)`: resize canvas and reflow.
|
|
193
|
+
- `setZoom(level: number, pivotPixel?: number, offsetX?: number)`: programmatic zoom.
|
|
194
|
+
- `on(event: string, handler)` / `off(event, handler)` / `trigger(event, ...args)`: event system.
|
|
195
|
+
- `select(articleId)`: bring to the front and trigger the `article-select` event.
|
|
196
|
+
|
|
197
|
+
### Events
|
|
198
|
+
|
|
199
|
+
Register handlers using `timeline.on(name, callback)` or pass `options.on = { [name]: handler }`.
|
|
200
|
+
|
|
201
|
+
Full list of events and payloads: [docs/events.md](docs/events.md)
|
|
202
|
+
|
|
203
|
+
Basic usage:
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
// Register a handler
|
|
207
|
+
timeline.on('article-click', (article, evt) => {
|
|
208
|
+
console.log('article-click', article, evt);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Or via options
|
|
212
|
+
const timeline = new Timeline(container, {
|
|
213
|
+
on: {
|
|
214
|
+
'article-click': (article, evt) => console.log('article-click', article, evt),
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Trigger an event programmatically (advanced)
|
|
219
|
+
timeline.trigger('my-custom-event', { any: 'payload' });
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Debugging and logging
|
|
223
|
+
|
|
224
|
+
HistropediaJS uses a centralized `Logger` service to control console output. Logging is **disabled by default** so it will not spam your console unless you explicitly turn it on.
|
|
225
|
+
|
|
226
|
+
- **Enable / disable debug logging (default export helpers)**:
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
import Histropedia from 'histropediajs';
|
|
230
|
+
|
|
231
|
+
// Turn on all HistropediaJS logging
|
|
232
|
+
Histropedia.enableDebug();
|
|
233
|
+
|
|
234
|
+
// Or explicitly set the flag
|
|
235
|
+
Histropedia.setDebug(true);
|
|
236
|
+
|
|
237
|
+
// Later, turn logging off again
|
|
238
|
+
Histropedia.disableDebug();
|
|
239
|
+
// Equivalent:
|
|
240
|
+
Histropedia.setDebug(false);
|
|
241
|
+
|
|
242
|
+
// Check current state
|
|
243
|
+
const isOn = Histropedia.isDebugEnabled(); // boolean
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
- **Using the `Logger` directly (ESM / bundlers)**:
|
|
247
|
+
|
|
248
|
+
```js
|
|
249
|
+
import { Logger } from 'histropediajs';
|
|
250
|
+
|
|
251
|
+
Logger.setEnabled(true); // enable logging
|
|
252
|
+
Logger.debug('Timeline initialised');
|
|
253
|
+
Logger.info('Loaded articles', articles);
|
|
254
|
+
Logger.warn('Something looks odd');
|
|
255
|
+
Logger.error('Something went wrong', err);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
- **UMD / script-tag usage**:
|
|
259
|
+
|
|
260
|
+
```html
|
|
261
|
+
<script src="https://cdn.jsdelivr.net/npm/histropediajs@1/dist/histropedia.umd.min.js"></script>
|
|
262
|
+
<script>
|
|
263
|
+
// Enable debug logging
|
|
264
|
+
Histropedia.enableDebug();
|
|
265
|
+
|
|
266
|
+
// Or via the Logger instance
|
|
267
|
+
Histropedia.Logger.setEnabled(true);
|
|
268
|
+
Histropedia.Logger.debug('Timeline ready');
|
|
269
|
+
</script>
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
- **Changing the debug label (prefix / "suffix" tag)**:
|
|
273
|
+
|
|
274
|
+
All log messages are prefixed with a label (by default `[Histropedia]`) so you can easily spot them in the console. You can change this to include your app name, environment, or any other marker.
|
|
275
|
+
|
|
276
|
+
```js
|
|
277
|
+
import { Logger } from 'histropediajs';
|
|
278
|
+
|
|
279
|
+
// Set a custom label that will appear in front of every log message
|
|
280
|
+
Logger.setPrefix('[MyApp Timeline]');
|
|
281
|
+
|
|
282
|
+
Logger.setEnabled(true);
|
|
283
|
+
Logger.debug('Loading articles...');
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
For script-tag/UMD usage:
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
Histropedia.Logger.setPrefix('[MyApp Timeline]');
|
|
290
|
+
Histropedia.enableDebug();
|
|
291
|
+
Histropedia.Logger.info('Timeline is ready');
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
The prefix is applied to all standard console-style methods exposed by the logger (`log`, `info`, `warn`, `error`, `debug`, `group`, `groupCollapsed`, `groupEnd`).
|
|
295
|
+
|
|
296
|
+
## Options
|
|
297
|
+
|
|
298
|
+
TimelineOptions tunes layout, interaction, article rendering, and image loading. Start with the defaults and override only what you need for your embed.
|
|
299
|
+
|
|
300
|
+
- **Layout**: adjust `width`, `height`, and `verticalOffset` to size and position the canvas.
|
|
301
|
+
- **Navigation**: set `initialDate`, `zoom.initial`, and `enableUserControl` to define how people explore the timeline.
|
|
302
|
+
- **Articles**: control stacking and presentation with `article.autoStacking`, adaptive `defaultCardLayout`, `cardLayoutBreakpoints`, `distanceToBaseline`, and density settings.
|
|
303
|
+
- **Lanes**: use `lanes.defaultStyle`, `lanes.data`, and per-lane `article` overrides for shared-axis multi-lane layouts.
|
|
304
|
+
- **Images**: use `image.sanitizer.allowedOrigins`, caching limits, or a custom `image.customSanitizer` to match your content policies.
|
|
305
|
+
- **Events**: register callbacks via the `on` map or helpers such as `onArticleClick`.
|
|
306
|
+
|
|
307
|
+
Find the full option reference, defaults, and advanced patterns in the hosted docs: https://js.histropedia.com/documentation.
|
|
308
|
+
|
|
309
|
+
### Card layouts
|
|
310
|
+
|
|
311
|
+
Two built-in layouts are registered: `portrait` and `landscape`. By default the timeline falls back to `article.defaultCardLayout: 'portrait'`, while ordered `article.cardLayoutBreakpoints` can override that fallback using the currently available vertical space for article cards.
|
|
312
|
+
|
|
313
|
+
```js
|
|
314
|
+
const timeline = new Timeline(container, {
|
|
315
|
+
article: {
|
|
316
|
+
distanceToBaseline: 350,
|
|
317
|
+
defaultCardLayout: 'portrait',
|
|
318
|
+
cardLayoutBreakpoints: [{ maxHeight: 220, layout: 'landscape' }],
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Explicit `article.cardLayout` values still win, and lane defaults can set `lane.article.defaultCardLayout` as that lane's fallback layout when no breakpoint matches.
|
|
324
|
+
|
|
325
|
+
You can register custom layouts:
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
import { Timeline } from 'histropediajs';
|
|
329
|
+
|
|
330
|
+
Timeline.registerCardLayout({
|
|
331
|
+
name: 'my-card',
|
|
332
|
+
draw(ctx) {
|
|
333
|
+
// draw using this.position, this._getCurrentStyle(), this.image, etc.
|
|
334
|
+
},
|
|
335
|
+
defaultStyle: {
|
|
336
|
+
/* optional style defaults */
|
|
337
|
+
},
|
|
338
|
+
defaultHoverStyle: {
|
|
339
|
+
/* optional */
|
|
340
|
+
},
|
|
341
|
+
defaultActiveStyle: {
|
|
342
|
+
/* optional */
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const timeline = new Timeline(container, {
|
|
347
|
+
article: { defaultCardLayout: 'my-card' },
|
|
348
|
+
});
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Images and security
|
|
352
|
+
|
|
353
|
+
- Every article image is sanitized before load. By default the timeline calls `sanitizeImageUrl` (src/services/url-sanitizer.js), which trims the value, enforces the scheme allowlist (`http`, `https`, `data`, `blob`), and rejects non image `data:` payloads.
|
|
354
|
+
- Origins are unrestricted unless you supply `image.sanitizer.allowedOrigins`. Add host patterns (full origins, `*.example.com`, `.example.com`, bare hostnames) to enforce an allowlist, or provide a custom sanitizer.
|
|
355
|
+
- `blob:` and `data:` URLs skip origin checks but still require an allowed scheme. `data:` URLs must begin with `data:image/`.
|
|
356
|
+
- If you provide `image.customSanitizer`, it receives the raw URL and your `image.sanitizer` options object (including any custom fields you add). Return a trusted URL string to allow the load or `null` to block it; when `null` is returned the article keeps rendering without an image.
|
|
357
|
+
|
|
358
|
+
```js
|
|
359
|
+
const timeline = new Histropedia.Timeline(container, {
|
|
360
|
+
image: {
|
|
361
|
+
sanitizer: {
|
|
362
|
+
// Configure the built-in sanitizer
|
|
363
|
+
allowedSchemes: ['https', 'data'],
|
|
364
|
+
allowedOrigins: [
|
|
365
|
+
'https://static.example-cdn.com',
|
|
366
|
+
'*.imgix.net',
|
|
367
|
+
'.example.com',
|
|
368
|
+
'media.example.com',
|
|
369
|
+
],
|
|
370
|
+
},
|
|
371
|
+
// Optional custom sanitizer (takes precedence)
|
|
372
|
+
customSanitizer: (url, opts) => {
|
|
373
|
+
try {
|
|
374
|
+
const candidate = new URL(url, window.location.href);
|
|
375
|
+
const isHttps = candidate.protocol === 'https:';
|
|
376
|
+
const onCdn = candidate.hostname.endsWith('.example-cdn.com');
|
|
377
|
+
return isHttps && onCdn ? candidate.href : null;
|
|
378
|
+
} catch {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### Image loader configuration
|
|
387
|
+
|
|
388
|
+
The image loader queues work on demand, deduplicates concurrent requests, and evicts cached bitmaps when the byte budget is exceeded. Tune it via `options.image`:
|
|
389
|
+
|
|
390
|
+
- `maxCacheBytes` (default `64 * 1024 * 1024`) caps the decoded raster cache. Set `0` to disable caching or `Infinity` to remove the cap.
|
|
391
|
+
- `maxConcurrent` (default `6`) limits concurrent fetch/decode operations.
|
|
392
|
+
- `requireCORS` (default `false`) sets `crossOrigin = 'anonymous'` so the canvas stays untainted when your CDN returns the correct CORS headers.
|
|
393
|
+
- `decodeMode` selects the decode pipeline: 'auto', 'prefer-bitmap', 'bitmap', 'prefer-img', or 'img'.
|
|
394
|
+
|
|
395
|
+
See `src/services/url-sanitizer.js` and `src/services/image-loader.js` for reference implementations and additional behaviour such as shape cropping and cache management.
|
|
396
|
+
|
|
397
|
+
## Accessibility
|
|
398
|
+
|
|
399
|
+
- Pointer interactions support mouse, touch, and trackpads.
|
|
400
|
+
- Consider keyboard affordances and focus management in your host app; the canvas itself is not focusable by default.
|
|
401
|
+
|
|
402
|
+
## Examples and demo
|
|
403
|
+
|
|
404
|
+
A demo app with scenarios is included.
|
|
405
|
+
|
|
406
|
+
- Run the demo locally:
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
npm install
|
|
410
|
+
npm run dev
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Then open the served URL (Vite dev server). Switch scenarios via the toolbar.
|
|
414
|
+
|
|
415
|
+
## Browser support / Build targets
|
|
416
|
+
|
|
417
|
+
### Build targets
|
|
418
|
+
|
|
419
|
+
| Build | File | Target | Notes |
|
|
420
|
+
| ----- | ----------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
421
|
+
| ESM | `histropedia.esm.js` | ES2020 | Published npm entrypoint for bundlers and other ESM-capable runtimes. Uses native `async/await`, optional chaining (`?.`), nullish coalescing (`??`). |
|
|
422
|
+
| UMD | `histropedia.umd.js` / `histropedia.umd.min.js` | ES2017 | For `<script>` tags, CDN usage, or self-hosted browser embeds. The minified UMD file is published for UNPKG/jsDelivr. This build is not a CommonJS `require()` entrypoint. |
|
|
423
|
+
|
|
424
|
+
### Web APIs used
|
|
425
|
+
|
|
426
|
+
The library uses several Web APIs that may not exist in all browsers. Most are feature-detected with automatic fallbacks; a few require polyfills if you support older environments.
|
|
427
|
+
|
|
428
|
+
#### Performance boosts (feature-detected)
|
|
429
|
+
|
|
430
|
+
These APIs improve performance when available. The timeline works correctly without them, but may use more main-thread time or be slightly less efficient:
|
|
431
|
+
|
|
432
|
+
| API | Used for | Without it |
|
|
433
|
+
| --------------------- | ---------------------------------- | --------------------------------------------------------------------------- |
|
|
434
|
+
| `createImageBitmap()` | Off-thread image decoding | Falls back to `HTMLImageElement` + canvas; images decode on the main thread |
|
|
435
|
+
| `OffscreenCanvas` | Off-screen image cropping/resizing | Falls back to regular `<canvas>`; slightly more GC pressure |
|
|
436
|
+
| `img.decode()` | Async decode before paint | Falls back to `onload`; may cause minor jank when large images appear |
|
|
437
|
+
| `performance.now()` | High-resolution cache timestamps | Falls back to `Date.now()`; millisecond precision instead of sub-ms |
|
|
438
|
+
|
|
439
|
+
#### Graceful degradation (feature-detected)
|
|
440
|
+
|
|
441
|
+
These APIs provide enhanced functionality when available. The timeline remains fully functional without them, with minor behavioural differences:
|
|
442
|
+
|
|
443
|
+
| API | Used for | Without it |
|
|
444
|
+
| --------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------ |
|
|
445
|
+
| `AbortController` | Cancelling in-flight image fetches | Requests complete even if no longer needed; wastes some bandwidth |
|
|
446
|
+
| `document.fonts` (CSS Font Loading API) | Detecting when custom fonts finish loading | Text may briefly render in fallback font before redraw |
|
|
447
|
+
| Pointer Events | Unified mouse/touch/pen handling | Falls back to separate mouse + touch listeners; same end behaviour |
|
|
448
|
+
|
|
449
|
+
#### APIs that may need polyfills
|
|
450
|
+
|
|
451
|
+
These APIs are used directly without fallbacks. They're widely supported in modern browsers, but very old environments may need polyfills:
|
|
452
|
+
|
|
453
|
+
| API | Used for |
|
|
454
|
+
| ----------------------- | ---------------------------------------- |
|
|
455
|
+
| `fetch()` | Network image loading |
|
|
456
|
+
| `Promise` | Async operations throughout |
|
|
457
|
+
| `Map` / `Set` | Caching, deduplication, pointer tracking |
|
|
458
|
+
| `URL` constructor | Parsing and validating image URLs |
|
|
459
|
+
| `requestAnimationFrame` | Smooth animations |
|
|
460
|
+
|
|
461
|
+
## Development
|
|
462
|
+
|
|
463
|
+
See CONTRIBUTING.md for the build, test, and release workflow, including npm scripts, linting, and publishing guidance.
|
|
464
|
+
|
|
465
|
+
## TypeScript
|
|
466
|
+
|
|
467
|
+
TypeScript definitions are included in the package via `index.d.ts`. The types are automatically picked up by TypeScript-aware editors and bundlers.
|
|
468
|
+
|
|
469
|
+
## Resources
|
|
470
|
+
|
|
471
|
+
- Hosted documentation (guides, API reference, option matrix): https://js.histropedia.com/documentation
|
|
472
|
+
- Event payload reference: docs/events.md
|
|
473
|
+
- Contribution workflow: CONTRIBUTING.md
|
|
474
|
+
- Security policy: SECURITY.md
|
|
475
|
+
|
|
476
|
+
## License
|
|
477
|
+
|
|
478
|
+
This package is distributed under a custom HistropediaJS license. Please review the full terms at: [https://js.histropedia.com/licence](https://js.histropedia.com/licence).
|
|
479
|
+
|
|
480
|
+
For repository consumers, a `LICENSE` stub is included pointing to the hosted license text. Commercial use or redistribution may require additional permissions - contact us if unsure.
|