1 | "use strict"
|
2 | Object.defineProperty(exports,"__esModule",{value:!0})
|
3 | exports.fn=exports.params=exports.description=exports.active=exports.type=exports.name=void 0
|
4 | var e=require("./_collections")
|
5 | const t=new Set(e.referencesProps)
|
6 | exports.name="cleanupIDs"
|
7 | exports.type="full"
|
8 | exports.active=!0
|
9 | exports.description="removes unused IDs and minifies used"
|
10 | exports.params={remove:!0,minify:!0,prefix:"",preserve:[],preservePrefixes:[],force:!1}
|
11 | const r=/\burl\(("|')?#(.+?)\1\)/
|
12 | const n=/^#(.+?)$/
|
13 | const s=/(\w+)\./
|
14 | const o=["style","script"]
|
15 | const i=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
|
16 | const c=i.length-1
|
17 | exports.fn=function(e,i){let c
|
18 | let l
|
19 | const p=new Map
|
20 | const u=new Map
|
21 | let v=!1
|
22 | const m=new Set(Array.isArray(i.preserve)?i.preserve:i.preserve?[i.preserve]:[])
|
23 | const x=new Set(Array.isArray(i.preservePrefixes)?i.preservePrefixes:i.preservePrefixes?[i.preservePrefixes]:[])
|
24 | e=function e(c){for(let f=0;f<c.content.length&&!v;f++){const a=c.content[f]
|
25 | if(!i.force){const e=Boolean(a.content)
|
26 | if(a.isElem(o)&&e){v=!0
|
27 | continue}if(a.isElem("svg")){let e=!0
|
28 | for(let t=0;t<a.content.length;t++)if(!a.content[t].isElem("defs")){e=!1
|
29 | break}if(e)break}}a.isElem()&&a.eachAttr((function(e){let o
|
30 | let i
|
31 | if("id"!==e.name){t.has(e.name)&&(i=e.value.match(r))?o=i[2]:("href"===e.local&&(i=e.value.match(n))||"begin"===e.name&&(i=e.value.match(s)))&&(o=i[1])
|
32 | if(o){const t=u.get(o)||[]
|
33 | t.push(e)
|
34 | u.set(o,t)}}else{o=e.value
|
35 | p.has(o)?a.removeAttr("id"):p.set(o,a)}}))
|
36 | a.content&&e(a)}return c}(e)
|
37 | if(v)return e
|
38 | const h=e=>m.has(e)||function(e,t){if(!t)return!1
|
39 | for(const r of e)if(t.startsWith(r))return!0
|
40 | return!1}(x,e)
|
41 | for(const e of u){const t=e[0]
|
42 | if(p.has(t)){if(i.minify&&!h(t)){do{l=a(c=f(c),i)}while(h(l))
|
43 | p.get(t).attr("id").value=l
|
44 | for(const r of e[1])r.value=r.value.includes("#")?r.value.replace("#"+t,"#"+l):r.value.replace(t+".",l+".")}p.delete(t)}}if(i.remove)for(const e of p)h(e[0])||e[1].removeAttr("id")
|
45 | return e}
|
46 | function f(e){if(!e)return[0]
|
47 | e[e.length-1]++
|
48 | for(let t=e.length-1;t>0;t--)if(e[t]>c){e[t]=0
|
49 | void 0!==e[t-1]&&e[t-1]++}if(e[0]>c){e[0]=0
|
50 | e.unshift(0)}return e}function a(e,t){return t.prefix+e.map((e=>i[e])).join("")} |
\ | No newline at end of file |