@realsee/live 0.7.8 → 0.7.10

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,5 @@
1
+ License update for @realsee/live@0.7.10
2
+
3
+ This release updates the Realsee-authored package license to the Realsee SDK License Agreement, last updated 2026-09-22. The package implementation is unchanged from @realsee/live@0.7.9.
4
+
5
+ Third-party components, notices and separately licensed materials retain their respective licenses. This update does not change the license of any previously published package version.
package/TERMS.txt CHANGED
@@ -1,56 +1,119 @@
1
1
  Realsee SDK License Agreement
2
2
 
3
- Update: July 28, 2021
3
+ Last updated: 2026-09-22
4
+
5
+ THIS LICENSE AGREEMENT BETWEEN YOU AND BEIKE REALSEE TECHNOLOGY (HK) LIMITED (“Realsee”) FORMS A LEGALLY BINDING CONTRACT BETWEEN YOU AND REALSEE IN RELATION TO YOUR USE OF THE SDK. This License Agreement accompanies the Realsee Software Development Kit(s) for the software and related explanatory materials (the "SDK") and includes any upgrades, modified versions, updates, additions, and copies of the SDK licensed to You by Realsee.
4
6
 
5
- THIS LICENSE AGREEMENT BETWEEN YOU AND 【BEIKE REALSEE TECHNOLOGY (HK) LIMITED】(“Realsee”) FORMS A LEGALLY BINDING CONTRACT BETWEEN YOU AND REALSEE IN RELATION TO YOUR USE OF THE SDK. This License Agreement accompanies the Realsee Software Development Kit(s) for the software and related explanatory materials (the "SDK") and includes any upgrades, modified versions, updates, additions, and copies of the SDK licensed to You by Realsee.
6
7
  BY DOWNLOADING, INSTALLING, OR OTHERWISE ACCESSING OR USING THE SDK, YOU AGREE THAT YOU HAVE READ, UNDERSTOOD, AND AGREE TO BE BOUND BY THIS AGREEMENT. YOU ARE AGREEING ON YOUR OWN BEHALF AND/OR ON BEHALF OF YOUR COMPANY OR ORGANIZATION TO THE TERMS AND CONDITIONS STATED BELOW.
8
+
7
9
  This Agreement applies to Your use of the SDK in the country in which You legally install it (“Territory”) and is subject to the laws of such Territory and further subject to Section 12 below. Different terms, conditions, and limitations may apply to the use of the SDK in any additional countries.
10
+
8
11
  1. DEFINITIONS.
12
+
9
13
  “Agreement” means this Realsee SDK License Agreement.
14
+
10
15
  “Developer”, “You” and “Your” means the person(s) or entity acquiring or using the SDK or otherwise exercising rights under the terms of this Agreement.
16
+
11
17
  “Documentation” means the technical or other specifications or documentation that Realsee may provide to You for use in connection with the SDK.
18
+
12
19
  “Integrated Product” means any software, website, or on-line service developed by You based on or using the SDK (collectively, the “Integrated Product”).
20
+
13
21
  “Intellectual Property” means any patents, patent rights, trademarks, service marks, registered and unregistered designs, applications for any of the foregoing, copyright, and any other similar protected rights in any country and to the extent recognised by any relevant jurisdiction as intellectual property, trade secrets, know-how and confidential information. Realsee reserves all rights not expressly granted to You.
22
+
14
23
  “Realsee” means [Beike Realsee Technology (HK) Limited, a company incorporated and validly existing under the laws of Hong Kong].
24
+
15
25
  “SDK” means the Realsee-proprietary Software Development Kits (SDK) provided hereunder, includes all development tools (including any compiler and debugger), application programming interfaces (“APIs”), libraries, binary utilities, header files, Documentation, content, data, code samples, and other materials provided to You in connection with this Agreement, whether delivered through a download, or any other media or form, and is licensed, not sold, to You by Realsee for use only under the terms of this Agreement. The terms of this Agreement will govern any updates provided by Realsee that replace and/or supplement the original SDK delivered to You, unless such update is accompanied by a separate license, in which case the terms of such license will govern.
26
+
27
+ “Term” means the period commencing on the date You first download, install, access, or use the SDK, and continuing until this Agreement is terminated in accordance with Section 6.
28
+
16
29
  2. LICENSED USES AND RESTRICTIONS.
17
- 2.1 Subject to the restrictions contained in this Section 2, Realsee grants to You during the term, a limited, non-exclusive, revocable, non-sublicensable, non-transferable license to install and use the SDK within the Territory only for the purpose of internal development.
18
- 2.2 Restrictions. You acknowledge and agree that, You shall not, and shall ensure that Your affiliates, employees, agents, representatives, officers, representatives, and subcontractors do not (directly or indirectly):
30
+
31
+ 2.1 Subject to the restrictions contained in this Section 2, Realsee grants to You during the Term, a limited, non-exclusive, revocable, non-sublicensable, non-transferable license to install, use, and integrate the SDK within the Territory only for the purpose of developing, testing, operating and supporting Integrated Products.
32
+
33
+ 2.2 Restrictions. You acknowledge and agree that, You shall not, and shall ensure that Your affiliates, employees, agents, representatives, officers, and subcontractors do not (directly or indirectly):
34
+
19
35
  2.2.1 decompile, reverse engineer, disassemble or attempt to derive the source code of, those components of the SDK provided in object code form, or any part thereof;
36
+
20
37
  2.2.2 remove, alter, or obscure any copyright notice or other proprietary rights notice on any part of the SDK;
38
+
21
39
  2.2.3 sell, assign, pledge, rent, lease, lend, upload to or host on any website or server for use by any third party except You, redistribute, or sublicense the SDK (or any part thereof), or operate the SDK (or any part thereof) in the capacity of a service bureau or other hosted services provider, in whole or in part, nor may You enable others to do so;
22
- 2.2.4 or alter, modify, customize or improve the SDK, or any part thereof;
40
+
41
+ 2.2.4 alter, modify, customize or improve the SDK, or any part thereof;
42
+
23
43
  2.2.5 use the SDK (or any part thereof) for any illegal purpose, in any manner that is inconsistent with the terms of this Agreement, or to engage in any illegal activity;
44
+
24
45
  2.2.6 use the SDK (or any part thereof) in any manner that may damage the operation of Realsee’s products or services; or
25
- 2.2.7 use the SDK or any information contained therein or otherwise provided by Realsee for the purpose of developing, or having developed, any product competitive with any Realsee product or service, as determined by Realsee in its sole discretion;
26
- 2.2.8 include any portion of the SDK in Your Developer products.
46
+
47
+ 2.2.7 use the SDK or any non-public information provided by Realsee for the primary purpose of developing products or services that substantially replicate the core functionality of Realsee proprietary SDK offerings;
48
+
49
+ 2.2.8 distribute, re-sell, or make available the SDK (or any part thereof) as a standalone product, library, or development toolkit to any third party.
50
+
27
51
  2.3 Realsee has the right to impose reasonable conditions such as a reasonable fee for use of the SDK in Integrated Product in the future.
52
+
28
53
  2.4 You may make a limited number of copies of the SDK to be used by Your employees or consultants as provided herein, and not for general business purposes, and such employees or consultants shall be subject to the obligations and restrictions in this Agreement.
54
+
29
55
  2.5 All licenses not expressly granted in this Agreement are reserved and no other licenses, immunity, or rights, express or implied, are granted by Realsee, by implication, estoppel, or otherwise.
56
+
30
57
  3. CONFIDENTIALITY.
58
+
31
59
  The SDK and all source code, Documentation, specifications, engineering details, and related information pertaining to the SDK, whether in oral, written, graphic, or electronic form, are and shall remain the confidential and proprietary information of Realsee or its licensors (collectively, the “Confidential Information”). You shall (i) disclose Confidential Information to only those directors and employees (collectively, “Affiliates”) whose duties justify their need to know such information and who have been clearly informed of their obligation to maintain the confidential, proprietary, and/or trade secret status of such Confidential Information; and (ii) use Confidential Information solely in accordance with the license granted hereunder. In any event, You and Your Affiliates shall treat Confidential Information as strictly confidential and shall use the same care to prevent disclosure of such information as You use with respect to Your own similar confidential and/or proprietary information, which shall not be less than the care a reasonable person would use under similar circumstances. All Confidential Information, and any copies thereof, shall be returned promptly to Realsee upon request. You shall ensure that Your Affiliates comply with the provisions of this Section 3, and You shall be liable for any breach of this Section 3 resulting from the act or omission of any of Your Affiliates. You shall not disclose Confidential Information to any third party, including, without limitation, any of Your subcontractors.
60
+
32
61
  4. PROPRIETARY RIGHTS.
62
+
33
63
  4.1 As between You and Realsee, Realsee and/or its licensors retain ownership of all right, title, and interest in, to, and under the SDK, including, without limitation, all patents, copyrights, trade secrets, trademarks and other intellectual property and other proprietary rights therein, and reserve all rights not expressly granted to You.
64
+
34
65
  4.2 The items contained in the SDK are the intellectual property of Realsee and its licensors and are protected by PRC copyright and patent law, international treaty provisions and applicable laws of the country in which it is being used. You agree to protect all copyright and other ownership interests of Realsee and/or its licensors in all items in the SDK supplied under this License Agreement. You agree that all copies of the items in the SDK, reproduced for any reason by You, contain the same copyright notices, and other proprietary notices as appropriate, as appear on or in the original items delivered by Realsee in the SDK. Realsee and/or its licensors retain title and ownership of the items in the SDK, the media on which it is loaded, and all subsequent copies, regardless of the form or media in or on which the original and other copies may exist. Except as stated above, this Agreement does not grant You any rights to patents, copyrights, trade secrets, trademarks or any other rights in respect to the items in the SDK.
35
- 5. TERM AND TERMINATION.
36
- 5.1 This Agreement is effective until terminated. Realsee has the right to terminate this Agreement immediately, without judicial intervention, if You fail to comply with any term herein. Upon any such termination You must remove all full and partial copies of the items in the SDK from Your computer and discontinue the use of the items in the SDK.
37
- 5.2 Realsee may at any time, terminate the Agreement with You if: (A) You have breached any provision of the Agreement; or (B) Realsee is required to do so by law; or (C) Realsee decides to no longer provide the SDK or certain parts of the SDK to users in the country in which You are resident or from which You use the service, or the provision of the SDK or certain SDK services to You by Realsee is, in Realsee's sole discretion, no longer legally or commercially viable.
38
- 5.3 When the Agreement comes to an end, all of the legal rights, obligations and liabilities that You and Realsee have benefited from, been subject to (or which have accrued over time whilst the Agreement has been in force) or which are expressed to continue indefinitely, shall be unaffected by this cessation, and the provisions of Section 3, 4, 6, 7 and 8 shall continue to apply to such rights, obligations and liabilities indefinitely.
39
- 6. DISCLAIMER OF WARRANTY.
66
+
67
+ 5. DATA PRIVACY AND PROTECTION
68
+
69
+ 5.1 In connection with Your use of the SDK and any Integrated Product, You shall comply with all applicable privacy, data protection, cybersecurity, and cross-border data transfer laws and regulations. To the extent Your use of the SDK involves the collection, processing, transmission, disclosure, or storage of personal data or personal information, You shall be solely responsible for: (i) ensuring that You have a valid legal basis for such processing; (ii) providing all required notices and obtaining all necessary consents or authorisations; and (iii) implementing reasonable and appropriate technical and organisational measures to protect such data against unauthorised access, use, disclosure, alteration, or destruction.
70
+
71
+ 5.2 You shall promptly notify Realsee of any material security incident relating to the SDK or Integrated Product that may materially affect Realsee, the SDK, or any personal data processed in connection with the SDK.
72
+
73
+ 5.3 Developer shall be solely responsible for Developer’s compliance with applicable privacy, data protection, and cybersecurity laws in connection with the Integrated Product.
74
+
75
+ 6. TERM AND TERMINATION.
76
+
77
+ 6.1 This Agreement is effective until terminated. Realsee has the right to terminate this Agreement immediately, without judicial intervention, if You fail to comply with any term herein. Upon any such termination You must remove all full and partial copies of the items in the SDK from Your computer and discontinue the use of the items in the SDK.
78
+
79
+ 6.2 Realsee may at any time, terminate the Agreement with You if: (A) You have breached any provision of the Agreement; or (B) Realsee is required to do so by law; or (C) Realsee decides to no longer provide the SDK or certain parts of the SDK to users in the country in which You are resident or from which You use the service, or the provision of the SDK or certain SDK services to You by Realsee is, in Realsee's sole discretion, no longer legally or commercially viable.
80
+
81
+ 6.3 When the Agreement comes to an end, all of the legal rights, obligations and liabilities that You and Realsee have benefited from, been subject to (or which have accrued over time whilst the Agreement has been in force) or which are expressed to continue indefinitely, shall be unaffected by this cessation, and the provisions of Sections 3, 4, 5, 7, 8, 9, 10, and 11 shall continue to apply to such rights, obligations and liabilities indefinitely.
82
+
83
+ 7. DISCLAIMER OF WARRANTY.
84
+
40
85
  YOU EXPRESSLY ACKNOWLEDGE AND AGREE THAT, TO THE EXTENT PERMITTED BY APPLICABLE LAW, USE OF THE SDK (OR ANY PART THEREOF) IS AT YOUR SOLE RISK AND THAT THE ENTIRE RISK AS TO SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH YOU. REALSEE LICENSES THE SDK TO YOU ONLY ON AN "AS-IS" BASIS. REALSEE MAKES NO REPRESENTATION WITH RESPECT TO THE ADEQUACY OF ANY ITEMS IN THE SDK, WHETHER OR NOT USED BY YOU IN THE DEVELOPMENT OF INTEGRATED PRODUCT, FOR ANY PARTICULAR PURPOSE OR WITH RESPECT TO THEIR ADEQUACY TO PRODUCE ANY PARTICULAR RESULT. REALSEE AND ITS LICENSORS SHALL NOT BE LIABLE FOR LOSS OR DAMAGE ARISING OUT OF THIS AGREEMENT OR FROM THE DISTRIBUTION OR USE OF INTEGRATED PRODUCT CONTAINING PORTIONS OF THE SDK. REALSEE AND ITS LICENSORS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED CONDITIONS OR WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF ANY THIRD PARTY RIGHT IN RESPECT OF THE ITEMS IN THE SDK OR ANY SERVICES RELATED TO THE SDK.
86
+
41
87
  REALSEE IS UNDER NO OBLIGATION TO PROVIDE ANY SUPPORT UNDER THIS LICENSE AGREEMENT, INCLUDING UPGRADES OR FUTURE VERSIONS OF THE SDK OR ANY PORTIONS THEREOF, TO YOU, END USER OR TO ANY OTHER PARTY.
42
- 7. LIMITATION OF LIABILITY.
43
- TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, IN NO EVENT WILL REALSEE OR ITS LICENSORS BE LIABLE FOR ANY DIRECT, INCIDENTAL, SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES, INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, LOSS OF BUSINESS, REVENUE, OR PROFITS, LOSS OF OPPORTUNITY (WHETHER DIRECT OR INDIRECT), CORRUPTION OR LOSS OF DATA, LOSS OF REPUTATION OR SAVINGS, DOWNTIME, OR DAMAGE TO, LOSS OF OR REPLACEMENT OF DATA OR TRANSACTIONS, COST OF PROCUREMENT OF SUBSTITUTE SERVICES, BUSINESS INTERRUPTION, OR ANY OTHER COMMERCIAL DAMAGES OR LOSSES, ARISING OUT OF OR RELATED TO YOUR USE OR INABILITY TO USE THE SDK (OR ANY PART THEREOF), ANY INTEGRATED PRODUCT, OR ANY THIRD PARTY SOFTWARE, APPLICATIONS, OR SERVICES IN CONJUNCTION WITH THE SDK (OR ANY PART THEREOF), HOWEVER CAUSED, REGARDLESS OF THE THEORY OF LIABILITY (CONTRACT, TORT, OR OTHERWISE) AND EVEN IF REALSEE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL REALSEE’S TOTAL LIABILITY TO YOU FOR ALL DAMAGES EXCEED ONE HUNDRED DOLLARS ($100.00). THE FOREGOING LIMITATIONS WILL APPLY EVEN IF THE ABOVE STATED REMEDY FAILS OF ITS ESSENTIAL PURPOSE. THE LIMITATIONS CONTAINED IN SECTIONS 6 AND THIS SECTION 7 ARE A FUNDAMENTAL PART OF THE BASIS OF REALSEE’S BARGAIN HEREUNDER, AND REALSEE WOULD NOT ENTER INTO THIS AGREEMENT OR PROVIDE YOU WITH ACCESS TO THE SDK ABSENT SUCH LIMITATIONS.
44
- 8. INDEMNIFICATION.
88
+
89
+ 8. LIMITATION OF LIABILITY.
90
+
91
+ TO THE EXTENT NOT PROHIBITED BY APPLICABLE LAW, IN NO EVENT WILL REALSEE OR ITS LICENSORS BE LIABLE FOR ANY DIRECT, INCIDENTAL, SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES, INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, LOSS OF BUSINESS, REVENUE, OR PROFITS, LOSS OF OPPORTUNITY (WHETHER DIRECT OR INDIRECT), CORRUPTION OR LOSS OF DATA, LOSS OF REPUTATION OR SAVINGS, DOWNTIME, OR DAMAGE TO, LOSS OF OR REPLACEMENT OF DATA OR TRANSACTIONS, COST OF PROCUREMENT OF SUBSTITUTE SERVICES, BUSINESS INTERRUPTION, OR ANY OTHER COMMERCIAL DAMAGES OR LOSSES, ARISING OUT OF OR RELATED TO YOUR USE OR INABILITY TO USE THE SDK (OR ANY PART THEREOF), ANY INTEGRATED PRODUCT, OR ANY THIRD PARTY SOFTWARE, APPLICATIONS, OR SERVICES IN CONJUNCTION WITH THE SDK (OR ANY PART THEREOF), HOWEVER CAUSED, REGARDLESS OF THE THEORY OF LIABILITY (CONTRACT, TORT, OR OTHERWISE) AND EVEN IF REALSEE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL REALSEE’S TOTAL LIABILITY TO YOU FOR ALL DAMAGES EXCEED ONE HUNDRED DOLLARS ($100.00). THE FOREGOING LIMITATIONS WILL APPLY EVEN IF THE ABOVE STATED REMEDY FAILS OF ITS ESSENTIAL PURPOSE. THE LIMITATIONS CONTAINED IN SECTION 7 AND THIS SECTION 8 ARE A FUNDAMENTAL PART OF THE BASIS OF REALSEE’S BARGAIN HEREUNDER, AND REALSEE WOULD NOT ENTER INTO THIS AGREEMENT OR PROVIDE YOU WITH ACCESS TO THE SDK ABSENT SUCH LIMITATIONS.
92
+
93
+ 9. INDEMNIFICATION.
94
+
45
95
  To the extent permitted by applicable law, You agree to indemnify, defend and hold harmless Realsee, its affiliates and each of their directors, officers, employees, independent contractors, and agents (each a “Realsee Indemnified Party”) from any and all claims, losses, liabilities, damages, expenses, and costs (including without limitation attorneys’ fees and court costs) incurred by a Realsee Indemnified Party as a result of: (i) Your non-compliance with any terms of this Agreement; (ii) Your use of the SDK (or any part thereof); or (iii) Your use of any Integrated Product, including any claim that Integrated Product infringes the copyright, trademark, trade secret or other intellectual property right of a third party.
