@aglyn/shared-data-mdi 1.0.0-beta.252 → 1.0.0-beta.254

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": "@aglyn/shared-data-mdi",
3
- "version": "1.0.0-beta.252",
3
+ "version": "1.0.0-beta.254",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/shared-util-tools": "1.0.0-beta.252",
28
+ "@aglyn/shared-util-tools": "1.0.0-beta.254",
29
29
  "@swc/helpers": "0.5.23",
30
30
  "change-case": "^5.4.4"
31
31
  },
package/src/lib/mdi.d.ts CHANGED
@@ -23,3 +23,4 @@ export * from './utils/get-mdi-all-icons';
23
23
  export * from './utils/get-mdi-icon-from-id';
24
24
  export * from './utils/handle-icon-not-found';
25
25
  export * from './utils/icon-path-prop';
26
+ export * from './utils/search-mdi-icons';
package/src/lib/mdi.js CHANGED
@@ -22,5 +22,6 @@ export * from "./utils/get-mdi-all-icons.js";
22
22
  export * from "./utils/get-mdi-icon-from-id.js";
23
23
  export * from "./utils/handle-icon-not-found.js";
24
24
  export * from "./utils/icon-path-prop.js";
25
+ export * from "./utils/search-mdi-icons.js";
25
26
 
26
27
  //# sourceMappingURL=mdi.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/shared/data/mdi/src/lib/mdi.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './types'\nexport * from './constants/mdi-icons'\nexport * from './constants/default-icon'\nexport * from '../../generated/6.5.95/mdi-icons'\n\nexport * from './utils/convert-id-to-module-name'\nexport * from './utils/get-mdi-all-icons'\nexport * from './utils/get-mdi-icon-from-id'\nexport * from './utils/handle-icon-not-found'\nexport * from './utils/icon-path-prop'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,aAAS;AACvB,cAAc,2BAAuB;AACrC,cAAc,8BAA0B;AACxC,cAAc,sCAAkC;AAEhD,cAAc,uCAAmC;AACjD,cAAc,+BAA2B;AACzC,cAAc,kCAA8B;AAC5C,cAAc,mCAA+B;AAC7C,cAAc,4BAAwB"}
