UNPKG

@oslokommune/punkt-elements

Version:

Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo

6 lines (5 loc) 1.5 kB
"use strict";const m=require("./element-6DBpyGQm.cjs"),x=require("./directive-C7oCP5Bh.cjs"),s=require("./directive-helpers-BBbxqP2W.cjs");/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const k=(l,v,d)=>{const h=new Map;for(let e=v;e<=d;e++)h.set(l[e],e);return h},q=x.e(class extends x.i{constructor(l){if(super(l),l.type!==x.t.CHILD)throw Error("repeat() can only be used in text expressions")}dt(l,v,d){let h;d===void 0?d=v:v!==void 0&&(h=v);const e=[],u=[];let n=0;for(const c of l)e[n]=h?h(c,n):n,u[n]=d(c,n),n++;return{values:u,keys:e}}render(l,v,d){return this.dt(l,v,d).values}update(l,[v,d,h]){const e=s.p(l),{values:u,keys:n}=this.dt(v,d,h);if(!Array.isArray(e))return this.ut=n,u;const c=this.ut??(this.ut=[]),f=[];let p,M,t=0,i=e.length-1,r=0,o=u.length-1;for(;t<=i&&r<=o;)if(e[t]===null)t++;else if(e[i]===null)i--;else if(c[t]===n[r])f[r]=s.v(e[t],u[r]),t++,r++;else if(c[i]===n[o])f[o]=s.v(e[i],u[o]),i--,o--;else if(c[t]===n[o])f[o]=s.v(e[t],u[o]),s.r(l,f[o+1],e[t]),t++,o--;else if(c[i]===n[r])f[r]=s.v(e[i],u[r]),s.r(l,e[t],e[i]),i--,r++;else if(p===void 0&&(p=k(n,r,o),M=k(c,t,i)),p.has(c[t]))if(p.has(c[i])){const a=M.get(n[r]),y=a!==void 0?e[a]:null;if(y===null){const g=s.r(l,e[t]);s.v(g,u[r]),f[r]=g}else f[r]=s.v(y,u[r]),s.r(l,e[t],y),e[a]=null;r++}else s.M(e[i]),i--;else s.M(e[t]),t++;for(;r<=o;){const a=s.r(l,f[o+1]);s.v(a,u[r]),f[r++]=a}for(;t<=i;){const a=e[t++];a!==null&&s.M(a)}return this.ut=n,s.m(l,f),m.T}});exports.c=q;