46
- 9. ACKNOWLEDGEMENTS.
96
+
97
+ 10. ACKNOWLEDGEMENTS.
98
+
47
99
  Portions of the SDK may utilize or include third party software and other copyrighted material. Acknowledgments, licensing terms, and disclaimers for such material are contained in Documentation for the SDK or may otherwise accompany such material, and Your use of such materials governed by their respective terms. In the event of conflict between the terms of this Agreement and an applicable open source or third party agreement, the open source or third party agreement will control solely with respect to the open source software or third party software. Moreover, You shall not subject any items (including not limited to source code, object code, and any software) included in the SDK to any open source license.
48
- 10. NON-BLOCKING OF REALSEE DEVELOPMENT.
100
+
101
+ 11. NON-BLOCKING OF REALSEE DEVELOPMENT.
102
+
49
103
  You acknowledge that Realsee is currently developing or may develop technologies and products in the future that have or may have design and/or functionality similar to Integrated Product that You may develop based on Your license herein. Nothing in this Agreement shall impair, limit or curtail Realsee's right to continue with its development, maintenance and/or distribution of Realsee's technology or products.
50
- 11. GENERAL.
51
- 11.1 Export Control. You may not use or otherwise export or re-export the SDK (or any part thereof) except as authorized by United States law and the laws of the jurisdiction(s) in which the SDK (or any part thereof) was obtained. In particular, but without limitation, the SDK may not be exported or re-exported (i) into any U.S. embargoed countries or (ii) to anyone on the U.S. Treasury Department's list of Specially Designated Nationals or the U.S. Department of Commerce Denied Person's List or Entity List. By using the SDK (or any part thereof), You represent and warrant that You are not located in any such country or on any such list.
52
- 11.2 Governing Law. This Agreement and the rights of the parties hereunder shall be governed by and construed in accordance with the laws of People’s Republic of China (for purpose of this Agreement, excluding Hong Kong, Taiwan, and Macau), without reference to its conflict of laws principles. Any dispute, controversy or claim arising from or in connection with this Agreement, or the breach, termination or invalidity thereof, shall be submitted to China International Economic and Trade Arbitration Commission (“CIETAC”) for arbitration in Beijing which shall be conducted in accordance with the CIETAC's arbitration rules in effect at the time of applying for arbitration. The arbitral award is final and binding upon both parties.
53
- 11.3 Severability. If any provision of this Agreement is held by a court of competent jurisdiction to be unenforceable for any reason, the remaining provisions hereof will be unaffected and remain in full force and effect.
54
- 11.4. Modifications. Realsee reserves the right, from time to time, with or without notice to You, to make revisions to this Agreement in our sole and absolute discretion. The most current version of this Agreement will supersede all previous versions and shall be made available on the website where the SDK is made available, or by such other means as Realsee may determine in its discretion. Any modified versions of this Agreement hereto shall take effect from the time that it is made available. You shall be responsible for regularly checking for notice of any such modifications. You agree that Your continued use of the SDK constitutes Your agreement to the modified Agreement.
55
- 11.5 Relationship of the Parties. This Agreement will not be construed as creating an agency, partnership, joint venture, fiduciary duty, or any other form of legal association between You and Realsee, and You will not represent to the contrary, whether expressly, by implication, appearance, or otherwise.
56
- 11.6 Entire Agreement; Governing Language. This Agreement constitutes the entire agreement between You and Realsee with respect to the use of the SDK licensed hereunder and supersedes all prior understandings regarding such subject matter. No amendment to or modification of this Agreement will be binding unless in writing and signed by Realsee. You and Realsee hereto confirm that this Agreement and all related documents shall be drafted in English.
104
+
105
+ 12. GENERAL.
106
+
107
+ 12.1 Export Control. You may not use or otherwise export or re-export the SDK (or any part thereof) except as authorized by United States law and the laws of the jurisdiction(s) in which the SDK (or any part thereof) was obtained. In particular, but without limitation, the SDK may not be exported or re-exported (i) into any U.S. embargoed countries or (ii) to anyone on the U.S. Treasury Department's list of Specially Designated Nationals or the U.S. Department of Commerce Denied Person's List or Entity List. By using the SDK (or any part thereof), You represent and warrant that You are not located in any such country or on any such list.
108
+
109
+ 12.2 Governing Law and Dispute Resolution.
110
+
111
+ This Agreement shall be governed by the laws of the Hong Kong Special Administrative Region of the People's Republic of China, without regard to its conflict of laws principles. Any dispute arising out of or in connection with this Agreement, including its existence, validity, interpretation, performance, breach, or termination, shall first be submitted to thirty (30) days of good faith consultation, and if unresolved, to final and binding arbitration administered by the HKIAC in Hong Kong in English under the HKIAC Administered Arbitration Rules in force at the time of submission, with one (1) arbitrator unless the amount in dispute exceeds USD 1,000,000, in which case three (3) arbitrators shall be appointed. Either party may seek interim or injunctive relief from any court of competent jurisdiction notwithstanding the foregoing.
112
+
113
+ 12.3 Severability. If any provision of this Agreement is held by a court of competent jurisdiction to be unenforceable for any reason, the remaining provisions hereof will be unaffected and remain in full force and effect.
114
+
115
+ 12.4 Modifications. Realsee reserves the right, from time to time, with or without notice to You, to make revisions to this Agreement in our sole and absolute discretion. The most current version of this Agreement will supersede all previous versions and shall be made available on the website where the SDK is made available, or by such other means as Realsee may determine in its discretion. Any modified versions of this Agreement hereto shall take effect from the time that it is made available. You shall be responsible for regularly checking for notice of any such modifications. You agree that Your continued use of the SDK constitutes Your agreement to the modified Agreement.
116
+
117
+ 12.5 Relationship of the Parties. This Agreement will not be construed as creating an agency, partnership, joint venture, fiduciary duty, or any other form of legal association between You and Realsee, and You will not represent to the contrary, whether expressly, by implication, appearance, or otherwise.
118
+
119
+ 12.6 Entire Agreement; Governing Language. This Agreement constitutes the entire agreement between You and Realsee with respect to the use of the SDK licensed hereunder and supersedes all prior understandings regarding such subject matter. No amendment to or modification of this Agreement will be binding unless in writing and signed by Realsee. You and Realsee hereto confirm that this Agreement and all related documents shall be drafted in English.
package/dist/index.cjs.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";var pn=Object.defineProperty;var _n=(i,e,t)=>e in i?pn(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>_n(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ut=require("trtc-js-sdk"),ee=require("amazon-chime-sdk-js"),mn=require("@realsee/jsbridge-x"),S=require("react"),fe=Symbol("$$REALSEE_LIVE_EVENT$$");function $e(i){return i[fe]||(i[fe]={}),i[fe]}function Pt(i){const e=i[fe];if(!e)return;Object.keys(e).some(n=>Array.isArray(e[n])&&e[n].length>0)||delete i[fe]}class pe{hasListener(e){const t=$e(this);return t&&t[e]&&t[e].length>0}on(e,t,n){const s=$e(this);return s[e]||(s[e]=[]),s[e].push([t,n||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){const n=$e(this);if(!e){delete this[fe];return}if(n[e]||(n[e]=[]),t===void 0){n[e].length=0,Pt(this);return}const s=n[e].findIndex(r=>r[0]===t);s!==-1&&n[e].splice(s,1),Pt(this)}emit(e,...t){let n=!1;const r=$e(this)[e]||[];for(let o of r.slice()){const[c,l=!1]=o,h=c(...t);l&&this.off(e,c),h===!1&&(n=!0)}return n}}class it extends pe{}var re=(i=>(i.RealseeBrowserRTC="RealseeBrowserRTC",i.RealseeVRWebViewRTC="RealseeVRWebViewRTC",i.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",i))(re||{}),Lt=(i=>(i.RealseeXTRTC="trtc",i.RealseeXChimeRTC="chime",i))(Lt||{});const wn=()=>{const i=new Date,e=i.getFullYear(),t=(i.getMonth()+1).toString().padStart(2,"0"),n=i.getDate().toString().padStart(2,"0"),s=i.getHours().toString().padStart(2,"0"),r=i.getMinutes().toString().padStart(2,"0"),o=i.getSeconds().toString().padStart(2,"0"),c=i.getMilliseconds().toString().padStart(3,"0");return`[${e}-${t}-${n} ${s}:${r}:${o}.${c}]`},Oe=(i,e=[])=>{const t=`Realsee Live ${wn()} <${i}> `;switch(i){case"INFO":console.info(t,...e);break;case"ERROR":console.error(t,...e);break;case"WARN":console.warn(t,...e);break;case"DEBUG":console.debug(t,...e);break;default:console.log(t,...e)}},m={log:(...i)=>Oe("LOG",i),info:(...i)=>Oe("INFO",i),error:(...i)=>Oe("ERROR",i),warn:(...i)=>Oe("WARN",i),debug:(...i)=>Oe("DEBUG",i)};function te(){return((1+Math.random())*65536|0).toString(16).substring(1)}function Le(){return[te(),te(),"4"+te().substring(0,3),te(),te(),te()+te()+te()].join("-").toLowerCase()}class fi extends it{constructor(t){super();a(this,"type",re.RealseeBrowserRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"checkRequirement",()=>ut.checkSystemRequirements());a(this,"$dom",document.createElement("div"));a(this,"_trtc",{client:null,stream:null});a(this,"join",async t=>{var r;this.emit("joinWillStart");const n=await this._getVoiceSign({voiceId:t.voiceId,roomId:t.roomId,userId:t.userId});this._trtc.client=ut.createClient({mode:"rtc",...n,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),(r=this._trtc.client)==null||r.enableAudioVolumeEvaluation(),this._registerRtcEvent();let s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.join({roomId:Number(t.voiceId)}).then(()=>o(!0)).catch(()=>o(!1))});return this.joined=s,s?(this._trtc.stream=ut.createStream({userId:n.userId,audio:!0,video:!1}),s=await new Promise(o=>{var c;(c=this._trtc.stream)==null||c.initialize().then(()=>o(!0)).catch(()=>o(!1))}),s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.publish(this._trtc.stream).then(()=>o(!0)).catch(()=>o(!1))}),this.joined=s,this.joined&&this.emit("joined"),s):!1});a(this,"_handleStreamAdded",t=>{var s;const n=t.stream;m.info("远端流增加:",n.getId()),(s=this._trtc.client)==null||s.subscribe(n)});a(this,"_handleStreamSubscribed",t=>{const n=t.stream;m.info("远端流订阅成功:",n.getId());const r=`rs-rtc-remote_stream-${n.getId()}`,o=document.createElement("div");o.id=r,this.$dom.appendChild(o),typeof this._autoPlayConfirm=="function"?(n.play(r).catch(c=>{m.warn("远端流播放失败(将尝试用户确认恢复)")}),n.on("error",c=>{if(c.getCode()===16451){const h=()=>n.resume();this._autoPlayConfirm({onConfirm:h})}})):n.play(r)});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${Le()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise(async t=>{var n,s;this.joined=!1,this._trtc.stream&&(await((n=this._trtc.client)==null?void 0:n.unpublish(this._trtc.stream)),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),(s=this._trtc.client)==null||s.leave().then(()=>this._trtc.client=null).then(()=>t(!0)).catch(()=>t(!1)),t(!0)})}detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(s=>{m.error(s.message),t(!1)})}catch(s){console.error(s),t(!1)}})}toggleMicro(t){return new Promise(n=>{var s,r,o,c;try{t?((r=(s=this._trtc)==null?void 0:s.stream)==null||r.unmuteAudio(),this.micro=!0):((c=(o=this._trtc)==null?void 0:o.stream)==null||c.muteAudio(),this.micro=!1),n(!0)}catch(l){n(!1)}})}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var t,n,s,r;(t=this._trtc.client)==null||t.on("stream-added",this._handleStreamAdded),(n=this._trtc.client)==null||n.on("stream-subscribed",this._handleStreamSubscribed),(s=this._trtc.client)==null||s.on("audio-volume",o=>this.emit("userVolumes",o.result.map(({userId:c,audioVolume:l})=>({userId:c,audioVolume:l})))),(r=this._trtc.client)==null||r.on("error",o=>this.emit("error",o))}}class Et extends it{constructor(t){super();a(this,"type",re.RealseeBrowserChimeRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"userId","");a(this,"logger");a(this,"deviceController");a(this,"meetingSession");a(this,"audioInput");a(this,"audioOutput");a(this,"deviceChangeObserver",{});a(this,"audioVideoObserver",{});a(this,"audioMixObserver");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"$dom",document.createElement("div"));a(this,"$audio",document.createElement("audio"));a(this,"_initDom",()=>{this.$audio.id=`rs-rtc-${Le()}`,this.$dom.id=`rs-rtc-${Le()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)});a(this,"initObservers",()=>{this.deviceChangeObserver={audioInputsChanged:t=>{this.logger.info(`audioInputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Microphone: ${n.label}`)})},audioOutputsChanged:t=>{this.logger.info(`audioOutputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Speaker: ${n.label}`)})},audioInputMuteStateChanged:(t,n)=>{this.logger.info(`Device ${t.toString()} ${n?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:t=>{this.logger.info(`Stopped with a session status code: ${t.statusCode()}`)},audioVideoDidStartConnecting:t=>{t&&this.logger.info("Attempting to reconnect")}},this.audioMixObserver={meetingAudioStreamBecameActive:t=>{if(this.$audio.paused){const n=()=>this.$audio.play().then(()=>{}).catch(s=>{if(m.error("播放远端流失败!",s),typeof this._autoPlayConfirm=="function"){const r=()=>n();this._autoPlayConfirm({onConfirm:r})}});n()}},meetingAudioStreamBecameInactive:t=>{}}});a(this,"_registerRtcEvent",()=>{var n,s,r,o,c,l;const t=((r=(s=(n=this.meetingSession)==null?void 0:n.configuration)==null?void 0:s.credentials)==null?void 0:r.attendeeId)||"";if(t){const h=new Map,u=()=>{const d=[];return h.forEach((g,_)=>{d.push({userId:g.userId,volume:g.muted||g.signalStrength===0||!g.volume?0:g.volume})}),d};(o=this.meetingSession)==null||o.audioVideo.realtimeSubscribeToAttendeeIdPresence((d,g,_)=>{var w;if(!g){h.delete(d),this.emit("userVolumes",u());return}(w=this.meetingSession)==null||w.audioVideo.realtimeSubscribeToVolumeIndicator(d,(y,b,O,p)=>{new ee.DefaultModality(y).base()===y&&(h.set(y,{userId:_||y,volume:b,muted:O,signalStrength:p}),this.emit("userVolumes",u()))})}),(c=this.meetingSession)==null||c.audioVideo.realtimeSubscribeToVolumeIndicator(t,(d,g,_,w)=>{new ee.DefaultModality(d).base()===d&&w!==null&&w!==1&&this.emit("weakNetwork")}),(l=this.meetingSession)==null||l.audioVideo.realtimeSubscribeToFatalError(d=>this.emit("error",d))}});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initDom(),this.logger=new ee.ConsoleLogger("WebRTCLogger",t.logLevel||ee.LogLevel.INFO),this.deviceController=new ee.DefaultDeviceController(this.logger),this.initObservers()}async join(t){return new Promise(async(n,s)=>{var r,o;this.emit("joinWillStart");try{const{sdkAppId:c,userId:l,roomId:h,userSig:u}=await this._getVoiceSign({...t,roomId:t.roomId||0});this.userId=l;const{attendence:d,vendor_wrapper:g}=JSON.parse(decodeURIComponent(u)),_=new ee.MeetingSessionConfiguration({Meeting:g},{Attendee:{ExternalUserId:d.external_user_id,AttendeeId:d.attendee_id,JoinToken:d.join_token}});this.meetingSession=new ee.DefaultMeetingSession(_,this.logger,this.deviceController),this._registerRtcEvent(),this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver),this.meetingSession.audioVideo.addObserver(this.audioVideoObserver),this.meetingSession.audioVideo.bindAudioElement(this.$audio);const w={audioVideoDidStart:()=>{var y;(y=this.meetingSession)==null||y.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),n(!0)},audioVideoDidStop:()=>{this.joined=!1,n(!1)}};this.meetingSession.audioVideo.addObserver(w),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{const y=await this.meetingSession.audioVideo.listAudioInputDevices();m.info("audioInputDevices ===>",y);const b=((r=y[0])==null?void 0:r.deviceId)||"default";await this.meetingSession.audioVideo.startAudioInput(b)}catch(y){m.error(`设置语音输入设备失败:${y.message}`)}try{const y=await this.meetingSession.audioVideo.listAudioOutputDevices();m.info("audioOutputDevices ===>",y);const b=((o=y[0])==null?void 0:o.deviceId)||"default";await this.meetingSession.audioVideo.chooseAudioOutput(b)}catch(y){m.error(`设置语音输出设备失败:${y.message}`)}this.meetingSession.audioVideo.start()}catch(c){this.emit("error",c),this.logger.error(c.message),n(!1)}})}quit(){return this.joined?new Promise((t,n)=>{var r,o;this.joined=!1;const s={audioVideoDidStop:async c=>{var h;const l=c.statusCode();(h=this.meetingSession)==null||h.deviceController.destroy(),l===ee.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),t(!0)):(this.logger.info(`Stopped with a session status code: ${l}`),t(!0))}};(r=this.meetingSession)==null||r.audioVideo.addObserver(s),(o=this.meetingSession)==null||o.audioVideo.stop()}):Promise.resolve(!0)}async detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(()=>t(!1))}catch(s){this.logger.error(s.message),t(!1)}})}async toggleMicro(t){var s,r,o;t?(s=this.meetingSession)==null||s.audioVideo.realtimeUnmuteLocalAudio():(r=this.meetingSession)==null||r.audioVideo.realtimeMuteLocalAudio();const n=(o=this.meetingSession)==null?void 0:o.audioVideo.realtimeIsLocalAudioMuted();return n!==void 0?t!==n:!1}shock(){throw new Error("Method not implemented.")}}var ae=(i=>(i[i.Success=0]="Success",i[i.Failure=1]="Failure",i[i.ReJoin=2]="ReJoin",i[i.NoMicroPermission=3]="NoMicroPermission",i[i.Unknown=500]="Unknown",i))(ae||{});class gi extends it{constructor({jsBridge:t,getVoiceSign:n}){super();a(this,"type",re.RealseeVRWebViewRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_joinOptions",null);a(this,"options");a(this,"handleUserVolumes",t=>{this.emit("userVolumes",t)});a(this,"handleWeakNetwork",t=>{t&&this.emit("weakNetwork")});a(this,"join",async t=>{this._joinOptions=t,this.emit("joinWillStart");const{sdkAppId:n,userId:s,userSig:r}=await this.getVoiceSignOrEmitError(t);return!n||!s||!r?!1:(this.type=t.type,this.jsBridge.webViewType==="WxMiniProgramWebView"?this.handleWxMiniProgramWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}):this.handleAppWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}))});a(this,"reJoin",async()=>this._joinOptions?this.join({voiceId:this._joinOptions.voiceId,userId:this._joinOptions.userId,roomId:this._joinOptions.roomId,type:this._joinOptions.type}):(this.emitErrorAndSetJoinedFalse("重连失败:未找到加入房间参数。"),!1));a(this,"getVoiceSignOrEmitError",async t=>{try{return await this.options.getVoiceSign(t)}catch(n){return this.emitErrorAndSetJoinedFalse("加入房间失败:rtc 签名请求异常"),{}}});a(this,"handleWxMiniProgramWebViewJoin",async t=>{const[n,s]=await this.joinRoomOrEmitError(t);return s?!1:this.handleJoinResult(n)});a(this,"handleAppWebViewJoin",t=>new Promise(n=>{this.off("inner.rtc.success");const s=r=>{this.off("inner.rtc.fail",s),this.off("inner.rtc.success",s),n(this.handleJoinResult(r))};this.once("inner.rtc.fail",s),this.once("inner.rtc.success",s);try{const{sdkAppId:r,userId:o,userSig:c,voiceId:l}=t;this.jsBridge.callAndListen(`live/join?sdkAppID=${r}&userID=${o}&roomID=${l}&userSig=${c}`,h=>{h===!0?this.emit("inner.rtc.success",h):typeof h=="object"?h.code===ae.Success||h.code===ae.ReJoin?this.emit("inner.rtc.success",h):this.emit("inner.rtc.fail",h):this.emit("inner.rtc.fail",h)})}catch(r){n(this.handleJoinResult({message:r.message,code:ae.Unknown}))}}));a(this,"joinRoomOrEmitError",async({sdkAppId:t,userId:n,voiceId:s,userSig:r})=>{try{return await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${t}&userID=${n}&roomID=${Number(s)}&userSig=${r}`)}catch(o){return this.emitErrorAndSetJoinedFalse("加入房间失败:"+o.message),[null,o]}});a(this,"handleJoinResult",t=>{switch(!0){case t===!0:case(typeof t=="object"&&t.code===ae.Success):case(typeof t=="object"&&t.code===ae.ReJoin):{this.emit("joined"),this.joined=!0;break}default:{this.joined=!1;const n=typeof t=="object"?t.message:"加入房间失败:未知异常。";this.emit("error",new Error(n,{cause:t}))}}return this.joined});a(this,"emitErrorAndSetJoinedFalse",t=>{this.emit("error",new Error(t)),this.joined=!1});a(this,"quit",async()=>{const[t,n]=await this.jsBridge.callAndBackfeed("live/quit");return t===null&&this.emit("error",n||new Error("退出房间失败:未知异常。")),this.joined=!1,!!t});a(this,"detectMicro",async()=>{const[t,n]=await this.jsBridge.detectMicro();return t===null?(this.emit("error",n||new Error("麦克风监测异常!")),!1):t});a(this,"toggleMicro",async t=>{const[n,s]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${t?1:0}`);return n===null?(this.emit("error",s||new Error("麦克风监测异常!")),!1):(this.micro=n,n)});a(this,"shock",()=>{this.jsBridge.shock(1)});this.options={jsBridge:t,getVoiceSign:n},this.jsBridge.webViewType!=="WxMiniProgramWebView"&&this.jsBridge.callAndListen("live/userVolumes",this.handleUserVolumes),this.jsBridge.callAndListen("live/weakNetwork",this.handleWeakNetwork),this.on("inner.rtc.fail",this.handleJoinResult)}get jsBridge(){return this.options.jsBridge}}var $=(i=>(i.SelfUserInfo="SELF_USER_INFO",i.RoomInfo="ROOM_INFO",i.RTCInfo="RTC_INFO",i.UserList="USER_LIST",i.BuiltinMsg="BUILTIN_MSG",i.CustomEvent="CUSTOM_EVENT",i.KeyframeSync="KEYFRAME_SYNC",i.UserKickOut="USER_KICK_OUT",i))($||{}),F=(i=>(i.UserChange="user_change",i.RoomChange="room_change",i))(F||{}),J=(i=>(i.UserMicroStatus="change_micro_status",i.UserMicroStatusSync="sync_micro_status",i.UserPermission="change_permission",i.UserStatus="change_status",i.UserInfo="change_info",i.RoomClose="close",i))(J||{}),ie=(i=>(i.OPEN="OPEN",i.CLOSE="CLOSE",i))(ie||{});function bn(i){try{const e=JSON.parse(i),t={code:e.code,message:e.message,command:e.command,roomCode:e.room_code,appID:e.app_id,requestId:e.request_id,frontRequestId:e.front_request_id,triggerUserID:e.trigger_user_id,data:e.data||{}},n=Object.keys(t).filter(s=>t[s]===void 0);return n.length>0&&console.warn(`推送数据格式异常:${n.join(" ")} 值不存在!`),t}catch(e){return!1}}var V=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSED=3]="CLOSED",i))(V||{}),pi=(i=>(i[i.Normal=0]="Normal",i[i.Removed=1]="Removed",i[i.Replaced=2]="Replaced",i))(pi||{}),_i=(i=>(i.WAIT_ENTER="WAIT_ENTER",i.ONLINE="ONLINE",i.LEAVE="LEAVE",i.KICK_OUT="KICK_OUT",i.BE_REPLACE="BE_REPLACE",i.EXCEPTION="EXCEPTION",i))(_i||{}),qe=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSING=2]="CLOSING",i[i.CLOSED=3]="CLOSED",i))(qe||{}),mi=(i=>(i.Error="Error",i.Close="Close",i.MicroAuth="MicroAuth",i.DuplicateConnect="DuplicateConnect",i.IllegalURL="IllegalURL",i.Unknown="Unknown",i.IllegalArgs="IllegalArgs",i))(mi||{}),wi=(i=>(i.Err_1000="CLOSE_NORMAL",i.Err_1001="CLOSE_GOING_AWAY",i.Err_1002="CLOSE_PROTOCOL_ERROR",i.Err_1003="CLOSE_UNSUPPORTED",i.Err_1006="CLOSE_ABNORMAL",i.Err_1007="Unsupported Data",i.Err_1008="Policy Violation",i.Err_1009="CLOSE_TOO_LARGE",i.Err_unknown="unknown",i))(wi||{});function bi(i){switch(i){case 1e3:return"CLOSE_NORMAL";case 1001:return"CLOSE_GOING_AWAY";case 1002:return"CLOSE_PROTOCOL_ERROR";case 1003:return"CLOSE_UNSUPPORTED";case 1006:return"CLOSE_ABNORMAL";case 1007:return"Unsupported Data";case 1008:return"Policy Violation";case 1009:return"CLOSE_TOO_LARGE"}return"unknown"}function yn(i,e={}){var c;const t=new URL(i,"http://localhost"),n=new URLSearchParams(t.search);for(const[l,h]of Object.entries(e))n.set(l,String(h));const s=n.toString(),r=i.split("#")[0].split("?")[0],o=(c=t.hash)!=null?c:"";return`${r}${s?`?${s}`:""}${o}`}const yi=(()=>{var t;const i=typeof process!="undefined"&&((t=process.versions)==null?void 0:t.node)!=null;return typeof window!="undefined"&&"Deno"in window||i||typeof window=="undefined"})(),_e=yi?"":navigator.userAgent,Sn=/android/i.test(_e),Cn=/iPhone|iPad|iPod|iPadOS/i.test(_e)||!yi&&/Macintosh/.test(_e)&&"ontouchend"in globalThis,Kt=/MicroMessenger/i.test(_e)&&/miniProgram/i.test(_e),Jt=/realsee/i.test(_e);function He(i){return Object.prototype.toString.call(i)==="[object Object]"}function nt(i,e){return i===e?!0:i==null||e==null||typeof i!=typeof e?!1:Number.isNaN(i)&&Number.isNaN(e)}function En(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>nt(i[s],e[s]))}function kn(i,e){return i===e?!0:i==null||e==null||i.length!==e.length?!1:i.every((t,n)=>nt(t,e[n]))}function vn(i,e){return nt(i,e)?!0:He(i)&&He(e)?En(i,e):Array.isArray(i)&&Array.isArray(e)?kn(i,e):!1}function Mt(i,e){return nt(i,e)?!0:He(i)&&He(e)?On(i,e):Array.isArray(i)&&Array.isArray(e)?In(i,e):!1}function In(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t<n;t++)if(!Mt(i[t],e[t]))return!1;return!0}function On(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>Mt(i[s],e[s]))}function Rn(i,e,t={deep:!1}){return t.deep?Mt(i,e):vn(i,e)}class Tn extends pe{constructor(t){super();a(this,"_realWebSocket");a(this,"_url");a(this,"_protocols");a(this,"_readyState",qe.NOTINITIALIZED);a(this,"_options",{timeout:1e4,shouldReconnect:(t,n)=>{if(!(t.code===1008||t.code===1011))return[0,1e3,2e3][n.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1});a(this,"_connectTimeout");a(this,"_attempts",0);a(this,"_reconnects",-1);a(this,"_reconnectWhenOnlineAgain",!1);a(this,"_explicitlyClosed",!1);a(this,"_pendingReconnect");a(this,"_connectivityEventsAttached",!1);a(this,"_heathCheckTimer");a(this,"_healthCheck",async()=>{if(this._realWebSocket){const t=this._realWebSocket.readyState;t!==this._readyState&&(this._readyState=t,this._readyState===qe.CLOSING&&this.emit("closing"))}await new Promise(t=>setTimeout(t,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_clearConnectTimeoutIfNeed",()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0)});a(this,"_clearHeathCheckIfNeed",()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)});a(this,"_startHealthCheck",()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_stopHealthCheck",()=>{this._clearHeathCheckIfNeed()});a(this,"_clearPendingReconnectIfNeeded",()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)});a(this,"_online",t=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(t))});a(this,"_offline",()=>{var t;this._reconnectWhenOnlineAgain=!0,(t=this._realWebSocket)==null||t.close(1e3,"offline")});a(this,"_detachConnectivityEvents",()=>{this._connectivityEventsAttached&&(globalThis==null||globalThis.removeEventListener("online",this._online),globalThis==null||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)});a(this,"_attachConnectivityEvents",()=>{this._connectivityEventsAttached||(globalThis==null||globalThis.addEventListener("online",this._online),globalThis==null||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)});a(this,"send",t=>{var n,s,r;((n=this._realWebSocket)==null?void 0:n.readyState)===((s=this._realWebSocket)==null?void 0:s.OPEN)&&((r=this._realWebSocket)==null||r.send(t))});a(this,"close",(t,n)=>{var s;return typeof t!="number"&&(n=t,t=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),(s=this._realWebSocket)==null?void 0:s.close(t,n)});a(this,"open",t=>{var n,s;t&&(this._url=t),((n=this._realWebSocket)==null?void 0:n.readyState)!==WebSocket.OPEN&&((s=this._realWebSocket)==null?void 0:s.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())});a(this,"_createWebSocket",()=>{var s;const t=typeof this._url=="string"?this._url:(s=this._url)==null?void 0:s.call(this,this);if(!t)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(t,this._protocols||void 0),this._attempts++,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));const n=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))};this._connectTimeout=setTimeout(n,this._options.timeout),this._dispatchWebSocketEvent(),this._options.ignoreConnectivityEvents||this._attachConnectivityEvents()});a(this,"_removeWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.removeEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.removeEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.removeEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.removeEventListener("message",this._webSocketMessageHandler)});a(this,"_dispatchWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.addEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.addEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.addEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.addEventListener("message",this._webSocketMessageHandler)});a(this,"_webSocketOpenHandler",t=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const n=++this._reconnects,s=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(t,{detail:{reconnects:n,attempts:s}}))});a(this,"_webSocketCloseHandler",t=>(this._reconnect(t),this._stopHealthCheck(),this.emit("close",t)));a(this,"_webSocketErrorHandler",t=>this.emit("error",new CustomEvent("error",{detail:{error:t}})));a(this,"_webSocketMessageHandler",t=>this.emit("message",t));t&&this.setOptions(t),this._startHealthCheck()}get attempts(){return this._attempts}setOptions(t){if(!t)return;this._url=t.url,this._protocols=t.protocols;const n=Object.assign(this._options,t.robustOptions||{});if(typeof(n==null?void 0:n.timeout)!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof(n==null?void 0:n.shouldReconnect)!="function")throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=n,this._options.automaticOpen&&this._createWebSocket()}_reconnect(t){var o,c,l;if(!this._options.should1000Reconnect&&t.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&((o=globalThis==null?void 0:globalThis.navigator)==null?void 0:o.onLine)===!1){this._reconnectWhenOnlineAgain=!0;return}const r=(l=(c=this._options).shouldReconnect)==null?void 0:l.call(c,t,this);typeof r=="number"?(m.debug(`RobustWebSocket: Reconnecting in ${r}ms...`),this._pendingReconnect=setTimeout(this._createWebSocket,r)):m.debug("RobustWebSocket: No reconnection will be attempted.")}}class An extends pe{constructor(){super();a(this,"_ws",new Tn({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}}));a(this,"_state",V.NOTINITIALIZED);a(this,"_addWebSocketEventListeners",()=>{this._ws.on("close",this._handleCloseEvent),this._ws.on("closing",this._handleClosingEvent),this._ws.on("connecting",this._handleConnectingEvent),this._ws.on("error",this._handleErrorEvent),this._ws.on("message",this._handleMessageEvent),this._ws.on("open",this._handleOpenEvent),this._ws.on("timeout",this._handleTimeoutEvent)});a(this,"_removeWebSocketEventListeners",()=>{this._ws.off("close",this._handleCloseEvent),this._ws.off("closing",this._handleClosingEvent),this._ws.off("connecting",this._handleConnectingEvent),this._ws.off("error",this._handleErrorEvent),this._ws.off("message",this._handleMessageEvent),this._ws.off("open",this._handleOpenEvent),this._ws.off("timeout",this._handleTimeoutEvent)});a(this,"_handleCloseEvent",t=>{m.info(`live room closed bacause of ${t.code}-${t.reason||bi(t.code)}`),this.state=V.CLOSED});a(this,"_handleClosingEvent",()=>{var t;m.info("live room is closing, onLine:",(t=globalThis==null?void 0:globalThis.navigator)==null?void 0:t.onLine),this.state=V.CLOSED});a(this,"_handleConnectingEvent",t=>{m.info("live room is connecting"),this.state=V.CONNECTING,t.detail.reconnects>0&&this.emit("reconnecting",t.detail)});a(this,"_handleErrorEvent",t=>{m.error("live room error",t),this.state=V.CLOSED});a(this,"_handleMessageEvent",t=>{let n=(()=>{try{return JSON.parse(t.data)}catch(s){return t.data}})();this.emit("message",n)});a(this,"_handleOpenEvent",t=>{m.info("live room open",t.detail),this.state=V.OPEN,t.detail.reconnects>0&&this.emit("reconnected",t.detail)});a(this,"_handleTimeoutEvent",t=>{m.error("live room connect timeout!",t.detail),this.state=V.CLOSED});a(this,"dispose",async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!")));a(this,"open",t=>this._ws.open(t));a(this,"close",(t,n)=>new Promise(s=>{this._ws.once("close",()=>s(!0)),this._ws.close(t,n)}));a(this,"sendMessage",(t="")=>{if(t==null)throw new Error("live message is empty!");if(this.state!==V.OPEN)throw new Error("live has not yet been initialized!");return this._ws.send(JSON.stringify(t))});a(this,"readyClose",()=>{this._ws&&(this._ws._explicitlyClosed=!0)});this._addWebSocketEventListeners()}set state(t){const n=JSON.parse(JSON.stringify(this._state));this._state=t,this.emit("stateChange",this.state,n)}get state(){return this._state}}const G=()=>new Map,kt=i=>{const e=G();return i.forEach((t,n)=>{e.set(n,t)}),e},Ce=(i,e,t)=>{let n=i.get(e);return n===void 0&&i.set(e,n=t()),n},Ln=(i,e)=>{const t=[];for(const[n,s]of i)t.push(e(s,n));return t},Mn=(i,e)=>{for(const[t,n]of i)if(e(n,t))return!0;return!1},me=()=>new Set,dt=i=>i[i.length-1],we=Array.from,Dn=Array.isArray;class Nn{constructor(){this._observers=G()}on(e,t){return Ce(this._observers,e,me).add(t),t}once(e,t){const n=(...s)=>{this.off(e,n),t(...s)};this.on(e,n)}off(e,t){const n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return we((this._observers.get(e)||G()).values()).forEach(n=>n(...t))}destroy(){this._observers=G()}}const he=Math.floor,Pe=Math.abs,Si=(i,e)=>i<e?i:e,Ee=(i,e)=>i>e?i:e,Vn=i=>i!==0?i<0:1/i<0,Gt=1,qt=2,ft=4,gt=8,Un=32,Ci=64,ze=128,jn=31,Ht=63,Te=127,Bn=2147483647,$n=Number.isInteger||(i=>typeof i=="number"&&isFinite(i)&&he(i)===i),xn=i=>i.toLowerCase(),Fn=/^\s*/g,Wn=i=>i.replace(Fn,""),Pn=/([A-Z])/g,zt=(i,e)=>Wn(i.replace(Pn,t=>`${e}${xn(t)}`)),Kn=i=>{const e=unescape(encodeURIComponent(i)),t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.codePointAt(s);return n},Me=typeof TextEncoder!="undefined"?new TextEncoder:null,Jn=i=>Me.encode(i),Gn=Me?Jn:Kn;let pt=typeof TextDecoder=="undefined"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});pt&&pt.decode(new Uint8Array).length===1&&(pt=null);class Be{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Dt=()=>new Be,qn=i=>{let e=i.cpos;for(let t=0;t<i.bufs.length;t++)e+=i.bufs[t].length;return e},Y=i=>{const e=new Uint8Array(qn(i));let t=0;for(let n=0;n<i.bufs.length;n++){const s=i.bufs[n];e.set(s,t),t+=s.length}return e.set(new Uint8Array(i.cbuf.buffer,0,i.cpos),t),e},Hn=(i,e)=>{const t=i.cbuf.length;t-i.cpos<e&&(i.bufs.push(new Uint8Array(i.cbuf.buffer,0,i.cpos)),i.cbuf=new Uint8Array(Ee(t,e)*2),i.cpos=0)},L=(i,e)=>{const t=i.cbuf.length;i.cpos===t&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(t*2),i.cpos=0),i.cbuf[i.cpos++]=e},vt=L,k=(i,e)=>{for(;e>Te;)L(i,ze|Te&e),e=he(e/128);L(i,Te&e)},Nt=(i,e)=>{const t=Vn(e);for(t&&(e=-e),L(i,(e>Ht?ze:0)|(t?Ci:0)|Ht&e),e=he(e/64);e>0;)L(i,(e>Te?ze:0)|Te&e),e=he(e/128)},It=new Uint8Array(3e4),zn=It.length/3,Yn=(i,e)=>{if(e.length<zn){const t=Me.encodeInto(e,It).written||0;k(i,t);for(let n=0;n<t;n++)L(i,It[n])}else x(i,Gn(e))},Xn=(i,e)=>{const t=unescape(encodeURIComponent(e)),n=t.length;k(i,n);for(let s=0;s<n;s++)L(i,t.codePointAt(s))},ge=Me&&Me.encodeInto?Yn:Xn,Vt=(i,e)=>{const t=i.cbuf.length,n=i.cpos,s=Si(t-n,e.length),r=e.length-s;i.cbuf.set(e.subarray(0,s),n),i.cpos+=s,r>0&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(Ee(t*2,r)),i.cbuf.set(e.subarray(s)),i.cpos=r)},x=(i,e)=>{k(i,e.byteLength),Vt(i,e)},Ut=(i,e)=>{Hn(i,e);const t=new DataView(i.cbuf.buffer,i.cpos,e);return i.cpos+=e,t},Zn=(i,e)=>Ut(i,4).setFloat32(0,e,!1),Qn=(i,e)=>Ut(i,8).setFloat64(0,e,!1),es=(i,e)=>Ut(i,8).setBigInt64(0,e,!1),Yt=new DataView(new ArrayBuffer(4)),ts=i=>(Yt.setFloat32(0,i),Yt.getFloat32(0)===i),De=(i,e)=>{switch(typeof e){case"string":L(i,119),ge(i,e);break;case"number":$n(e)&&Pe(e)<=Bn?(L(i,125),Nt(i,e)):ts(e)?(L(i,124),Zn(i,e)):(L(i,123),Qn(i,e));break;case"bigint":L(i,122),es(i,e);break;case"object":if(e===null)L(i,126);else if(Dn(e)){L(i,117),k(i,e.length);for(let t=0;t<e.length;t++)De(i,e[t])}else if(e instanceof Uint8Array)L(i,116),x(i,e);else{L(i,118);const t=Object.keys(e);k(i,t.length);for(let n=0;n<t.length;n++){const s=t[n];ge(i,s),De(i,e[s])}}break;case"boolean":L(i,e?120:121);break;default:L(i,127)}};class Xt extends Be{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&k(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Zt=i=>{i.count>0&&(Nt(i.encoder,i.count===1?i.s:-i.s),i.count>1&&k(i.encoder,i.count-2))};class Ke{constructor(){this.encoder=new Be,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Zt(this),this.count=1,this.s=e)}toUint8Array(){return Zt(this),Y(this.encoder)}}const Qt=i=>{if(i.count>0){const e=i.diff*2+(i.count===1?0:1);Nt(i.encoder,e),i.count>1&&k(i.encoder,i.count-2)}};class _t{constructor(){this.encoder=new Be,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Qt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Qt(this),Y(this.encoder)}}class is{constructor(){this.sarr=[],this.s="",this.lensE=new Ke}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new Be;return this.sarr.push(this.s),this.s="",ge(e,this.sarr.join("")),Vt(e,this.lensE.toUint8Array()),Y(e)}}const be=i=>new Error(i),q=()=>{throw be("Method unimplemented")},ue=()=>{throw be("Unexpected case")},ns=crypto.getRandomValues.bind(crypto),Ei=()=>ns(new Uint32Array(1))[0],ss="10000000-1000-4000-8000"+-1e11,rs=()=>ss.replace(/[018]/g,i=>(i^Ei()&15>>i/4).toString(16)),ei=i=>new Promise(i);Promise.all.bind(Promise);const ti=i=>i===void 0?null:i;class os{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}}let ki=new os,cs=!0;try{typeof localStorage!="undefined"&&localStorage&&(ki=localStorage,cs=!1)}catch(i){}const ls=ki,as=Object.assign,hs=Object.keys,us=(i,e)=>{for(const t in i)e(i[t],t)},ii=i=>hs(i).length,ds=i=>{for(const e in i)return!1;return!0},fs=(i,e)=>{for(const t in i)if(!e(i[t],t))return!1;return!0},gs=(i,e)=>Object.prototype.hasOwnProperty.call(i,e),ps=(i,e)=>i===e||ii(i)===ii(e)&&fs(i,(t,n)=>(t!==void 0||gs(e,n))&&e[n]===t),_s=Object.freeze,vi=i=>{for(const e in i){const t=i[e];(typeof t=="object"||typeof t=="function")&&vi(i[e])}return _s(i)},jt=(i,e,t=0)=>{try{for(;t<i.length;t++)i[t](...e)}finally{t<i.length&&jt(i,e,t+1)}},ms=(i,e)=>e.includes(i),Ne=typeof process!="undefined"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";let K;const ws=()=>{if(K===void 0)if(Ne){K=G();const i=process.argv;let e=null;for(let t=0;t<i.length;t++){const n=i[t];n[0]==="-"?(e!==null&&K.set(e,""),e=n):e!==null&&(K.set(e,n),e=null)}e!==null&&K.set(e,"")}else typeof location=="object"?(K=G(),(location.search||"?").slice(1).split("&").forEach(i=>{if(i.length!==0){const[e,t]=i.split("=");K.set(`--${zt(e,"-")}`,t),K.set(`-${zt(e,"-")}`,t)}})):K=G();return K},Ot=i=>ws().has(i),Ye=i=>ti(Ne?process.env[i.toUpperCase().replaceAll("-","_")]:ls.getItem(i)),Ii=i=>Ot("--"+i)||Ye(i)!==null;Ii("production");const bs=Ne&&ms(process.env.FORCE_COLOR,["true","1","2"]),ys=bs||!Ot("--no-colors")&&!Ii("no-color")&&(!Ne||process.stdout.isTTY)&&(!Ne||Ot("--color")||Ye("COLORTERM")!==null||(Ye("TERM")||"").includes("color"));class Ss{constructor(e,t){this.left=e,this.right=t}}const z=(i,e)=>new Ss(i,e);typeof DOMParser!="undefined"&&new DOMParser;const Cs=i=>Ln(i,(e,t)=>`${t}:${e};`).join(""),Q=Symbol,Oi=Q(),Ri=Q(),Es=Q(),ks=Q(),vs=Q(),Ti=Q(),Is=Q(),Bt=Q(),Os=Q(),Rs=i=>{var s;i.length===1&&((s=i[0])==null?void 0:s.constructor)===Function&&(i=i[0]());const e=[],t=[];let n=0;for(;n<i.length;n++){const r=i[n];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)e.push(r);else if(r.constructor===Object)break}for(n>0&&t.push(e.join(""));n<i.length;n++){const r=i[n];r instanceof Symbol||t.push(r)}return t},Ts={[Oi]:z("font-weight","bold"),[Ri]:z("font-weight","normal"),[Es]:z("color","blue"),[vs]:z("color","green"),[ks]:z("color","grey"),[Ti]:z("color","red"),[Is]:z("color","purple"),[Bt]:z("color","orange"),[Os]:z("color","black")},As=i=>{var o;i.length===1&&((o=i[0])==null?void 0:o.constructor)===Function&&(i=i[0]());const e=[],t=[],n=G();let s=[],r=0;for(;r<i.length;r++){const c=i[r],l=Ts[c];if(l!==void 0)n.set(l.left,l.right);else{if(c===void 0)break;if(c.constructor===String||c.constructor===Number){const h=Cs(n);r>0||h.length>0?(e.push("%c"+c),t.push(h)):e.push(c)}else break}}for(r>0&&(s=t,s.unshift(e.join("")));r<i.length;r++){const c=i[r];c instanceof Symbol||s.push(c)}return s},Ai=ys?As:Rs,Ls=(...i)=>{console.log(...Ai(i)),Li.forEach(e=>e.print(i))},Ms=(...i)=>{console.warn(...Ai(i)),i.unshift(Bt),Li.forEach(e=>e.print(i))},Li=me(),Mi=i=>({[Symbol.iterator](){return this},next:i}),Ds=(i,e)=>Mi(()=>{let t;do t=i.next();while(!t.done&&!e(t.value));return t}),mt=(i,e)=>Mi(()=>{const{done:t,value:n}=i.next();return{done:t,value:t?void 0:e(n)}});class Ns{constructor(e,t){this.clock=e,this.len=t}}class Vs{constructor(){this.clients=new Map}}const Di=(i,e,t)=>e.clients.forEach((n,s)=>{const r=i.doc.store.clients.get(s);for(let o=0;o<n.length;o++){const c=n[o];xi(i,r,c.clock,c.len,t)}}),Us=(i,e)=>{let t=0,n=i.length-1;for(;t<=n;){const s=he((t+n)/2),r=i[s],o=r.clock;if(o<=e){if(e<o+r.len)return s;t=s+1}else n=s-1}return null},Ni=(i,e)=>{const t=i.clients.get(e.client);return t!==void 0&&Us(t,e.clock)!==null},Vi=i=>{i.clients.forEach(e=>{e.sort((s,r)=>s.clock-r.clock);let t,n;for(t=1,n=1;t<e.length;t++){const s=e[n-1],r=e[t];s.clock+s.len>=r.clock?s.len=Ee(s.len,r.clock+r.len-s.clock):(n<t&&(e[n]=r),n++)}e.length=n})},Ui=(i,e,t,n)=>{Ce(i.clients,e,()=>[]).push(new Ns(t,n))},js=(i,e)=>{k(i.restEncoder,e.clients.size),we(e.clients.entries()).sort((t,n)=>n[0]-t[0]).forEach(([t,n])=>{i.resetDsCurVal(),k(i.restEncoder,t);const s=n.length;k(i.restEncoder,s);for(let r=0;r<s;r++){const o=n[r];i.writeDsClock(o.clock),i.writeDsLen(o.len)}})},ji=Ei;class ke extends Nn{constructor({guid:e=rs(),collectionid:t=null,gc:n=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=n,this.gcFilter=s,this.clientID=ji(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new qs,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ei(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});const l=()=>ei(h=>{const u=d=>{(d===void 0||d===!0)&&(this.off("sync",u),h())};this.on("sync",u)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&v(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(we(this.subdocs).map(e=>e.guid))}transact(e,t=null){return v(this,e,t)}get(e,t=N){const n=Ce(this.share,e,()=>{const r=new t;return r._integrate(this,null),r}),s=n.constructor;if(t!==N&&s!==t)if(s===N){const r=new t;r._map=n._map,n._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=n._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=""){return this.get(e,Ae)}getText(e=""){return this.get(e,et)}getMap(e=""){return this.get(e,Qe)}getXmlElement(e=""){return this.get(e,je)}getXmlFragment(e=""){return this.get(e,ye)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,we(this.subdocs).forEach(t=>t.destroy());const e=this._item;if(e!==null){this._item=null;const t=e.content;t.doc=new ke({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,v(e.parent.doc,n=>{const s=t.doc;e.deleted||n.subdocsAdded.add(s),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Bs{constructor(){this.restEncoder=Dt()}toUint8Array(){return Y(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){k(this.restEncoder,e)}writeDsLen(e){k(this.restEncoder,e)}}class $s extends Bs{writeLeftID(e){k(this.restEncoder,e.client),k(this.restEncoder,e.clock)}writeRightID(e){k(this.restEncoder,e.client),k(this.restEncoder,e.clock)}writeClient(e){k(this.restEncoder,e)}writeInfo(e){vt(this.restEncoder,e)}writeString(e){ge(this.restEncoder,e)}writeParentInfo(e){k(this.restEncoder,e?1:0)}writeTypeRef(e){k(this.restEncoder,e)}writeLen(e){k(this.restEncoder,e)}writeAny(e){De(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){ge(this.restEncoder,JSON.stringify(e))}writeKey(e){ge(this.restEncoder,e)}}class xs{constructor(){this.restEncoder=Dt(),this.dsCurrVal=0}toUint8Array(){return Y(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,k(this.restEncoder,t)}writeDsLen(e){e===0&&ue(),k(this.restEncoder,e-1),this.dsCurrVal+=e}}class Fs extends xs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new _t,this.clientEncoder=new Ke,this.leftClockEncoder=new _t,this.rightClockEncoder=new _t,this.infoEncoder=new Xt(vt),this.stringEncoder=new is,this.parentInfoEncoder=new Xt(vt),this.typeRefEncoder=new Ke,this.lenEncoder=new Ke}toUint8Array(){const e=Dt();return k(e,0),x(e,this.keyClockEncoder.toUint8Array()),x(e,this.clientEncoder.toUint8Array()),x(e,this.leftClockEncoder.toUint8Array()),x(e,this.rightClockEncoder.toUint8Array()),x(e,Y(this.infoEncoder)),x(e,this.stringEncoder.toUint8Array()),x(e,Y(this.parentInfoEncoder)),x(e,this.typeRefEncoder.toUint8Array()),x(e,this.lenEncoder.toUint8Array()),Vt(e,Y(this.restEncoder)),Y(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){De(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){De(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const Ws=(i,e,t,n)=>{n=Ee(n,e[0].id.clock);const s=X(e,n);k(i.restEncoder,e.length-s),i.writeClient(t),k(i.restEncoder,n);const r=e[s];r.write(i,n-r.id.clock);for(let o=s+1;o<e.length;o++)e[o].write(i,0)},Ps=(i,e,t)=>{const n=new Map;t.forEach((s,r)=>{B(e,r)>s&&n.set(r,s)}),$t(e).forEach((s,r)=>{t.has(r)||n.set(r,0)}),k(i.restEncoder,n.size),we(n.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{Ws(i,e.clients.get(s),s,r)})},Ks=(i,e)=>Ps(i,e.doc.store,e.beforeState);class Js{constructor(){this.l=[]}}const ni=()=>new Js,si=(i,e)=>i.l.push(e),ri=(i,e)=>{const t=i.l,n=t.length;i.l=t.filter(s=>e!==s),n===i.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Bi=(i,e,t)=>jt(i.l,[e,t]);class Je{constructor(e,t){this.client=e,this.clock=t}}const xe=(i,e)=>i===e||i!==null&&e!==null&&i.client===e.client&&i.clock===e.clock,I=(i,e)=>new Je(i,e),Gs=i=>{for(const[e,t]of i.doc.share.entries())if(t===i)return e;throw ue()},de=(i,e)=>e===void 0?!i.deleted:e.sv.has(i.id.client)&&(e.sv.get(i.id.client)||0)>i.id.clock&&!Ni(e.ds,i.id),Rt=(i,e)=>{const t=Ce(i.meta,Rt,me),n=i.doc.store;t.has(e)||(e.sv.forEach((s,r)=>{s<B(n,r)&&oe(i,I(r,s))}),Di(i,e.ds,s=>{}),t.add(e))};class qs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const $t=i=>{const e=new Map;return i.clients.forEach((t,n)=>{const s=t[t.length-1];e.set(n,s.id.clock+s.length)}),e},B=(i,e)=>{const t=i.clients.get(e);if(t===void 0)return 0;const n=t[t.length-1];return n.id.clock+n.length},$i=(i,e)=>{let t=i.clients.get(e.id.client);if(t===void 0)t=[],i.clients.set(e.id.client,t);else{const n=t[t.length-1];if(n.id.clock+n.length!==e.id.clock)throw ue()}t.push(e)},X=(i,e)=>{let t=0,n=i.length-1,s=i[n],r=s.id.clock;if(r===e)return n;let o=he(e/(r+s.length-1)*n);for(;t<=n;){if(s=i[o],r=s.id.clock,r<=e){if(e<r+s.length)return o;t=o+1}else n=o-1;o=he((t+n)/2)}throw ue()},Hs=(i,e)=>{const t=i.clients.get(e.client);return t[X(t,e.clock)]},wt=Hs,Tt=(i,e,t)=>{const n=X(e,t),s=e[n];return s.id.clock<t&&s instanceof U?(e.splice(n+1,0,rn(i,s,t-s.id.clock)),n+1):n},oe=(i,e)=>{const t=i.doc.store.clients.get(e.client);return t[Tt(i,t,e.clock)]},oi=(i,e,t)=>{const n=e.clients.get(t.client),s=X(n,t.clock),r=n[s];return t.clock!==r.id.clock+r.length-1&&r.constructor!==ne&&n.splice(s+1,0,rn(i,r,t.clock-r.id.clock+1)),r},zs=(i,e,t)=>{const n=i.clients.get(e.id.client);n[X(n,e.id.clock)]=t},xi=(i,e,t,n,s)=>{if(n===0)return;const r=t+n;let o=Tt(i,e,t),c;do c=e[o++],r<c.id.clock+c.length&&Tt(i,e,r),s(c);while(o<e.length&&e[o].id.clock<r)};class Ys{constructor(e,t,n){this.doc=e,this.deleteSet=new Vs,this.beforeState=$t(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ci=(i,e)=>e.deleteSet.clients.size===0&&!Mn(e.afterState,(t,n)=>e.beforeState.get(n)!==t)?!1:(Vi(e.deleteSet),Ks(i,e),js(i,e.deleteSet),!0),li=(i,e,t)=>{const n=e._item;(n===null||n.id.clock<(i.beforeState.get(n.id.client)||0)&&!n.deleted)&&Ce(i.changed,e,me).add(t)},Ge=(i,e)=>{let t=i[e],n=i[e-1],s=e;for(;s>0;t=n,n=i[--s-1]){if(n.deleted===t.deleted&&n.constructor===t.constructor&&n.mergeWith(t)){t instanceof U&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,n);continue}break}const r=e-s;return r&&i.splice(e+1-r,r),r},Xs=(i,e,t)=>{for(const[n,s]of i.clients.entries()){const r=e.clients.get(n);for(let o=s.length-1;o>=0;o--){const c=s[o],l=c.clock+c.len;for(let h=X(r,c.clock),u=r[h];h<r.length&&u.id.clock<l;u=r[++h]){const d=r[h];if(c.clock+c.len<=d.id.clock)break;d instanceof U&&d.deleted&&!d.keep&&t(d)&&d.gc(e,!1)}}}},Zs=(i,e)=>{i.clients.forEach((t,n)=>{const s=e.clients.get(n);for(let r=t.length-1;r>=0;r--){const o=t[r],c=Si(s.length-1,1+X(s,o.clock+o.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=o.clock;h=s[l])l-=1+Ge(s,l)}})},Fi=(i,e)=>{if(e<i.length){const t=i[e],n=t.doc,s=n.store,r=t.deleteSet,o=t._mergeStructs;try{Vi(r),t.afterState=$t(t.doc.store),n.emit("beforeObserverCalls",[t,n]);const c=[];t.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(t,l)})),c.push(()=>{t.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(u=>u.target._item===null||!u.target._item.deleted),l.forEach(u=>{u.currentTarget=h,u._path=null}),l.sort((u,d)=>u.path.length-d.path.length),Bi(h._dEH,l,t))})}),c.push(()=>n.emit("afterTransaction",[t,n])),jt(c,[]),t._needFormattingCleanup&&hr(t)}finally{n.gc&&Xs(r,s,n.gcFilter),Zs(r,s),t.afterState.forEach((u,d)=>{const g=t.beforeState.get(d)||0;if(g!==u){const _=s.clients.get(d),w=Ee(X(_,g),1);for(let y=_.length-1;y>=w;)y-=1+Ge(_,y)}});for(let u=o.length-1;u>=0;u--){const{client:d,clock:g}=o[u].id,_=s.clients.get(d),w=X(_,g);w+1<_.length&&Ge(_,w+1)>1||w>0&&Ge(_,w)}if(!t.local&&t.afterState.get(n.clientID)!==t.beforeState.get(n.clientID)&&(Ls(Bt,Oi,"[yjs] ",Ri,Ti,"Changed the client-id because another client seems to be using it."),n.clientID=ji()),n.emit("afterTransactionCleanup",[t,n]),n._observers.has("update")){const u=new $s;ci(u,t)&&n.emit("update",[u.toUint8Array(),t.origin,n,t])}if(n._observers.has("updateV2")){const u=new Fs;ci(u,t)&&n.emit("updateV2",[u.toUint8Array(),t.origin,n,t])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=t;(c.size>0||h.size>0||l.size>0)&&(c.forEach(u=>{u.clientID=n.clientID,u.collectionid==null&&(u.collectionid=n.collectionid),n.subdocs.add(u)}),h.forEach(u=>n.subdocs.delete(u)),n.emit("subdocs",[{loaded:l,added:c,removed:h},n,t]),h.forEach(u=>u.destroy())),i.length<=e+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,i])):Fi(i,e+1)}}},v=(i,e,t=null,n=!0)=>{const s=i._transactionCleanups;let r=!1,o=null;i._transaction===null&&(r=!0,i._transaction=new Ys(i,t,n),s.push(i._transaction),s.length===1&&i.emit("beforeAllTransactions",[i]),i.emit("beforeTransaction",[i._transaction,i]));try{o=e(i._transaction)}finally{if(r){const c=i._transaction===s[0];i._transaction=null,c&&Fi(s,0)}}return o},ai="You must not compute changes after the event-handler fired.";class st{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Qs(this.currentTarget,this.target))}deletes(e){return Ni(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw be(ai);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(s=>{if(s!==null){const r=t._map.get(s);let o,c;if(this.adds(r)){let l=r.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(r))if(l!==null&&this.deletes(l))o="delete",c=dt(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=dt(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(r))o="delete",c=dt(r.content.getContent());else return;e.set(s,{action:o,oldValue:c})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw be(ai);const t=this.target,n=me(),s=me(),r=[];if(e={added:n,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(t).has(null)){let c=null;const l=()=>{c&&r.push(c)};for(let h=t._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),n.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=e}return e}}const Qs=(i,e)=>{const t=[];for(;e._item!==null&&e!==i;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let n=0,s=e._item.parent._start;for(;s!==e._item&&s!==null;)!s.deleted&&s.countable&&(n+=s.length),s=s.right;t.unshift(n)}e=e._item.parent}return t},j=()=>{Ms("Invalid access: Add Yjs type to a document before reading data.")},Wi=80;let xt=0;class er{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=xt++}}const tr=i=>{i.timestamp=xt++},Pi=(i,e,t)=>{i.p.marker=!1,i.p=e,e.marker=!0,i.index=t,i.timestamp=xt++},ir=(i,e,t)=>{if(i.length>=Wi){const n=i.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return Pi(n,e,t),n}else{const n=new er(e,t);return i.push(n),n}},rt=(i,e)=>{if(i._start===null||e===0||i._searchMarker===null)return null;const t=i._searchMarker.length===0?null:i._searchMarker.reduce((r,o)=>Pe(e-r.index)<Pe(e-o.index)?r:o);let n=i._start,s=0;for(t!==null&&(n=t.p,s=t.index,tr(t));n.right!==null&&s<e;){if(!n.deleted&&n.countable){if(e<s+n.length)break;s+=n.length}n=n.right}for(;n.left!==null&&s>e;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);return t!==null&&Pe(t.index-s)<n.parent.length/Wi?(Pi(t,n,s),t):ir(i._searchMarker,n,s)},Ve=(i,e,t)=>{for(let n=i.length-1;n>=0;n--){const s=i[n];if(t>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){i.splice(n,1);continue}s.p=r,r.marker=!0}(e<s.index||t>0&&e===s.index)&&(s.index=Ee(e,s.index+t))}},ot=(i,e,t)=>{const n=i,s=e.changedParentTypes;for(;Ce(s,i,()=>[]).push(t),i._item!==null;)i=i._item.parent;Bi(n._eH,t,e)};class N{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ni(),this._dEH=ni(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw q()}clone(){throw q()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){si(this._eH,e)}observeDeep(e){si(this._dEH,e)}unobserve(e){ri(this._eH,e)}unobserveDeep(e){ri(this._dEH,e)}toJSON(){}}const Ki=(i,e,t)=>{var o;(o=i.doc)!=null||j(),e<0&&(e=i._length+e),t<0&&(t=i._length+t);let n=t-e;const s=[];let r=i._start;for(;r!==null&&n>0;){if(r.countable&&!r.deleted){const c=r.content.getContent();if(c.length<=e)e-=c.length;else{for(let l=e;l<c.length&&n>0;l++)s.push(c[l]),n--;e=0}}r=r.right}return s},Ji=i=>{var n;(n=i.doc)!=null||j();const e=[];let t=i._start;for(;t!==null;){if(t.countable&&!t.deleted){const s=t.content.getContent();for(let r=0;r<s.length;r++)e.push(s[r])}t=t.right}return e},Ue=(i,e)=>{var s;let t=0,n=i._start;for((s=i.doc)!=null||j();n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let o=0;o<r.length;o++)e(r[o],t++,i)}n=n.right}},Gi=(i,e)=>{const t=[];return Ue(i,(n,s)=>{t.push(e(n,s,i))}),t},nr=i=>{let e=i._start,t=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),n=0,e=e.right}const s=t[n++];return t.length<=n&&(t=null),{done:!1,value:s}}}},qi=(i,e)=>{var s;(s=i.doc)!=null||j();const t=rt(i,e);let n=i._start;for(t!==null&&(n=t.p,e-=t.index);n!==null;n=n.right)if(!n.deleted&&n.countable){if(e<n.length)return n.content.getContent()[e];e-=n.length}},Xe=(i,e,t,n)=>{let s=t;const r=i.doc,o=r.clientID,c=r.store,l=t===null?e._start:t.right;let h=[];const u=()=>{h.length>0&&(s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new Se(h)),s.integrate(i,0),h=[])};n.forEach(d=>{if(d===null)h.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(d);break;default:switch(u(),d.constructor){case Uint8Array:case ArrayBuffer:s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ct(new Uint8Array(d))),s.integrate(i,0);break;case ke:s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new lt(d)),s.integrate(i,0);break;default:if(d instanceof N)s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ce(d)),s.integrate(i,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Hi=()=>be("Length exceeded!"),zi=(i,e,t,n)=>{if(t>e._length)throw Hi();if(t===0)return e._searchMarker&&Ve(e._searchMarker,t,n.length),Xe(i,e,null,n);const s=t,r=rt(e,t);let o=e._start;for(r!==null&&(o=r.p,t-=r.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t<o.length&&oe(i,I(o.id.client,o.id.clock+t));break}t-=o.length}return e._searchMarker&&Ve(e._searchMarker,s,n.length),Xe(i,e,o,n)},sr=(i,e,t)=>{let s=(e._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;return Xe(i,e,s,t)},Yi=(i,e,t,n)=>{if(n===0)return;const s=t,r=n,o=rt(e,t);let c=e._start;for(o!==null&&(c=o.p,t-=o.index);c!==null&&t>0;c=c.right)!c.deleted&&c.countable&&(t<c.length&&oe(i,I(c.id.client,c.id.clock+t)),t-=c.length);for(;n>0&&c!==null;)c.deleted||(n<c.length&&oe(i,I(c.id.client,c.id.clock+n)),c.delete(i),n-=c.length),c=c.right;if(n>0)throw Hi();e._searchMarker&&Ve(e._searchMarker,s,-r+n)},Ze=(i,e,t)=>{const n=e._map.get(t);n!==void 0&&n.delete(i)},Ft=(i,e,t,n)=>{const s=e._map.get(t)||null,r=i.doc,o=r.clientID;let c;if(n==null)c=new Se([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c=new Se([n]);break;case Uint8Array:c=new ct(n);break;case ke:c=new lt(n);break;default:if(n instanceof N)c=new ce(n);else throw new Error("Unexpected content type")}new U(I(o,B(r.store,o)),s,s&&s.lastId,null,null,e,t,c).integrate(i,0)},Wt=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Xi=i=>{var t;const e={};return(t=i.doc)!=null||j(),i._map.forEach((n,s)=>{n.deleted||(e[s]=n.content.getContent()[n.length-1])}),e},Zi=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted},rr=(i,e)=>{const t={};return i._map.forEach((n,s)=>{let r=n;for(;r!==null&&(!e.sv.has(r.id.client)||r.id.clock>=(e.sv.get(r.id.client)||0));)r=r.left;r!==null&&de(r,e)&&(t[s]=r.content.getContent()[r.length-1])}),t},Fe=i=>{var e;return(e=i.doc)!=null||j(),Ds(i._map.entries(),t=>!t[1].deleted)};class or extends st{}class Ae extends N{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new Ae;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ae}clone(){const e=new Ae;return e.insert(0,this.toArray().map(t=>t instanceof N?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._length}_callObserver(e,t){super._callObserver(e,t),ot(this,e,new or(this,e))}insert(e,t){this.doc!==null?v(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?v(this.doc,t=>{sr(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?v(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return qi(this,e)}toArray(){return Ji(this)}slice(e=0,t=this.length){return Ki(this,e,t)}toJSON(){return this.map(e=>e instanceof N?e.toJSON():e)}map(e){return Gi(this,e)}forEach(e){Ue(this,e)}[Symbol.iterator](){return nr(this)}_write(e){e.writeTypeRef(_r)}}class cr extends st{constructor(e,t,n){super(e,t),this.keysChanged=n}}class Qe extends N{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((n,s)=>{this.set(s,n)}),this._prelimContent=null}_copy(){return new Qe}clone(){const e=new Qe;return this.forEach((t,n)=>{e.set(n,t instanceof N?t.clone():t)}),e}_callObserver(e,t){ot(this,e,new cr(this,e,t))}toJSON(){var t;(t=this.doc)!=null||j();const e={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[s]=r instanceof N?r.toJSON():r}}),e}get size(){return[...Fe(this)].length}keys(){return mt(Fe(this),e=>e[0])}values(){return mt(Fe(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return mt(Fe(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){var t;(t=this.doc)!=null||j(),this._map.forEach((n,s)=>{n.deleted||e(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Wt(this,e)}has(e){return Zi(this,e)}clear(){this.doc!==null?v(this.doc,e=>{this.forEach(function(t,n,s){Ze(e,s,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(mr)}}const se=(i,e)=>i===e||typeof i=="object"&&typeof e=="object"&&i&&e&&ps(i,e);class At{constructor(e,t,n,s){this.left=e,this.right=t,this.index=n,this.currentAttributes=s}forward(){switch(this.right===null&&ue(),this.right.content.constructor){case M:this.right.deleted||ve(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const hi=(i,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case M:e.right.deleted||ve(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&oe(i,I(e.right.id.client,e.right.id.clock+t)),e.index+=e.right.length,t-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},We=(i,e,t,n)=>{const s=new Map,r=n?rt(e,t):null;if(r){const o=new At(r.p.left,r.p,r.index,s);return hi(i,o,t-r.index)}else{const o=new At(null,e._start,0,s);return hi(i,o,t)}},Qi=(i,e,t,n)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===M&&se(n.get(t.right.content.key),t.right.content.value));)t.right.deleted||n.delete(t.right.content.key),t.forward();const s=i.doc,r=s.clientID;n.forEach((o,c)=>{const l=t.left,h=t.right,u=new U(I(r,B(s.store,r)),l,l&&l.lastId,h,h&&h.id,e,null,new M(c,o));u.integrate(i,0),t.right=u,t.forward()})},ve=(i,e)=>{const{key:t,value:n}=e;n===null?i.delete(t):i.set(t,n)},en=(i,e)=>{var t;for(;i.right!==null;){if(!(i.right.deleted||i.right.content.constructor===M&&se((t=e[i.right.content.key])!=null?t:null,i.right.content.value)))break;i.forward()}},tn=(i,e,t,n)=>{var c;const s=i.doc,r=s.clientID,o=new Map;for(const l in n){const h=n[l],u=(c=t.currentAttributes.get(l))!=null?c:null;if(!se(u,h)){o.set(l,u);const{left:d,right:g}=t;t.right=new U(I(r,B(s.store,r)),d,d&&d.lastId,g,g&&g.id,e,null,new M(l,h)),t.right.integrate(i,0),t.forward()}}return o},bt=(i,e,t,n,s)=>{t.currentAttributes.forEach((g,_)=>{s[_]===void 0&&(s[_]=null)});const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s),l=n.constructor===String?new Z(n):n instanceof N?new ce(n):new Ie(n);let{left:h,right:u,index:d}=t;e._searchMarker&&Ve(e._searchMarker,t.index,l.getLength()),u=new U(I(o,B(r.store,o)),h,h&&h.lastId,u,u&&u.id,e,null,l),u.integrate(i,0),t.right=u,t.index=d,t.forward(),Qi(i,e,t,c)},ui=(i,e,t,n,s)=>{const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s);e:for(;t.right!==null&&(n>0||c.size>0&&(t.right.deleted||t.right.content.constructor===M));){if(!t.right.deleted)switch(t.right.content.constructor){case M:{const{key:l,value:h}=t.right.content,u=s[l];if(u!==void 0){if(se(u,h))c.delete(l);else{if(n===0)break e;c.set(l,h)}t.right.delete(i)}else t.currentAttributes.set(l,h);break}default:n<t.right.length&&oe(i,I(t.right.id.client,t.right.id.clock+n)),n-=t.right.length;break}t.forward()}if(n>0){let l="";for(;n>0;n--)l+=`
2
2
  `;t.right=new U(I(o,B(r.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Z(l)),t.right.integrate(i,0),t.forward()}Qi(i,e,t,c)},nn=(i,e,t,n,s)=>{var h,u;let r=e;const o=G();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===M){const d=r.content;o.set(d.key,d)}r=r.right}let c=0,l=!1;for(;e!==r;){if(t===e&&(l=!0),!e.deleted){const d=e.content;switch(d.constructor){case M:{const{key:g,value:_}=d,w=(h=n.get(g))!=null?h:null;(o.get(g)!==d||w===_)&&(e.delete(i),c++,!l&&((u=s.get(g))!=null?u:null)===_&&w!==_&&(w===null?s.delete(g):s.set(g,w))),!l&&!e.deleted&&ve(s,d);break}}}e=e.right}return c},lr=(i,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===M){const n=e.content.key;t.has(n)?e.delete(i):t.add(n)}e=e.left}},ar=i=>{let e=0;return v(i.doc,t=>{let n=i._start,s=i._start,r=G();const o=kt(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case M:ve(o,s.content);break;default:e+=nn(t,n,s,r,o),r=kt(o),n=s;break}s=s.right}}),e},hr=i=>{const e=new Set,t=i.doc;for(const[n,s]of i.afterState.entries()){const r=i.beforeState.get(n)||0;s!==r&&xi(i,t.store.clients.get(n),r,s,o=>{!o.deleted&&o.content.constructor===M&&o.constructor!==ne&&e.add(o.parent)})}v(t,n=>{Di(i,i.deleteSet,s=>{if(s instanceof ne||!s.parent._hasFormatting||e.has(s.parent))return;const r=s.parent;s.content.constructor===M?e.add(r):lr(n,s)});for(const s of e)ar(s)})},di=(i,e,t)=>{const n=t,s=kt(e.currentAttributes),r=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case ce:case Ie:case Z:t<e.right.length&&oe(i,I(e.right.id.client,e.right.id.clock+t)),t-=e.right.length,e.right.delete(i);break}e.forward()}r&&nn(i,r,e.right,s,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Ve(o._searchMarker,e.index,-n+t),e};class ur extends st{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,t=[];v(e,n=>{var _,w,y;const s=new Map,r=new Map;let o=this.target._start,c=null;const l={};let h="",u=0,d=0;const g=()=>{if(c!==null){let b=null;switch(c){case"delete":d>0&&(b={delete:d}),d=0;break;case"insert":(typeof h=="object"||h.length>0)&&(b={insert:h},s.size>0&&(b.attributes={},s.forEach((O,p)=>{O!==null&&(b.attributes[p]=O)}))),h="";break;case"retain":u>0&&(b={retain:u},ds(l)||(b.attributes=as({},l))),u=0;break}b&&t.push(b),c=null}};for(;o!==null;){switch(o.content.constructor){case ce:case Ie:this.adds(o)?this.deletes(o)||(g(),c="insert",h=o.content.getContent()[0],g()):this.deletes(o)?(c!=="delete"&&(g(),c="delete"),d+=1):o.deleted||(c!=="retain"&&(g(),c="retain"),u+=1);break;case Z:this.adds(o)?this.deletes(o)||(c!=="insert"&&(g(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(g(),c="delete"),d+=o.length):o.deleted||(c!=="retain"&&(g(),c="retain"),u+=o.length);break;case M:{const{key:b,value:O}=o.content;if(this.adds(o)){if(!this.deletes(o)){const p=(_=s.get(b))!=null?_:null;se(p,O)?O!==null&&o.delete(n):(c==="retain"&&g(),se(O,(w=r.get(b))!=null?w:null)?delete l[b]:l[b]=O)}}else if(this.deletes(o)){r.set(b,O);const p=(y=s.get(b))!=null?y:null;se(p,O)||(c==="retain"&&g(),l[b]=p)}else if(!o.deleted){r.set(b,O);const p=l[b];p!==void 0&&(se(p,O)?p!==null&&o.delete(n):(c==="retain"&&g(),O===null?delete l[b]:l[b]=O))}o.deleted||(c==="insert"&&g(),ve(s,o.content));break}}o=o.right}for(g();t.length>0;){const b=t[t.length-1];if(b.retain!==void 0&&b.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}}class et extends N{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){var e;return(e=this.doc)!=null||j(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new et}clone(){const e=new et;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const n=new ur(this,e,t);ot(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){var n;(n=this.doc)!=null||j();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Z&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?v(this.doc,n=>{const s=new At(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const o=e[r];if(o.insert!==void 0){const c=!t&&typeof o.insert=="string"&&r===e.length-1&&s.right===null&&o.insert.slice(-1)===`
3
- `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&bt(n,this,s,c,o.attributes||{})}else o.retain!==void 0?ui(n,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&di(n,s,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){var d;(d=this.doc)!=null||j();const s=[],r=new Map,o=this.doc;let c="",l=this._start;function h(){if(c.length>0){const g={};let _=!1;r.forEach((y,b)=>{_=!0,g[b]=y});const w={insert:c};_&&(w.attributes=g),s.push(w),c=""}}const u=()=>{for(;l!==null;){if(de(l,e)||t!==void 0&&de(l,t))switch(l.content.constructor){case Z:{const g=r.get("ychange");e!==void 0&&!de(l,e)?(g===void 0||g.user!==l.id.client||g.type!=="removed")&&(h(),r.set("ychange",n?n("removed",l.id):{type:"removed"})):t!==void 0&&!de(l,t)?(g===void 0||g.user!==l.id.client||g.type!=="added")&&(h(),r.set("ychange",n?n("added",l.id):{type:"added"})):g!==void 0&&(h(),r.delete("ychange")),c+=l.content.str;break}case ce:case Ie:{h();const g={insert:l.content.getContent()[0]};if(r.size>0){const _={};g.attributes=_,r.forEach((w,y)=>{_[y]=w})}s.push(g);break}case M:de(l,e)&&(h(),ve(r,l.content));break}l=l.right}h()};return e||t?v(o,g=>{e&&Rt(g,e),t&&Rt(g,t),u()},"cleanup"):u(),s}insert(e,t,n){if(t.length<=0)return;const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!n);n||(n={},o.currentAttributes.forEach((c,l)=>{n[l]=c})),bt(r,this,o,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!n);bt(r,this,o,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(t===0)return;const n=this.doc;n!==null?v(n,s=>{di(s,We(s,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(t===0)return;const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!1);o.right!==null&&ui(r,this,o,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Wt(this,e)}getAttributes(){return Xi(this)}_write(e){e.writeTypeRef(wr)}}class yt{constructor(e,t=()=>!0){var n;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(n=e.doc)!=null||j()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===je||t.constructor===ye)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class ye extends N{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ye}clone(){const e=new ye;return e.insert(0,this.toArray().map(t=>t instanceof N?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new yt(this,e)}querySelector(e){e=e.toUpperCase();const n=new yt(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return n.done?null:n.value}querySelectorAll(e){return e=e.toUpperCase(),we(new yt(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){ot(this,e,new dr(this,t,e))}toString(){return Gi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ue(this,r=>{s.insertBefore(r.toDOM(e,t,n),null)}),s}insert(e,t){this.doc!==null?v(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)v(this.doc,n=>{const s=e&&e instanceof N?e._item:e;Xe(n,this,s,t)});else{const n=this._prelimContent,s=e===null?0:n.findIndex(r=>r===e)+1;if(s===0&&e!==null)throw be("Reference item not found");n.splice(s,0,...t)}}delete(e,t=1){this.doc!==null?v(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ji(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return qi(this,e)}slice(e=0,t=this.length){return Ki(this,e,t)}forEach(e){Ue(this,e)}_write(e){e.writeTypeRef(yr)}}class je extends ye{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new je(this.nodeName)}clone(){const e=new je(this.nodeName),t=this.getAttributes();return us(t,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof N?n.clone():n)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const c in e)n.push(c);n.sort();const s=n.length;for(let c=0;c<s;c++){const l=n[c];t.push(l+'="'+e[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Wt(this,e)}hasAttribute(e){return Zi(this,e)}getAttributes(e){return e?rr(this,e):Xi(this)}toDOM(e=document,t={},n){const s=e.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const c=r[o];typeof c=="string"&&s.setAttribute(o,c)}return Ue(this,o=>{s.appendChild(o.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(br),e.writeKey(this.nodeName)}}class dr extends st{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class sn{constructor(e,t){this.id=e,this.length=t}get deleted(){throw q()}mergeWith(e){return!1}write(e,t,n){throw q()}integrate(e,t){throw q()}}const fr=0;class ne extends sn{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),$i(e.doc.store,this)}write(e,t){e.writeInfo(fr),e.writeLen(this.length-t)}getMissing(e,t){return null}}class ct{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ct(this.content)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class tt{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new tt(this.len)}splice(e){const t=new tt(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Ui(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const gr=(i,e)=>new ke({guid:i,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class lt{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new lt(gr(this.doc.guid,this.opts))}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class Ie{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ie(this.embed)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class M{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new M(this.key,this.value)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const pr=Ye("node_env")==="development";class Se{constructor(e){this.arr=e,pr&&vi(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Se(this.arr)}splice(e){const t=new Se(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let s=t;s<n;s++){const r=this.arr[s];e.writeAny(r)}}getRef(){return 8}}class Z{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Z(this.str)}splice(e){const t=new Z(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}}const _r=0,mr=1,wr=2,br=3,yr=4;class ce{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ce(this.type._copy())}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const rn=(i,e,t)=>{const{client:n,clock:s}=e.id,r=new U(I(n,s+t),e,I(n,s+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),e.redone!==null&&(r.redone=I(e.redone.client,e.redone.clock+t)),e.right=r,r.right!==null&&(r.right.left=r),i._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),e.length=t,r};class U extends sn{constructor(e,t,n,s,r,o,c,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?qt:0}set marker(e){(this.info&gt)>0!==e&&(this.info^=gt)}get marker(){return(this.info&gt)>0}get keep(){return(this.info&Gt)>0}set keep(e){this.keep!==e&&(this.info^=Gt)}get countable(){return(this.info&qt)>0}get deleted(){return(this.info&ft)>0}set deleted(e){this.deleted!==e&&(this.info^=ft)}markDeleted(){this.info|=ft}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Je&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=oi(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=oe(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ne||this.right&&this.right.constructor===ne)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===U&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===U&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Je){const n=wt(t,this.parent);n.constructor===ne?this.parent=null:this.parent=n.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=oi(e,e.doc.store,I(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),xe(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,r.clear();else if(xe(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(wt(e.doc.store,s.origin)))r.has(wt(e.doc.store,s.origin))||(n=s,r.clear());else break;s=s.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),$i(e.doc.store,this),this.content.integrate(e,this),li(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new ne(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:I(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&xe(e.origin,this.lastId)&&this.right===e&&xe(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Ui(e.deleteSet,this.id.client,this.id.clock,this.length),li(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw ue();this.content.gc(e),t?zs(e,this,new ne(this.id,this.length)):this.content=new tt(this.length)}write(e,t){const n=t>0?I(this.id.client,this.id.clock+t-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&jn|(n===null?0:ze)|(s===null?0:Ci)|(r===null?0:Un);if(e.writeInfo(o),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const h=Gs(c);e.writeParentInfo(!0),e.writeString(h)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===Je?(e.writeParentInfo(!1),e.writeLeftID(c)):ue();r!==null&&e.writeString(r)}this.content.write(e,t)}}const on=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:{},cn="__ $YJS$ __";on[cn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");on[cn]=!0;const Re=i=>Promise.reject(new Error("unimplemented method GetVoiceSign")),St=(i,e={},t=[])=>({command:i,front_request_id:Le(),data:{...e,to_user_ids:Array.isArray(t)?t:[t]}}),ln=()=>{var i,e;window!=null&&window.__Realsee_Live__&&((e=(i=window==null?void 0:window.__Realsee_Live__)==null?void 0:i.dispose)==null||e.call(i),window.__Realsee_Live__=null)};class an extends pe{constructor(t){super();a(this,"_options",{});a(this,"keyframes",new pe);a(this,"_yDoc");a(this,"_buildInData");a(this,"_initializeKeyframesObservers",()=>{this._yDoc.getMap("keyframes").observe(this._handleKeyframesChange)});a(this,"_handleKeyframesChange",t=>{var o;const{transaction:n,target:s,changes:r}=t;if(s===this._buildInData.keyframes)if(n.origin.triggerUserId===((o=this.selfInfo)==null?void 0:o.id)){const c=St($.KeyframeSync,this.snapshot,void 0);try{this._controller.sendMessage(c)}catch(l){m.error("Failed to send keyframe sync message:",l)}}else r.keys.forEach((c,l)=>{const h=c.oldValue,u=this.getFramesByKey(l),d=n.origin.frontRequestId;this.keyframes.emit(l,u,h,d)}),r.keys.size!==0&&this.emit("keyframes",this.snapshot,n.origin.frontRequestId)});a(this,"getFramesByKey",t=>this.snapshot[t]);a(this,"sendKeyframe",(t,n)=>{var s;return this.state!==V.OPEN?(m.warn("Attempted to send keyframe while connection is not open"),!1):(this._yDoc.transact(()=>{this._buildInData.keyframes.set(t,n)},{triggerUserId:(s=this.selfInfo)==null?void 0:s.id,frontRequestId:""}),!0)});a(this,"_controller",new An);a(this,"_initializeOptions",t=>{var n;this._options=Object.assign({initialMicroStatus:ie.OPEN},t),this._options.jsBridge=this._initializeJsBridge(t),this._options.getVoiceSign=(n=t.getVoiceSign)!=null?n:Re,this._options.autoPlayConfirm=t.autoPlayConfirm,this._options.rtc=this._initializeRTC(t)});a(this,"_initializeJsBridge",t=>{if(t.jsBridge)return t.jsBridge;if(t.useBuiltInJsBridge)return new mn});a(this,"_initializeRTC",t=>{if(t.rtc)return t.rtc;if(t.rtcType)return this._createBuiltInRTC(t);if(t.useBuiltInRTC)return this._createDefaultRTC(t)});a(this,"_createBuiltInRTC",t=>{var n;if(!t.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}switch(t.rtcType){case re.RealseeVRWebViewRTC:return this._createVRWebViewRTC();case re.RealseeBrowserChimeRTC:return new Et({getVoiceSign:(n=this._options.getVoiceSign)!=null?n:Re,logLevel:t.__debug__?0:1});case re.RealseeBrowserRTC:return this._createBrowserRTC();default:m.error("unknown built-in RTC type");return}});a(this,"_createVRWebViewRTC",()=>{var t;if(this._options.jsBridge)return new gi({jsBridge:this._options.jsBridge,getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Re});m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances")});a(this,"_createBrowserRTC",()=>{var t;if(!this._options.autoPlayConfirm){m.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances");return}return new fi({getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Re,autoPlayConfirm:this._options.autoPlayConfirm})});a(this,"_createDefaultRTC",t=>{var s;const n=(s=this._options.getVoiceSign)!=null?s:Re;return!this._options.jsBridge||!Jt&&!Kt?t.builtInRTCType===Lt.RealseeXChimeRTC?new Et({getVoiceSign:n}):this._createBrowserRTC():Jt&&(Sn||Cn)||Kt?this._createVRWebViewRTC():this._createBrowserRTC()});a(this,"_autoConnect",()=>{this._options.url&&this._options.getTicket&&this.connect()});a(this,"_debugSetup",()=>{this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})});a(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});a(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});a(this,"_handleStateChange",(t,n)=>{m.info(`State changed from ${n} to ${t}`),this.emit("stateChange",t,n)});a(this,"_handleMessage",async t=>{var n,s,r,o,c,l,h,u,d;if(m.debug("Received message:",t),typeof t=="object"){const{command:g,data:_={},frontRequestId:w,code:y,message:b,triggerUserId:O}=t;if(y==="SUCCESS")switch(g){case $.SelfUserInfo:{const p=_;Rn(this.selfInfo,p,{deep:!0})||(this._buildInData.selfInfo=p,this.emit("selfInfoUpdate",this._buildInData.selfInfo,w));break}case $.RoomInfo:{const p=_;this._buildInData.roomInfo=Object.assign({},p);const W=p.last_frame||{};this._yDoc.transact(()=>{for(const f in W)this._buildInData.keyframes.set(f,W[f])},{triggerUserId:"readyKeyframeSync",frontRequestId:w}),this.emit("readyKeyframeSync",p.last_frame||{});break}case $.RTCInfo:{m.info("RTC info updated:",_);const{voice_id:p,type:W}=_;if(this._buildInData.rtcInfo={voiceId:p,type:W},(n=this.$RTC)!=null&&n.joined)m.warn("已加入语音房间,无需重复加入!");else if(await((o=this.$RTC)==null?void 0:o.join({voiceId:p,userId:((s=this.selfInfo)==null?void 0:s.id)||"",roomId:(r=this.roomInfo)==null?void 0:r.info.room_code,type:W}))){const C=(c=this._options.initialMicroStatus)!=null?c:ie.OPEN;await this.toggleMicro(C===ie.OPEN)}else m.error("加入语音房间失败");break}case $.UserList:{const p=_;this._buildInData.userList=p,this.emit("userListUpdate",this.userList,w);break}case $.CustomEvent:{const p=_;this.emit("broadcast",p,w);break}case $.KeyframeSync:{const p=_;if(O===((l=this.selfInfo)==null?void 0:l.id))return;this._yDoc.transact(()=>{for(const W in p)this._buildInData.keyframes.set(W,p[W])},{triggerUserId:O,frontRequestId:w});break}case $.BuiltinMsg:{const p=_;this.emit("builtinEvent",p),p.event_type===F.UserChange&&this.emit("userChange",p),p.event_type===F.RoomChange&&this.emit("roomChange",p),p.event_type===F.UserChange&&p.action===J.UserMicroStatus&&p.to_user_ids.includes((u=(h=this.selfInfo)==null?void 0:h.id)!=null?u:"")&&await((d=this.$RTC)==null?void 0:d.toggleMicro(p.data.status===ie.OPEN)),p.event_type===F.RoomChange&&p.action===J.RoomClose&&await this._exit();break}case $.UserKickOut:{this.emit("kickOut");break}default:m.warn("Unknown command received:",g)}else m.error("Error in message:",b),this.emit("error",t)}});a(this,"_clearLiveData",()=>{this._buildInData.keyframes.clear(),this._buildInData={keyframes:this._yDoc.getMap("keyframes")}});a(this,"connect",async(t={})=>{var s,r,o,c;if(m.info("Attempting to connect with options:",t),this._options.url=(r=(s=t.url)!=null?s:this._options.url)!=null?r:"",this._options.getTicket=(o=t.getTicket)!=null?o:this._options.getTicket,this._options.initialMicroStatus=(c=t.rtcMicStatus)!=null?c:this._options.initialMicroStatus,!/^wss?:\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return new Error("Invalid connection parameters");if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");const n=this.state;if(n===V.CONNECTING||n===V.OPEN)if(t.force)await this._controller.close("force close by connect").catch(console.warn);else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();try{const l=await this._options.getTicket(),h=yn(this._options.url,{ticket:l,force:+!!t.force});return this._controller.open(h),m.info("Connection established successfully"),!0}catch(l){return m.error("Failed to connect:",l),new Error("Failed to connect")}});a(this,"_exit",async()=>{var t;this._clearLiveData();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}return this.state!==V.OPEN?!0:await this._controller.close()});a(this,"exit",async()=>this.close());a(this,"close",async()=>{var t;await this._controller.readyClose();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}await this.updateStatus(F.RoomChange,J.RoomClose,{})});a(this,"dispose",async()=>{this._removeLiveControllerEventListeners();try{this._yDoc.getMap("keyframes").unobserve(this._handleKeyframesChange),this._yDoc.destroy()}catch(t){m.warn(t)}return this._clearLiveData(),await this._controller.dispose()});a(this,"setSelfInfo",async t=>await this.updateStatus(F.UserChange,J.UserInfo,t));a(this,"broadcast",(t,n,s)=>this.state!==V.OPEN?!1:new Promise((r,o)=>{const c=St($.CustomEvent,t,n),l=c.front_request_id,h=s?setTimeout(()=>{o(new Error("RESPONSE TIMEOUT")),this.off("broadcast",u)},s):void 0,u=(d,g)=>{g===l&&(h&&clearTimeout(h),this.off("broadcast",u),r(d))};this.on("broadcast",u);try{this._controller.sendMessage(c)}catch(d){o(d)}}));a(this,"toggleMicro",async t=>{var s,r,o;if(!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_own_micro))return!1;const n=await((o=this.$RTC)==null?void 0:o.toggleMicro(t));return n&&await this.updateStatus(F.UserChange,J.UserMicroStatus,{status:t?ie.OPEN:ie.CLOSE},[]),n});a(this,"forbidMicro",async(t,n)=>{var s,r;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_micro)?!1:await this.updateStatus(F.UserChange,J.UserMicroStatus,{status:t},n)});a(this,"forbidSync",async(t,n)=>{var s,r;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_sync)?!1:await this.updateStatus(F.UserChange,J.UserPermission,{sync_frame:t},n)});a(this,"kick",async t=>{var n,s;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(t)||!((s=(n=this.selfInfo)==null?void 0:n.permission)!=null&&s.change_other_status)?!1:await this.updateStatus(F.UserChange,J.UserStatus,{status:"KICK_OUT"},t)});a(this,"getSnapshotForKey",t=>this.snapshot[t]);m.info("Initializing Live instance with options:",t),this._addLiveControllerEventListeners(),this._yDoc=new ke({guid:Le()}),this._buildInData={keyframes:this._yDoc.getMap("keyframes")},this._initializeKeyframesObservers(),this._initializeOptions(t),this._autoConnect(),this._debugSetup()}get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}get snapshot(){return this._buildInData.keyframes.toJSON()}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(t,n,s,r){if(this.state!==V.OPEN)return!1;const o=Object.assign({event_type:t,action:n},{data:s}),c=St($.BuiltinMsg,o,r);try{return this._controller.sendMessage(c),!0}catch(l){return m.error(l),!1}}}const hn=i=>(ln(),new an(i));function Sr(i){const e=S.createContext(null),t=hn(i),n=t.jsBridge,s=f=>S.createElement(e.Provider,{value:t},f.children),r=()=>{const f=S.useContext(e);if(!f)throw new Error("LiveProvider never found.");return f},o=()=>t,c=()=>t.$RTC,l=()=>c(),h=()=>async f=>await t.connect(f);function u(f,C,A=[]){const E=r(),R=[E,f,...A],D=()=>E.keyframes.off(f,C);return S.useEffect(()=>(E.keyframes.on(f,C),D),R),D}function d(){const f=r(),C=S.useCallback(async T=>{await f.connect(T)},[f]),A=S.useCallback(T=>{f.toggleMicro(T)},[f]),E=S.useCallback(async(T,H,ht=0)=>{await f.broadcast(T,H,ht)},[f]),R=S.useCallback(async()=>{await f.exit()},[f]),D=S.useCallback(async T=>{await f.kick(T)},[f]),P=S.useCallback(async(T,H=[])=>{await f.forbidMicro(T,H)},[f]),le=S.useCallback((T,H=[])=>{f.forbidSync(T,H)},[f]),at=S.useCallback(T=>f.getFramesByKey(T),[f]),un=S.useCallback((T,H)=>{f.sendKeyframe(T,H)},[f]),dn=S.useCallback(T=>{f.setSelfInfo(T)},[f]),fn=S.useCallback((T,H,ht,gn)=>{f.updateStatus(T,H,ht,gn)},[f]);return{connect:C,broadcast:E,exit:R,kick:D,toggleMicro:A,forbidMicro:P,forbidSync:le,sendKeyframe:un,getFramesByKey:at,setSelfInfo:dn,updateStatus:fn}}function g(f){const C=r(),[A,E]=S.useState(C.getFramesByKey(f));S.useEffect(()=>{const D=at=>E(at),P=f,le=D;return C.keyframes.on(P,le),()=>C.keyframes.off(P,le)},[C]);const R=S.useCallback(D=>C.sendKeyframe(f,D),[C]);return[A,R]}function _(f,C,A=[]){const E=r(),R=()=>E.off(f,C),D=[E,f,...A];return S.useEffect(()=>(E.on(f,C),R),D),R}function w(){const f=r(),[C,A]=S.useState(f.state);return S.useEffect(()=>{const E=R=>A(R);return f.on("stateChange",E),()=>f.off("stateChange",E)},[f]),C}function y(){const f=r();return{join:P=>f.$RTC.join(P),quit:()=>f.$RTC.quit(),shock:()=>{var P,le;return(le=(P=f.$RTC).shock)==null?void 0:le.call(P)},toggleMicro:P=>f.$RTC.toggleMicro(P),detectMicro:()=>f.$RTC.detectMicro()}}function b(f,C,A=[]){const E=r(),R=()=>E.$RTC.off(f,C),D=[E,f,...A];return S.useEffect(()=>(E.$RTC.on(f,C),R),D),R}function O(){const f=r(),[C,A]=S.useState(f.selfInfo||{}),E=D=>A(D);S.useEffect(()=>(f.on("selfInfoUpdate",E),()=>f.off("selfInfoUpdate",E)),[f]);const R=S.useCallback(async D=>await f.setSelfInfo(D),[f]);return[C,R]}function p(){const f=r(),[C,A]=S.useState(f.snapshot);return S.useEffect(()=>{const E=R=>A(R);return f.on("keyframes",E),()=>f.off("keyframes",E)},[f]),C}function W(){const f=r(),[C,A]=S.useState(f.userList),E=R=>A(R);return S.useEffect(()=>(f.on("userListUpdate",E),()=>f.off("userListUpdate",E)),[f]),C}return{live:t,jsBridge:n,LiveProvider:s,unsafe__useLiveInstance:o,unsafe__useRTCInstance:l,useConnect:h,useKeyframe:g,useKeyframeUpdateCallback:u,useLiveAction:d,useLiveEventCallback:_,useLiveState:w,useRTCAction:y,useRTCEventCallback:b,useSelfInfo:O,useKeyframesSnapshot:p,useUserList:W}}const Ct=globalThis.__REALSEE_LIVE_BADGE_LOG__;(Ct==null||Ct)&&console.log("%c@realsee/live@0.7.8 (8/10/2026, 3:54:22 PM)","background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);");exports.BrowserRTC=fi;exports.BrowserRTC4Chime=Et;exports.BuiltInRTCType=Lt;exports.BuiltinActionType=J;exports.BuiltinEventType=F;exports.Command=$;exports.CoreRTC=it;exports.Live=an;exports.LiveState=V;exports.MemUserStatus=_i;exports.MicroStatus=ie;exports.RTCJoinedInfoCodeEnum=ae;exports.RTCType=re;exports.Subscribe=pe;exports.UserStatus=pi;exports.VRWebViewRTC=gi;exports.WebSocketCloseError=wi;exports.WebSocketErrorType=mi;exports.WebSocketState=qe;exports._clearLiveInstanceIfNeed=ln;exports.createLive=hn;exports.createLiveReact=Sr;exports.parseLiveMsg=bn;exports.parseWSClsErr=bi;
3
+ `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&bt(n,this,s,c,o.attributes||{})}else o.retain!==void 0?ui(n,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&di(n,s,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){var d;(d=this.doc)!=null||j();const s=[],r=new Map,o=this.doc;let c="",l=this._start;function h(){if(c.length>0){const g={};let _=!1;r.forEach((y,b)=>{_=!0,g[b]=y});const w={insert:c};_&&(w.attributes=g),s.push(w),c=""}}const u=()=>{for(;l!==null;){if(de(l,e)||t!==void 0&&de(l,t))switch(l.content.constructor){case Z:{const g=r.get("ychange");e!==void 0&&!de(l,e)?(g===void 0||g.user!==l.id.client||g.type!=="removed")&&(h(),r.set("ychange",n?n("removed",l.id):{type:"removed"})):t!==void 0&&!de(l,t)?(g===void 0||g.user!==l.id.client||g.type!=="added")&&(h(),r.set("ychange",n?n("added",l.id):{type:"added"})):g!==void 0&&(h(),r.delete("ychange")),c+=l.content.str;break}case ce:case Ie:{h();const g={insert:l.content.getContent()[0]};if(r.size>0){const _={};g.attributes=_,r.forEach((w,y)=>{_[y]=w})}s.push(g);break}case M:de(l,e)&&(h(),ve(r,l.content));break}l=l.right}h()};return e||t?v(o,g=>{e&&Rt(g,e),t&&Rt(g,t),u()},"cleanup"):u(),s}insert(e,t,n){if(t.length<=0)return;const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!n);n||(n={},o.currentAttributes.forEach((c,l)=>{n[l]=c})),bt(r,this,o,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!n);bt(r,this,o,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(t===0)return;const n=this.doc;n!==null?v(n,s=>{di(s,We(s,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(t===0)return;const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!1);o.right!==null&&ui(r,this,o,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Wt(this,e)}getAttributes(){return Xi(this)}_write(e){e.writeTypeRef(wr)}}class yt{constructor(e,t=()=>!0){var n;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(n=e.doc)!=null||j()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===je||t.constructor===ye)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class ye extends N{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ye}clone(){const e=new ye;return e.insert(0,this.toArray().map(t=>t instanceof N?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new yt(this,e)}querySelector(e){e=e.toUpperCase();const n=new yt(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return n.done?null:n.value}querySelectorAll(e){return e=e.toUpperCase(),we(new yt(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){ot(this,e,new dr(this,t,e))}toString(){return Gi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ue(this,r=>{s.insertBefore(r.toDOM(e,t,n),null)}),s}insert(e,t){this.doc!==null?v(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)v(this.doc,n=>{const s=e&&e instanceof N?e._item:e;Xe(n,this,s,t)});else{const n=this._prelimContent,s=e===null?0:n.findIndex(r=>r===e)+1;if(s===0&&e!==null)throw be("Reference item not found");n.splice(s,0,...t)}}delete(e,t=1){this.doc!==null?v(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ji(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return qi(this,e)}slice(e=0,t=this.length){return Ki(this,e,t)}forEach(e){Ue(this,e)}_write(e){e.writeTypeRef(yr)}}class je extends ye{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new je(this.nodeName)}clone(){const e=new je(this.nodeName),t=this.getAttributes();return us(t,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof N?n.clone():n)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const c in e)n.push(c);n.sort();const s=n.length;for(let c=0;c<s;c++){const l=n[c];t.push(l+'="'+e[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Wt(this,e)}hasAttribute(e){return Zi(this,e)}getAttributes(e){return e?rr(this,e):Xi(this)}toDOM(e=document,t={},n){const s=e.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const c=r[o];typeof c=="string"&&s.setAttribute(o,c)}return Ue(this,o=>{s.appendChild(o.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(br),e.writeKey(this.nodeName)}}class dr extends st{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class sn{constructor(e,t){this.id=e,this.length=t}get deleted(){throw q()}mergeWith(e){return!1}write(e,t,n){throw q()}integrate(e,t){throw q()}}const fr=0;class ne extends sn{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),$i(e.doc.store,this)}write(e,t){e.writeInfo(fr),e.writeLen(this.length-t)}getMissing(e,t){return null}}class ct{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ct(this.content)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class tt{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new tt(this.len)}splice(e){const t=new tt(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Ui(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const gr=(i,e)=>new ke({guid:i,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class lt{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new lt(gr(this.doc.guid,this.opts))}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class Ie{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ie(this.embed)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class M{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new M(this.key,this.value)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const pr=Ye("node_env")==="development";class Se{constructor(e){this.arr=e,pr&&vi(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Se(this.arr)}splice(e){const t=new Se(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let s=t;s<n;s++){const r=this.arr[s];e.writeAny(r)}}getRef(){return 8}}class Z{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Z(this.str)}splice(e){const t=new Z(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}}const _r=0,mr=1,wr=2,br=3,yr=4;class ce{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ce(this.type._copy())}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const rn=(i,e,t)=>{const{client:n,clock:s}=e.id,r=new U(I(n,s+t),e,I(n,s+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),e.redone!==null&&(r.redone=I(e.redone.client,e.redone.clock+t)),e.right=r,r.right!==null&&(r.right.left=r),i._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),e.length=t,r};class U extends sn{constructor(e,t,n,s,r,o,c,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?qt:0}set marker(e){(this.info&gt)>0!==e&&(this.info^=gt)}get marker(){return(this.info&gt)>0}get keep(){return(this.info&Gt)>0}set keep(e){this.keep!==e&&(this.info^=Gt)}get countable(){return(this.info&qt)>0}get deleted(){return(this.info&ft)>0}set deleted(e){this.deleted!==e&&(this.info^=ft)}markDeleted(){this.info|=ft}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Je&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=oi(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=oe(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ne||this.right&&this.right.constructor===ne)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===U&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===U&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Je){const n=wt(t,this.parent);n.constructor===ne?this.parent=null:this.parent=n.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=oi(e,e.doc.store,I(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),xe(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,r.clear();else if(xe(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(wt(e.doc.store,s.origin)))r.has(wt(e.doc.store,s.origin))||(n=s,r.clear());else break;s=s.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),$i(e.doc.store,this),this.content.integrate(e,this),li(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new ne(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:I(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&xe(e.origin,this.lastId)&&this.right===e&&xe(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Ui(e.deleteSet,this.id.client,this.id.clock,this.length),li(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw ue();this.content.gc(e),t?zs(e,this,new ne(this.id,this.length)):this.content=new tt(this.length)}write(e,t){const n=t>0?I(this.id.client,this.id.clock+t-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&jn|(n===null?0:ze)|(s===null?0:Ci)|(r===null?0:Un);if(e.writeInfo(o),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const h=Gs(c);e.writeParentInfo(!0),e.writeString(h)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===Je?(e.writeParentInfo(!1),e.writeLeftID(c)):ue();r!==null&&e.writeString(r)}this.content.write(e,t)}}const on=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:{},cn="__ $YJS$ __";on[cn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");on[cn]=!0;const Re=i=>Promise.reject(new Error("unimplemented method GetVoiceSign")),St=(i,e={},t=[])=>({command:i,front_request_id:Le(),data:{...e,to_user_ids:Array.isArray(t)?t:[t]}}),ln=()=>{var i,e;window!=null&&window.__Realsee_Live__&&((e=(i=window==null?void 0:window.__Realsee_Live__)==null?void 0:i.dispose)==null||e.call(i),window.__Realsee_Live__=null)};class an extends pe{constructor(t){super();a(this,"_options",{});a(this,"keyframes",new pe);a(this,"_yDoc");a(this,"_buildInData");a(this,"_initializeKeyframesObservers",()=>{this._yDoc.getMap("keyframes").observe(this._handleKeyframesChange)});a(this,"_handleKeyframesChange",t=>{var o;const{transaction:n,target:s,changes:r}=t;if(s===this._buildInData.keyframes)if(n.origin.triggerUserId===((o=this.selfInfo)==null?void 0:o.id)){const c=St($.KeyframeSync,this.snapshot,void 0);try{this._controller.sendMessage(c)}catch(l){m.error("Failed to send keyframe sync message:",l)}}else r.keys.forEach((c,l)=>{const h=c.oldValue,u=this.getFramesByKey(l),d=n.origin.frontRequestId;this.keyframes.emit(l,u,h,d)}),r.keys.size!==0&&this.emit("keyframes",this.snapshot,n.origin.frontRequestId)});a(this,"getFramesByKey",t=>this.snapshot[t]);a(this,"sendKeyframe",(t,n)=>{var s;return this.state!==V.OPEN?(m.warn("Attempted to send keyframe while connection is not open"),!1):(this._yDoc.transact(()=>{this._buildInData.keyframes.set(t,n)},{triggerUserId:(s=this.selfInfo)==null?void 0:s.id,frontRequestId:""}),!0)});a(this,"_controller",new An);a(this,"_initializeOptions",t=>{var n;this._options=Object.assign({initialMicroStatus:ie.OPEN},t),this._options.jsBridge=this._initializeJsBridge(t),this._options.getVoiceSign=(n=t.getVoiceSign)!=null?n:Re,this._options.autoPlayConfirm=t.autoPlayConfirm,this._options.rtc=this._initializeRTC(t)});a(this,"_initializeJsBridge",t=>{if(t.jsBridge)return t.jsBridge;if(t.useBuiltInJsBridge)return new mn});a(this,"_initializeRTC",t=>{if(t.rtc)return t.rtc;if(t.rtcType)return this._createBuiltInRTC(t);if(t.useBuiltInRTC)return this._createDefaultRTC(t)});a(this,"_createBuiltInRTC",t=>{var n;if(!t.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}switch(t.rtcType){case re.RealseeVRWebViewRTC:return this._createVRWebViewRTC();case re.RealseeBrowserChimeRTC:return new Et({getVoiceSign:(n=this._options.getVoiceSign)!=null?n:Re,logLevel:t.__debug__?0:1});case re.RealseeBrowserRTC:return this._createBrowserRTC();default:m.error("unknown built-in RTC type");return}});a(this,"_createVRWebViewRTC",()=>{var t;if(this._options.jsBridge)return new gi({jsBridge:this._options.jsBridge,getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Re});m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances")});a(this,"_createBrowserRTC",()=>{var t;if(!this._options.autoPlayConfirm){m.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances");return}return new fi({getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Re,autoPlayConfirm:this._options.autoPlayConfirm})});a(this,"_createDefaultRTC",t=>{var s;const n=(s=this._options.getVoiceSign)!=null?s:Re;return!this._options.jsBridge||!Jt&&!Kt?t.builtInRTCType===Lt.RealseeXChimeRTC?new Et({getVoiceSign:n}):this._createBrowserRTC():Jt&&(Sn||Cn)||Kt?this._createVRWebViewRTC():this._createBrowserRTC()});a(this,"_autoConnect",()=>{this._options.url&&this._options.getTicket&&this.connect()});a(this,"_debugSetup",()=>{this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})});a(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});a(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});a(this,"_handleStateChange",(t,n)=>{m.info(`State changed from ${n} to ${t}`),this.emit("stateChange",t,n)});a(this,"_handleMessage",async t=>{var n,s,r,o,c,l,h,u,d;if(m.debug("Received message:",t),typeof t=="object"){const{command:g,data:_={},frontRequestId:w,code:y,message:b,triggerUserId:O}=t;if(y==="SUCCESS")switch(g){case $.SelfUserInfo:{const p=_;Rn(this.selfInfo,p,{deep:!0})||(this._buildInData.selfInfo=p,this.emit("selfInfoUpdate",this._buildInData.selfInfo,w));break}case $.RoomInfo:{const p=_;this._buildInData.roomInfo=Object.assign({},p);const W=p.last_frame||{};this._yDoc.transact(()=>{for(const f in W)this._buildInData.keyframes.set(f,W[f])},{triggerUserId:"readyKeyframeSync",frontRequestId:w}),this.emit("readyKeyframeSync",p.last_frame||{});break}case $.RTCInfo:{m.info("RTC info updated:",_);const{voice_id:p,type:W}=_;if(this._buildInData.rtcInfo={voiceId:p,type:W},(n=this.$RTC)!=null&&n.joined)m.warn("已加入语音房间,无需重复加入!");else if(await((o=this.$RTC)==null?void 0:o.join({voiceId:p,userId:((s=this.selfInfo)==null?void 0:s.id)||"",roomId:(r=this.roomInfo)==null?void 0:r.info.room_code,type:W}))){const C=(c=this._options.initialMicroStatus)!=null?c:ie.OPEN;await this.toggleMicro(C===ie.OPEN)}else m.error("加入语音房间失败");break}case $.UserList:{const p=_;this._buildInData.userList=p,this.emit("userListUpdate",this.userList,w);break}case $.CustomEvent:{const p=_;this.emit("broadcast",p,w);break}case $.KeyframeSync:{const p=_;if(O===((l=this.selfInfo)==null?void 0:l.id))return;this._yDoc.transact(()=>{for(const W in p)this._buildInData.keyframes.set(W,p[W])},{triggerUserId:O,frontRequestId:w});break}case $.BuiltinMsg:{const p=_;this.emit("builtinEvent",p),p.event_type===F.UserChange&&this.emit("userChange",p),p.event_type===F.RoomChange&&this.emit("roomChange",p),p.event_type===F.UserChange&&p.action===J.UserMicroStatus&&p.to_user_ids.includes((u=(h=this.selfInfo)==null?void 0:h.id)!=null?u:"")&&await((d=this.$RTC)==null?void 0:d.toggleMicro(p.data.status===ie.OPEN)),p.event_type===F.RoomChange&&p.action===J.RoomClose&&await this._exit();break}case $.UserKickOut:{this.emit("kickOut");break}default:m.warn("Unknown command received:",g)}else m.error("Error in message:",b),this.emit("error",t)}});a(this,"_clearLiveData",()=>{this._buildInData.keyframes.clear(),this._buildInData={keyframes:this._yDoc.getMap("keyframes")}});a(this,"connect",async(t={})=>{var s,r,o,c;if(m.info("Attempting to connect with options:",t),this._options.url=(r=(s=t.url)!=null?s:this._options.url)!=null?r:"",this._options.getTicket=(o=t.getTicket)!=null?o:this._options.getTicket,this._options.initialMicroStatus=(c=t.rtcMicStatus)!=null?c:this._options.initialMicroStatus,!/^wss?:\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return new Error("Invalid connection parameters");if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");const n=this.state;if(n===V.CONNECTING||n===V.OPEN)if(t.force)await this._controller.close("force close by connect").catch(console.warn);else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();try{const l=await this._options.getTicket(),h=yn(this._options.url,{ticket:l,force:+!!t.force});return this._controller.open(h),m.info("Connection established successfully"),!0}catch(l){return m.error("Failed to connect:",l),new Error("Failed to connect")}});a(this,"_exit",async()=>{var t;this._clearLiveData();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}return this.state!==V.OPEN?!0:await this._controller.close()});a(this,"exit",async()=>this.close());a(this,"close",async()=>{var t;await this._controller.readyClose();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}await this.updateStatus(F.RoomChange,J.RoomClose,{})});a(this,"dispose",async()=>{this._removeLiveControllerEventListeners();try{this._yDoc.getMap("keyframes").unobserve(this._handleKeyframesChange),this._yDoc.destroy()}catch(t){m.warn(t)}return this._clearLiveData(),await this._controller.dispose()});a(this,"setSelfInfo",async t=>await this.updateStatus(F.UserChange,J.UserInfo,t));a(this,"broadcast",(t,n,s)=>this.state!==V.OPEN?!1:new Promise((r,o)=>{const c=St($.CustomEvent,t,n),l=c.front_request_id,h=s?setTimeout(()=>{o(new Error("RESPONSE TIMEOUT")),this.off("broadcast",u)},s):void 0,u=(d,g)=>{g===l&&(h&&clearTimeout(h),this.off("broadcast",u),r(d))};this.on("broadcast",u);try{this._controller.sendMessage(c)}catch(d){o(d)}}));a(this,"toggleMicro",async t=>{var s,r,o;if(!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_own_micro))return!1;const n=await((o=this.$RTC)==null?void 0:o.toggleMicro(t));return n&&await this.updateStatus(F.UserChange,J.UserMicroStatusSync,{status:t?ie.OPEN:ie.CLOSE},[]),n});a(this,"forbidMicro",async(t,n)=>{var s,r;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_micro)?!1:await this.updateStatus(F.UserChange,J.UserMicroStatus,{status:t},n)});a(this,"forbidSync",async(t,n)=>{var s,r;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_sync)?!1:await this.updateStatus(F.UserChange,J.UserPermission,{sync_frame:t},n)});a(this,"kick",async t=>{var n,s;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(t)||!((s=(n=this.selfInfo)==null?void 0:n.permission)!=null&&s.change_other_status)?!1:await this.updateStatus(F.UserChange,J.UserStatus,{status:"KICK_OUT"},t)});a(this,"getSnapshotForKey",t=>this.snapshot[t]);m.info("Initializing Live instance with options:",t),this._addLiveControllerEventListeners(),this._yDoc=new ke({guid:Le()}),this._buildInData={keyframes:this._yDoc.getMap("keyframes")},this._initializeKeyframesObservers(),this._initializeOptions(t),this._autoConnect(),this._debugSetup()}get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}get snapshot(){return this._buildInData.keyframes.toJSON()}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(t,n,s,r){if(this.state!==V.OPEN)return!1;const o=Object.assign({event_type:t,action:n},{data:s}),c=St($.BuiltinMsg,o,r);try{return this._controller.sendMessage(c),!0}catch(l){return m.error(l),!1}}}const hn=i=>(ln(),new an(i));function Sr(i){const e=S.createContext(null),t=hn(i),n=t.jsBridge,s=f=>S.createElement(e.Provider,{value:t},f.children),r=()=>{const f=S.useContext(e);if(!f)throw new Error("LiveProvider never found.");return f},o=()=>t,c=()=>t.$RTC,l=()=>c(),h=()=>async f=>await t.connect(f);function u(f,C,A=[]){const E=r(),R=[E,f,...A],D=()=>E.keyframes.off(f,C);return S.useEffect(()=>(E.keyframes.on(f,C),D),R),D}function d(){const f=r(),C=S.useCallback(async T=>{await f.connect(T)},[f]),A=S.useCallback(T=>{f.toggleMicro(T)},[f]),E=S.useCallback(async(T,H,ht=0)=>{await f.broadcast(T,H,ht)},[f]),R=S.useCallback(async()=>{await f.exit()},[f]),D=S.useCallback(async T=>{await f.kick(T)},[f]),P=S.useCallback(async(T,H=[])=>{await f.forbidMicro(T,H)},[f]),le=S.useCallback((T,H=[])=>{f.forbidSync(T,H)},[f]),at=S.useCallback(T=>f.getFramesByKey(T),[f]),un=S.useCallback((T,H)=>{f.sendKeyframe(T,H)},[f]),dn=S.useCallback(T=>{f.setSelfInfo(T)},[f]),fn=S.useCallback((T,H,ht,gn)=>{f.updateStatus(T,H,ht,gn)},[f]);return{connect:C,broadcast:E,exit:R,kick:D,toggleMicro:A,forbidMicro:P,forbidSync:le,sendKeyframe:un,getFramesByKey:at,setSelfInfo:dn,updateStatus:fn}}function g(f){const C=r(),[A,E]=S.useState(C.getFramesByKey(f));S.useEffect(()=>{const D=at=>E(at),P=f,le=D;return C.keyframes.on(P,le),()=>C.keyframes.off(P,le)},[C]);const R=S.useCallback(D=>C.sendKeyframe(f,D),[C]);return[A,R]}function _(f,C,A=[]){const E=r(),R=()=>E.off(f,C),D=[E,f,...A];return S.useEffect(()=>(E.on(f,C),R),D),R}function w(){const f=r(),[C,A]=S.useState(f.state);return S.useEffect(()=>{const E=R=>A(R);return f.on("stateChange",E),()=>f.off("stateChange",E)},[f]),C}function y(){const f=r();return{join:P=>f.$RTC.join(P),quit:()=>f.$RTC.quit(),shock:()=>{var P,le;return(le=(P=f.$RTC).shock)==null?void 0:le.call(P)},toggleMicro:P=>f.$RTC.toggleMicro(P),detectMicro:()=>f.$RTC.detectMicro()}}function b(f,C,A=[]){const E=r(),R=()=>E.$RTC.off(f,C),D=[E,f,...A];return S.useEffect(()=>(E.$RTC.on(f,C),R),D),R}function O(){const f=r(),[C,A]=S.useState(f.selfInfo||{}),E=D=>A(D);S.useEffect(()=>(f.on("selfInfoUpdate",E),()=>f.off("selfInfoUpdate",E)),[f]);const R=S.useCallback(async D=>await f.setSelfInfo(D),[f]);return[C,R]}function p(){const f=r(),[C,A]=S.useState(f.snapshot);return S.useEffect(()=>{const E=R=>A(R);return f.on("keyframes",E),()=>f.off("keyframes",E)},[f]),C}function W(){const f=r(),[C,A]=S.useState(f.userList),E=R=>A(R);return S.useEffect(()=>(f.on("userListUpdate",E),()=>f.off("userListUpdate",E)),[f]),C}return{live:t,jsBridge:n,LiveProvider:s,unsafe__useLiveInstance:o,unsafe__useRTCInstance:l,useConnect:h,useKeyframe:g,useKeyframeUpdateCallback:u,useLiveAction:d,useLiveEventCallback:_,useLiveState:w,useRTCAction:y,useRTCEventCallback:b,useSelfInfo:O,useKeyframesSnapshot:p,useUserList:W}}const Ct=globalThis.__REALSEE_LIVE_BADGE_LOG__;(Ct==null||Ct)&&console.log("%c@realsee/live@0.7.9 (8/10/2026, 5:30:44 PM)","background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);");exports.BrowserRTC=fi;exports.BrowserRTC4Chime=Et;exports.BuiltInRTCType=Lt;exports.BuiltinActionType=J;exports.BuiltinEventType=F;exports.Command=$;exports.CoreRTC=it;exports.Live=an;exports.LiveState=V;exports.MemUserStatus=_i;exports.MicroStatus=ie;exports.RTCJoinedInfoCodeEnum=ae;exports.RTCType=re;exports.Subscribe=pe;exports.UserStatus=pi;exports.VRWebViewRTC=gi;exports.WebSocketCloseError=wi;exports.WebSocketErrorType=mi;exports.WebSocketState=qe;exports._clearLiveInstanceIfNeed=ln;exports.createLive=hn;exports.createLiveReact=Sr;exports.parseLiveMsg=bn;exports.parseWSClsErr=bi;