@spectrum-web-components/shared 0.40.5 → 0.41.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/shared",
3
- "version": "0.40.5",
3
+ "version": "0.41.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -73,6 +73,10 @@
73
73
  "development": "./src/platform.dev.js",
74
74
  "default": "./src/platform.js"
75
75
  },
76
+ "./src/random-id.js": {
77
+ "development": "./src/random-id.dev.js",
78
+ "default": "./src/random-id.js"
79
+ },
76
80
  "./src/reparent-children.js": {
77
81
  "development": "./src/reparent-children.dev.js",
78
82
  "default": "./src/reparent-children.js"
@@ -97,7 +101,7 @@
97
101
  ],
98
102
  "dependencies": {
99
103
  "@lit-labs/observers": "^2.0.0",
100
- "@spectrum-web-components/base": "^0.40.5",
104
+ "@spectrum-web-components/base": "^0.41.1",
101
105
  "focus-visible": "^5.1.0"
102
106
  },
103
107
  "types": "./src/index.d.ts",
@@ -105,5 +109,5 @@
105
109
  "sideEffects": [
106
110
  "./**/*.dev.js"
107
111
  ],
108
- "gitHead": "2e0006478841b07af63c19a0167a136bf724d064"
112
+ "gitHead": "1eded35d98d01973b40990486b86840ba464a2da"
109
113
  }
package/src/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from './observe-slot-text.js';
9
9
  export * from './platform.js';
10
10
  export * from './reparent-children.js';
11
11
  export * from './get-label-from-slot.js';
12
+ export * from './random-id.js';
package/src/index.dev.js CHANGED
@@ -10,4 +10,5 @@ export * from "./observe-slot-text.dev.js";
10
10
  export * from "./platform.dev.js";
11
11
  export * from "./reparent-children.dev.js";
12
12
  export * from "./get-label-from-slot.dev.js";
13
+ export * from "./random-id.dev.js";
13
14
  //# sourceMappingURL=index.dev.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.ts"],
4
- "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './first-focusable-in.dev.js'\nexport * from './focus-visible.dev.js'\nexport * from './focusable.dev.js'\nexport * from './focusable-selectors.dev.js'\nexport * from './get-active-element.dev.js'\nexport * from './like-anchor.dev.js'\nexport * from './observe-slot-presence.dev.js'\nexport * from './observe-slot-text.dev.js'\nexport * from './platform.dev.js'\nexport * from './reparent-children.dev.js'\nexport * from './get-label-from-slot.dev.js'\n"],
5
- "mappings": ";AAYA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './first-focusable-in.dev.js'\nexport * from './focus-visible.dev.js'\nexport * from './focusable.dev.js'\nexport * from './focusable-selectors.dev.js'\nexport * from './get-active-element.dev.js'\nexport * from './like-anchor.dev.js'\nexport * from './observe-slot-presence.dev.js'\nexport * from './observe-slot-text.dev.js'\nexport * from './platform.dev.js'\nexport * from './reparent-children.dev.js'\nexport * from './get-label-from-slot.dev.js'\nexport * from './random-id.dev.js'\n"],
5
+ "mappings": ";AAYA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";export*from"./first-focusable-in.js";export*from"./focus-visible.js";export*from"./focusable.js";export*from"./focusable-selectors.js";export*from"./get-active-element.js";export*from"./like-anchor.js";export*from"./observe-slot-presence.js";export*from"./observe-slot-text.js";export*from"./platform.js";export*from"./reparent-children.js";export*from"./get-label-from-slot.js";
1
+ "use strict";export*from"./first-focusable-in.js";export*from"./focus-visible.js";export*from"./focusable.js";export*from"./focusable-selectors.js";export*from"./get-active-element.js";export*from"./like-anchor.js";export*from"./observe-slot-presence.js";export*from"./observe-slot-text.js";export*from"./platform.js";export*from"./reparent-children.js";export*from"./get-label-from-slot.js";export*from"./random-id.js";
2
2
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.ts"],
4
- "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './first-focusable-in.js';\nexport * from './focus-visible.js';\nexport * from './focusable.js';\nexport * from './focusable-selectors.js';\nexport * from './get-active-element.js';\nexport * from './like-anchor.js';\nexport * from './observe-slot-presence.js';\nexport * from './observe-slot-text.js';\nexport * from './platform.js';\nexport * from './reparent-children.js';\nexport * from './get-label-from-slot.js';\n"],
5
- "mappings": "aAYA,WAAc,0BACd,WAAc,qBACd,WAAc,iBACd,WAAc,2BACd,WAAc,0BACd,WAAc,mBACd,WAAc,6BACd,WAAc,yBACd,WAAc,gBACd,WAAc,yBACd,WAAc",
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './first-focusable-in.js';\nexport * from './focus-visible.js';\nexport * from './focusable.js';\nexport * from './focusable-selectors.js';\nexport * from './get-active-element.js';\nexport * from './like-anchor.js';\nexport * from './observe-slot-presence.js';\nexport * from './observe-slot-text.js';\nexport * from './platform.js';\nexport * from './reparent-children.js';\nexport * from './get-label-from-slot.js';\nexport * from './random-id.js';\n"],
5
+ "mappings": "aAYA,WAAc,0BACd,WAAc,qBACd,WAAc,iBACd,WAAc,2BACd,WAAc,0BACd,WAAc,mBACd,WAAc,6BACd,WAAc,yBACd,WAAc,gBACd,WAAc,yBACd,WAAc,2BACd,WAAc",
6
6
  "names": []
