@mattilsynet/design 0.2.7 → 0.2.10
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 +7 -0
- package/mtds/heading/heading.stories.d.ts +7 -0
- package/mtds/index.d.ts +1 -0
- package/mtds/index.iife.js +1 -1
- package/mtds/index.iife.js.map +1 -1
- package/mtds/pagination/pagination.js +1 -1
- package/mtds/pagination/pagination.js.map +1 -1
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +34 -33
- package/mtds/styles.module.css.js +40 -38
- package/mtds/styles.module.css.js.map +1 -1
- package/package.json +2 -6
package/README.md
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
# Design
|
|
2
2
|
Mattilsynets designsystem og designmanual
|
|
3
|
+
|
|
4
|
+
## Releasing a new version
|
|
5
|
+
1. Manually update the version number in `package.json`
|
|
6
|
+
2. Run `npm install`
|
|
7
|
+
3. Commit the update with the message `chore: update version to x.y.z` to the `next` branch, and push it
|
|
8
|
+
4. Create a pull request from `next` into `main`
|
|
9
|
+
5. After the pull request is merged, the new version will be published automatically by a GitHub action
|
package/mtds/index.d.ts
CHANGED
package/mtds/index.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var mtds=function(
|
|
1
|
+
var mtds=function(g){"use strict";const x="_validation_f0nxn_1 _ds-validation-message_14y6r_1",A="_tag_f0nxn_1 _ds-tag_14y6r_1",S="_tabs_f0nxn_1",$="_table_f0nxn_1 _ds-table_14y6r_1",M="_scrollShadow_f0nxn_1",E="_tableChildAdded_f0nxn_1",C="_skeleton_f0nxn_1 _ds-skeleton_14y6r_1",T="_popover_f0nxn_1",w="_pagination_f0nxn_1 _ds-pagination_14y6r_1",I="_modal_f0nxn_1 _ds-modal_14y6r_1",k="_logo_f0nxn_1 _ds-focus_14y6r_1",N="_link_f0nxn_1",L="_grid_f0nxn_1",B="_flex_f0nxn_1",O="_box_f0nxn_1",D="_input_f0nxn_1 _ds-input_14y6r_1",H="_fieldset_f0nxn_1 _ds-fieldset_14y6r_1",P="_fieldsetValidationAdded_f0nxn_1",V="_field_f0nxn_1 _ds-field_14y6r_1",U="_fieldChildAdded_f0nxn_1",W="_affixes_f0nxn_1 _ds-field-affixes_14y6r_1",j="_count_f0nxn_1",F="_errorsummary_f0nxn_1 _ds-error-summary_14y6r_1",z="_details_f0nxn_1 _ds-details_14y6r_1",X="_chip_f0nxn_1 _ds-chip_14y6r_1",Y="_card_f0nxn_1",q="_info_f0nxn_1",K="_button_f0nxn_1 _ds-button_14y6r_1",Q="_breadcrumbs_f0nxn_1 _ds-breadcrumbs_14y6r_1",R="_badge_f0nxn_1",G="_avatar_f0nxn_1 _ds-avatar_14y6r_1",J="_alert_f0nxn_1 _ds-alert_14y6r_1",Z="_heading_f0nxn_1 _ds-heading_14y6r_1",tt="_body_f0nxn_100",r={validation:x,tag:A,tabs:S,table:$,scrollShadow:M,tableChildAdded:E,skeleton:C,popover:T,pagination:w,modal:I,logo:k,link:N,grid:L,flex:B,box:O,input:D,fieldset:H,fieldsetValidationAdded:P,field:V,fieldChildAdded:U,affixes:W,count:j,errorsummary:F,details:z,chip:X,card:Y,info:q,button:K,breadcrumbs:Q,badge:R,avatar:G,alert:J,heading:Z,body:tt},gt=Object.freeze(Object.defineProperty({__proto__:null,affixes:W,alert:J,avatar:G,badge:R,body:tt,box:O,breadcrumbs:Q,button:K,card:Y,chip:X,count:j,default:r,details:z,errorsummary:F,field:V,fieldChildAdded:U,fieldset:H,fieldsetValidationAdded:P,flex:B,grid:L,heading:Z,info:q,input:D,link:N,logo:k,modal:I,pagination:w,popover:T,scrollShadow:M,skeleton:C,table:$,tableChildAdded:E,tabs:S,tag:A,validation:x},Symbol.toStringTag,{value:"Module"})),nt=typeof window<"u"&&typeof document<"u",d={capture:!0,passive:!0};let bt=0;const mt=`${Date.now().toString(36)}${Math.random().toString(36).slice(2,5)}`;function b(t){return t.id||(t.id=`${mt}${++bt}`),t.id}const et=(t,n,o)=>{for(const s of o[0].split(","))o[0]=s,Element.prototype[`${t}EventListener`].apply(n,o)},u=(t,...n)=>et("add",t,n),p=(t,...n)=>et("remove",t,n),y=(t,n)=>{let o=0;const s=e=>{e.animationName===t&&(cancelAnimationFrame(o),o=requestAnimationFrame(n))};return{observe:e=>u(e,"animationend",s,d),disconnect:e=>p(e,"animationstart",s,d)}},v=t=>t instanceof HTMLElement&&"validity"in t&&!(t instanceof HTMLButtonElement),yt=r.field.split(" ")[0],ot=r.validation.split(" "),vt=ot[0],st=new WeakMap;function ht(t){for(const n of t){const o=[],s=[];let e=null,a=!0;for(const i of n.getElementsByTagName("*"))i instanceof HTMLLabelElement?o.push(i):v(i)?e=i:i.classList.contains(vt)?(a=i.getAttribute("data-color")==="success",s.unshift(b(i))):i instanceof HTMLParagraphElement&&s.push(b(i));if(e)for(const i of o)i.htmlFor=b(e);e&&at(e),e==null||e.setAttribute("aria-describedby",s.join(" ")),e==null||e.setAttribute("aria-invalid",`${!a}`)}}function it({target:t}){v(t)&&at(t)}function at(t){const n=t==null?void 0:t.nextElementSibling,o=n==null?void 0:n.getAttribute("data-count");if(n&&o){const s=Number(o)-t.value.length,e=s<0;if(n.getAttribute("aria-live")==="polite"!==e){n.setAttribute("aria-live",e?"polite":"off");for(const i of ot)n.classList.toggle(i,e)}n.textContent=`${Math.abs(s)} tegn ${e?"for mye":"igjen"}`}}function xt(t){const n=t.getElementsByClassName(yt),o=y(r.fieldChildAdded,()=>ht(n));st.set(t,o),o.observe(t),u(t,"input",it,d)}function At(t){var n;(n=st.get(t))==null||n.disconnect(t),p(t,"input",it,d)}const St=r.fieldset.split(" ")[0],$t=r.validation.split(" ")[0],dt=new WeakMap;function Mt(t){for(const n of t){const o=[];let s="";for(const e of n.getElementsByTagName("*"))e.classList.contains($t)?s=b(e):v(e)&&o.push(e);if(s)for(const e of o)e.setAttribute("aria-describedby",s),e.setAttribute("aria-invalid","true")}}function Et(t){const n=t.getElementsByClassName(St),o=y(r.fieldsetValidationAdded,()=>Mt(n));dt.set(t,o),o.observe(t)}function Ct(t){var n;(n=dt.get(t))==null||n.disconnect(t)}function Tt(t){u(t,"click",lt),u(t,"toggle",rt,d)}function wt(t){p(t,"click",lt),p(t,"toggle",rt,d)}const ct=r.popover.split(" ")[0],l=nt?document.createElement("div"):null;l&&(l.style.cssText="position:absolute;padding:1px");function rt({target:t,newState:n}){var e;const s=n==="open"&&t instanceof HTMLElement&&t.classList.contains(ct)&&((e=t.getRootNode())==null?void 0:e.querySelector(`[popovertarget="${t.id}"]`));if(s){const a=t.getAttribute("data-position")==="over",i=()=>It(s,t,a),f=({newState:_})=>{_!=="open"&&(p(document,"DOMContentReady",i,d),p(t,"toggle",f,d),p(window,"load,resize,scroll",i,d),l==null||l.remove())};document.body.append(l||""),document.fonts.ready.then(i),u(window,"load,resize,scroll",i,d),u(document,"DOMContentReady",i,d),u(t,"toggle",f,d)}}function lt(t){var o;const n=t.target instanceof Element&&t.target.closest("a");if(n){const s=n.getRootNode(),e=((o=s.getElementById)==null?void 0:o.call(s,n.getAttribute("popovertarget")||""))||n.closest(`.${ct}`),a=n.getAttribute("popovertargetaction")||"toggle";t.defaultPrevented||e==null||e.togglePopover(a==="show"||(a==="hide"?!1:void 0))}}function It(t,n,o=!1){const{innerWidth:s,innerHeight:e,scrollY:a,scrollX:i}=window,{offsetWidth:f,offsetHeight:_}=n;let ut=-i,m=-a,c=t;do ut+=(c==null?void 0:c.offsetLeft)||0,m+=(c==null?void 0:c.offsetTop)||0,c=(c==null?void 0:c.offsetParent)||null;while(c);const h=m+((t==null?void 0:t.offsetHeight)||0),Pt=h+_<e,Vt=m-_>0,pt=!o&&Pt||!Vt,Ut=pt?a+h+_+30:0;n.style.left=`${Math.round(Math.min(Math.max(10,ut),s-f-10))}px`,n.style.top=`${Math.round(pt?h:m-_)}px`,l==null||l.style.setProperty("top",`${Math.round(Ut)}px`)}const kt=r.table.split(" ")[0],ft=new WeakMap;function Nt(t){var n,o;for(const s of t)if(s instanceof HTMLTableElement){const e=Array.from(((o=(n=s.tHead)==null?void 0:n.rows[0])==null?void 0:o.cells)||[],a=>{var i;return(i=a.innerText)==null?void 0:i.trim()});for(const a of s.tBodies)for(const i of a.rows)for(const f of i.cells)f.setAttribute("data-th",e[f.cellIndex]||":empty")}}function Lt(t){const n=t.getElementsByClassName(kt),o=y(r.tableChildAdded,()=>Nt(n));ft.set(t,o),o.observe(t)}function Bt(t){var n;(n=ft.get(t))==null||n.disconnect(t)}const Ot=(t,n,o)=>{const s=(o-1)/2,e=Math.max(Math.min(t-Math.floor(s),n-o+1),1),a=Math.min(Math.max(t+Math.ceil(s),o),n),i=Array.from({length:a+1-e},(f,_)=>_+e);return o>4&&e>1&&i.splice(0,2,1,0),o>3&&a<n&&i.splice(-2,2,0,n),i},Dt=({current:t=1,total:n=10,show:o=7})=>({prev:t>1?t-1:0,next:t<n?t+1:0,pages:Ot(t,n,o).map((s,e)=>({current:s===t&&"page",key:`key-${s}-${e}`,page:s}))});nt&&_t(document);function _t(t){xt(t),Et(t),Tt(t),Lt(t)}function Ht(t){At(t),Ct(t),wt(t),Bt(t)}return g.observe=_t,g.pagination=Dt,g.styles=gt,g.unobserve=Ht,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"}),g}({});
|
|
2
2
|
//# sourceMappingURL=index.iife.js.map
|
package/mtds/index.iife.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.iife.js","sources":["../designsystem/utils.ts","../designsystem/field/field.ts","../designsystem/fieldset/fieldset.ts","../designsystem/popover/popover.ts","../designsystem/table/table.ts","../designsystem/pagination/pagination.ts","../designsystem/index.ts"],"sourcesContent":["export const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';\nexport const QUICK_EVENT = { capture: true, passive: true };\n\n/**\n * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId (el: Element) {\n if (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n const queue: MutationRecord[] = [];\n const observer = new MutationObserver((mutations) => {\n if (!queue[0]) requestAnimationFrame(process);\n queue.push(...mutations);\n });\n\n const process = () => {\n callback(queue, observer);\n queue.length = 0; // Reset queue\n };\n\n return observer;\n}\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\trest: Parameters<typeof Element.prototype.addEventListener>,\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\tElement.prototype[`${action}EventListener`].apply(element, rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => events(\"add\", element, rest);\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\n/**\n * Child added event inspired by:\n * https://davidwalsh.name/detect-node-insertion\n */\nexport const onAdd = (animationName: string, callback: () => void) => {\n let timer: ReturnType<typeof requestAnimationFrame> | number = 0;\n const onAnimation = (event: Event & { animationName?: string }) => {\n if (event.animationName === animationName) {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(callback);\n }\n };\n\n\treturn {\n\t\tobserve: (el: Element | Document, ) => on(el, 'animationend', onAnimation, QUICK_EVENT),\n\t\tdisconnect: (el: Element | Document, ) => off(el, 'animationstart', onAnimation, QUICK_EVENT)\n\t};\n}\n\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement && 'validity' in el && !(el instanceof HTMLButtonElement);\n\n// Make React support popover=\"\"target attribute\n// https://github.com/facebook/react/issues/27479\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicAttributes {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: string | boolean;\n\t\t}\n\t}\n\tnamespace React {\n\t\tinterface HTMLAttributes<T> {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: \"\" | \"auto\" | \"manual\" | undefined;\n\t\t}\n\t}\n}","import styles from '../styles.module.css';\nimport { QUICK_EVENT, isInputLike, off, on, onAdd, useId } from '../utils';\n\nconst CSS_FIELD = styles.field.split(' ')[0];\nconst CSS_VALIDATIONS = styles.validation.split(' ');\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction renderAria(fields: HTMLCollectionOf<Element>) {\n for(const field of fields) {\n const labels: HTMLLabelElement[] = [];\n const descs: string[] = [];\n let input: HTMLInputElement | null = null;\n let valid = true;\n\n for (const el of field.getElementsByTagName('*')) {\n if (el instanceof HTMLLabelElement) labels.push(el);\n else if (isInputLike(el)) input = el;\n else if (el.classList.contains(CSS_VALIDATION)) { // Must be before instanceof HTMLParagraphElement since validation can also be a <p>\n valid = el.getAttribute('data-color') === 'success';\n descs.unshift(useId(el));\n } else if (el instanceof HTMLParagraphElement) descs.push(useId(el));\n }\n\n if (input) for (const label of labels) label.htmlFor = useId(input);\n if (input) renderCounter(input);\n\n input?.setAttribute('aria-describedby', descs.join(' '));\n input?.setAttribute('aria-invalid', `${!valid}`);\n }\n}\nfunction handleInput({ target }: Event) {\n if (isInputLike(target)) renderCounter(target);\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n const el = input?.nextElementSibling;\n const limit = el?.getAttribute('data-count');\n\n if (el && limit) {\n const remainder = Number(limit) - input.value.length;\n const nextInvalid = remainder < 0;\n const prevInvalid = el.getAttribute('aria-live') === 'polite';\n\n if (prevInvalid !== nextInvalid) {\n el.setAttribute('aria-live', nextInvalid ? 'polite' : 'off');\n for (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n }\n el.textContent = `${Math.abs(remainder)} tegn ${nextInvalid ? 'for mye' : 'igjen'}`;\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELD);\n const add = onAdd(styles.fieldChildAdded, () => renderAria(fields));\n BOUND.set(el, add);\n add.observe(el);\n on(el, 'input', handleInput, QUICK_EVENT);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n off(el, 'input', handleInput, QUICK_EVENT);\n}\n","import styles from '../styles.module.css';\nimport { isInputLike, onAdd, useId } from '../utils';\nconst CSS_FIELDSET = styles.fieldset.split(' ')[0];\nconst CSS_VALIDATION = styles.validation.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(fieldsets: HTMLCollectionOf<Element>) {\n for(const fieldset of fieldsets) {\n const inputs: HTMLInputElement[] = [];\n let validationId = '';\n\n for (const el of fieldset.getElementsByTagName('*')) {\n if (el.classList.contains(CSS_VALIDATION)) validationId = useId(el);\n else if (isInputLike(el)) inputs.push(el);\n }\n\n if (validationId) \n for(const input of inputs) {\n input.setAttribute('aria-describedby', validationId);\n input.setAttribute('aria-invalid', 'true');\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELDSET);\n const add = onAdd(styles.fieldsetValidationAdded, () => process(fields));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","import styles from '../styles.module.css';\nimport { IS_BROWSER, QUICK_EVENT, off, on } from '../utils';\n\nexport function observe(el: Node) {\n on(el, 'click', handleLinkClick); // Allow `<a>` to use `popovertarget` as well\n on(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\nexport function unobserve(el: Node) {\n off(el, 'click', handleLinkClick);\n off(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\n\ntype Toggle = Event & { newState?: string };\nconst CSS_POPOVER = styles.popover.split(' ')[0];\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) SCROLLER.style.cssText = 'position:absolute;padding:1px';\n\nfunction handleToggle ({ target: el, newState }: Toggle){\n const isPopping = newState === 'open' && el instanceof HTMLElement && el.classList.contains(CSS_POPOVER);\n const anchor = isPopping && (el.getRootNode() as ShadowRoot)?.querySelector<HTMLElement>(`[popovertarget=\"${el.id}\"]`);\n\n if (anchor) {\n const isOver = el.getAttribute('data-position') === 'over';\n const update = () => place(anchor, el, isOver);\n const removeEvent = ({ newState }: Toggle) => {\n if (newState === 'open') return;\n off(document, 'DOMContentReady', update, QUICK_EVENT);\n off(el, 'toggle', removeEvent, QUICK_EVENT);\n off(window, 'load,resize,scroll', update, QUICK_EVENT);\n SCROLLER?.remove();\n }\n\n document.body.append(SCROLLER || '');\n document.fonts.ready.then(update); // Inital render and when fonts load\n on(window, 'load,resize,scroll', update, QUICK_EVENT);\n on(document, 'DOMContentReady', update, QUICK_EVENT);\n on(el, 'toggle', removeEvent, QUICK_EVENT);\n }\n}\n\n// Polyfill popovertarget for <a> (not supported by native)\n// and automatically assume popovertarget is the closest parent popover\n// but respect the popovertarget and popovertargetaction attribute\nfunction handleLinkClick (event: Event){\n const link = event.target instanceof Element && event.target.closest('a');\n if (link) {\n const root = link.getRootNode() as ShadowRoot;\n const target = root.getElementById?.(link.getAttribute('popovertarget') || '') || link.closest(`.${CSS_POPOVER}`);\n const action = link.getAttribute('popovertargetaction') || 'toggle';\n\n if (!event.defaultPrevented) target?.togglePopover(action === 'show' || (action === 'hide' ? false : undefined));\n }\n}\n\nfunction place (anchor: HTMLElement | null, poppe: HTMLElement, isOver = false) {\n const { innerWidth: winW, innerHeight: winH, scrollY: winY, scrollX: winX } = window;\n const { offsetWidth: popperW, offsetHeight: popperH } = poppe;\n let anchorX = -winX;\n let anchorY = -winY;\n let el = anchor;\n\n do {\n anchorX += el?.offsetLeft || 0;\n anchorY += el?.offsetTop || 0;\n el = (el?.offsetParent || null) as HTMLElement | null;\n } while (el);\n\n const anchorBottom = anchorY + (anchor?.offsetHeight || 0);\n const hasSpaceUnder = anchorBottom + popperH < winH;\n const hasSpaceOver = anchorY - popperH > 0\n const placeUnder = (!isOver && hasSpaceUnder) || !hasSpaceOver // Always place under when no hasSpaceOver, as no OS can scroll further up than 0\n const scroll = placeUnder ? winY + anchorBottom + popperH + 30 : 0\n\n poppe.style.left = `${Math.round(Math.min(Math.max(10, anchorX), winW - popperW - 10))}px`\n poppe.style.top = `${Math.round(placeUnder ? anchorBottom : anchorY - popperH)}px`\n SCROLLER?.style.setProperty('top', `${Math.round(scroll)}px`);\n}\n","import styles from '../styles.module.css';\nimport { onAdd } from '../utils';\nconst CSS_TABLE = styles.table.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(tables: HTMLCollectionOf<Element>) {\n for(const table of tables) if (table instanceof HTMLTableElement) {\n const ths = Array.from(table.tHead?.rows[0]?.cells || [], (el) => el.innerText?.trim()); // Using innerText to only include visible text\n for (const tbody of table.tBodies) {\n for (const row of tbody.rows) {\n for (const cell of row.cells) {\n cell.setAttribute('data-th', ths[cell.cellIndex] || ':empty'); // Using U+200B to prevent empty string from collapsing\n }\n }\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const tables = el.getElementsByClassName(CSS_TABLE);\n const add = onAdd(styles.tableChildAdded, () => process(tables));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","const getSteps = (now: number, max: number, show: number) => {\n const offset = (show - 1) / 2;\n const start = Math.min(Math.max(now - Math.floor(offset), 1), max - show + 1);\n const end = Math.min(Math.max(now + Math.ceil(offset), show), max);\n const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);\n\n if (show > 4 && start > 1) pages.splice(0, 2, 1, 0);\n if (show > 3 && end < max) pages.splice(-2, 2, 0, max);\n return pages;\n};\n\nexport const pagination = ({\n current = 1,\n total = 10,\n show = 7,\n}) => ({\n prev: current > 1 ? current - 1 : 0,\n next: current < total ? current + 1 : 0,\n pages: getSteps(current, total, show).map((page, index) => ({\n current: page === current && 'page' as const,\n key: `key-${page}-${index}`,\n page,\n })),\n});\n","import * as field from './field/field';\nimport * as fieldset from './fieldset/fieldset';\nimport * as popover from './popover/popover';\nimport * as table from './table/table';\nimport { IS_BROWSER } from './utils';\nexport { pagination } from './pagination/pagination';\nexport * as styles from './styles.module.css';\n\nif (IS_BROWSER) observe(document); // Automatic observe on browser\n\nexport function observe(el: Element | Document) {\n field.observe(el);\n fieldset.observe(el);\n popover.observe(el);\n table.observe(el);\n}\n\nexport function unobserve(el: Element | Document) {\n field.unobserve(el);\n fieldset.unobserve(el);\n popover.unobserve(el);\n table.unobserve(el);\n}"],"names":["IS_BROWSER","QUICK_EVENT","id","UUID","useId","el","events","action","element","rest","type","on","off","onAdd","animationName","callback","timer","onAnimation","event","isInputLike","CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","BOUND","renderAria","fields","field","labels","descs","input","valid","label","handleInput","target","renderCounter","limit","remainder","nextInvalid","css","observe","add","unobserve","CSS_FIELDSET","process","fieldsets","fieldset","inputs","validationId","handleLinkClick","handleToggle","CSS_POPOVER","SCROLLER","newState","anchor","_a","isOver","update","place","removeEvent","link","root","poppe","winW","winH","winY","winX","popperW","popperH","anchorX","anchorY","anchorBottom","hasSpaceUnder","hasSpaceOver","placeUnder","scroll","CSS_TABLE","tables","table","ths","_b","tbody","row","cell","getSteps","now","max","show","offset","start","end","pages","i","pagination","current","total","page","index","field.observe","fieldset.observe","popover.observe","table.observe","field.unobserve","fieldset.unobserve","popover.unobserve","table.unobserve"],"mappings":"01DAAaA,GAAa,O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O,CACT,KAAO,CACL,KAAMO,EAAU,EAAIA,EAAU,EAAI,EAClC,KAAMA,EAAUC,EAAQD,EAAU,EAAI,EACtC,MAAOV,GAASU,EAASC,EAAOR,CAAI,EAAE,IAAI,CAACS,EAAMC,KAAW,CAC1D,QAASD,IAASF,GAAW,OAC7B,IAAK,OAAOE,CAAI,IAAIC,CAAK,GACzB,KAAAD,CAAA,EACA,CACJ,GCfIhG,OAAoB,QAAQ,EAEzB,SAASwC,GAAQnC,EAAwB,CAC9C6F,GAAc7F,CAAE,EAChB8F,GAAiB9F,CAAE,EACnB+F,GAAgB/F,CAAE,EAClBgG,GAAchG,CAAE,CAClB,CAEO,SAASqC,GAAUrC,EAAwB,CAChDiG,GAAgBjG,CAAE,EAClBkG,GAAmBlG,CAAE,EACrBmG,GAAkBnG,CAAE,EACpBoG,GAAgBpG,CAAE,CACpB"}
|
|
1
|
+
{"version":3,"file":"index.iife.js","sources":["../designsystem/utils.ts","../designsystem/field/field.ts","../designsystem/fieldset/fieldset.ts","../designsystem/popover/popover.ts","../designsystem/table/table.ts","../designsystem/pagination/pagination.ts","../designsystem/index.ts"],"sourcesContent":["export const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';\nexport const QUICK_EVENT = { capture: true, passive: true };\n\n/**\n * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId (el: Element) {\n if (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n const queue: MutationRecord[] = [];\n const observer = new MutationObserver((mutations) => {\n if (!queue[0]) requestAnimationFrame(process);\n queue.push(...mutations);\n });\n\n const process = () => {\n callback(queue, observer);\n queue.length = 0; // Reset queue\n };\n\n return observer;\n}\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\trest: Parameters<typeof Element.prototype.addEventListener>,\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\tElement.prototype[`${action}EventListener`].apply(element, rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => events(\"add\", element, rest);\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\n/**\n * Child added event inspired by:\n * https://davidwalsh.name/detect-node-insertion\n */\nexport const onAdd = (animationName: string, callback: () => void) => {\n let timer: ReturnType<typeof requestAnimationFrame> | number = 0;\n const onAnimation = (event: Event & { animationName?: string }) => {\n if (event.animationName === animationName) {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(callback);\n }\n };\n\n\treturn {\n\t\tobserve: (el: Element | Document, ) => on(el, 'animationend', onAnimation, QUICK_EVENT),\n\t\tdisconnect: (el: Element | Document, ) => off(el, 'animationstart', onAnimation, QUICK_EVENT)\n\t};\n}\n\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement && 'validity' in el && !(el instanceof HTMLButtonElement);\n\n// Make React support popover=\"\"target attribute\n// https://github.com/facebook/react/issues/27479\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicAttributes {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: string | boolean;\n\t\t}\n\t}\n\tnamespace React {\n\t\tinterface HTMLAttributes<T> {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: \"\" | \"auto\" | \"manual\" | undefined;\n\t\t}\n\t}\n}","import styles from '../styles.module.css';\nimport { QUICK_EVENT, isInputLike, off, on, onAdd, useId } from '../utils';\n\nconst CSS_FIELD = styles.field.split(' ')[0];\nconst CSS_VALIDATIONS = styles.validation.split(' ');\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction renderAria(fields: HTMLCollectionOf<Element>) {\n for(const field of fields) {\n const labels: HTMLLabelElement[] = [];\n const descs: string[] = [];\n let input: HTMLInputElement | null = null;\n let valid = true;\n\n for (const el of field.getElementsByTagName('*')) {\n if (el instanceof HTMLLabelElement) labels.push(el);\n else if (isInputLike(el)) input = el;\n else if (el.classList.contains(CSS_VALIDATION)) { // Must be before instanceof HTMLParagraphElement since validation can also be a <p>\n valid = el.getAttribute('data-color') === 'success';\n descs.unshift(useId(el));\n } else if (el instanceof HTMLParagraphElement) descs.push(useId(el));\n }\n\n if (input) for (const label of labels) label.htmlFor = useId(input);\n if (input) renderCounter(input);\n\n input?.setAttribute('aria-describedby', descs.join(' '));\n input?.setAttribute('aria-invalid', `${!valid}`);\n }\n}\nfunction handleInput({ target }: Event) {\n if (isInputLike(target)) renderCounter(target);\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n const el = input?.nextElementSibling;\n const limit = el?.getAttribute('data-count');\n\n if (el && limit) {\n const remainder = Number(limit) - input.value.length;\n const nextInvalid = remainder < 0;\n const prevInvalid = el.getAttribute('aria-live') === 'polite';\n\n if (prevInvalid !== nextInvalid) {\n el.setAttribute('aria-live', nextInvalid ? 'polite' : 'off');\n for (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n }\n el.textContent = `${Math.abs(remainder)} tegn ${nextInvalid ? 'for mye' : 'igjen'}`;\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELD);\n const add = onAdd(styles.fieldChildAdded, () => renderAria(fields));\n BOUND.set(el, add);\n add.observe(el);\n on(el, 'input', handleInput, QUICK_EVENT);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n off(el, 'input', handleInput, QUICK_EVENT);\n}\n","import styles from '../styles.module.css';\nimport { isInputLike, onAdd, useId } from '../utils';\nconst CSS_FIELDSET = styles.fieldset.split(' ')[0];\nconst CSS_VALIDATION = styles.validation.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(fieldsets: HTMLCollectionOf<Element>) {\n for(const fieldset of fieldsets) {\n const inputs: HTMLInputElement[] = [];\n let validationId = '';\n\n for (const el of fieldset.getElementsByTagName('*')) {\n if (el.classList.contains(CSS_VALIDATION)) validationId = useId(el);\n else if (isInputLike(el)) inputs.push(el);\n }\n\n if (validationId) \n for(const input of inputs) {\n input.setAttribute('aria-describedby', validationId);\n input.setAttribute('aria-invalid', 'true');\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELDSET);\n const add = onAdd(styles.fieldsetValidationAdded, () => process(fields));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","import styles from '../styles.module.css';\nimport { IS_BROWSER, QUICK_EVENT, off, on } from '../utils';\n\nexport function observe(el: Node) {\n on(el, 'click', handleLinkClick); // Allow `<a>` to use `popovertarget` as well\n on(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\nexport function unobserve(el: Node) {\n off(el, 'click', handleLinkClick);\n off(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\n\ntype Toggle = Event & { newState?: string };\nconst CSS_POPOVER = styles.popover.split(' ')[0];\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) SCROLLER.style.cssText = 'position:absolute;padding:1px';\n\nfunction handleToggle ({ target: el, newState }: Toggle){\n const isPopping = newState === 'open' && el instanceof HTMLElement && el.classList.contains(CSS_POPOVER);\n const anchor = isPopping && (el.getRootNode() as ShadowRoot)?.querySelector<HTMLElement>(`[popovertarget=\"${el.id}\"]`);\n\n if (anchor) {\n const isOver = el.getAttribute('data-position') === 'over';\n const update = () => place(anchor, el, isOver);\n const removeEvent = ({ newState }: Toggle) => {\n if (newState === 'open') return;\n off(document, 'DOMContentReady', update, QUICK_EVENT);\n off(el, 'toggle', removeEvent, QUICK_EVENT);\n off(window, 'load,resize,scroll', update, QUICK_EVENT);\n SCROLLER?.remove();\n }\n\n document.body.append(SCROLLER || '');\n document.fonts.ready.then(update); // Inital render and when fonts load\n on(window, 'load,resize,scroll', update, QUICK_EVENT);\n on(document, 'DOMContentReady', update, QUICK_EVENT);\n on(el, 'toggle', removeEvent, QUICK_EVENT);\n }\n}\n\n// Polyfill popovertarget for <a> (not supported by native)\n// and automatically assume popovertarget is the closest parent popover\n// but respect the popovertarget and popovertargetaction attribute\nfunction handleLinkClick (event: Event){\n const link = event.target instanceof Element && event.target.closest('a');\n if (link) {\n const root = link.getRootNode() as ShadowRoot;\n const target = root.getElementById?.(link.getAttribute('popovertarget') || '') || link.closest(`.${CSS_POPOVER}`);\n const action = link.getAttribute('popovertargetaction') || 'toggle';\n\n if (!event.defaultPrevented) target?.togglePopover(action === 'show' || (action === 'hide' ? false : undefined));\n }\n}\n\nfunction place (anchor: HTMLElement | null, poppe: HTMLElement, isOver = false) {\n const { innerWidth: winW, innerHeight: winH, scrollY: winY, scrollX: winX } = window;\n const { offsetWidth: popperW, offsetHeight: popperH } = poppe;\n let anchorX = -winX;\n let anchorY = -winY;\n let el = anchor;\n\n do {\n anchorX += el?.offsetLeft || 0;\n anchorY += el?.offsetTop || 0;\n el = (el?.offsetParent || null) as HTMLElement | null;\n } while (el);\n\n const anchorBottom = anchorY + (anchor?.offsetHeight || 0);\n const hasSpaceUnder = anchorBottom + popperH < winH;\n const hasSpaceOver = anchorY - popperH > 0\n const placeUnder = (!isOver && hasSpaceUnder) || !hasSpaceOver // Always place under when no hasSpaceOver, as no OS can scroll further up than 0\n const scroll = placeUnder ? winY + anchorBottom + popperH + 30 : 0\n\n poppe.style.left = `${Math.round(Math.min(Math.max(10, anchorX), winW - popperW - 10))}px`\n poppe.style.top = `${Math.round(placeUnder ? anchorBottom : anchorY - popperH)}px`\n SCROLLER?.style.setProperty('top', `${Math.round(scroll)}px`);\n}\n","import styles from '../styles.module.css';\nimport { onAdd } from '../utils';\nconst CSS_TABLE = styles.table.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(tables: HTMLCollectionOf<Element>) {\n for(const table of tables) if (table instanceof HTMLTableElement) {\n const ths = Array.from(table.tHead?.rows[0]?.cells || [], (el) => el.innerText?.trim()); // Using innerText to only include visible text\n for (const tbody of table.tBodies) {\n for (const row of tbody.rows) {\n for (const cell of row.cells) {\n cell.setAttribute('data-th', ths[cell.cellIndex] || ':empty'); // Using U+200B to prevent empty string from collapsing\n }\n }\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const tables = el.getElementsByClassName(CSS_TABLE);\n const add = onAdd(styles.tableChildAdded, () => process(tables));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","const getSteps = (now: number, max: number, show: number) => {\n const offset = (show - 1) / 2;\n const start = Math.max(Math.min(now - Math.floor(offset), max - show + 1), 1);\n const end = Math.min(Math.max(now + Math.ceil(offset), show), max);\n const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);\n\n if (show > 4 && start > 1) pages.splice(0, 2, 1, 0);\n if (show > 3 && end < max) pages.splice(-2, 2, 0, max);\n return pages;\n};\n\nexport const pagination = ({\n current = 1,\n total = 10,\n show = 7,\n}) => ({\n prev: current > 1 ? current - 1 : 0,\n next: current < total ? current + 1 : 0,\n pages: getSteps(current, total, show).map((page, index) => ({\n current: page === current && 'page' as const,\n key: `key-${page}-${index}`,\n page,\n })),\n});\n","import * as field from './field/field';\nimport * as fieldset from './fieldset/fieldset';\nimport * as popover from './popover/popover';\nimport * as table from './table/table';\nimport { IS_BROWSER } from './utils';\nexport { pagination } from './pagination/pagination';\nexport * as styles from './styles.module.css';\n\nif (IS_BROWSER) observe(document); // Automatic observe on browser\n\nexport function observe(el: Element | Document) {\n field.observe(el);\n fieldset.observe(el);\n popover.observe(el);\n table.observe(el);\n}\n\nexport function unobserve(el: Element | Document) {\n field.unobserve(el);\n fieldset.unobserve(el);\n popover.unobserve(el);\n table.unobserve(el);\n}"],"names":["IS_BROWSER","QUICK_EVENT","id","UUID","useId","el","events","action","element","rest","type","on","off","onAdd","animationName","callback","timer","onAnimation","event","isInputLike","CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","BOUND","renderAria","fields","field","labels","descs","input","valid","label","handleInput","target","renderCounter","limit","remainder","nextInvalid","css","observe","add","unobserve","CSS_FIELDSET","process","fieldsets","fieldset","inputs","validationId","handleLinkClick","handleToggle","CSS_POPOVER","SCROLLER","newState","anchor","_a","isOver","update","place","removeEvent","link","root","poppe","winW","winH","winY","winX","popperW","popperH","anchorX","anchorY","anchorBottom","hasSpaceUnder","hasSpaceOver","placeUnder","scroll","CSS_TABLE","tables","table","ths","_b","tbody","row","cell","getSteps","now","max","show","offset","start","end","pages","_","i","pagination","current","total","page","index","field.observe","fieldset.observe","popover.observe","table.observe","field.unobserve","fieldset.unobserve","popover.unobserve","table.unobserve"],"mappings":"25DAAaA,GAAa,OAAO,OAAW,KAAe,OAAO,SAAa,IAClEC,EAAc,CAAE,QAAS,GAAM,QAAS,EAAK,EAM1D,IAAIC,GAAK,EACT,MAAMC,GAAO,GAAG,KAAK,IAAM,EAAA,SAAS,EAAE,CAAC,GAAG,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,EAAG,CAAC,CAAC,GACzE,SAASC,EAAOC,EAAa,CAC9B,OAACA,EAAG,KAAIA,EAAG,GAAK,GAAGF,EAAI,GAAG,EAAED,EAAE,IAC5BG,EAAG,EACX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F,CAAE,EAChB+F,GAAiB/F,CAAE,EACnBgG,GAAgBhG,CAAE,EAClBiG,GAAcjG,CAAE,CAClB,CAEO,SAASqC,GAAUrC,EAAwB,CAChDkG,GAAgBlG,CAAE,EAClBmG,GAAmBnG,CAAE,EACrBoG,GAAkBpG,CAAE,EACpBqG,GAAgBrG,CAAE,CACpB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const o = (t, e, a) => {
|
|
2
|
-
const i = (a - 1) / 2, n = Math.
|
|
2
|
+
const i = (a - 1) / 2, n = Math.max(Math.min(t - Math.floor(i), e - a + 1), 1), p = Math.min(Math.max(t + Math.ceil(i), a), e), s = Array.from({ length: p + 1 - n }, (M, f) => f + n);
|
|
3
3
|
return a > 4 && n > 1 && s.splice(0, 2, 1, 0), a > 3 && p < e && s.splice(-2, 2, 0, e), s;
|
|
4
4
|
}, c = ({
|
|
5
5
|
current: t = 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.js","sources":["../../designsystem/pagination/pagination.ts"],"sourcesContent":["const getSteps = (now: number, max: number, show: number) => {\n const offset = (show - 1) / 2;\n const start = Math.
|
|
1
|
+
{"version":3,"file":"pagination.js","sources":["../../designsystem/pagination/pagination.ts"],"sourcesContent":["const getSteps = (now: number, max: number, show: number) => {\n const offset = (show - 1) / 2;\n const start = Math.max(Math.min(now - Math.floor(offset), max - show + 1), 1);\n const end = Math.min(Math.max(now + Math.ceil(offset), show), max);\n const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);\n\n if (show > 4 && start > 1) pages.splice(0, 2, 1, 0);\n if (show > 3 && end < max) pages.splice(-2, 2, 0, max);\n return pages;\n};\n\nexport const pagination = ({\n current = 1,\n total = 10,\n show = 7,\n}) => ({\n prev: current > 1 ? current - 1 : 0,\n next: current < total ? current + 1 : 0,\n pages: getSteps(current, total, show).map((page, index) => ({\n current: page === current && 'page' as const,\n key: `key-${page}-${index}`,\n page,\n })),\n});\n"],"names":["getSteps","now","max","show","offset","start","end","pages","_","i","pagination","current","total","page","index"],"mappings":"AAAA,MAAMA,IAAW,CAACC,GAAaC,GAAaC,MAAiB;AACrD,QAAAC,KAAUD,IAAO,KAAK,GACtBE,IAAQ,KAAK,IAAI,KAAK,IAAIJ,IAAM,KAAK,MAAMG,CAAM,GAAGF,IAAMC,IAAO,CAAC,GAAG,CAAC,GACtEG,IAAM,KAAK,IAAI,KAAK,IAAIL,IAAM,KAAK,KAAKG,CAAM,GAAGD,CAAI,GAAGD,CAAG,GAC3DK,IAAQ,MAAM,KAAK,EAAE,QAAQD,IAAM,IAAID,EAAS,GAAA,CAACG,GAAGC,MAAMA,IAAIJ,CAAK;AAErE,SAAAF,IAAO,KAAKE,IAAQ,OAAS,OAAO,GAAG,GAAG,GAAG,CAAC,GAC9CF,IAAO,KAAKG,IAAMJ,OAAW,OAAO,IAAI,GAAG,GAAGA,CAAG,GAC9CK;AACT,GAEaG,IAAa,CAAC;AAAA,EACzB,SAAAC,IAAU;AAAA,EACV,OAAAC,IAAQ;AAAA,EACR,MAAAT,IAAO;AACT,OAAO;AAAA,EACL,MAAMQ,IAAU,IAAIA,IAAU,IAAI;AAAA,EAClC,MAAMA,IAAUC,IAAQD,IAAU,IAAI;AAAA,EACtC,OAAOX,EAASW,GAASC,GAAOT,CAAI,EAAE,IAAI,CAACU,GAAMC,OAAW;AAAA,IAC1D,SAASD,MAASF,KAAW;AAAA,IAC7B,KAAK,OAAOE,CAAI,IAAIC,CAAK;AAAA,IACzB,MAAAD;AAAA,EAAA,EACA;AACJ;"}
|