@embedpdf/plugin-search 1.3.16 → 1.4.0
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/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +2 -11
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +2 -11
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/index.d.ts +1 -0
- package/dist/shared/components/search-layer.d.ts +10 -0
- package/dist/shared/hooks/index.d.ts +1 -0
- package/dist/shared/hooks/use-search.d.ts +15 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/svelte/components/SearchLayer.svelte.d.ts +10 -0
- package/dist/svelte/components/index.d.ts +1 -0
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-search.svelte.d.ts +15 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +3 -0
- package/dist/svelte/index.js +97 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +2 -11
- package/dist/vue/index.js.map +1 -1
- package/package.json +15 -8
package/dist/preact/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-search");require("preact");const r=require("preact/hooks"),i=require("preact/jsx-runtime"),s=()=>e.useCapability(t.SearchPlugin.id);exports.SearchLayer=function({pageIndex:e,scale:t,style:o,highlightColor:a="#FFFF00",activeHighlightColor:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-search");require("preact");const r=require("preact/hooks"),i=require("preact/jsx-runtime"),s=()=>e.useCapability(t.SearchPlugin.id);exports.SearchLayer=function({pageIndex:e,scale:t,style:o,highlightColor:a="#FFFF00",activeHighlightColor:n="#FFBF00",...l}){const{provides:u}=s(),[c,p]=r.useState(null);if(r.useEffect((()=>null==u?void 0:u.onSearchResultStateChange((e=>{p(e)}))),[u]),!c)return null;const d=c.results.map(((e,t)=>({result:e,originalIndex:t}))).filter((({result:t})=>t.pageIndex===e));return i.jsx("div",{style:{...o},...l,children:d.map((({result:e,originalIndex:r})=>e.rects.map(((e,s)=>i.jsx("div",{style:{position:"absolute",top:e.origin.y*t,left:e.origin.x*t,width:e.size.width*t,height:e.size.height*t,backgroundColor:r===c.activeResultIndex?n:a,mixBlendMode:"multiply",transform:"scale(1.02)",transformOrigin:"center",transition:"opacity .3s ease-in-out",opacity:1}},`${r}-${s}`)))))})},exports.useSearch=()=>{const{provides:e}=s(),[i,o]=r.useState(t.initialState);return r.useEffect((()=>null==e?void 0:e.onStateChange((e=>o(e)))),[e]),{state:i,provides:e}},exports.useSearchCapability=s,exports.useSearchPlugin=()=>e.usePlugin(t.SearchPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(initialState);\n\n useEffect(() => {\n return provides?.onStateChange((state) => setSearchState(state));\n }, [provides]);\n\n return {\n state: searchState,\n provides,\n };\n};\n","import { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\nimport { SearchResultState } from '@embedpdf/plugin-search';\n\nimport { useSearchCapability } from '../hooks';\n\ntype SearchLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n style?: CSSProperties;\n};\n\nexport function SearchLayer({\n pageIndex,\n scale,\n style,\n highlightColor = '#FFFF00',\n activeHighlightColor = '#FFBF00',\n ...props\n}: SearchLayoutProps) {\n const { provides: searchProvides } = useSearchCapability();\n const [searchResultState, setSearchResultState] = useState<SearchResultState | null>(null);\n\n useEffect(() => {\n return searchProvides?.onSearchResultStateChange((state) => {\n setSearchResultState(state);\n });\n }, [searchProvides]);\n\n if (!searchResultState) {\n return null;\n }\n\n // Filter results for current page while preserving original indices\n const pageResults = searchResultState.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === pageIndex);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {pageResults.map(({ result, originalIndex }) =>\n result.rects.map((rect, rectIndex) => (\n <div\n key={`${originalIndex}-${rectIndex}`}\n style={{\n position: 'absolute',\n top: rect.origin.y * scale,\n left: rect.origin.x * scale,\n width: rect.size.width * scale,\n height: rect.size.height * scale,\n backgroundColor:\n originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor,\n mixBlendMode: 'multiply',\n transform: 'scale(1.02)',\n transformOrigin: 'center',\n transition: 'opacity .3s ease-in-out',\n opacity: 1,\n }}\n ></div>\n )),\n )}\n </div>\n );\n}\n"],"names":["useSearchCapability","useCapability","SearchPlugin","id","pageIndex","scale","style","highlightColor","activeHighlightColor","props","provides","searchProvides","searchResultState","setSearchResultState","useState","useEffect","onSearchResultStateChange","state","pageResults","results","map","result","originalIndex","filter","jsxRuntime","jsx","children","rects","rect","rectIndex","position","top","origin","y","left","x","width","size","height","backgroundColor","activeResultIndex","mixBlendMode","transform","transformOrigin","transition","opacity","searchState","setSearchState","initialState","onStateChange","usePlugin"],"mappings":"gPAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,wBCQ3E,UAAqBC,UAC1BA,EAAAC,MACAA,EAAAC,MACAA,EAAAC,eACAA,EAAiB,UAAAC,qBACjBA,EAAuB,aACpBC,IAEH,MAAQC,SAAUC,GAAmBX,KAC9BY,EAAmBC,GAAwBC,EAAAA,SAAmC,MAQrF,GANAC,EAAAA,WAAU,IACD,MAAAJ,OAAA,EAAAA,EAAgBK,2BAA2BC,IAChDJ,EAAqBI,EAAK,KAE3B,CAACN,KAECC,EACI,OAAA,KAIT,MAAMM,EAAcN,EAAkBO,QACnCC,KAAI,CAACC,EAAQC,MAAqBD,SAAQC,oBAC1CC,QAAO,EAAGF,YAAaA,EAAOjB,YAAcA,IAG7C,OAAAoB,EAAAC,IAAC,MAAA,CACCnB,MAAO,IACFA,MAEDG,EAEHiB,SAAYR,EAAAE,KAAI,EAAGC,SAAQC,mBAC1BD,EAAOM,MAAMP,KAAI,CAACQ,EAAMC,IACtBL,EAAAC,IAAC,MAAA,CAECnB,MAAO,CACLwB,SAAU,WACVC,IAAKH,EAAKI,OAAOC,EAAI5B,EACrB6B,KAAMN,EAAKI,OAAOG,EAAI9B,EACtB+B,MAAOR,EAAKS,KAAKD,MAAQ/B,EACzBiC,OAAQV,EAAKS,KAAKC,OAASjC,EAC3BkC,gBACEjB,IAAkBV,EAAkB4B,kBAChChC,EACAD,EACNkC,aAAc,WACdC,UAAW,cACXC,gBAAiB,SACjBC,WAAY,0BACZC,QAAS,IAfN,GAAGvB,KAAiBO,UAsBrC,oBDhEyB,KACjB,MAAAnB,SAAEA,GAAaV,KACd8C,EAAaC,GAAkBjC,EAAAA,SAAsBkC,EAAAA,cAMrD,OAJPjC,EAAAA,WAAU,IACS,MAAVL,OAAU,EAAAA,EAAAuC,eAAehC,GAAU8B,EAAe9B,MACxD,CAACP,IAEG,CACLO,MAAO6B,EACPpC,WACF,wDAd6B,IAAMwC,YAAwBhD,EAAAA,aAAaC"}
|
package/dist/preact/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { usePlugin, useCapability } from "@embedpdf/core/preact";
|
|
2
|
-
import { SearchPlugin } from "@embedpdf/plugin-search";
|
|
2
|
+
import { SearchPlugin, initialState } from "@embedpdf/plugin-search";
|
|
3
3
|
export * from "@embedpdf/plugin-search";
|
|
4
4
|
import "preact";
|
|
5
5
|
import { useState, useEffect } from "preact/hooks";
|
|
@@ -8,16 +8,7 @@ const useSearchPlugin = () => usePlugin(SearchPlugin.id);
|
|
|
8
8
|
const useSearchCapability = () => useCapability(SearchPlugin.id);
|
|
9
9
|
const useSearch = () => {
|
|
10
10
|
const { provides } = useSearchCapability();
|
|
11
|
-
const [searchState, setSearchState] = useState(
|
|
12
|
-
flags: [],
|
|
13
|
-
results: [],
|
|
14
|
-
total: 0,
|
|
15
|
-
activeResultIndex: 0,
|
|
16
|
-
showAllResults: true,
|
|
17
|
-
query: "",
|
|
18
|
-
loading: false,
|
|
19
|
-
active: false
|
|
20
|
-
});
|
|
11
|
+
const [searchState, setSearchState] = useState(initialState);
|
|
21
12
|
useEffect(() => {
|
|
22
13
|
return provides == null ? void 0 : provides.onStateChange((state) => setSearchState(state));
|
|
23
14
|
}, [provides]);
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(initialState);\n\n useEffect(() => {\n return provides?.onStateChange((state) => setSearchState(state));\n }, [provides]);\n\n return {\n state: searchState,\n provides,\n };\n};\n","import { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\nimport { SearchResultState } from '@embedpdf/plugin-search';\n\nimport { useSearchCapability } from '../hooks';\n\ntype SearchLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n style?: CSSProperties;\n};\n\nexport function SearchLayer({\n pageIndex,\n scale,\n style,\n highlightColor = '#FFFF00',\n activeHighlightColor = '#FFBF00',\n ...props\n}: SearchLayoutProps) {\n const { provides: searchProvides } = useSearchCapability();\n const [searchResultState, setSearchResultState] = useState<SearchResultState | null>(null);\n\n useEffect(() => {\n return searchProvides?.onSearchResultStateChange((state) => {\n setSearchResultState(state);\n });\n }, [searchProvides]);\n\n if (!searchResultState) {\n return null;\n }\n\n // Filter results for current page while preserving original indices\n const pageResults = searchResultState.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === pageIndex);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {pageResults.map(({ result, originalIndex }) =>\n result.rects.map((rect, rectIndex) => (\n <div\n key={`${originalIndex}-${rectIndex}`}\n style={{\n position: 'absolute',\n top: rect.origin.y * scale,\n left: rect.origin.x * scale,\n width: rect.size.width * scale,\n height: rect.size.height * scale,\n backgroundColor:\n originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor,\n mixBlendMode: 'multiply',\n transform: 'scale(1.02)',\n transformOrigin: 'center',\n transition: 'opacity .3s ease-in-out',\n opacity: 1,\n }}\n ></div>\n )),\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,MAAM,YAAY,MAAM;AACvB,QAAA,EAAE,SAAS,IAAI,oBAAoB;AACzC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAsB,YAAY;AAExE,YAAU,MAAM;AACd,WAAO,qCAAU,cAAc,CAAC,UAAU,eAAe,KAAK;AAAA,EAAC,GAC9D,CAAC,QAAQ,CAAC;AAEN,SAAA;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;ACNO,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,uBAAuB;AAAA,EACvB,GAAG;AACL,GAAsB;AACpB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAAmC,IAAI;AAEzF,YAAU,MAAM;AACP,WAAA,iDAAgB,0BAA0B,CAAC,UAAU;AAC1D,2BAAqB,KAAK;AAAA,IAAA;AAAA,EAC3B,GACA,CAAC,cAAc,CAAC;AAEnB,MAAI,CAAC,mBAAmB;AACf,WAAA;AAAA,EAAA;AAIT,QAAM,cAAc,kBAAkB,QACnC,IAAI,CAAC,QAAQ,mBAAmB,EAAE,QAAQ,gBAAgB,EAC1D,OAAO,CAAC,EAAE,aAAa,OAAO,cAAc,SAAS;AAGtD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAY,YAAA;AAAA,QAAI,CAAC,EAAE,QAAQ,cAAc,MACxC,OAAO,MAAM,IAAI,CAAC,MAAM,cACtB;AAAA,UAAC;AAAA,UAAA;AAAA,YAEC,OAAO;AAAA,cACL,UAAU;AAAA,cACV,KAAK,KAAK,OAAO,IAAI;AAAA,cACrB,MAAM,KAAK,OAAO,IAAI;AAAA,cACtB,OAAO,KAAK,KAAK,QAAQ;AAAA,cACzB,QAAQ,KAAK,KAAK,SAAS;AAAA,cAC3B,iBACE,kBAAkB,kBAAkB,oBAChC,uBACA;AAAA,cACN,cAAc;AAAA,cACd,WAAW;AAAA,cACX,iBAAiB;AAAA,cACjB,YAAY;AAAA,cACZ,SAAS;AAAA,YAAA;AAAA,UACX;AAAA,UAhBK,GAAG,aAAa,IAAI,SAAS;AAAA,QAkBrC,CAAA;AAAA,MAAA;AAAA,IACH;AAAA,EACF;AAEJ;"}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-search"),r=require("react"),i=require("react/jsx-runtime"),s=()=>e.useCapability(t.SearchPlugin.id);exports.SearchLayer=function({pageIndex:e,scale:t,style:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-search"),r=require("react"),i=require("react/jsx-runtime"),s=()=>e.useCapability(t.SearchPlugin.id);exports.SearchLayer=function({pageIndex:e,scale:t,style:a,highlightColor:o="#FFFF00",activeHighlightColor:n="#FFBF00",...l}){const{provides:u}=s(),[c,p]=r.useState(null);if(r.useEffect((()=>null==u?void 0:u.onSearchResultStateChange((e=>{p(e)}))),[u]),!c)return null;const d=c.results.map(((e,t)=>({result:e,originalIndex:t}))).filter((({result:t})=>t.pageIndex===e));return i.jsx("div",{style:{...a},...l,children:d.map((({result:e,originalIndex:r})=>e.rects.map(((e,s)=>i.jsx("div",{style:{position:"absolute",top:e.origin.y*t,left:e.origin.x*t,width:e.size.width*t,height:e.size.height*t,backgroundColor:r===c.activeResultIndex?n:o,mixBlendMode:"multiply",transform:"scale(1.02)",transformOrigin:"center",transition:"opacity .3s ease-in-out",opacity:1}},`${r}-${s}`)))))})},exports.useSearch=()=>{const{provides:e}=s(),[i,a]=r.useState(t.initialState);return r.useEffect((()=>null==e?void 0:e.onStateChange((e=>a(e)))),[e]),{state:i,provides:e}},exports.useSearchCapability=s,exports.useSearchPlugin=()=>e.usePlugin(t.SearchPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(initialState);\n\n useEffect(() => {\n return provides?.onStateChange((state) => setSearchState(state));\n }, [provides]);\n\n return {\n state: searchState,\n provides,\n };\n};\n","import { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\nimport { SearchResultState } from '@embedpdf/plugin-search';\n\nimport { useSearchCapability } from '../hooks';\n\ntype SearchLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n style?: CSSProperties;\n};\n\nexport function SearchLayer({\n pageIndex,\n scale,\n style,\n highlightColor = '#FFFF00',\n activeHighlightColor = '#FFBF00',\n ...props\n}: SearchLayoutProps) {\n const { provides: searchProvides } = useSearchCapability();\n const [searchResultState, setSearchResultState] = useState<SearchResultState | null>(null);\n\n useEffect(() => {\n return searchProvides?.onSearchResultStateChange((state) => {\n setSearchResultState(state);\n });\n }, [searchProvides]);\n\n if (!searchResultState) {\n return null;\n }\n\n // Filter results for current page while preserving original indices\n const pageResults = searchResultState.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === pageIndex);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {pageResults.map(({ result, originalIndex }) =>\n result.rects.map((rect, rectIndex) => (\n <div\n key={`${originalIndex}-${rectIndex}`}\n style={{\n position: 'absolute',\n top: rect.origin.y * scale,\n left: rect.origin.x * scale,\n width: rect.size.width * scale,\n height: rect.size.height * scale,\n backgroundColor:\n originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor,\n mixBlendMode: 'multiply',\n transform: 'scale(1.02)',\n transformOrigin: 'center',\n transition: 'opacity .3s ease-in-out',\n opacity: 1,\n }}\n ></div>\n )),\n )}\n </div>\n );\n}\n"],"names":["useSearchCapability","useCapability","SearchPlugin","id","pageIndex","scale","style","highlightColor","activeHighlightColor","props","provides","searchProvides","searchResultState","setSearchResultState","useState","useEffect","onSearchResultStateChange","state","pageResults","results","map","result","originalIndex","filter","jsxRuntime","jsx","children","rects","rect","rectIndex","position","top","origin","y","left","x","width","size","height","backgroundColor","activeResultIndex","mixBlendMode","transform","transformOrigin","transition","opacity","searchState","setSearchState","initialState","onStateChange","usePlugin"],"mappings":"+MAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,wBCQ3E,UAAqBC,UAC1BA,EAAAC,MACAA,EAAAC,MACAA,EAAAC,eACAA,EAAiB,UAAAC,qBACjBA,EAAuB,aACpBC,IAEH,MAAQC,SAAUC,GAAmBX,KAC9BY,EAAmBC,GAAwBC,EAAAA,SAAmC,MAQrF,GANAC,EAAAA,WAAU,IACD,MAAAJ,OAAA,EAAAA,EAAgBK,2BAA2BC,IAChDJ,EAAqBI,EAAK,KAE3B,CAACN,KAECC,EACI,OAAA,KAIT,MAAMM,EAAcN,EAAkBO,QACnCC,KAAI,CAACC,EAAQC,MAAqBD,SAAQC,oBAC1CC,QAAO,EAAGF,YAAaA,EAAOjB,YAAcA,IAG7C,OAAAoB,EAAAC,IAAC,MAAA,CACCnB,MAAO,IACFA,MAEDG,EAEHiB,SAAYR,EAAAE,KAAI,EAAGC,SAAQC,mBAC1BD,EAAOM,MAAMP,KAAI,CAACQ,EAAMC,IACtBL,EAAAC,IAAC,MAAA,CAECnB,MAAO,CACLwB,SAAU,WACVC,IAAKH,EAAKI,OAAOC,EAAI5B,EACrB6B,KAAMN,EAAKI,OAAOG,EAAI9B,EACtB+B,MAAOR,EAAKS,KAAKD,MAAQ/B,EACzBiC,OAAQV,EAAKS,KAAKC,OAASjC,EAC3BkC,gBACEjB,IAAkBV,EAAkB4B,kBAChChC,EACAD,EACNkC,aAAc,WACdC,UAAW,cACXC,gBAAiB,SACjBC,WAAY,0BACZC,QAAS,IAfN,GAAGvB,KAAiBO,UAsBrC,oBDhEyB,KACjB,MAAAnB,SAAEA,GAAaV,KACd8C,EAAaC,GAAkBjC,EAAAA,SAAsBkC,EAAAA,cAMrD,OAJPjC,EAAAA,WAAU,IACS,MAAVL,OAAU,EAAAA,EAAAuC,eAAehC,GAAU8B,EAAe9B,MACxD,CAACP,IAEG,CACLO,MAAO6B,EACPpC,WACF,wDAd6B,IAAMwC,YAAwBhD,EAAAA,aAAaC"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { usePlugin, useCapability } from "@embedpdf/core/react";
|
|
2
|
-
import { SearchPlugin } from "@embedpdf/plugin-search";
|
|
2
|
+
import { SearchPlugin, initialState } from "@embedpdf/plugin-search";
|
|
3
3
|
export * from "@embedpdf/plugin-search";
|
|
4
4
|
import { useState, useEffect } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -7,16 +7,7 @@ const useSearchPlugin = () => usePlugin(SearchPlugin.id);
|
|
|
7
7
|
const useSearchCapability = () => useCapability(SearchPlugin.id);
|
|
8
8
|
const useSearch = () => {
|
|
9
9
|
const { provides } = useSearchCapability();
|
|
10
|
-
const [searchState, setSearchState] = useState(
|
|
11
|
-
flags: [],
|
|
12
|
-
results: [],
|
|
13
|
-
total: 0,
|
|
14
|
-
activeResultIndex: 0,
|
|
15
|
-
showAllResults: true,
|
|
16
|
-
query: "",
|
|
17
|
-
loading: false,
|
|
18
|
-
active: false
|
|
19
|
-
});
|
|
10
|
+
const [searchState, setSearchState] = useState(initialState);
|
|
20
11
|
useEffect(() => {
|
|
21
12
|
return provides == null ? void 0 : provides.onStateChange((state) => setSearchState(state));
|
|
22
13
|
}, [provides]);
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-search.ts","../../src/shared/components/search-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\nimport { useEffect, useState } from '@framework';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const [searchState, setSearchState] = useState<SearchState>(initialState);\n\n useEffect(() => {\n return provides?.onStateChange((state) => setSearchState(state));\n }, [provides]);\n\n return {\n state: searchState,\n provides,\n };\n};\n","import { useEffect, useState, HTMLAttributes, CSSProperties } from '@framework';\nimport { SearchResultState } from '@embedpdf/plugin-search';\n\nimport { useSearchCapability } from '../hooks';\n\ntype SearchLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n style?: CSSProperties;\n};\n\nexport function SearchLayer({\n pageIndex,\n scale,\n style,\n highlightColor = '#FFFF00',\n activeHighlightColor = '#FFBF00',\n ...props\n}: SearchLayoutProps) {\n const { provides: searchProvides } = useSearchCapability();\n const [searchResultState, setSearchResultState] = useState<SearchResultState | null>(null);\n\n useEffect(() => {\n return searchProvides?.onSearchResultStateChange((state) => {\n setSearchResultState(state);\n });\n }, [searchProvides]);\n\n if (!searchResultState) {\n return null;\n }\n\n // Filter results for current page while preserving original indices\n const pageResults = searchResultState.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === pageIndex);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {pageResults.map(({ result, originalIndex }) =>\n result.rects.map((rect, rectIndex) => (\n <div\n key={`${originalIndex}-${rectIndex}`}\n style={{\n position: 'absolute',\n top: rect.origin.y * scale,\n left: rect.origin.x * scale,\n width: rect.size.width * scale,\n height: rect.size.height * scale,\n backgroundColor:\n originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor,\n mixBlendMode: 'multiply',\n transform: 'scale(1.02)',\n transformOrigin: 'center',\n transition: 'opacity .3s ease-in-out',\n opacity: 1,\n }}\n ></div>\n )),\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,MAAM,YAAY,MAAM;AACvB,QAAA,EAAE,SAAS,IAAI,oBAAoB;AACzC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAsB,YAAY;AAExE,YAAU,MAAM;AACd,WAAO,qCAAU,cAAc,CAAC,UAAU,eAAe,KAAK;AAAA,EAAC,GAC9D,CAAC,QAAQ,CAAC;AAEN,SAAA;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;ACNO,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,uBAAuB;AAAA,EACvB,GAAG;AACL,GAAsB;AACpB,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAAmC,IAAI;AAEzF,YAAU,MAAM;AACP,WAAA,iDAAgB,0BAA0B,CAAC,UAAU;AAC1D,2BAAqB,KAAK;AAAA,IAAA;AAAA,EAC3B,GACA,CAAC,cAAc,CAAC;AAEnB,MAAI,CAAC,mBAAmB;AACf,WAAA;AAAA,EAAA;AAIT,QAAM,cAAc,kBAAkB,QACnC,IAAI,CAAC,QAAQ,mBAAmB,EAAE,QAAQ,gBAAgB,EAC1D,OAAO,CAAC,EAAE,aAAa,OAAO,cAAc,SAAS;AAGtD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAY,YAAA;AAAA,QAAI,CAAC,EAAE,QAAQ,cAAc,MACxC,OAAO,MAAM,IAAI,CAAC,MAAM,cACtB;AAAA,UAAC;AAAA,UAAA;AAAA,YAEC,OAAO;AAAA,cACL,UAAU;AAAA,cACV,KAAK,KAAK,OAAO,IAAI;AAAA,cACrB,MAAM,KAAK,OAAO,IAAI;AAAA,cACtB,OAAO,KAAK,KAAK,QAAQ;AAAA,cACzB,QAAQ,KAAK,KAAK,SAAS;AAAA,cAC3B,iBACE,kBAAkB,kBAAkB,oBAChC,uBACA;AAAA,cACN,cAAc;AAAA,cACd,WAAW;AAAA,cACX,iBAAiB;AAAA,cACjB,YAAY;AAAA,cACZ,SAAS;AAAA,YAAA;AAAA,UACX;AAAA,UAhBK,GAAG,aAAa,IAAI,SAAS;AAAA,QAkBrC,CAAA;AAAA,MAAA;AAAA,IACH;AAAA,EACF;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './search-layer';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTMLAttributes, CSSProperties } from '../../react/adapter.ts';
|
|
2
|
+
type SearchLayoutProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
highlightColor?: string;
|
|
6
|
+
activeHighlightColor?: string;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
};
|
|
9
|
+
export declare function SearchLayer({ pageIndex, scale, style, highlightColor, activeHighlightColor, ...props }: SearchLayoutProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-search';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SearchPlugin, SearchState } from '../../index.ts';
|
|
2
|
+
export declare const useSearchPlugin: () => {
|
|
3
|
+
plugin: SearchPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useSearchCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../index.ts').SearchCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const useSearch: () => {
|
|
13
|
+
state: SearchState;
|
|
14
|
+
provides: Readonly<import('../../index.ts').SearchCapability> | null;
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
highlightColor?: string;
|
|
6
|
+
activeHighlightColor?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const SearchLayer: import('svelte', { with: { "resolution-mode": "import" } }).Component<Props, {}, "">;
|
|
9
|
+
type SearchLayer = ReturnType<typeof SearchLayer>;
|
|
10
|
+
export default SearchLayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SearchLayer } from './SearchLayer.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-search.svelte';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SearchPlugin, SearchState } from '../../lib/index.ts';
|
|
2
|
+
export declare const useSearchPlugin: () => {
|
|
3
|
+
plugin: SearchPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useSearchCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../lib/index.ts').SearchCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const useSearch: () => {
|
|
13
|
+
readonly state: SearchState;
|
|
14
|
+
readonly provides: Readonly<import('../../lib/index.ts').SearchCapability> | null;
|
|
15
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/core/svelte"),r=require("@embedpdf/plugin-search");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}require("svelte/internal/disclose-version");const o=i(e),s=()=>t.useCapability(r.SearchPlugin.id);var n=o.from_html("<div></div>"),a=o.from_html("<div></div>");exports.SearchLayer=function(e,t){o.push(t,!0);const r=o.prop(t,"highlightColor",3,"#FFFF00"),i=o.prop(t,"activeHighlightColor",3,"#FFBF00"),l=o.rest_props(t,["$$slots","$$events","$$legacy","pageIndex","scale","highlightColor","activeHighlightColor"]),{provides:c}=s();let p=o.state(null);o.user_effect((()=>{if(c)return c.onSearchResultStateChange((e=>{o.set(p,e,!0)}))}));const g=o.derived((()=>o.get(p)?o.get(p).results.map(((e,t)=>({result:e,originalIndex:t}))).filter((({result:e})=>e.pageIndex===t.pageIndex)):[]));var u=o.comment(),d=o.first_child(u),h=e=>{var s=a();o.attribute_effect(s,(()=>({...l}))),o.each(s,21,(()=>o.get(g)),o.index,((e,s)=>{var a=o.comment(),l=o.first_child(a);o.each(l,17,(()=>o.get(s).result.rects),o.index,((e,a)=>{var l=n();let c;o.template_effect((e=>c=o.set_style(l,"",c,e)),[()=>({position:"absolute",top:o.get(a).origin.y*t.scale+"px",left:o.get(a).origin.x*t.scale+"px",width:o.get(a).size.width*t.scale+"px",height:o.get(a).size.height*t.scale+"px","background-color":o.get(s).originalIndex===o.get(p).activeResultIndex?i():r(),"mix-blend-mode":"multiply",transform:"scale(1.02)","transform-origin":"center",transition:"opacity .3s ease-in-out",opacity:"1"})]),o.append(e,l)})),o.append(e,a)})),o.reset(s),o.append(e,s)};o.if(d,(e=>{o.get(p)&&e(h)})),o.append(e,u),o.pop()},exports.useSearch=()=>{const e=o.derived(s),t=o.derived((()=>o.get(e).provides));let i=o.state(o.proxy(r.initialState));return o.user_effect((()=>{if(o.get(t))return o.get(t).onStateChange((e=>{o.set(i,e,!0)}))})),{get state(){return o.get(i)},get provides(){return o.get(t)}}},exports.useSearchCapability=s,exports.useSearchPlugin=()=>t.usePlugin(r.SearchPlugin.id),Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-search.svelte.ts","../../src/svelte/components/SearchLayer.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = $derived(useSearchCapability());\n let searchState = $state<SearchState>(initialState);\n\n $effect(() => {\n if (!provides) return;\n return provides.onStateChange((state) => {\n searchState = state;\n });\n });\n\n return {\n get state() {\n return searchState;\n },\n get provides() {\n return provides;\n },\n };\n};\n","<script lang=\"ts\">\n import type { SearchResultState } from '@embedpdf/plugin-search';\n import { useSearchCapability } from '../hooks';\n import type { HTMLAttributes } from 'svelte/elements';\n\n interface Props extends HTMLAttributes<HTMLDivElement> {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n }\n\n const {\n pageIndex,\n scale,\n highlightColor = '#FFFF00',\n activeHighlightColor = '#FFBF00',\n ...divProps\n }: Props = $props();\n\n const { provides: searchProvides } = useSearchCapability();\n let searchResultState = $state<SearchResultState | null>(null);\n\n $effect(() => {\n if (!searchProvides) return;\n return searchProvides.onSearchResultStateChange((state) => {\n searchResultState = state;\n });\n });\n\n const pageResults = $derived(\n searchResultState\n ? searchResultState.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === pageIndex)\n : [],\n );\n</script>\n\n{#if searchResultState}\n <div {...divProps}>\n {#each pageResults as { result, originalIndex }}\n {#each result.rects as rect}\n <div\n style:position=\"absolute\"\n style:top=\"{rect.origin.y * scale}px\"\n style:left=\"{rect.origin.x * scale}px\"\n style:width=\"{rect.size.width * scale}px\"\n style:height=\"{rect.size.height * scale}px\"\n style:background-color={originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor}\n style:mix-blend-mode=\"multiply\"\n style:transform=\"scale(1.02)\"\n style:transform-origin=\"center\"\n style:transition=\"opacity .3s ease-in-out\"\n style:opacity=\"1\"\n ></div>\n {/each}\n {/each}\n </div>\n{/if}\n"],"names":["useSearchCapability","useCapability","SearchPlugin","id","highlightColor","activeHighlightColor","divProps","$","rest_props","$$props","provides","searchProvides","searchResultState","user_effect","onSearchResultStateChange","state","$__namespace","set","pageResults","get","results","map","result","originalIndex","filter","pageIndex","index","$$anchor","$$item","rects","rect","origin","y","scale","x","size","width","height","activeResultIndex","consequent","searchState","initialState","onStateChange","usePlugin"],"mappings":"sgBAIaA,EAA4B,IAAAC,gBAA4BC,EAAAA,aAAaC,iHCW9E,MAAAC,8BAAiB,WACjBC,oCAAuB,WACpBC,EAAOC,EAAAC,WAAAC,EAAA,gGAGJC,SAAUC,GAAmBX,IACjC,IAAAY,UAAqD,MAEzDL,EAAAM,aAAc,QACPF,EACE,OAAAA,EAAeG,2BAA2BC,IAC/CC,EAAAC,IAAAL,EAAoBG,GAAK,EAAA,GAC1B,IAGG,MAAAG,uBACJN,GACIL,EAAAY,IAAAP,GAAkBQ,QACfC,KAAK,CAAAC,EAAQC,KAAa,CAAQD,SAAQC,oBAC1CC,QAAM,EAAIF,YAAaA,EAAOG,YAAShB,EAAAgB,qGAMvCnB,6BACAY,IAAWX,EAAAmB,OAAA,CAAAC,EAAAC,oEAAON,OACTO,OAAKtB,EAAAmB,OAAA,CAAAC,EAAIG,yGAGPA,GAAKC,OAAOC,EAACvB,EAAAwB,sBACZH,GAAKC,OAAOG,EAACzB,EAAAwB,uBACZH,GAAKK,KAAKC,MAAK3B,EAAAwB,wBACdH,GAAKK,KAAKE,OAAM5B,EAAAwB,WACP,4BARGV,sBAQeX,GAAkB0B,kBACxDjC,IACAD,uNAZTQ,MAAiB2B,EAAA,yBAFtB,2CD9BgCvC,GAAtBU,0BAAAA,WACJ,IAAA8B,kBAAkCC,EAAAA,sBAEtClC,EAAAM,2BACOH,GACE,OAAAH,EAAAY,IAAAT,GAASgC,eAAe3B,IACfC,EAAAC,IAAAuB,EAAAzB,GAAA,EAAA,GACf,KAIG,SAAAA,gBACKyB,EACT,EACI,YAAA9B,gBACKA,4DAnBwB,IAAAiC,YAAwBzC,EAAAA,aAAaC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as $ from "svelte/internal/client";
|
|
2
|
+
import { usePlugin, useCapability } from "@embedpdf/core/svelte";
|
|
3
|
+
import { SearchPlugin, initialState } from "@embedpdf/plugin-search";
|
|
4
|
+
export * from "@embedpdf/plugin-search";
|
|
5
|
+
import "svelte/internal/disclose-version";
|
|
6
|
+
const useSearchPlugin = () => usePlugin(SearchPlugin.id);
|
|
7
|
+
const useSearchCapability = () => useCapability(SearchPlugin.id);
|
|
8
|
+
const useSearch = () => {
|
|
9
|
+
const $$d = $.derived(useSearchCapability), provides = $.derived(() => $.get($$d).provides);
|
|
10
|
+
let searchState = $.state($.proxy(initialState));
|
|
11
|
+
$.user_effect(() => {
|
|
12
|
+
if (!$.get(provides)) return;
|
|
13
|
+
return $.get(provides).onStateChange((state) => {
|
|
14
|
+
$.set(searchState, state, true);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get state() {
|
|
19
|
+
return $.get(searchState);
|
|
20
|
+
},
|
|
21
|
+
get provides() {
|
|
22
|
+
return $.get(provides);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var root_3 = $.from_html(`<div></div>`);
|
|
27
|
+
var root_1 = $.from_html(`<div></div>`);
|
|
28
|
+
function SearchLayer($$anchor, $$props) {
|
|
29
|
+
$.push($$props, true);
|
|
30
|
+
const highlightColor = $.prop($$props, "highlightColor", 3, "#FFFF00"), activeHighlightColor = $.prop($$props, "activeHighlightColor", 3, "#FFBF00"), divProps = $.rest_props($$props, [
|
|
31
|
+
"$$slots",
|
|
32
|
+
"$$events",
|
|
33
|
+
"$$legacy",
|
|
34
|
+
"pageIndex",
|
|
35
|
+
"scale",
|
|
36
|
+
"highlightColor",
|
|
37
|
+
"activeHighlightColor"
|
|
38
|
+
]);
|
|
39
|
+
const { provides: searchProvides } = useSearchCapability();
|
|
40
|
+
let searchResultState = $.state(null);
|
|
41
|
+
$.user_effect(() => {
|
|
42
|
+
if (!searchProvides) return;
|
|
43
|
+
return searchProvides.onSearchResultStateChange((state) => {
|
|
44
|
+
$.set(searchResultState, state, true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const pageResults = $.derived(() => $.get(searchResultState) ? $.get(searchResultState).results.map((result, originalIndex) => ({ result, originalIndex })).filter(({ result }) => result.pageIndex === $$props.pageIndex) : []);
|
|
48
|
+
var fragment = $.comment();
|
|
49
|
+
var node = $.first_child(fragment);
|
|
50
|
+
{
|
|
51
|
+
var consequent = ($$anchor2) => {
|
|
52
|
+
var div = root_1();
|
|
53
|
+
$.attribute_effect(div, () => ({ ...divProps }));
|
|
54
|
+
$.each(div, 21, () => $.get(pageResults), $.index, ($$anchor3, $$item) => {
|
|
55
|
+
let result = () => $.get($$item).result;
|
|
56
|
+
let originalIndex = () => $.get($$item).originalIndex;
|
|
57
|
+
var fragment_1 = $.comment();
|
|
58
|
+
var node_1 = $.first_child(fragment_1);
|
|
59
|
+
$.each(node_1, 17, () => result().rects, $.index, ($$anchor4, rect) => {
|
|
60
|
+
var div_1 = root_3();
|
|
61
|
+
let styles;
|
|
62
|
+
$.template_effect(($0) => styles = $.set_style(div_1, "", styles, $0), [
|
|
63
|
+
() => ({
|
|
64
|
+
position: "absolute",
|
|
65
|
+
top: `${$.get(rect).origin.y * $$props.scale}px`,
|
|
66
|
+
left: `${$.get(rect).origin.x * $$props.scale}px`,
|
|
67
|
+
width: `${$.get(rect).size.width * $$props.scale}px`,
|
|
68
|
+
height: `${$.get(rect).size.height * $$props.scale}px`,
|
|
69
|
+
"background-color": originalIndex() === $.get(searchResultState).activeResultIndex ? activeHighlightColor() : highlightColor(),
|
|
70
|
+
"mix-blend-mode": "multiply",
|
|
71
|
+
transform: "scale(1.02)",
|
|
72
|
+
"transform-origin": "center",
|
|
73
|
+
transition: "opacity .3s ease-in-out",
|
|
74
|
+
opacity: "1"
|
|
75
|
+
})
|
|
76
|
+
]);
|
|
77
|
+
$.append($$anchor4, div_1);
|
|
78
|
+
});
|
|
79
|
+
$.append($$anchor3, fragment_1);
|
|
80
|
+
});
|
|
81
|
+
$.reset(div);
|
|
82
|
+
$.append($$anchor2, div);
|
|
83
|
+
};
|
|
84
|
+
$.if(node, ($$render) => {
|
|
85
|
+
if ($.get(searchResultState)) $$render(consequent);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
$.append($$anchor, fragment);
|
|
89
|
+
$.pop();
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
SearchLayer,
|
|
93
|
+
useSearch,
|
|
94
|
+
useSearchCapability,
|
|
95
|
+
useSearchPlugin
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-search.svelte.ts","../../src/svelte/components/SearchLayer.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = $derived(useSearchCapability());\n let searchState = $state<SearchState>(initialState);\n\n $effect(() => {\n if (!provides) return;\n return provides.onStateChange((state) => {\n searchState = state;\n });\n });\n\n return {\n get state() {\n return searchState;\n },\n get provides() {\n return provides;\n },\n };\n};\n","<script lang=\"ts\">\n import type { SearchResultState } from '@embedpdf/plugin-search';\n import { useSearchCapability } from '../hooks';\n import type { HTMLAttributes } from 'svelte/elements';\n\n interface Props extends HTMLAttributes<HTMLDivElement> {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n }\n\n const {\n pageIndex,\n scale,\n highlightColor = '#FFFF00',\n activeHighlightColor = '#FFBF00',\n ...divProps\n }: Props = $props();\n\n const { provides: searchProvides } = useSearchCapability();\n let searchResultState = $state<SearchResultState | null>(null);\n\n $effect(() => {\n if (!searchProvides) return;\n return searchProvides.onSearchResultStateChange((state) => {\n searchResultState = state;\n });\n });\n\n const pageResults = $derived(\n searchResultState\n ? searchResultState.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === pageIndex)\n : [],\n );\n</script>\n\n{#if searchResultState}\n <div {...divProps}>\n {#each pageResults as { result, originalIndex }}\n {#each result.rects as rect}\n <div\n style:position=\"absolute\"\n style:top=\"{rect.origin.y * scale}px\"\n style:left=\"{rect.origin.x * scale}px\"\n style:width=\"{rect.size.width * scale}px\"\n style:height=\"{rect.size.height * scale}px\"\n style:background-color={originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor}\n style:mix-blend-mode=\"multiply\"\n style:transform=\"scale(1.02)\"\n style:transform-origin=\"center\"\n style:transition=\"opacity .3s ease-in-out\"\n style:opacity=\"1\"\n ></div>\n {/each}\n {/each}\n </div>\n{/if}\n"],"names":["$$anchor"],"mappings":";;;;;AAGa,MAAA,kBAAwB,MAAA,UAAwB,aAAa,EAAE;AAC/D,MAAA,sBAA4B,MAAA,cAA4B,aAAa,EAAE;AAEvE,MAAA,kBAAkB;wBACC,sBAAtB,sCAAA,QAAA;AACJ,MAAA,8BAAkC,YAAY,CAAA;AAElD,IAAA,kBAAc;eACP,QAAU,EAAA;AACR,WAAA,EAAA,IAAA,QAAA,EAAS,cAAe,CAAA,UAAU;AACzB,QAAA,IAAA,aAAA,OAAA,IAAA;AAAA,KACf;AAAA,GACF;;IAGK,IAAA,QAAQ;mBACH,WAAA;AAAA,IACT;AAAA,IACI,IAAA,WAAW;mBACN,QAAA;AAAA;;AAGb;;;wCCzBA;;AAeI,QAAA,sDAAiB,SAAS,GAC1B,kEAAuB,SAAS,GAC7B,WAAO,EAAA,WAAA,SAAA;AAAA;;;;;;;;UAGJ,UAAU,eAAc,IAAK,oBAAmB;AACpD,MAAA,4BAAqD,IAAI;AAE7D,IAAA,YAAc,MAAA;SACP,eAAc;AACZ,WAAA,eAAe,0BAA2B,CAAA,UAAU;AACzD,QAAA,IAAA,mBAAoB,OAAK,IAAA;AAAA,KAC1B;AAAA,GACF;AAEK,QAAA,oCACJ,iBAAgB,IACZ,EAAA,IAAA,iBAAiB,EAAC,QACf,IAAK,CAAA,QAAQ,mBAAa,EAAQ,QAAQ,kBAC1C,OAAM,CAAA,EAAI,OAAM,MAAO,OAAO,cAAS,QAAA,SAAA;;;;;;0CAMvC,SAAQ,EAAA;kCACR,WAAW,GAAA,EAAA,OAAA,CAAAA,WAAA,WAAA;AAAO,YAAA,6BAAA;AAAQ,YAAA,oCAAA;;;iCACxB,OAAM,EAAC,OAAK,EAAA,OAAA,CAAAA,WAAI,SAAI;;;;;;4BAGX,IAAI,EAAC,OAAO,IAAC,QAAA,KAAA;AAAA,6BACZ,IAAI,EAAC,OAAO,IAAC,QAAA,KAAA;AAAA,8BACZ,IAAI,EAAC,KAAK,QAAK,QAAA,KAAA;AAAA,+BACd,IAAI,EAAC,KAAK,SAAM,QAAA,KAAA;AAAA,cACP,oBAAA,0BAAkB,iBAAiB,EAAC,oBACxD,yBACA,eAAc;AAAA;;;;;;;;;;;;;;;gBAZvB,iBAAiB,EAAA,UAAA,UAAA;AAAA;;;;AAFtB;"}
|
package/dist/vue/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),r=require("@embedpdf/plugin-search"),l=()=>t.useCapability(r.SearchPlugin.id),o=e.defineComponent({__name:"search-layer",props:{pageIndex:{},scale:{},highlightColor:{default:"#FFFF00"},activeHighlightColor:{default:"#FFBF00"}},setup(t){const r=t,{provides:o}=l(),n=e.ref(null),a=e.computed((()=>n.value?n.value.results.map(((e,t)=>({result:e,originalIndex:t}))).filter((({result:e})=>e.pageIndex===r.pageIndex)):[]));let i;return e.onMounted((()=>{o.value&&(i=o.value.onSearchResultStateChange((e=>{n.value=e})))})),e.onUnmounted((()=>{null==i||i()})),(t,r)=>n.value?(e.openBlock(),e.createElementBlock("div",e.normalizeProps(e.mergeProps({key:0},t.$attrs)),[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.value,(({result:r,originalIndex:l},o)=>(e.openBlock(),e.createElementBlock("div",{key:`result-${o}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.rects,((r,a)=>(e.openBlock(),e.createElementBlock("div",{key:`rect-${o}-${a}`,style:e.normalizeStyle({position:"absolute",top:r.origin.y*t.scale+"px",left:r.origin.x*t.scale+"px",width:r.size.width*t.scale+"px",height:r.size.height*t.scale+"px",backgroundColor:l===n.value.activeResultIndex?t.activeHighlightColor:t.highlightColor,mixBlendMode:"multiply",transform:"scale(1.02)",transformOrigin:"center",transition:"opacity .3s ease-in-out",opacity:1})},null,4)))),128))])))),128))],16)):e.createCommentVNode("",!0)}});exports.SearchLayer=o,exports.useSearch=()=>{const{provides:t}=l(),o=e.ref(r.initialState);return e.onMounted((()=>{if(!t.value)return;const r=t.value.onStateChange((e=>{o.value=e}));e.onUnmounted((()=>{r()}))})),{state:o,provides:t}},exports.useSearchCapability=l,exports.useSearchPlugin=()=>t.usePlugin(r.SearchPlugin.id),Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/vue/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-search.ts","../../src/vue/components/search-layer.vue"],"sourcesContent":["import { ref, onMounted, onUnmounted } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { SearchPlugin, SearchState } from '@embedpdf/plugin-search';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const searchState = ref<SearchState>(
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-search.ts","../../src/vue/components/search-layer.vue"],"sourcesContent":["import { ref, onMounted, onUnmounted } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const searchState = ref<SearchState>(initialState);\n\n onMounted(() => {\n if (!provides.value) return;\n\n const unsubscribe = provides.value.onStateChange((state) => {\n searchState.value = state;\n });\n\n onUnmounted(() => {\n unsubscribe();\n });\n });\n\n return {\n state: searchState,\n provides,\n };\n};\n","<template>\n <div v-if=\"searchResultState\" v-bind=\"$attrs\">\n <div v-for=\"({ result, originalIndex }, idx) in pageResults\" :key=\"`result-${idx}`\">\n <div\n v-for=\"(rect, rectIdx) in result.rects\"\n :key=\"`rect-${idx}-${rectIdx}`\"\n :style=\"{\n position: 'absolute',\n top: `${rect.origin.y * scale}px`,\n left: `${rect.origin.x * scale}px`,\n width: `${rect.size.width * scale}px`,\n height: `${rect.size.height * scale}px`,\n backgroundColor:\n originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor,\n mixBlendMode: 'multiply',\n transform: 'scale(1.02)',\n transformOrigin: 'center',\n transition: 'opacity .3s ease-in-out',\n opacity: 1,\n }\"\n />\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, computed, onMounted, onUnmounted } from 'vue';\nimport type { SearchResultState } from '@embedpdf/plugin-search';\nimport { useSearchCapability } from '../hooks/use-search';\n\ninterface SearchLayerProps {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n}\n\nconst props = withDefaults(defineProps<SearchLayerProps>(), {\n highlightColor: '#FFFF00',\n activeHighlightColor: '#FFBF00',\n});\n\nconst { provides: searchProvides } = useSearchCapability();\nconst searchResultState = ref<SearchResultState | null>(null);\n\n// Filter results for current page while preserving original indices\nconst pageResults = computed(() => {\n if (!searchResultState.value) return [];\n\n return searchResultState.value.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === props.pageIndex);\n});\n\nlet unsubscribe: (() => void) | undefined;\n\nonMounted(() => {\n if (!searchProvides.value) return;\n\n unsubscribe = searchProvides.value.onSearchResultStateChange((state) => {\n searchResultState.value = state;\n });\n});\n\nonUnmounted(() => {\n unsubscribe?.();\n});\n</script>\n"],"names":["useSearchCapability","useCapability","SearchPlugin","id","props","__props","provides","searchProvides","searchResultState","ref","pageResults","computed","value","results","map","result","originalIndex","filter","pageIndex","unsubscribe","onMounted","onSearchResultStateChange","state","onUnmounted","_openBlock","openBlock","_createElementBlock","$attrs","_Fragment","idx","createElementBlock","key","rects","rect","rectIdx","style","_normalizeStyle","top","origin","y","scale","left","x","width","size","height","activeResultIndex","activeHighlightColor","highlightColor","searchState","initialState","onStateChange","usePlugin"],"mappings":"4KAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,kKCkClF,MAAMC,EAAQC,GAKNC,SAAUC,GAAmBP,IAC/BQ,EAAoBC,MAA8B,MAGlDC,EAAcC,EAAAA,UAAS,IACtBH,EAAkBI,MAEhBJ,EAAkBI,MAAMC,QAC5BC,KAAI,CAACC,EAAQC,KAAA,CAAqBD,SAAQC,oBAC1CC,QAAO,EAAGF,YAAaA,EAAOG,YAAcd,EAAMc,YAJhB,KAOnC,IAAAC,SAEJC,EAAAA,WAAU,KACHb,EAAeK,QAEpBO,EAAcZ,EAAeK,MAAMS,2BAA2BC,IAC5Dd,EAAkBI,MAAQU,CAAA,IAC3B,IAGHC,EAAAA,aAAY,KACI,MAAAJ,GAAAA,GAAA,WAlEHX,EAAiBI,OAA5BY,EAAAC,YAAAC,EAAAA,mBAuBM,4CAvBgCC,EAAMA,SAAA,EAC1CH,EAAAA,WAAA,GAAAE,qBAqBME,EAAAA,2BArB0ClB,EAAWE,OAAA,EAA5CG,SAAQC,iBAAiBa,mBAAxCH,EAAAI,mBAqBM,MAAA,CArBwDC,cAAeF,OAC3EL,EAAAA,WAAA,GAAAE,EAmBEI,mBAAAF,6BAlB0Bb,EAAOiB,OAAzB,CAAAC,EAAMC,mBADhBR,EAAAI,mBAmBE,MAAA,CAjBCC,IAAG,QAAUF,KAAOK,IACpBC,MAAKC,EAAAA,eAAA,qBAAsDC,IAAAJ,EAAKK,OAAOC,EAAIC,EAAKA,MAArB,KAA8CC,KAAAR,EAAKK,OAAOI,EAAIF,EAAKA,MAArB,KAA+CG,MAAAV,EAAKW,KAAKD,MAAQH,EAAKA,MAAvB,KAAkDK,OAAAZ,EAAKW,KAAKC,OAASL,EAAKA,MAAxB,qBAAqExB,IAAkBR,EAAiBI,MAACkC,kBAAkCC,EAAoBA,qBAAiBC,EAAcA,mPDCxX,KACjB,MAAA1C,SAAEA,GAAaN,IACfiD,EAAcxC,MAAiByC,gBAc9B,OAZP9B,EAAAA,WAAU,KACJ,IAACd,EAASM,MAAO,OAErB,MAAMO,EAAcb,EAASM,MAAMuC,eAAe7B,IAChD2B,EAAYrC,MAAQU,CAAA,IAGtBC,EAAAA,aAAY,KACEJ,GAAA,GACb,IAGI,CACLG,MAAO2B,EACP3C,WACF,wDAtB6B,IAAM8C,YAAwBlD,EAAAA,aAAaC"}
|
package/dist/vue/index.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { ref, onMounted, onUnmounted, defineComponent, computed, createElementBlock, createCommentVNode, openBlock, normalizeProps, mergeProps, Fragment, renderList, normalizeStyle } from "vue";
|
|
2
2
|
import { usePlugin, useCapability } from "@embedpdf/core/vue";
|
|
3
|
-
import { SearchPlugin } from "@embedpdf/plugin-search";
|
|
3
|
+
import { SearchPlugin, initialState } from "@embedpdf/plugin-search";
|
|
4
4
|
export * from "@embedpdf/plugin-search";
|
|
5
5
|
const useSearchPlugin = () => usePlugin(SearchPlugin.id);
|
|
6
6
|
const useSearchCapability = () => useCapability(SearchPlugin.id);
|
|
7
7
|
const useSearch = () => {
|
|
8
8
|
const { provides } = useSearchCapability();
|
|
9
|
-
const searchState = ref(
|
|
10
|
-
flags: [],
|
|
11
|
-
results: [],
|
|
12
|
-
total: 0,
|
|
13
|
-
activeResultIndex: 0,
|
|
14
|
-
showAllResults: true,
|
|
15
|
-
query: "",
|
|
16
|
-
loading: false,
|
|
17
|
-
active: false
|
|
18
|
-
});
|
|
9
|
+
const searchState = ref(initialState);
|
|
19
10
|
onMounted(() => {
|
|
20
11
|
if (!provides.value) return;
|
|
21
12
|
const unsubscribe = provides.value.onStateChange((state) => {
|
package/dist/vue/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-search.ts","../../src/vue/components/search-layer.vue"],"sourcesContent":["import { ref, onMounted, onUnmounted } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { SearchPlugin, SearchState } from '@embedpdf/plugin-search';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const searchState = ref<SearchState>(
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-search.ts","../../src/vue/components/search-layer.vue"],"sourcesContent":["import { ref, onMounted, onUnmounted } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { initialState, SearchPlugin, SearchState } from '@embedpdf/plugin-search';\n\nexport const useSearchPlugin = () => usePlugin<SearchPlugin>(SearchPlugin.id);\nexport const useSearchCapability = () => useCapability<SearchPlugin>(SearchPlugin.id);\n\nexport const useSearch = () => {\n const { provides } = useSearchCapability();\n const searchState = ref<SearchState>(initialState);\n\n onMounted(() => {\n if (!provides.value) return;\n\n const unsubscribe = provides.value.onStateChange((state) => {\n searchState.value = state;\n });\n\n onUnmounted(() => {\n unsubscribe();\n });\n });\n\n return {\n state: searchState,\n provides,\n };\n};\n","<template>\n <div v-if=\"searchResultState\" v-bind=\"$attrs\">\n <div v-for=\"({ result, originalIndex }, idx) in pageResults\" :key=\"`result-${idx}`\">\n <div\n v-for=\"(rect, rectIdx) in result.rects\"\n :key=\"`rect-${idx}-${rectIdx}`\"\n :style=\"{\n position: 'absolute',\n top: `${rect.origin.y * scale}px`,\n left: `${rect.origin.x * scale}px`,\n width: `${rect.size.width * scale}px`,\n height: `${rect.size.height * scale}px`,\n backgroundColor:\n originalIndex === searchResultState.activeResultIndex\n ? activeHighlightColor\n : highlightColor,\n mixBlendMode: 'multiply',\n transform: 'scale(1.02)',\n transformOrigin: 'center',\n transition: 'opacity .3s ease-in-out',\n opacity: 1,\n }\"\n />\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, computed, onMounted, onUnmounted } from 'vue';\nimport type { SearchResultState } from '@embedpdf/plugin-search';\nimport { useSearchCapability } from '../hooks/use-search';\n\ninterface SearchLayerProps {\n pageIndex: number;\n scale: number;\n highlightColor?: string;\n activeHighlightColor?: string;\n}\n\nconst props = withDefaults(defineProps<SearchLayerProps>(), {\n highlightColor: '#FFFF00',\n activeHighlightColor: '#FFBF00',\n});\n\nconst { provides: searchProvides } = useSearchCapability();\nconst searchResultState = ref<SearchResultState | null>(null);\n\n// Filter results for current page while preserving original indices\nconst pageResults = computed(() => {\n if (!searchResultState.value) return [];\n\n return searchResultState.value.results\n .map((result, originalIndex) => ({ result, originalIndex }))\n .filter(({ result }) => result.pageIndex === props.pageIndex);\n});\n\nlet unsubscribe: (() => void) | undefined;\n\nonMounted(() => {\n if (!searchProvides.value) return;\n\n unsubscribe = searchProvides.value.onSearchResultStateChange((state) => {\n searchResultState.value = state;\n });\n});\n\nonUnmounted(() => {\n unsubscribe?.();\n});\n</script>\n"],"names":["_openBlock","_createElementBlock","$attrs","_Fragment","_normalizeStyle","scale","activeHighlightColor","highlightColor"],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,MAAM,YAAY,MAAM;AACvB,QAAA,EAAE,SAAS,IAAI,oBAAoB;AACnC,QAAA,cAAc,IAAiB,YAAY;AAEjD,YAAU,MAAM;AACV,QAAA,CAAC,SAAS,MAAO;AAErB,UAAM,cAAc,SAAS,MAAM,cAAc,CAAC,UAAU;AAC1D,kBAAY,QAAQ;AAAA,IAAA,CACrB;AAED,gBAAY,MAAM;AACJ,kBAAA;AAAA,IAAA,CACb;AAAA,EAAA,CACF;AAEM,SAAA;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;;;;;;;;;;ACYA,UAAM,QAAQ;AAKd,UAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACnD,UAAA,oBAAoB,IAA8B,IAAI;AAGtD,UAAA,cAAc,SAAS,MAAM;AACjC,UAAI,CAAC,kBAAkB,MAAO,QAAO,CAAC;AAE/B,aAAA,kBAAkB,MAAM,QAC5B,IAAI,CAAC,QAAQ,mBAAmB,EAAE,QAAQ,gBAAgB,EAC1D,OAAO,CAAC,EAAE,OAAA,MAAa,OAAO,cAAc,MAAM,SAAS;AAAA,IAAA,CAC/D;AAEG,QAAA;AAEJ,cAAU,MAAM;AACV,UAAA,CAAC,eAAe,MAAO;AAE3B,oBAAc,eAAe,MAAM,0BAA0B,CAAC,UAAU;AACtE,0BAAkB,QAAQ;AAAA,MAAA,CAC3B;AAAA,IAAA,CACF;AAED,gBAAY,MAAM;AACF;AAAA,IAAA,CACf;;aAnEY,kBAAiB,SAA5BA,UAAA,GAAAC,mBAuBM,6CAvBgCC,KAAM,MAAA,CAAA,GAAA;AAAA,SAC1CF,UAAA,IAAA,GAAAC,mBAqBME,2BArB0C,YAAW,OAAA,CAAA,EAA5C,QAAQ,cAAA,GAAiB,QAAG;8BAA3CF,mBAqBM,OAAA;AAAA,YArBwD,eAAe,GAAG;AAAA,UAAA;aAC9ED,UAAA,IAAA,GAAAC,mBAmBEE,2BAlB0B,OAAO,OAAzB,CAAA,MAAM,YAAO;kCADvBF,mBAmBE,OAAA;AAAA,gBAjBC,KAAG,QAAU,GAAG,IAAI,OAAO;AAAA,gBAC3B,OAAKG,eAAA;AAAA;kBAAsD,KAAA,GAAA,KAAK,OAAO,IAAIC,KAAK,KAAA;AAAA,kBAAyB,MAAA,GAAA,KAAK,OAAO,IAAIA,KAAK,KAAA;AAAA,kBAA0B,OAAA,GAAA,KAAK,KAAK,QAAQA,KAAK,KAAA;AAAA,kBAA2B,QAAA,GAAA,KAAK,KAAK,SAASA,KAAK,KAAA;AAAA,mCAA6C,kBAAkB,kBAAiB,MAAC,oBAAkCC,KAAoB,uBAAiBC,KAAc;AAAA;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-search",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -26,25 +26,31 @@
|
|
|
26
26
|
"types": "./dist/vue/index.d.ts",
|
|
27
27
|
"import": "./dist/vue/index.js",
|
|
28
28
|
"require": "./dist/vue/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./svelte": {
|
|
31
|
+
"types": "./dist/svelte/index.d.ts",
|
|
32
|
+
"import": "./dist/svelte/index.js",
|
|
33
|
+
"require": "./dist/svelte/index.cjs"
|
|
29
34
|
}
|
|
30
35
|
},
|
|
31
36
|
"dependencies": {
|
|
32
|
-
"@embedpdf/models": "1.
|
|
37
|
+
"@embedpdf/models": "1.4.0"
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
35
40
|
"@types/react": "^18.2.0",
|
|
36
41
|
"typescript": "^5.0.0",
|
|
37
|
-
"@embedpdf/build": "1.0
|
|
38
|
-
"@embedpdf/core": "1.
|
|
39
|
-
"@embedpdf/plugin-loader": "1.
|
|
42
|
+
"@embedpdf/build": "1.1.0",
|
|
43
|
+
"@embedpdf/core": "1.4.0",
|
|
44
|
+
"@embedpdf/plugin-loader": "1.4.0"
|
|
40
45
|
},
|
|
41
46
|
"peerDependencies": {
|
|
42
47
|
"react": ">=16.8.0",
|
|
43
48
|
"react-dom": ">=16.8.0",
|
|
44
49
|
"preact": "^10.26.4",
|
|
45
50
|
"vue": ">=3.2.0",
|
|
46
|
-
"
|
|
47
|
-
"@embedpdf/
|
|
51
|
+
"svelte": ">=5 <6",
|
|
52
|
+
"@embedpdf/core": "1.4.0",
|
|
53
|
+
"@embedpdf/plugin-loader": "1.4.0"
|
|
48
54
|
},
|
|
49
55
|
"files": [
|
|
50
56
|
"dist",
|
|
@@ -67,7 +73,8 @@
|
|
|
67
73
|
"build:react": "vite build --mode react",
|
|
68
74
|
"build:preact": "vite build --mode preact",
|
|
69
75
|
"build:vue": "vite build --mode vue",
|
|
70
|
-
"build": "
|
|
76
|
+
"build:svelte": "vite build --mode svelte",
|
|
77
|
+
"build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue,svelte \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\" \"vite build --mode svelte\"",
|
|
71
78
|
"clean": "rimraf dist",
|
|
72
79
|
"lint": "eslint src --color",
|
|
73
80
|
"lint:fix": "eslint src --color --fix"
|