@missing-elements/h5p-embed 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/site/embed.js +24 -7
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ To update, run the command again with `--force` and redeploy.
|
|
|
77
77
|
|
|
78
78
|
| Parameter | Effect |
|
|
79
79
|
|---|---|
|
|
80
|
-
| `src=<url>` | The package, required. Encode `&`, `#`, `+`, `%` and spaces |
|
|
80
|
+
| `src=<url>` | The package, required: an `http` or `https` URL, or a path on the player domain. Encode `&`, `#`, `+`, `%` and spaces |
|
|
81
81
|
| `libraries=pack`, `<url>` or `none` | Where libraries come from; several are tried in order. `pack` is this domain's copy, or jsDelivr's without one: a package gets the libraries it lacks from it, and those it carries at the pack's newer versions. `none` turns off `--default-libraries` |
|
|
82
82
|
| `refresh-libraries=off` | Play the libraries a package carries as exported; `pack` then only fills gaps |
|
|
83
83
|
| `frame`, `copyright`, `export`, `icon`, `reporting` | H5P's action bar and its buttons |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@missing-elements/h5p-embed",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Self-hosted H5P embeds: writes the H5P embed page as a static site for a player domain of your own, then any site frames it with an iframe and one script line. No H5P server, no third-party service; optional allowlists for package hosts and embedding sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/site/embed.js
CHANGED
|
@@ -256,6 +256,22 @@ export function startEmbed({ packBase = null, pack = null, librariesPack = null,
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
/**
|
|
260
|
+
* A package's address as the element is given it: resolved against this page, and only when it
|
|
261
|
+
* is `http` or `https`. `null` for anything else, a `javascript:` or `data:` URL or text that is
|
|
262
|
+
* not a URL. The element gets the parsed URL's `href`, never the text, so `src` holds what was
|
|
263
|
+
* checked.
|
|
264
|
+
* @param {string} value
|
|
265
|
+
*/
|
|
266
|
+
const packageUrl = (value) => {
|
|
267
|
+
try {
|
|
268
|
+
const url = new URL(value, location.href)
|
|
269
|
+
return url.protocol === 'http:' || url.protocol === 'https:' ? url : null
|
|
270
|
+
} catch {
|
|
271
|
+
return null
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
259
275
|
const allowed = packages ? new Set(packages) : null
|
|
260
276
|
/**
|
|
261
277
|
* Whether this player was told it may fetch from `origin`. Always true without a list.
|
|
@@ -355,11 +371,12 @@ export function startEmbed({ packBase = null, pack = null, librariesPack = null,
|
|
|
355
371
|
refuse('No package given. Add ?src=<url of a .h5p file> to the address.', 'no-src')
|
|
356
372
|
return
|
|
357
373
|
}
|
|
358
|
-
const
|
|
359
|
-
if (!
|
|
360
|
-
refuse('The package address is not
|
|
374
|
+
const address = packageUrl(src)
|
|
375
|
+
if (!address) {
|
|
376
|
+
refuse('The package address is not an http or https URL.')
|
|
361
377
|
return
|
|
362
378
|
}
|
|
379
|
+
const { origin } = address
|
|
363
380
|
if (!permitted(origin)) {
|
|
364
381
|
refuse(`This player does not play packages from ${origin}.`)
|
|
365
382
|
return
|
|
@@ -375,14 +392,14 @@ export function startEmbed({ packBase = null, pack = null, librariesPack = null,
|
|
|
375
392
|
// A host on the list was vouched for when the site was set up, and in another site's frame the
|
|
376
393
|
// storage is that site's own: those play as they are.
|
|
377
394
|
if (origin === location.origin || allowed || !sharesOriginStorage()) {
|
|
378
|
-
start(
|
|
395
|
+
start(address.href, sources.value)
|
|
379
396
|
return
|
|
380
397
|
}
|
|
381
398
|
|
|
382
399
|
// Anything else from another origin would share this origin's storage. It plays untrusted, as
|
|
383
400
|
// data with the library pack's code and none of its own, and waits for a click that names the
|
|
384
401
|
// host only when it cannot play without its own, or there is no pack to play it with.
|
|
385
|
-
const host =
|
|
402
|
+
const { host } = address
|
|
386
403
|
askToTrust = () => {
|
|
387
404
|
loader.hidden = true
|
|
388
405
|
const button = document.createElement('button')
|
|
@@ -393,7 +410,7 @@ export function startEmbed({ packBase = null, pack = null, librariesPack = null,
|
|
|
393
410
|
loader.hidden = false
|
|
394
411
|
player.untrusted = false
|
|
395
412
|
player.removeAttribute('src')
|
|
396
|
-
start(
|
|
413
|
+
start(address.href, sources.value)
|
|
397
414
|
})
|
|
398
415
|
say(
|
|
399
416
|
`This package from ${host} plays only with its own scripts. They would run on this site and ` +
|
|
@@ -411,5 +428,5 @@ export function startEmbed({ packBase = null, pack = null, librariesPack = null,
|
|
|
411
428
|
return
|
|
412
429
|
}
|
|
413
430
|
player.untrusted = true
|
|
414
|
-
start(
|
|
431
|
+
start(address.href, sitesSources)
|
|
415
432
|
}
|