@wcstack/devtools 4.10.1 → 4.11.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/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * bootstrapDevtools.ts
3
3
  *
4
4
  * `<wcs-devtools>` の登録と自動挿入(devtools-tag-design.md §2)。
5
- * - 既に定義済みなら再定義しない
5
+ * - 既に定義済みなら再定義しない(別のコピーが定義していれば 1 回警告する — registerComponents.ts)
6
6
  * - ページに `<wcs-devtools>` が無ければ body 末尾に 1 つ挿入
7
7
  * (手動で書かれていれば挿入しない)
8
8
  * - SSR では何もしない
package/dist/index.esm.js CHANGED
@@ -1,3 +1,5 @@
1
+ var pkg = {"name":"@wcstack/devtools","version":"4.11.0"};
2
+
1
3
  /**
2
4
  * protocol/types.ts
3
5
  *
@@ -2218,16 +2220,86 @@ class WcsDevtools extends HTMLElement {
2218
2220
  }
2219
2221
  }
2220
2222
 
2223
+ // ===========================================================================
2224
+ // AUTO-GENERATED FILE - DO NOT EDIT.
2225
+ // Generated from /protocol/define-element.ts by scripts/sync-protocol-types.mjs.
2226
+ // Run `node scripts/sync-protocol-types.mjs` after editing the source.
2227
+ // ===========================================================================
2228
+ /**
2229
+ * One copy of each package on a page (docs/timing-and-firing-contract.md §24). The first copy the
2230
+ * page evaluates defines the tags and a second one does nothing, so a copy that finds its tag defined
2231
+ * by another copy of the package — not its class, not a subclass of it, not the same version — warns
2232
+ * `[wcs/package-twice]` once per registry, naming both versions. The classes it defines carry
2233
+ * `"<package>@<version>"` under `Symbol.for("wcstack.package")`; a class without it is named
2234
+ * "another copy of <package> that does not name its version" (an older copy, or one loaded through
2235
+ * an entry that does not stamp).
2236
+ */
2237
+ /** The static a class defined through this helper carries: `"@wcstack/fetch@<version>"`. */
2238
+ const PACKAGE_STAMP = Symbol.for("wcstack.package");
2239
+ /** The registries this copy warned about: one warning per package per registry. */
2240
+ const warned = new WeakSet();
2241
+ /**
2242
+ * Marks `cls` as defined by `pkg` (`"@wcstack/fetch@<version>"`). A subclass inherits the mark, and
2243
+ * `defineProperty` writes it even where a parent's mark is read-only.
2244
+ */
2245
+ function stampPackage(cls, pkg) {
2246
+ Object.defineProperty(cls, PACKAGE_STAMP, { value: pkg, configurable: true });
2247
+ }
2248
+ /**
2249
+ * Warns when `tag` is defined as `existing` by another copy of the package `pkg` names: `existing`
2250
+ * is neither `own` nor a subclass of it (omit `own` when the copy has no class to compare with), and
2251
+ * carries another version or none. Once per registry.
2252
+ */
2253
+ function warnIfAnotherCopy(registry, tag, existing, own, pkg) {
2254
+ if (own !== undefined && (existing === own || existing.prototype instanceof own))
2255
+ return;
2256
+ const theirs = existing[PACKAGE_STAMP];
2257
+ if (theirs === pkg || warned.has(registry))
2258
+ return;
2259
+ warned.add(registry);
2260
+ const name = pkg.slice(0, pkg.lastIndexOf("@"));
2261
+ console.warn(`[${name}] [wcs/package-twice] <${tag}> is already defined by ` +
2262
+ `${theirs ?? `another copy of ${name} that does not name its version`}; ` +
2263
+ `this copy, ${pkg}, does nothing. Load each package once.`);
2264
+ }
2265
+ /**
2266
+ * Defines each `[tag, class]` in `registry` unless the tag is already defined, stamping the class
2267
+ * with `pkg` (`"@wcstack/fetch@<version>"`). A tag another copy of the package defined first is left
2268
+ * as it is, with the warning above.
2269
+ */
2270
+ function defineElements(registry, pkg, definitions) {
2271
+ for (const [tag, cls] of definitions) {
2272
+ const existing = registry.get(tag);
2273
+ if (existing === undefined) {
2274
+ stampPackage(cls, pkg);
2275
+ registry.define(tag, cls);
2276
+ }
2277
+ else {
2278
+ warnIfAnotherCopy(registry, tag, existing, cls, pkg);
2279
+ }
2280
+ }
2281
+ }
2282
+
2283
+ const TAG_NAME = "wcs-devtools";
2284
+ /**
2285
+ * `<wcs-devtools>` を `registry` に定義する(定義済みなら何もしない。別のコピーが定義していれば
2286
+ * 版を名指しして 1 回警告する — docs/timing-and-firing-contract.md §24)。
2287
+ */
2288
+ function registerComponents(registry = customElements) {
2289
+ defineElements(registry, `${pkg.name}@${pkg.version}`, [
2290
+ [TAG_NAME, WcsDevtools],
2291
+ ]);
2292
+ }
2293
+
2221
2294
  /**
2222
2295
  * bootstrapDevtools.ts
2223
2296
  *
2224
2297
  * `<wcs-devtools>` の登録と自動挿入(devtools-tag-design.md §2)。
2225
- * - 既に定義済みなら再定義しない
2298
+ * - 既に定義済みなら再定義しない(別のコピーが定義していれば 1 回警告する — registerComponents.ts)
2226
2299
  * - ページに `<wcs-devtools>` が無ければ body 末尾に 1 つ挿入
2227
2300
  * (手動で書かれていれば挿入しない)
2228
2301
  * - SSR では何もしない
2229
2302
  */
2230
- const TAG_NAME = "wcs-devtools";
2231
2303
  function insertIfAbsent() {
2232
2304
  if (document.querySelector(TAG_NAME) !== null) {
2233
2305
  return;
@@ -2238,9 +2310,7 @@ function bootstrapDevtools() {
2238
2310
  if (document.documentElement.hasAttribute("data-wcs-server")) {
2239
2311
  return;
2240
2312
  }
2241
- if (!customElements.get(TAG_NAME)) {
2242
- customElements.define(TAG_NAME, WcsDevtools);
2243
- }
2313
+ registerComponents();
2244
2314
  if (document.body !== null) {
2245
2315
  insertIfAbsent();
2246
2316
  }