tina4ruby 3.13.47 → 3.13.49
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.
- checksums.yaml +4 -4
- data/lib/tina4/localization.rb +155 -49
- data/lib/tina4/public/js/tina4js.min.js +5 -5
- data/lib/tina4/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fad5ed1437c7ff7d9cff3c8e565b33cdc653b2299299739e14c7339cc8f8f40d
|
|
4
|
+
data.tar.gz: 6db70aa2f9ebf2524f9e78d8de195bed243fec8d05d3d9ec4b38fcad1f25ef0f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2cfdce845c291d7bab4f3cd16ded8ba1c12bf5d61f5331c21a7b8dcb66c15a83b897e2acb9feaa2b23963ec6c401f77c7fe4e1d9947098fcc44d880335717d28
|
|
7
|
+
data.tar.gz: d35c62314e6c00b152aeb680f4a751331483cc263c1cbb25e8cd89904b64936064486ae2ad7bd15101b260964a1ddefd6d9c845af3cfed910a3b51a2394122e6
|
data/lib/tina4/localization.rb
CHANGED
|
@@ -24,38 +24,19 @@ module Tina4
|
|
|
24
24
|
@current_locale = locale.to_s
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
locale_dir = File.expand_path(dir, root_dir)
|
|
33
|
-
next unless Dir.exist?(locale_dir)
|
|
27
|
+
# The fallback locale used when a key is missing in the current locale.
|
|
28
|
+
# Mirrors the Python master (TINA4_LOCALE, else "en").
|
|
29
|
+
def default_locale
|
|
30
|
+
ENV["TINA4_LOCALE"] || "en"
|
|
31
|
+
end
|
|
34
32
|
|
|
33
|
+
def load(root_dir = Dir.pwd)
|
|
34
|
+
locale_search_dirs(root_dir).each do |locale_dir|
|
|
35
35
|
Dir.glob(File.join(locale_dir, "*.json")).each do |file|
|
|
36
|
-
|
|
37
|
-
data = JSON.parse(File.read(file))
|
|
38
|
-
translations[locale] ||= {}
|
|
39
|
-
translations[locale].merge!(data)
|
|
40
|
-
# Build leaf-key aliases from the loaded data
|
|
41
|
-
build_leaf_aliases(locale, data)
|
|
42
|
-
Tina4::Log.debug("Loaded locale: #{locale} from #{file}")
|
|
36
|
+
ingest_json_file(File.basename(file, ".json"), file)
|
|
43
37
|
end
|
|
44
|
-
|
|
45
|
-
# Also support YAML
|
|
46
38
|
Dir.glob(File.join(locale_dir, "*.{yml,yaml}")).each do |file|
|
|
47
|
-
|
|
48
|
-
require "yaml"
|
|
49
|
-
locale = File.basename(file, File.extname(file))
|
|
50
|
-
data = YAML.safe_load(File.read(file))
|
|
51
|
-
if data.is_a?(Hash)
|
|
52
|
-
translations[locale] ||= {}
|
|
53
|
-
translations[locale].merge!(data)
|
|
54
|
-
build_leaf_aliases(locale, data)
|
|
55
|
-
end
|
|
56
|
-
rescue LoadError
|
|
57
|
-
Tina4::Log.warning("YAML support requires the 'yaml' gem")
|
|
58
|
-
end
|
|
39
|
+
ingest_yaml_file(File.basename(file, File.extname(file)), file)
|
|
59
40
|
end
|
|
60
41
|
end
|
|
61
42
|
end
|
|
@@ -64,22 +45,53 @@ module Tina4
|
|
|
64
45
|
lang = locale || current_locale
|
|
65
46
|
value = lookup(lang, key)
|
|
66
47
|
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
# Fallback: current locale -> default/fallback locale -> the key itself.
|
|
49
|
+
if value.nil? && lang != default_locale
|
|
50
|
+
value = lookup(default_locale, key)
|
|
69
51
|
end
|
|
70
52
|
|
|
71
53
|
value = default || key if value.nil?
|
|
72
54
|
|
|
73
|
-
# Interpolation: "Hello
|
|
74
|
-
interpolations
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
value
|
|
55
|
+
# Interpolation: "Hello {name}" => "Hello World". PARTIAL — each {name}
|
|
56
|
+
# token present in interpolations is replaced; a missing param's
|
|
57
|
+
# placeholder is left literal, and a malformed placeholder ({x.y} with a
|
|
58
|
+
# dot, {n:d} with a spec, a lone unmatched brace) is left literal too.
|
|
59
|
+
# Never raises — a bad template must not crash t().
|
|
60
|
+
interpolate(value, interpolations)
|
|
79
61
|
end
|
|
80
62
|
|
|
81
63
|
def set_locale(locale)
|
|
82
64
|
self.current_locale = locale.to_s
|
|
65
|
+
# Lazily load the new locale's file if it hasn't been loaded yet, so a
|
|
66
|
+
# switch to an unloaded locale resolves its keys (parity with Python/PHP/
|
|
67
|
+
# Node, where setting the locale triggers a per-locale load).
|
|
68
|
+
load_locale(locale.to_s) unless translations.key?(locale.to_s)
|
|
69
|
+
current_locale
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Load a SINGLE locale's file (JSON, then YAML) from the configured search
|
|
73
|
+
# dirs if it is not already loaded. Boot-safe (a malformed file is skipped,
|
|
74
|
+
# never raised) — mirrors Python's _load_locale.
|
|
75
|
+
def load_locale(locale, root_dir = Dir.pwd)
|
|
76
|
+
locale = locale.to_s
|
|
77
|
+
return if translations.key?(locale)
|
|
78
|
+
|
|
79
|
+
locale_search_dirs(root_dir).each do |locale_dir|
|
|
80
|
+
json = File.join(locale_dir, "#{locale}.json")
|
|
81
|
+
if File.file?(json)
|
|
82
|
+
ingest_json_file(locale, json)
|
|
83
|
+
return
|
|
84
|
+
end
|
|
85
|
+
%w[yml yaml].each do |ext|
|
|
86
|
+
yaml = File.join(locale_dir, "#{locale}.#{ext}")
|
|
87
|
+
if File.file?(yaml)
|
|
88
|
+
ingest_yaml_file(locale, yaml)
|
|
89
|
+
return
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
# No file found — cache an empty table so lookups fall back to the key.
|
|
94
|
+
translations[locale] ||= {}
|
|
83
95
|
end
|
|
84
96
|
|
|
85
97
|
def get_locale
|
|
@@ -117,12 +129,102 @@ module Tina4
|
|
|
117
129
|
end
|
|
118
130
|
end
|
|
119
131
|
|
|
120
|
-
|
|
121
|
-
|
|
132
|
+
# List available locale codes by scanning the configured locale dir(s) for
|
|
133
|
+
# *.json / *.yml / *.yaml file stems, sorted. When no dir exists/has files,
|
|
134
|
+
# returns a [default_locale] floor (parity with Python/PHP/Node — never an
|
|
135
|
+
# empty list when a default locale is known).
|
|
136
|
+
def available_locales(root_dir = Dir.pwd)
|
|
137
|
+
stems = []
|
|
138
|
+
locale_search_dirs(root_dir).each do |locale_dir|
|
|
139
|
+
%w[*.json *.yml *.yaml].each do |pattern|
|
|
140
|
+
Dir.glob(File.join(locale_dir, pattern)).each do |file|
|
|
141
|
+
stems << File.basename(file, File.extname(file))
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
stems.uniq!
|
|
146
|
+
stems.empty? ? [default_locale] : stems.sort
|
|
122
147
|
end
|
|
123
148
|
|
|
124
149
|
private
|
|
125
150
|
|
|
151
|
+
# The locale directories to scan, in order: TINA4_LOCALE_DIR override (when
|
|
152
|
+
# set) else the built-in LOCALE_DIRS list, each resolved against root_dir,
|
|
153
|
+
# filtered to those that actually exist.
|
|
154
|
+
def locale_search_dirs(root_dir = Dir.pwd)
|
|
155
|
+
override = ENV["TINA4_LOCALE_DIR"]
|
|
156
|
+
dirs = override && !override.empty? ? [override] : LOCALE_DIRS
|
|
157
|
+
dirs.map { |dir| File.expand_path(dir, root_dir) }.select { |d| Dir.exist?(d) }
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Parse one JSON locale file into translations + leaf aliases. Boot-safe:
|
|
161
|
+
# a malformed/unreadable file is logged, skipped, and cached empty so a
|
|
162
|
+
# bad file never crashes boot and is never retried into a partial state.
|
|
163
|
+
def ingest_json_file(locale, file)
|
|
164
|
+
data = JSON.parse(File.read(file))
|
|
165
|
+
translations[locale] ||= {}
|
|
166
|
+
translations[locale].merge!(data)
|
|
167
|
+
build_leaf_aliases(locale, data)
|
|
168
|
+
Tina4::Log.debug("Loaded locale: #{locale} from #{file}")
|
|
169
|
+
rescue JSON::ParserError, IOError, SystemCallError, StandardError => e
|
|
170
|
+
Tina4::Log.error("Skipping malformed locale file #{file}: #{e.class}: #{e.message}")
|
|
171
|
+
translations[locale] ||= {}
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Parse one YAML locale file into translations + leaf aliases. Same
|
|
175
|
+
# boot-safe policy as ingest_json_file (Psych::SyntaxError is the YAML
|
|
176
|
+
# parse error; the broad StandardError is a final safety net).
|
|
177
|
+
def ingest_yaml_file(locale, file)
|
|
178
|
+
require "yaml"
|
|
179
|
+
data = YAML.safe_load(File.read(file))
|
|
180
|
+
if data.is_a?(Hash)
|
|
181
|
+
translations[locale] ||= {}
|
|
182
|
+
translations[locale].merge!(data)
|
|
183
|
+
build_leaf_aliases(locale, data)
|
|
184
|
+
end
|
|
185
|
+
rescue LoadError
|
|
186
|
+
Tina4::Log.warning("YAML support requires the 'yaml' gem")
|
|
187
|
+
rescue Psych::SyntaxError, IOError, SystemCallError, StandardError => e
|
|
188
|
+
Tina4::Log.error("Skipping malformed locale file #{file}: #{e.class}: #{e.message}")
|
|
189
|
+
translations[locale] ||= {}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# {name} placeholder. Matches Python's _PLACEHOLDER = \{(\w+)\}, so only a
|
|
193
|
+
# bare word inside braces is a candidate — {x.y} (a dot) and {n:d} (a spec)
|
|
194
|
+
# never match and are left literal, and a lone unmatched brace is untouched.
|
|
195
|
+
PLACEHOLDER = /\{(\w+)\}/.freeze
|
|
196
|
+
|
|
197
|
+
# Substitute {name} placeholders from params. PARTIAL + literal-leftover:
|
|
198
|
+
# a placeholder present in params is replaced; a missing or malformed
|
|
199
|
+
# placeholder is left untouched. Never raises (a bad template must not
|
|
200
|
+
# crash t()). Params may be keyed by symbol (kwargs) or string.
|
|
201
|
+
def interpolate(template, params)
|
|
202
|
+
return template unless template.is_a?(String)
|
|
203
|
+
return template if params.nil? || params.empty?
|
|
204
|
+
|
|
205
|
+
template.gsub(PLACEHOLDER) do
|
|
206
|
+
name = Regexp.last_match(1)
|
|
207
|
+
if params.key?(name.to_sym)
|
|
208
|
+
params[name.to_sym].to_s
|
|
209
|
+
elsif params.key?(name)
|
|
210
|
+
params[name].to_s
|
|
211
|
+
else
|
|
212
|
+
Regexp.last_match(0)
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Render a non-string locale scalar JSON-natively: boolean true/false ->
|
|
218
|
+
# "true"/"false", null/nil -> "null", numbers as their plain form ("42").
|
|
219
|
+
def coerce_scalar(value)
|
|
220
|
+
case value
|
|
221
|
+
when true then "true"
|
|
222
|
+
when false then "false"
|
|
223
|
+
when nil then "null"
|
|
224
|
+
else value.to_s
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
126
228
|
# Recursively walk a nested hash and register leaf-key aliases.
|
|
127
229
|
# First-wins: if a leaf key already exists, it is NOT overwritten.
|
|
128
230
|
def build_leaf_aliases(locale, hash, prefix = nil)
|
|
@@ -132,30 +234,34 @@ module Tina4
|
|
|
132
234
|
if value.is_a?(Hash)
|
|
133
235
|
build_leaf_aliases(locale, value, full_key)
|
|
134
236
|
else
|
|
135
|
-
# Store the leaf key as an alias (first-wins)
|
|
136
|
-
|
|
237
|
+
# Store the leaf key as an alias (first-wins). Coerce non-string
|
|
238
|
+
# JSON-native scalars (true/false/null/number) to their string form.
|
|
239
|
+
flat_aliases[locale.to_s][key.to_s] ||= coerce_scalar(value)
|
|
137
240
|
end
|
|
138
241
|
end
|
|
139
242
|
end
|
|
140
243
|
|
|
141
244
|
def lookup(locale, key)
|
|
142
245
|
keys = key.to_s.split(".")
|
|
143
|
-
|
|
144
|
-
return nil unless
|
|
246
|
+
node = translations[locale]
|
|
247
|
+
return nil unless node
|
|
145
248
|
|
|
146
|
-
# Try dot-path traversal first
|
|
147
|
-
|
|
249
|
+
# Try dot-path traversal first. Track found-ness explicitly so a leaf
|
|
250
|
+
# whose value is false/nil is still recognised as resolved.
|
|
251
|
+
found = true
|
|
148
252
|
keys.each do |k|
|
|
149
|
-
if
|
|
150
|
-
|
|
253
|
+
if node.is_a?(Hash) && (node.key?(k) || node.key?(k.to_sym))
|
|
254
|
+
node = node.key?(k) ? node[k] : node[k.to_sym]
|
|
151
255
|
else
|
|
152
|
-
|
|
256
|
+
found = false
|
|
153
257
|
break
|
|
154
258
|
end
|
|
155
259
|
end
|
|
156
|
-
|
|
260
|
+
# A resolved leaf (string OR JSON-native scalar) wins. An intermediate
|
|
261
|
+
# Hash is not a value — fall through to the leaf alias instead.
|
|
262
|
+
return coerce_scalar(node) if found && !node.is_a?(Hash)
|
|
157
263
|
|
|
158
|
-
# Fall back to leaf-key alias (
|
|
264
|
+
# Fall back to leaf-key alias (stored already-coerced as a string).
|
|
159
265
|
if flat_aliases[locale]
|
|
160
266
|
alias_val = flat_aliases[locale][key.to_s]
|
|
161
267
|
return alias_val if alias_val.is_a?(String)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var Tina4=(()=>{var B=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var Oe=(t,n)=>{for(var e in n)B(t,e,{get:n[e],enumerable:!0})},Ie=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of qe(n))!Ne.call(t,r)&&r!==e&&B(t,r,{get:()=>n[r],enumerable:!(o=Me(n,r))||o.enumerable});return t};var De=t=>Ie(B({},"__esModule",{value:!0}),t);var Ve={};Oe(Ve,{Tina4Element:()=>W,api:()=>we,batch:()=>F,computed:()=>ce,effect:()=>b,html:()=>ue,isSignal:()=>R,navigate:()=>G,pwa:()=>Se,route:()=>me,router:()=>ve,signal:()=>v,sse:()=>Te,ws:()=>Ee});var q=null,I=null,j=null;function S(t){j=t}function U(){return j}var ae=null,ie=null;var K=0,z=new Set;function v(t,n){let e=t,o=new Set,r={_t4:!0,get value(){if(q&&(o.add(q),I)){let s=q;I.push(()=>o.delete(s))}return e},set value(s){if(Object.is(s,e))return;let i=e;if(e=s,r._debugInfo&&r._debugInfo.updateCount++,ie&&ie(r,i,s),K>0)for(let a of o)z.add(a);else{let a;for(let c of[...o])try{c()}catch(l){a===void 0&&(a=l)}if(a!==void 0)throw a}},_subscribe(s){return o.add(s),()=>{o.delete(s)}},peek(){return e}};return ae&&(r._debugInfo={label:n,createdAt:Date.now(),updateCount:0,subs:o},ae(r,n)),r}function ce(t){let n=v(void 0);return b(()=>{n.value=t()}),{_t4:!0,get value(){return n.value},set value(e){throw new Error("[tina4] computed signals are read-only")},_subscribe(e){return n._subscribe(e)},peek(){return n.peek()}}}function b(t){let n=!1,e=[],o=()=>{if(n)return;for(let a of e)a();e=[];let s=q,i=I;q=o,I=e;try{t()}finally{q=s,I=i}};o();let r=()=>{n=!0;for(let s of e)s();e=[]};return j&&j.push(r),r}function F(t){K++;try{t()}finally{if(K--,K===0){let n=[...z];z.clear();let e;for(let o of n)try{o()}catch(r){e===void 0&&(e=r)}if(e!==void 0)throw e}}}function R(t){return t!==null&&typeof t=="object"&&t._t4===!0}var le=new WeakMap,Q="t4:";function ue(t,...n){let e=le.get(t);if(!e){e=document.createElement("template");let i="";for(let a=0;a<t.length;a++)i+=t[a],a<n.length&&(je(i)?i+=`__t4_${a}__`:i+=`<!--${Q}${a}-->`);e.innerHTML=i,le.set(t,e)}let o=e.content.cloneNode(!0),r=He(o);for(let{marker:i,index:a}of r)Pe(i,n[a]);let s=Le(o);for(let i of s)Ke(i,n);return o}function He(t){let n=[];return Y(t,e=>{if(e.nodeType===8){let o=e.data;if(o&&o.startsWith(Q)){let r=parseInt(o.slice(Q.length),10);n.push({marker:e,index:r})}}}),n}function Le(t){let n=[];return Y(t,e=>{e.nodeType===1&&n.push(e)}),n}function Y(t,n){let e=t.childNodes;for(let o=0;o<e.length;o++){let r=e[o];n(r),Y(r,n)}}function Pe(t,n){let e=t.parentNode;if(e)if(R(n)){let o=document.createTextNode("");e.replaceChild(o,t),b(()=>{o.data=String(n.value??"")})}else if(typeof n=="function"){let o=document.createComment("");e.replaceChild(o,t);let r=[],s=[];b(()=>{for(let u of s)u();s=[];let i=[],a=U();S(i);let c=n();S(a),s=i;for(let u of r)u.parentNode?.removeChild(u);r=[];let l=X(c),d=o.parentNode;if(d)for(let u of l)d.insertBefore(u,o),r.push(u)})}else if(de(n))e.replaceChild(n,t);else if(n instanceof Node)e.replaceChild(n,t);else if(Array.isArray(n)){let o=document.createDocumentFragment();for(let r of n){let s=X(r);for(let i of s)o.appendChild(i)}e.replaceChild(o,t)}else{let o=document.createTextNode(String(n??""));e.replaceChild(o,t)}}function Ke(t,n){let e=[];for(let o of Array.from(t.attributes)){let r=o.name,s=o.value;if(r.startsWith("@")){let a=r.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let l=n[parseInt(c[1],10)];typeof l=="function"&&t.addEventListener(a,d=>F(()=>l(d)))}e.push(r);continue}if(r.startsWith("?")){let a=r.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let l=n[parseInt(c[1],10)];if(R(l)){let d=l;b(()=>{d.value?t.setAttribute(a,""):t.removeAttribute(a)})}else typeof l=="function"?b(()=>{l()?t.setAttribute(a,""):t.removeAttribute(a)}):l&&t.setAttribute(a,"")}e.push(r);continue}if(r.startsWith(".")){let a=r.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let l=n[parseInt(c[1],10)];R(l)?b(()=>{t[a]=l.value}):t[a]=l}e.push(r);continue}let i=s.match(/__t4_(\d+)__/);if(i){let a=n[parseInt(i[1],10)];if(R(a)){let c=a;b(()=>{t.setAttribute(r,String(c.value??""))})}else typeof a=="function"?b(()=>{t.setAttribute(r,String(a()??""))}):t.setAttribute(r,String(a??""))}}for(let o of e)t.removeAttribute(o)}function X(t){if(t==null||t===!1)return[];if(de(t))return Array.from(t.childNodes);if(t instanceof Node)return[t];if(Array.isArray(t)){let n=[];for(let e of t)n.push(...X(e));return n}return[document.createTextNode(String(t))]}function de(t){return t!=null&&typeof t=="object"&&t.nodeType===11}function je(t){let n=!1,e=!1,o=!1;for(let r=0;r<t.length;r++){let s=t[r];s==="<"&&!n&&!e&&(o=!0),s===">"&&!n&&!e&&(o=!1),o&&(s==='"'&&!n&&(e=!e),s==="'"&&!e&&(n=!n))}return o}var fe=null,pe=null;var W=class extends HTMLElement{constructor(){super();this._props={};this._rendered=!1;this._disposeRender=null;this._innerDisposers=[];let e=this.constructor;this._root=e.shadow?this.attachShadow({mode:"open"}):this;for(let[o,r]of Object.entries(e.props))this._props[o]=v(this._coerce(this.getAttribute(o),r))}static{this.props={}}static{this.styles=""}static{this.shadow=!0}static get observedAttributes(){return Object.keys(this.props)}connectedCallback(){if(this._rendered)return;this._rendered=!0;let e=this.constructor,o=null;if(e.styles&&e.shadow&&this._root instanceof ShadowRoot){let r=document.createElement("style");r.textContent=e.styles,this._root.appendChild(r),o=r}this._disposeRender=b(()=>{for(let c of this._innerDisposers)c();this._innerDisposers=[];let r=[],s=U();S(r);let i=this.render();S(s),this._innerDisposers=r;let a=Array.from(this._root.childNodes);for(let c of a)c!==o&&this._root.removeChild(c);i&&this._root.appendChild(i)}),this.onMount(),fe&&fe(this)}disconnectedCallback(){this._disposeRender&&(this._disposeRender(),this._disposeRender=null);for(let e of this._innerDisposers)e();this._innerDisposers=[],this.onUnmount(),pe&&pe(this)}attributeChangedCallback(e,o,r){let i=this.constructor.props[e];i&&this._props[e]&&(this._props[e].value=this._coerce(r,i))}prop(e){if(!this._props[e])throw new Error(`[tina4] Prop '${e}' not declared in static props of <${this.tagName.toLowerCase()}>`);return this._props[e]}emit(e,o){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,...o}))}onMount(){}onUnmount(){}_coerce(e,o){return o===Boolean?e!==null:o===Number?e!==null?Number(e):0:e??""}};var Z=[],N=null,D="history",Ue=!1,H=[],$=[],ge=0;function me(t,n){let e=[],o;t==="*"?o=".*":o=t.replace(/\{(\w+)\}/g,(s,i)=>(e.push(i),"([^/]+)"));let r=new RegExp(`^${o}$`);typeof n=="function"?Z.push({pattern:t,regex:r,paramNames:e,handler:n}):Z.push({pattern:t,regex:r,paramNames:e,handler:n.handler,guard:n.guard})}function G(t,n){if(D==="hash")if(n?.replace){let e=new URL(location.href);e.hash="#"+t,history.replaceState(null,"",e.toString()),L()}else location.hash="#"+t;else n?.replace?history.replaceState(null,"",t):history.pushState(null,"",t),L()}function L(){if(!N)return;let t=performance.now(),n=++ge,e=D==="hash"?location.hash.slice(1)||"/":location.pathname;for(let o of Z){let r=e.match(o.regex);if(!r)continue;let s={};if(o.paramNames.forEach((c,l)=>{s[c]=decodeURIComponent(r[l+1])}),o.guard){let c=o.guard();if(c===!1)return;if(typeof c=="string"){G(c,{replace:!0});return}}for(let c of $)c();$=[],N.innerHTML="";let i=[];S(i);let a=o.handler(s);if(a instanceof Promise)a.then(c=>{if(S(null),n!==ge){for(let d of i)d();return}he(N,c),$=i;let l=performance.now()-t;for(let d of H)d({path:e,params:s,pattern:o.pattern,durationMs:l})});else{S(null),he(N,a),$=i;let c=performance.now()-t;for(let l of H)l({path:e,params:s,pattern:o.pattern,durationMs:c})}return}}function he(t,n){n instanceof DocumentFragment||n instanceof Node?t.replaceChildren(n):typeof n=="string"?t.innerHTML=n:n!=null&&t.replaceChildren(document.createTextNode(String(n)))}var ve={start(t){if(N=document.querySelector(t.target),!N)throw new Error(`[tina4] Router target '${t.target}' not found in DOM`);D=t.mode??"history",Ue=!0,window.addEventListener("popstate",L),D==="hash"&&window.addEventListener("hashchange",L),document.addEventListener("click",n=>{if(n.metaKey||n.ctrlKey||n.shiftKey||n.altKey)return;let e=n.target.closest("a[href]");if(!e||e.origin!==location.origin||e.hasAttribute("target")||e.hasAttribute("download")||e.getAttribute("rel")?.includes("external"))return;n.preventDefault();let o=D==="hash"?e.getAttribute("href"):e.pathname;G(o)}),L()},on(t,n){return H.push(n),()=>{let e=H.indexOf(n);e>=0&&H.splice(e,1)}}};var y={baseUrl:"",auth:!1,tokenKey:"tina4_token",headers:{}},J=[],V=[],ye=0;function ee(){try{return localStorage.getItem(y.tokenKey)}catch{return null}}function be(t){try{localStorage.setItem(y.tokenKey,t)}catch{}}async function O(t,n,e,o){let r={method:t,headers:{"Content-Type":"application/json",...y.headers}};if(y.auth){let u=ee();u&&(r.headers.Authorization=`Bearer ${u}`)}if(e!==void 0&&t!=="GET"){let u=typeof e=="object"&&e!==null?{...e}:e;if(y.auth&&typeof u=="object"&&u!==null){let g=ee();g&&(u.formToken=g)}r.body=JSON.stringify(u)}if(o?.headers&&Object.assign(r.headers,o.headers),o?.params){let u=Object.entries(o.params).map(([g,w])=>`${encodeURIComponent(g)}=${encodeURIComponent(String(w))}`).join("&");n+=(n.includes("?")?"&":"?")+u}let s=y.baseUrl+n;r._url=s,r._requestId=++ye;for(let u of J){let g=u(r);g&&(r=g)}let i=await fetch(s,r),a=i.headers.get("FreshToken");a&&be(a);let c=i.headers.get("Content-Type")??"",l;c.includes("json")?l=await i.json():l=await i.text();let d={status:i.status,data:l,ok:i.ok,headers:i.headers,_requestId:r._requestId};for(let u of V){let g=u(d);g&&(d=g)}if(!i.ok)throw d;return d.data}var we={configure(t){Object.assign(y,t)},get(t,n){return O("GET",t,void 0,n)},post(t,n,e){return O("POST",t,n,e)},put(t,n,e){return O("PUT",t,n,e)},patch(t,n,e){return O("PATCH",t,n,e)},delete(t,n){return O("DELETE",t,void 0,n)},async graphql(t,n,e,o){return O("POST",t,{query:n,variables:e||{}},o)},async upload(t,n,e){let o={method:"POST",headers:{...y.headers},body:n};if(delete o.headers["Content-Type"],delete o.headers["content-type"],y.auth){let d=ee();d&&(o.headers.Authorization=`Bearer ${d}`)}if(e?.headers&&Object.assign(o.headers,e.headers),e?.params){let d=Object.entries(e.params).map(([u,g])=>`${encodeURIComponent(u)}=${encodeURIComponent(String(g))}`).join("&");t+=(t.includes("?")?"&":"?")+d}let r=y.baseUrl+t;o._url=r,o._requestId=++ye;for(let d of J){let u=d(o);u&&(o=u)}let s=await fetch(r,o),i=s.headers.get("FreshToken");i&&be(i);let a=s.headers.get("Content-Type")??"",c;a.includes("json")?c=await s.json():c=await s.text();let l={status:s.status,data:c,ok:s.ok,headers:s.headers,_requestId:o._requestId};for(let d of V){let u=d(l);u&&(l=u)}if(!s.ok)throw l;return l.data},intercept(t,n){t==="request"?J.push(n):V.push(n)},_reset(){y.baseUrl="",y.auth=!1,y.tokenKey="tina4_token",y.headers={},J.length=0,V.length=0}};function Fe(t){let n=t.cacheStrategy??"network-first",e=JSON.stringify(t.precache??[]),o=t.offlineRoute?`'${t.offlineRoute}'`:"null";return`
|
|
1
|
+
"use strict";var Tina4=(()=>{var z=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var ze=Object.prototype.hasOwnProperty;var Ge=(e,n)=>{for(var t in n)z(e,t,{get:n[t],enumerable:!0})},Ve=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Je(n))!ze.call(e,o)&&o!==t&&z(e,o,{get:()=>n[o],enumerable:!(r=Ue(n,o))||r.enumerable});return e};var Be=e=>Ve(z({},"__esModule",{value:!0}),e);var ht={};Ge(ht,{Tina4Element:()=>A,api:()=>Te,batch:()=>U,clearPersistedKeys:()=>De,computed:()=>de,createI18n:()=>ne,effect:()=>k,html:()=>pe,i18n:()=>qe,isSignal:()=>x,navigate:()=>J,persist:()=>Pe,pwa:()=>Re,route:()=>be,router:()=>Se,signal:()=>S,sse:()=>Ce,ws:()=>_e});var M=null,D=null,P=null,K=null;function _(e){K=e}function W(){return K}var le=null,ce=null,ue=[],Ze=512;var j=0,G=new Set;function S(e,n){let t=e,r=new Set,o={_t4:!0,get value(){if(M&&(r.add(M),D)){let s=M;D.push(()=>r.delete(s))}return t},set value(s){if(Object.is(s,t))return;let i=t;if(t=s,o._debugInfo&&o._debugInfo.updateCount++,ce&&ce(o,i,s),j>0)for(let a of r)G.add(a);else{let a;for(let c of[...r])try{c()}catch(u){a===void 0&&(a=u)}if(a!==void 0)throw a}},_subscribe(s){return r.add(s),()=>{r.delete(s)}},peek(){return t}};return le?(o._debugInfo={label:n,createdAt:Date.now(),updateCount:0,subs:r},le(o,n)):ue.length<Ze&&ue.push({ref:new WeakRef(o),label:n,createdAt:Date.now(),subs:r}),o}function de(e){let n=S(void 0);return k(()=>{n.value=e()}),{_t4:!0,get value(){return n.value},set value(t){throw new Error("[tina4] computed signals are read-only")},_subscribe(t){return n._subscribe(t)},peek(){return n.peek()}}}function k(e){let n=!1,t=[],r=[],o=()=>{for(let a of r)a();r=[]},s=()=>{if(n)return;for(let m of t)m();t=[],o();let a=M,c=D,u=P;M=s,D=t,P=r;try{e()}finally{M=a,D=c,P=u}};s();let i=()=>{n=!0;for(let a of t)a();t=[],o()};return P&&P.push(i),K&&K.push(i),i}function U(e){j++;try{e()}finally{if(j--,j===0){let n=[...G];G.clear();let t;for(let r of n)try{r()}catch(o){t===void 0&&(t=o)}if(t!==void 0)throw t}}}function x(e){return e!==null&&typeof e=="object"&&e._t4===!0}var fe=new WeakMap,V="t4:";function pe(e,...n){let t=fe.get(e);if(!t){t=document.createElement("template");let i="";for(let a=0;a<e.length;a++)i+=e[a],a<n.length&&(tt(i)?i+=`__t4_${a}__`:i+=`<!--${V}${a}-->`);t.innerHTML=i,fe.set(e,t)}let r=t.content.cloneNode(!0),o=Qe(r);for(let{marker:i,index:a}of o)Ye(i,n[a]);let s=Xe(r);for(let i of s)et(i,n);return r}function Qe(e){let n=[];return Z(e,t=>{if(t.nodeType===8){let r=t.data;if(r&&r.startsWith(V)){let o=parseInt(r.slice(V.length),10);n.push({marker:t,index:o})}}}),n}function Xe(e){let n=[];return Z(e,t=>{t.nodeType===1&&n.push(t)}),n}function Z(e,n){let t=e.childNodes;for(let r=0;r<t.length;r++){let o=t[r];n(o),Z(o,n)}}function Ye(e,n){let t=e.parentNode;if(t)if(x(n)){let r=document.createTextNode("");t.replaceChild(r,e),k(()=>{r.data=String(n.value??"")})}else if(typeof n=="function"){let r=document.createComment("");t.replaceChild(r,e);let o=[],s=[];k(()=>{for(let y of s)y();s=[];let i=[],a=W();_(i);let c=n();_(a),s=i;for(let y of o)y.parentNode?.removeChild(y);o=[];let u=B(c),m=r.parentNode;if(m)for(let y of u)m.insertBefore(y,r),o.push(y)})}else if(ge(n))t.replaceChild(n,e);else if(n instanceof Node)t.replaceChild(n,e);else if(Array.isArray(n)){let r=document.createDocumentFragment();for(let o of n){let s=B(o);for(let i of s)r.appendChild(i)}t.replaceChild(r,e)}else{let r=document.createTextNode(String(n??""));t.replaceChild(r,e)}}function et(e,n){let t=[];for(let r of Array.from(e.attributes)){let o=r.name,s=r.value;if(o.startsWith("@")){let a=o.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let u=n[parseInt(c[1],10)];typeof u=="function"&&e.addEventListener(a,m=>U(()=>u(m)))}t.push(o);continue}if(o.startsWith("?")){let a=o.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let u=n[parseInt(c[1],10)];if(x(u)){let m=u;k(()=>{m.value?e.setAttribute(a,""):e.removeAttribute(a)})}else typeof u=="function"?k(()=>{u()?e.setAttribute(a,""):e.removeAttribute(a)}):u&&e.setAttribute(a,"")}t.push(o);continue}if(o.startsWith(".")){let a=o.slice(1),c=s.match(/__t4_(\d+)__/);if(c){let u=n[parseInt(c[1],10)];x(u)?k(()=>{e[a]=u.value}):typeof u=="function"?k(()=>{e[a]=u()??""}):e[a]=u}t.push(o);continue}let i=s.match(/__t4_(\d+)__/);if(i){let a=n[parseInt(i[1],10)];if(x(a)){let c=a;k(()=>{e.setAttribute(o,String(c.value??""))})}else typeof a=="function"?k(()=>{e.setAttribute(o,String(a()??""))}):e.setAttribute(o,String(a??""))}}for(let r of t)e.removeAttribute(r)}function B(e){if(e==null||e===!1)return[];if(ge(e))return Array.from(e.childNodes);if(e instanceof Node)return[e];if(Array.isArray(e)){let n=[];for(let t of e)n.push(...B(t));return n}return[document.createTextNode(String(e))]}function ge(e){return e!=null&&typeof e=="object"&&e.nodeType===11}function tt(e){let n=!1,t=!1,r=!1;for(let o=0;o<e.length;o++){let s=e[o];s==="<"&&!n&&!t&&(r=!0),s===">"&&!n&&!t&&(r=!1),r&&(s==='"'&&!n&&(t=!t),s==="'"&&!t&&(n=!n))}return r}var me=null,he=null;var A=class extends HTMLElement{constructor(){super();this._props={};this._rendered=!1;this._disposeRender=null;this._innerDisposers=[];let t=this.constructor;this._root=t.shadow?this.attachShadow({mode:"open"}):this;for(let[r,o]of Object.entries(t.props))this._props[r]=S(this._coerce(this.getAttribute(r),o))}static get observedAttributes(){return Object.keys(this.props)}connectedCallback(){if(this._rendered)return;this._rendered=!0;let t=this.constructor,r=null;if(t.styles&&t.shadow&&this._root instanceof ShadowRoot){let o=document.createElement("style");o.textContent=t.styles,this._root.appendChild(o),r=o}this._disposeRender=k(()=>{this._innerDisposers.splice(0).forEach(c=>c());let o=[],s=W();_(o);let i=this.render();_(s),this._innerDisposers=o;let a=Array.from(this._root.childNodes);for(let c of a)c!==r&&this._root.removeChild(c);i&&this._root.appendChild(i)}),this.onMount(),me&&me(this)}disconnectedCallback(){this._disposeRender&&(this._disposeRender(),this._disposeRender=null),this._innerDisposers.splice(0).forEach(t=>t()),this.onUnmount(),he&&he(this)}attributeChangedCallback(t,r,o){let i=this.constructor.props[t];i&&this._props[t]&&(this._props[t].value=this._coerce(o,i))}prop(t){if(!this._props[t])throw new Error(`[tina4] Prop '${t}' not declared in static props of <${this.tagName.toLowerCase()}>`);return this._props[t]}emit(t,r){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,...r}))}onMount(){}onUnmount(){}_coerce(t,r){return r===Boolean?t!==null:r===Number?t!==null?Number(t):0:t??""}};A.props={},A.styles="",A.shadow=!0;var X=[],N=null,F="history",nt=!1,q=[],Q=[],ve=0;function be(e,n){let t=[],r;e==="*"?r=".*":r=e.replace(/\{(\w+)\}/g,(s,i)=>(t.push(i),"([^/]+)"));let o=new RegExp(`^${r}$`);typeof n=="function"?X.push({pattern:e,regex:o,paramNames:t,handler:n}):X.push({pattern:e,regex:o,paramNames:t,handler:n.handler,guard:n.guard})}function J(e,n){if(F==="hash")if(n?.replace){let t=new URL(location.href);t.hash="#"+e,history.replaceState(null,"",t.toString()),H()}else location.hash="#"+e;else n?.replace?history.replaceState(null,"",e):history.pushState(null,"",e),H()}function H(){if(!N)return;let e=performance.now(),n=++ve,t=F==="hash"?location.hash.slice(1)||"/":location.pathname;for(let r of X){let o=t.match(r.regex);if(!o)continue;let s={};if(r.paramNames.forEach((c,u)=>{s[c]=decodeURIComponent(o[u+1])}),r.guard){let c=r.guard();if(c===!1)return;if(typeof c=="string"){J(c,{replace:!0});return}}Q.splice(0).forEach(c=>c()),N.innerHTML="";let i=[];_(i);let a=r.handler(s);if(a instanceof Promise)a.then(c=>{if(_(null),n!==ve){for(let m of i)m();return}ye(N,c),Q=i;let u=performance.now()-e;for(let m of q)m({path:t,params:s,pattern:r.pattern,durationMs:u})});else{_(null),ye(N,a),Q=i;let c=performance.now()-e;for(let u of q)u({path:t,params:s,pattern:r.pattern,durationMs:c})}return}}function ye(e,n){n instanceof DocumentFragment||n instanceof Node?e.replaceChildren(n):typeof n=="string"?e.innerHTML=n:n!=null&&e.replaceChildren(document.createTextNode(String(n)))}var Se={start(e){if(N=document.querySelector(e.target),!N)throw new Error(`[tina4] Router target '${e.target}' not found in DOM`);F=e.mode??"history",nt=!0,window.addEventListener("popstate",H),F==="hash"&&window.addEventListener("hashchange",H),document.addEventListener("click",n=>{if(n.metaKey||n.ctrlKey||n.shiftKey||n.altKey)return;let t=n.target.closest("a[href]");if(!t||t.origin!==location.origin||t.hasAttribute("target")||t.hasAttribute("download")||t.getAttribute("rel")?.includes("external"))return;n.preventDefault();let r=F==="hash"?t.getAttribute("href"):t.pathname;J(r)}),H()},on(e,n){return q.push(n),()=>{let t=q.indexOf(n);t>=0&&q.splice(t,1)}}};var E={baseUrl:"",auth:!1,tokenKey:"tina4_token",headers:{}},Y=[],ee=[],rt=0;function te(){try{return localStorage.getItem(E.tokenKey)}catch{return null}}function ot(e){try{localStorage.setItem(E.tokenKey,e)}catch{}}function we(e,n){let t=Object.entries(n).map(([r,o])=>`${encodeURIComponent(r)}=${encodeURIComponent(String(o))}`).join("&");return e+(e.includes("?")?"&":"?")+t}async function ke(e,n){e._url=n,e._requestId=++rt;for(let a of Y){let c=a(e);c&&(e=c)}let t=await fetch(n,e),r=t.headers.get("FreshToken");r&&ot(r);let o=t.headers.get("Content-Type")??"",s;o.includes("json")?s=await t.json():s=await t.text();let i={status:t.status,data:s,ok:t.ok,headers:t.headers,_requestId:e._requestId};for(let a of ee){let c=a(i);c&&(i=c)}if(!t.ok)throw i;return i.data}async function L(e,n,t,r){let o={method:e,credentials:"same-origin",headers:{"Content-Type":"application/json",...E.headers}};if(E.auth){let s=te();s&&(o.headers.Authorization=`Bearer ${s}`)}if(t!==void 0&&e!=="GET"){let s=typeof t=="object"&&t!==null?{...t}:t;if(E.auth&&typeof s=="object"&&s!==null){let i=te();i&&(s.formToken=i)}o.body=JSON.stringify(s)}return r?.headers&&Object.assign(o.headers,r.headers),r?.params&&(n=we(n,r.params)),ke(o,E.baseUrl+n)}var Te={configure(e){Object.assign(E,e)},get(e,n){return L("GET",e,void 0,n)},post(e,n,t){return L("POST",e,n,t)},put(e,n,t){return L("PUT",e,n,t)},patch(e,n,t){return L("PATCH",e,n,t)},delete(e,n){return L("DELETE",e,void 0,n)},async graphql(e,n,t,r){return L("POST",e,{query:n,variables:t||{}},r)},async upload(e,n,t){let r={method:"POST",headers:{...E.headers},body:n};if(delete r.headers["Content-Type"],delete r.headers["content-type"],E.auth){let o=te();o&&(r.headers.Authorization=`Bearer ${o}`)}return t?.headers&&Object.assign(r.headers,t.headers),t?.params&&(e=we(e,t.params)),ke(r,E.baseUrl+e)},intercept(e,n){e==="request"?Y.push(n):ee.push(n)},_reset(){E.baseUrl="",E.auth=!1,E.tokenKey="tina4_token",E.headers={},Y.length=0,ee.length=0}};function st(e){let n=e.cacheStrategy??"network-first",t=JSON.stringify(e.precache??[]),r=e.offlineRoute?`'${e.offlineRoute}'`:"null";return`
|
|
2
2
|
const CACHE = 'tina4-v1';
|
|
3
|
-
const PRECACHE = ${
|
|
4
|
-
const OFFLINE = ${
|
|
3
|
+
const PRECACHE = ${t};
|
|
4
|
+
const OFFLINE = ${r};
|
|
5
5
|
|
|
6
6
|
self.addEventListener('install', (e) => {
|
|
7
7
|
e.waitUntil(
|
|
@@ -44,5 +44,5 @@ self.addEventListener('fetch', (e) => {
|
|
|
44
44
|
))
|
|
45
45
|
);`}
|
|
46
46
|
});
|
|
47
|
-
`.trim()}function
|
|
48
|
-
`)
|
|
47
|
+
`.trim()}function Ee(e){let n={name:e.name,short_name:e.shortName??e.name,start_url:"/",display:e.display??"standalone",background_color:e.backgroundColor??"#ffffff",theme_color:e.themeColor??"#000000"};return e.icon&&(n.icons=[{src:e.icon,sizes:"192x192",type:"image/png"},{src:e.icon,sizes:"512x512",type:"image/png"}]),n}var Re={register(e){let n=Ee(e),t=new Blob([JSON.stringify(n)],{type:"application/json"}),r=document.createElement("link");r.rel="manifest",r.href=URL.createObjectURL(t),document.head.appendChild(r);let o=document.querySelector('meta[name="theme-color"]');o||(o=document.createElement("meta"),o.name="theme-color",document.head.appendChild(o)),o.content=e.themeColor??"#000000","serviceWorker"in navigator&&(e.swUrl?navigator.serviceWorker.register(e.swUrl).catch(s=>{console.warn("[tina4] Service worker registration failed:",s)}):navigator.serviceWorker.register("/sw.js").catch(()=>{console.info("[tina4] No service worker at /sw.js. Use pwa.generateServiceWorker() to create one, or pass swUrl in config.")}))},generateServiceWorker(e){return st(e)},generateManifest(e){return Ee(e)}};var it={reconnect:!0,reconnectDelay:1e3,reconnectMaxDelay:3e4,reconnectAttempts:1/0,protocols:[],token:""};function at(e){let n=Array.isArray(e.protocols)?e.protocols:e.protocols?[e.protocols]:[];return e.token?["bearer",e.token,...n]:e.protocols}function lt(e,n={}){let t={...it,...n},r=S("connecting"),o=S(!1),s=S(null),i=S(null),a=S(0),c={message:[],open:[],close:[],error:[]},u=null,m=!1,y=t.reconnectDelay,f=null,l=0;function p(g){if(typeof g!="string")return g;try{return JSON.parse(g)}catch{return g}}function d(){r.value=l>0?"reconnecting":"connecting";try{u=new WebSocket(e,at(t))}catch{r.value="closed",o.value=!1;return}u.onopen=()=>{r.value="open",o.value=!0,i.value=null,l=0,y=t.reconnectDelay,a.value=0;for(let g of c.open)g()},u.onmessage=g=>{let b=p(g.data);s.value=b;for(let R of c.message)R(b)},u.onclose=g=>{r.value="closed",o.value=!1;for(let b of c.close)b(g.code,g.reason);!m&&t.reconnect&&l<t.reconnectAttempts&&v()},u.onerror=g=>{i.value=g;for(let b of c.error)b(g)}}function v(){l++,a.value=l,r.value="reconnecting",f=setTimeout(()=>{f=null,d()},y),y=Math.min(y*2,t.reconnectMaxDelay)}let T={status:r,connected:o,lastMessage:s,error:i,reconnectCount:a,send(g){if(!u||u.readyState!==WebSocket.OPEN)throw new Error("[tina4] WebSocket is not connected");let b=typeof g=="string"?g:JSON.stringify(g);u.send(b)},on(g,b){return c[g].push(b),()=>{let R=c[g],I=R.indexOf(b);I>=0&&R.splice(I,1)}},pipe(g,b){let R=I=>{g.value=b(I,g.value)};return T.on("message",R)},close(g,b){m=!0,f&&(clearTimeout(f),f=null),u&&u.close(g??1e3,b??""),r.value="closed",o.value=!1}};return d(),T}var _e={connect:lt};var ct={mode:"eventsource",method:"GET",headers:{},body:void 0,reconnect:!0,reconnectDelay:1e3,reconnectMaxDelay:3e4,reconnectAttempts:1/0,events:[],json:!0};function ut(e,n={}){let t={...ct,...n},r=S("connecting"),o=S(!1),s=S(null),i=S(null),a=S(null),c=S(0),u={message:[],open:[],close:[],error:[]},m=null,y=null,f=!1,l=t.reconnectDelay,p=null,d=0;function v(h){if(!t.json||typeof h!="string")return h;try{return JSON.parse(h)}catch{return h}}function T(h,w){s.value=h,i.value=w;for(let C of u.message)C(h,w??void 0)}function g(){r.value="open",o.value=!0,a.value=null,d=0,l=t.reconnectDelay,c.value=0;for(let h of u.open)h()}function b(){r.value="closed",o.value=!1;for(let h of u.close)h();!f&&t.reconnect&&d<t.reconnectAttempts&&$e()}function R(h){a.value=h;for(let w of u.error)w(h)}function I(){r.value=d>0?"reconnecting":"connecting";try{m=new EventSource(e)}catch{r.value="closed",o.value=!1;return}m.onopen=()=>g(),m.onmessage=h=>{T(v(h.data),null)};for(let h of t.events)m.addEventListener(h,w=>{T(v(w.data),h)});m.onerror=h=>{R(h),m&&m.readyState===2&&(m=null,b())}}function He(){r.value=d>0?"reconnecting":"connecting",y=new AbortController;let h={method:t.method,headers:t.headers,signal:y.signal};t.body!==void 0&&(h.body=typeof t.body=="string"?t.body:JSON.stringify(t.body)),fetch(e,h).then(async w=>{if(!w.ok){R(new Error(`[tina4] SSE fetch ${w.status}`)),b();return}g();let C=w.body.getReader(),O=new TextDecoder,$="";for(;;){let{done:je,value:Ke}=await C.read();if(je)break;$+=O.decode(Ke,{stream:!0});let ie=$.split(`
|
|
48
|
+
`);$=ie.pop();for(let We of ie){let ae=We.trim();ae&&T(v(ae),null)}}let se=$.trim();se&&T(v(se),null),y=null,b()}).catch(w=>{w.name!=="AbortError"&&(y=null,R(w),b())})}function $e(){d++,c.value=d,r.value="reconnecting",p=setTimeout(()=>{p=null,re()},l),l=Math.min(l*2,t.reconnectMaxDelay)}function re(){t.mode==="fetch"?He():I()}let oe={status:r,connected:o,lastMessage:s,lastEvent:i,error:a,reconnectCount:c,on(h,w){return u[h].push(w),()=>{let C=u[h],O=C.indexOf(w);O>=0&&C.splice(O,1)}},pipe(h,w){let C=O=>{h.value=w(O,h.value)};return oe.on("message",C)},close(){f=!0,p&&(clearTimeout(p),p=null),m&&(m.close(),m=null),y&&(y.abort(),y=null),r.value="closed",o.value=!1}};return re(),oe}var Ce={connect:ut};var xe={read:e=>JSON.parse(e),write:e=>JSON.stringify(e)},Ae=/(token|password|passwd|secret|api[_-]?key|apikey|auth(?!or)|credential|jwt|bearer|otp|seed|private[_-]?key|session[_-]?id)/i,dt=/^[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}$/,ft=/^[A-Za-z0-9+/_=-]{40,}$/,Ie=new Set;function Oe(e,n){if(Ae.test(e))return`key name "${e}" looks like a credential`;if(typeof n=="string"){if(dt.test(n))return"value looks like a JWT";if(n.length>=40&&ft.test(n))return"value looks like a long base64 / token"}if(n&&typeof n=="object"&&!Array.isArray(n)){for(let t of Object.keys(n))if(Ae.test(t))return`object contains a credential-shape field "${t}"`}return null}function Me(e,n){Ie.has(n)||(Ie.add(n),console.warn(`[tina4 persist] ${e} (key: ${JSON.stringify(n)}). localStorage is XSS-readable and never appropriate for credentials, tokens, passwords, personal data, or secrets. See STORAGE.md.`))}function Le(e){if(typeof globalThis>"u")return null;try{let n=e==="local"?globalThis.localStorage:globalThis.sessionStorage;return!n||typeof n.getItem!="function"?null:n}catch{return null}}function Pe(e,n){let{key:t,storage:r="local",serializer:o=xe,version:s=1,migrate:i,syncTabs:a=!1,silenceCredentialWarning:c=!1}=n;if(!t||typeof t!="string")throw new Error("[tina4 persist] options.key is required and must be a string");let u=o===xe,m=Le(r);if(!m)return Ne(e,()=>{},()=>{});try{let l=m.getItem(t);if(l!==null){let p,d;try{let v=JSON.parse(l);v&&typeof v=="object"&&"value"in v?(p=v.v,d=v.value):d=v}catch{d=u?l:o.read(l)}if(p===s||p===void 0){let v=u?d:o.read(typeof d=="string"?d:JSON.stringify(d));e.value=v}else if(i)try{e.value=i(d,p)}catch(v){console.warn(`[tina4 persist] migrate() threw for key "${t}":`,v)}else console.warn(`[tina4 persist] stored version ${p} does not match current ${s} for key "${t}", and no migrate() was provided. Discarding the stored value.`)}}catch(l){console.warn(`[tina4 persist] failed to read key "${t}":`,l)}if(!c){let l=Oe(t,e.peek());l&&Me(l,t)}let y=k(()=>{let l=e.value;if(!c){let p=Oe(t,l);p&&Me(p,t)}try{let d=JSON.stringify(u?{v:s,value:l}:{v:s,value:o.write(l)});m.setItem(t,d)}catch(p){console.warn(`[tina4 persist] failed to write key "${t}":`,p)}}),f=null;if(a&&typeof globalThis<"u"&&"addEventListener"in globalThis){let l=p=>{let d=p;if(d.storageArea===m&&d.key===t&&d.newValue!==null)try{let v=JSON.parse(d.newValue),T=v&&typeof v=="object"&&"v"in v?v.v:void 0,g=T!==void 0?v.value:v;T!==void 0&&T!==s&&i?e.value=i(g,T):(T===s||T===void 0)&&(e.value=u?g:o.read(typeof g=="string"?g:JSON.stringify(g)))}catch(v){console.warn(`[tina4 persist] failed to parse storage event for key "${t}":`,v)}};globalThis.addEventListener?.("storage",l),f=()=>{globalThis.removeEventListener?.("storage",l)}}return Ne(e,()=>{try{m.removeItem(t)}catch(l){console.warn(`[tina4 persist] failed to clear key "${t}":`,l)}},()=>{y(),f&&f()})}function Ne(e,n,t){return Object.assign(e,{clear:n,dispose:t})}function De(e,n="local"){let t=Le(n);if(t)for(let r of e)try{t.removeItem(r)}catch(o){console.warn(`[tina4 persist] failed to clear key "${r}":`,o)}}var pt=["ar","he","fa","ur","ps","dv","syr","ckb","yi"];function gt(){return globalThis.navigator?.language||"en"}function Fe(e,n="",t={}){for(let[r,o]of Object.entries(e)){let s=n?`${n}.${r}`:r;if(o!==null&&typeof o=="object"&&!Array.isArray(o))Fe(o,s,t);else{let i=String(o);t[s]=i,r in t||(t[r]=i)}}return t}function mt(e,n){return e.replace(/\{(\w+)\}/g,(t,r)=>Object.prototype.hasOwnProperty.call(n,r)?String(n[r]):t)}function ne(e={}){let n=e.locale||gt(),t=e.fallbackLocale||n,r=new Set([...pt,...e.rtlLocales||[]]),o=S(n,"i18n.locale"),s=new Map,i=new Map;function a(f,l){let p=Fe(l),d=s.get(f);s.set(f,d?{...d,...p}:p)}if(e.messages)for(let[f,l]of Object.entries(e.messages))a(f,l);function c(f,l){return s.get(f)?.[l]}function u(f,l){let p=`n|${f}|${JSON.stringify(l||{})}`,d=i.get(p);return d||(d=new Intl.NumberFormat(f,l),i.set(p,d)),d}function m(f,l){let p=`d|${f}|${JSON.stringify(l||{})}`,d=i.get(p);return d||(d=new Intl.DateTimeFormat(f,l),i.set(p,d)),d}function y(f,l){let p=`r|${f}|${JSON.stringify(l||{})}`,d=i.get(p);return d||(d=new Intl.RelativeTimeFormat(f,l),i.set(p,d)),d}return{locale:o,t(f,l){let p=o.value,d=c(p,f);return d===void 0&&t!==p&&(d=c(t,f)),d===void 0&&(d=f),l?mt(d,l):d},setLocale(f){o.value=f},getLocale(){return o.value},addMessages:a,hasLocale(f){return s.has(f)},availableLocales(){return[...s.keys()].sort()},async loadMessages(f,l){let p=await fetch(l);if(!p.ok)throw new Error(`[tina4 i18n] failed to load "${f}" from ${l}: ${p.status}`);a(f,await p.json())},number(f,l){return u(o.value,l).format(f)},currency(f,l,p){return u(o.value,{style:"currency",currency:l,...p}).format(f)},date(f,l){let p=f instanceof Date?f:new Date(f);return m(o.value,l).format(p)},relativeTime(f,l,p){return y(o.value,p||{numeric:"auto"}).format(f,l)},isRTL(){return r.has(o.value.split("-")[0].toLowerCase())},dir(){return this.isRTL()?"rtl":"ltr"}}}var qe=ne();return Be(ht);})();
|
data/lib/tina4/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tina4ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.13.
|
|
4
|
+
version: 3.13.49
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tina4 Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-07-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|