swf2es 0.0.0 → 0.1.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 +202 -0
- package/LICENSE.third-party +899 -0
- package/README.md +95 -2
- package/dist/chunks/af343f894cedbf3e.js +2 -0
- package/dist/chunks/af343f894cedbf3e.js.map +1 -0
- package/dist/chunks/b66880f335048cfe.js +956 -0
- package/dist/chunks/b66880f335048cfe.js.map +1 -0
- package/dist/chunks/b6c820debc54f75c.js +2 -0
- package/dist/chunks/b6c820debc54f75c.js.map +1 -0
- package/dist/codegen.wasm +0 -0
- package/dist/swf2es.js +23 -0
- package/dist/swf2es.js.map +1 -0
- package/dist/worker.js +16 -0
- package/dist/worker.js.map +1 -0
- package/package.json +37 -6
package/README.md
CHANGED
|
@@ -1,5 +1,98 @@
|
|
|
1
1
|
# swf2es
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Plays SWF files on a web page from one `<script>` tag: the
|
|
4
|
+
`<swf2es-player>` element, `replaceFlash` and `watchFlash` for a page's
|
|
5
|
+
Flash tags, and ExternalInterface. It is
|
|
6
|
+
[`@swf2es/web`](https://www.npmjs.com/package/@swf2es/web) and the rest of
|
|
7
|
+
[swf2es](https://github.com/swf2es/swf2es) bundled into a folder of ES
|
|
8
|
+
modules that loads from a CDN, with nothing to install or build. A page
|
|
9
|
+
that has a bundler installs `@swf2es/web` instead.
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
```html
|
|
12
|
+
<script type="module" src="https://unpkg.com/swf2es@0.1.0"></script>
|
|
13
|
+
|
|
14
|
+
<swf2es-player src="movie.swf" width="800" height="600"></swf2es-player>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
jsDelivr serves it too, at `https://cdn.jsdelivr.net/npm/swf2es@0.1.0`.
|
|
18
|
+
The module exports what `@swf2es/web` does. To call it, import it from the
|
|
19
|
+
same URL, so that the page has one copy:
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<script type="module">
|
|
23
|
+
import { configure, watchFlash } from "https://unpkg.com/swf2es@0.1.0";
|
|
24
|
+
|
|
25
|
+
configure({ cache: true }); // keep compiled modules in IndexedDB
|
|
26
|
+
watchFlash(); // the page's Flash <object> and <embed> tags become players
|
|
27
|
+
</script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Players already in the markup start as the module loads, before any
|
|
31
|
+
script that imports it runs, so a page that configures its players adds
|
|
32
|
+
them from that script, after `configure`.
|
|
33
|
+
|
|
34
|
+
## Versions
|
|
35
|
+
|
|
36
|
+
Name a version in the URL. Until 1.0, a minor release (0.2) may change
|
|
37
|
+
what a page sees, so pin at least the minor version: unpkg's
|
|
38
|
+
`swf2es@0.1` takes 0.1's fixes as they are released, and redirects to the
|
|
39
|
+
exact version, whose files the page then loads together. On jsDelivr, pin
|
|
40
|
+
the exact version (`swf2es@0.1.0`): it serves a range without
|
|
41
|
+
redirecting, so the files the main one loads later would come from
|
|
42
|
+
whatever version the range names by then.
|
|
43
|
+
|
|
44
|
+
## What it loads
|
|
45
|
+
|
|
46
|
+
`swf2es.js` defines the element (1.8 MB, 0.7 MB compressed). The rest
|
|
47
|
+
lies beside it and loads as a page needs it: `codegen.wasm`, the
|
|
48
|
+
compiler, the renderer's chunk and the Flash Workers' host, a small one,
|
|
49
|
+
with the first player; `worker.js` only for a SWF that uses workers;
|
|
50
|
+
Stage3D's chunk only on a page that configures it (experimental).
|
|
51
|
+
|
|
52
|
+
## Content-Security-Policy
|
|
53
|
+
|
|
54
|
+
A page with a CSP needs, in `script-src`:
|
|
55
|
+
|
|
56
|
+
- the CDN's origin (`https://unpkg.com`);
|
|
57
|
+
- `'wasm-unsafe-eval'`, for its WebAssembly: the compiler, and the native
|
|
58
|
+
code that draws and decodes;
|
|
59
|
+
- `'unsafe-eval'`, for the JavaScript the SWF's ActionScript is compiled
|
|
60
|
+
to. Without it, only modules compiled ahead of time play: see
|
|
61
|
+
[Compile ahead of time](https://swf2es.github.io/swf2es/docs/#compile-ahead-of-time).
|
|
62
|
+
|
|
63
|
+
and, for Flash Workers, `worker-src` with the CDN's origin and `blob:`: a
|
|
64
|
+
browser starts a worker only on a script of the page's origin, so swf2es
|
|
65
|
+
starts it on a `blob:` module of the page's that imports `worker.js`, and
|
|
66
|
+
a module worker's imports are held to `worker-src` too. If the policy sets
|
|
67
|
+
`connect-src` or `default-src`, the CDN's origin goes there as well, for
|
|
68
|
+
`codegen.wasm`, and so do the origins of the SWFs and what they load; if
|
|
69
|
+
it sets `style-src`, that needs `'unsafe-inline'`, for the element's
|
|
70
|
+
styles. For example:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
script-src 'self' https://unpkg.com 'unsafe-eval' 'wasm-unsafe-eval'; worker-src https://unpkg.com blob:
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Cross-origin isolation
|
|
77
|
+
|
|
78
|
+
Only a SWF whose workers share memory (a shareable ByteArray, Mutex,
|
|
79
|
+
Condition) needs a cross-origin isolated page, served with
|
|
80
|
+
`Cross-Origin-Opener-Policy: same-origin` and
|
|
81
|
+
`Cross-Origin-Embedder-Policy: credentialless` (or `require-corp`: unpkg
|
|
82
|
+
and jsDelivr send `Cross-Origin-Resource-Policy: cross-origin`).
|
|
83
|
+
Elsewhere workers pass messages, and sharing throws an error that says
|
|
84
|
+
so.
|
|
85
|
+
|
|
86
|
+
## Hosting it yourself
|
|
87
|
+
|
|
88
|
+
The package's `dist/` folder is the whole of it (`npm pack swf2es`, or
|
|
89
|
+
`node_modules/swf2es/dist/` after `npm install swf2es`). Serve it as it
|
|
90
|
+
is, anywhere, and load `dist/swf2es.js` from it: its files find one
|
|
91
|
+
another by relative URL. Serve `.wasm` as `application/wasm`. From
|
|
92
|
+
another origin, send `Access-Control-Allow-Origin` as a CDN does.
|
|
93
|
+
|
|
94
|
+
The [guide](https://swf2es.github.io/swf2es/docs/) covers the element's
|
|
95
|
+
attributes and options, workers, sockets, files and ExternalInterface.
|
|
96
|
+
|
|
97
|
+
Apache-2.0 with the notices of what it bundles from elsewhere
|
|
98
|
+
([LICENSE](LICENSE), [LICENSE.third-party](LICENSE.third-party)).
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const __rspack_esm_ids=[167];export const __webpack_modules__={5610(e,t,r){let n=new Map,o=new Map,a=new Map;function l(e){let t=function(e){try{return new Worker(e,{type:"module"})}catch(n){if(!(n instanceof DOMException&&"SecurityError"===n.name))throw n;let t=new URL(e,globalThis.location?.href).href,r=a.get(t);if(void 0===r){let e=`import ${JSON.stringify(t)};`;r=URL.createObjectURL(new Blob([e],{type:"text/javascript"})),a.set(t,r)}return new Worker(r,{type:"module"})}}(e);return t.postMessage({type:"ping"}),t}function s(e,t){let r=String(e),o=n.get(r);for(o||(o=[],n.set(r,o));o.length<t;){let t;try{t=l(e)}catch{break}let r=()=>{},n={worker:t,ready:!1,failed:null,settled:new Promise(e=>{r=e}),settle:()=>r()};t.onmessage=e=>{e.data?.type==="ready"&&(n.ready=!0,n.settle())},t.onerror=e=>{e.preventDefault(),n.failed=e.message,n.settle()},o.push(n)}return o}r.d(t,{},{webWorkerHost:function(e){let t,a,i=e.url??new URL(r(Object(function(){var e=Error("Cannot find module './thread/player-hosts/web-worker.js'");throw e.code="MODULE_NOT_FOUND",e}())),r.b),d=globalThis.navigator?.hardwareConcurrency,u=e.spares??Math.min(4,Math.max(2,d??2));t=String(i),null!==(a=o.get(t)??{count:0,idle:null}).idle&&(clearTimeout(a.idle),a.idle=null),a.count++,o.set(t,a);let c=s(i,u),p=!1;return{ready:Promise.all(c.map(e=>e.settled)).then(()=>{}),release(){if(!p){let e,t;p=!0,e=String(i),!(t=o.get(e))||--t.count>0||(t.idle=setTimeout(()=>{for(let t of n.get(e)??[])t.settle(),t.worker.terminate();n.delete(e),o.delete(e)},1e4))}},start(t,r,n){let o=function(e){for(let t of e.filter(e=>null!==e.failed))t.worker.terminate(),e.splice(e.indexOf(t),1);let t=Math.max(e.findIndex(e=>e.ready),0);return e.splice(t,1)[0]}(s(i,u)),a=o?.worker??l(i);s(i,u),a.onmessage=e=>{e.data?.type==="ready"?o?.settle():r(e.data)},a.onerror=e=>{e.preventDefault(),o?.settle(),a.terminate(),n(Error(`a background worker's thread failed: ${e.message}`))};let d={codegen:e.codegen,init:t};return a.postMessage(d),{post:e=>a.postMessage(e),terminate:()=>(o?.settle(),a.terminate(),new Promise(e=>setTimeout(e,8e3)))}}}}})}};
|
|
2
|
+
//# sourceMappingURL=af343f894cedbf3e.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks/af343f894cedbf3e.js","sources":["webpack://swf2es/../player-hosts/dist/workers.js"],"sourcesContent":["/**\n * How long after a Web Worker's terminate it is taken to have stopped. A\n * browser does not say, and Chrome lets a busy worker's script run on for\n * some seconds (2.5 to 4 s measured, in Chrome 156) before it stops it by\n * force; Firefox's and Safari's were not measured. The player stops a\n * terminated worker's thread so only when the worker has not stopped\n * itself first (scripting/workers.ts).\n */\nconst STOPPED_GRACE = 8000;\n/** The workers started ahead, by script URL. */\nconst pools = new Map();\n/** How many hosts not yet released use each pool, and the timer that lets an unused one go. */\nconst users = new Map();\n/** How long a pool no player uses keeps its workers, for the next player a page makes. */\nconst IDLE = 10_000;\nfunction use(url) {\n const key = String(url);\n const u = users.get(key) ?? { count: 0, idle: null };\n if (u.idle !== null) {\n clearTimeout(u.idle);\n u.idle = null;\n }\n u.count++;\n users.set(key, u);\n}\nfunction release(url) {\n const key = String(url);\n const u = users.get(key);\n if (!u || --u.count > 0) {\n return;\n }\n u.idle = setTimeout(() => {\n for (const spare of pools.get(key) ?? []) {\n spare.settle();\n spare.worker.terminate();\n }\n pools.delete(key);\n users.delete(key);\n }, IDLE);\n}\n/** The page's own modules that import a worker script from another origin, by its URL. */\nconst importers = new Map();\nfunction spawn(url) {\n const worker = construct(url);\n // Answered with \"ready\" once the page's messages reach the worker.\n worker.postMessage({ type: \"ping\" });\n return worker;\n}\nfunction construct(url) {\n try {\n return new Worker(url, { type: \"module\" });\n }\n catch (error) {\n // A browser starts a worker only on a script of the page's origin.\n if (!(error instanceof DOMException && error.name === \"SecurityError\")) {\n throw error;\n }\n const href = new URL(url, globalThis.location?.href).href;\n let importer = importers.get(href);\n if (importer === undefined) {\n const source = `import ${JSON.stringify(href)};`;\n importer = URL.createObjectURL(new Blob([source], { type: \"text/javascript\" }));\n importers.set(href, importer);\n }\n return new Worker(importer, { type: \"module\" });\n }\n}\n/** Keep `count` workers started ahead for `url`; where the page cannot start one, fewer. */\nfunction fill(url, count) {\n const key = String(url);\n let pool = pools.get(key);\n if (!pool) {\n pool = [];\n pools.set(key, pool);\n }\n while (pool.length < count) {\n let worker;\n try {\n worker = spawn(url);\n }\n catch {\n // A policy that forbids the script: start() reports it.\n break;\n }\n let settle = () => { };\n const spare = {\n worker,\n ready: false,\n failed: null,\n settled: new Promise((resolve) => {\n settle = resolve;\n }),\n settle: () => settle(),\n };\n worker.onmessage = (event) => {\n if (event.data?.type === \"ready\") {\n spare.ready = true;\n spare.settle();\n }\n };\n worker.onerror = (event) => {\n event.preventDefault();\n spare.failed = event.message;\n spare.settle();\n };\n pool.push(spare);\n }\n return pool;\n}\n/** The pool's first worker that has loaded, else its first that has not failed. */\nfunction take(pool) {\n for (const spare of pool.filter((s) => s.failed !== null)) {\n spare.worker.terminate();\n pool.splice(pool.indexOf(spare), 1);\n }\n const at = Math.max(pool.findIndex((s) => s.ready), 0);\n return pool.splice(at, 1)[0];\n}\n/** Background workers on module Web Workers. */\nexport function webWorkerHost(options) {\n const url = options.url ?? new URL(\"./thread/player-hosts/web-worker.js\", import.meta.url);\n const cores = globalThis.navigator\n ?.hardwareConcurrency;\n const spares = options.spares ?? Math.min(4, Math.max(2, cores ?? 2));\n use(url);\n const pool = fill(url, spares);\n let released = false;\n return {\n ready: Promise.all(pool.map((s) => s.settled)).then(() => { }),\n release() {\n if (!released) {\n released = true;\n release(url);\n }\n },\n start(init, receive, failed) {\n const spare = take(fill(url, spares));\n const worker = spare?.worker ?? spawn(url);\n // One in its place, loaded once the page's thread is free.\n fill(url, spares);\n // Taken before it loaded, it still settles the ready of the host that started it ahead.\n worker.onmessage = (event) => {\n // A worker taken before it loaded says so first.\n if (event.data?.type === \"ready\") {\n spare?.settle();\n }\n else {\n receive(event.data);\n }\n };\n worker.onerror = (event) => {\n event.preventDefault();\n spare?.settle();\n worker.terminate();\n failed(new Error(`a background worker's thread failed: ${event.message}`));\n };\n const start = { codegen: options.codegen, init };\n worker.postMessage(start);\n return {\n post: (message) => worker.postMessage(message),\n // A browser tells nobody when a Web Worker has stopped.\n terminate: () => {\n spare?.settle();\n worker.terminate();\n return new Promise((resolve) => setTimeout(resolve, STOPPED_GRACE));\n },\n };\n },\n };\n}\n//# sourceMappingURL=workers.js.map"],"names":["Map","Worker","DOMException","URL","globalThis","JSON","Blob","String","Promise","e","Math","clearTimeout","setTimeout","r","Error"],"mappings":"kFAUA,IAAM,EAAQ,IAAIA,IAEZ,EAAQ,IAAIA,IA6BZ,EAAY,IAAIA,IACtB,SAAS,EAAM,CAAG,EACd,IAAM,EAAS,AAKnB,SAAmB,CAAG,EAClB,GAAI,CACA,OAAO,IAAIC,OAAO,EAAK,CAAE,KAAM,QAAS,EAC5C,CACA,MAAO,EAAO,CAEV,GAAI,CAAE,cAAiBC,cAAgB,AAAe,kBAAf,EAAM,IAAI,AAAmB,EAChE,MAAM,EAEV,IAAM,EAAO,IAAIC,IAAI,EAAKC,WAAW,QAAQ,EAAE,MAAM,IAAI,CACrD,EAAW,EAAU,GAAG,CAAC,GAC7B,GAAI,AAAa,SAAb,EAAwB,CACxB,IAAM,EAAS,CAAC,OAAO,EAAEC,KAAK,SAAS,CAAC,GAAM,CAAC,CAAC,CAChD,EAAWF,IAAI,eAAe,CAAC,IAAIG,KAAK,CAAC,EAAO,CAAE,CAAE,KAAM,iBAAkB,IAC5E,EAAU,GAAG,CAAC,EAAM,EACxB,CACA,OAAO,IAAIL,OAAO,EAAU,CAAE,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