svelte-tv 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/dist/utils.js +17 -5
  2. package/package.json +1 -1
package/dist/utils.js CHANGED
@@ -5,7 +5,7 @@ const WEBGL_CONTEXT_IDS = [
5
5
  'experimental-webgl2',
6
6
  'experimental-webgl',
7
7
  ];
8
- let supportedWebglVersions;
8
+ const supportedWebglVersions = new Map();
9
9
  export function hexColor(color = '') {
10
10
  if (isInteger(color)) {
11
11
  return color;
@@ -44,13 +44,19 @@ export function mod(n, m) {
44
44
  return ((n % m) + m) % m;
45
45
  }
46
46
  export function getWebglSupportedVersions(webglContextIds = WEBGL_CONTEXT_IDS) {
47
- if (supportedWebglVersions && webglContextIds === WEBGL_CONTEXT_IDS) {
48
- return supportedWebglVersions;
47
+ const cacheKey = webglContextIds.join('|');
48
+ const cached = supportedWebglVersions.get(cacheKey);
49
+ if (cached !== undefined) {
50
+ return cached;
49
51
  }
50
52
  const cv = document.createElement('canvas');
53
+ let probeContext = null;
51
54
  const supports = webglContextIds.filter((id) => {
52
55
  try {
53
56
  const context = cv.getContext(id);
57
+ if (context !== null && probeContext === null) {
58
+ probeContext = context;
59
+ }
54
60
  return !!(context &&
55
61
  (context instanceof WebGLRenderingContext ||
56
62
  context instanceof WebGL2RenderingContext ||
@@ -61,9 +67,15 @@ export function getWebglSupportedVersions(webglContextIds = WEBGL_CONTEXT_IDS) {
61
67
  return false;
62
68
  }
63
69
  });
64
- if (webglContextIds === WEBGL_CONTEXT_IDS) {
65
- supportedWebglVersions = supports;
70
+ const probe = probeContext;
71
+ if (probe !== null &&
72
+ 'getExtension' in probe &&
73
+ probe.isContextLost() === false) {
74
+ probe
75
+ .getExtension('WEBGL_lose_context')
76
+ ?.loseContext();
66
77
  }
78
+ supportedWebglVersions.set(cacheKey, supports);
67
79
  return supports;
68
80
  }
69
81
  export const supportsWebGL = (webGLSupportedVersion) => ['webgl', 'experimental-webgl', 'webgl2'].some((ver) => webGLSupportedVersion.includes(ver));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-tv",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Svelte speed for every screen 🚀✨",
5
5
  "type": "module",
6
6
  "exports": {