@swf2es/web 0.1.32 → 0.1.33

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 CHANGED
@@ -32,6 +32,19 @@ import { watchFlash } from "@swf2es/web";
32
32
  watchFlash();
33
33
  ```
34
34
 
35
+ For the page's scripts that look for Flash before they write its tags,
36
+ as swfobject does, `watchFlash` also lists Flash Player's plug-in,
37
+ "Shockwave Flash 32.0 r0", in `navigator.plugins` and its MIME types in
38
+ `navigator.mimeTypes`, after the browser's own entries;
39
+ `watchFlash(document, { plugin: false })` leaves it out, and
40
+ `replaceFlash`, which swaps only the tags there now, lists it only with
41
+ `{ plugin: true }`. A script that looks before `watchFlash` runs needs
42
+ `installFlashPlugin` first, from `@swf2es/web/plugin` in a classic script
43
+ ahead of it. The
44
+ [guide](https://swf2es.github.io/swf2es/docs/#replace-the-flash-tags-on-an-existing-page)
45
+ says how, and when to leave the plug-in out: some libraries pick their
46
+ SWF over HTML5 that works once they find Flash.
47
+
35
48
  ActionScript 3 needs no setup: builtin.abc and swf2es's own playerglobal
36
49
  ship with the packages. The packages are ES modules: serve them through a
37
50
  bundler or an import map. The page must let them compile WebAssembly
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { ExternalInterfaceError, type PageValue } from "./external.js";
7
7
  export { type Placement, place, type ScaleMode, scaleMode } from "./layout.js";
8
8
  export type { MeterCorner } from "./meter.js";
9
9
  export type { FrameListener, FrameStats } from "./playback.js";
10
- export { flashAttributes, isFlash, replaceFlash, watchFlash } from "./replace.js";
10
+ export { installFlashPlugin } from "./plugin.js";
11
+ export { flashAttributes, isFlash, type ReplaceOptions, replaceFlash, watchFlash, } from "./replace.js";
11
12
  export type { Stage3DSurfaceFactory, Stage3DSurfaceLoader } from "./stage3d.js";
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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gBAAgB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,KAAK,SAAS,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/E,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,eAAe,EACf,OAAO,EACP,KAAK,cAAc,EACnB,YAAY,EACZ,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * swf2es on any web page: the `<swf2es-player>` element, defined as this
3
3
  * module loads where there is a DOM, `replaceFlash` for a page's Flash
4
- * tags, `openAirApp` for an AIR application the element plays, and the
5
- * page's one configuration.
4
+ * tags and `installFlashPlugin` for its scripts that look for Flash,
5
+ * `openAirApp` for an AIR application the element plays, and the page's
6
+ * one configuration.
6
7
  */
7
8
  import { defineElement } from "./element.js";
8
9
  // Whether a page's own file inputs should go without a type filter, which iOS's pickers grey
@@ -14,6 +15,7 @@ export { configuration, configure, } from "./config.js";
14
15
  export { defineElement, Swf2esPlayerElement, TAG } from "./element.js";
15
16
  export { ExternalInterfaceError } from "./external.js";
16
17
  export { place, scaleMode } from "./layout.js";
17
- export { flashAttributes, isFlash, replaceFlash, watchFlash } from "./replace.js";
18
+ export { installFlashPlugin } from "./plugin.js";
19
+ export { flashAttributes, isFlash, replaceFlash, watchFlash, } from "./replace.js";
18
20
  defineElement();
19
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,6FAA6F;AAC7F,gBAAgB;AAChB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAmB,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAqB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAEL,aAAa,EACb,SAAS,GAGV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAkB,GAAG,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAkB,MAAM,eAAe,CAAC;AACvE,OAAO,EAAkB,KAAK,EAAkB,SAAS,EAAE,MAAM,aAAa,CAAC;AAG/E,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGlF,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,6FAA6F;AAC7F,gBAAgB;AAChB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAmB,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAqB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAEL,aAAa,EACb,SAAS,GAGV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAkB,GAAG,EAAE,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAkB,MAAM,eAAe,CAAC;AACvE,OAAO,EAAkB,KAAK,EAAkB,SAAS,EAAE,MAAM,aAAa,CAAC;AAG/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,eAAe,EACf,OAAO,EAEP,YAAY,EACZ,UAAU,GACX,MAAM,cAAc,CAAC;AAGtB,aAAa,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Lists Flash Player's plug-in, "Shockwave Flash 32.0 r0", in
3
+ * `navigator.plugins` and its MIME types in `navigator.mimeTypes`, after
4
+ * the browser's own, for scripts that look for Flash before they embed a
5
+ * SWF. watchFlash calls it, and replaceFlash when asked; the browser
6
+ * build's `dist/plugin.js` does as it loads, for a page's scripts that run
7
+ * before a module. Once a page: where a Flash plug-in is listed already,
8
+ * this does nothing, and where navigator is not a browser's, it throws
9
+ * nothing.
10
+ */
11
+ export declare function installFlashPlugin(): void;
12
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AA4JA;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAMzC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,158 @@
1
+ // Flash Player's plug-in as navigator lists it, for old pages' scripts
2
+ // that look for one before they write a Flash tag (swfobject, Adobe's
3
+ // detection kit): without it they write "Flash Player required" in the
4
+ // tag's place, and replaceFlash finds nothing to swap. One plug-in,
5
+ // "Shockwave Flash" of the version Capabilities.version reports, with its
6
+ // two MIME types; the browser's own entries stay listed as they were.
7
+ //
8
+ // No ActiveXObject, though some scripts try it: old scripts take a page
9
+ // that has one for Internet Explorer, and use its XML and DOM paths for
10
+ // everything else too. Every detection script asks navigator first.
11
+ //
12
+ // This file imports nothing, so that the browser build's classic script
13
+ // (packages/swf2es/src/plugin.ts) installs it alone, before a page's
14
+ // scripts run.
15
+ const NAME = "Shockwave Flash";
16
+ /** Capabilities.version's numbers (platformCapabilities in @swf2es/player): 32,0,0,465. */
17
+ const VERSION = [32, 0, 0, 465];
18
+ /** As Flash's plug-in described itself: major.minor and the revision, not the build. */
19
+ const DESCRIPTION = `${NAME} ${VERSION[0]}.${VERSION[1]} r${VERSION[2]}`;
20
+ /** Flash's plug-in's MIME types, in its order. */
21
+ const MIME_TYPES = [
22
+ ["application/x-shockwave-flash", "Shockwave Flash", "swf"],
23
+ ["application/futuresplash", "FutureSplash Player", "spl"],
24
+ ];
25
+ /** Read-only and left out of enumeration, as the browser's names and members. */
26
+ const hidden = (value) => ({ value, configurable: true });
27
+ /**
28
+ * An object of `proto`'s class listing `entries` as the browser's
29
+ * PluginArray, MimeTypeArray and Plugin do: by index, enumerable, and by
30
+ * name, not, with `length`, `item`, `namedItem` and iteration of its own,
31
+ * as the class's own would throw on an object the browser did not make.
32
+ */
33
+ function listing(proto, entries, nameOf, more = {}) {
34
+ const list = Object.create(proto);
35
+ for (let i = 0; i < entries.length; i++) {
36
+ Object.defineProperty(list, i, { value: entries[i], enumerable: true, configurable: true });
37
+ }
38
+ for (const entry of entries) {
39
+ const name = nameOf(entry);
40
+ if (!Object.hasOwn(list, name)) {
41
+ Object.defineProperty(list, name, hidden(entry));
42
+ }
43
+ }
44
+ Object.defineProperties(list, {
45
+ length: { get: () => entries.length, configurable: true },
46
+ // The index as the browser's, an unsigned 32-bit integer.
47
+ item: hidden((index) => entries[index >>> 0] ?? null),
48
+ namedItem: hidden((name) => entries.find((entry) => nameOf(entry) === String(name)) ?? null),
49
+ [Symbol.iterator]: hidden(() => entries.values()),
50
+ ...more,
51
+ });
52
+ return list;
53
+ }
54
+ /** A listing's entries, by `item`, which every browser's has. */
55
+ function entriesOf(list) {
56
+ const entries = [];
57
+ for (let i = 0; i < list.length; i++) {
58
+ const entry = list.item(i);
59
+ if (entry) {
60
+ entries.push(entry);
61
+ }
62
+ }
63
+ return entries;
64
+ }
65
+ const prototypeOf = (name) => globalThis[name]?.prototype ??
66
+ Object.prototype;
67
+ /**
68
+ * Lists `added` after the entries of navigator's `key`: a listing of both
69
+ * in its place, or, where navigator will not take one, `added` defined on
70
+ * the browser's listing itself by name, and in its `length`, `item` and
71
+ * iteration only where it takes them by index too, which Chrome's and
72
+ * Firefox's do not: a loop to `length` would read past what it indexes.
73
+ */
74
+ function extend(navigator, key, added, nameOf, more) {
75
+ const own = navigator[key];
76
+ const entries = [...entriesOf(own), ...added];
77
+ try {
78
+ Object.defineProperty(navigator, key, {
79
+ value: listing(Object.getPrototypeOf(own), entries, nameOf, more(own)),
80
+ configurable: true,
81
+ enumerable: true,
82
+ });
83
+ return;
84
+ }
85
+ catch {
86
+ // Not configurable, or navigator not extensible: the listing it has, then.
87
+ }
88
+ try {
89
+ const first = own.length;
90
+ let indexed = true;
91
+ for (let i = 0; i < added.length; i++) {
92
+ try {
93
+ Object.defineProperty(own, first + i, { value: added[i], configurable: true });
94
+ }
95
+ catch {
96
+ indexed = false;
97
+ }
98
+ Object.defineProperty(own, nameOf(added[i]), hidden(added[i]));
99
+ }
100
+ const { item, namedItem } = own;
101
+ Object.defineProperty(own, "namedItem", hidden((name) => namedItem.call(own, name) ??
102
+ added.find((entry) => nameOf(entry) === String(name)) ??
103
+ null));
104
+ if (indexed) {
105
+ Object.defineProperties(own, {
106
+ length: { get: () => entries.length, configurable: true },
107
+ item: hidden((index) => index >>> 0 < first ? item.call(own, index) : (entries[index >>> 0] ?? null)),
108
+ [Symbol.iterator]: hidden(() => entries.values()),
109
+ });
110
+ }
111
+ }
112
+ catch {
113
+ // A frozen listing: nothing to be done.
114
+ }
115
+ }
116
+ /**
117
+ * Lists Flash Player's plug-in, "Shockwave Flash 32.0 r0", in
118
+ * `navigator.plugins` and its MIME types in `navigator.mimeTypes`, after
119
+ * the browser's own, for scripts that look for Flash before they embed a
120
+ * SWF. watchFlash calls it, and replaceFlash when asked; the browser
121
+ * build's `dist/plugin.js` does as it loads, for a page's scripts that run
122
+ * before a module. Once a page: where a Flash plug-in is listed already,
123
+ * this does nothing, and where navigator is not a browser's, it throws
124
+ * nothing.
125
+ */
126
+ export function installFlashPlugin() {
127
+ try {
128
+ install();
129
+ }
130
+ catch {
131
+ // A navigator of a test's or a server's DOM, without the browser's listings' members.
132
+ }
133
+ }
134
+ function install() {
135
+ const navigator = globalThis.navigator;
136
+ if (!navigator?.plugins || !navigator.mimeTypes || navigator.plugins.namedItem(NAME)) {
137
+ return;
138
+ }
139
+ const mimePrototype = prototypeOf("MimeType");
140
+ const mimeTypes = MIME_TYPES.map(([type, description, suffixes]) => Object.create(mimePrototype, {
141
+ type: hidden(type),
142
+ description: hidden(description),
143
+ suffixes: hidden(suffixes),
144
+ enabledPlugin: { get: () => plugin, configurable: true },
145
+ }));
146
+ const plugin = listing(prototypeOf("Plugin"), mimeTypes, (mime) => mime.type, {
147
+ name: hidden(NAME),
148
+ description: hidden(DESCRIPTION),
149
+ filename: hidden("swf2es.js"),
150
+ });
151
+ extend(navigator, "plugins", [plugin], (entry) => entry.name, (own) => {
152
+ // The browser's own, as it was.
153
+ const refresh = own.refresh;
154
+ return typeof refresh === "function" ? { refresh: hidden(refresh.bind(own)) } : {};
155
+ });
156
+ extend(navigator, "mimeTypes", mimeTypes, (entry) => entry.type, () => ({}));
157
+ }
158
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,sEAAsE;AACtE,uEAAuE;AACvE,oEAAoE;AACpE,0EAA0E;AAC1E,sEAAsE;AACtE,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,oEAAoE;AACpE,EAAE;AACF,wEAAwE;AACxE,qEAAqE;AACrE,eAAe;AAEf,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAC/B,2FAA2F;AAC3F,MAAM,OAAO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CAAC,EAAE,CAAC,CACX,CAAC;AACJ,CAAC"}
package/dist/replace.d.ts CHANGED
@@ -1,4 +1,15 @@
1
1
  import { type Swf2esPlayerElement } from "./element.js";
2
+ /** What replaceFlash and watchFlash do besides swapping the tags. */
3
+ export interface ReplaceOptions {
4
+ /**
5
+ * Whether navigator lists Flash Player's plug-in (installFlashPlugin),
6
+ * for the page's scripts that look for it before they write a Flash
7
+ * tag: true by default for watchFlash, which swaps the tags they write;
8
+ * false for replaceFlash, which swaps only the tags there now, so that
9
+ * a page's later look for Flash does not write tags nothing swaps.
10
+ */
11
+ plugin?: boolean;
12
+ }
2
13
  /** Whether `element` is a Flash <object> or <embed>: by its type, its ActiveX class, or a .swf for its movie. */
3
14
  export declare function isFlash(element: Element): boolean;
4
15
  /**
@@ -11,12 +22,14 @@ export declare function flashAttributes(outer: Element): Map<string, string>;
11
22
  /**
12
23
  * Swap each Flash <object> and <embed> under `root` for a <swf2es-player>
13
24
  * carrying its parameters, in its place: the outermost of nested ones, its
14
- * fallbacks going with it. Returns the elements made.
25
+ * fallbacks going with it, and list Flash's plug-in in navigator if
26
+ * `options.plugin` is true. Returns the elements made.
15
27
  */
16
- export declare function replaceFlash(root?: ParentNode): Swf2esPlayerElement[];
28
+ export declare function replaceFlash(root?: ParentNode, options?: ReplaceOptions): Swf2esPlayerElement[];
17
29
  /**
18
30
  * replaceFlash now, and again for each Flash tag the page adds under `root`
19
- * later, until the returned function is called.
31
+ * later, until the returned function is called; Flash's plug-in listed in
32
+ * navigator unless `options.plugin` is false.
20
33
  */
21
- export declare function watchFlash(root?: ParentNode & Node): () => void;
34
+ export declare function watchFlash(root?: ParentNode & Node, options?: ReplaceOptions): () => void;
22
35
  //# sourceMappingURL=replace.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../src/replace.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,mBAAmB,EAAO,MAAM,cAAc,CAAC;AA4C5E,iHAAiH;AACjH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAiBjD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBnE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,UAAqB,GAAG,mBAAmB,EAAE,CAkC/E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,UAAU,GAAG,IAAe,GAAG,MAAM,IAAI,CAuBzE"}
1
+ {"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../src/replace.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,mBAAmB,EAAO,MAAM,cAAc,CAAC;AAG5E,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AA4CD,iHAAiH;AACjH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAiBjD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBnE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,GAAE,UAAqB,EAC3B,OAAO,GAAE,cAAmB,GAC3B,mBAAmB,EAAE,CAsCvB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,IAAI,GAAE,UAAU,GAAG,IAAe,EAClC,OAAO,GAAE,cAAmB,GAC3B,MAAM,IAAI,CAuBZ"}
package/dist/replace.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // with what they told Flash: the movie, its FlashVars, how it is shown
3
3
  // and scripted, its size, and the id and name the page's scripts find it by.
4
4
  import { defineElement, TAG } from "./element.js";
5
+ import { installFlashPlugin } from "./plugin.js";
5
6
  const FLASH_TYPES = new Set([
6
7
  "application/x-shockwave-flash",
7
8
  "application/futuresplash",
@@ -83,13 +84,17 @@ export function flashAttributes(outer) {
83
84
  /**
84
85
  * Swap each Flash <object> and <embed> under `root` for a <swf2es-player>
85
86
  * carrying its parameters, in its place: the outermost of nested ones, its
86
- * fallbacks going with it. Returns the elements made.
87
+ * fallbacks going with it, and list Flash's plug-in in navigator if
88
+ * `options.plugin` is true. Returns the elements made.
87
89
  */
88
- export function replaceFlash(root = document) {
90
+ export function replaceFlash(root = document, options = {}) {
89
91
  // Where it cannot be defined, a tag swapped for it would play nothing.
90
92
  if (!defineElement()) {
91
93
  return [];
92
94
  }
95
+ if (options.plugin === true) {
96
+ installFlashPlugin();
97
+ }
93
98
  const made = [];
94
99
  const tags = [...root.querySelectorAll("object, embed")];
95
100
  if (root instanceof Element && (root.localName === "object" || root.localName === "embed")) {
@@ -116,10 +121,11 @@ export function replaceFlash(root = document) {
116
121
  }
117
122
  /**
118
123
  * replaceFlash now, and again for each Flash tag the page adds under `root`
119
- * later, until the returned function is called.
124
+ * later, until the returned function is called; Flash's plug-in listed in
125
+ * navigator unless `options.plugin` is false.
120
126
  */
121
- export function watchFlash(root = document) {
122
- replaceFlash(root);
127
+ export function watchFlash(root = document, options = {}) {
128
+ replaceFlash(root, { plugin: options.plugin !== false });
123
129
  const observer = new MutationObserver((mutations) => {
124
130
  for (const mutation of mutations) {
125
131
  // A tag added, or one made Flash after it was added, its src or type set by a script.
@@ -128,7 +134,7 @@ export function watchFlash(root = document) {
128
134
  // A <param>'s tag is its <object>.
129
135
  const tag = node instanceof Element && node.localName === "param" ? node.parentElement : node;
130
136
  if (tag instanceof Element && tag.isConnected) {
131
- replaceFlash(tag);
137
+ replaceFlash(tag, { plugin: false });
132
138
  }
133
139
  }
134
140
  }
@@ -1 +1 @@
1
- {"version":3,"file":"replace.js","sourceRoot":"","sources":["../src/replace.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,uEAAuE;AACvE,6EAA6E;AAC7E,OAAO,EAAE,aAAa,EAA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C,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;YACvF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,mCAAmC;gBACnC,MAAM,GAAG,GACP,IAAI,YAAY,OAAO,IAAI,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;gBACpF,IAAI,GAAG,YAAY,OAAO,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC9C,YAAY,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QACrB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC;KAC7D,CAAC,CAAC;IACH,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;AACrC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swf2es/web",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "Plays SWFs on any web page: the <swf2es-player> element, replaceFlash and ExternalInterface",
5
5
  "keywords": [
6
6
  "swf",
@@ -24,6 +24,10 @@
24
24
  ".": {
25
25
  "types": "./dist/index.d.ts",
26
26
  "default": "./dist/index.js"
27
+ },
28
+ "./plugin": {
29
+ "types": "./dist/plugin.d.ts",
30
+ "default": "./dist/plugin.js"
27
31
  }
28
32
  },
29
33
  "files": [
@@ -32,9 +36,9 @@
32
36
  "src"
33
37
  ],
34
38
  "dependencies": {
35
- "@swf2es/codegen": "0.1.32",
36
- "@swf2es/player": "0.1.32",
37
- "@swf2es/format": "0.1.32",
38
- "@swf2es/player-hosts": "0.1.32"
39
+ "@swf2es/codegen": "0.1.33",
40
+ "@swf2es/format": "0.1.33",
41
+ "@swf2es/player": "0.1.33",
42
+ "@swf2es/player-hosts": "0.1.33"
39
43
  }
40
44
  }
package/src/index.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * swf2es on any web page: the `<swf2es-player>` element, defined as this
3
3
  * module loads where there is a DOM, `replaceFlash` for a page's Flash
4
- * tags, `openAirApp` for an AIR application the element plays, and the
5
- * page's one configuration.
4
+ * tags and `installFlashPlugin` for its scripts that look for Flash,
5
+ * `openAirApp` for an AIR application the element plays, and the page's
6
+ * one configuration.
6
7
  */
7
8
  import { defineElement } from "./element.js";
8
9
 
@@ -23,7 +24,14 @@ export { ExternalInterfaceError, type PageValue } from "./external.js";
23
24
  export { type Placement, place, type ScaleMode, scaleMode } from "./layout.js";
24
25
  export type { MeterCorner } from "./meter.js";
25
26
  export type { FrameListener, FrameStats } from "./playback.js";
26
- export { flashAttributes, isFlash, replaceFlash, watchFlash } from "./replace.js";
27
+ export { installFlashPlugin } from "./plugin.js";
28
+ export {
29
+ flashAttributes,
30
+ isFlash,
31
+ type ReplaceOptions,
32
+ replaceFlash,
33
+ watchFlash,
34
+ } from "./replace.js";
27
35
  export type { Stage3DSurfaceFactory, Stage3DSurfaceLoader } from "./stage3d.js";
28
36
 
29
37
  defineElement();
package/src/plugin.ts ADDED
@@ -0,0 +1,214 @@
1
+ // Flash Player's plug-in as navigator lists it, for old pages' scripts
2
+ // that look for one before they write a Flash tag (swfobject, Adobe's
3
+ // detection kit): without it they write "Flash Player required" in the
4
+ // tag's place, and replaceFlash finds nothing to swap. One plug-in,
5
+ // "Shockwave Flash" of the version Capabilities.version reports, with its
6
+ // two MIME types; the browser's own entries stay listed as they were.
7
+ //
8
+ // No ActiveXObject, though some scripts try it: old scripts take a page
9
+ // that has one for Internet Explorer, and use its XML and DOM paths for
10
+ // everything else too. Every detection script asks navigator first.
11
+ //
12
+ // This file imports nothing, so that the browser build's classic script
13
+ // (packages/swf2es/src/plugin.ts) installs it alone, before a page's
14
+ // scripts run.
15
+
16
+ const NAME = "Shockwave Flash";
17
+ /** Capabilities.version's numbers (platformCapabilities in @swf2es/player): 32,0,0,465. */
18
+ const VERSION = [32, 0, 0, 465];
19
+ /** As Flash's plug-in described itself: major.minor and the revision, not the build. */
20
+ const DESCRIPTION = `${NAME} ${VERSION[0]}.${VERSION[1]} r${VERSION[2]}`;
21
+ /** Flash's plug-in's MIME types, in its order. */
22
+ const MIME_TYPES = [
23
+ ["application/x-shockwave-flash", "Shockwave Flash", "swf"],
24
+ ["application/futuresplash", "FutureSplash Player", "spl"],
25
+ ];
26
+
27
+ interface Listing<T> {
28
+ readonly length: number;
29
+ item(index: number): T | null;
30
+ namedItem(name: string): T | null;
31
+ [index: number]: T;
32
+ }
33
+
34
+ /** Read-only and left out of enumeration, as the browser's names and members. */
35
+ const hidden = (value: unknown): PropertyDescriptor => ({ value, configurable: true });
36
+
37
+ /**
38
+ * An object of `proto`'s class listing `entries` as the browser's
39
+ * PluginArray, MimeTypeArray and Plugin do: by index, enumerable, and by
40
+ * name, not, with `length`, `item`, `namedItem` and iteration of its own,
41
+ * as the class's own would throw on an object the browser did not make.
42
+ */
43
+ function listing<T extends object>(
44
+ proto: object | null,
45
+ entries: T[],
46
+ nameOf: (entry: T) => string,
47
+ more: PropertyDescriptorMap = {},
48
+ ): Listing<T> {
49
+ const list = Object.create(proto);
50
+ for (let i = 0; i < entries.length; i++) {
51
+ Object.defineProperty(list, i, { value: entries[i], enumerable: true, configurable: true });
52
+ }
53
+
54
+ for (const entry of entries) {
55
+ const name = nameOf(entry);
56
+ if (!Object.hasOwn(list, name)) {
57
+ Object.defineProperty(list, name, hidden(entry));
58
+ }
59
+ }
60
+
61
+ Object.defineProperties(list, {
62
+ length: { get: () => entries.length, configurable: true },
63
+ // The index as the browser's, an unsigned 32-bit integer.
64
+ item: hidden((index: number) => entries[index >>> 0] ?? null),
65
+ namedItem: hidden(
66
+ (name: string) => entries.find((entry) => nameOf(entry) === String(name)) ?? null,
67
+ ),
68
+ [Symbol.iterator]: hidden(() => entries.values()),
69
+ ...more,
70
+ });
71
+ return list;
72
+ }
73
+
74
+ /** A listing's entries, by `item`, which every browser's has. */
75
+ function entriesOf<T>(list: Listing<T>): T[] {
76
+ const entries: T[] = [];
77
+ for (let i = 0; i < list.length; i++) {
78
+ const entry = list.item(i);
79
+ if (entry) {
80
+ entries.push(entry);
81
+ }
82
+ }
83
+
84
+ return entries;
85
+ }
86
+
87
+ const prototypeOf = (name: string): object =>
88
+ (globalThis as unknown as Record<string, { prototype?: object } | undefined>)[name]?.prototype ??
89
+ Object.prototype;
90
+
91
+ /**
92
+ * Lists `added` after the entries of navigator's `key`: a listing of both
93
+ * in its place, or, where navigator will not take one, `added` defined on
94
+ * the browser's listing itself by name, and in its `length`, `item` and
95
+ * iteration only where it takes them by index too, which Chrome's and
96
+ * Firefox's do not: a loop to `length` would read past what it indexes.
97
+ */
98
+ function extend<T extends object>(
99
+ navigator: Navigator,
100
+ key: "plugins" | "mimeTypes",
101
+ added: T[],
102
+ nameOf: (entry: T) => string,
103
+ more: (own: Listing<T>) => PropertyDescriptorMap,
104
+ ) {
105
+ const own = navigator[key] as unknown as Listing<T>;
106
+ const entries = [...entriesOf(own), ...added];
107
+
108
+ try {
109
+ Object.defineProperty(navigator, key, {
110
+ value: listing(Object.getPrototypeOf(own), entries, nameOf, more(own)),
111
+ configurable: true,
112
+ enumerable: true,
113
+ });
114
+ return;
115
+ } catch {
116
+ // Not configurable, or navigator not extensible: the listing it has, then.
117
+ }
118
+
119
+ try {
120
+ const first = own.length;
121
+ let indexed = true;
122
+ for (let i = 0; i < added.length; i++) {
123
+ try {
124
+ Object.defineProperty(own, first + i, { value: added[i], configurable: true });
125
+ } catch {
126
+ indexed = false;
127
+ }
128
+
129
+ Object.defineProperty(own, nameOf(added[i] as T), hidden(added[i]));
130
+ }
131
+
132
+ const { item, namedItem } = own;
133
+ Object.defineProperty(
134
+ own,
135
+ "namedItem",
136
+ hidden(
137
+ (name: string) =>
138
+ namedItem.call(own, name) ??
139
+ added.find((entry) => nameOf(entry) === String(name)) ??
140
+ null,
141
+ ),
142
+ );
143
+ if (indexed) {
144
+ Object.defineProperties(own, {
145
+ length: { get: () => entries.length, configurable: true },
146
+ item: hidden((index: number) =>
147
+ index >>> 0 < first ? item.call(own, index) : (entries[index >>> 0] ?? null),
148
+ ),
149
+ [Symbol.iterator]: hidden(() => entries.values()),
150
+ });
151
+ }
152
+ } catch {
153
+ // A frozen listing: nothing to be done.
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Lists Flash Player's plug-in, "Shockwave Flash 32.0 r0", in
159
+ * `navigator.plugins` and its MIME types in `navigator.mimeTypes`, after
160
+ * the browser's own, for scripts that look for Flash before they embed a
161
+ * SWF. watchFlash calls it, and replaceFlash when asked; the browser
162
+ * build's `dist/plugin.js` does as it loads, for a page's scripts that run
163
+ * before a module. Once a page: where a Flash plug-in is listed already,
164
+ * this does nothing, and where navigator is not a browser's, it throws
165
+ * nothing.
166
+ */
167
+ export function installFlashPlugin(): void {
168
+ try {
169
+ install();
170
+ } catch {
171
+ // A navigator of a test's or a server's DOM, without the browser's listings' members.
172
+ }
173
+ }
174
+
175
+ function install(): void {
176
+ const navigator = globalThis.navigator as Navigator | undefined;
177
+ if (!navigator?.plugins || !navigator.mimeTypes || navigator.plugins.namedItem(NAME)) {
178
+ return;
179
+ }
180
+
181
+ const mimePrototype = prototypeOf("MimeType");
182
+ const mimeTypes: MimeType[] = MIME_TYPES.map(([type, description, suffixes]) =>
183
+ Object.create(mimePrototype, {
184
+ type: hidden(type),
185
+ description: hidden(description),
186
+ suffixes: hidden(suffixes),
187
+ enabledPlugin: { get: () => plugin, configurable: true },
188
+ }),
189
+ );
190
+ const plugin = listing(prototypeOf("Plugin"), mimeTypes, (mime) => mime.type, {
191
+ name: hidden(NAME),
192
+ description: hidden(DESCRIPTION),
193
+ filename: hidden("swf2es.js"),
194
+ }) as unknown as Plugin;
195
+
196
+ extend(
197
+ navigator,
198
+ "plugins",
199
+ [plugin],
200
+ (entry) => entry.name,
201
+ (own): PropertyDescriptorMap => {
202
+ // The browser's own, as it was.
203
+ const refresh = (own as unknown as PluginArray).refresh;
204
+ return typeof refresh === "function" ? { refresh: hidden(refresh.bind(own)) } : {};
205
+ },
206
+ );
207
+ extend(
208
+ navigator,
209
+ "mimeTypes",
210
+ mimeTypes,
211
+ (entry) => entry.type,
212
+ () => ({}),
213
+ );
214
+ }
package/src/replace.ts CHANGED
@@ -2,6 +2,19 @@
2
2
  // with what they told Flash: the movie, its FlashVars, how it is shown
3
3
  // and scripted, its size, and the id and name the page's scripts find it by.
4
4
  import { defineElement, type Swf2esPlayerElement, TAG } from "./element.js";
5
+ import { installFlashPlugin } from "./plugin.js";
6
+
7
+ /** What replaceFlash and watchFlash do besides swapping the tags. */
8
+ export interface ReplaceOptions {
9
+ /**
10
+ * Whether navigator lists Flash Player's plug-in (installFlashPlugin),
11
+ * for the page's scripts that look for it before they write a Flash
12
+ * tag: true by default for watchFlash, which swaps the tags they write;
13
+ * false for replaceFlash, which swaps only the tags there now, so that
14
+ * a page's later look for Flash does not write tags nothing swaps.
15
+ */
16
+ plugin?: boolean;
17
+ }
5
18
 
6
19
  const FLASH_TYPES = new Set([
7
20
  "application/x-shockwave-flash",
@@ -101,14 +114,22 @@ export function flashAttributes(outer: Element): Map<string, string> {
101
114
  /**
102
115
  * Swap each Flash <object> and <embed> under `root` for a <swf2es-player>
103
116
  * carrying its parameters, in its place: the outermost of nested ones, its
104
- * fallbacks going with it. Returns the elements made.
117
+ * fallbacks going with it, and list Flash's plug-in in navigator if
118
+ * `options.plugin` is true. Returns the elements made.
105
119
  */
106
- export function replaceFlash(root: ParentNode = document): Swf2esPlayerElement[] {
120
+ export function replaceFlash(
121
+ root: ParentNode = document,
122
+ options: ReplaceOptions = {},
123
+ ): Swf2esPlayerElement[] {
107
124
  // Where it cannot be defined, a tag swapped for it would play nothing.
108
125
  if (!defineElement()) {
109
126
  return [];
110
127
  }
111
128
 
129
+ if (options.plugin === true) {
130
+ installFlashPlugin();
131
+ }
132
+
112
133
  const made: Swf2esPlayerElement[] = [];
113
134
  const tags = [...root.querySelectorAll("object, embed")];
114
135
  if (root instanceof Element && (root.localName === "object" || root.localName === "embed")) {
@@ -141,10 +162,14 @@ export function replaceFlash(root: ParentNode = document): Swf2esPlayerElement[]
141
162
 
142
163
  /**
143
164
  * replaceFlash now, and again for each Flash tag the page adds under `root`
144
- * later, until the returned function is called.
165
+ * later, until the returned function is called; Flash's plug-in listed in
166
+ * navigator unless `options.plugin` is false.
145
167
  */
146
- export function watchFlash(root: ParentNode & Node = document): () => void {
147
- replaceFlash(root);
168
+ export function watchFlash(
169
+ root: ParentNode & Node = document,
170
+ options: ReplaceOptions = {},
171
+ ): () => void {
172
+ replaceFlash(root, { plugin: options.plugin !== false });
148
173
  const observer = new MutationObserver((mutations) => {
149
174
  for (const mutation of mutations) {
150
175
  // A tag added, or one made Flash after it was added, its src or type set by a script.
@@ -154,7 +179,7 @@ export function watchFlash(root: ParentNode & Node = document): () => void {
154
179
  const tag =
155
180
  node instanceof Element && node.localName === "param" ? node.parentElement : node;
156
181
  if (tag instanceof Element && tag.isConnected) {
157
- replaceFlash(tag);
182
+ replaceFlash(tag, { plugin: false });
158
183
  }
159
184
  }
160
185
  }