7
7
  }
@@ -0,0 +1 @@
1
+ export declare function randomID(): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ export function randomID() {
3
+ return Array.from(
4
+ crypto.getRandomValues(new Uint8Array(4)),
5
+ (b) => `0${(b & 255).toString(16)}`.slice(-2)
6
+ ).join("");
7
+ }
8
+ //# sourceMappingURL=random-id.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["random-id.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n// This gnarly-looking implementation returns the equivalent of crypto.randomUUID().slice(0, 8).\n// It uses getRandomValues() in order to be compatible with HTTP contexts.\nexport function randomID(): string {\n return Array.from(crypto.getRandomValues(new Uint8Array(4)), (b) =>\n `0${(b & 0xff).toString(16)}`.slice(-2)\n ).join('');\n}\n"],
5
+ "mappings": ";AAcO,gBAAS,WAAmB;AAC/B,SAAO,MAAM;AAAA,IAAK,OAAO,gBAAgB,IAAI,WAAW,CAAC,CAAC;AAAA,IAAG,CAAC,MAC1D,KAAK,IAAI,KAAM,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE;AAAA,EAC1C,EAAE,KAAK,EAAE;AACb;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";export function randomID(){return Array.from(crypto.getRandomValues(new Uint8Array(4)),r=>`0${(r&255).toString(16)}`.slice(-2)).join("")}
2
+ //# sourceMappingURL=random-id.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["random-id.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n// This gnarly-looking implementation returns the equivalent of crypto.randomUUID().slice(0, 8).\n// It uses getRandomValues() in order to be compatible with HTTP contexts.\nexport function randomID(): string {\n return Array.from(crypto.getRandomValues(new Uint8Array(4)), (b) =>\n `0${(b & 0xff).toString(16)}`.slice(-2)\n ).join('');\n}\n"],
5
+ "mappings": "aAcO,gBAAS,UAAmB,CAC/B,OAAO,MAAM,KAAK,OAAO,gBAAgB,IAAI,WAAW,CAAC,CAAC,EAAIA,GAC1D,KAAKA,EAAI,KAAM,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,CAC1C,EAAE,KAAK,EAAE,CACb",
6
+ "names": ["b"]
7
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ import { randomID } from "@spectrum-web-components/shared/src/random-id.js";
3
+ import { expect } from "@open-wc/testing";
4
+ describe("randomID()", () => {
5
+ it("creates unique strings of 8 hex characters", () => {
6
+ const n = 1e3;
7
+ const ids = Array.from({ length: n }, randomID);
8
+ const shape = ids.filter((id) => {
9
+ return typeof id === "string" && id.length === 8 && id.split("").every((char) => "0123456789abcdef".includes(char));
10
+ });
11
+ const unique = new Set(ids);
12
+ expect(shape).to.have.length(n);
13
+ expect(unique).to.have.length(n);
14
+ });
15
+ it("generates 100k IDs in less than a second", () => {
16
+ const n = 1e5;
17
+ const sec = 1e3;
18
+ const start = performance.now();
19
+ const ids = Array.from({ length: n }, randomID);
20
+ const time = performance.now() - start;
21
+ expect(ids).to.have.length(n);
22
+ expect(time).to.be.lessThan(sec);
23
+ });
24
+ });
25
+ //# sourceMappingURL=random-id.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["random-id.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\nimport { expect } from '@open-wc/testing';\n\ndescribe('randomID()', () => {\n it('creates unique strings of 8 hex characters', () => {\n const n = 1000;\n const ids = Array.from({ length: n }, randomID);\n const shape = ids.filter((id) => {\n return (\n typeof id === 'string' &&\n id.length === 8 &&\n id.split('').every((char) => '0123456789abcdef'.includes(char))\n );\n });\n const unique = new Set(ids);\n\n expect(shape).to.have.length(n);\n expect(unique).to.have.length(n);\n });\n it('generates 100k IDs in less than a second', () => {\n const n = 100000;\n const sec = 1000;\n const start = performance.now();\n const ids = Array.from({ length: n }, randomID);\n const time = performance.now() - start;\n\n expect(ids).to.have.length(n);\n expect(time).to.be.lessThan(sec);\n });\n});\n"],
5
+ "mappings": ";AAYA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,SAAS,cAAc,MAAM;AACzB,KAAG,8CAA8C,MAAM;AACnD,UAAM,IAAI;AACV,UAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ;AAC9C,UAAM,QAAQ,IAAI,OAAO,CAAC,OAAO;AAC7B,aACI,OAAO,OAAO,YACd,GAAG,WAAW,KACd,GAAG,MAAM,EAAE,EAAE,MAAM,CAAC,SAAS,mBAAmB,SAAS,IAAI,CAAC;AAAA,IAEtE,CAAC;AACD,UAAM,SAAS,IAAI,IAAI,GAAG;AAE1B,WAAO,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC;AAC9B,WAAO,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC;AAAA,EACnC,CAAC;AACD,KAAG,4CAA4C,MAAM;AACjD,UAAM,IAAI;AACV,UAAM,MAAM;AACZ,UAAM,QAAQ,YAAY,IAAI;AAC9B,UAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ;AAC9C,UAAM,OAAO,YAAY,IAAI,IAAI;AAEjC,WAAO,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;AAC5B,WAAO,IAAI,EAAE,GAAG,GAAG,SAAS,GAAG;AAAA,EACnC,CAAC;AACL,CAAC;",
6
+ "names": []
7
+ }