@plaidev/karte-action-sdk 1.1.176 → 1.1.177-28040266.37adb031

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,8 +1,33 @@
1
- import { linear, elasticOut, cubicOut } from 'svelte/easing';
2
1
  import { writable, get } from 'svelte/store';
3
2
  import { onMount as onMount$1, onDestroy as onDestroy$1, beforeUpdate as beforeUpdate$1, afterUpdate as afterUpdate$1, tick as tick$1, setContext, getContext, createEventDispatcher } from 'svelte';
4
3
  import { SvelteComponent, init, safe_not_equal, create_slot, update_slot_base, get_all_dirty_from_scope, get_slot_changes, transition_in, transition_out, append_styles, empty, insert, group_outros, check_outros, detach, component_subscribe, element, space, attr, noop, listen, null_to_empty, is_function, create_component, mount_component, destroy_component, add_render_callback, create_in_transition, binding_callbacks, set_style, svg_element, append, destroy_each, text, set_data, src_url_equal, HtmlTag, construct_svelte_component, subscribe } from 'svelte/internal';
4
+ import { linear, elasticOut, cubicOut } from 'svelte/easing';
5
+
6
+ /** @internal */
7
+ const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
8
+ /** @internal */
9
+ const KARTE_ACTION_ROOT = 'karte-action-root';
10
+ /** @internal */
11
+ const KARTE_ACTION_RID = 'karte-action-rid';
12
+ /** @internal */
13
+ const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
14
+ /** @internal */
15
+ const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
16
+ /** @internal */
17
+ const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
18
+ // -------- The following codes are deprecated --------
19
+ /**
20
+ * 非推奨
21
+ *
22
+ * @deprecated 非推奨
23
+ *
24
+ * @internal
25
+ */
26
+ const KARTE_MODAL_ROOT = 'karte-modal-root';
5
27
 
28
+ /**
29
+ * 静的変数に関連するコードを管理する
30
+ */
6
31
  /** @internal */
