@miroart/sdk 0.2.0 → 0.3.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.
@@ -0,0 +1,14 @@
1
+ import { type FunctionalComponent } from "vue";
2
+ /**
3
+ * Tekst z CMS z formatowaniem: `<h1><MiroText :value="heading" /></h1>`.
4
+ *
5
+ * Bez `v-html`: tagi i style pochodzą ze stałych list, a tekst użytkownika trafia tylko do
6
+ * węzłów tekstowych. `<script>` w wartości pokaże się jako tekst. Wartość bez znaczników i
7
+ * złamań linii daje zwykły węzeł tekstowy, więc można tu podać wszystko to co do `{{ }}`.
8
+ *
9
+ * W ramce edytora wynik dostaje `data-miro-rich`: po tym nakładka poznaje, że znaczniki się
10
+ * tu wyrenderują, i pokazuje pasek formatowania. `display: contents` nie zmienia układu.
11
+ */
12
+ export declare const MiroText: FunctionalComponent<{
13
+ value?: unknown;
14
+ }>;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty,Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue");function e(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options}}}function r(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function n(t){return r(t)?t:null}function s(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function i(t){return t?String(t.uuid||t.domain||t.id||""):""}function o(t){return String.fromCharCode(...t.map(t=>23^t))}function a(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function c(){const t=o([56,118,103,126]),e=o([97,38]),r=o([100,126,99,114,100]),n=o([103,118,112,114,100]),s=o([100,114,118,101,116,127]),i=o([122,114,121,98,100]),c=o([122,114,115,126,118]),u=o([103,123,98,112,126,121,100]),l=o([118,116,99,126,120,121,100]);return{sites:()=>a("",`${t}/${e}/${r}`),site:n=>a("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:s=>a("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}`),page:(s,i)=>a("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:i=>a("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s}`),menus:n=>a("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${i}`),menu:(n,s)=>a("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${i}/${encodeURIComponent(s)}`),media:e=>a("",`${t}/${c}/${encodeURIComponent(e)}`),action:e=>a("",`${t}/${l}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const s=`${t}/${u}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${s}${n.startsWith("/")?n:`/${n}`}`:s}}}function u(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function l(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function p(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function h(t){const e=p(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function g(t){return h(t).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}class d extends String{kind;extra;constructor(t,e,r={}){super(h(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return h(this.toString())}cleanContent(){return g(this.toString())}stripHtml(){return this.cleanContent()}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=h(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return g(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class f extends d{constructor(t){super("PageTitle",t)}}class m extends d{constructor(t){super("PageSubtitle",t)}}class y extends d{constructor(t){super("PageSmallTitle",t)}}class w extends d{constructor(t){super("PageSummary",t)}}class S extends d{constructor(t){super("PageContent",t)}html(){return this.toString()}}class b extends d{constructor(t){super("SiteTitle",t)}}class $ extends d{constructor(t){super("SiteName",t)}}class _ extends d{key;structured;constructor(t,e){const r=C(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class j extends d{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class x extends d{constructor(t){super("MenuTitle",t)}}class k extends d{constructor(t){super("AssetName",t)}}class A extends d{constructor(t){super("SeoTitle",t)}}class P extends d{constructor(t){super("SeoDescription",t)}}function C(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return C(JSON.parse(e))}catch{return{text:h(t)}}return{text:h(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?C(t.value):{text:JSON.stringify(t),structured:t}:{text:p(t)}}function M(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function v(t){if("string"==typeof t){const e=t.trim();return e?I(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=R(e.source),n=O(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),s=O(e.uuid,r?.uuid);if(n||s&&I(s))return e;const i=O(e.value);return i?v(i):null}function O(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function T(t){return"string"==typeof t?t.trim():""}function R(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function U(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function I(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const N=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class W{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new k(this.record.name)}getAlt(){return T(this.record.alt)}getCaption(){return T(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>B(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:q(this.record.gallery_sort_order)}]}getMime(){const t=R(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=R(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=T(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new j(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=N.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=R(this.record.source),e=O(this.record.uuid,t?.uuid),r=O(this.record.disk,t?.disk);let n=O(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&I(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!U(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&I(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(O(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(s=e)?/\.svg$/i.test(s)?`/_images/${s}`:`/_images/${s.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var s;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(U(n))return n;n.includes("/")||n.includes("\\")||I(n)||(n=`images/${n}`);const i=n.startsWith("/")?n:`/${n}`;return U(i)||i.startsWith("/project-storage/")?i:`/storage${i}`}mediaUrl(t){const e=c().media(t),r=this.runtime.apiBase();return r?a(r,e):e}}class L{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function B(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const s=e.id;return{id:"number"==typeof s||"string"==typeof s?s:null,uuid:r,name:n,sort_order:q(e.sort_order)}}function q(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function E(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new W(t,e)):[]}const G=new Set(["id","uuid","created_at","updated_at"]);class D{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new j(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return J(this.item(),this.kernel)}}function J(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(G.has(r)||"string"!=typeof n||!z(n))continue;const t=v(n);if(t)return new W(t,e)}return null}function z(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function F(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:V(n.current_page,1),lastPage:V(n.last_page,1),perPage:V(n.per_page,Math.max(e,1)),total:K(n.total,e)}}function H(t,e){return Object.assign(t,{meta:e})}function V(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function K(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class Z{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=Q(),e=await t.request(c().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new Z(e,t))}static async find(t){const e=Q(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||i(n)===String(t)))return new Z(n,e);const s=l(await e.request(c().site(r)));return e.rememberSite(s),new Z(s,e)}static async findPage(t,e){return X.find(t,e)}static async findMenu(t,e){return ut.find(t,e)}getName(){return new $(this.record.name)}getTitle(){const t=M(this.record.options,"seo_title")||M(this.record.options,"title");return new b(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new _(t,M(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const s=v(n);return s?new W(s,this.kernel):null}async findPage(t){return X.find(t,this.ref())}async findMenu(t){return ut.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new ut(t,this.kernel)):((await this.kernel.request(c().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new ut(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,a]of Object.entries(r))e.set(o,String(a));const n=e.toString()?`?${e.toString()}`:"",s=await this.kernel.request(`${c().pages(this.ref())}${n}`),i=(s.data??[]).map(t=>(this.kernel.rememberPage(t),new X(t,this.kernel)));return H(i,F(s,i.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request(c().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let Y=null;function Q(){if(!Y)throw new Error("Client is not installed.");return Y}class X{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return at(t,e)}static async find(t,e){return at(t,e)}static async search(t,e,r){const n=et(),s=rt(n,e),i=new URLSearchParams;i.set("q",t),nt(i,r);const o=await n.request(`${c().search(s)}?${i.toString()}`),a=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new X(t,n)));return H(a,F(o,a.length))}getTitle(){return new f(this.record.title)}getSubtitle(){return new m(this.record.subtitle)}getSmallTitle(){return new y(this.record.smalltitle)}getSummary(){return new w(this.record.summary)}getContent(){return new S(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new j(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[M(this.record.options,t),this.kernel.snapshot().options[t],M(this.kernel.snapshot().site?.options,t),M(it(this.record.site),t)];for(const r of e)if(st(r))return new _(t,r);return new _(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=v(t);return e?new W(e,this.kernel):null};return{title:new A(t.title??this.record.title),description:new P(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new j(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new j(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:ot(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new D(t,e)):[];var t,e}collectionImage(){return J(this.collectionItem,this.kernel)}getAssets(){return new L(E(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new L([]);const r=[];return E(this.record.assets,this.kernel).forEach((t,n)=>{const s=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));s&&r.push({asset:t,sort:s.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new L(r.map(t=>t.asset))}getGalleries(){const t=E(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const s=r&&r>0?Math.floor(r):Math.max(n,1),i=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/s)),a=(i-1)*s;return{items:t.slice(a,a+s),meta:{currentPage:i,lastPage:o,perPage:s,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return H(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return H(t,F(null,t.length))}const s=new URLSearchParams;s.set("parent",n),e.length&&s.set("with",e.join(",")),nt(s,t);const i=await this.kernel.request(`${c().pages(this.siteRef())}?${s.toString()}`);return H(this.rowsToPages(i.data??[]),F(i,(i.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new X(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${c().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${c().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new X(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:at(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new Z(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new Z(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=l(await this.kernel.request(c().site(e)));return this.kernel.rememberSite(r),new Z(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=B(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?i(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new X(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,s=String(n.uuid||n.id||"");if(!s||e.has(s))break;e.add(s),t.unshift(new X(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=s(this.record);return t.filter(t=>s(t)!==e).map(t=>new X(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=l(await this.kernel.request(c().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let tt=null;function et(){if(!tt)throw new Error("Client is not installed.");return tt}function rt(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function nt(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function st(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function it(t){if(t&&"object"==typeof t)return t.options}function ot(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function at(t,e){const r=et(),n=rt(r,e),s=l(await r.request(c().page(n,t)));return r.rememberPage(s),new X(s,r)}class ct{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new x(this.record.title)}getUrl(){return new j(this.record.url)}getChildren(){return lt(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??pt,n=r?.snapshot().page;return!(!r||!n)&&e===new X(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??pt;return e?new X(t,e):null}raw(){return{...this.record}}}class ut{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!pt)throw new Error("Client is not installed.");return pt}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),s=r.snapshot().menus,i=s[t]||Object.values(s).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(i)return new ut(i,r);const o=l(await r.request(c().menu(n,t)));return r.rememberMenu(o),new ut(o,r)}getName(){return new x(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return lt(this.record.items,this.runtime)}raw(){return{...this.record}}}function lt(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ct(t,e)):[]}let pt=null;class ht{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{}};options;inflight=new Map;cache=new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),tt=this,Y=this,pt=this}hydrate(t){return this.snap=e(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{}};if(!t||"object"!=typeof t)return e;const s=t,i=r(s.props)?s.props:s;e.page=n(i.page),e.site=n(i.site),e.seo=r(i.seo)?i.seo:null,e.options=r(i.options)?i.options:{},e.locales=Array.isArray(i.locales)?i.locales:[];const o=i.menus;if(r(o))for(const[r,a]of Object.entries(o))e.menus[r]=n(a);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=u();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=u();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):i(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const s=this.apiBase();if(!s)throw new Error("Remote origin is not configured.");const i=async function(t,e,r={}){const{fetchImpl:n,...s}=r,i=e.startsWith("http")?e:a(t,e),o=n??fetch,c=new Headers(s.headers);c.has("Accept")||c.set("Accept","application/json");const u=await o(i,{...s,headers:c}),l=await u.text();let p=null;if(l)try{p=JSON.parse(l)}catch{p={message:l}}if(!u.ok){const t=new Error(`Request failed (${u.status})`);throw t.status=u.status,t.body=p,t}return p}(s,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,i),i.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),i}rememberPage(t){const r=this.snap.page;r&&String(r.id)===String(t.id)&&(this.snap=e(this.snap,{page:{...r,...t}}))}rememberSite(t){this.snap=e(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const r=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=e(this.snap,{menus:{[r]:t}})}}let gt=null;function dt(t={}){return gt=new ht(t),gt}function ft(){return gt||(gt=new ht),gt}const mt=Symbol.for("miro.client");function yt(){return t.inject(mt,null)??ft()}function wt(t={}){return{install(e,r={}){const n=dt({...t,...r});e.provide(mt,n),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const St=wt();class bt{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=$t(String(e.lang??""));return r?[{lang:r,domain:jt(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=_t(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||jt(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const s=_t(String(t[r]??""));s&&e.push({lang:n[1],domain:jt(s),url:s})}return e}(e)}(this.kernel.snapshot().locales)}current(){return $t(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=$t(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function $t(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function _t(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function jt(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function xt(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function kt(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const s=e.slice(0,n),i=e.slice(n+1);if(""!==s&&(i===t||At(i)===t))return s}return""}function At(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function Pt(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Ct(){const t=yt(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Mt(){const t=Ct();return vt(t),new X(()=>t.snapshot().page??{},t)}function vt(e){try{const r=function(){try{return Ot??null}catch{return null}}();if(!r)return;const n=r.usePage();e.hydrate(t.unref(n))}catch{}}let Ot=null;import("@inertiajs/vue3").then(t=>{Ot=t}).catch(()=>{Ot=null});const Tt=St;exports.Asset=W,exports.AssetName=k,exports.CollectionCard=D,exports.Gallery=L,exports.Locales=bt,exports.Menu=ut,exports.MenuItem=ct,exports.MenuTitle=x,exports.Miro=St,exports.OptionValue=_,exports.Page=X,exports.PageContent=S,exports.PageSmallTitle=y,exports.PageSubtitle=m,exports.PageSummary=w,exports.PageTitle=f,exports.SDK_KEY=mt,exports.SeoDescription=P,exports.SeoTitle=A,exports.Site=Z,exports.SiteName=$,exports.SiteTitle=b,exports.TextValue=d,exports.UrlValue=j,exports.createMiro=wt,exports.createRuntime=dt,exports.default=Tt,exports.getRuntime=ft,exports.pluginWindowKey=xt,exports.useKernel=yt,exports.useMiroAssets=function(){return Mt().getAssets()},exports.useMiroConfig=function(){const e=yt();return{apiBase:t.computed(()=>e.apiBase()),siteBase:t.computed(()=>e.siteBase()),siteRef:t.computed(()=>e.siteRef())}},exports.useMiroLocales=function(){const t=Ct();return vt(t),new bt(t)},exports.useMiroMenu=function(t="topbar"){const e=Ct();return vt(e),new ut(()=>e.snapshot().menus[t]??{position:t,items:[]},e)},exports.useMiroPage=Mt,exports.useMiroSite=function(){const t=Ct();return vt(t),new Z(()=>t.snapshot().site??{},t)},exports.usePlugin=function(t){return function(t,e){const r=xt(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:At(r.join("/")||e)}}const r=At(e);return{vendor:kt(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=Pt(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return Pt(t)}(r),api:()=>Pt(r),call:(t,...e)=>{const n=Pt(r),s=n[t];if("function"!=typeof s)throw new Error(`Missing plugin method: ${t}`);return s.apply(n,e)},request:async(t="/",r={})=>{const s=c().plugins(n.vendor,n.slug,t||"/"),i=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),l(await e.request(s,{...r,headers:i,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const s=Pt(r),i=s[String(e)];return"function"==typeof i?i.bind(s):i},has:(t,e)=>e in t||e in Pt(r)})}(t,yt())};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty,Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),e=["primary","secondary","accent","neutral","base-100","base-content","info","success","warning","error"],r=["sans","serif"],n=/\\(\[\/?(?:b|i|u|s|c|f)(?:=[a-z0-9-]+)?\])|\[(\/?)(b|i|u|s|c|f)(?:=([a-z0-9-]+))?\]/g;function s(t,n){return"c"===t?e.includes(n??""):"f"===t?r.includes(n??""):void 0===n}function i(t,e){""!==e&&e.split(/\r?\n/).forEach((e,r)=>{if(r>0&&t.push({type:"br"}),""===e)return;const n=t[t.length-1];"text"===n?.type?n.value+=e:t.push({type:"text",value:e})})}function o(t){const e=String(t??""),r=[],o=[],a=()=>o[o.length-1]?.children??r,c=()=>{var t,e;t=o.pop(),e=a(),0!==t.children.length&&("c"===t.tag?e.push({type:"c",value:t.value,children:t.children}):"f"===t.tag?e.push({type:"f",value:t.value,children:t.children}):e.push({type:t.tag,children:t.children}))};let u,l=0;for(n.lastIndex=0;null!==(u=n.exec(e));){i(a(),e.slice(l,u.index)),l=n.lastIndex;const[t,r,p,h,d]=u;if(void 0===r){if("/"===p){const e=void 0===d?o.map(t=>t.tag).lastIndexOf(h):-1;if(-1===e){i(a(),t);continue}for(;o.length>e;)c();continue}!s(h,d)||o.length>=8?i(a(),t):o.push({tag:h,value:d??null,children:[]})}else i(a(),r)}for(i(a(),e.slice(l));o.length>0;)c();return r}function a(t,e){for(const r of t)"text"===r.type?e.push(r.value):"br"===r.type?e.push("\n"):a(r.children,e)}function c(t){const e=String(t??"");if(!e.includes("["))return e;const r=[];return a(o(e),r),r.join("")}const u=/[⁢⁤][​‌‍⁠]+⁣/,l={b:"strong",i:"em",u:"u",s:"s"};function p(e){switch(e.type){case"text":return e.value;case"br":return t.h("br");case"c":return t.h("span",{style:{color:`var(--color-${e.value})`}},h(e.children));case"f":return t.h("span",{style:{fontFamily:`var(--font-${e.value})`}},h(e.children));default:return t.h(l[e.type],h(e.children))}}function h(t){return t.map(p)}const d=e=>{const r=t.toDisplayString(e.value),n=u.test(r);if(!n&&!function(t){return t.includes("[")||t.includes("\n")}(r))return r;const s=h(o(r));return n?t.h("span",{"data-miro-rich":"",style:{display:"contents"}},s):1===s.length?s[0]:s};function g(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options}}}function f(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function m(t){return f(t)?t:null}function y(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function w(t){return t?String(t.uuid||t.domain||t.id||""):""}function S(t){return String.fromCharCode(...t.map(t=>23^t))}function b(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function $(){const t=S([56,118,103,126]),e=S([97,38]),r=S([100,126,99,114,100]),n=S([103,118,112,114,100]),s=S([100,114,118,101,116,127]),i=S([122,114,121,98,100]),o=S([122,114,115,126,118]),a=S([103,123,98,112,126,121,100]),c=S([118,116,99,126,120,121,100]);return{sites:()=>b("",`${t}/${e}/${r}`),site:n=>b("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:s=>b("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}`),page:(s,i)=>b("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:i=>b("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s}`),menus:n=>b("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${i}`),menu:(n,s)=>b("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${i}/${encodeURIComponent(s)}`),media:e=>b("",`${t}/${o}/${encodeURIComponent(e)}`),action:e=>b("",`${t}/${c}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const s=`${t}/${a}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${s}${n.startsWith("/")?n:`/${n}`}`:s}}}function x(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function _(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function j(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function k(t){const e=j(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function A(t){return c(k(t)).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}d.props=["value"],d.displayName="MiroText";class v extends String{kind;extra;constructor(t,e,r={}){super(k(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return k(this.toString())}cleanContent(){return A(this.toString())}stripHtml(){return this.cleanContent()}plain(){return c(this.toString())}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=k(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return A(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class P extends v{constructor(t){super("PageTitle",t)}}class C extends v{constructor(t){super("PageSubtitle",t)}}class M extends v{constructor(t){super("PageSmallTitle",t)}}class T extends v{constructor(t){super("PageSummary",t)}}class O extends v{constructor(t){super("PageContent",t)}html(){return this.toString()}}class R extends v{constructor(t){super("SiteTitle",t)}}class I extends v{constructor(t){super("SiteName",t)}}class U extends v{key;structured;constructor(t,e){const r=E(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class N extends v{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class W extends v{constructor(t){super("MenuTitle",t)}}class L extends v{constructor(t){super("AssetName",t)}}class B extends v{constructor(t){super("SeoTitle",t)}}class q extends v{constructor(t){super("SeoDescription",t)}}function E(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return E(JSON.parse(e))}catch{return{text:k(t)}}return{text:k(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?E(t.value):{text:JSON.stringify(t),structured:t}:{text:j(t)}}function G(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function D(t){if("string"==typeof t){const e=t.trim();return e?V(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=F(e.source),n=z(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),s=z(e.uuid,r?.uuid);if(n||s&&V(s))return e;const i=z(e.value);return i?D(i):null}function z(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function J(t){return"string"==typeof t?t.trim():""}function F(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function H(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function V(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const K=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class Z{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new L(this.record.name)}getAlt(){return J(this.record.alt)}getCaption(){return J(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>Q(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:X(this.record.gallery_sort_order)}]}getMime(){const t=F(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=F(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=J(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new N(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=K.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=F(this.record.source),e=z(this.record.uuid,t?.uuid),r=z(this.record.disk,t?.disk);let n=z(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&V(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!H(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&V(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(z(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(s=e)?/\.svg$/i.test(s)?`/_images/${s}`:`/_images/${s.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var s;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(H(n))return n;n.includes("/")||n.includes("\\")||V(n)||(n=`images/${n}`);const i=n.startsWith("/")?n:`/${n}`;return H(i)||i.startsWith("/project-storage/")?i:`/storage${i}`}mediaUrl(t){const e=$().media(t),r=this.runtime.apiBase();return r?b(r,e):e}}class Y{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function Q(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const s=e.id;return{id:"number"==typeof s||"string"==typeof s?s:null,uuid:r,name:n,sort_order:X(e.sort_order)}}function X(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function tt(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new Z(t,e)):[]}const et=new Set(["id","uuid","created_at","updated_at"]);class rt{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new N(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return nt(this.item(),this.kernel)}}function nt(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(et.has(r)||"string"!=typeof n||!st(n))continue;const t=D(n);if(t)return new Z(t,e)}return null}function st(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function it(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:at(n.current_page,1),lastPage:at(n.last_page,1),perPage:at(n.per_page,Math.max(e,1)),total:ct(n.total,e)}}function ot(t,e){return Object.assign(t,{meta:e})}function at(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function ct(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class ut{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=pt(),e=await t.request($().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new ut(e,t))}static async find(t){const e=pt(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||w(n)===String(t)))return new ut(n,e);const s=_(await e.request($().site(r)));return e.rememberSite(s),new ut(s,e)}static async findPage(t,e){return ht.find(t,e)}static async findMenu(t,e){return xt.find(t,e)}getName(){return new I(this.record.name)}getTitle(){const t=G(this.record.options,"seo_title")||G(this.record.options,"title");return new R(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new U(t,G(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const s=D(n);return s?new Z(s,this.kernel):null}async findPage(t){return ht.find(t,this.ref())}async findMenu(t){return xt.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new xt(t,this.kernel)):((await this.kernel.request($().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new xt(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,a]of Object.entries(r))e.set(o,String(a));const n=e.toString()?`?${e.toString()}`:"",s=await this.kernel.request(`${$().pages(this.ref())}${n}`),i=(s.data??[]).map(t=>(this.kernel.rememberPage(t),new ht(t,this.kernel)));return ot(i,it(s,i.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request($().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let lt=null;function pt(){if(!lt)throw new Error("Client is not installed.");return lt}class ht{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return bt(t,e)}static async find(t,e){return bt(t,e)}static async search(t,e,r){const n=gt(),s=ft(n,e),i=new URLSearchParams;i.set("q",t),mt(i,r);const o=await n.request(`${$().search(s)}?${i.toString()}`),a=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new ht(t,n)));return ot(a,it(o,a.length))}getTitle(){return new P(this.record.title)}getSubtitle(){return new C(this.record.subtitle)}getSmallTitle(){return new M(this.record.smalltitle)}getSummary(){return new T(this.record.summary)}getContent(){return new O(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new N(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[G(this.record.options,t),this.kernel.snapshot().options[t],G(this.kernel.snapshot().site?.options,t),G(wt(this.record.site),t)];for(const r of e)if(yt(r))return new U(t,r);return new U(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=D(t);return e?new Z(e,this.kernel):null};return{title:new B(t.title??this.record.title),description:new q(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new N(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new N(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:St(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new rt(t,e)):[];var t,e}collectionImage(){return nt(this.collectionItem,this.kernel)}getAssets(){return new Y(tt(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new Y([]);const r=[];return tt(this.record.assets,this.kernel).forEach((t,n)=>{const s=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));s&&r.push({asset:t,sort:s.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new Y(r.map(t=>t.asset))}getGalleries(){const t=tt(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const s=r&&r>0?Math.floor(r):Math.max(n,1),i=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/s)),a=(i-1)*s;return{items:t.slice(a,a+s),meta:{currentPage:i,lastPage:o,perPage:s,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return ot(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return ot(t,it(null,t.length))}const s=new URLSearchParams;s.set("parent",n),e.length&&s.set("with",e.join(",")),mt(s,t);const i=await this.kernel.request(`${$().pages(this.siteRef())}?${s.toString()}`);return ot(this.rowsToPages(i.data??[]),it(i,(i.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ht(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${$().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${$().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new ht(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:bt(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new ut(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new ut(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=_(await this.kernel.request($().site(e)));return this.kernel.rememberSite(r),new ut(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=Q(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?w(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ht(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,s=String(n.uuid||n.id||"");if(!s||e.has(s))break;e.add(s),t.unshift(new ht(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=y(this.record);return t.filter(t=>y(t)!==e).map(t=>new ht(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=_(await this.kernel.request($().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let dt=null;function gt(){if(!dt)throw new Error("Client is not installed.");return dt}function ft(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function mt(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function yt(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function wt(t){if(t&&"object"==typeof t)return t.options}function St(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function bt(t,e){const r=gt(),n=ft(r,e),s=_(await r.request($().page(n,t)));return r.rememberPage(s),new ht(s,r)}class $t{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new W(this.record.title)}getUrl(){return new N(this.record.url)}getChildren(){return _t(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??jt,n=r?.snapshot().page;return!(!r||!n)&&e===new ht(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??jt;return e?new ht(t,e):null}raw(){return{...this.record}}}class xt{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!jt)throw new Error("Client is not installed.");return jt}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),s=r.snapshot().menus,i=s[t]||Object.values(s).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(i)return new xt(i,r);const o=_(await r.request($().menu(n,t)));return r.rememberMenu(o),new xt(o,r)}getName(){return new W(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return _t(this.record.items,this.runtime)}raw(){return{...this.record}}}function _t(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new $t(t,e)):[]}let jt=null;class kt{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{}};options;inflight=new Map;cache=new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),dt=this,lt=this,jt=this}hydrate(t){return this.snap=g(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{}};if(!t||"object"!=typeof t)return e;const r=t,n=f(r.props)?r.props:r;e.page=m(n.page),e.site=m(n.site),e.seo=f(n.seo)?n.seo:null,e.options=f(n.options)?n.options:{},e.locales=Array.isArray(n.locales)?n.locales:[];const s=n.menus;if(f(s))for(const[i,o]of Object.entries(s))e.menus[i]=m(o);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=x();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=x();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):w(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const s=this.apiBase();if(!s)throw new Error("Remote origin is not configured.");const i=async function(t,e,r={}){const{fetchImpl:n,...s}=r,i=e.startsWith("http")?e:b(t,e),o=n??fetch,a=new Headers(s.headers);a.has("Accept")||a.set("Accept","application/json");const c=await o(i,{...s,headers:a}),u=await c.text();let l=null;if(u)try{l=JSON.parse(u)}catch{l={message:u}}if(!c.ok){const t=new Error(`Request failed (${c.status})`);throw t.status=c.status,t.body=l,t}return l}(s,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,i),i.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),i}rememberPage(t){const e=this.snap.page;e&&String(e.id)===String(t.id)&&(this.snap=g(this.snap,{page:{...e,...t}}))}rememberSite(t){this.snap=g(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const e=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=g(this.snap,{menus:{[e]:t}})}}let At=null;function vt(t={}){return At=new kt(t),At}function Pt(){return At||(At=new kt),At}const Ct=Symbol.for("miro.client");function Mt(){return t.inject(Ct,null)??Pt()}function Tt(t={}){return{install(e,r={}){const n=vt({...t,...r});e.provide(Ct,n),e.component("MiroText",d),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const Ot=Tt();class Rt{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=It(String(e.lang??""));return r?[{lang:r,domain:Nt(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=Ut(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||Nt(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const s=Ut(String(t[r]??""));s&&e.push({lang:n[1],domain:Nt(s),url:s})}return e}(e)}(this.kernel.snapshot().locales)}current(){return It(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=It(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function It(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function Ut(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function Nt(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function Wt(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function Lt(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const s=e.slice(0,n),i=e.slice(n+1);if(""!==s&&(i===t||Bt(i)===t))return s}return""}function Bt(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function qt(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Et(){const t=Mt(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Gt(){const t=Et();return Dt(t),new ht(()=>t.snapshot().page??{},t)}function Dt(e){try{const r=function(){try{return zt??null}catch{return null}}();if(!r)return;const n=r.usePage();e.hydrate(t.unref(n))}catch{}}let zt=null;import("@inertiajs/vue3").then(t=>{zt=t}).catch(()=>{zt=null});const Jt=Ot;exports.Asset=Z,exports.AssetName=L,exports.CollectionCard=rt,exports.Gallery=Y,exports.Locales=Rt,exports.Menu=xt,exports.MenuItem=$t,exports.MenuTitle=W,exports.Miro=Ot,exports.MiroText=d,exports.OptionValue=U,exports.Page=ht,exports.PageContent=O,exports.PageSmallTitle=M,exports.PageSubtitle=C,exports.PageSummary=T,exports.PageTitle=P,exports.RICH_COLORS=e,exports.RICH_FONTS=r,exports.SDK_KEY=Ct,exports.SeoDescription=q,exports.SeoTitle=B,exports.Site=ut,exports.SiteName=I,exports.SiteTitle=R,exports.TextValue=v,exports.UrlValue=N,exports.createMiro=Tt,exports.createRuntime=vt,exports.default=Jt,exports.getRuntime=Pt,exports.parseRichText=o,exports.plainText=c,exports.pluginWindowKey=Wt,exports.useKernel=Mt,exports.useMiroAssets=function(){return Gt().getAssets()},exports.useMiroConfig=function(){const e=Mt();return{apiBase:t.computed(()=>e.apiBase()),siteBase:t.computed(()=>e.siteBase()),siteRef:t.computed(()=>e.siteRef())}},exports.useMiroLocales=function(){const t=Et();return Dt(t),new Rt(t)},exports.useMiroMenu=function(t="topbar"){const e=Et();return Dt(e),new xt(()=>e.snapshot().menus[t]??{position:t,items:[]},e)},exports.useMiroPage=Gt,exports.useMiroSite=function(){const t=Et();return Dt(t),new ut(()=>t.snapshot().site??{},t)},exports.usePlugin=function(t){return function(t,e){const r=Wt(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:Bt(r.join("/")||e)}}const r=Bt(e);return{vendor:Lt(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=qt(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return qt(t)}(r),api:()=>qt(r),call:(t,...e)=>{const n=qt(r),s=n[t];if("function"!=typeof s)throw new Error(`Missing plugin method: ${t}`);return s.apply(n,e)},request:async(t="/",r={})=>{const s=$().plugins(n.vendor,n.slug,t||"/"),i=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),_(await e.request(s,{...r,headers:i,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const s=qt(r),i=s[String(e)];return"function"==typeof i?i.bind(s):i},has:(t,e)=>e in t||e in qt(r)})}(t,Mt())};
package/dist/index.d.ts CHANGED
@@ -11,8 +11,10 @@ import { createRuntime, getRuntime } from "./runtime";
11
11
  import { useMiroAssets, useMiroConfig, useMiroLocales, useMiroMenu, useMiroPage, useMiroSite, usePlugin } from "./composables";
12
12
  import { AssetName, MenuTitle, OptionValue, PageContent, PageSmallTitle, PageSubtitle, PageSummary, PageTitle, SeoDescription, SeoTitle, SiteName, SiteTitle, TextValue, UrlValue } from "./values";
13
13
  import { pluginWindowKey } from "./plugin";
14
+ import { MiroText } from "./MiroText";
15
+ import { parseRichText, plainText, RICH_COLORS, RICH_FONTS, type RichColor, type RichFont, type RichNode } from "./richText";
14
16
  import type { ActionCall, ClientOptions } from "./types";
15
- export { Asset, AssetName, CollectionCard, createMiro, createRuntime, Gallery, getRuntime, Locales, Menu, MenuItem, MenuTitle, Miro, OptionValue, Page, PageContent, PageSmallTitle, PageSubtitle, PageSummary, PageTitle, pluginWindowKey, SDK_KEY, SeoDescription, SeoTitle, Site, SiteName, SiteTitle, TextValue, UrlValue, useKernel, useMiroAssets, useMiroConfig, useMiroLocales, useMiroMenu, useMiroPage, useMiroSite, usePlugin, };
16
- export type { ActionCall, ClientOptions, GalleryMembership, LocaleLink, PageGallery, PageListMeta, PageListQuery, PagedPages, SeoView, };
17
+ export { Asset, AssetName, MiroText, parseRichText, plainText, RICH_COLORS, RICH_FONTS, CollectionCard, createMiro, createRuntime, Gallery, getRuntime, Locales, Menu, MenuItem, MenuTitle, Miro, OptionValue, Page, PageContent, PageSmallTitle, PageSubtitle, PageSummary, PageTitle, pluginWindowKey, SDK_KEY, SeoDescription, SeoTitle, Site, SiteName, SiteTitle, TextValue, UrlValue, useKernel, useMiroAssets, useMiroConfig, useMiroLocales, useMiroMenu, useMiroPage, useMiroSite, usePlugin, };
18
+ export type { ActionCall, ClientOptions, GalleryMembership, LocaleLink, PageGallery, PageListMeta, PageListQuery, PagedPages, RichColor, RichFont, RichNode, SeoView, };
17
19
  declare const plugin: Plugin;
18
20
  export default plugin;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{inject as t,computed as e,unref as r}from"vue";function n(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options}}}function i(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function s(t){return i(t)?t:null}function o(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function a(t){return t?String(t.uuid||t.domain||t.id||""):""}function c(t){return String.fromCharCode(...t.map(t=>23^t))}function u(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function l(){const t=c([56,118,103,126]),e=c([97,38]),r=c([100,126,99,114,100]),n=c([103,118,112,114,100]),i=c([100,114,118,101,116,127]),s=c([122,114,121,98,100]),o=c([122,114,115,126,118]),a=c([103,123,98,112,126,121,100]),l=c([118,116,99,126,120,121,100]);return{sites:()=>u("",`${t}/${e}/${r}`),site:n=>u("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:i=>u("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}`),page:(i,s)=>u("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:s=>u("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i}`),menus:n=>u("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}`),menu:(n,i)=>u("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}/${encodeURIComponent(i)}`),media:e=>u("",`${t}/${o}/${encodeURIComponent(e)}`),action:e=>u("",`${t}/${l}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const i=`${t}/${a}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${i}${n.startsWith("/")?n:`/${n}`}`:i}}}function h(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function p(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function d(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function g(t){const e=d(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function f(t){return g(t).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}class m extends String{kind;extra;constructor(t,e,r={}){super(g(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return g(this.toString())}cleanContent(){return f(this.toString())}stripHtml(){return this.cleanContent()}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=g(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return f(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class y extends m{constructor(t){super("PageTitle",t)}}class w extends m{constructor(t){super("PageSubtitle",t)}}class S extends m{constructor(t){super("PageSmallTitle",t)}}class b extends m{constructor(t){super("PageSummary",t)}}class $ extends m{constructor(t){super("PageContent",t)}html(){return this.toString()}}class _ extends m{constructor(t){super("SiteTitle",t)}}class k extends m{constructor(t){super("SiteName",t)}}class j extends m{key;structured;constructor(t,e){const r=R(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class A extends m{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class P extends m{constructor(t){super("MenuTitle",t)}}class C extends m{constructor(t){super("AssetName",t)}}class x extends m{constructor(t){super("SeoTitle",t)}}class v extends m{constructor(t){super("SeoDescription",t)}}function R(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return R(JSON.parse(e))}catch{return{text:g(t)}}return{text:g(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?R(t.value):{text:JSON.stringify(t),structured:t}:{text:d(t)}}function U(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function T(t){if("string"==typeof t){const e=t.trim();return e?O(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=M(e.source),n=I(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),i=I(e.uuid,r?.uuid);if(n||i&&O(i))return e;const s=I(e.value);return s?T(s):null}function I(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function W(t){return"string"==typeof t?t.trim():""}function M(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function N(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function O(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const B=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class L{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new C(this.record.name)}getAlt(){return W(this.record.alt)}getCaption(){return W(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>E(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:G(this.record.gallery_sort_order)}]}getMime(){const t=M(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=M(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=W(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new A(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=B.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=M(this.record.source),e=I(this.record.uuid,t?.uuid),r=I(this.record.disk,t?.disk);let n=I(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&O(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!N(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&O(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(I(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(i=e)?/\.svg$/i.test(i)?`/_images/${i}`:`/_images/${i.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var i;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(N(n))return n;n.includes("/")||n.includes("\\")||O(n)||(n=`images/${n}`);const s=n.startsWith("/")?n:`/${n}`;return N(s)||s.startsWith("/project-storage/")?s:`/storage${s}`}mediaUrl(t){const e=l().media(t),r=this.runtime.apiBase();return r?u(r,e):e}}class q{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function E(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const i=e.id;return{id:"number"==typeof i||"string"==typeof i?i:null,uuid:r,name:n,sort_order:G(e.sort_order)}}function G(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function J(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new L(t,e)):[]}const z=/* @__PURE__ */new Set(["id","uuid","created_at","updated_at"]);class D{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new A(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return F(this.item(),this.kernel)}}function F(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(z.has(r)||"string"!=typeof n||!H(n))continue;const t=T(n);if(t)return new L(t,e)}return null}function H(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function Z(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:K(n.current_page,1),lastPage:K(n.last_page,1),perPage:K(n.per_page,Math.max(e,1)),total:Q(n.total,e)}}function V(t,e){return Object.assign(t,{meta:e})}function K(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function Q(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class X{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=tt(),e=await t.request(l().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new X(e,t))}static async find(t){const e=tt(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||a(n)===String(t)))return new X(n,e);const i=p(await e.request(l().site(r)));return e.rememberSite(i),new X(i,e)}static async findPage(t,e){return et.find(t,e)}static async findMenu(t,e){return ht.find(t,e)}getName(){return new k(this.record.name)}getTitle(){const t=U(this.record.options,"seo_title")||U(this.record.options,"title");return new _(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new j(t,U(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const i=T(n);return i?new L(i,this.kernel):null}async findPage(t){return et.find(t,this.ref())}async findMenu(t){return ht.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new ht(t,this.kernel)):((await this.kernel.request(l().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new ht(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,a]of Object.entries(r))e.set(o,String(a));const n=e.toString()?`?${e.toString()}`:"",i=await this.kernel.request(`${l().pages(this.ref())}${n}`),s=(i.data??[]).map(t=>(this.kernel.rememberPage(t),new et(t,this.kernel)));return V(s,Z(i,s.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request(l().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let Y=null;function tt(){if(!Y)throw new Error("Client is not installed.");return Y}class et{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return ut(t,e)}static async find(t,e){return ut(t,e)}static async search(t,e,r){const n=nt(),i=it(n,e),s=new URLSearchParams;s.set("q",t),st(s,r);const o=await n.request(`${l().search(i)}?${s.toString()}`),a=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new et(t,n)));return V(a,Z(o,a.length))}getTitle(){return new y(this.record.title)}getSubtitle(){return new w(this.record.subtitle)}getSmallTitle(){return new S(this.record.smalltitle)}getSummary(){return new b(this.record.summary)}getContent(){return new $(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new A(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[U(this.record.options,t),this.kernel.snapshot().options[t],U(this.kernel.snapshot().site?.options,t),U(at(this.record.site),t)];for(const r of e)if(ot(r))return new j(t,r);return new j(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=T(t);return e?new L(e,this.kernel):null};return{title:new x(t.title??this.record.title),description:new v(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new A(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new A(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:ct(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new D(t,e)):[];var t,e}collectionImage(){return F(this.collectionItem,this.kernel)}getAssets(){return new q(J(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new q([]);const r=[];return J(this.record.assets,this.kernel).forEach((t,n)=>{const i=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));i&&r.push({asset:t,sort:i.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new q(r.map(t=>t.asset))}getGalleries(){const t=J(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=/* @__PURE__ */new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const i=r&&r>0?Math.floor(r):Math.max(n,1),s=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/i)),a=(s-1)*i;return{items:t.slice(a,a+i),meta:{currentPage:s,lastPage:o,perPage:i,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return V(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return V(t,Z(null,t.length))}const i=new URLSearchParams;i.set("parent",n),e.length&&i.set("with",e.join(",")),st(i,t);const s=await this.kernel.request(`${l().pages(this.siteRef())}?${i.toString()}`);return V(this.rowsToPages(s.data??[]),Z(s,(s.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new et(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${l().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${l().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new et(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:ut(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new X(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new X(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=p(await this.kernel.request(l().site(e)));return this.kernel.rememberSite(r),new X(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=E(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=/* @__PURE__ */new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?a(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new et(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,i=String(n.uuid||n.id||"");if(!i||e.has(i))break;e.add(i),t.unshift(new et(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=o(this.record);return t.filter(t=>o(t)!==e).map(t=>new et(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=p(await this.kernel.request(l().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let rt=null;function nt(){if(!rt)throw new Error("Client is not installed.");return rt}function it(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function st(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function ot(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function at(t){if(t&&"object"==typeof t)return t.options}function ct(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function ut(t,e){const r=nt(),n=it(r,e),i=p(await r.request(l().page(n,t)));return r.rememberPage(i),new et(i,r)}class lt{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new P(this.record.title)}getUrl(){return new A(this.record.url)}getChildren(){return pt(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??dt,n=r?.snapshot().page;return!(!r||!n)&&e===new et(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??dt;return e?new et(t,e):null}raw(){return{...this.record}}}class ht{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!dt)throw new Error("Client is not installed.");return dt}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),i=r.snapshot().menus,s=i[t]||Object.values(i).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(s)return new ht(s,r);const o=p(await r.request(l().menu(n,t)));return r.rememberMenu(o),new ht(o,r)}getName(){return new P(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return pt(this.record.items,this.runtime)}raw(){return{...this.record}}}function pt(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new lt(t,e)):[]}let dt=null;class gt{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{}};options;inflight=/* @__PURE__ */new Map;cache=/* @__PURE__ */new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),rt=this,Y=this,dt=this}hydrate(t){return this.snap=n(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{}};if(!t||"object"!=typeof t)return e;const r=t,n=i(r.props)?r.props:r;e.page=s(n.page),e.site=s(n.site),e.seo=i(n.seo)?n.seo:null,e.options=i(n.options)?n.options:{},e.locales=Array.isArray(n.locales)?n.locales:[];const o=n.menus;if(i(o))for(const[i,a]of Object.entries(o))e.menus[i]=s(a);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=h();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=h();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):a(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const i=this.apiBase();if(!i)throw new Error("Remote origin is not configured.");const s=async function(t,e,r={}){const{fetchImpl:n,...i}=r,s=e.startsWith("http")?e:u(t,e),o=n??fetch,a=new Headers(i.headers);a.has("Accept")||a.set("Accept","application/json");const c=await o(s,{...i,headers:a}),l=await c.text();let h=null;if(l)try{h=JSON.parse(l)}catch{h={message:l}}if(!c.ok){const t=new Error(`Request failed (${c.status})`);throw t.status=c.status,t.body=h,t}return h}(i,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,s),s.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),s}rememberPage(t){const e=this.snap.page;e&&String(e.id)===String(t.id)&&(this.snap=n(this.snap,{page:{...e,...t}}))}rememberSite(t){this.snap=n(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const e=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=n(this.snap,{menus:{[e]:t}})}}let ft=null;function mt(t={}){return ft=new gt(t),ft}function yt(){return ft||(ft=new gt),ft}const wt=/* @__PURE__ */Symbol.for("miro.client");function St(){return t(wt,null)??yt()}function bt(t={}){return{install(e,r={}){const n=mt({...t,...r});e.provide(wt,n),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const $t=bt();class _t{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=kt(String(e.lang??""));return r?[{lang:r,domain:At(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=jt(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||At(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const i=jt(String(t[r]??""));i&&e.push({lang:n[1],domain:At(i),url:i})}return e}(e)}(this.kernel.snapshot().locales)}current(){return kt(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=kt(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function kt(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function jt(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function At(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function Pt(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function Ct(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const i=e.slice(0,n),s=e.slice(n+1);if(""!==i&&(s===t||xt(s)===t))return i}return""}function xt(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function vt(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Rt(){const t=St(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Ut(){const t=Rt();return Bt(t),new et(()=>t.snapshot().page??{},t)}function Tt(){const t=Rt();return Bt(t),new X(()=>t.snapshot().site??{},t)}function It(t="topbar"){const e=Rt();return Bt(e),new ht(()=>e.snapshot().menus[t]??{position:t,items:[]},e)}function Wt(){const t=Rt();return Bt(t),new _t(t)}function Mt(){return Ut().getAssets()}function Nt(t){return function(t,e){const r=Pt(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:xt(r.join("/")||e)}}const r=xt(e);return{vendor:Ct(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=vt(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return vt(t)}(r),api:()=>vt(r),call:(t,...e)=>{const n=vt(r),i=n[t];if("function"!=typeof i)throw new Error(`Missing plugin method: ${t}`);return i.apply(n,e)},request:async(t="/",r={})=>{const i=l().plugins(n.vendor,n.slug,t||"/"),s=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),p(await e.request(i,{...r,headers:s,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const i=vt(r),s=i[String(e)];return"function"==typeof s?s.bind(i):s},has:(t,e)=>e in t||e in vt(r)})}(t,St())}function Ot(){const t=St();return{apiBase:e(()=>t.apiBase()),siteBase:e(()=>t.siteBase()),siteRef:e(()=>t.siteRef())}}function Bt(t){try{const e=function(){try{return Lt??null}catch{return null}}();if(!e)return;const n=e.usePage();t.hydrate(r(n))}catch{}}let Lt=null;import("@inertiajs/vue3").then(t=>{Lt=t}).catch(()=>{Lt=null});const qt=$t;export{L as Asset,C as AssetName,D as CollectionCard,q as Gallery,_t as Locales,ht as Menu,lt as MenuItem,P as MenuTitle,$t as Miro,j as OptionValue,et as Page,$ as PageContent,S as PageSmallTitle,w as PageSubtitle,b as PageSummary,y as PageTitle,wt as SDK_KEY,v as SeoDescription,x as SeoTitle,X as Site,k as SiteName,_ as SiteTitle,m as TextValue,A as UrlValue,bt as createMiro,mt as createRuntime,qt as default,yt as getRuntime,Pt as pluginWindowKey,St as useKernel,Mt as useMiroAssets,Ot as useMiroConfig,Wt as useMiroLocales,It as useMiroMenu,Ut as useMiroPage,Tt as useMiroSite,Nt as usePlugin};
1
+ import{toDisplayString as t,h as e,inject as r,computed as n,unref as i}from"vue";const s=["primary","secondary","accent","neutral","base-100","base-content","info","success","warning","error"],o=["sans","serif"],c=/\\(\[\/?(?:b|i|u|s|c|f)(?:=[a-z0-9-]+)?\])|\[(\/?)(b|i|u|s|c|f)(?:=([a-z0-9-]+))?\]/g;function a(t,e){return"c"===t?s.includes(e??""):"f"===t?o.includes(e??""):void 0===e}function u(t,e){""!==e&&e.split(/\r?\n/).forEach((e,r)=>{if(r>0&&t.push({type:"br"}),""===e)return;const n=t[t.length-1];"text"===n?.type?n.value+=e:t.push({type:"text",value:e})})}function l(t){const e=String(t??""),r=[],n=[],i=()=>n[n.length-1]?.children??r,s=()=>{var t,e;t=n.pop(),e=i(),0!==t.children.length&&("c"===t.tag?e.push({type:"c",value:t.value,children:t.children}):"f"===t.tag?e.push({type:"f",value:t.value,children:t.children}):e.push({type:t.tag,children:t.children}))};let o,l=0;for(c.lastIndex=0;null!==(o=c.exec(e));){u(i(),e.slice(l,o.index)),l=c.lastIndex;const[t,r,h,p,d]=o;if(void 0===r){if("/"===h){const e=void 0===d?n.map(t=>t.tag).lastIndexOf(p):-1;if(-1===e){u(i(),t);continue}for(;n.length>e;)s();continue}!a(p,d)||n.length>=8?u(i(),t):n.push({tag:p,value:d??null,children:[]})}else u(i(),r)}for(u(i(),e.slice(l));n.length>0;)s();return r}function h(t,e){for(const r of t)"text"===r.type?e.push(r.value):"br"===r.type?e.push("\n"):h(r.children,e)}function p(t){const e=String(t??"");if(!e.includes("["))return e;const r=[];return h(l(e),r),r.join("")}const d=/[⁢⁤][​‌‍⁠]+⁣/,g={b:"strong",i:"em",u:"u",s:"s"};function f(t){switch(t.type){case"text":return t.value;case"br":return e("br");case"c":return e("span",{style:{color:`var(--color-${t.value})`}},m(t.children));case"f":return e("span",{style:{fontFamily:`var(--font-${t.value})`}},m(t.children));default:return e(g[t.type],m(t.children))}}function m(t){return t.map(f)}const y=r=>{const n=t(r.value),i=d.test(n);if(!i&&!function(t){return t.includes("[")||t.includes("\n")}(n))return n;const s=m(l(n));return i?e("span",{"data-miro-rich":"",style:{display:"contents"}},s):1===s.length?s[0]:s};function w(t,e){return{page:void 0!==e.page?e.page:t.page,site:void 0!==e.site?e.site:t.site,menus:e.menus?{...t.menus,...e.menus}:{...t.menus},locales:e.locales??t.locales,seo:void 0!==e.seo?e.seo:t.seo,options:e.options?{...t.options,...e.options}:{...t.options}}}function S(t){return Boolean(t)&&"object"==typeof t&&!Array.isArray(t)}function b(t){return S(t)?t:null}function $(t){return t?String(t.uuid||t.ulid||t.id||t.slug||t.full_url||""):""}function _(t){return t?String(t.uuid||t.domain||t.id||""):""}function k(t){return String.fromCharCode(...t.map(t=>23^t))}function j(t,e){const r=String(t||"").replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`;return r?`${r}${n}`:n}function A(){const t=k([56,118,103,126]),e=k([97,38]),r=k([100,126,99,114,100]),n=k([103,118,112,114,100]),i=k([100,114,118,101,116,127]),s=k([122,114,121,98,100]),o=k([122,114,115,126,118]),c=k([103,123,98,112,126,121,100]),a=k([118,116,99,126,120,121,100]);return{sites:()=>j("",`${t}/${e}/${r}`),site:n=>j("",`${t}/${e}/${r}/${encodeURIComponent(n)}`),pages:i=>j("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}`),page:(i,s)=>j("",`${t}/${e}/${r}/${encodeURIComponent(i)}/${n}/${s.split("/").map(t=>encodeURIComponent(t)).join("/")}`),search:s=>j("",`${t}/${e}/${r}/${encodeURIComponent(s)}/${n}/${i}`),menus:n=>j("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}`),menu:(n,i)=>j("",`${t}/${e}/${r}/${encodeURIComponent(n)}/${s}/${encodeURIComponent(i)}`),media:e=>j("",`${t}/${o}/${encodeURIComponent(e)}`),action:e=>j("",`${t}/${a}/${encodeURIComponent(e)}`),plugins:(e,r,n="")=>{const i=`${t}/${c}/${encodeURIComponent(e)}/${encodeURIComponent(r)}`;return n&&"/"!==n?`${i}${n.startsWith("/")?n:`/${n}`}`:i}}}function v(){if("undefined"==typeof globalThis)return{};const t=globalThis.MiroConfig;return t&&"object"==typeof t?t:{}}function x(t){return t&&"object"==typeof t&&"data"in t?t.data:t}function P(t){return null==t?"":"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):""}function C(t){const e=P(t);if(!e)return"";if("undefined"!=typeof document){const t=document.createElement("textarea");return t.innerHTML=e,t.value}return e.replace(/&#(\d+);/g,(t,e)=>String.fromCharCode(Number(e))).replace(/&#x([0-9a-f]+);/gi,(t,e)=>String.fromCharCode(parseInt(e,16))).replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function R(t){return p(C(t)).replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?>[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim()}y.props=["value"],y.displayName="MiroText";class U extends String{kind;extra;constructor(t,e,r={}){super(C(e)),this.kind=t,this.extra=r,Object.setPrototypeOf(this,new.target.prototype)}toString(){return String.prototype.toString.call(this)}valueOf(){return String.prototype.valueOf.call(this)}raw(){return this.toString()}decode(){return C(this.toString())}cleanContent(){return R(this.toString())}stripHtml(){return this.cleanContent()}plain(){return p(this.toString())}excerpt(t=160){const e=this.cleanContent();return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}firstParagraph(){return function(t){const e=C(t),r=e.match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);return R(r?r[1]:e)}(this.toString())}isEmpty(){return""===this.cleanContent()}json(){const t=this.toString().trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}bool(){const t=this.toString().trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}number(){const t=Number(this.toString().trim());return Number.isFinite(t)?t:null}}class I extends U{constructor(t){super("PageTitle",t)}}class T extends U{constructor(t){super("PageSubtitle",t)}}class M extends U{constructor(t){super("PageSmallTitle",t)}}class N extends U{constructor(t){super("PageSummary",t)}}class O extends U{constructor(t){super("PageContent",t)}html(){return this.toString()}}class W extends U{constructor(t){super("SiteTitle",t)}}class B extends U{constructor(t){super("SiteName",t)}}class L extends U{key;structured;constructor(t,e){const r=D(e);super("OptionValue",r.text,{key:t}),this.key=t,this.structured=r.structured}json(){return void 0!==this.structured?this.structured:super.json()}present(){return!this.isEmpty()}}class q extends U{constructor(t){super("UrlValue",t)}path(){const t=this.toString().trim();if(!t)return"/";try{if(/^https?:\/\//i.test(t))return new URL(t).pathname.replace(/\/+$/,"")||"/"}catch{}return(t.startsWith("/")?t:`/${t}`).replace(/\/+$/,"")||"/"}href(t=""){const e=this.path();return!t||/^https?:\/\//i.test(e)?e:`${String(t).replace(/\/+$/,"")}${e}`}}class E extends U{constructor(t){super("MenuTitle",t)}}class G extends U{constructor(t){super("AssetName",t)}}class z extends U{constructor(t){super("SeoTitle",t)}}class J extends U{constructor(t){super("SeoDescription",t)}}function D(t){if(null==t)return{text:""};if("boolean"==typeof t||"number"==typeof t)return{text:String(t)};if("string"==typeof t){const e=t.trim();if(""===e||"[]"===e||"{}"===e)return{text:""};if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]")||e.startsWith('"')&&e.endsWith('"'))try{return D(JSON.parse(e))}catch{return{text:C(t)}}return{text:C(t)}}return Array.isArray(t)?{text:JSON.stringify(t),structured:t}:"object"==typeof t?function(t){return"value"in t&&Object.keys(t).every(t=>"value"===t||"key"===t||"id"===t||"active"===t)}(t)?D(t.value):{text:JSON.stringify(t),structured:t}:{text:P(t)}}function F(t,e){if(!t)return"";if(Array.isArray(t)){const r=t.find(t=>t&&"object"==typeof t&&t.key===e);return r&&"object"==typeof r?r.value:""}return"object"==typeof t?t[e]:""}function H(t){if("string"==typeof t){const e=t.trim();return e?X(e)?{uuid:e}:{url:e,path:e}:null}if(!t||"object"!=typeof t||Array.isArray(t))return null;const e=t,r=K(e.source),n=Z(e.url,e.preview_url,e.path,e.src,r?.url,r?.preview_url,r?.path),i=Z(e.uuid,r?.uuid);if(n||i&&X(i))return e;const s=Z(e.value);return s?H(s):null}function Z(...t){for(const e of t)if("string"==typeof e&&""!==e.trim())return e.trim();return""}function V(t){return"string"==typeof t?t.trim():""}function K(t){return!t||"object"!=typeof t||Array.isArray(t)?null:t}function Q(t){return t.startsWith("/media/")||t.startsWith("/_images/")||t.startsWith("/api/media/")||t.startsWith("/branding-assets/")||t.startsWith("/storage/")}function X(t){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t)}const Y=[{mark:"1_8",width:256},{mark:"1_4",width:512},{mark:"1_2",width:1024},{mark:"2_3",width:1400}];class tt{constructor(t,e){this.record=t,this.runtime=e}record;runtime;getUuid(){return String(this.record.uuid||this.record.id||"")}getName(){return new G(this.record.name)}getAlt(){return V(this.record.alt)}getCaption(){return V(this.record.caption)}getGallery(){return this.memberships()[0]??null}galleryUuid(){return this.memberships()[0]?.uuid??""}galleryName(){return this.memberships()[0]?.name??""}memberships(){const t=this.record.galleries;if(Array.isArray(t)&&t.length>0)return t.map(t=>rt(t)).filter(t=>null!==t);const e=String(this.record.gallery_uuid??"").trim(),r=String(this.record.gallery_name??"").trim();if(!e&&!r)return[];const n=this.record.gallery_id;return[{id:"number"==typeof n||"string"==typeof n?n:null,uuid:e,name:r,sort_order:nt(this.record.gallery_sort_order)}]}getMime(){const t=K(this.record.source);return String(this.record.mime_type||t?.mime_type||"")}getSize(){const t=K(this.record.source),e=Number(this.record.size??t?.size??0);return Number.isFinite(e)?e:0}getType(){const t=V(this.record.type);if(t)return t;const e=this.getMime();return e.startsWith("image/")?"image":e.startsWith("video/")?"video":"application/pdf"===e?"pdf":""}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}isImage(){return!!this.getMime().startsWith("image/")||/\.(jpe?g|png|gif|webp|svg)(\?|$)/i.test(this.urlString())}url(){return new q(this.urlString())}srcset(){const t=this.urlString();if(!t||/\.svg([?#]|$)/i.test(t)||/^https?:\/\//i.test(t)||t.startsWith("//"))return"";if(!/\.webp([?#]|$)/i.test(t)||/\.(?:1_16|1_8|1_4|1_2|2_3)\.webp([?#]|$)/i.test(t))return"";const e=Y.map(({mark:e,width:r})=>`${t.replace(/\.webp([?#].*)?$/i,`.${e}.webp$1`)} ${r}w`);return e.push(`${t} 2048w`),e.join(", ")}raw(){return{...this.record}}urlString(){const t=K(this.record.source),e=Z(this.record.uuid,t?.uuid),r=Z(this.record.disk,t?.disk);let n=Z(this.record.url,this.record.preview_url,this.record.path,this.record.src,t?.url,t?.preview_url,t?.path);if(e&&X(e)&&n&&function(t,e){return!!(/\/project-storage\//i.test(r=t)||/\/editor\/project-file/i.test(r)||/cms\.miroart\.pl/i.test(r)&&/\/(?:project-storage|storage)\//i.test(r))||"project_public"===e&&!Q(t)&&!/^https?:\/\//i.test(t)&&!t.startsWith("//");var r}(n,r))return this.mediaUrl(e);if(!n)return e&&X(e)?this.mediaUrl(e):"";if(!0===globalThis.isSsg){if(n.startsWith("/_images/")||n.startsWith("_images/"))return n.startsWith("/")?n:`/${n}`;const e=function(t){const e=t.match(/[?&]path=([^&]+)/i);if(e)try{const t=decodeURIComponent(e[1].replace(/\+/g," ")).split(/[/\\]/).pop()||"";if(t&&"project-file"!==t.toLowerCase())return t.trim()}catch{}return(t.split("#")[0].split("?")[0].split(/[/\\]/).pop()||"").trim()}(Z(t?.path,this.record.path,n)),r=/\.(jpe?g|png|gif|webp|svg)$/i.test(i=e)?/\.svg$/i.test(i)?`/_images/${i}`:`/_images/${i.replace(/\.(jpe?g|png|gif|webp)$/i,".webp")}`:null;if(r)return r}var i;if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;if(n.startsWith("_images/"))return`/${n}`;if(Q(n))return n;n.includes("/")||n.includes("\\")||X(n)||(n=`images/${n}`);const s=n.startsWith("/")?n:`/${n}`;return Q(s)||s.startsWith("/project-storage/")?s:`/storage${s}`}mediaUrl(t){const e=A().media(t),r=this.runtime.apiBase();return r?j(r,e):e}}class et{constructor(t){this.items=t}items;all(){return this.items.slice()}first(){return this.items[0]??null}extra(){return this.items.slice(1)}hero(){return this.first()}urls(){return this.items.map(t=>t.url())}isEmpty(){return 0===this.items.length}count(){return this.items.length}[Symbol.iterator](){return this.items[Symbol.iterator]()}}function rt(t){if(!t||"object"!=typeof t)return null;const e=t,r=String(e.uuid??"").trim(),n=String(e.name??"").trim();if(!r&&!n)return null;const i=e.id;return{id:"number"==typeof i||"string"==typeof i?i:null,uuid:r,name:n,sort_order:nt(e.sort_order)}}function nt(t){const e=Number(t??0);return Number.isFinite(e)?e:0}function it(t,e){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new tt(t,e)):[]}const st=/* @__PURE__ */new Set(["id","uuid","created_at","updated_at"]);class ot{constructor(t,e){this.row=t,this.kernel=e}row;kernel;getHref(){return new q(this.row.href)}getTitle(){return String(this.row.title??"")}item(){const t=this.row.item;return t&&"object"==typeof t?t:{}}image(){return ct(this.item(),this.kernel)}}function ct(t,e){if(!t||"object"!=typeof t)return null;for(const[r,n]of Object.entries(t)){if(st.has(r)||"string"!=typeof n||!at(n))continue;const t=H(n);if(t)return new tt(t,e)}return null}function at(t){const e=t.trim();return!!e&&(!!(e.startsWith("/media/")||e.startsWith("/_images/")||e.startsWith("_images/")||e.startsWith("/api/media/")||e.startsWith("/branding-assets/"))||/\.(jpe?g|png|gif|webp|svg)(\?|#|$)/i.test(e))}function ut(t,e){const r=t&&"object"==typeof t?t.meta:null,n=r&&"object"==typeof r?r:{};return{currentPage:ht(n.current_page,1),lastPage:ht(n.last_page,1),perPage:ht(n.per_page,Math.max(e,1)),total:pt(n.total,e)}}function lt(t,e){return Object.assign(t,{meta:e})}function ht(t,e){const r=Number(t);return!Number.isFinite(r)||r<1?e:Math.floor(r)}function pt(t,e){if(null==t||""===t)return e;const r=Number(t);return!Number.isFinite(r)||r<0?e:Math.floor(r)}class dt{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}static async all(){const t=ft(),e=await t.request(A().sites());return(Array.isArray(e?.data)?e.data:[]).filter(t=>Boolean(t)&&"object"==typeof t).map(e=>new dt(e,t))}static async find(t){const e=ft(),r=null!=t&&""!==String(t)?String(t):e.siteRef(),n=e.snapshot().site;if(n&&(!t||String(n.uuid)===String(t)||String(n.id)===String(t)||String(n.domain)===String(t)||_(n)===String(t)))return new dt(n,e);const i=x(await e.request(A().site(r)));return e.rememberSite(i),new dt(i,e)}static async findPage(t,e){return mt.find(t,e)}static async findMenu(t,e){return vt.find(t,e)}getName(){return new B(this.record.name)}getTitle(){const t=F(this.record.options,"seo_title")||F(this.record.options,"title");return new W(t||this.record.name)}getDomain(){return String(this.record.domain||"")}getLang(){return String(this.record.lang||"")}getUuid(){return String(this.record.uuid||"")}getOption(t){return new L(t,F(this.record.options,t))}getImage(t){const e=this.getOption(t),r=e.json(),n=null==r?e.toString().trim():r;if(null==n||""===n)return null;const i=H(n);return i?new tt(i,this.kernel):null}async findPage(t){return mt.find(t,this.ref())}async findMenu(t){return vt.find(t,this.ref())}async menus(){const t=this.kernel.snapshot().menus,e=Object.values(t).filter(Boolean);return e.length?e.map(t=>new vt(t,this.kernel)):((await this.kernel.request(A().menus(this.ref()))).data??[]).map(t=>(this.kernel.rememberMenu(t),new vt(t,this.kernel)))}async pages(t={}){const e=new URLSearchParams,r={...t};null!=r.perPage&&null==r.per_page&&(r.per_page=r.perPage,delete r.perPage);for(const[o,c]of Object.entries(r))e.set(o,String(c));const n=e.toString()?`?${e.toString()}`:"",i=await this.kernel.request(`${A().pages(this.ref())}${n}`),s=(i.data??[]).map(t=>(this.kernel.rememberPage(t),new mt(t,this.kernel)));return lt(s,ut(i,s.length))}async runAction(t){const e=String(t.uuid||"").trim();if(!e)throw new Error("Action uuid is required.");const r=String(this.record.domain||this.ref());return this.kernel.request(A().action(r),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({uuid:e,method:t.method||"GET",path:t.path||"",query:t.query||{},body:t.body||"",headers:t.headers||{},params:t.params||{},post:t.post||{}})})}raw(){return{...this.record}}ref(){return String(this.record.uuid||this.record.domain||this.record.id||this.kernel.siteRef())}}let gt=null;function ft(){if(!gt)throw new Error("Client is not installed.");return gt}class mt{constructor(t,e){this.source=t,this.kernel=e}source;kernel;get record(){return"function"==typeof this.source?this.source():this.source}setRecord(t){"function"!=typeof this.source?this.source=t:this.kernel.rememberPage(t)}static async findByUlid(t,e){return jt(t,e)}static async find(t,e){return jt(t,e)}static async search(t,e,r){const n=wt(),i=St(n,e),s=new URLSearchParams;s.set("q",t),bt(s,r);const o=await n.request(`${A().search(i)}?${s.toString()}`),c=(Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[]).map(t=>(n.rememberPage(t),new mt(t,n)));return lt(c,ut(o,c.length))}getTitle(){return new I(this.record.title)}getSubtitle(){return new T(this.record.subtitle)}getSmallTitle(){return new M(this.record.smalltitle)}getSummary(){return new N(this.record.summary)}getContent(){return new O(this.record.content)}getSlug(){return String(this.record.slug||"")}getUrl(){return new q(this.record.full_url||(this.record.slug?`/${this.record.slug}`:"/"))}getUuid(){return String(this.record.uuid||this.record.ulid||"")}getId(){return String(this.record.id||this.getUuid())}getLayout(){return String(this.record.layout||"")}getDisplay(){return String(this.record.display||"")}getDisplayInMenu(){const t=this.record.display_in_menu;return null==t||""===t||!1!==t&&0!==t&&"0"!==t}getSortOrder(){const t=Number(this.record.sort_order??0);return Number.isFinite(t)?t:0}getLang(){const t=String(this.record.lang||"").trim();if(t)return t;const e=this.kernel.snapshot().site;return String(e?.lang||function(t){return t&&"object"==typeof t?String(t.lang||""):""}(this.record.site)||"")}getOption(t){const e=[F(this.record.options,t),this.kernel.snapshot().options[t],F(this.kernel.snapshot().site?.options,t),F(_t(this.record.site),t)];for(const r of e)if($t(r))return new L(t,r);return new L(t,"")}getSeo(){const t=this.seoBag(),e=t=>null==t?"":String(t),r=t=>{const e=H(t);return e?new tt(e,this.kernel):null};return{title:new z(t.title??this.record.title),description:new J(t.description??this.record.summary),keywords:e(t.keywords),robots:e(t.robots),canonical:new q(t.canonical),ogTitle:e(t.og_title??t.title??this.record.title),ogDescription:e(t.og_description??t.description??this.record.summary),ogImage:r(t.og_image),ogType:e(t.og_type),ogUrl:new q(t.og_url||t.canonical),twitterCard:e(t.twitter_card),twitterTitle:e(t.twitter_title??t.og_title??t.title),twitterDescription:e(t.twitter_description??t.og_description??t.description),twitterImage:r(t.twitter_image||t.og_image),ldJson:kt(t.ld_json),raw:{...t}}}get collectionItem(){const t=this.record.collectionItem;return t&&"object"==typeof t?t:{}}get collectionItems(){const t=this.record.collectionItems;return t&&"object"==typeof t?t:{}}get collectionGallery(){return t=this.record.collectionGallery,e=this.kernel,Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new ot(t,e)):[];var t,e}collectionImage(){return ct(this.collectionItem,this.kernel)}getAssets(){return new et(it(this.record.assets,this.kernel))}getGallery(t){const e=t.trim();if(!e)return new et([]);const r=[];return it(this.record.assets,this.kernel).forEach((t,n)=>{const i=t.memberships().find(t=>function(t,e){const r=e.trim().toLocaleLowerCase();return!!r&&(t.uuid.toLocaleLowerCase()===r||t.name.toLocaleLowerCase()===r)}(t,e));i&&r.push({asset:t,sort:i.sort_order,index:n})}),r.sort((t,e)=>t.sort-e.sort||t.index-e.index),new et(r.map(t=>t.asset))}getGalleries(){const t=it(this.record.assets,this.kernel);return this.galleryList(t).map(t=>({id:t.id,uuid:t.uuid,name:t.name,description:t.description,sort_order:t.sort_order,assets:this.getGallery(t.uuid||t.name)}))}async getChildren(t){const e=function(t){if(!Array.isArray(t))return[];const e=/* @__PURE__ */new Set(["options","assets"]),r=[];for(const n of t){const t=String(n).trim().toLowerCase();e.has(t)&&!r.includes(t)&&r.push(t)}return r}(t?.with),r=Array.isArray(this.record.children)?this.record.children:null;if(r&&function(t,e){return!e.length||t.every(t=>{if(!t||"object"!=typeof t)return!1;const r=t;if(e.includes("options")){const t=r.options;if(null==t||"object"!=typeof t)return!1}return!(e.includes("assets")&&!Array.isArray(r.assets))})}(r,e)){const e=function(t,e,r){const n=t.length;if(!e&&!r)return{items:t,meta:{currentPage:1,lastPage:1,perPage:Math.max(n,1),total:n}};const i=r&&r>0?Math.floor(r):Math.max(n,1),s=e&&e>0?Math.floor(e):1,o=Math.max(1,Math.ceil(n/i)),c=(s-1)*i;return{items:t.slice(c,c+i),meta:{currentPage:s,lastPage:o,perPage:i,total:n}}}(this.rowsToPages(r),t?.page,t?.perPage);return lt(e.items,e.meta)}const n=this.getUuid()||String(this.record.id??"");if(!n){const t=r?this.rowsToPages(r):[];return lt(t,ut(null,t.length))}const i=new URLSearchParams;i.set("parent",n),e.length&&i.set("with",e.join(",")),bt(i,t);const s=await this.kernel.request(`${A().pages(this.siteRef())}?${i.toString()}`);return lt(this.rowsToPages(s.data??[]),ut(s,(s.data??[]).length))}async getSiblings(){if(Array.isArray(this.record.siblings))return this.record.siblings.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new mt(t,this.kernel));const t=this.record.parent_id,e=this.siteRef();if(null==t||""===t){const t=await this.kernel.request(`${A().pages(e)}?parent=root`);return this.excludeSelf(t.data??[])}const r=await this.kernel.request(`${A().pages(e)}?parent=${encodeURIComponent(String(t))}`);return this.excludeSelf(r.data??[])}async getParent(){if(this.record.parent&&"object"==typeof this.record.parent)return new mt(this.record.parent,this.kernel);const t=this.record.parent_id;return null==t||""===t?null:jt(String(t),this.siteRef())}async getAncestors(){if(Array.isArray(this.record.ancestors))return this.rowsToPages(this.record.ancestors);const t=this.embeddedAncestors();if(t.length){const e=t[0],r=e.raw().parent_id;return null==r||""===r||0===r?t:[...await e.fetchAncestors(),...t]}return this.fetchAncestors()}async getSite(){if(this.record.site&&"object"==typeof this.record.site)return new dt(this.record.site,this.kernel);const t=this.kernel.snapshot().site;if(t&&(String(t.id)===String(this.record.site_id)||!this.record.site_id))return new dt(t,this.kernel);const e=this.record.site_id?String(this.record.site_id):this.kernel.siteRef(),r=x(await this.kernel.request(A().site(e)));return this.kernel.rememberSite(r),new dt(r,this.kernel)}async load(){return await this.ensure(["content","options","assets","children"]),this}raw(){return{...this.record}}seoBag(){const t=this.record.seo&&"object"==typeof this.record.seo?this.record.seo:this.kernel.snapshot().seo;return t&&"object"==typeof t?{...t}:{}}galleryList(t){if(Array.isArray(this.record.galleries))return this.record.galleries.flatMap(t=>{const e=rt(t);if(!e)return[];const r=t&&"object"==typeof t?String(t.description??""):"";return[{...e,description:r}]});const e=/* @__PURE__ */new Map;for(const r of t)for(const t of r.memberships()){const r=(t.uuid||t.name).toLocaleLowerCase();r&&!e.has(r)&&e.set(r,{...t,description:""})}return[...e.values()]}siteRef(){return this.record.site&&"object"==typeof this.record.site?_(this.record.site)||this.kernel.siteRef():this.record.site_id?String(this.record.site_id):this.kernel.siteRef()}rowsToPages(t){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new mt(t,this.kernel)):[]}embeddedAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=this.record.parent;for(;r&&"object"==typeof r&&t.length<12;){const n=r,i=String(n.uuid||n.id||"");if(!i||e.has(i))break;e.add(i),t.unshift(new mt(n,this.kernel)),r=n.parent}return t}async fetchAncestors(){const t=[],e=/* @__PURE__ */new Set;let r=await this.getParent();for(;r&&t.length<12;){const n=r.getUuid()||String(r.raw().id??"");if(!n||e.has(n))break;e.add(n),t.unshift(r),r=await r.getParent()}return t}excludeSelf(t){const e=$(this.record);return t.filter(t=>$(t)!==e).map(t=>new mt(t,this.kernel))}async ensure(t){if(!t.some(t=>void 0===this.record[t]))return;const e=this.getUuid()||this.getSlug()||String(this.record.id||"");if(!e)return;const r=x(await this.kernel.request(A().page(this.siteRef(),e)));this.setRecord({...this.record,...r})}}let yt=null;function wt(){if(!yt)throw new Error("Client is not installed.");return yt}function St(t,e){return null!=e&&""!==String(e)?String(e):t.siteRef()}function bt(t,e){e?.page&&e.page>0&&t.set("page",String(Math.floor(e.page))),e?.perPage&&e.perPage>0&&t.set("per_page",String(Math.floor(e.perPage)))}function $t(t){if(null==t)return!1;if("string"==typeof t){const e=t.trim();return""!==e&&"{}"!==e&&"[]"!==e}return Array.isArray(t)?t.length>0:"object"!=typeof t||Object.keys(t).length>0}function _t(t){if(t&&"object"==typeof t)return t.options}function kt(t){if("string"==typeof t)return t;if(t&&"object"==typeof t)try{return JSON.stringify(t)}catch{return""}return""}async function jt(t,e){const r=wt(),n=St(r,e),i=x(await r.request(A().page(n,t)));return r.rememberPage(i),new mt(i,r)}class At{constructor(t,e=null){this.record=t,this.kernel=e}record;kernel;getTitle(){return new E(this.record.title)}getUrl(){return new q(this.record.url)}getChildren(){return xt(this.record.children,this.kernel)}isCurrent(t){const e=this.getUrl().path();if(!e)return!1;if(t)return e===t.getUrl().path();const r=this.kernel??Pt,n=r?.snapshot().page;return!(!r||!n)&&e===new mt(n,r).getUrl().path()}getPage(){const t=this.record.page;if(!t||"object"!=typeof t)return null;const e=this.kernel??Pt;return e?new mt(t,e):null}raw(){return{...this.record}}}class vt{constructor(t,e){this.source=t,this.runtime=e}source;runtime;get record(){return"function"==typeof this.source?this.source():this.source}static async find(t,e){const r=function(){if(!Pt)throw new Error("Client is not installed.");return Pt}(),n=null!=e&&""!==String(e)?String(e):r.siteRef(),i=r.snapshot().menus,s=i[t]||Object.values(i).find(e=>!!e&&(String(e.uuid)===t||String(e.id)===t||String(e.name)===t||String(e.position)===t));if(s)return new vt(s,r);const o=x(await r.request(A().menu(n,t)));return r.rememberMenu(o),new vt(o,r)}getName(){return new E(this.record.name)}getPosition(){return String(this.record.position||"")}getItems(){return xt(this.record.items,this.runtime)}raw(){return{...this.record}}}function xt(t,e=null){return Array.isArray(t)?t.filter(t=>Boolean(t)&&"object"==typeof t).map(t=>new At(t,e)):[]}let Pt=null;class Ct{snap={page:null,site:null,menus:{},locales:[],seo:null,options:{}};options;inflight=/* @__PURE__ */new Map;cache=/* @__PURE__ */new Map;constructor(t={}){this.options=t,t.page&&this.hydrate(t.page),yt=this,gt=this,Pt=this}hydrate(t){return this.snap=w(this.snap,function(t){const e={page:null,site:null,menus:{},locales:[],seo:null,options:{}};if(!t||"object"!=typeof t)return e;const r=t,n=S(r.props)?r.props:r;e.page=b(n.page),e.site=b(n.site),e.seo=S(n.seo)?n.seo:null,e.options=S(n.options)?n.options:{},e.locales=Array.isArray(n.locales)?n.locales:[];const i=n.menus;if(S(i))for(const[s,o]of Object.entries(i))e.menus[s]=b(o);return e}(t)),this.snap}snapshot(){return this.snap}apiBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=v();return e.apiBase?String(e.apiBase).replace(/\/+$/,""):function(){if("undefined"==typeof location)return"";const t=String(location.origin||"").replace(/\/+$/,"");if(t&&"null"!==t)return t;const e=location.hostname||"";return e?`${location.protocol}//${e}`:""}()}(this.options.apiBase)}siteBase(){return function(t){if(t)return String(t).replace(/\/+$/,"");const e=v();return e.siteBase?String(e.siteBase).replace(/\/+$/,""):"undefined"!=typeof location?location.origin:""}(this.options.siteBase)}siteRef(){return null!=this.options.site&&""!==String(this.options.site)?String(this.options.site):_(this.snap.site)}async request(t,e={}){const r=String(e.method||"GET").toUpperCase(),n=`${r} ${t}`;if("GET"===r&&this.cache.has(n))return this.cache.get(n);if("GET"===r){const t=this.inflight.get(n);if(t)return t}const i=this.apiBase();if(!i)throw new Error("Remote origin is not configured.");const s=async function(t,e,r={}){const{fetchImpl:n,...i}=r,s=e.startsWith("http")?e:j(t,e),o=n??fetch,c=new Headers(i.headers);c.has("Accept")||c.set("Accept","application/json");const a=await o(s,{...i,headers:c}),u=await a.text();let l=null;if(u)try{l=JSON.parse(u)}catch{l={message:u}}if(!a.ok){const t=new Error(`Request failed (${a.status})`);throw t.status=a.status,t.body=l,t}return l}(i,t,{...e,fetchImpl:this.options.fetch}).then(t=>("GET"===r&&this.cache.set(n,t),t));return"GET"===r&&(this.inflight.set(n,s),s.finally(()=>{this.inflight.delete(n)}).catch(()=>{})),s}rememberPage(t){const e=this.snap.page;e&&String(e.id)===String(t.id)&&(this.snap=w(this.snap,{page:{...e,...t}}))}rememberSite(t){this.snap=w(this.snap,{site:{...this.snap.site??{},...t}})}rememberMenu(t){const e=String(t.position||t.uuid||t.id||t.name||"menu");this.snap=w(this.snap,{menus:{[e]:t}})}}let Rt=null;function Ut(t={}){return Rt=new Ct(t),Rt}function It(){return Rt||(Rt=new Ct),Rt}const Tt=/* @__PURE__ */Symbol.for("miro.client");function Mt(){return r(Tt,null)??It()}function Nt(t={}){return{install(e,r={}){const n=Ut({...t,...r});e.provide(Tt,n),e.component("MiroText",y),function(t){import("@inertiajs/vue3").then(e=>{const r=e.router;r?.page&&t.hydrate(r.page),r?.on?.("success",e=>{const r=e?.detail?.page;r&&t.hydrate(r)}),r?.on?.("navigate",e=>{const r=e?.detail?.page;r&&t.hydrate(r)})}).catch(()=>{})}(n)}}}const Ot=Nt();class Wt{constructor(t){this.kernel=t}kernel;all(){return function(t,e=function(){return globalThis}()){const r=Array.isArray(t)?t.flatMap(t=>function(t){if(!t||"object"!=typeof t)return[];const e=t,r=Bt(String(e.lang??""));return r?[{lang:r,domain:qt(String(e.domain??"")),url:String(e.url??"").trim()}]:[]}(t)):[];return r.length?r.flatMap(t=>{const r=Lt(t.url||function(t,e){const r=e[`locale_${t}_baseurl`];return"string"==typeof r?r.trim():""}(t.lang,e)||t.domain);return t.lang&&r?[{lang:t.lang,domain:t.domain||qt(r),url:r}]:[]}):function(t){const e=[];for(const r of Object.keys(t)){const n=/^locale_([a-z]+)_baseurl$/.exec(r);if(!n)continue;const i=Lt(String(t[r]??""));i&&e.push({lang:n[1],domain:qt(i),url:i})}return e}(e)}(this.kernel.snapshot().locales)}current(){return Bt(String(this.kernel.snapshot().site?.lang||""))}url(t){const e=Bt(t),r=this.all().find(t=>t.lang===e);return r?.url??""}}function Bt(t){return(t.trim().toLowerCase().replaceAll("_","-").split("-")[0]??"").replace(/[^a-z]/g,"")}function Lt(t){const e=t.trim();return e?(/^https?:\/\//i.test(e)?e:`https://${e.replace(/^\/+/,"")}`).replace(/\/+$/,""):""}function qt(t){return t.trim().replace(/^https?:\/\//i,"").replace(/\/.*$/,"")}function Et(t){return`mc_${(String(t??"").trim().split("/").pop()??"").replace(/^@/,"").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toUpperCase()}`}function Gt(t){if("undefined"==typeof window||""===t)return"";const e=window.__MIRO_WEB_PLUGINS__;if(!Array.isArray(e))return"";for(const r of e){const e=String(r??"").trim().toLowerCase(),n=e.lastIndexOf("/");if(n<=0)continue;const i=e.slice(0,n),s=e.slice(n+1);if(""!==i&&(s===t||zt(s)===t))return i}return""}function zt(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase()}function Jt(t){if("undefined"==typeof window)return{};const e=window[t];return e&&"object"==typeof e?e:{}}function Dt(){const t=Mt(),e=function(){try{const t=globalThis.__INERTIA_PAGE__;if(t?.props)return t.props}catch{}return function(){if("undefined"==typeof document)return null;const t=document.querySelector("[data-page]")?.getAttribute("data-page");if(!t)return null;try{return JSON.parse(t).props??null}catch{return null}}()}();return e&&t.hydrate(e),t}function Ft(){const t=Dt();return Yt(t),new mt(()=>t.snapshot().page??{},t)}function Ht(){const t=Dt();return Yt(t),new dt(()=>t.snapshot().site??{},t)}function Zt(t="topbar"){const e=Dt();return Yt(e),new vt(()=>e.snapshot().menus[t]??{position:t,items:[]},e)}function Vt(){const t=Dt();return Yt(t),new Wt(t)}function Kt(){return Ft().getAssets()}function Qt(t){return function(t,e){const r=Et(t),n=function(t){const e=String(t??"").trim();if(e.includes("/")){const[t,...r]=e.split("/");return{vendor:t||"miroart",slug:zt(r.join("/")||e)}}const r=zt(e);return{vendor:Gt(r)||"miroart",slug:r}}(t);return new Proxy({name:t,key:r,ready:async()=>async function(t){const e=Date.now();for(;Date.now()-e<4e3;){const e=Jt(t);if(Object.keys(e).length)return e;await new Promise(t=>setTimeout(t,50))}return Jt(t)}(r),api:()=>Jt(r),call:(t,...e)=>{const n=Jt(r),i=n[t];if("function"!=typeof i)throw new Error(`Missing plugin method: ${t}`);return i.apply(n,e)},request:async(t="/",r={})=>{const i=A().plugins(n.vendor,n.slug,t||"/"),s=new Headers(r.headers);let o=r.body;return void 0!==r.json&&(o=JSON.stringify(r.json)),x(await e.request(i,{...r,headers:s,body:o}))}},{get(t,e,n){if(e in t)return Reflect.get(t,e,n);if("then"===e||e===Symbol.toStringTag)return;const i=Jt(r),s=i[String(e)];return"function"==typeof s?s.bind(i):s},has:(t,e)=>e in t||e in Jt(r)})}(t,Mt())}function Xt(){const t=Mt();return{apiBase:n(()=>t.apiBase()),siteBase:n(()=>t.siteBase()),siteRef:n(()=>t.siteRef())}}function Yt(t){try{const e=function(){try{return te??null}catch{return null}}();if(!e)return;const r=e.usePage();t.hydrate(i(r))}catch{}}let te=null;import("@inertiajs/vue3").then(t=>{te=t}).catch(()=>{te=null});const ee=Ot;export{tt as Asset,G as AssetName,ot as CollectionCard,et as Gallery,Wt as Locales,vt as Menu,At as MenuItem,E as MenuTitle,Ot as Miro,y as MiroText,L as OptionValue,mt as Page,O as PageContent,M as PageSmallTitle,T as PageSubtitle,N as PageSummary,I as PageTitle,s as RICH_COLORS,o as RICH_FONTS,Tt as SDK_KEY,J as SeoDescription,z as SeoTitle,dt as Site,B as SiteName,W as SiteTitle,U as TextValue,q as UrlValue,Nt as createMiro,Ut as createRuntime,ee as default,It as getRuntime,l as parseRichText,p as plainText,Et as pluginWindowKey,Mt as useKernel,Kt as useMiroAssets,Xt as useMiroConfig,Vt as useMiroLocales,Zt as useMiroMenu,Ft as useMiroPage,Ht as useMiroSite,Qt as usePlugin};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Formatowanie w jednym stringu pola: `[b]`, `[i]`, `[u]`, `[s]`, `[c=primary]`, `[f=serif]`.
3
+ * Nie ma tu HTML-a: wynik to drzewo, z którego `MiroText` buduje węzły przez `h()`.
4
+ * Te same reguły są w nakładce edytora (`web/app/Support/VisualEdit/overlay.js`) i w
5
+ * `web/app/Support/RichInline.php`.
6
+ */
7
+ export declare const RICH_COLORS: readonly ["primary", "secondary", "accent", "neutral", "base-100", "base-content", "info", "success", "warning", "error"];
8
+ export declare const RICH_FONTS: readonly ["sans", "serif"];
9
+ export type RichColor = (typeof RICH_COLORS)[number];
10
+ export type RichFont = (typeof RICH_FONTS)[number];
11
+ export type RichNode = {
12
+ type: "text";
13
+ value: string;
14
+ } | {
15
+ type: "br";
16
+ } | {
17
+ type: "b" | "i" | "u" | "s";
18
+ children: RichNode[];
19
+ } | {
20
+ type: "c";
21
+ value: RichColor;
22
+ children: RichNode[];
23
+ } | {
24
+ type: "f";
25
+ value: RichFont;
26
+ children: RichNode[];
27
+ };
28
+ /**
29
+ * Nie rzuca wyjątku dla żadnego wejścia. Coś, co nie jest znanym znacznikiem z dozwoloną
30
+ * wartością, zostaje zwykłym tekstem. Niezamknięty znacznik kończy się z końcem wartości.
31
+ */
32
+ export declare function parseRichText(value: unknown): RichNode[];
33
+ /** Do atrybutów (`alt`, `aria-label`), `<title>` i liczenia znaków: bez znaczników, `\n` zostaje. */
34
+ export declare function plainText(value: unknown): string;
35
+ /** Czy wartość w ogóle wymaga drzewa. Reszta to jeden węzeł tekstowy, jak przy `{{ }}`. */
36
+ export declare function needsRichRender(raw: string): boolean;
package/dist/values.d.ts CHANGED
@@ -10,6 +10,8 @@ export declare class TextValue extends String {
10
10
  decode(): string;
11
11
  cleanContent(): string;
12
12
  stripHtml(): string;
13
+ /** Bez znaczników `[b]`, `[c=…]`: do atrybutów i `<title>`. Nowe linie zostają. */
14
+ plain(): string;
13
15
  excerpt(length?: number): string;
14
16
  firstParagraph(): string;
15
17
  isEmpty(): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miroart/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Vue 3 client for preloaded page data and a remote JSON origin.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",