1
+ {"version":3,"sources":["../../../../../../../libs/shared/data/mdi/src/lib/mdi.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './types'\nexport * from './constants/mdi-icons'\nexport * from './constants/default-icon'\nexport * from '../../generated/6.5.95/mdi-icons'\n\nexport * from './utils/convert-id-to-module-name'\nexport * from './utils/get-mdi-all-icons'\nexport * from './utils/get-mdi-icon-from-id'\nexport * from './utils/handle-icon-not-found'\nexport * from './utils/icon-path-prop'\nexport * from './utils/search-mdi-icons'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,aAAS;AACvB,cAAc,2BAAuB;AACrC,cAAc,8BAA0B;AACxC,cAAc,sCAAkC;AAEhD,cAAc,uCAAmC;AACjD,cAAc,+BAA2B;AACzC,cAAc,kCAA8B;AAC5C,cAAc,mCAA+B;AAC7C,cAAc,4BAAwB;AACtC,cAAc,8BAA0B"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { Icon } from '../types';
18
+ /** How many icons a search answers at most; the picker narrows with more words rather than paging. */
19
+ export declare const MDI_ICON_SEARCH_LIMIT = 60;
20
+ /**
21
+ * The icons a picker lists for what a person typed (AGL-3668).
22
+ *
23
+ * Every word typed has to start a word of the icon's name, an alias or a tag
24
+ * (or be inside its id), so "account circle" finds Account Circle and "cart"
25
+ * finds the shopping icons. A name hit ranks above an alias or tag hit, and
26
+ * a name that starts with the first word ranks above one that only contains
27
+ * it. With nothing typed the first icons are answered, in catalog order. The
28
+ * native apps ask for this over a route instead of carrying six thousand
29
+ * paths, and draw the SVG paths it answers.
30
+ */
31
+ export declare function searchMdiIcons(icons: Iterable<Icon>, query: string, limit?: number): Icon[];
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ /** How many icons a search answers at most; the picker narrows with more words rather than paging. */ export const MDI_ICON_SEARCH_LIMIT = 60;
17
+ const words = (text)=>text.toLowerCase().split(/[\s_-]+/).filter(Boolean);
18
+ /**
19
+ * The icons a picker lists for what a person typed (AGL-3668).
20
+ *
21
+ * Every word typed has to start a word of the icon's name, an alias or a tag
22
+ * (or be inside its id), so "account circle" finds Account Circle and "cart"
23
+ * finds the shopping icons. A name hit ranks above an alias or tag hit, and
24
+ * a name that starts with the first word ranks above one that only contains
25
+ * it. With nothing typed the first icons are answered, in catalog order. The
26
+ * native apps ask for this over a route instead of carrying six thousand
27
+ * paths, and draw the SVG paths it answers.
28
+ */ export function searchMdiIcons(icons, query, limit = MDI_ICON_SEARCH_LIMIT) {
29
+ const wanted = words(query);
30
+ const cap = Math.max(1, Math.min(limit, MDI_ICON_SEARCH_LIMIT));
31
+ if (!wanted.length) {
32
+ const first = [];
33
+ for (const icon of icons){
34
+ first.push(icon);
35
+ if (first.length >= cap) break;
36
+ }
37
+ return first;
38
+ }
39
+ const scored = [];
40
+ for (const icon of icons){
41
+ var _icon_as, _icon_tags;
42
+ var _nameWords_;
43
+ const nameWords = words(icon.name);
44
+ const otherWords = [
45
+ ...(_icon_as = icon.as) != null ? _icon_as : [],
46
+ ...(_icon_tags = icon.tags) != null ? _icon_tags : []
47
+ ].flatMap(words);
48
+ let score = 0;
49
+ let all = true;
50
+ for (const word of wanted){
51
+ if (nameWords.some((entry)=>entry.startsWith(word))) score += 3;
52
+ else if (icon.id.includes(word)) score += 2;
53
+ else if (otherWords.some((entry)=>entry.startsWith(word))) score += 1;
54
+ else {
55
+ all = false;
56
+ break;
57
+ }
58
+ }
59
+ if (!all) continue;
60
+ if ((_nameWords_ = nameWords[0]) == null ? void 0 : _nameWords_.startsWith(wanted[0])) score += 1;
61
+ scored.push({
62
+ icon,
63
+ score
64
+ });
65
+ }
66
+ return scored.sort((a, b)=>b.score - a.score || a.icon.name.localeCompare(b.icon.name)).slice(0, cap).map((entry)=>entry.icon);
67
+ }
68
+
69
+ //# sourceMappingURL=search-mdi-icons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/shared/data/mdi/src/lib/utils/search-mdi-icons.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Icon } from '../types'\n\n/** How many icons a search answers at most; the picker narrows with more words rather than paging. */\nexport const MDI_ICON_SEARCH_LIMIT = 60\n\nconst words = (text: string): string[] =>\n text\n .toLowerCase()\n .split(/[\\s_-]+/)\n .filter(Boolean)\n\n/**\n * The icons a picker lists for what a person typed (AGL-3668).\n *\n * Every word typed has to start a word of the icon's name, an alias or a tag\n * (or be inside its id), so \"account circle\" finds Account Circle and \"cart\"\n * finds the shopping icons. A name hit ranks above an alias or tag hit, and\n * a name that starts with the first word ranks above one that only contains\n * it. With nothing typed the first icons are answered, in catalog order. The\n * native apps ask for this over a route instead of carrying six thousand\n * paths, and draw the SVG paths it answers.\n */\nexport function searchMdiIcons(\n icons: Iterable<Icon>,\n query: string,\n limit: number = MDI_ICON_SEARCH_LIMIT,\n): Icon[] {\n const wanted = words(query)\n const cap = Math.max(1, Math.min(limit, MDI_ICON_SEARCH_LIMIT))\n if (!wanted.length) {\n const first: Icon[] = []\n for (const icon of icons) {\n first.push(icon)\n if (first.length >= cap) break\n }\n return first\n }\n const scored: Array<{ icon: Icon; score: number }> = []\n for (const icon of icons) {\n const nameWords = words(icon.name)\n const otherWords = [...(icon.as ?? []), ...(icon.tags ?? [])].flatMap(words)\n let score = 0\n let all = true\n for (const word of wanted) {\n if (nameWords.some((entry) => entry.startsWith(word))) score += 3\n else if (icon.id.includes(word)) score += 2\n else if (otherWords.some((entry) => entry.startsWith(word))) score += 1\n else {\n all = false\n break\n }\n }\n if (!all) continue\n if (nameWords[0]?.startsWith(wanted[0])) score += 1\n scored.push({ icon, score })\n }\n return scored\n .sort((a, b) => b.score - a.score || a.icon.name.localeCompare(b.icon.name))\n .slice(0, cap)\n .map((entry) => entry.icon)\n}\n"],"names":["MDI_ICON_SEARCH_LIMIT","words","text","toLowerCase","split","filter","Boolean","searchMdiIcons","icons","query","limit","wanted","cap","Math","max","min","length","first","icon","push","scored","nameWords","name","otherWords","as","tags","flatMap","score","all","word","some","entry","startsWith","id","includes","sort","a","b","localeCompare","slice","map"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAID,oGAAoG,GACpG,OAAO,MAAMA,wBAAwB,GAAE;AAEvC,MAAMC,QAAQ,CAACC,OACbA,KACGC,WAAW,GACXC,KAAK,CAAC,WACNC,MAAM,CAACC;AAEZ;;;;;;;;;;CAUC,GACD,OAAO,SAASC,eACdC,KAAqB,EACrBC,KAAa,EACbC,QAAgBV,qBAAqB;IAErC,MAAMW,SAASV,MAAMQ;IACrB,MAAMG,MAAMC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,GAAG,CAACL,OAAOV;IACxC,IAAI,CAACW,OAAOK,MAAM,EAAE;QAClB,MAAMC,QAAgB,EAAE;QACxB,KAAK,MAAMC,QAAQV,MAAO;YACxBS,MAAME,IAAI,CAACD;YACX,IAAID,MAAMD,MAAM,IAAIJ,KAAK;QAC3B;QACA,OAAOK;IACT;IACA,MAAMG,SAA+C,EAAE;IACvD,KAAK,MAAMF,QAAQV,MAAO;YAEAU,UAAoBA;YAaxCG;QAdJ,MAAMA,YAAYpB,MAAMiB,KAAKI,IAAI;QACjC,MAAMC,aAAa;gBAAKL,WAAAA,KAAKM,EAAE,YAAPN,WAAW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