7
32
  const PropTypes = [
8
33
  'BooleanKeyword',
@@ -247,21 +272,13 @@ const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused
247
272
  const isPreview = () => {
248
273
  return false;
249
274
  };
275
+ // prettier-ignore
250
276
  /** @internal */
251
- const handleFocus = (node) => (e) => {
252
- if (node) {
253
- // trap focus
254
- const nodes = node.querySelectorAll('*');
255
- const tabbable = Array.from(nodes).filter((n) => n.tabIndex >= 0);
256
- let index = tabbable.indexOf(document.activeElement);
257
- if (index === -1 && e.shiftKey)
258
- index = 0;
259
- index += tabbable.length + (e.shiftKey ? -1 : 1);
260
- index %= tabbable.length;
261
- tabbable[index].focus();
262
- e.preventDefault();
263
- }
264
- };
277
+ const actionId = typeof __FIX_ACTION_CHANGE_STATE_EVENT__ === 'string'
278
+ ? __FIX_ACTION_CHANGE_STATE_EVENT__
279
+ : typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
280
+ ? __FLYER_GEN_ACTION_ID_ON_BUILD__
281
+ : randStr();
265
282
  /** @internal */
266
283
  const setPreviousFocus = () => {
267
284
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -449,6 +466,23 @@ function randStr(digit = 8) {
449
466
  function getGoogleFontsParam() {
450
467
  return 'family=' + Fonts.map(font => font.replace(/ /g, '+')).join('&family=');
451
468
  }
469
+ /** @internal */
470
+ const h = (type, props, ...children) => {
471
+ const el = document.createElement(type);
472
+ for (const key of Object.keys(props)) {
473
+ const v = props[key];
474
+ if (key === 'style') {
475
+ Object.assign(el.style, v);
476
+ }
477
+ else {
478
+ el.setAttribute(key, v);
479
+ }
480
+ }
481
+ for (const child of children) {
482
+ el.appendChild(child);
483
+ }
484
+ return el;
485
+ };
452
486
 
453
487
  /**
454
488
  * Store to handle action setting
@@ -809,446 +843,123 @@ function resetVariables() {
809
843
  */
810
844
  const formData = writable({});
811
845
 
812
- function isEmpty(value) {
813
- if (Array.isArray(value)) {
814
- return value.length === 0;
815
- }
816
- else {
817
- return !value;
818
- }
819
- }
846
+ /**
847
+ * アクションのログの記録の管理
848
+ */
849
+ const MESSAGES_LIMIT = 1000;
850
+ const EVENTS_LIMIT = 1000;
851
+ // 実行ログ
852
+ let logs = [];
853
+ // KARTEイベント
854
+ let events = [];
820
855
  /** @internal */
821
- function registerInput({ name, statePath, validator = () => true, initialValue, }) {
822
- const writableValue = {
823
- subscribe(run) {
824
- return formData.subscribe(formData => {
825
- run(formData[name]?.value);
826
- });
827
- },
828
- set(value) {
829
- formData.update(prev => ({
830
- ...prev,
831
- [name]: {
832
- statePath,
833
- value,
834
- isValid: validator(value),
835
- },
836
- }));
837
- },
838
- update(updater) {
839
- formData.update(prev => {
840
- const prevValue = prev[name]?.value;
841
- return {
842
- ...prev,
843
- [name]: {
844
- statePath,
845
- value: updater(prevValue),
846
- isValid: validator(prevValue),
847
- },
848
- };
849
- });
850
- },
851
- };
852
- if (isEmpty(get(writableValue))) {
853
- writableValue.set(initialValue);
854
- }
855
- return writableValue;
856
+ function getLogs() {
857
+ return logs;
856
858
  }
857
859
  /** @internal */
858
- const getValuesAreValidReader = statePath => ({
859
- subscribe(callback) {
860
- return formData.subscribe(formData => {
861
- const valuesAreValid = Object.entries(formData)
862
- .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
863
- .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
864
- callback(valuesAreValid);
865
- });
860
+ function getEvents() {
861
+ return events;
862
+ }
863
+ // iframe内の場合は親windowを参照する
864
+ function w(w) {
865
+ return w.parent === w ? w : w.parent;
866
+ }
867
+ /**
868
+ * ログを送信する関数群
869
+ *
870
+ * @internal
871
+ */
872
+ const logger = {
873
+ info: (...messages) => {
874
+ const log = cloneToJson({ level: 'info', messages, date: new Date() });
875
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
866
876
  },
867
- });
868
- function formDataToEventValues(campaignId, formData) {
869
- const questions = [];
870
- const answersMap = {};
871
- Object.entries(formData).forEach(([name, dataItem]) => {
872
- questions.push(name);
873
- const value = dataItem.value;
874
- const answerKey = `question_${name}`;
875
- if (Array.isArray(value)) {
876
- answersMap[answerKey] = {
877
- choices: value,
878
- };
877
+ log: (...messages) => {
878
+ const log = cloneToJson({ level: 'info', messages, date: new Date() });
879
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
880
+ },
881
+ error: (...messages) => {
882
+ const log = cloneToJson({ level: 'error', messages, date: new Date() });
883
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
884
+ },
885
+ warn: (...messages) => {
886
+ const log = cloneToJson({ level: 'warn', messages, date: new Date() });
887
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
888
+ },
889
+ system: (...messages) => {
890
+ const log = cloneToJson({ level: 'system', messages, date: new Date() });
891
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
892
+ },
893
+ event: (name, values) => {
894
+ const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
895
+ w(window).postMessage({
896
+ type: 'KARTE-ACTION-LOGGER',
897
+ detail: { method: 'event', event, values: values },
898
+ }, '*');
899
+ },
900
+ clear: () => {
901
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
902
+ },
903
+ clearEvents: () => {
904
+ w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
905
+ },
906
+ };
907
+ /**
908
+ * メッセージを実行ログに表示する
909
+ *
910
+ * @internal
911
+ */
912
+ function listenLogger() {
913
+ const handler = (event) => {
914
+ const { type, detail } = event.data;
915
+ if (event.origin !== location.origin) {
916
+ return;
879
917
  }
880
- else if (typeof value === 'string') {
881
- answersMap[answerKey] = {
882
- free_answer: value,
883
- };
918
+ if (type !== 'KARTE-ACTION-LOGGER') {
919
+ return;
884
920
  }
885
- });
886
- return {
887
- [campaignId]: {
888
- questions,
889
- ...answersMap,
890
- },
921
+ if (detail.method === 'clear') {
922
+ logs = [];
923
+ }
924
+ else if (detail.method === 'clearEvents') {
925
+ events = [];
926
+ }
927
+ else if (detail.method === 'log') {
928
+ if (MESSAGES_LIMIT <= logs.length) {
929
+ logs.shift();
930
+ }
931
+ const { level, messages } = detail.log;
932
+ const log = { level, messages, date: new Date() };
933
+ logs.push(log);
934
+ }
935
+ else if (detail.method === 'event') {
936
+ if (EVENTS_LIMIT <= events.length) {
937
+ events.shift();
938
+ }
939
+ const { name, values } = detail.event;
940
+ const karteEvent = values
941
+ ? { name, values, date: new Date() }
942
+ : { name, date: new Date() };
943
+ events.push(karteEvent);
944
+ }
945
+ };
946
+ window.addEventListener('message', handler, false);
947
+ return () => {
948
+ window.removeEventListener('message', handler, false);
891
949
  };
892
950
  }
893
- /** @internal */
894
- function submit() {
895
- const systemConfig = getSystem();
896
- const campaignId = systemConfig.campaignId;
897
- if (campaignId) {
898
- const formData$1 = get(formData);
899
- const values = formDataToEventValues(campaignId, formData$1);
900
- return values;
901
- }
902
- return {};
903
- }
904
-
905
- /** @internal */
906
- const ALL_ACTION_ID = 'KARTE_ALL_ACTION_ID';
907
- /** @internal */
908
- const ALL_ACTION_SHORTEN_ID = 'KARTE_ALL_ACTION_SHORTEN_ID';
909
- // prettier-ignore
910
- /** @internal */
911
- const actionId = typeof __FIX_ACTION_CHANGE_STATE_EVENT__ === 'string'
912
- ? __FIX_ACTION_CHANGE_STATE_EVENT__
913
- : typeof __FLYER_GEN_ACTION_ID_ON_BUILD__ === 'string'
914
- ? __FLYER_GEN_ACTION_ID_ON_BUILD__
915
- : randStr();
916
- /** @internal */
917
- const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
918
- /** @internal */
919
- const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
920
- /** @internal */
921
- const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
922
- /** @internal */
923
- const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
924
- /** @internal */
925
- const handleState = (event) => {
926
- if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
927
- send_event('_message_state_changed', { state: event.detail.to });
928
- setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
929
- }
930
- };
931
- /** @internal */
932
- const initialize = (setting) => {
933
- const newSetting = setSetting(setting);
934
- if (newSetting.initialState) {
935
- setState$1(newSetting.initialState);
936
- }
937
- setOpened(true);
938
- setClosed(false); // deprecated
939
- return () => finalize();
940
- };
941
- /** @internal */
942
- const finalize = () => {
943
- resetSetting();
944
- };
945
- /** @internal */
946
- const send_event = (event_name, values) => {
947
- const setting = getSetting();
948
- setting?.send?.(event_name, values);
949
- };
950
- function _moveTo(to) {
951
- window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
952
- }
953
- /** @internal */
954
- const moveTo = (to) => () => {
955
- _moveTo(to);
956
- };
957
- /** @internal */
958
- const linkTo = (to, targetBlank = true) => () => {
959
- send_event('message_click', { url: to, state: getState$1() });
960
- if (targetBlank) {
961
- window.open(to);
962
- }
963
- else {
964
- location.href = to;
965
- }
966
- };
967
- /** @internal */
968
- const closeApp = (trigger) => () => {
969
- window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
970
- };
971
- /** @internal */
972
- const runScript = (handlerName) => () => {
973
- const handlers = getEventHandlers();
974
- const handler = handlers[handlerName];
975
- if (!handler)
976
- return;
977
- try {
978
- handler();
979
- }
980
- catch (e) {
981
- console.warn('Failed to run custom handler', handlerName, e);
982
- }
983
- };
984
- /** @internal */
985
- const submitForm = (to) => () => {
986
- const values = submit();
987
- send_event('_answer_question', values);
988
- _moveTo(to);
989
- };
990
- /** @internal */
991
- const execOnClickOperation = (onClickOperation) => {
992
- if (onClickOperation.operation === 'linkTo') {
993
- linkTo(...onClickOperation.args)();
994
- }
995
- else if (onClickOperation.operation === 'moveTo') {
996
- moveTo(...onClickOperation.args)();
997
- }
998
- else if (onClickOperation.operation === 'closeApp') {
999
- closeApp(onClickOperation.args[0] || 'button')();
1000
- }
1001
- else if (onClickOperation.operation === 'runScript') {
1002
- runScript(onClickOperation.args[0])();
1003
- }
1004
- else if (onClickOperation.operation === 'submitForm') {
1005
- submitForm(onClickOperation.args[0])();
1006
- }
1007
- };
1008
- /** @internal */
1009
- const haveFunction = (onClickOperation) => {
1010
- return onClickOperation.operation !== 'none';
1011
- };
1012
- function getAnimation(animation) {
1013
- switch (animation.type) {
1014
- case 'fade':
1015
- return `opacity: ${animation.progress}`;
1016
- case 'bounce': {
1017
- const translateX = animation.x;
1018
- const translateY = animation.y;
1019
- return `transform: translate3d(${translateX}%, ${translateY}%, 0) scale(${animation.progress});`;
1020
- }
1021
- case 'slide-down': {
1022
- const translateX = animation.x;
1023
- const translateY = animation.y - 100 * (1 - animation.progress);
1024
- return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
1025
- }
1026
- case 'slide-up': {
1027
- const translateX = animation.x;
1028
- const translateY = animation.y + 100 * (1 - animation.progress);
1029
- return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
1030
- }
1031
- case 'slide-left': {
1032
- const translateX = animation.x + 100 * (1 - animation.progress);
1033
- const translateY = animation.y;
1034
- return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
1035
- }
1036
- case 'slide-right': {
1037
- const translateX = animation.x - 100 * (1 - animation.progress);
1038
- const translateY = animation.y;
1039
- return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
1040
- }
1041
- case 'none': {
1042
- const translateX = animation.x;
1043
- const translateY = animation.y;
1044
- return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
1045
- }
1046
- default:
1047
- console.warn(`[action-sdk] invalid '${animation}', so we use 'transform: none' instead`);
1048
- return 'transform: none';
1049
- }
1050
- }
1051
- const EASING = {
1052
- fade: linear,
1053
- bounce: elasticOut,
1054
- 'slide-down': cubicOut,
1055
- 'slide-up': cubicOut,
1056
- 'slide-left': cubicOut,
1057
- 'slide-right': cubicOut,
1058
- none: linear,
1059
- };
1060
- /**
1061
- * The function to activate svelte animation.
1062
- *
1063
- * @param node - A target node of animation. This argument is passed by svelte, by default.
1064
- * @param customAnimationOptions - A custom animation option object
1065
- *
1066
- * @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
1067
- *
1068
- * @internal
1069
- */
1070
- function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
1071
- const [x, y] = transform;
1072
- return {
1073
- delay,
1074
- duration,
1075
- easing: EASING[animationStyle],
1076
- css: (progress) => getAnimation({ type: animationStyle, x, y, progress }),
1077
- };
1078
- }
1079
- /**
1080
- * ES Modules に対応していない JavaScript をページに読み込む
1081
- *
1082
- * @param src - JavaScript ファイルのリンク URL
1083
- *
1084
- * @public
1085
- */
1086
- async function loadGlobalScript(src) {
1087
- return new Promise((resolve, reject) => {
1088
- const script = document.createElement('script');
1089
- script.src = src;
1090
- document.body.appendChild(script);
1091
- script.addEventListener('load', () => resolve(script));
1092
- script.addEventListener('error', () => reject(script));
1093
- });
1094
- }
1095
- /**
1096
- * グローバル CSS をページに適用する
1097
- *
1098
- * @param css - CSS
1099
- *
1100
- * @public
1101
- */
1102
- async function applyGlobalCss(css) {
1103
- return new Promise((resolve, reject) => {
1104
- const style = document.createElement('style');
1105
- style.textContent = css;
1106
- document.body.appendChild(style);
1107
- style.addEventListener('load', () => resolve(style));
1108
- style.addEventListener('error', () => reject(style));
1109
- });
1110
- }
1111
- /**
1112
- * style ファイルをページに読み込む
1113
- *
1114
- * @param href - style ファイルのリンク URL
1115
- *
1116
- * @public
1117
- */
1118
- async function loadGlobalStyle(href) {
1119
- return new Promise((resolve, reject) => {
1120
- const link = document.createElement('link');
1121
- link.rel = 'stylesheet';
1122
- link.href = href;
1123
- document.body.appendChild(link);
1124
- link.addEventListener('load', () => resolve(link));
1125
- link.addEventListener('error', () => reject(link));
1126
- });
1127
- }
1128
- // @internal
1129
- function getCssVariables(data) {
1130
- return Object.entries(data)
1131
- .filter(([key, value]) => {
1132
- return ['string', 'number'].includes(typeof value) && key.startsWith('--');
1133
- })
1134
- .map(([key, value]) => `${key}:${value}`)
1135
- .join(';');
1136
- }
1137
-
1138
- /**
1139
- * アクションのログの記録の管理
1140
- */
1141
- const MESSAGES_LIMIT = 1000;
1142
- const EVENTS_LIMIT = 1000;
1143
- // 実行ログ
1144
- let logs = [];
1145
- // KARTEイベント
1146
- let events = [];
1147
- /** @internal */
1148
- function getLogs() {
1149
- return logs;
1150
- }
1151
- /** @internal */
1152
- function getEvents() {
1153
- return events;
1154
- }
1155
- // iframe内の場合は親windowを参照する
1156
- function w(w) {
1157
- return w.parent === w ? w : w.parent;
1158
- }
1159
- /**
1160
- * ログを送信する関数群
1161
- *
1162
- * @internal
1163
- */
1164
- const logger = {
1165
- info: (...messages) => {
1166
- const log = cloneToJson({ level: 'info', messages, date: new Date() });
1167
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1168
- },
1169
- log: (...messages) => {
1170
- const log = cloneToJson({ level: 'info', messages, date: new Date() });
1171
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1172
- },
1173
- error: (...messages) => {
1174
- const log = cloneToJson({ level: 'error', messages, date: new Date() });
1175
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1176
- },
1177
- warn: (...messages) => {
1178
- const log = cloneToJson({ level: 'warn', messages, date: new Date() });
1179
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1180
- },
1181
- system: (...messages) => {
1182
- const log = cloneToJson({ level: 'system', messages, date: new Date() });
1183
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'log', log } }, '*');
1184
- },
1185
- event: (name, values) => {
1186
- const event = values ? { name, values, date: new Date() } : { name, date: new Date() };
1187
- w(window).postMessage({
1188
- type: 'KARTE-ACTION-LOGGER',
1189
- detail: { method: 'event', event, values: values },
1190
- }, '*');
1191
- },
1192
- clear: () => {
1193
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clear' } }, '*');
1194
- },
1195
- clearEvents: () => {
1196
- w(window).postMessage({ type: 'KARTE-ACTION-LOGGER', detail: { method: 'clearEvents' } }, '*');
1197
- },
1198
- };
1199
- /**
1200
- * メッセージを実行ログに表示する
1201
- *
1202
- * @internal
1203
- */
1204
- function listenLogger() {
1205
- const handler = (event) => {
1206
- const { type, detail } = event.data;
1207
- if (event.origin !== location.origin) {
1208
- return;
1209
- }
1210
- if (type !== 'KARTE-ACTION-LOGGER') {
1211
- return;
1212
- }
1213
- if (detail.method === 'clear') {
1214
- logs = [];
1215
- }
1216
- else if (detail.method === 'clearEvents') {
1217
- events = [];
1218
- }
1219
- else if (detail.method === 'log') {
1220
- if (MESSAGES_LIMIT <= logs.length) {
1221
- logs.shift();
1222
- }
1223
- const { level, messages } = detail.log;
1224
- const log = { level, messages, date: new Date() };
1225
- logs.push(log);
1226
- }
1227
- else if (detail.method === 'event') {
1228
- if (EVENTS_LIMIT <= events.length) {
1229
- events.shift();
1230
- }
1231
- const { name, values } = detail.event;
1232
- const karteEvent = values
1233
- ? { name, values, date: new Date() }
1234
- : { name, date: new Date() };
1235
- events.push(karteEvent);
1236
- }
1237
- };
1238
- window.addEventListener('message', handler, false);
1239
- return () => {
1240
- window.removeEventListener('message', handler, false);
1241
- };
1242
- }
1243
- function cloneToJson(data) {
1244
- try {
1245
- return JSON.parse(JSON.stringify(data));
1246
- }
1247
- catch (e) {
1248
- return data;
951
+ function cloneToJson(data) {
952
+ try {
953
+ return JSON.parse(JSON.stringify(data));
954
+ }
955
+ catch (e) {
956
+ return data;
1249
957
  }
1250
958
  }
1251
959
 
960
+ /**
961
+ * モーダル(ポップアップ)のロジックを管理する
962
+ */
1252
963
  function doPresent({ direction, deltaRate }, downFn, upFn, condition = false) {
1253
964
  if (direction === 'down' && deltaRate > 0) {
1254
965
  downFn();
@@ -1393,6 +1104,23 @@ function checkAndDo(checkFn, fn, ...conditionFns) {
1393
1104
  return haveCondition ? cleanupAll : null;
1394
1105
  }
1395
1106
 
1107
+ /** @internal */
1108
+ const ACTION_DESTROY_EVENT = `KARTE-ACTION-DESTROY-${actionId}`;
1109
+ /** @internal */
1110
+ const ACTION_SHOW_EVENT = `KARTE-ACTION-SHOW-${actionId}`;
1111
+ /** @internal */
1112
+ const ACTION_CLOSE_EVENT = `KARTE-ACTION-CLOSE-${actionId}`;
1113
+ /** @internal */
1114
+ const ACTION_CHANGE_STATE_EVENT = `KARTE-ACTION-CHANGE-STATE-${actionId}`;
1115
+ /** @internal */
1116
+ const send_event = (event_name, values) => {
1117
+ const setting = getSetting();
1118
+ setting?.send?.(event_name, values);
1119
+ };
1120
+
1121
+ /**
1122
+ * アクションテーブルに関連するコードの管理
1123
+ */
1396
1124
  const DEFAULT_COLLECTION_ENDPOINT = typeof __FLYER_GEN_COLLECTION_API_ENDPOINT__ === 'string'
1397
1125
  ? __FLYER_GEN_COLLECTION_API_ENDPOINT__
1398
1126
  : 'https://t.karte.io/collection';
@@ -1498,83 +1226,34 @@ const loadActionTable = async (config, api_key, endpoint) => {
1498
1226
  }, {});
1499
1227
  };
1500
1228
 
1501
- /** @internal */
1502
- const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
1503
- /**
1504
- * アクションが作成 (create) される前にフックする関数
1505
- *
1506
- * @param fn - 呼び出されるフック関数
1507
- *
1508
- * @public
1509
- */
1510
- function onCreate(fn) {
1511
- let { onCreateHandlers } = getInternalHandlers();
1512
- if (!onCreateHandlers) {
1513
- onCreateHandlers = [];
1514
- }
1515
- onCreateHandlers.push(fn);
1516
- setInternalHandlers({ onCreateHandlers });
1517
- }
1518
- /**
1519
- * アクションが表示 (show) された後にフックする関数
1520
- *
1521
- * @param fn - 呼び出されるフック関数
1522
- *
1523
- * @public
1524
- */
1525
- function onShow(fn) {
1526
- let { onShowHandlers } = getInternalHandlers();
1527
- if (!onShowHandlers) {
1528
- onShowHandlers = [];
1529
- }
1530
- onShowHandlers.push(fn);
1531
- setInternalHandlers({ onShowHandlers });
1532
- }
1533
- /**
1534
- * アクションがクローズ (close) される前にフックする関数
1535
- *
1536
- * @param fn - 呼び出されるフック関数
1537
- *
1538
- * @public
1539
- */
1540
- function onClose(fn) {
1541
- let { onCloseHandlers } = getInternalHandlers();
1542
- if (!onCloseHandlers) {
1543
- onCloseHandlers = [];
1544
- }
1545
- onCloseHandlers.push(fn);
1546
- setInternalHandlers({ onCloseHandlers });
1547
- }
1548
1229
  /**
1549
- * アクションが破棄 (destroy) される前にフックする関数
1230
+ * Edgeが起動するアクションに関連するコードを管理する
1550
1231
  *
1551
- * @param fn - 呼び出されるフック関数
1232
+ * アクションのCreate, Destroyの状態はここで管理する。
1552
1233
  *
1553
- * @public
1234
+ * FIXME: モーダルなどの機能ごとのコードを分離したい
1554
1235
  */
1555
- function onDestroy(fn) {
1556
- let { onDestroyHandlers } = getInternalHandlers();
1557
- if (!onDestroyHandlers) {
1558
- onDestroyHandlers = [];
1236
+ /** @internal */
1237
+ const handleState = (event) => {
1238
+ if (event.detail.actionId === actionId || event.detail.actionId === ALL_ACTION_ID) {
1239
+ send_event('_message_state_changed', { state: event.detail.to });
1240
+ setState$1(event.detail.to, { disableInPreview: event.detail.disableInPreview });
1559
1241
  }
1560
- onDestroyHandlers.push(fn);
1561
- setInternalHandlers({ onDestroyHandlers });
1562
- }
1563
- /**
1564
- * アクションのステートが変更された (changeState) 後にフックする関数
1565
- *
1566
- * @param fn - 呼び出されるフック関数
1567
- *
1568
- * @public
1569
- */
1570
- function onChangeState(fn) {
1571
- let { onChangeStateHandlers } = getInternalHandlers();
1572
- if (!onChangeStateHandlers) {
1573
- onChangeStateHandlers = [];
1242
+ };
1243
+ /** @internal */
1244
+ const initialize = (setting) => {
1245
+ const newSetting = setSetting(setting);
1246
+ if (newSetting.initialState) {
1247
+ setState$1(newSetting.initialState);
1574
1248
  }
1575
- onChangeStateHandlers.push(fn);
1576
- setInternalHandlers({ onChangeStateHandlers });
1577
- }
1249
+ setOpened(true);
1250
+ setClosed(false); // deprecated
1251
+ return () => finalize();
1252
+ };
1253
+ /** @internal */
1254
+ const finalize = () => {
1255
+ resetSetting();
1256
+ };
1578
1257
  /**
1579
1258
  * アクションを作成する
1580
1259
  *
@@ -1789,92 +1468,154 @@ function create(App, options = {
1789
1468
  window.removeEventListener(ACTION_DESTROY_EVENT, handleDestroy);
1790
1469
  window.removeEventListener('beforeunload', dispatchDestroyEvent, false);
1791
1470
  };
1792
- return appCleanup;
1471
+ return appCleanup;
1472
+ }
1473
+ /** @internal */
1474
+ function ensureActionRoot(useShadow = true) {
1475
+ const systemConfig = getSystem();
1476
+ const rootAttrs = {
1477
+ class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
1478
+ [`data-${KARTE_ACTION_RID}`]: actionId,
1479
+ [`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
1480
+ ? systemConfig.shortenId
1481
+ : ALL_ACTION_SHORTEN_ID,
1482
+ };
1483
+ let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1484
+ if (el == null) {
1485
+ el = h('div', rootAttrs);
1486
+ document.body.appendChild(el);
1487
+ }
1488
+ const isShadow = !!document.body.attachShadow && useShadow;
1489
+ if (isShadow) {
1490
+ return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
1491
+ }
1492
+ else {
1493
+ return el;
1494
+ }
1495
+ }
1496
+ /**
1497
+ * Dispatch the event to destroy KARTE action
1498
+ *
1499
+ * @internal
1500
+ */
1501
+ function dispatchDestroyEvent() {
1502
+ const event = new CustomEvent(ACTION_DESTROY_EVENT);
1503
+ window.dispatchEvent(event);
1504
+ }
1505
+ /**
1506
+ * アクションの破棄する
1507
+ *
1508
+ * @public
1509
+ */
1510
+ function destroyAction() {
1511
+ setDestroyed(true);
1512
+ dispatchDestroyEvent();
1513
+ }
1514
+ /**
1515
+ * アクションが作成 (create) される前にフックする関数
1516
+ *
1517
+ * @param fn - 呼び出されるフック関数
1518
+ *
1519
+ * @public
1520
+ */
1521
+ function onCreate(fn) {
1522
+ let { onCreateHandlers } = getInternalHandlers();
1523
+ if (!onCreateHandlers) {
1524
+ onCreateHandlers = [];
1525
+ }
1526
+ onCreateHandlers.push(fn);
1527
+ setInternalHandlers({ onCreateHandlers });
1528
+ }
1529
+ /**
1530
+ * アクションが破棄 (destroy) される前にフックする関数
1531
+ *
1532
+ * @param fn - 呼び出されるフック関数
1533
+ *
1534
+ * @public
1535
+ */
1536
+ function onDestroy(fn) {
1537
+ let { onDestroyHandlers } = getInternalHandlers();
1538
+ if (!onDestroyHandlers) {
1539
+ onDestroyHandlers = [];
1540
+ }
1541
+ onDestroyHandlers.push(fn);
1542
+ setInternalHandlers({ onDestroyHandlers });
1543
+ }
1544
+ /**
1545
+ * 非推奨
1546
+ *
1547
+ * @deprecated 非推奨
1548
+ *
1549
+ * @internal
1550
+ */
1551
+ const showModal = create;
1552
+ /**
1553
+ * 非推奨
1554
+ *
1555
+ * @deprecated 非推奨
1556
+ *
1557
+ * @internal
1558
+ */
1559
+ const ensureModalRoot = ensureActionRoot;
1560
+ /**
1561
+ * 非推奨
1562
+ *
1563
+ * @deprecated 非推奨
1564
+ *
1565
+ * @internal
1566
+ */
1567
+ function createApp(App, options = {
1568
+ send: () => { },
1569
+ publish: () => { },
1570
+ props: {},
1571
+ variables: {},
1572
+ localVariablesQuery: undefined,
1573
+ }) {
1574
+ let app = null;
1575
+ const close = () => {
1576
+ if (app) {
1577
+ app.$destroy();
1578
+ app = null;
1579
+ }
1580
+ };
1581
+ const appArgs = {
1582
+ target: null,
1583
+ props: {
1584
+ send: options.send,
1585
+ publish: options.publish,
1586
+ close,
1587
+ data: {
1588
+ ...options.props,
1589
+ ...options.variables,
1590
+ },
1591
+ },
1592
+ };
1593
+ {
1594
+ const win = ensureModalRoot(true);
1595
+ appArgs.target = win;
1596
+ }
1597
+ return {
1598
+ close,
1599
+ show: () => {
1600
+ if (app) {
1601
+ return;
1602
+ }
1603
+ options.send('message_open');
1604
+ app = new App(appArgs);
1605
+ },
1606
+ };
1793
1607
  }
1794
1608
  /**
1795
- * Dispatch the event to destroy KARTE action
1609
+ * 非推奨
1796
1610
  *
1797
- * @internal
1798
- */
1799
- function dispatchDestroyEvent() {
1800
- const event = new CustomEvent(ACTION_DESTROY_EVENT);
1801
- window.dispatchEvent(event);
1802
- }
1803
- /**
1804
- * アクションの破棄する
1611
+ * @deprecated 非推奨
1805
1612
  *
1806
- * @public
1613
+ * @internal
1807
1614
  */
1808
- function destroyAction() {
1615
+ function destroy() {
1809
1616
  setDestroyed(true);
1810
1617
  dispatchDestroyEvent();
1811
1618
  }
1812
- /**
1813
- * アクションを表示する
1814
- *
1815
- * @public
1816
- */
1817
- function showAction() {
1818
- const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
1819
- window.dispatchEvent(event);
1820
- }
1821
- /**
1822
- * アクションを閉じる
1823
- *
1824
- * @param trigger - 閉じた時のトリガー。デフォルト `'none'`
1825
- *
1826
- * @public
1827
- */
1828
- function closeAction(trigger = 'none') {
1829
- const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
1830
- window.dispatchEvent(event);
1831
- }
1832
- /** @internal */
1833
- const KARTE_ACTION_ROOT = 'karte-action-root';
1834
- /** @internal */
1835
- const KARTE_ACTION_RID = 'karte-action-rid';
1836
- /** @internal */
1837
- const KARTE_ACTION_SHORTEN_ID = 'karte-action-id';
1838
- /** @internal */
1839
- function ensureActionRoot(useShadow = true) {
1840
- const systemConfig = getSystem();
1841
- const rootAttrs = {
1842
- class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
1843
- [`data-${KARTE_ACTION_RID}`]: actionId,
1844
- [`data-${KARTE_ACTION_SHORTEN_ID}`]: systemConfig.shortenId
1845
- ? systemConfig.shortenId
1846
- : ALL_ACTION_SHORTEN_ID,
1847
- };
1848
- let el = document.querySelector(`.${KARTE_MODAL_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1849
- if (el == null) {
1850
- el = h('div', rootAttrs);
1851
- document.body.appendChild(el);
1852
- }
1853
- const isShadow = !!document.body.attachShadow && useShadow;
1854
- if (isShadow) {
1855
- return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
1856
- }
1857
- else {
1858
- return el;
1859
- }
1860
- }
1861
- /** @internal */
1862
- const h = (type, props, ...children) => {
1863
- const el = document.createElement(type);
1864
- for (const key of Object.keys(props)) {
1865
- const v = props[key];
1866
- if (key === 'style') {
1867
- Object.assign(el.style, v);
1868
- }
1869
- else {
1870
- el.setAttribute(key, v);
1871
- }
1872
- }
1873
- for (const child of children) {
1874
- el.appendChild(child);
1875
- }
1876
- return el;
1877
- };
1878
1619
  /**
1879
1620
  * 非推奨
1880
1621
  *
@@ -1907,19 +1648,129 @@ function createFog({ color = '#000', opacity = '50%', zIndex = 999, onclick, })
1907
1648
  root.appendChild(fog);
1908
1649
  return { fog, close };
1909
1650
  }
1651
+
1910
1652
  /**
1911
- * アクションのルートの DOM 要素を取得する
1653
+ * スクリプト接客が利用するコードの管理
1654
+ */
1655
+ /**
1656
+ * ES Modules に対応していない JavaScript をページに読み込む
1912
1657
  *
1913
- * @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
1658
+ * @param src - JavaScript ファイルのリンク URL
1914
1659
  *
1915
1660
  * @public
1916
1661
  */
1917
- function getActionRoot() {
1918
- const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1919
- if (!root?.shadowRoot) {
1920
- return null;
1662
+ async function loadGlobalScript(src) {
1663
+ return new Promise((resolve, reject) => {
1664
+ const script = document.createElement('script');
1665
+ script.src = src;
1666
+ document.body.appendChild(script);
1667
+ script.addEventListener('load', () => resolve(script));
1668
+ script.addEventListener('error', () => reject(script));
1669
+ });
1670
+ }
1671
+ /**
1672
+ * グローバル CSS をページに適用する
1673
+ *
1674
+ * @param css - CSS
1675
+ *
1676
+ * @public
1677
+ */
1678
+ async function applyGlobalCss(css) {
1679
+ return new Promise((resolve, reject) => {
1680
+ const style = document.createElement('style');
1681
+ style.textContent = css;
1682
+ document.body.appendChild(style);
1683
+ style.addEventListener('load', () => resolve(style));
1684
+ style.addEventListener('error', () => reject(style));
1685
+ });
1686
+ }
1687
+ /**
1688
+ * style ファイルをページに読み込む
1689
+ *
1690
+ * @param href - style ファイルのリンク URL
1691
+ *
1692
+ * @public
1693
+ */
1694
+ async function loadGlobalStyle(href) {
1695
+ return new Promise((resolve, reject) => {
1696
+ const link = document.createElement('link');
1697
+ link.rel = 'stylesheet';
1698
+ link.href = href;
1699
+ document.body.appendChild(link);
1700
+ link.addEventListener('load', () => resolve(link));
1701
+ link.addEventListener('error', () => reject(link));
1702
+ });
1703
+ }
1704
+
1705
+ /**
1706
+ * モーダル(ポップアップ)に関連するコードの管理
1707
+ *
1708
+ * アクションのShow, Close, ChangeStateの状態はここで管理する。
1709
+ */
1710
+ /**
1711
+ * アクションが表示 (show) された後にフックする関数
1712
+ *
1713
+ * @param fn - 呼び出されるフック関数
1714
+ *
1715
+ * @public
1716
+ */
1717
+ function onShow(fn) {
1718
+ let { onShowHandlers } = getInternalHandlers();
1719
+ if (!onShowHandlers) {
1720
+ onShowHandlers = [];
1921
1721
  }
1922
- return root.shadowRoot;
1722
+ onShowHandlers.push(fn);
1723
+ setInternalHandlers({ onShowHandlers });
1724
+ }
1725
+ /**
1726
+ * アクションがクローズ (close) される前にフックする関数
1727
+ *
1728
+ * @param fn - 呼び出されるフック関数
1729
+ *
1730
+ * @public
1731
+ */
1732
+ function onClose(fn) {
1733
+ let { onCloseHandlers } = getInternalHandlers();
1734
+ if (!onCloseHandlers) {
1735
+ onCloseHandlers = [];
1736
+ }
1737
+ onCloseHandlers.push(fn);
1738
+ setInternalHandlers({ onCloseHandlers });
1739
+ }
1740
+ /**
1741
+ * アクションのステートが変更された (changeState) 後にフックする関数
1742
+ *
1743
+ * @param fn - 呼び出されるフック関数
1744
+ *
1745
+ * @public
1746
+ */
1747
+ function onChangeState(fn) {
1748
+ let { onChangeStateHandlers } = getInternalHandlers();
1749
+ if (!onChangeStateHandlers) {
1750
+ onChangeStateHandlers = [];
1751
+ }
1752
+ onChangeStateHandlers.push(fn);
1753
+ setInternalHandlers({ onChangeStateHandlers });
1754
+ }
1755
+ /**
1756
+ * アクションを表示する
1757
+ *
1758
+ * @public
1759
+ */
1760
+ function showAction() {
1761
+ const event = new CustomEvent(ACTION_SHOW_EVENT, { detail: { trigger: 'custom' } });
1762
+ window.dispatchEvent(event);
1763
+ }
1764
+ /**
1765
+ * アクションを閉じる
1766
+ *
1767
+ * @param trigger - 閉じた時のトリガー。デフォルト `'none'`
1768
+ *
1769
+ * @public
1770
+ */
1771
+ function closeAction(trigger = 'none') {
1772
+ const event = new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } });
1773
+ window.dispatchEvent(event);
1923
1774
  }
1924
1775
  /**
1925
1776
  * アクションに CSS を適用する
@@ -1934,7 +1785,7 @@ async function applyCss(css) {
1934
1785
  return new Promise((resolve, reject) => {
1935
1786
  const style = document.createElement('style');
1936
1787
  style.textContent = css;
1937
- const shadowRoot = getActionShadowRoot();
1788
+ const shadowRoot = getActionRoot();
1938
1789
  if (!shadowRoot)
1939
1790
  return;
1940
1791
  shadowRoot.append(style);
@@ -1973,7 +1824,7 @@ async function fixFontFaceIssue(href, cssRules) {
1973
1824
  * @public
1974
1825
  */
1975
1826
  async function loadStyle(href) {
1976
- const sr = getActionShadowRoot();
1827
+ const sr = getActionRoot();
1977
1828
  if (!sr)
1978
1829
  return;
1979
1830
  let cssRules = '';
@@ -2002,95 +1853,30 @@ async function loadStyle(href) {
2002
1853
  // @ts-ignore
2003
1854
  document.adoptedStyleSheets = [...document.adoptedStyleSheets, css, fontFaceCss];
2004
1855
  }
2005
- // -------- The following codes are deprecated --------
2006
- /**
2007
- * 非推奨
2008
- *
2009
- * @deprecated 非推奨
2010
- *
2011
- * @internal
2012
- */
2013
- const showModal = create;
2014
- /**
2015
- * 非推奨
2016
- *
2017
- * @deprecated 非推奨
2018
- *
2019
- * @internal
2020
- */
2021
- const KARTE_MODAL_ROOT = 'karte-modal-root';
2022
- /**
2023
- * 非推奨
2024
- *
2025
- * @deprecated 非推奨
2026
- *
2027
- * @internal
2028
- */
2029
- const ensureModalRoot = ensureActionRoot;
2030
- /**
2031
- * 非推奨
2032
- *
2033
- * @deprecated 非推奨
2034
- *
2035
- * @internal
2036
- */
2037
- const show = showAction;
2038
- /**
2039
- * 非推奨
2040
- *
2041
- * @deprecated 非推奨
2042
- *
2043
- * @internal
2044
- */
2045
- const close = closeAction;
1856
+ // @internal
1857
+ function getCssVariables(data) {
1858
+ return Object.entries(data)
1859
+ .filter(([key, value]) => {
1860
+ return ['string', 'number'].includes(typeof value) && key.startsWith('--');
1861
+ })
1862
+ .map(([key, value]) => `${key}:${value}`)
1863
+ .join(';');
1864
+ }
2046
1865
  /**
2047
- * 非推奨
1866
+ * アクションのルートの DOM 要素を取得する
2048
1867
  *
2049
- * @deprecated 非推奨
1868
+ * @returns アクションがルートの DOM 要素 を持つ場合は DOM 要素を返します。ない場合は `null` を返します
2050
1869
  *
2051
- * @internal
1870
+ * @public
2052
1871
  */
2053
- function createApp(App, options = {
2054
- send: () => { },
2055
- publish: () => { },
2056
- props: {},
2057
- variables: {},
2058
- localVariablesQuery: undefined,
2059
- }) {
2060
- let app = null;
2061
- const close = () => {
2062
- if (app) {
2063
- app.$destroy();
2064
- app = null;
2065
- }
2066
- };
2067
- const appArgs = {
2068
- target: null,
2069
- props: {
2070
- send: options.send,
2071
- publish: options.publish,
2072
- close,
2073
- data: {
2074
- ...options.props,
2075
- ...options.variables,
2076
- },
2077
- },
2078
- };
2079
- {
2080
- const win = ensureModalRoot(true);
2081
- appArgs.target = win;
1872
+ function getActionRoot() {
1873
+ const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
1874
+ if (!root?.shadowRoot) {
1875
+ return null;
2082
1876
  }
2083
- return {
2084
- close,
2085
- show: () => {
2086
- if (app) {
2087
- return;
2088
- }
2089
- options.send('message_open');
2090
- app = new App(appArgs);
2091
- },
2092
- };
1877
+ return root.shadowRoot;
2093
1878
  }
1879
+ // -------- The following codes are deprecated --------
2094
1880
  /**
2095
1881
  * 非推奨
2096
1882
  *
@@ -2098,13 +1884,7 @@ function createApp(App, options = {
2098
1884
  *
2099
1885
  * @internal
2100
1886
  */
2101
- function getActionShadowRoot() {
2102
- const root = document.querySelector(`.${KARTE_ACTION_ROOT}[data-${KARTE_ACTION_RID}='${actionId}']`);
2103
- if (!root?.shadowRoot) {
2104
- return null;
2105
- }
2106
- return root.shadowRoot;
2107
- }
1887
+ const show = showAction;
2108
1888
  /**
2109
1889
  * 非推奨
2110
1890
  *
@@ -2112,13 +1892,10 @@ function getActionShadowRoot() {
2112
1892
  *
2113
1893
  * @internal
2114
1894
  */
2115
- function destroy() {
2116
- setDestroyed(true);
2117
- dispatchDestroyEvent();
2118
- }
1895
+ const close = closeAction;
2119
1896
 
2120
1897
  /**
2121
- * Widget API 互換のインターフェース
1898
+ * エディタv1のWidget API 互換のインターフェース
2122
1899
  */
2123
1900
  const STORE_LS_KEY_PREFIX = 'krt___';
2124
1901
  const valCallbacks = {};
@@ -2627,12 +2404,238 @@ function instance$w($$self, $$props, $$invalidate) {
2627
2404
 
2628
2405
  return [path, $state, $$scope, slots];
2629
2406
  }
2630
-
2631
- class StateItem extends SvelteComponent {
2632
- constructor(options) {
2633
- super();
2634
- init(this, options, instance$w, create_fragment$w, safe_not_equal, { path: 0 }, add_css$t);
2635
- }
2407
+
2408
+ class StateItem extends SvelteComponent {
2409
+ constructor(options) {
2410
+ super();
2411
+ init(this, options, instance$w, create_fragment$w, safe_not_equal, { path: 0 }, add_css$t);
2412
+ }
2413
+ }
2414
+
2415
+ function isEmpty(value) {
2416
+ if (Array.isArray(value)) {
2417
+ return value.length === 0;
2418
+ }
2419
+ else {
2420
+ return !value;
2421
+ }
2422
+ }
2423
+ /** @internal */
2424
+ function registerInput({ name, statePath, validator = () => true, initialValue, }) {
2425
+ const writableValue = {
2426
+ subscribe(run) {
2427
+ return formData.subscribe(formData => {
2428
+ run(formData[name]?.value);
2429
+ });
2430
+ },
2431
+ set(value) {
2432
+ formData.update(prev => ({
2433
+ ...prev,
2434
+ [name]: {
2435
+ statePath,
2436
+ value,
2437
+ isValid: validator(value),
2438
+ },
2439
+ }));
2440
+ },
2441
+ update(updater) {
2442
+ formData.update(prev => {
2443
+ const prevValue = prev[name]?.value;
2444
+ return {
2445
+ ...prev,
2446
+ [name]: {
2447
+ statePath,
2448
+ value: updater(prevValue),
2449
+ isValid: validator(prevValue),
2450
+ },
2451
+ };
2452
+ });
2453
+ },
2454
+ };
2455
+ if (isEmpty(get(writableValue))) {
2456
+ writableValue.set(initialValue);
2457
+ }
2458
+ return writableValue;
2459
+ }
2460
+ /** @internal */
2461
+ const getValuesAreValidReader = statePath => ({
2462
+ subscribe(callback) {
2463
+ return formData.subscribe(formData => {
2464
+ const valuesAreValid = Object.entries(formData)
2465
+ .filter(([_, { statePath: s }]) => s === statePath) // eslint-disable-line @typescript-eslint/no-unused-vars
2466
+ .every(([_, { isValid }]) => isValid); // eslint-disable-line @typescript-eslint/no-unused-vars
2467
+ callback(valuesAreValid);
2468
+ });
2469
+ },
2470
+ });
2471
+ function formDataToEventValues(campaignId, formData) {
2472
+ const questions = [];
2473
+ const answersMap = {};
2474
+ Object.entries(formData).forEach(([name, dataItem]) => {
2475
+ questions.push(name);
2476
+ const value = dataItem.value;
2477
+ const answerKey = `question_${name}`;
2478
+ if (Array.isArray(value)) {
2479
+ answersMap[answerKey] = {
2480
+ choices: value,
2481
+ };
2482
+ }
2483
+ else if (typeof value === 'string') {
2484
+ answersMap[answerKey] = {
2485
+ free_answer: value,
2486
+ };
2487
+ }
2488
+ });
2489
+ return {
2490
+ [campaignId]: {
2491
+ questions,
2492
+ ...answersMap,
2493
+ },
2494
+ };
2495
+ }
2496
+ /** @internal */
2497
+ function submit() {
2498
+ const systemConfig = getSystem();
2499
+ const campaignId = systemConfig.campaignId;
2500
+ if (campaignId) {
2501
+ const formData$1 = get(formData);
2502
+ const values = formDataToEventValues(campaignId, formData$1);
2503
+ return values;
2504
+ }
2505
+ return {};
2506
+ }
2507
+
2508
+ /**
2509
+ * モーダル(ポップアップ)のコンポーネントが利用するコードの管理
2510
+ */
2511
+ function _moveTo(to) {
2512
+ window.dispatchEvent(new CustomEvent(ACTION_CHANGE_STATE_EVENT, { detail: { to, actionId } }));
2513
+ }
2514
+ /** @internal */
2515
+ const moveTo = (to) => () => {
2516
+ _moveTo(to);
2517
+ };
2518
+ /** @internal */
2519
+ const linkTo = (to, targetBlank = true) => () => {
2520
+ send_event('message_click', { url: to, state: getState$1() });
2521
+ if (targetBlank) {
2522
+ window.open(to);
2523
+ }
2524
+ else {
2525
+ location.href = to;
2526
+ }
2527
+ };
2528
+ /** @internal */
2529
+ const closeApp = (trigger) => () => {
2530
+ window.dispatchEvent(new CustomEvent(ACTION_CLOSE_EVENT, { detail: { trigger } }));
2531
+ };
2532
+ /** @internal */
2533
+ const runScript = (handlerName) => () => {
2534
+ const handlers = getEventHandlers();
2535
+ const handler = handlers[handlerName];
2536
+ if (!handler)
2537
+ return;
2538
+ try {
2539
+ handler();
2540
+ }
2541
+ catch (e) {
2542
+ console.warn('Failed to run custom handler', handlerName, e);
2543
+ }
2544
+ };
2545
+ /** @internal */
2546
+ const submitForm = (to) => () => {
2547
+ const values = submit();
2548
+ send_event('_answer_question', values);
2549
+ _moveTo(to);
2550
+ };
2551
+ /** @internal */
2552
+ const execOnClickOperation = (onClickOperation) => {
2553
+ if (onClickOperation.operation === 'linkTo') {
2554
+ linkTo(...onClickOperation.args)();
2555
+ }
2556
+ else if (onClickOperation.operation === 'moveTo') {
2557
+ moveTo(...onClickOperation.args)();
2558
+ }
2559
+ else if (onClickOperation.operation === 'closeApp') {
2560
+ closeApp(onClickOperation.args[0] || 'button')();
2561
+ }
2562
+ else if (onClickOperation.operation === 'runScript') {
2563
+ runScript(onClickOperation.args[0])();
2564
+ }
2565
+ else if (onClickOperation.operation === 'submitForm') {
2566
+ submitForm(onClickOperation.args[0])();
2567
+ }
2568
+ };
2569
+ /** @internal */
2570
+ const haveFunction = (onClickOperation) => {
2571
+ return onClickOperation.operation !== 'none';
2572
+ };
2573
+ function getAnimation(animation) {
2574
+ switch (animation.type) {
2575
+ case 'fade':
2576
+ return `opacity: ${animation.progress}`;
2577
+ case 'bounce': {
2578
+ const translateX = animation.x;
2579
+ const translateY = animation.y;
2580
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0) scale(${animation.progress});`;
2581
+ }
2582
+ case 'slide-down': {
2583
+ const translateX = animation.x;
2584
+ const translateY = animation.y - 100 * (1 - animation.progress);
2585
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
2586
+ }
2587
+ case 'slide-up': {
2588
+ const translateX = animation.x;
2589
+ const translateY = animation.y + 100 * (1 - animation.progress);
2590
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
2591
+ }
2592
+ case 'slide-left': {
2593
+ const translateX = animation.x + 100 * (1 - animation.progress);
2594
+ const translateY = animation.y;
2595
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
2596
+ }
2597
+ case 'slide-right': {
2598
+ const translateX = animation.x - 100 * (1 - animation.progress);
2599
+ const translateY = animation.y;
2600
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
2601
+ }
2602
+ case 'none': {
2603
+ const translateX = animation.x;
2604
+ const translateY = animation.y;
2605
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
2606
+ }
2607
+ default:
2608
+ console.warn(`[action-sdk] invalid '${animation}', so we use 'transform: none' instead`);
2609
+ return 'transform: none';
2610
+ }
2611
+ }
2612
+ const EASING = {
2613
+ fade: linear,
2614
+ bounce: elasticOut,
2615
+ 'slide-down': cubicOut,
2616
+ 'slide-up': cubicOut,
2617
+ 'slide-left': cubicOut,
2618
+ 'slide-right': cubicOut,
2619
+ none: linear,
2620
+ };
2621
+ /**
2622
+ * The function to activate svelte animation.
2623
+ *
2624
+ * @param node - A target node of animation. This argument is passed by svelte, by default.
2625
+ * @param customAnimationOptions - A custom animation option object
2626
+ *
2627
+ * @see {@link https://svelte.dev/docs#template-syntax-element-directives-transition-fn-custom-transition-functions| Custom transition functions} for detail documentation
2628
+ *
2629
+ * @internal
2630
+ */
2631
+ function customAnimation(node, { transform, animationStyle, delay = 0, duration = 1000 }) {
2632
+ const [x, y] = transform;
2633
+ return {
2634
+ delay,
2635
+ duration,
2636
+ easing: EASING[animationStyle],
2637
+ css: (progress) => getAnimation({ type: animationStyle, x, y, progress }),
2638
+ };
2636
2639
  }
2637
2640
 
2638
2641
  /* src/components/BackgroundOverray.svelte generated by Svelte v3.53.1 */
@@ -2730,8 +2733,8 @@ function add_css$r(target) {
2730
2733
  append_styles(target, "svelte-1tg0tf", ".button.svelte-1tg0tf{display:block;text-decoration:none;color:inherit;border:none;background:none;margin:0;padding:0}.button.svelte-1tg0tf:link,.button.svelte-1tg0tf:visited,.button.svelte-1tg0tf:active,.button.svelte-1tg0tf:hover{color:inherit}");
2731
2734
  }
2732
2735
 
2733
- // (48:0) {:else}
2734
- function create_else_block$2(ctx) {
2736
+ // (49:0) {:else}
2737
+ function create_else_block$3(ctx) {
2735
2738
  let button;
2736
2739
  let current;
2737
2740
  let mounted;
@@ -2798,7 +2801,7 @@ function create_else_block$2(ctx) {
2798
2801
  };
2799
2802
  }
2800
2803
 
2801
- // (44:39)
2804
+ // (45:39)
2802
2805
  function create_if_block_2(ctx) {
2803
2806
  let div;
2804
2807
  let current;
@@ -2857,7 +2860,7 @@ function create_if_block_2(ctx) {
2857
2860
  };
2858
2861
  }
2859
2862
 
2860
- // (40:41)
2863
+ // (41:41)
2861
2864
  function create_if_block_1$2(ctx) {
2862
2865
  let a;
2863
2866
  let a_href_value;
@@ -2937,7 +2940,7 @@ function create_if_block_1$2(ctx) {
2937
2940
  };
2938
2941
  }
2939
2942
 
2940
- // (36:0) {#if disabled}
2943
+ // (37:0) {#if disabled}
2941
2944
  function create_if_block$6(ctx) {
2942
2945
  let div;
2943
2946
  let current;
@@ -3001,7 +3004,7 @@ function create_fragment$u(ctx) {
3001
3004
  let if_block;
3002
3005
  let if_block_anchor;
3003
3006
  let current;
3004
- const if_block_creators = [create_if_block$6, create_if_block_1$2, create_if_block_2, create_else_block$2];
3007
+ const if_block_creators = [create_if_block$6, create_if_block_1$2, create_if_block_2, create_else_block$3];
3005
3008
  const if_blocks = [];
3006
3009
 
3007
3010
  function select_block_type(ctx, dirty) {
@@ -3166,7 +3169,7 @@ function add_css$q(target) {
3166
3169
  append_styles(target, "svelte-yyiwdt", ".modal.svelte-yyiwdt{position:fixed;box-sizing:border-box;z-index:2147483647;display:flex}.modal.svelte-yyiwdt > .button{flex:auto;display:flex}.close.svelte-yyiwdt{position:absolute;top:0;right:0}.close.svelte-yyiwdt > .button{position:absolute;display:flex;justify-content:center;align-items:center;background-color:transparent;border:none;cursor:pointer;padding:0;transition:all 0.25s}.close.svelte-yyiwdt > .button:hover{transform:rotate(90deg)}.modal-content.svelte-yyiwdt{flex:auto;display:flex;justify-content:center;align-items:center}");
3167
3170
  }
3168
3171
 
3169
- // (144:0) {#if visible}
3172
+ // (145:0) {#if visible}
3170
3173
  function create_if_block$5(ctx) {
3171
3174
  let div;
3172
3175
  let button;
@@ -3245,7 +3248,7 @@ function create_if_block$5(ctx) {
3245
3248
  };
3246
3249
  }
3247
3250
 
3248
- // (161:6) {#if closable}
3251
+ // (162:6) {#if closable}
3249
3252
  function create_if_block_1$1(ctx) {
3250
3253
  let div;
3251
3254
  let button;
@@ -3307,7 +3310,7 @@ function create_if_block_1$1(ctx) {
3307
3310
  };
3308
3311
  }
3309
3312
 
3310
- // (163:10) <Button onClick={onClose} style={_closeStyle} eventName={closeEventName} eventValue={closeEventValue}>
3313
+ // (164:10) <Button onClick={onClose} style={_closeStyle} eventName={closeEventName} eventValue={closeEventValue}>
3311
3314
  function create_default_slot_1$1(ctx) {
3312
3315
  let svg;
3313
3316
  let path;
@@ -3340,7 +3343,7 @@ function create_default_slot_1$1(ctx) {
3340
3343
  };
3341
3344
  }
3342
3345
 
3343
- // (160:4) <Button {onClick} eventName={clickEventName} eventValue={clickEventValue}>
3346
+ // (161:4) <Button {onClick} eventName={clickEventName} eventValue={clickEventValue}>
3344
3347
  function create_default_slot$6(ctx) {
3345
3348
  let t;
3346
3349
  let div;
@@ -3442,7 +3445,7 @@ function create_fragment$t(ctx) {
3442
3445
 
3443
3446
  backgroundoverray = new BackgroundOverray({
3444
3447
  props: {
3445
- backgroundOverray: /*backgroundOverray*/ ctx[11]
3448
+ backgroundOverray: /*backgroundOverray*/ ctx[10]
3446
3449
  }
3447
3450
  });
3448
3451
 
@@ -3477,7 +3480,7 @@ function create_fragment$t(ctx) {
3477
3480
  p(new_ctx, [dirty]) {
3478
3481
  ctx = new_ctx;
3479
3482
  const backgroundoverray_changes = {};
3480
- if (dirty & /*backgroundOverray*/ 2048) backgroundoverray_changes.backgroundOverray = /*backgroundOverray*/ ctx[11];
3483
+ if (dirty & /*backgroundOverray*/ 1024) backgroundoverray_changes.backgroundOverray = /*backgroundOverray*/ ctx[10];
3481
3484
  backgroundoverray.$set(backgroundoverray_changes);
3482
3485
 
3483
3486
  if (/*visible*/ ctx[12]) {
@@ -3565,7 +3568,7 @@ function instance$t($$self, $$props, $$invalidate) {
3565
3568
  function div_binding($$value) {
3566
3569
  binding_callbacks[$$value ? 'unshift' : 'push'](() => {
3567
3570
  modal = $$value;
3568
- $$invalidate(10, modal);
3571
+ $$invalidate(11, modal);
3569
3572
  });
3570
3573
  }
3571
3574
 
@@ -3603,7 +3606,7 @@ function instance$t($$self, $$props, $$invalidate) {
3603
3606
  if ($$self.$$.dirty & /*placement*/ 2097152) {
3604
3607
  {
3605
3608
  if (placement && placement.backgroundOverlay) {
3606
- $$invalidate(11, backgroundOverray = placement.backgroundOverlay);
3609
+ $$invalidate(10, backgroundOverray = placement.backgroundOverlay);
3607
3610
  }
3608
3611
  }
3609
3612
  }
@@ -3654,12 +3657,12 @@ function instance$t($$self, $$props, $$invalidate) {
3654
3657
  $$invalidate(14, marginStyle = getMarginStyle(overwriteMargin));
3655
3658
  }
3656
3659
 
3657
- if ($$self.$$.dirty & /*close, modal*/ 16778240) {
3658
- $$invalidate(13, handle_keydown = handleKeydown({ Escape: close, Tab: handleFocus(modal) }));
3660
+ if ($$self.$$.dirty & /*close*/ 16777216) {
3661
+ $$invalidate(13, handle_keydown = handleKeydown({ Escape: close }));
3659
3662
  }
3660
3663
  };
3661
3664
 
3662
- $$invalidate(10, modal = null);
3665
+ $$invalidate(11, modal = null);
3663
3666
 
3664
3667
  // svelteコンポーネントのアニメーションを発火させるためにマウント時にvisibleをtrueにする。
3665
3668
  $$invalidate(12, visible = false);
@@ -3675,8 +3678,8 @@ function instance$t($$self, $$props, $$invalidate) {
3675
3678
  closeEventValue,
3676
3679
  closeButtonColor,
3677
3680
  _closeStyle,
3678
- modal,
3679
3681
  backgroundOverray,
3682
+ modal,
3680
3683
  visible,
3681
3684
  handle_keydown,
3682
3685
  marginStyle,
@@ -3998,7 +4001,7 @@ function get_each_context$6(ctx, list, i) {
3998
4001
  }
3999
4002
 
4000
4003
  // (13:2) {:else}
4001
- function create_else_block$1(ctx) {
4004
+ function create_else_block$2(ctx) {
4002
4005
  let t_value = /*item*/ ctx[2] + "";
4003
4006
  let t;
4004
4007
 
@@ -4045,7 +4048,7 @@ function create_each_block$6(ctx) {
4045
4048
  if (dirty & /*items*/ 1) show_if = null;
4046
4049
  if (show_if == null) show_if = !!/*item*/ ctx[2].match(regexp);
4047
4050
  if (show_if) return create_if_block$4;
4048
- return create_else_block$1;
4051
+ return create_else_block$2;
4049
4052
  }
4050
4053
 
4051
4054
  let current_block_type = select_block_type(ctx, -1);
@@ -4167,120 +4170,123 @@ class RenderText extends SvelteComponent {
4167
4170
  /* src/components/TextElement.svelte generated by Svelte v3.53.1 */
4168
4171
 
4169
4172
  function add_css$o(target) {
4170
- append_styles(target, "svelte-13cs3g2", ".text-element-wrapper.svelte-13cs3g2.svelte-13cs3g2{position:relative;height:100%}.text-element.svelte-13cs3g2.svelte-13cs3g2{display:flex;position:relative;width:100%;height:100%;box-sizing:border-box;white-space:pre-wrap;overflow:auto}.text-element-inner.svelte-13cs3g2.svelte-13cs3g2{width:100%;height:auto}.text-direction-vertical.svelte-13cs3g2.svelte-13cs3g2{writing-mode:vertical-rl}.text-direction-vertical.svelte-13cs3g2 .text-element-inner.svelte-13cs3g2{width:auto;height:100%}.tooltip.svelte-13cs3g2.svelte-13cs3g2{display:none;position:absolute;bottom:-40px;left:50%;transform:translateX(-50%);color:#fff;background-color:#3d4948;white-space:nowrap;padding:4px 8px 4px 8px;border-radius:4px;font-size:12px;z-index:2147483647}.tooltip.svelte-13cs3g2.svelte-13cs3g2:before{content:'';position:absolute;top:-13px;left:50%;margin-left:-7px;border:7px solid transparent;border-bottom:7px solid #3d4948}.tooltip.show.svelte-13cs3g2.svelte-13cs3g2{display:block}.tooltip-error.svelte-13cs3g2.svelte-13cs3g2{background-color:#c00}.tooltip-error.svelte-13cs3g2.svelte-13cs3g2:before{border-bottom:7px solid #c00}");
4173
+ append_styles(target, "svelte-600oh0", ".text-element-wrapper.svelte-600oh0.svelte-600oh0{position:relative;height:100%}.text-element.svelte-600oh0.svelte-600oh0{display:flex;position:relative;width:100%;height:100%;box-sizing:border-box;white-space:pre-wrap;overflow:auto;margin:0px;padding:0px}.text-link-element.svelte-600oh0.svelte-600oh0{text-decoration:none;color:inherit}.text-element-inner.svelte-600oh0.svelte-600oh0{width:100%;height:auto}.text-direction-vertical.svelte-600oh0.svelte-600oh0{writing-mode:vertical-rl}.text-direction-vertical.svelte-600oh0 .text-element-inner.svelte-600oh0{width:auto;height:100%}.tooltip.svelte-600oh0.svelte-600oh0{display:none;position:absolute;bottom:-40px;left:50%;transform:translateX(-50%);color:#fff;background-color:#3d4948;white-space:nowrap;padding:4px 8px 4px 8px;border-radius:4px;font-size:12px;z-index:2147483647}.tooltip.svelte-600oh0.svelte-600oh0:before{content:'';position:absolute;top:-13px;left:50%;margin-left:-7px;border:7px solid transparent;border-bottom:7px solid #3d4948}.tooltip.show.svelte-600oh0.svelte-600oh0{display:block}.tooltip-error.svelte-600oh0.svelte-600oh0{background-color:#c00}.tooltip-error.svelte-600oh0.svelte-600oh0:before{border-bottom:7px solid #c00}");
4171
4174
  }
4172
4175
 
4173
- // (58:2) {#if enableCopy}
4174
- function create_if_block$3(ctx) {
4175
- let div0;
4176
- let t1;
4176
+ // (78:2) {:else}
4177
+ function create_else_block$1(ctx) {
4177
4178
  let div1;
4179
+ let div0;
4180
+ let rendertext;
4181
+ let div1_class_value;
4182
+ let current;
4183
+ rendertext = new RenderText({ props: { text: /*text*/ ctx[0] } });
4178
4184
 
4179
4185
  return {
4180
4186
  c() {
4181
- div0 = element("div");
4182
- div0.textContent = "コピーしました";
4183
- t1 = space();
4184
4187
  div1 = element("div");
4185
- div1.textContent = "コピーできませんでした";
4186
- attr(div0, "class", "tooltip svelte-13cs3g2");
4187
- attr(div1, "class", "tooltip tooltip-error svelte-13cs3g2");
4188
+ div0 = element("div");
4189
+ create_component(rendertext.$$.fragment);
4190
+ attr(div0, "class", "text-element-inner svelte-600oh0");
4191
+ attr(div1, "class", div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"));
4192
+ attr(div1, "style", /*style*/ ctx[5]);
4188
4193
  },
4189
4194
  m(target, anchor) {
4190
- insert(target, div0, anchor);
4191
- /*div0_binding*/ ctx[9](div0);
4192
- insert(target, t1, anchor);
4193
4195
  insert(target, div1, anchor);
4194
- /*div1_binding*/ ctx[10](div1);
4196
+ append(div1, div0);
4197
+ mount_component(rendertext, div0, null);
4198
+ current = true;
4199
+ },
4200
+ p(ctx, dirty) {
4201
+ const rendertext_changes = {};
4202
+ if (dirty & /*text*/ 1) rendertext_changes.text = /*text*/ ctx[0];
4203
+ rendertext.$set(rendertext_changes);
4204
+
4205
+ if (!current || dirty & /*textDirection*/ 2 && div1_class_value !== (div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"))) {
4206
+ attr(div1, "class", div1_class_value);
4207
+ }
4208
+
4209
+ if (!current || dirty & /*style*/ 32) {
4210
+ attr(div1, "style", /*style*/ ctx[5]);
4211
+ }
4212
+ },
4213
+ i(local) {
4214
+ if (current) return;
4215
+ transition_in(rendertext.$$.fragment, local);
4216
+ current = true;
4217
+ },
4218
+ o(local) {
4219
+ transition_out(rendertext.$$.fragment, local);
4220
+ current = false;
4195
4221
  },
4196
- p: noop,
4197
4222
  d(detaching) {
4198
- if (detaching) detach(div0);
4199
- /*div0_binding*/ ctx[9](null);
4200
- if (detaching) detach(t1);
4201
4223
  if (detaching) detach(div1);
4202
- /*div1_binding*/ ctx[10](null);
4224
+ destroy_component(rendertext);
4203
4225
  }
4204
4226
  };
4205
4227
  }
4206
4228
 
4207
- function create_fragment$p(ctx) {
4208
- let div2;
4209
- let link;
4210
- let link_href_value;
4211
- let t0;
4212
- let div1;
4229
+ // (69:2) {#if enableCopy}
4230
+ function create_if_block$3(ctx) {
4231
+ let a;
4213
4232
  let div0;
4214
4233
  let rendertext;
4215
- let div1_class_value;
4216
- let t1;
4234
+ let a_class_value;
4235
+ let t0;
4236
+ let div1;
4237
+ let t2;
4238
+ let div2;
4217
4239
  let current;
4218
4240
  let mounted;
4219
4241
  let dispose;
4220
4242
  rendertext = new RenderText({ props: { text: /*text*/ ctx[0] } });
4221
- let if_block = /*enableCopy*/ ctx[1] && create_if_block$3(ctx);
4222
4243
 
4223
4244
  return {
4224
4245
  c() {
4225
- div2 = element("div");
4226
- link = element("link");
4227
- t0 = space();
4228
- div1 = element("div");
4246
+ a = element("a");
4229
4247
  div0 = element("div");
4230
4248
  create_component(rendertext.$$.fragment);
4231
- t1 = space();
4232
- if (if_block) if_block.c();
4233
- attr(link, "href", link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`);
4234
- attr(link, "rel", "stylesheet");
4235
- attr(div0, "class", "text-element-inner svelte-13cs3g2");
4236
- attr(div1, "class", div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[2]}`) + " svelte-13cs3g2"));
4237
- attr(div1, "style", /*style*/ ctx[5]);
4238
- attr(div2, "class", "text-element-wrapper svelte-13cs3g2");
4249
+ t0 = space();
4250
+ div1 = element("div");
4251
+ div1.textContent = "コピーしました";
4252
+ t2 = space();
4253
+ div2 = element("div");
4254
+ div2.textContent = "コピーできませんでした";
4255
+ attr(div0, "class", "text-element-inner svelte-600oh0");
4256
+ attr(a, "href", '');
4257
+ attr(a, "class", a_class_value = "" + (null_to_empty(`text-element text-link-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"));
4258
+ attr(a, "style", /*style*/ ctx[5]);
4259
+ attr(div1, "class", "tooltip svelte-600oh0");
4260
+ attr(div2, "class", "tooltip tooltip-error svelte-600oh0");
4239
4261
  },
4240
4262
  m(target, anchor) {
4241
- insert(target, div2, anchor);
4242
- append(div2, link);
4243
- append(div2, t0);
4244
- append(div2, div1);
4245
- append(div1, div0);
4263
+ insert(target, a, anchor);
4264
+ append(a, div0);
4246
4265
  mount_component(rendertext, div0, null);
4247
- append(div2, t1);
4248
- if (if_block) if_block.m(div2, null);
4266
+ insert(target, t0, anchor);
4267
+ insert(target, div1, anchor);
4268
+ /*div1_binding*/ ctx[10](div1);
4269
+ insert(target, t2, anchor);
4270
+ insert(target, div2, anchor);
4271
+ /*div2_binding*/ ctx[11](div2);
4249
4272
  current = true;
4250
4273
 
4251
4274
  if (!mounted) {
4252
- dispose = listen(div1, "click", /*click*/ ctx[6]);
4275
+ dispose = listen(a, "click", /*onCopy*/ ctx[6]);
4253
4276
  mounted = true;
4254
4277
  }
4255
4278
  },
4256
- p(ctx, [dirty]) {
4257
- if (!current || dirty & /*text*/ 1 && link_href_value !== (link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`)) {
4258
- attr(link, "href", link_href_value);
4259
- }
4260
-
4279
+ p(ctx, dirty) {
4261
4280
  const rendertext_changes = {};
4262
4281
  if (dirty & /*text*/ 1) rendertext_changes.text = /*text*/ ctx[0];
4263
4282
  rendertext.$set(rendertext_changes);
4264
4283
 
4265
- if (!current || dirty & /*textDirection*/ 4 && div1_class_value !== (div1_class_value = "" + (null_to_empty(`text-element text-direction-${/*textDirection*/ ctx[2]}`) + " svelte-13cs3g2"))) {
4266
- attr(div1, "class", div1_class_value);
4284
+ if (!current || dirty & /*textDirection*/ 2 && a_class_value !== (a_class_value = "" + (null_to_empty(`text-element text-link-element text-direction-${/*textDirection*/ ctx[1]}`) + " svelte-600oh0"))) {
4285
+ attr(a, "class", a_class_value);
4267
4286
  }
4268
4287
 
4269
4288
  if (!current || dirty & /*style*/ 32) {
4270
- attr(div1, "style", /*style*/ ctx[5]);
4271
- }
4272
-
4273
- if (/*enableCopy*/ ctx[1]) {
4274
- if (if_block) {
4275
- if_block.p(ctx, dirty);
4276
- } else {
4277
- if_block = create_if_block$3(ctx);
4278
- if_block.c();
4279
- if_block.m(div2, null);
4280
- }
4281
- } else if (if_block) {
4282
- if_block.d(1);
4283
- if_block = null;
4289
+ attr(a, "style", /*style*/ ctx[5]);
4284
4290
  }
4285
4291
  },
4286
4292
  i(local) {
@@ -4293,53 +4299,147 @@ function create_fragment$p(ctx) {
4293
4299
  current = false;
4294
4300
  },
4295
4301
  d(detaching) {
4296
- if (detaching) detach(div2);
4302
+ if (detaching) detach(a);
4297
4303
  destroy_component(rendertext);
4298
- if (if_block) if_block.d();
4304
+ if (detaching) detach(t0);
4305
+ if (detaching) detach(div1);
4306
+ /*div1_binding*/ ctx[10](null);
4307
+ if (detaching) detach(t2);
4308
+ if (detaching) detach(div2);
4309
+ /*div2_binding*/ ctx[11](null);
4299
4310
  mounted = false;
4300
4311
  dispose();
4301
4312
  }
4302
4313
  };
4303
4314
  }
4304
4315
 
4316
+ function create_fragment$p(ctx) {
4317
+ let div;
4318
+ let link;
4319
+ let link_href_value;
4320
+ let t;
4321
+ let current_block_type_index;
4322
+ let if_block;
4323
+ let current;
4324
+ const if_block_creators = [create_if_block$3, create_else_block$1];
4325
+ const if_blocks = [];
4326
+
4327
+ function select_block_type(ctx, dirty) {
4328
+ if (/*enableCopy*/ ctx[2]) return 0;
4329
+ return 1;
4330
+ }
4331
+
4332
+ current_block_type_index = select_block_type(ctx);
4333
+ if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
4334
+
4335
+ return {
4336
+ c() {
4337
+ div = element("div");
4338
+ link = element("link");
4339
+ t = space();
4340
+ if_block.c();
4341
+ attr(link, "href", link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`);
4342
+ attr(link, "rel", "stylesheet");
4343
+ attr(div, "class", "text-element-wrapper svelte-600oh0");
4344
+ },
4345
+ m(target, anchor) {
4346
+ insert(target, div, anchor);
4347
+ append(div, link);
4348
+ append(div, t);
4349
+ if_blocks[current_block_type_index].m(div, null);
4350
+ current = true;
4351
+ },
4352
+ p(ctx, [dirty]) {
4353
+ if (!current || dirty & /*text*/ 1 && link_href_value !== (link_href_value = `https://fonts.googleapis.com/css2?${getGoogleFontsParam()}&display=swap&text=${/*text*/ ctx[0]}`)) {
4354
+ attr(link, "href", link_href_value);
4355
+ }
4356
+
4357
+ let previous_block_index = current_block_type_index;
4358
+ current_block_type_index = select_block_type(ctx);
4359
+
4360
+ if (current_block_type_index === previous_block_index) {
4361
+ if_blocks[current_block_type_index].p(ctx, dirty);
4362
+ } else {
4363
+ group_outros();
4364
+
4365
+ transition_out(if_blocks[previous_block_index], 1, 1, () => {
4366
+ if_blocks[previous_block_index] = null;
4367
+ });
4368
+
4369
+ check_outros();
4370
+ if_block = if_blocks[current_block_type_index];
4371
+
4372
+ if (!if_block) {
4373
+ if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
4374
+ if_block.c();
4375
+ } else {
4376
+ if_block.p(ctx, dirty);
4377
+ }
4378
+
4379
+ transition_in(if_block, 1);
4380
+ if_block.m(div, null);
4381
+ }
4382
+ },
4383
+ i(local) {
4384
+ if (current) return;
4385
+ transition_in(if_block);
4386
+ current = true;
4387
+ },
4388
+ o(local) {
4389
+ transition_out(if_block);
4390
+ current = false;
4391
+ },
4392
+ d(detaching) {
4393
+ if (detaching) detach(div);
4394
+ if_blocks[current_block_type_index].d();
4395
+ }
4396
+ };
4397
+ }
4398
+
4305
4399
  function instance$p($$self, $$props, $$invalidate) {
4306
4400
  let style;
4307
4401
  let { text = 'サンプルSample' } = $$props;
4402
+ let { _textStyle = 'font-size:12px; line-height: 1.5;' } = $$props;
4403
+ let { textDirection = 'horizontal' } = $$props;
4404
+ let { _style = '' } = $$props;
4308
4405
  let { enableCopy = false } = $$props;
4406
+ let { eventName = '' } = $$props;
4407
+ let eventValue = undefined;
4309
4408
  let tooltipEl;
4310
4409
  let tooltipErrorEl;
4311
4410
 
4312
- const click = async () => {
4313
- if (enableCopy) {
4314
- try {
4315
- await navigator.clipboard.writeText(text);
4316
- tooltipEl.classList.add('show');
4317
- } catch(err) {
4318
- tooltipErrorEl.classList.add('show');
4411
+ const onCopy = async e => {
4412
+ e.preventDefault();
4413
+
4414
+ try {
4415
+ await navigator.clipboard.writeText(text);
4416
+
4417
+ if (eventName) {
4418
+ send_event(eventName, eventValue);
4319
4419
  }
4320
4420
 
4321
- setTimeout(
4322
- () => {
4323
- tooltipEl.classList.remove('show');
4324
- tooltipErrorEl.classList.remove('show');
4325
- },
4326
- 1000
4327
- );
4421
+ tooltipEl.classList.add('show');
4422
+ } catch(err) {
4423
+ tooltipErrorEl.classList.add('show');
4328
4424
  }
4329
- };
4330
4425
 
4331
- let { _textStyle = 'font-size:12px; line-height: 1.5;' } = $$props;
4332
- let { textDirection = 'horizontal' } = $$props;
4333
- let { _style = '' } = $$props;
4426
+ setTimeout(
4427
+ () => {
4428
+ tooltipEl.classList.remove('show');
4429
+ tooltipErrorEl.classList.remove('show');
4430
+ },
4431
+ 1000
4432
+ );
4433
+ };
4334
4434
 
4335
- function div0_binding($$value) {
4435
+ function div1_binding($$value) {
4336
4436
  binding_callbacks[$$value ? 'unshift' : 'push'](() => {
4337
4437
  tooltipEl = $$value;
4338
4438
  $$invalidate(3, tooltipEl);
4339
4439
  });
4340
4440
  }
4341
4441
 
4342
- function div1_binding($$value) {
4442
+ function div2_binding($$value) {
4343
4443
  binding_callbacks[$$value ? 'unshift' : 'push'](() => {
4344
4444
  tooltipErrorEl = $$value;
4345
4445
  $$invalidate(4, tooltipErrorEl);
@@ -4348,10 +4448,11 @@ function instance$p($$self, $$props, $$invalidate) {
4348
4448
 
4349
4449
  $$self.$$set = $$props => {
4350
4450
  if ('text' in $$props) $$invalidate(0, text = $$props.text);
4351
- if ('enableCopy' in $$props) $$invalidate(1, enableCopy = $$props.enableCopy);
4352
4451
  if ('_textStyle' in $$props) $$invalidate(7, _textStyle = $$props._textStyle);
4353
- if ('textDirection' in $$props) $$invalidate(2, textDirection = $$props.textDirection);
4452
+ if ('textDirection' in $$props) $$invalidate(1, textDirection = $$props.textDirection);
4354
4453
  if ('_style' in $$props) $$invalidate(8, _style = $$props._style);
4454
+ if ('enableCopy' in $$props) $$invalidate(2, enableCopy = $$props.enableCopy);
4455
+ if ('eventName' in $$props) $$invalidate(9, eventName = $$props.eventName);
4355
4456
  };
4356
4457
 
4357
4458
  $$self.$$.update = () => {
@@ -4362,16 +4463,17 @@ function instance$p($$self, $$props, $$invalidate) {
4362
4463
 
4363
4464
  return [
4364
4465
  text,
4365
- enableCopy,
4366
4466
  textDirection,
4467
+ enableCopy,
4367
4468
  tooltipEl,
4368
4469
  tooltipErrorEl,
4369
4470
  style,
4370
- click,
4471
+ onCopy,
4371
4472
  _textStyle,
4372
4473
  _style,
4373
- div0_binding,
4374
- div1_binding
4474
+ eventName,
4475
+ div1_binding,
4476
+ div2_binding
4375
4477
  ];
4376
4478
  }
4377
4479
 
@@ -4387,10 +4489,11 @@ class TextElement extends SvelteComponent {
4387
4489
  safe_not_equal,
4388
4490
  {
4389
4491
  text: 0,
4390
- enableCopy: 1,
4391
4492
  _textStyle: 7,
4392
- textDirection: 2,
4393
- _style: 8
4493
+ textDirection: 1,
4494
+ _style: 8,
4495
+ enableCopy: 2,
4496
+ eventName: 9
4394
4497
  },
4395
4498
  add_css$o
4396
4499
  );