@ks-digital/designsystem-web 0.0.1-alpha.73

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 KS Digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ export type CopyState = 'rest' | 'success' | 'error';
2
+ export type CopyEventDetail = {
3
+ value: string;
4
+ };
5
+ export type CopyErrorEventDetail = {
6
+ value: string;
7
+ error: unknown;
8
+ };
9
+ /** Enhances every `[data-copy]` in `scope`. Needed for content the document observer has not seen yet. */
10
+ export declare const initCopyButtons: (scope?: Element | Document | null) => void;
11
+ declare global {
12
+ interface GlobalEventHandlersEventMap {
13
+ 'ksd-copy': CustomEvent<CopyEventDetail>;
14
+ 'ksd-copy-error': CustomEvent<CopyErrorEventDetail>;
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ export * from './copy-button';
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("@digdir/designsystemet-web/tooltip");var e=`http://www.w3.org/2000/svg`,t={fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`16`},n=n=>{let r=document.createElementNS(e,`svg`);r.setAttribute(`viewBox`,`0 0 256 256`);for(let[i,a]of n){let n=document.createElementNS(e,i);for(let[e,r]of Object.entries({...t,...a}))n.setAttribute(e,r);r.append(n)}return r},r=()=>typeof window<`u`&&typeof document<`u`,i=(e,...t)=>{!r()||window.dsWarnings===!1||console.log(`KS Designsystem: ${e}`,...t)},a=(e,t,n)=>n===void 0?e.getAttribute(t):(n===null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n),null),o=e=>{let t=e.target?.shadowRoot&&e.composedPath()[0]||e.target;return t?.nodeType===1?t:null},s=(e,t,n,r)=>{for(let i of t.split(` `))e.removeEventListener(i,n,r)},c=(e,t,n,r)=>{for(let i of t.split(` `))e.addEventListener(i,n,r);return()=>s(e,t,n,r)},l=(e,t,n)=>{let i=()=>a.disconnect(),a=new MutationObserver(n=>{if(!r()||!e.isConnected)return i();t(e,n)});return t(e),a.observe(e,n),i},u=(e,t)=>{if(!r())return;let n=window.ksdHotReloadCleanup||=new Map;for(let t of n.get(e)||[])t();n.set(e,t())},d=`data-copy`,f=`data-copy-icon`,p=`data-copy-state`,m=`data-tooltip`,h=`[${d}]`,g={rest:`data-copy-label`,success:`data-copied-label`,error:`data-error-label`},_={rest:`Kopier`,success:`Kopiert`,error:`Kopiering feilet`},v={rest:[[`polyline`,{points:`168 168 216 168 216 40 88 40 88 88`}],[`rect`,{x:`40`,y:`88`,width:`128`,height:`128`}]],success:[[`polyline`,{points:`40 144 96 200 224 72`}]],error:[[`line`,{x1:`160`,y1:`96`,x2:`96`,y2:`160`}],[`line`,{x1:`96`,y1:`96`,x2:`160`,y2:`160`}],[`circle`,{cx:`128`,cy:`128`,r:`96`}]]},y=new WeakMap,b=new WeakMap,x=e=>e.querySelector(`:scope > [${f}]`),S=e=>e.nodeName===`BUTTON`,C=e=>e.hasAttribute(`disabled`)||a(e,`aria-disabled`)===`true`,w=e=>e===`success`||e===`error`?e:`rest`,T=(e,t)=>{a(e,p,t),a(e,m,a(e,g[t])||_[t]);let r=x(e);r&&r.replaceChildren(n(v[t]))},E=e=>{if(!S(e)){i(`${d} expects a <button>, got <${e.nodeName.toLowerCase()}>:`,e);return}if(!x(e)){let t=document.createElement(`span`);a(t,f,``),a(t,`aria-hidden`,`true`),e.prepend(t)}T(e,w(a(e,p)))},D=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:n})),O=e=>{y.get(e)?.();let t=()=>{y.delete(e),T(e,`rest`)};if(e!==document.activeElement)return t();y.set(e,c(e,`blur`,t,{once:!0}))},k=async e=>{let t=o(e)?.closest(h);if(!t||!S(t)||C(t))return;let n=a(t,d)||``;t instanceof HTMLElement&&t.focus();let r=(b.get(t)??0)+1;b.set(t,r),y.get(t)?.();try{if(await navigator.clipboard.writeText(n),b.get(t)!==r)return;T(t,`success`),D(t,`ksd-copy`,{value:n})}catch(e){if(b.get(t)!==r)return;T(t,`error`),D(t,`ksd-copy-error`,{value:n,error:e})}O(t)},A=e=>{for(let t of e?.querySelectorAll(h)||[])E(t)},j=e=>(e.ownerDocument??e)===document||(i(`ignoring a scope from another document:`,e),!1),M=(e=r()?document:null)=>{!e||!j(e)||A(e)},N=(e,t)=>{if(!t)return A(document);for(let e of t)if(e.attributeName){let t=e.target;t.hasAttribute(d)&&E(t)}else for(let t of e.addedNodes)t.nodeType===1&&(t.hasAttribute(d)&&E(t),A(t))};u(`copy-button`,()=>[c(document,`click`,k,!0),l(document,N,{attributeFilter:[d,...Object.values(g)],attributes:!0,childList:!0,subtree:!0})]),exports.initCopyButtons=M;var P=require("@digdir/designsystemet-web");Object.keys(P).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return P[e]}})});
@@ -0,0 +1,2 @@
1
+ export * from '@digdir/designsystemet-web';
2
+ export * from './copy-button';
package/dist/index.js ADDED
@@ -0,0 +1,139 @@
1
+ import "@digdir/designsystemet-web/tooltip";
2
+ export * from "@digdir/designsystemet-web";
3
+ //#region src/utils/icon.ts
4
+ var e = "http://www.w3.org/2000/svg", t = {
5
+ fill: "none",
6
+ stroke: "currentColor",
7
+ "stroke-linecap": "round",
8
+ "stroke-linejoin": "round",
9
+ "stroke-width": "16"
10
+ }, n = (n) => {
11
+ let r = document.createElementNS(e, "svg");
12
+ r.setAttribute("viewBox", "0 0 256 256");
13
+ for (let [i, a] of n) {
14
+ let n = document.createElementNS(e, i);
15
+ for (let [e, r] of Object.entries({
16
+ ...t,
17
+ ...a
18
+ })) n.setAttribute(e, r);
19
+ r.append(n);
20
+ }
21
+ return r;
22
+ }, r = () => typeof window < "u" && typeof document < "u", i = (e, ...t) => {
23
+ !r() || window.dsWarnings === !1 || console.log(`KS Designsystem: ${e}`, ...t);
24
+ }, a = (e, t, n) => n === void 0 ? e.getAttribute(t) : (n === null ? e.removeAttribute(t) : e.getAttribute(t) !== n && e.setAttribute(t, n), null), o = (e) => {
25
+ let t = e.target?.shadowRoot && e.composedPath()[0] || e.target;
26
+ return t?.nodeType === 1 ? t : null;
27
+ }, s = (e, t, n, r) => {
28
+ for (let i of t.split(" ")) e.removeEventListener(i, n, r);
29
+ }, c = (e, t, n, r) => {
30
+ for (let i of t.split(" ")) e.addEventListener(i, n, r);
31
+ return () => s(e, t, n, r);
32
+ }, l = (e, t, n) => {
33
+ let i = () => a.disconnect(), a = new MutationObserver((n) => {
34
+ if (!r() || !e.isConnected) return i();
35
+ t(e, n);
36
+ });
37
+ return t(e), a.observe(e, n), i;
38
+ }, u = (e, t) => {
39
+ if (!r()) return;
40
+ let n = window.ksdHotReloadCleanup ||= /* @__PURE__ */ new Map();
41
+ for (let t of n.get(e) || []) t();
42
+ n.set(e, t());
43
+ }, d = "data-copy", f = "data-copy-icon", p = "data-copy-state", m = "data-tooltip", h = `[${d}]`, g = {
44
+ rest: "data-copy-label",
45
+ success: "data-copied-label",
46
+ error: "data-error-label"
47
+ }, _ = {
48
+ rest: "Kopier",
49
+ success: "Kopiert",
50
+ error: "Kopiering feilet"
51
+ }, v = {
52
+ rest: [["polyline", { points: "168 168 216 168 216 40 88 40 88 88" }], ["rect", {
53
+ x: "40",
54
+ y: "88",
55
+ width: "128",
56
+ height: "128"
57
+ }]],
58
+ success: [["polyline", { points: "40 144 96 200 224 72" }]],
59
+ error: [
60
+ ["line", {
61
+ x1: "160",
62
+ y1: "96",
63
+ x2: "96",
64
+ y2: "160"
65
+ }],
66
+ ["line", {
67
+ x1: "96",
68
+ y1: "96",
69
+ x2: "160",
70
+ y2: "160"
71
+ }],
72
+ ["circle", {
73
+ cx: "128",
74
+ cy: "128",
75
+ r: "96"
76
+ }]
77
+ ]
78
+ }, y = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), x = (e) => e.querySelector(`:scope > [${f}]`), S = (e) => e.nodeName === "BUTTON", C = (e) => e.hasAttribute("disabled") || a(e, "aria-disabled") === "true", w = (e) => e === "success" || e === "error" ? e : "rest", T = (e, t) => {
79
+ a(e, p, t), a(e, m, a(e, g[t]) || _[t]);
80
+ let r = x(e);
81
+ r && r.replaceChildren(n(v[t]));
82
+ }, E = (e) => {
83
+ if (!S(e)) {
84
+ i(`${d} expects a <button>, got <${e.nodeName.toLowerCase()}>:`, e);
85
+ return;
86
+ }
87
+ if (!x(e)) {
88
+ let t = document.createElement("span");
89
+ a(t, f, ""), a(t, "aria-hidden", "true"), e.prepend(t);
90
+ }
91
+ T(e, w(a(e, p)));
92
+ }, D = (e, t, n) => e.dispatchEvent(new CustomEvent(t, {
93
+ bubbles: !0,
94
+ composed: !0,
95
+ detail: n
96
+ })), O = (e) => {
97
+ y.get(e)?.();
98
+ let t = () => {
99
+ y.delete(e), T(e, "rest");
100
+ };
101
+ if (e !== document.activeElement) return t();
102
+ y.set(e, c(e, "blur", t, { once: !0 }));
103
+ }, k = async (e) => {
104
+ let t = o(e)?.closest(h);
105
+ if (!t || !S(t) || C(t)) return;
106
+ let n = a(t, d) || "";
107
+ t instanceof HTMLElement && t.focus();
108
+ let r = (b.get(t) ?? 0) + 1;
109
+ b.set(t, r), y.get(t)?.();
110
+ try {
111
+ if (await navigator.clipboard.writeText(n), b.get(t) !== r) return;
112
+ T(t, "success"), D(t, "ksd-copy", { value: n });
113
+ } catch (e) {
114
+ if (b.get(t) !== r) return;
115
+ T(t, "error"), D(t, "ksd-copy-error", {
116
+ value: n,
117
+ error: e
118
+ });
119
+ }
120
+ O(t);
121
+ }, A = (e) => {
122
+ for (let t of e?.querySelectorAll(h) || []) E(t);
123
+ }, j = (e) => (e.ownerDocument ?? e) === document || (i("ignoring a scope from another document:", e), !1), M = (e = r() ? document : null) => {
124
+ !e || !j(e) || A(e);
125
+ }, N = (e, t) => {
126
+ if (!t) return A(document);
127
+ for (let e of t) if (e.attributeName) {
128
+ let t = e.target;
129
+ t.hasAttribute(d) && E(t);
130
+ } else for (let t of e.addedNodes) t.nodeType === 1 && (t.hasAttribute(d) && E(t), A(t));
131
+ };
132
+ u("copy-button", () => [c(document, "click", k, !0), l(document, N, {
133
+ attributeFilter: [d, ...Object.values(g)],
134
+ attributes: !0,
135
+ childList: !0,
136
+ subtree: !0
137
+ })]);
138
+ //#endregion
139
+ export { M as initCopyButtons };
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@ks-digital/designsystem-web",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/ks-no/designsystem.git",
6
+ "directory": "packages/web"
7
+ },
8
+ "version": "0.0.1-alpha.73",
9
+ "license": "MIT",
10
+ "private": false,
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "./dist"
25
+ ],
26
+ "dependencies": {
27
+ "@digdir/designsystemet-web": "catalog:designsystemet"
28
+ },
29
+ "devDependencies": {
30
+ "@ks-digital/designsystem-themes": "workspace:*",
31
+ "@storybook/addon-docs": "catalog:storybook",
32
+ "@testing-library/jest-dom": "catalog:testing-library",
33
+ "@storybook/web-components": "catalog:storybook",
34
+ "@storybook/web-components-vite": "catalog:storybook",
35
+ "lit": "catalog:lit",
36
+ "storybook": "catalog:storybook",
37
+ "typescript": "catalog:typescript",
38
+ "vitest-axe": "catalog:vitest-a11y"
39
+ }
40
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ export type IconShape = [tag: string, attrs: Record<string, string>];
2
+ /** Builds the SVG node by hand, since Trusted Types blocks innerHTML even for static markup. */
3
+ export declare const createIcon: (shapes: IconShape[]) => SVGSVGElement;
@@ -0,0 +1,19 @@
1
+ export declare const isBrowser: () => boolean;
2
+ /** Returns void on purpose: consuming the result of a logging call is always a mistake. */
3
+ export declare const warn: (message: string, ...args: unknown[]) => void;
4
+ /** Get attribute when `value` is omitted, set it when a string, remove it when `null`. */
5
+ export declare const attr: (el: Element, name: string, value?: string | null) => string | null;
6
+ /** Resolves the real target even when the event crosses a shadow boundary. */
7
+ export declare const getComposedTarget: (event: Event) => Element | null;
8
+ export declare const off: (el: EventTarget, types: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void;
9
+ export declare const on: (el: EventTarget, types: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => () => void;
10
+ /** Runs `callback` immediately, then on every matching mutation. Returns a disconnect function. */
11
+ export declare const onMutation: <T extends Node>(el: T, callback: (el: T, records?: MutationRecord[]) => void, options: MutationObserverInit) => () => void;
12
+ /** Re-runs setup on hot reload, tearing down the listeners registered by the previous run. */
13
+ export declare const onHotReload: (key: string, setup: () => (() => void)[]) => void;
14
+ declare global {
15
+ interface Window {
16
+ dsWarnings?: boolean;
17
+ ksdHotReloadCleanup?: Map<string, (() => void)[]>;
18
+ }
19
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@ks-digital/designsystem-web",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/ks-no/designsystem.git",
6
+ "directory": "packages/web"
7
+ },
8
+ "version": "0.0.1-alpha.73",
9
+ "license": "MIT",
10
+ "private": false,
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "./dist"
25
+ ],
26
+ "dependencies": {
27
+ "@digdir/designsystemet-web": "1.21.0"
28
+ },
29
+ "devDependencies": {
30
+ "@storybook/addon-docs": "10.2.17",
31
+ "@testing-library/jest-dom": "~6.6.3",
32
+ "@storybook/web-components": "10.2.17",
33
+ "@storybook/web-components-vite": "10.2.17",
34
+ "lit": "^3.3.0",
35
+ "storybook": "10.5.8",
36
+ "typescript": "6.0.3",
37
+ "vitest-axe": "^0.1.0",
38
+ "@ks-digital/designsystem-themes": "0.0.1-alpha.73"
39
+ }
40
+ }